Repository navigation
Conversation
|
Fresh data point for this, from today: I ran SELECT COUNT(*) FROM parse_failures
WHERE (raw_command GLOB 'cmd_ok*' OR raw_command GLOB 'cmd_fail*'
OR raw_command GLOB '*test_[0-9]*');returns 32 all-time, 8 of them written today. Samples, PID-suffixed straight out of the fixtures: Those sit in the same table as real telemetry and are indistinguishable from it downstream unless you know the fixture naming. My Practical effect: anyone following CONTRIBUTING's instruction to run |
`cargo test` — which CONTRIBUTING instructs contributors to run — inserted rows into the developer's live `<data-dir>/rtk/history.db`. On one machine a single full run wrote 25 `commands` rows and 8 `parse_failures` rows, which then show up in `rtk gain` output and in anything downstream that treats that database as real telemetry. Fix it at the point where the database is opened rather than per test. Every write path funnels through `Tracker::new()`, so the leak is not limited to the few tests in this module that construct a Tracker directly: command tests that exercise the real code path via `TimedExecution` leak too, and in practice those (`find`, `git`, `read`) accounted for the majority of the observed rows. Converting individual tests to `new_in_memory()` would have missed them. `tracker_db_path()` diverts to a per-process temp file under `cfg(test)`, so no present or future test can reach the real database regardless of which code path it exercises. An explicit `RTK_DB_PATH` still takes precedence, and `get_db_path()` stays a pure configuration resolver so `test_db_path_env_and_default` continues to assert the real precedence rules instead of the test shim. Verified: full suite on x86_64-pc-windows-msvc leaves zero test rows in the real database and writes to `rtk-test-history-<pid>.db` in the temp dir instead. cargo fmt --check and cargo clippy --all-targets clean. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01AjBptHzBAhjM1TcMu32AYD
55d894d to
3df0f9d
Compare
|
Rebased onto current
Re-measured today, since
Same full run with this branch applied: zero fixture rows written. So the blast radius moved from Full gate on Windows: fmt clean, clippy zero warnings, 3595 passed / 0 failed (the 3 Windows-only failures on |
|
Closing in favour of #3758, which fixes the same leak at the root: it redirects rtk's whole data directory under cfg(test), so the tracking database, the tee spool, the telemetry salt, the trust store and the hook markers are all covered, and it adds a guard test for children spawned by the suite. This change covers the tracking database only, so merging #3758 makes it redundant. Review and comments are very welcome on #3758, or reply here if you had a case in mind that it does not cover. |
Problem
cargo test— which CONTRIBUTING instructs contributors to run — inserted rows into the developer's live<data-dir>/rtk/history.db. On one machine a single full run wrote 25commandsrows and 8parse_failuresrows, which then show up inrtk gainoutput and in anything downstream that treats that database as real telemetry.Why the fix is at
tracker_db_path()and not per-testEvery write path funnels through
Tracker::new(), so the leak is not limited to the few tests in this module that construct aTrackerdirectly: command tests that exercise the real code path viaTimedExecutionleak too, and in practice those (find,git,read) accounted for the majority of the observed rows. Converting individual tests tonew_in_memory()would have missed them — I counted 10 rows attributable to the direct-Trackertests out of 25 total.tracker_db_path()diverts to a per-process temp file undercfg(test), so no present or future test can reach the real database regardless of which code path it exercises.Preserved behaviour
RTK_DB_PATHstill takes precedence.get_db_path()stays a pure configuration resolver, sotest_db_path_env_and_defaultcontinues to assert the real precedence rules instead of the test shim.Verification
Full suite on
x86_64-pc-windows-msvcleaves zero test rows in the real database and writes tortk-test-history-<pid>.dbin the temp dir instead.cargo fmt --checkandcargo clippy --all-targetsclean.