@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.
- package/dist/attempts/attempt-machine.d.ts +804 -0
- package/dist/attempts/attempt-moves.d.ts +2 -0
- package/dist/attempts/bind-attempt-session.d.ts +14 -0
- package/dist/attempts/build-attempt-change.d.ts +73 -0
- package/dist/attempts/build-attempt-fact.d.ts +3 -0
- package/dist/attempts/end-item-attempts.d.ts +18 -0
- package/dist/attempts/is-same-guard.d.ts +5 -0
- package/dist/attempts/pick-call-attempt.d.ts +10 -0
- package/dist/attempts/stop-stray-session.d.ts +11 -0
- package/dist/attempts/types.d.ts +142 -0
- package/dist/attempts/write-attempt-move.d.ts +7 -0
- package/dist/attempts/write-session-bind.d.ts +3 -0
- package/dist/claims/build-snapshot-hash.d.ts +2 -0
- package/dist/claims/claim-next.d.ts +6 -0
- package/dist/claims/pick-kept-session.d.ts +9 -0
- package/dist/claims/request-wake.d.ts +3 -0
- package/dist/claims/resume-claim.d.ts +3 -0
- package/dist/claims/start-claim.d.ts +3 -0
- package/dist/claims/types.d.ts +44 -0
- package/dist/closeouts/build-settle-plans.d.ts +17 -0
- package/dist/closeouts/close-out-attempt.d.ts +3 -0
- package/dist/closeouts/effect-handlers.d.ts +2 -0
- package/dist/closeouts/pick-settlement.d.ts +14 -0
- package/dist/closeouts/settle-attempt.d.ts +3 -0
- package/dist/closeouts/types.d.ts +50 -0
- package/dist/index.d.ts +38 -0
- package/dist/notices/constants.d.ts +4 -0
- package/dist/notices/create-null-notifier.d.ts +2 -0
- package/dist/notices/send-notices.d.ts +2 -0
- package/dist/notices/types.d.ts +11 -0
- package/dist/outbox/build-backoff-ms.d.ts +2 -0
- package/dist/outbox/build-initial-sender-state.d.ts +2 -0
- package/dist/outbox/build-outbox-status.d.ts +15 -0
- package/dist/outbox/constants.d.ts +2 -0
- package/dist/outbox/measure-wire-bytes.d.ts +2 -0
- package/dist/outbox/pick-sender-move.d.ts +10 -0
- package/dist/outbox/run-sender-once.d.ts +2 -0
- package/dist/outbox/take-batch.d.ts +3 -0
- package/dist/outbox/types.d.ts +61 -0
- package/dist/pull-requests/build-link-change.d.ts +11 -0
- package/dist/pull-requests/build-state-fact.d.ts +8 -0
- package/dist/pull-requests/collect-attempt-trailers.d.ts +2 -0
- package/dist/pull-requests/collect-seen-state.d.ts +7 -0
- package/dist/pull-requests/constants.d.ts +3 -0
- package/dist/pull-requests/link-pull-request.d.ts +2 -0
- package/dist/pull-requests/parse-pull-request-url.d.ts +2 -0
- package/dist/pull-requests/types.d.ts +37 -0
- package/dist/pull-requests/watch-pull-requests.d.ts +2 -0
- package/dist/readings/act-on-reading.d.ts +3 -0
- package/dist/readings/find-waiting-since.d.ts +9 -0
- package/dist/readings/pick-reading-action.d.ts +2 -0
- package/dist/readings/types.d.ts +79 -0
- package/dist/sessions/build-keep-writes.d.ts +9 -0
- package/dist/sessions/build-kept-clear.d.ts +2 -0
- package/dist/sessions/forget-sessions.d.ts +2 -0
- package/dist/sessions/is-kept-due.d.ts +2 -0
- package/dist/sessions/resume-kept-session.d.ts +6 -0
- package/dist/sessions/types.d.ts +19 -0
- package/dist/test-utils/apply-memory-change.d.ts +3 -0
- package/dist/test-utils/build-memory-reader.d.ts +3 -0
- package/dist/test-utils/build-mock-claim-change.d.ts +2 -2
- package/dist/test-utils/build-mock-new-id.d.ts +2 -0
- package/dist/test-utils/build-mock-note-change.d.ts +2 -0
- package/dist/test-utils/build-mock-pull-request-change.d.ts +1 -0
- package/dist/test-utils/{build-mock-link-change.d.ts → build-mock-relation-change.d.ts} +2 -2
- package/dist/test-utils/build-mock-running-reading.d.ts +6 -0
- package/dist/test-utils/build-mock-start-change.d.ts +2 -2
- package/dist/test-utils/claim-store-close-cases.d.ts +2 -0
- package/dist/test-utils/claim-store-copy-cases.d.ts +2 -0
- package/dist/test-utils/claim-store-outbox-cases.d.ts +2 -0
- package/dist/test-utils/claim-store-race-cases.d.ts +2 -0
- package/dist/test-utils/claim-store-seat-cases.d.ts +2 -0
- package/dist/test-utils/claim-store-session-cases.d.ts +2 -0
- package/dist/test-utils/collect-memory-limit-fills.d.ts +3 -0
- package/dist/test-utils/compare-text.d.ts +1 -0
- package/dist/test-utils/create-fake-backoff.d.ts +2 -0
- package/dist/test-utils/create-fake-clock.d.ts +5 -0
- package/dist/test-utils/create-fake-fact-sink.d.ts +8 -0
- package/dist/test-utils/create-fake-forge.d.ts +17 -0
- package/dist/test-utils/create-fake-worker.d.ts +42 -0
- package/dist/test-utils/create-memory-claim-store.d.ts +2 -2
- package/dist/test-utils/create-test-dispatch.d.ts +46 -0
- package/dist/test-utils/forge-contract.d.ts +15 -0
- package/dist/test-utils/is-same-held-seat.d.ts +2 -0
- package/dist/test-utils/types.d.ts +12 -2
- package/dist/test-utils/worker-contract.d.ts +14 -0
- package/dist/timeouts.d.ts +2 -0
- package/dist/types.d.ts +13 -0
- package/package.json +10 -3
- package/src/attempts/attempt-machine.ts +147 -0
- package/src/attempts/attempt-moves.ts +218 -0
- package/src/attempts/bind-attempt-session.ts +61 -0
- package/src/attempts/build-attempt-change.ts +540 -0
- package/src/attempts/build-attempt-fact.ts +135 -0
- package/src/attempts/end-item-attempts.ts +95 -0
- package/src/attempts/is-same-guard.ts +22 -0
- package/src/attempts/pick-call-attempt.ts +32 -0
- package/src/attempts/stop-stray-session.ts +48 -0
- package/src/attempts/types.ts +231 -0
- package/src/attempts/write-attempt-move.ts +41 -0
- package/src/attempts/write-session-bind.ts +47 -0
- package/src/claims/build-snapshot-hash.ts +9 -0
- package/src/claims/claim-next.ts +306 -0
- package/src/claims/pick-kept-session.ts +41 -0
- package/src/claims/request-wake.ts +17 -0
- package/src/claims/resume-claim.ts +56 -0
- package/src/claims/start-claim.ts +99 -0
- package/src/claims/types.ts +67 -0
- package/src/closeouts/build-settle-plans.ts +173 -0
- package/src/closeouts/close-out-attempt.ts +156 -0
- package/src/closeouts/effect-handlers.ts +232 -0
- package/src/closeouts/pick-settlement.ts +80 -0
- package/src/closeouts/settle-attempt.ts +161 -0
- package/src/closeouts/types.ts +87 -0
- package/src/index.ts +61 -0
- package/src/notices/constants.ts +7 -0
- package/src/notices/create-null-notifier.ts +6 -0
- package/src/notices/send-notices.ts +41 -0
- package/src/notices/types.ts +14 -0
- package/src/outbox/build-backoff-ms.ts +14 -0
- package/src/outbox/build-initial-sender-state.ts +14 -0
- package/src/outbox/build-outbox-status.ts +43 -0
- package/src/outbox/constants.ts +15 -0
- package/src/outbox/measure-wire-bytes.ts +31 -0
- package/src/outbox/pick-sender-move.ts +37 -0
- package/src/outbox/run-sender-once.ts +174 -0
- package/src/outbox/take-batch.ts +35 -0
- package/src/outbox/types.ts +76 -0
- package/src/pull-requests/build-link-change.ts +95 -0
- package/src/pull-requests/build-state-fact.ts +39 -0
- package/src/pull-requests/collect-attempt-trailers.ts +20 -0
- package/src/pull-requests/collect-seen-state.ts +19 -0
- package/src/pull-requests/constants.ts +5 -0
- package/src/pull-requests/link-pull-request.ts +119 -0
- package/src/pull-requests/parse-pull-request-url.ts +30 -0
- package/src/pull-requests/types.ts +63 -0
- package/src/pull-requests/watch-pull-requests.ts +308 -0
- package/src/readings/act-on-reading.ts +318 -0
- package/src/readings/find-waiting-since.ts +46 -0
- package/src/readings/pick-reading-action.ts +315 -0
- package/src/readings/types.ts +98 -0
- package/src/sessions/build-keep-writes.ts +55 -0
- package/src/sessions/build-kept-clear.ts +12 -0
- package/src/sessions/forget-sessions.ts +106 -0
- package/src/sessions/is-kept-due.ts +27 -0
- package/src/sessions/resume-kept-session.ts +25 -0
- package/src/sessions/types.ts +39 -0
- package/src/test-utils/apply-memory-change.ts +252 -0
- package/src/test-utils/build-memory-reader.ts +364 -0
- package/src/test-utils/build-mock-bind-change.ts +18 -11
- package/src/test-utils/build-mock-claim-change.ts +18 -8
- package/src/test-utils/build-mock-file-item-change.ts +3 -1
- package/src/test-utils/build-mock-new-id.ts +12 -0
- package/src/test-utils/build-mock-note-change.ts +18 -0
- package/src/test-utils/build-mock-pause-change.ts +2 -10
- package/src/test-utils/build-mock-pull-request-change.ts +19 -9
- package/src/test-utils/{build-mock-link-change.ts → build-mock-relation-change.ts} +6 -6
- package/src/test-utils/build-mock-running-reading.ts +19 -0
- package/src/test-utils/build-mock-settle-change.ts +18 -6
- package/src/test-utils/build-mock-start-change.ts +13 -6
- package/src/test-utils/claim-store-attempt-reader-cases.ts +163 -133
- package/src/test-utils/claim-store-claim-cases.ts +168 -85
- package/src/test-utils/claim-store-close-cases.ts +95 -0
- package/src/test-utils/claim-store-contract.ts +12 -2
- package/src/test-utils/claim-store-copy-cases.ts +100 -0
- package/src/test-utils/claim-store-exclusive-cases.ts +65 -19
- package/src/test-utils/claim-store-guard-cases.ts +92 -82
- package/src/test-utils/claim-store-item-reader-cases.ts +291 -77
- package/src/test-utils/claim-store-outbox-cases.ts +281 -0
- package/src/test-utils/claim-store-race-cases.ts +150 -0
- package/src/test-utils/claim-store-rollback-cases.ts +50 -50
- package/src/test-utils/claim-store-seat-cases.ts +270 -0
- package/src/test-utils/claim-store-session-cases.ts +289 -0
- package/src/test-utils/collect-memory-limit-fills.ts +15 -0
- package/src/test-utils/compare-text.ts +8 -0
- package/src/test-utils/create-fake-backoff.ts +16 -0
- package/src/test-utils/create-fake-clock.ts +20 -0
- package/src/test-utils/create-fake-fact-sink.ts +74 -0
- package/src/test-utils/create-fake-forge.ts +117 -0
- package/src/test-utils/create-fake-worker.ts +303 -0
- package/src/test-utils/create-memory-claim-store.ts +73 -484
- package/src/test-utils/create-test-dispatch.ts +597 -0
- package/src/test-utils/forge-contract.ts +171 -0
- package/src/test-utils/is-same-held-seat.ts +11 -0
- package/src/test-utils/types.ts +14 -2
- package/src/test-utils/worker-contract.ts +192 -0
- package/src/timeouts.ts +17 -0
- package/src/types.ts +32 -0
- package/dist/test-utils/claim-store-pool-cases.d.ts +0 -2
- 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
|
-
|
|
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
|
-
{
|
|
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:
|
|
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:
|
|
34
|
+
entity: `boxxy:item:${attempt.item}`,
|
|
28
35
|
actor: `boxxy:runner:${attempt.runner}`,
|
|
29
36
|
payload: {
|
|
30
|
-
|
|
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
|
-
|
|
35
|
-
|
|
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:
|
|
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 {
|
|
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
|
|
17
|
+
const number = input.number ?? 7;
|
|
16
18
|
|
|
17
|
-
const pullRequest =
|
|
19
|
+
const pullRequest = buildMockV1PullRequestRow({
|
|
18
20
|
repo: brandSchemas.repoName.parse('acme/lamps'),
|
|
19
|
-
number
|
|
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: '
|
|
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.
|
|
47
|
-
entity: `boxxy:
|
|
49
|
+
type: 'boxxy.pull_request.linked',
|
|
50
|
+
entity: `boxxy:item:${attempt.item}`,
|
|
48
51
|
actor: `boxxy:hook:${attempt.id}`,
|
|
49
|
-
payload: {
|
|
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
|
|
5
|
+
interface RelationInput {
|
|
6
6
|
readonly source: ItemId;
|
|
7
7
|
readonly target: ItemId;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export function
|
|
11
|
-
const type = brandSchemas.
|
|
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: '
|
|
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.
|
|
34
|
-
entity: `boxxy:
|
|
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
|
|
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
|
-
|
|
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-
|
|
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:
|
|
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
|
-
|
|
6
|
-
|
|
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:
|
|
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
|
};
|