Skip to content

fix(eval): restore SEC_UNIT_TERMS_REF override with fail-fast on missing path - #212

Merged
sroussey merged 1 commit into
mainfrom
claude/beautiful-archimedes-3e56is
Jul 24, 2026
Merged

fix(eval): restore SEC_UNIT_TERMS_REF override with fail-fast on missing path#212
sroussey merged 1 commit into
mainfrom
claude/beautiful-archimedes-3e56is

Conversation

@sroussey

Copy link
Copy Markdown
Contributor

Finding

PR #211 (this branch's parent) silently removed the SEC_UNIT_TERMS_REF env override from src/eval/embarcUnitTermsReference.ts when the module was refactored to use resolveAsset() and fileURLToPath. The pre-#211 resolveReferencePath() began with:

const envPath = process.env.SEC_UNIT_TERMS_REF;
return resolveAsset([
  ...(envPath ? [envPath] : []),
  join(import.meta.dir, "mock_data/embarc-spac-unit-terms.csv"),
  ...
]);

That override is the seam downstream packages depend on — the published @workglow/sec tarball does not ship mock_data/, so embarc-data (and any future consumer of loadEmbarcUnitTermsReference()) points SEC_UNIT_TERMS_REF at its own vendored copy of the CSV. Without it, loadEmbarcUnitTermsReference() throws at any consumer that doesn't have the source-tree layout on disk.

Fix

  1. Restore the override. Re-add the process.env.SEC_UNIT_TERMS_REF check in resolveReferencePath().
  2. Strengthen the semantics. When the env var is set, honor it strictly: a missing file throws a clear error naming the env var and the path, rather than silently falling through to the package-relative default. A typo in a downstream caller's env cannot masquerade as "fixture missing, using default" anymore — this is the improvement over pre-test(config,vitest): harden test isolation and complete vitest migration #211 behavior.
  3. Restore & update the explanatory docstring above the resolver.
  4. Add existsSync to the node:fs import for the file-exists check.
  5. Export _resetEmbarcUnitTermsCacheForTesting() so tests can force reload without vi.resetModules().
  6. Tests (src/eval/embarcUnitTermsReference.test.ts): a new describe("SEC_UNIT_TERMS_REF override") block with three cases, wrapping process.env.SEC_UNIT_TERMS_REF in beforeEach/afterEach restore and calling the reset helper:
    • env set + file exists → loader returns the row from the override CSV;
    • env set + file missing → loader throws matching /SEC_UNIT_TERMS_REF.*does not exist/;
    • env unset → committed fixture still loads (> 1200 rows, mirroring the existing baseline test).
  7. Docs: added a SEC_UNIT_TERMS_REF bullet next to SEC_S1_MOCK_DIR in CLAUDE.md.

Verification

  • bun x vitest run src/eval/embarcUnitTermsReference.test.ts10 passed (7 existing + 3 new).
  • bun x tsc --noEmit -p tsconfig.json → clean.

Only src/eval/embarcUnitTermsReference.ts, its test file, and the CLAUDE.md bullet are touched. No unrelated changes; no version bump.

Stacking

This PR stacks on top of #211 (base = claude/beautiful-archimedes-o87xem). Merge #211 first; this PR should then rebase cleanly onto main.


Generated by Claude Code

…ing path

PR #211 removed the SEC_UNIT_TERMS_REF env override from
embarcUnitTermsReference.ts when the module was refactored to use
resolveAsset() and fileURLToPath. Downstream packages (embarc-data) rely
on this env var to point at a vendored copy of the reference CSV, since
the published @workglow/sec tarball does not ship mock_data/.

Restore the override and strengthen its semantics: when SEC_UNIT_TERMS_REF
is set, the loader honors the path strictly — a missing file throws
naming the env var and the path, instead of silently falling through to
the package-relative default. A typo in a downstream caller's env cannot
masquerade as "fixture missing, using default" anymore.

Also:
- add existsSync to the node:fs imports;
- restore the explanatory docstring describing the override + fail-fast;
- export _resetEmbarcUnitTermsCacheForTesting() so tests exercise the
  env-override branches without vi.resetModules();
- add a three-case describe block (env set + exists, env set + missing,
  env unset) with beforeEach/afterEach env restore + cache reset;
- document SEC_UNIT_TERMS_REF next to SEC_S1_MOCK_DIR in CLAUDE.md.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sroussey
sroussey changed the base branch from claude/beautiful-archimedes-o87xem to main July 24, 2026 15:02
@sroussey
sroussey merged commit 866b8ca into main Jul 24, 2026
1 check passed
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.

2 participants