@namzu/sdk 20.4.0 → 21.1.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 (98) hide show
  1. package/CHANGELOG.md +223 -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 +8 -0
  12. package/dist/public-runtime.d.ts.map +1 -1
  13. package/dist/public-runtime.js +31 -0
  14. package/dist/public-runtime.js.map +1 -1
  15. package/dist/run/command-gate.d.ts +107 -0
  16. package/dist/run/command-gate.d.ts.map +1 -0
  17. package/dist/run/command-gate.js +157 -0
  18. package/dist/run/command-gate.js.map +1 -0
  19. package/dist/run/drain.d.ts +194 -0
  20. package/dist/run/drain.d.ts.map +1 -0
  21. package/dist/run/drain.js +228 -0
  22. package/dist/run/drain.js.map +1 -0
  23. package/dist/run/index.d.ts +8 -0
  24. package/dist/run/index.d.ts.map +1 -1
  25. package/dist/run/index.js +4 -0
  26. package/dist/run/index.js.map +1 -1
  27. package/dist/run/memory-promoter.d.ts +70 -0
  28. package/dist/run/memory-promoter.d.ts.map +1 -0
  29. package/dist/run/memory-promoter.js +117 -0
  30. package/dist/run/memory-promoter.js.map +1 -0
  31. package/dist/run/workspace-fingerprint.d.ts +105 -0
  32. package/dist/run/workspace-fingerprint.d.ts.map +1 -0
  33. package/dist/run/workspace-fingerprint.js +147 -0
  34. package/dist/run/workspace-fingerprint.js.map +1 -0
  35. package/dist/runtime/query/events.d.ts +12 -0
  36. package/dist/runtime/query/events.d.ts.map +1 -1
  37. package/dist/runtime/query/events.js +61 -3
  38. package/dist/runtime/query/events.js.map +1 -1
  39. package/dist/runtime/query/index.d.ts +36 -0
  40. package/dist/runtime/query/index.d.ts.map +1 -1
  41. package/dist/runtime/query/index.js +32 -0
  42. package/dist/runtime/query/index.js.map +1 -1
  43. package/dist/runtime/query/resume-run.d.ts +25 -0
  44. package/dist/runtime/query/resume-run.d.ts.map +1 -1
  45. package/dist/runtime/query/resume-run.js +15 -3
  46. package/dist/runtime/query/resume-run.js.map +1 -1
  47. package/dist/store/index.d.ts +1 -1
  48. package/dist/store/index.d.ts.map +1 -1
  49. package/dist/store/index.js +1 -1
  50. package/dist/store/index.js.map +1 -1
  51. package/dist/store/run/conformance.d.ts +159 -0
  52. package/dist/store/run/conformance.d.ts.map +1 -0
  53. package/dist/store/run/conformance.js +451 -0
  54. package/dist/store/run/conformance.js.map +1 -0
  55. package/dist/store/run/disk.d.ts +30 -2
  56. package/dist/store/run/disk.d.ts.map +1 -1
  57. package/dist/store/run/disk.js +101 -0
  58. package/dist/store/run/disk.js.map +1 -1
  59. package/dist/store/run/memory.d.ts +5 -4
  60. package/dist/store/run/memory.d.ts.map +1 -1
  61. package/dist/store/run/memory.js +30 -1
  62. package/dist/store/run/memory.js.map +1 -1
  63. package/dist/types/doctor/check.d.ts +28 -2
  64. package/dist/types/doctor/check.d.ts.map +1 -1
  65. package/dist/types/run/event-cursor.d.ts +90 -0
  66. package/dist/types/run/event-cursor.d.ts.map +1 -0
  67. package/dist/types/run/event-cursor.js +47 -0
  68. package/dist/types/run/event-cursor.js.map +1 -0
  69. package/dist/types/run/events.d.ts +71 -1
  70. package/dist/types/run/events.d.ts.map +1 -1
  71. package/dist/types/run/events.js.map +1 -1
  72. package/dist/types/run/index.d.ts +1 -0
  73. package/dist/types/run/index.d.ts.map +1 -1
  74. package/dist/types/run/index.js +1 -0
  75. package/dist/types/run/index.js.map +1 -1
  76. package/dist/types/run/store.d.ts +41 -1
  77. package/dist/types/run/store.d.ts.map +1 -1
  78. package/package.json +6 -1
  79. package/src/bridge/sse/mapper.ts +28 -1
  80. package/src/manager/run/persistence.ts +43 -0
  81. package/src/public-runtime.ts +53 -0
  82. package/src/run/command-gate.ts +234 -0
  83. package/src/run/drain.ts +393 -0
  84. package/src/run/index.ts +20 -0
  85. package/src/run/memory-promoter.ts +155 -0
  86. package/src/run/workspace-fingerprint.ts +193 -0
  87. package/src/runtime/query/events.ts +68 -4
  88. package/src/runtime/query/index.ts +87 -0
  89. package/src/runtime/query/resume-run.ts +67 -12
  90. package/src/store/index.ts +1 -1
  91. package/src/store/run/conformance.ts +705 -0
  92. package/src/store/run/disk.ts +106 -2
  93. package/src/store/run/memory.ts +35 -5
  94. package/src/types/doctor/check.ts +28 -2
  95. package/src/types/run/event-cursor.ts +118 -0
  96. package/src/types/run/events.ts +80 -3
  97. package/src/types/run/index.ts +1 -0
  98. package/src/types/run/store.ts +43 -1
@@ -1,6 +1,8 @@
1
1
  import type { PendingDecision } from '../../types/hitl/index.js';
2
2
  import type { CheckpointStore, ClaimFence } from '../../types/run/checkpoint-store.js';
3
3
  import type { Run } from '../../types/run/entity.js';
4
+ import type { RunEventReplay } from '../../types/run/event-cursor.js';
5
+ import type { RunEventListener } from '../../types/run/events.js';
4
6
  import type { RunState } from '../../types/run/state.js';
5
7
  import { type QueryParams } from './index.js';
6
8
  import { type RunStateScope } from './run-state.js';
@@ -26,6 +28,16 @@ export type ResumeOutcome = {
26
28
  readonly resumed: true;
27
29
  readonly run: Run;
28
30
  readonly state: RunState;
31
+ /**
32
+ * What became of {@link ResumeRunParams.eventCursor}. Absent when no
33
+ * cursor was supplied.
34
+ *
35
+ * Reported rather than thrown: a stale cursor is the client's
36
+ * problem and the run still had to be resumed. A caller that sees
37
+ * `unavailable` re-derives its view from the run's transcript
38
+ * instead of folding a hole into it.
39
+ */
40
+ readonly replay?: RunEventReplay;
29
41
  };
30
42
  /**
31
43
  * The half of a run that cannot be serialized, plus where to look.
@@ -52,6 +64,19 @@ export interface ResumeRunParams extends Omit<QueryParams, 'messages' | 'runId'
52
64
  * Absent means the parked checkpoint if there is one, else the newest.
53
65
  */
54
66
  readonly checkpointId?: RunState['checkpointId'];
67
+ /**
68
+ * Where to send the resumed run's events.
69
+ *
70
+ * This call had none, and the consequence was total: it drains the run to
71
+ * completion and every event the run emits — every tool call, every park,
72
+ * every token update — was discarded, because `drainQuery` forwards to a
73
+ * listener and none was ever passed. So the one API for continuing a run
74
+ * another process started could not show anybody what the run was doing.
75
+ *
76
+ * It is also what makes {@link ResumeRunParams.eventCursor} mean anything:
77
+ * a catch-up delivered into a stream nobody receives is not a catch-up.
78
+ */
79
+ readonly listener?: RunEventListener;
55
80
  }
56
81
  /**
57
82
  * Continue a run that a different process started.
@@ -1 +1 @@
1
- {"version":3,"file":"resume-run.d.ts","sourceRoot":"","sources":["../../../src/runtime/query/resume-run.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAA;AACtF,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAA;AACpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,EAAE,KAAK,WAAW,EAAc,MAAM,YAAY,CAAA;AACzD,OAAO,EAAE,KAAK,aAAa,EAAgB,MAAM,gBAAgB,CAAA;AAEjE;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,GACtB;IAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAA;CAAE,GAC7D;IACA,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAA;IACpC,uCAAuC;IACvC,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAA;IACjC,QAAQ,CAAC,KAAK,EAAE,QAAQ,C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;AACH,MAAM,MAAM,aAAa,GACtB;IAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAA;CAAE,GAC7D;IACA,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAA;IACpC,uCAAuC;IACvC,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAA;IACjC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAA;CACvB,GACD;IACA,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAA;IACtB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAA;IACjB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAA;IACxB;;;;;;;;OAQG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,cAAc,CAAA;CAC/B,CAAA;AAEJ;;;;;;GAMG;AACH,MAAM,WAAW,eAChB,SAAQ,IAAI,CAAC,WAAW,EAAE,UAAU,GAAG,OAAO,GAAG,sBAAsB,CAAC;IACxE,sDAAsD;IACtD,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAA;IAC7B,2EAA2E;IAC3E,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAA;IAEzC;;;;;;OAMG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAA;IAChC;;;OAGG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAA;IAEhD;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAA;CACpC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,aAAa,CAAC,CAkD/E"}
@@ -22,7 +22,7 @@ import { loadRunState } from './run-state.js';
22
22
  * resumed past without the answer it is waiting for.
23
23
  */
24
24
  export async function resumeRun(params) {
25
- const { scope, checkpointStore, checkpointId, pendingDecision, claimFence, ...rest } = params;
25
+ const { scope, checkpointStore, checkpointId, pendingDecision, claimFence, listener, onEventReplay, ...rest } = params;
26
26
  const state = await loadRunState(checkpointStore, scope, checkpointId);
27
27
  if (!state?.checkpointId)
28
28
  return { resumed: false, reason: 'no-checkpoint' };
@@ -33,15 +33,27 @@ export async function resumeRun(params) {
33
33
  if (outstanding && !pendingDecision) {
34
34
  return { resumed: false, reason: 'awaiting-decision', pending: outstanding, state };
35
35
  }
36
+ let replay;
36
37
  const run = await drainQuery({
37
38
  ...rest,
38
39
  messages: [],
39
40
  runId: state.runId,
41
+ // Forwarded, and it is not cosmetic: the run store nests a sub-run's
42
+ // evidence under `<parent>/children/<run>`, so resuming a sub-run
43
+ // without this binds `<base>/<run>` instead — a second, empty
44
+ // transcript under a run id that already has one, a sequence that
45
+ // restarts at 1, and a catch-up that reports a live run as having
46
+ // produced nothing.
47
+ ...(state.parentRunId !== undefined ? { parentRunId: state.parentRunId } : {}),
40
48
  resumeFromCheckpoint: state.checkpointId,
41
49
  checkpointStore,
42
50
  ...(claimFence !== undefined ? { claimFence } : {}),
43
51
  ...(pendingDecision ? { pendingDecision } : {}),
44
- });
45
- return { resumed: true, run, state };
52
+ onEventReplay: (verdict) => {
53
+ replay = verdict;
54
+ onEventReplay?.(verdict);
55
+ },
56
+ }, listener);
57
+ return { resumed: true, run, state, ...(replay !== undefined ? { replay } : {}) };
46
58
  }
47
59
  //# sourceMappingURL=resume-run.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resume-run.js","sourceRoot":"","sources":["../../../src/runtime/query/resume-run.ts"],"names":[],"mappings":"AAIA,OAAO,EAAoB,UAAU,EAAE,MAAM,YAAY,CAAA;AACzD,OAAO,EAAsB,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAmDjE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,MAAuB;IACtD,MAAM,EAAE,KAAK,EAAE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,KAAK,CAAC,YAAY;QACxC,eAAe;QACf,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnD,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/C,aAAa,EAAE,CAAC,OAAuB,EAAE,EAAE;YAC1C,MAAM,GAAG,OAAO,CAAA;YAChB,aAAa,EAAE,CAAC,OAAO,CAAC,CAAA;QACzB,CAAC;KACc,EAChB,QAAQ,CACR,CAAA;IAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAA;AAClF,CAAC"}
@@ -1,6 +1,6 @@
1
1
  export { InMemoryStore } from './InMemoryStore.js';
2
2
  export type { Identifiable, Timestamped } from './InMemoryStore.js';
3
- export { RunDiskStore } from './run/disk.js';
3
+ export { RunDiskStore, readRunEventsIn } from './run/disk.js';
4
4
  export { InMemoryRunStore } from './run/memory.js';
5
5
  export { DiskCheckpointStore } from './run/checkpoint-disk.js';
6
6
  export type { DiskCheckpointStoreAttribution } from './run/checkpoint-disk.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEnE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,YAAY,EAAE,8BAA8B,EA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BAAmB,EACnB,UAAU,EACV,cAAc,EACd,iBAAiB,GACjB,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,YAAY,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAEhF,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAEzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,YAAY,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA"}
@@ -1,5 +1,5 @@
1
1
  export { InMemoryStore } from './InMemoryStore.js';
2
- export { RunDiskStore } from './run/disk.js';
2
+ export { RunDiskStore, readRunEventsIn } from './run/disk.js';
3
3
  export { InMemoryRunStore } from './run/memory.js';
4
4
  export { DiskCheckpointStore } from './run/checkpoint-disk.js';
5
5
  export { InMemoryCheckpointStore } from './run/checkpoint-memory.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAE9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAA;AACpE,4EAA4E;AAC5E,4EAA4E;AAC5E,2EAA2E;AAC3E,kEAAkE;AAClE,mEAAmE;AACnE,EAAE;AACF,6EAA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ACpD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAG9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA"}
@@ -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.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conformance.d.ts","sourceRoot":"","sources":["../../../src/store/run/conformance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AAIH,OAAO,KAAK,EAAgB,SAAS,EAAS,SAAS,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACnG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAA;AAG1E;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,iCAAiC,IAAI,CAAA;AAElD;;;;;;;;GAQG;AACH,MAAM,WAAW,2BAA2B;IAC3C;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;IACxB,8CAA8C;IAC9C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB;;;;;;;OAOG;IACH,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAA;CAC7B;AAED,0DAA0D;AAC1D,MAAM,WAAW,sBAAsB;IACtC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;IAC3B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAA;IAC7B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAA;CAC7B;AAED,qEAAqE;A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