@boxxy/dispatch 0.1.1 → 0.1.3

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.
Files changed (190) hide show
  1. package/dist/attempts/attempt-machine.d.ts +804 -0
  2. package/dist/attempts/attempt-moves.d.ts +2 -0
  3. package/dist/attempts/bind-attempt-session.d.ts +14 -0
  4. package/dist/attempts/build-attempt-change.d.ts +73 -0
  5. package/dist/attempts/build-attempt-fact.d.ts +3 -0
  6. package/dist/attempts/end-item-attempts.d.ts +18 -0
  7. package/dist/attempts/is-same-guard.d.ts +5 -0
  8. package/dist/attempts/pick-call-attempt.d.ts +10 -0
  9. package/dist/attempts/stop-stray-session.d.ts +11 -0
  10. package/dist/attempts/types.d.ts +142 -0
  11. package/dist/attempts/write-attempt-move.d.ts +7 -0
  12. package/dist/attempts/write-session-bind.d.ts +3 -0
  13. package/dist/claims/build-snapshot-hash.d.ts +2 -0
  14. package/dist/claims/claim-next.d.ts +6 -0
  15. package/dist/claims/pick-kept-session.d.ts +9 -0
  16. package/dist/claims/request-wake.d.ts +3 -0
  17. package/dist/claims/resume-claim.d.ts +3 -0
  18. package/dist/claims/start-claim.d.ts +3 -0
  19. package/dist/claims/types.d.ts +44 -0
  20. package/dist/closeouts/build-settle-plans.d.ts +17 -0
  21. package/dist/closeouts/close-out-attempt.d.ts +3 -0
  22. package/dist/closeouts/effect-handlers.d.ts +2 -0
  23. package/dist/closeouts/pick-settlement.d.ts +14 -0
  24. package/dist/closeouts/settle-attempt.d.ts +3 -0
  25. package/dist/closeouts/types.d.ts +50 -0
  26. package/dist/index.d.ts +38 -0
  27. package/dist/notices/constants.d.ts +4 -0
  28. package/dist/notices/create-null-notifier.d.ts +2 -0
  29. package/dist/notices/send-notices.d.ts +2 -0
  30. package/dist/notices/types.d.ts +11 -0
  31. package/dist/outbox/build-backoff-ms.d.ts +2 -0
  32. package/dist/outbox/build-initial-sender-state.d.ts +2 -0
  33. package/dist/outbox/build-outbox-status.d.ts +15 -0
  34. package/dist/outbox/constants.d.ts +2 -0
  35. package/dist/outbox/measure-wire-bytes.d.ts +2 -0
  36. package/dist/outbox/pick-sender-move.d.ts +10 -0
  37. package/dist/outbox/run-sender-once.d.ts +2 -0
  38. package/dist/outbox/take-batch.d.ts +3 -0
  39. package/dist/outbox/types.d.ts +61 -0
  40. package/dist/pull-requests/build-link-change.d.ts +11 -0
  41. package/dist/pull-requests/build-state-fact.d.ts +8 -0
  42. package/dist/pull-requests/collect-attempt-trailers.d.ts +2 -0
  43. package/dist/pull-requests/collect-seen-state.d.ts +7 -0
  44. package/dist/pull-requests/constants.d.ts +3 -0
  45. package/dist/pull-requests/link-pull-request.d.ts +2 -0
  46. package/dist/pull-requests/parse-pull-request-url.d.ts +2 -0
  47. package/dist/pull-requests/types.d.ts +37 -0
  48. package/dist/pull-requests/watch-pull-requests.d.ts +2 -0
  49. package/dist/readings/act-on-reading.d.ts +3 -0
  50. package/dist/readings/find-waiting-since.d.ts +9 -0
  51. package/dist/readings/pick-reading-action.d.ts +2 -0
  52. package/dist/readings/types.d.ts +79 -0
  53. package/dist/sessions/build-keep-writes.d.ts +9 -0
  54. package/dist/sessions/build-kept-clear.d.ts +2 -0
  55. package/dist/sessions/forget-sessions.d.ts +2 -0
  56. package/dist/sessions/is-kept-due.d.ts +2 -0
  57. package/dist/sessions/resume-kept-session.d.ts +6 -0
  58. package/dist/sessions/types.d.ts +19 -0
  59. package/dist/test-utils/apply-memory-change.d.ts +3 -0
  60. package/dist/test-utils/build-memory-reader.d.ts +3 -0
  61. package/dist/test-utils/build-mock-claim-change.d.ts +2 -2
  62. package/dist/test-utils/build-mock-new-id.d.ts +2 -0
  63. package/dist/test-utils/build-mock-note-change.d.ts +2 -0
  64. package/dist/test-utils/build-mock-pull-request-change.d.ts +1 -0
  65. package/dist/test-utils/{build-mock-link-change.d.ts → build-mock-relation-change.d.ts} +2 -2
  66. package/dist/test-utils/build-mock-running-reading.d.ts +6 -0
  67. package/dist/test-utils/build-mock-start-change.d.ts +2 -2
  68. package/dist/test-utils/claim-store-close-cases.d.ts +2 -0
  69. package/dist/test-utils/claim-store-copy-cases.d.ts +2 -0
  70. package/dist/test-utils/claim-store-outbox-cases.d.ts +2 -0
  71. package/dist/test-utils/claim-store-race-cases.d.ts +2 -0
  72. package/dist/test-utils/claim-store-seat-cases.d.ts +2 -0
  73. package/dist/test-utils/claim-store-session-cases.d.ts +2 -0
  74. package/dist/test-utils/collect-memory-limit-fills.d.ts +3 -0
  75. package/dist/test-utils/compare-text.d.ts +1 -0
  76. package/dist/test-utils/create-fake-backoff.d.ts +2 -0
  77. package/dist/test-utils/create-fake-clock.d.ts +5 -0
  78. package/dist/test-utils/create-fake-fact-sink.d.ts +8 -0
  79. package/dist/test-utils/create-fake-forge.d.ts +17 -0
  80. package/dist/test-utils/create-fake-worker.d.ts +42 -0
  81. package/dist/test-utils/create-memory-claim-store.d.ts +2 -2
  82. package/dist/test-utils/create-test-dispatch.d.ts +46 -0
  83. package/dist/test-utils/forge-contract.d.ts +15 -0
  84. package/dist/test-utils/is-same-held-seat.d.ts +2 -0
  85. package/dist/test-utils/types.d.ts +12 -2
  86. package/dist/test-utils/worker-contract.d.ts +14 -0
  87. package/dist/timeouts.d.ts +2 -0
  88. package/dist/types.d.ts +13 -0
  89. package/package.json +10 -3
  90. package/src/attempts/attempt-machine.ts +147 -0
  91. package/src/attempts/attempt-moves.ts +218 -0
  92. package/src/attempts/bind-attempt-session.ts +61 -0
  93. package/src/attempts/build-attempt-change.ts +540 -0
  94. package/src/attempts/build-attempt-fact.ts +135 -0
  95. package/src/attempts/end-item-attempts.ts +95 -0
  96. package/src/attempts/is-same-guard.ts +22 -0
  97. package/src/attempts/pick-call-attempt.ts +32 -0
  98. package/src/attempts/stop-stray-session.ts +48 -0
  99. package/src/attempts/types.ts +231 -0
  100. package/src/attempts/write-attempt-move.ts +41 -0
  101. package/src/attempts/write-session-bind.ts +47 -0
  102. package/src/claims/build-snapshot-hash.ts +9 -0
  103. package/src/claims/claim-next.ts +306 -0
  104. package/src/claims/pick-kept-session.ts +41 -0
  105. package/src/claims/request-wake.ts +17 -0
  106. package/src/claims/resume-claim.ts +56 -0
  107. package/src/claims/start-claim.ts +99 -0
  108. package/src/claims/types.ts +67 -0
  109. package/src/closeouts/build-settle-plans.ts +173 -0
  110. package/src/closeouts/close-out-attempt.ts +156 -0
  111. package/src/closeouts/effect-handlers.ts +232 -0
  112. package/src/closeouts/pick-settlement.ts +80 -0
  113. package/src/closeouts/settle-attempt.ts +161 -0
  114. package/src/closeouts/types.ts +87 -0
  115. package/src/index.ts +61 -0
  116. package/src/notices/constants.ts +7 -0
  117. package/src/notices/create-null-notifier.ts +6 -0
  118. package/src/notices/send-notices.ts +41 -0
  119. package/src/notices/types.ts +14 -0
  120. package/src/outbox/build-backoff-ms.ts +14 -0
  121. package/src/outbox/build-initial-sender-state.ts +14 -0
  122. package/src/outbox/build-outbox-status.ts +43 -0
  123. package/src/outbox/constants.ts +15 -0
  124. package/src/outbox/measure-wire-bytes.ts +31 -0
  125. package/src/outbox/pick-sender-move.ts +37 -0
  126. package/src/outbox/run-sender-once.ts +174 -0
  127. package/src/outbox/take-batch.ts +35 -0
  128. package/src/outbox/types.ts +76 -0
  129. package/src/pull-requests/build-link-change.ts +95 -0
  130. package/src/pull-requests/build-state-fact.ts +39 -0
  131. package/src/pull-requests/collect-attempt-trailers.ts +20 -0
  132. package/src/pull-requests/collect-seen-state.ts +19 -0
  133. package/src/pull-requests/constants.ts +5 -0
  134. package/src/pull-requests/link-pull-request.ts +119 -0
  135. package/src/pull-requests/parse-pull-request-url.ts +30 -0
  136. package/src/pull-requests/types.ts +63 -0
  137. package/src/pull-requests/watch-pull-requests.ts +308 -0
  138. package/src/readings/act-on-reading.ts +318 -0
  139. package/src/readings/find-waiting-since.ts +46 -0
  140. package/src/readings/pick-reading-action.ts +315 -0
  141. package/src/readings/types.ts +98 -0
  142. package/src/sessions/build-keep-writes.ts +55 -0
  143. package/src/sessions/build-kept-clear.ts +12 -0
  144. package/src/sessions/forget-sessions.ts +106 -0
  145. package/src/sessions/is-kept-due.ts +27 -0
  146. package/src/sessions/resume-kept-session.ts +25 -0
  147. package/src/sessions/types.ts +39 -0
  148. package/src/test-utils/apply-memory-change.ts +252 -0
  149. package/src/test-utils/build-memory-reader.ts +364 -0
  150. package/src/test-utils/build-mock-bind-change.ts +18 -11
  151. package/src/test-utils/build-mock-claim-change.ts +18 -8
  152. package/src/test-utils/build-mock-file-item-change.ts +3 -1
  153. package/src/test-utils/build-mock-new-id.ts +12 -0
  154. package/src/test-utils/build-mock-note-change.ts +18 -0
  155. package/src/test-utils/build-mock-pause-change.ts +2 -10
  156. package/src/test-utils/build-mock-pull-request-change.ts +19 -9
  157. package/src/test-utils/{build-mock-link-change.ts → build-mock-relation-change.ts} +6 -6
  158. package/src/test-utils/build-mock-running-reading.ts +19 -0
  159. package/src/test-utils/build-mock-settle-change.ts +18 -6
  160. package/src/test-utils/build-mock-start-change.ts +13 -6
  161. package/src/test-utils/claim-store-attempt-reader-cases.ts +163 -133
  162. package/src/test-utils/claim-store-claim-cases.ts +168 -85
  163. package/src/test-utils/claim-store-close-cases.ts +95 -0
  164. package/src/test-utils/claim-store-contract.ts +12 -2
  165. package/src/test-utils/claim-store-copy-cases.ts +100 -0
  166. package/src/test-utils/claim-store-exclusive-cases.ts +65 -19
  167. package/src/test-utils/claim-store-guard-cases.ts +92 -82
  168. package/src/test-utils/claim-store-item-reader-cases.ts +291 -77
  169. package/src/test-utils/claim-store-outbox-cases.ts +281 -0
  170. package/src/test-utils/claim-store-race-cases.ts +150 -0
  171. package/src/test-utils/claim-store-rollback-cases.ts +50 -50
  172. package/src/test-utils/claim-store-seat-cases.ts +270 -0
  173. package/src/test-utils/claim-store-session-cases.ts +289 -0
  174. package/src/test-utils/collect-memory-limit-fills.ts +15 -0
  175. package/src/test-utils/compare-text.ts +8 -0
  176. package/src/test-utils/create-fake-backoff.ts +16 -0
  177. package/src/test-utils/create-fake-clock.ts +20 -0
  178. package/src/test-utils/create-fake-fact-sink.ts +74 -0
  179. package/src/test-utils/create-fake-forge.ts +117 -0
  180. package/src/test-utils/create-fake-worker.ts +303 -0
  181. package/src/test-utils/create-memory-claim-store.ts +73 -484
  182. package/src/test-utils/create-test-dispatch.ts +597 -0
  183. package/src/test-utils/forge-contract.ts +171 -0
  184. package/src/test-utils/is-same-held-seat.ts +11 -0
  185. package/src/test-utils/types.ts +14 -2
  186. package/src/test-utils/worker-contract.ts +192 -0
  187. package/src/timeouts.ts +17 -0
  188. package/src/types.ts +32 -0
  189. package/dist/test-utils/claim-store-pool-cases.d.ts +0 -2
  190. package/src/test-utils/claim-store-pool-cases.ts +0 -178
