@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,7 @@
|
|
|
1
|
+
import { readinessChecks, type ForgeReadinessCheck } from './readiness'
|
|
2
|
+
import { gitRewrite } from './git-rewrite'
|
|
3
|
+
import { historyContainsBuild, withBuildTrailer } from '../../kernel/build-identity'
|
|
4
|
+
import type { BuildLandingOptions } from '../types'
|
|
1
5
|
import { findSummaryMarker } from './summary-marker'
|
|
2
6
|
import { mkdtemp, rm, writeFile } from 'node:fs/promises'
|
|
3
7
|
import { tmpdir } from 'node:os'
|
|
@@ -24,6 +28,7 @@ const localPrRecord = z.strictObject({
|
|
|
24
28
|
openedHeadSha: objectId,
|
|
25
29
|
status: z.enum(['open', 'closed', 'merged']),
|
|
26
30
|
mergedSha: objectId.optional(),
|
|
31
|
+
mergedHeadSha: objectId.optional(),
|
|
27
32
|
pendingLanding: pendingLanding.optional(),
|
|
28
33
|
comments: z.array(z.string()),
|
|
29
34
|
})
|
|
@@ -39,6 +44,15 @@ function detail(error: unknown): string {
|
|
|
39
44
|
* Git database. No method invokes a shell, remote command, network client, or
|
|
40
45
|
* `gh`; every subprocess is an argv-form `git` command. */
|
|
41
46
|
export class LocalGitForge implements Forge {
|
|
47
|
+
async inspectReadiness(): Promise<ForgeReadinessCheck[]> {
|
|
48
|
+
return readinessChecks('pass', 'Local Git has no hosted merge settings or protection policy.')
|
|
49
|
+
}
|
|
50
|
+
get rewrite() {
|
|
51
|
+
return gitRewrite(this.exec, true)
|
|
52
|
+
}
|
|
53
|
+
async inspectLandingGate(_branch: string): Promise<import('../types').LandingGateInspection> {
|
|
54
|
+
return { kind: 'proved-ungated' }
|
|
55
|
+
}
|
|
42
56
|
readonly name = 'local-git'
|
|
43
57
|
private readonly exec: Exec
|
|
44
58
|
/** The repository the optional checkout-less read seam reads from. The
|
|
@@ -66,6 +80,35 @@ export class LocalGitForge implements Forge {
|
|
|
66
80
|
return result.stdout.trim()
|
|
67
81
|
}
|
|
68
82
|
|
|
83
|
+
async createNodeBranch(branch: string, sha: string): Promise<string> {
|
|
84
|
+
if (!this.repoRoot) throw new Error('local-git node branches require repoRoot')
|
|
85
|
+
const ref = `refs/heads/${branch}`
|
|
86
|
+
await this.assertRef(ref, this.repoRoot)
|
|
87
|
+
const existing = await this.command(['rev-parse', '--verify', ref], this.repoRoot, true)
|
|
88
|
+
if (existing.exitCode === 0) {
|
|
89
|
+
const contains = await this.command(
|
|
90
|
+
['merge-base', '--is-ancestor', sha, ref],
|
|
91
|
+
this.repoRoot,
|
|
92
|
+
true,
|
|
93
|
+
)
|
|
94
|
+
if (contains.exitCode !== 0) throw new Error(`node branch collision: ${branch}`)
|
|
95
|
+
return existing.stdout.trim()
|
|
96
|
+
}
|
|
97
|
+
await this.command(['update-ref', ref, sha, ''], this.repoRoot)
|
|
98
|
+
return sha
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async compareBranches(parent: string, head: string) {
|
|
102
|
+
if (!this.repoRoot) throw new Error('local-git node comparison requires repoRoot')
|
|
103
|
+
const parentSha = await this.remoteBranchSha(parent)
|
|
104
|
+
const headSha = await this.remoteBranchSha(head)
|
|
105
|
+
const count = await this.command(
|
|
106
|
+
['rev-list', '--count', `${parentSha}..${headSha}`],
|
|
107
|
+
this.repoRoot,
|
|
108
|
+
)
|
|
109
|
+
return { parentSha, headSha, ahead: Number(count.stdout.trim()) }
|
|
110
|
+
}
|
|
111
|
+
|
|
69
112
|
/** File bytes from the served repository. Ref omitted → the checkout's HEAD.
|
|
70
113
|
* Throws when the path does not exist at that ref. */
|
|
71
114
|
async readFile(path: string, ref?: string): Promise<string> {
|
|
@@ -88,7 +131,10 @@ export class LocalGitForge implements Forge {
|
|
|
88
131
|
}
|
|
89
132
|
|
|
90
133
|
private async sha(ref: string, cwd: string): Promise<string> {
|
|
91
|
-
const result = await this.command(
|
|
134
|
+
const result = await this.command(
|
|
135
|
+
['rev-parse', '--verify', '--end-of-options', `${ref}^{commit}`],
|
|
136
|
+
cwd,
|
|
137
|
+
)
|
|
92
138
|
const sha = result.stdout.trim()
|
|
93
139
|
if (!objectId.safeParse(sha).success) {
|
|
94
140
|
throw new Error(
|
|
@@ -255,7 +301,8 @@ export class LocalGitForge implements Forge {
|
|
|
255
301
|
for (;;) {
|
|
256
302
|
const records = await this.records(opts.workspacePath)
|
|
257
303
|
const adopted = records.find(
|
|
258
|
-
(record) =>
|
|
304
|
+
(record) =>
|
|
305
|
+
record.status === 'open' && record.head === opts.head && record.base === opts.base,
|
|
259
306
|
)
|
|
260
307
|
if (adopted !== undefined) {
|
|
261
308
|
return { number: adopted.number, url: headRef, headSha }
|
|
@@ -344,6 +391,34 @@ export class LocalGitForge implements Forge {
|
|
|
344
391
|
return (await this.transitionCheckout(checkout, pending.baseSha, pending.commitSha, false)).ok
|
|
345
392
|
}
|
|
346
393
|
|
|
394
|
+
async retargetPr(workspacePath: string, number: number, base: string): Promise<void> {
|
|
395
|
+
await this.sha(`refs/heads/${base}`, workspacePath)
|
|
396
|
+
if ((await this.getPrState(workspacePath, number)).state !== 'open')
|
|
397
|
+
throw new Error(`PR #${number} is no longer open`)
|
|
398
|
+
await this.updateRecord(workspacePath, number, (current) => {
|
|
399
|
+
if (current.status !== 'open' || current.pendingLanding)
|
|
400
|
+
throw new Error(`PR #${number} is landing or terminal`)
|
|
401
|
+
return { ...current, base }
|
|
402
|
+
})
|
|
403
|
+
if ((await this.inspectLandingPr(workspacePath, number)).base !== base)
|
|
404
|
+
throw new Error(`PR #${number} base acknowledgement failed`)
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
async inspectLandingPr(workspacePath: string, number: number) {
|
|
408
|
+
const { record } = await this.readRecord(workspacePath, number)
|
|
409
|
+
if (record.status === 'merged' && !record.mergedHeadSha)
|
|
410
|
+
throw new Error('historical local-git landing has no frozen source head')
|
|
411
|
+
return {
|
|
412
|
+
base: record.base,
|
|
413
|
+
head: record.head,
|
|
414
|
+
headSha:
|
|
415
|
+
record.status === 'merged'
|
|
416
|
+
? (record.mergedHeadSha ?? record.openedHeadSha)
|
|
417
|
+
: await this.sha(`refs/heads/${record.head}`, workspacePath),
|
|
418
|
+
open: record.status === 'open',
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
347
422
|
async getPrState(workspacePath: string, number: number): Promise<PrState> {
|
|
348
423
|
let { record } = await this.readRecord(workspacePath, number)
|
|
349
424
|
if (record.status === 'merged') return { state: 'merged', sha: record.mergedSha! }
|
|
@@ -356,6 +431,7 @@ export class LocalGitForge implements Forge {
|
|
|
356
431
|
(await this.isAncestor(workspacePath, record.pendingLanding.commitSha, baseSha))
|
|
357
432
|
) {
|
|
358
433
|
const landingSha = record.pendingLanding.commitSha
|
|
434
|
+
const mergedHeadSha = record.pendingLanding.headSha
|
|
359
435
|
// At the exact ref-move crash boundary, merged observation waits until
|
|
360
436
|
// the checkout transition succeeds. A later descendant means another Git
|
|
361
437
|
// operation already advanced the landed base, so there is no old checkout
|
|
@@ -369,6 +445,7 @@ export class LocalGitForge implements Forge {
|
|
|
369
445
|
record = await this.updateRecord(workspacePath, number, (current) => ({
|
|
370
446
|
...current,
|
|
371
447
|
status: 'merged',
|
|
448
|
+
mergedHeadSha,
|
|
372
449
|
mergedSha: landingSha,
|
|
373
450
|
pendingLanding: undefined,
|
|
374
451
|
}))
|
|
@@ -516,7 +593,27 @@ export class LocalGitForge implements Forge {
|
|
|
516
593
|
}
|
|
517
594
|
}
|
|
518
595
|
|
|
519
|
-
async
|
|
596
|
+
async readCommitMessage(workspacePath: string, sha: string): Promise<string> {
|
|
597
|
+
const commit = await this.sha(sha, workspacePath)
|
|
598
|
+
return (await this.command(['show', '-s', '--format=%B', commit, '--'], workspacePath)).stdout
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
async containsBuild(workspacePath: string, branch: string, buildSlug: string): Promise<boolean> {
|
|
602
|
+
await this.assertRef(`refs/heads/${branch}`, workspacePath)
|
|
603
|
+
const tip = await this.sha(`refs/heads/${branch}`, workspacePath)
|
|
604
|
+
const history = await this.command(['log', '--format=%B%x00', tip, '--'], workspacePath)
|
|
605
|
+
async function* messages() {
|
|
606
|
+
for (const message of history.stdout.split('\0')) yield message
|
|
607
|
+
}
|
|
608
|
+
return historyContainsBuild(messages(), buildSlug)
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
async squashMerge(
|
|
612
|
+
workspacePath: string,
|
|
613
|
+
number: number,
|
|
614
|
+
expectedHeadSha: string,
|
|
615
|
+
options?: BuildLandingOptions,
|
|
616
|
+
): Promise<void> {
|
|
520
617
|
let { record } = await this.readRecord(workspacePath, number)
|
|
521
618
|
if (record.status === 'merged') return
|
|
522
619
|
const headRef = `refs/heads/${record.head}`
|
|
@@ -531,7 +628,17 @@ export class LocalGitForge implements Forge {
|
|
|
531
628
|
|
|
532
629
|
if (record.pendingLanding !== undefined) {
|
|
533
630
|
if (await this.isAncestor(workspacePath, record.pendingLanding.commitSha, baseSha)) return
|
|
534
|
-
if (
|
|
631
|
+
if (
|
|
632
|
+
record.pendingLanding.baseSha === baseSha &&
|
|
633
|
+
record.pendingLanding.headSha === headSha &&
|
|
634
|
+
(options === undefined ||
|
|
635
|
+
(
|
|
636
|
+
await this.readCommitMessage(workspacePath, record.pendingLanding.commitSha)
|
|
637
|
+
).trimEnd() ===
|
|
638
|
+
withBuildTrailer(record.mergeMessage, options.buildSlug, {
|
|
639
|
+
includesSubject: true,
|
|
640
|
+
}).trimEnd())
|
|
641
|
+
) {
|
|
535
642
|
// Resume the crash window after pending evidence but before ref update.
|
|
536
643
|
} else {
|
|
537
644
|
record = await this.updateRecord(workspacePath, number, (current) => ({
|
|
@@ -545,7 +652,14 @@ export class LocalGitForge implements Forge {
|
|
|
545
652
|
if (pending === undefined) {
|
|
546
653
|
const treeSha = await this.mergeTree(workspacePath, baseSha, headSha)
|
|
547
654
|
if (treeSha === null) throw new Error(`local-git PR #${number} is not mergeable`)
|
|
548
|
-
const commitSha = await this.commitTree(
|
|
655
|
+
const commitSha = await this.commitTree(
|
|
656
|
+
workspacePath,
|
|
657
|
+
treeSha,
|
|
658
|
+
baseSha,
|
|
659
|
+
options === undefined
|
|
660
|
+
? record.mergeMessage
|
|
661
|
+
: withBuildTrailer(record.mergeMessage, options.buildSlug, { includesSubject: true }),
|
|
662
|
+
)
|
|
549
663
|
pending = { baseSha, headSha, treeSha, commitSha }
|
|
550
664
|
record = await this.updateRecord(workspacePath, number, (current) => ({
|
|
551
665
|
...current,
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import type { Forge } from '../types'
|
|
3
|
+
|
|
4
|
+
export const hardReadinessKeys = [
|
|
5
|
+
'squash',
|
|
6
|
+
'rebase',
|
|
7
|
+
'build-refs',
|
|
8
|
+
'node-refs',
|
|
9
|
+
'archive-refs',
|
|
10
|
+
] as const
|
|
11
|
+
export const readinessKeySchema = z.enum([...hardReadinessKeys, 'linear-history', 'root-freshness'])
|
|
12
|
+
export type ReadinessKey = z.infer<typeof readinessKeySchema>
|
|
13
|
+
export const forgeReadinessCheckSchema = z.object({
|
|
14
|
+
check: readinessKeySchema,
|
|
15
|
+
requirement: z.enum(['hard', 'recommendation']),
|
|
16
|
+
status: z.enum(['pass', 'fail', 'unknown']),
|
|
17
|
+
detail: z.string().min(1),
|
|
18
|
+
remediation: z.string().min(1),
|
|
19
|
+
})
|
|
20
|
+
export type ForgeReadinessCheck = z.infer<typeof forgeReadinessCheckSchema>
|
|
21
|
+
export interface ForgeReadinessInput {
|
|
22
|
+
rootBranch: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const inventory: readonly [ReadinessKey, string][] = [
|
|
26
|
+
['squash', 'Enable Settings → General → Allow squash merging.'],
|
|
27
|
+
['rebase', 'Enable Settings → General → Allow rebase merging.'],
|
|
28
|
+
[
|
|
29
|
+
'build-refs',
|
|
30
|
+
'Allow Contents:write and direct force pushes throughout refs/heads/ab/ in branch protection and rulesets.',
|
|
31
|
+
],
|
|
32
|
+
[
|
|
33
|
+
'node-refs',
|
|
34
|
+
'Allow Contents:write and direct force pushes throughout refs/heads/ab-node/ in branch protection and rulesets.',
|
|
35
|
+
],
|
|
36
|
+
[
|
|
37
|
+
'archive-refs',
|
|
38
|
+
'Allow publication of immutable refs/autobuild/archive/ refs; manually verify access without overwriting archives.',
|
|
39
|
+
],
|
|
40
|
+
['linear-history', 'Enable Require linear history on protected root and node target branches.'],
|
|
41
|
+
[
|
|
42
|
+
'root-freshness',
|
|
43
|
+
'Require branches to be up to date before merging on the root, with nonempty required checks enforced for all actors; otherwise root landing is best-effort rather than fenced.',
|
|
44
|
+
],
|
|
45
|
+
]
|
|
46
|
+
export function readinessChecks(
|
|
47
|
+
status: ForgeReadinessCheck['status'],
|
|
48
|
+
detail: string,
|
|
49
|
+
): ForgeReadinessCheck[] {
|
|
50
|
+
return inventory.map(([check, remediation]) => ({
|
|
51
|
+
check,
|
|
52
|
+
requirement: (hardReadinessKeys as readonly string[]).includes(check)
|
|
53
|
+
? 'hard'
|
|
54
|
+
: 'recommendation',
|
|
55
|
+
status,
|
|
56
|
+
detail,
|
|
57
|
+
remediation,
|
|
58
|
+
}))
|
|
59
|
+
}
|
|
60
|
+
export async function inspectForgeReadiness(
|
|
61
|
+
forge: Forge,
|
|
62
|
+
input: ForgeReadinessInput,
|
|
63
|
+
): Promise<ForgeReadinessCheck[]> {
|
|
64
|
+
if (!forge.inspectReadiness)
|
|
65
|
+
return readinessChecks(
|
|
66
|
+
'unknown',
|
|
67
|
+
'Forge adapter does not implement readiness inspection; upgrade the adapter.',
|
|
68
|
+
)
|
|
69
|
+
try {
|
|
70
|
+
const checks = z.array(forgeReadinessCheckSchema).parse(await forge.inspectReadiness(input))
|
|
71
|
+
const defaults = readinessChecks('unknown', 'Adapter omitted this check; upgrade the adapter.')
|
|
72
|
+
return defaults.map((fallback) => {
|
|
73
|
+
const matches = checks.filter((item) => item.check === fallback.check)
|
|
74
|
+
return matches.length === 1 ? { ...matches[0]!, requirement: fallback.requirement } : fallback
|
|
75
|
+
})
|
|
76
|
+
} catch {
|
|
77
|
+
return readinessChecks(
|
|
78
|
+
'unknown',
|
|
79
|
+
'Forge inspection unavailable. Grant Metadata:read and Administration:read (classic private repositories: repo scope), then revalidate. Contents:write is separately required for publication.',
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export function readinessLabel(check: ForgeReadinessCheck): string {
|
|
84
|
+
return check.status === 'unknown'
|
|
85
|
+
? 'UNKNOWN'
|
|
86
|
+
: check.status === 'fail' && check.requirement === 'recommendation'
|
|
87
|
+
? 'WARN'
|
|
88
|
+
: check.status.toUpperCase()
|
|
89
|
+
}
|
|
90
|
+
export function formatReadinessFailure(check: {
|
|
91
|
+
check: string
|
|
92
|
+
detail: string
|
|
93
|
+
remediation: string
|
|
94
|
+
}): string {
|
|
95
|
+
return `Forge ${check.check}: ${check.detail} ${check.remediation}`
|
|
96
|
+
}
|
|
97
|
+
export function formatForgeReadiness(check: ForgeReadinessCheck): string {
|
|
98
|
+
return `${readinessLabel(check)} ${formatReadinessFailure(check)}`
|
|
99
|
+
}
|
|
@@ -117,6 +117,47 @@ export function describeTicketSourceContract(
|
|
|
117
117
|
factory: TicketSourceContractFactory,
|
|
118
118
|
): void {
|
|
119
119
|
describe(`TicketSource contract: ${name}`, () => {
|
|
120
|
+
test('optional integration tree metadata preserves graph invariants', async () => {
|
|
121
|
+
await withTicketSource(factory, async (harness) => {
|
|
122
|
+
const source = harness.source
|
|
123
|
+
if (!source.integrationTree) return
|
|
124
|
+
expect(typeof source.listAll).toBe('function')
|
|
125
|
+
const node = await createTracked(harness, {
|
|
126
|
+
title: contractTicketTitle('node'),
|
|
127
|
+
body: CONTRACT_TICKET_BODY,
|
|
128
|
+
kind: 'node',
|
|
129
|
+
})
|
|
130
|
+
const child = await createTracked(harness, {
|
|
131
|
+
title: contractTicketTitle('child'),
|
|
132
|
+
body: CONTRACT_TICKET_BODY,
|
|
133
|
+
target: node.ref.id,
|
|
134
|
+
})
|
|
135
|
+
expect((await source.get(node.ref.id))?.kind).toBe('node')
|
|
136
|
+
expect((await source.get(child.ref.id))?.target).toBe(node.ref.id)
|
|
137
|
+
expect(
|
|
138
|
+
(await source.listAll!()).tickets.some((ticket) => ticket.ref.id === child.ref.id),
|
|
139
|
+
).toBe(true)
|
|
140
|
+
await expect(
|
|
141
|
+
source.update(node.ref.id, { kind: 'work', title: 'Must not change' }),
|
|
142
|
+
).rejects.toThrow()
|
|
143
|
+
expect((await source.get(node.ref.id))?.title).toBe(node.title)
|
|
144
|
+
await expect(source.update(node.ref.id, { target: node.ref.id })).rejects.toThrow()
|
|
145
|
+
const nested = await createTracked(harness, {
|
|
146
|
+
title: contractTicketTitle('nested node'),
|
|
147
|
+
body: CONTRACT_TICKET_BODY,
|
|
148
|
+
kind: 'node',
|
|
149
|
+
target: node.ref.id,
|
|
150
|
+
})
|
|
151
|
+
await source.update(child.ref.id, { target: nested.ref.id })
|
|
152
|
+
expect((await source.get(child.ref.id))?.target).toBe(nested.ref.id)
|
|
153
|
+
await expect(source.update(node.ref.id, { target: nested.ref.id })).rejects.toThrow()
|
|
154
|
+
await source.update(child.ref.id, { target: null })
|
|
155
|
+
await source.update(nested.ref.id, { target: null, kind: 'work' })
|
|
156
|
+
await source.update(node.ref.id, { kind: 'work' })
|
|
157
|
+
expect((await source.get(node.ref.id))?.kind).toBe('work')
|
|
158
|
+
})
|
|
159
|
+
})
|
|
160
|
+
|
|
120
161
|
test('revisions cover mutable content and guarded writes fail closed', async () => {
|
|
121
162
|
await withTicketSource(factory, async (harness) => {
|
|
122
163
|
const source = harness.source
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { compatibleTicketSource } from './tree'
|
|
1
2
|
import { configuredStore } from '../../cli/configured-store'
|
|
2
3
|
import { projectToken } from '../../cli/project-credentials'
|
|
3
4
|
import { resolveRepoOrigin } from '../../cli/repo-state'
|
|
@@ -23,7 +24,7 @@ function reason(error: unknown): string {
|
|
|
23
24
|
return error instanceof Error ? error.message : String(error)
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
async function rawTicketSource(
|
|
27
28
|
config: TicketsConfig,
|
|
28
29
|
env: Record<string, string | undefined>,
|
|
29
30
|
/** A relative [tickets].dir is relative to the repo, not this process's cwd. */
|
|
@@ -177,3 +178,9 @@ export async function createTicketSource(
|
|
|
177
178
|
)
|
|
178
179
|
}
|
|
179
180
|
}
|
|
181
|
+
|
|
182
|
+
export async function createTicketSource(
|
|
183
|
+
...args: Parameters<typeof rawTicketSource>
|
|
184
|
+
): Promise<TicketSource> {
|
|
185
|
+
return compatibleTicketSource(await rawTicketSource(...args))
|
|
186
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { validateTicketTree } from './tree'
|
|
1
2
|
import { fileRequestedIds } from './requested-id'
|
|
2
3
|
import { ticketRevision, checkTicketRevision } from './revision'
|
|
3
4
|
/**
|
|
@@ -20,6 +21,8 @@ import { validateTicketUpdate } from './update'
|
|
|
20
21
|
|
|
21
22
|
function cloneTicket(ticket: Ticket, doneState: string): Ticket {
|
|
22
23
|
return {
|
|
24
|
+
kind: ticket.kind ?? 'work',
|
|
25
|
+
...(ticket.target !== undefined ? { target: ticket.target } : {}),
|
|
23
26
|
revision: ticketRevision(ticket),
|
|
24
27
|
ref: { ...ticket.ref },
|
|
25
28
|
...(ticket.creationKey !== undefined ? { creationKey: ticket.creationKey } : {}),
|
|
@@ -35,6 +38,14 @@ function cloneTicket(ticket: Ticket, doneState: string): Ticket {
|
|
|
35
38
|
export class FakeTicketSource implements TicketSource {
|
|
36
39
|
readonly requestedIds = fileRequestedIds
|
|
37
40
|
readonly name = 'fake'
|
|
41
|
+
readonly integrationTree = true
|
|
42
|
+
|
|
43
|
+
async listAll(): Promise<TicketListing> {
|
|
44
|
+
return {
|
|
45
|
+
tickets: [...this.tickets.values()].map((ticket) => cloneTicket(ticket, this.doneState)),
|
|
46
|
+
diagnostics: [],
|
|
47
|
+
}
|
|
48
|
+
}
|
|
38
49
|
|
|
39
50
|
/** Journal of every projection sent outward (§13), in call order. */
|
|
40
51
|
readonly comments: Array<{ id: string; body: string }> = []
|
|
@@ -139,7 +150,16 @@ export class FakeTicketSource implements TicketSource {
|
|
|
139
150
|
}
|
|
140
151
|
const id = opts.requestedId ?? `fake-${this.nextId++}`
|
|
141
152
|
if (this.tickets.has(id)) throw new Error(`requested ticket id already occupied: ${id}`)
|
|
153
|
+
const canonicalTarget = await validateTicketTree(this, id, draft)
|
|
154
|
+
// Graph reads yield: recheck adoption and occupancy before the in-memory write.
|
|
155
|
+
if (opts.idempotencyKey !== undefined) {
|
|
156
|
+
const adopted = this.idempotency.get(opts.idempotencyKey)
|
|
157
|
+
if (adopted !== undefined) return cloneTicket(this.require(adopted, 'create'), this.doneState)
|
|
158
|
+
}
|
|
159
|
+
if (this.tickets.has(id)) throw new Error(`requested ticket id already occupied: ${id}`)
|
|
142
160
|
const ticket: Ticket = {
|
|
161
|
+
kind: draft.kind ?? 'work',
|
|
162
|
+
...(canonicalTarget != null ? { target: canonicalTarget } : {}),
|
|
143
163
|
revision: 'pending',
|
|
144
164
|
ref: { source: this.name, id, title: draft.title },
|
|
145
165
|
...(opts.idempotencyKey !== undefined ? { creationKey: opts.idempotencyKey } : {}),
|
|
@@ -164,7 +184,7 @@ export class FakeTicketSource implements TicketSource {
|
|
|
164
184
|
async mutateIfRevision(id: string, expected: string, mutation: TicketMutation): Promise<void> {
|
|
165
185
|
const ticket = this.require(id, 'revision-checked write')
|
|
166
186
|
checkTicketRevision(cloneTicket(ticket, this.doneState), expected)
|
|
167
|
-
if (mutation.kind === 'update') await this.
|
|
187
|
+
if (mutation.kind === 'update') await this.applyUpdate(id, mutation.patch, expected)
|
|
168
188
|
else if (mutation.kind === 'transition') await this.transition(id, mutation.state)
|
|
169
189
|
else {
|
|
170
190
|
for (const blocker of mutation.ids) {
|
|
@@ -183,8 +203,17 @@ export class FakeTicketSource implements TicketSource {
|
|
|
183
203
|
}
|
|
184
204
|
|
|
185
205
|
async update(id: string, patch: TicketUpdate): Promise<void> {
|
|
206
|
+
await this.applyUpdate(id, patch)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private async applyUpdate(id: string, patch: TicketUpdate, expected?: string): Promise<void> {
|
|
186
210
|
const validated = validateTicketUpdate(patch)
|
|
211
|
+
const canonicalTarget = await validateTicketTree(this, id, validated)
|
|
187
212
|
const ticket = this.require(id, 'update')
|
|
213
|
+
if (expected !== undefined) checkTicketRevision(cloneTicket(ticket, this.doneState), expected)
|
|
214
|
+
if (validated.kind !== undefined) ticket.kind = validated.kind
|
|
215
|
+
if (canonicalTarget === null) delete ticket.target
|
|
216
|
+
else if (canonicalTarget !== undefined) ticket.target = canonicalTarget
|
|
188
217
|
|
|
189
218
|
if (validated.title !== undefined) {
|
|
190
219
|
ticket.title = validated.title
|
|
@@ -243,6 +272,8 @@ export class FakeTicketSource implements TicketSource {
|
|
|
243
272
|
|
|
244
273
|
function cloneUpdate(patch: TicketUpdate): TicketUpdate {
|
|
245
274
|
return {
|
|
275
|
+
...(patch.kind !== undefined ? { kind: patch.kind } : {}),
|
|
276
|
+
...(patch.target !== undefined ? { target: patch.target } : {}),
|
|
246
277
|
...(patch.title !== undefined ? { title: patch.title } : {}),
|
|
247
278
|
...(patch.body !== undefined ? { body: patch.body } : {}),
|
|
248
279
|
...(patch.labels !== undefined ? { labels: [...patch.labels] } : {}),
|
|
@@ -3,6 +3,11 @@ import { parse as parseToml, stringify as stringifyToml } from 'smol-toml'
|
|
|
3
3
|
import { z } from 'zod'
|
|
4
4
|
|
|
5
5
|
const frontmatterSchema = z.strictObject({
|
|
6
|
+
kind: z.enum(['work', 'node']).optional(),
|
|
7
|
+
target: z
|
|
8
|
+
.string()
|
|
9
|
+
.refine((value) => value.trim().length > 0)
|
|
10
|
+
.optional(),
|
|
6
11
|
comments: z
|
|
7
12
|
.array(
|
|
8
13
|
z.strictObject({ body: z.string(), createdAt: z.string(), author: z.string().optional() }),
|
|
@@ -74,6 +79,8 @@ export function parseTicketFile(path: string, raw: string): { front: Frontmatter
|
|
|
74
79
|
|
|
75
80
|
export function serializeTicketFile(front: Frontmatter, body: string): string {
|
|
76
81
|
const data: Record<string, unknown> = { id: front.id, title: front.title }
|
|
82
|
+
if (front.kind === 'node') data.kind = front.kind
|
|
83
|
+
if (front.target !== undefined) data.target = front.target
|
|
77
84
|
if (front.labels.length > 0) data.labels = front.labels
|
|
78
85
|
// Only when nonempty: a file that never declared blockers must round-trip
|
|
79
86
|
// byte-identically rather than sprouting `blockedBy = []` on every write.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { validateTicketTree } from './tree'
|
|
1
2
|
import { fileRequestedIds, validateFileTicketId } from './requested-id'
|
|
2
3
|
import { FileTicketAssets } from './file-assets'
|
|
3
4
|
/**
|
|
@@ -93,6 +94,7 @@ interface Located {
|
|
|
93
94
|
|
|
94
95
|
export class FileTicketSource implements TicketSource {
|
|
95
96
|
readonly name = 'file'
|
|
97
|
+
readonly integrationTree = true
|
|
96
98
|
readonly requestedIds = fileRequestedIds
|
|
97
99
|
readonly assets: FileTicketAssets
|
|
98
100
|
|
|
@@ -278,7 +280,10 @@ export class FileTicketSource implements TicketSource {
|
|
|
278
280
|
const taken = new Set(located.map((f) => f.id))
|
|
279
281
|
let n = 1
|
|
280
282
|
while (taken.has(`file-${n}`)) n += 1
|
|
283
|
+
const canonicalTarget = await validateTicketTree(this, opts.requestedId, draft)
|
|
281
284
|
const front: Frontmatter = {
|
|
285
|
+
...(draft.kind !== undefined ? { kind: draft.kind } : {}),
|
|
286
|
+
...(canonicalTarget != null ? { target: canonicalTarget } : {}),
|
|
282
287
|
id: opts.requestedId ?? `file-${n}`,
|
|
283
288
|
comments: [],
|
|
284
289
|
title: draft.title,
|
|
@@ -307,6 +312,7 @@ export class FileTicketSource implements TicketSource {
|
|
|
307
312
|
await this.requireForWrite(blocker, 'blocker')
|
|
308
313
|
}
|
|
309
314
|
}
|
|
315
|
+
const canonicalTarget = patch ? await validateTicketTree(this, id, patch) : undefined
|
|
310
316
|
// Final locate/read immediately precedes the write. This is best effort,
|
|
311
317
|
// matching unguarded file writes; it does not introduce filesystem locks.
|
|
312
318
|
const loaded = await this.requireForWrite(id, 'revision-checked write')
|
|
@@ -318,6 +324,9 @@ export class FileTicketSource implements TicketSource {
|
|
|
318
324
|
const front = { ...loaded.front }
|
|
319
325
|
let body = loaded.body
|
|
320
326
|
if (patch) {
|
|
327
|
+
if (patch.kind !== undefined) front.kind = patch.kind
|
|
328
|
+
if (canonicalTarget === null) delete front.target
|
|
329
|
+
else if (canonicalTarget !== undefined) front.target = canonicalTarget
|
|
321
330
|
if (patch.title !== undefined) front.title = patch.title
|
|
322
331
|
if (patch.labels !== undefined) front.labels = patch.labels
|
|
323
332
|
if (patch.body !== undefined) body = patch.body
|
|
@@ -335,12 +344,16 @@ export class FileTicketSource implements TicketSource {
|
|
|
335
344
|
async update(id: string, patch: TicketUpdate): Promise<void> {
|
|
336
345
|
const validated = validateTicketUpdate(patch)
|
|
337
346
|
await this.ensureLayout()
|
|
347
|
+
const canonicalTarget = await validateTicketTree(this, id, validated)
|
|
338
348
|
const loaded = await this.requireForWrite(id, 'update')
|
|
339
349
|
const front: Frontmatter = {
|
|
340
350
|
...loaded.front,
|
|
351
|
+
...(validated.kind !== undefined ? { kind: validated.kind } : {}),
|
|
352
|
+
...(canonicalTarget != null ? { target: canonicalTarget } : {}),
|
|
341
353
|
...(validated.title !== undefined ? { title: validated.title } : {}),
|
|
342
354
|
...(validated.labels !== undefined ? { labels: [...validated.labels] } : {}),
|
|
343
355
|
}
|
|
356
|
+
if (canonicalTarget === null) delete front.target
|
|
344
357
|
await this.rewriteAt(loaded.found, front, validated.body ?? loaded.body)
|
|
345
358
|
}
|
|
346
359
|
|
|
@@ -619,7 +632,7 @@ export class FileTicketSource implements TicketSource {
|
|
|
619
632
|
await rename(temp, found.path)
|
|
620
633
|
}
|
|
621
634
|
|
|
622
|
-
|
|
635
|
+
async listAll(): Promise<TicketListing> {
|
|
623
636
|
const tickets: Ticket[] = []
|
|
624
637
|
const diagnostics: string[] = []
|
|
625
638
|
// Complete discovery first. Structural failures (including duplicate ids)
|
|
@@ -642,7 +655,11 @@ export class FileTicketSource implements TicketSource {
|
|
|
642
655
|
|
|
643
656
|
private toTicket(front: Frontmatter, body: string, state: string): Ticket {
|
|
644
657
|
return {
|
|
658
|
+
kind: front.kind ?? 'work',
|
|
659
|
+
...(front.target !== undefined ? { target: front.target } : {}),
|
|
645
660
|
revision: ticketRevision({
|
|
661
|
+
kind: front.kind,
|
|
662
|
+
target: front.target,
|
|
646
663
|
title: front.title,
|
|
647
664
|
body,
|
|
648
665
|
labels: front.labels,
|
|
@@ -5,6 +5,8 @@ export { HostedTicketSource } from './remote'
|
|
|
5
5
|
export type { HostedTicketFetch, HostedTicketSourceOptions } from './remote'
|
|
6
6
|
export {
|
|
7
7
|
HOSTED_TICKET_OPERATIONS,
|
|
8
|
+
TICKET_TREE_HEADER,
|
|
9
|
+
TICKET_TREE_CAPABILITY,
|
|
8
10
|
TICKET_COMMENTS_HEADER,
|
|
9
11
|
TICKET_COMMENTS_CAPABILITY,
|
|
10
12
|
hostedTicketContextSchema,
|