Skip to content

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.

test(api): prove observation time travels with deltas [A2,N26]

Corey Olson393345213dfd
diff --git a/src/api-delta-fields.js b/src/api-delta-fields.js
new file mode 100644
index 00000000..d32d4f1f
--- /dev/null
+++ b/src/api-delta-fields.js
@@ -0,0 +1,5 @@
+/** Request projections and small decision lists travel whole in every state delta [A2,N26]. */
+export const WHOLE_STATE_DELTA_FIELDS = Object.freeze([
+ // Observation time belongs to this read, even when a cached build's event sequence is unchanged.
+ 'observedAt', 'unseen', 'proofStats', 'decisions', 'decisionQueue', 'holds', 'requests', 'personRequests',
+]);
diff --git a/src/api.js b/src/api.js
index c5f3bd91..07c261c2 100644
--- a/src/api.js
+++ b/src/api.js
@@ -1,6 +1,7 @@
import { buildLocalBoardState } from './native-board-state.js';
import { stateFileInputs } from './native-board-state.js';
import { fileRevision } from './native-board-state.js';
+import { WHOLE_STATE_DELTA_FIELDS } from './api-delta-fields.js';
import { nativeStateClockMatches } from './native-state-clock.js';
import { foreignDependencyStates } from './cross-repo-dependencies.js';
import {
@@ -444,8 +445,8 @@ function snapshotEntry(revision, state, preparedFlow, { inputs = null, itemMeta
print: fingerprint(summary), items: new Map(state.items.map((item) => [item.id, item])), itemMeta, itemMoveCounts, inputs, clockWindow, searchTexts: null };
}
-/** State fields every delta carries whole: this request's unread count and flow, and the small Needs-you lists. */
-const DELTA_WHOLE = new Set(['observedAt', 'unseen', 'proofStats', 'decisions', 'decisionQueue', 'holds', 'requests', 'personRequests']);
+/** Per-read projections, including observation time, are not part of a cached build fingerprint. */
+const DELTA_WHOLE = new Set(WHOLE_STATE_DELTA_FIELDS);
/** The state lists a delta merges entry by entry, and the field that names each entry. */
const DELTA_KEYS = Object.freeze({ items: 'id', shouts: 'shout_id', asked: 'shout_id', events: 'event_id', agents: 'agent_id', spec: 'id', practice: 'id', milestones: 'name' });
/** How many recent builds of each board a server keeps as possible delta bases. */
diff --git a/test/api-http.test.js b/test/api-http.test.js
index e3785622..fd8522b7 100644
--- a/test/api-http.test.js
+++ b/test/api-http.test.js
@@ -12,6 +12,7 @@ import { createLocalApiHandler, serveApi } from '../src/api.js';
import { serveView } from '../src/serve.js';
import { main } from '../src/cli.js';
import { applyStateDelta, createApiHandler } from '../src/api-http.js';
+import { WHOLE_STATE_DELTA_FIELDS } from '../src/api-delta-fields.js';
import { registryFile, registerProject, forgetProject } from '../src/projects.js';
import { Refused } from '../src/refused.js';
import * as store from '../src/board.js';
@@ -861,8 +862,8 @@ test('[A2, N26] a delta brings a snapshot up to date', async (t) => {
* Ask for what changed since the held snapshot, apply it, and compare it with a fresh snapshot
* read at the same instant, so the flow observation in both is the same.
*/
- async function catchUp(label) {
- t.mock.timers.enable({ apis: ['Date'], now: Date.now() });
+ async function catchUp(label, observedAt = Date.now()) {
+ t.mock.timers.enable({ apis: ['Date'], now: observedAt });
try {
const answer = await box.call(box.path + '/state?since=' + held.sequence);
const fresh = await box.call(box.path + '/state');
@@ -887,10 +888,15 @@ test('[A2, N26] a delta brings a snapshot up to date', async (t) => {
assert.deepEqual(changed(claimed, 'items'), [item], 'only the claimed item travels');
assert.equal(claimed.merge.items.set[0].claim.by, builder.agent);
assert.equal(Object.hasOwn(claimed.merge.items, 'ids'), false, 'no item came or went, so the order is not sent');
- const still = await catchUp('nothing changed');
+ const unchangedSequence = held.sequence;
+ const nextObservation = Date.parse(held.observedAt) + 1; // One logical clock tick; no board move or timed wait.
+ const still = await catchUp('only the observation clock changed', nextObservation);
+ assert.equal(held.sequence, unchangedSequence, 'advancing the observation clock writes no board event');
+ assert.equal(still.replace.observedAt, new Date(nextObservation).toISOString(),
+ 'even a no-event delta must refresh the held snapshot observation time');
assert.deepEqual(still.merge, {}, 'an unchanged board merges nothing');
- assert.deepEqual(Object.keys(still.replace).sort(), ['decisionQueue', 'decisions', 'holds', 'personRequests', 'proofStats', 'requests', 'unseen'],
- 'only the always-whole fields come, including the landed coordinator decision queue');
+ assert.deepEqual(Object.keys(still.replace).sort(), [...WHOLE_STATE_DELTA_FIELDS].sort(),
+ 'only the declared per-read projections and small decision lists travel whole');
assert.deepEqual(still.replace.decisionQueue, [], 'the unchanged empty coordinator queue travels as a whole field');
await move({ verb: 'submit', item, agent: builder.agent });