@defrex/autobuild 1.15.0 → 1.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/SPEC.md +110 -10
- package/docs/answering-blocked-builds.md +34 -1
- package/docs/architecture.md +41 -7
- package/docs/configuration.md +41 -7
- package/docs/dispatcher-hosting.md +3 -0
- package/docs/operator-api.md +15 -5
- package/docs/plugin-authoring.md +1 -0
- package/docs/remote-store-protocol.md +13 -3
- package/docs/remote-ticket-protocol.md +3 -1
- package/docs/restacking.md +41 -1
- package/docs/setup.md +15 -6
- package/docs/troubleshooting.md +51 -3
- package/docs/workspaces.md +4 -1
- package/package.json +3 -3
- package/packages/core/src/cli/accounts.ts +3 -0
- package/packages/core/src/cli/binary-direct.ts +14 -1
- package/packages/core/src/cli/binary.ts +10 -7
- package/packages/core/src/cli/dispatch.ts +610 -356
- package/packages/core/src/cli/secrets.ts +2 -0
- package/packages/core/src/config/schema.ts +15 -2
- package/packages/core/src/events/payloads.ts +8 -5
- package/packages/core/src/events/repository.ts +12 -6
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/e28c68e63cbd265f.json +108 -0
- package/packages/core/src/kernel/engine.ts +118 -0
- package/packages/core/src/kernel/reconcile-restack.ts +72 -9
- package/packages/core/src/kernel/reducer-revisions.ts +1 -0
- package/packages/core/src/kernel/tracked-dirt.ts +173 -0
- package/packages/core/src/ontology.ts +1 -0
- package/packages/core/src/operator/index.ts +10 -0
- package/packages/core/src/operator/merged-builds.ts +51 -0
- package/packages/core/src/operator/registry.ts +190 -101
- package/packages/core/src/operator/repo-argument.ts +43 -0
- package/packages/core/src/ports/tickets/grants.ts +2 -0
- package/packages/core/src/ports/tickets/remote.ts +2 -0
- package/packages/core/src/ports/types.ts +25 -4
- package/packages/core/src/ports/workspace/vercel-command-diagnostics.ts +144 -0
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +811 -169
- package/packages/core/src/processes/build-child.ts +15 -1
- package/packages/core/src/processes/build-runner.ts +349 -20
- package/packages/core/src/processes/dispatcher.ts +509 -104
- package/packages/core/src/processes/harvest-child.ts +21 -1
- package/packages/core/src/processes/harvest-runner.ts +82 -35
- package/packages/core/src/processes/invocation-budget.ts +6 -0
- package/packages/core/src/processes/launch-cut.ts +37 -0
- package/packages/core/src/processes/phase-failure-budget.ts +1 -0
- package/packages/core/src/processes/provisioning-progress.ts +23 -0
- package/packages/core/src/processes/repo-view.ts +25 -4
- package/packages/core/src/processes/workspace-preparation.ts +1 -0
- package/packages/core/src/store/adapter.ts +34 -5
- package/packages/core/src/store/build-feed.ts +148 -22
- package/packages/core/src/store/build-scope.ts +12 -3
- package/packages/core/src/store/caller-attribution.ts +170 -0
- package/packages/core/src/store/contract.ts +1038 -165
- package/packages/core/src/store/local/schema.ts +12 -1
- package/packages/core/src/store/local/store.ts +260 -25
- package/packages/core/src/store/memory.ts +156 -9
- package/packages/core/src/store/phase-session.ts +23 -3
- package/packages/core/src/store/reducer-value-shapes.json +5351 -5338
- package/packages/core/src/store/remote/client.ts +90 -11
- package/packages/core/src/store/remote/credentials.ts +2 -0
- package/packages/core/src/store/remote/index.ts +31 -5
- package/packages/core/src/store/remote/protocol.ts +45 -8
- package/packages/core/src/store/remote/released-clients.json +22 -0
- package/packages/core/src/store/remote/released-reducer-values/1.16.0.json +36358 -0
- package/packages/core/src/store/remote/released-reducer-values/1.17.0.json +36367 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +20 -16
- package/packages/core/src/store/remote/released-value-policy.ts +7 -0
- package/packages/core/src/store/session-handle.ts +12 -3
- package/packages/core/src/store/types.ts +48 -3
- package/packages/core/src/testing/reduced-read-budget.ts +310 -12
- package/skills/guide/SKILL.md +58 -9
- package/skills/guide/references/operator-api.md +15 -5
- package/skills/guide/references/plugin-authoring.md +1 -0
- package/skills/guide/references/remote-store-protocol.md +13 -3
- package/skills/guide/references/remote-ticket-protocol.md +3 -1
- package/skills/guide/references/restacking.md +41 -1
- package/skills/guide/references/setup.md +15 -6
- package/skills/operate/SKILL.md +31 -7
- package/templates/hosted-service/package.json +2 -2
|
@@ -213,7 +213,11 @@ export function runStartedWrite(
|
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
export function messagePostedWrite(text = 'hello'): SessionEventWrite<'message.posted'> {
|
|
216
|
-
return {
|
|
216
|
+
return {
|
|
217
|
+
actor: humanActor('operator'),
|
|
218
|
+
type: 'message.posted',
|
|
219
|
+
payload: { text },
|
|
220
|
+
}
|
|
217
221
|
}
|
|
218
222
|
|
|
219
223
|
export function turnStartedWrite(
|
|
@@ -275,7 +279,12 @@ export function representativeStreamParts(): StreamPart[] {
|
|
|
275
279
|
{ type: 'reasoning-start', id: 'r1' },
|
|
276
280
|
{ type: 'reasoning-delta', id: 'r1', delta: 'considering' },
|
|
277
281
|
{ type: 'reasoning-end', id: 'r1' },
|
|
278
|
-
{
|
|
282
|
+
{
|
|
283
|
+
type: 'tool-input-available',
|
|
284
|
+
toolCallId: 'c1',
|
|
285
|
+
toolName: 'read',
|
|
286
|
+
input: { path: 'a.ts' },
|
|
287
|
+
},
|
|
279
288
|
{ type: 'tool-output-available', toolCallId: 'c1', output: { lines: 10 } },
|
|
280
289
|
{ type: 'data-probe', id: 'd1', data: { n: 1 } },
|
|
281
290
|
{ type: 'error', errorText: 'transient' },
|
|
@@ -346,11 +355,20 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
346
355
|
const clock = manualClock()
|
|
347
356
|
await withStore(factory, { clock }, async (store) => {
|
|
348
357
|
const repo = 'presence-repo'
|
|
349
|
-
const identity = {
|
|
358
|
+
const identity = {
|
|
359
|
+
id: 'a',
|
|
360
|
+
host: 'host-a',
|
|
361
|
+
pid: 42,
|
|
362
|
+
startedAt: clock().toISOString(),
|
|
363
|
+
}
|
|
350
364
|
expect(await store.listOperatorPresence(repo)).toEqual([])
|
|
351
365
|
expect(await store.getRepo(repo)).toBeNull()
|
|
352
366
|
const initial = await store.upsertOperatorPresence(repo, identity)
|
|
353
|
-
expect(initial).toEqual({
|
|
367
|
+
expect(initial).toEqual({
|
|
368
|
+
...identity,
|
|
369
|
+
repo,
|
|
370
|
+
heartbeatAt: clock().toISOString(),
|
|
371
|
+
})
|
|
354
372
|
expect(await store.getRepo(repo)).toBeNull()
|
|
355
373
|
expect(await store.listOperatorPresence('foreign-repo')).toEqual([])
|
|
356
374
|
await store.ensureRepo(repo)
|
|
@@ -369,7 +387,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
369
387
|
pid: 43,
|
|
370
388
|
startedAt: clock().toISOString(),
|
|
371
389
|
}),
|
|
372
|
-
store.upsertOperatorPresence(repo, {
|
|
390
|
+
store.upsertOperatorPresence(repo, {
|
|
391
|
+
...identity,
|
|
392
|
+
id: 'b',
|
|
393
|
+
host: 'host-b',
|
|
394
|
+
}),
|
|
373
395
|
store.upsertOperatorPresence(repo, identity),
|
|
374
396
|
])
|
|
375
397
|
expect(revived.startedAt).toBe(identity.startedAt)
|
|
@@ -385,9 +407,17 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
385
407
|
test('operator withdrawal is idempotent, isolated and permits re-registration without journal writes', async () => {
|
|
386
408
|
const clock = manualClock()
|
|
387
409
|
await withStore(factory, { clock }, async (store) => {
|
|
388
|
-
const identity = {
|
|
410
|
+
const identity = {
|
|
411
|
+
id: 'one',
|
|
412
|
+
host: 'host',
|
|
413
|
+
pid: 1,
|
|
414
|
+
startedAt: clock().toISOString(),
|
|
415
|
+
}
|
|
389
416
|
await store.upsertOperatorPresence('withdraw', identity)
|
|
390
|
-
await store.upsertOperatorPresence('withdraw', {
|
|
417
|
+
await store.upsertOperatorPresence('withdraw', {
|
|
418
|
+
...identity,
|
|
419
|
+
id: 'two',
|
|
420
|
+
})
|
|
391
421
|
await store.upsertOperatorPresence('other', identity)
|
|
392
422
|
await store.ensureRepo('withdraw')
|
|
393
423
|
await store.claimRepoLease('withdraw', 'dispatcher', 900_000)
|
|
@@ -410,8 +440,12 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
410
440
|
expect(await store.listOperatorPresence('withdraw')).toEqual([])
|
|
411
441
|
const restartedAt = clock().toISOString()
|
|
412
442
|
expect(
|
|
413
|
-
(
|
|
414
|
-
.
|
|
443
|
+
(
|
|
444
|
+
await store.upsertOperatorPresence('withdraw', {
|
|
445
|
+
...identity,
|
|
446
|
+
startedAt: restartedAt,
|
|
447
|
+
})
|
|
448
|
+
).startedAt,
|
|
415
449
|
).toBe(restartedAt)
|
|
416
450
|
expect(await store.getRepo('withdraw')).toEqual(before)
|
|
417
451
|
expect(await store.getRepoEvents('withdraw')).toEqual(events)
|
|
@@ -420,7 +454,12 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
420
454
|
|
|
421
455
|
test('operator presence validates identity before mutation', async () => {
|
|
422
456
|
await withStore(factory, undefined, async (store) => {
|
|
423
|
-
const identity = {
|
|
457
|
+
const identity = {
|
|
458
|
+
id: 'ok',
|
|
459
|
+
host: 'host',
|
|
460
|
+
pid: 1,
|
|
461
|
+
startedAt: CONTRACT_T0,
|
|
462
|
+
}
|
|
424
463
|
for (const bad of [
|
|
425
464
|
{ id: '' },
|
|
426
465
|
{ host: '' },
|
|
@@ -430,7 +469,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
430
469
|
{ id: 'x'.repeat(257) },
|
|
431
470
|
]) {
|
|
432
471
|
await expect(
|
|
433
|
-
store.upsertOperatorPresence('invalid-presence', {
|
|
472
|
+
store.upsertOperatorPresence('invalid-presence', {
|
|
473
|
+
...identity,
|
|
474
|
+
...bad,
|
|
475
|
+
}),
|
|
434
476
|
).rejects.toThrow()
|
|
435
477
|
}
|
|
436
478
|
expect(await store.listOperatorPresence('invalid-presence')).toEqual([])
|
|
@@ -493,7 +535,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
493
535
|
// native serialization happens to retain insertion order.
|
|
494
536
|
expect(
|
|
495
537
|
sameParentRejection(
|
|
496
|
-
{
|
|
538
|
+
{
|
|
539
|
+
reason: previous!.reason,
|
|
540
|
+
target: previous!.target,
|
|
541
|
+
revision: previous!.revision,
|
|
542
|
+
},
|
|
497
543
|
rejection,
|
|
498
544
|
),
|
|
499
545
|
).toBe(true)
|
|
@@ -539,14 +585,21 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
539
585
|
repo: input.repo,
|
|
540
586
|
baseBranch: 'main',
|
|
541
587
|
kind: 'node',
|
|
542
|
-
target: {
|
|
588
|
+
target: {
|
|
589
|
+
ticket: { source: 'file', id: 'parent' },
|
|
590
|
+
build: 'parent-build',
|
|
591
|
+
},
|
|
543
592
|
},
|
|
544
593
|
},
|
|
545
594
|
})
|
|
546
595
|
await store.append(input.slug, {
|
|
547
596
|
actor: DISPATCHER,
|
|
548
597
|
type: 'node.opening',
|
|
549
|
-
payload: {
|
|
598
|
+
payload: {
|
|
599
|
+
branch: 'ab-node/integration-node',
|
|
600
|
+
parent: 'main',
|
|
601
|
+
sha: 'opening',
|
|
602
|
+
},
|
|
550
603
|
})
|
|
551
604
|
await readBuildFacts(store, input.slug)
|
|
552
605
|
await store.append(input.slug, {
|
|
@@ -571,10 +624,18 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
571
624
|
actor: DISPATCHER,
|
|
572
625
|
type: 'pr.opened',
|
|
573
626
|
payload: {
|
|
574
|
-
pr: {
|
|
627
|
+
pr: {
|
|
628
|
+
number: 1,
|
|
629
|
+
url: 'https://example.test/pr/1',
|
|
630
|
+
headSha: 'child',
|
|
631
|
+
},
|
|
575
632
|
},
|
|
576
633
|
})
|
|
577
|
-
await store.append(input.slug, {
|
|
634
|
+
await store.append(input.slug, {
|
|
635
|
+
actor: DISPATCHER,
|
|
636
|
+
type: 'pr.closed',
|
|
637
|
+
payload: {},
|
|
638
|
+
})
|
|
578
639
|
expect((await store.getRepoBuildDigests(input.repo)).get(input.slug)?.prClosed).toBe(true)
|
|
579
640
|
expect((await store.getBuild(input.slug))?.lease).toBeUndefined()
|
|
580
641
|
})
|
|
@@ -624,7 +685,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
624
685
|
test('createBuild appends an initial build.created as seq 1, atomically with the record', async () => {
|
|
625
686
|
await withStore(factory, undefined, async (store) => {
|
|
626
687
|
const created = buildCreatedWrite()
|
|
627
|
-
await store.createBuild({
|
|
688
|
+
await store.createBuild({
|
|
689
|
+
...sampleBuildInput('with-created'),
|
|
690
|
+
created,
|
|
691
|
+
})
|
|
628
692
|
const events = await store.getEvents('with-created')
|
|
629
693
|
expect(events.map((event) => [event.seq, event.type])).toEqual([[1, 'build.created']])
|
|
630
694
|
expect(events[0]?.payload).toEqual(created.payload)
|
|
@@ -644,13 +708,21 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
644
708
|
await expect(
|
|
645
709
|
store.createBuild({
|
|
646
710
|
...sampleBuildInput('bad-created'),
|
|
647
|
-
created: {
|
|
711
|
+
created: {
|
|
712
|
+
actor: DISPATCHER,
|
|
713
|
+
type: 'build.created',
|
|
714
|
+
payload: { nope: 1 },
|
|
715
|
+
} as never,
|
|
648
716
|
}),
|
|
649
717
|
).rejects.toThrow()
|
|
650
718
|
await expect(
|
|
651
719
|
store.createBuild({
|
|
652
720
|
...sampleBuildInput('wrong-type'),
|
|
653
|
-
created: {
|
|
721
|
+
created: {
|
|
722
|
+
actor: DISPATCHER,
|
|
723
|
+
type: 'build.completed',
|
|
724
|
+
payload: {},
|
|
725
|
+
} as never,
|
|
654
726
|
}),
|
|
655
727
|
).rejects.toThrow()
|
|
656
728
|
expect(await store.getBuild('bad-created')).toBeNull()
|
|
@@ -777,13 +849,22 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
777
849
|
},
|
|
778
850
|
}
|
|
779
851
|
}
|
|
780
|
-
await store.createBuild({
|
|
781
|
-
|
|
852
|
+
await store.createBuild({
|
|
853
|
+
...sampleBuildInput('n1', { repo }),
|
|
854
|
+
created: created(),
|
|
855
|
+
})
|
|
856
|
+
await store.createBuild({
|
|
857
|
+
...sampleBuildInput('work', { repo }),
|
|
858
|
+
created: created('n1'),
|
|
859
|
+
})
|
|
782
860
|
await store.createBuild({
|
|
783
861
|
...sampleBuildInput('moved', { repo }),
|
|
784
862
|
created: created('n1', 'node'),
|
|
785
863
|
})
|
|
786
|
-
await store.createBuild({
|
|
864
|
+
await store.createBuild({
|
|
865
|
+
...sampleBuildInput('plain', { repo }),
|
|
866
|
+
created: created(),
|
|
867
|
+
})
|
|
787
868
|
const ticket = buildCreatedWrite().payload.ticket
|
|
788
869
|
const move = {
|
|
789
870
|
id: 'move-1',
|
|
@@ -919,7 +1000,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
919
1000
|
type: 'build.completed',
|
|
920
1001
|
payload: { outcome: 'merged' },
|
|
921
1002
|
})
|
|
922
|
-
await store.append('ob-aborted', {
|
|
1003
|
+
await store.append('ob-aborted', {
|
|
1004
|
+
actor: KERNEL,
|
|
1005
|
+
type: 'build.aborted',
|
|
1006
|
+
payload: {},
|
|
1007
|
+
})
|
|
923
1008
|
expect((await expectOpenMatchesDigests(store, repo)).sort()).toEqual([
|
|
924
1009
|
'ob-aborted',
|
|
925
1010
|
'ob-queued',
|
|
@@ -958,7 +1043,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
958
1043
|
// clears a terminal.
|
|
959
1044
|
await store.append(slug, reopen)
|
|
960
1045
|
expect(await expectOpenMatchesDigests(store, repo)).toEqual([])
|
|
961
|
-
await store.append(slug, {
|
|
1046
|
+
await store.append(slug, {
|
|
1047
|
+
actor: KERNEL,
|
|
1048
|
+
type: 'build.aborted',
|
|
1049
|
+
payload: {},
|
|
1050
|
+
})
|
|
962
1051
|
expect(await expectOpenMatchesDigests(store, repo)).toEqual([slug])
|
|
963
1052
|
await store.append(slug, reopen)
|
|
964
1053
|
expect(await expectOpenMatchesDigests(store, repo)).toEqual([slug])
|
|
@@ -1003,7 +1092,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
1003
1092
|
commit: 'unknown',
|
|
1004
1093
|
source: { kind: 'package' as const, location: '/old' },
|
|
1005
1094
|
}
|
|
1006
|
-
const targetRuntime = {
|
|
1095
|
+
const targetRuntime = {
|
|
1096
|
+
...runtime,
|
|
1097
|
+
source: { ...runtime.source, location: '/new' },
|
|
1098
|
+
}
|
|
1007
1099
|
await store.append(slug, {
|
|
1008
1100
|
actor: DISPATCHER,
|
|
1009
1101
|
type: 'execution.started',
|
|
@@ -1012,9 +1104,20 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
1012
1104
|
await store.append(slug, {
|
|
1013
1105
|
actor: DISPATCHER,
|
|
1014
1106
|
type: 'execution.drain-authorized',
|
|
1015
|
-
payload: {
|
|
1107
|
+
payload: {
|
|
1108
|
+
instance: 'i',
|
|
1109
|
+
correlation: 'h',
|
|
1110
|
+
run: 'old',
|
|
1111
|
+
runtime,
|
|
1112
|
+
targetRuntime,
|
|
1113
|
+
},
|
|
1016
1114
|
})
|
|
1017
|
-
const request = {
|
|
1115
|
+
const request = {
|
|
1116
|
+
instance: 'i',
|
|
1117
|
+
correlation: 'h',
|
|
1118
|
+
from: runtime,
|
|
1119
|
+
to: targetRuntime,
|
|
1120
|
+
}
|
|
1018
1121
|
await store.append(slug, {
|
|
1019
1122
|
actor: KERNEL,
|
|
1020
1123
|
type: 'execution.relaunch-requested',
|
|
@@ -1026,7 +1129,12 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
1026
1129
|
await store.append(slug, {
|
|
1027
1130
|
actor: DISPATCHER,
|
|
1028
1131
|
type: 'execution.ended',
|
|
1029
|
-
payload: {
|
|
1132
|
+
payload: {
|
|
1133
|
+
instance: 'i',
|
|
1134
|
+
workspaceRef: 'w',
|
|
1135
|
+
outcome: 'relaunch',
|
|
1136
|
+
exitCode: 0,
|
|
1137
|
+
},
|
|
1030
1138
|
})
|
|
1031
1139
|
const facts = (await readBuildFacts(store, slug)).value
|
|
1032
1140
|
expect(facts.lastExecution).toBe('relaunch')
|
|
@@ -1042,7 +1150,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
1042
1150
|
const slug = 'dg-work'
|
|
1043
1151
|
await store.createBuild(sampleBuildInput(slug, { repo }))
|
|
1044
1152
|
await store.append(slug, buildCreatedWrite())
|
|
1045
|
-
const flags = async (): Promise<{
|
|
1153
|
+
const flags = async (): Promise<{
|
|
1154
|
+
executionOpen?: true
|
|
1155
|
+
reclaimPending?: true
|
|
1156
|
+
}> => {
|
|
1046
1157
|
const digest = (await store.getRepoBuildDigests(repo)).get(slug)!
|
|
1047
1158
|
return {
|
|
1048
1159
|
...(digest.executionOpen ? { executionOpen: true as const } : {}),
|
|
@@ -1156,7 +1267,14 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
1156
1267
|
attempt: { proposal, ticket },
|
|
1157
1268
|
outcome,
|
|
1158
1269
|
...(outcome === 'accepted'
|
|
1159
|
-
? {
|
|
1270
|
+
? {
|
|
1271
|
+
measurement: {
|
|
1272
|
+
revision: 1,
|
|
1273
|
+
baseline: 50,
|
|
1274
|
+
candidate: 40,
|
|
1275
|
+
delta: 10,
|
|
1276
|
+
},
|
|
1277
|
+
}
|
|
1160
1278
|
: {}),
|
|
1161
1279
|
},
|
|
1162
1280
|
})
|
|
@@ -1527,7 +1645,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
1527
1645
|
await expect(scoped.beginRepoTick(repo, 'owner')).rejects.toThrow()
|
|
1528
1646
|
const failure = { outcome: 'failed' as const, error: 'failed' }
|
|
1529
1647
|
await expect(scoped.finishRepoTick(repo, 'owner', failure, [])).rejects.toThrow()
|
|
1530
|
-
const session = await store.createSession({
|
|
1648
|
+
const session = await store.createSession({
|
|
1649
|
+
repo,
|
|
1650
|
+
operator: 'operator',
|
|
1651
|
+
})
|
|
1531
1652
|
await expect(
|
|
1532
1653
|
store.scopeSession(session.id).upsertOperatorPresence(repo, {
|
|
1533
1654
|
id: 'op',
|
|
@@ -1548,7 +1669,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
1548
1669
|
const before = await store.getRepo(repo)
|
|
1549
1670
|
await expect(
|
|
1550
1671
|
store.finishRepoTick(repo, 'owner', failure, [
|
|
1551
|
-
{
|
|
1672
|
+
{
|
|
1673
|
+
actor: DISPATCHER,
|
|
1674
|
+
type: 'dispatcher.tick-started',
|
|
1675
|
+
payload: { run: 'owner' },
|
|
1676
|
+
},
|
|
1552
1677
|
{
|
|
1553
1678
|
actor: humanActor('operator'),
|
|
1554
1679
|
type: 'dispatcher.intake-set',
|
|
@@ -1909,7 +2034,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
1909
2034
|
await store.beginRepoTick(repo, 'two')
|
|
1910
2035
|
await stable()
|
|
1911
2036
|
await store.finishRepoTick(repo, 'two', { outcome: 'failed', error: 'test' }, [
|
|
1912
|
-
{
|
|
2037
|
+
{
|
|
2038
|
+
actor: DISPATCHER,
|
|
2039
|
+
type: 'dispatcher.tick-started',
|
|
2040
|
+
payload: { run: 'two' },
|
|
2041
|
+
},
|
|
1913
2042
|
{
|
|
1914
2043
|
actor: DISPATCHER,
|
|
1915
2044
|
type: 'dispatcher.tick-failed',
|
|
@@ -1919,7 +2048,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
1919
2048
|
await repoAdvanced()
|
|
1920
2049
|
await store.releaseRepoLease(repo, 'two')
|
|
1921
2050
|
await repoAdvanced()
|
|
1922
|
-
await store.createBuild({
|
|
2051
|
+
await store.createBuild({
|
|
2052
|
+
slug: 'position-foreign',
|
|
2053
|
+
repo: 'foreign',
|
|
2054
|
+
})
|
|
1923
2055
|
await store.ensureRepo('foreign')
|
|
1924
2056
|
await store.appendRepo('foreign', event)
|
|
1925
2057
|
await store.claimRepoLease('foreign', 'peer', 1000)
|
|
@@ -1944,14 +2076,21 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
1944
2076
|
|
|
1945
2077
|
await store.createBuild({ slug: 'feed-a', repo })
|
|
1946
2078
|
await store.createBuild({ slug: 'feed-b', repo })
|
|
1947
|
-
await store.createBuild({
|
|
2079
|
+
await store.createBuild({
|
|
2080
|
+
slug: 'feed-foreign',
|
|
2081
|
+
repo: 'feed/other',
|
|
2082
|
+
})
|
|
1948
2083
|
const p0 = await store.getRepoChangePosition(repo)
|
|
1949
2084
|
const all = await store.listBuildsChangedSince(repo, '0')
|
|
1950
2085
|
expect(all.position).toBe(p0)
|
|
1951
2086
|
expect(all.builds.map((build) => build.slug)).toEqual(['feed-a', 'feed-b'])
|
|
1952
2087
|
expect(all.builds.at(-1)!.position).toBe(p0)
|
|
1953
2088
|
|
|
1954
|
-
await store.append('feed-a', {
|
|
2089
|
+
await store.append('feed-a', {
|
|
2090
|
+
actor: KERNEL,
|
|
2091
|
+
type: 'build.aborted',
|
|
2092
|
+
payload: {},
|
|
2093
|
+
})
|
|
1955
2094
|
const afterAppend = await store.listBuildsChangedSince(repo, p0)
|
|
1956
2095
|
expect(afterAppend.builds).toEqual([{ slug: 'feed-a', position: afterAppend.position }])
|
|
1957
2096
|
expect(compareChangePositions(afterAppend.position, p0)).toBe(1)
|
|
@@ -1968,9 +2107,21 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
1968
2107
|
expect(afterCreate.builds).toEqual([{ slug: 'feed-c', position: afterCreate.position }])
|
|
1969
2108
|
|
|
1970
2109
|
// Changed twice: once, at the latest position, after a later build.
|
|
1971
|
-
await store.append('feed-b', {
|
|
1972
|
-
|
|
1973
|
-
|
|
2110
|
+
await store.append('feed-b', {
|
|
2111
|
+
actor: KERNEL,
|
|
2112
|
+
type: 'build.aborted',
|
|
2113
|
+
payload: {},
|
|
2114
|
+
})
|
|
2115
|
+
await store.append('feed-a', {
|
|
2116
|
+
actor: KERNEL,
|
|
2117
|
+
type: 'build.aborted',
|
|
2118
|
+
payload: {},
|
|
2119
|
+
})
|
|
2120
|
+
await store.append('feed-b', {
|
|
2121
|
+
actor: KERNEL,
|
|
2122
|
+
type: 'build.aborted',
|
|
2123
|
+
payload: {},
|
|
2124
|
+
})
|
|
1974
2125
|
const twice = await store.listBuildsChangedSince(repo, afterCreate.position)
|
|
1975
2126
|
expect(twice.builds.map((build) => build.slug)).toEqual(['feed-a', 'feed-b'])
|
|
1976
2127
|
expect(twice.builds.at(-1)!.position).toBe(twice.position)
|
|
@@ -2032,7 +2183,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
2032
2183
|
round: number,
|
|
2033
2184
|
clock: Clock & { advance(ms: number): void },
|
|
2034
2185
|
) => {
|
|
2035
|
-
await store.append(slug, {
|
|
2186
|
+
await store.append(slug, {
|
|
2187
|
+
actor: KERNEL,
|
|
2188
|
+
type: 'plan.started',
|
|
2189
|
+
payload: { round },
|
|
2190
|
+
})
|
|
2036
2191
|
clock.advance(90_000)
|
|
2037
2192
|
await store.append(slug, {
|
|
2038
2193
|
actor: agentActor('plan', 's'),
|
|
@@ -2077,9 +2232,17 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
2077
2232
|
expect(first.cursor).toBe(0)
|
|
2078
2233
|
expect(first.value).toEqual(await expected(store, ['rollup-a', 'rollup-b'], clock()))
|
|
2079
2234
|
await plan(store, 'rollup-b', 2, clock)
|
|
2080
|
-
await store.append('rollup-a', {
|
|
2235
|
+
await store.append('rollup-a', {
|
|
2236
|
+
actor: KERNEL,
|
|
2237
|
+
type: 'build.paused',
|
|
2238
|
+
payload: {},
|
|
2239
|
+
})
|
|
2081
2240
|
clock.advance(30_000)
|
|
2082
|
-
await store.append('rollup-a', {
|
|
2241
|
+
await store.append('rollup-a', {
|
|
2242
|
+
actor: KERNEL,
|
|
2243
|
+
type: 'build.resumed',
|
|
2244
|
+
payload: {},
|
|
2245
|
+
})
|
|
2083
2246
|
const next = await store.getReducerValue(scope, request)
|
|
2084
2247
|
expect(next.value).toEqual(await expected(store, ['rollup-a', 'rollup-b'], clock()))
|
|
2085
2248
|
expect(next.value).not.toEqual(first.value)
|
|
@@ -2111,7 +2274,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
2111
2274
|
const answer = (await store.getReducerValue(scope, merged))
|
|
2112
2275
|
.value as unknown as StepDurationsValue
|
|
2113
2276
|
expect(answer.steps).toEqual([
|
|
2114
|
-
expect.objectContaining({
|
|
2277
|
+
expect.objectContaining({
|
|
2278
|
+
step: 'plan',
|
|
2279
|
+
count: 2,
|
|
2280
|
+
totalMs: 180_000,
|
|
2281
|
+
}),
|
|
2115
2282
|
])
|
|
2116
2283
|
expect(answer as unknown).toEqual(await expected(store, ['rollup-reopen'], clock(), {}))
|
|
2117
2284
|
})
|
|
@@ -2146,7 +2313,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
2146
2313
|
{ reducer: 'stepDurations' },
|
|
2147
2314
|
)
|
|
2148
2315
|
expect(answer.cursor).toBe(0)
|
|
2149
|
-
expect(answer.value).toEqual({
|
|
2316
|
+
expect(answer.value).toEqual({
|
|
2317
|
+
position: '0',
|
|
2318
|
+
window: '7d',
|
|
2319
|
+
steps: [],
|
|
2320
|
+
})
|
|
2150
2321
|
expect(await store.getRepo('rollup/nobody')).toBeNull()
|
|
2151
2322
|
await expect(store.getReducerValue(scope, { reducer: 'unknownRollup' })).rejects.toThrow()
|
|
2152
2323
|
})
|
|
@@ -2167,7 +2338,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
2167
2338
|
}
|
|
2168
2339
|
const finish = (store: BuildStore, slug: string, type: 'merged' | 'aborted') =>
|
|
2169
2340
|
type === 'aborted'
|
|
2170
|
-
? store.append(slug, {
|
|
2341
|
+
? store.append(slug, {
|
|
2342
|
+
actor: KERNEL,
|
|
2343
|
+
type: 'build.aborted',
|
|
2344
|
+
payload: {},
|
|
2345
|
+
})
|
|
2171
2346
|
: store.append(slug, {
|
|
2172
2347
|
actor: DISPATCHER,
|
|
2173
2348
|
type: 'build.completed',
|
|
@@ -2286,7 +2461,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
2286
2461
|
await raise(store, 'de-active')
|
|
2287
2462
|
await complete(store, 'de-late')
|
|
2288
2463
|
await raise(store, 'de-aborted')
|
|
2289
|
-
await store.append('de-aborted', {
|
|
2464
|
+
await store.append('de-aborted', {
|
|
2465
|
+
actor: KERNEL,
|
|
2466
|
+
type: 'build.aborted',
|
|
2467
|
+
payload: {},
|
|
2468
|
+
})
|
|
2290
2469
|
// The abort closed its escalation, so cleanup's completion lists nothing.
|
|
2291
2470
|
await store.append('de-aborted', {
|
|
2292
2471
|
actor: DISPATCHER,
|
|
@@ -2304,7 +2483,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
2304
2483
|
await store.append('de-late', {
|
|
2305
2484
|
actor: humanActor('op'),
|
|
2306
2485
|
type: 'escalation.answered',
|
|
2307
|
-
payload: {
|
|
2486
|
+
payload: {
|
|
2487
|
+
id: 'de-late-esc',
|
|
2488
|
+
answer: 'ack',
|
|
2489
|
+
resolution: 'retry',
|
|
2490
|
+
},
|
|
2308
2491
|
})
|
|
2309
2492
|
const answered = await read(store)
|
|
2310
2493
|
expect(answered.builds).toEqual([])
|
|
@@ -2352,7 +2535,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
2352
2535
|
const clock = manualClock(CONTRACT_T0)
|
|
2353
2536
|
await withStore(factory, { clock }, async (store) => {
|
|
2354
2537
|
const repo = 'page/repo'
|
|
2355
|
-
expect(await store.listBuildsPage(repo)).toEqual({
|
|
2538
|
+
expect(await store.listBuildsPage(repo)).toEqual({
|
|
2539
|
+
builds: [],
|
|
2540
|
+
next: null,
|
|
2541
|
+
})
|
|
2356
2542
|
expect(await store.getRepo(repo)).toBeNull()
|
|
2357
2543
|
await store.createBuild({ slug: 'page-a', repo })
|
|
2358
2544
|
clock.advance(1)
|
|
@@ -2370,9 +2556,15 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
2370
2556
|
expect(first.next).not.toBeNull()
|
|
2371
2557
|
// A build created after page 1 neither repeats nor drops later rows.
|
|
2372
2558
|
await store.createBuild({ slug: 'page-f', repo })
|
|
2373
|
-
const second = await store.listBuildsPage(repo, {
|
|
2559
|
+
const second = await store.listBuildsPage(repo, {
|
|
2560
|
+
limit: 2,
|
|
2561
|
+
cursor: first.next!,
|
|
2562
|
+
})
|
|
2374
2563
|
expect(second.builds.map((build) => build.slug)).toEqual(['page-c', 'page-b'])
|
|
2375
|
-
const third = await store.listBuildsPage(repo, {
|
|
2564
|
+
const third = await store.listBuildsPage(repo, {
|
|
2565
|
+
limit: 2,
|
|
2566
|
+
cursor: second.next!,
|
|
2567
|
+
})
|
|
2376
2568
|
expect(third.builds.map((build) => build.slug)).toEqual(['page-a'])
|
|
2377
2569
|
expect(third.next).toBeNull()
|
|
2378
2570
|
|
|
@@ -2432,7 +2624,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
2432
2624
|
},
|
|
2433
2625
|
})
|
|
2434
2626
|
const complete = (store: BuildStore, slug: string, outcome: 'merged' | 'closed-unmerged') =>
|
|
2435
|
-
store.append(slug, {
|
|
2627
|
+
store.append(slug, {
|
|
2628
|
+
actor: DISPATCHER,
|
|
2629
|
+
type: 'build.completed',
|
|
2630
|
+
payload: { outcome },
|
|
2631
|
+
})
|
|
2436
2632
|
const reopen = (store: BuildStore, slug: string) =>
|
|
2437
2633
|
store.append(slug, {
|
|
2438
2634
|
actor: humanActor('op'),
|
|
@@ -2524,15 +2720,28 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
2524
2720
|
'act-a',
|
|
2525
2721
|
])
|
|
2526
2722
|
expect(
|
|
2527
|
-
slugs(
|
|
2723
|
+
slugs(
|
|
2724
|
+
await walkPages(store, repo, {
|
|
2725
|
+
activeSince: since,
|
|
2726
|
+
outcome: 'merged',
|
|
2727
|
+
}),
|
|
2728
|
+
),
|
|
2528
2729
|
).toEqual(['act-a'])
|
|
2529
|
-
expect(
|
|
2530
|
-
|
|
2531
|
-
|
|
2730
|
+
expect(
|
|
2731
|
+
slugs(
|
|
2732
|
+
await walkPages(store, repo, {
|
|
2733
|
+
activeSince: since,
|
|
2734
|
+
kind: 'node',
|
|
2735
|
+
}),
|
|
2736
|
+
),
|
|
2737
|
+
).toEqual([])
|
|
2532
2738
|
|
|
2533
2739
|
// A build written mid-traversal jumps ahead of the cursor; the walk
|
|
2534
2740
|
// continues from the saved key, so consumers dedupe by slug.
|
|
2535
|
-
const first = await store.listBuildsPage(repo, {
|
|
2741
|
+
const first = await store.listBuildsPage(repo, {
|
|
2742
|
+
activeSince: since,
|
|
2743
|
+
limit: 1,
|
|
2744
|
+
})
|
|
2536
2745
|
expect(slugs(first.builds)).toEqual(['act-d'])
|
|
2537
2746
|
await reopen(store, 'act-a')
|
|
2538
2747
|
const second = await store.listBuildsPage(repo, {
|
|
@@ -2550,8 +2759,12 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
2550
2759
|
await store.createBuild({ slug: 'reject-a', repo })
|
|
2551
2760
|
await store.createBuild({ slug: 'reject-b', repo })
|
|
2552
2761
|
const created = (await store.listBuildsPage(repo, { limit: 1 })).next!
|
|
2553
|
-
const updated = (
|
|
2554
|
-
.
|
|
2762
|
+
const updated = (
|
|
2763
|
+
await store.listBuildsPage(repo, {
|
|
2764
|
+
limit: 1,
|
|
2765
|
+
activeSince: CONTRACT_T0,
|
|
2766
|
+
})
|
|
2767
|
+
).next!
|
|
2555
2768
|
for (const opts of [
|
|
2556
2769
|
{ limit: 0 },
|
|
2557
2770
|
{ limit: 101 },
|
|
@@ -2577,6 +2790,292 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
2577
2790
|
})
|
|
2578
2791
|
})
|
|
2579
2792
|
|
|
2793
|
+
describe('merged build listing', () => {
|
|
2794
|
+
const ticket = (id: string) => ({
|
|
2795
|
+
source: 'file' as const,
|
|
2796
|
+
id,
|
|
2797
|
+
title: `Ticket ${id}`,
|
|
2798
|
+
})
|
|
2799
|
+
const created = (
|
|
2800
|
+
slug: string,
|
|
2801
|
+
repo: string,
|
|
2802
|
+
opts: {
|
|
2803
|
+
kind?: 'node'
|
|
2804
|
+
target?: { build: string; ticket: ReturnType<typeof ticket> }
|
|
2805
|
+
} = {},
|
|
2806
|
+
) => ({
|
|
2807
|
+
actor: DISPATCHER,
|
|
2808
|
+
type: 'build.created' as const,
|
|
2809
|
+
payload: {
|
|
2810
|
+
ticket: ticket(slug),
|
|
2811
|
+
repo,
|
|
2812
|
+
baseBranch: 'main',
|
|
2813
|
+
...(opts.kind ? { kind: opts.kind } : {}),
|
|
2814
|
+
...(opts.target ? { target: opts.target } : {}),
|
|
2815
|
+
},
|
|
2816
|
+
})
|
|
2817
|
+
const complete = (store: BuildStore, slug: string, outcome: 'merged' | 'closed-unmerged') =>
|
|
2818
|
+
store.append(slug, {
|
|
2819
|
+
actor: DISPATCHER,
|
|
2820
|
+
type: 'build.completed',
|
|
2821
|
+
payload: { outcome },
|
|
2822
|
+
})
|
|
2823
|
+
const pr = (number: number) => ({
|
|
2824
|
+
number,
|
|
2825
|
+
url: `https://forge.example/pr/${number}`,
|
|
2826
|
+
headSha: `sha${number}`,
|
|
2827
|
+
})
|
|
2828
|
+
const slugs = (page: import('./build-feed').MergedBuildPage) =>
|
|
2829
|
+
page.builds.map((build) => build.record.slug)
|
|
2830
|
+
const walk = async (
|
|
2831
|
+
store: BuildStore,
|
|
2832
|
+
repo: string,
|
|
2833
|
+
opts: import('./build-feed').MergedBuildPageOptions,
|
|
2834
|
+
) => {
|
|
2835
|
+
const walked: string[] = []
|
|
2836
|
+
let cursor: string | undefined
|
|
2837
|
+
do {
|
|
2838
|
+
const page = await store.listMergedBuildsPage(repo, {
|
|
2839
|
+
...opts,
|
|
2840
|
+
...(cursor === undefined ? {} : { cursor }),
|
|
2841
|
+
})
|
|
2842
|
+
walked.push(...slugs(page))
|
|
2843
|
+
cursor = page.next ?? undefined
|
|
2844
|
+
} while (cursor !== undefined)
|
|
2845
|
+
return walked
|
|
2846
|
+
}
|
|
2847
|
+
|
|
2848
|
+
test('orders by merge time with a slug tiebreak and carries every listing fact', async () => {
|
|
2849
|
+
const clock = manualClock(CONTRACT_T0)
|
|
2850
|
+
await withStore(factory, { clock }, async (store) => {
|
|
2851
|
+
const repo = 'merged/repo'
|
|
2852
|
+
expect(await store.listMergedBuildsPage(repo)).toEqual({
|
|
2853
|
+
builds: [],
|
|
2854
|
+
next: null,
|
|
2855
|
+
})
|
|
2856
|
+
expect(await store.getRepo(repo)).toBeNull()
|
|
2857
|
+
const parent = { build: 'm-node', ticket: ticket('m-node') }
|
|
2858
|
+
await store.createBuild({
|
|
2859
|
+
slug: 'm-node',
|
|
2860
|
+
repo,
|
|
2861
|
+
ticket: ticket('m-node'),
|
|
2862
|
+
created: created('m-node', repo, { kind: 'node' }),
|
|
2863
|
+
})
|
|
2864
|
+
await store.createBuild({
|
|
2865
|
+
slug: 'm-child',
|
|
2866
|
+
repo,
|
|
2867
|
+
ticket: ticket('m-child'),
|
|
2868
|
+
created: created('m-child', repo, { target: parent }),
|
|
2869
|
+
})
|
|
2870
|
+
await store.createBuild({
|
|
2871
|
+
slug: 'm-leaf',
|
|
2872
|
+
repo,
|
|
2873
|
+
created: created('m-leaf', repo),
|
|
2874
|
+
})
|
|
2875
|
+
await store.createBuild({
|
|
2876
|
+
slug: 'm-open',
|
|
2877
|
+
repo,
|
|
2878
|
+
created: created('m-open', repo),
|
|
2879
|
+
})
|
|
2880
|
+
await store.createBuild({
|
|
2881
|
+
slug: 'm-closed',
|
|
2882
|
+
repo,
|
|
2883
|
+
created: created('m-closed', repo),
|
|
2884
|
+
})
|
|
2885
|
+
await store.createBuild({
|
|
2886
|
+
slug: 'm-tie',
|
|
2887
|
+
repo,
|
|
2888
|
+
created: created('m-tie', repo),
|
|
2889
|
+
})
|
|
2890
|
+
await store.createBuild({ slug: 'm-other', repo: 'merged/other' })
|
|
2891
|
+
clock.advance(1000)
|
|
2892
|
+
|
|
2893
|
+
await store.append('m-child', {
|
|
2894
|
+
actor: DISPATCHER,
|
|
2895
|
+
type: 'pr.opened',
|
|
2896
|
+
payload: { pr: pr(1) },
|
|
2897
|
+
})
|
|
2898
|
+
await store.append('m-child', {
|
|
2899
|
+
actor: KERNEL,
|
|
2900
|
+
type: 'finalize.completed',
|
|
2901
|
+
payload: { pr: pr(2) },
|
|
2902
|
+
})
|
|
2903
|
+
await store.append('m-open', {
|
|
2904
|
+
actor: DISPATCHER,
|
|
2905
|
+
type: 'pr.opened',
|
|
2906
|
+
payload: { pr: pr(9) },
|
|
2907
|
+
})
|
|
2908
|
+
// Merged in the reverse of creation order; m-tie shares m-leaf's instant.
|
|
2909
|
+
await complete(store, 'm-child', 'merged')
|
|
2910
|
+
const childMergedAt = clock().toISOString()
|
|
2911
|
+
clock.advance(10)
|
|
2912
|
+
await complete(store, 'm-tie', 'merged')
|
|
2913
|
+
await complete(store, 'm-leaf', 'merged')
|
|
2914
|
+
const leafMergedAt = clock().toISOString()
|
|
2915
|
+
clock.advance(10)
|
|
2916
|
+
await complete(store, 'm-closed', 'closed-unmerged')
|
|
2917
|
+
await complete(store, 'm-node', 'merged')
|
|
2918
|
+
await complete(store, 'm-other', 'merged')
|
|
2919
|
+
clock.advance(10)
|
|
2920
|
+
// Later writes move updatedAt but never the merge time.
|
|
2921
|
+
await store.append('m-child', sampleEventWrite('after the merge'))
|
|
2922
|
+
expect(await store.claimLease('m-leaf', 'runner', 60_000)).toBe(true)
|
|
2923
|
+
|
|
2924
|
+
const page = await store.listMergedBuildsPage(repo)
|
|
2925
|
+
expect(slugs(page)).toEqual(['m-node', 'm-tie', 'm-leaf', 'm-child'])
|
|
2926
|
+
expect(page.next).toBeNull()
|
|
2927
|
+
const bySlug = new Map(page.builds.map((build) => [build.record.slug, build]))
|
|
2928
|
+
const records = new Map(
|
|
2929
|
+
(await store.listBuildsForRepo(repo)).map((record) => [record.slug, record]),
|
|
2930
|
+
)
|
|
2931
|
+
for (const build of page.builds)
|
|
2932
|
+
expect(build.record).toEqual(records.get(build.record.slug)!)
|
|
2933
|
+
expect(bySlug.get('m-child')).toMatchObject({
|
|
2934
|
+
mergedAt: childMergedAt,
|
|
2935
|
+
kind: 'leaf',
|
|
2936
|
+
pr: { number: 2, url: 'https://forge.example/pr/2' },
|
|
2937
|
+
target: parent,
|
|
2938
|
+
})
|
|
2939
|
+
expect(bySlug.get('m-leaf')!.mergedAt).toBe(leafMergedAt)
|
|
2940
|
+
expect(bySlug.get('m-leaf')!.pr).toBeUndefined()
|
|
2941
|
+
expect(bySlug.get('m-leaf')!.target).toBeUndefined()
|
|
2942
|
+
expect(bySlug.get('m-node')!.kind).toBe('node')
|
|
2943
|
+
expect(await walk(store, repo, { limit: 1 })).toEqual(slugs(page))
|
|
2944
|
+
|
|
2945
|
+
// `since` is inclusive and `until` exclusive; bounds normalize.
|
|
2946
|
+
expect(await walk(store, repo, { since: leafMergedAt, limit: 1 })).toEqual([
|
|
2947
|
+
'm-node',
|
|
2948
|
+
'm-tie',
|
|
2949
|
+
'm-leaf',
|
|
2950
|
+
])
|
|
2951
|
+
expect(await walk(store, repo, { until: leafMergedAt, limit: 1 })).toEqual(['m-child'])
|
|
2952
|
+
const offset = new Date(Date.parse(leafMergedAt) + 3_600_000).toISOString()
|
|
2953
|
+
expect(
|
|
2954
|
+
await walk(store, repo, {
|
|
2955
|
+
since: childMergedAt,
|
|
2956
|
+
until: `${offset.slice(0, 23)}+01:00`,
|
|
2957
|
+
limit: 1,
|
|
2958
|
+
}),
|
|
2959
|
+
).toEqual(['m-child'])
|
|
2960
|
+
expect(
|
|
2961
|
+
slugs(
|
|
2962
|
+
await store.listMergedBuildsPage(repo, {
|
|
2963
|
+
since: leafMergedAt,
|
|
2964
|
+
until: leafMergedAt,
|
|
2965
|
+
}),
|
|
2966
|
+
),
|
|
2967
|
+
).toEqual([])
|
|
2968
|
+
})
|
|
2969
|
+
})
|
|
2970
|
+
|
|
2971
|
+
test('a reopen or a later unmerged completion removes a build, a re-merge moves it, and node targets follow parent acceptance', async () => {
|
|
2972
|
+
const clock = manualClock(CONTRACT_T0)
|
|
2973
|
+
await withStore(factory, { clock }, async (store) => {
|
|
2974
|
+
const repo = 'merged/moves'
|
|
2975
|
+
const old = { build: 'parent-a', ticket: ticket('parent-a') }
|
|
2976
|
+
const next = { build: 'parent-b', ticket: ticket('parent-b') }
|
|
2977
|
+
await store.createBuild({
|
|
2978
|
+
slug: 'mv-node',
|
|
2979
|
+
repo,
|
|
2980
|
+
created: created('mv-node', repo, { kind: 'node', target: old }),
|
|
2981
|
+
})
|
|
2982
|
+
await store.createBuild({
|
|
2983
|
+
slug: 'mv-leaf',
|
|
2984
|
+
repo,
|
|
2985
|
+
created: created('mv-leaf', repo, { target: old }),
|
|
2986
|
+
})
|
|
2987
|
+
await store.createBuild({
|
|
2988
|
+
slug: 'mv-gone',
|
|
2989
|
+
repo,
|
|
2990
|
+
created: created('mv-gone', repo),
|
|
2991
|
+
})
|
|
2992
|
+
const accept = (slug: string, from: typeof old | null, to: typeof old | null) =>
|
|
2993
|
+
store.append(slug, {
|
|
2994
|
+
actor: DISPATCHER,
|
|
2995
|
+
type: 'node.parent-accepted',
|
|
2996
|
+
payload: {
|
|
2997
|
+
id: `${slug}-${to?.build ?? 'root'}`,
|
|
2998
|
+
old: { target: from, branch: 'main' },
|
|
2999
|
+
next: { target: to, branch: 'main' },
|
|
3000
|
+
revision: 'r',
|
|
3001
|
+
},
|
|
3002
|
+
})
|
|
3003
|
+
clock.advance(1)
|
|
3004
|
+
await complete(store, 'mv-node', 'merged')
|
|
3005
|
+
clock.advance(1)
|
|
3006
|
+
await complete(store, 'mv-leaf', 'merged')
|
|
3007
|
+
clock.advance(1)
|
|
3008
|
+
await complete(store, 'mv-gone', 'merged')
|
|
3009
|
+
clock.advance(1)
|
|
3010
|
+
await store.append('mv-gone', {
|
|
3011
|
+
actor: humanActor('op'),
|
|
3012
|
+
type: 'build.reopened',
|
|
3013
|
+
payload: { feedback: 'again' },
|
|
3014
|
+
})
|
|
3015
|
+
expect(slugs(await store.listMergedBuildsPage(repo))).toEqual(['mv-leaf', 'mv-node'])
|
|
3016
|
+
|
|
3017
|
+
// A leaf ignores parent acceptance; a node takes `next.target`.
|
|
3018
|
+
await accept('mv-node', old, next)
|
|
3019
|
+
await accept('mv-leaf', old, next)
|
|
3020
|
+
let page = await store.listMergedBuildsPage(repo)
|
|
3021
|
+
expect(page.builds.map((build) => build.target)).toEqual([old, next])
|
|
3022
|
+
|
|
3023
|
+
await store.append('mv-node', {
|
|
3024
|
+
actor: humanActor('op'),
|
|
3025
|
+
type: 'build.reopened',
|
|
3026
|
+
payload: { feedback: 'again' },
|
|
3027
|
+
})
|
|
3028
|
+
await accept('mv-node', next, null)
|
|
3029
|
+
clock.advance(1)
|
|
3030
|
+
await complete(store, 'mv-node', 'merged')
|
|
3031
|
+
const remergedAt = clock().toISOString()
|
|
3032
|
+
await complete(store, 'mv-leaf', 'closed-unmerged')
|
|
3033
|
+
page = await store.listMergedBuildsPage(repo)
|
|
3034
|
+
expect(slugs(page)).toEqual(['mv-node'])
|
|
3035
|
+
expect(page.builds[0]!.mergedAt).toBe(remergedAt)
|
|
3036
|
+
expect(page.builds[0]!.target).toBeUndefined()
|
|
3037
|
+
})
|
|
3038
|
+
})
|
|
3039
|
+
|
|
3040
|
+
test('rejects an invalid window, a foreign cursor or an out-of-range limit', async () => {
|
|
3041
|
+
await withStore(factory, undefined, async (store) => {
|
|
3042
|
+
const repo = 'merged/reject'
|
|
3043
|
+
for (const slug of ['rj-a', 'rj-b']) {
|
|
3044
|
+
await store.createBuild({ slug, repo })
|
|
3045
|
+
await complete(store, slug, 'merged')
|
|
3046
|
+
}
|
|
3047
|
+
const merged = (await store.listMergedBuildsPage(repo, { limit: 1 })).next!
|
|
3048
|
+
const createdCursor = (await store.listBuildsPage(repo, { limit: 1 })).next!
|
|
3049
|
+
const updated = (
|
|
3050
|
+
await store.listBuildsPage(repo, {
|
|
3051
|
+
limit: 1,
|
|
3052
|
+
activeSince: CONTRACT_T0,
|
|
3053
|
+
})
|
|
3054
|
+
).next!
|
|
3055
|
+
await expect(store.listBuildsPage(repo, { cursor: merged })).rejects.toThrow(
|
|
3056
|
+
BuildFeedValidationError,
|
|
3057
|
+
)
|
|
3058
|
+
for (const opts of [
|
|
3059
|
+
{ limit: 0 },
|
|
3060
|
+
{ limit: 101 },
|
|
3061
|
+
{ cursor: 'not a cursor' },
|
|
3062
|
+
{ cursor: createdCursor },
|
|
3063
|
+
{ cursor: updated },
|
|
3064
|
+
{ since: 'yesterday' },
|
|
3065
|
+
{ until: '2026-11-24T00:00:00' },
|
|
3066
|
+
{ since: 1 },
|
|
3067
|
+
{ since: atT0(1), until: atT0(0) },
|
|
3068
|
+
])
|
|
3069
|
+
await expect(
|
|
3070
|
+
store.listMergedBuildsPage(
|
|
3071
|
+
repo,
|
|
3072
|
+
opts as import('./build-feed').MergedBuildPageOptions,
|
|
3073
|
+
),
|
|
3074
|
+
).rejects.toThrow(BuildFeedValidationError)
|
|
3075
|
+
})
|
|
3076
|
+
})
|
|
3077
|
+
})
|
|
3078
|
+
|
|
2580
3079
|
describe('getRepoHighWater', () => {
|
|
2581
3080
|
test('unknown repo rejects like getRepoEvents and creates nothing', async () => {
|
|
2582
3081
|
await withStore(factory, undefined, async (store) => {
|
|
@@ -2641,7 +3140,12 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
2641
3140
|
await store.append(slug, {
|
|
2642
3141
|
actor: KERNEL,
|
|
2643
3142
|
type: 'session.native-handle-recorded',
|
|
2644
|
-
payload: {
|
|
3143
|
+
payload: {
|
|
3144
|
+
session: 's_native',
|
|
3145
|
+
phase: 'implement',
|
|
3146
|
+
round: 1,
|
|
3147
|
+
handle,
|
|
3148
|
+
},
|
|
2645
3149
|
})
|
|
2646
3150
|
expect(
|
|
2647
3151
|
(await readBuildFacts(store, slug)).value.state.sessions.open[0]?.nativeHandle,
|
|
@@ -2748,7 +3252,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
2748
3252
|
})
|
|
2749
3253
|
expect(await readBuildSelector(store, slug, 'publishedBranchHead')).toBe(head)
|
|
2750
3254
|
expect(await readBuildSelector(store, slug, 'verifyDiffBase')).toBe(old)
|
|
2751
|
-
await store.append(slug, {
|
|
3255
|
+
await store.append(slug, {
|
|
3256
|
+
actor: KERNEL,
|
|
3257
|
+
type: 'restack.completed',
|
|
3258
|
+
payload: intent,
|
|
3259
|
+
})
|
|
2752
3260
|
expect(await readBuildSelector(store, slug, 'verifyDiffBase')).toBe(base)
|
|
2753
3261
|
const evidence = {
|
|
2754
3262
|
step: 'unit',
|
|
@@ -2757,7 +3265,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
2757
3265
|
headSha: head,
|
|
2758
3266
|
restackId: transaction.id,
|
|
2759
3267
|
}
|
|
2760
|
-
await store.append(slug, {
|
|
3268
|
+
await store.append(slug, {
|
|
3269
|
+
actor: KERNEL,
|
|
3270
|
+
type: 'verify.started',
|
|
3271
|
+
payload: evidence,
|
|
3272
|
+
})
|
|
2761
3273
|
await store.append(slug, {
|
|
2762
3274
|
actor: KERNEL,
|
|
2763
3275
|
type: 'verify.completed',
|
|
@@ -2772,7 +3284,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
2772
3284
|
headSha: head,
|
|
2773
3285
|
restackId: transaction.id,
|
|
2774
3286
|
})
|
|
2775
|
-
expect(facts.state.verify.results.at(-1)).toMatchObject({
|
|
3287
|
+
expect(facts.state.verify.results.at(-1)).toMatchObject({
|
|
3288
|
+
...evidence,
|
|
3289
|
+
outcome: 'pass',
|
|
3290
|
+
})
|
|
2776
3291
|
})
|
|
2777
3292
|
})
|
|
2778
3293
|
|
|
@@ -2830,7 +3345,12 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
2830
3345
|
await store.append(slug, {
|
|
2831
3346
|
actor: KERNEL,
|
|
2832
3347
|
type: 'reconcile.publish-intended',
|
|
2833
|
-
payload: {
|
|
3348
|
+
payload: {
|
|
3349
|
+
...transaction,
|
|
3350
|
+
headSha: head,
|
|
3351
|
+
conflicted: true,
|
|
3352
|
+
artifact,
|
|
3353
|
+
},
|
|
2834
3354
|
})
|
|
2835
3355
|
await store.append(slug, {
|
|
2836
3356
|
actor: KERNEL,
|
|
@@ -2864,7 +3384,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
2864
3384
|
const facts = (await readBuildFacts(store, slug)).value
|
|
2865
3385
|
expect(facts.gitTips).toContain(old)
|
|
2866
3386
|
expect(facts.gitTips).toContain(head)
|
|
2867
|
-
expect(facts.reconcileReplay).toEqual({
|
|
3387
|
+
expect(facts.reconcileReplay).toEqual({
|
|
3388
|
+
id: transaction.id,
|
|
3389
|
+
conflicted: true,
|
|
3390
|
+
})
|
|
2868
3391
|
})
|
|
2869
3392
|
},
|
|
2870
3393
|
)
|
|
@@ -2920,7 +3443,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
2920
3443
|
const events = scope.kind === 'repo' ? repoEvents : buildEvents
|
|
2921
3444
|
const expected = JSON.parse(JSON.stringify(resolved.reducer.reduce(events)))
|
|
2922
3445
|
const answer = await store.getReducerValue(scope, request)
|
|
2923
|
-
const canonical = {
|
|
3446
|
+
const canonical = {
|
|
3447
|
+
version: resolved.reducer.version,
|
|
3448
|
+
value: expected,
|
|
3449
|
+
}
|
|
2924
3450
|
// A remote server answers this source client, whose value contract
|
|
2925
3451
|
// matches the current package release, in that release's versions,
|
|
2926
3452
|
// so a fold revision made since the release reads as the published one.
|
|
@@ -2956,7 +3482,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
2956
3482
|
store.putReducerSnapshot(scope, resolved.key, {
|
|
2957
3483
|
version: resolved.reducer.version,
|
|
2958
3484
|
cursor: 1,
|
|
2959
|
-
state: {
|
|
3485
|
+
state: {
|
|
3486
|
+
identity: resolved.identity,
|
|
3487
|
+
acc: resolved.reducer.initial(),
|
|
3488
|
+
},
|
|
2960
3489
|
}),
|
|
2961
3490
|
).rejects.toThrow('reserved')
|
|
2962
3491
|
await expect(
|
|
@@ -3058,7 +3587,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
3058
3587
|
type: 'dispatcher.intake-set',
|
|
3059
3588
|
payload: { enabled: false },
|
|
3060
3589
|
})
|
|
3061
|
-
const state = {
|
|
3590
|
+
const state = {
|
|
3591
|
+
counts: { a: 1 },
|
|
3592
|
+
list: [1, 'two', null],
|
|
3593
|
+
flag: true,
|
|
3594
|
+
}
|
|
3062
3595
|
expect(
|
|
3063
3596
|
await store.putReducerSnapshot(buildScope('snap-rt'), 'build', {
|
|
3064
3597
|
version: 2,
|
|
@@ -3100,27 +3633,47 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
3100
3633
|
await withStore(factory, undefined, async (store) => {
|
|
3101
3634
|
await buildWithEvents(store, 'snap-ver', 5)
|
|
3102
3635
|
const scope = buildScope('snap-ver')
|
|
3103
|
-
await store.putReducerSnapshot(scope, 'build', {
|
|
3636
|
+
await store.putReducerSnapshot(scope, 'build', {
|
|
3637
|
+
version: 1,
|
|
3638
|
+
cursor: 3,
|
|
3639
|
+
state: 'v1',
|
|
3640
|
+
})
|
|
3104
3641
|
expect(await store.getReducerSnapshot(scope, 'build', 2)).toBeNull()
|
|
3105
3642
|
// Same cursor, lower version: no-op.
|
|
3106
3643
|
expect(
|
|
3107
|
-
await store.putReducerSnapshot(scope, 'build', {
|
|
3644
|
+
await store.putReducerSnapshot(scope, 'build', {
|
|
3645
|
+
version: 1,
|
|
3646
|
+
cursor: 3,
|
|
3647
|
+
state: 'x',
|
|
3648
|
+
}),
|
|
3108
3649
|
).toBe(false)
|
|
3109
3650
|
// Higher version at an unchanged cursor replaces the old shape.
|
|
3110
3651
|
expect(
|
|
3111
|
-
await store.putReducerSnapshot(scope, 'build', {
|
|
3652
|
+
await store.putReducerSnapshot(scope, 'build', {
|
|
3653
|
+
version: 2,
|
|
3654
|
+
cursor: 3,
|
|
3655
|
+
state: 'v2',
|
|
3656
|
+
}),
|
|
3112
3657
|
).toBe(true)
|
|
3113
3658
|
expect(await store.getReducerSnapshot(scope, 'build', 1)).toBeNull()
|
|
3114
3659
|
expect((await store.getReducerSnapshot(scope, 'build', 2))?.state).toBe('v2')
|
|
3115
3660
|
// A lower version cannot replace a newer cache, even at a later cursor.
|
|
3116
3661
|
expect(
|
|
3117
|
-
await store.putReducerSnapshot(scope, 'build', {
|
|
3662
|
+
await store.putReducerSnapshot(scope, 'build', {
|
|
3663
|
+
version: 1,
|
|
3664
|
+
cursor: 4,
|
|
3665
|
+
state: 'v1b',
|
|
3666
|
+
}),
|
|
3118
3667
|
).toBe(false)
|
|
3119
3668
|
expect((await store.getReducerSnapshot(scope, 'build', 2))?.state).toBe('v2')
|
|
3120
3669
|
expect(await store.getReducerSnapshot(scope, 'build', 1)).toBeNull()
|
|
3121
3670
|
// But never at a lower cursor, whatever its version.
|
|
3122
3671
|
expect(
|
|
3123
|
-
await store.putReducerSnapshot(scope, 'build', {
|
|
3672
|
+
await store.putReducerSnapshot(scope, 'build', {
|
|
3673
|
+
version: 9,
|
|
3674
|
+
cursor: 2,
|
|
3675
|
+
state: 'old',
|
|
3676
|
+
}),
|
|
3124
3677
|
).toBe(false)
|
|
3125
3678
|
expect((await store.getReducerSnapshot(scope, 'build', 2))?.state).toBe('v2')
|
|
3126
3679
|
})
|
|
@@ -3131,13 +3684,25 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
3131
3684
|
await buildWithEvents(store, 'snap-mono', 4)
|
|
3132
3685
|
const scope = buildScope('snap-mono')
|
|
3133
3686
|
expect(
|
|
3134
|
-
await store.putReducerSnapshot(scope, 'build', {
|
|
3687
|
+
await store.putReducerSnapshot(scope, 'build', {
|
|
3688
|
+
version: 1,
|
|
3689
|
+
cursor: 3,
|
|
3690
|
+
state: 'a',
|
|
3691
|
+
}),
|
|
3135
3692
|
).toBe(true)
|
|
3136
3693
|
expect(
|
|
3137
|
-
await store.putReducerSnapshot(scope, 'build', {
|
|
3694
|
+
await store.putReducerSnapshot(scope, 'build', {
|
|
3695
|
+
version: 1,
|
|
3696
|
+
cursor: 3,
|
|
3697
|
+
state: 'b',
|
|
3698
|
+
}),
|
|
3138
3699
|
).toBe(false)
|
|
3139
3700
|
expect(
|
|
3140
|
-
await store.putReducerSnapshot(scope, 'build', {
|
|
3701
|
+
await store.putReducerSnapshot(scope, 'build', {
|
|
3702
|
+
version: 1,
|
|
3703
|
+
cursor: 2,
|
|
3704
|
+
state: 'c',
|
|
3705
|
+
}),
|
|
3141
3706
|
).toBe(false)
|
|
3142
3707
|
expect(await store.getReducerSnapshot(scope, 'build', 1)).toEqual({
|
|
3143
3708
|
version: 1,
|
|
@@ -3145,7 +3710,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
3145
3710
|
state: 'a',
|
|
3146
3711
|
})
|
|
3147
3712
|
expect(
|
|
3148
|
-
await store.putReducerSnapshot(scope, 'build', {
|
|
3713
|
+
await store.putReducerSnapshot(scope, 'build', {
|
|
3714
|
+
version: 1,
|
|
3715
|
+
cursor: 4,
|
|
3716
|
+
state: 'd',
|
|
3717
|
+
}),
|
|
3149
3718
|
).toBe(true)
|
|
3150
3719
|
})
|
|
3151
3720
|
})
|
|
@@ -3155,12 +3724,20 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
3155
3724
|
await buildWithEvents(store, 'snap-ahead', 2)
|
|
3156
3725
|
const scope = buildScope('snap-ahead')
|
|
3157
3726
|
expect(
|
|
3158
|
-
await store.putReducerSnapshot(scope, 'build', {
|
|
3727
|
+
await store.putReducerSnapshot(scope, 'build', {
|
|
3728
|
+
version: 1,
|
|
3729
|
+
cursor: 3,
|
|
3730
|
+
state: 'x',
|
|
3731
|
+
}),
|
|
3159
3732
|
).toBe(false)
|
|
3160
3733
|
expect(await store.getReducerSnapshot(scope, 'build', 1)).toBeNull()
|
|
3161
3734
|
// Within the tail it is accepted, and stays readable as the log grows.
|
|
3162
3735
|
expect(
|
|
3163
|
-
await store.putReducerSnapshot(scope, 'build', {
|
|
3736
|
+
await store.putReducerSnapshot(scope, 'build', {
|
|
3737
|
+
version: 1,
|
|
3738
|
+
cursor: 2,
|
|
3739
|
+
state: 'ok',
|
|
3740
|
+
}),
|
|
3164
3741
|
).toBe(true)
|
|
3165
3742
|
await store.append('snap-ahead', sampleEventWrite('more'))
|
|
3166
3743
|
expect((await store.getReducerSnapshot(scope, 'build', 1))?.cursor).toBe(2)
|
|
@@ -3216,12 +3793,19 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
3216
3793
|
)
|
|
3217
3794
|
await Promise.all(
|
|
3218
3795
|
writes.map((write) =>
|
|
3219
|
-
store.putReducerSnapshot(scope, 'build', {
|
|
3796
|
+
store.putReducerSnapshot(scope, 'build', {
|
|
3797
|
+
...write,
|
|
3798
|
+
state: write,
|
|
3799
|
+
}),
|
|
3220
3800
|
),
|
|
3221
3801
|
)
|
|
3222
3802
|
// The cursor is the max; at that cursor the highest version won.
|
|
3223
3803
|
const final = await store.getReducerSnapshot(scope, 'build', 3)
|
|
3224
|
-
expect(final).toEqual({
|
|
3804
|
+
expect(final).toEqual({
|
|
3805
|
+
version: 3,
|
|
3806
|
+
cursor: tail,
|
|
3807
|
+
state: { version: 3, cursor: tail },
|
|
3808
|
+
})
|
|
3225
3809
|
})
|
|
3226
3810
|
})
|
|
3227
3811
|
})
|
|
@@ -3241,7 +3825,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
3241
3825
|
roleWarnings: [],
|
|
3242
3826
|
},
|
|
3243
3827
|
},
|
|
3244
|
-
{
|
|
3828
|
+
{
|
|
3829
|
+
actor: DISPATCHER,
|
|
3830
|
+
type: 'dispatcher.tick-started',
|
|
3831
|
+
payload: { run },
|
|
3832
|
+
},
|
|
3245
3833
|
{
|
|
3246
3834
|
actor: DISPATCHER,
|
|
3247
3835
|
type: 'dispatcher.tick-completed',
|
|
@@ -3270,7 +3858,12 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
3270
3858
|
await store.appendRepo(repo, {
|
|
3271
3859
|
actor: DISPATCHER,
|
|
3272
3860
|
type: 'ticket-preparation.intended',
|
|
3273
|
-
payload: {
|
|
3861
|
+
payload: {
|
|
3862
|
+
attempt: 'prep',
|
|
3863
|
+
ticket,
|
|
3864
|
+
readyState: 'Ready',
|
|
3865
|
+
claimedState: 'Doing',
|
|
3866
|
+
},
|
|
3274
3867
|
})
|
|
3275
3868
|
await store.appendRepo(repo, {
|
|
3276
3869
|
actor: DISPATCHER,
|
|
@@ -3348,7 +3941,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
3348
3941
|
await store.appendRepo(repo, {
|
|
3349
3942
|
actor: DISPATCHER,
|
|
3350
3943
|
type: 'dispatcher.ticket-source-recovered',
|
|
3351
|
-
payload: {
|
|
3944
|
+
payload: {
|
|
3945
|
+
source: 'fake',
|
|
3946
|
+
cause: 'rate-limited',
|
|
3947
|
+
operation: 'dependency-check',
|
|
3948
|
+
},
|
|
3352
3949
|
})
|
|
3353
3950
|
expect(
|
|
3354
3951
|
(await store.getRepoStateEvents(repo)).filter((event) =>
|
|
@@ -3429,7 +4026,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
3429
4026
|
await store.appendRepo(repo, {
|
|
3430
4027
|
actor: DISPATCHER,
|
|
3431
4028
|
type: 'dispatcher.upgrade-failed',
|
|
3432
|
-
payload: {
|
|
4029
|
+
payload: {
|
|
4030
|
+
...identity,
|
|
4031
|
+
run: 'foreign',
|
|
4032
|
+
reason: 'registry unavailable',
|
|
4033
|
+
},
|
|
3433
4034
|
})
|
|
3434
4035
|
await store.appendRepo(repo, {
|
|
3435
4036
|
actor: DISPATCHER,
|
|
@@ -3437,7 +4038,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
3437
4038
|
payload: {
|
|
3438
4039
|
run: 'foreign',
|
|
3439
4040
|
lineage: identity.lineage,
|
|
3440
|
-
target: {
|
|
4041
|
+
target: {
|
|
4042
|
+
...identity.target,
|
|
4043
|
+
mode: 'source',
|
|
4044
|
+
sha: 'b'.repeat(40),
|
|
4045
|
+
},
|
|
3441
4046
|
},
|
|
3442
4047
|
})
|
|
3443
4048
|
const first = (await readRepositoryFacts(store, repo)).value.upgrades
|
|
@@ -3574,12 +4179,24 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
3574
4179
|
await withStore(factory, undefined, async (store) => {
|
|
3575
4180
|
await store.ensureRepo('acme/no-anchor')
|
|
3576
4181
|
for (const write of [
|
|
3577
|
-
{
|
|
3578
|
-
|
|
4182
|
+
{
|
|
4183
|
+
actor: humanActor('op'),
|
|
4184
|
+
type: 'dispatcher.intake-set',
|
|
4185
|
+
payload: { enabled: false },
|
|
4186
|
+
},
|
|
4187
|
+
{
|
|
4188
|
+
actor: KERNEL,
|
|
4189
|
+
type: 'harvest.started',
|
|
4190
|
+
payload: harvestStartedWrite('h1').payload,
|
|
4191
|
+
},
|
|
3579
4192
|
// Run-scoped fact with no anchor anywhere in the journal: if the
|
|
3580
4193
|
// read degenerated into a whole-journal select, this would leak
|
|
3581
4194
|
// into the result.
|
|
3582
|
-
{
|
|
4195
|
+
{
|
|
4196
|
+
actor: DISPATCHER,
|
|
4197
|
+
type: 'dispatcher.tick-started',
|
|
4198
|
+
payload: { run: 'r1' },
|
|
4199
|
+
},
|
|
3583
4200
|
] as RepositoryEventWrite[]) {
|
|
3584
4201
|
await store.appendRepo('acme/no-anchor', write)
|
|
3585
4202
|
}
|
|
@@ -3596,12 +4213,25 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
3596
4213
|
await store.ensureRepo('acme/state')
|
|
3597
4214
|
for (const write of [
|
|
3598
4215
|
...noopInvocation('r1'),
|
|
3599
|
-
{
|
|
3600
|
-
|
|
4216
|
+
{
|
|
4217
|
+
actor: humanActor('op'),
|
|
4218
|
+
type: 'dispatcher.intake-set',
|
|
4219
|
+
payload: { enabled: false },
|
|
4220
|
+
},
|
|
4221
|
+
{
|
|
4222
|
+
actor: KERNEL,
|
|
4223
|
+
type: 'harvest.started',
|
|
4224
|
+
payload: harvestStartedWrite('h1').payload,
|
|
4225
|
+
},
|
|
3601
4226
|
{
|
|
3602
4227
|
actor: humanActor('op'),
|
|
3603
4228
|
type: 'orchestrator.sandbox.provisioned',
|
|
3604
|
-
payload: {
|
|
4229
|
+
payload: {
|
|
4230
|
+
operator: 'op',
|
|
4231
|
+
environmentId: 'env',
|
|
4232
|
+
provider: 'p',
|
|
4233
|
+
workspacePath: '/w',
|
|
4234
|
+
},
|
|
3605
4235
|
},
|
|
3606
4236
|
...noopInvocation('r2'),
|
|
3607
4237
|
{
|
|
@@ -3665,7 +4295,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
3665
4295
|
const sha = 'c'.repeat(40),
|
|
3666
4296
|
from = 'b'.repeat(40)
|
|
3667
4297
|
const lineage = [
|
|
3668
|
-
{
|
|
4298
|
+
{
|
|
4299
|
+
node: 'parent',
|
|
4300
|
+
from,
|
|
4301
|
+
receipts: [{ id: 'tx', previous: from, head: sha }],
|
|
4302
|
+
},
|
|
3669
4303
|
]
|
|
3670
4304
|
await store.append(slug, {
|
|
3671
4305
|
actor: KERNEL,
|
|
@@ -3695,7 +4329,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
3695
4329
|
await store.createBuild(sampleBuildInput(slug))
|
|
3696
4330
|
const previous = 'a'.repeat(40)
|
|
3697
4331
|
const receipt = { id: 'tx', previous, head: 'b'.repeat(40) }
|
|
3698
|
-
const write = {
|
|
4332
|
+
const write = {
|
|
4333
|
+
actor: KERNEL,
|
|
4334
|
+
type: 'node.rewritten',
|
|
4335
|
+
payload: receipt,
|
|
4336
|
+
} as const
|
|
3699
4337
|
expect(await store.getNodeRewrite(slug, previous)).toBeNull()
|
|
3700
4338
|
await store.append(slug, write)
|
|
3701
4339
|
expect(await store.getNodeRewrite(slug, previous)).toEqual(receipt)
|
|
@@ -3719,7 +4357,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
3719
4357
|
copy!.id = 'mutated'
|
|
3720
4358
|
expect((await store.getNodeRewrite(slug, previous))?.id).toBe('tx-4')
|
|
3721
4359
|
expect((await store.getNodeRewrite(slug, undefined, previous))?.id).toBe('tx-3')
|
|
3722
|
-
const later = {
|
|
4360
|
+
const later = {
|
|
4361
|
+
id: 'tx-5',
|
|
4362
|
+
previous: 'c'.repeat(40),
|
|
4363
|
+
head: 'd'.repeat(40),
|
|
4364
|
+
}
|
|
3723
4365
|
await store.append(slug, { ...write, payload: later })
|
|
3724
4366
|
expect(await store.getNodeRewrite(slug, undefined, later.previous)).toEqual({
|
|
3725
4367
|
...receipt,
|
|
@@ -3749,7 +4391,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
3749
4391
|
await store.createBuild(sampleBuildInput('envelope'))
|
|
3750
4392
|
const envelope = await store.append('envelope', buildCreatedWrite())
|
|
3751
4393
|
expect(envelope).toEqual({
|
|
3752
|
-
compatibility: {
|
|
4394
|
+
compatibility: {
|
|
4395
|
+
writerVersion: AUTOBUILD_VERSION,
|
|
4396
|
+
classification: 'decisive',
|
|
4397
|
+
},
|
|
3753
4398
|
build: 'envelope',
|
|
3754
4399
|
seq: 1,
|
|
3755
4400
|
ts: CONTRACT_T0,
|
|
@@ -3974,7 +4619,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
3974
4619
|
sha: 'landed',
|
|
3975
4620
|
...(evidence === undefined ? {} : { buildTrailerPresent: evidence }),
|
|
3976
4621
|
}
|
|
3977
|
-
await store.append(slug, {
|
|
4622
|
+
await store.append(slug, {
|
|
4623
|
+
actor: DISPATCHER,
|
|
4624
|
+
type: 'pr.merged',
|
|
4625
|
+
payload,
|
|
4626
|
+
})
|
|
3978
4627
|
const events = await store.getEvents(slug)
|
|
3979
4628
|
expect(events.at(-1)?.payload).toEqual(payload)
|
|
3980
4629
|
const historical = events.map((event) =>
|
|
@@ -4010,7 +4659,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
4010
4659
|
await withStore(factory, undefined, async (store) => {
|
|
4011
4660
|
await store.createBuild(sampleBuildInput('val-dispatcher-answer'))
|
|
4012
4661
|
for (const payload of [
|
|
4013
|
-
{
|
|
4662
|
+
{
|
|
4663
|
+
id: 'esc_1',
|
|
4664
|
+
answer: 'continue',
|
|
4665
|
+
resolution: 'guidance' as const,
|
|
4666
|
+
},
|
|
4014
4667
|
{ id: 'esc_1', answer: 'retry', resolution: 'retry' as const },
|
|
4015
4668
|
]) {
|
|
4016
4669
|
const err = await store
|
|
@@ -4129,7 +4782,9 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
4129
4782
|
test('an append during the wait returns early carrying that event', async () => {
|
|
4130
4783
|
await withStore(factory, undefined, async (store) => {
|
|
4131
4784
|
await store.createBuild(sampleBuildInput('evt-wait-wake'))
|
|
4132
|
-
const pending = store.getEvents('evt-wait-wake', 0, {
|
|
4785
|
+
const pending = store.getEvents('evt-wait-wake', 0, {
|
|
4786
|
+
waitSeconds: 5,
|
|
4787
|
+
})
|
|
4133
4788
|
await Bun.sleep(100)
|
|
4134
4789
|
const event = await store.append('evt-wait-wake', sampleEventWrite('wake'))
|
|
4135
4790
|
expect(await pending).toEqual([event])
|
|
@@ -4140,16 +4795,20 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
4140
4795
|
await withStore(factory, undefined, async (store) => {
|
|
4141
4796
|
await store.ensureRepo('acme/evt-wait')
|
|
4142
4797
|
const started = Date.now()
|
|
4143
|
-
const pending = store.getRepoEvents('acme/evt-wait', 0, {
|
|
4798
|
+
const pending = store.getRepoEvents('acme/evt-wait', 0, {
|
|
4799
|
+
waitSeconds: 5,
|
|
4800
|
+
})
|
|
4144
4801
|
await Bun.sleep(100)
|
|
4145
4802
|
const event = await store.appendRepo('acme/evt-wait', harvestStartedWrite('h_wait'))
|
|
4146
4803
|
expect(await pending).toEqual([event])
|
|
4147
4804
|
// Events past since still answer immediately.
|
|
4148
4805
|
expect(Date.now() - started).toBeLessThan(5_000)
|
|
4149
4806
|
const immediateStart = Date.now()
|
|
4150
|
-
expect(
|
|
4151
|
-
|
|
4152
|
-
|
|
4807
|
+
expect(
|
|
4808
|
+
await store.getRepoEvents('acme/evt-wait', event.seq, {
|
|
4809
|
+
waitSeconds: 1,
|
|
4810
|
+
}),
|
|
4811
|
+
).toEqual([])
|
|
4153
4812
|
// Nothing newer exists, so this is a held read answered at the
|
|
4154
4813
|
// bound — the symmetric quiet-stream assertion.
|
|
4155
4814
|
expect(Date.now() - immediateStart).toBeGreaterThanOrEqual(950)
|
|
@@ -4166,16 +4825,25 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
4166
4825
|
await withStore(factory, undefined, async (store) => {
|
|
4167
4826
|
await store.createBuild(sampleBuildInput('abort-pre'))
|
|
4168
4827
|
await store.ensureRepo('acme/abort-pre')
|
|
4169
|
-
const session = await store.createSession({
|
|
4828
|
+
const session = await store.createSession({
|
|
4829
|
+
repo: 'acme/abort-pre',
|
|
4830
|
+
operator: 'op',
|
|
4831
|
+
})
|
|
4170
4832
|
const stream = await store.createStream({ kind: 'build', build: 'abort-pre' }, 's')
|
|
4171
4833
|
const controller = new AbortController()
|
|
4172
4834
|
controller.abort()
|
|
4173
4835
|
const started = Date.now()
|
|
4174
4836
|
await expect(
|
|
4175
|
-
store.getEvents('abort-pre', 0, {
|
|
4837
|
+
store.getEvents('abort-pre', 0, {
|
|
4838
|
+
waitSeconds: 5,
|
|
4839
|
+
signal: controller.signal,
|
|
4840
|
+
}),
|
|
4176
4841
|
).resolves.toEqual([])
|
|
4177
4842
|
await expect(
|
|
4178
|
-
store.getRepoEvents('acme/abort-pre', 0, {
|
|
4843
|
+
store.getRepoEvents('acme/abort-pre', 0, {
|
|
4844
|
+
waitSeconds: 5,
|
|
4845
|
+
signal: controller.signal,
|
|
4846
|
+
}),
|
|
4179
4847
|
).resolves.toEqual([])
|
|
4180
4848
|
await expect(
|
|
4181
4849
|
store.getSessionEvents(session.id, 1, {
|
|
@@ -4198,7 +4866,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
4198
4866
|
test('a mid-hold abort on a quiet session read resolves empty well under the bound', async () => {
|
|
4199
4867
|
await withStore(factory, undefined, async (store) => {
|
|
4200
4868
|
await store.ensureRepo('acme/abort-mid')
|
|
4201
|
-
const session = await store.createSession({
|
|
4869
|
+
const session = await store.createSession({
|
|
4870
|
+
repo: 'acme/abort-mid',
|
|
4871
|
+
operator: 'op',
|
|
4872
|
+
})
|
|
4202
4873
|
const controller = new AbortController()
|
|
4203
4874
|
// since=1: the session's own creation event is backlog; the hold
|
|
4204
4875
|
// must establish past it or there is nothing held to abort.
|
|
@@ -4243,9 +4914,18 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
4243
4914
|
test('revisions are 0-based per kind (§6.3): first deposit rev 0, next rev 1', async () => {
|
|
4244
4915
|
await withStore(factory, undefined, async (store) => {
|
|
4245
4916
|
await store.createBuild(sampleBuildInput('revs'))
|
|
4246
|
-
const p0 = await store.putArtifact('revs', {
|
|
4247
|
-
|
|
4248
|
-
|
|
4917
|
+
const p0 = await store.putArtifact('revs', {
|
|
4918
|
+
kind: 'plan',
|
|
4919
|
+
content: 'plan v0',
|
|
4920
|
+
})
|
|
4921
|
+
const p1 = await store.putArtifact('revs', {
|
|
4922
|
+
kind: 'plan',
|
|
4923
|
+
content: 'plan v1',
|
|
4924
|
+
})
|
|
4925
|
+
const s0 = await store.putArtifact('revs', {
|
|
4926
|
+
kind: 'spec',
|
|
4927
|
+
content: 'spec v0',
|
|
4928
|
+
})
|
|
4249
4929
|
expect(p0.revision).toBe(0)
|
|
4250
4930
|
expect(p1.revision).toBe(1)
|
|
4251
4931
|
expect(s0.revision).toBe(0)
|
|
@@ -4255,8 +4935,14 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
4255
4935
|
test('same content twice yields the same blobRef (content-addressed, §7.1) but distinct revisions', async () => {
|
|
4256
4936
|
await withStore(factory, undefined, async (store) => {
|
|
4257
4937
|
await store.createBuild(sampleBuildInput('dedupe'))
|
|
4258
|
-
const a = await store.putArtifact('dedupe', {
|
|
4259
|
-
|
|
4938
|
+
const a = await store.putArtifact('dedupe', {
|
|
4939
|
+
kind: 'plan',
|
|
4940
|
+
content: 'identical',
|
|
4941
|
+
})
|
|
4942
|
+
const b = await store.putArtifact('dedupe', {
|
|
4943
|
+
kind: 'plan',
|
|
4944
|
+
content: 'identical',
|
|
4945
|
+
})
|
|
4260
4946
|
expect(a.blobRef).toBe(contentHash(toBytes('identical')))
|
|
4261
4947
|
expect(b.blobRef).toBe(a.blobRef)
|
|
4262
4948
|
expect([a.revision, b.revision]).toEqual([0, 1])
|
|
@@ -4267,7 +4953,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
4267
4953
|
await withStore(factory, undefined, async (store) => {
|
|
4268
4954
|
await store.createBuild(sampleBuildInput('meta'))
|
|
4269
4955
|
const metadata = { phase: 'plan', round: 2, tags: ['a', 'b'] }
|
|
4270
|
-
await store.putArtifact('meta', {
|
|
4956
|
+
await store.putArtifact('meta', {
|
|
4957
|
+
kind: 'plan',
|
|
4958
|
+
content: 'p',
|
|
4959
|
+
metadata,
|
|
4960
|
+
})
|
|
4271
4961
|
const artifact = await store.getArtifact('meta', 'plan')
|
|
4272
4962
|
expect(artifact?.meta.metadata).toEqual(metadata)
|
|
4273
4963
|
})
|
|
@@ -4325,7 +5015,12 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
4325
5015
|
for (const run of ['run-0', 'run-1', 'run-2']) {
|
|
4326
5016
|
const { artifacts } = await store.appendRepoWithArtifacts(
|
|
4327
5017
|
'acme/retention',
|
|
4328
|
-
[
|
|
5018
|
+
[
|
|
5019
|
+
{
|
|
5020
|
+
kind: 'dispatcher-effective-config',
|
|
5021
|
+
content: `cfg-${run}`,
|
|
5022
|
+
},
|
|
5023
|
+
],
|
|
4329
5024
|
(deposited) => runStartedWrite(run, deposited),
|
|
4330
5025
|
)
|
|
4331
5026
|
expect(artifacts.map((a) => a.revision)).toEqual([Number(run.slice(-1))])
|
|
@@ -4689,7 +5384,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
4689
5384
|
test('failure: an invalid event rolls back the whole deposit and propagates the error', async () => {
|
|
4690
5385
|
await withStore(factory, undefined, async (store) => {
|
|
4691
5386
|
await store.createBuild(sampleBuildInput('rollback'))
|
|
4692
|
-
await store.putArtifact('rollback', {
|
|
5387
|
+
await store.putArtifact('rollback', {
|
|
5388
|
+
kind: 'plan',
|
|
5389
|
+
content: 'original plan',
|
|
5390
|
+
})
|
|
4693
5391
|
await store.append('rollback', sampleEventWrite('pre-existing'))
|
|
4694
5392
|
|
|
4695
5393
|
const err = await store
|
|
@@ -4914,7 +5612,12 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
4914
5612
|
size: 6,
|
|
4915
5613
|
})
|
|
4916
5614
|
expect(meta.entries).toEqual([
|
|
4917
|
-
{
|
|
5615
|
+
{
|
|
5616
|
+
type: 'file',
|
|
5617
|
+
path: 'shot.png',
|
|
5618
|
+
size: 6,
|
|
5619
|
+
blobRef: contentHash(binary),
|
|
5620
|
+
},
|
|
4918
5621
|
])
|
|
4919
5622
|
const got = await store.getTicketAsset(REPO, 'T-1', 'design', 'shot.png')
|
|
4920
5623
|
expect(got?.meta).toEqual(meta)
|
|
@@ -4937,8 +5640,16 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
4937
5640
|
treeAsset(
|
|
4938
5641
|
'site',
|
|
4939
5642
|
[
|
|
4940
|
-
{
|
|
4941
|
-
|
|
5643
|
+
{
|
|
5644
|
+
type: 'file',
|
|
5645
|
+
path: 'index.html',
|
|
5646
|
+
content: enc('<h1>hi</h1>'),
|
|
5647
|
+
},
|
|
5648
|
+
{
|
|
5649
|
+
type: 'file',
|
|
5650
|
+
path: 'img/a.png',
|
|
5651
|
+
content: Uint8Array.from([1, 2, 3]),
|
|
5652
|
+
},
|
|
4942
5653
|
],
|
|
4943
5654
|
[{ type: 'dir', path: 'img/empty' }],
|
|
4944
5655
|
),
|
|
@@ -4954,11 +5665,19 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
4954
5665
|
])
|
|
4955
5666
|
expect(site?.entries).toEqual([
|
|
4956
5667
|
{ type: 'file', path: 'index.html', content: enc('<h1>hi</h1>') },
|
|
4957
|
-
{
|
|
5668
|
+
{
|
|
5669
|
+
type: 'file',
|
|
5670
|
+
path: 'img/a.png',
|
|
5671
|
+
content: Uint8Array.from([1, 2, 3]),
|
|
5672
|
+
},
|
|
4958
5673
|
{ type: 'dir', path: 'img/empty' },
|
|
4959
5674
|
])
|
|
4960
5675
|
const hollow = await store.getTicketAsset(REPO, 'T-1', 'design', 'hollow')
|
|
4961
|
-
expect(hollow?.meta).toMatchObject({
|
|
5676
|
+
expect(hollow?.meta).toMatchObject({
|
|
5677
|
+
layout: 'tree',
|
|
5678
|
+
size: 0,
|
|
5679
|
+
entries: [],
|
|
5680
|
+
})
|
|
4962
5681
|
expect(hollow?.entries).toEqual([])
|
|
4963
5682
|
|
|
4964
5683
|
const list = await store.listTicketAssets(REPO, 'T-1')
|
|
@@ -4987,7 +5706,9 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
4987
5706
|
|
|
4988
5707
|
const current = await store.listTicketAssets(REPO, 'T-1')
|
|
4989
5708
|
expect(current.map((a) => [a.name, a.revision, a.size])).toEqual([['a', 1, 4]])
|
|
4990
|
-
const all = await store.listTicketAssets(REPO, 'T-1', {
|
|
5709
|
+
const all = await store.listTicketAssets(REPO, 'T-1', {
|
|
5710
|
+
revisions: true,
|
|
5711
|
+
})
|
|
4991
5712
|
expect(all.map((a) => a.revision)).toEqual([0, 1])
|
|
4992
5713
|
})
|
|
4993
5714
|
})
|
|
@@ -5018,13 +5739,19 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
5018
5739
|
await store.putTicketAsset(REPO, 'T-1', fileAsset('a', enc('one')))
|
|
5019
5740
|
await store.putTicketAsset(REPO, 'T-1', fileAsset('a', enc('two')))
|
|
5020
5741
|
const removed = await store.removeTicketAsset(REPO, 'T-1', 'design', 'a')
|
|
5021
|
-
expect(removed).toMatchObject({
|
|
5742
|
+
expect(removed).toMatchObject({
|
|
5743
|
+
kind: 'design',
|
|
5744
|
+
name: 'a',
|
|
5745
|
+
revision: 1,
|
|
5746
|
+
})
|
|
5022
5747
|
expect(await store.getTicketAsset(REPO, 'T-1', 'design', 'a')).toBeNull()
|
|
5023
5748
|
expect(await store.listTicketAssets(REPO, 'T-1')).toEqual([])
|
|
5024
5749
|
const pinned = await store.getTicketAsset(REPO, 'T-1', 'design', 'a', 0)
|
|
5025
5750
|
expect(pinned?.entries[0]).toMatchObject({ content: enc('one') })
|
|
5026
5751
|
const pinnedLatest = await store.getTicketAsset(REPO, 'T-1', 'design', 'a', 1)
|
|
5027
|
-
expect(pinnedLatest?.entries[0]).toMatchObject({
|
|
5752
|
+
expect(pinnedLatest?.entries[0]).toMatchObject({
|
|
5753
|
+
content: enc('two'),
|
|
5754
|
+
})
|
|
5028
5755
|
// Tombstones are not revisions to list.
|
|
5029
5756
|
expect(
|
|
5030
5757
|
(await store.listTicketAssets(REPO, 'T-1', { revisions: true })).map((a) => a.revision),
|
|
@@ -5090,7 +5817,12 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
5090
5817
|
['a/xy', 2],
|
|
5091
5818
|
['c/x', 0],
|
|
5092
5819
|
])
|
|
5093
|
-
expect(current[2]).toMatchObject({
|
|
5820
|
+
expect(current[2]).toMatchObject({
|
|
5821
|
+
layout: 'tree',
|
|
5822
|
+
fileCount: 1,
|
|
5823
|
+
dirCount: 1,
|
|
5824
|
+
size: 3,
|
|
5825
|
+
})
|
|
5094
5826
|
expect(
|
|
5095
5827
|
(await store.listTicketAssets(REPO, 'T-1', { revisions: true })).map(
|
|
5096
5828
|
(a) => `${a.kind}/${a.name}@${a.revision}`,
|
|
@@ -5126,7 +5858,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
5126
5858
|
|
|
5127
5859
|
test('rejects invalid names, paths and structures, storing nothing', async () => {
|
|
5128
5860
|
await withStore(factory, undefined, async (store) => {
|
|
5129
|
-
const f = (path: string) => ({
|
|
5861
|
+
const f = (path: string) => ({
|
|
5862
|
+
type: 'file' as const,
|
|
5863
|
+
path,
|
|
5864
|
+
content: enc('x'),
|
|
5865
|
+
})
|
|
5130
5866
|
const bad = [
|
|
5131
5867
|
{ ...fileAsset('a', enc('x')), name: 'has space' },
|
|
5132
5868
|
{ ...fileAsset('a', enc('x')), kind: '' },
|
|
@@ -5155,7 +5891,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
5155
5891
|
await withStore(factory, undefined, async (store) => {
|
|
5156
5892
|
await store.putTicketAsset(REPO, 'T-1', fileAsset('a', enc('ok')))
|
|
5157
5893
|
await expect(
|
|
5158
|
-
store.putTicketAsset(REPO, 'T-1', {
|
|
5894
|
+
store.putTicketAsset(REPO, 'T-1', {
|
|
5895
|
+
...fileAsset('a', enc('x')),
|
|
5896
|
+
name: 'a b',
|
|
5897
|
+
}),
|
|
5159
5898
|
).rejects.toThrow()
|
|
5160
5899
|
expect(
|
|
5161
5900
|
(await store.putTicketAsset(REPO, 'T-1', fileAsset('a', enc('ok2')))).revision,
|
|
@@ -5211,7 +5950,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
5211
5950
|
const created = buildCreatedWrite()
|
|
5212
5951
|
await store.createBuild({
|
|
5213
5952
|
...sampleBuildInput(slug),
|
|
5214
|
-
created: {
|
|
5953
|
+
created: {
|
|
5954
|
+
...created,
|
|
5955
|
+
payload: { ...created.payload, repo: REPO, assets },
|
|
5956
|
+
},
|
|
5215
5957
|
})
|
|
5216
5958
|
}
|
|
5217
5959
|
|
|
@@ -5227,7 +5969,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
5227
5969
|
await store.append('snapshot-pin', {
|
|
5228
5970
|
actor: KERNEL,
|
|
5229
5971
|
type: 'spec.revised',
|
|
5230
|
-
payload: {
|
|
5972
|
+
payload: {
|
|
5973
|
+
artifact: { kind: 'spec', rev: 1 },
|
|
5974
|
+
escalation: 1,
|
|
5975
|
+
assets: newer,
|
|
5976
|
+
},
|
|
5231
5977
|
})
|
|
5232
5978
|
await source.removeTicketAsset(REPO, 'TICK-1', 'design', 'a.txt')
|
|
5233
5979
|
expect(text(await store.getPinnedTicketAsset('snapshot-pin', 'design', 'a.txt'))).toBe(
|
|
@@ -5274,7 +6020,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
5274
6020
|
test('a build with no pin and an unknown build', async () => {
|
|
5275
6021
|
await withStore(factory, undefined, async (store) => {
|
|
5276
6022
|
await store.putTicketAsset(REPO, 'TICK-1', file('a.txt', 'one'))
|
|
5277
|
-
await store.createBuild({
|
|
6023
|
+
await store.createBuild({
|
|
6024
|
+
...sampleBuildInput('pin-none'),
|
|
6025
|
+
created: buildCreatedWrite(),
|
|
6026
|
+
})
|
|
5278
6027
|
expect(await store.getPinnedTicketAsset('pin-none', 'design', 'a.txt')).toBeNull()
|
|
5279
6028
|
await expect(store.getPinnedTicketAsset('never', 'design', 'a.txt')).rejects.toThrow()
|
|
5280
6029
|
})
|
|
@@ -5288,7 +6037,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
5288
6037
|
await store.append('pin-c', {
|
|
5289
6038
|
actor: KERNEL,
|
|
5290
6039
|
type: 'spec.revised',
|
|
5291
|
-
payload: {
|
|
6040
|
+
payload: {
|
|
6041
|
+
artifact: { kind: 'spec', rev: 1 },
|
|
6042
|
+
escalation: 1,
|
|
6043
|
+
assets: [pinOf(v1)],
|
|
6044
|
+
},
|
|
5292
6045
|
})
|
|
5293
6046
|
expect(text(await store.getPinnedTicketAsset('pin-c', 'design', 'a.txt'))).toBe('two')
|
|
5294
6047
|
expect(text(await store.getPinnedTicketAsset('pin-c', 'design', 'a.txt', 0))).toBe('one')
|
|
@@ -5296,7 +6049,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
5296
6049
|
await store.append('pin-c', {
|
|
5297
6050
|
actor: KERNEL,
|
|
5298
6051
|
type: 'spec.revised',
|
|
5299
|
-
payload: {
|
|
6052
|
+
payload: {
|
|
6053
|
+
artifact: { kind: 'spec', rev: 2 },
|
|
6054
|
+
escalation: 1,
|
|
6055
|
+
assets: [],
|
|
6056
|
+
},
|
|
5300
6057
|
})
|
|
5301
6058
|
expect(await store.getPinnedTicketAsset('pin-c', 'design', 'a.txt')).toBeNull()
|
|
5302
6059
|
expect(text(await store.getPinnedTicketAsset('pin-c', 'design', 'a.txt', 1))).toBe('two')
|
|
@@ -5329,7 +6086,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
5329
6086
|
expect(scoped.buildScope).toBe('scope-own')
|
|
5330
6087
|
expect(await scoped.getBuild('scope-own')).not.toBeNull()
|
|
5331
6088
|
await scoped.append('scope-own', sampleEventWrite())
|
|
5332
|
-
await scoped.putArtifact('scope-own', {
|
|
6089
|
+
await scoped.putArtifact('scope-own', {
|
|
6090
|
+
kind: 'notes',
|
|
6091
|
+
content: 'owned',
|
|
6092
|
+
})
|
|
5333
6093
|
expect(textContent((await scoped.getArtifact('scope-own', 'notes'))!)).toBe('owned')
|
|
5334
6094
|
expect(await scoped.claimLease('scope-own', 'runner', 1000)).toBe(true)
|
|
5335
6095
|
expect(await scoped.heartbeat('scope-own', 'runner')).toBe(true)
|
|
@@ -5502,7 +6262,12 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
5502
6262
|
(await store.listStreams({ kind: 'build', build: 'st-tie-b' })).map((s) => s.id),
|
|
5503
6263
|
).toEqual([b.id])
|
|
5504
6264
|
expect(
|
|
5505
|
-
(
|
|
6265
|
+
(
|
|
6266
|
+
await store.listStreams({
|
|
6267
|
+
kind: 'repo',
|
|
6268
|
+
repo: 'acme/rate-limiter',
|
|
6269
|
+
})
|
|
6270
|
+
).map((s) => s.id),
|
|
5506
6271
|
).toEqual([r.id])
|
|
5507
6272
|
// Distinct-timestamp ordering is unchanged.
|
|
5508
6273
|
clock.advance(1)
|
|
@@ -5526,7 +6291,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
5526
6291
|
clock.advance(1000)
|
|
5527
6292
|
const parts: StreamPart[] = [
|
|
5528
6293
|
{ type: 'text-delta', id: 't', delta: 'hello' },
|
|
5529
|
-
{
|
|
6294
|
+
{
|
|
6295
|
+
type: 'data-probe',
|
|
6296
|
+
data: { nested: true, extra: 'keys survive' },
|
|
6297
|
+
},
|
|
5530
6298
|
]
|
|
5531
6299
|
const c1 = await store.appendStreamParts(a.id, parts)
|
|
5532
6300
|
clock.advance(1000)
|
|
@@ -5879,7 +6647,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
5879
6647
|
])
|
|
5880
6648
|
clock.advance(1000)
|
|
5881
6649
|
const record = await store.closeStream(stream.id, 'aborted')
|
|
5882
|
-
expect(record.scope).toEqual({
|
|
6650
|
+
expect(record.scope).toEqual({
|
|
6651
|
+
kind: 'repo',
|
|
6652
|
+
repo: 'acme/rate-limiter',
|
|
6653
|
+
})
|
|
5883
6654
|
expect(record.outcome).toBe('aborted')
|
|
5884
6655
|
const artifact = await store.getRepoArtifact('acme/rate-limiter', `stream:${stream.id}`)
|
|
5885
6656
|
expect(artifact?.meta.metadata).toMatchObject({
|
|
@@ -5896,7 +6667,12 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
5896
6667
|
},
|
|
5897
6668
|
])
|
|
5898
6669
|
expect(
|
|
5899
|
-
(
|
|
6670
|
+
(
|
|
6671
|
+
await store.listStreams({
|
|
6672
|
+
kind: 'repo',
|
|
6673
|
+
repo: 'acme/rate-limiter',
|
|
6674
|
+
})
|
|
6675
|
+
).map((r) => r.id),
|
|
5900
6676
|
).toEqual([stream.id])
|
|
5901
6677
|
})
|
|
5902
6678
|
})
|
|
@@ -5921,7 +6697,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
5921
6697
|
])
|
|
5922
6698
|
clock.advance(1000)
|
|
5923
6699
|
const record = await store.closeStream(stream.id, 'completed')
|
|
5924
|
-
expect(record.scope).toEqual({
|
|
6700
|
+
expect(record.scope).toEqual({
|
|
6701
|
+
kind: 'session',
|
|
6702
|
+
session: session.id,
|
|
6703
|
+
})
|
|
5925
6704
|
expect(record.outcome).toBe('completed')
|
|
5926
6705
|
const artifact = await store.getSessionArtifact(session.id, `stream:${stream.id}`)
|
|
5927
6706
|
expect(artifact?.meta.metadata).toMatchObject({
|
|
@@ -5981,10 +6760,22 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
5981
6760
|
const clock = manualClock(CONTRACT_T0)
|
|
5982
6761
|
await withStore(factory, { clock }, async (store) => {
|
|
5983
6762
|
expect(await store.getSession('os_never')).toBeNull()
|
|
5984
|
-
const a = await store.createSession({
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
6763
|
+
const a = await store.createSession({
|
|
6764
|
+
repo: 'acme/a',
|
|
6765
|
+
operator: 'op',
|
|
6766
|
+
})
|
|
6767
|
+
const a2 = await store.createSession({
|
|
6768
|
+
repo: 'acme/a',
|
|
6769
|
+
operator: 'op',
|
|
6770
|
+
})
|
|
6771
|
+
const a3 = await store.createSession({
|
|
6772
|
+
repo: 'acme/a',
|
|
6773
|
+
operator: 'op',
|
|
6774
|
+
})
|
|
6775
|
+
const b = await store.createSession({
|
|
6776
|
+
repo: 'acme/b',
|
|
6777
|
+
operator: 'op',
|
|
6778
|
+
})
|
|
5988
6779
|
expect([a.createdAt, a2.createdAt, a3.createdAt, b.createdAt]).toEqual([
|
|
5989
6780
|
CONTRACT_T0,
|
|
5990
6781
|
CONTRACT_T0,
|
|
@@ -6000,9 +6791,15 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
6000
6791
|
expect(await store.listSessions('acme/never')).toEqual([])
|
|
6001
6792
|
// Distinct-timestamp ordering is unchanged.
|
|
6002
6793
|
clock.advance(1)
|
|
6003
|
-
const a4 = await store.createSession({
|
|
6794
|
+
const a4 = await store.createSession({
|
|
6795
|
+
repo: 'acme/a',
|
|
6796
|
+
operator: 'op',
|
|
6797
|
+
})
|
|
6004
6798
|
clock.advance(1)
|
|
6005
|
-
const a5 = await store.createSession({
|
|
6799
|
+
const a5 = await store.createSession({
|
|
6800
|
+
repo: 'acme/a',
|
|
6801
|
+
operator: 'op',
|
|
6802
|
+
})
|
|
6006
6803
|
expect(a4.createdAt > a2.createdAt).toBe(true)
|
|
6007
6804
|
expect(a5.createdAt > a4.createdAt).toBe(true)
|
|
6008
6805
|
expect((await store.listSessions('acme/a')).map((s) => s.id)).toEqual([
|
|
@@ -6027,8 +6824,14 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
6027
6824
|
test('per-session sequencing is independent across sessions and updates the record', async () => {
|
|
6028
6825
|
const clock = manualClock(CONTRACT_T0)
|
|
6029
6826
|
await withStore(factory, { clock }, async (store) => {
|
|
6030
|
-
const a = await store.createSession({
|
|
6031
|
-
|
|
6827
|
+
const a = await store.createSession({
|
|
6828
|
+
repo: 'acme/a',
|
|
6829
|
+
operator: 'op',
|
|
6830
|
+
})
|
|
6831
|
+
const b = await store.createSession({
|
|
6832
|
+
repo: 'acme/a',
|
|
6833
|
+
operator: 'op',
|
|
6834
|
+
})
|
|
6032
6835
|
clock.advance(1000)
|
|
6033
6836
|
const a2 = await store.appendSessionEvent(a.id, messagePostedWrite('first'))
|
|
6034
6837
|
clock.advance(1000)
|
|
@@ -6045,7 +6848,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
6045
6848
|
|
|
6046
6849
|
test('appendSessionEvent validation rejects unknown types, malformed payloads, and wrong actor kinds, leaving the log untouched', async () => {
|
|
6047
6850
|
await withStore(factory, undefined, async (store) => {
|
|
6048
|
-
const session = await store.createSession({
|
|
6851
|
+
const session = await store.createSession({
|
|
6852
|
+
repo: 'acme/a',
|
|
6853
|
+
operator: 'op',
|
|
6854
|
+
})
|
|
6049
6855
|
const cases = [
|
|
6050
6856
|
// Unknown type.
|
|
6051
6857
|
{
|
|
@@ -6054,7 +6860,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
6054
6860
|
payload: {},
|
|
6055
6861
|
},
|
|
6056
6862
|
// Malformed payload: message.posted requires nonempty text.
|
|
6057
|
-
{
|
|
6863
|
+
{
|
|
6864
|
+
actor: humanActor('op'),
|
|
6865
|
+
type: 'message.posted',
|
|
6866
|
+
payload: { text: '' },
|
|
6867
|
+
},
|
|
6058
6868
|
// Wrong actor kind: only humans post messages.
|
|
6059
6869
|
{
|
|
6060
6870
|
actor: agentActor('orchestrator', 'os_t'),
|
|
@@ -6094,7 +6904,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
6094
6904
|
|
|
6095
6905
|
test('appendSessionEventIfCurrent (atomic session compare-and-append): win, stale miss leaves the log untouched, concurrent race yields exactly one winner', async () => {
|
|
6096
6906
|
await withStore(factory, undefined, async (store) => {
|
|
6097
|
-
const session = await store.createSession({
|
|
6907
|
+
const session = await store.createSession({
|
|
6908
|
+
repo: 'acme/a',
|
|
6909
|
+
operator: 'op',
|
|
6910
|
+
})
|
|
6098
6911
|
// session.created is seq 1, so the current tail is 1.
|
|
6099
6912
|
const won = await store.appendSessionEventIfCurrent(
|
|
6100
6913
|
session.id,
|
|
@@ -6161,9 +6974,14 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
6161
6974
|
|
|
6162
6975
|
test('bounded-wait session event read: early return on append, waits out the bound when empty, clamps above 30', async () => {
|
|
6163
6976
|
await withStore(factory, undefined, async (store) => {
|
|
6164
|
-
const session = await store.createSession({
|
|
6977
|
+
const session = await store.createSession({
|
|
6978
|
+
repo: 'acme/a',
|
|
6979
|
+
operator: 'op',
|
|
6980
|
+
})
|
|
6165
6981
|
// Early return when an event lands during the wait.
|
|
6166
|
-
const pending = store.getSessionEvents(session.id, 1, {
|
|
6982
|
+
const pending = store.getSessionEvents(session.id, 1, {
|
|
6983
|
+
waitSeconds: 5,
|
|
6984
|
+
})
|
|
6167
6985
|
await Bun.sleep(100)
|
|
6168
6986
|
const appended = await store.appendSessionEvent(session.id, messagePostedWrite('wake'))
|
|
6169
6987
|
const woke = await pending
|
|
@@ -6171,7 +6989,9 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
6171
6989
|
|
|
6172
6990
|
// Waits out the bound when nothing arrives.
|
|
6173
6991
|
const started = Date.now()
|
|
6174
|
-
const empty = await store.getSessionEvents(session.id, 99, {
|
|
6992
|
+
const empty = await store.getSessionEvents(session.id, 99, {
|
|
6993
|
+
waitSeconds: 1,
|
|
6994
|
+
})
|
|
6175
6995
|
expect(empty).toEqual([])
|
|
6176
6996
|
expect(Date.now() - started).toBeGreaterThanOrEqual(950)
|
|
6177
6997
|
})
|
|
@@ -6179,7 +6999,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
6179
6999
|
|
|
6180
7000
|
test('session deposits are atomic: success, invalid-event rollback, validation-before-prune', async () => {
|
|
6181
7001
|
await withStore(factory, undefined, async (store) => {
|
|
6182
|
-
const session = await store.createSession({
|
|
7002
|
+
const session = await store.createSession({
|
|
7003
|
+
repo: 'acme/a',
|
|
7004
|
+
operator: 'op',
|
|
7005
|
+
})
|
|
6183
7006
|
const { event, artifacts } = await store.appendSessionWithArtifacts(
|
|
6184
7007
|
session.id,
|
|
6185
7008
|
[{ kind: 'turn-context', content: '{"turn":"t1"}' }],
|
|
@@ -6224,7 +7047,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
6224
7047
|
|
|
6225
7048
|
test('session artifacts version per kind and read latest/pinned', async () => {
|
|
6226
7049
|
await withStore(factory, undefined, async (store) => {
|
|
6227
|
-
const session = await store.createSession({
|
|
7050
|
+
const session = await store.createSession({
|
|
7051
|
+
repo: 'acme/a',
|
|
7052
|
+
operator: 'op',
|
|
7053
|
+
})
|
|
6228
7054
|
const a0 = await store.putSessionArtifact(session.id, {
|
|
6229
7055
|
kind: 'context',
|
|
6230
7056
|
content: 'v0',
|
|
@@ -6250,8 +7076,14 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
6250
7076
|
|
|
6251
7077
|
test('session-scoped handles touch only their own session and reject everything else', async () => {
|
|
6252
7078
|
await withStore(factory, undefined, async (store) => {
|
|
6253
|
-
const own = await store.createSession({
|
|
6254
|
-
|
|
7079
|
+
const own = await store.createSession({
|
|
7080
|
+
repo: 'acme/a',
|
|
7081
|
+
operator: 'op',
|
|
7082
|
+
})
|
|
7083
|
+
const foreign = await store.createSession({
|
|
7084
|
+
repo: 'acme/a',
|
|
7085
|
+
operator: 'op',
|
|
7086
|
+
})
|
|
6255
7087
|
await store.ensureRepo('acme/a')
|
|
6256
7088
|
await store.createBuild(sampleBuildInput('scope-build'))
|
|
6257
7089
|
const scoped = store.scopeSession(own.id)
|
|
@@ -6260,7 +7092,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
6260
7092
|
// Own operations work.
|
|
6261
7093
|
expect(await scoped.getSession(own.id)).not.toBeNull()
|
|
6262
7094
|
await scoped.appendSessionEvent(own.id, messagePostedWrite('mine'))
|
|
6263
|
-
await scoped.putSessionArtifact(own.id, {
|
|
7095
|
+
await scoped.putSessionArtifact(own.id, {
|
|
7096
|
+
kind: 'notes',
|
|
7097
|
+
content: 'owned',
|
|
7098
|
+
})
|
|
6264
7099
|
expect((await scoped.getSessionArtifact(own.id, 'notes'))?.meta.revision).toBe(0)
|
|
6265
7100
|
const ownStream = await scoped.createStream(
|
|
6266
7101
|
{ kind: 'session', session: own.id },
|
|
@@ -6309,7 +7144,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
6309
7144
|
|
|
6310
7145
|
test('build-scoped handles reject session operations and session-scoped streams', async () => {
|
|
6311
7146
|
await withStore(factory, undefined, async (store) => {
|
|
6312
|
-
const session = await store.createSession({
|
|
7147
|
+
const session = await store.createSession({
|
|
7148
|
+
repo: 'acme/a',
|
|
7149
|
+
operator: 'op',
|
|
7150
|
+
})
|
|
6313
7151
|
await store.createBuild(sampleBuildInput('bscope'))
|
|
6314
7152
|
const scoped = store.scopeBuild('bscope')
|
|
6315
7153
|
const sessionStream = await store.createStream(
|
|
@@ -6321,7 +7159,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
6321
7159
|
() => scoped.appendSessionEvent(session.id, messagePostedWrite()),
|
|
6322
7160
|
() => scoped.listSessions('acme/a'),
|
|
6323
7161
|
() => scoped.createSession({ repo: 'acme/a', operator: 'op' }),
|
|
6324
|
-
() =>
|
|
7162
|
+
() =>
|
|
7163
|
+
scoped.putSessionArtifact(session.id, {
|
|
7164
|
+
kind: 'x',
|
|
7165
|
+
content: 'x',
|
|
7166
|
+
}),
|
|
6325
7167
|
() => scoped.listSessionArtifacts(session.id),
|
|
6326
7168
|
() => scoped.createStream({ kind: 'session', session: session.id }, 'x'),
|
|
6327
7169
|
() =>
|
|
@@ -6341,7 +7183,10 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
6341
7183
|
|
|
6342
7184
|
test('session streams never list under build or repo scopes and vice versa', async () => {
|
|
6343
7185
|
await withStore(factory, undefined, async (store) => {
|
|
6344
|
-
const session = await store.createSession({
|
|
7186
|
+
const session = await store.createSession({
|
|
7187
|
+
repo: 'acme/a',
|
|
7188
|
+
operator: 'op',
|
|
7189
|
+
})
|
|
6345
7190
|
await store.createBuild(sampleBuildInput('st-mix'))
|
|
6346
7191
|
await store.ensureRepo('acme/a')
|
|
6347
7192
|
const sessionStream = await store.createStream(
|
|
@@ -6353,7 +7198,12 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
6353
7198
|
'phase',
|
|
6354
7199
|
)
|
|
6355
7200
|
expect(
|
|
6356
|
-
(
|
|
7201
|
+
(
|
|
7202
|
+
await store.listStreams({
|
|
7203
|
+
kind: 'session',
|
|
7204
|
+
session: session.id,
|
|
7205
|
+
})
|
|
7206
|
+
).map((r) => r.id),
|
|
6357
7207
|
).toEqual([sessionStream.id])
|
|
6358
7208
|
expect(
|
|
6359
7209
|
(await store.listStreams({ kind: 'build', build: 'st-mix' })).map((r) => r.id),
|
|
@@ -6421,13 +7271,19 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
6421
7271
|
type: 'build.pause-requested',
|
|
6422
7272
|
payload: {},
|
|
6423
7273
|
})
|
|
6424
|
-
expect(plain.actor).toEqual({
|
|
7274
|
+
expect(plain.actor).toEqual({
|
|
7275
|
+
kind: 'human',
|
|
7276
|
+
user: 'operator',
|
|
7277
|
+
})
|
|
6425
7278
|
const repoPlain = await store.appendRepo('acme/via', {
|
|
6426
7279
|
actor: humanActor('operator'),
|
|
6427
7280
|
type: 'dispatcher.intake-set',
|
|
6428
7281
|
payload: { enabled: false },
|
|
6429
7282
|
})
|
|
6430
|
-
expect(repoPlain.actor).toEqual({
|
|
7283
|
+
expect(repoPlain.actor).toEqual({
|
|
7284
|
+
kind: 'human',
|
|
7285
|
+
user: 'operator',
|
|
7286
|
+
})
|
|
6431
7287
|
return
|
|
6432
7288
|
}
|
|
6433
7289
|
// Token carrying a via (kept for future harnesses): the token is
|
|
@@ -6444,13 +7300,21 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
6444
7300
|
baseBranch: 'main',
|
|
6445
7301
|
},
|
|
6446
7302
|
})
|
|
6447
|
-
expect(envelope.actor).toEqual({
|
|
7303
|
+
expect(envelope.actor).toEqual({
|
|
7304
|
+
kind: 'human',
|
|
7305
|
+
user: 'operator',
|
|
7306
|
+
via: tokenVia,
|
|
7307
|
+
})
|
|
6448
7308
|
const stamped = await store.append('via-build', {
|
|
6449
7309
|
actor: humanActor('operator'),
|
|
6450
7310
|
type: 'build.pause-requested',
|
|
6451
7311
|
payload: {},
|
|
6452
7312
|
})
|
|
6453
|
-
expect(stamped.actor).toEqual({
|
|
7313
|
+
expect(stamped.actor).toEqual({
|
|
7314
|
+
kind: 'human',
|
|
7315
|
+
user: 'operator',
|
|
7316
|
+
via: tokenVia,
|
|
7317
|
+
})
|
|
6454
7318
|
const mismatch = await store
|
|
6455
7319
|
.append('via-build', {
|
|
6456
7320
|
actor: humanActor('operator', other),
|
|
@@ -6476,7 +7340,11 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
6476
7340
|
baseBranch: 'main',
|
|
6477
7341
|
},
|
|
6478
7342
|
})
|
|
6479
|
-
expect(envelope.actor).toEqual({
|
|
7343
|
+
expect(envelope.actor).toEqual({
|
|
7344
|
+
kind: 'human',
|
|
7345
|
+
user: 'operator',
|
|
7346
|
+
via,
|
|
7347
|
+
})
|
|
6480
7348
|
await store.appendRepo('acme/via', {
|
|
6481
7349
|
actor: humanActor('operator', via),
|
|
6482
7350
|
type: 'dispatcher.intake-set',
|
|
@@ -6510,7 +7378,12 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
6510
7378
|
await store.ensureRepo('acme/via')
|
|
6511
7379
|
for (const actor of [
|
|
6512
7380
|
{ kind: 'kernel', via: viaSession },
|
|
6513
|
-
{
|
|
7381
|
+
{
|
|
7382
|
+
kind: 'agent',
|
|
7383
|
+
role: 'implement',
|
|
7384
|
+
session: 's_1',
|
|
7385
|
+
via: viaSession,
|
|
7386
|
+
},
|
|
6514
7387
|
{ kind: 'dispatcher', via: viaMcp },
|
|
6515
7388
|
{ kind: 'ingester', source: 'webhook', via: viaMcp },
|
|
6516
7389
|
]) {
|