Skip to content

fix(db): keep test runs off the operator's real DATA_DIR - #10432

Merged
diegosouzapw merged 2 commits into
release/v3.8.50from
fix/datadir-test-guard
Aug 15, 2026
Merged

diegosouzapw merged 2 commits into
release/v3.8.50from
fix/datadir-test-guard

Conversation

@diegosouzapw

Copy link
Copy Markdown
Collaborator

Closes #10428.

Problem

Any process that opens the DB without setting DATA_DIR resolves to ~/.omniroute/storage.sqlite — the operator's live database, provider credentials included. tests/_setup/isolateDataDir.ts protects the npm test scripts, but it is opt-in per invocation: the AGENTS.md-documented single-file command (node --import tsx/esm --test tests/unit/x.test.ts) does not load it, and neither does an ad-hoc node --import tsx probe.ts.

This is not hypothetical — during #10334 a verification script did exactly that and opened the real DB (audited afterwards: integrity ok, nothing lost).

Fix

resolveWritableDataDir — the single function src/lib/db/core.ts uses to pick the DB location — now redirects a test-context process that never chose a DATA_DIR to a throwaway temp dir, stable for the process so repeated calls share one DB.

Test context is detected via NODE_TEST_CONTEXT (set by node --test in every spawned test process), VITEST, NODE_ENV=test, or an explicit --test flag — covering both runners plus the single-file command.

Redirect rather than throw, deliberately: a hard failure on the documented command would only teach people to disable the guard. OMNIROUTE_ALLOW_DEFAULT_DATA_DIR=1 opts back in, so a deliberate run against the real dir is recorded rather than silent.

Validation

  • 6 new tests: redirect happens, explicit DATA_DIR still wins, escape hatch works, a normal server run is untouched, NODE_TEST_CONTEXT detection, and stability across calls.
  • Re-ran the DB-heavy suites most exposed to this change (35/35): auth-terminal-status, agentrouter-lock-scope-10334, auth-ollama-cloud-per-model-403-3027, mark-account-unavailable-numeric-epoch-guard.
  • typecheck:core and eslint clean.

⚠️ base-red inherited: #9985

A script or test that opens the DB without setting DATA_DIR resolved to
~/.omniroute — the operator's live database, provider credentials included.
tests/_setup/isolateDataDir.ts only covers the npm scripts; the documented
single-file command and any ad-hoc probe bypass it.

resolveWritableDataDir now redirects a test-context process with no DATA_DIR
to a throwaway temp dir (stable per process), keeping the documented command
working instead of failing it. OMNIROUTE_ALLOW_DEFAULT_DATA_DIR=1 opts back in.

Closes #10428
…ests

The env-doc-sync gate requires every env var referenced in code to be
documented, and two pre-existing tests pinned the old behavior while
themselves running in a test context:

- .env.example + docs/reference/ENVIRONMENT.md document
  OMNIROUTE_ALLOW_DEFAULT_DATA_DIR.
- data-dir-writable-fallback and db-core-init opt into the real dir
  explicitly, so they keep asserting the SERVER path instead of the guard.
@diegosouzapw
diegosouzapw merged commit 2a04b24 into release/v3.8.50 Aug 15, 2026
22 checks passed
@diegosouzapw
diegosouzapw deleted the fix/datadir-test-guard branch August 15, 2026 05:33
diegosouzapw added a commit that referenced this pull request Aug 25, 2026
The router-eval CLI test spawns the CLI with spawnSync and asserts stderr stays empty. NODE_TEST_CONTEXT is inherited by those children, so since #10432 (guard #10428) resolveWritableDataDir() detects a test context with no DATA_DIR and warns on stderr before falling back to a throwaway dir - 194 chars that broke three cases. Pass an isolated DATA_DIR in the child env (the resolution the guard message itself prescribes) instead of loosening the assertions.
tkgo11 pushed a commit to tkgo11/OmniRoute that referenced this pull request Sep 23, 2026
…erence#10432)

Any process that opened the DB without setting DATA_DIR resolved to ~/.omniroute/storage.sqlite — the operator's live database, provider credentials included. tests/_setup/isolateDataDir.ts only covers the npm scripts; the documented single-file test command and ad-hoc probes bypassed it (one did exactly that during cheaper-inference#10334).

resolveWritableDataDir now redirects a test-context process with no DATA_DIR to a throwaway temp dir, stable per process. Redirect rather than throw, so the documented single-file command keeps working; OMNIROUTE_ALLOW_DEFAULT_DATA_DIR=1 opts back in and records the intent.

Closes cheaper-inference#10428
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
…erence#10432)

Any process that opened the DB without setting DATA_DIR resolved to ~/.omniroute/storage.sqlite — the operator's live database, provider credentials included. tests/_setup/isolateDataDir.ts only covers the npm scripts; the documented single-file test command and ad-hoc probes bypassed it (one did exactly that during cheaper-inference#10334).

resolveWritableDataDir now redirects a test-context process with no DATA_DIR to a throwaway temp dir, stable per process. Redirect rather than throw, so the documented single-file command keeps working; OMNIROUTE_ALLOW_DEFAULT_DATA_DIR=1 opts back in and records the intent.

Closes cheaper-inference#10428
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
The router-eval CLI test spawns the CLI with spawnSync and asserts stderr stays empty. NODE_TEST_CONTEXT is inherited by those children, so since cheaper-inference#10432 (guard cheaper-inference#10428) resolveWritableDataDir() detects a test context with no DATA_DIR and warns on stderr before falling back to a throwaway dir - 194 chars that broke three cases. Pass an isolated DATA_DIR in the child env (the resolution the guard message itself prescribes) instead of loosening the assertions.
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.

fix(db): refuse to open the operator's real DATA_DIR from test/ad-hoc runs

2 participants