@@ -1,11 +1,18 @@
1
- import type { AttemptRow, StoreChange } from '@boxxy/model';
1
+ import type { AttemptRow, LimitName, StoreChange } from '@boxxy/model';
2
2
  import { buildMockFactId } from '@boxxy/model/test-utils/build-mock-fact-id';
3
3
 
4
- export function buildMockClaimChange(attempt: AttemptRow): StoreChange {
4
+ // A claim that takes the lease and a seat in each named limit, and inserts the attempt as given.
5
+ export function buildMockClaimChange(
6
+ attempt: AttemptRow,
7
+ limits: readonly LimitName[] = [],
8
+ ): StoreChange {
5
9
  return {
6
10
  at: attempt.claimedAt,
7
11
  writes: [
8
- { op: 'take-slot', pool: attempt.pool, holder: attempt.id },
12
+ {
13
+ op: 'take-seats',
14
+ take: { limits, attempt: attempt.id, holdGen: attempt.holdGen, overCap: false },
15
+ },
9
16
  {
10
17
  op: 'insert',
11
18
  table: 'leases',
@@ -18,22 +25,25 @@ export function buildMockClaimChange(attempt: AttemptRow): StoreChange {
18
25
  releasedAt: null,
19
26
  },
20
27
  },
21
- { op: 'insert', table: 'attempts', row: { ...attempt, slot: 0, slotGen: 0 } },
28
+ { op: 'insert', table: 'attempts', row: attempt },
22
29
  ],
23
30
  facts: [
24
31
  {
25
32
  id: buildMockFactId(),
26
33
  type: 'boxxy.attempt.claimed',
27
- entity: `boxxy:attempt:${attempt.id}`,
34
+ entity: `boxxy:item:${attempt.item}`,
28
35
  actor: `boxxy:runner:${attempt.runner}`,
29
36
  payload: {
30
- item: attempt.item,
37
+ attempt: attempt.id,
31
38
  phase: attempt.phase,
32
39
  number: attempt.number,
40
+ round: attempt.round,
41
+ mode: attempt.mode,
33
42
  pool: attempt.pool,
34
- slot: 0,
35
- gen: 0,
43
+ fields: attempt.fields,
44
+ seats: limits.map((limit) => ({ limit })),
36
45
  recipeHash: attempt.recipeHash,
46
+ skillsRef: null,
37
47
  rulesVersion: attempt.rulesVersion,
38
48
  },
39
49
  },
@@ -2,6 +2,8 @@ import type { ItemRow, StoreChange } from '@boxxy/model';
2
2
  import { buildMockFactId } from '@boxxy/model/test-utils/build-mock-fact-id';
3
3
 
4
4
  export function buildMockFileItemChange(item: ItemRow): StoreChange {
5
+ const { keptSession: _keptSession, ...filed } = item;
6
+
5
7
  return {
6
8
  at: item.filedAt,
7
9
  writes: [{ op: 'insert', table: 'items', row: item }],
@@ -11,7 +13,7 @@ export function buildMockFileItemChange(item: ItemRow): StoreChange {
11
13
  type: 'boxxy.item.filed',
12
14
  entity: `boxxy:item:${item.id}`,
13
15
  actor: 'boxxy:owner:local',
14
- payload: item,
16
+ payload: filed,
15
17
  },
16
18
  ],
17
19
  };
@@ -0,0 +1,12 @@
1
+ import type { NewId } from '@boxxy/model';
2
+
3
+ // A new-ID source that gives version 7 UUIDs in order: 1, 2, 3, … in the last group.
4
+ export function buildMockNewId(): NewId {
5
+ let count = 0;
6
+
7
+ return () => {
8
+ count += 1;
9
+
10
+ return `0190a6f4-0000-7000-8000-${String(count).padStart(12, '0')}`;
11
+ };
12
+ }
@@ -0,0 +1,18 @@
1
+ import type { NoteRow, StoreChange } from '@boxxy/model';
2
+ import { buildMockFactId } from '@boxxy/model/test-utils/build-mock-fact-id';
3
+
4
+ export function buildMockNoteChange(note: NoteRow): StoreChange {
5
+ return {
6
+ at: note.at,
7
+ writes: [{ op: 'insert', table: 'notes', row: note }],
8
+ facts: [
9
+ {
10
+ id: buildMockFactId(),
11
+ type: 'boxxy.item.noted',
12
+ entity: `boxxy:item:${note.item}`,
13
+ actor: note.by,
14
+ payload: { seq: note.seq, text: note.text },
15
+ },
16
+ ],
17
+ };
18
+ }
@@ -1,7 +1,7 @@
1
1
  import { brandSchemas } from '@boxxy/model';
2
2
  import type { RunnerId, StoreChange } from '@boxxy/model';
3
- import { buildMockFactId } from '@boxxy/model/test-utils/build-mock-fact-id';
4
3
 
4
+ // The fact catalog has no runner fact, so the pause writes the row and no fact.
5
5
  export function buildMockPauseChange(runner: RunnerId): StoreChange {
6
6
  return {
7
7
  at: brandSchemas.instant.parse(1500),
@@ -14,14 +14,6 @@ export function buildMockPauseChange(runner: RunnerId): StoreChange {
14
14
  set: { paused: true },
15
15
  },
16
16
  ],
17
- facts: [
18
- {
19
- id: buildMockFactId(),
20
- type: 'boxxy.runner.paused',
21
- entity: `boxxy:runner:${runner}`,
22
- actor: 'boxxy:owner:local',
23
- payload: { runner },
24
- },
25
- ],
17
+ facts: [],
26
18
  };
27
19
  }
@@ -1,23 +1,26 @@
1
1
  import { brandSchemas } from '@boxxy/model';
2
2
  import type { AttemptRow, PullRequestRow, StoreChange } from '@boxxy/model';
3
3
  import { buildMockFactId } from '@boxxy/model/test-utils/build-mock-fact-id';
4
- import { buildMockPullRequestRow } from '@boxxy/model/test-utils/build-mock-pull-request-row';
4
+ import { buildMockV1PullRequestRow } from '@boxxy/model/test-utils/build-mock-v1-pull-request-row';
5
5
 
6
6
  interface PullRequestInput {
7
7
  readonly attempt: AttemptRow;
8
8
  readonly state: PullRequestRow['state'];
9
+ readonly number?: number;
9
10
  }
10
11
 
12
+ // The hook links a pull request of `acme/lamps` to the attempt, with its evidence row.
11
13
  export function buildMockPullRequestChange(input: PullRequestInput): StoreChange {
12
14
  const attempt = input.attempt;
13
15
  const linkedAt = brandSchemas.instant.parse(4000);
14
16
  const factId = buildMockFactId();
15
- const url = 'https://github.com/acme/lamps/pull/7';
17
+ const number = input.number ?? 7;
16
18
 
17
- const pullRequest = buildMockPullRequestRow({
19
+ const pullRequest = buildMockV1PullRequestRow({
18
20
  repo: brandSchemas.repoName.parse('acme/lamps'),
19
- number: 7,
21
+ number,
20
22
  attempt: attempt.id,
23
+ githubId: 2_000_000 + number,
21
24
  state: input.state,
22
25
  checkedAt: linkedAt,
23
26
  });
@@ -32,8 +35,8 @@ export function buildMockPullRequestChange(input: PullRequestInput): StoreChange
32
35
  row: {
33
36
  factId,
34
37
  attempt: attempt.id,
35
- kind: 'pr',
36
- ref: url,
38
+ kind: 'pull_request',
39
+ ref: pullRequest.url,
37
40
  observed: null,
38
41
  source: 'hook',
39
42
  at: linkedAt,
@@ -43,10 +46,17 @@ export function buildMockPullRequestChange(input: PullRequestInput): StoreChange
43
46
  facts: [
44
47
  {
45
48
  id: factId,
46
- type: 'boxxy.evidence.pr_linked',
47
- entity: `boxxy:attempt:${attempt.id}`,
49
+ type: 'boxxy.pull_request.linked',
50
+ entity: `boxxy:item:${attempt.item}`,
48
51
  actor: `boxxy:hook:${attempt.id}`,
49
- payload: { repo: pullRequest.repo, number: 7, url },
52
+ payload: {
53
+ attempt: attempt.id,
54
+ repo: pullRequest.repo,
55
+ number,
56
+ url: pullRequest.url,
57
+ pullRequestId: String(pullRequest.githubId),
58
+ source: 'hook',
59
+ },
50
60
  },
51
61
  ],
52
62
  };
@@ -2,13 +2,13 @@ import { brandSchemas } from '@boxxy/model';
2
2
  import type { ItemId, StoreChange } from '@boxxy/model';
3
3
  import { buildMockFactId } from '@boxxy/model/test-utils/build-mock-fact-id';
4
4
 
5
- interface LinkInput {
5
+ interface RelationInput {
6
6
  readonly source: ItemId;
7
7
  readonly target: ItemId;
8
8
  }
9
9
 
10
- export function buildMockLinkChange(input: LinkInput): StoreChange {
11
- const type = brandSchemas.linkTypeName.parse('blocks');
10
+ export function buildMockRelationChange(input: RelationInput): StoreChange {
11
+ const type = brandSchemas.relationTypeName.parse('blocks');
12
12
  const addedAt = brandSchemas.instant.parse(3500);
13
13
 
14
14
  return {
@@ -16,7 +16,7 @@ export function buildMockLinkChange(input: LinkInput): StoreChange {
16
16
  writes: [
17
17
  {
18
18
  op: 'insert',
19
- table: 'links',
19
+ table: 'relations',
20
20
  row: {
21
21
  source: input.source,
22
22
  target: input.target,
@@ -30,8 +30,8 @@ export function buildMockLinkChange(input: LinkInput): StoreChange {
30
30
  facts: [
31
31
  {
32
32
  id: buildMockFactId(),
33
- type: 'boxxy.link.added',
34
- entity: `boxxy:link:${input.source}:${type}:${input.target}`,
33
+ type: 'boxxy.relation.added',
34
+ entity: `boxxy:item:${input.source}`,
35
35
  actor: 'boxxy:owner:local',
36
36
  payload: { source: input.source, target: input.target, type },
37
37
  },
@@ -0,0 +1,19 @@
1
+ import type { SessionReading } from '@boxxy/model';
2
+ import { brandSchemas } from '@boxxy/model';
3
+
4
+ type RunningReading = Extract<SessionReading, { kind: 'running' }>;
5
+
6
+ // A working session with an agent session ID, no caller and no usage limit, active at time 0.
7
+ export function buildMockRunningReading(overrides: Partial<RunningReading> = {}): RunningReading {
8
+ return {
9
+ kind: 'running',
10
+ atcSession: brandSchemas.atcSessionId.parse('atc-1'),
11
+ agentSession: brandSchemas.agentSessionId.parse('agent-1'),
12
+ caller: null,
13
+ attention: 'working',
14
+ lastActivityAt: brandSchemas.instant.parse(0),
15
+ lastOwnerAt: brandSchemas.instant.parse(0),
16
+ usageLimitResetsAt: null,
17
+ ...overrides,
18
+ };
19
+ }
@@ -3,15 +3,18 @@ import type { AttemptRow, StoreChange } from '@boxxy/model';
3
3
  import { buildMockFactId } from '@boxxy/model/test-utils/build-mock-fact-id';
4
4
 
5
5
  interface SettleInput {
6
- // the attempt as claimed, with the slot and slot gen its take got
7
6
  readonly attempt: AttemptRow;
8
7
  readonly state: 'succeeded' | 'failed';
9
8
  }
10
9
 
10
+ // A settle under the live lease and hold generations: it releases the lease and the seats. A
11
+ // succeeded attempt ends `built`; a failed one ends `lost` with `closeout-missing`.
11
12
  export function buildMockSettleChange(input: SettleInput): StoreChange {
12
13
  const attempt = input.attempt;
13
14
  const endedAt = brandSchemas.instant.parse(3000);
14
- const failure = input.state === 'failed' ? 'closeout-missing' : null;
15
+ const isSucceeded = input.state === 'succeeded';
16
+ const failure = isSucceeded ? null : 'closeout-missing';
17
+ const outcome = isSucceeded ? brandSchemas.outcomeName.parse('built') : 'lost';
15
18
 
16
19
  return {
17
20
  at: endedAt,
@@ -19,7 +22,7 @@ export function buildMockSettleChange(input: SettleInput): StoreChange {
19
22
  item: attempt.item,
20
23
  phase: attempt.phase,
21
24
  gen: attempt.leaseGen,
22
- slot: { pool: attempt.pool, slot: attempt.slot, gen: attempt.slotGen },
25
+ holdGen: attempt.holdGen,
23
26
  },
24
27
  writes: [
25
28
  {
@@ -27,7 +30,7 @@ export function buildMockSettleChange(input: SettleInput): StoreChange {
27
30
  table: 'attempts',
28
31
  key: { id: attempt.id },
29
32
  expect: { state: attempt.state },
30
- set: { state: input.state, failure, endedAt },
33
+ set: { state: input.state, failure, outcome, endedAt },
31
34
  },
32
35
  {
33
36
  op: 'update',
@@ -36,21 +39,30 @@ export function buildMockSettleChange(input: SettleInput): StoreChange {
36
39
  expect: { releasedAt: null },
37
40
  set: { releasedAt: endedAt },
38
41
  },
39
- { op: 'release-slot', pool: attempt.pool, slot: attempt.slot, holder: attempt.id },
42
+ { op: 'release-seats', release: { attempt: attempt.id, holdGen: attempt.holdGen } },
40
43
  ],
41
44
  facts: [
42
45
  {
43
46
  id: buildMockFactId(),
44
47
  type: 'boxxy.attempt.settled',
45
- entity: `boxxy:attempt:${attempt.id}`,
48
+ entity: `boxxy:item:${attempt.item}`,
46
49
  actor: `boxxy:runner:${attempt.runner}`,
47
50
  payload: {
51
+ attempt: attempt.id,
52
+ phase: attempt.phase,
53
+ round: attempt.round,
48
54
  state: input.state,
49
55
  failure,
56
+ outcome,
57
+ returnedOutcome: null,
58
+ closing: null,
59
+ asleep: false,
60
+ sessionStopped: true,
50
61
  endedAt,
51
62
  criteria: [],
52
63
  matched: [],
53
64
  frictionDropped: 0,
65
+ skippedEffects: [],
54
66
  },
55
67
  },
56
68
  ],
@@ -1,11 +1,18 @@
1
1
  import { brandSchemas } from '@boxxy/model';
2
- import type { AttemptRow, StoreChange } from '@boxxy/model';
2
+ import type { AttemptRow, CallerIdentity, StoreChange } from '@boxxy/model';
3
3
  import { buildMockFactId } from '@boxxy/model/test-utils/build-mock-fact-id';
4
+ import invariant from 'tiny-invariant';
4
5
 
5
- export function buildMockStartChange(attempt: AttemptRow): StoreChange {
6
- const atcSession = brandSchemas.atcSessionId.parse('atc-session-1');
6
+ // The start of a `starting` attempt on its own atc session, with the caller the worker reported.
7
+ export function buildMockStartChange(
8
+ attempt: AttemptRow,
9
+ caller: CallerIdentity | null = null,
10
+ ): StoreChange {
11
+ const atcSession = attempt.atcSession;
7
12
  const startedAt = brandSchemas.instant.parse(2500);
8
13
 
14
+ invariant(atcSession !== null, 'a started attempt names its atc session');
15
+
9
16
  return {
10
17
  at: startedAt,
11
18
  under: { item: attempt.item, phase: attempt.phase, gen: attempt.leaseGen },
@@ -15,16 +22,16 @@ export function buildMockStartChange(attempt: AttemptRow): StoreChange {
15
22
  table: 'attempts',
16
23
  key: { id: attempt.id },
17
24
  expect: { state: 'starting' },
18
- set: { state: 'running', atcSession, startedAt },
25
+ set: { state: 'running', atcSession, caller, startedAt },
19
26
  },
20
27
  ],
21
28
  facts: [
22
29
  {
23
30
  id: buildMockFactId(),
24
31
  type: 'boxxy.attempt.started',
25
- entity: `boxxy:attempt:${attempt.id}`,
32
+ entity: `boxxy:item:${attempt.item}`,
26
33
  actor: `boxxy:runner:${attempt.runner}`,
27
- payload: { atcSession },
34
+ payload: { attempt: attempt.id, atcSession, resumeFallback: false, caller },
28
35
  },
29
36
  ],
30
37
  };