@defrex/autobuild 1.0.0-beta.1 → 1.0.0-beta.3
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/SPEC.md +310 -56
- package/bin/ab-build-runner.ts +10 -8
- package/docs/architecture.md +177 -23
- package/docs/configuration.md +35 -4
- package/docs/hosted-service.md +35 -0
- package/docs/integration-tree.md +83 -4
- package/docs/landing-policy.md +11 -0
- package/docs/migration-1.0.md +9 -0
- package/docs/operator-api.md +18 -0
- package/docs/remote-store-protocol.md +16 -0
- package/docs/remote-ticket-protocol.md +5 -0
- package/docs/restacking.md +42 -7
- package/docs/setup.md +25 -0
- package/docs/spec-standard.md +71 -0
- package/docs/ticket-dependencies.md +6 -45
- package/docs/ticket-migration.md +50 -4
- package/package.json +3 -3
- package/packages/core/src/cli/attention.ts +4 -1
- package/packages/core/src/cli/binary.ts +17 -1
- package/packages/core/src/cli/build-control.ts +3 -3
- package/packages/core/src/cli/context.ts +53 -1
- package/packages/core/src/cli/dashboard/actions.ts +4 -0
- package/packages/core/src/cli/dashboard/detail.ts +45 -1
- package/packages/core/src/cli/dashboard/facts.ts +7 -2
- package/packages/core/src/cli/dashboard/integration-detail.ts +144 -0
- package/packages/core/src/cli/dashboard/integration-row.ts +255 -0
- package/packages/core/src/cli/dashboard/landing-display.ts +64 -0
- package/packages/core/src/cli/dashboard/model.ts +147 -16
- package/packages/core/src/cli/dashboard/poll.ts +40 -4
- package/packages/core/src/cli/dashboard/render.ts +106 -5
- package/packages/core/src/cli/dashboard/transcript.ts +2 -1
- package/packages/core/src/cli/dispatch-frontend.ts +11 -0
- package/packages/core/src/cli/dispatch-repository-feed.ts +2 -1
- package/packages/core/src/cli/dispatch.ts +49 -14
- package/packages/core/src/cli/help.ts +17 -1
- package/packages/core/src/cli/main.ts +48 -8
- package/packages/core/src/cli/publication-settlement.ts +49 -5
- package/packages/core/src/cli/repository-status.ts +103 -2
- package/packages/core/src/cli/status.ts +24 -1
- package/packages/core/src/cli/terminals.ts +94 -93
- package/packages/core/src/cli/ticket.ts +35 -11
- package/packages/core/src/cli/wait.ts +11 -2
- package/packages/core/src/cli/watch.ts +12 -0
- package/packages/core/src/config/schema.ts +3 -0
- package/packages/core/src/events/catalog.ts +38 -0
- package/packages/core/src/events/compatibility.ts +183 -0
- package/packages/core/src/events/native-session.ts +13 -0
- package/packages/core/src/events/payloads.ts +150 -2
- package/packages/core/src/events/policy.ts +210 -0
- package/packages/core/src/events/repository.ts +69 -0
- package/packages/core/src/integration/harness.ts +4 -4
- package/packages/core/src/kernel/__snapshots__/{reducer-registry.test.ts.snap → reducer-accumulator-shapes.json} +4286 -4006
- package/packages/core/src/kernel/change-presence.ts +11 -3
- package/packages/core/src/kernel/dispatch-capacity.ts +127 -0
- package/packages/core/src/kernel/dispatcher-liveness.ts +5 -1
- package/packages/core/src/kernel/engine.ts +25 -5
- package/packages/core/src/kernel/forge-health.ts +19 -0
- package/packages/core/src/kernel/generators/build-log.ts +18 -0
- package/packages/core/src/kernel/generators/node-restack-log.ts +1 -1
- package/packages/core/src/kernel/generators/repository-journals.ts +10 -0
- package/packages/core/src/kernel/guarded-forge.ts +159 -0
- package/packages/core/src/kernel/incremental.ts +4 -2
- package/packages/core/src/kernel/integration-completeness.ts +108 -9
- package/packages/core/src/kernel/integration-landing.ts +5 -4
- package/packages/core/src/kernel/janitor-failure.ts +36 -0
- package/packages/core/src/kernel/landing-publication.ts +35 -15
- package/packages/core/src/kernel/landing-state.ts +7 -0
- package/packages/core/src/kernel/leaf-restack-state.ts +1 -1
- package/packages/core/src/kernel/log-index.ts +12 -1
- package/packages/core/src/kernel/mixed-version.ts +52 -0
- package/packages/core/src/kernel/node-landing.ts +14 -11
- package/packages/core/src/kernel/node-parent.ts +35 -10
- package/packages/core/src/kernel/node-restack-demand.ts +29 -0
- package/packages/core/src/kernel/node-restack-state.ts +46 -16
- package/packages/core/src/kernel/node-restack-transaction.ts +151 -8
- package/packages/core/src/kernel/node-restack.ts +34 -10
- package/packages/core/src/kernel/publication.ts +22 -0
- package/packages/core/src/kernel/read-deferrals.ts +111 -0
- package/packages/core/src/kernel/read-facts.ts +34 -6
- package/packages/core/src/kernel/reconcile-restack.ts +23 -2
- package/packages/core/src/kernel/reducer-registry.ts +18 -2
- package/packages/core/src/kernel/reducer.ts +196 -10
- package/packages/core/src/kernel/repository-attention.ts +38 -1
- package/packages/core/src/kernel/terminal-guard.ts +11 -4
- package/packages/core/src/kernel/ticket-migrations.ts +139 -0
- package/packages/core/src/operator/annotations.ts +6 -0
- package/packages/core/src/operator/index.ts +2 -0
- package/packages/core/src/operator/presentation.ts +5 -0
- package/packages/core/src/operator/query.ts +51 -11
- package/packages/core/src/operator/registry.ts +17 -1
- package/packages/core/src/operator/restack.ts +51 -0
- package/packages/core/src/operator/tickets.ts +30 -26
- package/packages/core/src/plugin-sdk/index.ts +10 -0
- package/packages/core/src/plugins/manifest.ts +1 -1
- package/packages/core/src/ports/forge/contract.ts +23 -0
- package/packages/core/src/ports/forge/fake.ts +6 -2
- package/packages/core/src/ports/forge/git-rewrite.ts +92 -64
- package/packages/core/src/ports/forge/github-transport.ts +45 -2
- package/packages/core/src/ports/forge/github.ts +56 -17
- package/packages/core/src/ports/forge/local-git.ts +7 -2
- package/packages/core/src/ports/forge-failure.ts +40 -0
- package/packages/core/src/ports/forge-request-context.ts +35 -0
- package/packages/core/src/ports/forge-telemetry.ts +16 -0
- package/packages/core/src/ports/runner/claude.ts +136 -9
- package/packages/core/src/ports/runner/codex.ts +112 -7
- package/packages/core/src/ports/runner/contract.ts +78 -0
- package/packages/core/src/ports/runner/fake.ts +59 -1
- package/packages/core/src/ports/runner/native-cli-fixture.ts +86 -0
- package/packages/core/src/ports/runner/native-process-fixture.ts +38 -0
- package/packages/core/src/ports/runner/native-session.ts +110 -0
- package/packages/core/src/ports/runner/pi-rpc.ts +7 -1
- package/packages/core/src/ports/runner/pi.ts +162 -2
- package/packages/core/src/ports/tickets/linear.ts +180 -12
- package/packages/core/src/ports/tickets/migration.ts +92 -9
- package/packages/core/src/ports/types.ts +60 -5
- package/packages/core/src/ports/workspace/git-worktree.ts +45 -51
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +28 -12
- package/packages/core/src/processes/build-child-exit.ts +50 -2
- package/packages/core/src/processes/build-child.ts +15 -7
- package/packages/core/src/processes/build-runner.ts +909 -213
- package/packages/core/src/processes/dispatcher.ts +815 -369
- package/packages/core/src/processes/execution-no-progress.ts +15 -0
- package/packages/core/src/processes/pause-execution-fixture.ts +37 -0
- package/packages/core/src/processes/phase-failure-budget.ts +2 -1
- package/packages/core/src/processes/publication-loss.ts +7 -3
- package/packages/core/src/processes/repo-view.ts +53 -6
- package/packages/core/src/processes/tick-publication.ts +6 -2
- package/packages/core/src/runtime-identity.ts +37 -0
- package/packages/core/src/store/adapter.ts +4 -2
- package/packages/core/src/store/build-scope.ts +9 -0
- package/packages/core/src/store/contract.ts +233 -16
- package/packages/core/src/store/digest.ts +20 -2
- package/packages/core/src/store/local/schema.ts +6 -0
- package/packages/core/src/store/local/store.ts +57 -4
- package/packages/core/src/store/memory.ts +83 -2
- package/packages/core/src/store/new-build.ts +2 -2
- package/packages/core/src/store/phase-session.ts +13 -0
- package/packages/core/src/store/reduced-reads.ts +43 -4
- package/packages/core/src/store/reducer-value-shapes.json +8911 -6344
- package/packages/core/src/store/reducer-value-validation.ts +103 -3
- package/packages/core/src/store/reducer-values.ts +21 -6
- package/packages/core/src/store/remote/client.ts +145 -20
- package/packages/core/src/store/remote/index.ts +2 -0
- package/packages/core/src/store/remote/protocol.ts +19 -0
- package/packages/core/src/store/remote/version.ts +2 -0
- package/packages/core/src/store/repo-state-events.ts +5 -2
- package/packages/core/src/store/repo-tick.ts +6 -1
- package/packages/core/src/store/session-handle.ts +8 -0
- package/packages/core/src/store/snapshots.ts +21 -5
- package/packages/core/src/store/types.ts +17 -1
- package/packages/core/src/testing/dispatch-read-budget.ts +18 -2
- package/packages/core/src/testing/index.ts +7 -0
- package/packages/core/src/testing/newer-writer.ts +37 -0
- package/packages/core/src/testing/reduced-read-budget.ts +3 -0
- package/skills/guide/SKILL.md +140 -25
- package/skills/guide/references/integration-tree.md +83 -4
- package/skills/guide/references/landing-policy.md +11 -0
- package/skills/guide/references/migration-1.0.md +9 -0
- package/skills/guide/references/operator-api.md +18 -0
- package/skills/guide/references/plugin-authoring.md +47 -4
- package/skills/guide/references/remote-store-protocol.md +16 -0
- package/skills/guide/references/remote-ticket-protocol.md +5 -0
- package/skills/guide/references/restacking.md +42 -7
- package/skills/guide/references/setup.md +25 -0
- package/skills/guide/references/spec-standard.md +71 -0
- package/skills/guide/references/ticket-dependencies.md +6 -45
- package/skills/guide/references/ticket-migration.md +50 -4
- package/skills/implement/SKILL.md +4 -2
- package/skills/operate/SKILL.md +63 -6
- package/skills/reconcile/SKILL.md +3 -1
- package/skills/spec/SKILL.md +62 -40
- package/skills/tickets/SKILL.md +15 -43
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { Config } from '../../config/schema'
|
|
2
|
+
import type { BuildRecord } from '../../store/types'
|
|
3
|
+
import type { BuildState } from '../../kernel/reducer'
|
|
4
|
+
import type { LeafRestackState } from '../../kernel/leaf-restack-state'
|
|
5
|
+
import {
|
|
6
|
+
integrationComplete,
|
|
7
|
+
integrationCurrent,
|
|
8
|
+
integrationCycleVerified,
|
|
9
|
+
} from '../../kernel/integration-state'
|
|
10
|
+
import { landingReady } from '../../kernel/landing-readiness'
|
|
11
|
+
import { projectIntegrationRow } from './integration-row'
|
|
12
|
+
import { nodeLandingPolicyDisplay, nodeLandingRuleDisplay } from './landing-display'
|
|
13
|
+
|
|
14
|
+
export interface IntegrationChild {
|
|
15
|
+
source: string
|
|
16
|
+
id: string
|
|
17
|
+
title: string
|
|
18
|
+
builds?: string[]
|
|
19
|
+
claims?: string[]
|
|
20
|
+
state: string
|
|
21
|
+
landed: boolean
|
|
22
|
+
}
|
|
23
|
+
export interface IntegrationDetail {
|
|
24
|
+
parentDistance?: string
|
|
25
|
+
destination: string
|
|
26
|
+
branch: string
|
|
27
|
+
restack: string
|
|
28
|
+
conflictFiles?: string[]
|
|
29
|
+
children: IntegrationChild[]
|
|
30
|
+
membershipKnown: boolean
|
|
31
|
+
diagnostics: string[]
|
|
32
|
+
verification: string
|
|
33
|
+
verifySteps: { step: string; outcome: string }[]
|
|
34
|
+
landing: string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function projectIntegrationDetail(
|
|
38
|
+
record: BuildRecord,
|
|
39
|
+
state: BuildState,
|
|
40
|
+
restack: LeafRestackState,
|
|
41
|
+
config: Config,
|
|
42
|
+
pipeline: Config,
|
|
43
|
+
): IntegrationDetail | undefined {
|
|
44
|
+
const row = projectIntegrationRow(record, state, restack, config)
|
|
45
|
+
if (!row) return undefined
|
|
46
|
+
const observation = state.integration?.observation
|
|
47
|
+
const membershipSource = observation?.membershipSource ?? record.ticket?.source
|
|
48
|
+
const open = new Set(observation?.openChildren ?? [])
|
|
49
|
+
const contributions = new Set(observation?.contributions ?? [])
|
|
50
|
+
const children: IntegrationChild[] = (observation?.children ?? [])
|
|
51
|
+
.filter(
|
|
52
|
+
(c) =>
|
|
53
|
+
observation!.diagnostics.length ||
|
|
54
|
+
(c.source === membershipSource && open.has(c.id)) ||
|
|
55
|
+
c.builds?.some((b) => contributions.has(b)),
|
|
56
|
+
)
|
|
57
|
+
.map((c) => ({
|
|
58
|
+
...c,
|
|
59
|
+
title: c.title ?? 'title unavailable',
|
|
60
|
+
landed:
|
|
61
|
+
!!c.builds?.some((b) => contributions.has(b)) &&
|
|
62
|
+
!(c.source === membershipSource && open.has(c.id)),
|
|
63
|
+
state:
|
|
64
|
+
c.builds?.some((b) => contributions.has(b)) &&
|
|
65
|
+
!(c.source === membershipSource && open.has(c.id))
|
|
66
|
+
? 'landed'
|
|
67
|
+
: 'queued',
|
|
68
|
+
}))
|
|
69
|
+
for (const id of open)
|
|
70
|
+
if (!children.some((c) => c.id === id && c.source === membershipSource))
|
|
71
|
+
children.push({
|
|
72
|
+
source: membershipSource ?? '',
|
|
73
|
+
id,
|
|
74
|
+
title: 'title unavailable',
|
|
75
|
+
state: 'queued',
|
|
76
|
+
landed: false,
|
|
77
|
+
})
|
|
78
|
+
for (const contribution of contributions)
|
|
79
|
+
if (!children.some((c) => c.builds?.includes(contribution)))
|
|
80
|
+
children.push({
|
|
81
|
+
source: membershipSource ?? '',
|
|
82
|
+
id: contribution,
|
|
83
|
+
builds: [contribution],
|
|
84
|
+
title: 'title unavailable',
|
|
85
|
+
state: 'landed',
|
|
86
|
+
landed: true,
|
|
87
|
+
})
|
|
88
|
+
children.sort(
|
|
89
|
+
(a, b) =>
|
|
90
|
+
Number(a.landed) - Number(b.landed) ||
|
|
91
|
+
a.source.localeCompare(b.source) ||
|
|
92
|
+
a.id.localeCompare(b.id),
|
|
93
|
+
)
|
|
94
|
+
const cycle = state.integration?.cycle
|
|
95
|
+
const current = integrationCurrent(state)
|
|
96
|
+
const expected: string[] = cycle ? JSON.parse(cycle.config).verify.steps : pipeline.verify.steps
|
|
97
|
+
const results =
|
|
98
|
+
current && cycle
|
|
99
|
+
? state.verify.results.filter(
|
|
100
|
+
(r) =>
|
|
101
|
+
r.seq > cycle.seq &&
|
|
102
|
+
r.restackId === cycle.id &&
|
|
103
|
+
r.headSha === cycle.head &&
|
|
104
|
+
r.baseSha === cycle.parent,
|
|
105
|
+
)
|
|
106
|
+
: []
|
|
107
|
+
const verifySteps = [...new Set(expected)].map((step) => ({
|
|
108
|
+
step,
|
|
109
|
+
outcome:
|
|
110
|
+
results.find((r) => r.step === step && r.outcome === 'fail')?.outcome ??
|
|
111
|
+
results.findLast((r) => r.step === step)?.outcome ??
|
|
112
|
+
'pending',
|
|
113
|
+
}))
|
|
114
|
+
const failed = verifySteps.find((s) => s.outcome === 'fail')
|
|
115
|
+
const conflict =
|
|
116
|
+
state.nodeRestack?.conflict ??
|
|
117
|
+
(restack.active && restack.replay?.conflicted ? restack.replay : undefined)
|
|
118
|
+
const mode = nodeLandingPolicyDisplay(state, config.landing)
|
|
119
|
+
return {
|
|
120
|
+
parentDistance: row.parentDistance,
|
|
121
|
+
destination: `${row.destination}${state.target ? '' : ' (the configured base branch)'}`,
|
|
122
|
+
branch: record.branch ?? state.nodeOpening?.branch ?? 'unknown branch',
|
|
123
|
+
restack: conflict
|
|
124
|
+
? 'conflicted'
|
|
125
|
+
: state.nodeRestack?.active || restack.active
|
|
126
|
+
? 'active'
|
|
127
|
+
: 'idle',
|
|
128
|
+
...(conflict
|
|
129
|
+
? { conflictFiles: conflict.files ?? ['conflicting filenames were not recorded'] }
|
|
130
|
+
: {}),
|
|
131
|
+
children,
|
|
132
|
+
membershipKnown: !!observation && !observation.diagnostics.length,
|
|
133
|
+
diagnostics: observation?.diagnostics ?? ['child membership unknown'],
|
|
134
|
+
verification: failed
|
|
135
|
+
? `${failed.step} failed — file a repair child targeting ${record.ticket?.id ?? record.slug}`
|
|
136
|
+
: !integrationComplete(state)
|
|
137
|
+
? `pending — runs on the node head against ${row.destination} once every child has landed`
|
|
138
|
+
: current && integrationCycleVerified(state)
|
|
139
|
+
? 'verified on the current node head and destination'
|
|
140
|
+
: 'pending on the current node head and destination',
|
|
141
|
+
verifySteps,
|
|
142
|
+
landing: `${mode} — ${nodeLandingRuleDisplay(state, config.landing)}${landingReady(state, restack) && mode === 'consent' && state.landing?.command?.kind !== 'land' ? ` — press l, or ab land ${record.slug}` : ''}`,
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import type { Config } from '../../config/schema'
|
|
2
|
+
import type { BuildState } from '../../kernel/reducer'
|
|
3
|
+
import type { LeafRestackState } from '../../kernel/leaf-restack-state'
|
|
4
|
+
import {
|
|
5
|
+
integrationComplete,
|
|
6
|
+
integrationCurrent,
|
|
7
|
+
integrationCycleVerified,
|
|
8
|
+
} from '../../kernel/integration-state'
|
|
9
|
+
import { landingReady } from '../../kernel/landing-readiness'
|
|
10
|
+
import type { BuildRecord } from '../../store/types'
|
|
11
|
+
import type { DashboardBuild, PipelineStep } from './model'
|
|
12
|
+
import { nodeLandingPolicyDisplay } from './landing-display'
|
|
13
|
+
|
|
14
|
+
/** Shared list progress and five integration steps. */
|
|
15
|
+
export interface IntegrationRow {
|
|
16
|
+
parentDistance?: string
|
|
17
|
+
destination: string
|
|
18
|
+
children:
|
|
19
|
+
| { known: false }
|
|
20
|
+
| { known: true; landed: number; building: number; queued: number; total: number }
|
|
21
|
+
verified: boolean
|
|
22
|
+
steps: PipelineStep[]
|
|
23
|
+
alert?: { tone: 'red' | 'yellow'; text: string }
|
|
24
|
+
openChildren: string[]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function projectIntegrationRow(
|
|
28
|
+
record: BuildRecord,
|
|
29
|
+
state: BuildState,
|
|
30
|
+
restack: LeafRestackState,
|
|
31
|
+
config: Config,
|
|
32
|
+
): IntegrationRow | undefined {
|
|
33
|
+
if (state.kind !== 'node') return undefined
|
|
34
|
+
const destination = state.target
|
|
35
|
+
? `${state.target.ticket.id} ${state.target.build}`
|
|
36
|
+
: (state.baseBranch ?? 'unknown destination')
|
|
37
|
+
const observation = state.integration?.observation
|
|
38
|
+
const openChildren = [...new Set(observation?.openChildren ?? [])]
|
|
39
|
+
const landed = new Set(observation?.contributions ?? []).size
|
|
40
|
+
const known = !!observation && observation.diagnostics.length === 0
|
|
41
|
+
const complete = integrationComplete(state)
|
|
42
|
+
const current = integrationCurrent(state)
|
|
43
|
+
const verified = current && integrationCycleVerified(state)
|
|
44
|
+
const cycle = state.integration?.cycle
|
|
45
|
+
const selected: string[] = cycle ? JSON.parse(cycle.config).verify.steps : []
|
|
46
|
+
const expected = [...new Set(selected)]
|
|
47
|
+
const receipts =
|
|
48
|
+
current && cycle
|
|
49
|
+
? state.verify.results.filter(
|
|
50
|
+
(r) =>
|
|
51
|
+
r.seq > cycle.seq &&
|
|
52
|
+
r.restackId === cycle.id &&
|
|
53
|
+
r.headSha === cycle.head &&
|
|
54
|
+
r.baseSha === cycle.parent &&
|
|
55
|
+
expected.includes(r.step),
|
|
56
|
+
)
|
|
57
|
+
: []
|
|
58
|
+
const failure = receipts.find((r) => r.outcome === 'fail')
|
|
59
|
+
const passed = new Set(
|
|
60
|
+
receipts.filter((r) => r.outcome === 'pass' || r.outcome === 'skipped').map((r) => r.step),
|
|
61
|
+
).size
|
|
62
|
+
const ready = landingReady(state, restack)
|
|
63
|
+
const mode = nodeLandingPolicyDisplay(state, config.landing)
|
|
64
|
+
const step = (
|
|
65
|
+
label: string,
|
|
66
|
+
done: boolean,
|
|
67
|
+
active: boolean,
|
|
68
|
+
qualifier?: PipelineStep['qualifier'],
|
|
69
|
+
): PipelineStep => ({
|
|
70
|
+
label,
|
|
71
|
+
state: done ? 'done' : active ? 'current' : 'pending',
|
|
72
|
+
...(qualifier ? { qualifier } : {}),
|
|
73
|
+
})
|
|
74
|
+
const conflicted = state.nodeRestack?.conflict || (restack.active && restack.replay?.conflicted)
|
|
75
|
+
const alert: IntegrationRow['alert'] = state.janitor?.attention
|
|
76
|
+
? { tone: 'red', text: `Janitor failing: ${state.janitor.message}` }
|
|
77
|
+
: conflicted
|
|
78
|
+
? {
|
|
79
|
+
tone: 'red',
|
|
80
|
+
text: `restack onto ${destination} conflicted — open the detail view for files`,
|
|
81
|
+
}
|
|
82
|
+
: failure
|
|
83
|
+
? {
|
|
84
|
+
tone: 'red',
|
|
85
|
+
text: `${failure.step} failed — file a repair child targeting ${record.ticket?.id ?? record.slug}`,
|
|
86
|
+
}
|
|
87
|
+
: ready && mode === 'consent' && state.landing?.command?.kind !== 'land'
|
|
88
|
+
? {
|
|
89
|
+
tone: 'yellow',
|
|
90
|
+
text: `ready to land into ${destination} — press l, or ab land ${record.slug}`,
|
|
91
|
+
}
|
|
92
|
+
: undefined
|
|
93
|
+
return {
|
|
94
|
+
destination,
|
|
95
|
+
parentDistance: nodeParentDistance(state),
|
|
96
|
+
openChildren,
|
|
97
|
+
children: known
|
|
98
|
+
? {
|
|
99
|
+
known: true,
|
|
100
|
+
landed,
|
|
101
|
+
building: 0,
|
|
102
|
+
queued: openChildren.length,
|
|
103
|
+
total: landed + openChildren.length,
|
|
104
|
+
}
|
|
105
|
+
: { known: false },
|
|
106
|
+
verified,
|
|
107
|
+
steps: [
|
|
108
|
+
step('spec', state.specRev !== undefined, false),
|
|
109
|
+
step('open', !!state.nodeOpened, !state.nodeOpened),
|
|
110
|
+
step('collect', complete, !!state.nodeOpened && !complete),
|
|
111
|
+
step(
|
|
112
|
+
'verify',
|
|
113
|
+
verified,
|
|
114
|
+
current && !verified,
|
|
115
|
+
failure ? 'failed' : current && !verified ? `${passed}/${expected.length}` : undefined,
|
|
116
|
+
),
|
|
117
|
+
step('land', !!state.integration?.landing, ready, mode),
|
|
118
|
+
],
|
|
119
|
+
...(alert ? { alert } : {}),
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Recomputed from the whole already-read repository, even on an empty parent delta.
|
|
124
|
+
* Never mutate cached rows or snapshots; leaf identity is preserved. */
|
|
125
|
+
export function enrichIntegrationRows(
|
|
126
|
+
rows: readonly DashboardBuild[],
|
|
127
|
+
records: readonly BuildRecord[] = [],
|
|
128
|
+
): DashboardBuild[] {
|
|
129
|
+
return rows.map((row) => {
|
|
130
|
+
const list = row.integrationRow
|
|
131
|
+
const identity = row.collectionIdentity
|
|
132
|
+
if (!list || !identity) return row
|
|
133
|
+
const live = (id: string, source: string, claims?: string[]) =>
|
|
134
|
+
rows
|
|
135
|
+
.filter((child) => {
|
|
136
|
+
const match = child.collectionIdentity
|
|
137
|
+
return (
|
|
138
|
+
match &&
|
|
139
|
+
match.repo === identity.repo &&
|
|
140
|
+
match.targetBuild === row.slug &&
|
|
141
|
+
(claims?.includes(child.slug) ||
|
|
142
|
+
(match.targetSource === identity.source &&
|
|
143
|
+
match.targetId === identity.id &&
|
|
144
|
+
(match.id ? match.source === source && match.id === id : child.slug === id))) &&
|
|
145
|
+
match.status !== 'queued' &&
|
|
146
|
+
match.status !== 'done' &&
|
|
147
|
+
match.status !== 'aborted'
|
|
148
|
+
)
|
|
149
|
+
})
|
|
150
|
+
.sort(
|
|
151
|
+
(a, b) =>
|
|
152
|
+
(b.collectionIdentity?.createdAt ?? '').localeCompare(
|
|
153
|
+
a.collectionIdentity?.createdAt ?? '',
|
|
154
|
+
) || b.slug.localeCompare(a.slug),
|
|
155
|
+
)[0]
|
|
156
|
+
const detail = row.integrationDetail
|
|
157
|
+
const building = list.openChildren.filter((id) => {
|
|
158
|
+
const child = detail?.children.find((entry) => entry.id === id && !entry.landed)
|
|
159
|
+
return live(id, child?.source ?? identity.source ?? '', child?.claims)
|
|
160
|
+
}).length
|
|
161
|
+
const projected = detail?.children.map((child) => {
|
|
162
|
+
const active = child.landed ? undefined : live(child.id, child.source, child.claims)
|
|
163
|
+
const historical = child.builds?.length
|
|
164
|
+
? records.find((r) => r.repo === identity.repo && child.builds?.includes(r.slug))
|
|
165
|
+
: undefined
|
|
166
|
+
return {
|
|
167
|
+
...child,
|
|
168
|
+
id: child.id === historical?.slug ? (historical.ticket?.id ?? child.id) : child.id,
|
|
169
|
+
source:
|
|
170
|
+
child.id === historical?.slug
|
|
171
|
+
? (historical.ticket?.source ?? child.source)
|
|
172
|
+
: child.source,
|
|
173
|
+
title:
|
|
174
|
+
child.title === 'title unavailable'
|
|
175
|
+
? (active?.collectionIdentity?.title ?? historical?.ticket?.title ?? child.title)
|
|
176
|
+
: child.title,
|
|
177
|
+
state: child.landed ? 'landed' : (active?.collectionIdentity?.phase ?? 'queued'),
|
|
178
|
+
}
|
|
179
|
+
})
|
|
180
|
+
// Historical contribution records can resolve several build slugs to the
|
|
181
|
+
// same ticket, including a reopened ticket that is also currently open.
|
|
182
|
+
const byTicket = new Map<string, import('./integration-detail').IntegrationChild>()
|
|
183
|
+
for (const child of projected ?? []) {
|
|
184
|
+
const key = JSON.stringify([child.source, child.id])
|
|
185
|
+
const previous = byTicket.get(key)
|
|
186
|
+
const preferred = previous && !previous.landed ? previous : child
|
|
187
|
+
byTicket.set(
|
|
188
|
+
key,
|
|
189
|
+
previous
|
|
190
|
+
? {
|
|
191
|
+
...preferred,
|
|
192
|
+
title:
|
|
193
|
+
preferred.title === 'title unavailable'
|
|
194
|
+
? previous.title === 'title unavailable'
|
|
195
|
+
? child.title
|
|
196
|
+
: previous.title
|
|
197
|
+
: preferred.title,
|
|
198
|
+
builds: [...new Set([...(previous.builds ?? []), ...(child.builds ?? [])])].sort(),
|
|
199
|
+
}
|
|
200
|
+
: child,
|
|
201
|
+
)
|
|
202
|
+
}
|
|
203
|
+
const children = detail
|
|
204
|
+
? [...byTicket.values()].sort(
|
|
205
|
+
(a, b) =>
|
|
206
|
+
Number(a.landed) - Number(b.landed) ||
|
|
207
|
+
a.source.localeCompare(b.source) ||
|
|
208
|
+
a.id.localeCompare(b.id),
|
|
209
|
+
)
|
|
210
|
+
: undefined
|
|
211
|
+
const changed = children && JSON.stringify(children) !== JSON.stringify(detail?.children)
|
|
212
|
+
if ((!list.children.known || list.children.building === building) && !changed) return row
|
|
213
|
+
return {
|
|
214
|
+
...row,
|
|
215
|
+
integrationRow: list.children.known
|
|
216
|
+
? {
|
|
217
|
+
...list,
|
|
218
|
+
children: { ...list.children, building, queued: list.openChildren.length - building },
|
|
219
|
+
}
|
|
220
|
+
: list,
|
|
221
|
+
...(detail && children ? { integrationDetail: { ...detail, children } } : {}),
|
|
222
|
+
}
|
|
223
|
+
})
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Largest-remainder allocation keeps the track exactly 22 terminal cells. */
|
|
227
|
+
export function integrationBarCells(landed: number, building: number, queued: number): number[] {
|
|
228
|
+
const total = landed + building + queued
|
|
229
|
+
if (!total) return [0, 0, 22]
|
|
230
|
+
const raw = [landed, building, queued].map((n) => (n * 22) / total)
|
|
231
|
+
const cells = raw.map(Math.floor)
|
|
232
|
+
const remaining = 22 - cells.reduce((a, b) => a + b, 0)
|
|
233
|
+
const order = raw
|
|
234
|
+
.map((n, i) => ({ i, remainder: n - cells[i]! }))
|
|
235
|
+
.sort((a, b) => b.remainder - a.remainder || a.i - b.i)
|
|
236
|
+
for (const part of order.slice(0, remaining)) cells[part.i]! += 1
|
|
237
|
+
return cells
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export function nodeParentDistance(state: BuildState): string {
|
|
241
|
+
const node = state.nodeRestack
|
|
242
|
+
const distance = node?.distance
|
|
243
|
+
const count =
|
|
244
|
+
distance &&
|
|
245
|
+
distance.base === node?.contributionBase &&
|
|
246
|
+
distance.branch === state.baseBranch &&
|
|
247
|
+
distance.parent === (node?.observedParent?.sha ?? state.nodeComparison?.parentSha)
|
|
248
|
+
? distance.count
|
|
249
|
+
: null
|
|
250
|
+
return count === null
|
|
251
|
+
? 'parent distance unknown'
|
|
252
|
+
: count === 0
|
|
253
|
+
? 'parent current'
|
|
254
|
+
: `parent ${count} commit${count === 1 ? '' : 's'} ahead`
|
|
255
|
+
}
|
|
@@ -1,6 +1,70 @@
|
|
|
1
|
+
import { evaluateLandingPolicy } from '../../kernel/landing-policy'
|
|
1
2
|
import type { BuildState } from '../../kernel/reducer'
|
|
2
3
|
|
|
3
4
|
export function landingPolicyDisplay(landing: BuildState['landing']): string {
|
|
4
5
|
if (landing?.command?.kind === 'hold') return 'held'
|
|
5
6
|
return landing?.decision?.mode ?? 'policy pending'
|
|
6
7
|
}
|
|
8
|
+
|
|
9
|
+
/** Prospective display only: absent labels are unknown, never an empty set.
|
|
10
|
+
* Follow reachable first matches; repeated excluded labels are unreachable. */
|
|
11
|
+
export function nodeLandingPolicyDisplay(
|
|
12
|
+
state: BuildState,
|
|
13
|
+
rules: readonly import('../../config/schema').LandingRule[],
|
|
14
|
+
): 'held' | 'auto' | 'consent' | 'policy pending' {
|
|
15
|
+
if (state.landing?.command?.kind === 'hold') return 'held'
|
|
16
|
+
if (state.landing?.decision) return state.landing.decision.mode
|
|
17
|
+
const into = state.target
|
|
18
|
+
? { kind: 'node' as const, ticket: state.target.ticket.id }
|
|
19
|
+
: { kind: 'root' as const }
|
|
20
|
+
const input = { from: 'node' as const, into, labels: [] as string[] }
|
|
21
|
+
const excluded = new Set<string>()
|
|
22
|
+
const modes = new Set<string>()
|
|
23
|
+
for (const rule of rules) {
|
|
24
|
+
if (rule.from && rule.from !== 'node') continue
|
|
25
|
+
if (
|
|
26
|
+
rule.into &&
|
|
27
|
+
(rule.into === 'root'
|
|
28
|
+
? into.kind !== 'root'
|
|
29
|
+
: into.kind !== 'node' || (rule.into !== 'node' && rule.into !== into.ticket))
|
|
30
|
+
)
|
|
31
|
+
continue
|
|
32
|
+
if (rule.label) {
|
|
33
|
+
if (excluded.has(rule.label)) continue
|
|
34
|
+
modes.add(evaluateLandingPolicy(rules, { ...input, labels: [rule.label] }).mode)
|
|
35
|
+
excluded.add(rule.label)
|
|
36
|
+
} else {
|
|
37
|
+
modes.add(evaluateLandingPolicy(rules, input).mode)
|
|
38
|
+
return modes.size === 1 ? ([...modes][0] as 'auto' | 'consent') : 'policy pending'
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
modes.add(evaluateLandingPolicy(rules, input).mode)
|
|
42
|
+
return modes.size === 1 ? ([...modes][0] as 'auto' | 'consent') : 'policy pending'
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Explain the durable rule when available; unknown labels must not invent a match. */
|
|
46
|
+
export function nodeLandingRuleDisplay(
|
|
47
|
+
state: BuildState,
|
|
48
|
+
rules: readonly import('../../config/schema').LandingRule[],
|
|
49
|
+
): string {
|
|
50
|
+
const recorded = state.landing?.decision?.rule
|
|
51
|
+
if (recorded) {
|
|
52
|
+
if ('default' in recorded) return 'default rule for integration builds: consent'
|
|
53
|
+
return `rule ${recorded.index + 1}: ${JSON.stringify(recorded.snapshot)}`
|
|
54
|
+
}
|
|
55
|
+
const into = state.target
|
|
56
|
+
? { kind: 'node' as const, ticket: state.target.ticket.id }
|
|
57
|
+
: { kind: 'root' as const }
|
|
58
|
+
const candidates = [
|
|
59
|
+
evaluateLandingPolicy(rules, { from: 'node', into, labels: [] }),
|
|
60
|
+
...rules
|
|
61
|
+
.filter((r) => r.label)
|
|
62
|
+
.map((r) => evaluateLandingPolicy(rules, { from: 'node', into, labels: [r.label!] })),
|
|
63
|
+
]
|
|
64
|
+
const unique = new Map(candidates.map((c) => [JSON.stringify(c.rule), c.rule]))
|
|
65
|
+
if (unique.size !== 1) return 'rule pending ticket labels'
|
|
66
|
+
const rule = [...unique.values()][0]!
|
|
67
|
+
return 'default' in rule
|
|
68
|
+
? 'default rule for integration builds: consent'
|
|
69
|
+
: `rule ${rule.index + 1}: ${JSON.stringify(rule.snapshot)}`
|
|
70
|
+
}
|