test(opencode): isolate the custody log sink from the live state file - #60
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.jsonlheld 2473 rows, and 1989 of them (80%) came from 435 PIDs that lived under two seconds, one perbun testrun. One example: pid 793109 wrote nine rows in 40ms, one second after a gate run started, with statesserving,transient/transport_error,CustodyExhaustionError,served,timeout,gonefor providerdeepseek. Read cold, the file describes a deepseek not-found incident that never happened.Mechanism:
plugin.tsfalls through to the default file sink when a test constructs a plugin or serve closure without injecting a logger (createLogger(dependencies.logSink ?? ...)).serve.test.tsbuilds eight and injects a logger into five;freshness.test.tsten 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 rootbunfig.tomland a packagebunfig.toml(root-invokedbun test packages/...does not pick up the package file; verified both invocation shapes print the guarded env): setsCLAUSTRUM_CUSTODY_LOG=offunless a test set it explicitly, and pointsXDG_STATE_HOMEat a freshmkdtempdirectory so even a test that sets a state-relative path cannot reach the real one.package.jsontest:hermeticgainsCLAUSTRUM_CUSTODY_LOG=offbeside 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: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.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by cubic
Stops the
opencodeplugin'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
bunfig.tomlfiles, setsCLAUSTRUM_CUSTODY_LOG=offunless a test sets it and redirectsXDG_STATE_HOMEto a fresh temp directory so state-relative paths can't reach the live file.test:hermeticscript gains the same env override so the gate stays isolated even if bunfig resolution changes.sink-isolation.test.tsbuilds 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.Written for commit e8b9a24. Summary will update on new commits.