From d3ed0883be904ff80e9a5e0ba003792cbc6b7754 Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Sun, 29 Nov 2026 10:45:46 -0600 Subject: [PATCH 01/14] claim-adjudicate.ps1: hold on any open copy, guard unknown and lone glyphs, index the ledger once BACKLOG #5480, the items added from engine PR 3124's open findings. Releasing direction: - Item 1: a landing phrase supersedes only where no status line reads OPEN. The #1010 test now uses #1010's own shape (no status glyph). - Item 2: every copy of an item number is judged, in both ledger files or twice in one, and SUPERSEDED needs every copy to protect it. - Item 3: a banner-shaped line opening with a symbol that is neither a status nor owed_ledger_acts.py's decoration holds the item. - Item 4: the status grammar reads one line at a time with horizontal spaces, so a CLOSED glyph alone on its line is no status; a lone OPEN glyph still holds. - Item 10: refuse a -LedgerRepo sharing a root commit with this repo, and a ledger whose pinned commit is older than -LedgerMaxAgeHours. Other: item 6 top-level -Json reference is the ledger's, with sources.engine added; item 7 standalone cases per rule; item 8 one heading scan per file; item 9 a parity test against owed_ledger_acts.py; item 11 engine-ref refusal wording. Verified-by: tests --- scripts/coord/claim-adjudicate.ps1 | 292 +++++++++++++++++++------ tests/test_coord_claim_adjudicate.py | 305 ++++++++++++++++++++++++++- 2 files changed, 521 insertions(+), 76 deletions(-) diff --git a/scripts/coord/claim-adjudicate.ps1 b/scripts/coord/claim-adjudicate.ps1 index 2cfbecb230..fa2b5f50c3 100644 --- a/scripts/coord/claim-adjudicate.ps1 +++ b/scripts/coord/claim-adjudicate.ps1 @@ -35,7 +35,8 @@ That is the single release criterion here: SUPERSEDED = the item exists in the backlog namespace on origin/main - AND its banner there already protects it. + AND its banner there already protects it -- in EVERY copy of the item, where + its number stands more than once. Nothing else is ever proposed for release. Not age, not quiet, not "the note says it is done". @@ -63,6 +64,19 @@ So OPEN means "not superseded HERE", never "not landed". An OPEN item whose branch carries unmerged commits is reported as blocking, never as available. + * A LANDING PHRASE UNDER AN OPEN STATUS LINE (BACKLOG #5480 item 1). The do-not-rebuild phrases + supersede only an item whose banner has no OPEN status line, the #1010 shape above. An open + item's banner carries the same capitals as SCOPE -- a PARTIAL banner names the half that + shipped, and vault #1393 quoted "DO NOT REBUILD" while it stood open -- so reading the phrase + over an open status line printed a release line for open work. + + A STALE LEDGER (BACKLOG #5480 items 5 and 10). A ledger checkout that has not fetched errs BOTH + ways: a banner it has not fetched reads as absent, which holds a claim that is safe to release, + and an item reopened since its last fetch still reads CLOSED there, which prints a release line + for open work. So the run refuses when the pinned ledger commit is older than + -LedgerMaxAgeHours (24 by default), and refuses a -LedgerRepo that shares a root commit with this + repository, since a clone of it from before 2026-09-13 still carries a full, stale ledger. + WHY THERE IS NO -Apply. `claim.ps1` owns the .history ledger: it writes the record BEFORE removing the file and refuses the release if the record cannot be written (BACKLOG #1068). A second writer of that file would be a second definition of it. This emits `claim.ps1 -Release` @@ -105,7 +119,11 @@ param( [string]$ClaimsDir = "", # A checkout of the repository that holds the backlog ledger (the vault). Every backlog-namespace # read runs there, pinned to its origin/main. See "WHERE THE LEDGER IS" in .NOTES. - [string]$LedgerRepo = "" + [string]$LedgerRepo = "", + # How old the ledger's pinned commit may be before the run refuses, in hours. See "A STALE LEDGER" + # in .NOTES: a checkout that has not fetched can show a since-reopened item CLOSED. + [ValidateRange(1, 87600)] + [int]$LedgerMaxAgeHours = 24 ) # A CLAUDE CODE CLOUD SESSION REACHES NO OTHER SESSION THROUGH THIS SCRIPT: its --git-common-dir is @@ -167,8 +185,10 @@ if (-not (Test-Path -LiteralPath $claimsDir)) { # with $PSNativeCommandUseErrorActionPreference true, git's first stderr line or its exit code throws # a generic error and the refusal below, with git's own words, never prints. alloc.ps1's # Invoke-SweepGit is the same shape for the same reason. $In is the repository the read runs in: -# this one, or the ledger checkout -LedgerRepo names. -function Invoke-NamespaceGit([string]$In, [string[]]$GitArgs, [string]$What, [string]$Why) { +# this one, or the ledger checkout -LedgerRepo names. $Consequence replaces the namespace sentence +# for a read that is not of the namespace (BACKLOG #5480 item 11): under -LedgerRepo this +# repository's main is not the namespace, so a failure there must not say it is. +function Invoke-NamespaceGit([string]$In, [string[]]$GitArgs, [string]$What, [string]$Why, [string]$Consequence = "") { $ErrorActionPreference = "Continue" $PSNativeCommandUseErrorActionPreference = $false $global:LASTEXITCODE = -1 @@ -176,7 +196,8 @@ function Invoke-NamespaceGit([string]$In, [string[]]$GitArgs, [string]$What, [st $code = $LASTEXITCODE $detail = (@($all | Where-Object { $_ -is [System.Management.Automation.ErrorRecord] } | ForEach-Object { "$_" }) -join "`n ").Trim() if ($code -ne 0) { - throw "could not read $What (git $($GitArgs[0]) exited $code): cannot adjudicate any key against a namespace that was $Why. git said:`n $detail" + if (-not $Consequence) { $Consequence = "cannot adjudicate any key against a namespace that was $Why" } + throw "could not read $What (git $($GitArgs[0]) exited $code): $Consequence. git said:`n $detail" } # A clean exit can still carry a warning (a broken or ambiguous ref, say). Echoed to stderr, so # it neither disappears nor lands in the -Json document on stdout; not refused, git answered. @@ -200,7 +221,7 @@ function Invoke-NamespaceGit([string]$In, [string[]]$GitArgs, [string]$What, [st # banner nobody published, and reading it would RELEASE a claim on protection that does not travel -- # the costly direction, not the harmless one. So a ledger checkout without origin/main refuses, with # git's own words, through the wrapper. -function Resolve-PinnedMain([string]$In, [switch]$AllowLocal) { +function Resolve-PinnedMain([string]$In, [switch]$AllowLocal, [string]$Consequence = "") { $ref = "origin/main" if ($AllowLocal) { $sha = "$(& git -C $In rev-parse --verify --quiet refs/remotes/origin/main 2>$null)".Trim() @@ -208,13 +229,16 @@ function Resolve-PinnedMain([string]$In, [switch]$AllowLocal) { $ref = "main" } $full = if ($ref -eq "main") { "refs/heads/main" } else { "refs/remotes/origin/main" } - $sha = (@(Invoke-NamespaceGit $In @('rev-parse', '--verify', "$full^{commit}") "$ref in $In" "not read") -join '').Trim() + $sha = (@(Invoke-NamespaceGit $In @('rev-parse', '--verify', "$full^{commit}") "$ref in $In" "not read" $Consequence) -join '').Trim() [pscustomobject]@{ Ref = $ref; Sha = $sha; IsRemote = ($ref -eq "origin/main") } } # This repository's reference: the citation log and the ahead counts, and the namespace when no -# -LedgerRepo is given. -$pinned = Resolve-PinnedMain $repo -AllowLocal +# -LedgerRepo is given. Under -LedgerRepo it is not the namespace, and its refusal says what it is. +$engineConsequence = if ($LedgerRepo) { + "cannot count the claimed branches' commits or collect their citations against this repository's main, so no key was adjudicated" +} else { "" } +$pinned = Resolve-PinnedMain $repo -AllowLocal -Consequence $engineConsequence $mainRef = $pinned.Ref; $mainSha = $pinned.Sha; $mainIsRemote = $pinned.IsRemote # --------------------------------------------------------------------------------------------- @@ -240,6 +264,46 @@ else { } $ledgerRef = $ledgerPinned.Ref; $ledgerSha = $ledgerPinned.Sha +# --------------------------------------------------------------------------------------------- +# IS IT THE LEDGER, AND IS IT RECENT (BACKLOG #5480 item 10). +# +# NOT THIS REPOSITORY'S OWN HISTORY. A clone of this repository that last fetched before 2026-09-13 +# still carries the full ledger on its origin/main, and it passes every check below it: the item +# headings are real, only stale. So a -LedgerRepo that shares a root commit with this repository +# refuses. This proves the checkout is not this repository; it does not prove which repository it +# is, and the item-heading admission below is what refuses one that holds no ledger at all. +# +# NOT STALE. A ledger checkout that has not fetched can show a since-reopened item CLOSED, and that +# prints a release line for open work -- the costly direction. Whether origin/main has moved upstream +# since the last fetch cannot be known without a fetch, which this tool does not do, so the bound is +# on the pinned commit's own committer date: older than -LedgerMaxAgeHours refuses. It applies with +# or without -LedgerRepo, since whichever repository is read is the one whose banners decide. +# --------------------------------------------------------------------------------------------- +if ($LedgerRepo) { + $engineRoots = @(Invoke-NamespaceGit $repo @('rev-list', '--max-parents=0', $mainSha) "the root commits of $mainRef in $repo" "not read" $engineConsequence) + $ledgerRoots = @(Invoke-NamespaceGit $ledgerRoot @('rev-list', '--max-parents=0', $ledgerSha) "the root commits of $ledgerRef ($ledgerSha) in $ledgerRoot" "not read") + $shared = @($ledgerRoots | Where-Object { $_ -and ($engineRoots -ccontains $_) }) + if ($shared.Count) { + throw ("-LedgerRepo $ledgerRoot shares root commit $($shared[0]) with this repository, so it is a " + + "checkout of this repository and not of the ledger's. Its backlog files are this repository's " + + "stub, or a ledger copy from before 2026-09-13 that nothing keeps current. Refusing rather than " + + "adjudicate against it.$remedy") + } +} +$ledgerStamp = (@(Invoke-NamespaceGit $ledgerRoot @('log', '-1', '--format=%ct', $ledgerSha) "the commit date of $ledgerRef ($ledgerSha) in $ledgerRoot" "not read") -join '').Trim() +if ($ledgerStamp -notmatch '^\d+$') { + throw "could not read the commit date of $ledgerRef ($ledgerSha) in ${ledgerRoot}: git printed '$ledgerStamp'. Refusing rather than adjudicate against a ledger of unknown age." +} +$ledgerAgeHours = ([DateTimeOffset]::UtcNow.ToUnixTimeSeconds() - [long]$ledgerStamp) / 3600.0 +if ($ledgerAgeHours -gt $LedgerMaxAgeHours) { + $when = [DateTimeOffset]::FromUnixTimeSeconds([long]$ledgerStamp).UtcDateTime.ToString('yyyy-MM-ddTHH:mm:ssZ') + throw ("the ledger at $ledgerRef ($ledgerSha) in $ledgerRoot was committed $when, " + + "$([Math]::Floor($ledgerAgeHours)) hours ago, past -LedgerMaxAgeHours $LedgerMaxAgeHours. A stale " + + "ledger can show a since-reopened item CLOSED and print a release line for open work. Run " + + "'git -C `"$ledgerRoot`" fetch origin' and adjudicate again; if its origin/main truly has not moved " + + "since then, pass a larger -LedgerMaxAgeHours.") +} + # --------------------------------------------------------------------------------------------- # THE BACKLOG NAMESPACE ON $ledgerRef OF $ledgerRoot. # @@ -287,22 +351,75 @@ if (-not $corpus.Count) { } $corpusFiles = @($corpus.Keys | Sort-Object) -# The status vocabulary is backlog_status_check.py's, not this file's. Held as codepoints so the -# source stays readable on a console that cannot render them. -$CLOSED_GLYPH = [ordered]@{} -$CLOSED_GLYPH[[char]::ConvertFromUtf32(0x2705)] = "shipped" -$CLOSED_GLYPH[[char]::ConvertFromUtf32(0x26D4)] = "declined" -$CLOSED_GLYPH[[char]::ConvertFromUtf32(0x1FAA6)] = "retired" -$OPEN_GLYPH = [ordered]@{} -$OPEN_GLYPH[[char]::ConvertFromUtf32(0x1F522)] = "prioritized" -$OPEN_GLYPH[[char]::ConvertFromUtf32(0x1F6A7)] = "in progress" +# EVERY ITEM HEADING, INDEXED ONCE (BACKLOG #5480 item 8). A per-key regex over the whole corpus, +# followed by a copy of everything after the match, cost about 1.5 s a key on the 35 MB vault ledger. +# One pass over each file records where every `## N.` heading starts and where the next `## ` +# heading ends it; a key then reads its blocks out of that map. The grammar is the one the per-key +# match used: the heading's digits as written, and the block running to the next level-2 heading. +# +# EVERY COPY, NOT THE FIRST (item 2). A number standing in both ledger files -- mid-move between +# them -- or twice in one file has as many blocks here as it has headings, and the verdict below +# supersedes only when every copy protects the item. Taking the first copy took the archive's, since +# it sorts first, and a CLOSED archive copy then released a claim the live copy still holds OPEN. +# owed_ledger_acts.py reads such a row OPEN if either copy is, and this is the same rule. +# +# ONE SCAN PER FILE: every level-2 heading, with the item number captured where the heading is an +# item's. `^##\s` then `\s*\d+\.\s` is the per-key pattern `^##\s+N\.\s` split in two. A +# `Regex.Match(text, startat)` per heading was tried first and rescanned the text from each start. +$itemIndex = [System.Collections.Generic.Dictionary[string, System.Collections.Generic.List[object]]]::new([StringComparer]::Ordinal) +$heading = [regex]'(?m)^##\s(?:\s*(?\d+)\.\s)?' +foreach ($f in $corpusFiles) { + $text = $corpus[$f] + $starts = [System.Collections.Generic.List[int]]::new() + $items = [System.Collections.Generic.List[object]]::new() + foreach ($h in $heading.Matches($text)) { + $starts.Add($h.Index) + if ($h.Groups['n'].Success) { $items.Add($h) } + } + foreach ($m in $items) { + # The block runs to the first heading starting at or after this heading's own end. + $j = $starts.BinarySearch($m.Index + $m.Length) + if ($j -lt 0) { $j = -bnot $j } + $end = if ($j -lt $starts.Count) { $starts[$j] } else { $text.Length } + $n = $m.Groups['n'].Value + if (-not $itemIndex.ContainsKey($n)) { $itemIndex[$n] = [System.Collections.Generic.List[object]]::new() } + $itemIndex[$n].Add([pscustomobject]@{ File = $f; Start = $m.Index; Length = $end - $m.Index }) + } +} + +# The status vocabulary is backlog_status_check.py's, not this file's, restated as +# owed_ledger_acts.py restates it; tests/test_coord_claim_adjudicate.py holds the codepoints equal to +# that file's. Held as codepoints so the source stays readable on a console that cannot render them, +# and looked up ORDINALLY: PowerShell's own string comparison is a culture collation, under which two +# different symbols can compare equal. +$GLYPH_NAME = [System.Collections.Generic.Dictionary[string, string]]::new([StringComparer]::Ordinal) +$CLOSED_GLYPH = [System.Collections.Generic.List[string]]::new() +$OPEN_GLYPH = [System.Collections.Generic.List[string]]::new() +foreach ($e in @(@(0x2705, 'shipped'), @(0x26D4, 'declined'), @(0x1FAA6, 'retired'))) { + $g = [char]::ConvertFromUtf32($e[0]); $CLOSED_GLYPH.Add($g); $GLYPH_NAME[$g] = $e[1] +} +foreach ($e in @(@(0x1F522, 'prioritized'), @(0x1F6A7, 'in progress'))) { + $g = [char]::ConvertFromUtf32($e[0]); $OPEN_GLYPH.Add($g); $GLYPH_NAME[$g] = $e[1] +} +# The symbols that open blockquote lines in the vault ledger as DECORATION, not status: +# owed_ledger_acts.py's `_DECORATION`, measured there over both ledger files. +$DECORATION = [System.Collections.Generic.HashSet[string]]::new([StringComparer]::Ordinal) +foreach ($cp in @(0x26A0, 0x1F6E0, 0x1F4CC, 0x1F4D0, 0x2B06, 0x1F50E, 0x1F7E2, 0x1F536, 0x1F9ED, 0x1F512, 0x1F501, 0x2B50)) { + [void]$DECORATION.Add([char]::ConvertFromUtf32($cp)) +} # A STATUS IS A LINE THAT OPENS WITH ONE: `> `, the glyph, an optional variation selector, a space -- # owed_ledger_acts.py's `_BANNER`, restating the vault ledger's grammar. A glyph anywhere else in the # banner run is decoration or prose, and the vault ledger uses the declined glyph that way inside # items that are open (measured 2026-11-19: "not started. OPEN ON EVERY GATE # MEASURED"). Matching it anywhere read those items CLOSED and printed a release line for open work. -$STATUS_LINE = [regex]('(?m)^>\s(?' + ((@($CLOSED_GLYPH.Keys) + @($OPEN_GLYPH.Keys) | ForEach-Object { [regex]::Escape($_) }) -join '|') + ')\uFE0F?\s') +# +# THE SPACES ARE HORIZONTAL (item 4). `\s` matches a newline too, so a CLOSED glyph alone on its line +# read as a status off the line below it; owed_ledger_acts.py matches one line at a time and does +# not. This reads one line at a time as well, and spells the space as whitespace other than a line +# break. It cuts one way: an OPEN glyph opening a line holds the item whatever follows it, since an +# open status misread costs a stale claim and a closed one misread costs a duplicate build. +$BANNER_SHAPE = [regex]'^>[^\S\r\n](?[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\x00-\x7F])\uFE0F?(?[^\S\r\n])?' # A do-not-rebuild banner is prose, so it is matched on the few phrasings that assert the LANDING # ITSELF. A bare "do not build" is deliberately absent: a note reading "DO NOT BUILD half B" is @@ -317,20 +434,15 @@ $LANDED_BANNER = @( ) function Get-ItemBlock([string]$ItemKey) { - # The item's text and the file it came from, or $null. Only a whole-number key can name a backlog - # item; anything else belongs to a different namespace and must not be pattern-matched into this - # one. - if ($ItemKey -notmatch '^\d+$') { return $null } - foreach ($f in $corpusFiles) { - $text = $corpus[$f] - $m = [regex]::Match($text, '(?m)^##\s+' + [regex]::Escape($ItemKey) + '\.\s') - if (-not $m.Success) { continue } - $rest = $text.Substring($m.Index) - $nxt = [regex]::Match($rest.Substring($m.Length), '(?m)^##\s') - $block = if ($nxt.Success) { $rest.Substring(0, $m.Length + $nxt.Index) } else { $rest } - return [pscustomobject]@{ File = $f; Text = $block } - } - return $null + # Every block the key names, each with the file it came from; empty when it names none. Only a + # whole-number key can name a backlog item; anything else belongs to a different namespace and + # must not be pattern-matched into this one. + if ($ItemKey -notmatch '^\d+$') { return @() } + $hits = $null + if (-not $itemIndex.TryGetValue($ItemKey, [ref]$hits)) { return @() } + @(foreach ($h in $hits) { + [pscustomobject]@{ File = $h.File; Text = $corpus[$h.File].Substring($h.Start, $h.Length) } + }) } function Get-LeadingQuote([string]$Block) { @@ -353,6 +465,61 @@ function Get-LeadingQuote([string]$Block) { return ($out -join "`n") } +function Get-BannerState([string]$Block) { + # One block's banner state, whether it protects the item, and the observation it rests on. + # + # AN OPEN STATUS LINE WINS OVER A LANDING PHRASE (BACKLOG #5480 item 1). A landing phrase is prose, + # and an open item's banner carries it as SCOPE: vault #1393 once quoted "DO NOT REBUILD" while it + # stood open, and a PARTIAL banner names the half that shipped in exactly those words. So the + # phrase protects an item only where no status line reads OPEN. #1010's shape, a landing banner + # with no status glyph at all, still supersedes. + # + # A SYMBOL THIS COPY OF THE GRAMMAR DOES NOT KNOW HOLDS THE ITEM (item 3). owed_ledger_acts.py + # reads a banner-shaped line opening with an unknown symbol as a status it cannot judge, and + # never reads that row CLOSED; a status the vault adds later is far likelier an open one than not. + # Here it blocks the landing phrase as well, for item 1's reason. + $lead = Get-LeadingQuote $Block + $closed = [System.Collections.Generic.List[string]]::new() + $open = [System.Collections.Generic.List[string]]::new() + $unknown = [System.Collections.Generic.List[string]]::new() + foreach ($l in ($lead -split "`n")) { + $m = $BANNER_SHAPE.Match($l) + if (-not $m.Success) { continue } + $g = $m.Groups['g'].Value + if ($OPEN_GLYPH.Contains($g)) { $open.Add($g); continue } + if ($CLOSED_GLYPH.Contains($g)) { + if ($m.Groups['sp'].Success) { $closed.Add($g) } + continue + } + if ($DECORATION.Contains($g)) { continue } + $rune = [System.Text.Rune]::GetRuneAt($g, 0) + if ([System.Text.Rune]::GetUnicodeCategory($rune) -eq [System.Globalization.UnicodeCategory]::OtherSymbol) { + $unknown.Add(('U+{0:X4}' -f $rune.Value)) + } + } + if (-not $open.Count -and -not $unknown.Count) { + # CLOSED only where a closed status line stands and no open one does -- the vault's own verdict. + foreach ($g in $CLOSED_GLYPH) { + if ($closed.Contains($g)) { + return [pscustomobject]@{ State = "CLOSED/" + $GLYPH_NAME[$g]; Why = ""; Protects = $true } + } + } + foreach ($p in $LANDED_BANNER) { + if ([regex]::IsMatch($lead, $p)) { + # Quote the banner's own sentence back, so the verdict carries the observation it + # rests on rather than a label the reader must take on trust. + $line = ($lead -split "`n" | Where-Object { [regex]::IsMatch($_, $p) } | Select-Object -First 1) + $why = (($line -replace '^\s*>\s*', '') -replace '\*', '').Trim() + return [pscustomobject]@{ State = "LANDED-BANNER"; Why = $why; Protects = $true } + } + } + } + $state = if ($open.Count) { "OPEN/" + $GLYPH_NAME[$open[0]] } + elseif ($unknown.Count) { "UNKNOWN-STATUS/" + $unknown[0] } + else { "NO-BANNER" } + [pscustomobject]@{ State = $state; Why = ""; Protects = $false } +} + # --------------------------------------------------------------------------------------------- # Delivery citations. COLLECTED AND PRINTED, NEVER SCORED -- see .NOTES. # --------------------------------------------------------------------------------------------- @@ -474,52 +641,37 @@ foreach ($f in $files) { continue } - $block = Get-ItemBlock $k + $blocks = @(Get-ItemBlock $k) # @() re-wraps what PowerShell unrolled on return. Without it a SINGLE citation reaches # ConvertTo-Json as a bare object rather than a one-element array, so a JSON consumer that # iterates `citations` gets field NAMES when there is one hit and records when there are two -- # a shape that changes with the data is worse than one that is always awkward. $cites = @(Get-Citations $k) - if (-not $block) { + if (-not $blocks.Count) { $rows += [pscustomobject]@{ key = $k; holder = $holder; branch = $branch; note = $note item = ""; banner = ""; citations = $cites; verdict = "NO-ITEM" why = "'$k' names no item in the backlog namespace on $ledgerAt -- this instrument does not reach it, which is not a finding about the work" } continue } - $lead = Get-LeadingQuote $block.Text - $bannerState = ""; $bannerWhy = "" - $status = @([regex]::Matches($lead, $STATUS_LINE) | ForEach-Object { $_.Groups['g'].Value }) - $openAt = @($status | Where-Object { $OPEN_GLYPH.Contains($_) }) - - # CLOSED only where a closed status line stands and no open one does -- the vault's own verdict. - if (-not $openAt.Count) { - foreach ($g in $CLOSED_GLYPH.Keys) { - if ($status -contains $g) { $bannerState = "CLOSED/" + $CLOSED_GLYPH[$g]; break } - } - } - if (-not $bannerState) { - foreach ($p in $LANDED_BANNER) { - if ([regex]::IsMatch($lead, $p)) { - $bannerState = "LANDED-BANNER" - # Quote the banner's own sentence back, so the verdict carries the observation it - # rests on rather than a label the reader must take on trust. - $line = ($lead -split "`n" | Where-Object { [regex]::IsMatch($_, $p) } | Select-Object -First 1) - $bannerWhy = ($line -replace '^\s*>\s*', '') -replace '\*', '' - $bannerWhy = $bannerWhy.Trim() - break - } - } - } - if (-not $bannerState -and $openAt.Count) { $bannerState = "OPEN/" + $OPEN_GLYPH[$openAt[0]] } - if (-not $bannerState) { $bannerState = "NO-BANNER" } - - if ($bannerState -like 'CLOSED/*' -or $bannerState -eq 'LANDED-BANNER') { + # Every copy is judged, and the first that does not protect the item decides (item 2). + $judged = @(foreach ($b in $blocks) { + $s = Get-BannerState $b.Text + [pscustomobject]@{ File = $b.File; State = $s.State; Why = $s.Why; Protects = $s.Protects } + }) + $holding = @($judged | Where-Object { -not $_.Protects }) + $copies = if ($judged.Count -gt 1) { + " (the item stands $($judged.Count) times, in " + ((@($judged | ForEach-Object File) | Select-Object -Unique) -join ', ') + ", and every copy is read)" + } else { "" } + + if (-not $holding.Count) { + $bannerState = $judged[0].State; $bannerWhy = $judged[0].Why $quote = if ($bannerWhy) { ": `"" + $bannerWhy.Substring(0, [Math]::Min(140, $bannerWhy.Length)) + "`"" } else { "" } $rows += [pscustomobject]@{ key = $k; holder = $holder; branch = $branch; note = $note - item = $block.File; banner = $bannerState; citations = $cites; verdict = "SUPERSEDED" - why = "the item's banner on $ledgerAt already protects it ($bannerState)$quote -- that protection travels to every checkout and this machine-local claim does not" } + item = ((@($judged | ForEach-Object File) | Select-Object -Unique) -join ', '); banner = $bannerState + citations = $cites; verdict = "SUPERSEDED" + why = "the item's banner on $ledgerAt already protects it ($bannerState)$quote$copies -- that protection travels to every checkout and this machine-local claim does not" } } else { # BOTH copies of the branch, spelled in full (BACKLOG #7563). Probing the local branch first and @@ -550,8 +702,8 @@ foreach ($f in $files) { elseif ($parts[0].Zero) { "'$branch' carries no commit $mainRef lacks" } else { "'$branch' carries $($parts[0].Text)" } $rows += [pscustomobject]@{ key = $k; holder = $holder; branch = $branch; note = $note - item = $block.File; banner = $bannerState; citations = $cites; verdict = "BLOCKING" - why = "item reads $bannerState on $ledgerAt and $aheadTxt -- so the key is unclaimable by any future session while nothing on $ledgerAt protects it" } + item = $holding[0].File; banner = $holding[0].State; citations = $cites; verdict = "BLOCKING" + why = "item reads $($holding[0].State) on $ledgerAt and $aheadTxt -- so the key is unclaimable by any future session while nothing on $ledgerAt protects it$copies" } } } @@ -561,7 +713,10 @@ foreach ($f in $files) { if ($Json) { [pscustomobject]@{ scanned = $true - reference = $mainRef + # The reference every VERDICT was read against, which is the ledger's (BACKLOG #5480 item 6). + # Under -LedgerRepo this repository's main decides only the ahead counts and the citations, + # and `sources.engine` names it. + reference = $ledgerRef applied = $false sources = [pscustomobject]@{ claims = $claimsDir @@ -569,6 +724,7 @@ if ($Json) { # The repository, ref and pinned SHA every namespace read took, so a report names the # ledger it was read against rather than leaving the reader to assume this repository. ledger = [pscustomobject]@{ repo = $ledgerRoot; reference = $ledgerRef; sha = $ledgerSha } + engine = [pscustomobject]@{ repo = $repo; reference = $mainRef; sha = $mainSha } } counts = [pscustomobject]@{ total = $rows.Count diff --git a/tests/test_coord_claim_adjudicate.py b/tests/test_coord_claim_adjudicate.py index 63ab37e498..a2dd66db20 100644 --- a/tests/test_coord_claim_adjudicate.py +++ b/tests/test_coord_claim_adjudicate.py @@ -22,11 +22,14 @@ from __future__ import annotations +import importlib.util import json import os import re import shutil import subprocess +import sys +import time from pathlib import Path import pytest @@ -191,20 +194,22 @@ def test_a_closed_banner_supersedes_the_claim( assert r["banner"] == expected -def test_a_do_not_rebuild_banner_supersedes_even_while_the_item_reads_open( +def test_a_do_not_rebuild_banner_supersedes_an_item_with_no_status_line( repo: Path, tmp_path: Path ) -> None: """#1010's exact shape, and the case the branch-level tool structurally cannot reach. - The item is LANDED, the banner says so in prose, and the status glyph still reads OPEN because - the flip was written on a branch that has not merged. reconcile sees 74 unmerged commits on the - seat branch and holds. What actually matters is on origin/main and says DO NOT REBUILD. + The item is LANDED, the banner says so in prose, and it carries NO status glyph because the flip + was written on a branch that has not merged (the script's .NOTES). reconcile sees 74 unmerged + commits on the seat branch and holds. What actually matters is on origin/main and says DO NOT + REBUILD. Before BACKLOG #5480 item 1 this fixture also carried an OPEN status line and still + superseded; that combination now holds (test_a_landing_phrase_under_an_open_status_line_holds). """ backlog( repo, - f"## 8. A landed thing\n\n" - f"> **THE BUILD HAS LANDED ON `origin/main` AND THIS BANNER STILL READS OPEN. " - f"DO NOT REBUILD.**\n>\n> {PRIORITIZED} P2 quick win\n\nbody\n", + "## 8. A landed thing\n\n" + "> **THE BUILD HAS LANDED ON `origin/main` AND THIS BANNER STILL READS OPEN. " + "DO NOT REBUILD.**\n>\n> P2 quick win\n\nbody\n", ) unmerged_branch(repo, "seat") write_claim(repo, "8", tmp_path / "gone", "seat") @@ -907,6 +912,13 @@ def test_an_archive_file_not_named_backlog_does_not_shadow_the_ledger( f"> {IN_PROGRESS} in progress\n> **Filed -- not started. {DECLINED} OPEN ON EVERY GATE.**", # "do not rebuild" as SCOPE, in lower case, inside an open item. f"> {PRIORITIZED} open\n> Build the pane; do not rebuild the endpoint.", + # EACH RULE ALONE (BACKLOG #5480 item 7). With an OPEN status line beside it, the open line + # holds the item whatever the rule under test does, so the two cases above cannot fail when + # that rule regresses. These carry no status line, so only the rule named holds them. + # The line-start rule: a CLOSED glyph mid-line is not a status. + f"> **Filed -- not started. {DECLINED} OPEN ON EVERY GATE.**", + # The case rule: a landing phrase in lower case is scope, not a landing. + "> Build the pane; do not rebuild the endpoint.", ], ) def test_vault_banner_shapes_that_are_not_a_closure_stay_blocking( @@ -914,7 +926,8 @@ def test_vault_banner_shapes_that_are_not_a_closure_stay_blocking( ) -> None: """MUST TRIP on origin/main, which matched a CLOSED glyph anywhere in the banner run and the landing phrases in any case. Both shapes stand in the vault ledger inside open items (measured - 2026-11-19), and each read SUPERSEDED there: a printed release line for open, unbuilt work.""" + 2026-11-19), and each read SUPERSEDED there: a printed release line for open, unbuilt work. + The last two cases pin each rule on its own; the first two pin them beside an open line.""" backlog(repo, f"## 69. Open thing\n\n{lead}\n\nbody\n") unmerged_branch(repo, "seat") write_claim(repo, "69", tmp_path / "gone", "seat") @@ -1089,3 +1102,279 @@ def test_the_key_file_fold_is_claim_ps1s_own() -> None: """The copy here must fold a -Key exactly as claim.ps1 names the file, or -Key drops the key's own unreadable claim.""" assert _ps_function(ADJUDICATE, "ConvertTo-KeyFile") == _ps_function(CLAIM, "ConvertTo-KeyFile") + + +# =================================================================================================== +# BACKLOG #5480: ENGINE PR 3124'S OPEN FINDINGS. Items 1 to 5 could release a claim that should be +# held. Each test below that says MUST TRIP fails on the script at engine origin/main ddf50248fae. +# =================================================================================================== + +# A symbol no copy of the ledger grammar knows: neither a status nor owed_ledger_acts.py's decoration. +UNKNOWN = "\N{LARGE RED SQUARE}" +# owed_ledger_acts.py's first decoration glyph, which is not a status. +DECORATION = "\N{WARNING SIGN}" + + +@pytest.mark.parametrize("glyph", [PRIORITIZED, IN_PROGRESS]) +@pytest.mark.parametrize("phrase_first", [True, False]) +def test_a_landing_phrase_under_an_open_status_line_holds( + repo: Path, tmp_path: Path, glyph: str, phrase_first: bool +) -> None: + """MUST TRIP (item 1). A PARTIAL banner names the half that shipped in capitals, and vault #1393 + quoted DO NOT REBUILD while it stood open. With an OPEN status line standing, the phrase is scope + and the item is held, whichever line comes first. The control is the no-status-line case above.""" + status = f"> {glyph} **PARTIAL -- half A shipped**" + phrase = "> **Half A HAS LANDED ON `origin/main`. DO NOT REBUILD it; half B is open.**" + lead = f"{phrase}\n>\n{status}" if phrase_first else f"{status}\n>\n{phrase}" + backlog(repo, f"## 70. Half built\n\n{lead}\n\nbody\n") + unmerged_branch(repo, "seat") + write_claim(repo, "70", tmp_path / "gone", "seat") + r = rows(repo)["70"] + assert r["verdict"] == "BLOCKING", r + assert r["banner"].startswith("OPEN/"), r + + +@pytest.mark.parametrize("live_open", [True, False]) +def test_an_item_in_both_ledger_files_is_superseded_only_when_every_copy_protects_it( + repo: Path, tmp_path: Path, live_open: bool +) -> None: + """MUST TRIP (item 2) when ``live_open``. A row mid-move stands in both files; the archive sorts + first, and taking its CLOSED copy released a claim the live copy still holds OPEN. The control is + both copies CLOSED, which still supersedes and names both files.""" + _publish( + repo, + "docs/archive/backlog/BACKLOG-CLOSED.md", + f"# Closed\n\n## 71. Moving thing\n\n> {SHIPPED} SHIPPED\n\nbody\n", + ) + live = f"> {PRIORITIZED} reopened" if live_open else f"> {SHIPPED} SHIPPED" + backlog(repo, f"## 71. Moving thing\n\n{live}\n\nbody\n") + unmerged_branch(repo, "seat") + write_claim(repo, "71", tmp_path / "gone", "seat") + r = rows(repo)["71"] + if live_open: + assert r["verdict"] == "BLOCKING", r + assert r["banner"] == "OPEN/prioritized", r + assert r["item"] == "docs/BACKLOG.md", r + assert "every copy is read" in r["why"], r + else: + assert r["verdict"] == "SUPERSEDED", r + assert "docs/BACKLOG.md" in r["item"] and "archive" in r["item"], r + + +def test_an_item_twice_in_one_file_is_held_if_either_copy_is_open( + repo: Path, tmp_path: Path +) -> None: + """MUST TRIP (item 2). The same rule inside one file: the second heading's OPEN copy holds.""" + backlog( + repo, + f"## 72. Twice\n\n> {SHIPPED} SHIPPED\n\nbody\n\n## 72. Twice\n\n> {IN_PROGRESS} open\n\nbody\n", + ) + unmerged_branch(repo, "seat") + write_claim(repo, "72", tmp_path / "gone", "seat") + assert verdicts(repo)["72"] == "BLOCKING" + + +@pytest.mark.parametrize( + "lead", + [ + # MUST TRIP: an unknown symbol on a banner-shaped line beside a CLOSED status. + f"> {UNKNOWN} a status added later\n> {SHIPPED} SHIPPED", + # MUST TRIP: an unknown symbol also blocks a landing phrase, for item 1's reason. + f"> {UNKNOWN} a status added later\n> **DO NOT REBUILD.**", + ], +) +def test_an_unknown_status_glyph_holds_the_item(repo: Path, tmp_path: Path, lead: str) -> None: + """Item 3: owed_ledger_acts.py never reads a row CLOSED when a banner-shaped line opens with a + symbol it does not know, since a status the vault adds later may be an open one.""" + backlog(repo, f"## 73. Unknown\n\n{lead}\n\nbody\n") + unmerged_branch(repo, "seat") + write_claim(repo, "73", tmp_path / "gone", "seat") + r = rows(repo)["73"] + assert r["verdict"] == "BLOCKING", r + assert r["banner"] == "UNKNOWN-STATUS/U+1F7E5", r + + +@pytest.mark.parametrize( + "lead", + [ + # A known decoration glyph is not a status, so the CLOSED line still decides. + f"> {DECORATION} a note\n> {SHIPPED} SHIPPED", + # A variation selector after the status glyph is part of the status. + f"> {SHIPPED}\N{VARIATION SELECTOR-16} SHIPPED", + ], +) +def test_controls_that_still_supersede(repo: Path, tmp_path: Path, lead: str) -> None: + """THE CONTROLS for items 3 and 4: neither guard holds an item the vault's grammar reads CLOSED.""" + backlog(repo, f"## 74. Closed\n\n{lead}\n\nbody\n") + unmerged_branch(repo, "seat") + write_claim(repo, "74", tmp_path / "gone", "seat") + assert verdicts(repo)["74"] == "SUPERSEDED" + + +@pytest.mark.parametrize( + "lead,state", + [ + # MUST TRIP: `\s` after the glyph matched the newline, so a lone glyph read as a status. + (f"> {SHIPPED}\n> landed, maybe", "NO-BANNER"), + # A lone OPEN glyph still holds: the guard cuts one way, so this is no loosening. + (f"> {IN_PROGRESS}\n> {SHIPPED} SHIPPED", "OPEN/in progress"), + ], +) +def test_a_status_glyph_alone_on_its_line_is_not_a_closed_status( + repo: Path, tmp_path: Path, lead: str, state: str +) -> None: + """Item 4: a status is `> `, the glyph and a space ON ONE LINE, as owed_ledger_acts.py reads it.""" + backlog(repo, f"## 75. Lone glyph\n\n{lead}\n\nbody\n") + unmerged_branch(repo, "seat") + write_claim(repo, "75", tmp_path / "gone", "seat") + r = rows(repo)["75"] + assert r["verdict"] == "BLOCKING", r + assert r["banner"] == state, r + + +def test_json_reference_is_the_ledgers_and_the_engine_ref_is_named_apart( + repo: Path, vault: Path, tmp_path: Path +) -> None: + """MUST TRIP (item 6). The top-level `reference` is what the verdicts were read against. With an + engine clone that has no origin/main, its ahead counts fall back to local main, while every + verdict still came from the ledger's origin/main; the report said "main".""" + backlog(repo, STUB) + git(repo, "remote", "remove", "origin") + write_claim(repo, "60", tmp_path / "gone", "seat") + proc = adjudicate(repo, "-Json", "-LedgerRepo", str(vault)) + assert proc.returncode == 0, proc.stderr + report = json.loads(proc.stdout) + assert report["reference"] == "origin/main", report + assert report["sources"]["engine"]["reference"] == "main", report["sources"] + assert report["sources"]["engine"]["sha"] == git(repo, "rev-parse", "main").strip() + + +@pytest.mark.parametrize("same_checkout", [True, False]) +def test_a_ledger_repo_that_is_this_repositorys_history_refuses( + repo: Path, tmp_path: Path, same_checkout: bool +) -> None: + """MUST TRIP (item 10). A clone of this repository from before the ledger moved carries a full, + stale ledger on its origin/main, and every other check passes on it. Sharing a root commit with + this repository refuses. The control is the vault fixture, which the tests above adjudicate.""" + backlog(repo, f"## 60. Shipped thing\n\n> {SHIPPED} SHIPPED\n\nbody\n") + write_claim(repo, "60", tmp_path / "gone", "seat") + ledger = repo + if not same_checkout: + ledger = tmp_path / "old-engine-clone" + subprocess.run(["git", "clone", "-q", str(repo), str(ledger)], check=True, timeout=TIMEOUT) + proc = adjudicate(repo, "-Json", "-LedgerRepo", str(ledger)) + combined = _flat(proc.stderr + proc.stdout) + assert proc.returncode != 0, combined + assert "shares root commit" in combined, combined + assert '"claims"' not in proc.stdout, combined + + +def test_a_stale_ledger_refuses_and_a_wider_bound_reads_it( + repo: Path, vault: Path, tmp_path: Path +) -> None: + """MUST TRIP (item 10). An item reopened since the checkout's last fetch still reads CLOSED there. + The pinned commit's own date bounds that: older than -LedgerMaxAgeHours refuses, naming the + fetch. The control is the same ledger under a bound wide enough to cover it.""" + backlog(repo, STUB) + write_claim(repo, "60", tmp_path / "gone", "seat") + (vault / "docs" / "BACKLOG.md").write_text( + f"# Backlog\n\n## 60. Shipped thing\n\n> {SHIPPED} SHIPPED\n\nbody\n", encoding="utf-8" + ) + git(vault, "add", "-A") + when = "2026-01-01T00:00:00Z" + subprocess.run( + ["git", "-C", str(vault), "commit", "-qm", "dated"], + check=True, + capture_output=True, + timeout=TIMEOUT, + env=dict(os.environ, GIT_COMMITTER_DATE=when, GIT_AUTHOR_DATE=when), + ) + git(vault, "push", "-q", "origin", "main") + + proc = adjudicate(repo, "-Json", "-LedgerRepo", str(vault)) + combined = _flat(proc.stderr + proc.stdout) + assert proc.returncode != 0, combined + assert "-LedgerMaxAgeHours 24" in combined, combined + assert "fetch origin" in combined, combined + assert '"claims"' not in proc.stdout, combined + + wide = verdicts(repo, "-LedgerRepo", str(vault), "-LedgerMaxAgeHours", "87600") + assert wide["60"] == "SUPERSEDED" + + +def test_under_ledger_repo_an_unreadable_engine_main_does_not_call_itself_the_namespace( + repo: Path, vault: Path, tmp_path: Path +) -> None: + """MUST TRIP (item 11). Under -LedgerRepo this repository's main decides the ahead counts and the + citations, not the namespace; a failure to read it says so. The control is the same failure + without -LedgerRepo, where this repository's main IS the namespace and keeps its wording.""" + backlog(repo, STUB) + git(repo, "remote", "remove", "origin") + git(repo, "branch", "-m", "main", "trunk") + write_claim(repo, "60", tmp_path / "gone", "seat") + + proc = adjudicate(repo, "-Json", "-LedgerRepo", str(vault)) + combined = _flat(proc.stderr + proc.stdout) + assert proc.returncode != 0, combined + assert "git rev-parse exited" in combined, combined + assert "namespace" not in combined, combined + assert "citations" in combined, combined + + proc = adjudicate(repo, "-Json") + combined = _flat(proc.stderr + proc.stdout) + assert proc.returncode != 0, combined + assert "against a namespace that was not read" in combined, combined + + +def test_the_namespace_is_indexed_once_not_scanned_per_key(repo: Path, tmp_path: Path) -> None: + """MUST TRIP (item 8). Each key ran a regex over the whole corpus and copied everything after the + match, about 2 s a key on a 34 MB ledger (measured 2026-11-29: 9.1 s for one key, 49.7 s for + twenty). The headings are now indexed in one pass. + + SELF-CALIBRATING, so a slow runner slows both halves alike: the cost of 24 more keys is compared + with a whole one-key run over the same ledger. Per-key scanning makes the extra keys cost several + one-key runs; the index leaves them one git log each, well under one run. Every key reads OPEN and + records no branch, so no per-key git work but the citation log runs on either path. + """ + body = "lorem ipsum dolor sit amet " * 160 + "\n" + items = "".join(f"## {i}. Item {i}\n\n> {IN_PROGRESS} open\n\n{body}\n" for i in range(1, 3001)) + backlog(repo, items) + + def timed(keys: range) -> float: + for p in claims_dir(repo).glob("*.json"): + p.unlink() + for k in keys: + write_claim(repo, str(k), tmp_path / "gone", "") + start = time.monotonic() + got = verdicts(repo) + elapsed = time.monotonic() - start + assert set(got) == {str(k) for k in keys} and set(got.values()) == {"BLOCKING"}, got + return elapsed + + one = timed(range(3000, 3001)) + many = timed(range(2976, 3001)) + assert many - one < 2 * one, f"24 more keys cost {many - one:.1f}s against {one:.1f}s for one" + + +def _ps_codepoints(line_marker: str) -> set[str]: + """The code points written on the one script line holding ``line_marker``.""" + text = ADJUDICATE.read_text(encoding="utf-8") + lines = [ln for ln in text.splitlines() if line_marker in ln] + assert len(lines) == 1, (line_marker, lines) + return {chr(int(h, 16)) for h in re.findall(r"0x([0-9A-Fa-f]+)", lines[0])} + + +def test_the_status_grammar_is_owed_ledger_acts_own() -> None: + """Item 9: the vault grammar is restated here and in owed_ledger_acts.py. A PowerShell script + cannot share the Python parser without depending on an interpreter, so the copies are held equal + instead: a glyph or decoration added to one and not the other fails here.""" + spec = importlib.util.spec_from_file_location( + "owed_ledger_acts_for_adjudicate", ROOT / "scripts" / "coord" / "owed_ledger_acts.py" + ) + assert spec is not None and spec.loader is not None + mod = importlib.util.module_from_spec(spec) + sys.modules[spec.name] = mod + spec.loader.exec_module(mod) + assert _ps_codepoints("'shipped')") == set(mod._CLOSED_GLYPHS) + assert _ps_codepoints("'prioritized')") == set(mod._OPEN_GLYPHS) + assert _ps_codepoints("foreach ($cp in @(") == set(mod._DECORATION) From 16ee3d8801764260115249633973b6f8dbdb3eca Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Sun, 29 Nov 2026 10:46:59 -0600 Subject: [PATCH 02/14] docs/WORKTREES.md: a stale vault checkout errs both ways; when a landing phrase counts BACKLOG #5480 item 5: the "fetch first" sentence named only the harmless side of a stale ledger. A stale checkout also shows a since-reopened row CLOSED, which prints a release line for open work. The section now says so and names the -LedgerMaxAgeHours and shared-root refusals (item 10), and states items 1 to 3's supersession rules. Verified-by: none --- docs/WORKTREES.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/WORKTREES.md b/docs/WORKTREES.md index a75a32249b..fdaf4703d8 100644 --- a/docs/WORKTREES.md +++ b/docs/WORKTREES.md @@ -1097,8 +1097,16 @@ a whole seat at once, and a long-lived seat branch never clears. is in the vault (`CLAUDE.md` section 5). Without `-LedgerRepo` it reads this repository's stub, which holds no item, and refuses. With it, every banner is read from that checkout's `origin/main`, pinned to one SHA that the report prints beside the checkout's path, and a checkout with no `origin/main` refuses rather than read its local `main`. The -claims, branches and citations stay this repository's. Fetch the vault checkout first: a banner it -has not fetched reads as absent. +claims, branches and citations stay this repository's. + +**Fetch the vault checkout first. A stale one errs both ways.** A banner it has not fetched reads as +absent, which holds a claim that is safe to release. An item reopened since its last fetch still +reads CLOSED there, which prints a release line for open work. So the run refuses when the pinned +commit is older than `-LedgerMaxAgeHours` (24 by default); the refusal names the fetch, and a larger +value is for a vault whose `origin/main` truly has not moved. It also refuses a `-LedgerRepo` that +shares a root commit with this repository, because a clone of it from before 2026-09-13 carries a +full ledger that nothing keeps current. That proves only that the checkout is not this repository. +(BACKLOG #5480, items 5 and 10.) ### The criterion is the project's own, and it is not "is the work done" @@ -1110,6 +1118,11 @@ question is not whether the work finished but whether something durable has repl > **SUPERSEDED** = the item exists in the backlog namespace on `origin/main` **and** its banner there > already protects it — a CLOSED status glyph, or a do-not-rebuild banner naming the landing. +A do-not-rebuild banner counts only where no status line reads OPEN, because an open item's banner +carries the same capitals as scope. A banner line opening with a symbol the tool does not know holds +the item too. An item whose number stands more than once, in both ledger files or twice in one, +supersedes only when every copy protects it (BACKLOG #5480, items 1 to 3). + Nothing else is ever proposed for release. Not age, not quiet, not a note saying the work is done. The tool has **no `-Apply`** and will not grow one: `claim.ps1` owns the `.history` ledger and writes the record before removing the file (BACKLOG #1068), and a second writer would be a second definition From c43dbb47166b5744e95a6a7e01a693838b96169e Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Sun, 29 Nov 2026 11:21:24 -0600 Subject: [PATCH 03/14] claim-adjudicate.ps1: review round one, hold on every shape owed_ledger_acts.py reads open BACKLOG #5480. Code-review round one on d3ed0883be9 measured shapes that still released; each now holds, with a test failing on d3ed0883be9: - an OPEN glyph anywhere in the banner blocks a landing phrase; - an indented OPEN status line holds, and a CLOSED line past owed_ledger_acts.py's block boundary is not counted; - lines split as Python's splitlines() does, and only a space or tab follows a status glyph (U+2028 case); - `## 079.` and `## 79.` are copies of one item; - a shallow engine clone is refused by its package at the pinned commit; - a tip dated over an hour in the future refuses; a FETCH_HEAD naming the pinned commit as main counts as recent, so a quiet vault needs a fetch, not a wider bound; the stale refusal names the vault remedy. Glyph tables are ordered maps; the parity test's scope is stated. Verified-by: tests --- docs/WORKTREES.md | 13 +-- scripts/coord/claim-adjudicate.ps1 | 129 ++++++++++++++++++-------- tests/test_coord_claim_adjudicate.py | 131 ++++++++++++++++++++++++++- 3 files changed, 225 insertions(+), 48 deletions(-) diff --git a/docs/WORKTREES.md b/docs/WORKTREES.md index fdaf4703d8..2f795c31d8 100644 --- a/docs/WORKTREES.md +++ b/docs/WORKTREES.md @@ -1101,10 +1101,11 @@ claims, branches and citations stay this repository's. **Fetch the vault checkout first. A stale one errs both ways.** A banner it has not fetched reads as absent, which holds a claim that is safe to release. An item reopened since its last fetch still -reads CLOSED there, which prints a release line for open work. So the run refuses when the pinned -commit is older than `-LedgerMaxAgeHours` (24 by default); the refusal names the fetch, and a larger -value is for a vault whose `origin/main` truly has not moved. It also refuses a `-LedgerRepo` that -shares a root commit with this repository, because a clone of it from before 2026-09-13 carries a +reads CLOSED there, which prints a release line for open work. So the run refuses when both the +pinned commit and that checkout's own fetch of it are older than `-LedgerMaxAgeHours` (24 by +default). A fetch counts even where nobody has merged to the vault since, so the remedy is the fetch +the refusal names, not a larger value. It also refuses a `-LedgerRepo` that shares a root commit +with this repository or carries its package, because a clone of it from before 2026-09-13 carries a full ledger that nothing keeps current. That proves only that the checkout is not this repository. (BACKLOG #5480, items 5 and 10.) @@ -1118,8 +1119,8 @@ question is not whether the work finished but whether something durable has repl > **SUPERSEDED** = the item exists in the backlog namespace on `origin/main` **and** its banner there > already protects it — a CLOSED status glyph, or a do-not-rebuild banner naming the landing. -A do-not-rebuild banner counts only where no status line reads OPEN, because an open item's banner -carries the same capitals as scope. A banner line opening with a symbol the tool does not know holds +A do-not-rebuild banner counts only where no status line reads OPEN and no OPEN glyph stands +anywhere in the banner, because an open item's banner carries the same capitals as scope. A banner line opening with a symbol the tool does not know holds the item too. An item whose number stands more than once, in both ledger files or twice in one, supersedes only when every copy protects it (BACKLOG #5480, items 1 to 3). diff --git a/scripts/coord/claim-adjudicate.ps1 b/scripts/coord/claim-adjudicate.ps1 index fa2b5f50c3..a67ab3c89e 100644 --- a/scripts/coord/claim-adjudicate.ps1 +++ b/scripts/coord/claim-adjudicate.ps1 @@ -73,9 +73,10 @@ A STALE LEDGER (BACKLOG #5480 items 5 and 10). A ledger checkout that has not fetched errs BOTH ways: a banner it has not fetched reads as absent, which holds a claim that is safe to release, and an item reopened since its last fetch still reads CLOSED there, which prints a release line - for open work. So the run refuses when the pinned ledger commit is older than - -LedgerMaxAgeHours (24 by default), and refuses a -LedgerRepo that shares a root commit with this - repository, since a clone of it from before 2026-09-13 still carries a full, stale ledger. + for open work. So the run refuses when both the pinned ledger commit and the checkout's own + fetch of it, read from FETCH_HEAD, are older than -LedgerMaxAgeHours (24 by default). It also + refuses a -LedgerRepo that shares a root commit with this repository or carries its package, + since a clone of it from before 2026-09-13 still carries a full, stale ledger. WHY THERE IS NO -Apply. `claim.ps1` owns the .history ledger: it writes the record BEFORE removing the file and refuses the release if the record cannot be written (BACKLOG #1068). A @@ -267,41 +268,65 @@ $ledgerRef = $ledgerPinned.Ref; $ledgerSha = $ledgerPinned.Sha # --------------------------------------------------------------------------------------------- # IS IT THE LEDGER, AND IS IT RECENT (BACKLOG #5480 item 10). # -# NOT THIS REPOSITORY'S OWN HISTORY. A clone of this repository that last fetched before 2026-09-13 -# still carries the full ledger on its origin/main, and it passes every check below it: the item -# headings are real, only stale. So a -LedgerRepo that shares a root commit with this repository -# refuses. This proves the checkout is not this repository; it does not prove which repository it -# is, and the item-heading admission below is what refuses one that holds no ledger at all. +# NOT THIS REPOSITORY. A clone of this repository that last fetched before 2026-09-13 still carries +# the full ledger on its origin/main, with real item headings, only stale. The age bound below +# refuses it at its default; this check is what refuses it once that bound has been widened. Two +# signs, because neither alone holds: a shared root commit, which a SHALLOW clone hides (its roots +# are its shallow boundary, and vault checkouts are shallow in use), and this repository's own +# package at the pinned commit, which every engine commit carries. It proves the checkout is not +# this repository; it does not prove which repository it is, and the item-heading admission below +# is what refuses one that holds no ledger at all. # # NOT STALE. A ledger checkout that has not fetched can show a since-reopened item CLOSED, and that -# prints a release line for open work -- the costly direction. Whether origin/main has moved upstream -# since the last fetch cannot be known without a fetch, which this tool does not do, so the bound is -# on the pinned commit's own committer date: older than -LedgerMaxAgeHours refuses. It applies with -# or without -LedgerRepo, since whichever repository is read is the one whose banners decide. +# prints a release line for open work -- the costly direction. This tool does not fetch, so the +# bound is on two readings, either of which may show the checkout recent: the pinned commit's own +# committer date, and the checkout's FETCH_HEAD where it names this same commit as `main`, so a +# fetch into a vault nobody merged to since still counts. Older than -LedgerMaxAgeHours on both +# refuses, and so does a commit dated more than an hour in the future with no such fetch, since its +# age cannot be read. It applies with or without -LedgerRepo: whichever repository is read is the +# one whose banners decide. # --------------------------------------------------------------------------------------------- if ($LedgerRepo) { $engineRoots = @(Invoke-NamespaceGit $repo @('rev-list', '--max-parents=0', $mainSha) "the root commits of $mainRef in $repo" "not read" $engineConsequence) $ledgerRoots = @(Invoke-NamespaceGit $ledgerRoot @('rev-list', '--max-parents=0', $ledgerSha) "the root commits of $ledgerRef ($ledgerSha) in $ledgerRoot" "not read") $shared = @($ledgerRoots | Where-Object { $_ -and ($engineRoots -ccontains $_) }) - if ($shared.Count) { - throw ("-LedgerRepo $ledgerRoot shares root commit $($shared[0]) with this repository, so it is a " + - "checkout of this repository and not of the ledger's. Its backlog files are this repository's " + - "stub, or a ledger copy from before 2026-09-13 that nothing keeps current. Refusing rather than " + - "adjudicate against it.$remedy") + $package = @(Invoke-NamespaceGit $ledgerRoot @('ls-tree', '--name-only', $ledgerSha, '--', 'messagefoundry/__init__.py') "the tree of $ledgerRef ($ledgerSha) in $ledgerRoot" "not read") + $sign = if ($shared.Count) { "shares root commit $($shared[0]) with this repository" } + elseif (@($package | Where-Object { $_ }).Count) { "carries this repository's package, messagefoundry/__init__.py, at $ledgerSha" } + else { "" } + if ($sign) { + throw ("-LedgerRepo $ledgerRoot $sign, so it is a checkout of this repository and not of the " + + "ledger's. Its backlog files are this repository's stub, or a ledger copy from before " + + "2026-09-13 that nothing keeps current. Refusing rather than adjudicate against it.$remedy") } } $ledgerStamp = (@(Invoke-NamespaceGit $ledgerRoot @('log', '-1', '--format=%ct', $ledgerSha) "the commit date of $ledgerRef ($ledgerSha) in $ledgerRoot" "not read") -join '').Trim() if ($ledgerStamp -notmatch '^\d+$') { throw "could not read the commit date of $ledgerRef ($ledgerSha) in ${ledgerRoot}: git printed '$ledgerStamp'. Refusing rather than adjudicate against a ledger of unknown age." } -$ledgerAgeHours = ([DateTimeOffset]::UtcNow.ToUnixTimeSeconds() - [long]$ledgerStamp) / 3600.0 -if ($ledgerAgeHours -gt $LedgerMaxAgeHours) { +$nowSec = [DateTimeOffset]::UtcNow.ToUnixTimeSeconds() +$commitAgeHours = ($nowSec - [long]$ledgerStamp) / 3600.0 +# FETCH_HEAD is per worktree, so this reads the fetch made in THIS checkout. A line counts only where +# it names the pinned commit as some remote's `main`: a fetch of another branch says nothing of main. +$fetchAgeHours = $null +$fetchHead = (@(Invoke-NamespaceGit $ledgerRoot @('rev-parse', '--path-format=absolute', '--git-path', 'FETCH_HEAD') "the FETCH_HEAD path of $ledgerRoot" "not read") -join '').Trim() +if ($fetchHead -and (Test-Path -LiteralPath $fetchHead -PathType Leaf)) { + $named = @(Get-Content -LiteralPath $fetchHead -Encoding utf8 | Where-Object { $_ -cmatch ('^' + [regex]::Escape($ledgerSha) + "\t[^\t]*\tbranch 'main' of ") }) + if ($named.Count) { + $fetchAgeHours = ($nowSec - [DateTimeOffset]::new((Get-Item -LiteralPath $fetchHead).LastWriteTimeUtc).ToUnixTimeSeconds()) / 3600.0 + } +} +$recent = { param($age) ($null -ne $age) -and ($age -ge -1) -and ($age -le $LedgerMaxAgeHours) } +if (-not ((& $recent $commitAgeHours) -or (& $recent $fetchAgeHours))) { $when = [DateTimeOffset]::FromUnixTimeSeconds([long]$ledgerStamp).UtcDateTime.ToString('yyyy-MM-ddTHH:mm:ssZ') - throw ("the ledger at $ledgerRef ($ledgerSha) in $ledgerRoot was committed $when, " + - "$([Math]::Floor($ledgerAgeHours)) hours ago, past -LedgerMaxAgeHours $LedgerMaxAgeHours. A stale " + - "ledger can show a since-reopened item CLOSED and print a release line for open work. Run " + - "'git -C `"$ledgerRoot`" fetch origin' and adjudicate again; if its origin/main truly has not moved " + - "since then, pass a larger -LedgerMaxAgeHours.") + $age = if ($commitAgeHours -lt -1) { "dated $([Math]::Floor(-$commitAgeHours)) hours in the FUTURE, so its age cannot be read" } + else { "$([Math]::Floor($commitAgeHours)) hours ago, past -LedgerMaxAgeHours $LedgerMaxAgeHours" } + $fetched = if ($null -eq $fetchAgeHours) { "and this checkout's FETCH_HEAD does not name it as main" } + else { "and this checkout last fetched it $([Math]::Floor($fetchAgeHours)) hours ago" } + throw ("the ledger at $ledgerRef ($ledgerSha) in $ledgerRoot was committed $when, $age, $fetched. " + + "A stale ledger can show a since-reopened item CLOSED and print a release line for open work. " + + "Run 'git -C `"$ledgerRoot`" fetch origin' and adjudicate again: a fetch in that checkout counts " + + "even where nobody has merged since, so a larger -LedgerMaxAgeHours should not be needed.$remedy") } # --------------------------------------------------------------------------------------------- @@ -366,6 +391,14 @@ $corpusFiles = @($corpus.Keys | Sort-Object) # ONE SCAN PER FILE: every level-2 heading, with the item number captured where the heading is an # item's. `^##\s` then `\s*\d+\.\s` is the per-key pattern `^##\s+N\.\s` split in two. A # `Regex.Match(text, startat)` per heading was tried first and rescanned the text from each start. +# +# KEYED BY THE NUMBER, NOT ITS SPELLING. owed_ledger_acts.py keys a row by int(), so `## 079.` and +# `## 79.` are copies of one row there, and the every-copy rule must see both here too. Leading zeros +# are dropped from the heading and from the claim's key alike. +function ConvertTo-ItemNumber([string]$Digits) { + $t = $Digits.TrimStart('0') + if ($t) { $t } else { '0' } +} $itemIndex = [System.Collections.Generic.Dictionary[string, System.Collections.Generic.List[object]]]::new([StringComparer]::Ordinal) $heading = [regex]'(?m)^##\s(?:\s*(?\d+)\.\s)?' foreach ($f in $corpusFiles) { @@ -381,7 +414,7 @@ foreach ($f in $corpusFiles) { $j = $starts.BinarySearch($m.Index + $m.Length) if ($j -lt 0) { $j = -bnot $j } $end = if ($j -lt $starts.Count) { $starts[$j] } else { $text.Length } - $n = $m.Groups['n'].Value + $n = ConvertTo-ItemNumber $m.Groups['n'].Value if (-not $itemIndex.ContainsKey($n)) { $itemIndex[$n] = [System.Collections.Generic.List[object]]::new() } $itemIndex[$n].Add([pscustomobject]@{ File = $f; Start = $m.Index; Length = $end - $m.Index }) } @@ -395,11 +428,12 @@ foreach ($f in $corpusFiles) { $GLYPH_NAME = [System.Collections.Generic.Dictionary[string, string]]::new([StringComparer]::Ordinal) $CLOSED_GLYPH = [System.Collections.Generic.List[string]]::new() $OPEN_GLYPH = [System.Collections.Generic.List[string]]::new() -foreach ($e in @(@(0x2705, 'shipped'), @(0x26D4, 'declined'), @(0x1FAA6, 'retired'))) { - $g = [char]::ConvertFromUtf32($e[0]); $CLOSED_GLYPH.Add($g); $GLYPH_NAME[$g] = $e[1] +# Ordered tables rather than nested arrays, which PowerShell flattens when only one pair is left. +foreach ($e in ([ordered]@{ 0x2705 = 'shipped'; 0x26D4 = 'declined'; 0x1FAA6 = 'retired' }).GetEnumerator()) { + $g = [char]::ConvertFromUtf32($e.Key); $CLOSED_GLYPH.Add($g); $GLYPH_NAME[$g] = $e.Value } -foreach ($e in @(@(0x1F522, 'prioritized'), @(0x1F6A7, 'in progress'))) { - $g = [char]::ConvertFromUtf32($e[0]); $OPEN_GLYPH.Add($g); $GLYPH_NAME[$g] = $e[1] +foreach ($e in ([ordered]@{ 0x1F522 = 'prioritized'; 0x1F6A7 = 'in progress' }).GetEnumerator()) { + $g = [char]::ConvertFromUtf32($e.Key); $OPEN_GLYPH.Add($g); $GLYPH_NAME[$g] = $e.Value } # The symbols that open blockquote lines in the vault ledger as DECORATION, not status: # owed_ledger_acts.py's `_DECORATION`, measured there over both ledger files. @@ -414,12 +448,15 @@ foreach ($cp in @(0x26A0, 0x1F6E0, 0x1F4CC, 0x1F4D0, 0x2B06, 0x1F50E, 0x1F7E2, 0 # items that are open (measured 2026-11-19: "not started. OPEN ON EVERY GATE # MEASURED"). Matching it anywhere read those items CLOSED and printed a release line for open work. # -# THE SPACES ARE HORIZONTAL (item 4). `\s` matches a newline too, so a CLOSED glyph alone on its line -# read as a status off the line below it; owed_ledger_acts.py matches one line at a time and does -# not. This reads one line at a time as well, and spells the space as whitespace other than a line -# break. It cuts one way: an OPEN glyph opening a line holds the item whatever follows it, since an -# open status misread costs a stale claim and a closed one misread costs a duplicate build. -$BANNER_SHAPE = [regex]'^>[^\S\r\n](?[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\x00-\x7F])\uFE0F?(?[^\S\r\n])?' +# THE SPACES ARE A SPACE OR A TAB, AND THE LINES ARE PYTHON'S (item 4). `\s` matches a newline too, +# so a CLOSED glyph alone on its line read as a status off the line below it; owed_ledger_acts.py +# matches one line at a time and does not. This reads one line at a time as well, split where +# Python's splitlines() splits, U+2028 and its kin included, and takes only a space or a tab as the +# space. It cuts one way: an OPEN glyph opening a line holds the item whatever follows it, indented +# or not, since an open status misread costs a stale claim and a closed one misread costs a +# duplicate build. +$BANNER_SHAPE = [regex]'^(?[ \t]*)>[ \t](?[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\x00-\x7F])\uFE0F?(?[ \t])?' +$LINE_BREAK = [regex]'\r\n|[\n\r\v\f\x1c\x1d\x1e\x85\u2028\u2029]' # A do-not-rebuild banner is prose, so it is matched on the few phrasings that assert the LANDING # ITSELF. A bare "do not build" is deliberately absent: a note reading "DO NOT BUILD half B" is @@ -439,7 +476,7 @@ function Get-ItemBlock([string]$ItemKey) { # must not be pattern-matched into this one. if ($ItemKey -notmatch '^\d+$') { return @() } $hits = $null - if (-not $itemIndex.TryGetValue($ItemKey, [ref]$hits)) { return @() } + if (-not $itemIndex.TryGetValue((ConvertTo-ItemNumber $ItemKey), [ref]$hits)) { return @() } @(foreach ($h in $hits) { [pscustomobject]@{ File = $h.File; Text = $corpus[$h.File].Substring($h.Start, $h.Length) } }) @@ -478,17 +515,30 @@ function Get-BannerState([string]$Block) { # reads a banner-shaped line opening with an unknown symbol as a status it cannot judge, and # never reads that row CLOSED; a status the vault adds later is far likelier an open one than not. # Here it blocks the landing phrase as well, for item 1's reason. + # + # WHERE owed_ledger_acts.py STOPS, A CLOSED LINE STOPS COUNTING. Its banner block is the blank + # lines and the lines starting `>` under the heading, and the first other line ends it -- an + # indented ` >` line included, which Get-LeadingQuote keeps. A CLOSED status past that point is + # one the vault's own reading never sees, so it is not counted. OPEN and unknown lines count + # wherever they stand, indented or past that point: holding is the cheap direction. + # + # AN OPEN GLYPH ANYWHERE IN THE RUN BLOCKS THE LANDING PHRASE. The phrase is plain text, not the + # status grammar, so it gets no grammar's benefit of the doubt: `> **PARTIAL** + # half B open. Half A HAS LANDED ON origin/main; DO NOT REBUILD it.` opens with no status line and + # is still open work. $lead = Get-LeadingQuote $Block $closed = [System.Collections.Generic.List[string]]::new() $open = [System.Collections.Generic.List[string]]::new() $unknown = [System.Collections.Generic.List[string]]::new() - foreach ($l in ($lead -split "`n")) { + $pastVault = $false + foreach ($l in $LINE_BREAK.Split($lead)) { + if ($l.Trim() -and -not $l.StartsWith('>', [StringComparison]::Ordinal)) { $pastVault = $true } $m = $BANNER_SHAPE.Match($l) if (-not $m.Success) { continue } $g = $m.Groups['g'].Value if ($OPEN_GLYPH.Contains($g)) { $open.Add($g); continue } if ($CLOSED_GLYPH.Contains($g)) { - if ($m.Groups['sp'].Success) { $closed.Add($g) } + if ($m.Groups['sp'].Success -and -not $m.Groups['ind'].Length -and -not $pastVault) { $closed.Add($g) } continue } if ($DECORATION.Contains($g)) { continue } @@ -497,6 +547,7 @@ function Get-BannerState([string]$Block) { $unknown.Add(('U+{0:X4}' -f $rune.Value)) } } + $openAnywhere = @($OPEN_GLYPH | Where-Object { $lead.Contains($_, [StringComparison]::Ordinal) }) if (-not $open.Count -and -not $unknown.Count) { # CLOSED only where a closed status line stands and no open one does -- the vault's own verdict. foreach ($g in $CLOSED_GLYPH) { @@ -505,6 +556,7 @@ function Get-BannerState([string]$Block) { } } foreach ($p in $LANDED_BANNER) { + if ($openAnywhere.Count) { break } if ([regex]::IsMatch($lead, $p)) { # Quote the banner's own sentence back, so the verdict carries the observation it # rests on rather than a label the reader must take on trust. @@ -516,6 +568,7 @@ function Get-BannerState([string]$Block) { } $state = if ($open.Count) { "OPEN/" + $GLYPH_NAME[$open[0]] } elseif ($unknown.Count) { "UNKNOWN-STATUS/" + $unknown[0] } + elseif ($openAnywhere.Count) { "OPEN-IN-PROSE/" + $GLYPH_NAME[$openAnywhere[0]] } else { "NO-BANNER" } [pscustomobject]@{ State = $state; Why = ""; Protects = $false } } diff --git a/tests/test_coord_claim_adjudicate.py b/tests/test_coord_claim_adjudicate.py index a2dd66db20..4a87f608da 100644 --- a/tests/test_coord_claim_adjudicate.py +++ b/tests/test_coord_claim_adjudicate.py @@ -1301,6 +1301,62 @@ def test_a_stale_ledger_refuses_and_a_wider_bound_reads_it( wide = verdicts(repo, "-LedgerRepo", str(vault), "-LedgerMaxAgeHours", "87600") assert wide["60"] == "SUPERSEDED" + # A fetch into this checkout that names the same commit as main counts, though nobody merged + # since: a quiet vault needs the fetch the refusal names, not a wider bound (review round one). + git(vault, "fetch", "-q", "origin") + assert verdicts(repo, "-LedgerRepo", str(vault))["60"] == "SUPERSEDED" + + +def _dated_commit(repo: Path, rel: str, text: str, when: str) -> None: + (repo / rel).parent.mkdir(parents=True, exist_ok=True) + (repo / rel).write_text(text, encoding="utf-8") + git(repo, "add", "-A") + subprocess.run( + ["git", "-C", str(repo), "commit", "-qm", "dated"], + check=True, + capture_output=True, + timeout=TIMEOUT, + env=dict(os.environ, GIT_COMMITTER_DATE=when, GIT_AUTHOR_DATE=when), + ) + git(repo, "push", "-q", "origin", "main") + + +def test_a_ledger_dated_in_the_future_refuses(repo: Path, vault: Path, tmp_path: Path) -> None: + """MUST TRIP on d3ed0883be9 (review round one). A tip dated ahead of the clock has a negative + age, which passed every bound until that date arrived, however long ago it was fetched.""" + backlog(repo, STUB) + write_claim(repo, "60", tmp_path / "gone", "seat") + _dated_commit( + vault, + "docs/BACKLOG.md", + f"# Backlog\n\n## 60. Shipped thing\n\n> {SHIPPED} SHIPPED\n\nbody\n", + "2099-01-01T00:00:00Z", + ) + proc = adjudicate(repo, "-Json", "-LedgerRepo", str(vault)) + combined = _flat(proc.stderr + proc.stdout) + assert proc.returncode != 0, combined + assert "in the FUTURE" in combined, combined + + +def test_a_stale_ledger_without_ledger_repo_names_the_vault_remedy( + repo: Path, tmp_path: Path +) -> None: + """MUST TRIP on d3ed0883be9 (review round one). Without -LedgerRepo this repository's stale + ledger refuses first, and fetching it would only reach the stub refusal: the remedy is the + vault, named the way every other refusal in that section names it.""" + write_claim(repo, "60", tmp_path / "gone", "seat") + _dated_commit( + repo, + "docs/BACKLOG.md", + f"# Backlog\n\n## 60. Shipped thing\n\n> {SHIPPED} SHIPPED\n\nbody\n", + "2026-01-01T00:00:00Z", + ) + proc = adjudicate(repo, "-Json") + combined = _flat(proc.stderr + proc.stdout) + assert proc.returncode != 0, combined + assert "-LedgerMaxAgeHours 24" in combined, combined + assert "pass -LedgerRepo" in combined, combined + def test_under_ledger_repo_an_unreadable_engine_main_does_not_call_itself_the_namespace( repo: Path, vault: Path, tmp_path: Path @@ -1326,6 +1382,71 @@ def test_under_ledger_repo_an_unreadable_engine_main_does_not_call_itself_the_na assert "against a namespace that was not read" in combined, combined +LSEP = "\N{LINE SEPARATOR}" + + +@pytest.mark.parametrize( + "lead", + [ + # An OPEN glyph mid-line, with no status line at all, still blocks the landing phrase. + f"> **PARTIAL** {IN_PROGRESS} half B open. Half A HAS LANDED ON origin/main; DO NOT REBUILD it.", + # An indented OPEN status line holds, though the status grammar reads column 0. + f" > {IN_PROGRESS} open, indented\n> {SHIPPED} SHIPPED", + # An indented quote line ends owed_ledger_acts.py's banner block: a CLOSED line after it is + # one the vault's own reading never sees. + f" > an indented note\n> {SHIPPED} SHIPPED", + # Python's splitlines() breaks at U+2028: no space follows the glyph on that line. + f"> {SHIPPED}{LSEP}maybe", + # ... and the OPEN status after U+2028 is a line of its own there. + f"> {SHIPPED} SHIPPED{LSEP}> {IN_PROGRESS} reopened", + ], +) +def test_round_one_review_shapes_hold(repo: Path, tmp_path: Path, lead: str) -> None: + """MUST TRIP on this branch's first head d3ed0883be9, where each read SUPERSEDED: the code-review + round's measured shapes. Each differs from owed_ledger_acts.py's reading or lets a landing phrase + release open work; the controls that still supersede are test_controls_that_still_supersede.""" + backlog(repo, f"## 76. Shape\n\n{lead}\n\nbody\n") + unmerged_branch(repo, "seat") + write_claim(repo, "76", tmp_path / "gone", "seat") + r = rows(repo)["76"] + assert r["verdict"] == "BLOCKING", r + + +def test_a_zero_padded_heading_is_a_copy_of_the_same_item(repo: Path, tmp_path: Path) -> None: + """MUST TRIP on d3ed0883be9 (item 2, review round one). owed_ledger_acts.py keys a row by int(), + so `## 079.` and `## 79.` are one row, OPEN if either copy is.""" + backlog( + repo, + f"## 79. Thing\n\n> {SHIPPED} SHIPPED\n\nbody\n\n## 079. Thing\n\n> {IN_PROGRESS} open\n\nb\n", + ) + unmerged_branch(repo, "seat") + write_claim(repo, "79", tmp_path / "gone", "seat") + assert verdicts(repo)["79"] == "BLOCKING" + + +def test_a_shallow_clone_of_this_repository_is_refused_by_its_package( + repo: Path, tmp_path: Path +) -> None: + """MUST TRIP on d3ed0883be9 (item 10, review round one). A shallow clone's roots are its shallow + boundary, so the shared-root sign misses it; this repository's package at the pinned commit does + not.""" + (repo / "messagefoundry").mkdir() + (repo / "messagefoundry" / "__init__.py").write_text("", encoding="utf-8") + backlog(repo, f"## 60. Shipped thing\n\n> {SHIPPED} SHIPPED\n\nbody\n") + write_claim(repo, "60", tmp_path / "gone", "seat") + shallow = tmp_path / "shallow-engine-clone" + subprocess.run( + ["git", "clone", "-q", "--depth", "1", repo.resolve().as_uri(), str(shallow)], + check=True, + timeout=TIMEOUT, + ) + assert git(shallow, "rev-parse", "--is-shallow-repository").strip() == "true" + proc = adjudicate(repo, "-Json", "-LedgerRepo", str(shallow)) + combined = _flat(proc.stderr + proc.stdout) + assert proc.returncode != 0, combined + assert "carries this repository's package" in combined, combined + + def test_the_namespace_is_indexed_once_not_scanned_per_key(repo: Path, tmp_path: Path) -> None: """MUST TRIP (item 8). Each key ran a regex over the whole corpus and copied everything after the match, about 2 s a key on a 34 MB ledger (measured 2026-11-29: 9.1 s for one key, 49.7 s for @@ -1366,8 +1487,10 @@ def _ps_codepoints(line_marker: str) -> set[str]: def test_the_status_grammar_is_owed_ledger_acts_own() -> None: """Item 9: the vault grammar is restated here and in owed_ledger_acts.py. A PowerShell script - cannot share the Python parser without depending on an interpreter, so the copies are held equal - instead: a glyph or decoration added to one and not the other fails here.""" + cannot share the Python parser without depending on an interpreter, so the GLYPH LISTS are held + equal instead: a status glyph or decoration added to one and not the other fails here. Only the + lists: the line, heading and block rules are restated by hand, and the shape tests above pin + them one case at a time, not against owed_ledger_acts.py.""" spec = importlib.util.spec_from_file_location( "owed_ledger_acts_for_adjudicate", ROOT / "scripts" / "coord" / "owed_ledger_acts.py" ) @@ -1375,6 +1498,6 @@ def test_the_status_grammar_is_owed_ledger_acts_own() -> None: mod = importlib.util.module_from_spec(spec) sys.modules[spec.name] = mod spec.loader.exec_module(mod) - assert _ps_codepoints("'shipped')") == set(mod._CLOSED_GLYPHS) - assert _ps_codepoints("'prioritized')") == set(mod._OPEN_GLYPHS) + assert _ps_codepoints("= 'shipped';") == set(mod._CLOSED_GLYPHS) + assert _ps_codepoints("= 'prioritized';") == set(mod._OPEN_GLYPHS) assert _ps_codepoints("foreach ($cp in @(") == set(mod._DECORATION) From 4400a96a9ebaa8ac6fe2ffd2ea45e457ba8d9d8a Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Sun, 29 Nov 2026 11:52:02 -0600 Subject: [PATCH 04/14] claim-adjudicate.ps1: review round two, one line set for every rule, origin-only fetch evidence BACKLOG #5480. Code-review round two on c43dbb47166: - the corpus is split once at load where Python's splitlines() splits, so the heading index, the banner run and the status lines read the lines owed_ledger_acts.py reads (U+2028 heading and status cases); - any whitespace before a status glyph counts again, as on origin/main (round one's space-or-tab had narrowed away an NBSP OPEN line); - a blank line is Python's blank, not PowerShell's culture compare, which read a control-character line as blank and released; - headings keyed by digit value (int() reads Arabic-Indic digits); - FETCH_HEAD counts only for main of origin's URL; the commit date is read with --no-show-signature; one scan per file admits and indexes; - `item` is always one path; the stale and landing rules are stated once (.NOTES, Get-BannerState), WORKTREES.md points at them; - the timing test takes the best of two runs a side. Proposed PR title: claim-adjudicate.ps1: close engine PR 3124's open findings on the ledger read (BACKLOG #5480) Proposed banner #5480: SHIPPED in b20037/claim-adjudicate-5480 -- the eleven items added from engine PR 3124: items 1-4 and 10 hold or refuse in the safe direction (open status or glyph blocks a landing phrase; every copy of a number judged; unknown glyph holds; line-at-a-time grammar on Python's lines; refuses an engine clone and a ledger neither committed nor fetched from origin within -LedgerMaxAgeHours), item 5 and 10 documented in docs/WORKTREES.md, item 6 JSON reference is the ledger's, item 7 standalone per-rule cases, item 8 one heading scan per file (34 MB: 20 extra keys 40.6 s before, 4.3 s after), item 9 a glyph-list parity test (sharing the Python parser declined: a pwsh script would then depend on an interpreter), item 11 engine-ref wording. Fail-before: 16 failed, 57 passed against origin/main 74910c69104 (script identical to ddf50248fae); round-one tests 11 failed on d3ed0883be9; round-two tests 6 failed on c43dbb47166 plus the control-line case. Verified-by: tests --- docs/WORKTREES.md | 17 ++-- scripts/coord/claim-adjudicate.ps1 | 114 +++++++++++++++------------ tests/test_coord_claim_adjudicate.py | 68 ++++++++++++++-- 3 files changed, 130 insertions(+), 69 deletions(-) diff --git a/docs/WORKTREES.md b/docs/WORKTREES.md index 2f795c31d8..a7579333f9 100644 --- a/docs/WORKTREES.md +++ b/docs/WORKTREES.md @@ -1101,13 +1101,9 @@ claims, branches and citations stay this repository's. **Fetch the vault checkout first. A stale one errs both ways.** A banner it has not fetched reads as absent, which holds a claim that is safe to release. An item reopened since its last fetch still -reads CLOSED there, which prints a release line for open work. So the run refuses when both the -pinned commit and that checkout's own fetch of it are older than `-LedgerMaxAgeHours` (24 by -default). A fetch counts even where nobody has merged to the vault since, so the remedy is the fetch -the refusal names, not a larger value. It also refuses a `-LedgerRepo` that shares a root commit -with this repository or carries its package, because a clone of it from before 2026-09-13 carries a -full ledger that nothing keeps current. That proves only that the checkout is not this repository. -(BACKLOG #5480, items 5 and 10.) +reads CLOSED there, which prints a release line for open work. So the run refuses a ledger it +cannot show is recent, and a `-LedgerRepo` that is a clone of this repository; the conditions are +in the script's header, *A STALE LEDGER*, and are not copied here (BACKLOG #5480, items 5 and 10). ### The criterion is the project's own, and it is not "is the work done" @@ -1119,10 +1115,9 @@ question is not whether the work finished but whether something durable has repl > **SUPERSEDED** = the item exists in the backlog namespace on `origin/main` **and** its banner there > already protects it — a CLOSED status glyph, or a do-not-rebuild banner naming the landing. -A do-not-rebuild banner counts only where no status line reads OPEN and no OPEN glyph stands -anywhere in the banner, because an open item's banner carries the same capitals as scope. A banner line opening with a symbol the tool does not know holds -the item too. An item whose number stands more than once, in both ledger files or twice in one, -supersedes only when every copy protects it (BACKLOG #5480, items 1 to 3). +A do-not-rebuild banner does not count inside an open item's banner, and an item whose number +stands more than once supersedes only when every copy protects it. The script's `Get-BannerState` +and its item index state the exact rules (BACKLOG #5480, items 1 to 3). Nothing else is ever proposed for release. Not age, not quiet, not a note saying the work is done. The tool has **no `-Apply`** and will not grow one: `claim.ps1` owns the `.history` ledger and writes diff --git a/scripts/coord/claim-adjudicate.ps1 b/scripts/coord/claim-adjudicate.ps1 index a67ab3c89e..de3c86a579 100644 --- a/scripts/coord/claim-adjudicate.ps1 +++ b/scripts/coord/claim-adjudicate.ps1 @@ -64,19 +64,20 @@ So OPEN means "not superseded HERE", never "not landed". An OPEN item whose branch carries unmerged commits is reported as blocking, never as available. - * A LANDING PHRASE UNDER AN OPEN STATUS LINE (BACKLOG #5480 item 1). The do-not-rebuild phrases - supersede only an item whose banner has no OPEN status line, the #1010 shape above. An open - item's banner carries the same capitals as SCOPE -- a PARTIAL banner names the half that - shipped, and vault #1393 quoted "DO NOT REBUILD" while it stood open -- so reading the phrase - over an open status line printed a release line for open work. + * A LANDING PHRASE IN AN OPEN BANNER (BACKLOG #5480 item 1). The do-not-rebuild phrases + supersede only the #1010 shape above; Get-BannerState states the rule and its reason. A STALE LEDGER (BACKLOG #5480 items 5 and 10). A ledger checkout that has not fetched errs BOTH ways: a banner it has not fetched reads as absent, which holds a claim that is safe to release, and an item reopened since its last fetch still reads CLOSED there, which prints a release line - for open work. So the run refuses when both the pinned ledger commit and the checkout's own - fetch of it, read from FETCH_HEAD, are older than -LedgerMaxAgeHours (24 by default). It also - refuses a -LedgerRepo that shares a root commit with this repository or carries its package, - since a clone of it from before 2026-09-13 still carries a full, stale ledger. + for open work. This tool does not fetch, so it bounds two readings, either of which may show the + checkout recent: the pinned commit's own committer date, and the checkout's FETCH_HEAD where it + names that commit as main of origin's URL, so a fetch into a vault nobody merged to since still + counts and the remedy is the fetch, not a wider bound. Both older than -LedgerMaxAgeHours (24 by + default) refuses, and so does a commit dated more than an hour in the future with no such + fetch, since its age cannot be read. It also refuses a -LedgerRepo that shares a root commit + with this repository or carries its package, since a clone of it from before 2026-09-13 still + carries a full, stale ledger. WHY THERE IS NO -Apply. `claim.ps1` owns the .history ledger: it writes the record BEFORE removing the file and refuses the release if the record cannot be written (BACKLOG #1068). A @@ -277,14 +278,7 @@ $ledgerRef = $ledgerPinned.Ref; $ledgerSha = $ledgerPinned.Sha # this repository; it does not prove which repository it is, and the item-heading admission below # is what refuses one that holds no ledger at all. # -# NOT STALE. A ledger checkout that has not fetched can show a since-reopened item CLOSED, and that -# prints a release line for open work -- the costly direction. This tool does not fetch, so the -# bound is on two readings, either of which may show the checkout recent: the pinned commit's own -# committer date, and the checkout's FETCH_HEAD where it names this same commit as `main`, so a -# fetch into a vault nobody merged to since still counts. Older than -LedgerMaxAgeHours on both -# refuses, and so does a commit dated more than an hour in the future with no such fetch, since its -# age cannot be read. It applies with or without -LedgerRepo: whichever repository is read is the -# one whose banners decide. +# NOT STALE. The rule and its reason are .NOTES' "A STALE LEDGER"; the code below is its only copy. # --------------------------------------------------------------------------------------------- if ($LedgerRepo) { $engineRoots = @(Invoke-NamespaceGit $repo @('rev-list', '--max-parents=0', $mainSha) "the root commits of $mainRef in $repo" "not read" $engineConsequence) @@ -300,18 +294,24 @@ if ($LedgerRepo) { "2026-09-13 that nothing keeps current. Refusing rather than adjudicate against it.$remedy") } } -$ledgerStamp = (@(Invoke-NamespaceGit $ledgerRoot @('log', '-1', '--format=%ct', $ledgerSha) "the commit date of $ledgerRef ($ledgerSha) in $ledgerRoot" "not read") -join '').Trim() +# --no-show-signature: a `log.showSignature` setting otherwise prints gpg lines before the date. +$ledgerStamp = (@(Invoke-NamespaceGit $ledgerRoot @('log', '-1', '--no-show-signature', '--format=%ct', $ledgerSha) "the commit date of $ledgerRef ($ledgerSha) in $ledgerRoot" "not read") -join '').Trim() if ($ledgerStamp -notmatch '^\d+$') { throw "could not read the commit date of $ledgerRef ($ledgerSha) in ${ledgerRoot}: git printed '$ledgerStamp'. Refusing rather than adjudicate against a ledger of unknown age." } $nowSec = [DateTimeOffset]::UtcNow.ToUnixTimeSeconds() $commitAgeHours = ($nowSec - [long]$ledgerStamp) / 3600.0 # FETCH_HEAD is per worktree, so this reads the fetch made in THIS checkout. A line counts only where -# it names the pinned commit as some remote's `main`: a fetch of another branch says nothing of main. +# it names the pinned commit as `main` of ORIGIN's URL, spelled as git writes it there (credentials, +# trailing slashes and `.git` dropped): a fetch of another branch, or of another remote whose main +# happens to sit at the same commit, says nothing of when origin was last read. $fetchAgeHours = $null $fetchHead = (@(Invoke-NamespaceGit $ledgerRoot @('rev-parse', '--path-format=absolute', '--git-path', 'FETCH_HEAD') "the FETCH_HEAD path of $ledgerRoot" "not read") -join '').Trim() -if ($fetchHead -and (Test-Path -LiteralPath $fetchHead -PathType Leaf)) { - $named = @(Get-Content -LiteralPath $fetchHead -Encoding utf8 | Where-Object { $_ -cmatch ('^' + [regex]::Escape($ledgerSha) + "\t[^\t]*\tbranch 'main' of ") }) +$originUrl = "$(& git -C $ledgerRoot remote get-url origin 2>$null)".Trim() +$originUrl = (($originUrl -replace '^([a-z][a-z0-9+.-]*://)[^/@]*@', '$1') -replace '/+$', '') -replace '\.git$', '' +if ($originUrl -and $fetchHead -and (Test-Path -LiteralPath $fetchHead -PathType Leaf)) { + $want = [regex]::Escape($ledgerSha) + "\t[^\t]*\tbranch 'main' of " + [regex]::Escape($originUrl) + '$' + $named = @(Get-Content -LiteralPath $fetchHead -Encoding utf8 | Where-Object { $_ -cmatch "^$want" }) if ($named.Count) { $fetchAgeHours = ($nowSec - [DateTimeOffset]::new((Get-Item -LiteralPath $fetchHead).LastWriteTimeUtc).ToUnixTimeSeconds()) / 3600.0 } @@ -362,19 +362,19 @@ if (-not $backlogFiles.Count) { # report the check above refuses. So a file joins the corpus only if it holds an item heading, in # the shape Get-ItemBlock matches, and a corpus left empty refuses. A stub is then never listed as a # source either. A file that could not be READ refuses too: dropping it silently would turn its -# items into NO-ITEM the same way. -$itemHeading = '(?m)^##\s+\d+\.\s' -$corpus = @{} +# items into NO-ITEM the same way. The test is the index below: a file joins when it gave an item. +# +# ONE SET OF LINES FOR EVERY RULE BELOW. owed_ledger_acts.py splits the ledger with Python's +# splitlines(), which breaks at U+2028, U+2029, U+0085, \v, \f and \x1c-\x1e as well as \r and \n. +# Each such break becomes `\n` here once, at load, so the heading index, the banner run and the +# status lines all read the lines that file reads; a heading or a status line after a U+2028 is a +# line of its own there and here alike. +$LINE_BREAK = [regex]'\r\n|[\n\r\v\f\x1c\x1d\x1e\x85

]' +$loaded = [ordered]@{} foreach ($bf in $backlogFiles) { $text = (Invoke-NamespaceGit $ledgerRoot @('show', "${ledgerSha}:$bf") "${ledgerRef}:$bf in $ledgerRoot" "only partly read") -join "`n" - if ($text -match $itemHeading) { $corpus[$bf] = $text } -} -if (-not $corpus.Count) { - throw ("no backlog item heading found in the backlog file(s) on $ledgerRef ($ledgerSha) in " + - "$ledgerRoot ($($backlogFiles -join ', ')), so there is no ledger there to adjudicate any " + - "key against. Refusing rather than report every key NO-ITEM.$remedy") + $loaded[$bf] = $LINE_BREAK.Replace($text, "`n") } -$corpusFiles = @($corpus.Keys | Sort-Object) # EVERY ITEM HEADING, INDEXED ONCE (BACKLOG #5480 item 8). A per-key regex over the whole corpus, # followed by a copy of everything after the match, cost about 1.5 s a key on the 35 MB vault ledger. @@ -393,22 +393,26 @@ $corpusFiles = @($corpus.Keys | Sort-Object) # `Regex.Match(text, startat)` per heading was tried first and rescanned the text from each start. # # KEYED BY THE NUMBER, NOT ITS SPELLING. owed_ledger_acts.py keys a row by int(), so `## 079.` and -# `## 79.` are copies of one row there, and the every-copy rule must see both here too. Leading zeros -# are dropped from the heading and from the claim's key alike. +# `## 79.` are copies of one row there, and the every-copy rule must see both here too. Each digit is +# read as its value, which int() also does for a non-ASCII decimal digit, and leading zeros are +# dropped -- from the heading and from the claim's key alike. function ConvertTo-ItemNumber([string]$Digits) { - $t = $Digits.TrimStart('0') + $t = (-join @(foreach ($c in $Digits.ToCharArray()) { [int][char]::GetNumericValue($c) })).TrimStart('0') if ($t) { $t } else { '0' } } $itemIndex = [System.Collections.Generic.Dictionary[string, System.Collections.Generic.List[object]]]::new([StringComparer]::Ordinal) $heading = [regex]'(?m)^##\s(?:\s*(?\d+)\.\s)?' -foreach ($f in $corpusFiles) { - $text = $corpus[$f] +$corpus = @{} +foreach ($f in $loaded.Keys) { + $text = $loaded[$f] $starts = [System.Collections.Generic.List[int]]::new() $items = [System.Collections.Generic.List[object]]::new() foreach ($h in $heading.Matches($text)) { $starts.Add($h.Index) if ($h.Groups['n'].Success) { $items.Add($h) } } + if (-not $items.Count) { continue } + $corpus[$f] = $text foreach ($m in $items) { # The block runs to the first heading starting at or after this heading's own end. $j = $starts.BinarySearch($m.Index + $m.Length) @@ -419,6 +423,12 @@ foreach ($f in $corpusFiles) { $itemIndex[$n].Add([pscustomobject]@{ File = $f; Start = $m.Index; Length = $end - $m.Index }) } } +if (-not $corpus.Count) { + throw ("no backlog item heading found in the backlog file(s) on $ledgerRef ($ledgerSha) in " + + "$ledgerRoot ($($backlogFiles -join ', ')), so there is no ledger there to adjudicate any " + + "key against. Refusing rather than report every key NO-ITEM.$remedy") +} +$corpusFiles = @($corpus.Keys | Sort-Object) # The status vocabulary is backlog_status_check.py's, not this file's, restated as # owed_ledger_acts.py restates it; tests/test_coord_claim_adjudicate.py holds the codepoints equal to @@ -448,15 +458,18 @@ foreach ($cp in @(0x26A0, 0x1F6E0, 0x1F4CC, 0x1F4D0, 0x2B06, 0x1F50E, 0x1F7E2, 0 # items that are open (measured 2026-11-19: "not started. OPEN ON EVERY GATE # MEASURED"). Matching it anywhere read those items CLOSED and printed a release line for open work. # -# THE SPACES ARE A SPACE OR A TAB, AND THE LINES ARE PYTHON'S (item 4). `\s` matches a newline too, -# so a CLOSED glyph alone on its line read as a status off the line below it; owed_ledger_acts.py -# matches one line at a time and does not. This reads one line at a time as well, split where -# Python's splitlines() splits, U+2028 and its kin included, and takes only a space or a tab as the -# space. It cuts one way: an OPEN glyph opening a line holds the item whatever follows it, indented -# or not, since an open status misread costs a stale claim and a closed one misread costs a -# duplicate build. -$BANNER_SHAPE = [regex]'^(?[ \t]*)>[ \t](?[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\x00-\x7F])\uFE0F?(?[ \t])?' -$LINE_BREAK = [regex]'\r\n|[\n\r\v\f\x1c\x1d\x1e\x85\u2028\u2029]' +# ONE LINE AT A TIME (item 4). `\s` matches a newline too, so a CLOSED glyph alone on its line read +# as a status off the line below it; owed_ledger_acts.py matches one line at a time and does not. +# This reads the lines the corpus load normalised, one at a time. Before the glyph, any whitespace +# counts, as in that file's `^>\s` (no line break is left inside a line to match). After a CLOSED +# glyph only a space or a tab does, stricter than that file in the holding direction. An OPEN glyph +# opening a line holds the item whatever follows it, indented or not, since an open status misread +# costs a stale claim and a closed one misread costs a duplicate build. +$BANNER_SHAPE = [regex]'^(?\s*)>\s(?[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\x00-\x7F])\uFE0F?(?[ \t])?' + +# Blank as Python's strip() reads it: .NET whitespace, plus \x1f, which Python counts and .NET does +# not (\x1c-\x1e are line breaks by now). +function Test-BlankLine([string]$Line) { -not ($Line -creplace '[\s\x1f]', '') } # A do-not-rebuild banner is prose, so it is matched on the few phrasings that assert the LANDING # ITSELF. A bare "do not build" is deliberately absent: a note reading "DO NOT BUILD half B" is @@ -496,7 +509,7 @@ function Get-LeadingQuote([string]$Block) { for ($i = 1; $i -lt $lines.Count; $i++) { $l = $lines[$i] if ($l -match '^\s*>') { $out.Add($l); continue } - if ($l.Trim() -eq '') { continue } + if (Test-BlankLine $l) { continue } break } return ($out -join "`n") @@ -531,8 +544,8 @@ function Get-BannerState([string]$Block) { $open = [System.Collections.Generic.List[string]]::new() $unknown = [System.Collections.Generic.List[string]]::new() $pastVault = $false - foreach ($l in $LINE_BREAK.Split($lead)) { - if ($l.Trim() -and -not $l.StartsWith('>', [StringComparison]::Ordinal)) { $pastVault = $true } + foreach ($l in ($lead -split "`n")) { + if (-not (Test-BlankLine $l) -and -not $l.StartsWith('>', [StringComparison]::Ordinal)) { $pastVault = $true } $m = $BANNER_SHAPE.Match($l) if (-not $m.Success) { continue } $g = $m.Groups['g'].Value @@ -555,8 +568,7 @@ function Get-BannerState([string]$Block) { return [pscustomobject]@{ State = "CLOSED/" + $GLYPH_NAME[$g]; Why = ""; Protects = $true } } } - foreach ($p in $LANDED_BANNER) { - if ($openAnywhere.Count) { break } + foreach ($p in $(if (-not $openAnywhere.Count) { $LANDED_BANNER })) { if ([regex]::IsMatch($lead, $p)) { # Quote the banner's own sentence back, so the verdict carries the observation it # rests on rather than a label the reader must take on trust. @@ -722,7 +734,7 @@ foreach ($f in $files) { $bannerState = $judged[0].State; $bannerWhy = $judged[0].Why $quote = if ($bannerWhy) { ": `"" + $bannerWhy.Substring(0, [Math]::Min(140, $bannerWhy.Length)) + "`"" } else { "" } $rows += [pscustomobject]@{ key = $k; holder = $holder; branch = $branch; note = $note - item = ((@($judged | ForEach-Object File) | Select-Object -Unique) -join ', '); banner = $bannerState + item = $judged[0].File; banner = $bannerState citations = $cites; verdict = "SUPERSEDED" why = "the item's banner on $ledgerAt already protects it ($bannerState)$quote$copies -- that protection travels to every checkout and this machine-local claim does not" } } diff --git a/tests/test_coord_claim_adjudicate.py b/tests/test_coord_claim_adjudicate.py index 4a87f608da..9129f65ee3 100644 --- a/tests/test_coord_claim_adjudicate.py +++ b/tests/test_coord_claim_adjudicate.py @@ -1158,7 +1158,9 @@ def test_an_item_in_both_ledger_files_is_superseded_only_when_every_copy_protect assert "every copy is read" in r["why"], r else: assert r["verdict"] == "SUPERSEDED", r - assert "docs/BACKLOG.md" in r["item"] and "archive" in r["item"], r + # `item` stays one path whatever the data; the why names every copy (review round two). + assert "," not in r["item"], r + assert "docs/BACKLOG.md" in r["why"] and "BACKLOG-CLOSED.md" in r["why"], r def test_an_item_twice_in_one_file_is_held_if_either_copy_is_open( @@ -1301,6 +1303,20 @@ def test_a_stale_ledger_refuses_and_a_wider_bound_reads_it( wide = verdicts(repo, "-LedgerRepo", str(vault), "-LedgerMaxAgeHours", "87600") assert wide["60"] == "SUPERSEDED" + # A fetch of ANOTHER remote whose main sits at the same commit says nothing of origin + # (review round two): it must not count as recent. + mirror = tmp_path / "vault-mirror.git" + subprocess.run( + ["git", "clone", "-q", "--bare", str(tmp_path / "vault-origin.git"), str(mirror)], + check=True, + timeout=TIMEOUT, + ) + git(vault, "remote", "add", "mirror", str(mirror)) + git(vault, "fetch", "-q", "mirror") + proc = adjudicate(repo, "-Json", "-LedgerRepo", str(vault)) + assert proc.returncode != 0, proc.stdout + assert "does not name it as main" in _flat(proc.stderr), proc.stderr + # A fetch into this checkout that names the same commit as main counts, though nobody merged # since: a quiet vault needs the fetch the refusal names, not a wider bound (review round one). git(vault, "fetch", "-q", "origin") @@ -1412,12 +1428,49 @@ def test_round_one_review_shapes_hold(repo: Path, tmp_path: Path, lead: str) -> assert r["verdict"] == "BLOCKING", r -def test_a_zero_padded_heading_is_a_copy_of_the_same_item(repo: Path, tmp_path: Path) -> None: - """MUST TRIP on d3ed0883be9 (item 2, review round one). owed_ledger_acts.py keys a row by int(), - so `## 079.` and `## 79.` are one row, OPEN if either copy is.""" +@pytest.mark.parametrize( + "body", + [ + # A non-breaking space after `>`: origin/main's `^>\s` and owed_ledger_acts.py read the OPEN + # status; round one's space-or-tab narrowed it away and released. + f"## 77. T\n\n> {SHIPPED} SHIPPED half A\n>\N{NO-BREAK SPACE}{IN_PROGRESS} reopened\n\nb\n", + # A U+2028 in the heading line: the OPEN status after it is a line of its own in Python. + f"## 77. T{LSEP}> {IN_PROGRESS} reopened\n> {SHIPPED} SHIPPED\n\nb\n", + # A heading after a U+2028 is a second copy of the item in Python. + f"## 77. T\n\n> {SHIPPED} SHIPPED\n\nprose{LSEP}## 77. T\n\n> {IN_PROGRESS} open\n\nb\n", + # A line holding only \x01 is NOT blank to Python's strip(), so owed_ledger_acts.py's banner + # block ends there and never sees the CLOSED line below it. PowerShell's culture-aware `-eq` + # read the line equal to '' and went on, then released. (The review's \x1f shape cannot + # bite: that compare already reads \x1f as blank, as Python does.) + f"## 77. T\n\n> a note\n\x01\n> {SHIPPED} SHIPPED\n\nb\n", + ], +) +def test_round_two_review_shapes_hold(repo: Path, tmp_path: Path, body: str) -> None: + """MUST TRIP on c43dbb47166, this branch's round-one head, where each read SUPERSEDED while + owed_ledger_acts.py reads the row OPEN (review round two, measured there).""" + backlog(repo, body) + unmerged_branch(repo, "seat") + write_claim(repo, "77", tmp_path / "gone", "seat") + assert verdicts(repo)["77"] == "BLOCKING" + + +@pytest.mark.parametrize( + "spelling", + [ + "079", + # Arabic-Indic seven and nine: int() reads them as 79 (review round two). + "\N{ARABIC-INDIC DIGIT SEVEN}\N{ARABIC-INDIC DIGIT NINE}", + ], +) +def test_a_zero_padded_heading_is_a_copy_of_the_same_item( + repo: Path, tmp_path: Path, spelling: str +) -> None: + """MUST TRIP on d3ed0883be9 (item 2, review rounds one and two). owed_ledger_acts.py keys a row + by int(), so `## 079.` and `## 79.` are one row, OPEN if either copy is.""" backlog( repo, - f"## 79. Thing\n\n> {SHIPPED} SHIPPED\n\nbody\n\n## 079. Thing\n\n> {IN_PROGRESS} open\n\nb\n", + f"## 79. Thing\n\n> {SHIPPED} SHIPPED\n\nbody\n\n" + f"## {spelling}. Thing\n\n> {IN_PROGRESS} open\n\nb\n", ) unmerged_branch(repo, "seat") write_claim(repo, "79", tmp_path / "gone", "seat") @@ -1472,8 +1525,9 @@ def timed(keys: range) -> float: assert set(got) == {str(k) for k in keys} and set(got.values()) == {"BLOCKING"}, got return elapsed - one = timed(range(3000, 3001)) - many = timed(range(2976, 3001)) + # The best of two runs a side, so one slow moment on a shared runner cannot decide it. + one = min(timed(range(3000, 3001)), timed(range(3000, 3001))) + many = min(timed(range(2976, 3001)), timed(range(2976, 3001))) assert many - one < 2 * one, f"24 more keys cost {many - one:.1f}s against {one:.1f}s for one" From f0710a8b7a8aecd48ce72b652a5947894c2dde49 Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Sun, 29 Nov 2026 12:08:20 -0600 Subject: [PATCH 05/14] Record: BACKLOG #5480 review round three (unrepaired) and the corrected proposed banner The cap of two repair rounds was reached; round three ran on the pushed head 4400a96a9eb and nothing it found was fixed. It names five shapes where this branch releases a claim that origin/main holds, each because the branch adopted owed_ledger_acts.py's reading outright: a control or zero-width line now ends the banner run; U+2028-class breaks create a CLOSED line or cut the run; zero-padded, non-ASCII-digit or after-U+2028 headings now resolve keys origin/main read NO-ITEM. The repair is to release only where BOTH readings protect the item. This supersedes the SHIPPED banner proposed in 4400a96a9eb. Proposed PR title: claim-adjudicate.ps1: close engine PR 3124's open findings on the ledger read (BACKLOG #5480) Proposed banner #5480: PARTIAL in b20037/claim-adjudicate-5480 -- built items 1-11 from engine PR 3124 (open status or glyph blocks a landing phrase; every copy judged; unknown glyph holds; line-at-a-time grammar; JSON reference is the ledger's; per-rule cases; one heading scan per file, 34 MB ledger 20 extra keys 40.6 s before and 4.3 s after; glyph-list parity test, sharing the Python parser declined; engine-ref wording; refuses an engine clone and a ledger neither committed nor fetched from origin within -LedgerMaxAgeHours; WORKTREES.md). Fail-before 16 failed, 57 passed at origin/main 74910c69104. STAYS OPEN on review round three's five shapes that release what origin/main holds, and its other nine findings. Verified-by: none From 84e2fb726565d7511764abf93f7fc1654aee39dc Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Sun, 29 Nov 2026 12:18:45 -0600 Subject: [PATCH 06/14] claim-adjudicate.ps1: a release needs both readings; the timing test is opt-in BACKLOG #5480, Manager repair after review round three. The ledger is read twice. RAW is origin/main's reading (`\n` lines, PowerShell's blank test, the key's digits as written) and alone decides whether a key names an item. NORMALISED is owed_ledger_acts.py's (splitlines() breaks, Python's blank test, keys by value) and only adds copies. SUPERSEDED needs every copy in both readings to protect the item, so the five round-three shapes hold again: a control or zero-width line, a U+2028 making a CLOSED line, a U+2028 cutting the run, a zero-padded or non-ASCII-digit key, a heading after a U+2028. test_a_release_needs_both_readings, 7 cases: 7 passed (holds) on origin/main e00507a5678 (script identical to ddf50248fae), 7 failed (releases) on f0710a8b7a8, 7 passed here. The timing test now skips unless MEFOR_ADJUDICATE_TIMING=1. Verified-by: tests --- scripts/coord/claim-adjudicate.ps1 | 128 ++++++++++++++++----------- tests/test_coord_claim_adjudicate.py | 56 ++++++++++++ 2 files changed, 132 insertions(+), 52 deletions(-) diff --git a/scripts/coord/claim-adjudicate.ps1 b/scripts/coord/claim-adjudicate.ps1 index de3c86a579..c8785f2084 100644 --- a/scripts/coord/claim-adjudicate.ps1 +++ b/scripts/coord/claim-adjudicate.ps1 @@ -364,16 +364,25 @@ if (-not $backlogFiles.Count) { # source either. A file that could not be READ refuses too: dropping it silently would turn its # items into NO-ITEM the same way. The test is the index below: a file joins when it gave an item. # -# ONE SET OF LINES FOR EVERY RULE BELOW. owed_ledger_acts.py splits the ledger with Python's -# splitlines(), which breaks at U+2028, U+2029, U+0085, \v, \f and \x1c-\x1e as well as \r and \n. -# Each such break becomes `\n` here once, at load, so the heading index, the banner run and the -# status lines all read the lines that file reads; a heading or a status line after a U+2028 is a -# line of its own there and here alike. +# TWO READINGS, AND A RELEASE NEEDS BOTH (BACKLOG #5480, Manager repair after review round three). +# +# RAW is origin/main's reading: the text split on `\n` only, PowerShell's blank test, and a key that +# matches a heading's digits exactly as written. NORMALISED is owed_ledger_acts.py's: Python's +# splitlines() breaks (U+2028, U+2029, U+0085, \v, \f, \x1c-\x1e, as well as \r and \n) turned into +# `\n` once at load, Python's blank test, and headings keyed by numeric value. +# +# Each reading is right where the other is not, and each alone released open work somewhere the +# other held it: the raw one past a U+2028 that hides an OPEN line, the normalised one where a +# control-character line ends the banner run early or a U+2028 makes a CLOSED line. So the raw +# reading alone decides whether the key names an item at all -- no new key, none origin/main read +# NO-ITEM -- and the normalised reading may only ADD copies and lines that hold. An item supersedes +# only when every copy in BOTH readings protects it. $LINE_BREAK = [regex]'\r\n|[\n\r\v\f\x1c\x1d\x1e\x85

]' -$loaded = [ordered]@{} +$loaded = @{ raw = [ordered]@{}; norm = [ordered]@{} } foreach ($bf in $backlogFiles) { $text = (Invoke-NamespaceGit $ledgerRoot @('show', "${ledgerSha}:$bf") "${ledgerRef}:$bf in $ledgerRoot" "only partly read") -join "`n" - $loaded[$bf] = $LINE_BREAK.Replace($text, "`n") + $loaded.raw[$bf] = $text + $loaded.norm[$bf] = $LINE_BREAK.Replace($text, "`n") } # EVERY ITEM HEADING, INDEXED ONCE (BACKLOG #5480 item 8). A per-key regex over the whole corpus, @@ -392,43 +401,48 @@ foreach ($bf in $backlogFiles) { # item's. `^##\s` then `\s*\d+\.\s` is the per-key pattern `^##\s+N\.\s` split in two. A # `Regex.Match(text, startat)` per heading was tried first and rescanned the text from each start. # -# KEYED BY THE NUMBER, NOT ITS SPELLING. owed_ledger_acts.py keys a row by int(), so `## 079.` and -# `## 79.` are copies of one row there, and the every-copy rule must see both here too. Each digit is -# read as its value, which int() also does for a non-ASCII decimal digit, and leading zeros are -# dropped -- from the heading and from the claim's key alike. +# KEYED BY THE NUMBER IN THE NORMALISED READING, BY ITS SPELLING IN THE RAW ONE. owed_ledger_acts.py +# keys a row by int(), so `## 079.` and `## 79.` are copies of one row there; the normalised index +# reads each digit as its value, as int() does for a non-ASCII decimal digit, and drops leading +# zeros. The raw index keeps the digits as written, origin/main's key, so a spelling origin/main +# never matched cannot make a key resolve. function ConvertTo-ItemNumber([string]$Digits) { $t = (-join @(foreach ($c in $Digits.ToCharArray()) { [int][char]::GetNumericValue($c) })).TrimStart('0') if ($t) { $t } else { '0' } } -$itemIndex = [System.Collections.Generic.Dictionary[string, System.Collections.Generic.List[object]]]::new([StringComparer]::Ordinal) $heading = [regex]'(?m)^##\s(?:\s*(?\d+)\.\s)?' -$corpus = @{} -foreach ($f in $loaded.Keys) { - $text = $loaded[$f] - $starts = [System.Collections.Generic.List[int]]::new() - $items = [System.Collections.Generic.List[object]]::new() - foreach ($h in $heading.Matches($text)) { - $starts.Add($h.Index) - if ($h.Groups['n'].Success) { $items.Add($h) } - } - if (-not $items.Count) { continue } - $corpus[$f] = $text - foreach ($m in $items) { - # The block runs to the first heading starting at or after this heading's own end. - $j = $starts.BinarySearch($m.Index + $m.Length) - if ($j -lt 0) { $j = -bnot $j } - $end = if ($j -lt $starts.Count) { $starts[$j] } else { $text.Length } - $n = ConvertTo-ItemNumber $m.Groups['n'].Value - if (-not $itemIndex.ContainsKey($n)) { $itemIndex[$n] = [System.Collections.Generic.List[object]]::new() } - $itemIndex[$n].Add([pscustomobject]@{ File = $f; Start = $m.Index; Length = $end - $m.Index }) +$itemIndex = @{} +$corpus = @{ raw = @{}; norm = @{} } +foreach ($mode in 'raw', 'norm') { + $itemIndex[$mode] = [System.Collections.Generic.Dictionary[string, System.Collections.Generic.List[object]]]::new([StringComparer]::Ordinal) + foreach ($f in $loaded[$mode].Keys) { + $text = $loaded[$mode][$f] + $starts = [System.Collections.Generic.List[int]]::new() + $items = [System.Collections.Generic.List[object]]::new() + foreach ($h in $heading.Matches($text)) { + $starts.Add($h.Index) + if ($h.Groups['n'].Success) { $items.Add($h) } + } + if (-not $items.Count) { continue } + $corpus[$mode][$f] = $text + foreach ($m in $items) { + # The block runs to the first heading starting at or after this heading's own end. + $j = $starts.BinarySearch($m.Index + $m.Length) + if ($j -lt 0) { $j = -bnot $j } + $end = if ($j -lt $starts.Count) { $starts[$j] } else { $text.Length } + $n = if ($mode -eq 'raw') { $m.Groups['n'].Value } else { ConvertTo-ItemNumber $m.Groups['n'].Value } + if (-not $itemIndex[$mode].ContainsKey($n)) { $itemIndex[$mode][$n] = [System.Collections.Generic.List[object]]::new() } + $itemIndex[$mode][$n].Add([pscustomobject]@{ File = $f; Start = $m.Index; Length = $end - $m.Index }) + } } } -if (-not $corpus.Count) { +# A file joins the corpus, as origin/main admitted it, when its RAW text holds an item heading. +if (-not $corpus.raw.Count) { throw ("no backlog item heading found in the backlog file(s) on $ledgerRef ($ledgerSha) in " + "$ledgerRoot ($($backlogFiles -join ', ')), so there is no ledger there to adjudicate any " + "key against. Refusing rather than report every key NO-ITEM.$remedy") } -$corpusFiles = @($corpus.Keys | Sort-Object) +$corpusFiles = @($corpus.raw.Keys | Sort-Object) # The status vocabulary is backlog_status_check.py's, not this file's, restated as # owed_ledger_acts.py restates it; tests/test_coord_claim_adjudicate.py holds the codepoints equal to @@ -467,9 +481,13 @@ foreach ($cp in @(0x26A0, 0x1F6E0, 0x1F4CC, 0x1F4D0, 0x2B06, 0x1F50E, 0x1F7E2, 0 # costs a stale claim and a closed one misread costs a duplicate build. $BANNER_SHAPE = [regex]'^(?\s*)>\s(?[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\x00-\x7F])\uFE0F?(?[ \t])?' -# Blank as Python's strip() reads it: .NET whitespace, plus \x1f, which Python counts and .NET does -# not (\x1c-\x1e are line breaks by now). -function Test-BlankLine([string]$Line) { -not ($Line -creplace '[\s\x1f]', '') } +# Blank, per reading. NORMALISED: as Python's strip() reads it, .NET whitespace plus \x1f, which +# Python counts and .NET does not (\x1c-\x1e are line breaks by then). RAW: origin/main's own test, +# a culture-aware compare that also reads a line of control or zero-width characters as blank. +function Test-BlankLine([string]$Line, [string]$Mode) { + if ($Mode -eq 'raw') { return ($Line.Trim() -eq '') } + -not ($Line -creplace '[\s\x1f]', '') +} # A do-not-rebuild banner is prose, so it is matched on the few phrasings that assert the LANDING # ITSELF. A bare "do not build" is deliberately absent: a note reading "DO NOT BUILD half B" is @@ -483,19 +501,20 @@ $LANDED_BANNER = @( 'HAS LANDED ON `?origin/main' ) -function Get-ItemBlock([string]$ItemKey) { - # Every block the key names, each with the file it came from; empty when it names none. Only a - # whole-number key can name a backlog item; anything else belongs to a different namespace and - # must not be pattern-matched into this one. +function Get-ItemBlock([string]$ItemKey, [string]$Mode) { + # Every block the key names in one reading, each with its file and reading; empty when it names + # none. Only a whole-number key can name a backlog item; anything else belongs to a different + # namespace and must not be pattern-matched into this one. if ($ItemKey -notmatch '^\d+$') { return @() } + $lookup = if ($Mode -eq 'raw') { $ItemKey } else { ConvertTo-ItemNumber $ItemKey } $hits = $null - if (-not $itemIndex.TryGetValue((ConvertTo-ItemNumber $ItemKey), [ref]$hits)) { return @() } + if (-not $itemIndex[$Mode].TryGetValue($lookup, [ref]$hits)) { return @() } @(foreach ($h in $hits) { - [pscustomobject]@{ File = $h.File; Text = $corpus[$h.File].Substring($h.Start, $h.Length) } + [pscustomobject]@{ File = $h.File; Mode = $Mode; Text = $corpus[$Mode][$h.File].Substring($h.Start, $h.Length) } }) } -function Get-LeadingQuote([string]$Block) { +function Get-LeadingQuote([string]$Block, [string]$Mode) { # The banner run: the contiguous blockquote lines that OPEN the item, blank lines allowed between # quoted paragraphs. Bounded at the first ordinary prose line, because a blockquote deeper in the # body is a citation or an aside and is not the item's status. @@ -509,13 +528,13 @@ function Get-LeadingQuote([string]$Block) { for ($i = 1; $i -lt $lines.Count; $i++) { $l = $lines[$i] if ($l -match '^\s*>') { $out.Add($l); continue } - if (Test-BlankLine $l) { continue } + if (Test-BlankLine $l $Mode) { continue } break } return ($out -join "`n") } -function Get-BannerState([string]$Block) { +function Get-BannerState([string]$Block, [string]$Mode) { # One block's banner state, whether it protects the item, and the observation it rests on. # # AN OPEN STATUS LINE WINS OVER A LANDING PHRASE (BACKLOG #5480 item 1). A landing phrase is prose, @@ -539,13 +558,13 @@ function Get-BannerState([string]$Block) { # status grammar, so it gets no grammar's benefit of the doubt: `> **PARTIAL** # half B open. Half A HAS LANDED ON origin/main; DO NOT REBUILD it.` opens with no status line and # is still open work. - $lead = Get-LeadingQuote $Block + $lead = Get-LeadingQuote $Block $Mode $closed = [System.Collections.Generic.List[string]]::new() $open = [System.Collections.Generic.List[string]]::new() $unknown = [System.Collections.Generic.List[string]]::new() $pastVault = $false foreach ($l in ($lead -split "`n")) { - if (-not (Test-BlankLine $l) -and -not $l.StartsWith('>', [StringComparison]::Ordinal)) { $pastVault = $true } + if (-not (Test-BlankLine $l $Mode) -and -not $l.StartsWith('>', [StringComparison]::Ordinal)) { $pastVault = $true } $m = $BANNER_SHAPE.Match($l) if (-not $m.Success) { continue } $g = $m.Groups['g'].Value @@ -706,7 +725,10 @@ foreach ($f in $files) { continue } - $blocks = @(Get-ItemBlock $k) + # The raw reading alone says whether the key names an item; the normalised one only adds copies. + $rawBlocks = @(Get-ItemBlock $k 'raw') + $normBlocks = @(Get-ItemBlock $k 'norm') + $blocks = if ($rawBlocks.Count) { @($rawBlocks) + @($normBlocks) } else { @() } # @() re-wraps what PowerShell unrolled on return. Without it a SINGLE citation reaches # ConvertTo-Json as a bare object rather than a one-element array, so a JSON consumer that # iterates `citations` gets field NAMES when there is one hit and records when there are two -- @@ -720,14 +742,16 @@ foreach ($f in $files) { continue } - # Every copy is judged, and the first that does not protect the item decides (item 2). + # Every copy in both readings is judged, and the first that does not protect the item decides + # (item 2). The count is the larger reading's, since each copy stands once in each reading. $judged = @(foreach ($b in $blocks) { - $s = Get-BannerState $b.Text + $s = Get-BannerState $b.Text $b.Mode [pscustomobject]@{ File = $b.File; State = $s.State; Why = $s.Why; Protects = $s.Protects } }) $holding = @($judged | Where-Object { -not $_.Protects }) - $copies = if ($judged.Count -gt 1) { - " (the item stands $($judged.Count) times, in " + ((@($judged | ForEach-Object File) | Select-Object -Unique) -join ', ') + ", and every copy is read)" + $nCopies = [Math]::Max($rawBlocks.Count, $normBlocks.Count) + $copies = if ($nCopies -gt 1) { + " (the item stands $nCopies times, in " + ((@($judged | ForEach-Object File) | Select-Object -Unique) -join ', ') + ", and every copy is read)" } else { "" } if (-not $holding.Count) { diff --git a/tests/test_coord_claim_adjudicate.py b/tests/test_coord_claim_adjudicate.py index 9129f65ee3..5cdf8cbce8 100644 --- a/tests/test_coord_claim_adjudicate.py +++ b/tests/test_coord_claim_adjudicate.py @@ -1500,6 +1500,62 @@ def test_a_shallow_clone_of_this_repository_is_refused_by_its_package( assert "carries this repository's package" in combined, combined +@pytest.mark.parametrize( + "key,body,verdict", + [ + # Shape 1: a line of control or zero-width characters. origin/main's culture compare reads it + # blank and goes on to the OPEN line; the normalised reading ends the run there. + ( + "80", + f"## 80. T\n\n> {SHIPPED} SHIPPED half A\n\x01\n> {IN_PROGRESS} reopened\n\nb\n", + "BLOCKING", + ), + ( + "80", + f"## 80. T\n\n> {SHIPPED} SHIPPED half A\n\N{ZERO WIDTH SPACE}\n> {IN_PROGRESS} reopened\n\nb\n", + "BLOCKING", + ), + # Shape 2: a U+2028 makes a CLOSED status line out of the tail of a prose line. + ( + "80", + f"## 80. T\n\n> Note: reopened, see below{LSEP}> {SHIPPED} SHIPPED\n\nb\n", + "BLOCKING", + ), + # Shape 3: a U+2028 cuts a quote line, and its tail ends the run before the OPEN line. + ( + "80", + f"## 80. T\n\n> {SHIPPED} SHIPPED{LSEP}more prose\n> {IN_PROGRESS} reopened\n\nb\n", + "BLOCKING", + ), + # Shape 4: a key spelled only as a zero-padded or non-ASCII-digit heading. + ("81", f"## 081. T\n\n> {SHIPPED} SHIPPED\n\nb\n", "NO-ITEM"), + ( + "81", + f"## \N{ARABIC-INDIC DIGIT EIGHT}\N{ARABIC-INDIC DIGIT ONE}. T\n\n> {SHIPPED} SHIPPED\n\n" + "b\n## 1. Admits the file\n", + "NO-ITEM", + ), + # Shape 5: a heading that starts a line only after a U+2028. + ("82", f"## 1. Other\n\nprose{LSEP}## 82. T\n\n> {SHIPPED} SHIPPED\n\nb\n", "NO-ITEM"), + ], +) +def test_a_release_needs_both_readings( + repo: Path, tmp_path: Path, key: str, body: str, verdict: str +) -> None: + """MUST TRIP on f0710a8b7a8, which read each SUPERSEDED, and holds on origin/main (review round + three, Manager repair). The normalised reading may only add what holds; the raw reading, origin/ + main's, still decides whether the key names an item and must protect it too.""" + backlog(repo, body) + unmerged_branch(repo, "seat") + write_claim(repo, key, tmp_path / "gone", "seat") + assert verdicts(repo)[key] == verdict + + +@pytest.mark.skipif( + os.environ.get("MEFOR_ADJUDICATE_TIMING") != "1", + reason="a wall-clock comparison; opt in with MEFOR_ADJUDICATE_TIMING=1, so a loaded runner " + "cannot fail a required leg on it", +) def test_the_namespace_is_indexed_once_not_scanned_per_key(repo: Path, tmp_path: Path) -> None: """MUST TRIP (item 8). Each key ran a regex over the whole corpus and copied everything after the match, about 2 s a key on a 34 MB ledger (measured 2026-11-29: 9.1 s for one key, 49.7 s for From 648054f685ffe779007819bf3791ad5b6e474be5 Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Sun, 29 Nov 2026 12:35:21 -0600 Subject: [PATCH 07/14] Record: BACKLOG #5480 repair-round review, and the proposed banner (supersedes all earlier ones) One code-review round (xhigh, round-8463c80546) ran on 84e2fb72656 and nothing it found was fixed. It found ONE shape that still releases a claim origin/main holds: a heading with `##` and whitespace after it on the same line (`## 5. ## x`, `## 5.\t##\tx`, `## 5. ##`). origin/main's block ended at that inline `##` and read NO-BANNER (BLOCKING); the index here runs the block to the next line-start heading and reads the banner below (SUPERSEDED). owed_ledger_acts.py also reads it CLOSED. The repair is for the raw reading to end the block at an inline `##\s` right after the heading match, as origin/main did. Its other nine findings release nothing origin/main holds. Proposed PR title: claim-adjudicate.ps1: close engine PR 3124's open findings on the ledger read (BACKLOG #5480) Proposed banner #5480: PARTIAL in b20037/claim-adjudicate-5480 -- this supersedes the banners proposed in 4400a96a9eb and f0710a8b7a8. Built items 1-11 from engine PR 3124: open status or glyph blocks a landing phrase; every copy judged; unknown glyph holds; line-at-a-time grammar; a release needs both origin/main's raw reading and the owed_ledger_acts.py-style reading; JSON reference is the ledger's; per-rule cases; one heading scan per file (34 MB ledger, 20 extra keys 40.6 s before and 4.3 s after; the timing test is opt-in, MEFOR_ADJUDICATE_TIMING=1); glyph-list parity test, sharing the Python parser declined; engine-ref wording; refuses an engine clone and a ledger neither committed nor fetched from origin within -LedgerMaxAgeHours; WORKTREES.md. Fail-before 16 failed, 57 passed at origin/main 74910c69104; the both-readings test 7 failed on f0710a8b7a8, 7 passed on origin/main e00507a5678. STAYS OPEN on the inline-`##` heading shape that releases what origin/main holds, and on the round's other nine findings. Verified-by: none From ce3b69bec9196d18d64142746fad971d7eb34e31 Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Sun, 29 Nov 2026 12:39:40 -0600 Subject: [PATCH 08/14] claim-adjudicate.ps1: the raw reading ends a block at an inline ## after the heading BACKLOG #5480, Manager's final repair round. origin/main's per-key match searched `(?m)^##\s` in the text after the heading, where position 0 counts as a line start, so `## 5. ## x` was a block of the heading alone and read NO-BANNER. The raw index now ends the block there too; the index had run on to the banner below and released what origin/main held. Also corrects the copy-count comment: a copy can stand only in the normalised reading. test_a_release_needs_both_readings, the three new cases (`## 83. ## x`, `## 83.\t##\tx`, `## 83. ##`): 3 passed (holds) on origin/main e00507a5678, 3 failed (releases) on 648054f685f, 3 passed here. Verified-by: tests --- scripts/coord/claim-adjudicate.ps1 | 13 +++++++++++-- tests/test_coord_claim_adjudicate.py | 5 +++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/scripts/coord/claim-adjudicate.ps1 b/scripts/coord/claim-adjudicate.ps1 index c8785f2084..057ef5c4d8 100644 --- a/scripts/coord/claim-adjudicate.ps1 +++ b/scripts/coord/claim-adjudicate.ps1 @@ -427,9 +427,17 @@ foreach ($mode in 'raw', 'norm') { $corpus[$mode][$f] = $text foreach ($m in $items) { # The block runs to the first heading starting at or after this heading's own end. - $j = $starts.BinarySearch($m.Index + $m.Length) + $headEnd = $m.Index + $m.Length + $j = $starts.BinarySearch($headEnd) if ($j -lt 0) { $j = -bnot $j } $end = if ($j -lt $starts.Count) { $starts[$j] } else { $text.Length } + # RAW ENDS AT AN INLINE `##` RIGHT AFTER THE HEADING, as origin/main's per-key match did: it + # searched `(?m)^##\s` in the text after the heading, where position 0 counts as a line + # start, so `## 5. ## x` was a block of the heading alone and read NO-BANNER. Running on to + # the banner below released what origin/main held (review of 84e2fb72656). + if ($mode -eq 'raw' -and [regex]::IsMatch($text.Substring($headEnd, [Math]::Min(3, $text.Length - $headEnd)), '^##\s')) { + $end = $headEnd + } $n = if ($mode -eq 'raw') { $m.Groups['n'].Value } else { ConvertTo-ItemNumber $m.Groups['n'].Value } if (-not $itemIndex[$mode].ContainsKey($n)) { $itemIndex[$mode][$n] = [System.Collections.Generic.List[object]]::new() } $itemIndex[$mode][$n].Add([pscustomobject]@{ File = $f; Start = $m.Index; Length = $end - $m.Index }) @@ -743,7 +751,8 @@ foreach ($f in $files) { } # Every copy in both readings is judged, and the first that does not protect the item decides - # (item 2). The count is the larger reading's, since each copy stands once in each reading. + # (item 2). The count is the larger reading's: most copies stand once in each reading, but a + # zero-padded or non-ASCII-digit heading, or one after a U+2028, stands only in the normalised one. $judged = @(foreach ($b in $blocks) { $s = Get-BannerState $b.Text $b.Mode [pscustomobject]@{ File = $b.File; State = $s.State; Why = $s.Why; Protects = $s.Protects } diff --git a/tests/test_coord_claim_adjudicate.py b/tests/test_coord_claim_adjudicate.py index 5cdf8cbce8..f2c4c3698f 100644 --- a/tests/test_coord_claim_adjudicate.py +++ b/tests/test_coord_claim_adjudicate.py @@ -1535,6 +1535,11 @@ def test_a_shallow_clone_of_this_repository_is_refused_by_its_package( "b\n## 1. Admits the file\n", "NO-ITEM", ), + # Shape 6 (review of 84e2fb72656): `##` and whitespace right after the heading on its own line. + # origin/main's block ended there and read NO-BANNER. + ("83", f"## 83. ## x\n\n> {SHIPPED} SHIPPED\n\nb\n", "BLOCKING"), + ("83", f"## 83.\t##\tx\n\n> {SHIPPED} SHIPPED\n\nb\n", "BLOCKING"), + ("83", f"## 83. ##\n\n> {SHIPPED} SHIPPED\n\nb\n", "BLOCKING"), # Shape 5: a heading that starts a line only after a U+2028. ("82", f"## 1. Other\n\nprose{LSEP}## 82. T\n\n> {SHIPPED} SHIPPED\n\nb\n", "NO-ITEM"), ], From 64695101cd32c31e05ed054598ccaa311bc944d1 Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Sun, 29 Nov 2026 12:55:53 -0600 Subject: [PATCH 09/14] Record: BACKLOG #5480 final review round, and the proposed banner (supersedes all earlier ones) The last code-review round (xhigh, round-551dcf989e) ran on ce3b69bec91; nothing it found was fixed. Its answer to the key question: no shape makes this branch print SUPERSEDED where origin/main holds the claim, by reading the code and by a 36-shape differential probe (0 such shapes; 11 shapes origin/main released and this branch holds). It names 12 findings, none of which releases a claim origin/main holds. Proposed PR title: claim-adjudicate.ps1: close engine PR 3124's open findings on the ledger read (BACKLOG #5480) Proposed banner #5480: SHIPPED in b20037/claim-adjudicate-5480 -- this supersedes the banners proposed in 4400a96a9eb, f0710a8b7a8 and 648054f685f. Built the eleven items from engine PR 3124: open status or glyph blocks a landing phrase; every copy judged; unknown glyph holds; line-at-a-time grammar; a release needs both origin/main's raw reading and the owed_ledger_acts.py-style reading; JSON reference is the ledger's; per-rule cases; one heading scan per file (34 MB ledger, 20 extra keys 40.6 s before and 4.3 s after; the timing test is opt-in, MEFOR_ADJUDICATE_TIMING=1); glyph-list parity test, sharing the Python parser declined; engine-ref wording; refuses an engine clone and a ledger neither committed nor fetched from origin within -LedgerMaxAgeHours; WORKTREES.md. Fail-before 16 failed, 57 passed at origin/main 74910c69104; the both-readings test 10 failed across f0710a8b7a8 and 648054f685f and 10 passed on origin/main e00507a5678. The final review's 12 findings are filed under ledger ruling R2; none releases a claim origin/main holds. Verified-by: none From d9deb54d1846cf0c8113202e1d1841d50569f677 Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Sun, 29 Nov 2026 15:14:11 -0600 Subject: [PATCH 10/14] claim-adjudicate.ps1: repair the six items of the Lander's hold BACKLOG #5480, Lander hold on 64695101cd3 (engine PR 3469). 1. The loaded and corpus maps key file names ordinally, so two backlog files that differ only in case are each read. 64695101cd3 released item 7 where BACKLOG-OLD.md holds it OPEN beside a BACKLOG-old.md with no item; origin/main and this head print BLOCKING. 2. The FETCH_HEAD match spells origin as git's fetch writes it: user@ dropped from an scp-style URL, and a case-sensitive .git strip. 3. The package refusal names both causes, an engine checkout or a vault checkout last fetched before 2026-09-26, with a remedy for each. 4. The age check runs after the no-item-heading refusal, so a stale stub without -LedgerRepo points to the vault first, as on origin/main. 5. Each held key prints its own state, file and copies. A hold that is not a plain OPEN names its cause and says to correct the ledger row, with no claim about the work or a branch decision. 6. Comments, .NOTES and the docs/WORKTREES.md paragraph say what the code does, with "at least" for the cases that can still release, and document the unknown-symbol hold and its remedy. Fail-before at 64695101cd3, the new tests: 8 failed, 3 passed (the 3 are the origin-form controls). Verified-by: tests --- docs/WORKTREES.md | 18 +- scripts/coord/claim-adjudicate.ps1 | 266 ++++++++++++++++++++------- tests/test_coord_claim_adjudicate.py | 214 +++++++++++++++++++++ 3 files changed, 422 insertions(+), 76 deletions(-) diff --git a/docs/WORKTREES.md b/docs/WORKTREES.md index a7579333f9..cd690c238e 100644 --- a/docs/WORKTREES.md +++ b/docs/WORKTREES.md @@ -1102,8 +1102,11 @@ claims, branches and citations stay this repository's. **Fetch the vault checkout first. A stale one errs both ways.** A banner it has not fetched reads as absent, which holds a claim that is safe to release. An item reopened since its last fetch still reads CLOSED there, which prints a release line for open work. So the run refuses a ledger it -cannot show is recent, and a `-LedgerRepo` that is a clone of this repository; the conditions are -in the script's header, *A STALE LEDGER*, and are not copied here (BACKLOG #5480, items 5 and 10). +cannot show is recent, a `-LedgerRepo` that shares a root commit with this repository, and one that +carries this repository's package, which is an engine checkout or a vault checkout last fetched +before 2026-09-26. The recency bound is a floor, not proof of a recent read: at least +`git fetch --append` can make an old fetch look recent. The conditions are in the script's header, +*A STALE LEDGER*, and are not copied here (BACKLOG #5480, items 5 and 10). ### The criterion is the project's own, and it is not "is the work done" @@ -1115,9 +1118,14 @@ question is not whether the work finished but whether something durable has repl > **SUPERSEDED** = the item exists in the backlog namespace on `origin/main` **and** its banner there > already protects it — a CLOSED status glyph, or a do-not-rebuild banner naming the landing. -A do-not-rebuild banner does not count inside an open item's banner, and an item whose number -stands more than once supersedes only when every copy protects it. The script's `Get-BannerState` -and its item index state the exact rules (BACKLOG #5480, items 1 to 3). +A do-not-rebuild banner does not count where any line of the banner carries an OPEN status symbol, +or a banner line opens with a symbol the script does not know. It still counts where neither +stands, so at least an item marked open only in words, such as `**PARTIAL**` with no status symbol, +supersedes on it. An item whose number stands more than once supersedes only when every copy +protects it. A banner line opening with an unknown symbol holds the item; the report names the +symbol and says to correct the ledger row, or to add the symbol to the script's lists where the +vault has adopted it as a status. The script's `Get-BannerState` and its item index state the +exact rules (BACKLOG #5480, items 1 to 3). Nothing else is ever proposed for release. Not age, not quiet, not a note saying the work is done. The tool has **no `-Apply`** and will not grow one: `claim.ps1` owns the `.history` ledger and writes diff --git a/scripts/coord/claim-adjudicate.ps1 b/scripts/coord/claim-adjudicate.ps1 index 057ef5c4d8..817bf947ca 100644 --- a/scripts/coord/claim-adjudicate.ps1 +++ b/scripts/coord/claim-adjudicate.ps1 @@ -65,7 +65,19 @@ unmerged commits is reported as blocking, never as available. * A LANDING PHRASE IN AN OPEN BANNER (BACKLOG #5480 item 1). The do-not-rebuild phrases - supersede only the #1010 shape above; Get-BannerState states the rule and its reason. + supersede only where no line of the banner run carries an OPEN status symbol anywhere and no + banner line opens with a symbol this tool does not know; Get-BannerState states the rule and + its reason. An item marked open only + in words is the #1010 shape to this test, so at least a `**PARTIAL**` banner with no status + symbol and a landing phrase supersedes, as on origin/main. + + A HOLD THE LEDGER ROW MUST CLEAR (BACKLOG #5480). A banner-shaped line that opens with a symbol + outside the status and decoration lists holds the item, whatever else the banner says, because + a status the vault adds later is likelier open than closed. Its BLOCKING line names the symbol + and says to correct the ledger row: give it a status this grammar knows, or, where the vault + has adopted the symbol as a status, add it to the lists here and in owed_ledger_acts.py. The + same remedy is printed for the other holds that are not a plain OPEN: an open symbol only in + the banner's prose, no status at all, and copies or readings of the item that disagree. A STALE LEDGER (BACKLOG #5480 items 5 and 10). A ledger checkout that has not fetched errs BOTH ways: a banner it has not fetched reads as absent, which holds a claim that is safe to release, @@ -75,9 +87,16 @@ names that commit as main of origin's URL, so a fetch into a vault nobody merged to since still counts and the remedy is the fetch, not a wider bound. Both older than -LedgerMaxAgeHours (24 by default) refuses, and so does a commit dated more than an hour in the future with no such - fetch, since its age cannot be read. It also refuses a -LedgerRepo that shares a root commit - with this repository or carries its package, since a clone of it from before 2026-09-13 still - carries a full, stale ledger. + fetch, since its age cannot be read. These two readings bound staleness from below and do not + prove a recent read: at least `git fetch --append` refreshes FETCH_HEAD's time while keeping an + older `main` line. The age is checked only after the corpus admits an item heading, so a stub + refuses as a stub first. + + It also refuses a -LedgerRepo that shares a root commit with this repository, since a clone of + it from before 2026-09-13 still carries a full, stale ledger; and one that carries this + repository's package, messagefoundry/__init__.py, which is either such a clone (pass a vault + checkout instead) or a vault checkout last fetched before 2026-09-26, when the vault still + carried the package (fetch it). WHY THERE IS NO -Apply. `claim.ps1` owns the .history ledger: it writes the record BEFORE removing the file and refuses the release if the record cannot be written (BACKLOG #1068). A @@ -267,67 +286,43 @@ else { $ledgerRef = $ledgerPinned.Ref; $ledgerSha = $ledgerPinned.Sha # --------------------------------------------------------------------------------------------- -# IS IT THE LEDGER, AND IS IT RECENT (BACKLOG #5480 item 10). +# IS IT THE LEDGER (BACKLOG #5480 item 10). # # NOT THIS REPOSITORY. A clone of this repository that last fetched before 2026-09-13 still carries -# the full ledger on its origin/main, with real item headings, only stale. The age bound below +# the full ledger on its origin/main, with real item headings, only stale. The age bound further on # refuses it at its default; this check is what refuses it once that bound has been widened. Two # signs, because neither alone holds: a shared root commit, which a SHALLOW clone hides (its roots # are its shallow boundary, and vault checkouts are shallow in use), and this repository's own -# package at the pinned commit, which every engine commit carries. It proves the checkout is not -# this repository; it does not prove which repository it is, and the item-heading admission below -# is what refuses one that holds no ledger at all. -# -# NOT STALE. The rule and its reason are .NOTES' "A STALE LEDGER"; the code below is its only copy. +# package at the pinned commit, which every engine commit carries. The root sign names this +# repository. The package sign does not: the vault carried the package too until 2026-09-26, so a +# vault checkout last fetched before then carries it as well, and that refusal names both causes +# and a remedy for each. Passing both proves the checkout is neither; it does not prove which +# repository it is, and the item-heading admission below is what refuses one that holds no ledger. +# The age bound runs after that admission; see IS IT RECENT below. # --------------------------------------------------------------------------------------------- if ($LedgerRepo) { $engineRoots = @(Invoke-NamespaceGit $repo @('rev-list', '--max-parents=0', $mainSha) "the root commits of $mainRef in $repo" "not read" $engineConsequence) $ledgerRoots = @(Invoke-NamespaceGit $ledgerRoot @('rev-list', '--max-parents=0', $ledgerSha) "the root commits of $ledgerRef ($ledgerSha) in $ledgerRoot" "not read") $shared = @($ledgerRoots | Where-Object { $_ -and ($engineRoots -ccontains $_) }) $package = @(Invoke-NamespaceGit $ledgerRoot @('ls-tree', '--name-only', $ledgerSha, '--', 'messagefoundry/__init__.py') "the tree of $ledgerRef ($ledgerSha) in $ledgerRoot" "not read") - $sign = if ($shared.Count) { "shares root commit $($shared[0]) with this repository" } - elseif (@($package | Where-Object { $_ }).Count) { "carries this repository's package, messagefoundry/__init__.py, at $ledgerSha" } - else { "" } - if ($sign) { - throw ("-LedgerRepo $ledgerRoot $sign, so it is a checkout of this repository and not of the " + - "ledger's. Its backlog files are this repository's stub, or a ledger copy from before " + - "2026-09-13 that nothing keeps current. Refusing rather than adjudicate against it.$remedy") + if ($shared.Count) { + throw ("-LedgerRepo $ledgerRoot shares root commit $($shared[0]) with this repository, so it is " + + "a checkout of this repository and not of the ledger's. Its backlog files are this " + + "repository's stub, or a ledger copy from before 2026-09-13 that nothing keeps current. " + + "Refusing rather than adjudicate against it.$remedy") } -} -# --no-show-signature: a `log.showSignature` setting otherwise prints gpg lines before the date. -$ledgerStamp = (@(Invoke-NamespaceGit $ledgerRoot @('log', '-1', '--no-show-signature', '--format=%ct', $ledgerSha) "the commit date of $ledgerRef ($ledgerSha) in $ledgerRoot" "not read") -join '').Trim() -if ($ledgerStamp -notmatch '^\d+$') { - throw "could not read the commit date of $ledgerRef ($ledgerSha) in ${ledgerRoot}: git printed '$ledgerStamp'. Refusing rather than adjudicate against a ledger of unknown age." -} -$nowSec = [DateTimeOffset]::UtcNow.ToUnixTimeSeconds() -$commitAgeHours = ($nowSec - [long]$ledgerStamp) / 3600.0 -# FETCH_HEAD is per worktree, so this reads the fetch made in THIS checkout. A line counts only where -# it names the pinned commit as `main` of ORIGIN's URL, spelled as git writes it there (credentials, -# trailing slashes and `.git` dropped): a fetch of another branch, or of another remote whose main -# happens to sit at the same commit, says nothing of when origin was last read. -$fetchAgeHours = $null -$fetchHead = (@(Invoke-NamespaceGit $ledgerRoot @('rev-parse', '--path-format=absolute', '--git-path', 'FETCH_HEAD') "the FETCH_HEAD path of $ledgerRoot" "not read") -join '').Trim() -$originUrl = "$(& git -C $ledgerRoot remote get-url origin 2>$null)".Trim() -$originUrl = (($originUrl -replace '^([a-z][a-z0-9+.-]*://)[^/@]*@', '$1') -replace '/+$', '') -replace '\.git$', '' -if ($originUrl -and $fetchHead -and (Test-Path -LiteralPath $fetchHead -PathType Leaf)) { - $want = [regex]::Escape($ledgerSha) + "\t[^\t]*\tbranch 'main' of " + [regex]::Escape($originUrl) + '$' - $named = @(Get-Content -LiteralPath $fetchHead -Encoding utf8 | Where-Object { $_ -cmatch "^$want" }) - if ($named.Count) { - $fetchAgeHours = ($nowSec - [DateTimeOffset]::new((Get-Item -LiteralPath $fetchHead).LastWriteTimeUtc).ToUnixTimeSeconds()) / 3600.0 + if (@($package | Where-Object { $_ }).Count) { + # TWO CAUSES, AND EACH HAS ITS OWN REMEDY (BACKLOG #5480, Lander hold on 64695101cd3). The vault + # carried this package too until 2026-09-26, so the sign alone cannot tell the two apart. + throw ("-LedgerRepo $ledgerRoot carries this repository's package, messagefoundry/__init__.py, " + + "at $ledgerRef ($ledgerSha). Either it is a checkout of this repository (an engine " + + "checkout), whose backlog files are its stub or a ledger copy from before 2026-09-13 that " + + "nothing keeps current: pass a checkout of the ledger repository (the vault) as -LedgerRepo " + + "instead. Or it is a vault checkout last fetched before 2026-09-26, when the vault still " + + "carried that package: run 'git -C `"$ledgerRoot`" fetch origin' and adjudicate again. " + + "Refusing rather than adjudicate against it.") } } -$recent = { param($age) ($null -ne $age) -and ($age -ge -1) -and ($age -le $LedgerMaxAgeHours) } -if (-not ((& $recent $commitAgeHours) -or (& $recent $fetchAgeHours))) { - $when = [DateTimeOffset]::FromUnixTimeSeconds([long]$ledgerStamp).UtcDateTime.ToString('yyyy-MM-ddTHH:mm:ssZ') - $age = if ($commitAgeHours -lt -1) { "dated $([Math]::Floor(-$commitAgeHours)) hours in the FUTURE, so its age cannot be read" } - else { "$([Math]::Floor($commitAgeHours)) hours ago, past -LedgerMaxAgeHours $LedgerMaxAgeHours" } - $fetched = if ($null -eq $fetchAgeHours) { "and this checkout's FETCH_HEAD does not name it as main" } - else { "and this checkout last fetched it $([Math]::Floor($fetchAgeHours)) hours ago" } - throw ("the ledger at $ledgerRef ($ledgerSha) in $ledgerRoot was committed $when, $age, $fetched. " + - "A stale ledger can show a since-reopened item CLOSED and print a release line for open work. " + - "Run 'git -C `"$ledgerRoot`" fetch origin' and adjudicate again: a fetch in that checkout counts " + - "even where nobody has merged since, so a larger -LedgerMaxAgeHours should not be needed.$remedy") -} # --------------------------------------------------------------------------------------------- # THE BACKLOG NAMESPACE ON $ledgerRef OF $ledgerRoot. @@ -366,7 +361,8 @@ if (-not $backlogFiles.Count) { # # TWO READINGS, AND A RELEASE NEEDS BOTH (BACKLOG #5480, Manager repair after review round three). # -# RAW is origin/main's reading: the text split on `\n` only, PowerShell's blank test, and a key that +# RAW is origin/main's reading: git's output as PowerShell splits it into lines -- at `\n`, `\r\n` +# and a lone `\r` (measured 2026-11-29), rejoined on `\n` -- PowerShell's blank test, and a key that # matches a heading's digits exactly as written. NORMALISED is owed_ledger_acts.py's: Python's # splitlines() breaks (U+2028, U+2029, U+0085, \v, \f, \x1c-\x1e, as well as \r and \n) turned into # `\n` once at load, Python's blank test, and headings keyed by numeric value. @@ -378,7 +374,12 @@ if (-not $backlogFiles.Count) { # NO-ITEM -- and the normalised reading may only ADD copies and lines that hold. An item supersedes # only when every copy in BOTH readings protects it. $LINE_BREAK = [regex]'\r\n|[\n\r\v\f\x1c\x1d\x1e\x85

]' -$loaded = @{ raw = [ordered]@{}; norm = [ordered]@{} } +# KEYED ORDINALLY, as git names a path (BACKLOG #5480, Lander hold on 64695101cd3). PowerShell's own +# tables fold case, so of two files whose names differ only in case the second overwrote the first +# here, and an archive copy reading OPEN vanished behind a same-named file holding no item: a release +# origin/main, which admitted only files holding an item heading, did not print. +function New-OrdinalMap { [System.Collections.Specialized.OrderedDictionary]::new([StringComparer]::Ordinal) } +$loaded = @{ raw = (New-OrdinalMap); norm = (New-OrdinalMap) } foreach ($bf in $backlogFiles) { $text = (Invoke-NamespaceGit $ledgerRoot @('show', "${ledgerSha}:$bf") "${ledgerRef}:$bf in $ledgerRoot" "only partly read") -join "`n" $loaded.raw[$bf] = $text @@ -403,16 +404,19 @@ foreach ($bf in $backlogFiles) { # # KEYED BY THE NUMBER IN THE NORMALISED READING, BY ITS SPELLING IN THE RAW ONE. owed_ledger_acts.py # keys a row by int(), so `## 079.` and `## 79.` are copies of one row there; the normalised index -# reads each digit as its value, as int() does for a non-ASCII decimal digit, and drops leading -# zeros. The raw index keeps the digits as written, origin/main's key, so a spelling origin/main -# never matched cannot make a key resolve. +# reads each digit as its value, as int() does for a decimal digit in the Basic Multilingual Plane, +# and drops leading zeros. The raw index keeps the digits as written, origin/main's key, so a +# spelling origin/main never matched cannot make a key resolve. .NET's `\d` matches one UTF-16 unit, +# so at least a heading spelled in decimal digits outside that plane is indexed in neither reading +# while int() reads it: that copy is never judged, and the key can supersede on its other copies, as +# on origin/main, which does not read it either. function ConvertTo-ItemNumber([string]$Digits) { $t = (-join @(foreach ($c in $Digits.ToCharArray()) { [int][char]::GetNumericValue($c) })).TrimStart('0') if ($t) { $t } else { '0' } } $heading = [regex]'(?m)^##\s(?:\s*(?\d+)\.\s)?' $itemIndex = @{} -$corpus = @{ raw = @{}; norm = @{} } +$corpus = @{ raw = (New-OrdinalMap); norm = (New-OrdinalMap) } foreach ($mode in 'raw', 'norm') { $itemIndex[$mode] = [System.Collections.Generic.Dictionary[string, System.Collections.Generic.List[object]]]::new([StringComparer]::Ordinal) foreach ($f in $loaded[$mode].Keys) { @@ -452,6 +456,72 @@ if (-not $corpus.raw.Count) { } $corpusFiles = @($corpus.raw.Keys | Sort-Object) +# IS IT RECENT (BACKLOG #5480 item 10). The rule and its reason are .NOTES' "A STALE LEDGER"; the +# code below is its only copy. It runs only after the refusals above, so a namespace with no item +# heading -- this repository's stub, with no -LedgerRepo -- gets the answer that points to the vault +# first, not a fetch that would only lead back to it (Lander hold on 64695101cd3). +# --no-show-signature: a `log.showSignature` setting otherwise prints gpg lines before the date. +$ledgerStamp = (@(Invoke-NamespaceGit $ledgerRoot @('log', '-1', '--no-show-signature', '--format=%ct', $ledgerSha) "the commit date of $ledgerRef ($ledgerSha) in $ledgerRoot" "not read") -join '').Trim() +if ($ledgerStamp -notmatch '^\d+$') { + throw "could not read the commit date of $ledgerRef ($ledgerSha) in ${ledgerRoot}: git printed '$ledgerStamp'. Refusing rather than adjudicate against a ledger of unknown age." +} +$nowSec = [DateTimeOffset]::UtcNow.ToUnixTimeSeconds() +$commitAgeHours = ($nowSec - [long]$ledgerStamp) / 3600.0 +# FETCH_HEAD is per worktree, so this reads the fetch made in THIS checkout. A line counts only where +# it names the pinned commit as `main` of ORIGIN's URL, spelled as git writes it there: a fetch of +# another branch, or of another remote whose main happens to sit at the same commit, says nothing of +# when origin was last read. The file's time is the age, so this is a floor on staleness, not proof +# of a recent read: at least `git fetch --append` keeps an earlier `main` line and refreshes the +# file's time, so a `main` line from an old fetch can read as recent. +# +# GIT'S OWN SPELLING (BACKLOG #5480, Lander hold on 64695101cd3). builtin/fetch.c writes the URL +# through transport_anonymize_url(), then drops trailing slashes and a `.git` suffix. Anonymising +# drops everything up to the first `@`: in a URL with a `://` scheme where no `/` comes before that +# `@`, and in one with no `://` (scp-style `user@host:path`) where a `:` follows the `@` and the URL +# is not a local path. The suffix strip is case-sensitive, so a `.GIT` suffix stays. A spelling that +# differs from git's only refuses (the remedy then fails), never releases. +function ConvertTo-FetchHeadUrl([string]$Url) { + $at = $Url.IndexOf([char]'@') + $colon = $Url.IndexOf([char]':'); $slash = $Url.IndexOf([char]'/') + $local = ($colon -lt 0) -or ($slash -ge 0 -and $slash -lt $colon) -or ($IsWindows -and $Url -cmatch '^[A-Za-z]:') + if ($at -ge 0 -and -not $local) { + $scheme = $Url.IndexOf('://', [StringComparison]::Ordinal) + if ($scheme -lt 0) { + if ($Url.IndexOf([char]':', $at + 1) -ge 0) { $Url = $Url.Substring($at + 1) } + } + elseif ($Url.Substring(0, $scheme) -cmatch '^[A-Za-z0-9+.-]*$') { + $after = $Url.IndexOf([char]'/', $scheme + 3) + if ($after -lt 0 -or $after -gt $at) { $Url = $Url.Substring(0, $scheme + 3) + $Url.Substring($at + 1) } + } + } + $Url = $Url.TrimEnd('/') + if ($Url.Length -gt 5 -and $Url.EndsWith('.git', [StringComparison]::Ordinal)) { $Url = $Url.Substring(0, $Url.Length - 4) } + $Url +} +$fetchAgeHours = $null +$fetchHead = (@(Invoke-NamespaceGit $ledgerRoot @('rev-parse', '--path-format=absolute', '--git-path', 'FETCH_HEAD') "the FETCH_HEAD path of $ledgerRoot" "not read") -join '').Trim() +$originUrl = "$(& git -C $ledgerRoot remote get-url origin 2>$null)".Trim() +if ($originUrl) { $originUrl = ConvertTo-FetchHeadUrl $originUrl } +if ($originUrl -and $fetchHead -and (Test-Path -LiteralPath $fetchHead -PathType Leaf)) { + $want = [regex]::Escape($ledgerSha) + "\t[^\t]*\tbranch 'main' of " + [regex]::Escape($originUrl) + '$' + $named = @(Get-Content -LiteralPath $fetchHead -Encoding utf8 | Where-Object { $_ -cmatch "^$want" }) + if ($named.Count) { + $fetchAgeHours = ($nowSec - [DateTimeOffset]::new((Get-Item -LiteralPath $fetchHead).LastWriteTimeUtc).ToUnixTimeSeconds()) / 3600.0 + } +} +$recent = { param($age) ($null -ne $age) -and ($age -ge -1) -and ($age -le $LedgerMaxAgeHours) } +if (-not ((& $recent $commitAgeHours) -or (& $recent $fetchAgeHours))) { + $when = [DateTimeOffset]::FromUnixTimeSeconds([long]$ledgerStamp).UtcDateTime.ToString('yyyy-MM-ddTHH:mm:ssZ') + $age = if ($commitAgeHours -lt -1) { "dated $([Math]::Floor(-$commitAgeHours)) hours in the FUTURE, so its age cannot be read" } + else { "$([Math]::Floor($commitAgeHours)) hours ago, past -LedgerMaxAgeHours $LedgerMaxAgeHours" } + $fetched = if ($null -eq $fetchAgeHours) { "and this checkout's FETCH_HEAD does not name it as main" } + else { "and this checkout last fetched it $([Math]::Floor($fetchAgeHours)) hours ago" } + throw ("the ledger at $ledgerRef ($ledgerSha) in $ledgerRoot was committed $when, $age, $fetched. " + + "A stale ledger can show a since-reopened item CLOSED and print a release line for open work. " + + "Run 'git -C `"$ledgerRoot`" fetch origin' and adjudicate again: a fetch in that checkout counts " + + "even where nobody has merged since, so a larger -LedgerMaxAgeHours should not be needed.$remedy") +} + # The status vocabulary is backlog_status_check.py's, not this file's, restated as # owed_ledger_acts.py restates it; tests/test_coord_claim_adjudicate.py holds the codepoints equal to # that file's. Held as codepoints so the source stays readable on a console that cannot render them, @@ -482,11 +552,14 @@ foreach ($cp in @(0x26A0, 0x1F6E0, 0x1F4CC, 0x1F4D0, 0x2B06, 0x1F50E, 0x1F7E2, 0 # # ONE LINE AT A TIME (item 4). `\s` matches a newline too, so a CLOSED glyph alone on its line read # as a status off the line below it; owed_ledger_acts.py matches one line at a time and does not. -# This reads the lines the corpus load normalised, one at a time. Before the glyph, any whitespace -# counts, as in that file's `^>\s` (no line break is left inside a line to match). After a CLOSED -# glyph only a space or a tab does, stricter than that file in the holding direction. An OPEN glyph -# opening a line holds the item whatever follows it, indented or not, since an open status misread -# costs a stale claim and a closed one misread costs a duplicate build. +# This reads one line at a time, in each reading. Between `>` and the glyph, .NET's `\s` counts, +# which is narrower than Python's `\s` in that file's `^>\s`: at least \x1f is whitespace to Python +# and not here. So at least a line opening `>`, \x1f and a status glyph is no status line here where +# it is one there: an OPEN glyph on it still blocks a landing phrase as prose, but beside a CLOSED +# status line the item supersedes, as on origin/main, which reads `^>\s` with .NET's `\s` too. +# After a CLOSED glyph only a space or a tab does, stricter than that file in the holding +# direction. An OPEN glyph opening a line holds the item whatever follows it, indented or not, since +# an open status misread costs a stale claim and a closed one misread costs a duplicate build. $BANNER_SHAPE = [regex]'^(?\s*)>\s(?[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\x00-\x7F])\uFE0F?(?[ \t])?' # Blank, per reading. NORMALISED: as Python's strip() reads it, .NET whitespace plus \x1f, which @@ -554,7 +627,11 @@ function Get-BannerState([string]$Block, [string]$Mode) { # A SYMBOL THIS COPY OF THE GRAMMAR DOES NOT KNOW HOLDS THE ITEM (item 3). owed_ledger_acts.py # reads a banner-shaped line opening with an unknown symbol as a status it cannot judge, and # never reads that row CLOSED; a status the vault adds later is far likelier an open one than not. - # Here it blocks the landing phrase as well, for item 1's reason. + # Here it blocks the landing phrase as well, for item 1's reason. The symbol is one in Unicode's + # Other Symbol category on a banner-shaped line, outside the status and decoration lists. Its + # BLOCKING line names it and says to correct the ledger row: give the row a status this grammar + # knows, or, where the vault has adopted a new status symbol, add it to the lists here and in + # owed_ledger_acts.py, which tests/test_coord_claim_adjudicate.py holds equal. # # WHERE owed_ledger_acts.py STOPS, A CLOSED LINE STOPS COUNTING. Its banner block is the blank # lines and the lines starting `>` under the heading, and the first other line ends it -- an @@ -799,9 +876,40 @@ foreach ($f in $files) { elseif ($parts.Count -gt 1) { "'$branch' carries " + (@($parts | ForEach-Object { "$($_.Text) at $($_.Ref)" }) -join ' and ') } elseif ($parts[0].Zero) { "'$branch' carries no commit $mainRef lacks" } else { "'$branch' carries $($parts[0].Text)" } + # EACH KEY SAYS WHAT HOLDS IT (BACKLOG #5480, Lander hold on 64695101cd3). The copies note is + # this key's own and names each file's state, so a branch roll-up cannot lend one key's copies + # to another. A PLAIN OPEN is every copy, in both readings, on an OPEN status line: the claim + # is doing its job there, and the branch decision applies. Every other hold -- an unknown + # symbol, an open symbol only in prose, no status at all, or copies and readings that + # disagree -- is a ledger row that does not read as one status. Its text names the cause and + # the remedy, correcting the row, and says nothing about the work or the branch. + $byFile = New-OrdinalMap + foreach ($j in $judged) { + if (-not $byFile.Contains($j.File)) { $byFile[$j.File] = [System.Collections.Generic.List[string]]::new() } + if (-not $byFile[$j.File].Contains($j.State)) { $byFile[$j.File].Add($j.State) } + } + $perFile = @(foreach ($cf in $byFile.Keys) { "$cf reads " + ($byFile[$cf] -join ' in one reading and ') }) + $copiesOwn = if ($nCopies -gt 1) { " (the item stands $nCopies times: " + ($perFile -join '; ') + "; every copy is read)" } else { "" } + $odd = @($judged | Where-Object { $_.State -cnotlike 'OPEN/*' }) + $plain = -not $odd.Count + $tail = "so the key is unclaimable by any future session while nothing on $ledgerAt protects it" + if (-not $plain) { + $cause = if (@($judged | ForEach-Object State | Select-Object -Unique).Count -gt 1) { + "its copies or readings disagree (" + ($perFile -join '; ') + "), and a release needs every one to protect the item" + } elseif ($odd[0].State -clike 'UNKNOWN-STATUS/*') { + "a banner line opens with $($odd[0].State.Substring(15)), a symbol outside this tool's status and decoration lists, which holds the item whatever else the banner says" + } elseif ($odd[0].State -clike 'OPEN-IN-PROSE/*') { + "an open status symbol stands in the banner's prose with no status line this tool counts, which blocks a landing phrase" + } else { + "no copy carries a status line or a landing phrase this tool counts" + } + $tail = "$cause. Correct the ledger row on $ledgerAt so every copy carries the item's status in a line the ledger grammar reads, then adjudicate again" + } + $own = "reads $($holding[0].State) in $($holding[0].File) on $ledgerAt$copiesOwn" $rows += [pscustomobject]@{ key = $k; holder = $holder; branch = $branch; note = $note item = $holding[0].File; banner = $holding[0].State; citations = $cites; verdict = "BLOCKING" - why = "item reads $($holding[0].State) on $ledgerAt and $aheadTxt -- so the key is unclaimable by any future session while nothing on $ledgerAt protects it$copies" } + why = "item $own and $aheadTxt -- $tail" + _own = $own; _ahead = $aheadTxt; _plain = $plain; _tail = $tail } } } @@ -833,7 +941,8 @@ if ($Json) { elsewhere = @($rows | Where-Object verdict -eq 'ELSEWHERE').Count other = @($rows | Where-Object { $_.verdict -in @('UNREADABLE', 'STRANDED-REGISTERED') }).Count } - claims = $rows + # The underscored fields carry the roll-up's pieces of `why`; the document keeps its shape. + claims = @($rows | Select-Object -Property * -ExcludeProperty _own, _ahead, _plain, _tail) } | ConvertTo-Json -Depth 6 exit 0 } @@ -865,7 +974,7 @@ $hld = @($rows | Where-Object verdict -eq 'HELD') $els = @($rows | Where-Object verdict -eq 'ELSEWHERE') Write-Host "SUPERSEDED $($sup.Count) -- origin/main already protects the item; the claim adds nothing and can go" -ForegroundColor Green -Write-Host "BLOCKING $($blk.Count) -- nothing on origin/main protects the item, so the key is stuck: unclaimable AND unbuilt" -ForegroundColor Yellow +Write-Host "BLOCKING $($blk.Count) -- not every copy of the item protects it on $ledgerRef, so the claim stays; each key below says what holds it" -ForegroundColor Yellow Write-Host "NO-ITEM $($nit.Count) -- key is outside the backlog namespace; this instrument does not reach it" if ($oth.Count) { Write-Host "OTHER $($oth.Count) -- unreadable, or a half-finished removal prune-merged.ps1 owns" } if ($hld.Count) { Write-Host "HELD $($hld.Count) -- holder exists; not adjudicated" } @@ -888,8 +997,14 @@ if ($blk.Count) { Write-Host "-- BLOCKING, grouped by branch: the decision is per BRANCH, not per key ---------" -ForegroundColor Yellow # The roll-up is the point. Twenty stranded keys were six branch decisions on 2026-08-18, and a # per-key list hides that one "land it or abandon it" call clears nine of them at once. - # The why-string's "item reads on and" lead, stripped from both listings below. - $whyLead = '^item reads .+? on \S+ and ' + # EACH KEY ON ITS OWN LINE, with its own state, file and copies (BACKLOG #5480, Lander hold on + # 64695101cd3): printing the first key's sentence for the whole branch lent one key's copies and + # state to the others. The branch's commit count is the branch's, so it prints once. + $keyLines = { + param($r, [string]$Lead) + Write-Host (" {0,-18} {1}" -f $r.key, $(if ($Lead) { "$Lead; item $($r._own)" } else { $r._own })) + if (-not $r._plain) { Write-Host (" {0,-18} {1}" -f "", $r._tail) } + } # A claim that records no branch has no branch decision, so those keys are never grouped into one # (BACKLOG #7563): each is listed on its own below. foreach ($grp in ($blk | Where-Object branch | Group-Object branch | Sort-Object Count -Descending)) { @@ -897,14 +1012,23 @@ if ($blk.Count) { $plural = if ($grp.Count -eq 1) { "" } else { "s" } Write-Host (" {0}" -f $grp.Name) -ForegroundColor Yellow Write-Host (" {0} key{1}: {2}" -f $grp.Count, $plural, $keys) - Write-Host (" {0}" -f ($grp.Group[0].why -replace $whyLead, '')) - Write-Host (" one decision for the branch -- land it, or abandon it and release all {0}." -f $grp.Count) + Write-Host (" {0}" -f $grp.Group[0]._ahead) + foreach ($r in ($grp.Group | Sort-Object key)) { & $keyLines $r "" } + # The branch decision covers only the keys a plain OPEN holds; the others wait on their row. + $open = @($grp.Group | Where-Object { $_._plain } | ForEach-Object { $_.key } | Sort-Object) + if ($open.Count -eq $grp.Count) { + Write-Host (" one decision for the branch -- land it, or abandon it and release all {0}." -f $grp.Count) + } + elseif ($open.Count) { + Write-Host (" for the {0} key(s) that read OPEN ({1}), one decision for the branch -- land it, or abandon it and release them; the others wait on their ledger row." -f $open.Count, ($open -join ', ')) + } + else { Write-Host " no branch decision until each ledger row above is corrected." } Write-Host "" } $noBranch = @($blk | Where-Object { -not $_.branch }) if ($noBranch.Count) { Write-Host " (no branch recorded) -- no branch decision applies; adjudicate each key on its own" -ForegroundColor Yellow - foreach ($r in $noBranch) { Write-Host (" {0,-18} {1}" -f $r.key, ($r.why -replace $whyLead, '')) } + foreach ($r in $noBranch) { & $keyLines $r $r._ahead } Write-Host "" } } diff --git a/tests/test_coord_claim_adjudicate.py b/tests/test_coord_claim_adjudicate.py index f2c4c3698f..25f58335bd 100644 --- a/tests/test_coord_claim_adjudicate.py +++ b/tests/test_coord_claim_adjudicate.py @@ -1592,6 +1592,220 @@ def timed(keys: range) -> float: assert many - one < 2 * one, f"24 more keys cost {many - one:.1f}s against {one:.1f}s for one" +# =================================================================================================== +# BACKLOG #5480: THE LANDER'S HOLD ON 64695101cd3. Each test below that says MUST TRIP fails on the +# script at 64695101cd3 and passes after the repair. +# =================================================================================================== + + +def _commit_blobs(repo: Path, files: dict[str, str]) -> None: + """Commit ``files`` through the index alone and publish. Two paths that differ only in case + cannot both stand in a Windows working tree, but git's tree holds them apart.""" + for rel, text in files.items(): + blob = ( + subprocess.run( + ["git", "-C", str(repo), "hash-object", "-w", "--stdin"], + input=text.encode("utf-8"), + capture_output=True, + check=True, + timeout=TIMEOUT, + ) + .stdout.decode("ascii") + .strip() + ) + git( + repo, + "-c", + "core.ignorecase=false", + "update-index", + "--add", + "--cacheinfo", + f"100644,{blob},{rel}", + ) + git(repo, "commit", "-qm", "files by the index") + git(repo, "push", "-q", "origin", "main") + + +def test_backlog_files_differing_only_in_case_are_each_read(repo: Path, tmp_path: Path) -> None: + """MUST TRIP (hold item 1). PowerShell's tables fold case, so `BACKLOG-old.md`, holding no item, + overwrote `BACKLOG-OLD.md`, whose copy of item 7 reads OPEN, and the live CLOSED copy released + the claim. origin/main admitted only files holding an item heading and printed BLOCKING.""" + backlog(repo, f"## 7. Thing\n\n> {SHIPPED} SHIPPED\n\nbody\n") + unmerged_branch(repo, "seat") + _commit_blobs( + repo, + { + "docs/archive/backlog/BACKLOG-OLD.md": ( + f"# Old\n\n## 7. Thing\n\n> {PRIORITIZED} reopened\n\nbody\n" + ), + "docs/archive/backlog/BACKLOG-old.md": "# Notes\n\nNo item here.\n", + }, + ) + names = git(repo, "ls-tree", "-r", "--name-only", "origin/main", "--", "docs/archive/backlog/") + assert len(names.split()) == 2, names + write_claim(repo, "7", tmp_path / "gone", "seat") + r = rows(repo)["7"] + assert r["verdict"] == "BLOCKING", r + assert r["banner"] == "OPEN/prioritized", r + assert r["item"] == "docs/archive/backlog/BACKLOG-OLD.md", r + + +_FAKE_SSH = ( + "import os, subprocess, sys\n" + "sys.exit(subprocess.call(['git', 'upload-pack', os.environ['FAKE_SSH_REPO']]))\n" +) + + +@pytest.mark.parametrize( + "form", + [ + # MUST TRIP: git's FETCH_HEAD drops the `user@` of an scp-style URL. + "scp-user", + # MUST TRIP: git drops a `.git` suffix case-sensitively, so a `.GIT` suffix stays. + "upper-git", + # Controls the old normalisation already matched. + "scp-no-user", + "ssh-scheme-user", + "local-trailing-slash", + ], +) +def test_fetch_head_counts_for_each_origin_form( + repo: Path, vault: Path, tmp_path: Path, form: str +) -> None: + """Hold item 2. The stale-ledger refusal tells the reader to fetch, and a real fetch must then + count however origin is spelled; for these forms the refusal came back after its own remedy. + Each fetch is real: the ssh forms run through a stand-in for ssh serving the vault's origin.""" + backlog(repo, STUB) + write_claim(repo, "60", tmp_path / "gone", "seat") + _dated_commit( + vault, + "docs/BACKLOG.md", + f"# Backlog\n\n## 60. Shipped thing\n\n> {SHIPPED} SHIPPED\n\nbody\n", + "2026-01-01T00:00:00Z", + ) + origin = tmp_path / "vault-origin.git" + url = { + "scp-user": "git@fakehost.invalid:org/ledger.git", + "upper-git": str(tmp_path / "vault-origin.GIT"), + "scp-no-user": "fakehost.invalid:org/ledger.git", + "ssh-scheme-user": "ssh://git@fakehost.invalid/org/ledger.git", + "local-trailing-slash": str(origin) + "/", + }[form] + proc = adjudicate(repo, "-Json", "-LedgerRepo", str(vault)) + assert proc.returncode != 0, proc.stdout + assert "fetch origin" in _flat(proc.stderr), proc.stderr + + git(vault, "remote", "set-url", "origin", url) + fake = tmp_path / "fake_ssh.py" + fake.write_text(_FAKE_SSH, encoding="utf-8") + env = dict( + os.environ, + GIT_SSH_COMMAND=f'"{Path(sys.executable).as_posix()}" "{fake.as_posix()}"', + GIT_SSH_VARIANT="simple", + FAKE_SSH_REPO=str(origin), + ) + subprocess.run( + ["git", "-C", str(vault), "fetch", "-q", "origin"], + check=True, + capture_output=True, + timeout=TIMEOUT, + env=env, + ) + fetch_head = (vault / ".git" / "FETCH_HEAD").read_text(encoding="utf-8") + assert "branch 'main' of" in fetch_head, fetch_head + proc = adjudicate(repo, "-Json", "-LedgerRepo", str(vault)) + assert proc.returncode == 0, (fetch_head, proc.stderr) + assert {c["key"]: c["verdict"] for c in json.loads(proc.stdout)["claims"]}["60"] == "SUPERSEDED" + + +def test_the_package_refusal_names_both_causes_and_a_remedy_for_each( + repo: Path, vault: Path, tmp_path: Path +) -> None: + """MUST TRIP (hold item 3). The vault carried this repository's package until 2026-09-26, so a + vault checkout last fetched before then carries it too, and fetching is its remedy. The refusal + called every such checkout an engine checkout.""" + backlog(repo, STUB) + write_claim(repo, "60", tmp_path / "gone", "seat") + _publish(vault, "messagefoundry/__init__.py", "") + proc = adjudicate(repo, "-Json", "-LedgerRepo", str(vault)) + combined = _flat(proc.stderr + proc.stdout) + assert proc.returncode != 0, combined + assert "carries this repository's package" in combined, combined + assert "an engine checkout" in combined, combined + assert "before 2026-09-26" in combined, combined + assert "fetch origin" in combined, combined + assert '"claims"' not in proc.stdout, combined + + +def test_a_stale_stub_without_ledger_repo_points_to_the_vault_first( + repo: Path, tmp_path: Path +) -> None: + """MUST TRIP (hold item 4). Without -LedgerRepo and with this repository's main older than the + bound, origin/main's first answer is the stub refusal, which names the vault. The age check ran + first and asked for a fetch, which would only reach the stub refusal.""" + write_claim(repo, "60", tmp_path / "gone", "seat") + _dated_commit(repo, "docs/BACKLOG.md", "# Backlog\n\n" + STUB, "2026-01-01T00:00:00Z") + proc = adjudicate(repo, "-Json") + combined = _flat(proc.stderr + proc.stdout) + assert proc.returncode != 0, combined + assert "no backlog item heading found" in combined, combined + assert "pass -LedgerRepo" in combined, combined + assert "-LedgerMaxAgeHours" not in combined, combined + + +def _key_line(stdout: str, key: str) -> str: + lines = [ln for ln in stdout.splitlines() if re.match(rf"^\s+{key}\s+(?:.*; item )?reads ", ln)] + assert len(lines) == 1, (key, stdout) + return lines[0] + + +def test_each_blocking_key_prints_its_own_state_and_copies(repo: Path, tmp_path: Path) -> None: + """MUST TRIP (hold item 5). Keys 5 and 6 share a branch and only 5 stands twice; the roll-up + printed the first key's sentence for the branch, so it said the item stood twice for both.""" + _publish( + repo, + "docs/archive/backlog/BACKLOG-CLOSED.md", + f"# Closed\n\n## 5. Five\n\n> {PRIORITIZED} open\n\nbody\n", + ) + backlog( + repo, + f"## 5. Five\n\n> {PRIORITIZED} open\n\nbody\n\n## 6. Six\n\n> {IN_PROGRESS} open\n\nbody\n", + ) + unmerged_branch(repo, "seat") + write_claim(repo, "5", tmp_path / "gone", "seat") + write_claim(repo, "6", tmp_path / "gone", "seat") + proc = adjudicate(repo) + assert proc.returncode == 0, proc.stderr + five, six = _key_line(proc.stdout, "5"), _key_line(proc.stdout, "6") + assert "OPEN/prioritized" in five and "stands 2 times" in five, five + assert "OPEN/in progress" in six and "stands" not in six, six + assert proc.stdout.count("stands 2 times") == 1, proc.stdout + assert "release all 2" in proc.stdout, proc.stdout + + +@pytest.mark.parametrize("branch", ["seat", ""]) +def test_a_hold_that_is_not_a_plain_open_names_the_ledger_remedy( + repo: Path, tmp_path: Path, branch: str +) -> None: + """MUST TRIP (hold item 5). A SHIPPED item beside an unknown symbol is held, and the report said + nothing protected it, that it was unbuilt, and to land or abandon the branch. The cause is the + ledger row, and so is the remedy.""" + backlog(repo, f"## 73. Unknown\n\n> {UNKNOWN} a status added later\n> {SHIPPED} SHIPPED\n\nb\n") + if branch: + unmerged_branch(repo, branch) + write_claim(repo, "73", tmp_path / "gone", branch) + r = rows(repo)["73"] + assert r["verdict"] == "BLOCKING", r + assert "U+1F7E5" in r["why"] and "Correct the ledger row" in r["why"], r + assert "nothing on" not in r["why"], r + proc = adjudicate(repo) + assert proc.returncode == 0, proc.stderr + assert "U+1F7E5" in _key_line(proc.stdout, "73"), proc.stdout + assert "Correct the ledger row" in proc.stdout, proc.stdout + for false_text in ("nothing on", "unbuilt", "abandon"): + assert false_text not in proc.stdout, (false_text, proc.stdout) + + def _ps_codepoints(line_marker: str) -> set[str]: """The code points written on the one script line holding ``line_marker``.""" text = ADJUDICATE.read_text(encoding="utf-8") From 467f9379243a0edddeb9b0d3543bc764559aa729 Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Sun, 29 Nov 2026 15:40:31 -0600 Subject: [PATCH 11/14] claim-adjudicate.ps1: review round one on the hold repair BACKLOG #5480, Lander hold on 64695101cd3, code-review round-99005fb472. - An open item with no status, or an open symbol only in prose, keeps the branch decision: only a hold with a protecting copy or an unknown symbol is sent to correct the ledger row. - A file's states are joined plainly, not as "in one reading and", which was false for two headings in one file. - The unknown-symbol hold is documented as Unicode's Other Symbol category only; at least an arrow or a letter is not held on. - A comment naming the removed roll-up strip is gone. Fail-before at 64695101cd3, all new tests: 10 failed, 3 passed (the 3 are origin-form controls). Old-against-new comparison over 76 shapes: 49 same, 27 tighter, 0 looser. Verified-by: tests --- docs/WORKTREES.md | 13 ++++---- scripts/coord/claim-adjudicate.ps1 | 49 +++++++++++++--------------- tests/test_coord_claim_adjudicate.py | 30 +++++++++++++++++ 3 files changed, 60 insertions(+), 32 deletions(-) diff --git a/docs/WORKTREES.md b/docs/WORKTREES.md index cd690c238e..45c353f5ac 100644 --- a/docs/WORKTREES.md +++ b/docs/WORKTREES.md @@ -1119,12 +1119,13 @@ question is not whether the work finished but whether something durable has repl > already protects it — a CLOSED status glyph, or a do-not-rebuild banner naming the landing. A do-not-rebuild banner does not count where any line of the banner carries an OPEN status symbol, -or a banner line opens with a symbol the script does not know. It still counts where neither -stands, so at least an item marked open only in words, such as `**PARTIAL**` with no status symbol, -supersedes on it. An item whose number stands more than once supersedes only when every copy -protects it. A banner line opening with an unknown symbol holds the item; the report names the -symbol and says to correct the ledger row, or to add the symbol to the script's lists where the -vault has adopted it as a status. The script's `Get-BannerState` and its item index state the +or a banner line opens with an unknown symbol in Unicode's Other Symbol category (most emoji). It +still counts where neither stands, so at least an item marked open only in words, such as +`**PARTIAL**` with no status symbol, supersedes on it. An item whose number stands more than once +supersedes only when every copy protects it. A banner line opening with such an unknown symbol +holds the item; the report names the symbol and says to correct the ledger row, or to add the +symbol to the script's lists where the vault has adopted it as a status. An unknown symbol of +another category, at least an arrow or a letter, is not held on. The script's `Get-BannerState` and its item index state the exact rules (BACKLOG #5480, items 1 to 3). Nothing else is ever proposed for release. Not age, not quiet, not a note saying the work is done. diff --git a/scripts/coord/claim-adjudicate.ps1 b/scripts/coord/claim-adjudicate.ps1 index 817bf947ca..b8aa085e60 100644 --- a/scripts/coord/claim-adjudicate.ps1 +++ b/scripts/coord/claim-adjudicate.ps1 @@ -66,18 +66,18 @@ * A LANDING PHRASE IN AN OPEN BANNER (BACKLOG #5480 item 1). The do-not-rebuild phrases supersede only where no line of the banner run carries an OPEN status symbol anywhere and no - banner line opens with a symbol this tool does not know; Get-BannerState states the rule and - its reason. An item marked open only - in words is the #1010 shape to this test, so at least a `**PARTIAL**` banner with no status - symbol and a landing phrase supersedes, as on origin/main. + banner line opens with an unknown symbol (below); Get-BannerState states the rule and its + reason. An item marked open only in words is the #1010 shape to this test, so at least a + `**PARTIAL**` banner with no status symbol and a landing phrase supersedes, as on origin/main. A HOLD THE LEDGER ROW MUST CLEAR (BACKLOG #5480). A banner-shaped line that opens with a symbol - outside the status and decoration lists holds the item, whatever else the banner says, because - a status the vault adds later is likelier open than closed. Its BLOCKING line names the symbol - and says to correct the ledger row: give it a status this grammar knows, or, where the vault - has adopted the symbol as a status, add it to the lists here and in owed_ledger_acts.py. The - same remedy is printed for the other holds that are not a plain OPEN: an open symbol only in - the banner's prose, no status at all, and copies or readings of the item that disagree. + in Unicode's Other Symbol category (most emoji), outside the status and decoration lists, holds + the item whatever else the banner says, because a status the vault adds later is likelier open + than closed. An unknown symbol of another category, at least an arrow or a letter, is not held + on. Its BLOCKING line names the symbol and says to correct the ledger row: give it a status this + grammar knows, or, where the vault has adopted the symbol as a status, add it to the lists here + and in owed_ledger_acts.py. The same remedy is printed where the item's copies or readings + disagree, some protecting it and some not. A STALE LEDGER (BACKLOG #5480 items 5 and 10). A ledger checkout that has not fetched errs BOTH ways: a banner it has not fetched reads as absent, which holds a claim that is safe to release, @@ -274,7 +274,6 @@ if ($LedgerRepo) { $ledgerPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($LedgerRepo) $ledgerRoot = (@(Invoke-NamespaceGit $ledgerPath @('rev-parse', '--path-format=absolute', '--show-toplevel') "-LedgerRepo $ledgerPath as a git repository" "not read") -join '').Trim() $ledgerPinned = Resolve-PinnedMain $ledgerRoot - # One token, so the BLOCKING roll-up's strip of the why-string's lead stays anchored. $ledgerAt = "ledger:$($ledgerPinned.Ref)@$($ledgerPinned.Sha.Substring(0, [Math]::Min(12, $ledgerPinned.Sha.Length)))" $remedy = " Check that -LedgerRepo names a checkout of the ledger repository (the vault)." } @@ -878,30 +877,28 @@ foreach ($f in $files) { else { "'$branch' carries $($parts[0].Text)" } # EACH KEY SAYS WHAT HOLDS IT (BACKLOG #5480, Lander hold on 64695101cd3). The copies note is # this key's own and names each file's state, so a branch roll-up cannot lend one key's copies - # to another. A PLAIN OPEN is every copy, in both readings, on an OPEN status line: the claim - # is doing its job there, and the branch decision applies. Every other hold -- an unknown - # symbol, an open symbol only in prose, no status at all, or copies and readings that - # disagree -- is a ledger row that does not read as one status. Its text names the cause and - # the remedy, correcting the row, and says nothing about the work or the branch. + # to another. A PLAIN OPEN is a hold where no copy protects the item and none carries an + # unknown symbol: an OPEN status, an open symbol in prose, or no status at all, each of which + # the vault's own reading takes as open. Nothing protects it, and the branch decision applies. + # The other holds -- an unknown symbol, or copies and readings that disagree, some protecting + # the item -- are a ledger row that does not read as one status. Their text names the cause + # and the remedy, correcting the row, and says nothing about the work or the branch. $byFile = New-OrdinalMap foreach ($j in $judged) { if (-not $byFile.Contains($j.File)) { $byFile[$j.File] = [System.Collections.Generic.List[string]]::new() } if (-not $byFile[$j.File].Contains($j.State)) { $byFile[$j.File].Add($j.State) } } - $perFile = @(foreach ($cf in $byFile.Keys) { "$cf reads " + ($byFile[$cf] -join ' in one reading and ') }) + # A file's distinct states, across its copies and both readings. + $perFile = @(foreach ($cf in $byFile.Keys) { "$cf reads " + ($byFile[$cf] -join ' and ') }) $copiesOwn = if ($nCopies -gt 1) { " (the item stands $nCopies times: " + ($perFile -join '; ') + "; every copy is read)" } else { "" } - $odd = @($judged | Where-Object { $_.State -cnotlike 'OPEN/*' }) - $plain = -not $odd.Count + $unknownCopy = @($judged | Where-Object { $_.State -clike 'UNKNOWN-STATUS/*' }) + $plain = ($holding.Count -eq $judged.Count) -and -not $unknownCopy.Count $tail = "so the key is unclaimable by any future session while nothing on $ledgerAt protects it" if (-not $plain) { - $cause = if (@($judged | ForEach-Object State | Select-Object -Unique).Count -gt 1) { + $cause = if ($holding.Count -lt $judged.Count) { "its copies or readings disagree (" + ($perFile -join '; ') + "), and a release needs every one to protect the item" - } elseif ($odd[0].State -clike 'UNKNOWN-STATUS/*') { - "a banner line opens with $($odd[0].State.Substring(15)), a symbol outside this tool's status and decoration lists, which holds the item whatever else the banner says" - } elseif ($odd[0].State -clike 'OPEN-IN-PROSE/*') { - "an open status symbol stands in the banner's prose with no status line this tool counts, which blocks a landing phrase" } else { - "no copy carries a status line or a landing phrase this tool counts" + "a banner line opens with $($unknownCopy[0].State.Substring(15)), a symbol in Unicode's Other Symbol category outside this tool's status and decoration lists, which holds the item whatever else the banner says" } $tail = "$cause. Correct the ledger row on $ledgerAt so every copy carries the item's status in a line the ledger grammar reads, then adjudicate again" } @@ -1020,7 +1017,7 @@ if ($blk.Count) { Write-Host (" one decision for the branch -- land it, or abandon it and release all {0}." -f $grp.Count) } elseif ($open.Count) { - Write-Host (" for the {0} key(s) that read OPEN ({1}), one decision for the branch -- land it, or abandon it and release them; the others wait on their ledger row." -f $open.Count, ($open -join ', ')) + Write-Host (" for the {0} key(s) that read open ({1}), one decision for the branch -- land it, or abandon it and release them; the others wait on their ledger row." -f $open.Count, ($open -join ', ')) } else { Write-Host " no branch decision until each ledger row above is corrected." } Write-Host "" diff --git a/tests/test_coord_claim_adjudicate.py b/tests/test_coord_claim_adjudicate.py index 25f58335bd..10075a9474 100644 --- a/tests/test_coord_claim_adjudicate.py +++ b/tests/test_coord_claim_adjudicate.py @@ -1806,6 +1806,36 @@ def test_a_hold_that_is_not_a_plain_open_names_the_ledger_remedy( assert false_text not in proc.stdout, (false_text, proc.stdout) +@pytest.mark.parametrize( + "archive,live,plain", + [ + # Copies that disagree, one protecting the item: the row is the ledger's to correct. + (f"> {SHIPPED} SHIPPED", f"> {PRIORITIZED} reopened", False), + # No copy protects it and none carries an unknown symbol: open work, the branch decision. + ("plain prose", f"> {PRIORITIZED} open", True), + ], +) +def test_disagreeing_copies_name_the_ledger_remedy_and_open_ones_the_branch( + repo: Path, tmp_path: Path, archive: str, live: str, plain: bool +) -> None: + """Hold item 5: only a hold with no protecting copy and no unknown symbol keeps the branch + decision; copies that disagree name each file's state and the ledger remedy instead.""" + _publish(repo, "docs/archive/backlog/BACKLOG-CLOSED.md", f"# C\n\n## 84. T\n\n{archive}\n\nb\n") + backlog(repo, f"## 84. T\n\n{live}\n\nbody\n") + unmerged_branch(repo, "seat") + write_claim(repo, "84", tmp_path / "gone", "seat") + proc = adjudicate(repo) + assert proc.returncode == 0, proc.stderr + line = _key_line(proc.stdout, "84") + assert "BACKLOG-CLOSED.md reads" in line and "docs/BACKLOG.md reads" in line, line + if plain: + assert "release all 1" in proc.stdout, proc.stdout + assert "Correct the ledger row" not in proc.stdout, proc.stdout + else: + assert "disagree" in proc.stdout and "Correct the ledger row" in proc.stdout, proc.stdout + assert "abandon" not in proc.stdout, proc.stdout + + def _ps_codepoints(line_marker: str) -> set[str]: """The code points written on the one script line holding ``line_marker``.""" text = ADJUDICATE.read_text(encoding="utf-8") From ae1efcd712c22b5f36831ba8b98ba53d91b37ed6 Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Sun, 29 Nov 2026 16:01:48 -0600 Subject: [PATCH 12/14] claim-adjudicate.ps1: the unknown-symbol remedy names adopting the symbol BACKLOG #5480, Lander hold on 64695101cd3, code-review round-684fc9ff72. The .NOTES, a comment and docs/WORKTREES.md said the report also tells the reader to add an adopted symbol to the status lists; the printed text did not. It does now, wherever an unknown symbol holds a copy. Old-against-new comparison on this head over 76 ledger shapes: 49 same, 27 tighter, 0 looser. Fail-before at 64695101cd3 for the hold's tests: 10 failed, 3 passed (the 3 are origin-form controls). Proposed PR title: claim-adjudicate reads the ledger the way the ledger tools do, and releases only where both readings protect the item (BACKLOG #5480) Proposed banner #5480: SHIPPED. Engine PR 3112 and PR 3124 met the row's own claim; this PR builds the eleven items PR 3124 left open and repairs the Lander's six-item hold on 64695101cd3. A release needs every copy, in origin/main's raw reading and an owed_ledger_acts.py-style reading, to protect the item. Measured over 76 ledger shapes against origin/main: 49 same verdict, 27 held or refused here that origin/main released, and none released here that origin/main holds; at least the releases both versions share stay open (a \x1f after `>`, non-BMP heading digits, a PARTIAL banner with no status symbol). New fail-closed refusals: an engine checkout or a vault checkout last fetched before 2026-09-26 named as -LedgerRepo, and a ledger neither committed nor fetched from origin within -LedgerMaxAgeHours. Fail-before: 16 failed, 57 passed at origin/main 74910c69104; the hold's tests 10 failed, 3 passed at 64695101cd3. The review's open findings are queued for filing under ledger ruling R2. Verified-by: tests --- scripts/coord/claim-adjudicate.ps1 | 6 +++++- tests/test_coord_claim_adjudicate.py | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/coord/claim-adjudicate.ps1 b/scripts/coord/claim-adjudicate.ps1 index b8aa085e60..512c2fbbff 100644 --- a/scripts/coord/claim-adjudicate.ps1 +++ b/scripts/coord/claim-adjudicate.ps1 @@ -900,7 +900,11 @@ foreach ($f in $files) { } else { "a banner line opens with $($unknownCopy[0].State.Substring(15)), a symbol in Unicode's Other Symbol category outside this tool's status and decoration lists, which holds the item whatever else the banner says" } - $tail = "$cause. Correct the ledger row on $ledgerAt so every copy carries the item's status in a line the ledger grammar reads, then adjudicate again" + $tail = "$cause. Correct the ledger row on $ledgerAt so every copy carries the item's status in a line the ledger grammar reads" + if ($unknownCopy.Count) { + $tail += ", or, where the vault has adopted $($unknownCopy[0].State.Substring(15)) as a status, add it to the status lists in this script and in owed_ledger_acts.py" + } + $tail += ", then adjudicate again" } $own = "reads $($holding[0].State) in $($holding[0].File) on $ledgerAt$copiesOwn" $rows += [pscustomobject]@{ key = $k; holder = $holder; branch = $branch; note = $note diff --git a/tests/test_coord_claim_adjudicate.py b/tests/test_coord_claim_adjudicate.py index 10075a9474..8dcf0fb364 100644 --- a/tests/test_coord_claim_adjudicate.py +++ b/tests/test_coord_claim_adjudicate.py @@ -1797,6 +1797,7 @@ def test_a_hold_that_is_not_a_plain_open_names_the_ledger_remedy( r = rows(repo)["73"] assert r["verdict"] == "BLOCKING", r assert "U+1F7E5" in r["why"] and "Correct the ledger row" in r["why"], r + assert "owed_ledger_acts.py" in r["why"], r assert "nothing on" not in r["why"], r proc = adjudicate(repo) assert proc.returncode == 0, proc.stderr From 717d9660362c13f7e887e5dc1536646aef910b64 Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Sun, 29 Nov 2026 17:53:07 -0600 Subject: [PATCH 13/14] claim-adjudicate.ps1: no release on a dropped case-pair file, and only a plain OPEN gets the branch decision Repair of the Lander's hold on ae1efcd712c (BACKLOG #5480), its items H1 to H6. H1: of two ledger files whose names differ only in case, origin/main's case-folding table kept the last one holding an item heading, so a key only the other file holds read NO-ITEM there and this head released it. Such a key now reads NO-ITEM again, unless a copy holds it, and the report names the file and says to rename one of the pair. H2 to H4: Get-BannerState also returns Plain and Unknown. Only a hold whose every copy and reading has an OPEN line, and no banner line opening with a closed or unknown symbol, gets the land-or-abandon text. Every other hold names its cause and asks for the row's true status. The comment now says the vault's checker reports a row with no status, or with both, as an error. H5 and H6: docs/WORKTREES.md says what BLOCKING now means, and names the two kinds of heading the script never reads, as does the index comment. Verified-by: tests --- docs/WORKTREES.md | 22 +++++--- scripts/coord/claim-adjudicate.ps1 | 73 +++++++++++++++++--------- tests/test_coord_claim_adjudicate.py | 77 ++++++++++++++++++++++++++-- 3 files changed, 136 insertions(+), 36 deletions(-) diff --git a/docs/WORKTREES.md b/docs/WORKTREES.md index 45c353f5ac..8bdcd84e83 100644 --- a/docs/WORKTREES.md +++ b/docs/WORKTREES.md @@ -1122,10 +1122,14 @@ A do-not-rebuild banner does not count where any line of the banner carries an O or a banner line opens with an unknown symbol in Unicode's Other Symbol category (most emoji). It still counts where neither stands, so at least an item marked open only in words, such as `**PARTIAL**` with no status symbol, supersedes on it. An item whose number stands more than once -supersedes only when every copy protects it. A banner line opening with such an unknown symbol +supersedes only when every copy the script reads protects it. At least a copy whose heading number +uses digits outside Unicode's Basic Multilingual Plane, or has `\x1f` after its dot, is not read, +as on `origin/main`. A banner line opening with such an unknown symbol holds the item; the report names the symbol and says to correct the ledger row, or to add the symbol to the script's lists where the vault has adopted it as a status. An unknown symbol of -another category, at least an arrow or a letter, is not held on. The script's `Get-BannerState` and its item index state the +another category, at least an arrow or a letter, is not held on. Correcting the row is +also the remedy for every other held item whose copies do not each read as one open status, at least +a row with no status line. The script's `Get-BannerState` and its item index state the exact rules (BACKLOG #5480, items 1 to 3). Nothing else is ever proposed for release. Not age, not quiet, not a note saying the work is done. @@ -1148,12 +1152,18 @@ Each was tried against the live data on 2026-08-18 and produced a wrong answer. `SUPERSEDED` is a **floor** on what is safe to release, never a ceiling on what has landed. Every other verdict is a question the instrument could not close, not a finding that the work is live: -- **BLOCKING** — nothing on `origin/main` protects the item, so the key is stuck in the worst way: - unclaimable *and* unbuilt. These are **grouped by branch**, because that is where the decision - lives — one *land it or abandon it* call cleared nine keys at once on the day this was written. - A claim that records no branch has no such decision, so those keys are listed one by one. +- **BLOCKING** means that not every copy of the item protects it on `origin/main`, so the claim stays. + Each key prints its own state, file and copies. Where every copy reads as one open status, + nothing protects the item, and the branch needs one *land it or abandon it* decision. Those keys + are **grouped by branch**: one call cleared nine keys at once on the day this was written. A + claim that records no branch has no such decision, so those keys are listed one by one. Any + other held key names its cause. Correct its ledger row and adjudicate again before any branch + decision: the item may already be built. - **NO-ITEM** — the key is outside the backlog namespace (`ha-recheck-inc145`, `usage-forecast` on the live registry). The instrument does not reach it. That is not a finding about the work. + A key also reads NO-ITEM where its only copies would release it but stand in a backlog file that + `origin/main`'s script skipped, because another file has the same name apart from case. The + report names the file. Rename one of the two. - **STRANDED-REGISTERED** — half a removal. `prune-merged.ps1` owns it and releases as it removes. - **UNREADABLE** — `claim_check.py` reads a malformed claim as *unclaimed*, so the key is already ungated. Deleting the file would hide that rather than fix it. diff --git a/scripts/coord/claim-adjudicate.ps1 b/scripts/coord/claim-adjudicate.ps1 index 512c2fbbff..1f7a0907ff 100644 --- a/scripts/coord/claim-adjudicate.ps1 +++ b/scripts/coord/claim-adjudicate.ps1 @@ -76,8 +76,10 @@ than closed. An unknown symbol of another category, at least an arrow or a letter, is not held on. Its BLOCKING line names the symbol and says to correct the ledger row: give it a status this grammar knows, or, where the vault has adopted the symbol as a status, add it to the lists here - and in owed_ledger_acts.py. The same remedy is printed where the item's copies or readings - disagree, some protecting it and some not. + and in owed_ledger_acts.py. Correcting the row is also the remedy for every other hold that is + not a plain OPEN: at least a closed symbol beside an open one, an open symbol only in prose, no + status line this tool counts, and copies or readings that disagree. A plain OPEN reads as one + open status in every copy and reading. Only it gets the land-or-abandon decision. A STALE LEDGER (BACKLOG #5480 items 5 and 10). A ledger checkout that has not fetched errs BOTH ways: a banner it has not fetched reads as absent, which holds a claim that is safe to release, @@ -369,9 +371,9 @@ if (-not $backlogFiles.Count) { # Each reading is right where the other is not, and each alone released open work somewhere the # other held it: the raw one past a U+2028 that hides an OPEN line, the normalised one where a # control-character line ends the banner run early or a U+2028 makes a CLOSED line. So the raw -# reading alone decides whether the key names an item at all -- no new key, none origin/main read -# NO-ITEM -- and the normalised reading may only ADD copies and lines that hold. An item supersedes -# only when every copy in BOTH readings protects it. +# reading alone decides whether the key names an item at all, no key origin/main read NO-ITEM is +# released ($namingFiles, below), and the normalised reading may only ADD copies and lines that +# hold. An item supersedes only when every copy in BOTH readings protects it. $LINE_BREAK = [regex]'\r\n|[\n\r\v\f\x1c\x1d\x1e\x85

]' # KEYED ORDINALLY, as git names a path (BACKLOG #5480, Lander hold on 64695101cd3). PowerShell's own # tables fold case, so of two files whose names differ only in case the second overwrote the first @@ -406,9 +408,9 @@ foreach ($bf in $backlogFiles) { # reads each digit as its value, as int() does for a decimal digit in the Basic Multilingual Plane, # and drops leading zeros. The raw index keeps the digits as written, origin/main's key, so a # spelling origin/main never matched cannot make a key resolve. .NET's `\d` matches one UTF-16 unit, -# so at least a heading spelled in decimal digits outside that plane is indexed in neither reading -# while int() reads it: that copy is never judged, and the key can supersede on its other copies, as -# on origin/main, which does not read it either. +# so at least a heading spelled in decimal digits outside that plane, or one with \x1f after its +# dot, is indexed in neither reading while owed_ledger_acts.py reads it: that copy is never judged, +# and the key can supersede on its other copies, as on origin/main, which does not read it either. function ConvertTo-ItemNumber([string]$Digits) { $t = (-join @(foreach ($c in $Digits.ToCharArray()) { [int][char]::GetNumericValue($c) })).TrimStart('0') if ($t) { $t } else { '0' } @@ -454,6 +456,13 @@ if (-not $corpus.raw.Count) { "key against. Refusing rather than report every key NO-ITEM.$remedy") } $corpusFiles = @($corpus.raw.Keys | Sort-Object) +# THE FILES THAT MAY RELEASE A KEY. Of two files whose names differ only in case, origin/main's +# case-folding table kept the last one holding an item heading, so a key that only the other file +# holds read NO-ITEM there. That file's copies are judged here, so they can hold an item, but they +# never release one on their own. $folded is that same table, on purpose. +$folded = @{} +foreach ($f in $corpus.raw.Keys) { $folded[$f] = $f } +$namingFiles = [System.Collections.Generic.HashSet[string]]::new([string[]]@($folded.Values), [StringComparer]::Ordinal) # IS IT RECENT (BACKLOG #5480 item 10). The rule and its reason are .NOTES' "A STALE LEDGER"; the # code below is its only copy. It runs only after the refusals above, so a namespace with no item @@ -646,6 +655,7 @@ function Get-BannerState([string]$Block, [string]$Mode) { $closed = [System.Collections.Generic.List[string]]::new() $open = [System.Collections.Generic.List[string]]::new() $unknown = [System.Collections.Generic.List[string]]::new() + $closedSeen = $false $pastVault = $false foreach ($l in ($lead -split "`n")) { if (-not (Test-BlankLine $l $Mode) -and -not $l.StartsWith('>', [StringComparison]::Ordinal)) { $pastVault = $true } @@ -654,6 +664,7 @@ function Get-BannerState([string]$Block, [string]$Mode) { $g = $m.Groups['g'].Value if ($OPEN_GLYPH.Contains($g)) { $open.Add($g); continue } if ($CLOSED_GLYPH.Contains($g)) { + $closedSeen = $true if ($m.Groups['sp'].Success -and -not $m.Groups['ind'].Length -and -not $pastVault) { $closed.Add($g) } continue } @@ -668,7 +679,7 @@ function Get-BannerState([string]$Block, [string]$Mode) { # CLOSED only where a closed status line stands and no open one does -- the vault's own verdict. foreach ($g in $CLOSED_GLYPH) { if ($closed.Contains($g)) { - return [pscustomobject]@{ State = "CLOSED/" + $GLYPH_NAME[$g]; Why = ""; Protects = $true } + return [pscustomobject]@{ State = "CLOSED/" + $GLYPH_NAME[$g]; Why = ""; Protects = $true; Plain = $false; Unknown = "" } } } foreach ($p in $(if (-not $openAnywhere.Count) { $LANDED_BANNER })) { @@ -677,7 +688,7 @@ function Get-BannerState([string]$Block, [string]$Mode) { # rests on rather than a label the reader must take on trust. $line = ($lead -split "`n" | Where-Object { [regex]::IsMatch($_, $p) } | Select-Object -First 1) $why = (($line -replace '^\s*>\s*', '') -replace '\*', '').Trim() - return [pscustomobject]@{ State = "LANDED-BANNER"; Why = $why; Protects = $true } + return [pscustomobject]@{ State = "LANDED-BANNER"; Why = $why; Protects = $true; Plain = $false; Unknown = "" } } } } @@ -685,7 +696,11 @@ function Get-BannerState([string]$Block, [string]$Mode) { elseif ($unknown.Count) { "UNKNOWN-STATUS/" + $unknown[0] } elseif ($openAnywhere.Count) { "OPEN-IN-PROSE/" + $GLYPH_NAME[$openAnywhere[0]] } else { "NO-BANNER" } - [pscustomobject]@{ State = $state; Why = ""; Protects = $false } + # A PLAIN OPEN reads as one open status: an OPEN line, and no closed or unknown symbol opening + # another banner line. + [pscustomobject]@{ State = $state; Why = ""; Protects = $false + Plain = [bool]($open.Count -and -not $closedSeen -and -not $unknown.Count) + Unknown = "$($unknown | Select-Object -First 1)" } } # --------------------------------------------------------------------------------------------- @@ -831,7 +846,7 @@ foreach ($f in $files) { # zero-padded or non-ASCII-digit heading, or one after a U+2028, stands only in the normalised one. $judged = @(foreach ($b in $blocks) { $s = Get-BannerState $b.Text $b.Mode - [pscustomobject]@{ File = $b.File; State = $s.State; Why = $s.Why; Protects = $s.Protects } + [pscustomobject]@{ File = $b.File; State = $s.State; Why = $s.Why; Protects = $s.Protects; Plain = $s.Plain; Unknown = $s.Unknown } }) $holding = @($judged | Where-Object { -not $_.Protects }) $nCopies = [Math]::Max($rawBlocks.Count, $normBlocks.Count) @@ -839,7 +854,12 @@ foreach ($f in $files) { " (the item stands $nCopies times, in " + ((@($judged | ForEach-Object File) | Select-Object -Unique) -join ', ') + ", and every copy is read)" } else { "" } - if (-not $holding.Count) { + if (-not $holding.Count -and -not @($rawBlocks | Where-Object { $namingFiles.Contains($_.File) }).Count) { + $rows += [pscustomobject]@{ key = $k; holder = $holder; branch = $branch; note = $note + item = ""; banner = ""; citations = $cites; verdict = "NO-ITEM" + why = "'$k' stands on $ledgerAt only in $($rawBlocks[0].File), and another backlog file there has the same name apart from case, so this tool does not release on it. Rename one of the two files in the ledger, then adjudicate again" } + } + elseif (-not $holding.Count) { $bannerState = $judged[0].State; $bannerWhy = $judged[0].Why $quote = if ($bannerWhy) { ": `"" + $bannerWhy.Substring(0, [Math]::Min(140, $bannerWhy.Length)) + "`"" } else { "" } $rows += [pscustomobject]@{ key = $k; holder = $holder; branch = $branch; note = $note @@ -877,12 +897,13 @@ foreach ($f in $files) { else { "'$branch' carries $($parts[0].Text)" } # EACH KEY SAYS WHAT HOLDS IT (BACKLOG #5480, Lander hold on 64695101cd3). The copies note is # this key's own and names each file's state, so a branch roll-up cannot lend one key's copies - # to another. A PLAIN OPEN is a hold where no copy protects the item and none carries an - # unknown symbol: an OPEN status, an open symbol in prose, or no status at all, each of which - # the vault's own reading takes as open. Nothing protects it, and the branch decision applies. - # The other holds -- an unknown symbol, or copies and readings that disagree, some protecting - # the item -- are a ledger row that does not read as one status. Their text names the cause - # and the remedy, correcting the row, and says nothing about the work or the branch. + # to another. A PLAIN OPEN is a hold where every copy, in both readings, reads as one + # open status (Get-BannerState's Plain). Nothing protects it, and the branch decision + # applies. Every other hold -- at least an unknown symbol, a closed symbol beside an open + # one, an open symbol only in prose, no status line, or copies and readings that disagree -- + # is a ledger row that does not read as one status. The vault's backlog_status_check.py + # reports a row with no status, or with both, as an error in the row. So the text names the + # cause and the remedy, correcting the row, and says nothing about the work or the branch. $byFile = New-OrdinalMap foreach ($j in $judged) { if (-not $byFile.Contains($j.File)) { $byFile[$j.File] = [System.Collections.Generic.List[string]]::new() } @@ -891,18 +912,20 @@ foreach ($f in $files) { # A file's distinct states, across its copies and both readings. $perFile = @(foreach ($cf in $byFile.Keys) { "$cf reads " + ($byFile[$cf] -join ' and ') }) $copiesOwn = if ($nCopies -gt 1) { " (the item stands $nCopies times: " + ($perFile -join '; ') + "; every copy is read)" } else { "" } - $unknownCopy = @($judged | Where-Object { $_.State -clike 'UNKNOWN-STATUS/*' }) - $plain = ($holding.Count -eq $judged.Count) -and -not $unknownCopy.Count + $unknownCopy = @($judged | Where-Object { $_.Unknown }) + $plain = -not @($judged | Where-Object { -not $_.Plain }).Count $tail = "so the key is unclaimable by any future session while nothing on $ledgerAt protects it" if (-not $plain) { $cause = if ($holding.Count -lt $judged.Count) { "its copies or readings disagree (" + ($perFile -join '; ') + "), and a release needs every one to protect the item" + } elseif (-not $unknownCopy.Count) { + "not every copy and reading carries exactly one status in a line this tool counts (" + ($perFile -join '; ') + ")" } else { - "a banner line opens with $($unknownCopy[0].State.Substring(15)), a symbol in Unicode's Other Symbol category outside this tool's status and decoration lists, which holds the item whatever else the banner says" + "a banner line opens with $($unknownCopy[0].Unknown), a symbol in Unicode's Other Symbol category outside this tool's status and decoration lists, which holds the item whatever else the banner says" } - $tail = "$cause. Correct the ledger row on $ledgerAt so every copy carries the item's status in a line the ledger grammar reads" + $tail = "$cause. Correct the ledger row on $ledgerAt so every copy carries the item's true status, open or closed, in one line the ledger grammar reads" if ($unknownCopy.Count) { - $tail += ", or, where the vault has adopted $($unknownCopy[0].State.Substring(15)) as a status, add it to the status lists in this script and in owed_ledger_acts.py" + $tail += ", or, where the vault has adopted $($unknownCopy[0].Unknown) as a status, add it to the status lists in this script and in owed_ledger_acts.py" } $tail += ", then adjudicate again" } @@ -1021,7 +1044,7 @@ if ($blk.Count) { Write-Host (" one decision for the branch -- land it, or abandon it and release all {0}." -f $grp.Count) } elseif ($open.Count) { - Write-Host (" for the {0} key(s) that read open ({1}), one decision for the branch -- land it, or abandon it and release them; the others wait on their ledger row." -f $open.Count, ($open -join ', ')) + Write-Host (" for the {0} key(s) that read OPEN ({1}), one decision for the branch -- land it, or abandon it and release them; the others wait on their ledger row." -f $open.Count, ($open -join ', ')) } else { Write-Host " no branch decision until each ledger row above is corrected." } Write-Host "" diff --git a/tests/test_coord_claim_adjudicate.py b/tests/test_coord_claim_adjudicate.py index 8dcf0fb364..8871386be4 100644 --- a/tests/test_coord_claim_adjudicate.py +++ b/tests/test_coord_claim_adjudicate.py @@ -1812,15 +1812,17 @@ def test_a_hold_that_is_not_a_plain_open_names_the_ledger_remedy( [ # Copies that disagree, one protecting the item: the row is the ledger's to correct. (f"> {SHIPPED} SHIPPED", f"> {PRIORITIZED} reopened", False), - # No copy protects it and none carries an unknown symbol: open work, the branch decision. - ("plain prose", f"> {PRIORITIZED} open", True), + # A copy with no status line is the ledger's to correct too. + ("plain prose", f"> {PRIORITIZED} open", False), + # Every copy reads as one open status: open work, the branch decision. + (f"> {IN_PROGRESS} open", f"> {PRIORITIZED} open", True), ], ) def test_disagreeing_copies_name_the_ledger_remedy_and_open_ones_the_branch( repo: Path, tmp_path: Path, archive: str, live: str, plain: bool ) -> None: - """Hold item 5: only a hold with no protecting copy and no unknown symbol keeps the branch - decision; copies that disagree name each file's state and the ledger remedy instead.""" + """Only a hold whose every copy reads as one open status keeps the branch decision; any other + names each file's state and the ledger remedy instead.""" _publish(repo, "docs/archive/backlog/BACKLOG-CLOSED.md", f"# C\n\n## 84. T\n\n{archive}\n\nb\n") backlog(repo, f"## 84. T\n\n{live}\n\nbody\n") unmerged_branch(repo, "seat") @@ -1833,10 +1835,75 @@ def test_disagreeing_copies_name_the_ledger_remedy_and_open_ones_the_branch( assert "release all 1" in proc.stdout, proc.stdout assert "Correct the ledger row" not in proc.stdout, proc.stdout else: - assert "disagree" in proc.stdout and "Correct the ledger row" in proc.stdout, proc.stdout + assert "Correct the ledger row" in proc.stdout, proc.stdout + assert ("readings disagree" in proc.stdout) == (SHIPPED in archive), proc.stdout assert "abandon" not in proc.stdout, proc.stdout +@pytest.mark.parametrize( + "lead", + [ + # origin/main released each of these; the row, not the branch, is what must change. + f"> {SHIPPED}\n> landed in PR 12", + f"> {SHIPPED}\N{NO-BREAK SPACE}SHIPPED", + f" > a note\n> {SHIPPED} SHIPPED", + f" > {IN_PROGRESS} indented\n> {SHIPPED} SHIPPED", + f"> was {IN_PROGRESS}. THE BUILD HAS LANDED. DO NOT REBUILD.", + # origin/main held these and gave the branch decision. + "plain prose", + f"> **PARTIAL** {IN_PROGRESS} half B open", + f"> {PRIORITIZED} open\n> {SHIPPED} SHIPPED", + f"> {PRIORITIZED} open\n> {UNKNOWN} later", + ], +) +def test_a_row_that_does_not_read_as_one_status_names_the_ledger_remedy( + repo: Path, tmp_path: Path, lead: str +) -> None: + """MUST TRIP: each read as a plain OPEN, so the report said to land or abandon the branch.""" + backlog(repo, f"## 85. T\n\n{lead}\n\nbody\n") + unmerged_branch(repo, "seat") + write_claim(repo, "85", tmp_path / "gone", "seat") + r = rows(repo)["85"] + assert r["verdict"] == "BLOCKING", r + assert "Correct the ledger row" in r["why"] and "nothing on" not in r["why"], r + assert ("U+1F7E5" in r["why"]) == (UNKNOWN in lead), r + proc = adjudicate(repo) + assert proc.returncode == 0, proc.stderr + assert "abandon" not in proc.stdout and "read open" not in proc.stdout, proc.stdout + + +def test_an_open_row_with_a_landing_phrase_keeps_the_branch_decision( + repo: Path, tmp_path: Path +) -> None: + """Control: one OPEN status line is a plain OPEN, whatever its prose says.""" + backlog(repo, f"## 86. T\n\n> {PRIORITIZED} open\n> Half A: DO NOT REBUILD\n\nbody\n") + unmerged_branch(repo, "seat") + write_claim(repo, "86", tmp_path / "gone", "seat") + proc = adjudicate(repo) + assert "release all 1" in proc.stdout, proc.stdout + assert "Correct the ledger row" not in proc.stdout, proc.stdout + + +def test_a_key_only_the_dropped_file_of_a_case_pair_holds_is_not_released( + repo: Path, tmp_path: Path +) -> None: + """MUST TRIP: origin/main read only the second file of the pair, so key 7 was NO-ITEM + there, not released. A key the second file holds still supersedes.""" + backlog(repo, f"## 9. Nine\n\n> {PRIORITIZED} open\n\nbody\n") + _commit_blobs( + repo, + { + "docs/archive/backlog/BACKLOG-OLD.md": f"# O\n\n## 7. T\n\n> {SHIPPED} S\n\nb\n", + "docs/archive/backlog/BACKLOG-old.md": f"# N\n\n## 8. T\n\n> {SHIPPED} S\n\nb\n", + }, + ) + write_claim(repo, "7", tmp_path / "gone", "seat") + write_claim(repo, "8", tmp_path / "gone", "seat") + got = rows(repo) + assert {k: v["verdict"] for k, v in got.items()} == {"7": "NO-ITEM", "8": "SUPERSEDED"} + assert "BACKLOG-OLD.md" in got["7"]["why"] and "Rename" in got["7"]["why"], got["7"] + + def _ps_codepoints(line_marker: str) -> set[str]: """The code points written on the one script line holding ``line_marker``.""" text = ADJUDICATE.read_text(encoding="utf-8") From 95281637a0a709f8faefe93872404b8af6f37f6f Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Sun, 29 Nov 2026 18:13:49 -0600 Subject: [PATCH 14/14] claim-adjudicate.ps1: correct the repair's report text and cover it Review round-2d8b4f84c6 found text 717d9660362 made wrong (BACKLOG #5480). No verdict or hold rule changes. - The new NO-ITEM message named one file and said "only" there. It now names every file holding the number as the claim spells it, and says to rename so no two names differ only in case. - The NO-ITEM summary line no longer calls such a key outside the namespace. - The cause of a hold that is not a plain OPEN and has no unknown symbol now mentions a closed symbol that does not release the item. The old text was false for a closed symbol alone on its line beside an OPEN one. - The roll-up says "read as one open status", because a key it excludes can also print an OPEN state. - docs/WORKTREES.md: the NO-ITEM rule says what this script does, which stays true after the merge, and every held key with a branch is grouped by it. Tests: a branch holding both kinds of key, and three files whose names differ only in case, one of them with an open item. One assertion looked for roll-up text that is no longer printed; it now looks for text that is. Verified-by: tests --- docs/WORKTREES.md | 15 ++++---- scripts/coord/claim-adjudicate.ps1 | 8 ++-- tests/test_coord_claim_adjudicate.py | 55 +++++++++++++++++++++++++++- 3 files changed, 66 insertions(+), 12 deletions(-) diff --git a/docs/WORKTREES.md b/docs/WORKTREES.md index 8bdcd84e83..81979babdc 100644 --- a/docs/WORKTREES.md +++ b/docs/WORKTREES.md @@ -1154,16 +1154,17 @@ other verdict is a question the instrument could not close, not a finding that t - **BLOCKING** means that not every copy of the item protects it on `origin/main`, so the claim stays. Each key prints its own state, file and copies. Where every copy reads as one open status, - nothing protects the item, and the branch needs one *land it or abandon it* decision. Those keys - are **grouped by branch**: one call cleared nine keys at once on the day this was written. A - claim that records no branch has no such decision, so those keys are listed one by one. Any - other held key names its cause. Correct its ledger row and adjudicate again before any branch + nothing protects the item, and the branch needs one *land it or abandon it* decision for those + keys. Held keys are **grouped by branch**: one call cleared nine keys at once on the day this was + written. A claim that records no branch has no such decision, so those keys are listed one by + one. Any other held key names its cause. Correct its ledger row and adjudicate again before any branch decision: the item may already be built. - **NO-ITEM** — the key is outside the backlog namespace (`ha-recheck-inc145`, `usage-forecast` on the live registry). The instrument does not reach it. That is not a finding about the work. - A key also reads NO-ITEM where its only copies would release it but stand in a backlog file that - `origin/main`'s script skipped, because another file has the same name apart from case. The - report names the file. Rename one of the two. + A key also reads NO-ITEM where its copies would release it, but none stands, under the number as + the claim spells it, in a file that may release a key. Of files whose names differ only in case, + only the last one in git's order that holds an item heading may. The report names the file. + Rename files so no two names differ only in case. - **STRANDED-REGISTERED** — half a removal. `prune-merged.ps1` owns it and releases as it removes. - **UNREADABLE** — `claim_check.py` reads a malformed claim as *unclaimed*, so the key is already ungated. Deleting the file would hide that rather than fix it. diff --git a/scripts/coord/claim-adjudicate.ps1 b/scripts/coord/claim-adjudicate.ps1 index 1f7a0907ff..d28fe53237 100644 --- a/scripts/coord/claim-adjudicate.ps1 +++ b/scripts/coord/claim-adjudicate.ps1 @@ -857,7 +857,7 @@ foreach ($f in $files) { if (-not $holding.Count -and -not @($rawBlocks | Where-Object { $namingFiles.Contains($_.File) }).Count) { $rows += [pscustomobject]@{ key = $k; holder = $holder; branch = $branch; note = $note item = ""; banner = ""; citations = $cites; verdict = "NO-ITEM" - why = "'$k' stands on $ledgerAt only in $($rawBlocks[0].File), and another backlog file there has the same name apart from case, so this tool does not release on it. Rename one of the two files in the ledger, then adjudicate again" } + why = "'$k' stands on $ledgerAt in $((@($rawBlocks | ForEach-Object File) | Select-Object -Unique) -join ', '), and another backlog file there has the same name apart from case, so this tool does not release on it. Rename files in the ledger so no two names differ only in case, then adjudicate again" } } elseif (-not $holding.Count) { $bannerState = $judged[0].State; $bannerWhy = $judged[0].Why @@ -919,7 +919,7 @@ foreach ($f in $files) { $cause = if ($holding.Count -lt $judged.Count) { "its copies or readings disagree (" + ($perFile -join '; ') + "), and a release needs every one to protect the item" } elseif (-not $unknownCopy.Count) { - "not every copy and reading carries exactly one status in a line this tool counts (" + ($perFile -join '; ') + ")" + "in at least one copy or reading, no banner line opens with an open status symbol, or one opens with a closed status symbol that does not release the item (" + ($perFile -join '; ') + ")" } else { "a banner line opens with $($unknownCopy[0].Unknown), a symbol in Unicode's Other Symbol category outside this tool's status and decoration lists, which holds the item whatever else the banner says" } @@ -999,7 +999,7 @@ $els = @($rows | Where-Object verdict -eq 'ELSEWHERE') Write-Host "SUPERSEDED $($sup.Count) -- origin/main already protects the item; the claim adds nothing and can go" -ForegroundColor Green Write-Host "BLOCKING $($blk.Count) -- not every copy of the item protects it on $ledgerRef, so the claim stays; each key below says what holds it" -ForegroundColor Yellow -Write-Host "NO-ITEM $($nit.Count) -- key is outside the backlog namespace; this instrument does not reach it" +Write-Host "NO-ITEM $($nit.Count) -- key names no item this instrument can release on; each key below says why" if ($oth.Count) { Write-Host "OTHER $($oth.Count) -- unreadable, or a half-finished removal prune-merged.ps1 owns" } if ($hld.Count) { Write-Host "HELD $($hld.Count) -- holder exists; not adjudicated" } if ($els.Count) { Write-Host "ELSEWHERE $($els.Count) -- held on another machine; not checkable here, not adjudicated" } @@ -1044,7 +1044,7 @@ if ($blk.Count) { Write-Host (" one decision for the branch -- land it, or abandon it and release all {0}." -f $grp.Count) } elseif ($open.Count) { - Write-Host (" for the {0} key(s) that read OPEN ({1}), one decision for the branch -- land it, or abandon it and release them; the others wait on their ledger row." -f $open.Count, ($open -join ', ')) + Write-Host (" for the {0} key(s) that read as one open status ({1}), one decision for the branch -- land it, or abandon it and release them; the others wait on their ledger row." -f $open.Count, ($open -join ', ')) } else { Write-Host " no branch decision until each ledger row above is corrected." } Write-Host "" diff --git a/tests/test_coord_claim_adjudicate.py b/tests/test_coord_claim_adjudicate.py index 8871386be4..ef57015a15 100644 --- a/tests/test_coord_claim_adjudicate.py +++ b/tests/test_coord_claim_adjudicate.py @@ -1869,7 +1869,30 @@ def test_a_row_that_does_not_read_as_one_status_names_the_ledger_remedy( assert ("U+1F7E5" in r["why"]) == (UNKNOWN in lead), r proc = adjudicate(repo) assert proc.returncode == 0, proc.stderr - assert "abandon" not in proc.stdout and "read open" not in proc.stdout, proc.stdout + assert "abandon" not in proc.stdout and "key(s) that read" not in proc.stdout, proc.stdout + + +def test_a_branch_with_both_kinds_of_hold_offers_the_decision_for_the_plain_open_key_alone( + repo: Path, tmp_path: Path +) -> None: + """MUST TRIP: keys 88 (no status) and 89 (a closed symbol beside the open one) were listed + under the land-or-abandon decision with key 87.""" + backlog( + repo, + f"## 87. T\n\n> {PRIORITIZED} open\n\nb\n\n## 88. T\n\nplain prose\n\n" + f"## 89. T\n\n> {PRIORITIZED} open\n> {SHIPPED}\n\nb\n", + ) + unmerged_branch(repo, "seat") + for key in ("87", "88", "89"): + write_claim(repo, key, tmp_path / "gone", "seat") + proc = adjudicate(repo) + assert proc.returncode == 0, proc.stderr + assert "for the 1 key(s) that read as one open status (87), one decision" in proc.stdout, ( + proc.stdout + ) + assert proc.stdout.count("abandon") == 1, proc.stdout + assert proc.stdout.count("Correct the ledger row") == 2, proc.stdout + assert "opens with a closed status symbol" in proc.stdout, proc.stdout def test_an_open_row_with_a_landing_phrase_keeps_the_branch_decision( @@ -1904,6 +1927,36 @@ def test_a_key_only_the_dropped_file_of_a_case_pair_holds_is_not_released( assert "BACKLOG-OLD.md" in got["7"]["why"] and "Rename" in got["7"]["why"], got["7"] +def test_of_three_files_differing_only_in_case_only_the_last_may_release( + repo: Path, tmp_path: Path +) -> None: + """MUST TRIP: key 7 stands in both dropped files, and the report names both. Control: key 6, + OPEN in a dropped file, is still held, and key 8, in the last file, still supersedes.""" + backlog(repo, f"## 9. Nine\n\n> {PRIORITIZED} open\n\nbody\n") + seven = f"# F\n\n## 7. T\n\n> {SHIPPED} S\n\nb\n" + _commit_blobs( + repo, + { + "docs/archive/backlog/BACKLOG-OLD.md": seven, + "docs/archive/backlog/BACKLOG-Old.md": ( + f"{seven}\n## 6. T\n\n> {PRIORITIZED} reopened\n\nb\n" + ), + "docs/archive/backlog/BACKLOG-old.md": f"# N\n\n## 8. T\n\n> {SHIPPED} S\n\nb\n", + }, + ) + for key in ("6", "7", "8"): + write_claim(repo, key, tmp_path / "gone", "seat") + got = rows(repo) + assert {k: v["verdict"] for k, v in got.items()} == { + "6": "BLOCKING", + "7": "NO-ITEM", + "8": "SUPERSEDED", + } + why = got["7"]["why"] + assert "BACKLOG-OLD.md" in why and "BACKLOG-Old.md" in why, why + assert "BACKLOG-old.md" not in why and " only in " not in why.split("Rename")[0], why + + def _ps_codepoints(line_marker: str) -> set[str]: """The code points written on the one script line holding ``line_marker``.""" text = ADJUDICATE.read_text(encoding="utf-8")