Skip to content

Commit 2dea2eb

Browse files
author
DavidQ
committed
Fix AsteroidsValidation test canvas shim for Node runner
- preserve named run export contract - add minimal node-safe #game canvas shim before bootAsteroidsNew - restore globals after test scope - optionally align VectorNativeTemplate path assertion if still stale
1 parent ff5fe8d commit 2dea2eb

11 files changed

Lines changed: 156 additions & 75 deletions

docs/dev/CODEX_COMMANDS.md

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,30 @@ MODEL: GPT-5.4-codex
22
REASONING: high
33

44
COMMAND:
5-
Create BUILD_PR_TEST_RUNNER_DRIFT_FIX as a docs-following, test-only patch.
6-
7-
Inspect these files first:
8-
- tests/run-tests.mjs
9-
- tests/games/AsteroidsValidation.test.mjs
10-
- games/Asteroids/index.js
11-
- tests/tools/VectorNativeTemplate.test.mjs
12-
13-
Then apply the minimum safe changes needed to restore `npm test --ignore-scripts`:
14-
15-
1. Re-align `tests/games/AsteroidsValidation.test.mjs` with the runner contract:
16-
- export a named `run`
17-
- remove any self-executing `run().catch(...)` block if present
18-
- preserve existing assertions and structure
19-
20-
2. Fix the Asteroids validation environment using a Node-safe local shim:
21-
- do NOT use `document.body.innerHTML`
22-
- inspect the boot path and mock only the minimal globals actually touched
23-
- likely candidates: `globalThis.document`, `document.getElementById('game')`, a minimal fake canvas/context, and possibly `globalThis.window`
24-
- restore original globals after the test
25-
26-
3. Update `tests/tools/VectorNativeTemplate.test.mjs` so the expected template path matches the current repo output:
27-
- `tools/templates/vector-native-arcade/`
28-
29-
Constraints:
30-
- no broad rewrites
31-
- no stub file replacement
32-
- no runtime behavior changes in game code unless absolutely required by an already-existing contract mismatch
33-
- no new heavy dependencies
34-
35-
Validate with:
36-
- npm test --ignore-scripts
37-
38-
If there is another failing test afterward, report it separately instead of rolling unrelated fixes into this PR.
39-
40-
NEXT COMMAND:
41-
npm test --ignore-scripts
5+
Create a small test-only patch for the current Asteroids failure.
6+
7+
Primary target:
8+
- `tests/games/AsteroidsValidation.test.mjs`
9+
10+
Do the following:
11+
1. Inspect the real file around the current failing call:
12+
- stack shows `tests/games/AsteroidsValidation.test.mjs:152:37`
13+
2. Preserve the existing structure and assertions.
14+
3. Ensure the file exports the named `run` function expected by `tests/run-tests.mjs`.
15+
4. Immediately before the failing `bootAsteroidsNew(...)` path, install the minimum Node-safe DOM/canvas shim so:
16+
- `globalThis.document` exists for this test scope
17+
- `document.getElementById('game')` returns a canvas-like object
18+
- the returned object supports the canvas methods/properties Asteroids boot actually uses
19+
5. Restore globals after the test scope finishes.
20+
6. Do not use a browser-only approach that assumes a full DOM implementation.
21+
7. Do not edit `games/Asteroids/index.js`.
22+
23+
Secondary target, only if still failing in the current branch:
24+
- `tests/tools/VectorNativeTemplate.test.mjs`
25+
- update expected path from `templates/vector-native-arcade/` to `tools/templates/vector-native-arcade/`
26+
27+
Success criteria:
28+
- `npm test --ignore-scripts > output.txt`
29+
- the first failure is no longer `Missing #game canvas element`
30+
- `PASS AsteroidsValidation` appears
31+
- stop after the first new failure, if any, and report it

docs/dev/COMMIT_COMMENT.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
Fix node test-runner drift in AsteroidsValidation and VectorNativeTemplate
1+
Fix AsteroidsValidation test canvas shim for Node runner
22

3-
- restore named run export contract for AsteroidsValidation
4-
- replace invalid browser-only DOM setup with a minimal node-safe test shim
5-
- update VectorNativeTemplate path expectation to current tools/templates location
3+
- preserve named run export contract
4+
- add minimal node-safe #game canvas shim before bootAsteroidsNew
5+
- restore globals after test scope
6+
- optionally align VectorNativeTemplate path assertion if still stale
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
PR intent:
2-
- repair current `npm test --ignore-scripts` failures without changing runtime behavior
3-
- keep scope limited to test harness drift and assertion drift
1+
Purpose:
2+
- eliminate the current Asteroids test blocker in plain Node
43

5-
Primary targets:
6-
- tests/games/AsteroidsValidation.test.mjs
7-
- tests/tools/VectorNativeTemplate.test.mjs
4+
Current blocker:
5+
- `Missing #game canvas element`
6+
- thrown by `bootAsteroidsNew(...)`
7+
- invoked from `tests/games/AsteroidsValidation.test.mjs`
88

9-
Known symptoms from user run:
10-
- missing named `run` export in AsteroidsValidation after a bad overwrite attempt
11-
- `document is not defined` when trying a browser-style patch in a plain Node test runner
12-
- template path expectation still points at `templates/...` while actual output is `tools/templates/...`
9+
Expected patch style:
10+
- test-only
11+
- minimum diff
12+
- no production game code changes
13+
- no full-file replacement

