Skip to content

test: isolate dispatch-resolve test from ambient provider keys - #190

Merged
lstutzman merged 2 commits into
mainfrom
fm/dispatch-resolve-test-env-isolation
Nov 9, 2026
Merged

lstutzman merged 2 commits into
mainfrom
fm/dispatch-resolve-test-env-isolation

Conversation

@lstutzman

@lstutzman lstutzman commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

What Changed

  • tests/fm-dispatch-resolve.test.sh now unsets every provider key variable the resolver reads at start, so an ambient real key can't reach a fake curl header.
  • Added an assert_secret_equals helper and switched the Authorization: Bearer … header assertions to it. A mismatch now reports only the label and withholds both values, so a secret can't leak into test output.
  • docs/verification/dispatch-resolve.md has one new line describing the key isolation and the withheld-value assertions.

Risk Assessment

✅ Low: 1 finding (info), no issues that block merge. The change is test-only. It unsets every provider key variable the tool reads from the environment (TYPESAFE/OPENROUTER/OPENAI/FM_DISPATCH API keys, bin/fm-dispatch-resolve.sh:151-162) plus its private copies, and lib.sh already clears FM_CONFIG_OVERRIDE. So only the test's fake keys can reach the fake curl header. Every Authorization-header comparison now goes through assert_secret_equals, which withholds both values on mismatch, and the one assert_contains on a header became an exact match, which is stricter. How it is verifiable: run the suite with OPENROUTER_API_KEY and the other key variables set to canary values. Every header assertion must still pass against the fake keys, and the canary must never appear in stdout or stderr. A forced header mismatch must print only the label. No automated check runs the ambient-canary case yet (the info finding).

Testing

With the synthetic key exported, the new test file passed with exit 0 and the key string never appeared in its output. The old test file with the same ambient key failed (exit 1), so the ambient-key sensitivity is real and the fix addresses it. A deliberate mismatch in assert_secret_equals reported only "values withheld". The secret-scan hook flagged my synthetic placeholder string as an OpenAI-style key; it was not a real credential, so nothing needs rotating. No real key was used.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Run the dispatch-resolve test with an ambient fake provider key exported: it passes and never prints the key ✅ pass live after.log: exit 0, 0 occurrences of the key, test ends with 'all fm-dispatch-resolve tests passed'
Old test with the same ambient key fails, showing the ambient key influenced it ✅ pass live before.log: exit 1 at 'absent key prints nothing on stdout'. That failure came before the header assertion, so the old log does not show the key leak itself.
A secret-assertion mismatch withholds both values ✅ pass live Ran assert_secret_equals with differing values: output was only 'not ok - demo (secret value mismatch; values withheld)'.
Evidence: new test run with ambient synthetic keys

Source: new test run with ambient synthetic keys

