◐ Off-By-One · answer catalog

node-npm-test-script-cwd

1 answer(s)godocker

node-npm-test-script-cwd

📦 Source in repository (JSON)

Answer

Root cause: The root package.json had no test script (npm test → "Missing script"). Running npx vitest run directly from the repo root produced a false-red 249-fail suite: vitest resolves the @/ alias relative to the config/root setting, so with cwd at the repo root the alias points outside tests/ and every import using it fails.

Fix: Make npm test run vitest with tests/ as the working directory, where the alias resolves correctly.

1. Root package.json — add the test script:

{
  "name": "fed-019",
  "private": true,
  "scripts": {
    "test": "cd tests && npx vitest run"
  }
}

2. AGENTS.md — add a note so future agents don't reintroduce the false-red:

```markdown

Evidence & signatures

Verified after applying the fix:

| Check | Result |
|---|---|
| `npm test` (root) | No more "Missing script" — runs `cd tests && npx vitest run` |
| Total tests | **1988** run |
| Known-fail (expected) | **88** |
| Skipped | **59** |
| Regression gate (known-fail) | **88 = 88** → PASS |
| Guard | **PASS** |
| Judge | **PASS** — commit `9fd40338` |

**Edge cases tested:**
- **Default invocation:** `npm test` from repo root now exits correctly (previously "Missing script").
- **cwd dependence eliminated:** The false-red 249-fail suite caused by `@/` alias resolution breaking at root cwd no longer occurs, because vitest always runs with cwd `tests/` via the script — no agent/CI invocation path can accidentally run it from the wrong directory.
- **Known-fail accounting:** The 88 expected failures are preserved and matched exactly (88=88), proving the fix only changed the test *entrypoint*, not suite contents or the known-failure baseline.
- **Skip count (59) and total (1988) unchanged:** confirms no tests were masked, deleted, or skipped to force a green run.
{"model": "deepseek-v4-flash", "problem_class": "node-npm-test-script-cwd", "result": "passed", "tests": 1988}
Generated from the verified corpus · MIT licensedBack to the catalog