@defrex/autobuild 1.0.0-beta.0 → 1.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -4
- package/SPEC.md +295 -62
- package/bin/ab-build-runner.ts +10 -8
- package/docs/architecture.md +179 -25
- package/docs/configuration.md +41 -6
- package/docs/hosted-service.md +35 -0
- package/docs/integration-tree.md +81 -4
- package/docs/landing-policy.md +11 -0
- package/docs/migration-1.0.md +9 -0
- package/docs/operator-api.md +18 -0
- package/docs/remote-store-protocol.md +11 -0
- package/docs/restacking.md +42 -7
- package/docs/setup.md +25 -0
- package/docs/ticket-dependencies.md +6 -45
- package/package.json +3 -3
- package/packages/core/src/cli/attention.ts +4 -1
- package/packages/core/src/cli/binary.ts +17 -1
- package/packages/core/src/cli/context.ts +53 -1
- package/packages/core/src/cli/dashboard/actions.ts +4 -0
- package/packages/core/src/cli/dashboard/detail.ts +45 -1
- package/packages/core/src/cli/dashboard/facts.ts +7 -2
- package/packages/core/src/cli/dashboard/integration-detail.ts +142 -0
- package/packages/core/src/cli/dashboard/integration-row.ts +248 -0
- package/packages/core/src/cli/dashboard/landing-display.ts +64 -0
- package/packages/core/src/cli/dashboard/model.ts +140 -16
- package/packages/core/src/cli/dashboard/poll.ts +40 -4
- package/packages/core/src/cli/dashboard/refresh.ts +20 -13
- package/packages/core/src/cli/dashboard/render.ts +106 -5
- package/packages/core/src/cli/dashboard/transcript.ts +2 -1
- package/packages/core/src/cli/dispatch-frontend.ts +22 -12
- package/packages/core/src/cli/dispatch.ts +59 -25
- package/packages/core/src/cli/help.ts +19 -2
- package/packages/core/src/cli/main.ts +37 -0
- package/packages/core/src/cli/publication-settlement.ts +49 -5
- package/packages/core/src/cli/repository-status.ts +97 -2
- package/packages/core/src/cli/status.ts +24 -1
- package/packages/core/src/cli/terminals.ts +94 -93
- package/packages/core/src/cli/wait.ts +11 -2
- package/packages/core/src/cli/watch.ts +12 -0
- package/packages/core/src/config/schema.ts +3 -0
- package/packages/core/src/events/catalog.ts +38 -0
- package/packages/core/src/events/compatibility.ts +183 -0
- package/packages/core/src/events/native-session.ts +13 -0
- package/packages/core/src/events/payloads.ts +148 -2
- package/packages/core/src/events/policy.ts +209 -0
- package/packages/core/src/events/repository.ts +48 -0
- package/packages/core/src/integration/harness.ts +4 -4
- package/packages/core/src/kernel/__snapshots__/{reducer-registry.test.ts.snap → reducer-accumulator-shapes.json} +771 -538
- package/packages/core/src/kernel/change-presence.ts +4 -2
- package/packages/core/src/kernel/dispatch-capacity.ts +119 -0
- package/packages/core/src/kernel/dispatcher-liveness.ts +5 -1
- package/packages/core/src/kernel/engine.ts +25 -5
- package/packages/core/src/kernel/forge-health.ts +19 -0
- package/packages/core/src/kernel/generators/build-log.ts +18 -0
- package/packages/core/src/kernel/generators/node-restack-log.ts +1 -1
- package/packages/core/src/kernel/generators/repository-journals.ts +10 -0
- package/packages/core/src/kernel/guarded-forge.ts +159 -0
- package/packages/core/src/kernel/incremental.ts +4 -2
- package/packages/core/src/kernel/integration-completeness.ts +61 -0
- package/packages/core/src/kernel/integration-landing.ts +5 -4
- package/packages/core/src/kernel/janitor-failure.ts +36 -0
- package/packages/core/src/kernel/landing-publication.ts +35 -15
- package/packages/core/src/kernel/landing-state.ts +7 -0
- package/packages/core/src/kernel/leaf-restack-state.ts +1 -1
- package/packages/core/src/kernel/log-index.ts +12 -1
- package/packages/core/src/kernel/mixed-version.ts +52 -0
- package/packages/core/src/kernel/node-landing.ts +14 -11
- package/packages/core/src/kernel/node-restack-demand.ts +29 -0
- package/packages/core/src/kernel/node-restack-state.ts +46 -16
- package/packages/core/src/kernel/node-restack-transaction.ts +151 -8
- package/packages/core/src/kernel/node-restack.ts +34 -10
- package/packages/core/src/kernel/publication.ts +22 -0
- package/packages/core/src/kernel/read-deferrals.ts +111 -0
- package/packages/core/src/kernel/read-facts.ts +27 -6
- package/packages/core/src/kernel/reconcile-restack.ts +23 -2
- package/packages/core/src/kernel/reducer-registry.ts +15 -2
- package/packages/core/src/kernel/reducer.ts +196 -10
- package/packages/core/src/kernel/repository-attention.ts +38 -1
- package/packages/core/src/kernel/terminal-guard.ts +11 -4
- package/packages/core/src/operator/annotations.ts +6 -0
- package/packages/core/src/operator/index.ts +2 -0
- package/packages/core/src/operator/presentation.ts +5 -0
- package/packages/core/src/operator/query.ts +45 -11
- package/packages/core/src/operator/registry.ts +17 -1
- package/packages/core/src/operator/restack.ts +51 -0
- package/packages/core/src/plugin-sdk/index.ts +10 -0
- package/packages/core/src/plugins/load.ts +3 -4
- package/packages/core/src/plugins/manifest.ts +1 -1
- package/packages/core/src/ports/forge/contract.ts +23 -0
- package/packages/core/src/ports/forge/fake.ts +6 -2
- package/packages/core/src/ports/forge/git-rewrite.ts +92 -64
- package/packages/core/src/ports/forge/github-transport.ts +45 -2
- package/packages/core/src/ports/forge/github.ts +56 -17
- package/packages/core/src/ports/forge/local-git.ts +7 -2
- package/packages/core/src/ports/forge-failure.ts +40 -0
- package/packages/core/src/ports/forge-request-context.ts +35 -0
- package/packages/core/src/ports/forge-telemetry.ts +16 -0
- package/packages/core/src/ports/runner/claude.ts +136 -9
- package/packages/core/src/ports/runner/codex.ts +112 -7
- package/packages/core/src/ports/runner/contract.ts +78 -0
- package/packages/core/src/ports/runner/fake.ts +59 -1
- package/packages/core/src/ports/runner/native-cli-fixture.ts +86 -0
- package/packages/core/src/ports/runner/native-process-fixture.ts +38 -0
- package/packages/core/src/ports/runner/native-session.ts +110 -0
- package/packages/core/src/ports/runner/pi-rpc.ts +7 -1
- package/packages/core/src/ports/runner/pi.ts +162 -2
- package/packages/core/src/ports/types.ts +53 -5
- package/packages/core/src/ports/workspace/git-worktree.ts +45 -51
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +28 -12
- package/packages/core/src/processes/build-child-exit.ts +50 -2
- package/packages/core/src/processes/build-child.ts +15 -7
- package/packages/core/src/processes/build-runner.ts +909 -213
- package/packages/core/src/processes/dispatcher.ts +652 -334
- package/packages/core/src/processes/execution-no-progress.ts +15 -0
- package/packages/core/src/processes/pause-execution-fixture.ts +37 -0
- package/packages/core/src/processes/phase-failure-budget.ts +2 -1
- package/packages/core/src/processes/publication-loss.ts +7 -3
- package/packages/core/src/processes/repo-view.ts +53 -6
- package/packages/core/src/processes/tick-publication.ts +6 -2
- package/packages/core/src/runtime-identity.ts +37 -0
- package/packages/core/src/store/adapter.ts +4 -2
- package/packages/core/src/store/build-scope.ts +9 -0
- package/packages/core/src/store/contract.ts +203 -16
- package/packages/core/src/store/digest.ts +20 -2
- package/packages/core/src/store/local/schema.ts +6 -0
- package/packages/core/src/store/local/store.ts +57 -4
- package/packages/core/src/store/memory.ts +83 -2
- package/packages/core/src/store/new-build.ts +2 -2
- package/packages/core/src/store/phase-session.ts +13 -0
- package/packages/core/src/store/reduced-reads.ts +43 -4
- package/packages/core/src/store/reducer-value-shapes.json +8238 -5764
- package/packages/core/src/store/reducer-value-validation.ts +103 -3
- package/packages/core/src/store/reducer-values.ts +21 -6
- package/packages/core/src/store/remote/client.ts +146 -20
- package/packages/core/src/store/remote/compatibility.ts +6 -0
- package/packages/core/src/store/remote/index.ts +2 -0
- package/packages/core/src/store/remote/protocol.ts +19 -0
- package/packages/core/src/store/remote/version.ts +2 -0
- package/packages/core/src/store/repo-state-events.ts +3 -1
- package/packages/core/src/store/repo-tick.ts +6 -1
- package/packages/core/src/store/session-handle.ts +8 -0
- package/packages/core/src/store/snapshots.ts +21 -5
- package/packages/core/src/store/types.ts +19 -1
- package/packages/core/src/testing/dispatch-read-budget.ts +17 -2
- package/packages/core/src/testing/index.ts +7 -0
- package/packages/core/src/testing/newer-writer.ts +37 -0
- package/packages/core/src/testing/reduced-read-budget.ts +3 -0
- package/skills/guide/SKILL.md +144 -27
- package/skills/guide/references/integration-tree.md +81 -4
- package/skills/guide/references/landing-policy.md +11 -0
- package/skills/guide/references/migration-1.0.md +9 -0
- package/skills/guide/references/operator-api.md +18 -0
- package/skills/guide/references/plugin-authoring.md +55 -7
- package/skills/guide/references/remote-store-protocol.md +11 -0
- package/skills/guide/references/restacking.md +42 -7
- package/skills/guide/references/setup.md +25 -0
- package/skills/guide/references/ticket-dependencies.md +6 -45
- package/skills/implement/SKILL.md +4 -2
- package/skills/operate/SKILL.md +63 -6
- package/skills/reconcile/SKILL.md +3 -1
- package/skills/spec/SKILL.md +49 -39
- package/skills/tickets/SKILL.md +15 -43
|
@@ -14,21 +14,27 @@ const schemas: Record<string, Shape> = shapes.schemas
|
|
|
14
14
|
* optional fields and literal discriminants. No accumulator is trusted merely
|
|
15
15
|
* because finish() happens to accept it. */
|
|
16
16
|
export function validateAccumulator(name: string, value: unknown): boolean {
|
|
17
|
+
if (!Object.hasOwn(shapes.roots, name)) return false
|
|
17
18
|
const root = (shapes.roots as Record<string, { acc: string }>)[name]
|
|
18
19
|
return root !== undefined && matches(root.acc, value)
|
|
19
20
|
}
|
|
20
21
|
export function validateReducerValue(name: string, value: unknown): boolean {
|
|
22
|
+
if (!Object.hasOwn(shapes.roots, name)) return false
|
|
21
23
|
const root = (shapes.roots as Record<string, { value: string }>)[name]
|
|
22
24
|
return root !== undefined && matches(root.value, value)
|
|
23
25
|
}
|
|
24
|
-
function json(value: unknown): boolean {
|
|
26
|
+
function json(value: unknown, seen = new Set<object>()): boolean {
|
|
25
27
|
if (value === null || typeof value === 'string' || typeof value === 'boolean') return true
|
|
26
28
|
if (typeof value === 'number') return Number.isFinite(value)
|
|
27
|
-
if (
|
|
29
|
+
if (typeof value === 'object' && value !== null) {
|
|
30
|
+
if (seen.has(value)) return false
|
|
31
|
+
seen.add(value)
|
|
32
|
+
}
|
|
33
|
+
if (Array.isArray(value)) return value.every((item) => json(item, new Set(seen)))
|
|
28
34
|
return (
|
|
29
35
|
typeof value === 'object' &&
|
|
30
36
|
Object.getPrototypeOf(value) === Object.prototype &&
|
|
31
|
-
Object.values(value).every(json)
|
|
37
|
+
Object.values(value).every((item) => json(item, new Set(seen)))
|
|
32
38
|
)
|
|
33
39
|
}
|
|
34
40
|
function matches(id: string, value: unknown): boolean {
|
|
@@ -74,6 +80,100 @@ function matches(id: string, value: unknown): boolean {
|
|
|
74
80
|
}
|
|
75
81
|
}
|
|
76
82
|
|
|
83
|
+
export interface ValidationFailure {
|
|
84
|
+
path: string
|
|
85
|
+
expected: string
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Stable structural diagnostics only: persisted values never enter error text. */
|
|
89
|
+
export function diagnoseReducerValue(name: string, value: unknown): ValidationFailure | undefined {
|
|
90
|
+
const root = Object.hasOwn(shapes.roots, name)
|
|
91
|
+
? (shapes.roots as Record<string, { value: string }>)[name]
|
|
92
|
+
: undefined
|
|
93
|
+
if (!root) return { path: '$', expected: 'known reducer' }
|
|
94
|
+
const failure = diagnose(root.value, value, '$', 0)
|
|
95
|
+
return failure ? { path: failure.path, expected: failure.expected } : undefined
|
|
96
|
+
}
|
|
97
|
+
function property(path: string, key: string): string {
|
|
98
|
+
return /^[A-Za-z_$][\w$]*$/.test(key) ? `${path}.${key}` : `${path}[${JSON.stringify(key)}]`
|
|
99
|
+
}
|
|
100
|
+
type Diagnostic = ValidationFailure & { depth: number }
|
|
101
|
+
function diagnoseJson(
|
|
102
|
+
value: unknown,
|
|
103
|
+
path: string,
|
|
104
|
+
depth: number,
|
|
105
|
+
seen = new Set<object>(),
|
|
106
|
+
): Diagnostic | undefined {
|
|
107
|
+
if (
|
|
108
|
+
value === null ||
|
|
109
|
+
typeof value === 'string' ||
|
|
110
|
+
typeof value === 'boolean' ||
|
|
111
|
+
(typeof value === 'number' && Number.isFinite(value))
|
|
112
|
+
)
|
|
113
|
+
return undefined
|
|
114
|
+
if (typeof value !== 'object' || seen.has(value)) return { path, expected: 'json', depth }
|
|
115
|
+
seen.add(value)
|
|
116
|
+
if (Array.isArray(value)) {
|
|
117
|
+
for (let i = 0; i < value.length; i++) {
|
|
118
|
+
const failure = diagnoseJson(value[i], `${path}[${i}]`, depth + 1, new Set(seen))
|
|
119
|
+
if (failure) return failure
|
|
120
|
+
}
|
|
121
|
+
} else if (Object.getPrototypeOf(value) === Object.prototype) {
|
|
122
|
+
for (const key of Object.keys(value).sort()) {
|
|
123
|
+
const failure = diagnoseJson(
|
|
124
|
+
(value as Record<string, unknown>)[key],
|
|
125
|
+
property(path, key),
|
|
126
|
+
depth + 1,
|
|
127
|
+
new Set(seen),
|
|
128
|
+
)
|
|
129
|
+
if (failure) return failure
|
|
130
|
+
}
|
|
131
|
+
} else return { path, expected: 'json', depth }
|
|
132
|
+
return undefined
|
|
133
|
+
}
|
|
134
|
+
function diagnose(id: string, value: unknown, path: string, depth: number): Diagnostic | undefined {
|
|
135
|
+
if (matches(id, value)) return undefined
|
|
136
|
+
const shape = schemas[id]!
|
|
137
|
+
const failure = {
|
|
138
|
+
path,
|
|
139
|
+
depth,
|
|
140
|
+
expected: shape.kind === 'literal' ? JSON.stringify(shape.value) : shape.kind,
|
|
141
|
+
}
|
|
142
|
+
if (shape.kind === 'json') return diagnoseJson(value, path, depth)
|
|
143
|
+
if (shape.kind === 'union') {
|
|
144
|
+
return (shape.items as string[])
|
|
145
|
+
.map((item) => diagnose(item, value, path, depth)!)
|
|
146
|
+
.reduce((best, next) => (next.depth > best.depth ? next : best))
|
|
147
|
+
}
|
|
148
|
+
if (shape.kind === 'array' && Array.isArray(value)) {
|
|
149
|
+
for (let i = 0; i < value.length; i++) {
|
|
150
|
+
const found = diagnose(shape.items as string, value[i], `${path}[${i}]`, depth + 1)
|
|
151
|
+
if (found) return found
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (
|
|
155
|
+
shape.kind === 'object' &&
|
|
156
|
+
value !== null &&
|
|
157
|
+
typeof value === 'object' &&
|
|
158
|
+
Object.getPrototypeOf(value) === Object.prototype
|
|
159
|
+
) {
|
|
160
|
+
const record = value as Record<string, unknown>
|
|
161
|
+
for (const [key, prop] of Object.entries(shape.props!)) {
|
|
162
|
+
if (!(key in record) && prop.optional) continue
|
|
163
|
+
const found = diagnose(prop.type, record[key], property(path, key), depth + 1)
|
|
164
|
+
if (found) return found
|
|
165
|
+
}
|
|
166
|
+
for (const key of Object.keys(record).sort()) {
|
|
167
|
+
if (Object.hasOwn(shape.props!, key)) continue
|
|
168
|
+
if (!shape.index)
|
|
169
|
+
return { path: property(path, key), expected: 'no additional property', depth: depth + 1 }
|
|
170
|
+
const found = diagnose(shape.index, record[key], property(path, key), depth + 1)
|
|
171
|
+
if (found) return found
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return failure
|
|
175
|
+
}
|
|
176
|
+
|
|
77
177
|
/** Existing optional object fields keep their ordinary JSON omission semantics.
|
|
78
178
|
* Collections, functions, nonfinite numbers and undefined array entries cannot
|
|
79
179
|
* silently become a different public contract during JSON serialization. */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { READ_CATALOG_IDENTITY, projectStoredEvents } from '../events/compatibility'
|
|
1
2
|
/** Named JSON answers over persisted incremental state. The event log remains authoritative. */
|
|
2
3
|
import { z } from 'zod'
|
|
3
4
|
import type { AbEvent } from '../events/catalog'
|
|
@@ -19,6 +20,7 @@ export const reducerValueRequestSchema = z
|
|
|
19
20
|
export type ReducerValueRequest = z.infer<typeof reducerValueRequestSchema>
|
|
20
21
|
export type JsonValue = z.infer<ReturnType<typeof z.json>>
|
|
21
22
|
export interface ReducerValue {
|
|
23
|
+
catalogIdentity?: string
|
|
22
24
|
version: number
|
|
23
25
|
cursor: number
|
|
24
26
|
value: JsonValue
|
|
@@ -51,7 +53,11 @@ function canonical(value: unknown): string {
|
|
|
51
53
|
return JSON.stringify(value)
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
export function resolveReducerValue(
|
|
56
|
+
export function resolveReducerValue(
|
|
57
|
+
scope: SnapshotScope,
|
|
58
|
+
input: ReducerValueRequest,
|
|
59
|
+
catalogIdentity = READ_CATALOG_IDENTITY,
|
|
60
|
+
) {
|
|
55
61
|
const request = reducerValueRequestSchema.parse(input)
|
|
56
62
|
const registration = Object.hasOwn(REDUCERS, request.reducer)
|
|
57
63
|
? REDUCERS[request.reducer]
|
|
@@ -63,7 +69,13 @@ export function resolveReducerValue(scope: SnapshotScope, input: ReducerValueReq
|
|
|
63
69
|
if (entry.scope !== scope.kind) throw new Error(`wrong scope for reducer "${request.reducer}"`)
|
|
64
70
|
const args = entry.args.parse(request.args ?? {})
|
|
65
71
|
const reducer = entry.create(args)
|
|
66
|
-
const identity = canonical({
|
|
72
|
+
const identity = canonical({
|
|
73
|
+
scope,
|
|
74
|
+
reducer: request.reducer,
|
|
75
|
+
version: reducer.version,
|
|
76
|
+
catalogIdentity,
|
|
77
|
+
args,
|
|
78
|
+
})
|
|
67
79
|
// v2 ignores checkpoints from the former client-writable key format.
|
|
68
80
|
const key = `${REDUCER_VALUE_SNAPSHOT_PREFIX}v2.${new Bun.CryptoHasher('sha256').update(identity).digest('hex').slice(0, 54)}`
|
|
69
81
|
return { name: request.reducer, reducer, identity, key, entry }
|
|
@@ -130,16 +142,19 @@ export async function readReducerValue(
|
|
|
130
142
|
cursor = event.seq
|
|
131
143
|
}
|
|
132
144
|
if (cursor !== boundary) throw new Error('incomplete reducer log')
|
|
133
|
-
acc = reducer.advance(acc, entry.adapt(delta))
|
|
145
|
+
acc = reducer.advance(acc, entry.adapt(projectStoredEvents(delta)))
|
|
134
146
|
const value = entry.value(reducer.finish(acc))
|
|
135
147
|
if (!valid || delta.length > 0) {
|
|
136
148
|
const next = { version: reducer.version, cursor, state: { identity, acc } }
|
|
137
149
|
try {
|
|
138
|
-
if (row && !valid
|
|
139
|
-
|
|
150
|
+
if (row && !valid && row.snapshot.version === reducer.version)
|
|
151
|
+
await storage.repair(key, row, next)
|
|
152
|
+
else if (row && !valid && row.snapshot.version !== reducer.version) {
|
|
153
|
+
/* foreign cache is read-only */
|
|
154
|
+
} else await storage.put(key, next)
|
|
140
155
|
} catch {
|
|
141
156
|
/* best-effort cache; log and reduction errors propagate */
|
|
142
157
|
}
|
|
143
158
|
}
|
|
144
|
-
return { version: reducer.version, cursor, value }
|
|
159
|
+
return { version: reducer.version, cursor, value, catalogIdentity: READ_CATALOG_IDENTITY }
|
|
145
160
|
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import { stampCompatibility, buildEventPolicy, repositoryEventPolicy } from '../../events/policy'
|
|
2
|
+
import { READ_CATALOG_IDENTITY, projectStoredEvents } from '../../events/compatibility'
|
|
3
|
+
import { CATALOG_IDENTITY_HEADER } from './version'
|
|
4
|
+
import { validateReducerValue } from '../reducer-value-validation'
|
|
5
|
+
import { prepareEventWrite as validateEventWrite } from '../../events/catalog'
|
|
6
|
+
import { prepareRepositoryEventWrite as validateRepositoryEventWrite } from '../../events/repository'
|
|
1
7
|
import {
|
|
2
8
|
resolveReducerValue,
|
|
3
9
|
reducerValueSchema,
|
|
@@ -108,6 +114,7 @@ import {
|
|
|
108
114
|
reducerSnapshotPutResponseSchema,
|
|
109
115
|
reducerSnapshotResponseSchema,
|
|
110
116
|
placeholderRev,
|
|
117
|
+
substitutePlaceholderRefs,
|
|
111
118
|
repoDepositsResponseSchema,
|
|
112
119
|
repositoryArtifactGetResponseSchema,
|
|
113
120
|
repositoryArtifactMetaListSchema,
|
|
@@ -170,6 +177,11 @@ export interface RemoteBuildStoreOptions {
|
|
|
170
177
|
}
|
|
171
178
|
|
|
172
179
|
export class RemoteBuildStore implements BuildStore {
|
|
180
|
+
readonly catalogIdentity = READ_CATALOG_IDENTITY
|
|
181
|
+
readonly networkReads = true
|
|
182
|
+
// Reader-local accumulators for this client instance. Never publish these into the service's
|
|
183
|
+
// cache: its catalog may interpret the same journal differently.
|
|
184
|
+
private readonly replayStates = new Map<string, { cursor: number; acc: unknown }>()
|
|
173
185
|
private readonly base: string
|
|
174
186
|
private readonly token: string | undefined
|
|
175
187
|
private readonly fetchFn: typeof fetch
|
|
@@ -275,7 +287,10 @@ export class RemoteBuildStore implements BuildStore {
|
|
|
275
287
|
}
|
|
276
288
|
|
|
277
289
|
async createBuild(input: NewBuildInput): Promise<BuildRecord> {
|
|
278
|
-
return this.requestJson('POST', '/builds', buildRecordWireSchema,
|
|
290
|
+
return this.requestJson('POST', '/builds', buildRecordWireSchema, {
|
|
291
|
+
...input,
|
|
292
|
+
...(input.created ? { created: validateEventWrite(input.created) } : {}),
|
|
293
|
+
})
|
|
279
294
|
}
|
|
280
295
|
|
|
281
296
|
async getBuild(slug: string): Promise<BuildRecord | null> {
|
|
@@ -294,12 +309,13 @@ export class RemoteBuildStore implements BuildStore {
|
|
|
294
309
|
// count. The route answers from build records, so an unknown repo or a
|
|
295
310
|
// repo without a journal record answers 200 with an empty array rather
|
|
296
311
|
// than 404 — the server composes it before the repository-existence gate.
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
312
|
+
const response = await this.raw('GET', `${this.repoPath(repo)}/build-digests`)
|
|
313
|
+
if (!response.ok) throw await this.toError(response)
|
|
314
|
+
const digests = buildDigestListSchema.parse(await response.json())
|
|
315
|
+
if (response.headers.get(CATALOG_IDENTITY_HEADER) === READ_CATALOG_IDENTITY)
|
|
316
|
+
return new Map(digests.map((digest) => [digest.slug, digest]))
|
|
317
|
+
const { readPersistedBuildDigests } = await import('../reduced-reads')
|
|
318
|
+
return readPersistedBuildDigests(this, repo)
|
|
303
319
|
}
|
|
304
320
|
|
|
305
321
|
async append<T extends EventType>(slug: string, event: EventWrite<T>): Promise<EventEnvelope<T>> {
|
|
@@ -307,7 +323,7 @@ export class RemoteBuildStore implements BuildStore {
|
|
|
307
323
|
'POST',
|
|
308
324
|
`${this.buildPath(slug)}/events`,
|
|
309
325
|
eventEnvelopeWireSchema,
|
|
310
|
-
|
|
326
|
+
validateEventWrite(event),
|
|
311
327
|
)
|
|
312
328
|
return envelope as unknown as EventEnvelope<T>
|
|
313
329
|
}
|
|
@@ -323,7 +339,7 @@ export class RemoteBuildStore implements BuildStore {
|
|
|
323
339
|
conditionalEventResponseSchema,
|
|
324
340
|
{
|
|
325
341
|
expectedSeq,
|
|
326
|
-
event:
|
|
342
|
+
event: validateEventWrite(event),
|
|
327
343
|
},
|
|
328
344
|
)
|
|
329
345
|
return envelope as EventEnvelope<T> | null
|
|
@@ -353,6 +369,13 @@ export class RemoteBuildStore implements BuildStore {
|
|
|
353
369
|
createdAt: '',
|
|
354
370
|
}))
|
|
355
371
|
const write = makeEvent(sentinels)
|
|
372
|
+
validateEventWrite({
|
|
373
|
+
...write,
|
|
374
|
+
payload: substitutePlaceholderRefs(
|
|
375
|
+
write.payload,
|
|
376
|
+
sentinels.map((meta) => ({ ...meta, revision: 0 })),
|
|
377
|
+
),
|
|
378
|
+
})
|
|
356
379
|
const result = await this.requestJson(
|
|
357
380
|
'POST',
|
|
358
381
|
`${this.buildPath(slug)}/deposits`,
|
|
@@ -363,7 +386,13 @@ export class RemoteBuildStore implements BuildStore {
|
|
|
363
386
|
contentBase64: encodeBase64(toBytes(artifact.content)),
|
|
364
387
|
...(artifact.metadata !== undefined ? { metadata: artifact.metadata } : {}),
|
|
365
388
|
})),
|
|
366
|
-
event: {
|
|
389
|
+
event: {
|
|
390
|
+
...write,
|
|
391
|
+
compatibility: stampCompatibility(
|
|
392
|
+
buildEventPolicy[write.type as keyof typeof buildEventPolicy],
|
|
393
|
+
write.compatibility,
|
|
394
|
+
),
|
|
395
|
+
},
|
|
367
396
|
},
|
|
368
397
|
)
|
|
369
398
|
return {
|
|
@@ -372,6 +401,55 @@ export class RemoteBuildStore implements BuildStore {
|
|
|
372
401
|
}
|
|
373
402
|
}
|
|
374
403
|
|
|
404
|
+
async appendWithArtifactsIfCurrent<T extends EventType>(
|
|
405
|
+
slug: string,
|
|
406
|
+
expectedSeq: number,
|
|
407
|
+
artifacts: ArtifactInput[],
|
|
408
|
+
makeEvent: (deposited: ArtifactMeta[]) => EventWrite<T>,
|
|
409
|
+
): Promise<{ event: EventEnvelope<T>; artifacts: ArtifactMeta[] } | null> {
|
|
410
|
+
const sentinels: ArtifactMeta[] = artifacts.map((artifact, index) => ({
|
|
411
|
+
build: slug,
|
|
412
|
+
kind: artifact.kind,
|
|
413
|
+
revision: placeholderRev(index),
|
|
414
|
+
blobRef: '',
|
|
415
|
+
metadata: structuredClone(artifact.metadata ?? {}),
|
|
416
|
+
createdAt: '',
|
|
417
|
+
}))
|
|
418
|
+
const write = makeEvent(sentinels)
|
|
419
|
+
validateEventWrite({
|
|
420
|
+
...write,
|
|
421
|
+
payload: substitutePlaceholderRefs(
|
|
422
|
+
write.payload,
|
|
423
|
+
sentinels.map((meta) => ({ ...meta, revision: 0 })),
|
|
424
|
+
),
|
|
425
|
+
})
|
|
426
|
+
const result = await this.requestJson(
|
|
427
|
+
'POST',
|
|
428
|
+
`${this.buildPath(slug)}/deposits/conditional`,
|
|
429
|
+
depositsResponseSchema.nullable(),
|
|
430
|
+
{
|
|
431
|
+
expectedSeq,
|
|
432
|
+
artifacts: artifacts.map((artifact) => ({
|
|
433
|
+
kind: artifact.kind,
|
|
434
|
+
contentBase64: encodeBase64(toBytes(artifact.content)),
|
|
435
|
+
...(artifact.metadata !== undefined ? { metadata: artifact.metadata } : {}),
|
|
436
|
+
})),
|
|
437
|
+
event: {
|
|
438
|
+
...write,
|
|
439
|
+
compatibility: stampCompatibility(
|
|
440
|
+
buildEventPolicy[write.type as keyof typeof buildEventPolicy],
|
|
441
|
+
write.compatibility,
|
|
442
|
+
),
|
|
443
|
+
},
|
|
444
|
+
},
|
|
445
|
+
)
|
|
446
|
+
if (result === null) return null
|
|
447
|
+
return {
|
|
448
|
+
event: result.event as unknown as EventEnvelope<T>,
|
|
449
|
+
artifacts: result.artifacts,
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
375
453
|
/** The BuildStore abort contract (AUT-380): a held read whose caller's
|
|
376
454
|
* signal fires resolves with the empty result — the client-side mirror of
|
|
377
455
|
* the server's `withDisconnect`, which discards the aborted response
|
|
@@ -517,7 +595,7 @@ export class RemoteBuildStore implements BuildStore {
|
|
|
517
595
|
'POST',
|
|
518
596
|
`${this.repoPath(repo)}/events`,
|
|
519
597
|
repositoryEventEnvelopeWireSchema,
|
|
520
|
-
|
|
598
|
+
validateRepositoryEventWrite(event),
|
|
521
599
|
)
|
|
522
600
|
return envelope as unknown as RepositoryEventEnvelope<T>
|
|
523
601
|
}
|
|
@@ -539,6 +617,13 @@ export class RemoteBuildStore implements BuildStore {
|
|
|
539
617
|
createdAt: '',
|
|
540
618
|
}))
|
|
541
619
|
const write = makeEvent(sentinels)
|
|
620
|
+
validateRepositoryEventWrite({
|
|
621
|
+
...write,
|
|
622
|
+
payload: substitutePlaceholderRefs(
|
|
623
|
+
write.payload,
|
|
624
|
+
sentinels.map((meta) => ({ ...meta, revision: 0 })),
|
|
625
|
+
),
|
|
626
|
+
})
|
|
542
627
|
const result = await this.requestJson(
|
|
543
628
|
'POST',
|
|
544
629
|
`${this.repoPath(repo)}/deposits`,
|
|
@@ -549,7 +634,13 @@ export class RemoteBuildStore implements BuildStore {
|
|
|
549
634
|
contentBase64: encodeBase64(toBytes(artifact.content)),
|
|
550
635
|
...(artifact.metadata !== undefined ? { metadata: artifact.metadata } : {}),
|
|
551
636
|
})),
|
|
552
|
-
event: {
|
|
637
|
+
event: {
|
|
638
|
+
...write,
|
|
639
|
+
compatibility: stampCompatibility(
|
|
640
|
+
repositoryEventPolicy[write.type as keyof typeof repositoryEventPolicy],
|
|
641
|
+
write.compatibility,
|
|
642
|
+
),
|
|
643
|
+
},
|
|
553
644
|
},
|
|
554
645
|
)
|
|
555
646
|
return {
|
|
@@ -580,14 +671,49 @@ export class RemoteBuildStore implements BuildStore {
|
|
|
580
671
|
}
|
|
581
672
|
|
|
582
673
|
async getReducerValue(scope: SnapshotScope, request: ReducerValueRequest): Promise<ReducerValue> {
|
|
583
|
-
resolveReducerValue(scope, request)
|
|
674
|
+
const { reducer, entry, identity: replayIdentity } = resolveReducerValue(scope, request)
|
|
584
675
|
const root = scope.kind === 'build' ? this.buildPath(scope.slug) : this.repoPath(scope.repo)
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
676
|
+
const response = await this.raw('POST', `${root}/reducer-values`, request)
|
|
677
|
+
if (!response.ok) throw await this.toError(response)
|
|
678
|
+
const result = reducerValueSchema.parse(await response.json())
|
|
679
|
+
const identity = response.headers.get(CATALOG_IDENTITY_HEADER)
|
|
680
|
+
if (
|
|
681
|
+
identity === READ_CATALOG_IDENTITY &&
|
|
682
|
+
result.version === reducer.version &&
|
|
683
|
+
validateReducerValue(request.reducer, result.value)
|
|
684
|
+
)
|
|
685
|
+
return {
|
|
686
|
+
version: result.version,
|
|
687
|
+
cursor: result.cursor,
|
|
688
|
+
value: result.value as ReducerValue['value'],
|
|
689
|
+
catalogIdentity: identity,
|
|
690
|
+
}
|
|
691
|
+
// Freeze at this response's cursor, including when concurrent reads finish
|
|
692
|
+
// out of order. Clone before folding: reducers may mutate their accumulator.
|
|
693
|
+
const cached = this.replayStates.get(replayIdentity)
|
|
694
|
+
const reusable = cached !== undefined && cached.cursor <= result.cursor ? cached : undefined
|
|
695
|
+
let cursor = reusable?.cursor ?? 0
|
|
696
|
+
let acc = reusable === undefined ? reducer.initial() : structuredClone(reusable.acc)
|
|
697
|
+
if (cursor < result.cursor) {
|
|
698
|
+
const events =
|
|
699
|
+
scope.kind === 'build'
|
|
700
|
+
? await this.getEvents(scope.slug, cursor)
|
|
701
|
+
: await this.getRepoEvents(scope.repo, cursor)
|
|
702
|
+
const bounded = events.filter((event) => event.seq <= result.cursor)
|
|
703
|
+
for (const event of bounded) {
|
|
704
|
+
if (event.seq !== cursor + 1) throw new Error('noncontiguous reducer log')
|
|
705
|
+
cursor = event.seq
|
|
706
|
+
}
|
|
707
|
+
if (cursor !== result.cursor) throw new Error('incomplete reducer log')
|
|
708
|
+
acc = reducer.advance(acc, entry.adapt(projectStoredEvents(bounded)))
|
|
709
|
+
}
|
|
710
|
+
const value = entry.value(reducer.finish(structuredClone(acc)))
|
|
711
|
+
// Commit only successful folds, and never regress a concurrent accumulator.
|
|
712
|
+
if ((this.replayStates.get(replayIdentity)?.cursor ?? -1) <= cursor) {
|
|
713
|
+
this.replayStates.delete(replayIdentity)
|
|
714
|
+
this.replayStates.set(replayIdentity, { cursor, acc })
|
|
715
|
+
}
|
|
716
|
+
return { version: reducer.version, cursor, value, catalogIdentity: READ_CATALOG_IDENTITY }
|
|
591
717
|
}
|
|
592
718
|
|
|
593
719
|
private snapshotPath(scope: SnapshotScope, reducer: string): string {
|
|
@@ -903,7 +1029,7 @@ export class RemoteBuildStore implements BuildStore {
|
|
|
903
1029
|
'POST',
|
|
904
1030
|
`${this.repoPath(repo)}/tick/finish`,
|
|
905
1031
|
finishRepoTickResponseSchema,
|
|
906
|
-
{ holder, completion, events },
|
|
1032
|
+
{ holder, completion, events: events.map((event) => validateRepositoryEventWrite(event)) },
|
|
907
1033
|
)) as RepoTickFinish | null
|
|
908
1034
|
}
|
|
909
1035
|
|
|
@@ -17,6 +17,12 @@ export function releaseVersion(value: unknown): semver.SemVer | undefined {
|
|
|
17
17
|
return parsed && parsed.version === value ? parsed : undefined
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/** Capability history, independent of admission: the audit signal arrived in 0.14. */
|
|
21
|
+
export function clientSupportsIntegrationAuditPending(version: unknown): boolean {
|
|
22
|
+
const parsed = releaseVersion(version)
|
|
23
|
+
return parsed !== undefined && (parsed.major > 0 || parsed.minor >= 14)
|
|
24
|
+
}
|
|
25
|
+
|
|
20
26
|
const stableVersionSchema = z.string().refine((value) => stableVersion(value) !== undefined)
|
|
21
27
|
export const supportedClientRangeSchema = z
|
|
22
28
|
.strictObject({
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export type { StoredEvent } from '../../events/compatibility'
|
|
1
2
|
// Client half + shared wire vocabulary for the remote BuildStore (SPEC §7.2).
|
|
2
3
|
// The HTTP server half ships in `@defrex/autobuild-hosted-store-service`;
|
|
3
4
|
// this barrel is what a local CLI and the hosted package both build against.
|
|
@@ -12,6 +13,7 @@ export type {
|
|
|
12
13
|
DelegatedTokenScope,
|
|
13
14
|
} from './token'
|
|
14
15
|
export {
|
|
16
|
+
CATALOG_IDENTITY_HEADER,
|
|
15
17
|
AUTOBUILD_VERSION,
|
|
16
18
|
AUTOBUILD_VERSION_HEADER,
|
|
17
19
|
REMOTE_STORE_PROTOCOL_VERSION,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { compatibilityMetadataSchema } from '../../events/policy'
|
|
1
2
|
/**
|
|
2
3
|
* The wire protocol of the remote BuildStore (SPEC §7.2 adapter 2): JSON
|
|
3
4
|
* bodies, artifact content as base64, errors as `{error, kind}`. Server
|
|
@@ -50,6 +51,7 @@ export type ErrorBody = z.infer<typeof errorBodySchema>
|
|
|
50
51
|
* shadowed by a duplicate wire-schema error.
|
|
51
52
|
*/
|
|
52
53
|
export const eventWriteWireSchema = z.object({
|
|
54
|
+
compatibility: compatibilityMetadataSchema.optional(),
|
|
53
55
|
actor: z.unknown(),
|
|
54
56
|
type: z.string().min(1),
|
|
55
57
|
payload: z.unknown(),
|
|
@@ -87,6 +89,7 @@ export const buildRecordListSchema = z.array(buildRecordWireSchema)
|
|
|
87
89
|
// ── Events ───────────────────────────────────────────────────────────────────
|
|
88
90
|
|
|
89
91
|
export const eventEnvelopeWireSchema = z.object({
|
|
92
|
+
compatibility: compatibilityMetadataSchema.optional(),
|
|
90
93
|
build: z.string(),
|
|
91
94
|
seq: z.number().int().positive(),
|
|
92
95
|
ts: z.string(),
|
|
@@ -115,6 +118,7 @@ export const repositoryRecordWireSchema = z.object({
|
|
|
115
118
|
})
|
|
116
119
|
|
|
117
120
|
export const repositoryEventEnvelopeWireSchema = z.object({
|
|
121
|
+
compatibility: compatibilityMetadataSchema.optional(),
|
|
118
122
|
repo: z.string(),
|
|
119
123
|
seq: z.number().int().positive(),
|
|
120
124
|
ts: z.string(),
|
|
@@ -283,6 +287,20 @@ export const sessionDepositsResponseSchema = z.object({
|
|
|
283
287
|
// the build's log carries no terminal fact, per the protocol's omission
|
|
284
288
|
// convention for optional members.
|
|
285
289
|
export const buildDigestWireSchema = z.object({
|
|
290
|
+
compatibility: z
|
|
291
|
+
.object({
|
|
292
|
+
unknownFacts: z.number().int().nonnegative(),
|
|
293
|
+
decisiveFacts: z.number().int().nonnegative(),
|
|
294
|
+
lastSeq: z.number().int().nonnegative(),
|
|
295
|
+
decisiveBoundary: z.number().int().nonnegative(),
|
|
296
|
+
types: z.array(z.string()),
|
|
297
|
+
writerVersions: z.array(z.string()),
|
|
298
|
+
legacyVersionUnavailable: z.boolean(),
|
|
299
|
+
decisiveTypes: z.array(z.string()).default([]),
|
|
300
|
+
decisiveWriterVersions: z.array(z.string()).default([]),
|
|
301
|
+
decisiveLegacyVersionUnavailable: z.boolean().default(false),
|
|
302
|
+
})
|
|
303
|
+
.optional(),
|
|
286
304
|
integrationAuditPending: z.literal(true).optional(),
|
|
287
305
|
mergedSha: z.string().min(1).optional(),
|
|
288
306
|
nodeContribution: eventPayloadSchemas['node.contribution-recorded'].optional(),
|
|
@@ -334,6 +352,7 @@ export const artifactGetResponseSchema = z.union([
|
|
|
334
352
|
// ── Atomic deposits (see module header) ──────────────────────────────────────
|
|
335
353
|
|
|
336
354
|
export const depositsBodySchema = z.object({
|
|
355
|
+
expectedSeq: z.number().int().nonnegative().optional(),
|
|
337
356
|
artifacts: z.array(putArtifactBodySchema),
|
|
338
357
|
event: eventWriteWireSchema,
|
|
339
358
|
})
|
|
@@ -14,3 +14,5 @@ export const REMOTE_STORE_PROTOCOL_VERSION = '4'
|
|
|
14
14
|
|
|
15
15
|
export const AUTOBUILD_VERSION_HEADER = 'x-autobuild-version'
|
|
16
16
|
export const REMOTE_STORE_PROTOCOL_VERSION_HEADER = 'x-autobuild-protocol-version'
|
|
17
|
+
|
|
18
|
+
export const CATALOG_IDENTITY_HEADER = 'x-autobuild-catalog-identity'
|
|
@@ -23,6 +23,8 @@ const RUN_STARTED = 'dispatcher.run-started'
|
|
|
23
23
|
* setting types are enumerated because they share one schema group with the
|
|
24
24
|
* run-correlated `dispatcher.config-reloaded`. */
|
|
25
25
|
export const REPOSITORY_STATE_EVENT_TYPES: readonly RepositoryEventType[] = [
|
|
26
|
+
'dispatcher.forge-degraded',
|
|
27
|
+
'dispatcher.forge-recovered',
|
|
26
28
|
...Object.keys(changePresenceEventPayloadSchemas),
|
|
27
29
|
...Object.keys(ticketSourceHealthEventPayloadSchemas),
|
|
28
30
|
...Object.keys(harvestEventPayloadSchemas),
|
|
@@ -151,7 +153,7 @@ export interface JournalViewAcc {
|
|
|
151
153
|
}
|
|
152
154
|
|
|
153
155
|
/** Bump when `JournalViewAcc` or its fold changes. */
|
|
154
|
-
export const JOURNAL_VIEW_REDUCER_VERSION =
|
|
156
|
+
export const JOURNAL_VIEW_REDUCER_VERSION = 5
|
|
155
157
|
|
|
156
158
|
/** Fold seq-ordered events into a journal view in place. */
|
|
157
159
|
export function foldJournalView(acc: JournalViewAcc, events: readonly RepositoryEvent[]): void {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod'
|
|
2
|
+
import { forgeRequestCountsSchema } from '../ports/forge-telemetry'
|
|
2
3
|
import { EventValidationError } from '../events/catalog'
|
|
3
4
|
import {
|
|
4
5
|
dispatcherStatusEventPayloadSchemas,
|
|
@@ -12,7 +13,11 @@ export const repoTickCompletionSchema = z.discriminatedUnion('outcome', [
|
|
|
12
13
|
outcome: z.literal('completed'),
|
|
13
14
|
counters: dispatcherStatusEventPayloadSchemas['dispatcher.tick-completed'].shape.counters,
|
|
14
15
|
}),
|
|
15
|
-
z.object({
|
|
16
|
+
z.object({
|
|
17
|
+
outcome: z.literal('failed'),
|
|
18
|
+
error: z.string().min(1),
|
|
19
|
+
forgeRequests: forgeRequestCountsSchema.optional(),
|
|
20
|
+
}),
|
|
16
21
|
])
|
|
17
22
|
export const repoTickObservationSchema = z.object({
|
|
18
23
|
run: z.string().min(1),
|
|
@@ -126,6 +126,14 @@ export function createSessionScopedStore(store: BuildStore, scope: string): Sess
|
|
|
126
126
|
): Promise<{ event: EventEnvelope<T>; artifacts: ArtifactMeta[] }> {
|
|
127
127
|
return Promise.reject(new SessionScopeError(scope, 'appendWithArtifacts', slug))
|
|
128
128
|
},
|
|
129
|
+
appendWithArtifactsIfCurrent<T extends EventType>(
|
|
130
|
+
slug: string,
|
|
131
|
+
_expectedSeq: number,
|
|
132
|
+
_artifacts: ArtifactInput[],
|
|
133
|
+
_makeEvent: (deposited: ArtifactMeta[]) => EventWrite<T>,
|
|
134
|
+
): Promise<{ event: EventEnvelope<T>; artifacts: ArtifactMeta[] } | null> {
|
|
135
|
+
return Promise.reject(new SessionScopeError(scope, 'appendWithArtifactsIfCurrent', slug))
|
|
136
|
+
},
|
|
129
137
|
getEvents(slug: string, _sinceSeq?: number): Promise<AbEvent[]> {
|
|
130
138
|
return Promise.reject(new SessionScopeError(scope, 'getEvents', slug))
|
|
131
139
|
},
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { READ_CATALOG_IDENTITY } from '../events/compatibility'
|
|
1
2
|
/**
|
|
2
3
|
* Reducer snapshots: a cache beside the event log, never an authority.
|
|
3
4
|
*
|
|
@@ -51,13 +52,14 @@ export function snapshotScopeKey(scope: SnapshotScope): string {
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
/** Whether a put replaces the stored row. The stored cursor never decreases:
|
|
54
|
-
*
|
|
55
|
-
* an older shape at an unchanged cursor. */
|
|
55
|
+
* an advancing cursor never downgrades the stored reducer version, and an
|
|
56
|
+
* upgraded reducer may replace an older shape at an unchanged cursor. */
|
|
56
57
|
export function snapshotSupersedes(
|
|
57
58
|
next: Pick<ReducerSnapshot, 'version' | 'cursor'>,
|
|
58
59
|
stored: Pick<ReducerSnapshot, 'version' | 'cursor'> | undefined,
|
|
59
60
|
): boolean {
|
|
60
61
|
if (stored === undefined) return true
|
|
62
|
+
if (next.version < stored.version) return false
|
|
61
63
|
if (next.cursor !== stored.cursor) return next.cursor > stored.cursor
|
|
62
64
|
return next.version > stored.version
|
|
63
65
|
}
|
|
@@ -73,10 +75,13 @@ export async function loadReducerSnapshot(
|
|
|
73
75
|
): Promise<ReducerSnapshot | null> {
|
|
74
76
|
if (store.getReducerSnapshot === undefined) return null
|
|
75
77
|
try {
|
|
76
|
-
const found = await store.getReducerSnapshot(scope, name, reducer.version)
|
|
78
|
+
const found = await store.getReducerSnapshot(scope, catalogSnapshotName(name), reducer.version)
|
|
77
79
|
if (found === null || found.version !== reducer.version) return null
|
|
78
80
|
if (!Number.isInteger(found.cursor) || found.cursor < 0) return null
|
|
79
|
-
|
|
81
|
+
const state = found.state as { catalogIdentity?: unknown; acc?: unknown } | null
|
|
82
|
+
if (!state || state.catalogIdentity !== READ_CATALOG_IDENTITY || !Object.hasOwn(state, 'acc'))
|
|
83
|
+
return null
|
|
84
|
+
return { ...found, state: state.acc }
|
|
80
85
|
} catch {
|
|
81
86
|
return null
|
|
82
87
|
}
|
|
@@ -91,8 +96,19 @@ export async function persistReducerSnapshot(
|
|
|
91
96
|
): Promise<boolean> {
|
|
92
97
|
if (store.putReducerSnapshot === undefined) return false
|
|
93
98
|
try {
|
|
94
|
-
return await store.putReducerSnapshot(scope, name,
|
|
99
|
+
return await store.putReducerSnapshot(scope, catalogSnapshotName(name), {
|
|
100
|
+
...snapshot,
|
|
101
|
+
state: { catalogIdentity: READ_CATALOG_IDENTITY, acc: snapshot.state },
|
|
102
|
+
})
|
|
95
103
|
} catch {
|
|
96
104
|
return false
|
|
97
105
|
}
|
|
98
106
|
}
|
|
107
|
+
|
|
108
|
+
/** Fixed-size names isolate checkpoints even when reducer integers match. */
|
|
109
|
+
export function catalogSnapshotName(name: string, catalogIdentity = READ_CATALOG_IDENTITY): string {
|
|
110
|
+
return `catalog.${new Bun.CryptoHasher('sha256')
|
|
111
|
+
.update(JSON.stringify([name, catalogIdentity]))
|
|
112
|
+
.digest('hex')
|
|
113
|
+
.slice(0, 56)}`
|
|
114
|
+
}
|