Spaces: the inside of the world, and a sun that is actually where it should be

Ten agents wrote this in parallel against CONTRACT.md, which exists because the
five design agents before them collided on fifteen blocking points — four files
specified twice with incompatible contents, three separate backends for one box,
and `Environment` exported twice meaning different things.

What landed: a Stage owning only the renderer and the loop, with the city and an
office as two scenes over it. They cannot share one — San Francisco is ~94 m per
scene unit with 3.6x vertical exaggeration and an office is 1 unit = 1 m — and
the city is paused rather than disposed on the way in, because rebuilding its
336,864-point heightfield costs about a second on the way back out.

Offices are data. `src/offices/lumbridge-hq.ts` is fifteen rooms and seventy-six
seats, and it is the file a self-hoster copies. Walls are a segment list with
1-D openings, so doors and windows are holes punched in a wall rather than
placed objects, and the pass that splits a wall around its openings hands the
walk-mode collider its segments for free.

The sun is real. `solar.ts` is a NOAA/Meeus implementation with no imports at
all — not even three.js — so time of day keeps working on a laptop in a field.
Verified against known values: 75.45 degrees at the June solstice in SF, 28.79
at December, sunset at 03:15Z. The first screenshot after wiring it was a black
rectangle, which turned out to be correct: it was midnight in San Francisco.

Presence binds to a seat id and never to a coordinate. The pack knows where
`eng-04` is; who is sitting in it is private data behind an API. Same shape as
the marker rule, one level in.

Two corrections to ARCHITECTURE.md are in here. Containment does not discharge
ODbL — publishing OSM-derived coordinates is Public Use of a Derivative Database
wherever the rows live, so the rule is about the geocoder (US Census, public
domain) and not the storage. And a person at a desk is not a Marker; markers are
geographic.

One contract gap surfaced only in a screenshot: two agents read `height` on a
viewpoint differently, so the establishing shot aimed at empty air fourteen
metres above the roof. It now means what the same field means for a city.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Karti Tripathi
2026-08-05 00:11:01 -07:00
parent 36471bbad7
commit d464459838
77 changed files with 14266 additions and 216 deletions
+158
View File
@@ -0,0 +1,158 @@
/**
* The acceptance test: a stranger with no keys, no account and no environment.
*
* This is CONTRACT.md §5.1 written as code, because it is the thing two
* independent server designs got wrong in the same way — a weather source that
* defaults to a provider needing a contact string, and a hard failure when it is
* absent. The last test in this file starts the real entry point under a
* genuinely empty environment and asks it for its health, which is the same
* assertion the `docker compose up` CI job makes from outside.
*/
import assert from "node:assert/strict";
import { spawn } from "node:child_process";
import { after, describe, it } from "node:test";
import { buildApp } from "../app.ts";
import { loadConfig } from "../config.ts";
import type {
FlightsBody,
HealthBody,
MarkersBody,
WeatherBody,
} from "../../../src/server/wire.ts";
/** `loadConfig({})` is exactly what `env -i` produces, minus the process. */
function emptyEnvApp() {
const config = loadConfig({});
config.logLevel = "silent";
return buildApp(config);
}
describe("a box handed nothing", () => {
it("defaults every source to its keyless setting and reports no demotions", () => {
const config = loadConfig({});
assert.equal(config.weather.source, "none");
assert.equal(config.flights.source, "sim");
assert.equal(config.markers.source, "none");
assert.equal(config.auth.mode, "none");
assert.equal(config.host, "127.0.0.1");
assert.equal(config.port, 8431);
assert.deepEqual(config.degraded, []);
});
it("answers health", async () => {
const app = emptyEnvApp();
after(() => app.close());
const res = await app.inject({ method: "GET", url: "/api/v1/health" });
assert.equal(res.statusCode, 200);
const body = res.json<HealthBody>();
assert.equal(body.ok, true);
assert.equal(body.auth.mode, "none");
assert.equal(body.auth.entryUrl, null);
assert.deepEqual(body.degraded, []);
});
it("serves a synthetic clear day rather than failing on a missing contact", async () => {
const app = emptyEnvApp();
after(() => app.close());
const res = await app.inject({ method: "GET", url: "/api/v1/weather" });
assert.equal(res.statusCode, 200);
const body = res.json<WeatherBody>();
assert.equal(body.synthetic, true);
assert.equal(body.source, "none");
assert.equal(body.condition, "clear");
});
it("serves the simulated sky as a plan, not as positions", async () => {
const app = emptyEnvApp();
after(() => app.close());
const body = (await app.inject({ method: "GET", url: "/api/v1/flights" })).json<FlightsBody>();
assert.equal(body.mode, "plan");
assert.equal(body.source, "sim");
assert.ok(body.mode === "plan" && body.routes.length > 0);
// A fixed origin, so a restart does not teleport every aircraft.
assert.ok(body.mode === "plan" && body.t0 < Date.now());
});
it("serves no markers and says so, rather than 404ing the route", async () => {
const app = emptyEnvApp();
after(() => app.close());
const res = await app.inject({ method: "GET", url: "/api/v1/markers" });
assert.equal(res.statusCode, 200);
assert.deepEqual(res.json<MarkersBody>().markers, []);
});
it("has no offices", async () => {
const app = emptyEnvApp();
after(() => app.close());
const res = await app.inject({ method: "GET", url: "/api/v1/offices/anything" });
assert.equal(res.statusCode, 404);
});
});
describe("cache-control is fail-closed", () => {
it("stamps private, no-store on anything that did not opt in", async () => {
const app = emptyEnvApp();
after(() => app.close());
const health = await app.inject({ method: "GET", url: "/api/v1/health" });
assert.equal(health.headers["cache-control"], "private, no-store");
const missing = await app.inject({ method: "GET", url: "/api/v1/nope" });
assert.equal(missing.statusCode, 404);
assert.equal(missing.headers["cache-control"], "private, no-store");
});
it("lets a route opt in explicitly", async () => {
const app = emptyEnvApp();
after(() => app.close());
const res = await app.inject({ method: "GET", url: "/api/v1/flights" });
assert.match(String(res.headers["cache-control"]), /^public, max-age=\d+$/);
});
it("refuses to opt in when the request carried a credential", async () => {
const app = emptyEnvApp();
after(() => app.close());
const res = await app.inject({
method: "GET",
url: "/api/v1/flights",
headers: { authorization: "Bearer something" },
});
assert.equal(res.headers["cache-control"], "private, no-store");
});
});
describe("the real process under env -i", () => {
it("boots and answers health with no environment at all", async () => {
const entry = new URL("../index.ts", import.meta.url).pathname;
// A genuinely empty environment: no PATH, no HOME, no TERA_*. `execPath` is
// absolute, so the child needs nothing from the parent to start.
const child = spawn(process.execPath, [entry], { env: {}, stdio: "ignore" });
after(() => child.kill("SIGKILL"));
const url = "http://127.0.0.1:8431/api/v1/health";
const deadline = Date.now() + 15_000;
let body: HealthBody | null = null;
while (Date.now() < deadline && body === null) {
try {
const res = await fetch(url);
if (res.ok) body = (await res.json()) as HealthBody;
} catch {
await new Promise((resolve) => setTimeout(resolve, 200));
}
}
assert.ok(body !== null, "the server never answered on 127.0.0.1:8431");
assert.equal(body.ok, true);
assert.equal(body.service, "tera-api");
});
});