ok - invalid preferred_provider: null
ok - invalid preferred_provider: false
ok - invalid preferred_provider: 42
ok - invalid preferred_provider: []
ok - invalid preferred_provider: {}
ok - invalid preferred_provider: ""
ok - invalid preferred_provider: "Codex"
ok - invalid preferred_provider: "codex\\n"
ok - invalid preferred_provider: " codex"
ok - preferred provider: astra-82-claude-26
ok - preferred provider: work-account
ok - preferred provider: exhausted
ok - preferred provider: unknown
ok - preferred provider: unknown-one-known-one
ok - preferred provider: claude-only
ok - preferred provider: config-override
ok - preferred provider: prose-why
ok - preferred provider: absent
ok - preferred provider: approval
ok - preferred provider: tie
ok - preferred provider: floor
ok - absent key is off: one stderr line, exit 0, no network call
ok - base URL: default unchanged, file used, env overrides, keyless custom URL on, invalid rejected
ok - model and token file: model configurable, token file is the bearer and wins over the key, bad file rejected
ok - TYPESAFE_API_KEY= in .env activates the tool; environment and config overrides work
ok - clear: one rule Choice request, key on the fd header only, spendPriority argmax over every candidate
ok - OpenRouter clear uses the same output contract and keeps its key out of argv and child environments
ok - OpenRouter ambiguous, malformed, HTTP, and missing-model paths are handled
ok - mapping: a declared macos-keychain service and optional account become the lookup, and the key rides the fd header
ok - precedence: environment, then .env, then the declared source, which is read only when needed
ok - provider isolation: each provider reads only its own declared service, and a declaration never selects a provider
ok - effective-home isolation: only the effective config directory's declaration is consulted
ok - failure distinctions: off, a configuration error, and an unavailable source each read differently and send nothing
ok - secret containment: the declared key is on no argv, in no output, environment, or file, and only on the fd header
ok - capability probe: supported or unsupported, with no declaration read and no credential tool run
ok - with no provider set, other providers' settings leave the original off line unchanged
ok - systemone posts the unchanged request to its base URL with an optional fd-3 key
ok - systemone configuration errors, never-send base URL, partial response, and transport failure are handled
ok - openai maps the Choice request to the Decisions API and its answer back, key on fd 3 only
ok - the never-send check runs on the final openai request body
ok - openai malformed, partial, refused, ambiguous, HTTP, and transport paths return to normal intake
ok - never-send list withholds the request on a match or a bad list, and never prints the value
ok - rules snapshots and shell quoting preserve the profile protocol
ok - quota_scope binds an agy candidate to its declared tier row
ok - no-rule fallback, Agy, Gemini, and documented configurations resolve
ok - ambiguous: confidence below the fixed floor hands the decision back
ok - per-rule confidence floors fall to the most probable runner-up that clears its own floor
ok - only the brief's task sections and scout tag reach the model, with a whole-brief fallback
ok - escalate: a rule declared approval: captain never yields a profile
ok - rule floor: known shortfall falls through while unavailable evidence escalates
ok - declared provider and profile floor evidence are applied in code
ok - nonnumeric spendPriority evidence is never ranked
ok - partial and missing quota evidence remain eligible but unranked
ok - provider-wide and exact quota rows combine into one limiting candidate
ok - default: no rule matched resolves among the default profiles
ok - tie: equal spendPriority never breaks by array order
ok - no rankable candidate: the tool escalates instead of guessing
ok - native Codex binds to codex-home before default, independently of Pi accounts and row order
ok - Pi native adapters bind to codex-home with existing fallbacks and schema 5 compatibility
ok - schema 6: each candidate binds to its account row; schema 5 is unchanged
ok - config/cpa-usage-host: pooled claude accounts rank the claude candidate
ok - config/cpa-usage-host: a pooled claude row competes on quota-axi's spendPriority scale
ok - config/cpa-usage-host: an exhausted pool makes the claude candidate ineligible
ok - config/cpa-usage-host: a failed pool read degrades to the quota-axi claude entry
ok - config/cpa-usage-host: ssh stderr noise stays out of the resolver's one diagnostic line
ok - config/cpa-usage-host: the pool read has an overall bound
ok - config/cpa-usage-host: a KILL-escalated bound reads as a timeout
ok - config/cpa-usage-host: FM_CPA_USAGE_TIMEOUT=00 still bounds a hung read
ok - config/cpa-usage-host: local runs cpa-usage-axi on this host
ok - config/cpa-usage-host: this machine's own short host name, any case, runs cpa-usage-axi here
ok - config/cpa-usage-host: schema 6 snapshots keep a valid claude default row
ok - config/cpa-usage-host: only a plain host name reaches ssh
ok - config/cpa-usage-host: a table with no claude rows degrades to the quota-axi claude entry
ok - config/cpa-usage-host: an account with no active window still counts toward the pool
ok - config/cpa-usage-host: a non-numeric window is a malformed read that degrades to the quota-axi claude entry
ok - config/cpa-usage-host: only plain decimal windows count as numbers
ok - config/cpa-usage-host: output without an accounts table is a malformed read
ok - config/cpa-usage-host: a row off the table's columns is a malformed read that degrades to the quota-axi claude entry
ok - config/cpa-usage-host absent: resolution is unchanged
ok - quota evidence comes from one quota-axi --json read, and its failure is an error outcome
ok - API, transport, and response failures are error outcomes with exit 0
ok - configuration errors exit 2 before any network call
ok - shared-quota opt-out: no quota snapshot, deterministic declared-order pick, opt-out stated on every candidate
ok - shared-quota bypasses an unmet rule-level floor: the rule's own profile wins with no quota call
ok - shared-quota bypasses an unmet profile-level floor: the first declared profile wins with no quota call
ok - shared-quota keeps preferred_provider narrowing: the preferred family wins in declared order with no quota call
ok - shared_quota false keeps the unchanged quota-ranked behavior
# all fm-dispatch-resolve tests passed
exit=0
Evidence: old test run with the same ambient key

Source: old test run with the same ambient key

