1
0
This repository has been archived on 2026-08-25. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
tera/src/test/walker.test.ts
T
karti b25f217e3e feat: real fire on the boards, the LA office as a twin, and a night sky worth reading
The world stops being a simulation of California and starts being California.

**THE PROMOTION GATE WAS THE FIRST COMMIT, BEFORE ANY ORANGE PIXEL EXISTED.**
On today's live store the SoCal board contains 22 incidents. Every one has NULL
acreage and fifteen are nameless LA County dispatch numbers. Drawn naively that
is 22 orange marks over Los Angeles on a day nothing is burning — in a frame that
contains no other warm colour, so one glyph would be the most salient object on
the board and twenty-two would spend its credibility permanently.

`acres >= 10 AND contained < 80 AND type != 'RX' AND last_seen = max(last_seen)`
returns 0 on SoCal, exactly 5 on California, 0 on the Bay — same body, same day,
three correct answers. The empty board is a deliverable, not a fallback: it says
"No active fire on this board — CAL FIRE and WFIGS, just now", states that 21
records were gated and why, lists the largest fires burning OUTSIDE the frame
with distances, and counts the hot pixels it is deliberately not drawing.

**The privacy leak is structurally impossible rather than carefully avoided.**
cloud-1 serves a projection; the four home-relative columns never leave that box.
`observations.threat` was the one that nearly got through — it is
`(16/distance)^2 x log10(acres) x momentum x containment x wind-alignment`, so
with acreage and containment public it inverts to a distance circle around a
house and three fires give an intersection. A grep of the built bundle for
distance_km, bearing_deg, threat, 7762 and the street name returns nothing.

**Deliberately not used, and both would have produced a confident wrong answer:**
the store's `air` table retains only the last parameter of each poll, so all 78
rows read "Good" while the live feed reports ozone 101 "Unhealthy for Sensitive
Groups" — haze driven off it would clear the sky during a smoke event. And
`weather` is written only inside the NWS alerts loop, so a quiet day stores no
wind at all. Tera's own per-region NWS wind is already correct and already what
the clouds drift on.

Satellite detections are drawn as evidence and never as incidents. The permanent
industrial heat source 4.7 km from the owner's house is flagged persistent and
dropped, asserted by a test that first proves it is present in the fixture.
MODIS integer confidence and VIIRS string confidence are branched on `sat`.

**The LA office is a twin.** Its entire authored second storey — Model Loft,
Model Bay, The Materials Room, 430 lines nobody had ever stood in — is reachable
on foot: a walker crosses level-1 to level-2 in 73 fixed steps, floorY 0 to 5,
verified against the real pack rather than a synthetic plan. Its two studio
devices read real hardware through a field-allowlisted bridge: mute, volume and
reachability only. Never level, because there is no passive level upstream and
obtaining one would record a room with people in it. Never dB, because upstream
is gainPct across four different native scales. The bridge refuses all writes.

Fixed at its root: an anonymous visitor was getting permanently at-rest
instruments backing off against a 401. The tier moves into `createDeviceSource`,
so anon gets the living simulator three file headers already promised.

**Item 8 is closed, not fixed, and the correction is the point.** The Bay Area
"stutter" was GPU power management — the card sat at 500 MHz of 2725 through
every run that reproduced it, 4096/2048/1024/256 shadow maps all render in
1.21-1.31 ms, and two consecutive runs over a byte-identical dist gave 33.4 then
16.7. The allowance is removed and the cell is back to 16.7. Geometry is the
gate; frame time is advisory.

Item 7 was re-scoped after measuring: 1,069,006 of the Bay Area's 2,265,056
triangles were the second submission of the same buildings into the shadow pass.
Mobile now has its own triangle caps and bay-area mobile draws 1,266,096.

