Skip to content

test: isolate the suite from the operator's meridian environment - #927

Closed
materemias wants to merge 1 commit into
rynfar:mainfrom
materemias:fix/test-env-isolation
Closed

test: isolate the suite from the operator's meridian environment#927
materemias wants to merge 1 commit into
rynfar:mainfrom
materemias:fix/test-env-isolation

Conversation

@materemias

Copy link
Copy Markdown
Contributor

Problem

Every runtime knob is read through env()MERIDIAN_<X> with a CLAUDE_PROXY_<X> fallback — so anything a developer exports to run their own proxy silently reconfigures the code under test. The suite inherits it, and CI (which exports none of it) cannot see the difference.

Two cases observed on one machine, both from a normal operator environment:

  • MERIDIAN_NO_FILE_CHANGES=1 disables the PostToolUse file-change hook, so the three "File change visibility: other adapters still track" cases in src/__tests__/proxy-file-changes.test.ts fail on main — with no local change in sight.
  • MERIDIAN_TELEMETRY_PERSIST=1 makes the process-global telemetry store the real ~/.config/meridian/telemetry.db. The suite is written against the in-memory store and calls telemetryStore.clear() / diagnosticLog.clear(), which issue DELETE FROM metrics / DELETE FROM diagnostic_logs — so running npm test destroys every metric and diagnostic log the operator's own proxy has recorded. Redirecting MERIDIAN_CONFIG_DIR does not help: src/telemetry/index.ts resolves its path from env("TELEMETRY_DB") and otherwise hard-codes ~/.config/meridian/telemetry.db.

The second one is data loss, and it is silent.

Fix

Strip the MERIDIAN_* / CLAUDE_PROXY_* namespace in src/__tests__/preload.ts, before any module import. The preload then sets the values the suite owns (config dir, session dir, SDK process gate) as it already did.

CI runs with none of these set, so this is precisely what makes a local run mean the same thing as a CI run. Tests that need a knob set it themselves, in-process, after the preload.

Verification

npm test on this branch: all 13 invocations green (2982 + 251 tests, 0 fail). Before it, on the same machine, main reported 3 failures in proxy-file-changes.test.ts and wiped the local telemetry database.

Copilot AI lite review requested due to automatic review settings September 3, 2026 19:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is confined to the test preload and directly enforces deterministic, non-destructive test isolation without altering production behavior.

Pull request overview

This PR hardens the test harness so local npm test runs are isolated from any MERIDIAN_* / legacy CLAUDE_PROXY_* environment variables a developer may have exported for running their own proxy, preventing silent test reconfiguration and (notably) accidental writes/deletes against a real on-disk telemetry DB.

Changes:

  • Clears the entire MERIDIAN_* and CLAUDE_PROXY_* env var namespaces in the test preload before the suite config is applied.
  • Continues to set suite-owned paths/knobs (config dir, session dir, SDK process gate) to throwaway values for test isolation.
File summaries
File Description
src/__tests__/preload.ts Removes operator configuration influence by stripping MERIDIAN_* / CLAUDE_PROXY_* env vars before setting test-owned env state.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Every runtime knob is read through `env()` — `MERIDIAN_<X>` with a
`CLAUDE_PROXY_<X>` fallback — so anything a developer exports to run their
own proxy silently reconfigures the code under test. Two real cases on one
machine:

- `MERIDIAN_NO_FILE_CHANGES=1` disables the PostToolUse hook, failing the
  three "other adapters still track" cases in proxy-file-changes.test.ts.
- `MERIDIAN_TELEMETRY_PERSIST=1` makes the global telemetry store the real
  ~/.config/meridian/telemetry.db, which the suite then DELETEs: tests call
  `telemetryStore.clear()` and `diagnosticLog.clear()`, so a local run
  destroys every metric and diagnostic the operator's proxy has recorded.
  Redirecting MERIDIAN_CONFIG_DIR does not save it — telemetry resolves its
  path from `env("TELEMETRY_DB")` alone.

Strip the whole namespace in the preload, before any module import. CI runs
with none of it set, so this is what makes a local run mean the same thing
as a CI run; tests that need a knob set it themselves, in-process.
@materemias
materemias force-pushed the fix/test-env-isolation branch from 53ffd0a to ee086a7 Compare September 4, 2026 15:23
@rynfar

rynfar commented Sep 4, 2026

Copy link
Copy Markdown
Owner

Your test job is red for a reason that has nothing to do with this PR — please rebase onto main and it should clear.

The 11 failures here (Retry-After (#901) ×5, Empty messages array (#450), Passthrough tool_use ×5) are #917, which was diagnosed and fixed earlier today in #935. The transcript ownership ceiling is bounded per session root, and the test preload pointed all ~179 files at a single root — so prepared transcripts accumulated until it filled, after which every request in the process returned 500 session transcript ownership backlog is full regardless of which file issued it. That is why unrelated tests fail with impossible statuses, like a 429 test receiving 500.

This branch predates that fix, so it is still running against the broken harness. git rebase origin/main and push, and the cluster should disappear.

Apologies for the delay in getting you CI signal on this — the approval was held while the flake made every result untrustworthy.

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.

3 participants