@defrex/autobuild 1.3.0 → 1.4.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.
- package/README.md +1 -1
- package/SPEC.md +302 -26
- package/docs/accounts.md +38 -0
- package/docs/architecture.md +187 -19
- package/docs/build-store.md +18 -0
- package/docs/builds.md +5 -1
- package/docs/cli.md +1 -1
- package/docs/configuration.md +38 -19
- package/docs/dispatcher-hosting.md +42 -0
- package/docs/dispatcher.md +41 -0
- package/docs/forges.md +5 -0
- package/docs/integration-tree.md +8 -0
- package/docs/operating.md +11 -3
- package/docs/operator-api.md +37 -4
- package/docs/plugin-authoring.md +45 -1
- package/docs/remote-store-protocol.md +258 -42
- package/docs/remote-ticket-protocol.md +12 -10
- package/docs/restacking.md +60 -3
- package/docs/setup.md +37 -8
- package/docs/skills.md +1 -1
- package/docs/spec-standard.md +37 -3
- package/docs/troubleshooting.md +9 -0
- package/docs/workspaces.md +1 -1
- package/package.json +4 -3
- package/packages/core/src/accounts/availability.ts +96 -0
- package/packages/core/src/accounts/local-owner.ts +49 -2
- package/packages/core/src/cli/attention.ts +2 -0
- package/packages/core/src/cli/binary.ts +17 -1
- package/packages/core/src/cli/context.ts +62 -0
- package/packages/core/src/cli/dashboard/model.ts +12 -3
- package/packages/core/src/cli/dashboard/poll.ts +65 -8
- package/packages/core/src/cli/dashboard/refresh.ts +2 -0
- package/packages/core/src/cli/dashboard/render.ts +46 -5
- package/packages/core/src/cli/dispatch-args.ts +27 -3
- package/packages/core/src/cli/dispatch-frontend.ts +178 -52
- package/packages/core/src/cli/dispatch-mode.ts +94 -0
- package/packages/core/src/cli/dispatch-preflight.ts +43 -0
- package/packages/core/src/cli/dispatch-repository-feed.ts +45 -9
- package/packages/core/src/cli/dispatch.ts +145 -11
- package/packages/core/src/cli/harvest.ts +2 -1
- package/packages/core/src/cli/help.ts +16 -3
- package/packages/core/src/cli/historical-build-state.ts +6 -0
- package/packages/core/src/cli/main.ts +15 -2
- package/packages/core/src/cli/publication-settlement.ts +17 -0
- package/packages/core/src/cli/remote-poll.ts +11 -1
- package/packages/core/src/cli/repository-status.ts +11 -0
- package/packages/core/src/cli/status.ts +7 -1
- package/packages/core/src/cli/wait.ts +9 -2
- package/packages/core/src/cli/watch.ts +38 -3
- package/packages/core/src/config/roles.ts +16 -1
- package/packages/core/src/events/catalog.ts +7 -0
- package/packages/core/src/events/payloads.ts +85 -2
- package/packages/core/src/events/policy.ts +10 -0
- package/packages/core/src/events/repository.ts +35 -0
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +189 -0
- package/packages/core/src/kernel/dispatch-placement.ts +30 -0
- package/packages/core/src/kernel/engine.ts +19 -12
- package/packages/core/src/kernel/generators/leaf-restack-log.ts +17 -1
- package/packages/core/src/kernel/leaf-restack-state.ts +24 -2
- package/packages/core/src/kernel/log-index.ts +1 -1
- package/packages/core/src/kernel/node-landing.ts +27 -10
- package/packages/core/src/kernel/node-restack-demand.ts +1 -0
- package/packages/core/src/kernel/node-restack-state.ts +16 -1
- package/packages/core/src/kernel/node-restack-transaction.ts +14 -0
- package/packages/core/src/kernel/read-facts.ts +114 -9
- package/packages/core/src/kernel/reconcile-head.ts +34 -11
- package/packages/core/src/kernel/reconcile-restack.ts +106 -72
- package/packages/core/src/kernel/reducer-registry.ts +3 -0
- package/packages/core/src/kernel/reducer.ts +20 -2
- package/packages/core/src/kernel/replay-retention.ts +176 -0
- package/packages/core/src/kernel/target-lineage.ts +65 -0
- package/packages/core/src/kernel/target-observation.ts +117 -0
- package/packages/core/src/operator/registry.ts +5 -13
- package/packages/core/src/operator/tickets.ts +8 -2
- package/packages/core/src/plugin-sdk/index.ts +1 -0
- package/packages/core/src/ports/forge/fake.ts +22 -0
- package/packages/core/src/ports/forge/git-rewrite.ts +49 -12
- package/packages/core/src/ports/forge/github.ts +42 -10
- package/packages/core/src/ports/forge/local-git.ts +16 -1
- package/packages/core/src/ports/types.ts +58 -4
- package/packages/core/src/ports/workspace/account-policy.ts +2 -1
- package/packages/core/src/ports/workspace/commit-preservation.ts +175 -0
- package/packages/core/src/ports/workspace/create.ts +2 -0
- package/packages/core/src/ports/workspace/fake.ts +4 -0
- package/packages/core/src/ports/workspace/git-worktree.ts +22 -1
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +304 -56
- package/packages/core/src/processes/build-runner.ts +240 -111
- package/packages/core/src/processes/dispatcher-selectors.ts +3 -2
- package/packages/core/src/processes/dispatcher.ts +262 -80
- package/packages/core/src/processes/execution-no-progress.ts +7 -0
- package/packages/core/src/processes/harvest-runner.ts +6 -7
- package/packages/core/src/processes/publication-state.ts +2 -1
- package/packages/core/src/processes/repo-view.ts +22 -0
- package/packages/core/src/processes/workspace-preservation.ts +164 -0
- package/packages/core/src/scenarios/harness.ts +7 -0
- package/packages/core/src/store/adapter.ts +9 -0
- package/packages/core/src/store/build-scope.ts +28 -0
- package/packages/core/src/store/contract.ts +125 -0
- package/packages/core/src/store/event-reads.ts +156 -0
- package/packages/core/src/store/local/schema.ts +11 -0
- package/packages/core/src/store/local/store.ts +117 -2
- package/packages/core/src/store/memory.ts +237 -0
- package/packages/core/src/store/phase-session.ts +47 -0
- package/packages/core/src/store/reduced-reads.ts +8 -0
- package/packages/core/src/store/reducer-value-shapes.json +6262 -5227
- package/packages/core/src/store/reducer-value-validation.ts +3 -0
- package/packages/core/src/store/reducer-values.ts +62 -2
- package/packages/core/src/store/remote/client.ts +161 -16
- package/packages/core/src/store/remote/compatibility.ts +177 -46
- package/packages/core/src/store/remote/errors.ts +16 -0
- package/packages/core/src/store/remote/index.ts +11 -0
- package/packages/core/src/store/remote/protocol.ts +22 -0
- package/packages/core/src/store/remote/released-clients.json +37 -0
- package/packages/core/src/store/remote/released-clients.ts +88 -0
- package/packages/core/src/store/remote/released-reducer-values/1.3.0.json +25093 -0
- package/packages/core/src/store/remote/released-reducer-values/1.4.0.json +26128 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +13 -0
- package/packages/core/src/store/remote/version.ts +5 -2
- package/packages/core/src/store/repo-state-events.ts +4 -3
- package/packages/core/src/store/scan-cadence.ts +15 -0
- package/packages/core/src/store/session-handle.ts +18 -0
- package/packages/core/src/store/types.ts +27 -6
- package/packages/core/src/testing/dispatch-read-budget.ts +313 -2
- package/packages/core/src/testing/index.ts +5 -0
- package/packages/core/src/testing/reduced-read-budget.ts +728 -5
- package/skills/guide/SKILL.md +177 -16
- package/skills/guide/references/accounts.md +38 -0
- package/skills/guide/references/integration-tree.md +8 -0
- package/skills/guide/references/operator-api.md +37 -4
- package/skills/guide/references/plugin-authoring.md +45 -1
- package/skills/guide/references/remote-store-protocol.md +258 -42
- package/skills/guide/references/remote-ticket-protocol.md +12 -10
- package/skills/guide/references/restacking.md +60 -3
- package/skills/guide/references/setup.md +37 -8
- package/skills/guide/references/spec-standard.md +37 -3
- package/skills/implement/SKILL.md +12 -3
- package/skills/operate/SKILL.md +64 -7
- package/skills/plan/SKILL.md +27 -4
- package/skills/plan-review/SKILL.md +22 -2
- package/skills/reconcile/SKILL.md +10 -1
- package/skills/spec/SKILL.md +7 -4
- package/templates/hosted-service/package.json +2 -2
|
@@ -126,6 +126,10 @@ export class RepoViewStore implements BuildStore {
|
|
|
126
126
|
private readonly backing: BuildStore,
|
|
127
127
|
opts: RepoViewOptions,
|
|
128
128
|
) {
|
|
129
|
+
this.getBuildEventPage = backing.getBuildEventPage?.bind(backing)
|
|
130
|
+
this.getRepositoryTail = backing.getRepositoryTail?.bind(backing)
|
|
131
|
+
this.getStreamSeed = backing.getStreamSeed?.bind(backing)
|
|
132
|
+
this.getHarvestHistoryPage = backing.getHarvestHistoryPage?.bind(backing)
|
|
129
133
|
this.repo = opts.repo
|
|
130
134
|
}
|
|
131
135
|
private build<T>(slug: string, task: () => Promise<T>): Promise<T> {
|
|
@@ -290,6 +294,10 @@ export class RepoViewStore implements BuildStore {
|
|
|
290
294
|
getRepoStateEvents(repo: string): Promise<RepositoryEvent[]> {
|
|
291
295
|
return this.backing.getRepoStateEvents(repo)
|
|
292
296
|
}
|
|
297
|
+
getBuildEventPage: BuildStore['getBuildEventPage']
|
|
298
|
+
getRepositoryTail: BuildStore['getRepositoryTail']
|
|
299
|
+
getStreamSeed: BuildStore['getStreamSeed']
|
|
300
|
+
getHarvestHistoryPage: BuildStore['getHarvestHistoryPage']
|
|
293
301
|
getReducerValue(scope: SnapshotScope, request: ReducerValueRequest): Promise<ReducerValue> {
|
|
294
302
|
return this.backing.getReducerValue(scope, request)
|
|
295
303
|
}
|
|
@@ -462,6 +470,16 @@ export class RepoViewStore implements BuildStore {
|
|
|
462
470
|
await this.backing.releaseLease(slug, holder)
|
|
463
471
|
this.invalidate()
|
|
464
472
|
}
|
|
473
|
+
getScanCadence(repo: string) {
|
|
474
|
+
return this.backing.getScanCadence(repo)
|
|
475
|
+
}
|
|
476
|
+
putScanCadence(
|
|
477
|
+
repo: string,
|
|
478
|
+
cadence: import('../store/scan-cadence').ScanCadence,
|
|
479
|
+
allowClockRollback = false,
|
|
480
|
+
) {
|
|
481
|
+
return this.backing.putScanCadence(repo, cadence, allowClockRollback)
|
|
482
|
+
}
|
|
465
483
|
upsertOperatorPresence(
|
|
466
484
|
repo: string,
|
|
467
485
|
identity: OperatorIdentity,
|
|
@@ -495,6 +513,10 @@ export class RepoViewStore implements BuildStore {
|
|
|
495
513
|
getArtifact(slug: string, kind: string, rev?: number): Promise<Artifact | null> {
|
|
496
514
|
return this.backing.getArtifact(slug, kind, rev)
|
|
497
515
|
}
|
|
516
|
+
get getNodeRewrite(): BuildStore['getNodeRewrite'] {
|
|
517
|
+
return this.backing.getNodeRewrite?.bind(this.backing)
|
|
518
|
+
}
|
|
519
|
+
|
|
498
520
|
get getLatestArtifactMeta(): BuildStore['getLatestArtifactMeta'] {
|
|
499
521
|
return this.backing.getLatestArtifactMeta?.bind(this.backing)
|
|
500
522
|
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { DISPATCHER } from '../events/envelope'
|
|
2
|
+
import { remoteBranchHead } from '../ports/forge/git-rewrite'
|
|
3
|
+
import type { Forge, WorkspaceProvider } from '../ports/types'
|
|
4
|
+
import type { Exec } from '../ports/workspace/git-worktree'
|
|
5
|
+
import { preserveGitCommits } from '../ports/workspace/commit-preservation'
|
|
6
|
+
import { readBuildFacts } from '../store/reduced-reads'
|
|
7
|
+
import type { BuildStore } from '../store/types'
|
|
8
|
+
|
|
9
|
+
export class WorkspaceFenceUnknown extends Error {}
|
|
10
|
+
|
|
11
|
+
/** Every caller holds the build's cleanup boundary. A fence is revalidated on
|
|
12
|
+
* every invocation, including restart: durable receipts cannot stop new code. */
|
|
13
|
+
export async function preserveWorkspaceBeforeRelease(deps: {
|
|
14
|
+
store: BuildStore
|
|
15
|
+
slug: string
|
|
16
|
+
owner: WorkspaceProvider
|
|
17
|
+
forge: Forge
|
|
18
|
+
exec: Exec
|
|
19
|
+
reason: string
|
|
20
|
+
now?: Date
|
|
21
|
+
}): Promise<void> {
|
|
22
|
+
let current = await readBuildFacts(deps.store, deps.slug)
|
|
23
|
+
const source = current.value.latestWorkspace
|
|
24
|
+
if (!source || current.value.workspace === null) return
|
|
25
|
+
const handle = { ...source.payload, path: source.payload.path ?? source.payload.ref }
|
|
26
|
+
const execution = current.value.state.executions.at(-1)
|
|
27
|
+
const executionSeq = execution?.workspaceRef === source.payload.ref ? execution.seq : 0
|
|
28
|
+
const record = await deps.store.getBuild(deps.slug)
|
|
29
|
+
if (
|
|
30
|
+
current.value.open !== null &&
|
|
31
|
+
record?.lease &&
|
|
32
|
+
new Date(record.lease.expiresAt).getTime() > (deps.now ?? new Date()).getTime()
|
|
33
|
+
)
|
|
34
|
+
throw new Error('workspace preservation refused while execution lease is live')
|
|
35
|
+
if (!deps.owner.recovery && current.value.open !== null)
|
|
36
|
+
throw new WorkspaceFenceUnknown('local execution teardown has not been recorded')
|
|
37
|
+
const outcome = deps.owner.recovery
|
|
38
|
+
? await deps.owner.recovery.fence?.(handle)
|
|
39
|
+
: { outcome: 'confirmed' as const }
|
|
40
|
+
if (!outcome || outcome.outcome === 'unknown')
|
|
41
|
+
throw new WorkspaceFenceUnknown(
|
|
42
|
+
`workspace fence is unknown: ${outcome && 'error' in outcome ? outcome.error : 'provider lacks non-destructive fencing'}`,
|
|
43
|
+
)
|
|
44
|
+
const fence = current.value.workspaceFence?.payload
|
|
45
|
+
if (
|
|
46
|
+
fence?.workspace !== source.seq ||
|
|
47
|
+
fence.execution !== executionSeq ||
|
|
48
|
+
fence.outcome !== outcome.outcome
|
|
49
|
+
) {
|
|
50
|
+
if (
|
|
51
|
+
!(await deps.store.appendIfCurrent(deps.slug, current.cursor, {
|
|
52
|
+
actor: DISPATCHER,
|
|
53
|
+
type: 'workspace.fenced',
|
|
54
|
+
payload: {
|
|
55
|
+
workspace: source.seq,
|
|
56
|
+
execution: executionSeq,
|
|
57
|
+
ref: handle.ref,
|
|
58
|
+
outcome: outcome.outcome,
|
|
59
|
+
},
|
|
60
|
+
}))
|
|
61
|
+
)
|
|
62
|
+
throw new Error('workspace changed during fencing; retry cleanup')
|
|
63
|
+
current = await readBuildFacts(deps.store, deps.slug)
|
|
64
|
+
}
|
|
65
|
+
const prior = current.value.workspacePreservation?.payload
|
|
66
|
+
const loss = current.value.workspaceLoss?.payload
|
|
67
|
+
if (
|
|
68
|
+
outcome.outcome === 'absent' &&
|
|
69
|
+
loss?.workspace === source.seq &&
|
|
70
|
+
loss.execution === executionSeq
|
|
71
|
+
)
|
|
72
|
+
return
|
|
73
|
+
const request = current.value.publication.latestUncompletedRequest()
|
|
74
|
+
const candidates = [
|
|
75
|
+
...new Set([
|
|
76
|
+
...(request && !current.value.publication.lostRecorded(request) ? [request.payload.sha] : []),
|
|
77
|
+
...(prior?.heads.map((head) => head.sha) ?? []),
|
|
78
|
+
]),
|
|
79
|
+
]
|
|
80
|
+
const metadata = {
|
|
81
|
+
workspace: source.seq,
|
|
82
|
+
execution: executionSeq,
|
|
83
|
+
ref: handle.ref,
|
|
84
|
+
branch: handle.branch,
|
|
85
|
+
phase: current.value.state.phase ?? 'implement',
|
|
86
|
+
round: current.value.state.round ?? 1,
|
|
87
|
+
}
|
|
88
|
+
let preserved:
|
|
89
|
+
| { outcome: 'preserved'; heads: import('../ports/types').WorkspacePreservationHead[] }
|
|
90
|
+
| { outcome: 'absent' }
|
|
91
|
+
if (outcome.outcome === 'absent') preserved = { outcome: 'absent' }
|
|
92
|
+
else if (deps.owner.preservation || deps.owner.publication) {
|
|
93
|
+
const preserve = deps.owner.preservation ?? deps.owner.publication?.preserve
|
|
94
|
+
if (!preserve) throw new Error('remote provider lacks trusted commit preservation')
|
|
95
|
+
preserved = await preserve({
|
|
96
|
+
ref: handle.ref,
|
|
97
|
+
slug: deps.slug,
|
|
98
|
+
branch: handle.branch,
|
|
99
|
+
base: source.payload.base.sha,
|
|
100
|
+
candidates,
|
|
101
|
+
})
|
|
102
|
+
} else {
|
|
103
|
+
const rewrite = deps.forge.kernelRewrite ?? deps.forge.rewrite
|
|
104
|
+
if (!rewrite) throw new Error('forge lacks immutable workspace commit archives')
|
|
105
|
+
let base: string
|
|
106
|
+
try {
|
|
107
|
+
base = await rewrite.snapshot({
|
|
108
|
+
workspacePath: handle.path,
|
|
109
|
+
branch: handle.branch,
|
|
110
|
+
destinationRef: `refs/autobuild/reconcile/${deps.slug}/preservation`,
|
|
111
|
+
})
|
|
112
|
+
} catch (error) {
|
|
113
|
+
// A never-published branch compares against its recorded base; any other
|
|
114
|
+
// snapshot failure, or an unreadable remote, keeps the workspace intact.
|
|
115
|
+
const remote = await remoteBranchHead(
|
|
116
|
+
deps.forge.kernelExec ?? deps.exec,
|
|
117
|
+
handle.path,
|
|
118
|
+
handle.branch,
|
|
119
|
+
).catch(() => undefined)
|
|
120
|
+
if (remote !== null) throw error
|
|
121
|
+
base = source.payload.base.sha
|
|
122
|
+
}
|
|
123
|
+
preserved = {
|
|
124
|
+
outcome: 'preserved',
|
|
125
|
+
heads: await preserveGitCommits({
|
|
126
|
+
exec: deps.forge.kernelExec ?? deps.exec,
|
|
127
|
+
workspacePath: handle.path,
|
|
128
|
+
branch: handle.branch,
|
|
129
|
+
slug: deps.slug,
|
|
130
|
+
base,
|
|
131
|
+
candidates,
|
|
132
|
+
archive: rewrite.archive,
|
|
133
|
+
}),
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (
|
|
137
|
+
preserved.outcome === 'preserved' &&
|
|
138
|
+
prior?.workspace === source.seq &&
|
|
139
|
+
prior.execution === executionSeq &&
|
|
140
|
+
JSON.stringify(prior.heads) === JSON.stringify(preserved.heads)
|
|
141
|
+
)
|
|
142
|
+
return
|
|
143
|
+
const write =
|
|
144
|
+
preserved.outcome === 'preserved'
|
|
145
|
+
? {
|
|
146
|
+
actor: DISPATCHER,
|
|
147
|
+
type: 'workspace.commits-preserved' as const,
|
|
148
|
+
payload: { ...metadata, heads: preserved.heads },
|
|
149
|
+
}
|
|
150
|
+
: {
|
|
151
|
+
actor: DISPATCHER,
|
|
152
|
+
type: 'workspace.commits-lost' as const,
|
|
153
|
+
payload: {
|
|
154
|
+
...metadata,
|
|
155
|
+
shas: [...new Set([...candidates, ...(request ? [request.payload.sha] : [])])].filter(
|
|
156
|
+
(sha) => !prior?.heads.some((head) => head.sha === sha),
|
|
157
|
+
),
|
|
158
|
+
inventory: 'additional-shas-unavailable' as const,
|
|
159
|
+
reason: `${deps.reason}: source environment is absent; additional unpublished SHAs could not be inspected`,
|
|
160
|
+
},
|
|
161
|
+
}
|
|
162
|
+
if (!(await deps.store.appendIfCurrent(deps.slug, current.cursor, write)))
|
|
163
|
+
throw new Error('workspace changed during commit preservation; retry cleanup')
|
|
164
|
+
}
|
|
@@ -476,6 +476,13 @@ export async function makeHarness(opts: {
|
|
|
476
476
|
gatePresence: opts.gatePresence ?? 'present',
|
|
477
477
|
...(opts.pluginForge?.prAttachments === true ? { prAttachments: true } : {}),
|
|
478
478
|
})
|
|
479
|
+
// This fixture's served bare repository is the authoritative forge, even
|
|
480
|
+
// when FakeForge supplies the scripted PR surface.
|
|
481
|
+
const served = new LocalGitForge({ repoRoot: opts.localGitForge === true ? origin : remote })
|
|
482
|
+
const scriptedBranch = forge.remoteBranchSha.bind(forge)
|
|
483
|
+
forge.remoteBranchSha = async (branch) =>
|
|
484
|
+
forge.remoteBranches.has(branch) ? scriptedBranch(branch) : served.remoteBranchSha(branch)
|
|
485
|
+
forge.isCommitAncestor = (ancestor, descendant) => served.isCommitAncestor(ancestor, descendant)
|
|
479
486
|
const recordPush = forge.pushBranch.bind(forge)
|
|
480
487
|
forge.pushBranch = async (cwd, branch, sha) => {
|
|
481
488
|
await recordPush(cwd, branch, sha)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from './scan-cadence'
|
|
1
2
|
export * from './operator-presence'
|
|
2
3
|
export type { StoredEvent } from '../events/compatibility'
|
|
3
4
|
export { READ_CATALOG_IDENTITY } from '../events/compatibility'
|
|
@@ -146,3 +147,11 @@ export type {
|
|
|
146
147
|
export { assertPublicSnapshotReducer } from './snapshots'
|
|
147
148
|
|
|
148
149
|
export { readPersistedBuildDigests } from './reduced-reads'
|
|
150
|
+
|
|
151
|
+
export { dispatchPlacementSchema, dispatchPlacementReducer } from '../kernel/dispatch-placement'
|
|
152
|
+
export type { DispatchPlacement } from '../kernel/dispatch-placement'
|
|
153
|
+
export { dispatchPlacementFactSchema } from '../events/repository'
|
|
154
|
+
export type { DispatchPlacementFact } from '../events/repository'
|
|
155
|
+
|
|
156
|
+
export { readDispatchPlacement } from './reduced-reads'
|
|
157
|
+
export * from './event-reads'
|
|
@@ -104,6 +104,12 @@ export function createBuildScopedStore(store: BuildStore, scope: string): BuildS
|
|
|
104
104
|
listBuildsForRepo(repo: string): Promise<BuildRecord[]> {
|
|
105
105
|
return Promise.reject(new BuildScopeError(scope, 'listBuildsForRepo', repo))
|
|
106
106
|
},
|
|
107
|
+
async getScanCadence(): Promise<never> {
|
|
108
|
+
throw new BuildScopeError(scope, 'getScanCadence')
|
|
109
|
+
},
|
|
110
|
+
async putScanCadence(): Promise<never> {
|
|
111
|
+
throw new BuildScopeError(scope, 'putScanCadence')
|
|
112
|
+
},
|
|
107
113
|
async upsertOperatorPresence(): Promise<never> {
|
|
108
114
|
throw new BuildScopeError(scope, 'upsertOperatorPresence')
|
|
109
115
|
},
|
|
@@ -151,6 +157,28 @@ export function createBuildScopedStore(store: BuildStore, scope: string): BuildS
|
|
|
151
157
|
own('appendWithArtifactsIfCurrent', slug)
|
|
152
158
|
return store.appendWithArtifactsIfCurrent(slug, expectedSeq, artifacts, makeEvent)
|
|
153
159
|
},
|
|
160
|
+
...(store.getBuildEventPage
|
|
161
|
+
? {
|
|
162
|
+
async getBuildEventPage(
|
|
163
|
+
slug: string,
|
|
164
|
+
since?: number,
|
|
165
|
+
opts?: import('./event-reads').EventReadOptions,
|
|
166
|
+
) {
|
|
167
|
+
own('getBuildEventPage', slug)
|
|
168
|
+
return store.getBuildEventPage!(slug, since, opts)
|
|
169
|
+
},
|
|
170
|
+
}
|
|
171
|
+
: {}),
|
|
172
|
+
...(store.getStreamSeed
|
|
173
|
+
? {
|
|
174
|
+
async getStreamSeed(target: SnapshotScope, cursor: number) {
|
|
175
|
+
if (target.kind !== 'build')
|
|
176
|
+
throw new BuildScopeError(scope, 'getStreamSeed', target.repo)
|
|
177
|
+
own('getStreamSeed', target.slug)
|
|
178
|
+
return store.getStreamSeed!(target, cursor)
|
|
179
|
+
},
|
|
180
|
+
}
|
|
181
|
+
: {}),
|
|
154
182
|
async getEvents(
|
|
155
183
|
slug: string,
|
|
156
184
|
sinceSeq?: number,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IncompleteEventReadError, BUILD_EVENT_PAGE_SIZE } from './event-reads'
|
|
1
2
|
import { repositoryReadFactsReducer } from '../kernel/read-facts'
|
|
2
3
|
import { validateReducerValue } from './reducer-value-validation'
|
|
3
4
|
import { READ_CATALOG_IDENTITY } from '../events/compatibility'
|
|
@@ -291,6 +292,34 @@ function atT0(offsetMs: number): string {
|
|
|
291
292
|
|
|
292
293
|
export function describeBuildStoreContract(name: string, factory: BuildStoreFactory): void {
|
|
293
294
|
describe(`BuildStore contract: ${name}`, () => {
|
|
295
|
+
test('scan cadence is keyed disposable metadata with atomic replacement and clock rollback', async () => {
|
|
296
|
+
await withStore(factory, undefined, async (store) => {
|
|
297
|
+
expect(await store.getScanCadence('cadence')).toBeNull()
|
|
298
|
+
expect(await store.getRepo('cadence')).toBeNull()
|
|
299
|
+
await store.ensureRepo('cadence')
|
|
300
|
+
const first = {
|
|
301
|
+
scanSeq: 1,
|
|
302
|
+
startedAt: CONTRACT_T0,
|
|
303
|
+
mode: 'admission' as const,
|
|
304
|
+
readinessFingerprint: 'ready',
|
|
305
|
+
criteriaFingerprint: 'criteria',
|
|
306
|
+
}
|
|
307
|
+
await store.putScanCadence('cadence', first)
|
|
308
|
+
expect(await store.getScanCadence('cadence')).toEqual(first)
|
|
309
|
+
expect(await store.getScanCadence('other')).toBeNull()
|
|
310
|
+
const later = { ...first, startedAt: atT0(60_000) }
|
|
311
|
+
await store.putScanCadence('cadence', later)
|
|
312
|
+
await store.putScanCadence('cadence', first)
|
|
313
|
+
expect(await store.getScanCadence('cadence')).toEqual(later)
|
|
314
|
+
await store.putScanCadence('cadence', first, true)
|
|
315
|
+
expect(await store.getScanCadence('cadence')).toEqual(first)
|
|
316
|
+
const next = { ...first, scanSeq: 2, mode: 'observation' as const }
|
|
317
|
+
await store.putScanCadence('cadence', next)
|
|
318
|
+
expect(await store.getScanCadence('cadence')).toEqual(next)
|
|
319
|
+
expect(await store.getRepoEvents('cadence')).toEqual([])
|
|
320
|
+
})
|
|
321
|
+
})
|
|
322
|
+
|
|
294
323
|
test('operator presence is concurrent, renewable advisory liveness without journal writes', async () => {
|
|
295
324
|
const clock = manualClock()
|
|
296
325
|
await withStore(factory, { clock }, async (store) => {
|
|
@@ -2652,6 +2681,78 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
2652
2681
|
})
|
|
2653
2682
|
|
|
2654
2683
|
describe('append', () => {
|
|
2684
|
+
test('cleared targets retain bounded lineage in persisted reduced values', async () => {
|
|
2685
|
+
await withStore(factory, undefined, async (store) => {
|
|
2686
|
+
const slug = 'target-proof'
|
|
2687
|
+
await store.createBuild(sampleBuildInput(slug))
|
|
2688
|
+
const sha = 'c'.repeat(40),
|
|
2689
|
+
from = 'b'.repeat(40)
|
|
2690
|
+
const lineage = [
|
|
2691
|
+
{ node: 'parent', from, receipts: [{ id: 'tx', previous: from, head: sha }] },
|
|
2692
|
+
]
|
|
2693
|
+
await store.append(slug, {
|
|
2694
|
+
actor: KERNEL,
|
|
2695
|
+
type: 'target.moved',
|
|
2696
|
+
payload: { branch: 'main', sha },
|
|
2697
|
+
})
|
|
2698
|
+
await store.append(slug, {
|
|
2699
|
+
actor: KERNEL,
|
|
2700
|
+
type: 'target.rewritten',
|
|
2701
|
+
payload: { branch: 'main', sha, previousSha: from },
|
|
2702
|
+
})
|
|
2703
|
+
await store.append(slug, {
|
|
2704
|
+
actor: KERNEL,
|
|
2705
|
+
type: 'target.rewrite-cleared',
|
|
2706
|
+
payload: { branch: 'main', sha, lineage },
|
|
2707
|
+
})
|
|
2708
|
+
const facts = (await readBuildFacts(store, slug)).value
|
|
2709
|
+
expect(facts.log.restack.target?.lineage).toEqual(lineage)
|
|
2710
|
+
expect(facts.state.targetRewrite).toBeUndefined()
|
|
2711
|
+
})
|
|
2712
|
+
})
|
|
2713
|
+
|
|
2714
|
+
test('rewrite receipt point lookup covers every atomic append path', async () => {
|
|
2715
|
+
await withStore(factory, undefined, async (store) => {
|
|
2716
|
+
if (!store.getNodeRewrite) return
|
|
2717
|
+
const slug = 'rewrite-index'
|
|
2718
|
+
await store.createBuild(sampleBuildInput(slug))
|
|
2719
|
+
const previous = 'a'.repeat(40)
|
|
2720
|
+
const receipt = { id: 'tx', previous, head: 'b'.repeat(40) }
|
|
2721
|
+
const write = { actor: KERNEL, type: 'node.rewritten', payload: receipt } as const
|
|
2722
|
+
expect(await store.getNodeRewrite(slug, previous)).toBeNull()
|
|
2723
|
+
await store.append(slug, write)
|
|
2724
|
+
expect(await store.getNodeRewrite(slug, previous)).toEqual(receipt)
|
|
2725
|
+
const next = { ...write, payload: { ...receipt, id: 'tx-2' } }
|
|
2726
|
+
expect(await store.appendIfCurrent(slug, 0, next)).toBeNull()
|
|
2727
|
+
expect(await store.getNodeRewrite(slug, previous)).toEqual(receipt)
|
|
2728
|
+
await store.appendIfCurrent(slug, 1, next)
|
|
2729
|
+
expect((await store.getNodeRewrite(slug, previous))?.id).toBe('tx-2')
|
|
2730
|
+
await store.appendWithArtifacts(slug, [], () => ({
|
|
2731
|
+
...write,
|
|
2732
|
+
payload: { ...receipt, id: 'tx-3' },
|
|
2733
|
+
}))
|
|
2734
|
+
expect((await store.getNodeRewrite(slug, previous))?.id).toBe('tx-3')
|
|
2735
|
+
await store.appendWithArtifactsIfCurrent(slug, 3, [], () => ({
|
|
2736
|
+
...write,
|
|
2737
|
+
payload: { ...receipt, id: 'tx-4' },
|
|
2738
|
+
}))
|
|
2739
|
+
const copy = await store.getNodeRewrite(slug, previous)
|
|
2740
|
+
expect(copy?.id).toBe('tx-4')
|
|
2741
|
+
expect(await store.getNodeRewrite(slug)).toEqual(copy)
|
|
2742
|
+
copy!.id = 'mutated'
|
|
2743
|
+
expect((await store.getNodeRewrite(slug, previous))?.id).toBe('tx-4')
|
|
2744
|
+
expect((await store.getNodeRewrite(slug, undefined, previous))?.id).toBe('tx-3')
|
|
2745
|
+
const later = { id: 'tx-5', previous: 'c'.repeat(40), head: 'd'.repeat(40) }
|
|
2746
|
+
await store.append(slug, { ...write, payload: later })
|
|
2747
|
+
expect(await store.getNodeRewrite(slug, undefined, later.previous)).toEqual({
|
|
2748
|
+
...receipt,
|
|
2749
|
+
id: 'tx-4',
|
|
2750
|
+
})
|
|
2751
|
+
expect(await store.getNodeRewrite(slug, undefined, 'e'.repeat(40))).toBeNull()
|
|
2752
|
+
await expect(store.getNodeRewrite('unknown', previous)).rejects.toThrow()
|
|
2753
|
+
})
|
|
2754
|
+
})
|
|
2755
|
+
|
|
2655
2756
|
test('assigns seq 1..n per build, independently across builds (§15.1)', async () => {
|
|
2656
2757
|
await withStore(factory, undefined, async (store) => {
|
|
2657
2758
|
await store.createBuild(sampleBuildInput('seq-a'))
|
|
@@ -2900,6 +3001,30 @@ export function describeBuildStoreContract(name: string, factory: BuildStoreFact
|
|
|
2900
3001
|
})
|
|
2901
3002
|
|
|
2902
3003
|
describe('getEvents', () => {
|
|
3004
|
+
test('bounded page traversal is complete and array reads never return partial history', async () => {
|
|
3005
|
+
await withStore(factory, undefined, async (store) => {
|
|
3006
|
+
await store.createBuild(sampleBuildInput('paged-history'))
|
|
3007
|
+
for (let i = 0; i < BUILD_EVENT_PAGE_SIZE + 3; i++)
|
|
3008
|
+
await store.append('paged-history', sampleEventWrite(`page-${i}`))
|
|
3009
|
+
try {
|
|
3010
|
+
expect(await store.getEvents('paged-history')).toHaveLength(BUILD_EVENT_PAGE_SIZE + 3)
|
|
3011
|
+
} catch (error) {
|
|
3012
|
+
expect(error).toBeInstanceOf(IncompleteEventReadError)
|
|
3013
|
+
}
|
|
3014
|
+
if (!store.getBuildEventPage) return
|
|
3015
|
+
const seen: number[] = []
|
|
3016
|
+
let cursor = 0
|
|
3017
|
+
for (;;) {
|
|
3018
|
+
const page = await store.getBuildEventPage('paged-history', cursor)
|
|
3019
|
+
expect(page.events.length).toBeLessThanOrEqual(BUILD_EVENT_PAGE_SIZE)
|
|
3020
|
+
seen.push(...page.events.map((event) => event.seq))
|
|
3021
|
+
cursor = page.cursor
|
|
3022
|
+
if (!page.hasMore) break
|
|
3023
|
+
}
|
|
3024
|
+
expect(seen).toEqual(Array.from({ length: BUILD_EVENT_PAGE_SIZE + 3 }, (_, i) => i + 1))
|
|
3025
|
+
})
|
|
3026
|
+
})
|
|
3027
|
+
|
|
2903
3028
|
test('since is strictly greater-than, in seq order; default 0 = all (§7.2)', async () => {
|
|
2904
3029
|
await withStore(factory, undefined, async (store) => {
|
|
2905
3030
|
await store.createBuild(sampleBuildInput('since'))
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import type { AbEvent } from '../events/catalog'
|
|
2
|
+
import type { RepositoryEvent } from '../events/repository'
|
|
3
|
+
import type { SnapshotScope } from './snapshots'
|
|
4
|
+
import type { ReducerValue } from './reducer-values'
|
|
5
|
+
|
|
6
|
+
export const REPOSITORY_TAIL_WINDOW = 1_000
|
|
7
|
+
export const BUILD_EVENT_PAGE_SIZE = 256
|
|
8
|
+
export interface EventPage<E> {
|
|
9
|
+
events: E[]
|
|
10
|
+
cursor: number
|
|
11
|
+
hasMore: boolean
|
|
12
|
+
}
|
|
13
|
+
export interface EventReadOptions {
|
|
14
|
+
through?: number
|
|
15
|
+
waitSeconds?: number
|
|
16
|
+
signal?: AbortSignal
|
|
17
|
+
}
|
|
18
|
+
export interface BoundedEventReads {
|
|
19
|
+
getBuildEventPage?(
|
|
20
|
+
slug: string,
|
|
21
|
+
since?: number,
|
|
22
|
+
opts?: EventReadOptions,
|
|
23
|
+
): Promise<EventPage<AbEvent>>
|
|
24
|
+
getRepositoryTail?(
|
|
25
|
+
repo: string,
|
|
26
|
+
since?: number,
|
|
27
|
+
opts?: EventReadOptions,
|
|
28
|
+
): Promise<RepositoryEvent[]>
|
|
29
|
+
getStreamSeed?(scope: SnapshotScope, cursor: number): Promise<ReducerValue>
|
|
30
|
+
getHarvestHistoryPage?(repo: string, before?: number): Promise<EventPage<RepositoryEvent>>
|
|
31
|
+
}
|
|
32
|
+
export function validateEventCursor(cursor: number): void {
|
|
33
|
+
if (!Number.isSafeInteger(cursor) || cursor < 0)
|
|
34
|
+
throw new Error('event cursor must be a safe nonnegative integer')
|
|
35
|
+
}
|
|
36
|
+
export class CursorTooOldError extends Error {
|
|
37
|
+
override readonly name = 'CursorTooOldError'
|
|
38
|
+
readonly oldestCursor: number
|
|
39
|
+
constructor(
|
|
40
|
+
readonly scope: SnapshotScope,
|
|
41
|
+
readonly requestedCursor: number,
|
|
42
|
+
readonly head: number,
|
|
43
|
+
) {
|
|
44
|
+
const oldest = Math.max(0, head - REPOSITORY_TAIL_WINDOW)
|
|
45
|
+
super(
|
|
46
|
+
`cursor ${requestedCursor} is too old; oldest servable cursor is ${oldest}. Re-arm without --since and reconcile repository/build status; the historical gap is unavailable.`,
|
|
47
|
+
)
|
|
48
|
+
this.oldestCursor = oldest
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export class IncompleteEventReadError extends Error {
|
|
52
|
+
override readonly name = 'IncompleteEventReadError'
|
|
53
|
+
constructor(
|
|
54
|
+
readonly requestedCursor: number,
|
|
55
|
+
readonly continuationCursor: number,
|
|
56
|
+
readonly pageLimit = BUILD_EVENT_PAGE_SIZE,
|
|
57
|
+
) {
|
|
58
|
+
super(
|
|
59
|
+
`event suffix exceeds ${pageLimit} events; use getBuildEventPage and continue from ${continuationCursor}`,
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export class CheckpointIntegrityError extends Error {
|
|
64
|
+
override readonly name = 'CheckpointIntegrityError'
|
|
65
|
+
}
|
|
66
|
+
export class RetiredSeedGenerationError extends Error {
|
|
67
|
+
override readonly name = 'RetiredSeedGenerationError'
|
|
68
|
+
constructor() {
|
|
69
|
+
super(
|
|
70
|
+
'retired stream-seed generation; upgrade or restart, re-arm without --since and reconcile status',
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export function assertResumeWindow(scope: SnapshotScope, cursor: number, head: number): void {
|
|
75
|
+
validateEventCursor(cursor)
|
|
76
|
+
if (cursor < Math.max(0, head - REPOSITORY_TAIL_WINDOW))
|
|
77
|
+
throw new CursorTooOldError(scope, cursor, head)
|
|
78
|
+
}
|
|
79
|
+
export function isTerminalEventReadError(error: unknown): boolean {
|
|
80
|
+
return (
|
|
81
|
+
error instanceof CursorTooOldError ||
|
|
82
|
+
error instanceof CheckpointIntegrityError ||
|
|
83
|
+
error instanceof IncompleteEventReadError ||
|
|
84
|
+
error instanceof RetiredSeedGenerationError
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** One page for history UIs; local adapters keep their complete array method. */
|
|
89
|
+
export async function readBuildPage(
|
|
90
|
+
store: import('./types').BuildStore,
|
|
91
|
+
slug: string,
|
|
92
|
+
since = 0,
|
|
93
|
+
opts?: EventReadOptions,
|
|
94
|
+
): Promise<EventPage<AbEvent>> {
|
|
95
|
+
if (store.getBuildEventPage) return store.getBuildEventPage(slug, since, opts)
|
|
96
|
+
const events = (await store.getEvents(slug, since, opts)).filter(
|
|
97
|
+
(event) => event.seq <= (opts?.through ?? Number.MAX_SAFE_INTEGER),
|
|
98
|
+
)
|
|
99
|
+
const page = events.slice(0, BUILD_EVENT_PAGE_SIZE)
|
|
100
|
+
return {
|
|
101
|
+
events: page,
|
|
102
|
+
cursor: page.at(-1)?.seq ?? since,
|
|
103
|
+
hasMore: events.length > BUILD_EVENT_PAGE_SIZE,
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** An explicitly required interval freezes its upper boundary before traversal. */
|
|
107
|
+
export async function readBuildRange(
|
|
108
|
+
store: import('./types').BuildStore,
|
|
109
|
+
slug: string,
|
|
110
|
+
since: number,
|
|
111
|
+
opts?: EventReadOptions,
|
|
112
|
+
): Promise<AbEvent[]> {
|
|
113
|
+
if (!store.getBuildEventPage) return store.getEvents(slug, since, opts)
|
|
114
|
+
const through =
|
|
115
|
+
opts?.through ??
|
|
116
|
+
(await store.getReducerValue({ kind: 'build', slug }, { reducer: 'buildStreamSeed' })).cursor
|
|
117
|
+
if (since >= through && opts?.waitSeconds) {
|
|
118
|
+
const first = await store.getBuildEventPage(slug, since, opts)
|
|
119
|
+
if (!first.hasMore) return first.events
|
|
120
|
+
return [
|
|
121
|
+
...first.events,
|
|
122
|
+
...(await readBuildRange(store, slug, first.cursor, { ...opts, waitSeconds: 0 })),
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
const events: AbEvent[] = []
|
|
126
|
+
let cursor = since
|
|
127
|
+
do {
|
|
128
|
+
const page = await store.getBuildEventPage(slug, cursor, { ...opts, through })
|
|
129
|
+
events.push(...page.events)
|
|
130
|
+
if (!page.hasMore) return events
|
|
131
|
+
if (page.cursor <= cursor) throw new CheckpointIntegrityError('nonadvancing event page')
|
|
132
|
+
cursor = page.cursor
|
|
133
|
+
} while (cursor < through)
|
|
134
|
+
return events
|
|
135
|
+
}
|
|
136
|
+
export async function readHarvestTail(
|
|
137
|
+
store: import('./types').BuildStore,
|
|
138
|
+
repo: string,
|
|
139
|
+
count: number,
|
|
140
|
+
): Promise<RepositoryEvent[]> {
|
|
141
|
+
if (count <= 0) return []
|
|
142
|
+
if (!store.getHarvestHistoryPage)
|
|
143
|
+
return (await store.getRepoEvents(repo))
|
|
144
|
+
.filter((e) => e.type.startsWith('harvest.'))
|
|
145
|
+
.slice(-count)
|
|
146
|
+
const events: RepositoryEvent[] = []
|
|
147
|
+
let cursor = Number.MAX_SAFE_INTEGER
|
|
148
|
+
while (events.length < count) {
|
|
149
|
+
const page = await store.getHarvestHistoryPage(repo, cursor)
|
|
150
|
+
events.push(...page.events.slice(0, count - events.length))
|
|
151
|
+
if (!page.hasMore) break
|
|
152
|
+
if (page.cursor >= cursor) throw new CheckpointIntegrityError('nonadvancing harvest page')
|
|
153
|
+
cursor = page.cursor
|
|
154
|
+
}
|
|
155
|
+
return events.reverse()
|
|
156
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm'
|
|
1
2
|
/**
|
|
2
3
|
* Drizzle schema for the local SQLite BuildStore (SPEC §7.1): simple,
|
|
3
4
|
* normalized, boring. Lease + heartbeat are mutable liveness columns on
|
|
@@ -15,6 +16,13 @@ import type { TicketRef } from '../../ontology'
|
|
|
15
16
|
import type { TicketAssetEntry } from '../ticket-assets'
|
|
16
17
|
import type { StreamPart } from '../streams/types'
|
|
17
18
|
|
|
19
|
+
export const scanCadence = sqliteTable('scan_cadence', {
|
|
20
|
+
repo: text('repo')
|
|
21
|
+
.primaryKey()
|
|
22
|
+
.references(() => repoStreams.repo, { onDelete: 'cascade' }),
|
|
23
|
+
value: text('value').notNull(),
|
|
24
|
+
})
|
|
25
|
+
|
|
18
26
|
export const builds = sqliteTable(
|
|
19
27
|
'builds',
|
|
20
28
|
{
|
|
@@ -55,6 +63,9 @@ export const events = sqliteTable(
|
|
|
55
63
|
(t) => [
|
|
56
64
|
primaryKey({ columns: [t.build, t.seq] }),
|
|
57
65
|
index('events_type_build_seq').on(t.type, t.build, t.seq),
|
|
66
|
+
index('events_node_rewrite_previous')
|
|
67
|
+
.on(t.build, sql`json_extract(${t.payload}, '$.previous')`, t.seq)
|
|
68
|
+
.where(sql`${t.type} = 'node.rewritten'`),
|
|
58
69
|
],
|
|
59
70
|
)
|
|
60
71
|
|