@defrex/autobuild 1.11.1 → 1.12.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 +177 -54
- package/docs/answering-blocked-builds.md +10 -2
- package/docs/architecture.md +66 -6
- package/docs/assets/headline-wide.png +0 -0
- package/docs/configuration.md +13 -11
- package/docs/dispatcher.md +1 -1
- package/docs/integration-tree.md +28 -16
- package/docs/operator-api.md +4 -4
- package/docs/operator-surfaces.md +35 -0
- package/docs/optimization-nodes.md +3 -2
- package/docs/tickets.md +1 -1
- package/docs/troubleshooting.md +1 -1
- package/package.json +3 -3
- package/packages/core/src/cli/ambient-errors.ts +17 -0
- package/packages/core/src/cli/bounded-io.ts +174 -0
- package/packages/core/src/cli/dashboard/model.ts +81 -23
- package/packages/core/src/cli/dashboard/poll.ts +20 -31
- package/packages/core/src/cli/dashboard/render.ts +14 -37
- package/packages/core/src/cli/dashboard/row-text.ts +24 -7
- package/packages/core/src/cli/dashboard/tone-ansi.ts +39 -0
- package/packages/core/src/cli/dashboard/vocabulary.ts +161 -20
- package/packages/core/src/cli/dispatch-handoff.ts +41 -10
- package/packages/core/src/cli/dispatch-launch-contract.ts +5 -0
- package/packages/core/src/cli/dispatch-launcher-cadence.ts +80 -0
- package/packages/core/src/cli/dispatch-launcher.ts +9 -10
- package/packages/core/src/cli/dispatch-preflight.ts +12 -3
- package/packages/core/src/cli/dispatch-release-observer.ts +53 -0
- package/packages/core/src/cli/dispatch-runtime-cache.ts +204 -82
- package/packages/core/src/cli/dispatch-runtime-dependencies.ts +250 -43
- package/packages/core/src/cli/dispatch-upgrade-install.ts +36 -16
- package/packages/core/src/cli/dispatch-upgrade-source.ts +8 -2
- package/packages/core/src/cli/dispatch-yield-observer.ts +82 -0
- package/packages/core/src/cli/dispatch.ts +68 -5
- package/packages/core/src/cli/env.ts +2 -15
- package/packages/core/src/cli/help.ts +5 -4
- package/packages/core/src/cli/main.ts +4 -2
- package/packages/core/src/cli/production-store.ts +102 -0
- package/packages/core/src/cli/repo-state.ts +2 -3
- package/packages/core/src/cli/repository-status.ts +28 -22
- package/packages/core/src/cli/sessionless-store.ts +26 -0
- package/packages/core/src/cli/status.ts +169 -40
- package/packages/core/src/cli/store-opening.ts +15 -58
- package/packages/core/src/cli/store-ref.ts +6 -1
- package/packages/core/src/config/schema.ts +1 -1
- package/packages/core/src/distribution-packaging.ts +156 -18
- package/packages/core/src/events/catalog-identity.ts +28 -0
- package/packages/core/src/events/catalog.ts +3 -9
- package/packages/core/src/events/compatibility.ts +2 -30
- package/packages/core/src/events/payloads.ts +11 -0
- package/packages/core/src/events/policy.ts +3 -0
- package/packages/core/src/events/repository.ts +1 -1
- package/packages/core/src/events/sessions.ts +1 -1
- package/packages/core/src/events/validation-error.ts +12 -0
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +9 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/3064e337cc75f8d6.json +310 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/a1e90a969d32a367.json +307 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/da3bc91c49211eab.json +310 -0
- package/packages/core/src/kernel/auto-merge-default.ts +2 -1
- package/packages/core/src/kernel/capacity-build.ts +21 -0
- package/packages/core/src/kernel/discard-in-flight.ts +13 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +354 -147
- package/packages/core/src/kernel/engine.ts +2 -8
- package/packages/core/src/kernel/measurement.ts +24 -0
- package/packages/core/src/kernel/read-facts.ts +8 -370
- package/packages/core/src/kernel/reducer-registry.ts +40 -125
- package/packages/core/src/kernel/reducer-revisions.ts +3 -0
- package/packages/core/src/kernel/reducer-value-entry.ts +98 -0
- package/packages/core/src/kernel/reducer-value-index.ts +75 -0
- package/packages/core/src/kernel/reducer.ts +57 -9
- package/packages/core/src/kernel/reopen-state.ts +10 -0
- package/packages/core/src/kernel/repository-read-facts.ts +375 -0
- package/packages/core/src/kernel/verify-stage-state.ts +145 -3
- package/packages/core/src/operator/presentation.ts +13 -0
- package/packages/core/src/operator/query.ts +40 -39
- package/packages/core/src/operator/registry.ts +3 -3
- package/packages/core/src/ports/workspace/fake.ts +15 -3
- package/packages/core/src/processes/dispatcher.ts +232 -75
- package/packages/core/src/processes/execution-no-progress.ts +1 -0
- package/packages/core/src/store/local/capabilities.ts +115 -0
- package/packages/core/src/store/local/store.ts +86 -56
- package/packages/core/src/store/reduced-reads.ts +9 -1
- package/packages/core/src/store/reducer-value-read.ts +235 -0
- package/packages/core/src/store/reducer-value-shapes.json +1437 -1349
- package/packages/core/src/store/reducer-values.ts +36 -204
- package/packages/core/src/store/remote/released-clients.json +11 -0
- package/packages/core/src/store/remote/released-reducer-values/1.12.0.json +35806 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +18 -16
- package/packages/core/src/store/rollup-lease.ts +41 -0
- package/packages/core/src/store/rollups.ts +7 -38
- package/packages/core/src/store/snapshots.ts +1 -1
- package/packages/core/src/testing/dispatch-read-budget.ts +265 -4
- package/packages/core/src/testing/import-graph.ts +78 -0
- package/packages/core/src/testing/reduced-read-budget.ts +221 -22
- package/packages/core/src/testing/slot-agreement.ts +52 -0
- package/packages/core/src/web/assets/app.js +5 -5
- package/skills/guide/SKILL.md +115 -44
- package/skills/guide/references/integration-tree.md +28 -16
- package/skills/guide/references/operator-api.md +4 -4
- package/skills/guide/references/optimization-nodes.md +3 -2
- package/skills/operate/SKILL.md +38 -20
- package/templates/hosted-service/package.json +2 -2
|
@@ -2152,7 +2152,6 @@ async function measureProposerStages(
|
|
|
2152
2152
|
admitProposers(
|
|
2153
2153
|
builds: unknown[],
|
|
2154
2154
|
now: Date,
|
|
2155
|
-
admitted: number,
|
|
2156
2155
|
report: unknown,
|
|
2157
2156
|
launched: Set<string>,
|
|
2158
2157
|
opts: object,
|
|
@@ -2168,7 +2167,7 @@ async function measureProposerStages(
|
|
|
2168
2167
|
await stages.advanceOptimizationNodes(report, {}, entries, now)
|
|
2169
2168
|
await stages.optimizationCreationHolds()
|
|
2170
2169
|
await stages.releaseStrandedNodeWorkspaces(builds, now, new Set(), report, {})
|
|
2171
|
-
await stages.admitProposers(builds, now,
|
|
2170
|
+
await stages.admitProposers(builds, now, report, new Set(), {})
|
|
2172
2171
|
})
|
|
2173
2172
|
}
|
|
2174
2173
|
|
|
@@ -2887,6 +2886,10 @@ export async function nodePollingReadBudget(opts: {
|
|
|
2887
2886
|
* so the every-tick admission stage is measured on its waiting path. Its
|
|
2888
2887
|
* own reads are excluded from the measurement. */
|
|
2889
2888
|
slotWaiting?: () => Promise<boolean>
|
|
2889
|
+
/** Proves an admitted node keeps holding its slot after each measured tick
|
|
2890
|
+
* with no further admission: `admissions()` counts its `slot.admitted`
|
|
2891
|
+
* facts, `held()` reports `nodeHoldsSlot`. Their own reads are excluded. */
|
|
2892
|
+
slotHeld?: { admissions(): Promise<number>; held(): Promise<boolean> }
|
|
2890
2893
|
/** An optimization node with one in-flight attempt build (#1069): proves
|
|
2891
2894
|
* its active-hours activity pass. Each change is appended on the attempt
|
|
2892
2895
|
* build; `pad` appends unrelated events there. */
|
|
@@ -2950,6 +2953,7 @@ export async function nodePollingReadBudget(opts: {
|
|
|
2950
2953
|
return selected
|
|
2951
2954
|
}
|
|
2952
2955
|
const costs: number[] = []
|
|
2956
|
+
const admitted = opts.slotHeld ? await opts.slotHeld.admissions() : 0
|
|
2953
2957
|
let calls = 0
|
|
2954
2958
|
const getReduced = store.getReducerValue.bind(store)
|
|
2955
2959
|
store.getReducerValue = async (...args) => {
|
|
@@ -2967,6 +2971,10 @@ export async function nodePollingReadBudget(opts: {
|
|
|
2967
2971
|
if (elapsed === 10_000) expect(rows).toBe(0)
|
|
2968
2972
|
costs.push(rows, calls)
|
|
2969
2973
|
if (opts.slotWaiting) expect(await opts.slotWaiting()).toBe(true)
|
|
2974
|
+
if (opts.slotHeld) {
|
|
2975
|
+
expect(await opts.slotHeld.held()).toBe(true)
|
|
2976
|
+
expect(await opts.slotHeld.admissions()).toBe(admitted)
|
|
2977
|
+
}
|
|
2970
2978
|
history = 0
|
|
2971
2979
|
}
|
|
2972
2980
|
} finally {
|
|
@@ -4263,8 +4271,9 @@ export async function urgentIntakeReadBudget() {
|
|
|
4263
4271
|
* on a full repository cost each idle tick zero historical rows, no append and
|
|
4264
4272
|
* no ready listing inside the scan interval, at 100 and 100,000 events. Once
|
|
4265
4273
|
* `free` opens one slot for the normal build, its first deferral forces one
|
|
4266
|
-
* listing
|
|
4267
|
-
*
|
|
4274
|
+
* listing and admits it with exactly one `slot.admitted` fact; while its
|
|
4275
|
+
* launch keeps being refused, idle ticks retry it holding its slot, append
|
|
4276
|
+
* nothing, force no further listing and read no history. */
|
|
4268
4277
|
export async function slotAdmissionReadBudget(opts: {
|
|
4269
4278
|
store: import('../store/memory').MemoryBuildStore
|
|
4270
4279
|
/** The normal parked build; filler events extend its log. */
|
|
@@ -4290,7 +4299,15 @@ export async function slotAdmissionReadBudget(opts: {
|
|
|
4290
4299
|
total += repo.events.length
|
|
4291
4300
|
return total
|
|
4292
4301
|
}
|
|
4293
|
-
const
|
|
4302
|
+
const admissions = () => {
|
|
4303
|
+
let total = 0
|
|
4304
|
+
for (const build of (
|
|
4305
|
+
Reflect.get(store, 'builds') as Map<string, { events: { type: string }[] }>
|
|
4306
|
+
).values())
|
|
4307
|
+
total += build.events.filter((event) => event.type === 'slot.admitted').length
|
|
4308
|
+
return total
|
|
4309
|
+
}
|
|
4310
|
+
const idle = async (ticks: number, relaunches = false) => {
|
|
4294
4311
|
const boundary = events.at(-1)!.seq
|
|
4295
4312
|
const metrics = { historicalRows: 0, tailRows: 0 }
|
|
4296
4313
|
const restore = instrumentBuildRows(store, slug, () => boundary, metrics)
|
|
@@ -4305,7 +4322,9 @@ export async function slotAdmissionReadBudget(opts: {
|
|
|
4305
4322
|
}
|
|
4306
4323
|
expect(metrics.historicalRows).toBe(0)
|
|
4307
4324
|
expect(opts.listed() - before.listed).toBe(0)
|
|
4308
|
-
|
|
4325
|
+
// An admitted build holds its slot, so its refused launch is retried
|
|
4326
|
+
// (here with no first-claim grace); a waiter is never launched.
|
|
4327
|
+
expect(opts.launched() - before.launched).toBe(relaunches ? ticks : 0)
|
|
4309
4328
|
expect(appended() - before.appended).toBe(0)
|
|
4310
4329
|
}
|
|
4311
4330
|
let filler = 0
|
|
@@ -4330,10 +4349,81 @@ export async function slotAdmissionReadBudget(opts: {
|
|
|
4330
4349
|
await opts.free()
|
|
4331
4350
|
opts.advance()
|
|
4332
4351
|
const listed = opts.listed()
|
|
4352
|
+
const admitted = admissions()
|
|
4333
4353
|
await opts.tick()
|
|
4334
|
-
// The first deferral forces one listing and admits the build after it
|
|
4354
|
+
// The first deferral forces one listing and admits the build after it:
|
|
4355
|
+
// admission is one durable `slot.admitted` fact (SPEC §12 "What holds a
|
|
4356
|
+
// slot"), appended once and never per idle tick.
|
|
4335
4357
|
expect(opts.listed() - listed).toBe(1)
|
|
4336
|
-
|
|
4358
|
+
expect(admissions() - admitted).toBe(1)
|
|
4359
|
+
// One tick advances the saved reduced values past that fact; the admitted
|
|
4360
|
+
// build then holds its slot and its refused launch is retried, with no
|
|
4361
|
+
// listing, append or history read.
|
|
4362
|
+
opts.advance()
|
|
4363
|
+
await opts.tick()
|
|
4364
|
+
await idle(3, true)
|
|
4365
|
+
expect(admissions() - admitted).toBe(1)
|
|
4366
|
+
}
|
|
4367
|
+
|
|
4368
|
+
/** A leaf whose question was answered while its runner still worked keeps
|
|
4369
|
+
* the slot it never gave up (SPEC §12 "What holds a slot", #1348): idle ticks
|
|
4370
|
+
* over it, at 100 and 100,000 events, read no historical event rows, append
|
|
4371
|
+
* nothing (no per-tick launch record), force no ready listing, launch nothing,
|
|
4372
|
+
* and leave it held. */
|
|
4373
|
+
export async function runnerRetainedSlotReadBudget(opts: {
|
|
4374
|
+
store: import('../store/memory').MemoryBuildStore
|
|
4375
|
+
/** The retained leaf; filler events extend its log. */
|
|
4376
|
+
slug: string
|
|
4377
|
+
tick: () => Promise<unknown>
|
|
4378
|
+
listed: () => number
|
|
4379
|
+
launched: () => number
|
|
4380
|
+
/** Advance the clock by a small fraction of the scan interval. */
|
|
4381
|
+
advance: () => void
|
|
4382
|
+
/** Advance the clock past the scan interval, so the next scan is due. */
|
|
4383
|
+
advanceDue: () => void
|
|
4384
|
+
held: () => Promise<boolean>
|
|
4385
|
+
}): Promise<void> {
|
|
4386
|
+
const { store, slug } = opts
|
|
4387
|
+
const events = buildEventRows(store, slug)
|
|
4388
|
+
const appended = () => {
|
|
4389
|
+
let total = 0
|
|
4390
|
+
for (const build of (
|
|
4391
|
+
Reflect.get(store, 'builds') as Map<string, { events: unknown[] }>
|
|
4392
|
+
).values())
|
|
4393
|
+
total += build.events.length
|
|
4394
|
+
for (const repo of (Reflect.get(store, 'repos') as Map<string, { events: unknown[] }>).values())
|
|
4395
|
+
total += repo.events.length
|
|
4396
|
+
return total
|
|
4397
|
+
}
|
|
4398
|
+
for (const length of [100, 100_000]) {
|
|
4399
|
+
while (events.length < length)
|
|
4400
|
+
await store.append(slug, {
|
|
4401
|
+
actor: humanActor('budget'),
|
|
4402
|
+
type: 'build.auto-merge-cancelled',
|
|
4403
|
+
payload: {},
|
|
4404
|
+
})
|
|
4405
|
+
opts.advanceDue()
|
|
4406
|
+
await opts.tick()
|
|
4407
|
+
opts.advance()
|
|
4408
|
+
await opts.tick()
|
|
4409
|
+
const boundary = events.at(-1)!.seq
|
|
4410
|
+
const metrics = { historicalRows: 0, tailRows: 0 }
|
|
4411
|
+
const restore = instrumentBuildRows(store, slug, () => boundary, metrics)
|
|
4412
|
+
const before = { listed: opts.listed(), launched: opts.launched(), appended: appended() }
|
|
4413
|
+
try {
|
|
4414
|
+
for (let tick = 0; tick < 3; tick++) {
|
|
4415
|
+
opts.advance()
|
|
4416
|
+
await opts.tick()
|
|
4417
|
+
}
|
|
4418
|
+
} finally {
|
|
4419
|
+
restore()
|
|
4420
|
+
}
|
|
4421
|
+
expect(metrics.historicalRows).toBe(0)
|
|
4422
|
+
expect(opts.listed() - before.listed).toBe(0)
|
|
4423
|
+
expect(opts.launched() - before.launched).toBe(0)
|
|
4424
|
+
expect(appended() - before.appended).toBe(0)
|
|
4425
|
+
expect(await opts.held()).toBe(true)
|
|
4426
|
+
}
|
|
4337
4427
|
}
|
|
4338
4428
|
|
|
4339
4429
|
/** Open-PR backpressure (SPEC §12 Intake order) counts open root PRs over the
|
|
@@ -7092,11 +7182,11 @@ export async function panelProgressReadBudget(): Promise<void> {
|
|
|
7092
7182
|
const shared = { record, state, workspace: true }
|
|
7093
7183
|
const before = requests.vector()
|
|
7094
7184
|
for (let repeat = 0; repeat < 5; repeat++) {
|
|
7095
|
-
expect(slotRequest(
|
|
7185
|
+
expect(slotRequest(shared, now)).toBe('verification')
|
|
7096
7186
|
expect(decideNextFromFacts(state, facts.log, config).kind).toBe('measure-progress')
|
|
7097
7187
|
expect(strandedNodeWorkspace(shared, now)).toBe(false)
|
|
7098
7188
|
state.currentPhase = { phase: 'propose', round: 100, seq: state.lastSeq }
|
|
7099
|
-
expect(slotRequest(
|
|
7189
|
+
expect(slotRequest(shared, now)).toBe('propose')
|
|
7100
7190
|
expect(decideNextFromFacts(state, facts.log, config)).toMatchObject({
|
|
7101
7191
|
kind: 'run-phase',
|
|
7102
7192
|
phase: 'propose',
|
|
@@ -7452,6 +7542,9 @@ export async function ticketStartReadBudget(): Promise<{
|
|
|
7452
7542
|
},
|
|
7453
7543
|
}) as unknown as Source
|
|
7454
7544
|
// Unrelated active builds: legacy aliases and readable ids in mixed case.
|
|
7545
|
+
// Each runs under an attached runner's live lease, so it holds its slot
|
|
7546
|
+
// for the whole budget: a build blocked by a failed dispatch boundary
|
|
7547
|
+
// would hold none (SPEC §12 "What holds a slot").
|
|
7455
7548
|
for (let i = 1; i <= builds; i++) {
|
|
7456
7549
|
const ref = { source: 'hosted', id: i % 2 ? `ticket-${i}` : `ab-${i}` }
|
|
7457
7550
|
await store.createBuild({
|
|
@@ -7465,6 +7558,12 @@ export async function ticketStartReadBudget(): Promise<{
|
|
|
7465
7558
|
payload: { ticket: ref, repo, baseBranch: 'main' },
|
|
7466
7559
|
},
|
|
7467
7560
|
})
|
|
7561
|
+
await store.append(`active-${i}`, {
|
|
7562
|
+
actor: KERNEL,
|
|
7563
|
+
type: 'runner.attached',
|
|
7564
|
+
payload: { instance: `runner-active-${i}`, host: 'budget' },
|
|
7565
|
+
})
|
|
7566
|
+
await store.claimLease(`active-${i}`, `runner-active-${i}`, 365 * 24 * 3_600_000)
|
|
7468
7567
|
}
|
|
7469
7568
|
// Unrelated builds this runtime defers for a newer writer's decisive
|
|
7470
7569
|
// fact, one per five active builds: they hold slots and their deferral
|
|
@@ -7622,10 +7721,9 @@ export async function ticketStartReadBudget(): Promise<{
|
|
|
7622
7721
|
control.fresh()
|
|
7623
7722
|
pending.fresh()
|
|
7624
7723
|
}
|
|
7625
|
-
//
|
|
7626
|
-
//
|
|
7627
|
-
//
|
|
7628
|
-
// the control does not.
|
|
7724
|
+
// Capacity is measured from the facts the tick's own stages read, so
|
|
7725
|
+
// even a fresh process's first waiting tick reads no build the control
|
|
7726
|
+
// does not.
|
|
7629
7727
|
for (let i = 0; i < (fresh ? 1 : 2); i++) {
|
|
7630
7728
|
const base = await control.tick()
|
|
7631
7729
|
const measured = await pending.tick()
|
|
@@ -8179,13 +8277,17 @@ function memoryListingEntryCounter(store: import('../store/memory').MemoryBuildS
|
|
|
8179
8277
|
* held-config capacity — receive the same record and digest entries at 1 and
|
|
8180
8278
|
* 30 settled builds and at 100 and 100,000 events, each through a fresh
|
|
8181
8279
|
* store handle (the stand-in for a fresh process), and read zero event rows
|
|
8182
|
-
* while nothing changes (#1230).
|
|
8183
|
-
|
|
8280
|
+
* while nothing changes (#1230). Every answer reports slot state (#1341).
|
|
8281
|
+
* With `commands`, `ab builds`, `ab build status` and `ab repository status`
|
|
8282
|
+
* JSON also report it with zero event rows; they read checkout files, so only
|
|
8283
|
+
* an integration test passes it. Returns the per-surface entry vectors. */
|
|
8284
|
+
export async function openBuildListingReadBudget(opts: { commands?: boolean } = {}) {
|
|
8184
8285
|
const { MemoryBuildStore } = await import('../store/memory')
|
|
8185
8286
|
const { listOperatorLandings } = await import('../operator/landings')
|
|
8186
8287
|
const { getOperatorAttention } = await import('../operator/attention')
|
|
8187
|
-
const { readRepositoryCapacity } = await import('../cli/repository-status')
|
|
8188
|
-
const
|
|
8288
|
+
const { readRepositoryCapacity, abRepositoryStatus } = await import('../cli/repository-status')
|
|
8289
|
+
const { abBuilds, abBuildStatus } = await import('../cli/status')
|
|
8290
|
+
const repo = '/open-listing-budget'
|
|
8189
8291
|
const now = new Date(1000)
|
|
8190
8292
|
const created = (slug: string) => ({
|
|
8191
8293
|
actor: DISPATCHER,
|
|
@@ -8277,9 +8379,59 @@ export async function openBuildListingReadBudget() {
|
|
|
8277
8379
|
dashboard: (store: BuildStore) => getOperatorDashboard({ store, repo, clock: () => now }),
|
|
8278
8380
|
status: (store: BuildStore) => getRepositoryStatus(store, repo, now),
|
|
8279
8381
|
attention: (store: BuildStore) => getOperatorAttention({ store, repo, now }),
|
|
8382
|
+
get: (store: BuildStore) => getOperatorBuild({ store, repo, slug: 'open-consent', now }),
|
|
8280
8383
|
history: (store: BuildStore) => listOperatorBuilds({ store, repo, scope: 'all', now }),
|
|
8281
8384
|
}
|
|
8282
|
-
|
|
8385
|
+
type Vector = { records: number; digests: number; calls: Record<string, number> }
|
|
8386
|
+
// The CLI status commands over the same store: each prints its JSON once.
|
|
8387
|
+
const exec = async (args: string[]) =>
|
|
8388
|
+
args[1] === 'remote'
|
|
8389
|
+
? { stdout: '', stderr: 'no origin', exitCode: 2 }
|
|
8390
|
+
: { stdout: `${repo}/.git\n${repo}/.git\n${repo}\n`, stderr: '', exitCode: 0 }
|
|
8391
|
+
const cli = async (
|
|
8392
|
+
store: BuildStore,
|
|
8393
|
+
command: (opts: {
|
|
8394
|
+
targetRepo: string
|
|
8395
|
+
env: Record<string, string>
|
|
8396
|
+
exec: typeof exec
|
|
8397
|
+
storeRef: string
|
|
8398
|
+
openStore: () => BuildStore
|
|
8399
|
+
now: () => Date
|
|
8400
|
+
json: true
|
|
8401
|
+
stdout: (line: string) => void
|
|
8402
|
+
}) => Promise<void>,
|
|
8403
|
+
) => {
|
|
8404
|
+
const lines: string[] = []
|
|
8405
|
+
// A handle whose close leaves the shared memory store open.
|
|
8406
|
+
const handle = new Proxy(store, {
|
|
8407
|
+
get(target, property) {
|
|
8408
|
+
if (property === 'close') return async () => {}
|
|
8409
|
+
const value = Reflect.get(target, property)
|
|
8410
|
+
return typeof value === 'function' ? value.bind(target) : value
|
|
8411
|
+
},
|
|
8412
|
+
})
|
|
8413
|
+
await command({
|
|
8414
|
+
targetRepo: repo,
|
|
8415
|
+
env: {},
|
|
8416
|
+
exec,
|
|
8417
|
+
// A named store reads no checkout configuration.
|
|
8418
|
+
storeRef: '/budget',
|
|
8419
|
+
openStore: () => handle,
|
|
8420
|
+
now: () => now,
|
|
8421
|
+
json: true,
|
|
8422
|
+
stdout: (line) => lines.push(line),
|
|
8423
|
+
})
|
|
8424
|
+
return JSON.parse(lines.join('\n'))
|
|
8425
|
+
}
|
|
8426
|
+
const commands = opts.commands
|
|
8427
|
+
? {
|
|
8428
|
+
builds: (store: BuildStore) => cli(store, abBuilds),
|
|
8429
|
+
buildStatus: (store: BuildStore) =>
|
|
8430
|
+
cli(store, (command) => abBuildStatus({ ...command, slug: 'open-consent' })),
|
|
8431
|
+
repositoryStatus: (store: BuildStore) => cli(store, abRepositoryStatus),
|
|
8432
|
+
}
|
|
8433
|
+
: {}
|
|
8434
|
+
let baseline: Record<string, Vector> | undefined
|
|
8283
8435
|
const history = new Map<number, number>()
|
|
8284
8436
|
for (const settled of [1, 30])
|
|
8285
8437
|
for (const padding of [100, 100_000]) {
|
|
@@ -8293,8 +8445,28 @@ export async function openBuildListingReadBudget() {
|
|
|
8293
8445
|
const all = { ...surfaces, capacity, attentionAtHead }
|
|
8294
8446
|
// Warm-up: every once-per-key reduction happens here. The seeded
|
|
8295
8447
|
// surfaces answer real work, so the counted reads are meaningful.
|
|
8296
|
-
for (const run of Object.values(all)) await run(store)
|
|
8448
|
+
for (const run of [...Object.values(all), ...Object.values(commands)]) await run(store)
|
|
8297
8449
|
expect((await surfaces.landings(store)).map((entry) => entry.slug)).toEqual(['open-consent'])
|
|
8450
|
+
// Every answer reports slot state (#1341) from the facts it already read.
|
|
8451
|
+
const held = { state: 'held' } as const
|
|
8452
|
+
const none = { state: 'none' } as const
|
|
8453
|
+
// The consent leaf has not recorded `pipeline.settled`: it still holds.
|
|
8454
|
+
const slots = { 'open-queued': held, 'open-consent': held, 'open-aborted': none }
|
|
8455
|
+
for (const scope of ['active', 'queued'] as const)
|
|
8456
|
+
for (const row of await surfaces[scope](store))
|
|
8457
|
+
expect({ slug: row.slug, slot: row.slot }).toEqual({
|
|
8458
|
+
slug: row.slug,
|
|
8459
|
+
slot: slots[row.slug as keyof typeof slots],
|
|
8460
|
+
})
|
|
8461
|
+
const dashboardRows = (await surfaces.dashboard(store)).model.builds
|
|
8462
|
+
expect(Object.fromEntries(dashboardRows.map((row) => [row.slug, row.slot]))).toEqual(slots)
|
|
8463
|
+
// Repository status projects capacity as the dispatcher does, without
|
|
8464
|
+
// the aborted build in cleanup.
|
|
8465
|
+
const { 'open-aborted': _aborted, ...admitted } = slots
|
|
8466
|
+
expect((await surfaces.status(store)).capacity?.slots).toEqual(admitted)
|
|
8467
|
+
expect((await capacity(store))?.slots).toEqual(admitted)
|
|
8468
|
+
const got = await surfaces.get(store)
|
|
8469
|
+
expect([got.detail.slot, got.dashboardRow?.slot]).toEqual([held, held])
|
|
8298
8470
|
expect(
|
|
8299
8471
|
(await surfaces.dashboard(store)).model.builds.map((build) => build.slug).sort(),
|
|
8300
8472
|
).toEqual(['open-aborted', 'open-consent', 'open-queued'])
|
|
@@ -8305,7 +8477,8 @@ export async function openBuildListingReadBudget() {
|
|
|
8305
8477
|
expect(JSON.stringify(digest)).not.toMatch(/open-aborted|settled-/)
|
|
8306
8478
|
const rows = memoryRepositoryReadCounter(store, repo)
|
|
8307
8479
|
const entries = memoryListingEntryCounter(store)
|
|
8308
|
-
const
|
|
8480
|
+
const calls = memoryStoreRequestCounter(store)
|
|
8481
|
+
const vectors: Record<string, Vector> = {}
|
|
8309
8482
|
try {
|
|
8310
8483
|
for (const [name, run] of Object.entries(all)) {
|
|
8311
8484
|
// A fresh handle shares no store-identity-keyed cache.
|
|
@@ -8317,6 +8490,7 @@ export async function openBuildListingReadBudget() {
|
|
|
8317
8490
|
})
|
|
8318
8491
|
rows.reset()
|
|
8319
8492
|
entries.reset()
|
|
8493
|
+
calls.reset()
|
|
8320
8494
|
await run(fresh)
|
|
8321
8495
|
expect({ name, rows: rows.rows, buildRows: rows.buildRows }).toEqual({
|
|
8322
8496
|
name,
|
|
@@ -8324,9 +8498,34 @@ export async function openBuildListingReadBudget() {
|
|
|
8324
8498
|
buildRows: 0,
|
|
8325
8499
|
})
|
|
8326
8500
|
if (name === 'history') history.set(settled, entries.vector.records)
|
|
8327
|
-
else vectors[name] = entries.vector
|
|
8501
|
+
else vectors[name] = { ...entries.vector, calls: calls.vector() }
|
|
8502
|
+
}
|
|
8503
|
+
// The CLI listing iterates every record (pre-existing), so it stays
|
|
8504
|
+
// out of the flat vectors; it still reads no event row.
|
|
8505
|
+
for (const [name, run] of Object.entries(commands)) {
|
|
8506
|
+
rows.reset()
|
|
8507
|
+
const output = await run(store)
|
|
8508
|
+
expect({ name, rows: rows.rows, buildRows: rows.buildRows }).toEqual({
|
|
8509
|
+
name,
|
|
8510
|
+
rows: 0,
|
|
8511
|
+
buildRows: 0,
|
|
8512
|
+
})
|
|
8513
|
+
const reported =
|
|
8514
|
+
name === 'builds'
|
|
8515
|
+
? Object.fromEntries(
|
|
8516
|
+
(output as { slug: string; slot?: unknown }[]).map((row) => [row.slug, row.slot]),
|
|
8517
|
+
)
|
|
8518
|
+
: name === 'buildStatus'
|
|
8519
|
+
? { 'open-consent': output.slot }
|
|
8520
|
+
: output.capacity.slots
|
|
8521
|
+
expect({ name, reported }).toEqual({
|
|
8522
|
+
name,
|
|
8523
|
+
// `ab builds` lists the active scope: the queued build is under --queued.
|
|
8524
|
+
reported: name === 'repositoryStatus' ? admitted : { 'open-consent': held },
|
|
8525
|
+
})
|
|
8328
8526
|
}
|
|
8329
8527
|
} finally {
|
|
8528
|
+
calls.restore()
|
|
8330
8529
|
entries.restore()
|
|
8331
8530
|
}
|
|
8332
8531
|
if (baseline) expect(vectors).toEqual(baseline)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { expect } from 'bun:test'
|
|
2
|
+
import {
|
|
3
|
+
occupiesCapacity,
|
|
4
|
+
slotState,
|
|
5
|
+
type CapacityBuild,
|
|
6
|
+
type DispatchCapacity,
|
|
7
|
+
} from '../kernel/dispatch-capacity'
|
|
8
|
+
|
|
9
|
+
/** The reported slot state agrees with what admission counts (#1341): every
|
|
10
|
+
* build's `slots` entry is its `slotState`, `held` exactly when it occupies a
|
|
11
|
+
* slot, a `requested` build is a waiter with the same request and priority,
|
|
12
|
+
* every waiter is `requested` or `held`, and with every nonterminal build
|
|
13
|
+
* known, `occupied` equals the `held` entries. Pure; no IO. */
|
|
14
|
+
export function expectSlotAgreement(
|
|
15
|
+
builds: readonly CapacityBuild[],
|
|
16
|
+
now: Date,
|
|
17
|
+
capacity: DispatchCapacity,
|
|
18
|
+
): void {
|
|
19
|
+
const unique = [...new Map(builds.map((build) => [build.record.slug, build])).values()]
|
|
20
|
+
const slots = capacity.slots ?? {}
|
|
21
|
+
const waiters = new Map(
|
|
22
|
+
[...(capacity.waitingNodes ?? []), ...(capacity.waitingBuilds ?? [])].map((waiter) => [
|
|
23
|
+
waiter.slug,
|
|
24
|
+
waiter,
|
|
25
|
+
]),
|
|
26
|
+
)
|
|
27
|
+
for (const build of unique) {
|
|
28
|
+
const slug = build.record.slug
|
|
29
|
+
const expected = slotState(build, now)
|
|
30
|
+
expect({ slug, slot: slots[slug] }).toEqual({ slug, slot: expected })
|
|
31
|
+
if (expected)
|
|
32
|
+
expect({ slug, held: expected.state === 'held' }).toEqual({
|
|
33
|
+
slug,
|
|
34
|
+
held: occupiesCapacity(build, now),
|
|
35
|
+
})
|
|
36
|
+
if (expected?.state === 'requested') {
|
|
37
|
+
const { state: _state, ...request } = expected
|
|
38
|
+
expect({ slug, ...waiters.get(slug) }).toEqual({ slug, ...request })
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// A waiter from an older server's value is unknown, which is never `none`.
|
|
42
|
+
for (const slug of waiters.keys())
|
|
43
|
+
if (slots[slug] !== undefined)
|
|
44
|
+
expect({ slug, waits: slots[slug].state !== 'none' }).toEqual({ slug, waits: true })
|
|
45
|
+
const known = unique.every(
|
|
46
|
+
(build) => build.state.status === 'done' || slots[build.record.slug] !== undefined,
|
|
47
|
+
)
|
|
48
|
+
if (known)
|
|
49
|
+
expect(Object.values(slots).filter((slot) => slot.state === 'held').length).toBe(
|
|
50
|
+
capacity.occupied,
|
|
51
|
+
)
|
|
52
|
+
}
|