diff --git a/examples/land/README.md b/examples/land/README.md index 8637766c1..d9a99f2b2 100644 --- a/examples/land/README.md +++ b/examples/land/README.md @@ -222,3 +222,7 @@ npm ci --prefix ../../packages/surface --ignore-scripts && npm run --prefix ../. npm ci && npm test && npm run typecheck flows check land.flow.ts ``` + +Hosted auto stages A–D use read-only repository grants. The `gh` authentication +and push-capability preflight runs at E/F, where Cloud supplies the write grant; +a denied write grant stops that stage before the GitHub gate or final push. diff --git a/examples/land/evidence/staged-write-preflight/baseline.txt b/examples/land/evidence/staged-write-preflight/baseline.txt new file mode 100644 index 000000000..8d0e335e3 --- /dev/null +++ b/examples/land/evidence/staged-write-preflight/baseline.txt @@ -0,0 +1,34 @@ +TAP version 13 +# Subtest: hosted auto allows read-only A-D and proves write access only at E/F +not ok 1 - hosted auto allows read-only A-D and proves write access only at E/F + --- + duration_ms: 1.782291 + type: 'test' + location: '/Volumes/T7/Projects/AgentWorkforce/worktrees/flows/flows-land-mode-contract-20261103/examples/land/tests/flow.test.ts:761:1' + failureType: 'testCodeFailure' + error: |- + read-only A-adversarial must advance + + actual - expected + + + 'needs_human' + - 'success' + + code: 'ERR_ASSERTION' + name: 'AssertionError' + expected: 'success' + actual: 'needs_human' + operator: 'strictEqual' + stack: |- + TestContext. (file:///Volumes/T7/Projects/AgentWorkforce/worktrees/flows/flows-land-mode-contract-20261103/examples/land/tests/flow.test.ts:769:12) + async Test.run (node:internal/test_runner/test:1054:7) + async startSubtestAfterBootstrap (node:internal/test_runner/harness:296:3) + ... +1..1 +# tests 1 +# suites 0 +# pass 0 +# fail 1 +# cancelled 0 +# skipped 0 +# todo 0 +# duration_ms 75.223917 diff --git a/examples/land/evidence/staged-write-preflight/land-tests.txt b/examples/land/evidence/staged-write-preflight/land-tests.txt new file mode 100644 index 000000000..eff4f5d54 --- /dev/null +++ b/examples/land/evidence/staged-write-preflight/land-tests.txt @@ -0,0 +1,560 @@ + +> test +> node --experimental-strip-types --test tests/*.test.ts + +TAP version 13 +# Subtest: defaults: mergePolicy is shadow, placeholders are the spec proposals +ok 1 - defaults: mergePolicy is shadow, placeholders are the spec proposals + --- + duration_ms: 0.771417 + type: 'test' + ... +# Subtest: a full relay-desktop shaped config round-trips +ok 2 - a full relay-desktop shaped config round-trips + --- + duration_ms: 0.1975 + type: 'test' + ... +# Subtest: model overrides are explicitly unsupported for every harness +ok 3 - model overrides are explicitly unsupported for every harness + --- + duration_ms: 0.277916 + type: 'test' + ... +# Subtest: refusals: unknown keys, bad enums, unsafe paths, out-of-range numbers +ok 4 - refusals: unknown keys, bad enums, unsafe paths, out-of-range numbers + --- + duration_ms: 0.628334 + type: 'test' + ... +# Subtest: JSON schema matches the runtime validator: keys, required, enums and defaults +ok 5 - JSON schema matches the runtime validator: keys, required, enums and defaults + --- + duration_ms: 0.113208 + type: 'test' + ... +# Subtest: every PLACEHOLDER default names its open question +ok 6 - every PLACEHOLDER default names its open question + --- + duration_ms: 0.353583 + type: 'test' + ... +# Subtest: clean shadow run: one hosted run per stage, E would dispatch, squash plan written, never pushed +ok 7 - clean shadow run: one hosted run per stage, E would dispatch, squash plan written, never pushed + --- + duration_ms: 3.609208 + type: 'test' + ... +# Subtest: intent isolation: only context review is given intentFile; the adversarial fleet never sees it +ok 8 - intent isolation: only context review is given intentFile; the adversarial fleet never sees it + --- + duration_ms: 1.110959 + type: 'test' + ... +# Subtest: fix loop: the fixup head is carried between runs in land.bundle, then the gate reruns clean +ok 9 - fix loop: the fixup head is carried between runs in land.bundle, then the gate reruns clean + --- + duration_ms: 2.481667 + type: 'test' + ... +# Subtest: non-convergence: a finding surviving 2 rounds ends needs_human with a ≤150-byte ask +ok 10 - non-convergence: a finding surviving 2 rounds ends needs_human with a ≤150-byte ask + --- + duration_ms: 1.131042 + type: 'test' + ... +# Subtest: formatter guard: a fix round touching files outside change ∪ findings ends needs_human +ok 11 - formatter guard: a fix round touching files outside change ∪ findings ends needs_human + --- + duration_ms: 1.424875 + type: 'test' + ... +# Subtest: changelog required with no new Unreleased bullet becomes a finding for the fix loop +ok 12 - changelog required with no new Unreleased bullet becomes a finding for the fix loop + --- + duration_ms: 1.189292 + type: 'test' + ... +# Subtest: stage D: a moved base rebases and regates; a conflict ends needs_human +ok 13 - stage D: a moved base rebases and regates; a conflict ends needs_human + --- + duration_ms: 1.0085 + type: 'test' + ... +# Subtest: superseded: the land ref moved → cancelled before any work in that run +ok 14 - superseded: the land ref moved → cancelled before any work in that run + --- + duration_ms: 0.185834 + type: 'test' + ... +# Subtest: idempotent cursor: a retried stage whose state write landed is a no-op; a reaped one reruns +ok 15 - idempotent cursor: a retried stage whose state write landed is a no-op; a reaped one reruns + --- + duration_ms: 1.1995 + type: 'test' + ... +# Subtest: stage E in shadow: records what it would dispatch, launches nothing, moves on to F +ok 16 - stage E in shadow: records what it would dispatch, launches nothing, moves on to F + --- + duration_ms: 0.593291 + type: 'test' + ... +# Subtest: the removed githubGateInShadow flag is refused as an unknown key, before any work +ok 17 - the removed githubGateInShadow flag is refused as an unknown key, before any work + --- + duration_ms: 0.147917 + type: 'test' + ... +# Subtest: refusals: no state outside A-adversarial, approval mode, state or intent inside the checkout, wrong run +ok 18 - refusals: no state outside A-adversarial, approval mode, state or intent inside the checkout, wrong run + --- + duration_ms: 0.343666 + type: 'test' + ... +# Subtest: runId: an explicit Cloud id names the Land-Run trailer and every completion detail, not the stateDir path +ok 19 - runId: an explicit Cloud id names the Land-Run trailer and every completion detail, not the stateDir path + --- + duration_ms: 0.375583 + type: 'test' + ... +# Subtest: runId: absent, it falls back to the stateDir segment for local use +ok 20 - runId: absent, it falls back to the stateDir segment for local use + --- + duration_ms: 0.426334 + type: 'test' + ... +# Subtest: runId: a malformed id, or a stateDir segment that is not one, is refused before any work +ok 21 - runId: a malformed id, or a stateDir segment that is not one, is refused before any work + --- + duration_ms: 0.095 + type: 'test' + ... +# Subtest: runId: a stage invoked with another run id is refused and leaves the state alone +ok 22 - runId: a stage invoked with another run id is refused and leaves the state alone + --- + duration_ms: 0.11775 + type: 'test' + ... +# Subtest: $HOME paths: expanded from the run's own HOME, read once per run through a journaled step +ok 23 - $HOME paths: expanded from the run's own HOME, read once per run through a journaled step + --- + duration_ms: 0.50375 + type: 'test' + ... +# Subtest: $HOME paths: a trailing slash on HOME is normalized +ok 24 - $HOME paths: a trailing slash on HOME is normalized + --- + duration_ms: 0.094833 + type: 'test' + ... +# Subtest: $HOME paths: absolute paths never read HOME +ok 25 - $HOME paths: absolute paths never read HOME + --- + duration_ms: 0.320833 + type: 'test' + ... +# Subtest: $HOME paths: refused when HOME is unset, relative, or unsafe +ok 26 - $HOME paths: refused when HOME is unset, relative, or unsafe + --- + duration_ms: 0.11125 + type: 'test' + ... +# Subtest: $HOME paths: only the exact $HOME/ prefix; no other variable, form or .. segment +ok 27 - $HOME paths: only the exact $HOME/ prefix; no other variable, form or .. segment + --- + duration_ms: 0.151625 + type: 'test' + ... +# Subtest: $HOME paths: the outside-checkout check runs on the expanded path +ok 28 - $HOME paths: the outside-checkout check runs on the expanded path + --- + duration_ms: 0.058666 + type: 'test' + ... +# Subtest: absolute paths: a . or .. in any segment is refused, including the first (/../x) +ok 29 - absolute paths: a . or .. in any segment is refused, including the first (/../x) + --- + duration_ms: 0.080917 + type: 'test' + ... +# Subtest: the base fetch deepens a shallow checkout and names only the base refspec +ok 30 - the base fetch deepens a shallow checkout and names only the base refspec + --- + duration_ms: 148.979583 + type: 'test' + ... +# Subtest: auto: dispatch overruns, the next E awaits the pushed snapshot, F squash-pushes and lands +ok 31 - auto: dispatch overruns, the next E awaits the pushed snapshot, F squash-pushes and lands + --- + duration_ms: 1.929958 + type: 'test' + ... +# Subtest: auto: a gate that finishes inside the dispatch window applies its verdict in the same run +ok 32 - auto: a gate that finishes inside the dispatch window applies its verdict in the same run + --- + duration_ms: 0.468708 + type: 'test' + ... +# Subtest: auto: red GitHub gate goes to the next fix round +ok 33 - auto: red GitHub gate goes to the next fix round + --- + duration_ms: 1.183917 + type: 'test' + ... +# Subtest: auto: a failed dispatched run is red to the fix loop +ok 34 - auto: a failed dispatched run is red to the fix loop + --- + duration_ms: 0.911625 + type: 'test' + ... +# Subtest: auto: still-pending dispatched runs keep E as the cursor across stage runs +ok 35 - auto: still-pending dispatched runs keep E as the cursor across stage runs + --- + duration_ms: 0.309541 + type: 'test' + ... +# Subtest: auto: F goes back to D on non-fast-forward +ok 36 - auto: F goes back to D on non-fast-forward + --- + duration_ms: 0.373666 + type: 'test' + ... +# Subtest: auto: a moved base at F goes back to D and regates +ok 37 - auto: a moved base at F goes back to D and regates + --- + duration_ms: 1.031833 + type: 'test' + ... +# Subtest: auto: a non-FF, non-permission push failure ends needs_human +ok 38 - auto: a non-FF, non-permission push failure ends needs_human + --- + duration_ms: 1.173 + type: 'test' + ... +# Subtest: auto and shadow: the land harness is the review fleets' clis and the fix agent's cli +ok 39 - auto and shadow: the land harness is the review fleets' clis and the fix agent's cli + --- + duration_ms: 1.685167 + type: 'test' + ... +# Subtest: auto: a stage reaped after the push records the landed commit instead of landing twice +ok 40 - auto: a stage reaped after the push records the landed commit instead of landing twice + --- + duration_ms: 0.373166 + type: 'test' + ... +# Subtest: auto: F refuses to squash a head that never contained the base +ok 41 - auto: F refuses to squash a head that never contained the base + --- + duration_ms: 0.370292 + type: 'test' + ... +# Subtest: auto: D rebases a head that never contained an unmoved base, then lands +ok 42 - auto: D rebases a head that never contained an unmoved base, then lands + --- + duration_ms: 0.527667 + type: 'test' + ... +# Subtest: auto: three red GitHub gates escalate stuck_finding instead of alternating past the stall checks +ok 43 - auto: three red GitHub gates escalate stuck_finding instead of alternating past the stall checks + --- + duration_ms: 1.070041 + type: 'test' + ... +# Subtest: auto: a run set still growing between polls stays pending; a stable set gives the verdict +ok 44 - auto: a run set still growing between polls stays pending; a stable set gives the verdict + --- + duration_ms: 0.539333 + type: 'test' + ... +# Subtest: auto: a stale completed run older than the dispatch bound cannot produce a verdict +ok 45 - auto: a stale completed run older than the dispatch bound cannot produce a verdict + --- + duration_ms: 0.670791 + type: 'test' + ... +# Subtest: auto and shadow: a non-default harness is the review fleets' clis and the fix agent's cli +ok 46 - auto and shadow: a non-default harness is the review fleets' clis and the fix agent's cli + --- + duration_ms: 0.512667 + type: 'test' + ... +# Subtest: a harness unsupported in land fails at stage one with a clear error +ok 47 - a harness unsupported in land fails at stage one with a clear error + --- + duration_ms: 0.089708 + type: 'test' + ... +# Subtest: each supported fix harness launches with its literal pinned model +ok 48 - each supported fix harness launches with its literal pinned model + --- + duration_ms: 0.799834 + type: 'test' + ... +# Subtest: a review lane that cannot launch its cli ends needs_human, not a fix round +ok 49 - a review lane that cannot launch its cli ends needs_human, not a fix round + --- + duration_ms: 0.111875 + type: 'test' + ... +# Subtest: codex without a login in the stage sandbox ends needs_human at preflight +ok 50 - codex without a login in the stage sandbox ends needs_human at preflight + --- + duration_ms: 0.075416 + type: 'test' + ... +# Subtest: auto: a push-denied git credential fails write preflight at E +ok 51 - auto: a push-denied git credential fails write preflight at E + --- + duration_ms: 0.196708 + type: 'test' + ... +# Subtest: hosted crossed modes refuse before review, agent or push work +ok 52 - hosted crossed modes refuse before review, agent or push work + --- + duration_ms: 0.152791 + type: 'test' + ... +# Subtest: hosted matching modes preserve real auto pushes and shadow no-push behavior +ok 53 - hosted matching modes preserve real auto pushes and shadow no-push behavior + --- + duration_ms: 0.494041 + type: 'test' + ... +# Subtest: hosted mode mismatch refuses an already-advanced stage without rewriting state +ok 54 - hosted mode mismatch refuses an already-advanced stage without rewriting state + --- + duration_ms: 0.121666 + type: 'test' + ... +# Subtest: hosted mode mismatch cannot replay a terminal shadow result as an auto landing +ok 55 - hosted mode mismatch cannot replay a terminal shadow result as an auto landing + --- + duration_ms: 0.399416 + type: 'test' + ... +# Subtest: hosted mergeMode is optional locally and validates all supplied values +ok 56 - hosted mergeMode is optional locally and validates all supplied values + --- + duration_ms: 0.187083 + type: 'test' + ... +# Subtest: hosted auto allows read-only A-D and proves write access only at E/F +ok 57 - hosted auto allows read-only A-D and proves write access only at E/F + --- + duration_ms: 0.565625 + type: 'test' + ... +# Subtest: convergence: a clean gate proceeds, even past the budget or cap +ok 58 - convergence: a clean gate proceeds, even past the budget or cap + --- + duration_ms: 0.747583 + type: 'test' + ... +# Subtest: convergence: findings with rounds and budget left ask for a fix +ok 59 - convergence: findings with rounds and budget left ask for a fix + --- + duration_ms: 0.073208 + type: 'test' + ... +# Subtest: convergence: round cap +ok 60 - convergence: round cap + --- + duration_ms: 0.339 + type: 'test' + ... +# Subtest: convergence: the same finding id surviving 2 consecutive rounds +ok 61 - convergence: the same finding id surviving 2 consecutive rounds + --- + duration_ms: 0.155917 + type: 'test' + ... +# Subtest: convergence: finding count not decreasing for 2 rounds +ok 62 - convergence: finding count not decreasing for 2 rounds + --- + duration_ms: 0.106 + type: 'test' + ... +# Subtest: convergence: budget wins over every other rule +ok 63 - convergence: budget wins over every other rule + --- + duration_ms: 0.04125 + type: 'test' + ... +# Subtest: convergence: refuses an empty history +ok 64 - convergence: refuses an empty history + --- + duration_ms: 0.179208 + type: 'test' + ... +# Subtest: escalation: exact template when it fits +ok 65 - escalation: exact template when it fits + --- + duration_ms: 0.091708 + type: 'test' + ... +# Subtest: escalation: a realistic UUID run URL drops the repo owner first +ok 66 - escalation: a realistic UUID run URL drops the repo owner first + --- + duration_ms: 0.198833 + type: 'test' + ... +# Subtest: escalation: over 150 bytes truncates the summary, keeps the ask and URL intact +ok 67 - escalation: over 150 bytes truncates the summary, keeps the ask and URL intact + --- + duration_ms: 0.272708 + type: 'test' + ... +# Subtest: escalation: counts bytes, not code points, and never splits a character +ok 68 - escalation: counts bytes, not code points, and never splits a character + --- + duration_ms: 0.085583 + type: 'test' + ... +# Subtest: escalation: a URL that cannot fit is refused, never cut +ok 69 - escalation: a URL that cannot fit is refused, never cut + --- + duration_ms: 0.049792 + type: 'test' + ... +# Subtest: formatter guard: allows change files and finding files +ok 70 - formatter guard: allows change files and finding files + --- + duration_ms: 0.092167 + type: 'test' + ... +# Subtest: formatter guard: rejects files outside change ∪ findings and flags cargo fmt churn +ok 71 - formatter guard: rejects files outside change ∪ findings and flags cargo fmt churn + --- + duration_ms: 0.054375 + type: 'test' + ... +# Subtest: finding ids survive line moves and the verifier's "raised before" marker +ok 72 - finding ids survive line moves and the verifier's "raised before" marker + --- + duration_ms: 0.17225 + type: 'test' + ... +# Subtest: changelog: requires a new bullet under \#\# Unreleased +ok 73 - changelog: requires a new bullet under \#\# Unreleased + --- + duration_ms: 0.156584 + type: 'test' + ... +# Subtest: isInside +ok 74 - isInside + --- + duration_ms: 0.054583 + type: 'test' + ... +# Subtest: squash plan carries the trailers and is never marked pushed +ok 75 - squash plan carries the trailers and is never marked pushed + --- + duration_ms: 0.069584 + type: 'test' + ... +# Subtest: expandHome: only the literal $HOME/ prefix, against an absolute HOME +ok 76 - expandHome: only the literal $HOME/ prefix, against an absolute HOME + --- + duration_ms: 0.178792 + type: 'test' + ... +# Subtest: clean run: A-adversarial → A-context → B → D → E (would dispatch) → F → landed +ok 77 - clean run: A-adversarial → A-context → B → D → E (would dispatch) → F → landed + --- + duration_ms: 1.089375 + type: 'test' + ... +# Subtest: E in shadow always reports would-dispatch and moves on to F, without closing a gate +ok 78 - E in shadow always reports would-dispatch and moves on to F, without closing a gate + --- + duration_ms: 0.414166 + type: 'test' + ... +# Subtest: the gate unions all three lanes and feeds the fix round +ok 79 - the gate unions all three lanes and feeds the fix round + --- + duration_ms: 0.129916 + type: 'test' + ... +# Subtest: convergence stop: the same finding id surviving 2 consecutive rounds +ok 80 - convergence stop: the same finding id surviving 2 consecutive rounds + --- + duration_ms: 0.3205 + type: 'test' + ... +# Subtest: convergence stop: count not decreasing for 2 rounds +ok 81 - convergence stop: count not decreasing for 2 rounds + --- + duration_ms: 0.178292 + type: 'test' + ... +# Subtest: convergence stop: round cap and wallclock budget +ok 82 - convergence stop: round cap and wallclock budget + --- + duration_ms: 0.235541 + type: 'test' + ... +# Subtest: formatter guard breach and rebase conflict end needs_human; a clean rebase regates +ok 83 - formatter guard breach and rebase conflict end needs_human; a clean rebase regates + --- + duration_ms: 0.274334 + type: 'test' + ... +# Subtest: superseded: the land ref moved (or was deleted) → cancelled, from any stage +ok 84 - superseded: the land ref moved (or was deleted) → cancelled, from any stage + --- + duration_ms: 0.193833 + type: 'test' + ... +# Subtest: pure and fail-closed: no mutation, wrong result kinds and terminal states refused +ok 85 - pure and fail-closed: no mutation, wrong result kinds and terminal states refused + --- + duration_ms: 0.387375 + type: 'test' + ... +# Subtest: idempotent: the same state and result always give the same next state +ok 86 - idempotent: the same state and result always give the same next state + --- + duration_ms: 0.325792 + type: 'test' + ... +# Subtest: land-state.json round-trips and refuses other versions +ok 87 - land-state.json round-trips and refuses other versions + --- + duration_ms: 0.348958 + type: 'test' + ... +# Subtest: auto E: pending keeps the cursor at E, green moves to F, red feeds the fix loop +ok 88 - auto E: pending keeps the cursor at E, green moves to F, red feeds the fix loop + --- + duration_ms: 0.119292 + type: 'test' + ... +# Subtest: auto E: a red gate still escalates on round cap +ok 89 - auto E: a red gate still escalates on round cap + --- + duration_ms: 0.115833 + type: 'test' + ... +# Subtest: auto F: pushed lands with the commit; moved and non_ff go back to D +ok 90 - auto F: pushed lands with the commit; moved and non_ff go back to D + --- + duration_ms: 0.115625 + type: 'test' + ... +# Subtest: mode discipline: shadow outcomes refuse auto and vice versa +ok 91 - mode discipline: shadow outcomes refuse auto and vice versa + --- + duration_ms: 0.155167 + type: 'test' + ... +1..91 +# tests 91 +# suites 0 +# pass 91 +# fail 0 +# cancelled 0 +# skipped 0 +# todo 0 +# duration_ms 279.924708 diff --git a/examples/land/evidence/staged-write-preflight/typecheck.txt b/examples/land/evidence/staged-write-preflight/typecheck.txt new file mode 100644 index 000000000..96a7245a2 --- /dev/null +++ b/examples/land/evidence/staged-write-preflight/typecheck.txt @@ -0,0 +1,4 @@ + +> typecheck +> tsc -p tsconfig.json + diff --git a/examples/land/evidence/staged-write-preflight/verification.md b/examples/land/evidence/staged-write-preflight/verification.md new file mode 100644 index 000000000..e4ee6385f --- /dev/null +++ b/examples/land/evidence/staged-write-preflight/verification.md @@ -0,0 +1,43 @@ +# Hosted auto stage grants + +Cloud PR #5944 limits repository write grants to auto stages E/F. The existing +land flow instead proves push access at every auto stage, so a correctly +read-only A stage refuses before review. Limit that preflight to E/F; early +review, fix and rebase stages keep read-only access. The preflight still refuses +an E-stage write denial before dispatching the GitHub gate or pushing. + +Commands use Node v22.22.2 from this worktree. For the regression, temporarily +replace only the E/F condition with the old unconditional auto condition: + +```sh +PATH=/Users/khaliqgant/.nvm/versions/node/v22.22.2/bin:$PATH node --experimental-strip-types --test --test-name-pattern='hosted auto allows read-only' examples/land/tests/flow.test.ts +``` + +The final regression test fails at read-only A-adversarial, exit 1: literal +[baseline.txt](baseline.txt). Restored `land.flow.ts` byte-for-byte, SHA256 +`12e10654f13d52343a2d25d343de85642955825415c5a3cae20cee44bd018ffb`. +Then ran: + +```sh +PATH=/Users/khaliqgant/.nvm/versions/node/v22.22.2/bin:$PATH npm --prefix examples/land run typecheck +PATH=/Users/khaliqgant/.nvm/versions/node/v22.22.2/bin:$PATH npm --prefix examples/land test +``` + +Both exit 0: literal [typecheck.txt](typecheck.txt) and +[land-tests.txt](land-tests.txt), 91 passed, 0 failed. The regression drives +A, B, a C fix round, and D without a push probe, then proves an E write denial +refuses. Existing matching-mode auto coverage still completes through F. +These are local fixtures; this does not prove the hosted grant boundary. + +No runtime packages, model pins, or gates change. No npm release is needed. +The land operator must redeploy the source after human review and merge. + +Literal hash check after restoration: + +```sh +shasum -a 256 examples/land/land.flow.ts +``` + +```text +12e10654f13d52343a2d25d343de85642955825415c5a3cae20cee44bd018ffb examples/land/land.flow.ts +``` diff --git a/examples/land/land.flow.ts b/examples/land/land.flow.ts index 4569352ef..b48723f69 100644 --- a/examples/land/land.flow.ts +++ b/examples/land/land.flow.ts @@ -921,9 +921,9 @@ export async function land(f: Ctx, raw: LandInput): Promise { const want = `${config.runner.os === 'linux' ? 'Linux' : 'Darwin'} ${config.runner.arch === 'x64' ? 'x86_64' : 'arm64'}`; if (uname.replace('aarch64', 'arm64') !== want) throw new NeedsHuman(`runner is ${uname}; land.config needs ${want}`); await f.run(config.runner.commands.map(c => `command -v ${shellWord(c)} >/dev/null`).join(' && ') || 'true'); - if (config.mergePolicy.mode === 'auto') { - // Preflight, not polling: the GitHub gate and the push need an authed gh - // and a write-capable git credential; prove both at stage one. + if (config.mergePolicy.mode === 'auto' && (input.stage === 'E' || input.stage === 'F')) { + // Cloud grants A-D read-only access. Prove write capability only in + // E/F, where the GitHub gate and final push need the scoped write grant. const gh = await f.run(`command -v gh >/dev/null && gh auth status`, { onNonZero: 'record' }); if (!gh.ok) throw new NeedsHuman('mergePolicy.mode "auto" needs gh installed and authenticated (a write repository grant); shadow runs do not'); // Write access is proven by dry-running a push to a fresh throwaway ref: diff --git a/examples/land/tests/flow.test.ts b/examples/land/tests/flow.test.ts index e0b3c87a4..86adef47e 100644 --- a/examples/land/tests/flow.test.ts +++ b/examples/land/tests/flow.test.ts @@ -692,7 +692,7 @@ test('codex without a login in the stage sandbox ends needs_human at preflight', assert.equal(w.agents.length, 0, 'stage one stopped: no fix agent ran'); }); -test('auto: a push-denied git credential fails preflight before any stage runs', async () => { +test('auto: a push-denied git credential fails write preflight at E', async () => { const w = world({ config: autoConfig, pushDryRunFails: true }); const { result } = await w.drive(); assert.equal(result.reason, 'needs_human'); @@ -756,3 +756,27 @@ test('hosted mergeMode is optional locally and validates all supplied values', ( assert.throws(() => parseInput({ ...input, mergeMode } as LandInput), /mergeMode must match/); } }); + + +test('hosted auto allows read-only A-D and proves write access only at E/F', async () => { + const w = world({ config: autoConfig, pushDryRunFails: true, + adversarial: [[blocker('probe/src/relay/agents.rs', 'fix')], []], roundFiles: [['probe/src/relay/agents.rs']] }); + let stage = 'A-adversarial'; + const seen: string[] = []; + for (let i = 0; i < 12 && stage !== 'E'; i++) { + seen.push(stage); + const result = await w.invoke(stage, { mergeMode: 'auto' }); + assert.equal(result.reason, 'success', `read-only ${stage} must advance`); + assert.equal(result.detail.land, 'next'); + neverPushes(w.commands); + stage = String(result.detail.stage); + } + assert.equal(stage, 'E'); + assert.ok(seen.some(s => s.startsWith('C-')), 'the read-only fix agent stage ran'); + assert.equal(w.agents.length, 1); + assert.ok(seen.includes('D'), 'the read-only rebase stage ran'); + const result = await w.invoke('E', { mergeMode: 'auto' }); + assert.equal(result.reason, 'needs_human'); + assert.match(String(result.detail.detail), /push-capable git credential/); + assert.equal(w.commands.flat().filter(c => c.includes('git push --dry-run')).length, 1); +});