Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
test(relay): expose cached clock-window parity drift [H5,H16,A2]
Corey Olsonb1fc8f21c0cf
diff --git a/test/relay-parity-clock.test.js b/test/relay-parity-clock.test.jsnew file mode 100644index 00000000..e8007d78--- /dev/null+++ b/test/relay-parity-clock.test.js@@ -0,0 +1,97 @@+/** Native cached HTTP state keeps the same explicit clock as a fresh relay reader [H5,H16,A2]. */+import assert from 'node:assert/strict';+import { randomBytes } from 'node:crypto';+import { join } from 'node:path';+import { test } from 'node:test';+import * as store from '../src/board.js';+import { serveApi } from '../src/api.js';+import { main } from '../src/cli.js';+import { recordBlock } from '../src/blocks.js';+import { exportBoard } from '../src/exchange.js';+import { resolveCommit, tryGit } from '../src/git.js';+import { relayPresentation } from '../src/relay-presentation.js';+import { snapshotState } from '../relay/browser-model.js';+import { assertReaderParity } from './relay-parity-reader.js';+import { relayClientFixture } from './relay-client-fixture.js';+import { submitFixture } from './board-submit-fixture.js';++const HOUR = 3_600_000;++/** Expose a real initialized SQLite board through HTTP with only the existing internal constructor clock port. */+async function clockFixture(t) {+ const box = await relayClientFixture(t);+ const base = Date.now() + 1_000;+ const clock = { value: base };+ const board = store.openBoard(join(box.root, '.git', 'pullboard', 'board.sqlite'), { now: () => new Date(base) });+ t.after(() => store.closeBoard(board));+ const id = store.boardId(board);+ const secret = randomBytes(24).toString('base64url');+ const api = await serveApi({ secret, runCommand: main, projects: () => [{ root: box.root, name: 'clock-parity' }],+ scope: { projectRoot: box.root }, isMain: true, stateDetail: 'full', now: () => clock.value });+ t.after(api.close);+ /** Compare the complete authenticated native response with the uncached production reader at exactly its clock.+ * This additional cache witness makes no API2/decryption claim; that transport has its separate real oracle.+ */+ async function read() {+ const response = await fetch(`http://127.0.0.1:${api.port}/api/v1/boards/${id}/state?detail=full`, { headers: { 'x-pullboard-key': secret } });+ assert.equal(response.status, 200);+ const native = (await response.json()).state;+ const presentation = relayPresentation(box.root, { observedAt: clock.value });+ const relay = snapshotState({ ...exportBoard(board), presentation }, id);+ assert.equal(native.observedAt, new Date(clock.value).toISOString());+ assert.equal(relay.observedAt, native.observedAt);+ return { native, relay };+ }+ return { ...box, board, base, clock, read };+}++test('native and relay readers expire a person block at the same observedAt without a write [H5,H16,A2]', { timeout: 60_000 }, async t => { // budget: real fixture startup, HTTP and cleanup; clock advancement never sleeps.+ const box = await clockFixture(t);+ recordBlock(join(box.root, '.git'), { at: new Date(box.base).toISOString(), code: 'PARITY_CLOCK_FIXTURE', command: 'synthetic projection input',+ by: 'coordinator', path: box.root, audience: 'person', reason: 'A private fixture block expires after a day.', step: 'Inspect the unchanged board.' });+ box.clock.value = box.base + 24 * HOUR - 1;+ const before = await box.read();+ assert.equal(before.native.blocks.length, 1, 'the real recorded person block is still within its window');+ assertReaderParity(before.native, before.relay);+ const inputs = exportBoard(box.board);+ box.clock.value += 2;+ const after = await box.read();+ assert.deepEqual(exportBoard(box.board), inputs, 'clock advancement makes no native mutation');+ assert.equal(after.relay.blocks.length, 0, 'the fresh production reader expires the recorded block');+ assertReaderParity(after.native, after.relay);+});++/** Seed real lifecycle events with synthetic acceptance metadata; this is not gate, CI or outside-review assurance. */+function seedLandingPace(box) {+ const builder = store.register(box.board, { lane: box.lane, path: join(box.root, 'clock-builder'), parentDigest: 'a'.repeat(64) });+ const reviewer = store.register(box.board, { lane: 'tests', path: join(box.root, 'clock-reviewer'), parentDigest: 'b'.repeat(64) });+ const head = resolveCommit(box.root, 'HEAD');+ const tree = tryGit(box.root, ['rev-parse', `${head}^{tree}`]).stdout.trim();+ for (let index = 0; index < 3; index++) {+ const id = store.addItem(box.board, { by: 'coordinator', lane: box.lane, title: `Synthetic pace item ${index}`, criterion: 'Recorded landing pace remains visible' });+ const frozen = { text: '{"rows":[]}', digest: `synthetic-pace-${index}` };+ store.claim(box.board, id, { agentId: builder, lane: box.lane, leaseMs: HOUR, head, freeze: () => frozen });+ submitFixture(box.board, id, { agentId: builder, commit: head, tree });+ store.reserveReview(box.board, id, { agentId: reviewer, lane: 'tests', leaseMs: HOUR, policy: 'any' });+ store.verify(box.board, id, { agentId: reviewer, decision: 'ACCEPT', head, digest: frozen.digest, policy: 'any', familyPolicy: 'off',+ note: 'Synthetic projection state only; no gate or assurance.', review: { commit: head, head, trunk: head, paths: [] } });+ store.merged(box.board, id, { agentId: 'coordinator', commit: head });+ }+ const pending = store.addItem(box.board, { by: 'coordinator', lane: box.lane, title: 'Pace forecast input', criterion: 'A pending item observes the current landing window' });+ store.addMilestone(box.board, { agentId: 'coordinator', name: 'Clock pace', items: [pending] });+}++test('native and relay readers cross a landing pace window at the same observedAt without a write [H5,H16,A2]', { timeout: 60_000 }, async t => { // budget: real fixture startup, native lifecycle inputs, HTTP and cleanup; no timed wait.+ const box = await clockFixture(t);+ seedLandingPace(box);+ box.clock.value = box.base + 2 * HOUR - 1;+ const before = await box.read();+ assert.equal(before.native.milestones.find(row => row.name === 'Clock pace').summary.pace.last2h, 3);+ assertReaderParity(before.native, before.relay);+ const inputs = exportBoard(box.board);+ box.clock.value += 2;+ const after = await box.read();+ assert.deepEqual(exportBoard(box.board), inputs, 'clock advancement makes no native mutation');+ assert.equal(after.relay.milestones.find(row => row.name === 'Clock pace').summary.pace.last2h, 0);+ assertReaderParity(after.native, after.relay);+});