Skip to content

test(opencode): isolate the custody log sink from the live state file - #60

Merged
ualtinok merged 1 commit into
cortexkit:masterfrom
legion-works:fix/test-sink-isolation
Sep 18, 2026
Merged

ualtinok merged 1 commit into
cortexkit:masterfrom
legion-works:fix/test-sink-isolation

Conversation

@iceteaSA

@iceteaSA iceteaSA commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

What was wrong

The plugin's hermetic test suite writes into the operator's live telemetry file.

Measured on the deployment that runs this plugin: ~/.local/state/cortexkit/opencode-plugin/custody.jsonl held 2473 rows, and 1989 of them (80%) came from 435 PIDs that lived under two seconds, one per bun test run. One example: pid 793109 wrote nine rows in 40ms, one second after a gate run started, with states serving, transient/transport_error, CustodyExhaustionError, served, timeout, gone for provider deepseek. Read cold, the file describes a deepseek not-found incident that never happened.

Mechanism: plugin.ts falls through to the default file sink when a test constructs a plugin or serve closure without injecting a logger (createLogger(dependencies.logSink ?? ...)). serve.test.ts builds eight and injects a logger into five; freshness.test.ts ten and eight. The default sink is the real state path.

Change

Two layers, on purpose. Injecting a logger into each existing test fixes the tests that exist; the next test that forgets is the one that matters.

  • packages/opencode/src/tests/preload.ts, wired from a root bunfig.toml and a package bunfig.toml (root-invoked bun test packages/... does not pick up the package file; verified both invocation shapes print the guarded env): sets CLAUSTRUM_CUSTODY_LOG=off unless a test set it explicitly, and points XDG_STATE_HOME at a fresh mkdtemp directory so even a test that sets a state-relative path cannot reach the real one.
  • Root package.json test:hermetic gains CLAUSTRUM_CUSTODY_LOG=off beside the two existing isolation vars, so the gate path is isolated even if bunfig resolution changes.
  • sink-isolation.test.ts: builds a serve closure with no logger, drives one serve, and asserts the $HOME-derived live path gained nothing (existence, content, mtime).

Verification

The arrival proof, run by me on the live file as the oracle. Defeating layer 1 alone (CLAUSTRUM_CUSTODY_LOG= empty) is absorbed by layer 2 and stays green, which is the design working, not the test failing to discriminate. The discriminating mutation is disarming the preload itself:

preload.ts replaced with a comment (0 env assignments)
  0 pass 1 fail · live rows 2512 -> 2515 (+3)
preload.ts restored byte-identically (cmp)
  1 pass 0 fail · live rows unchanged

Those three rows are the last fixture rows that file will receive from this suite.

bun run test:hermetic: 230 pass, 0 fail. bash scripts/gate.sh: exit 0. Five files, 84 insertions, 1 deletion, all in the test harness; no source change.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Stops the opencode plugin's hermetic tests from writing into the operator's live custody log. Tests previously produced 80% of the rows in ~/.local/state/cortexkit/opencode-plugin/custody.jsonl — including a phantom deepseek not-found incident — because a plugin built without an injected logger falls through to the real file sink.

Bug Fixes

  • A preload, wired from both bunfig.toml files, sets CLAUSTRUM_CUSTODY_LOG=off unless a test sets it and redirects XDG_STATE_HOME to a fresh temp directory so state-relative paths can't reach the live file.
  • The test:hermetic script gains the same env override so the gate stays isolated even if bunfig resolution changes.
  • sink-isolation.test.ts builds a logger-less plugin, serves once, and asserts the live path is unchanged; removing the preload makes it fail and writes 3 rows to the live file, proving it discriminates.
  • No source changes — the diff is confined to the test harness and scripts.

Written for commit e8b9a24. Summary will update on new commits.

Review in cubic

The hermetic suite previously contributed 1989 of 2473 live custody-log rows, including 435 short-lived test PIDs. Add process-level Bun preloads plus the hermetic script override so tests cannot write the operator's sink.
@ualtinok
ualtinok merged commit 568333d into cortexkit:master Sep 18, 2026
6 checks passed
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.

2 participants