Skip to content

tests: the camera-speed viewer test passes the globals loadWorld needs - #7085

Closed
kett1m wants to merge 2 commits into
ItsNotRexed:mainfrom
kett1m:viewer-test-abort
Closed

kett1m wants to merge 2 commits into
ItsNotRexed:mainfrom
kett1m:viewer-test-abort

Conversation

@kett1m

@kett1m kett1m commented Nov 23, 2026

Copy link
Copy Markdown

Claimed in the coordination issue as a new item.

What and why

tests/test_viewer_streaming.cjs fails on main (Node 24.21.0, Linux) at the camera-speed test:

✖ Shift speeds the camera up and Ctrl slows it down, on either side of the keyboard
  ReferenceError: AbortController is not defined
    at loadWorld (...)

That test builds its own vm sandbox and was the only one of the four that did not pass AbortController, setTimeout and clearTimeout. The viewer's loadWorld calls new AbortController() and sets a timeout, so the sandbox needs both. The change adds the three globals to that sandbox.

Tested

node --test tests/test_viewer_streaming.cjs (Node 24.21.0): 57 of 57 pass. Before the change: 56 pass, 1 fail.

No game data, network or browser involved.

AI-assisted: yes

@tikD1337

Copy link
Copy Markdown
Contributor

Review: #7085, the camera-speed viewer test now gets the globals loadWorld needs

Verdict: approve. This is a one-line fix to the test harness. It repairs a test that is red on main and changes no viewer code.

What changed

In tests/test_viewer_streaming.cjs:414, the vm sandbox of the test "Shift speeds the camera up and Ctrl slows it down…" now passes AbortController, setTimeout and clearTimeout to the context, next to performance.

Why it is needed

The test runs the whole viewer module (viewerModule) in vm.runInNewContext. That module calls loadWorld(), which needs all three globals from its first lines (viewer/index.html:99–112):

const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), WORLD_MANIFEST_TIMEOUT_MS);
...
} finally {
  clearTimeout(timer);
}

A vm context created with runInNewContext gets only the ECMAScript built-ins. Node's web and timer globals (AbortController, setTimeout, clearTimeout) are not passed through unless you supply them. So before this change the sandbox threw ReferenceError: AbortController is not defined at the first line of loadWorld, before any camera assertion ran.

The fix matches how the file's other sandboxes handle this:

  • the loadWorld() helper at :15–17 passes AbortController, ...timers;
  • the bounds-overlay test at :356 passes AbortController, setTimeout, clearTimeout;
  • the streaming fixture() at :443–453 passes AbortController with fake timers.

This was the only full-module sandbox missing them. That fits the history: the AbortController and timeout in loadWorld probably landed after this test was written, and the other sandboxes were updated but this one was missed.

Subtle points I checked

  • Real timers, not fakes. The test passes the host's real setTimeout rather than a stub. That is safe here. fetch is manifestResponse(...), which resolves straight away, and the finally clears the 10 s manifest timer. No timer handle is left to keep the node --test process alive past the test, and the measured run time (~0.8 s for the file) confirms it.
  • No masking. The assertions are unchanged: E alone climbs 4 m at 0.1 s/frame, Shift gives 20 m, Ctrl gives 0.8 m, each checked for both left and right keys. The test now gets to them instead of failing during setup, so its coverage goes up.
  • Scope. The patch only adds globals the browser always has. It does not stub out or work around anything in the viewer itself.

Optional follow-up, not blocking: four sandboxes now repeat the same browser-global set by hand. A small shared browserGlobals object would stop the next viewer global added to loadWorld from breaking one sandbox silently again. That is a separate change and need not hold up this one.

Verification (Windows 11, CPython 3.13, Node v24.19.0)

Check Result
git diff --check PASS
python -m compileall -q make_game.py tools tests PASS
python -I tools/check_no_game_data.py PASS
python -I make_game.py --help PASS
node --test tests/test_viewer_streaming.cjs (this PR) 57 / 57 pass, 0 fail, ~813 ms
Same file from the parent commit fails with ReferenceError: AbortController is not defined

None of these needs game files or a GPU. The before and after runs reproduce the commit message's claim (56 passed and 1 failed before; 57 of 57 after).

Project rules

  • No game data: the change is one line of test-harness JavaScript. It has no archives, shaders, textures, logs or carved content, and check_no_game_data.py passes.
  • No keys, decryption or protection workarounds: none touched.
  • Nothing online: the test's fetch is the local manifestResponse stub, and no network or Rockstar/Xbox Live endpoints are involved.
  • Fix, don't disable: the failing test is repaired by giving it the environment it needs, not skipped or loosened, and its assertions are untouched.

AI-assisted.

@kett1m

kett1m commented Nov 23, 2026

Copy link
Copy Markdown
Author

Added the optional follow-up from the review in a second commit: the four sandboxes now spread one browserGlobals object (AbortController, setTimeout, clearTimeout, URLSearchParams), and the streaming fixture's fake timers and clock still override the shared entries. node --test tests/test_viewer_streaming.cjs: 57 of 57 pass.

@Daazd

Daazd commented Nov 23, 2026

Copy link
Copy Markdown

Independent check (Linux, Python 3.12.3, Node 24.13, CPU only, no game files): head 7c85e034d merged onto main 6a4299563: merges clean.

  • node --test tests/test_viewer_streaming.cjs: ℹ pass 57 ℹ fail 0 (exit 0)

Fixes the red viewer test on main (Shift speeds the camera up...: AbortController is not defined). Same fix as #5692 and #7063; all three pass.

AI-assisted (Claude Code).

Its vm sandbox was the only one without AbortController, setTimeout and clearTimeout, so the test failed on main with
"ReferenceError: AbortController is not defined" at viewer/index.html's first `new AbortController()` in loadWorld.
The other three sandboxes already pass them.

node --test tests/test_viewer_streaming.cjs: 57 of 57 pass (56 and one failure before).
tikD1337's review of this PR noted that four sandboxes repeat the same browser globals by hand, so the next global
loadWorld reads would break one of them silently, which is how this started. They now spread one browserGlobals
object. The streaming fixture's fake timers and its performance clock still override the shared entries.

node --test tests/test_viewer_streaming.cjs: 57 of 57 pass.
@kett1m

kett1m commented Nov 23, 2026

Copy link
Copy Markdown
Author

Rebased onto main dde82f27 (Daazd checked against 6a4299563). node --test tests/test_viewer_streaming.cjs: 57 of 57 pass, fail 0.

main at dde82f27 is still red the same way: 56 pass, 1 fail, ReferenceError: AbortController is not defined, so the fix has not landed through another PR yet.

Daazd noted #5692 and #7063 as the same change. This one is rebased, approved, and has both independent checks; whichever lands first wins.

@YordiLorenzo

Copy link
Copy Markdown

Tested e9421da on Linux, Node 22.22.1: pass

  • node --test tests/test_viewer_streaming.cjs: 57 of 57 pass on the head, and merged onto main 867d922
  • Negative control, main alone: 56 pass, 1 fail with the AbortController ReferenceError
  • Read the spread order too: the fixture's fake setTimeout and clearTimeout come after the shared globals, so they still win

@naxhh

naxhh commented Nov 23, 2026

Copy link
Copy Markdown

Duplicate of #5692, which claimed this first as TEST-1354 (claim). It passes 57/57 here too (Windows 11, Node 26.13.1), so one of the two can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants