visibilityPolygon casts one ray per 64-gon vertex and ang, ang+-RayEps per wall
endpoint. A wall radial to the viewer is collinear with the ray that crosses it,
and rayHit rejected the collinear case; its own +-RayEps rays meet the wall's
line at the viewer (t = 0, rejected by t > Eps). So the wall got no ray, no
vertex and no shadow, and a token on the line beyond it stayed inside the
polygon: a player-view fog leak (DESIGN 3.1).
Fix: rayHit returns the nearest point of the overlap when the wall lies on the
ray's line (and Inf only for a parallel wall on another line). {.inline.} keeps
the fan's inner loop at its previous cost (CPU-time cross-check on 20k dense
polygons: 25.8s before, 32.5s without the pragma, 24.9s with it).
Proof: tgeometry visibility tests (horizontal k=0, vertical k=16, both wall
directions, a 32 px grid translation, 10 degrees, plus the non-radial and
0.5 px-off negative controls); the leak world gains a wall on the subject's own
column with a hidden token beyond it, and leakcheck's HIDDEN_TOKEN class now
asserts the token-level over-approximation (token centre + viewer->token
segment, 5.4 tolerance), which the GEOMETRY class structurally cannot see.
58 lines
3.3 KiB
JavaScript
58 lines
3.3 KiB
JavaScript
// M3 slice 5 (#20), leak test A and B (DESIGN 10.1 "leak test", 10.3): the driver builds a scene
|
|
// over the real wire and records every frame each socket saw; tools/leakcheck.nim then verifies the
|
|
// subject's whole view against the GM socket (ground truth) and its own geometry. One run per
|
|
// subject on its own server; logs land in results/leak-<subject>.{jsonl,log}.
|
|
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
import { runLeak, runChecker } from './leak.mjs'
|
|
import { gmKeyOf, makeStateDir, startServer, stopServer } from './withserver.mjs'
|
|
import { projectRoot } from './lib.mjs'
|
|
|
|
const results = path.join(projectRoot, 'results')
|
|
|
|
for (const subject of ['A', 'B']) {
|
|
test(`leak test ${subject}: the subject's whole view matches the GM's truth`, async () => {
|
|
fs.mkdirSync(results, { recursive: true })
|
|
const stateDir = makeStateDir()
|
|
const gmKey = gmKeyOf(stateDir)
|
|
const s = await startServer({ stateDir })
|
|
const transcript = path.join(results, `leak-${subject}.jsonl`)
|
|
try {
|
|
const run = await runLeak({ origin: s.origin, gmKey, stateDir, transcript })
|
|
assert.ok(run.groups > 15, `the scenario must have real coverage, got ${run.groups} groups`)
|
|
if (subject === 'A') {
|
|
// #61: the world's own contract, read off the GM's wall frames and the subject's markers.
|
|
// A rewrite that drops an element (or a side of the marker sight test) fails here, not in
|
|
// a fault that happens to stop firing.
|
|
const cov = run.coverage
|
|
assert.ok(cov.oneWay >= 1, `the world needs a one-way wall: ${JSON.stringify(cov)}`)
|
|
assert.ok(cov.secretDoors >= 1, `the world needs a secret door: ${JSON.stringify(cov)}`)
|
|
assert.ok(cov.lockedDoors >= 1, `the world needs a locked door: ${JSON.stringify(cov)}`)
|
|
assert.ok(cov.markedNonWindows >= 1,
|
|
`the world needs a marked non-window wall (MARKER_EXTRA control): ${JSON.stringify(cov)}`)
|
|
assert.ok(cov.markedWindowsSeen >= 1,
|
|
`the world needs a marked window the subject sees: ${JSON.stringify(cov)}`)
|
|
assert.ok(cov.markedWindowsUnseen >= 1,
|
|
`the world needs a marked window the subject never sees (MARKER_EARLY control): ${JSON.stringify(cov)}`)
|
|
assert.ok(cov.markedWindowsOccluded >= 1,
|
|
`the world needs a marked window behind the far wall (TESTING 5.8): ${JSON.stringify(cov)}`)
|
|
assert.equal(cov.markedWindowsOccludedSeen, 0,
|
|
`a wall behind a sight blocker yields no marker: ${JSON.stringify(cov)}`)
|
|
// #26: a wall lying along a vision ray with a hidden token beyond it must be in the world;
|
|
// the checker's HIDDEN_TOKEN class is the assertion that it does not leak.
|
|
assert.ok(cov.onRayHidden >= 1,
|
|
`the world needs a token hidden behind a wall lying along a vision ray (#26): ${JSON.stringify(cov)}`)
|
|
}
|
|
const check = runChecker(transcript, subject)
|
|
fs.writeFileSync(path.join(results, `leak-${subject}.log`), check.output)
|
|
assert.equal(check.status, 0, `${check.output}\n--- server log ---\n${s.log()}`)
|
|
assert.match(check.output, / 0 failures/)
|
|
} finally {
|
|
await stopServer(s)
|
|
fs.rmSync(stateDir, { recursive: true, force: true })
|
|
}
|
|
})
|
|
}
|