viewer: say the world file could not be read when the body read fails, not that the JSON is invalid (WORLD-JSON-READ-MISREPORTED) #918

Merged
TuroYT merged 1 commit from upstream-pr/918 into main 2026-11-29 02:15:49 +00:00
TuroYT commented 2026-11-24 15:11:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TuroYT on 2026-11-24T15:11:32Z.


Claimed in the coordination issue as: WORLD-JSON-READ-MISREPORTED (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135526454)

What was wrong

viewer/index.html, loadWorld() (line 119 before this change): world = await response.json(); ran inside the same try as the fetch. The catch chose its message from response, which is set once the fetch has returned. So when the status was 200 and the body read failed (for example a dropped connection), the viewer said world/world.json could not be read as valid JSON. The file may be valid, and the failure was the network.

Reproduction on main (a28927849), with a stubbed fetch and the function read from the file in memory:

200 + body read fails -> "world/world.json could not be read as valid JSON."
no response          -> "world/world.json could not be loaded."

What changed

  • loadWorld() reads the body with response.text() and parses it with JSON.parse as two separate steps. A stage variable records which step was running when the error was thrown.
  • The catch now returns:
    • ... could not be read. when the read failed,
    • ... could not be read as valid JSON. when the parse failed,
    • ... could not be loaded. when the fetch failed (unchanged),
    • ... download timed out. when the deadline fired (unchanged).
  • Test mocks that provided json: now provide text:. The test sandbox gets the host JSON, so parsed arrays compare as before.
  • New cases: a read that throws after a 200 response expects could not be read. and not valid JSON; a valid body still loads.

Overlap with open pull requests

  • #651 (VIEWER-CHUNK-IDLE-TIMEOUT) edits loadChunk in viewer/index.html and adds fixtures and tests after line 456 of the test file. This pull request does not touch those hunks. Its loadWorld hunk is at lines 110-130, and its test hunks are at lines 21-22, 68-95 and 110.
  • #93 changes one camera speed test in the test file. No overlap.
  • No other open pull request touches these two files for loadWorld.

Tested

node --test tests/test_viewer_streaming.cjs        # node v24.22.0
# tests 59, pass 59, fail 0
python3 -I tests/test_text_write_line_endings.py   # Ran 3 tests, OK
python3 -I scripts/check_no_game_data.py viewer/index.html tests/test_viewer_streaming.cjs   # exit 0
git diff --check                                   # no output

The new cases fail on the unfixed viewer/index.html (the main version, run with the new test file):

node --test --test-name-pattern="read failure|body read that fails|valid manifest body still loads|test mode, a missing" tests/test_viewer_streaming.cjs
# tests 3, pass 1, fail 2
# AssertionError: 'world/world.json could not be read as valid JSON.' does not match /could not be read\./

The valid-body case also fails on the unfixed code, because its mock provides only text() and the old code calls json().

