Skip to content

tracking: test/fixture invocations pollute production history.db #91

Closed

Description

@thehoff

Symptom

Local production tracking DB contains 175+ rows of `git -C /path status test_NNNNN` and dozens of `cargo --version` parse_failures, all originating from `/Users/thehoff/…/rtk-fork` and `/Users/thehoff/Workspace/contextZip/rtk-fork` (the old path). These are the project's own integration tests writing to the user's live `~/Library/Application Support/rtk/history.db`.

```
$ sqlite3 history.db "SELECT raw_command FROM parse_failures WHERE raw_command LIKE 'git -C /path status test%' LIMIT 3;"
git -C /path status test_95136
git -C /path status test_77560
git -C /path status test_3698
```

Impact

  • Distorts `contextcrawler gain` and `discover` output for any developer running the test suite.
  • Hides genuine user-traffic patterns under fixture noise.
  • Wastes IO on every test run that should write nowhere.

Fix

Two complementary changes; either alone helps, both is best.

Change 1 — tests use an isolated DB

In `tests/common/mod.rs` (or wherever the integration-test harness lives), set:

```rust
std::env::set_var("RTK_DB_PATH", tempfile::NamedTempFile::new()?.path());
```

before invoking `contextcrawler`. `core::config::tracking_database_path` already honours the env var; tests just need to opt in.

Change 2 — detect test context and short-circuit

In `core::tracking::TimedExecution::track` / `track_passthrough` / `record_parse_failure_silent`, bail before writing if:

  • `CARGO_PKG_NAME == "contextcrawler"` AND `CARGO_MANIFEST_DIR` is set (running under `cargo test` inside the project), OR
  • `RUST_TEST_THREADS` is set (test runner active), OR
  • `RTK_DB_PATH == "/dev/null"` (explicit opt-out).

A simple `fn is_test_context() -> bool` helper consulted by every write-path is enough.

Acceptance

  • After fix, running `cargo test --workspace` produces ZERO new rows in `~/Library/Application Support/rtk/history.db`.
  • A targeted integration test that needs tracking can opt in by setting `RTK_DB_PATH=` explicitly.
  • Existing user telemetry is untouched.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions