Repository navigation
fix(db): keep test runs off the operator's real DATA_DIR - #10432
Merged
Merged
Conversation
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
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.
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.
Closes #10428.
Problem
Any process that opens the DB without setting
DATA_DIRresolves to~/.omniroute/storage.sqlite— the operator's live database, provider credentials included.tests/_setup/isolateDataDir.tsprotects 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-hocnode --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 functionsrc/lib/db/core.tsuses to pick the DB location — now redirects a test-context process that never chose aDATA_DIRto a throwaway temp dir, stable for the process so repeated calls share one DB.Test context is detected via
NODE_TEST_CONTEXT(set bynode --testin every spawned test process),VITEST,NODE_ENV=test, or an explicit--testflag — 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=1opts back in, so a deliberate run against the real dir is recorded rather than silent.Validation
DATA_DIRstill wins, escape hatch works, a normal server run is untouched,NODE_TEST_CONTEXTdetection, and stability across calls.auth-terminal-status,agentrouter-lock-scope-10334,auth-ollama-cloud-per-model-403-3027,mark-account-unavailable-numeric-epoch-guard.typecheck:coreand eslint clean.