The renderer contract names what a renderer does, by role

ROLES sorts every member of PORTS into one of six roles: the Earth (streaming
and building the globe from map sources), scene contents, camera and input,
world queries, the look, and the host and frame loop. The ports follow the
API's shape; the roles say what the engine behind them does, and that the app
keeps the data while the renderer owns everything from a source spec or a
draw set down to the pixels. roleOf resolves a member to its role, the most
specific entry winning. No member changes; a test keeps every member in
exactly one role and every entry naming a real member.
This commit is contained in:
Sameh Khamis committed 2026-11-11 13:36:06 -08:00
1 parent 1f307e0735
commit 21fdc6a332
3 files changed
+132

No files matched your search

+32
View File
@@ -8,6 +8,8 @@ import {
CONTRACT_VERSION,
FRAME_STEPS,
PORTS,
ROLES,
roleOf,
QUALITY_KEYS,
checkPortShape,
checkRendererShape,
@@ -126,6 +128,36 @@ test('PORTS lists every member of every port, required exactly when the type req
}
});
test('every member of every port has one role, and each role names real members', () => {
const ids = ROLES.map((r) => r.id);
assert.equal(new Set(ids).size, ids.length);
for (const [port, members] of Object.entries(PORTS))
for (const member of Object.keys(members))
assert.ok(
ids.includes(roleOf(port, member)),
`${port}.${member} has no role`,
);
// An entry is a port, or a member (or a prefix of dotted members) of one.
for (const role of ROLES)
for (const entry of role.members) {
const [port, ...rest] = entry.split('.');
const member = rest.join('.');
assert.ok(PORTS[port], `${role.id}: ${entry} names no port`);
if (member)
assert.ok(
Object.keys(PORTS[port]).some(
(m) => m === member || m.startsWith(`${member}.`),
),
`${role.id}: ${entry} names no member`,
);
}
// The most specific entry wins.
assert.equal(roleOf('globe', 'setBase'), 'surface');
assert.equal(roleOf('globe', 'sky.set'), 'look');
assert.equal(roleOf('globe', 'setSurfaceShading'), 'look');
assert.equal(roleOf('nowhere', 'x'), undefined);
});
test('the capability and frame-step lists are the types’ own', () => {
assert.deepEqual([...CAPABILITIES].sort(), unionLiterals('Capability'));
assert.deepEqual([...FRAME_STEPS].sort(), unionLiterals('FrameStep'));