| import test from 'node:test'; | |
| import assert from 'node:assert/strict'; | |
| import { CHECKPOINTS, EVENTS, HAZARDS, OBJECTIVES, TOOLS, deriveSnapshot, serializeReplay } from '../docs/simulation.mjs'; | |
| import { createWasmBoundary } from '../docs/wasm-boundary.mjs'; | |
| test('scenario is deterministic and has a complete event vocabulary', () => { | |
| const required = ['OBSERVE', 'SCAN', 'DISCOVER', 'PLAN', 'MOVE', 'TOOL_CALL', 'HAZARD_DETECTED', 'REASON', 'REROUTE', 'ACTION', 'VERIFICATION', 'FAILURE', 'RECOVERY', 'CHECKPOINT', 'COMPLETE']; | |
| for (const type of required) assert.ok(EVENTS.some(item => item.type === type), `missing ${type}`); | |
| assert.equal(EVENTS[0].timestamp, '14:02:31'); | |
| assert.equal(EVENTS.at(-1).position.x, 92); | |
| assert.equal(HAZARDS.length, 6); | |
| assert.equal(CHECKPOINTS.length, 4); | |
| assert.equal(OBJECTIVES.length, 8); | |
| assert.equal(TOOLS.length, 9); | |
| assert.equal(JSON.stringify(deriveSnapshot(8)), JSON.stringify(deriveSnapshot(8))); | |
| }); | |
| test('replay restores path, hazards, mirror response, and verification state', () => { | |
| const before = deriveSnapshot(5); | |
| const blocked = deriveSnapshot(8); | |
| const after = deriveSnapshot(12); | |
| assert.equal(before.path.length, 6); | |
| assert.equal(blocked.current.verification, 'fail'); | |
| assert.equal(blocked.mirror.status, 'PATH COLLAPSED'); | |
| assert.ok(blocked.mirror.boundaryHardness > before.mirror.boundaryHardness); | |
| assert.equal(after.current.verification, 'pass'); | |
| assert.equal(after.world.blockedPaths, 0); | |
| assert.equal(after.checkpoints.length, 2); | |
| assert.equal(deriveSnapshot(2).path.length, 3); | |
| assert.notEqual(serializeReplay(5), serializeReplay(12)); | |
| }); | |
| test('snapshot clamps time travel and preserves completion', () => { | |
| assert.equal(deriveSnapshot(-50).index, 0); | |
| assert.equal(deriveSnapshot(1000).index, EVENTS.length - 1); | |
| assert.equal(deriveSnapshot(1000).isComplete, true); | |
| assert.equal(deriveSnapshot(1000).current.verification, 'pass'); | |
| }); | |
| test('WASM boundary is deterministic and explicitly reports its implementation', async () => { | |
| const boundary = await createWasmBoundary(); | |
| assert.ok(['READY', 'FALLBACK'].includes(boundary.status)); | |
| assert.equal(boundary.score(41), 42); | |
| assert.equal(boundary.score(0), 1); | |
| }); | |