@namzu/sdk 20.3.0 → 21.0.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.
Files changed (111) hide show
  1. package/CHANGELOG.md +321 -0
  2. package/dist/bridge/sse/mapper.d.ts +19 -0
  3. package/dist/bridge/sse/mapper.d.ts.map +1 -1
  4. package/dist/bridge/sse/mapper.js +9 -1
  5. package/dist/bridge/sse/mapper.js.map +1 -1
  6. package/dist/contracts/schemas.d.ts +10 -10
  7. package/dist/manager/run/persistence.d.ts +26 -0
  8. package/dist/manager/run/persistence.d.ts.map +1 -1
  9. package/dist/manager/run/persistence.js +40 -0
  10. package/dist/manager/run/persistence.js.map +1 -1
  11. package/dist/public-runtime.d.ts +5 -0
  12. package/dist/public-runtime.d.ts.map +1 -1
  13. package/dist/public-runtime.js +21 -0
  14. package/dist/public-runtime.js.map +1 -1
  15. package/dist/run/drain.d.ts +194 -0
  16. package/dist/run/drain.d.ts.map +1 -0
  17. package/dist/run/drain.js +228 -0
  18. package/dist/run/drain.js.map +1 -0
  19. package/dist/run/index.d.ts +2 -0
  20. package/dist/run/index.d.ts.map +1 -1
  21. package/dist/run/index.js +1 -0
  22. package/dist/run/index.js.map +1 -1
  23. package/dist/runtime/query/checkpoint.d.ts +27 -1
  24. package/dist/runtime/query/checkpoint.d.ts.map +1 -1
  25. package/dist/runtime/query/checkpoint.js +34 -4
  26. package/dist/runtime/query/checkpoint.js.map +1 -1
  27. package/dist/runtime/query/events.d.ts +12 -0
  28. package/dist/runtime/query/events.d.ts.map +1 -1
  29. package/dist/runtime/query/events.js +61 -3
  30. package/dist/runtime/query/events.js.map +1 -1
  31. package/dist/runtime/query/index.d.ts +57 -1
  32. package/dist/runtime/query/index.d.ts.map +1 -1
  33. package/dist/runtime/query/index.js +36 -0
  34. package/dist/runtime/query/index.js.map +1 -1
  35. package/dist/runtime/query/resume-run.d.ts +34 -1
  36. package/dist/runtime/query/resume-run.d.ts.map +1 -1
  37. package/dist/runtime/query/resume-run.js +16 -3
  38. package/dist/runtime/query/resume-run.js.map +1 -1
  39. package/dist/store/index.d.ts +2 -2
  40. package/dist/store/index.d.ts.map +1 -1
  41. package/dist/store/index.js +2 -2
  42. package/dist/store/index.js.map +1 -1
  43. package/dist/store/run/checkpoint-disk.d.ts +18 -2
  44. package/dist/store/run/checkpoint-disk.d.ts.map +1 -1
  45. package/dist/store/run/checkpoint-disk.js +50 -5
  46. package/dist/store/run/checkpoint-disk.js.map +1 -1
  47. package/dist/store/run/checkpoint-memory.d.ts +22 -2
  48. package/dist/store/run/checkpoint-memory.d.ts.map +1 -1
  49. package/dist/store/run/checkpoint-memory.js +99 -4
  50. package/dist/store/run/checkpoint-memory.js.map +1 -1
  51. package/dist/store/run/claim-disk.d.ts +130 -0
  52. package/dist/store/run/claim-disk.d.ts.map +1 -0
  53. package/dist/store/run/claim-disk.js +550 -0
  54. package/dist/store/run/claim-disk.js.map +1 -0
  55. package/dist/store/run/conformance.d.ts +159 -0
  56. package/dist/store/run/conformance.d.ts.map +1 -0
  57. package/dist/store/run/conformance.js +451 -0
  58. package/dist/store/run/conformance.js.map +1 -0
  59. package/dist/store/run/disk.d.ts +30 -2
  60. package/dist/store/run/disk.d.ts.map +1 -1
  61. package/dist/store/run/disk.js +101 -0
  62. package/dist/store/run/disk.js.map +1 -1
  63. package/dist/store/run/listing.d.ts +44 -1
  64. package/dist/store/run/listing.d.ts.map +1 -1
  65. package/dist/store/run/listing.js +92 -1
  66. package/dist/store/run/listing.js.map +1 -1
  67. package/dist/store/run/memory.d.ts +5 -4
  68. package/dist/store/run/memory.d.ts.map +1 -1
  69. package/dist/store/run/memory.js +30 -1
  70. package/dist/store/run/memory.js.map +1 -1
  71. package/dist/types/doctor/check.d.ts +28 -2
  72. package/dist/types/doctor/check.d.ts.map +1 -1
  73. package/dist/types/run/checkpoint-store.d.ts +178 -2
  74. package/dist/types/run/checkpoint-store.d.ts.map +1 -1
  75. package/dist/types/run/event-cursor.d.ts +90 -0
  76. package/dist/types/run/event-cursor.d.ts.map +1 -0
  77. package/dist/types/run/event-cursor.js +47 -0
  78. package/dist/types/run/event-cursor.js.map +1 -0
  79. package/dist/types/run/events.d.ts +71 -1
  80. package/dist/types/run/events.d.ts.map +1 -1
  81. package/dist/types/run/events.js.map +1 -1
  82. package/dist/types/run/index.d.ts +1 -0
  83. package/dist/types/run/index.d.ts.map +1 -1
  84. package/dist/types/run/index.js +1 -0
  85. package/dist/types/run/index.js.map +1 -1
  86. package/dist/types/run/store.d.ts +41 -1
  87. package/dist/types/run/store.d.ts.map +1 -1
  88. package/package.json +6 -1
  89. package/src/bridge/sse/mapper.ts +28 -1
  90. package/src/manager/run/persistence.ts +43 -0
  91. package/src/public-runtime.ts +27 -0
  92. package/src/run/drain.ts +393 -0
  93. package/src/run/index.ts +3 -0
  94. package/src/runtime/query/checkpoint.ts +42 -5
  95. package/src/runtime/query/events.ts +68 -4
  96. package/src/runtime/query/index.ts +113 -1
  97. package/src/runtime/query/resume-run.ts +77 -12
  98. package/src/store/index.ts +5 -1
  99. package/src/store/run/checkpoint-disk.ts +70 -5
  100. package/src/store/run/checkpoint-memory.ts +118 -3
  101. package/src/store/run/claim-disk.ts +593 -0
  102. package/src/store/run/conformance.ts +705 -0
  103. package/src/store/run/disk.ts +106 -2
  104. package/src/store/run/listing.ts +116 -1
  105. package/src/store/run/memory.ts +35 -5
  106. package/src/types/doctor/check.ts +28 -2
  107. package/src/types/run/checkpoint-store.ts +189 -2
  108. package/src/types/run/event-cursor.ts +118 -0
  109. package/src/types/run/events.ts +80 -3
  110. package/src/types/run/index.ts +1 -0
  111. package/src/types/run/store.ts +43 -1
