@defrex/autobuild 0.14.0 → 1.0.0-beta.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 +4 -2
- package/SPEC.md +654 -98
- package/docs/architecture.md +226 -5
- package/docs/assets/headline-wide.png +0 -0
- package/docs/configuration.md +112 -12
- package/docs/hosted-service.md +18 -0
- package/docs/integration-tree.md +117 -0
- package/docs/landing-policy.md +150 -0
- package/docs/mcp.md +24 -0
- package/docs/migration-1.0.md +68 -0
- package/docs/operator-api.md +19 -8
- package/docs/remote-store-protocol.md +30 -7
- package/docs/remote-ticket-protocol.md +26 -5
- package/docs/restacking.md +79 -0
- package/docs/setup.md +49 -6
- package/docs/ticket-dependencies.md +69 -0
- package/docs/ticket-migration.md +8 -0
- package/package.json +3 -3
- package/packages/core/src/cli/attention.ts +25 -2
- package/packages/core/src/cli/build-control.ts +65 -41
- package/packages/core/src/cli/context.ts +54 -2
- package/packages/core/src/cli/dashboard/actions.ts +6 -3
- package/packages/core/src/cli/dashboard/landing-display.ts +6 -0
- package/packages/core/src/cli/dashboard/live.ts +5 -0
- package/packages/core/src/cli/dashboard/model.ts +142 -18
- package/packages/core/src/cli/dashboard/poll.ts +15 -9
- package/packages/core/src/cli/dashboard/refresh.ts +176 -0
- package/packages/core/src/cli/dashboard/render.ts +78 -28
- package/packages/core/src/cli/dashboard/repository-poll.ts +57 -0
- package/packages/core/src/cli/dashboard/selection.ts +7 -1
- package/packages/core/src/cli/dashboard/tree.ts +107 -0
- package/packages/core/src/cli/dispatch-frontend.ts +156 -109
- package/packages/core/src/cli/dispatch.ts +250 -136
- package/packages/core/src/cli/dispatcher-liveness.ts +15 -2
- package/packages/core/src/cli/help.ts +49 -32
- package/packages/core/src/cli/init-validation.ts +43 -2
- package/packages/core/src/cli/keyboard.ts +6 -0
- package/packages/core/src/cli/landings.ts +18 -0
- package/packages/core/src/cli/main.ts +49 -15
- package/packages/core/src/cli/mcp.ts +9 -0
- package/packages/core/src/cli/publication-settlement.ts +168 -2
- package/packages/core/src/cli/repository-status.ts +11 -0
- package/packages/core/src/cli/status.ts +72 -5
- package/packages/core/src/cli/terminal-restore.ts +54 -0
- package/packages/core/src/cli/terminal.ts +16 -2
- package/packages/core/src/cli/terminals.ts +98 -79
- package/packages/core/src/cli/ticket-editor.ts +10 -3
- package/packages/core/src/cli/ticket.ts +113 -18
- package/packages/core/src/cli/upgrade-commit.ts +4 -0
- package/packages/core/src/cli/upgrade-compatibility.ts +2 -2
- package/packages/core/src/cli/upgrade-landing.ts +69 -0
- package/packages/core/src/cli/upgrade.ts +16 -0
- package/packages/core/src/cli/wait.ts +115 -19
- package/packages/core/src/cli/watch.ts +51 -12
- package/packages/core/src/config/landing.ts +22 -0
- package/packages/core/src/config/live.ts +1 -0
- package/packages/core/src/config/schema.ts +3 -0
- package/packages/core/src/events/catalog.ts +48 -3
- package/packages/core/src/events/payloads.ts +295 -6
- package/packages/core/src/events/repository.ts +31 -0
- package/packages/core/src/integration/harness.ts +10 -0
- package/packages/core/src/kernel/__snapshots__/reducer-registry.test.ts.snap +1030 -239
- package/packages/core/src/kernel/auto-merge-default.ts +1 -0
- package/packages/core/src/kernel/auto-merge.ts +12 -3
- package/packages/core/src/kernel/build-identity.ts +94 -0
- package/packages/core/src/kernel/change-presence.ts +179 -0
- package/packages/core/src/kernel/dispatch-status.ts +17 -1
- package/packages/core/src/kernel/engine.ts +89 -2
- package/packages/core/src/kernel/generators/build-log.ts +23 -0
- package/packages/core/src/kernel/generators/leaf-restack-log.ts +110 -0
- package/packages/core/src/kernel/generators/node-restack-log.ts +94 -0
- package/packages/core/src/kernel/generators/repository-journals.ts +11 -0
- package/packages/core/src/kernel/integration-completeness.ts +81 -0
- package/packages/core/src/kernel/integration-landing.ts +263 -0
- package/packages/core/src/kernel/integration-stack.ts +36 -0
- package/packages/core/src/kernel/integration-state.ts +135 -0
- package/packages/core/src/kernel/landing-policy.ts +47 -0
- package/packages/core/src/kernel/landing-publication.ts +41 -0
- package/packages/core/src/kernel/landing-readiness.ts +67 -0
- package/packages/core/src/kernel/landing-state.ts +96 -0
- package/packages/core/src/kernel/leaf-restack-completion.ts +24 -0
- package/packages/core/src/kernel/leaf-restack-state.ts +73 -0
- package/packages/core/src/kernel/log-index.ts +35 -5
- package/packages/core/src/kernel/node-landing.ts +439 -0
- package/packages/core/src/kernel/node-parent.ts +184 -0
- package/packages/core/src/kernel/node-restack-state.ts +191 -0
- package/packages/core/src/kernel/node-restack-transaction.ts +210 -0
- package/packages/core/src/kernel/node-restack.ts +274 -0
- package/packages/core/src/kernel/read-facts.ts +70 -3
- package/packages/core/src/kernel/reconcile-head.ts +51 -0
- package/packages/core/src/kernel/reconcile-restack.ts +560 -0
- package/packages/core/src/kernel/reducer-registry.ts +16 -0
- package/packages/core/src/kernel/reducer.ts +121 -6
- package/packages/core/src/kernel/snapshot-parent.ts +33 -0
- package/packages/core/src/ontology.ts +9 -1
- package/packages/core/src/operator/annotations.ts +12 -0
- package/packages/core/src/operator/control.ts +6 -0
- package/packages/core/src/operator/index.ts +4 -0
- package/packages/core/src/operator/landings.ts +35 -0
- package/packages/core/src/operator/presentation.ts +1 -0
- package/packages/core/src/operator/protocol.ts +12 -3
- package/packages/core/src/operator/query.ts +3 -1
- package/packages/core/src/operator/registry.ts +48 -19
- package/packages/core/src/operator/requests.ts +1 -8
- package/packages/core/src/operator/tickets.ts +55 -9
- package/packages/core/src/ports/forge/contract.ts +91 -3
- package/packages/core/src/ports/forge/fake.ts +142 -4
- package/packages/core/src/ports/forge/git-rewrite.ts +232 -0
- package/packages/core/src/ports/forge/github-readiness.ts +421 -0
- package/packages/core/src/ports/forge/github.ts +631 -35
- package/packages/core/src/ports/forge/local-git.ts +119 -5
- package/packages/core/src/ports/forge/readiness.ts +99 -0
- package/packages/core/src/ports/tickets/contract.ts +41 -0
- package/packages/core/src/ports/tickets/create.ts +8 -1
- package/packages/core/src/ports/tickets/fake.ts +32 -1
- package/packages/core/src/ports/tickets/file-codec.ts +7 -0
- package/packages/core/src/ports/tickets/file.ts +18 -1
- package/packages/core/src/ports/tickets/hosted-index.ts +2 -0
- package/packages/core/src/ports/tickets/linear.ts +124 -4
- package/packages/core/src/ports/tickets/migration.ts +25 -1
- package/packages/core/src/ports/tickets/operations.ts +7 -2
- package/packages/core/src/ports/tickets/remote-protocol.ts +19 -0
- package/packages/core/src/ports/tickets/remote.ts +10 -1
- package/packages/core/src/ports/tickets/revision.ts +3 -1
- package/packages/core/src/ports/tickets/tree.ts +148 -0
- package/packages/core/src/ports/tickets/update.ts +15 -2
- package/packages/core/src/ports/types.ts +135 -5
- package/packages/core/src/ports/workspace/git-worktree.ts +2 -1
- package/packages/core/src/ports/workspace/provider-capabilities.ts +1 -1
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +60 -3
- package/packages/core/src/processes/build-runner.ts +530 -23
- package/packages/core/src/processes/dispatcher-selectors.ts +15 -9
- package/packages/core/src/processes/dispatcher.ts +2145 -203
- package/packages/core/src/processes/execution-no-progress.ts +46 -1
- package/packages/core/src/processes/publication-state.ts +30 -5
- package/packages/core/src/processes/repo-view.ts +21 -2
- package/packages/core/src/store/build-scope.ts +18 -0
- package/packages/core/src/store/contract.ts +658 -0
- package/packages/core/src/store/digest.ts +52 -4
- package/packages/core/src/store/local/schema.ts +25 -13
- package/packages/core/src/store/local/store.ts +117 -1
- package/packages/core/src/store/memory.ts +62 -1
- package/packages/core/src/store/phase-session.ts +17 -0
- package/packages/core/src/store/reduced-reads.ts +2 -1
- package/packages/core/src/store/reducer-value-shapes.json +10707 -6440
- package/packages/core/src/store/remote/client.ts +44 -0
- package/packages/core/src/store/remote/compatibility.ts +19 -9
- package/packages/core/src/store/remote/protocol.ts +11 -0
- package/packages/core/src/store/repo-state-events.ts +2 -0
- package/packages/core/src/store/session-handle.ts +15 -0
- package/packages/core/src/store/subscribe.ts +1 -1
- package/packages/core/src/store/types.ts +32 -4
- package/packages/core/src/testing/index.ts +2 -0
- package/packages/core/src/testing/reduced-read-budget.ts +48 -8
- package/packages/core/src/testing/refresh-scheduler.ts +32 -0
- package/skills/guide/SKILL.md +110 -61
- package/skills/guide/references/integration-tree.md +117 -0
- package/skills/guide/references/landing-policy.md +150 -0
- package/skills/guide/references/migration-1.0.md +68 -0
- package/skills/guide/references/operator-api.md +12 -5
- package/skills/guide/references/plugin-authoring.md +34 -0
- package/skills/guide/references/remote-store-protocol.md +30 -7
- package/skills/guide/references/remote-ticket-protocol.md +26 -5
- package/skills/guide/references/restacking.md +79 -0
- package/skills/guide/references/setup.md +49 -6
- package/skills/guide/references/ticket-dependencies.md +69 -0
- package/skills/guide/references/ticket-migration.md +8 -0
- package/skills/operate/SKILL.md +55 -5
- package/skills/reconcile/SKILL.md +55 -48
- package/skills/spec/SKILL.md +67 -1
- package/skills/tickets/SKILL.md +55 -2
- package/templates/autobuild.toml +3 -0
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { updateTicketTarget } from '../kernel/node-parent'
|
|
2
|
+
import { projectTicketTree, compatibleTicketSource } from '../ports/tickets/tree'
|
|
1
3
|
import { readBuildFacts } from '../store/reduced-reads'
|
|
2
4
|
import { samplePinnedAssets, preparePinnedAssets } from '../store/ticket-assets'
|
|
3
5
|
import type { TicketRef } from '../ontology'
|
|
@@ -18,12 +20,15 @@ import { effectiveConfig } from './query'
|
|
|
18
20
|
export interface OperatorTicketContext {
|
|
19
21
|
repo: string
|
|
20
22
|
tickets: Config['tickets']
|
|
23
|
+
baseBranch?: string
|
|
21
24
|
teamKey: string
|
|
22
25
|
claimedState?: string
|
|
23
26
|
createState?: string
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
export interface OperatorTicketBackend {
|
|
30
|
+
supportsNodeRetarget?(context: OperatorTicketContext): Promise<boolean>
|
|
31
|
+
|
|
27
32
|
contextFor?(repo: string): Promise<OperatorTicketContext>
|
|
28
33
|
sourceFor(context: OperatorTicketContext): TicketSource | Promise<TicketSource>
|
|
29
34
|
statesFor(context: OperatorTicketContext, source: TicketSource): string[] | Promise<string[]>
|
|
@@ -56,6 +61,7 @@ function contextFor(config: Config, repo: string): OperatorTicketContext {
|
|
|
56
61
|
const tickets = config.tickets
|
|
57
62
|
return {
|
|
58
63
|
repo,
|
|
64
|
+
baseBranch: config.baseBranch,
|
|
59
65
|
tickets,
|
|
60
66
|
teamKey: tickets.teamKey ?? '',
|
|
61
67
|
...(tickets.claimedState !== undefined ? { claimedState: tickets.claimedState } : {}),
|
|
@@ -71,7 +77,7 @@ export async function openOperatorTickets(opts: {
|
|
|
71
77
|
const context = opts.backend.contextFor
|
|
72
78
|
? await opts.backend.contextFor(opts.repo)
|
|
73
79
|
: contextFor((await effectiveConfig(opts.store, opts.repo)).config, opts.repo)
|
|
74
|
-
return { context, source: await opts.backend.sourceFor(context) }
|
|
80
|
+
return { context, source: compatibleTicketSource(await opts.backend.sourceFor(context)) }
|
|
75
81
|
}
|
|
76
82
|
|
|
77
83
|
export async function listOperatorTickets(opts: {
|
|
@@ -190,6 +196,8 @@ export async function mutateOperatorTicket(opts: {
|
|
|
190
196
|
operation:
|
|
191
197
|
| {
|
|
192
198
|
kind: 'create'
|
|
199
|
+
ticketKind?: import('../ports/types').TicketKind
|
|
200
|
+
target?: string | null
|
|
193
201
|
title: string
|
|
194
202
|
body: string
|
|
195
203
|
labels?: string[]
|
|
@@ -205,15 +213,32 @@ export async function mutateOperatorTicket(opts: {
|
|
|
205
213
|
if (operation.kind === 'update') await requireTicket(source, operation.id)
|
|
206
214
|
const ticket =
|
|
207
215
|
operation.kind === 'create'
|
|
208
|
-
? await createTicket(source, operation)
|
|
216
|
+
? await createTicket(source, { ...operation, kind: operation.ticketKind })
|
|
209
217
|
: operation.kind === 'update'
|
|
210
|
-
? (await
|
|
211
|
-
source,
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
218
|
+
? (await (operation.patch.target === undefined
|
|
219
|
+
? updateTicket(source, operation.id, operation.patch, true, operation.expectedRevision)
|
|
220
|
+
: updateTicketTarget(
|
|
221
|
+
{
|
|
222
|
+
store: opts.store,
|
|
223
|
+
repo: opts.repo,
|
|
224
|
+
source,
|
|
225
|
+
configuredSource: context.tickets.source,
|
|
226
|
+
root:
|
|
227
|
+
context.baseBranch ??
|
|
228
|
+
(
|
|
229
|
+
await effectiveConfig(opts.store, opts.repo)
|
|
230
|
+
).config.baseBranch,
|
|
231
|
+
supportsRetarget: async () => {
|
|
232
|
+
if (opts.backend.supportsNodeRetarget)
|
|
233
|
+
return opts.backend.supportsNodeRetarget(context)
|
|
234
|
+
const config = (await effectiveConfig(opts.store, opts.repo)).config
|
|
235
|
+
return config.forge === 'github' || config.forge === 'local-git'
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
operation.id,
|
|
239
|
+
operation.patch,
|
|
240
|
+
operation.expectedRevision,
|
|
241
|
+
)))!
|
|
217
242
|
: operation.kind === 'move'
|
|
218
243
|
? await moveTicket(source, operation.id, operation.state, operation.expectedRevision)
|
|
219
244
|
: await changeBlockers(
|
|
@@ -283,3 +308,24 @@ export async function createOperatorTicketState(opts: {
|
|
|
283
308
|
)
|
|
284
309
|
}
|
|
285
310
|
}
|
|
311
|
+
|
|
312
|
+
/** Exhaustive source tree, including resolved tickets and listing diagnostics. */
|
|
313
|
+
export async function readTicketTree(source: TicketSource, root: string) {
|
|
314
|
+
source = compatibleTicketSource(source)
|
|
315
|
+
if (!source.listAll)
|
|
316
|
+
throw new Error(
|
|
317
|
+
`${source.name} cannot enumerate all tickets; use a source with listAll support`,
|
|
318
|
+
)
|
|
319
|
+
const listing = await source.listAll()
|
|
320
|
+
return { ...projectTicketTree(listing.tickets, root), diagnostics: listing.diagnostics }
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export async function getOperatorTicketTree(opts: {
|
|
324
|
+
store: BuildStore
|
|
325
|
+
repo: string
|
|
326
|
+
backend: OperatorTicketBackend
|
|
327
|
+
}) {
|
|
328
|
+
const { context, source } = await openOperatorTickets(opts)
|
|
329
|
+
if (!context.baseBranch) throw new Error('Repository base branch unavailable')
|
|
330
|
+
return readTicketTree(source, context.baseBranch)
|
|
331
|
+
}
|
|
@@ -90,6 +90,78 @@ async function pushAndOpen(harness: ForgeContractHarness): Promise<{
|
|
|
90
90
|
*/
|
|
91
91
|
export function describeForgeContract(name: string, factory: ForgeContractFactory): void {
|
|
92
92
|
describe(`Forge contract: ${name}`, () => {
|
|
93
|
+
test('optional node refs open empty without a PR and retries preserve their head', async () => {
|
|
94
|
+
await withForge(factory, undefined, async (h) => {
|
|
95
|
+
const forge = h.forge
|
|
96
|
+
if (!forge.createNodeBranch || !forge.compareBranches || !forge.remoteBranchSha) return
|
|
97
|
+
await forge.pushBranch(h.workspacePath, h.head)
|
|
98
|
+
const opening = await forge.remoteBranchSha(h.head)
|
|
99
|
+
const branch = `ab-node/contract-${crypto.randomUUID()}`
|
|
100
|
+
try {
|
|
101
|
+
expect(await forge.createNodeBranch(branch, opening)).toBe(opening)
|
|
102
|
+
expect(await forge.createNodeBranch(branch, opening)).toBe(opening)
|
|
103
|
+
expect(await forge.compareBranches(h.head, branch)).toEqual({
|
|
104
|
+
parentSha: opening,
|
|
105
|
+
headSha: opening,
|
|
106
|
+
ahead: 0,
|
|
107
|
+
})
|
|
108
|
+
} finally {
|
|
109
|
+
if (forge.deleteBranch) await forge.deleteBranch(h.workspacePath, branch)
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
})
|
|
113
|
+
test('optional retarget preserves review identity and acknowledges the new base idempotently', async () => {
|
|
114
|
+
await withForge(factory, undefined, async (h) => {
|
|
115
|
+
const forge = h.forge
|
|
116
|
+
if (
|
|
117
|
+
!forge.retargetPr ||
|
|
118
|
+
!forge.createNodeBranch ||
|
|
119
|
+
!forge.inspectLandingPr ||
|
|
120
|
+
!forge.remoteBranchSha
|
|
121
|
+
)
|
|
122
|
+
return
|
|
123
|
+
const { pr } = await pushAndOpen(h)
|
|
124
|
+
const branch = `ab-node/retarget-${crypto.randomUUID()}`
|
|
125
|
+
await forge.createNodeBranch(branch, await forge.remoteBranchSha(h.base))
|
|
126
|
+
try {
|
|
127
|
+
await forge.setAutoMerge(h.workspacePath, pr.number, false)
|
|
128
|
+
await forge.retargetPr(h.workspacePath, pr.number, branch)
|
|
129
|
+
await forge.retargetPr(h.workspacePath, pr.number, branch)
|
|
130
|
+
expect(await forge.inspectLandingPr(h.workspacePath, pr.number)).toMatchObject({
|
|
131
|
+
base: branch,
|
|
132
|
+
head: h.head,
|
|
133
|
+
open: true,
|
|
134
|
+
})
|
|
135
|
+
} finally {
|
|
136
|
+
await h.controls.closePr(pr.number)
|
|
137
|
+
await forge.deleteBranch?.(h.workspacePath, branch)
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
})
|
|
141
|
+
test('optional rewrite snapshots the authoritative head and refuses a stale lease', async () => {
|
|
142
|
+
await withForge(factory, undefined, async (harness) => {
|
|
143
|
+
const capability = harness.forge.rewrite
|
|
144
|
+
if (capability === undefined) return
|
|
145
|
+
const { remoteHead } = await pushAndOpen(harness)
|
|
146
|
+
expect(
|
|
147
|
+
await capability.snapshot({
|
|
148
|
+
workspacePath: harness.workspacePath,
|
|
149
|
+
branch: harness.head,
|
|
150
|
+
destinationRef: 'refs/autobuild/reconcile/contract-probe/head',
|
|
151
|
+
}),
|
|
152
|
+
).toBe(remoteHead)
|
|
153
|
+
expect(
|
|
154
|
+
await capability.replace({
|
|
155
|
+
workspacePath: harness.workspacePath,
|
|
156
|
+
branch: harness.head,
|
|
157
|
+
expected: '0'.repeat(40),
|
|
158
|
+
sha: 'e'.repeat(40),
|
|
159
|
+
}),
|
|
160
|
+
).toEqual({ kind: 'lease-mismatch', actual: remoteHead })
|
|
161
|
+
expect(await harness.controls.remoteHead(harness.head)).toBe(remoteHead)
|
|
162
|
+
})
|
|
163
|
+
})
|
|
164
|
+
|
|
93
165
|
test('pushBranch publishes the head and openPr returns/adopts the actual PR', async () => {
|
|
94
166
|
await withForge(factory, undefined, async (harness) => {
|
|
95
167
|
const { pr, remoteHead } = await pushAndOpen(harness)
|
|
@@ -113,7 +185,7 @@ export function describeForgeContract(name: string, factory: ForgeContractFactor
|
|
|
113
185
|
await withForge(factory, undefined, async (harness) => {
|
|
114
186
|
const { pr } = await pushAndOpen(harness)
|
|
115
187
|
await harness.controls.prepareMergeable(pr.number)
|
|
116
|
-
expect(await harness.forge.getPrState(harness.workspacePath, pr.number)).
|
|
188
|
+
expect(await harness.forge.getPrState(harness.workspacePath, pr.number)).toMatchObject({
|
|
117
189
|
state: 'open',
|
|
118
190
|
mergeable: true,
|
|
119
191
|
})
|
|
@@ -124,7 +196,7 @@ export function describeForgeContract(name: string, factory: ForgeContractFactor
|
|
|
124
196
|
await withForge(factory, undefined, async (harness) => {
|
|
125
197
|
const { pr } = await pushAndOpen(harness)
|
|
126
198
|
await harness.controls.makeConflict(pr.number)
|
|
127
|
-
expect(await harness.forge.getPrState(harness.workspacePath, pr.number)).
|
|
199
|
+
expect(await harness.forge.getPrState(harness.workspacePath, pr.number)).toMatchObject({
|
|
128
200
|
state: 'open',
|
|
129
201
|
mergeable: false,
|
|
130
202
|
})
|
|
@@ -156,6 +228,22 @@ export function describeForgeContract(name: string, factory: ForgeContractFactor
|
|
|
156
228
|
})
|
|
157
229
|
})
|
|
158
230
|
|
|
231
|
+
test('identity-aware squash exposes the actual landed trailer when inspection is supported', async () => {
|
|
232
|
+
await withForge(factory, undefined, async (harness) => {
|
|
233
|
+
const { pr } = await pushAndOpen(harness)
|
|
234
|
+
await harness.controls.prepareMergeable(pr.number)
|
|
235
|
+
await harness.forge.squashMerge(harness.workspacePath, pr.number, pr.headSha, {
|
|
236
|
+
buildSlug: 'contract-build',
|
|
237
|
+
})
|
|
238
|
+
const sha = await harness.controls.mergeSha(pr.number)
|
|
239
|
+
if (harness.forge.readCommitMessage !== undefined) {
|
|
240
|
+
expect(await harness.forge.readCommitMessage(harness.workspacePath, sha)).toContain(
|
|
241
|
+
'Autobuild-Build: contract-build',
|
|
242
|
+
)
|
|
243
|
+
}
|
|
244
|
+
})
|
|
245
|
+
})
|
|
246
|
+
|
|
159
247
|
test('setAutoMerge acknowledges native state and is idempotent', async () => {
|
|
160
248
|
await withForge(factory, { gated: true }, async (harness) => {
|
|
161
249
|
if (harness.nativeAutoMerge === false) return
|
|
@@ -192,7 +280,7 @@ export function describeForgeContract(name: string, factory: ForgeContractFactor
|
|
|
192
280
|
await expect(
|
|
193
281
|
harness.forge.squashMerge(harness.workspacePath, pr.number, pr.headSha),
|
|
194
282
|
).rejects.toThrow()
|
|
195
|
-
expect(await harness.forge.getPrState(harness.workspacePath, pr.number)).
|
|
283
|
+
expect(await harness.forge.getPrState(harness.workspacePath, pr.number)).toMatchObject({
|
|
196
284
|
state: 'open',
|
|
197
285
|
mergeable: true,
|
|
198
286
|
})
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { readinessChecks, type ForgeReadinessCheck } from './readiness'
|
|
2
|
+
import { hasBuildTrailer, withBuildTrailer } from '../../kernel/build-identity'
|
|
3
|
+
import type { BuildLandingOptions } from '../types'
|
|
1
4
|
import { findSummaryMarker } from './summary-marker'
|
|
2
5
|
/**
|
|
3
6
|
* FakeForge (SPEC §3.2): in-memory Forge for seam tests. Gate existence and
|
|
@@ -56,6 +59,7 @@ export interface AutoMergeRecord {
|
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
export interface SquashMergeRecord {
|
|
62
|
+
buildSlug?: string
|
|
59
63
|
workspacePath: string
|
|
60
64
|
number: number
|
|
61
65
|
expectedHeadSha: string
|
|
@@ -81,7 +85,80 @@ export type MergeSha = string | ((number: number) => string)
|
|
|
81
85
|
type FakeGateState = MergeGatePresence | AutoMergeDeferralReason
|
|
82
86
|
|
|
83
87
|
export class FakeForge implements Forge {
|
|
88
|
+
readiness: ForgeReadinessCheck[] = readinessChecks(
|
|
89
|
+
'pass',
|
|
90
|
+
'Fake forge permits repository operations.',
|
|
91
|
+
)
|
|
92
|
+
async inspectReadiness() {
|
|
93
|
+
return this.readiness
|
|
94
|
+
}
|
|
95
|
+
readonly linearStackMerges: { number: number; head: string }[] = []
|
|
96
|
+
async inspectMergeFreshness(_branch: string) {
|
|
97
|
+
return { fenced: false, evidence: ['Fake freshness enforcement is not configured'] }
|
|
98
|
+
}
|
|
99
|
+
async mergeLinearStack(_workspacePath: string, number: number, head: string): Promise<string> {
|
|
100
|
+
this.assertPr(number)
|
|
101
|
+
const pr = this.prs.get(number)!
|
|
102
|
+
if (pr.state !== 'open' || pr.mergeable !== true || this.headShas.get(number) !== head)
|
|
103
|
+
throw new Error('Fake stack merge requires an open mergeable exact head')
|
|
104
|
+
const gate = this.gates.get(number) ?? this.defaultGatePresence
|
|
105
|
+
if (gate !== 'absent') throw new Error('Fake stack merge is gated')
|
|
106
|
+
const sha = this.resolveMergeSha(number)
|
|
107
|
+
this.linearStackMerges.push({ number, head })
|
|
108
|
+
this.prs.set(number, { state: 'merged', sha, headSha: head })
|
|
109
|
+
return sha
|
|
110
|
+
}
|
|
111
|
+
readonly retargeted: { number: number; base: string }[] = []
|
|
112
|
+
async retargetPr(workspacePath: string, number: number, base: string): Promise<void> {
|
|
113
|
+
const pr = await this.inspectLandingPr(workspacePath, number)
|
|
114
|
+
if (!pr.open) throw new Error(`PR #${number} is no longer open`)
|
|
115
|
+
this.opened[number - 1]!.base = base
|
|
116
|
+
this.retargeted.push({ number, base })
|
|
117
|
+
}
|
|
118
|
+
async inspectLandingPr(_workspacePath: string, number: number) {
|
|
119
|
+
const pr = this.opened[number - 1]
|
|
120
|
+
if (!pr) throw new Error(`FakeForge: missing PR refs #${number}`)
|
|
121
|
+
return {
|
|
122
|
+
base: pr.base,
|
|
123
|
+
head: pr.head,
|
|
124
|
+
headSha: this.headShas.get(number) ?? this.resolveHeadSha(number),
|
|
125
|
+
open: this.prs.get(number)?.state === 'open',
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async inspectLandingGate(branch: string): Promise<import('../types').LandingGateInspection> {
|
|
129
|
+
const index = this.opened.findIndex((pr) => pr.base === branch)
|
|
130
|
+
const gate =
|
|
131
|
+
index === -1
|
|
132
|
+
? this.defaultGatePresence
|
|
133
|
+
: (this.gates.get(index + 1) ?? this.defaultGatePresence)
|
|
134
|
+
if (typeof gate !== 'string') return { kind: 'unproven', reason: gate.detail }
|
|
135
|
+
return gate === 'absent'
|
|
136
|
+
? { kind: 'proved-ungated' }
|
|
137
|
+
: { kind: 'gated', reason: 'Fake destination requires merge gates' }
|
|
138
|
+
}
|
|
84
139
|
readonly name = 'fake'
|
|
140
|
+
readonly archives = new Map<string, string>()
|
|
141
|
+
readonly rewrites: { branch: string; expected: string; sha: string }[] = []
|
|
142
|
+
rewrite: import('../types').ForgeRewrite = {
|
|
143
|
+
snapshot: async ({ branch }) => {
|
|
144
|
+
const sha = this.remoteBranches.get(branch)
|
|
145
|
+
if (sha === undefined) throw new Error(`fake: unknown build branch ${branch}`)
|
|
146
|
+
return sha
|
|
147
|
+
},
|
|
148
|
+
archive: async ({ ref, sha }) => {
|
|
149
|
+
const prior = this.archives.get(ref)
|
|
150
|
+
if (prior !== undefined && prior !== sha) throw new Error(`immutable archive ${ref} differs`)
|
|
151
|
+
this.archives.set(ref, sha)
|
|
152
|
+
},
|
|
153
|
+
replace: async ({ branch, expected, sha }) => {
|
|
154
|
+
const actual = this.remoteBranches.get(branch) ?? null
|
|
155
|
+
if (actual === sha) return { kind: 'published' }
|
|
156
|
+
if (actual !== expected) return { kind: 'lease-mismatch', actual }
|
|
157
|
+
this.rewrites.push({ branch, expected, sha })
|
|
158
|
+
this.remoteBranches.set(branch, sha)
|
|
159
|
+
return { kind: 'published' }
|
|
160
|
+
},
|
|
161
|
+
}
|
|
85
162
|
readonly prAttachments?: PrAttachmentHosting
|
|
86
163
|
|
|
87
164
|
/** Optional checkout-less read seam (SPEC §16.1 pipeline pinning): seeded
|
|
@@ -90,6 +167,8 @@ export class FakeForge implements Forge {
|
|
|
90
167
|
* not-found contract as the production adapters. */
|
|
91
168
|
readonly remoteBranches = new Map<string, string>()
|
|
92
169
|
readonly files = new Map<string, string>()
|
|
170
|
+
readonly commitMessages = new Map<string, string>()
|
|
171
|
+
readonly buildSlugs = new Map<number, string>()
|
|
93
172
|
|
|
94
173
|
/** Journals — public so tests assert directly on call order and args. */
|
|
95
174
|
readonly pushes: PushRecord[] = []
|
|
@@ -122,6 +201,29 @@ export class FakeForge implements Forge {
|
|
|
122
201
|
private readonly deleteBranchErrors: string[] = []
|
|
123
202
|
private readonly publishedBranches = new Set<string>()
|
|
124
203
|
|
|
204
|
+
readonly nodeOpenings: { branch: string; sha: string }[] = []
|
|
205
|
+
readonly nodeComparisons = new Map<string, number>()
|
|
206
|
+
readonly nodeAncestors = new Map<string, Set<string>>()
|
|
207
|
+
async createNodeBranch(branch: string, sha: string): Promise<string> {
|
|
208
|
+
this.nodeOpenings.push({ branch, sha })
|
|
209
|
+
const existing = this.remoteBranches.get(branch)
|
|
210
|
+
if (existing !== undefined) {
|
|
211
|
+
if (existing !== sha && !this.nodeAncestors.get(existing)?.has(sha))
|
|
212
|
+
throw new Error(`node branch collision: ${branch}`)
|
|
213
|
+
return existing
|
|
214
|
+
}
|
|
215
|
+
this.remoteBranches.set(branch, sha)
|
|
216
|
+
return sha
|
|
217
|
+
}
|
|
218
|
+
async compareBranches(parent: string, head: string) {
|
|
219
|
+
const parentSha = await this.remoteBranchSha(parent)
|
|
220
|
+
const headSha = await this.remoteBranchSha(head)
|
|
221
|
+
const ahead = this.nodeComparisons.get(`${parent}...${head}`)
|
|
222
|
+
if (ahead === undefined && parentSha !== headSha)
|
|
223
|
+
throw new Error('seed fake node comparison for differing heads')
|
|
224
|
+
return { parentSha, headSha, ahead: ahead ?? 0 }
|
|
225
|
+
}
|
|
226
|
+
|
|
125
227
|
constructor(
|
|
126
228
|
opts: {
|
|
127
229
|
headSha?: HeadSha
|
|
@@ -365,6 +467,10 @@ export class FakeForge implements Forge {
|
|
|
365
467
|
async pushBranch(workspacePath: string, branch: string): Promise<void> {
|
|
366
468
|
this.pushes.push({ workspacePath, branch })
|
|
367
469
|
this.publishedBranches.add(branch)
|
|
470
|
+
this.remoteBranches.set(
|
|
471
|
+
branch,
|
|
472
|
+
typeof this.headSha === 'string' ? this.headSha : this.headSha(this.nextNumber),
|
|
473
|
+
)
|
|
368
474
|
}
|
|
369
475
|
|
|
370
476
|
async closePr(workspacePath: string, number: number): Promise<ClosePrResult> {
|
|
@@ -383,6 +489,7 @@ export class FakeForge implements Forge {
|
|
|
383
489
|
const error = this.deleteBranchErrors.shift()
|
|
384
490
|
if (error !== undefined) throw new Error(error)
|
|
385
491
|
this.publishedBranches.delete(branch)
|
|
492
|
+
this.remoteBranches.delete(branch)
|
|
386
493
|
}
|
|
387
494
|
|
|
388
495
|
async openPr(opts: {
|
|
@@ -396,7 +503,7 @@ export class FakeForge implements Forge {
|
|
|
396
503
|
// Idempotent by head branch, mirroring GitHubForge (SPEC §8.7).
|
|
397
504
|
for (let i = this.opened.length - 1; i >= 0; i -= 1) {
|
|
398
505
|
const number = i + 1
|
|
399
|
-
if (this.opened[i]!.head !== opts.head) continue
|
|
506
|
+
if (this.opened[i]!.head !== opts.head || this.opened[i]!.base !== opts.base) continue
|
|
400
507
|
if (this.prs.get(number)?.state !== 'open') continue
|
|
401
508
|
return {
|
|
402
509
|
number,
|
|
@@ -418,14 +525,18 @@ export class FakeForge implements Forge {
|
|
|
418
525
|
this.getPrStateCalls.push({ workspacePath, number })
|
|
419
526
|
const state = this.prs.get(number)
|
|
420
527
|
if (!state) throw new Error(`FakeForge: unknown PR #${number}`)
|
|
421
|
-
return state
|
|
528
|
+
return state.state === 'open'
|
|
529
|
+
? { ...state, nativeAutoMerge: state.nativeAutoMerge ?? this.isAutoMergeEnabled(number) }
|
|
530
|
+
: state
|
|
422
531
|
}
|
|
423
532
|
|
|
424
533
|
async setAutoMerge(
|
|
425
534
|
workspacePath: string,
|
|
426
535
|
number: number,
|
|
427
536
|
enabled: boolean,
|
|
537
|
+
options?: BuildLandingOptions,
|
|
428
538
|
): Promise<AutoMergeResult> {
|
|
539
|
+
if (enabled && options !== undefined) this.buildSlugs.set(number, options.buildSlug)
|
|
429
540
|
this.assertPr(number)
|
|
430
541
|
const currentlyEnabled = this.autoMerge.get(number) ?? false
|
|
431
542
|
|
|
@@ -450,6 +561,8 @@ export class FakeForge implements Forge {
|
|
|
450
561
|
this.autoMergeCalls.push({ workspacePath, number, enabled: true, changed: false })
|
|
451
562
|
return { kind: 'deferred', reason }
|
|
452
563
|
}
|
|
564
|
+
if (options?.canApply !== undefined && !(await options.canApply()))
|
|
565
|
+
return { kind: 'deferred' }
|
|
453
566
|
this.autoMerge.set(number, true)
|
|
454
567
|
this.autoMergeCalls.push({
|
|
455
568
|
workspacePath,
|
|
@@ -484,7 +597,12 @@ export class FakeForge implements Forge {
|
|
|
484
597
|
}
|
|
485
598
|
}
|
|
486
599
|
|
|
487
|
-
async squashMerge(
|
|
600
|
+
async squashMerge(
|
|
601
|
+
workspacePath: string,
|
|
602
|
+
number: number,
|
|
603
|
+
expectedHeadSha: string,
|
|
604
|
+
options?: BuildLandingOptions,
|
|
605
|
+
): Promise<void> {
|
|
488
606
|
this.assertPr(number)
|
|
489
607
|
const error = this.squashErrors.get(number)
|
|
490
608
|
if (error !== undefined) throw new Error(error)
|
|
@@ -509,10 +627,30 @@ export class FakeForge implements Forge {
|
|
|
509
627
|
throw new Error(`FakeForge: PR #${number} is no longer direct-merge eligible`)
|
|
510
628
|
}
|
|
511
629
|
|
|
512
|
-
this.squashMergeCalls.push({
|
|
630
|
+
this.squashMergeCalls.push({
|
|
631
|
+
workspacePath,
|
|
632
|
+
number,
|
|
633
|
+
expectedHeadSha,
|
|
634
|
+
...(options === undefined ? {} : { buildSlug: options.buildSlug }),
|
|
635
|
+
})
|
|
636
|
+
const message = this.opened[number - 1]?.mergeMessage ?? this.opened[number - 1]?.body ?? ''
|
|
637
|
+
this.commitMessages.set(
|
|
638
|
+
this.resolveMergeSha(number),
|
|
639
|
+
options === undefined ? message : withBuildTrailer(message, options.buildSlug),
|
|
640
|
+
)
|
|
513
641
|
this.prs.set(number, { state: 'merged', sha: this.resolveMergeSha(number) })
|
|
514
642
|
}
|
|
515
643
|
|
|
644
|
+
async readCommitMessage(_workspacePath: string, sha: string): Promise<string> {
|
|
645
|
+
return this.commitMessages.get(sha) ?? ''
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
async containsBuild(_workspacePath: string, branch: string, buildSlug: string): Promise<boolean> {
|
|
649
|
+
const sha = this.remoteBranches.get(branch)
|
|
650
|
+
if (sha === undefined) throw new Error(`FakeForge: unknown branch ${branch}`)
|
|
651
|
+
return hasBuildTrailer(await this.readCommitMessage(_workspacePath, sha), buildSlug)
|
|
652
|
+
}
|
|
653
|
+
|
|
516
654
|
async commentOnPr(workspacePath: string, number: number, body: string): Promise<void> {
|
|
517
655
|
this.assertPr(number)
|
|
518
656
|
const marker = findSummaryMarker(body)
|