-
Notifications
You must be signed in to change notification settings - Fork 472
Add CJS syntax gate to catch module-load async/await errors earlier #43473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,9 @@ jobs: | |
| - name: Install npm dependencies | ||
| run: cd actions/setup/js && npm ci | ||
|
|
||
| - name: Check runtime CJS syntax | ||
| run: make check-cjs-syntax | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/diagnosing-bugs] The syntax gate only runs in the 💡 Options to close the gapOption A (simplest): Add the same step to each job that runs CJS files (js-tests, impacted-js-tests). Option B (preferred): Make js-tests:
needs: js-typecheck
name: JS Tests (shard ...)
...This ensures any job that could fail due to bad CJS is gated earlier. @copilot please address this. |
||
|
|
||
| - name: Run typecheck | ||
| run: cd actions/setup/js && npm run typecheck | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -231,6 +231,14 @@ security-govulncheck-sarif: | |
| @echo "✓ Govulncheck complete (results in govulncheck-results.sarif)" | ||
|
|
||
| # Test JavaScript files | ||
| .PHONY: check-cjs-syntax | ||
| check-cjs-syntax: | ||
| @echo "→ Checking CommonJS runtime syntax..." | ||
| @find actions/setup/js \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scope gap: runtime driver 💡 Detail and suggested fixThe repo has two runtime CJS files that workflows execute directly, and both live outside Both Suggested fix — expand the search scope: check-cjs-syntax:
`@echo` "→ Checking CommonJS runtime syntax..."
`@find` actions/setup/js .github/drivers \
\( -path "*/node_modules" -prune \) -o \
-type f -name "*.cjs" ! -name "*.test.cjs" -print0 | xargs -0 -n1 node --check
`@echo` "✓ CommonJS runtime syntax validated"If the drivers are intentionally excluded, that decision should be documented, but given the PR's stated goal of covering "runtime CommonJS files ... before they are loaded by workflows," excluding known workflow entrypoints undermines that goal. |
||
| -path 'actions/setup/js/node_modules' -prune -o \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
💡 Detail and suggested fix
The established portable idiom for pruning all `@find` actions/setup/js \
-name node_modules -prune -o \
-type f -name *.cjs ! -name *.test.cjs -print0 | ...Using |
||
| -type f -name '*.cjs' ! -name '*.test.cjs' -print0 | xargs -0 -r -n1 node --check | ||
|
Comment on lines
+237
to
+239
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Consider adding it to the lint: fmt-check fmt-check-json lint-cjs check-cjs-syntax golint validate-model-alias-chains lint-action-shOr at minimum to @copilot please address this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/diagnosing-bugs] The 💡 Suggested fix`@find` actions/setup/js \
-path 'actions/setup/js/node_modules*' -prune -o \
-type f -name '*.cjs' ! -name '*.test.cjs' -print0 | xargs -0 -r -n1 node --checkThe trailing @copilot please address this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/tdd] No regression test verifies the gate actually fails when a CJS file contains invalid 💡 Suggested testAdd a shell-level test or a Makefile test target: # test/check-cjs-syntax.sh
echo 'async function wrong() {} const bad = await wrong();' > /tmp/test-bad.cjs
if node --check /tmp/test-bad.cjs 2>/dev/null; then
echo 'FAIL: expected syntax error not detected'; exit 1
fi
echo 'PASS: invalid await correctly rejected'This follows /diagnosing-bugs: the fix should be accompanied by a regression test that would have caught the original failure. @copilot please address this. |
||
| @echo "✓ CommonJS runtime syntax validated" | ||
|
|
||
| .PHONY: test-js | ||
| test-js: build-js | ||
| cd actions/setup/js && npm run test:js -- --no-file-parallelism | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Syntax gate is wired only into
js-typecheck;js-testsandimpacted-js-testsrun in parallel with no dependency on it, so a broken CJS file can still reach test execution.💡 Detail
The
js-tests(4 shards) andimpacted-js-testsjobs have noneeds: js-typecheckdeclaration, so they start at the same time asjs-typecheck. The syntax check runs inside thejs-typecheckjob, not as a blocking prerequisite. Under normal CI, this means aSyntaxErrorthat failsjs-typecheckwill have already triggered 4+ parallel test-shard runs — the exact class of noisy runtime failure the PR intends to prevent.The cleanest fix is to either:
check-cjs-syntaxinto a standalone job and addneeds: check-cjs-syntaxtojs-tests,impacted-js-tests, andlint-js, orneeds: js-typecheckto every job that executes.cjsfiles at runtime.Option 1 keeps the check fast and lightweight while ensuring nothing downstream starts until syntax is clean.