Repository navigation
Description
Filed as an issue rather than a pull request: PR creation from outside accounts is currently refused on this repo (GraphQL returns FORBIDDEN for CreatePullRequest), and no non-owner PR has been opened since 2026-06-11. Issue creation still works, so I'm following CONTRIBUTING's preference for issues anyway.
Branch with the change, if useful as a reference: fix/telemetry-test-isolation
Problem
The telemetry-core test suite reads the real ~/.jcode, so whether it passes depends on whose machine it runs on. On any machine where the developer has opted out of telemetry, 12 of 35 tests fail.
Reproduction, on a clean checkout with no other changes:
touch ~/.jcode/no_telemetry
cargo test -p jcode-telemetry-core --lib
# test result: FAILED. 23 passed; 12 failed
A single marker file is enough.
Why the failure looks unrelated to telemetry
This is the part that took me a while to see, so it seems worth writing down.
is_enabled() reads ~/.jcode/no_telemetry, so begin_session_with_mode returns early and leaves SESSION_STATE as None. The first expect(...) then panics while holding the lock, which poisons it. The remaining session tests fail with PoisonError, not with anything mentioning telemetry or opt-out. So only the first failure points at the real cause and the other 11 are noise.
Second, quieter problem
Before this change, running the test suite wrote into the developer's own ~/.jcode: telemetry_id, session-start records, and telemetry_active_sessions/ entries. Tests were mutating real user state.
Fix
jcode_dir() already honors JCODE_HOME, so the fix is to point it at a directory owned by the test binary for the duration of the run.
The directory is a per-pid path under a shared root rather than a tempfile::TempDir held in a static. I originally wrote the static version, on the model of the tempfile::tempdir() + JCODE_HOME pattern in jcode-provider-openrouter-runtime, and it is wrong here: Rust does not drop statics, so it leaked one directory per cargo test run. I noticed only after 82 of them had accumulated in my own home directory. Each run now also sweeps sibling entries untouched for ten minutes, which reclaims the homes of runs that crashed before cleaning up, while leaving a concurrently running test process alone.
One file, no production code touched.
Verification
35 passed; 0 failed in four configurations:
- real
HOMEwith the opt-out marker present (previously 23/12) - sandboxed
HOMEwith the marker - sandboxed
HOMEwithout the marker --test-threads=1and the default parallel runner
Also confirmed the suite writes nothing into a real jcode home, and that three consecutive runs add no leftover directories. The sweep itself is verified by planting a back-dated entry and watching the next run remove it.
cargo fmt, clippy -D warnings, and the five ratchet scripts flag exactly the same files on this branch as on master, none from this change. (Master is currently red on several of those gates independently of this change, so I compared file sets rather than pass/fail.)
Notes
This fits CONTRIBUTING's issue-first preference well, since it reproduces with a single touch. The branch is linked above only in case the diff is useful as a reference. Happy for it to be treated purely as a reproduction.
Disclosure: written with agent assistance, reviewed and verified by me. The reproduction and the four-configuration verification above were actually run, not assumed.
Activity
1jehuang commentedon Aug 12, 2026
Isolated telemetry tests from the developer's real Jcode home and opt-out state in #907. The telemetry-core suite passes with 39 tests.
— Jcode agent (automated triage), on behalf of @1jehuang
fix: isolate telemetry tests from user config (fixes 1jehuang#892)
chore: sync fork with upstream jcode (fresh merge onto current master) (
fix: isolate telemetry tests from user config (fixes 1jehuang#892)
fix: isolate telemetry tests from user config (fixes 1jehuang#892)
fix: isolate telemetry tests from user config (fixes 1jehuang#892)
fix: isolate telemetry tests from user config (fixes 1jehuang#892)
fix: isolate telemetry tests from user config (fixes 1jehuang#892)
fix: isolate telemetry tests from user config (fixes 1jehuang#892)