Skip to content

verdict: answers that cannot be read as complete (#1121) - #1166

Open
Smaug123 wants to merge 9 commits into
mainfrom
claude/borzoi-verdict-crate
Open

Smaug123 wants to merge 9 commits into
mainfrom
claude/borzoi-verdict-crate

Conversation

@Smaug123

@Smaug123 Smaug123 commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Claim. borzoi-verdict provides two types, each of which can hold an answer only in a form that cannot be read as complete:

  • Verdict<T, C> is Certain(T) | Unknown(C).
  • Lookup<T, C> is Found(T) | ProvedAbsent | Unknown(C).

Lookup<T, C> and Verdict<Option<T>, C> convert into each other without loss. Each operation obeys the laws written in its doc comment, and each law is checked exhaustively. This PR adds no consumers.

Domain. The crate is the whole domain: its two types, the isomorphism between them, and these operations:

  • map, map_cause, and_then and as_ref on both types;
  • zip and FromIterator on Verdict;
  • or_shadowed on Lookup.

This is the first PR of #1121's plan. The plan's PR 1b uses the crate to publish ParsedProject's defines and reference edges as verdicts (#1112).

Deliberately absent:

  • Conversion from Option or bool. It would assert that the search behind a None or false was complete.
  • Projection to Option or bool, and iteration. Each merges ProvedAbsent or Unknown into another variant.
  • Default. It would give an Unknown with no cause, or an unproven ProvedAbsent.
  • or on Verdict. Falling back to another value is a guess.

compile_fail doctests spell out each absence, and a passing control doctest shows that the allowed spelling of each line compiles. A reading can be added under any name, so tests/pin.rs also pins every file under src whole, by the SHA-1 of the bytes rustc compiles. Any change to the crate therefore fails until tests/src.pin is regenerated, and the regenerated pin is in the diff.

Laws, checked exhaustively (tests/laws.rs). Values range over {0, 1} and causes over {a, b}, so a verdict takes 4 values and a lookup 5. Every function the laws quantify over is enumerated as a table: 4 value functions, 16 verdict-valued, 25 lookup-valued and 4 cause functions. The laws:

  • Functors and monads. map and map_cause are functors on both types. and_then is a monad on both, with Unknown (and, for a lookup, ProvedAbsent) passing through.

  • zip. It equals sequencing (v.and_then(|x| w.map(|y| (x, y)))), keeps the leftmost Unknown, and is associative up to regrouping.

  • collect. It gives the leftmost Unknown, else the target's collection of the values, however the target reads. That is checked for each of seven ways of reading:

    • all of it, none, the first value, through a zero;
    • asking again after the end;
    • as many as the lower size bound;
    • recording every size hint it is offered.

    The source is not fused, and every sequence up to length 4 is checked (341 sequences). Two more checks:

    • Option<Vec<_>>, over 781 sequences;
    • a Vec, where collecting equals the fold of zip.

    The source is never read past its first Unknown or its first end.

  • or_shadowed.

    • ProvedAbsent is the two-sided identity.
    • Found and Unknown are left zeros: an inner Unknown is never skipped.
    • It is associative.
    • The outer scope is asked only when the inner one proved it holds nothing.
  • The isomorphism. It round-trips both ways, and commutes with map, map_cause and and_then.

Mutation check. Every guard was mutated and seen to fail a test (each mutation confirmed applied by comparing file contents, then restored from a saved copy):

  • Absences. Adding From<Option>, From<Lookup> for Option, From<bool>, Into<bool>, Default (either type), IntoIterator or Verdict::or fails its own compile_fail doctest, and only that one. Any edit to src/ fails the pin.
  • or_shadowed. Skipping an inner Unknown, or evaluating the outer scope eagerly, fails the law tests.
  • zip. Keeping the rightmost Unknown fails the law tests.
  • collect. Each of these fails the law tests:
    • the original map_while implementation (codex round 1's repro);
    • no rest-check after a target stops early;
    • an adapter not fused after an Unknown, or after the end;
    • a later Unknown overwriting the first;
    • forwarding the source's lower size bound;
    • an upper bound of Some(0) or None.
  • The isomorphism, and map. Breaking either direction of the isomorphism, or losing Found in map, fails the law tests.
  • The pin.
    • A one-character doc edit fails it, and so does a new file under src/.
    • A CRLF copy of the crate passes every test.
    • Dropping the CRLF normalisation fails the pin's unit test.

CI. No job in .github/workflows/ci.yml runs cargo test -p borzoi-verdict, and the agent token cannot push workflow changes.

  • crates/verdict routes to the workspace filter, as crates/spawn does. detect-changes.test.sh gains that routing case.
  • The test-verdict job, a copy of test-spawn added to the required-checks aggregate, is the patch below.
  • The user committed that patch as dae95d59 ("ci: run the verdict crate's tests"). test-verdict ran the crate's 22 law tests, 3 pin tests and 13 doctests and passed, and all-required-checks-complete is green.
  • detect-changes.test.sh would not have noticed the missing job. That gap is filed as detect-changes.test.sh passes a workspace crate whose tests no CI job runs #1165.
ci.yml patch (also ci-test-verdict.patch in the agent's worktree)
--- a/.github/workflows/ci.yml	2026-11-25 21:39:16
+++ b/.github/workflows/ci.yml	2026-11-25 21:39:16
@@ -1341,7 +1341,58 @@
         if: steps.gate.outputs.run == 'true'
         run: |
           nix develop --command cargo test -p borzoi-spawn --verbose
+
+      - name: Report the slowest tests
+        if: ${{ !cancelled() && steps.gate.outputs.run == 'true' }}
+        run: bash tools/ci/slowest-tests.sh | tee -a "$GITHUB_STEP_SUMMARY"
+
+  test-verdict:
+    name: Test verdict
+    needs: changes
+    runs-on: ubuntu-latest
+    steps:
+      # verdict holds the answer types the evaluating crates publish, so it
+      # lives in the `workspace` filter: a change to it runs the whole suite,
+      # and this job runs its own law tests and doctests. No fcs-dump needed.
+      - name: Check gate
+        id: gate
+        run: |
+          if [[ "${{ needs.changes.outputs.workspace }}" == "true" ]]; then
+            echo "Gate passed — running verdict tests."
+            echo "run=true" >> "$GITHUB_OUTPUT"
+          else
+            echo "No relevant changes — skipping verdict tests."
+            echo "run=false" >> "$GITHUB_OUTPUT"
+          fi
+      - name: Checkout code
+        if: steps.gate.outputs.run == 'true'
+        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
+
+      - name: Move /nix and cargo's target/ to the large /mnt disk
+        if: steps.gate.outputs.run == 'true'
+        run: |
+          df -h / /mnt || true
+          sudo mkdir -p /mnt/nix /nix
+          sudo mount --bind /mnt/nix /nix
+          sudo mkdir -p /mnt/cargo-target
+          sudo chown "$(id -u):$(id -g)" /mnt/cargo-target
+          mkdir -p "$GITHUB_WORKSPACE/target"
+          sudo mount --bind /mnt/cargo-target "$GITHUB_WORKSPACE/target"
+      - name: Install Nix
+        if: steps.gate.outputs.run == 'true'
+        uses: DeterminateSystems/nix-installer-action@ef8a148080ab6020fd15196c2084a2eea5ff2d25 # v22
+      - name: Cache cargo target/
+        if: steps.gate.outputs.run == 'true'
+        uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2
+        with:
+          cmd-format: nix develop -c {0}
+          save-if: ${{ github.ref == 'refs/heads/main' }}
 
+      - name: Test verdict crate
+        if: steps.gate.outputs.run == 'true'
+        run: |
+          nix develop --command cargo test -p borzoi-verdict --verbose
+
       - name: Report the slowest tests
         if: ${{ !cancelled() && steps.gate.outputs.run == 'true' }}
         run: bash tools/ci/slowest-tests.sh | tee -a "$GITHUB_STEP_SUMMARY"
@@ -1508,6 +1559,7 @@
       - test-lsp-sweeps
       - test-sidecar
       - test-spawn
+      - test-verdict
       - test-oracle-harness
       - nix-build
     runs-on: ubuntu-latest

Gate. Green on the build box at f2c405da (and at 779ac5c9 before it): fmt, clippy, doc, the featureless borzoi-verdict lint and doc, cargo test (whole workspace), the crate's tests, and detect-changes.test.sh. The CI commit on top changes only the workflow, and the PR's CI runs test-verdict on it.

Codex. Rounds 1–6 ran at xhigh, and rounds 7 and 8 at high (the user's setting since). Every round also flagged the missing CI job, which the patch below closes. The other findings, by round:

  1. Round 1.
    • R1: collect into a target that stops early hid a later Unknown.
    • R2: the adapter was not fused.
    • R3: the compile_fail blocks check only the names they spell.
  2. Round 2.
    • R2: the surface listing missed cfg_attr derives.
    • R3: the law test had no hostile-value table row.
    • R4: the listing's own test depended on how lib.rs is spelt.
  3. Round 3. R3: the listing missed signatures.
  4. Round 4.
    • R3: the listing missed items declared in function bodies.
    • R4: the surface test had no hostile-value table row.
  5. Round 5.
    • R3: the listing missed macro arguments.
    • R3: the collect law did not account for size hints.
  6. Round 6. R3: the laws checked reads against the size hint, not the hint itself.
  7. Round 7. R2: the pin failed on a CRLF checkout.

Rounds 2–5 were one stream: each found another way to hide from a surface listing read off the syntax. So the listing was replaced by a whole-text pin, which has no walker for anything to hide from. Every finding is fixed, each with a test that fails without its fix.

  1. Round 8 (high, on the final head dae95d59, which includes the user's CI commit, against merge base f935de31): no findings.

Decline cost. None: the crate has no consumers, and every manifest is unchanged.

🤖 Generated with Claude Code

Smaug123 and others added 9 commits November 25, 2026 21:41
A new zero-dependency crate, borzoi-verdict, with two types:
Verdict<T, C> (Certain | Unknown(cause)) and Lookup<T, C>
(Found | ProvedAbsent | Unknown(cause)), the same information converted
losslessly both ways. It has no conversion from or to Option/bool, no
Default, no iteration and no `or` on Verdict, each held by a compile_fail
doctest. Every operation's laws (functor, monad, zip as sequencing, collect
as a fold of zip, or_shadowed's identity/zeros/associativity/laziness, the
isomorphism's round trips and naturality) are checked exhaustively over a
finite domain, every function on it included.

No consumers yet: #1121's plan wires it into msbuild's ParsedProject next.
crates/verdict routes to the `workspace` change filter, as crates/spawn does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s, and the surface is an exact list

Codex round 1 (xhigh) found two defects in `FromIterator for Verdict`:
- A target that stops reading early (`Option<Vec<_>>` at its first `None`)
  hid a later `Unknown`, so the collection came back `Certain`.
- The `map_while` adapter was not fused, so a target that asked again after
  being told the end read past the first `Unknown`, and reported a later
  cause.

Collection now reads through a fused adapter that also stops at the
source's first end, and checks the rest of the source when the target
stopped early. The law tests run collection under every way a target can
read (all, none, a prefix, through a value, asking again after the end),
over a source that is not fused, and into `Option<Vec<_>>`. The old
implementation fails them.

A reading as `Option`/`bool`/`Default` can be added under any name, which
`compile_fail` doctests cannot see, so `tests/surface.rs` holds every item of
`src/lib.rs` to an exact list (syn and quote, as dev-dependencies only).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ve a hostile-table row

Codex round 2 (xhigh):
- The surface listing saw only plain `derive`s, so a
  `#[cfg_attr(target_os = "macos", derive(Default))]` with a `#[default]`
  variant left it unchanged while giving one platform a `Default`. The
  listing now records every attribute other than docs:
  - on each type, each variant (now listed with its fields), each method,
    each impl, and the crate itself;
  - a plain `derive` by its sorted names, everything else as written.
- Its own test mutated `src/lib.rs` by text, so reordering a derive there
  broke it. It now runs on a fixture, holding the listing to move on every
  change to a surface (new names, impls, plain and conditional derives,
  `#[default]`, variants, `cfg` on methods and impls, crate attributes) and to
  stay put on derive order, docs and formatting.
- `tests/laws.rs` runs a table-driven differential with no automatic marker,
  so it gets a not-applicable row in the hostile-value table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex round 3 (xhigh) found that the surface listing named each method but
not its signature: changing `or_shadowed`'s `FnOnce` to `Fn` left every test
green. This is the second round to find a dimension the listing modelled
apart, so it no longer models dimensions at all. It lists the whole of
`src/lib.rs` except what cannot change the surface: doc comments and function
bodies. A plain `derive` has its names sorted. Each impl's header and each
member get a line apiece.

The fixture test now also moves on a loosened bound, a parameter, a return
type, an impl bound, a where clause, a changed field and a bound on a trait
method. It stays put on derive order, docs, formatting and function bodies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex round 4 (xhigh) found that an impl inside a function body (in a local
module) adds methods callable from outside the crate, and that clearing
bodies hid it. The listing now walks each function body before dropping its
statements. It lists every item the body declares, recursively, as a
top-level item is listed, and the path of every macro the body invokes,
since a macro may expand to items. The fixture test moves on a nested impl
in a local module, an impl directly in a body, a nested function, an
`include!` and a macro in an expression.

`tests/surface.rs` perturbs a fixture, so it gets a not-applicable row in
the hostile-value table too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex round 5 (xhigh):
- The surface listing recorded a body macro by its path alone. A local
  module declaring a public method on `Lookup`, placed in the scrutinee of
  the existing `matches!`, reached other crates unlisted. A macro's
  arguments are the one part of a body the syntax walk cannot see into, so
  the listing now records each invocation whole. The fixture covers changing
  an existing macro's arguments.
- The collection law promised `Certain(values.collect())` for every target,
  but a target may read the size hint, and the adapter offers a lower bound
  of zero (an `Unknown` may cut the source short) and the source's upper
  bound. The law now says so, and qualifies the plain-collect form to
  targets whose result depends only on the values. The law tests add a
  target that reads the lower bound's worth and one that checks the upper
  bound. Forwarding the source's lower bound, or a too-small upper bound,
  fails them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… and check the size hint offered

The surface test read the crate's surface off its syntax. Rounds 2–5 each
found another place an addition could hide from it (a conditional derive,
a signature, an item declared in a body, a macro's arguments), and each fix
grew the walker the next round probed. There is now no walker. `tests/pin.rs`
pins every file under `src` whole, by SHA-1 and length in `tests/src.pin`,
together with the set of file names. Any edit, and any new or removed file,
fails until the pin is regenerated (`BORZOI_UPDATE_MANIFESTS=1`), so every
change to this primitive is in a reviewed diff. Doc comments are pinned too,
so the parser that excluded them goes, and with it the syn and quote
dev-dependencies (sha1 replaces them).

The hostile-value table's row for `tests/surface.rs` goes with that file.
The pin perturbs nothing, so it needs no row. The row for `tests/laws.rs`
still applies.

Codex round 6 found that the collection laws checked a target's reads
against the size hint's upper bound but not the hint itself, so an adapter
offering `(0, None)` passed. A target now records the hint it is offered
before every read and after the end, and the laws hold it to a lower bound
of zero and the source's upper bound at each step, through to `(0, Some(0))`
once the first `Unknown` or the end is reached. An adapter offering
`(0, None)` fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex round 7 found that under `core.autocrlf=true`, Git checks out
`src/lib.rs` with CRLF, so hashing its working-tree bytes failed the pin on
an unchanged checkout. rustc reads a CRLF line end as LF, so the pin now
hashes those bytes. A lone CR is kept, since rustc reads it. The pin file is
compared by line, so its own line ends do not matter either. A unit test
holds the normalisation, and a CRLF copy of the crate passes every test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant