@defrex/autobuild 1.12.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/SPEC.md +435 -160
- package/bin/ab-build-runner.ts +8 -0
- package/docs/answering-blocked-builds.md +25 -3
- package/docs/architecture.md +124 -53
- package/docs/cli.md +1 -1
- package/docs/configuration.md +110 -15
- package/docs/dispatcher.md +19 -8
- package/docs/integration-overview.md +1 -1
- package/docs/integration-tree.md +12 -9
- package/docs/merge-policy.md +7 -2
- package/docs/operating.md +5 -3
- package/docs/operator-api.md +46 -23
- package/docs/operator-surfaces.md +7 -6
- package/docs/optimization-nodes.md +7 -6
- package/docs/plugin-authoring.md +46 -18
- package/docs/remote-store-protocol.md +51 -12
- package/docs/remote-ticket-protocol.md +85 -38
- package/docs/restacking.md +48 -3
- package/docs/setup.md +2 -1
- package/docs/ticket-migration.md +2 -2
- package/docs/ticket-sources.md +23 -8
- package/docs/tickets.md +4 -4
- package/docs/troubleshooting.md +17 -2
- package/docs/verification.md +3 -1
- package/package.json +3 -3
- package/packages/core/src/cli/build-control.ts +72 -6
- package/packages/core/src/cli/dashboard/actions.ts +4 -0
- package/packages/core/src/cli/dashboard/integration-row.ts +43 -19
- package/packages/core/src/cli/dashboard/model.ts +14 -8
- package/packages/core/src/cli/dashboard/poll.ts +218 -10
- package/packages/core/src/cli/dashboard/queue.ts +21 -10
- package/packages/core/src/cli/dashboard/row-text.ts +2 -1
- package/packages/core/src/cli/dashboard/vocabulary.ts +5 -1
- package/packages/core/src/cli/dispatch-frontend.ts +2 -1
- package/packages/core/src/cli/dispatch-tickets.ts +33 -12
- package/packages/core/src/cli/dispatch.ts +527 -144
- package/packages/core/src/cli/help.ts +38 -24
- package/packages/core/src/cli/main.ts +7 -5
- package/packages/core/src/cli/publication-settlement.ts +4 -0
- package/packages/core/src/cli/remote-poll.ts +22 -5
- package/packages/core/src/cli/repository-status.ts +19 -9
- package/packages/core/src/cli/status.ts +23 -11
- package/packages/core/src/cli/store-opening.ts +12 -0
- package/packages/core/src/cli/ticket-start.ts +3 -3
- package/packages/core/src/cli/ticket.ts +12 -11
- package/packages/core/src/cli/wait.ts +8 -28
- package/packages/core/src/cli/watch.ts +113 -50
- package/packages/core/src/config/reference-metadata.ts +7 -1
- package/packages/core/src/config/reference.ts +5 -2
- package/packages/core/src/config/schema.ts +51 -16
- package/packages/core/src/events/payloads.ts +74 -14
- package/packages/core/src/events/repository.ts +14 -3
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +27 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/0a10010ee5cf2e47.json +577 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/227701361be6d1e0.json +490 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/76e5043bae7a80ab.json +86 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/87a917802870bbed.json +87 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/9d85616e5b9e24c1.json +500 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/c7c94fbe7f63cf07.json +84 -0
- package/packages/core/src/kernel/clean-restack-policy.ts +40 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +243 -107
- package/packages/core/src/kernel/done-escalations.ts +269 -0
- package/packages/core/src/kernel/engine.ts +28 -9
- package/packages/core/src/kernel/integration-landing.ts +24 -4
- package/packages/core/src/kernel/integration-stack.ts +39 -0
- package/packages/core/src/kernel/janitor-failure.ts +20 -1
- package/packages/core/src/kernel/log-index-value.ts +3 -0
- package/packages/core/src/kernel/log-index.ts +41 -2
- package/packages/core/src/kernel/open-pr-backpressure.ts +3 -3
- package/packages/core/src/kernel/reducer-registry.ts +3 -0
- package/packages/core/src/kernel/reducer-revisions.ts +15 -0
- package/packages/core/src/kernel/reducer.ts +27 -7
- package/packages/core/src/kernel/repository-attention.ts +14 -5
- package/packages/core/src/kernel/ticket-starts.ts +15 -4
- package/packages/core/src/kernel/verify-stages.ts +46 -7
- package/packages/core/src/operator/attention.ts +28 -3
- package/packages/core/src/operator/done-escalations.ts +38 -0
- package/packages/core/src/operator/presentation.ts +1 -1
- package/packages/core/src/operator/protocol.ts +8 -5
- package/packages/core/src/operator/query.ts +33 -19
- package/packages/core/src/operator/registry.ts +17 -13
- package/packages/core/src/operator/ticket-start.ts +8 -7
- package/packages/core/src/operator/tickets.ts +28 -9
- package/packages/core/src/plugin-sdk/index.ts +10 -0
- package/packages/core/src/plugins/manifest.ts +14 -1
- package/packages/core/src/ports/forge/create.ts +8 -0
- package/packages/core/src/ports/forge/github-transport.ts +5 -1
- package/packages/core/src/ports/forge/github.ts +3 -0
- package/packages/core/src/ports/tickets/contract.ts +147 -76
- package/packages/core/src/ports/tickets/create.ts +47 -7
- package/packages/core/src/ports/tickets/fake.ts +8 -4
- package/packages/core/src/ports/tickets/file-codec.ts +4 -3
- package/packages/core/src/ports/tickets/file.ts +7 -3
- package/packages/core/src/ports/tickets/github.ts +1 -0
- package/packages/core/src/ports/tickets/grants.ts +11 -3
- package/packages/core/src/ports/tickets/hosted-index.ts +5 -0
- package/packages/core/src/ports/tickets/linear.ts +28 -9
- package/packages/core/src/ports/tickets/migration.ts +4 -4
- package/packages/core/src/ports/tickets/operations.ts +4 -2
- package/packages/core/src/ports/tickets/priority-labels.ts +213 -0
- package/packages/core/src/ports/tickets/priority.ts +127 -21
- package/packages/core/src/ports/tickets/remote-protocol.ts +10 -0
- package/packages/core/src/ports/tickets/remote.ts +104 -11
- package/packages/core/src/ports/tickets/revision.ts +5 -3
- package/packages/core/src/ports/tickets/search.ts +9 -0
- package/packages/core/src/ports/tickets/tree.ts +8 -6
- package/packages/core/src/ports/types.ts +30 -15
- package/packages/core/src/ports/workspace/build-execution.ts +4 -0
- package/packages/core/src/ports/workspace/builtin-capabilities.ts +4 -0
- package/packages/core/src/ports/workspace/create.ts +16 -3
- package/packages/core/src/ports/workspace/execution-exit-marker.ts +41 -0
- package/packages/core/src/ports/workspace/recovery-step.ts +101 -0
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +510 -145
- package/packages/core/src/processes/build-execution-state.ts +4 -0
- package/packages/core/src/processes/build-runner.ts +14 -1
- package/packages/core/src/processes/dispatcher.ts +544 -212
- package/packages/core/src/processes/execution-settlement.ts +1 -0
- package/packages/core/src/processes/harvest-runner.ts +12 -7
- package/packages/core/src/processes/infrastructure-failure-budget.ts +7 -2
- package/packages/core/src/processes/invocation-budget.ts +176 -0
- package/packages/core/src/processes/publication-loss.ts +38 -3
- package/packages/core/src/processes/workspace-preservation.ts +86 -15
- package/packages/core/src/store/contract.ts +81 -3
- package/packages/core/src/store/event-reads.ts +30 -1
- package/packages/core/src/store/reduced-reads.ts +23 -0
- package/packages/core/src/store/reducer-value-shapes.json +6628 -6469
- package/packages/core/src/store/reducer-value-validation.ts +181 -33
- package/packages/core/src/store/remote/client.ts +169 -29
- package/packages/core/src/store/remote/compatibility.ts +113 -56
- package/packages/core/src/store/remote/credentials.ts +4 -1
- package/packages/core/src/store/remote/protocol.ts +3 -0
- package/packages/core/src/store/remote/released-clients.json +11 -0
- package/packages/core/src/store/remote/released-reducer-values/1.13.0.json +35966 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +18 -16
- package/packages/core/src/store/remote/released-value-policy.ts +144 -0
- package/packages/core/src/store/remote/retry.ts +406 -0
- package/packages/core/src/testing/dispatch-read-budget.ts +144 -10
- package/packages/core/src/testing/index.ts +2 -0
- package/packages/core/src/testing/invocation-budget.ts +42 -0
- package/packages/core/src/testing/reduced-read-budget.ts +381 -18
- package/packages/core/src/testing/released-value-coverage.ts +423 -0
- package/packages/core/src/web/overview-source.ts +19 -6
- package/skills/guide/SKILL.md +138 -67
- package/skills/guide/references/integration-tree.md +12 -9
- package/skills/guide/references/merge-policy.md +7 -2
- package/skills/guide/references/operator-api.md +46 -23
- package/skills/guide/references/optimization-nodes.md +7 -6
- package/skills/guide/references/plugin-authoring.md +46 -18
- package/skills/guide/references/remote-store-protocol.md +51 -12
- package/skills/guide/references/remote-ticket-protocol.md +85 -38
- package/skills/guide/references/restacking.md +48 -3
- package/skills/guide/references/setup.md +2 -1
- package/skills/guide/references/ticket-migration.md +2 -2
- package/skills/operate/SKILL.md +82 -51
- package/skills/plan/SKILL.md +4 -3
- package/skills/spec/SKILL.md +9 -5
- package/skills/tickets/SKILL.md +25 -17
- package/templates/hosted-service/package.json +2 -2
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
/** Populated-value coverage for released reducer contracts (test-only).
|
|
2
|
+
*
|
|
3
|
+
* `populatedSamples` generates, from a finished-value catalog, a sparse set of
|
|
4
|
+
* values that together place every union member at every site, including as a
|
|
5
|
+
* nested array element and record entry. `sweepReleasedValues` puts each sample
|
|
6
|
+
* through the server's released-client adaptation and the release's own reader
|
|
7
|
+
* projection, and reports every failure that the released-value policy does not
|
|
8
|
+
* declare. Not exported from the package barrel. */
|
|
9
|
+
import {
|
|
10
|
+
projectReducerValue,
|
|
11
|
+
projectsOnto,
|
|
12
|
+
type ReducerValueCatalog,
|
|
13
|
+
} from '../store/reducer-value-validation'
|
|
14
|
+
import { projectReleasedValue } from '../store/remote/compatibility'
|
|
15
|
+
import { policyBySite, type ReleasedValuePolicy } from '../store/remote/released-value-policy'
|
|
16
|
+
|
|
17
|
+
const sampleCaches = new WeakMap<ReducerValueCatalog, Map<string, unknown[]>>()
|
|
18
|
+
const IN_PROGRESS: unknown[] = []
|
|
19
|
+
const size = (value: unknown) => (value === undefined ? 0 : JSON.stringify(value).length)
|
|
20
|
+
|
|
21
|
+
/** Memoized sparse packed samples of schema `id`. Every union member reachable
|
|
22
|
+
* from `id` appears in some sample; element 0 (the base) keeps every optional
|
|
23
|
+
* property and gives every array one element. A cycle yields no samples. */
|
|
24
|
+
export function populatedSamples(catalog: ReducerValueCatalog, id: string): unknown[] {
|
|
25
|
+
let cache = sampleCaches.get(catalog)
|
|
26
|
+
if (!cache) {
|
|
27
|
+
cache = new Map()
|
|
28
|
+
sampleCaches.set(catalog, cache)
|
|
29
|
+
}
|
|
30
|
+
const cached = cache.get(id)
|
|
31
|
+
if (cached) return cached
|
|
32
|
+
cache.set(id, IN_PROGRESS)
|
|
33
|
+
const samples = generate(catalog, id)
|
|
34
|
+
cache.set(id, samples)
|
|
35
|
+
return samples
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function generate(catalog: ReducerValueCatalog, id: string): unknown[] {
|
|
39
|
+
const shape = catalog.schemas[id]!
|
|
40
|
+
switch (shape.kind) {
|
|
41
|
+
case 'literal':
|
|
42
|
+
return [shape.value]
|
|
43
|
+
case 'string':
|
|
44
|
+
return ['x']
|
|
45
|
+
case 'number':
|
|
46
|
+
return [1]
|
|
47
|
+
case 'boolean':
|
|
48
|
+
return [true]
|
|
49
|
+
case 'json':
|
|
50
|
+
return [{}]
|
|
51
|
+
case 'undefined':
|
|
52
|
+
return [undefined]
|
|
53
|
+
case 'union': {
|
|
54
|
+
const items = shape.items as string[]
|
|
55
|
+
const defined = items.filter((item) => catalog.schemas[item]!.kind !== 'undefined')
|
|
56
|
+
const samples = defined.flatMap((item) => populatedSamples(catalog, item))
|
|
57
|
+
return defined.length < items.length ? [...samples, undefined] : samples
|
|
58
|
+
}
|
|
59
|
+
case 'array': {
|
|
60
|
+
const items = populatedSamples(catalog, shape.items as string)
|
|
61
|
+
return items.length ? items.map((item) => [item]) : [[]]
|
|
62
|
+
}
|
|
63
|
+
case 'object': {
|
|
64
|
+
const props = Object.entries(shape.props ?? {}).map(([key, prop]) => ({
|
|
65
|
+
key,
|
|
66
|
+
optional: prop.optional,
|
|
67
|
+
samples: populatedSamples(catalog, prop.type),
|
|
68
|
+
}))
|
|
69
|
+
if (shape.index)
|
|
70
|
+
props.push({ key: 'k0', optional: true, samples: populatedSamples(catalog, shape.index) })
|
|
71
|
+
if (props.some((prop) => !prop.optional && !prop.samples.length)) return []
|
|
72
|
+
const smallest = props.map((prop) =>
|
|
73
|
+
prop.samples.reduce<unknown>(
|
|
74
|
+
(best, next) => (size(next) < size(best) ? next : best),
|
|
75
|
+
prop.samples[0],
|
|
76
|
+
),
|
|
77
|
+
)
|
|
78
|
+
const width = Math.max(1, ...props.map((prop) => prop.samples.length))
|
|
79
|
+
const out: unknown[] = []
|
|
80
|
+
for (let i = 0; i < width; i++) {
|
|
81
|
+
const value: Record<string, unknown> = {}
|
|
82
|
+
props.forEach((prop, p) => {
|
|
83
|
+
if (i < prop.samples.length) value[prop.key] = prop.samples[i]
|
|
84
|
+
else if (!prop.optional) value[prop.key] = smallest[p]
|
|
85
|
+
})
|
|
86
|
+
out.push(value)
|
|
87
|
+
}
|
|
88
|
+
return out
|
|
89
|
+
}
|
|
90
|
+
default:
|
|
91
|
+
return []
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
type Segment = { kind: 'prop'; key: string } | { kind: 'index'; at: number }
|
|
96
|
+
function segments(concrete: string): Segment[] {
|
|
97
|
+
if (!concrete.startsWith('$')) throw new Error(`not a diagnostic path: ${concrete}`)
|
|
98
|
+
const out: Segment[] = []
|
|
99
|
+
const pattern = /\.([A-Za-z_$][\w$]*)|\[(\d+)\]|\[("(?:[^"\\]|\\.)*")\]/y
|
|
100
|
+
pattern.lastIndex = 1
|
|
101
|
+
while (pattern.lastIndex < concrete.length) {
|
|
102
|
+
const match = pattern.exec(concrete)
|
|
103
|
+
if (!match) throw new Error(`not a diagnostic path: ${concrete}`)
|
|
104
|
+
if (match[1] !== undefined) out.push({ kind: 'prop', key: match[1] })
|
|
105
|
+
else if (match[2] !== undefined) out.push({ kind: 'index', at: Number(match[2]) })
|
|
106
|
+
else out.push({ kind: 'prop', key: JSON.parse(match[3]!) as string })
|
|
107
|
+
}
|
|
108
|
+
return out
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function expand(catalog: ReducerValueCatalog, ids: Iterable<string>): string[] {
|
|
112
|
+
const out = new Set<string>()
|
|
113
|
+
const visit = (id: string) => {
|
|
114
|
+
const shape = catalog.schemas[id]!
|
|
115
|
+
if (shape.kind === 'union') for (const item of shape.items as string[]) visit(item)
|
|
116
|
+
else out.add(id)
|
|
117
|
+
}
|
|
118
|
+
for (const id of ids) visit(id)
|
|
119
|
+
return [...out]
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Normalize a diagnostic path (`$.a[3].b["k"]`) to the policy site form,
|
|
123
|
+
* using the catalog to tell record keys (`[*]`) from properties (`.prop`). */
|
|
124
|
+
export function siteOf(catalog: ReducerValueCatalog, reducer: string, concrete: string): string {
|
|
125
|
+
let ids = [catalog.roots[reducer]!.value]
|
|
126
|
+
let site = '$'
|
|
127
|
+
for (const segment of segments(concrete)) {
|
|
128
|
+
const members = expand(catalog, ids)
|
|
129
|
+
if (segment.kind === 'index') {
|
|
130
|
+
site += '[]'
|
|
131
|
+
ids = members.flatMap((id) => {
|
|
132
|
+
const shape = catalog.schemas[id]!
|
|
133
|
+
return shape.kind === 'array' ? [shape.items as string] : []
|
|
134
|
+
})
|
|
135
|
+
continue
|
|
136
|
+
}
|
|
137
|
+
const declared = members.flatMap((id) => {
|
|
138
|
+
const prop = catalog.schemas[id]!.props?.[segment.key]
|
|
139
|
+
return prop ? [prop.type] : []
|
|
140
|
+
})
|
|
141
|
+
if (declared.length) {
|
|
142
|
+
site += `.${segment.key}`
|
|
143
|
+
ids = declared
|
|
144
|
+
} else {
|
|
145
|
+
site += '[*]'
|
|
146
|
+
ids = members.flatMap((id) => {
|
|
147
|
+
const index = catalog.schemas[id]!.index
|
|
148
|
+
return index ? [index] : []
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return site
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** A copy of `value` with the subtree at the diagnostic path replaced. */
|
|
156
|
+
export function replaceAt(value: unknown, concrete: string, replacement: unknown): unknown {
|
|
157
|
+
const walk = (input: unknown, rest: Segment[]): unknown => {
|
|
158
|
+
if (!rest.length) return replacement
|
|
159
|
+
const [head, ...tail] = rest
|
|
160
|
+
if (head!.kind === 'index') {
|
|
161
|
+
const array = [...(input as unknown[])]
|
|
162
|
+
array[head!.at] = walk(array[head!.at], tail)
|
|
163
|
+
return array
|
|
164
|
+
}
|
|
165
|
+
const record = { ...(input as Record<string, unknown>) }
|
|
166
|
+
record[head!.key] = walk(record[head!.key], tail)
|
|
167
|
+
return record
|
|
168
|
+
}
|
|
169
|
+
return walk(value, segments(concrete))
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** The declared schema ids at a diagnostic path, narrowing unions on the way
|
|
173
|
+
* by the value actually present so an event slot resolves to its variant. */
|
|
174
|
+
function slotTypes(
|
|
175
|
+
catalog: ReducerValueCatalog,
|
|
176
|
+
reducer: string,
|
|
177
|
+
value: unknown,
|
|
178
|
+
concrete: string,
|
|
179
|
+
): string[] {
|
|
180
|
+
let ids = [catalog.roots[reducer]!.value]
|
|
181
|
+
let at = value
|
|
182
|
+
for (const segment of segments(concrete)) {
|
|
183
|
+
const members = expand(catalog, ids).filter((id) => projectsShape(catalog, id, at))
|
|
184
|
+
if (segment.kind === 'index') {
|
|
185
|
+
ids = members.flatMap((id) => {
|
|
186
|
+
const shape = catalog.schemas[id]!
|
|
187
|
+
return shape.kind === 'array' ? [shape.items as string] : []
|
|
188
|
+
})
|
|
189
|
+
at = (at as unknown[] | undefined)?.[segment.at]
|
|
190
|
+
continue
|
|
191
|
+
}
|
|
192
|
+
ids = members.flatMap((id) => {
|
|
193
|
+
const shape = catalog.schemas[id]!
|
|
194
|
+
const prop = shape.props?.[segment.key]
|
|
195
|
+
return prop ? [prop.type] : shape.index ? [shape.index] : []
|
|
196
|
+
})
|
|
197
|
+
at = (at as Record<string, unknown> | undefined)?.[segment.key]
|
|
198
|
+
}
|
|
199
|
+
return ids
|
|
200
|
+
}
|
|
201
|
+
/** Structural kind agreement, used only to narrow unions while walking. */
|
|
202
|
+
function projectsShape(catalog: ReducerValueCatalog, id: string, value: unknown): boolean {
|
|
203
|
+
const shape = catalog.schemas[id]!
|
|
204
|
+
if (shape.kind === 'array') return Array.isArray(value)
|
|
205
|
+
if (shape.kind !== 'object') return false
|
|
206
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return false
|
|
207
|
+
for (const key of ['type', 't']) {
|
|
208
|
+
const prop = shape.props?.[key]
|
|
209
|
+
const literal = prop && !prop.optional ? catalog.schemas[prop.type] : undefined
|
|
210
|
+
if (literal?.kind === 'literal' && (value as Record<string, unknown>)[key] !== literal.value)
|
|
211
|
+
return false
|
|
212
|
+
}
|
|
213
|
+
return true
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function siteMatcher(site: string): RegExp {
|
|
217
|
+
const [, path] = /^[^:]+:(.*)$/.exec(site)!
|
|
218
|
+
const source = path!.replace(/\$|\.[A-Za-z_$][\w$]*|\[\]|\[\*\]/g, (part) => {
|
|
219
|
+
if (part === '$') return '\\$'
|
|
220
|
+
if (part === '[]') return '\\[\\d+\\]'
|
|
221
|
+
if (part === '[*]') return '(?:\\.[A-Za-z_$][\\w$]*|\\["(?:[^"\\\\]|\\\\.)*"\\])'
|
|
222
|
+
return `\\.${part.slice(1).replace(/\$/g, '\\$')}`
|
|
223
|
+
})
|
|
224
|
+
return new RegExp(`^${source}$`)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export interface ReleasedValueSweep {
|
|
228
|
+
/** Unique `reducer site expected release` lines. */
|
|
229
|
+
failures: string[]
|
|
230
|
+
/** Policy sites that fired (map, omit) or were repaired (refuse). */
|
|
231
|
+
exercised: Set<string>
|
|
232
|
+
/** Samples generated per reducer. */
|
|
233
|
+
samples: Map<string, number>
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export type ReleasedValueCheck =
|
|
237
|
+
| { sample: unknown; served: unknown; repaired: string[] }
|
|
238
|
+
| { failure: string; repaired: string[] }
|
|
239
|
+
|
|
240
|
+
/** Serve one canonical value to a release through `serve` (the server's
|
|
241
|
+
* released-client adaptation) and the release's reader projection. A failure
|
|
242
|
+
* under a declared refuse site is repaired, by replacing that slot with a value
|
|
243
|
+
* the release can represent, and the value is checked again so later sites are
|
|
244
|
+
* not masked. Any other failure is returned as `site expected`. */
|
|
245
|
+
export function releasedValueChecker(input: {
|
|
246
|
+
current: ReducerValueCatalog
|
|
247
|
+
contract: ReducerValueCatalog
|
|
248
|
+
policy: readonly ReleasedValuePolicy[]
|
|
249
|
+
serve: (reducer: string, value: unknown) => unknown
|
|
250
|
+
maxRepairs?: number
|
|
251
|
+
}): (reducer: string, sample: unknown) => ReleasedValueCheck {
|
|
252
|
+
const { current, contract, policy, serve } = input
|
|
253
|
+
const maxRepairs = input.maxRepairs ?? 8
|
|
254
|
+
const bySite = policyBySite(policy)
|
|
255
|
+
const replacements = new Map<string, unknown>()
|
|
256
|
+
const refuses = policy.flatMap((entry) =>
|
|
257
|
+
entry.kind === 'refuse'
|
|
258
|
+
? entry.sites.map((site) => ({ site, pattern: siteMatcher(site) }))
|
|
259
|
+
: [],
|
|
260
|
+
)
|
|
261
|
+
return (reducer, sample) => {
|
|
262
|
+
const own = refuses.filter(({ site }) => site.startsWith(`${reducer}:`))
|
|
263
|
+
const repaired: string[] = []
|
|
264
|
+
for (let repairs = 0; ; repairs++) {
|
|
265
|
+
// The server's own walk names the site it refused: a refused answer
|
|
266
|
+
// goes back unchanged, so the reader's diagnostic can land anywhere.
|
|
267
|
+
// A repaired sample is re-checked with that walk alone, and goes
|
|
268
|
+
// through the real serving path once it no longer fails there.
|
|
269
|
+
let failure = repairs
|
|
270
|
+
? projectReleasedValue(reducer, sample, contract, bySite, current)
|
|
271
|
+
: undefined
|
|
272
|
+
if (!failure || !('path' in failure)) {
|
|
273
|
+
const served = serve(reducer, sample)
|
|
274
|
+
const result = projectReducerValue(reducer, served, contract)
|
|
275
|
+
if (!('path' in result)) return { sample, served, repaired }
|
|
276
|
+
const refused = projectReleasedValue(reducer, sample, contract, bySite, current)
|
|
277
|
+
failure = 'path' in refused ? refused : result
|
|
278
|
+
}
|
|
279
|
+
const concrete = failure.path
|
|
280
|
+
const refuse = refuseFor(concrete, own)
|
|
281
|
+
if (!refuse || repairs >= maxRepairs)
|
|
282
|
+
return {
|
|
283
|
+
failure: `${siteOf(contract, reducer, concrete)} ${failure.expected}${refuse ? ' (repairs exhausted)' : ''}`,
|
|
284
|
+
repaired,
|
|
285
|
+
}
|
|
286
|
+
repaired.push(refuse.site)
|
|
287
|
+
const slots = slotTypes(current, reducer, sample, refuse.concrete)
|
|
288
|
+
const releaseSlots = slotTypes(contract, reducer, sample, refuse.concrete)
|
|
289
|
+
const key = `${slots.join(',')}|${releaseSlots.join(',')}`
|
|
290
|
+
if (!replacements.has(key))
|
|
291
|
+
replacements.set(
|
|
292
|
+
key,
|
|
293
|
+
slots
|
|
294
|
+
.flatMap((id) => populatedSamples(current, id))
|
|
295
|
+
.find((candidate) => releaseSlots.some((id) => projectsOnto(contract, id, candidate))),
|
|
296
|
+
)
|
|
297
|
+
const replacement = replacements.get(key)
|
|
298
|
+
if (replacement === undefined) return { failure: `${refuse.site} irreparable`, repaired }
|
|
299
|
+
sample = replaceAt(sample, refuse.concrete, replacement)
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** Check every populated sample of each reducer against one release contract
|
|
305
|
+
* (see `releasedValueChecker`), and record which policy sites fired. */
|
|
306
|
+
export function sweepReleasedValues(input: {
|
|
307
|
+
current: ReducerValueCatalog
|
|
308
|
+
contract: ReducerValueCatalog
|
|
309
|
+
release: string
|
|
310
|
+
reducers: readonly string[]
|
|
311
|
+
policy: readonly ReleasedValuePolicy[]
|
|
312
|
+
serve: (reducer: string, value: unknown) => unknown
|
|
313
|
+
maxRepairs?: number
|
|
314
|
+
}): ReleasedValueSweep {
|
|
315
|
+
const { current, release, policy } = input
|
|
316
|
+
const check = releasedValueChecker(input)
|
|
317
|
+
const failures = new Set<string>()
|
|
318
|
+
const exercised = new Set<string>()
|
|
319
|
+
const samples = new Map<string, number>()
|
|
320
|
+
const changes = policy.flatMap((entry) =>
|
|
321
|
+
entry.kind === 'refuse'
|
|
322
|
+
? []
|
|
323
|
+
: entry.sites.map((site) => ({ site, entry, pattern: siteMatcher(site) })),
|
|
324
|
+
)
|
|
325
|
+
for (const reducer of input.reducers) {
|
|
326
|
+
const own = changes.filter(({ site }) => site.startsWith(`${reducer}:`))
|
|
327
|
+
const generated = populatedSamples(current, current.roots[reducer]!.value)
|
|
328
|
+
samples.set(reducer, generated.length)
|
|
329
|
+
for (const sample of generated) {
|
|
330
|
+
const result = check(reducer, sample)
|
|
331
|
+
for (const site of result.repaired) exercised.add(site)
|
|
332
|
+
if ('failure' in result) failures.add(`${reducer} ${result.failure} ${release}`)
|
|
333
|
+
else if (own.length) observeChanges(result.sample, result.served, '$', own, exercised)
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return { failures: [...failures].sort(), exercised, samples }
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/** The concrete path of a policy site inside a populated sample: array
|
|
340
|
+
* elements at index 0 and record entries at key `k0`. */
|
|
341
|
+
export function sampleSitePath(site: string): string {
|
|
342
|
+
return site
|
|
343
|
+
.replace(/^[^:]+:/, '')
|
|
344
|
+
.replace(/\[\]/g, '[0]')
|
|
345
|
+
.replace(/\[\*\]/g, '.k0')
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/** The value at a diagnostic path, or undefined where the path is absent. */
|
|
349
|
+
export function valueAt(value: unknown, concrete: string): unknown {
|
|
350
|
+
let at = value
|
|
351
|
+
for (const segment of segments(concrete)) {
|
|
352
|
+
if (at === null || typeof at !== 'object') return undefined
|
|
353
|
+
at =
|
|
354
|
+
segment.kind === 'index'
|
|
355
|
+
? (at as unknown[])[segment.at]
|
|
356
|
+
: (at as Record<string, unknown>)[segment.key]
|
|
357
|
+
}
|
|
358
|
+
return at
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/** The longest declared refuse site that is a prefix of the failing path. */
|
|
362
|
+
function refuseFor(
|
|
363
|
+
concrete: string,
|
|
364
|
+
refuses: readonly { site: string; pattern: RegExp }[],
|
|
365
|
+
): { site: string; concrete: string } | undefined {
|
|
366
|
+
const parts = segments(concrete)
|
|
367
|
+
for (let length = parts.length; length >= 0; length--) {
|
|
368
|
+
const prefix = render(parts.slice(0, length))
|
|
369
|
+
const found = refuses.find(({ pattern }) => pattern.test(prefix))
|
|
370
|
+
if (found) return { site: found.site, concrete: prefix }
|
|
371
|
+
}
|
|
372
|
+
return undefined
|
|
373
|
+
}
|
|
374
|
+
function render(parts: Segment[]): string {
|
|
375
|
+
return (
|
|
376
|
+
'$' +
|
|
377
|
+
parts
|
|
378
|
+
.map((part) =>
|
|
379
|
+
part.kind === 'index'
|
|
380
|
+
? `[${part.at}]`
|
|
381
|
+
: /^[A-Za-z_$][\w$]*$/.test(part.key)
|
|
382
|
+
? `.${part.key}`
|
|
383
|
+
: `[${JSON.stringify(part.key)}]`,
|
|
384
|
+
)
|
|
385
|
+
.join('')
|
|
386
|
+
)
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/** Walk input and served value together, recording map and omit sites that
|
|
390
|
+
* changed a value. */
|
|
391
|
+
function observeChanges(
|
|
392
|
+
input: unknown,
|
|
393
|
+
served: unknown,
|
|
394
|
+
path: string,
|
|
395
|
+
changes: readonly { site: string; entry: ReleasedValuePolicy; pattern: RegExp }[],
|
|
396
|
+
exercised: Set<string>,
|
|
397
|
+
): void {
|
|
398
|
+
if (Array.isArray(input) && Array.isArray(served)) {
|
|
399
|
+
input.forEach((item, i) => {
|
|
400
|
+
const at = `${path}[${i}]`
|
|
401
|
+
if (i < served.length) observeChanges(item, served[i], at, changes, exercised)
|
|
402
|
+
check(at, item, i < served.length ? served[i] : OMITTED)
|
|
403
|
+
})
|
|
404
|
+
return
|
|
405
|
+
}
|
|
406
|
+
if (!input || typeof input !== 'object' || !served || typeof served !== 'object') return
|
|
407
|
+
const out = served as Record<string, unknown>
|
|
408
|
+
for (const [key, value] of Object.entries(input)) {
|
|
409
|
+
const at = /^[A-Za-z_$][\w$]*$/.test(key) ? `${path}.${key}` : `${path}[${JSON.stringify(key)}]`
|
|
410
|
+
if (key in out) observeChanges(value, out[key], at, changes, exercised)
|
|
411
|
+
check(at, value, key in out ? out[key] : OMITTED)
|
|
412
|
+
}
|
|
413
|
+
function check(at: string, before: unknown, after: unknown) {
|
|
414
|
+
if (typeof before !== 'string' || before === after) return
|
|
415
|
+
for (const { site, entry, pattern } of changes) {
|
|
416
|
+
if (!pattern.test(at)) continue
|
|
417
|
+
if (entry.kind === 'map' && entry.map[before] === after) exercised.add(site)
|
|
418
|
+
if (entry.kind === 'omit' && after === OMITTED && entry.values.includes(before))
|
|
419
|
+
exercised.add(site)
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
const OMITTED = Symbol('omitted')
|
|
@@ -14,8 +14,10 @@
|
|
|
14
14
|
* source never saw, created and completed between two polls).
|
|
15
15
|
* - One `getRepoArtifact` per new effective-config ref.
|
|
16
16
|
* - Cold start (first read of a process, a repository reset, a config first
|
|
17
|
-
* appearing): the `buildRoster`
|
|
18
|
-
* live build
|
|
17
|
+
* appearing): the `buildRoster` and `doneEscalations` rollups plus the
|
|
18
|
+
* per-build reads for each live build, each aborted entry among the
|
|
19
|
+
* roster's newest finished builds and each done build with an open
|
|
20
|
+
* escalation.
|
|
19
21
|
*
|
|
20
22
|
* It never lists builds or reads events. A remote store that lacks the roster
|
|
21
23
|
* or the feed fails the read with its typed error; there is no fallback.
|
|
@@ -42,6 +44,7 @@ import type { CapacityBuild } from '../kernel/dispatch-capacity'
|
|
|
42
44
|
import type { BuildState } from '../kernel/reducer'
|
|
43
45
|
import {
|
|
44
46
|
readBuildFacts,
|
|
47
|
+
readDoneEscalations,
|
|
45
48
|
readRepositoryFacts,
|
|
46
49
|
type CurrentBuildFacts,
|
|
47
50
|
type RepositoryReadFacts,
|
|
@@ -177,11 +180,18 @@ export class OverviewFrameSource implements WebFrameSource {
|
|
|
177
180
|
|
|
178
181
|
private async coldStart(reader: OverviewFrameReader, config: LoadedConfig): Promise<BuildsState> {
|
|
179
182
|
const roster = await readRoster(reader, this.repo)
|
|
183
|
+
const escalated = await readDoneEscalations(reader, this.repo)
|
|
180
184
|
// An acknowledged abort stays visible as cleaning until its final
|
|
181
|
-
// completion, so the roster's newest aborted entries are checked too
|
|
185
|
+
// completion, so the roster's newest aborted entries are checked too, and
|
|
186
|
+
// a done build stays visible while an escalation is open.
|
|
182
187
|
const slugs = [
|
|
183
|
-
...
|
|
184
|
-
|
|
188
|
+
...new Set([
|
|
189
|
+
...roster.live.map((entry) => entry.slug),
|
|
190
|
+
...roster.finished
|
|
191
|
+
.filter((entry) => entry.outcome === 'aborted')
|
|
192
|
+
.map((entry) => entry.slug),
|
|
193
|
+
...escalated.builds.map((entry) => entry.slug),
|
|
194
|
+
]),
|
|
185
195
|
]
|
|
186
196
|
const live = new Map<string, LiveBuild>()
|
|
187
197
|
for (const read of await mapBounded(slugs, (slug) => this.readBuild(reader, slug, config)))
|
|
@@ -284,7 +294,10 @@ export class OverviewFrameSource implements WebFrameSource {
|
|
|
284
294
|
status,
|
|
285
295
|
config: config.config,
|
|
286
296
|
repositoryFacts: facts,
|
|
287
|
-
|
|
297
|
+
// A done build with an open escalation holds no slot.
|
|
298
|
+
capacityBuilds: visible
|
|
299
|
+
.filter((build) => build.facts.state.status !== 'done')
|
|
300
|
+
.map((build) => build.capacity),
|
|
288
301
|
states: visible.map((build) => build.facts.state),
|
|
289
302
|
now: this.clock(),
|
|
290
303
|
...(status.triage !== undefined ? { triage: status.triage } : {}),
|