docs/dev/reports/file_tree.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
docs/
22
pr/
3-
PLAN_PR_TEST_RUNNER_DRIFT_FIX.md
4-
BUILD_PR_TEST_RUNNER_DRIFT_FIX.md
3+
PLAN_PR_ASTEROIDS_GAME_CANVAS_FIX.md
4+
BUILD_PR_ASTEROIDS_GAME_CANVAS_FIX.md
55
dev/
66
codex_commands.md
77
commit_comment.txt

docs/dev/reports/launch_smoke_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Launch Smoke Report
22

3-
Generated: 2026-04-13T04:47:02.910Z
3+
Generated: 2026-04-13T05:16:12.121Z
44

55
Filters: games=true, samples=true, tools=true, sampleRange=all
66

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
[ ] Inspect current source before editing; do not patch from memory
2-
[ ] `tests/games/AsteroidsValidation.test.mjs` exports named `run`
3-
[ ] No standalone `run().catch(...)` remains in that file
4-
[ ] AsteroidsValidation uses a node-safe local DOM/canvas shim rather than `document.body.innerHTML`
5-
[ ] Original globals are restored after the test
6-
[ ] `tests/tools/VectorNativeTemplate.test.mjs` expects `tools/templates/vector-native-arcade/`
7-
[ ] `npm test --ignore-scripts` rerun after edits
8-
[ ] Any remaining failures documented separately
1+
[ ] `tests/games/AsteroidsValidation.test.mjs` updated with minimum shim
2+
[ ] named `run` export preserved
3+
[ ] globals restored after test
4+
[ ] `games/Asteroids/index.js` unchanged
5+
[ ] `npm test --ignore-scripts > output.txt` run
6+
[ ] no `Missing #game canvas element`
7+
[ ] `PASS AsteroidsValidation`
8+
[ ] if a new failure appears, capture only the first new failure
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# BUILD_PR_ASTEROIDS_GAME_CANVAS_FIX
2+
3+
## Summary
4+
Apply a surgical test-only fix to `tests/games/AsteroidsValidation.test.mjs` so the Asteroids boot path can resolve `#game` inside the Node test runner.
5+
6+
## File targets
7+
- `tests/games/AsteroidsValidation.test.mjs`
8+
- optionally `tests/tools/VectorNativeTemplate.test.mjs`
9+
10+
## Implementation rules
11+
1. Inspect the real source around the current failing call site in `AsteroidsValidation.test.mjs`.
12+
2. Keep the existing `run` export contract expected by `tests/run-tests.mjs`.
13+
3. Before the failing `bootAsteroidsNew(...)` call, ensure the active `document` responds to:
14+
- `getElementById('game')` with a non-null canvas-like object
15+
4. The canvas shim should only implement what the Asteroids boot path actually needs.
16+
5. Restore any global overrides after the test section completes.
17+
6. Avoid any broad or file-wide rewrites.
18+
7. Do not modify `games/Asteroids/index.js` for this fix.
19+
20+
## Validation
21+
Run:
22+
23+
```bash
24+
npm test --ignore-scripts > output.txt
25+
```
26+
27+
Then confirm:
28+
- no `Missing #game canvas element`
29+
- `PASS AsteroidsValidation`
30+
31+
If the suite advances to a different failure, stop there and report the new first failure.
32+
33+
## Non-goals
34+
- shared extraction guard remediation
35+
- launch-smoke tuning
36+
- game runtime refactors
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# PLAN_PR_ASTEROIDS_GAME_CANVAS_FIX
2+
3+
## Goal
4+
Fix the current `npm test --ignore-scripts` blocker in `tests/games/AsteroidsValidation.test.mjs` where `bootAsteroidsNew(...)` throws:
5+
6+
`Missing #game canvas element`
7+
8+
## Scope
9+
- `tests/games/AsteroidsValidation.test.mjs`
10+
- optionally `tests/tools/VectorNativeTemplate.test.mjs` only if the path assertion is still stale in the current branch
11+
12+
## Required behavior
13+
- Preserve the existing Asteroids test intent and assertions
14+
- Preserve the module export contract expected by `tests/run-tests.mjs`
15+
- Do **not** replace the whole file
16+
- Do **not** change production game code in `games/Asteroids/index.js`
17+
- Do **not** introduce browser-only DOM setup such as direct `document.body.innerHTML` unless the test already has a DOM implementation
18+
- Add the minimum Node-safe shim required so `document.getElementById('game')` returns a canvas-like object during the boot call
19+
20+
## Acceptance criteria
21+
1. `npm test --ignore-scripts` no longer fails with:
22+
`Missing #game canvas element`
23+
2. The fix is test-only
24+
3. Existing passing Asteroids tests remain passing
25+
4. If VectorNativeTemplate still expects `templates/vector-native-arcade/`, update it to `tools/templates/vector-native-arcade/`
26+
27+
## Notes for implementation
28+
The current failure stack is:
29+
30+
- `bootAsteroidsNew (...) games/Asteroids/index.js:116:31`
31+
- `run (...) tests/games/AsteroidsValidation.test.mjs:152:37`
32+
33+
The likely issue is that the test is running in plain Node and needs a minimal stub for:
34+
- `globalThis.document`
35+
- `document.getElementById('game')`
36+
- a canvas-like object with the methods actually used by Asteroids boot/setup
37+
38+
The shim must be installed immediately before the boot path and restored afterward.

out1.txt

14.9 KB
Binary file not shown.

output.txt

78.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)