Skip to content

fix(amico-run): isolate the coordination-ledger contract suite from the production ledger (#642) - #644

Open
aarontrowbridge wants to merge 3 commits into
mainfrom
642-fix-coordination-ledger-test-isolation
Open

fix(amico-run): isolate the coordination-ledger contract suite from the production ledger (#642)#644
aarontrowbridge wants to merge 3 commits into
mainfrom
642-fix-coordination-ledger-test-isolation

Conversation

@aarontrowbridge

Copy link
Copy Markdown
Member

Closes #642

What

The coordination-ledger contract suite was writing synthetic fixture claims into the production ledger: the service's default path resolution falls back to the real claims ledger when no isolation env is set, and the suite constructed the service bare. The production ledger held 176 fixture rows and zero real claims before ops archived it (2026-08-30).

The fix routes every suite claims write through the existing isolation bridge (AMICO_CLAIMS_FILE → per-run tmp partition) — a test-only change, zero source edits: the seam already existed (claims-file resolution reads the env per append), so production callers keep their default path untouched. A fail-closed backstop in the shared test setup additionally refuses any future suite that forgets to isolate.

Acceptance criteria — evidence

  • Contract suite passes with the claims path isolated, asserting no write reaches production — RED commit reproduced the exact 176-row mechanism under a fake HOME (pristine ledger grew 1→6 lines in one run); GREEN commit: 7/7 tests pass with the guard asserting claim writes landed in the mkdtemp partition and the production path stayed byte-identical (suite-wide afterAll re-assert).
  • A fresh run leaves a pristine claims ledger untouched — verified across three HOME shapes: existing ledger → sha256 identical before/after; CI shape (no ledger) → file never created; real HOME → archived path absent before and after.
  • Ops archive noted — referenced in the backstop comment, all three commit messages, and the test file docs.

Director gates (run independently on this branch)

  • pnpm --filter amico-run typecheck — clean
  • pnpm --filter amico-run test74 files / 1187 passed / 13 skipped / 0 failed
  • Diff is test-only (+64/−1 across two test files), so the esbuild bundle surface is structurally unchanged.

Judgment calls

  • Kept the package-wide fail-closed backstop in the shared test setup (slightly beyond minimal scope, flagged by the implementer as droppable): it mirrors the documented AMICO_LEDGER sibling backstop and makes the whole bug class structurally impossible rather than just this suite — which is the point of the issue.
  • Environment hermeticity: one pre-existing, unrelated failure exists — agent_spawn.test.ts fails in any harness that exports OPENCODE_CONFIG_CONTENT (e.g. sessions inside the amicode server) because the OPENCODE_-prefix allowlist forwards the var to the spawned child. Proven pre-existing on pristine origin/main (fails identically there; passes 40/40 with the var scrubbed). Follow-up issue filed; not a regression of this branch.

Merge

Awaiting human review (afk campaign — merges stay human-only). CI will run on this PR; ready-for-review flips once green.

…lated partition (#642)

RED tracer: the guard test constructs the coordination service the way the
suite always has — bare — and asserts (a) the claim line lands in the suite's
per-run tmp partition and (b) the production claims ledger
(~/.amico/ledger/claims.jsonl) stays byte-identical to its module-load
snapshot. It fails today: with $AMICO_CLAIMS_FILE unset the service's
default-path resolution appends every fixture claim to the production ledger
(reproduced under a fake HOME: 1 pristine line grew to 6 in one run; on the
server this accumulated 176 rows before ops archived the ledger
2026-08-30).
…MS_FILE bridge (#642)

GREEN: file-level beforeAll points $AMICO_CLAIMS_FILE at a per-run tmp
partition (mkdtemp) — the seam claimsFile() reads per append, so every
service construction in the suite, present and future, writes there while
production callers keep their default. afterAll adds the order-robust
suite-wide guard (production ledger byte-identical to its module-load
snapshot, or still absent), restores the env per the repo idiom so nothing
leaks across suites, and removes the tmp partition.

Verified in all three shapes: pristine ledger byte-identical (sha256 equal),
CI shape (no ledger) creates nothing, and the archived real path stays
absent. Suite 7/7 green.
…ite the real claims ledger (#642)

The runs-ledger backstop above exists because "the risk is in the test
someone writes next" — the claims ledger had no such guard, which is exactly
how the contract suite polluted it: 176 fixture rows before ops archived the
ledger 2026-08-30 as claims.jsonl.archive-20260830-test-pollution (no
in-repo action beyond this guard). Mirrors the AMICO_LEDGER pattern:
set-if-unset to a /nonexistent path, so an unset claims env fails closed
(mkdir at the filesystem root throws; preflight's durable append is
deliberately best-effort) instead of resolving to
~/.amico/ledger/claims.jsonl. Suites that want real claim-file I/O point the
env at their own tmp partition — the contract suite now does; this is the
backstop for the ones that forget.

Verified behaviorally with a scratch forgetful suite (bare construction,
env unset): polluted the default path before this commit, fails closed after
— no file created, claim semantics unaffected (preflight still ok).
@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 45ef92c3-c3ec-4132-8593-e5ac33a25db0


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

BUG: coordination-ledger contract suite writes fixture claims into the production ledger

1 participant