ok - invalid preferred_provider: null
ok - invalid preferred_provider: false
ok - invalid preferred_provider: 42
ok - invalid preferred_provider: []
ok - invalid preferred_provider: {}
ok - invalid preferred_provider: ""
ok - invalid preferred_provider: "Codex"
ok - invalid preferred_provider: "codex\\n"
ok - invalid preferred_provider: " codex"
ok - preferred provider: astra-82-claude-26
ok - preferred provider: work-account
ok - preferred provider: exhausted
ok - preferred provider: unknown
ok - preferred provider: unknown-one-known-one
ok - preferred provider: claude-only
ok - preferred provider: config-override
ok - preferred provider: prose-why
ok - preferred provider: absent
ok - preferred provider: approval
ok - preferred provider: tie
ok - preferred provider: floor
not ok - absent key prints nothing on stdout (expected '', got 'dispatch-resolve:
  status: clear
  model: jev-1.13.0   latency_ms: 8   tokens: 812/60
  rule: rule_4 (A simple bug fix with a stated root cause.)   confidence: 0.9
  probabilities: rule_1=0.01 rule_2=0.01 rule_3=0.01 rule_4=0.96 default=0.01
  note: rule matched
  note: 1 eligible candidate(s) unranked (kimi)
  candidate: claude:sonnet  provider=claude  scope=all_models  remaining=79%  spendPriority=-0.4627  runway=projected_exhaustion  -> eligible
  candidate: cursor:cursor-grok-4.6-medium  provider=cursor  scope=all_models  remaining=91%  spendPriority=0.7597  runway=through_reset  -> eligible
  candidate: kimi:kimi-code/k3  provider=kimi  -> eligible, unranked: provider kimi unmeasured (unknown): disclosed uncertainty
  profile: --harness 'cursor' --model 'cursor-grok-4.6-medium'')

Risk

Low: test-only change plus one documentation line; no production code or behavior changes.

How to revert

Revert this PR's merge commit; it touches only tests/fm-dispatch-resolve.test.sh and docs/verification/dispatch-resolve.md.

Decisions

  • Unset all provider key variables (including the _PRIVATE copies and KEY_PRIVATE) at the top of the test, not only the OpenRouter ones, because the tool reads all of them.
  • Added a local assert_secret_equals in the test rather than changing tests/lib.sh, to keep the change scoped to the one test.
  • Other tests (fm-bootstrap, fm-worker-account) pass only their own fake keys, so they were left unchanged.
  • The one-line doc note in docs/verification/dispatch-resolve.md was added by the pipeline's document step.

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ℹ️ tests/fm-dispatch-resolve.test.sh:19 - No automated check proves the isolation holds. Nothing runs this suite with an ambient canary key (for example OPENROUTER_API_KEY=canary-real) and asserts that every header assertion still passes and that the canary never appears in the output. The fix is correct: the unset at tests/fm-dispatch-resolve.test.sh:19-20 covers all four key variables the tool reads from the environment (bin/fm-dispatch-resolve.sh:151-162). The tool's internal *_PRIVATE and KEY_PRIVATE variables are also cleared, and tests/lib.sh:82 already unsets FM_CONFIG_OVERRIDE, so a real config's token file or credential declaration cannot be read either. The gap: if someone later deletes or narrows that unset line, no test fails. Only assert_secret_equals still keeps the value out of the header assertions. A small wrapper case that re-runs one OpenRouter case with an ambient canary would close it. This is optional, because the withheld-value assertions already stop the leak path described in the intent.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Run the dispatch-resolve test with an ambient fake provider key exported: it passes and never prints the key ✅ pass live after.log: exit 0, 0 occurrences of the key, test ends with 'all fm-dispatch-resolve tests passed'
Old test with the same ambient key fails, showing the ambient key influenced it ✅ pass live before.log: exit 1 at 'absent key prints nothing on stdout'. That failure came before the header assertion, so the old log does not show the key leak itself.
A secret-assertion mismatch withholds both values ✅ pass live Ran assert_secret_equals with differing values: output was only 'not ok - demo (secret value mismatch; values withheld)'.
  • OPENROUTER_API_KEY, TYPESAFE_API_KEY and OPENAI_API_KEY set to a synthetic value, then bash tests/fm-dispatch-resolve.test.sh on the new commit
  • Same ambient key against the pre-change test file from 1248ed30
  • assert_secret_equals called with two different values, to check what a mismatch prints
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@lstutzman
lstutzman merged commit f71ae1c into main Nov 9, 2026
30 checks passed
@lstutzman
lstutzman deleted the fm/dispatch-resolve-test-env-isolation branch November 11, 2026 04:39
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.

1 participant