Skip to content

Commit dbd4662

Browse files
JohnMcLearclaude
andauthored
fix(backend-tests): un-skip api/ and admin/ subdirectory specs (#7789)
* fix(backend-tests): un-skip tests/backend/specs/{api,admin}/* The pnpm test script's glob `tests/backend/specs/**.ts` only matched files at the top level of tests/backend/specs/. Every spec under tests/backend/specs/api/ (14 files) and tests/backend/specs/admin/ (2 files) has been silently skipped by CI — including the failing tests reported in #7785, #7786, #7787, #7788. Switch to passing the directories with `--extension ts --recursive`, which makes mocha walk the tree the way --recursive is documented to. Local run after this change picks up 16 additional spec files and surfaces 6 newly-visible failures: 4 already filed (#7785#7788) plus one that wasn't yet filed (appendTextAuthor.ts: "appendText without authorId does not attribute to any author"). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * test(backend): regression check for tests/backend/specs/{api,admin} discovery Read the pnpm test script from src/package.json, hand mocha the same arguments under --dry-run --list-files, and assert that a representative spec from tests/backend/specs/api/ and tests/backend/specs/admin/ appears in the discovered list. Locks in the glob fix from this PR: if anyone re-narrows the script back to the previous tests/backend/specs/**.ts pattern (which only matches depth 1), this vitest fails with a clear "glob missed ..." message instead of letting the affected specs silently drop out of CI. Verified the test FAILS when the script is reverted to the broken glob. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 8f499b4 commit dbd4662

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
},
148148
"scripts": {
149149
"lint": "eslint .",
150-
"test": "cross-env NODE_ENV=production mocha --import=tsx --require ./tests/backend/diagnostics.ts --timeout 120000 --recursive tests/backend/specs/**.ts ../node_modules/ep_*/static/tests/backend/specs/**",
150+
"test": "cross-env NODE_ENV=production mocha --import=tsx --require ./tests/backend/diagnostics.ts --timeout 120000 --extension ts --recursive tests/backend/specs ../node_modules/ep_*/static/tests/backend/specs",
151151
"test-utils": "cross-env NODE_ENV=production mocha --import=tsx --timeout 5000 --recursive tests/backend/specs/*utils.ts",
152152
"test-container": "mocha --import=tsx --timeout 5000 tests/container/specs/api",
153153
"dev": "cross-env NODE_ENV=development node --require tsx/cjs node/server.ts",
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
'use strict';
2+
3+
// Regression check for the `pnpm test` glob. The previous spec script
4+
// `tests/backend/specs/**.ts` only matched files at depth 1 under
5+
// tests/backend/specs/, silently skipping every spec under api/ and
6+
// admin/ — including the failures filed in #7785–#7788, #7790. This
7+
// test asserts that mocha (running the exact arguments from
8+
// src/package.json's "test" script) still discovers a representative
9+
// file in each of those subdirectories.
10+
//
11+
// If the glob is ever narrowed again, this test fails loudly instead
12+
// of letting the affected specs slip out of CI.
13+
14+
import {execFileSync} from 'child_process';
15+
import {readFileSync} from 'fs';
16+
import {join} from 'path';
17+
import {describe, it, expect} from 'vitest';
18+
19+
const srcRoot = join(__dirname, '..', '..', '..');
20+
const pkg = JSON.parse(readFileSync(join(srcRoot, 'package.json'), 'utf8'));
21+
22+
// Strip `cross-env NAME=value` prefixes and the leading binary name so we
23+
// can pass the remaining tokens straight to npx mocha --dry-run.
24+
const tokens = String(pkg.scripts.test).split(/\s+/);
25+
while (tokens[0] && /^[A-Z_][A-Z0-9_]*=/.test(tokens[0])) tokens.shift();
26+
if (tokens[0] === 'cross-env') {
27+
tokens.shift();
28+
while (tokens[0] && /^[A-Z_][A-Z0-9_]*=/.test(tokens[0])) tokens.shift();
29+
}
30+
// Drop the binary itself (mocha) — npx will re-add it.
31+
if (tokens[0] === 'mocha') tokens.shift();
32+
33+
const REQUIRED = [
34+
'tests/backend/specs/api/pad.ts',
35+
'tests/backend/specs/api/importexportGetPost.ts',
36+
'tests/backend/specs/admin/authorSearch.ts',
37+
];
38+
39+
describe('backend test glob', () => {
40+
it('discovers nested specs under tests/backend/specs/{api,admin}/', () => {
41+
const out = execFileSync(
42+
'npx', ['mocha', '--dry-run', '--list-files', ...tokens],
43+
{cwd: srcRoot, encoding: 'utf8', env: {...process.env, NODE_ENV: 'production'}},
44+
);
45+
// mocha --list-files prints absolute paths. Normalise to repo-relative.
46+
const seen = out.split('\n')
47+
.map((l) => l.trim())
48+
.filter(Boolean)
49+
.map((l) => l.replace(`${srcRoot}/`, ''));
50+
for (const required of REQUIRED) {
51+
expect(seen, `mocha test glob missed ${required}`).toContain(required);
52+
}
53+
}, 60000);
54+
});

0 commit comments

Comments
 (0)