@defrex/autobuild 1.5.0 → 1.7.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 +192 -24
- package/docs/agent-runtimes.md +1 -1
- package/docs/answering-blocked-builds.md +7 -4
- package/docs/architecture.md +100 -32
- package/docs/configuration-overview.md +10 -0
- package/docs/configuration.md +340 -10
- package/docs/dispatcher.md +2 -2
- package/docs/forges.md +1 -0
- package/docs/glossary.md +1 -1
- package/docs/operating.md +1 -1
- package/docs/operator-api.md +33 -10
- package/docs/operator-surfaces.md +6 -3
- package/docs/plugin-authoring.md +48 -6
- package/docs/remote-store-protocol.md +33 -10
- package/docs/restacking.md +16 -7
- package/docs/ticket-sources.md +34 -6
- package/docs/tickets.md +7 -1
- package/docs/troubleshooting.md +1 -1
- package/docs/workspaces.md +1 -1
- package/package.json +3 -3
- package/packages/core/src/cli/attention.ts +3 -0
- package/packages/core/src/cli/binary-direct.ts +1 -0
- package/packages/core/src/cli/dashboard/model.ts +14 -4
- package/packages/core/src/cli/dashboard/poll.ts +14 -0
- package/packages/core/src/cli/dashboard/render.ts +3 -0
- package/packages/core/src/cli/dispatch-frontend.ts +10 -14
- package/packages/core/src/cli/dispatch-preflight.ts +5 -1
- package/packages/core/src/cli/dispatch-repository-feed.ts +145 -109
- package/packages/core/src/cli/dispatch-tickets.ts +47 -0
- package/packages/core/src/cli/dispatch-upgrade-controller.ts +3 -0
- package/packages/core/src/cli/dispatch.ts +377 -101
- package/packages/core/src/cli/help.ts +15 -6
- package/packages/core/src/cli/init-validation.ts +14 -1
- package/packages/core/src/cli/repo-lease.ts +225 -0
- package/packages/core/src/cli/repository-status.ts +40 -3
- package/packages/core/src/cli/status.ts +21 -13
- package/packages/core/src/cli/ticket.ts +22 -4
- package/packages/core/src/cli/wait.ts +4 -1
- package/packages/core/src/cli/watch.ts +17 -4
- package/packages/core/src/config/live.ts +4 -0
- package/packages/core/src/config/profiles.ts +96 -0
- package/packages/core/src/config/ready-assignee.ts +43 -11
- package/packages/core/src/config/roles.ts +33 -10
- package/packages/core/src/config/schema.ts +204 -26
- package/packages/core/src/events/catalog.ts +2 -0
- package/packages/core/src/events/compatibility.ts +3 -1
- package/packages/core/src/events/forge-degradation-policy.ts +16 -2
- package/packages/core/src/events/payloads.ts +23 -0
- package/packages/core/src/events/policy.ts +3 -0
- package/packages/core/src/events/repository.ts +19 -0
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +267 -352
- package/packages/core/src/kernel/build-creation.ts +29 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +134 -30
- package/packages/core/src/kernel/engine.ts +13 -6
- package/packages/core/src/kernel/forge-health.ts +47 -0
- package/packages/core/src/kernel/generators/build-log.ts +9 -0
- package/packages/core/src/kernel/guarded-forge.ts +76 -18
- package/packages/core/src/kernel/incremental-fixtures.ts +1 -0
- package/packages/core/src/kernel/janitor-failure.ts +85 -5
- package/packages/core/src/kernel/leaf-restack-state.ts +4 -2
- package/packages/core/src/kernel/log-index.ts +1 -1
- package/packages/core/src/kernel/node-landing.ts +2 -1
- package/packages/core/src/kernel/node-parent.ts +2 -0
- package/packages/core/src/kernel/read-facts.ts +9 -1
- package/packages/core/src/kernel/reducer-registry.ts +6 -1
- package/packages/core/src/kernel/reducer.ts +75 -4
- package/packages/core/src/kernel/ticket-preparation.ts +15 -8
- package/packages/core/src/operator/protocol.ts +10 -0
- package/packages/core/src/operator/query.ts +16 -13
- package/packages/core/src/operator/registry.ts +25 -5
- package/packages/core/src/operator/sandbox-host.ts +3 -0
- package/packages/core/src/operator/tickets.ts +15 -3
- package/packages/core/src/plugin-sdk/index.ts +4 -0
- package/packages/core/src/ports/forge/create.ts +6 -0
- package/packages/core/src/ports/forge/github-transport.ts +40 -3
- package/packages/core/src/ports/forge/github.ts +12 -1
- package/packages/core/src/ports/forge/workspace-ancestry.ts +60 -0
- package/packages/core/src/ports/forge-failure.ts +31 -2
- package/packages/core/src/ports/runner/routing.ts +66 -5
- package/packages/core/src/ports/tickets/assignees.ts +54 -0
- package/packages/core/src/ports/tickets/contract.ts +164 -4
- package/packages/core/src/ports/tickets/create.ts +35 -7
- package/packages/core/src/ports/tickets/github-fake.ts +18 -2
- package/packages/core/src/ports/tickets/github.ts +247 -29
- package/packages/core/src/ports/tickets/hosted-index.ts +1 -0
- package/packages/core/src/ports/tickets/operations.ts +6 -1
- package/packages/core/src/ports/tickets/tree.ts +12 -2
- package/packages/core/src/ports/tickets/update.ts +6 -2
- package/packages/core/src/ports/types.ts +37 -3
- package/packages/core/src/ports/workspace/commit-preservation.ts +28 -12
- package/packages/core/src/ports/workspace/git-worktree.ts +3 -1
- package/packages/core/src/ports/workspace/harvest-execution.ts +4 -2
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +12 -0
- package/packages/core/src/processes/build-child.ts +28 -7
- package/packages/core/src/processes/build-execution-state.ts +4 -1
- package/packages/core/src/processes/build-runner.ts +17 -2
- package/packages/core/src/processes/dispatcher.ts +329 -59
- package/packages/core/src/processes/execution-no-progress.ts +2 -0
- package/packages/core/src/processes/harvest-child.ts +8 -2
- package/packages/core/src/processes/harvest-execution-state.ts +104 -0
- package/packages/core/src/processes/harvest-runner.ts +251 -17
- package/packages/core/src/processes/repo-view.ts +2 -0
- package/packages/core/src/scenarios/harness.ts +160 -36
- package/packages/core/src/store/reduced-reads.ts +10 -0
- package/packages/core/src/store/reducer-value-shapes.json +3339 -2898
- package/packages/core/src/store/remote/client.ts +21 -8
- package/packages/core/src/store/remote/index.ts +4 -0
- package/packages/core/src/store/remote/protocol.ts +7 -0
- package/packages/core/src/store/remote/released-clients.json +22 -0
- package/packages/core/src/store/remote/released-reducer-values/1.6.0.json +27173 -0
- package/packages/core/src/store/remote/released-reducer-values/1.7.0.json +27366 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +4 -0
- package/packages/core/src/store/repo-state-events.ts +1 -0
- package/packages/core/src/store/types.ts +11 -0
- package/packages/core/src/testing/dispatch-read-budget.ts +84 -58
- package/packages/core/src/testing/index.ts +2 -0
- package/packages/core/src/testing/reduced-read-budget.ts +411 -11
- package/skills/guide/SKILL.md +166 -35
- package/skills/guide/references/operator-api.md +33 -10
- package/skills/guide/references/plugin-authoring.md +48 -6
- package/skills/guide/references/remote-store-protocol.md +33 -10
- package/skills/guide/references/restacking.md +16 -7
- package/skills/operate/SKILL.md +79 -14
- package/skills/tickets/SKILL.md +22 -4
- package/templates/hosted-service/package.json +2 -2
|
@@ -24,6 +24,7 @@ import { gitRewrite } from '../ports/forge/git-rewrite'
|
|
|
24
24
|
* agents never touch the remote, so a journal IS the remote) and
|
|
25
25
|
* FakeTicketSource (§13 — projections flow outward only).
|
|
26
26
|
*/
|
|
27
|
+
import type { afterEach as BunAfterEach, test as BunTest } from 'bun:test'
|
|
27
28
|
import { mkdir, mkdtemp, realpath, rm, writeFile } from 'node:fs/promises'
|
|
28
29
|
import { tmpdir } from 'node:os'
|
|
29
30
|
import { dirname, join } from 'node:path'
|
|
@@ -56,7 +57,7 @@ import type {
|
|
|
56
57
|
TicketSource,
|
|
57
58
|
WorkspaceProvider,
|
|
58
59
|
} from '../ports/types'
|
|
59
|
-
import { GitWorktreeProvider, spawnExec } from '../ports/workspace/git-worktree'
|
|
60
|
+
import { GitWorktreeProvider, spawnExec, type Exec } from '../ports/workspace/git-worktree'
|
|
60
61
|
import { InProcessBuildExecution } from '../ports/workspace/in-process-build-execution'
|
|
61
62
|
import { BuildRunner, LeaseHeldError, SetupFailureError } from '../processes/build-runner'
|
|
62
63
|
import {
|
|
@@ -83,6 +84,17 @@ import { steppingClock } from '../testing/fixed'
|
|
|
83
84
|
// The check command is the harness's control knob (§15.6-A): `test -f
|
|
84
85
|
// ok.marker` fails until an implement round commits the marker file.
|
|
85
86
|
|
|
87
|
+
/** Repository dispatch lease budget for every scenario deriving from
|
|
88
|
+
* CONFIG_TOML. `steppingClock` advances 1 s per read while the lease heartbeat
|
|
89
|
+
* renews on real time, so nothing renews inside a fast scenario: under the
|
|
90
|
+
* 60 s product default a pass (or an in-process child sharing the clock)
|
|
91
|
+
* lapses its own authority after ~60 incidental reads. An hour keeps ordinary
|
|
92
|
+
* passes inside authority; scenarios that test expiry advance the clock past
|
|
93
|
+
* it explicitly (see overlap-lease-fencing). Mirrors the runner leaseTtlMs
|
|
94
|
+
* pinned in makeHarness. */
|
|
95
|
+
export const SCENARIO_DISPATCH_LEASE_SECONDS = 3600
|
|
96
|
+
export const SCENARIO_DISPATCH_LEASE_RENEWAL_SECONDS = 20
|
|
97
|
+
|
|
86
98
|
export const CONFIG_TOML = `
|
|
87
99
|
baseBranch = "main"
|
|
88
100
|
capacity = 2
|
|
@@ -99,6 +111,8 @@ command = "test"
|
|
|
99
111
|
|
|
100
112
|
[policy]
|
|
101
113
|
stallRounds = 3
|
|
114
|
+
dispatchLeaseTimeoutSeconds = ${SCENARIO_DISPATCH_LEASE_SECONDS}
|
|
115
|
+
dispatchLeaseRenewalSeconds = ${SCENARIO_DISPATCH_LEASE_RENEWAL_SECONDS}
|
|
102
116
|
|
|
103
117
|
[roles.default]
|
|
104
118
|
runtime = "scripted"
|
|
@@ -151,8 +165,11 @@ export const GIT_ID = [
|
|
|
151
165
|
'commit.gpgsign=false',
|
|
152
166
|
]
|
|
153
167
|
|
|
154
|
-
export async function git(args: string[], cwd: string): Promise<string> {
|
|
155
|
-
const result = await spawnExec(['git', ...args], {
|
|
168
|
+
export async function git(args: string[], cwd: string, signal?: AbortSignal): Promise<string> {
|
|
169
|
+
const result = await spawnExec(['git', ...args], {
|
|
170
|
+
cwd,
|
|
171
|
+
...(signal === undefined ? {} : { signal }),
|
|
172
|
+
})
|
|
156
173
|
if (result.exitCode !== 0) {
|
|
157
174
|
throw new Error(`git ${args.join(' ')} failed: ${result.stderr}`)
|
|
158
175
|
}
|
|
@@ -176,25 +193,30 @@ export async function writeFileIn(dir: string, rel: string, content: string): Pr
|
|
|
176
193
|
return path
|
|
177
194
|
}
|
|
178
195
|
|
|
179
|
-
async function initOrigin(
|
|
196
|
+
async function initOrigin(
|
|
197
|
+
dir: string,
|
|
198
|
+
configToml: string,
|
|
199
|
+
noRemote = false,
|
|
200
|
+
signal?: AbortSignal,
|
|
201
|
+
): Promise<string> {
|
|
180
202
|
// Reconcile fetches the current base from the conventional `origin` remote
|
|
181
203
|
// at phase startup. Keep that seam real in every integration scenario: the
|
|
182
204
|
// dispatcher works from `dir`, while a separate bare repo is its remote.
|
|
183
205
|
const remote = join(dirname(dir), 'remote.git')
|
|
184
206
|
if (!noRemote) {
|
|
185
207
|
await mkdir(remote, { recursive: true })
|
|
186
|
-
await git(['init', '--bare', '-q', '-b', 'main'], remote)
|
|
208
|
+
await git(['init', '--bare', '-q', '-b', 'main'], remote, signal)
|
|
187
209
|
}
|
|
188
210
|
|
|
189
211
|
await mkdir(dir, { recursive: true })
|
|
190
|
-
await git(['init', '-q', '-b', 'main'], dir)
|
|
191
|
-
if (!noRemote) await git(['remote', 'add', 'origin', remote], dir)
|
|
212
|
+
await git(['init', '-q', '-b', 'main'], dir, signal)
|
|
213
|
+
if (!noRemote) await git(['remote', 'add', 'origin', remote], dir, signal)
|
|
192
214
|
// No `.ab/` ignore here — see commitAll: the product establishes it.
|
|
193
215
|
await writeFile(join(dir, 'autobuild.toml'), configToml)
|
|
194
216
|
await writeFile(join(dir, 'README.md'), 'e2e origin\n')
|
|
195
|
-
await git(['add', '-A'], dir)
|
|
196
|
-
await git([...GIT_ID, 'commit', '-q', '-m', 'initial'], dir)
|
|
197
|
-
if (!noRemote) await git(['push', '-q', '-u', 'origin', 'main'], dir)
|
|
217
|
+
await git(['add', '-A'], dir, signal)
|
|
218
|
+
await git([...GIT_ID, 'commit', '-q', '-m', 'initial'], dir, signal)
|
|
219
|
+
if (!noRemote) await git(['push', '-q', '-u', 'origin', 'main'], dir, signal)
|
|
198
220
|
return remote
|
|
199
221
|
}
|
|
200
222
|
|
|
@@ -294,6 +316,8 @@ export interface E2eHarness {
|
|
|
294
316
|
/** Run the most recently launched BuildRunner to its park point (§11). */
|
|
295
317
|
runLatest(): Promise<BuildState>
|
|
296
318
|
events(slug: string): Promise<AbEvent[]>
|
|
319
|
+
/** Idempotent: every call after the first returns the first call's promise,
|
|
320
|
+
* so a scenario's own `finally` and scenarioScope can both invoke it. */
|
|
297
321
|
cleanup(): Promise<void>
|
|
298
322
|
}
|
|
299
323
|
|
|
@@ -446,17 +470,30 @@ export async function makeHarness(opts: {
|
|
|
446
470
|
/** Execute scripted phase commands through the private `ab` launcher on
|
|
447
471
|
* PATH, forcing production ambient-env parsing and Store reopening. */
|
|
448
472
|
processCli?: boolean
|
|
473
|
+
/** Owned by scenarioScope: aborting kills harness-routed subprocesses and
|
|
474
|
+
* stops harness entry points. */
|
|
475
|
+
signal?: AbortSignal
|
|
449
476
|
}): Promise<E2eHarness> {
|
|
477
|
+
const signal = opts.signal
|
|
478
|
+
const exec: Exec =
|
|
479
|
+
signal === undefined
|
|
480
|
+
? spawnExec
|
|
481
|
+
: (cmd, o) =>
|
|
482
|
+
spawnExec(cmd, {
|
|
483
|
+
...o,
|
|
484
|
+
signal: o.signal === undefined ? signal : AbortSignal.any([o.signal, signal]),
|
|
485
|
+
})
|
|
450
486
|
const tmp = await mkdtemp(join(tmpdir(), 'ab-e2e-'))
|
|
451
487
|
try {
|
|
488
|
+
signal?.throwIfAborted()
|
|
452
489
|
const originPath = join(tmp, 'origin')
|
|
453
490
|
const configToml = opts.configToml ?? CONFIG_TOML
|
|
454
|
-
const remote = await initOrigin(originPath, configToml, opts.localGitForge === true)
|
|
491
|
+
const remote = await initOrigin(originPath, configToml, opts.localGitForge === true, signal)
|
|
455
492
|
// Git canonicalizes temporary paths on macOS (`/var` → `/private/var`).
|
|
456
493
|
// Records and every dispatch caller must use that same repository identity.
|
|
457
494
|
const origin = await realpath(originPath)
|
|
458
495
|
const remoteUpdater = join(tmp, 'remote-updater')
|
|
459
|
-
if (opts.localGitForge !== true) await git(['clone', '-q', remote, remoteUpdater], tmp)
|
|
496
|
+
if (opts.localGitForge !== true) await git(['clone', '-q', remote, remoteUpdater], tmp, signal)
|
|
460
497
|
|
|
461
498
|
const clock = steppingClock()
|
|
462
499
|
const ids = sequentialIds()
|
|
@@ -472,9 +509,9 @@ export async function makeHarness(opts: {
|
|
|
472
509
|
// Ad-hoc scenario configs predating mandatory runtime defaults stay explicit
|
|
473
510
|
// at the harness boundary rather than relying on production wiring.
|
|
474
511
|
config.roles.default ??= { runtime: 'scripted' }
|
|
475
|
-
await git(['config', 'user.name', 'ab-e2e'], origin)
|
|
476
|
-
await git(['config', 'user.email', 'ab-e2e@example.invalid'], origin)
|
|
477
|
-
await git(['config', 'commit.gpgsign', 'false'], origin)
|
|
512
|
+
await git(['config', 'user.name', 'ab-e2e'], origin, signal)
|
|
513
|
+
await git(['config', 'user.email', 'ab-e2e@example.invalid'], origin, signal)
|
|
514
|
+
await git(['config', 'commit.gpgsign', 'false'], origin, signal)
|
|
478
515
|
const forge = new FakeForge({
|
|
479
516
|
gatePresence: opts.gatePresence ?? 'present',
|
|
480
517
|
...(opts.pluginForge?.prAttachments === true ? { prAttachments: true } : {}),
|
|
@@ -482,7 +519,10 @@ export async function makeHarness(opts: {
|
|
|
482
519
|
})
|
|
483
520
|
// This fixture's served bare repository is the authoritative forge, even
|
|
484
521
|
// when FakeForge supplies the scripted PR surface.
|
|
485
|
-
const served = new LocalGitForge({
|
|
522
|
+
const served = new LocalGitForge({
|
|
523
|
+
repoRoot: opts.localGitForge === true ? origin : remote,
|
|
524
|
+
exec,
|
|
525
|
+
})
|
|
486
526
|
const scriptedBranch = forge.remoteBranchSha.bind(forge)
|
|
487
527
|
forge.remoteBranchSha = async (branch) =>
|
|
488
528
|
forge.remoteBranches.has(branch) ? scriptedBranch(branch) : served.remoteBranchSha(branch)
|
|
@@ -490,11 +530,11 @@ export async function makeHarness(opts: {
|
|
|
490
530
|
const recordPush = forge.pushBranch.bind(forge)
|
|
491
531
|
forge.pushBranch = async (cwd, branch, sha) => {
|
|
492
532
|
await recordPush(cwd, branch, sha)
|
|
493
|
-
await git(['push', '-q', 'origin', `HEAD:refs/heads/${branch}`], cwd)
|
|
533
|
+
await git(['push', '-q', 'origin', `HEAD:refs/heads/${branch}`], cwd, signal)
|
|
494
534
|
}
|
|
495
|
-
forge.rewrite = gitRewrite(
|
|
535
|
+
forge.rewrite = gitRewrite(exec, false)
|
|
496
536
|
let selectedForge: Forge =
|
|
497
|
-
opts.localGitForge === true ? new LocalGitForge({ repoRoot: origin }) : forge
|
|
537
|
+
opts.localGitForge === true ? new LocalGitForge({ repoRoot: origin, exec }) : forge
|
|
498
538
|
let plugins: PluginRegistry | undefined
|
|
499
539
|
if (opts.pluginForge !== undefined) {
|
|
500
540
|
plugins = createPluginRegistry()
|
|
@@ -515,7 +555,7 @@ export async function makeHarness(opts: {
|
|
|
515
555
|
const worktreeRoot = join(tmp, 'worktrees')
|
|
516
556
|
const workspaces =
|
|
517
557
|
opts.createWorkspaceProvider === undefined
|
|
518
|
-
? new GitWorktreeProvider({ root: worktreeRoot })
|
|
558
|
+
? new GitWorktreeProvider({ root: worktreeRoot, exec })
|
|
519
559
|
: await opts.createWorkspaceProvider({ config, repoRoot: origin, worktreeRoot })
|
|
520
560
|
|
|
521
561
|
const launched: Array<{ slug: string; runner: BuildRunner; instance: string }> = []
|
|
@@ -571,7 +611,7 @@ export async function makeHarness(opts: {
|
|
|
571
611
|
env,
|
|
572
612
|
workspacePath: ws,
|
|
573
613
|
forge: selectedForge,
|
|
574
|
-
exec
|
|
614
|
+
exec,
|
|
575
615
|
ids,
|
|
576
616
|
clock,
|
|
577
617
|
stdout: (line) => out.push(line),
|
|
@@ -637,7 +677,7 @@ export async function makeHarness(opts: {
|
|
|
637
677
|
store: activeStore.scopeBuild(slug),
|
|
638
678
|
config,
|
|
639
679
|
...(opts.verifyCycleConfig
|
|
640
|
-
? { readVerifyPipeline: () => readVerifyPipeline(workspacePath,
|
|
680
|
+
? { readVerifyPipeline: () => readVerifyPipeline(workspacePath, exec) }
|
|
641
681
|
: {}),
|
|
642
682
|
...(opts.pinnedConfig
|
|
643
683
|
? {
|
|
@@ -662,7 +702,7 @@ export async function makeHarness(opts: {
|
|
|
662
702
|
workspacePath,
|
|
663
703
|
branch: record.branch ?? `ab/${slug}`,
|
|
664
704
|
slug,
|
|
665
|
-
exec
|
|
705
|
+
exec,
|
|
666
706
|
forge: selectedForge,
|
|
667
707
|
ids,
|
|
668
708
|
clock,
|
|
@@ -670,7 +710,8 @@ export async function makeHarness(opts: {
|
|
|
670
710
|
host: 'e2e-host',
|
|
671
711
|
...(sessionEnv !== undefined ? { sessionEnv } : {}),
|
|
672
712
|
// Long lease/heartbeat: liveness is driven by the shared stepping
|
|
673
|
-
// clock; scenarios advance it explicitly to expire a lease.
|
|
713
|
+
// clock; scenarios advance it explicitly to expire a lease. The
|
|
714
|
+
// repository dispatch lease follows SCENARIO_DISPATCH_LEASE_SECONDS.
|
|
674
715
|
opts: {
|
|
675
716
|
heartbeatMs: 3_600_000,
|
|
676
717
|
leaseTtlMs: 3_600_000,
|
|
@@ -700,12 +741,19 @@ export async function makeHarness(opts: {
|
|
|
700
741
|
forge: selectedForge,
|
|
701
742
|
config: opts.dispatcherConfig?.(structuredClone(config)) ?? config,
|
|
702
743
|
repo: origin,
|
|
703
|
-
exec
|
|
744
|
+
exec,
|
|
704
745
|
launchRunner,
|
|
705
746
|
...(opts.getConfig ? { getConfig: opts.getConfig } : {}),
|
|
706
747
|
ids,
|
|
707
748
|
clock,
|
|
708
749
|
})
|
|
750
|
+
if (signal !== undefined) {
|
|
751
|
+
const tick = dispatcher.tick.bind(dispatcher)
|
|
752
|
+
dispatcher.tick = (...args) => {
|
|
753
|
+
signal.throwIfAborted()
|
|
754
|
+
return tick(...args)
|
|
755
|
+
}
|
|
756
|
+
}
|
|
709
757
|
const wiring: DispatchWiring = {
|
|
710
758
|
store: activeStore,
|
|
711
759
|
tickets: ticketSource,
|
|
@@ -744,6 +792,7 @@ export async function makeHarness(opts: {
|
|
|
744
792
|
...(plugins !== undefined ? { plugins } : {}),
|
|
745
793
|
}
|
|
746
794
|
|
|
795
|
+
let cleaned: Promise<void> | undefined
|
|
747
796
|
return {
|
|
748
797
|
tmp,
|
|
749
798
|
origin,
|
|
@@ -765,14 +814,16 @@ export async function makeHarness(opts: {
|
|
|
765
814
|
if (opts.localGitForge === true) {
|
|
766
815
|
throw new Error('advanceRemote is unavailable for a no-remote local-git harness')
|
|
767
816
|
}
|
|
817
|
+
signal?.throwIfAborted()
|
|
768
818
|
for (const [path, content] of Object.entries(changes)) {
|
|
769
819
|
await writeFileIn(remoteUpdater, path, content)
|
|
770
820
|
}
|
|
771
821
|
const sha = await commitAll(remoteUpdater, message)
|
|
772
|
-
await git(['push', '-q', 'origin', 'main'], remoteUpdater)
|
|
822
|
+
await git(['push', '-q', 'origin', 'main'], remoteUpdater, signal)
|
|
773
823
|
return sha
|
|
774
824
|
},
|
|
775
825
|
async runLatest(): Promise<BuildState> {
|
|
826
|
+
signal?.throwIfAborted()
|
|
776
827
|
const entry = launched.at(-1)
|
|
777
828
|
if (entry === undefined) throw new Error('runLatest: nothing launched')
|
|
778
829
|
try {
|
|
@@ -784,16 +835,17 @@ export async function makeHarness(opts: {
|
|
|
784
835
|
}
|
|
785
836
|
},
|
|
786
837
|
events: (slug) => store.getEvents(slug),
|
|
787
|
-
cleanup:
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
838
|
+
cleanup: () =>
|
|
839
|
+
(cleaned ??= (async () => {
|
|
840
|
+
try {
|
|
841
|
+
if (!snapshotsOff) await assertSnapshotEquivalence(store, origin)
|
|
842
|
+
await activeStore.close()
|
|
843
|
+
if (activeStore !== store) await store.close()
|
|
844
|
+
await adapted?.cleanup?.()
|
|
845
|
+
} finally {
|
|
846
|
+
await rm(tmp, { recursive: true, force: true })
|
|
847
|
+
}
|
|
848
|
+
})()),
|
|
797
849
|
}
|
|
798
850
|
} catch (error) {
|
|
799
851
|
await rm(tmp, { recursive: true, force: true })
|
|
@@ -801,6 +853,78 @@ export async function makeHarness(opts: {
|
|
|
801
853
|
}
|
|
802
854
|
}
|
|
803
855
|
|
|
856
|
+
// ── Scenario lifetime scope ──────────────────────────────────────────────────
|
|
857
|
+
|
|
858
|
+
/** A harness maker bound to one scenario's lifetime. */
|
|
859
|
+
export type Make = (opts: Parameters<typeof makeHarness>[0]) => Promise<E2eHarness>
|
|
860
|
+
|
|
861
|
+
/**
|
|
862
|
+
* Own every harness a scenario creates from the moment creation starts. Bun
|
|
863
|
+
* runs `afterEach` after a timed-out test but never the abandoned body's
|
|
864
|
+
* `finally`, so the scope's hook aborts the case's signal (killing
|
|
865
|
+
* harness-routed subprocesses and stopping the next harness entry point),
|
|
866
|
+
* drains the body, and disposes every harness before the next case starts.
|
|
867
|
+
* A timed-out case's late rejection and cleanup errors are swallowed; it is
|
|
868
|
+
* already reported as timed out. A case that settled keeps its own outcome,
|
|
869
|
+
* and its cleanup errors fail the hook.
|
|
870
|
+
*
|
|
871
|
+
* Bun's `test` and `afterEach` are passed in so the harness itself never
|
|
872
|
+
* imports `bun:test`.
|
|
873
|
+
*/
|
|
874
|
+
export function scenarioScope(bun: { test: typeof BunTest; afterEach: typeof BunAfterEach }) {
|
|
875
|
+
interface Case {
|
|
876
|
+
controller: AbortController
|
|
877
|
+
abandoned: boolean
|
|
878
|
+
settled: boolean
|
|
879
|
+
run: Promise<void>
|
|
880
|
+
created: Promise<E2eHarness>[]
|
|
881
|
+
}
|
|
882
|
+
let current: Case | undefined
|
|
883
|
+
bun.afterEach(async () => {
|
|
884
|
+
const c = current
|
|
885
|
+
current = undefined
|
|
886
|
+
if (c === undefined) return
|
|
887
|
+
const timedOut = !c.settled
|
|
888
|
+
// Set before any await: a late rejection from the drained body is swallowed.
|
|
889
|
+
c.abandoned = true
|
|
890
|
+
c.controller.abort(new Error('scenario ended'))
|
|
891
|
+
await c.run.catch(() => {})
|
|
892
|
+
const errors: unknown[] = []
|
|
893
|
+
for (const created of c.created) {
|
|
894
|
+
// A failed creation already removed its own temporary directory.
|
|
895
|
+
const h = await created.catch(() => undefined)
|
|
896
|
+
await h?.cleanup().catch((error: unknown) => errors.push(error))
|
|
897
|
+
}
|
|
898
|
+
if (errors.length > 0 && !timedOut) throw errors[0]
|
|
899
|
+
}, 30_000)
|
|
900
|
+
return (name: string, body: (makeHarness: Make) => Promise<void>, timeout?: number): void =>
|
|
901
|
+
bun.test(
|
|
902
|
+
name,
|
|
903
|
+
() => {
|
|
904
|
+
const c: Case = {
|
|
905
|
+
controller: new AbortController(),
|
|
906
|
+
abandoned: false,
|
|
907
|
+
settled: false,
|
|
908
|
+
run: Promise.resolve(),
|
|
909
|
+
created: [],
|
|
910
|
+
}
|
|
911
|
+
const make: Make = (opts) => {
|
|
912
|
+
const created = makeHarness({ ...opts, signal: c.controller.signal })
|
|
913
|
+
c.created.push(created)
|
|
914
|
+
return created
|
|
915
|
+
}
|
|
916
|
+
current = c
|
|
917
|
+
c.run = body(make).finally(() => {
|
|
918
|
+
c.settled = true
|
|
919
|
+
})
|
|
920
|
+
return c.run.catch((error: unknown) => {
|
|
921
|
+
if (!c.abandoned) throw error
|
|
922
|
+
})
|
|
923
|
+
},
|
|
924
|
+
timeout,
|
|
925
|
+
)
|
|
926
|
+
}
|
|
927
|
+
|
|
804
928
|
// ── Default (§15.6 happy-path) handlers over the REAL CLI ────────────────────
|
|
805
929
|
|
|
806
930
|
/**
|
|
@@ -64,6 +64,16 @@ async function readValue<T>(
|
|
|
64
64
|
return { cursor: result.cursor, value: result.value as T }
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
/** One served constant-size value naming the current hosted harvest
|
|
68
|
+
* authority; no `getRepo` call, no event download. */
|
|
69
|
+
export async function readHostedHarvestAuthority(store: Reader, repo: string) {
|
|
70
|
+
return readValue<
|
|
71
|
+
ReturnType<
|
|
72
|
+
typeof import('../processes/harvest-execution-state').hostedHarvestAuthorityReducer.finish
|
|
73
|
+
>
|
|
74
|
+
>(store, { kind: 'repo', repo }, 'hostedHarvestAuthority')
|
|
75
|
+
}
|
|
76
|
+
|
|
67
77
|
export type RepositoryReadFacts = ReturnType<typeof repositoryReadFactsReducer.finish>
|
|
68
78
|
export async function readRepositoryFacts(
|
|
69
79
|
store: Reader & Pick<BuildStore, 'getRepo'>,
|