Not tested: a real browser. The viewer was not served or opened, so no page load, console or network check was done. The change is inside loadWorld(), which runs once at startup. No GPU, no game files.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5474854543 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/918). Originally posted by [TuroYT](https://github.com/TuroYT) on 2026-11-24T15:11:32Z. --- Claimed in the coordination issue as: WORLD-JSON-READ-MISREPORTED (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135526454) ## What was wrong `viewer/index.html`, `loadWorld()` (line 119 before this change): `world = await response.json();` ran inside the same try as the fetch. The catch chose its message from `response`, which is set once the fetch has returned. So when the status was 200 and the body read failed (for example a dropped connection), the viewer said `world/world.json could not be read as valid JSON.` The file may be valid, and the failure was the network. Reproduction on `main` (`a28927849`), with a stubbed fetch and the function read from the file in memory: ``` 200 + body read fails -> "world/world.json could not be read as valid JSON." no response -> "world/world.json could not be loaded." ``` ## What changed - `loadWorld()` reads the body with `response.text()` and parses it with `JSON.parse` as two separate steps. A `stage` variable records which step was running when the error was thrown. - The catch now returns: - `... could not be read.` when the read failed, - `... could not be read as valid JSON.` when the parse failed, - `... could not be loaded.` when the fetch failed (unchanged), - `... download timed out.` when the deadline fired (unchanged). - Test mocks that provided `json:` now provide `text:`. The test sandbox gets the host `JSON`, so parsed arrays compare as before. - New cases: a read that throws after a 200 response expects `could not be read.` and not `valid JSON`; a valid body still loads. ## Overlap with open pull requests - #651 (VIEWER-CHUNK-IDLE-TIMEOUT) edits `loadChunk` in `viewer/index.html` and adds fixtures and tests after line 456 of the test file. This pull request does not touch those hunks. Its `loadWorld` hunk is at lines 110-130, and its test hunks are at lines 21-22, 68-95 and 110. - #93 changes one camera speed test in the test file. No overlap. - No other open pull request touches these two files for `loadWorld`. ## Tested ``` node --test tests/test_viewer_streaming.cjs # node v24.22.0 # tests 59, pass 59, fail 0 python3 -I tests/test_text_write_line_endings.py # Ran 3 tests, OK python3 -I scripts/check_no_game_data.py viewer/index.html tests/test_viewer_streaming.cjs # exit 0 git diff --check # no output ``` The new cases fail on the unfixed `viewer/index.html` (the `main` version, run with the new test file): ``` node --test --test-name-pattern="read failure|body read that fails|valid manifest body still loads|test mode, a missing" tests/test_viewer_streaming.cjs # tests 3, pass 1, fail 2 # AssertionError: 'world/world.json could not be read as valid JSON.' does not match /could not be read\./ ``` The valid-body case also fails on the unfixed code, because its mock provides only `text()` and the old code calls `json()`. Not tested: a real browser. The viewer was not served or opened, so no page load, console or network check was done. The change is inside `loadWorld()`, which runs once at startup. No GPU, no game files. AI-assisted (Claude Code).
MoonEyes commented 2026-11-24 17:39:34 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-24T17:39:34Z.

Review: APPROVED


LGTM. Measured on Windows 11 with Node 26, against main cf4c00cba:

  • node --test tests/test_viewer_streaming.cjs: main 57/57; this PR and a local merge into main 59/59.
  • Mutation: deleting the stage === "read" line from this PR's viewer/index.html turns the new read-failure test red (58 pass, 1 fail). The body-stall test now mocks text(), so the deadline still covers the read.
  • Not tried in a browser, only through the vm harness.

AI-assisted: yes (Claude Code ran the checks; I read them).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6044345387 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/918#pullrequestreview-6044345387). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-24T17:39:34Z. **Review:** APPROVED --- LGTM. Measured on Windows 11 with Node 26, against main cf4c00cba: - `node --test tests/test_viewer_streaming.cjs`: main 57/57; this PR and a local merge into main 59/59. - Mutation: deleting the `stage === "read"` line from this PR's `viewer/index.html` turns the new read-failure test red (58 pass, 1 fail). The body-stall test now mocks `text()`, so the deadline still covers the read. - Not tried in a browser, only through the `vm` harness. AI-assisted: yes (Claude Code ran the checks; I read them).
zmasi commented 2026-11-28 21:46:29 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T21:46:29Z.


#918 | head 23b70597de (merged cleanly with main a8465211fb) | node --test tests/test_viewer_streaming.cjs | red on main: fail 25 / 59 (viewer/index.html called await response.json() directly and caught every post-fetch error with "world/world.json could not be read as valid JSON.", misreporting mid-body HTTP 200 read drops as JSON syntax errors) | green on PR+main: pass 59 / 59, fail 0 (duration_ms 282.6) | Windows 11 (10.0.26200.9974), Node.js v24.16.0 | AI-assisted: yes

Audited viewer/index.html and tests/test_viewer_streaming.cjs on Windows 11: tracking stage = "fetch" | "read" | "parse" across fetch, response.text(), and JSON.parse(text) cleanly separates body-stream read failures ("world/world.json could not be read.") from malformed JSON ("world/world.json could not be read as valid JSON.") while preserving the AbortController timeout path. Also verified tests/test_ci_registration.py and scripts/check_no_game_data.py.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246261622 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/918#issuecomment-7246261622). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T21:46:29Z. --- #918 | head 23b70597de2fa197a9f5b23e0c0f6026798cf7c9 (merged cleanly with main a8465211fb) | `node --test tests/test_viewer_streaming.cjs` | red on main: `fail 25 / 59` (`viewer/index.html` called `await response.json()` directly and caught every post-`fetch` error with `"world/world.json could not be read as valid JSON."`, misreporting mid-body HTTP 200 read drops as JSON syntax errors) | green on PR+main: `pass 59 / 59, fail 0` (`duration_ms 282.6`) | Windows 11 (`10.0.26200.9974`), Node.js v24.16.0 | AI-assisted: yes Audited `viewer/index.html` and `tests/test_viewer_streaming.cjs` on Windows 11: tracking `stage = "fetch" | "read" | "parse"` across `fetch`, `response.text()`, and `JSON.parse(text)` cleanly separates body-stream read failures (`"world/world.json could not be read."`) from malformed JSON (`"world/world.json could not be read as valid JSON."`) while preserving the `AbortController` timeout path. Also verified `tests/test_ci_registration.py` and `scripts/check_no_game_data.py`.
OreoFR commented 2026-11-29 01:58:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T01:58:20Z.


Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Node v26.7.0, main 59e65849b, PR head 23b70597d : red 25 failures / green 59 OK

node --test tests/test_viewer_streaming.cjs:

  • Red (main + only this PR's test file): 59 tests (incl. subtests), 25 failed cases in 10 top-level tests:
    • a valid manifest is used, including an intentionally empty world
    • malformed manifests keep the viewer usable and identify the invalid field (12 subtests)
    • a body read that fails after a 200 response is reported as a read failure, not as invalid JSON
    • a valid manifest body still loads after the read and parse are split
    • a stalled world manifest falls back to generated terrain at the startup deadline
    • manifest success clears the deadline and explicit test mode never schedules it
    • the bounds overlay creates helpers on the first G press and reuses them
    • Shift speeds the camera up and Ctrl slows it down
    • manifest chunks with test metadata still load their GLB
    • a valid LOD manifest is accepted
  • Green (main + merge): 59/59 OK.
  • (MEASURED n=3) each failing test rerun alone 3 times: red 3/3 fail, green 3/3 pass.
  • Skipped: none (skip 0, todo 0). No npm dependencies (CI runs node --test tests/test_*.cjs).
  • Merge: clean (git merge --no-ff onto main). The PR's test file is not older than main's, so the red run is the plain one.

Verdict: READY

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7249129532 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/918#issuecomment-7249129532). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T01:58:20Z. --- Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Node v26.7.0, main 59e65849b, PR head 23b70597d : red 25 failures / green 59 OK `node --test tests/test_viewer_streaming.cjs`: - **Red** (main + only this PR's test file): 59 tests (incl. subtests), 25 failed cases in 10 top-level tests: - `a valid manifest is used, including an intentionally empty world` - `malformed manifests keep the viewer usable and identify the invalid field (12 subtests)` - `a body read that fails after a 200 response is reported as a read failure, not as invalid JSON` - `a valid manifest body still loads after the read and parse are split` - `a stalled world manifest falls back to generated terrain at the startup deadline` - `manifest success clears the deadline and explicit test mode never schedules it` - `the bounds overlay creates helpers on the first G press and reuses them` - `Shift speeds the camera up and Ctrl slows it down` - `manifest chunks with test metadata still load their GLB` - `a valid LOD manifest is accepted` - **Green** (main + merge): 59/59 OK. - (MEASURED n=3) each failing test rerun alone 3 times: red 3/3 fail, green 3/3 pass. - Skipped: none (skip 0, todo 0). No npm dependencies (CI runs `node --test tests/test_*.cjs`). - Merge: clean (`git merge --no-ff` onto main). The PR's test file is not older than main's, so the red run is the plain one. **Verdict: READY** AI-assisted: Claude Code
MoonEyes commented 2026-11-29 02:15:51 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T02:15:51Z.


Merged after OreoFR's red/green check (check) (macOS 27.2.1, Apple M5) and a local re-check here. Merged after local re-verification: this PR merged onto main 21bdf6b60 without conflict, and its test file(s) (tests/test_viewer_streaming.cjs) pass there. Earlier today the same tests failed on main without the PR (red/green) and a bundle with other open PRs showed no new failures. check_no_game_data.py is clean. Windows 11, Python 3.14; no GPU needed for these tests.

AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7249315656 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/918#issuecomment-7249315656). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T02:15:51Z. --- Merged after **OreoFR**'s red/green check ([check](https://github.com/ProjectLeonida/mandy/pull/918#issuecomment-7249129532)) (macOS 27.2.1, Apple M5) and a local re-check here. Merged after local re-verification: this PR merged onto `main` 21bdf6b60 without conflict, and its test file(s) (`tests/test_viewer_streaming.cjs`) pass there. Earlier today the same tests failed on `main` without the PR (red/green) and a bundle with other open PRs showed no new failures. `check_no_game_data.py` is clean. Windows 11, Python 3.14; no GPU needed for these tests. _AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes._
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!918
No description provided.