@@ -0,0 +1,159 @@
1
+ /**
2
+ * The checkpoint-store contract, as a suite a host can run against its own
3
+ * backend.
4
+ *
5
+ * ## Why this ships rather than staying a test
6
+ *
7
+ * {@link import('./checkpoint-memory.js').InMemoryCheckpointStore} says in its
8
+ * own doc comment that it is "the reference a host reads when writing a
9
+ * backend of its own". That claim was unbacked, and the cost of it was not
10
+ * hypothetical: the two shipped stores disagreed at the enforcement point —
11
+ * the in-memory one accepted a write from a holder that had been superseded
12
+ * and then released around, the disk one refused it — and the class documented
13
+ * as the reference was the one carrying the defect. Reading a reference cannot
14
+ * tell you that. Running it can.
15
+ *
16
+ * The rules below are the ones a claim depends on and no type can state:
17
+ * exclusivity, expiry, that a superseded write is refused, and that a listing
18
+ * answers for the tenant it was asked about and no other. Those are exactly
19
+ * the points at which the two built-in implementations already diverged.
20
+ *
21
+ * ## Why it takes its runner as an argument
22
+ *
23
+ * `describe`, `it` and `expect` come in through
24
+ * {@link CheckpointStoreConformanceOptions}. The suite therefore imports no
25
+ * test framework, `@namzu/sdk` gains no test dependency from publishing it,
26
+ * and a host on a different runner can still run it by handing over three
27
+ * functions of the shapes below.
28
+ *
29
+ * It also buys the one property that separates this file from decoration: a
30
+ * caller can pass a *recording* `describe`/`it` and run the whole contract as
31
+ * ordinary code, which is how `conformance-fails-a-wrong-store.test.ts`
32
+ * establishes that a deliberately broken store fails it.
33
+ *
34
+ * ## Consuming it
35
+ *
36
+ * See `docs/sdk/runtime/checkpoint-store-conformance.md`. In short:
37
+ *
38
+ * ```typescript
39
+ * import { describe, expect, it } from 'your-runner'
40
+ * import { defineCheckpointStoreConformance } from '@namzu/sdk/testing'
41
+ *
42
+ * defineCheckpointStoreConformance({
43
+ * describe, it, expect,
44
+ * label: 'my-backend',
45
+ * contractVersion: 1,
46
+ * capabilities: { claims: true, listing: true, multiTenant: true },
47
+ * makeStore: (binding) => ({ store: new MyStore(binding) }),
48
+ * })
49
+ * ```
50
+ *
51
+ * ## The assertions are public API
52
+ *
53
+ * Once a host wires this in, every assertion below is something their build
54
+ * fails on. Adding one is therefore a breaking change for them even though it
55
+ * adds no export — so a new rule arrives behind a raised
56
+ * {@link CHECKPOINT_STORE_CONTRACT_VERSION} and a `major`, and the version
57
+ * check is what turns "your backend silently satisfies an older, smaller
58
+ * contract" into a named failure.
59
+ */
60
+ import type { ProjectId, SessionId, TenantId } from '../../types/ids/index.js';
61
+ import type { CheckpointStore } from '../../types/run/checkpoint-store.js';
62
+ /**
63
+ * Which revision of the contract the assertions in this file express.
64
+ *
65
+ * A host DECLARES the version it wrote its backend against, as a literal in
66
+ * its own test file, and the suite's first case compares the two. Re-exporting
67
+ * this constant into that slot defeats the check — the point is that the
68
+ * number is frozen in the host's source at the moment they wrote the backend,
69
+ * so upgrading `@namzu/sdk` past a contract revision fails with a sentence
70
+ * naming both numbers instead of a scatter of assertion failures whose common
71
+ * cause is not obvious.
72
+ *
73
+ * Raised only together with a `major`, and only when an assertion is ADDED or
74
+ * TIGHTENED. Adding a case behind a new optional capability flag does not
75
+ * raise it: a host that does not declare the capability never runs the case.
76
+ */
77
+ export declare const CHECKPOINT_STORE_CONTRACT_VERSION = 1;
78
+ /**
79
+ * What a backend can do, so the suite runs the cases it is answerable for and
80
+ * no others.
81
+ *
82
+ * Every field is required rather than defaulted. A capability that defaults to
83
+ * `false` lets a host skip a whole section by forgetting a key, and a suite you
84
+ * can opt out of by omission is a suite that reports a pass it did not
85
+ * establish.
86
+ */
87
+ export interface CheckpointStoreCapabilities {
88
+ /**
89
+ * The store implements `claimRun` / `releaseRun` and enforces the fence at
90
+ * `writeCheckpoint`. `false` skips every claim case — appropriate only for
91
+ * a single-writer backend, which is a deployment shape, not a shortcut.
92
+ */
93
+ readonly claims: boolean;
94
+ /** The store implements `listDurableRuns`. */
95
+ readonly listing: boolean;
96
+ /**
97
+ * One instance can hold more than one tenant's runs.
98
+ *
99
+ * `false` for a store whose addressing fixes the tenant — the built-in disk
100
+ * layout has no tenant segment in it, so a second tenant is a second store.
101
+ * Such a backend still answers the isolation case that CAN be put to it: a
102
+ * listing for a tenant it does not hold returns nothing.
103
+ */
104
+ readonly multiTenant: boolean;
105
+ }
106
+ /** The attribution the suite addresses its runs under. */
107
+ export interface CheckpointStoreBinding {
108
+ readonly tenantId: TenantId;
109
+ readonly projectId: ProjectId;
110
+ readonly sessionId: SessionId;
111
+ }
112
+ /** A store to test, plus whatever teardown producing it required. */
113
+ export interface CheckpointStoreHandle {
114
+ readonly store: CheckpointStore;
115
+ /** Called after each case, pass or fail. */
116
+ dispose?(): void | Promise<void>;
117
+ }
118
+ /**
119
+ * Build a store bound to `binding`. Called once per case, so no case can be
120
+ * affected by another's writes — the suite never assumes a shared instance and
121
+ * never cleans one.
122
+ */
123
+ export type MakeCheckpointStore = (binding: CheckpointStoreBinding) => CheckpointStoreHandle | Promise<CheckpointStoreHandle>;
124
+ /** The assertions the suite uses, and nothing more. */
125
+ export interface ConformanceAssertion {
126
+ toBe(expected: unknown): void;
127
+ toEqual(expected: unknown): void;
128
+ toBeGreaterThan(expected: number): void;
129
+ toMatch(expected: RegExp): void;
130
+ }
131
+ /** Shape of the `expect` a runner supplies. */
132
+ export type ConformanceExpect = (actual: unknown) => ConformanceAssertion;
133
+ /** Shape of the `it` a runner supplies. */
134
+ export type ConformanceIt = (name: string, body: () => Promise<void>) => unknown;
135
+ /** Shape of the `describe` a runner supplies. */
136
+ export type ConformanceDescribe = (name: string, body: () => void) => unknown;
137
+ /** Everything {@link defineCheckpointStoreConformance} needs. */
138
+ export interface CheckpointStoreConformanceOptions {
139
+ readonly describe: ConformanceDescribe;
140
+ readonly it: ConformanceIt;
141
+ readonly expect: ConformanceExpect;
142
+ /**
143
+ * The contract revision this backend was written against, written as a
144
+ * literal. See {@link CHECKPOINT_STORE_CONTRACT_VERSION}.
145
+ */
146
+ readonly contractVersion: number;
147
+ readonly capabilities: CheckpointStoreCapabilities;
148
+ readonly makeStore: MakeCheckpointStore;
149
+ /** Names the backend in test output. Defaults to `checkpoint store`. */
150
+ readonly label?: string;
151
+ }
152
+ /**
153
+ * Register the checkpoint-store contract against one backend.
154
+ *
155
+ * Call it once per backend. It registers cases through the supplied `describe`
156
+ * and `it`; it does not run them.
157
+ */
158
+ export declare function defineCheckpointStoreConformance(options: CheckpointStoreConformanceOptions): void;
159
+ //# sourceMappingURL=conformance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E,OAAO,GAAG,IAAI,CAAA;IAChC,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvC,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CAC/B;AAED,+CAA+C;AAC/C,MAAM,MAAM,iBAAiB,GAAG,CAAC,MAAM,EAAE,OAAO,KAAK,oBAAoB,CAAA;AACzE,2CAA2C;AAC3C,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,CAAA;AAChF,iDAAiD;AACjD,MAAM,MAAM,mBAAmB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,IAAI,KAAK,OAAO,CAAA;AAE7E,iEAAiE;AACjE,MAAM,WAAW,iCAAiC;IACjD,QAAQ,CAAC,QAAQ,EAAE,mBAAmB,CAAA;IACtC,QAAQ,CAAC,EAAE,EAAE,aAAa,CAAA;IAC1B,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAA;IAClC;;;OAGG;IACH,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;IAChC,QAAQ,CAAC,YAAY,EAAE,2BAA2B,CAAA;IAClD,QAAQ,CAAC,SAAS,EAAE,mBAAmB,CAAA;IACvC,wEAAwE;IACxE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CACvB;AAuED;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAAC,OAAO,EAAE,iCAAiC,GAAG,IAAI,CA+cjG"}
@@ -0,0 +1,451 @@
1
+ /**
2
+ * The checkpoint-store contract, as a suite a host can run against its own
3
+ * backend.
4
+ *
5
+ * ## Why this ships rather than staying a test
6
+ *
7
+ * {@link import('./checkpoint-memory.js').InMemoryCheckpointStore} says in its
8
+ * own doc comment that it is "the reference a host reads when writing a
9
+ * backend of its own". That claim was unbacked, and the cost of it was not
10
+ * hypothetical: the two shipped stores disagreed at the enforcement point —
11
+ * the in-memory one accepted a write from a holder that had been superseded
12
+ * and then released around, the disk one refused it — and the class documented
13
+ * as the reference was the one carrying the defect. Reading a reference cannot
14
+ * tell you that. Running it can.
15
+ *
16
+ * The rules below are the ones a claim depends on and no type can state:
17
+ * exclusivity, expiry, that a superseded write is refused, and that a listing
18
+ * answers for the tenant it was asked about and no other. Those are exactly
19
+ * the points at which the two built-in implementations already diverged.
20
+ *
21
+ * ## Why it takes its runner as an argument
22
+ *
23
+ * `describe`, `it` and `expect` come in through
24
+ * {@link CheckpointStoreConformanceOptions}. The suite therefore imports no
25
+ * test framework, `@namzu/sdk` gains no test dependency from publishing it,
26
+ * and a host on a different runner can still run it by handing over three
27
+ * functions of the shapes below.
28
+ *
29
+ * It also buys the one property that separates this file from decoration: a
30
+ * caller can pass a *recording* `describe`/`it` and run the whole contract as
31
+ * ordinary code, which is how `conformance-fails-a-wrong-store.test.ts`
32
+ * establishes that a deliberately broken store fails it.
33
+ *
34
+ * ## Consuming it
35
+ *
36
+ * See `docs/sdk/runtime/checkpoint-store-conformance.md`. In short:
37
+ *
38
+ * ```typescript
39
+ * import { describe, expect, it } from 'your-runner'
40
+ * import { defineCheckpointStoreConformance } from '@namzu/sdk/testing'
41
+ *
42
+ * defineCheckpointStoreConformance({
43
+ * describe, it, expect,
44
+ * label: 'my-backend',
45
+ * contractVersion: 1,
46
+ * capabilities: { claims: true, listing: true, multiTenant: true },
47
+ * makeStore: (binding) => ({ store: new MyStore(binding) }),
48
+ * })
49
+ * ```
50
+ *
51
+ * ## The assertions are public API
52
+ *
53
+ * Once a host wires this in, every assertion below is something their build
54
+ * fails on. Adding one is therefore a breaking change for them even though it
55
+ * adds no export — so a new rule arrives behind a raised
56
+ * {@link CHECKPOINT_STORE_CONTRACT_VERSION} and a `major`, and the version
57
+ * check is what turns "your backend silently satisfies an older, smaller
58
+ * contract" into a named failure.
59
+ */
60
+ import { claimRun, listDurableRuns, releaseRun } from './listing.js';
61
+ /**
62
+ * Which revision of the contract the assertions in this file express.
63
+ *
64
+ * A host DECLARES the version it wrote its backend against, as a literal in
65
+ * its own test file, and the suite's first case compares the two. Re-exporting
66
+ * this constant into that slot defeats the check — the point is that the
67
+ * number is frozen in the host's source at the moment they wrote the backend,
68
+ * so upgrading `@namzu/sdk` past a contract revision fails with a sentence
69
+ * naming both numbers instead of a scatter of assertion failures whose common
70
+ * cause is not obvious.
71
+ *
72
+ * Raised only together with a `major`, and only when an assertion is ADDED or
73
+ * TIGHTENED. Adding a case behind a new optional capability flag does not
74
+ * raise it: a host that does not declare the capability never runs the case.
75
+ */
76
+ export const CHECKPOINT_STORE_CONTRACT_VERSION = 1;
77
+ /** The tenant/project/session every case addresses unless it needs a second. */
78
+ const BINDING = {
79
+ tenantId: 'tnt_conformance',
80
+ projectId: 'prj_conformance',
81
+ sessionId: 'ses_conformance',
82
+ };
83
+ /** A tenant no backend under test holds runs for. */
84
+ const FOREIGN_TENANT = 'tnt_conformance_other';
85
+ /** Fixed instant, so every expiry in a case is judged against one clock. */
86
+ const NOW = 5_000_000;
87
+ const NO_COST = {
88
+ inputCostPer1M: 0,
89
+ outputCostPer1M: 0,
90
+ totalCost: 0,
91
+ cacheDiscount: 0,
92
+ };
93
+ let checkpointSeq = 0;
94
+ function checkpoint(runId) {
95
+ checkpointSeq += 1;
96
+ return {
97
+ id: `cp_conformance_${checkpointSeq}`,
98
+ runId: runId,
99
+ iteration: 1,
100
+ messages: [],
101
+ tokenUsage: {
102
+ promptTokens: 1,
103
+ completionTokens: 1,
104
+ totalTokens: 2,
105
+ cachedTokens: 0,
106
+ cacheWriteTokens: 0,
107
+ },
108
+ costInfo: NO_COST,
109
+ guardState: { iterationCount: 1, elapsedMs: 1 },
110
+ createdAt: NOW,
111
+ };
112
+ }
113
+ function runScope(binding, runId = 'run_conformance_a') {
114
+ return { ...binding, runId: runId };
115
+ }
116
+ /**
117
+ * Assert that `call` rejected with a message matching `pattern`.
118
+ *
119
+ * Written against `toMatch` rather than a runner's `rejects` helper so the
120
+ * suite needs no matcher beyond the four on {@link ConformanceAssertion}. A
121
+ * call that RESOLVES yields a sentence saying so, which is the diagnostic that
122
+ * matters: the failure this whole file exists for is a write that was accepted
123
+ * when it should have been refused.
124
+ */
125
+ async function expectRejection(expect, call, pattern) {
126
+ let message = '<the call resolved; no rejection was raised>';
127
+ try {
128
+ await call();
129
+ }
130
+ catch (error) {
131
+ message = error instanceof Error ? error.message : String(error);
132
+ }
133
+ expect(message).toMatch(pattern);
134
+ }
135
+ /**
136
+ * Register the checkpoint-store contract against one backend.
137
+ *
138
+ * Call it once per backend. It registers cases through the supplied `describe`
139
+ * and `it`; it does not run them.
140
+ */
141
+ export function defineCheckpointStoreConformance(options) {
142
+ const { describe, it, expect, capabilities, makeStore } = options;
143
+ const label = options.label ?? 'checkpoint store';
144
+ /**
145
+ * Run `body` against a store built for this case alone.
146
+ *
147
+ * `finally`, so a failing assertion still disposes — a suite that leaks a
148
+ * temp directory per failure makes a red run expensive to iterate on, and
149
+ * an expensive red run is one people stop running.
150
+ */
151
+ const withStore = (body) => async () => {
152
+ const handle = await makeStore(BINDING);
153
+ try {
154
+ await body(handle.store);
155
+ }
156
+ finally {
157
+ await handle.dispose?.();
158
+ }
159
+ };
160
+ describe(`${label} conformance`, () => {
161
+ it('declares the contract revision this suite implements', async () => {
162
+ // First case on purpose. When it fails, every case below it is
163
+ // answering a different contract than the backend was written for,
164
+ // and reading their failures as defects would send a host chasing
165
+ // bugs that are really a version skew.
166
+ //
167
+ // Both numbers ride in the COMPARED VALUES rather than in a
168
+ // sentence, because a runner truncates a long actual when it builds
169
+ // the failure message — measured, on the first draft of this, at 37
170
+ // characters, which cut off the very numbers the case exists to
171
+ // report. The guidance that would not fit lives on
172
+ // `CHECKPOINT_STORE_CONTRACT_VERSION`, which is where a reader of
173
+ // this failure is being sent anyway.
174
+ expect(`checkpoint-store contract v${options.contractVersion}`).toBe(`checkpoint-store contract v${CHECKPOINT_STORE_CONTRACT_VERSION}`);
175
+ });
176
+ if (capabilities.claims) {
177
+ describe('claim exclusivity', () => {
178
+ it('gives the run to the first taker and refuses the second', withStore(async (store) => {
179
+ const first = await claimRun(store, runScope(BINDING), {
180
+ holder: 'w1',
181
+ ttlMs: 60_000,
182
+ now: NOW,
183
+ });
184
+ const second = await claimRun(store, runScope(BINDING), {
185
+ holder: 'w2',
186
+ ttlMs: 60_000,
187
+ now: NOW,
188
+ });
189
+ expect(first?.holder).toBe('w1');
190
+ // `null`, not a throw: two readers on one queue is the
191
+ // ordinary case, and an exception would make the normal
192
+ // outcome look like a fault.
193
+ expect(second).toBe(null);
194
+ }));
195
+ it('advances the fence on renewal, so a stalled twin cannot write', withStore(async (store) => {
196
+ const first = await claimRun(store, runScope(BINDING), {
197
+ holder: 'w1',
198
+ ttlMs: 1_000,
199
+ now: NOW,
200
+ });
201
+ const renewed = await claimRun(store, runScope(BINDING), {
202
+ holder: 'w1',
203
+ ttlMs: 60_000,
204
+ now: NOW + 500,
205
+ });
206
+ // Renewal and reclamation are one operation and both
207
+ // advance. A renewal that kept the fence would leave any
208
+ // duplicate of the holder — a retried job, a
209
+ // double-scheduled pod — able to write with the number it
210
+ // captured before.
211
+ expect(renewed?.fence).toBeGreaterThan(first?.fence);
212
+ }));
213
+ it('refuses a lease with no duration', withStore(async (store) => {
214
+ // A lease that expires immediately is a lease every worker
215
+ // can take at once, which is the condition the call exists
216
+ // to prevent.
217
+ await expectRejection(expect, () => claimRun(store, runScope(BINDING), { holder: 'w1', ttlMs: 0, now: NOW }), /positive number of milliseconds/);
218
+ }));
219
+ });
220
+ describe('claim expiry', () => {
221
+ it('lets a later worker take a run whose holder went away', withStore(async (store) => {
222
+ const first = await claimRun(store, runScope(BINDING), {
223
+ holder: 'w1',
224
+ ttlMs: 1_000,
225
+ now: NOW,
226
+ });
227
+ const second = await claimRun(store, runScope(BINDING), {
228
+ holder: 'w2',
229
+ ttlMs: 60_000,
230
+ now: NOW + 2_000,
231
+ });
232
+ // A lock held by a dead process is held forever. The expiry
233
+ // is the whole difference between a lease and a wedged run.
234
+ expect(second?.holder).toBe('w2');
235
+ expect(second?.fence).toBeGreaterThan(first?.fence);
236
+ }));
237
+ it('returns the run to the queue when its holder releases', withStore(async (store) => {
238
+ const claim = await claimRun(store, runScope(BINDING), {
239
+ holder: 'w1',
240
+ ttlMs: 60_000,
241
+ now: NOW,
242
+ });
243
+ await releaseRun(store, runScope(BINDING), claim?.fence);
244
+ const next = await claimRun(store, runScope(BINDING), {
245
+ holder: 'w2',
246
+ ttlMs: 60_000,
247
+ now: NOW + 1,
248
+ });
249
+ expect(next?.holder).toBe('w2');
250
+ }));
251
+ it('releases only on the fence that currently holds it', withStore(async (store) => {
252
+ const first = await claimRun(store, runScope(BINDING), {
253
+ holder: 'w1',
254
+ ttlMs: 1_000,
255
+ now: NOW,
256
+ });
257
+ await claimRun(store, runScope(BINDING), {
258
+ holder: 'w2',
259
+ ttlMs: 60_000,
260
+ now: NOW + 2_000,
261
+ });
262
+ // A worker that stalled past its lease must not be able to
263
+ // hand away a run somebody else is now holding.
264
+ await releaseRun(store, runScope(BINDING), first?.fence);
265
+ const third = await claimRun(store, runScope(BINDING), {
266
+ holder: 'w3',
267
+ ttlMs: 60_000,
268
+ now: NOW + 3_000,
269
+ });
270
+ expect(third).toBe(null);
271
+ }));
272
+ });
273
+ describe('fenced-out writes', () => {
274
+ it('lets the current holder keep writing', withStore(async (store) => {
275
+ const claim = await claimRun(store, runScope(BINDING), {
276
+ holder: 'w1',
277
+ ttlMs: 60_000,
278
+ now: NOW,
279
+ });
280
+ await store.writeCheckpoint(runScope(BINDING), checkpoint('run_conformance_a'), claim?.fence);
281
+ const written = await store.listCheckpoints(runScope(BINDING));
282
+ expect(written.length).toBe(1);
283
+ }));
284
+ it('still accepts an unfenced write on a claimed run', withStore(async (store) => {
285
+ await claimRun(store, runScope(BINDING), {
286
+ holder: 'w1',
287
+ ttlMs: 60_000,
288
+ now: NOW,
289
+ });
290
+ // A host that adopts claims on one worker must not break the
291
+ // workers that have not adopted them yet. Refusing here would
292
+ // make the capability impossible to roll out incrementally.
293
+ await store.writeCheckpoint(runScope(BINDING), checkpoint('run_conformance_a'));
294
+ const written = await store.listCheckpoints(runScope(BINDING));
295
+ expect(written.length).toBe(1);
296
+ }));
297
+ it('fences the stalled holder out at the moment it writes', withStore(async (store) => {
298
+ const first = await claimRun(store, runScope(BINDING), {
299
+ holder: 'w1',
300
+ ttlMs: 1_000,
301
+ now: NOW,
302
+ });
303
+ await claimRun(store, runScope(BINDING), {
304
+ holder: 'w2',
305
+ ttlMs: 60_000,
306
+ now: NOW + 2_000,
307
+ });
308
+ // `w1` believes it still holds the run. It cannot know
309
+ // otherwise: a long pause, a suspended container and a
310
+ // partition all look from the inside like time not passing.
311
+ // The write is the only place it can be told, and this is
312
+ // that place.
313
+ await expectRejection(expect, () => store.writeCheckpoint(runScope(BINDING), checkpoint('run_conformance_a'), first?.fence), /no longer holds it/);
314
+ }));
315
+ it('still refuses a superseded fence after the new holder releases', withStore(async (store) => {
316
+ // The silent one, and the case on which the two built-in
317
+ // stores actually disagreed. Not a duplicate write — a LOST
318
+ // one.
319
+ //
320
+ // w1 stalls at its fence. w2 reclaims, does the work, and
321
+ // releases cleanly, which is the documented
322
+ // `finally { releaseRun() }`. w1 then wakes believing it
323
+ // still holds the run and writes. If that write is accepted,
324
+ // its checkpoint carries a fresh `createdAt`, sorts newest,
325
+ // and the next resume restores w1's stale history — so w2's
326
+ // completed work vanishes with no error anywhere.
327
+ const stale = await claimRun(store, runScope(BINDING), {
328
+ holder: 'w1',
329
+ ttlMs: 1_000,
330
+ now: NOW,
331
+ });
332
+ const live = await claimRun(store, runScope(BINDING), {
333
+ holder: 'w2',
334
+ ttlMs: 60_000,
335
+ now: NOW + 2_000,
336
+ });
337
+ await releaseRun(store, runScope(BINDING), live?.fence);
338
+ await expectRejection(expect, () => store.writeCheckpoint(runScope(BINDING), checkpoint('run_conformance_a'), stale?.fence), /no longer holds it/);
339
+ }));
340
+ it('refuses the fence its own holder just released', withStore(async (store) => {
341
+ // The same hole one step shorter, and the one that pins the
342
+ // release itself rather than a reclaim before it. A holder
343
+ // that gives a run back has given up the right to write to
344
+ // it; nothing else took the run in between, so only the
345
+ // release can be what refuses this.
346
+ const claim = await claimRun(store, runScope(BINDING), {
347
+ holder: 'w1',
348
+ ttlMs: 60_000,
349
+ now: NOW,
350
+ });
351
+ await releaseRun(store, runScope(BINDING), claim?.fence);
352
+ await expectRejection(expect, () => store.writeCheckpoint(runScope(BINDING), checkpoint('run_conformance_a'), claim?.fence), /no longer holds it/);
353
+ }));
354
+ });
355
+ }
356
+ if (capabilities.listing) {
357
+ describe('listing scope isolation', () => {
358
+ it('answers nothing for a tenant it does not hold', withStore(async (store) => {
359
+ await store.writeCheckpoint(runScope(BINDING, 'run_conformance_a'), checkpoint('run_conformance_a'));
360
+ const foreign = await listDurableRuns(store, { tenantId: FOREIGN_TENANT });
361
+ // A listing is SCOPED, not addressed: another tenant is a
362
+ // question this store has no rows for. Leaking one row here
363
+ // is the whole of a cross-tenant read.
364
+ expect(foreign.entries.map((e) => e.runId)).toEqual([]);
365
+ }));
366
+ it('answers nothing for a project it does not hold', withStore(async (store) => {
367
+ await store.writeCheckpoint(runScope(BINDING, 'run_conformance_a'), checkpoint('run_conformance_a'));
368
+ const foreign = await listDurableRuns(store, {
369
+ tenantId: BINDING.tenantId,
370
+ projectId: 'prj_conformance_other',
371
+ });
372
+ expect(foreign.entries.map((e) => e.runId)).toEqual([]);
373
+ }));
374
+ it('refuses a listing scope with a hole in it', withStore(async (store) => {
375
+ // `{ tenantId, sessionId }` reads as "that session under
376
+ // whichever project holds it". A flat backend can answer it
377
+ // and a hierarchical one cannot, so answering differently per
378
+ // backend is the one thing this contract exists to prevent.
379
+ await expectRejection(expect, () => listDurableRuns(store, {
380
+ tenantId: BINDING.tenantId,
381
+ sessionId: BINDING.sessionId,
382
+ }), /contiguous prefix|without `projectId`/);
383
+ }));
384
+ it('rebuilds an addressable row for every run it holds', withStore(async (store) => {
385
+ await store.writeCheckpoint(runScope(BINDING, 'run_conformance_a'), checkpoint('run_conformance_a'));
386
+ await store.writeCheckpoint(runScope(BINDING, 'run_conformance_b'), checkpoint('run_conformance_b'));
387
+ const page = await listDurableRuns(store, { tenantId: BINDING.tenantId });
388
+ expect(page.entries.map((e) => e.runId)).toEqual([
389
+ 'run_conformance_a',
390
+ 'run_conformance_b',
391
+ ]);
392
+ // A row that cannot be turned back into a scope is a report,
393
+ // not a work queue.
394
+ expect(page.entries.map((e) => e.tenantId)).toEqual([
395
+ BINDING.tenantId,
396
+ BINDING.tenantId,
397
+ ]);
398
+ expect(page.entries.map((e) => e.sessionId)).toEqual([
399
+ BINDING.sessionId,
400
+ BINDING.sessionId,
401
+ ]);
402
+ }));
403
+ if (capabilities.multiTenant) {
404
+ it('keeps one tenant’s runs out of another tenant’s listing', withStore(async (store) => {
405
+ await store.writeCheckpoint(runScope(BINDING, 'run_conformance_a'), checkpoint('run_conformance_a'));
406
+ await store.writeCheckpoint({
407
+ tenantId: FOREIGN_TENANT,
408
+ projectId: BINDING.projectId,
409
+ sessionId: BINDING.sessionId,
410
+ runId: 'run_conformance_z',
411
+ }, checkpoint('run_conformance_z'));
412
+ const mine = await listDurableRuns(store, { tenantId: BINDING.tenantId });
413
+ expect(mine.entries.map((e) => e.runId)).toEqual(['run_conformance_a']);
414
+ const theirs = await listDurableRuns(store, { tenantId: FOREIGN_TENANT });
415
+ expect(theirs.entries.map((e) => e.runId)).toEqual(['run_conformance_z']);
416
+ }));
417
+ }
418
+ if (capabilities.claims) {
419
+ it('shows the queue reader which runs nobody holds', withStore(async (store) => {
420
+ for (const id of ['run_conformance_a', 'run_conformance_b', 'run_conformance_c'])
421
+ await store.writeCheckpoint(runScope(BINDING, id), checkpoint(id));
422
+ await claimRun(store, runScope(BINDING, 'run_conformance_a'), {
423
+ holder: 'w1',
424
+ ttlMs: 60_000,
425
+ now: NOW,
426
+ });
427
+ await claimRun(store, runScope(BINDING, 'run_conformance_b'), {
428
+ holder: 'w1',
429
+ ttlMs: 1_000,
430
+ now: NOW,
431
+ });
432
+ const free = await listDurableRuns(store, { tenantId: BINDING.tenantId }, { claimed: false, now: NOW + 2_000 });
433
+ // `run_conformance_b`'s holder is gone. An expired claim
434
+ // counts as unheld, or a dead worker's runs stay invisible
435
+ // forever — the failure the lease exists to prevent,
436
+ // reintroduced by the filter that reads it.
437
+ expect(free.entries.map((e) => e.runId)).toEqual([
438
+ 'run_conformance_b',
439
+ 'run_conformance_c',
440
+ ]);
441
+ const taken = await listDurableRuns(store, { tenantId: BINDING.tenantId }, { claimed: true, now: NOW + 2_000 });
442
+ expect(taken.entries.map((e) => e.runId)).toEqual(['run_conformance_a']);
443
+ expect(taken.entries[0]?.claim?.holder).toBe('w1');
444
+ expect(taken.entries[0]?.claim?.expired).toBe(false);
445
+ }));
446
+ }
447
+ });
448
+ }
449
+ });
450
+ }
451
+ //# sourceMappingURL=conformance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conformance.js","sourceRoot":"","sources":["../../../src/store/run/conformance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AAMH,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEpE;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,CAAA;AAqFlD,gFAAgF;AAChF,MAAM,OAAO,GAA2B;IACvC,QAAQ,EAAE,iBAA6B;IACvC,SAAS,EAAE,iBAA8B;IACzC,SAAS,EAAE,iBAA8B;CACzC,CAAA;AAED,qDAAqD;AACrD,MAAM,cAAc,GAAG,uBAAmC,CAAA;AAE1D,4EAA4E;AAC5E,MAAM,GAAG,GAAG,SAAS,CAAA;AAErB,MAAM,OAAO,GAAa;IACzB,cAAc,EAAE,CAAC;IACjB,eAAe,EAAE,CAAC;IA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