Also: bridges and the freeway corridor light up at night as emission, not lights
— 1,614 deck lamps and 18 tower heads on the Bay in two draw calls. The single
change that made US-101 legible was moving its edge lines from the lit material
to the unlit one: retroreflective paint, the argument the SFO night frame already
makes. California went 21,991 lamps to 4,051, clustered at the 17 town districts,
because a rural interurban corridor genuinely is unlit.

Tests 1137 -> 1340, server 280. All ten budget cells pass on first attempt with
no cap raised.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-22 18:01:11 -07:00

276 lines
11 KiB
TypeScript

import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { Plan } from "../interiors/plan.ts";
import {
createWalker,
normalizeWalkerAction,
type WalkerOptions,
} from "../interiors/walker.ts";
import type { Level, Office, Room, Wall } from "../interiors/types.ts";
const ROOM: Room = {
id: "floor",
name: "Floor",
floor: "floor" as never,
outline: [
{ x: 0, z: 0 },
{ x: 10, z: 0 },
{ x: 10, z: 8 },
{ x: 0, z: 8 },
],
};
function planWith(walls: Wall[] = []): Plan {
const level: Level = {
id: "ground",
name: "Ground",
elevation: 0,
wallHeight: 3,
wallThickness: 0.1,
floorplan: { rooms: [ROOM], walls },
};
const office: Office = { id: "walk-test", name: "Walk Test", levels: [level], viewpoints: [] };
return new Plan(office, { warn: false });
}
function walker(plan: Plan, over: Partial<WalkerOptions> = {}) {
return createWalker(plan, {
levelId: "ground",
position: { x: 2, z: 2 },
speed: 1,
fixedStep: 0.1,
...over,
});
}
describe("walker input and clock", () => {
it("normalizes planar actions without amplifying smaller input", () => {
assert.deepEqual(normalizeWalkerAction({ x: 0.3, z: -0.4 }), { x: 0.3, z: -0.4 });
const diagonal = normalizeWalkerAction({ x: 1, z: 1 });
assert.ok(Math.abs(Math.hypot(diagonal.x, diagonal.z) - 1) < 1e-12);
assert.deepEqual(normalizeWalkerAction({ x: Number.NaN, z: 1 }), { x: 0, z: 0 });
});
it("moves only in fixed steps and is deterministic across frame chunking", () => {
const plan = planWith();
const one = walker(plan);
const many = walker(plan);
one.tick(0.05, { x: 1, z: 0 });
assert.deepEqual(one.state().position, { x: 2, z: 2 });
one.tick(0.35, { x: 1, z: 0 });
for (let index = 0; index < 4; index += 1) many.tick(0.1, { x: 1, z: 0 });
assert.deepEqual(one.state(), many.state());
assert.ok(Math.abs(one.state().distance - 0.4) < 1e-12);
});
it("returns defensive state snapshots", () => {
const controller = walker(planWith());
const leaked = controller.state();
leaked.position.x = Number.NaN;
assert.deepEqual(controller.state().position, { x: 2, z: 2 });
});
it("uses and restores a normalized authored arrival facing", () => {
const controller = walker(planWith(), { facing: { x: 3, z: 4 } });
assert.deepEqual(controller.state().facing, { x: 0.6, z: 0.8 });
controller.tick(0.1, { x: -1, z: 0 });
assert.deepEqual(controller.state().facing, { x: -1, z: 0 });
controller.reset();
assert.deepEqual(controller.state().facing, { x: 0.6, z: 0.8 });
});
});
describe("walker collision", () => {
it("sweeps its circular footprint and cannot tunnel through a wall", () => {
const plan = planWith([{ id: "divider", from: { x: 5, z: 0 }, to: { x: 5, z: 8 } }]);
const controller = walker(plan, { speed: 100, fixedStep: 0.1 });
const state = controller.tick(0.1, { x: 1, z: 0 });
assert.ok(state.position.x < 4.65 && state.position.x > 4.64, `${state.position.x}`);
assert.equal(plan.blocked("ground", state.position, state.position, 0.3), false);
});
it("slides the unblocked component of diagonal movement along a wall", () => {
const plan = planWith([{ id: "divider", from: { x: 5, z: 0 }, to: { x: 5, z: 8 } }]);
const controller = walker(plan, { position: { x: 4.6, z: 2 }, speed: 2 });
for (let index = 0; index < 10; index += 1) controller.tick(0.1, { x: 1, z: 1 });
const state = controller.state();
assert.ok(state.position.x < 4.65, `${state.position.x}`);
assert.ok(state.position.z > 3, `${state.position.z}`);
assert.equal(plan.blocked("ground", state.position, state.position, 0.3), false);
});
it("walks through a resolved door gap without a door-specific exception", () => {
const plan = planWith([
{
id: "divider",
from: { x: 5, z: 0 },
to: { x: 5, z: 8 },
openings: [{ kind: "door", start: 3.4, width: 1.2, sill: 0, head: 2.1 }],
},
]);
const controller = walker(plan, { position: { x: 4, z: 4 }, speed: 2 });
for (let index = 0; index < 10; index += 1) controller.tick(0.1, { x: 1, z: 0 });
assert.ok(controller.state().position.x > 5.5, `${controller.state().position.x}`);
});
});
describe("walker guardrails", () => {
it("stays within finite level bounds and ignores invalid time/input", () => {
const controller = walker(planWith(), { position: { x: 9.6, z: 4 }, speed: 10 });
controller.tick(Number.NaN, { x: 1, z: 0 });
controller.tick(1, { x: Number.POSITIVE_INFINITY, z: 0 });
assert.deepEqual(controller.state().position, { x: 9.6, z: 4 });
controller.tick(1, { x: 1, z: 0 });
const state = controller.state();
assert.equal(state.position.x, 9.7);
assert.ok(Number.isFinite(state.position.x) && Number.isFinite(state.distance));
});
it("resets atomically and rejects invalid spawns/configuration", () => {
const plan = planWith();
const controller = walker(plan);
controller.tick(0.2, { x: 1, z: 0 });
assert.deepEqual(controller.reset({ levelId: "ground", position: { x: 7, z: 6 } }).position, { x: 7, z: 6 });
assert.equal(controller.state().distance, 0);
assert.throws(() => controller.reset({ levelId: "ground", position: { x: Number.NaN, z: 1 } }), RangeError);
assert.deepEqual(controller.state().position, { x: 7, z: 6 });
assert.throws(() => walker(plan, { radius: 0 }), RangeError);
assert.throws(() => walker(plan, { position: { x: 11, z: 2 } }), RangeError);
});
});
// ---- Cross-level -----------------------------------------------------------
/**
* Two storeys, hand-authored, with different footprints on purpose.
*
* Level 2 is deliberately *smaller* than level 1 and offset from it, so "valid
* on the level you are on" is a different question from "valid anywhere in the
* building" and a test can tell the two apart. Nothing here is a stair: the
* controller knows nothing about transitions, only about being told to be
* somewhere else.
*/
function twoLevelPlan(): Plan {
const lower: Level = {
id: "level-1",
name: "Ground",
elevation: 0,
wallHeight: 3,
wallThickness: 0.1,
floorplan: { rooms: [ROOM], walls: [] },
};
const upper: Level = {
id: "level-2",
name: "Upper",
elevation: 4,
wallHeight: 3,
wallThickness: 0.1,
floorplan: {
rooms: [{
id: "loft",
name: "Loft",
floor: "floor" as never,
outline: [
{ x: 0, z: 0 },
{ x: 6, z: 0 },
{ x: 6, z: 8 },
{ x: 0, z: 8 },
],
}],
walls: [],
},
};
const office: Office = {
id: "two-level-test",
name: "Two Level Test",
levels: [lower, upper],
viewpoints: [],
};
return new Plan(office, { warn: false });
}
describe("walker levels", () => {
it("crosses to another storey without zeroing the odometer", () => {
const plan = twoLevelPlan();
const controller = walker(plan, { levelId: "level-1", position: { x: 2, z: 2 }, speed: 1 });
for (let index = 0; index < 10; index += 1) controller.tick(0.1, { x: 1, z: 0 });
const before = controller.state();
assert.equal(before.levelId, "level-1");
assert.ok(Math.abs(before.distance - 1) < 1e-9, `${before.distance}`);
// The transition path. `reset` would have been the easy way to write this
// and it is the wrong one: it zeroes `distance` and restores the authored
// facing, so every flight of stairs would silently reset the odometer.
const crossed = controller.enterLevel("level-2", { x: 3, z: 2 });
assert.equal(crossed.levelId, "level-2");
assert.deepEqual(crossed.position, { x: 3, z: 2 });
assert.equal(crossed.distance, before.distance);
assert.deepEqual(crossed.facing, before.facing);
for (let index = 0; index < 10; index += 1) controller.tick(0.1, { x: 1, z: 0 });
const after = controller.state();
assert.equal(after.levelId, "level-2");
assert.ok(after.distance > before.distance, `${after.distance}`);
assert.ok(Math.abs(after.distance - 2) < 1e-9, `${after.distance}`);
// And the upper storey's own bounds hold: level 2 stops at x = 6 where
// level 1 runs to 10, so walking east on the loft stops sooner.
for (let index = 0; index < 60; index += 1) controller.tick(0.1, { x: 1, z: 0 });
assert.ok(controller.state().position.x <= 6 - 0.3 + 1e-9, `${controller.state().position.x}`);
});
it("refuses a crossing to an unknown level or an invalid position on a known one", () => {
const controller = walker(twoLevelPlan(), { levelId: "level-1", position: { x: 2, z: 2 } });
assert.throws(() => controller.enterLevel("level-3", { x: 2, z: 2 }), RangeError);
// Inside level 1 and outside level 2: the check is per level, not per building.
assert.throws(() => controller.enterLevel("level-2", { x: 8, z: 2 }), RangeError);
assert.throws(() => controller.enterLevel("level-2", { x: Number.NaN, z: 2 }), RangeError);
assert.equal(controller.state().levelId, "level-1");
assert.deepEqual(controller.state().position, { x: 2, z: 2 });
});
it("restores a snapshot from another storey, and still refuses an invalid one", () => {
const plan = twoLevelPlan();
const controller = walker(plan, { levelId: "level-1", position: { x: 2, z: 2 } });
// The rule is "a level this plan resolves, at a position valid on it" — not
// "the level you spawned on". `src/arena/officeNav.ts` restores through this.
const restored = controller.restore({
levelId: "level-2",
position: { x: 4, z: 5 },
facing: { x: 0, z: 1 },
distance: 12.5,
});
assert.equal(restored.levelId, "level-2");
assert.deepEqual(restored.position, { x: 4, z: 5 });
assert.equal(restored.distance, 12.5);
// Valid on level 1, outside level 2. Relaxing the level check must not have
// relaxed the position check with it.
assert.throws(() => controller.restore({
levelId: "level-2",
position: { x: 8, z: 5 },
facing: { x: 0, z: 1 },
distance: 1,
}), RangeError);
assert.throws(() => controller.restore({
levelId: "level-9",
position: { x: 4, z: 5 },
facing: { x: 0, z: 1 },
distance: 1,
}), RangeError);
assert.throws(() => controller.restore({
levelId: "level-2",
position: { x: 4, z: 5 },
facing: { x: 0, z: 1 },
distance: -1,
}), RangeError);
assert.equal(controller.state().levelId, "level-2");
// `reset()` still returns to the configured spawn, which is on level 1 —
// a crossing changes where you are, never where the episode began.
assert.equal(controller.reset().levelId, "level-1");
});
});