ci(unit-tests): extend grep guard to async vi.mock with dynamic import
The pdfjs-dist literal grep added in 9260866f only caught one named
trigger of the birpc teardown race; the underlying mechanism (ADR 012 /
#553) is any async vi.mock factory whose body performs `await import(...)`.
Add a second PCRE-multiline grep matching that shape. Scoped to
**/*.{spec,test}.ts under frontend/src/, excluding __meta__ (which holds
the fixture strings exercising the meta-test). Defence in depth pairs with
the ESLint rule (saves at edit time) and the in-suite meta-test (catches
when tests run).
Verified locally with real GNU grep against a planted synthetic offender.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -39,10 +39,22 @@ jobs:
|
|||||||
- name: Assert no banned vi.mock patterns
|
- name: Assert no banned vi.mock patterns
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
|
# Literal pdfjs-dist (libLoader pattern — ADR 012)
|
||||||
if grep -rF "vi.mock('pdfjs-dist'" frontend/src/; then
|
if grep -rF "vi.mock('pdfjs-dist'" frontend/src/; then
|
||||||
echo "FAIL: banned vi.mock('pdfjs-dist') pattern found — see ADR 012. Use the libLoader prop injection pattern instead."
|
echo "FAIL: banned vi.mock('pdfjs-dist') pattern found — see ADR 012. Use the libLoader prop injection pattern instead."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
# Async factory with dynamic import in body (named mechanism — ADR 012 / #553).
|
||||||
|
# Multiline PCRE matches `vi.mock(<arg>, async ... { ... await import(...) ... })`
|
||||||
|
# across line breaks. __meta__ is excluded because it contains fixture strings
|
||||||
|
# demonstrating the very pattern this check is meant to forbid.
|
||||||
|
if grep -rPzln 'vi\.mock\([^)]+,\s*async[^{]*\{[\s\S]*?await\s+import\s*\(' \
|
||||||
|
--include='*.spec.ts' --include='*.test.ts' \
|
||||||
|
--exclude-dir='__meta__' \
|
||||||
|
frontend/src/; then
|
||||||
|
echo "FAIL: banned async vi.mock factory with dynamic import in body — see ADR 012 / #553. Use a synchronous factory + vi.hoisted instead."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Run unit and component tests with coverage
|
- name: Run unit and component tests with coverage
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
Reference in New Issue
Block a user