@defrex/autobuild 1.8.1 → 1.9.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 +92 -11
- package/docs/architecture.md +38 -14
- package/docs/configuration.md +247 -4
- package/docs/dispatcher-hosting.md +4 -0
- package/docs/merge-policy.md +45 -5
- package/docs/operating.md +21 -0
- package/docs/operator-api.md +11 -2
- package/docs/plugin-authoring.md +4 -1
- package/docs/restacking.md +4 -0
- package/docs/setup.md +3 -1
- package/docs/verification.md +7 -6
- package/package.json +4 -3
- package/packages/core/src/cli/attention.ts +3 -0
- package/packages/core/src/cli/dashboard/landing-display.ts +9 -1
- package/packages/core/src/cli/dashboard/model.ts +25 -6
- package/packages/core/src/cli/dashboard/render.ts +2 -2
- package/packages/core/src/cli/dispatch.ts +120 -1
- package/packages/core/src/cli/help.ts +6 -2
- package/packages/core/src/cli/repository-status.ts +66 -1
- package/packages/core/src/cli/status.ts +2 -2
- package/packages/core/src/cli/watch.ts +1074 -627
- package/packages/core/src/config/live.ts +1 -0
- package/packages/core/src/config/load.ts +19 -0
- package/packages/core/src/config/schema.ts +114 -0
- package/packages/core/src/events/catalog.ts +2 -0
- package/packages/core/src/events/payloads.ts +22 -0
- package/packages/core/src/events/policy.ts +9 -0
- package/packages/core/src/events/repository.ts +43 -0
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +31 -0
- package/packages/core/src/kernel/auto-merge.ts +33 -0
- package/packages/core/src/kernel/generators/repository-journals.ts +18 -0
- package/packages/core/src/kernel/landing-state.ts +56 -0
- package/packages/core/src/kernel/reducer.ts +1 -1
- package/packages/core/src/plugin-sdk/index.ts +7 -1
- package/packages/core/src/ports/forge/fake.ts +128 -8
- package/packages/core/src/ports/forge/git-rewrite.ts +34 -3
- package/packages/core/src/ports/forge/github-squash-message.ts +89 -0
- package/packages/core/src/ports/forge/github-transport.ts +30 -0
- package/packages/core/src/ports/forge/github.ts +565 -164
- package/packages/core/src/ports/types.ts +47 -3
- package/packages/core/src/processes/build-execution-state.ts +4 -3
- package/packages/core/src/processes/dispatcher.ts +73 -4
- package/packages/core/src/processes/execution-no-progress.ts +2 -0
- package/packages/core/src/processes/hook-command.ts +125 -0
- package/packages/core/src/processes/hook-webhook.ts +144 -0
- package/packages/core/src/processes/hooks.ts +740 -0
- package/packages/core/src/store/contract.ts +28 -0
- package/packages/core/src/store/reducer-value-shapes.json +3729 -3297
- package/packages/core/src/store/remote/released-clients.json +11 -0
- package/packages/core/src/store/remote/released-reducer-values/1.9.0.json +29475 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +2 -0
- package/packages/core/src/store/repo-state-events.ts +3 -0
- package/packages/core/src/store/retention.ts +16 -2
- package/packages/core/src/testing/index.ts +1 -0
- package/packages/core/src/testing/reduced-read-budget.ts +476 -1
- package/skills/guide/SKILL.md +81 -6
- package/skills/guide/references/merge-policy.md +45 -5
- package/skills/guide/references/operator-api.md +11 -2
- package/skills/guide/references/plugin-authoring.md +4 -1
- package/skills/guide/references/restacking.md +4 -0
- package/skills/guide/references/setup.md +3 -1
- package/skills/operate/SKILL.md +24 -4
- package/templates/hosted-service/package.json +2 -2
|
@@ -6,6 +6,7 @@ import release3 from './1.5.0.json'
|
|
|
6
6
|
import release4 from './1.6.0.json'
|
|
7
7
|
import release5 from './1.7.0.json'
|
|
8
8
|
import release6 from './1.8.0.json'
|
|
9
|
+
import release7 from './1.9.0.json'
|
|
9
10
|
import type { ReducerValueCatalog } from '../../reducer-value-validation'
|
|
10
11
|
export interface ReleasedReducerValues extends ReducerValueCatalog {
|
|
11
12
|
versions: Record<string, number>
|
|
@@ -18,4 +19,5 @@ export const RELEASED_REDUCER_VALUES: Readonly<Record<string, ReleasedReducerVal
|
|
|
18
19
|
'1.6.0.json': release4,
|
|
19
20
|
'1.7.0.json': release5,
|
|
20
21
|
'1.8.0.json': release6,
|
|
22
|
+
'1.9.0.json': release7,
|
|
21
23
|
}
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
ticketSourceHealthEventPayloadSchemas,
|
|
13
13
|
dispatcherSettingEventPayloadSchemas,
|
|
14
14
|
dispatcherStatusEventPayloadSchemas,
|
|
15
|
+
hookEventPayloadSchemas,
|
|
15
16
|
harvestEventPayloadSchemas,
|
|
16
17
|
orchestratorSandboxEventPayloadSchemas,
|
|
17
18
|
} from '../events/repository'
|
|
@@ -74,6 +75,8 @@ export const REPOSITORY_RUN_SCOPED_EVENT_TYPES: readonly RepositoryEventType[] =
|
|
|
74
75
|
!REPOSITORY_STATE_EVENT_TYPES.includes(type as RepositoryEventType),
|
|
75
76
|
),
|
|
76
77
|
'dispatcher.config-reloaded',
|
|
78
|
+
// Hook delivery health is attention only: no state reducer consumes it.
|
|
79
|
+
...Object.keys(hookEventPayloadSchemas),
|
|
77
80
|
] as RepositoryEventType[]
|
|
78
81
|
|
|
79
82
|
const STATE_TYPES = new Set<string>(REPOSITORY_STATE_EVENT_TYPES)
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
* The rule is count-based, not age-based: revision sequences already order by
|
|
20
20
|
* deposit recency, so recency is preserved without a clock in the decision,
|
|
21
21
|
* the boundary is deterministic, and an age rule would still only ever fire on
|
|
22
|
-
* a deposit (there is no sweeper).
|
|
22
|
+
* a deposit (there is no sweeper). Hook progress kinds (`hook-progress.*`)
|
|
23
|
+
* follow the same rule. Events and journal entries are never
|
|
23
24
|
* pruned — historical payloads may reference a revision that no longer
|
|
24
25
|
* resolves; the current run's snapshot is always among the newest deposits.
|
|
25
26
|
*/
|
|
@@ -65,6 +66,18 @@ export const OPERATOR_RETENTION_REPO_KINDS = [OPERATOR_NOTES_REPO_KIND] as const
|
|
|
65
66
|
*/
|
|
66
67
|
export const DISPATCHER_RETENTION_BUILD_KINDS = ['build-runner-effective-config'] as const
|
|
67
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Configured hook progress (`processes/hooks.ts`): one repository artifact
|
|
71
|
+
* kind per hook name, `hook-progress.<name>`, holding the hook's durable safe
|
|
72
|
+
* point. Written once per successful delivery, so it is retention-managed
|
|
73
|
+
* under the same deposit-time bound; only the latest revision is ever read.
|
|
74
|
+
*/
|
|
75
|
+
export const HOOK_PROGRESS_KIND_PREFIX = 'hook-progress.'
|
|
76
|
+
|
|
77
|
+
export function hookProgressKind(name: string): string {
|
|
78
|
+
return `${HOOK_PROGRESS_KIND_PREFIX}${name}`
|
|
79
|
+
}
|
|
80
|
+
|
|
68
81
|
/** Default bound: the newest 200 revisions of each retention-managed kind survive. */
|
|
69
82
|
export const DEFAULT_ARTIFACT_RETENTION_MAX_REVISIONS = 200
|
|
70
83
|
|
|
@@ -73,7 +86,8 @@ export function isRetentionManagedKind(kind: string): boolean {
|
|
|
73
86
|
return (
|
|
74
87
|
(DISPATCHER_RETENTION_REPO_KINDS as readonly string[]).includes(kind) ||
|
|
75
88
|
(OPERATOR_RETENTION_REPO_KINDS as readonly string[]).includes(kind) ||
|
|
76
|
-
(DISPATCHER_RETENTION_BUILD_KINDS as readonly string[]).includes(kind)
|
|
89
|
+
(DISPATCHER_RETENTION_BUILD_KINDS as readonly string[]).includes(kind) ||
|
|
90
|
+
kind.startsWith(HOOK_PROGRESS_KIND_PREFIX)
|
|
77
91
|
)
|
|
78
92
|
}
|
|
79
93
|
|
|
@@ -1600,7 +1600,7 @@ export async function ticketWaitIdleReadBudget(opts: {
|
|
|
1600
1600
|
}
|
|
1601
1601
|
|
|
1602
1602
|
/** Count every MemoryBuildStore method call made while `run` executes. */
|
|
1603
|
-
async function countStoreRequests(
|
|
1603
|
+
export async function countStoreRequests(
|
|
1604
1604
|
store: import('../store/memory').MemoryBuildStore,
|
|
1605
1605
|
run: () => Promise<void>,
|
|
1606
1606
|
): Promise<Record<string, number>> {
|
|
@@ -3074,6 +3074,87 @@ export async function nativeMaintenanceReadBudget(opts: {
|
|
|
3074
3074
|
}
|
|
3075
3075
|
}
|
|
3076
3076
|
|
|
3077
|
+
/** A gated root leaf landing by polling (GraphQL unavailable, PR blocked,
|
|
3078
|
+
* current polling fact): each quiet tick costs one conditional PR read and
|
|
3079
|
+
* nothing else — no GraphQL, queue, consent or store work beyond a tick
|
|
3080
|
+
* that makes no landing call at all — and appends nothing, at 100 and
|
|
3081
|
+
* 10,000 events. `settle` then records a human-merge fact: those ticks make
|
|
3082
|
+
* no landing call and match the polling tick's store cost. */
|
|
3083
|
+
export async function gatedPollingReadBudget(opts: {
|
|
3084
|
+
store: import('../store/memory').MemoryBuildStore
|
|
3085
|
+
slug: string
|
|
3086
|
+
forge: FakeForge
|
|
3087
|
+
tick: () => Promise<unknown>
|
|
3088
|
+
settle: () => Promise<unknown>
|
|
3089
|
+
}) {
|
|
3090
|
+
const { store, slug, forge } = opts
|
|
3091
|
+
const events = buildEventRows(store, slug)
|
|
3092
|
+
const fill = async (length: number) => {
|
|
3093
|
+
let filler = 0
|
|
3094
|
+
while (events.length < length)
|
|
3095
|
+
await store.append(slug, {
|
|
3096
|
+
actor: KERNEL,
|
|
3097
|
+
type: 'observation.recorded',
|
|
3098
|
+
payload: { id: `obs_polling_${length}_${filler++}`, kind: 'followup', summary: 'filler' },
|
|
3099
|
+
})
|
|
3100
|
+
}
|
|
3101
|
+
const measure = async () => {
|
|
3102
|
+
// Warm the saved reduced values past any new rows before measuring.
|
|
3103
|
+
await opts.tick()
|
|
3104
|
+
const boundary = events.at(-1)!.seq
|
|
3105
|
+
const metrics = { historicalRows: 0, tailRows: 0 }
|
|
3106
|
+
let calls = 0
|
|
3107
|
+
const getReduced = store.getReducerValue.bind(store)
|
|
3108
|
+
store.getReducerValue = async (...args) => {
|
|
3109
|
+
calls++
|
|
3110
|
+
return getReduced(...args)
|
|
3111
|
+
}
|
|
3112
|
+
const restore = instrumentBuildRows(store, slug, () => boundary, metrics)
|
|
3113
|
+
const before = {
|
|
3114
|
+
prReads: forge.getPrStateCalls.length,
|
|
3115
|
+
graphql: forge.graphqlRequests,
|
|
3116
|
+
activity: forge.activityReads,
|
|
3117
|
+
fastPath: forge.pollingFastPath,
|
|
3118
|
+
autoMerge: forge.autoMergeCalls.length,
|
|
3119
|
+
squash: forge.squashMergeCalls.length,
|
|
3120
|
+
}
|
|
3121
|
+
try {
|
|
3122
|
+
await opts.tick()
|
|
3123
|
+
} finally {
|
|
3124
|
+
restore()
|
|
3125
|
+
store.getReducerValue = getReduced
|
|
3126
|
+
}
|
|
3127
|
+
expect(metrics.historicalRows).toBe(0)
|
|
3128
|
+
expect(events.at(-1)!.seq).toBe(boundary)
|
|
3129
|
+
expect(forge.getPrStateCalls.length - before.prReads).toBe(1)
|
|
3130
|
+
expect(forge.graphqlRequests - before.graphql).toBe(0)
|
|
3131
|
+
expect(forge.activityReads - before.activity).toBe(0)
|
|
3132
|
+
expect(forge.autoMergeCalls.length - before.autoMerge).toBe(0)
|
|
3133
|
+
expect(forge.squashMergeCalls.length - before.squash).toBe(0)
|
|
3134
|
+
return {
|
|
3135
|
+
rows: metrics.tailRows,
|
|
3136
|
+
calls,
|
|
3137
|
+
landingCalls: forge.pollingFastPath - before.fastPath,
|
|
3138
|
+
}
|
|
3139
|
+
}
|
|
3140
|
+
let polling: { rows: number; calls: number; landingCalls: number } | undefined
|
|
3141
|
+
for (const length of [100, 10_000]) {
|
|
3142
|
+
await fill(length)
|
|
3143
|
+
const costs = await measure()
|
|
3144
|
+
expect(costs.landingCalls).toBe(1)
|
|
3145
|
+
if (polling) expect(costs).toEqual(polling)
|
|
3146
|
+
polling = costs
|
|
3147
|
+
}
|
|
3148
|
+
await opts.settle()
|
|
3149
|
+
const settled = await measure()
|
|
3150
|
+
expect(settled.landingCalls).toBe(0)
|
|
3151
|
+
// No consent read or other store work on a quiet polling tick.
|
|
3152
|
+
expect({ rows: settled.rows, calls: settled.calls }).toEqual({
|
|
3153
|
+
rows: polling!.rows,
|
|
3154
|
+
calls: polling!.calls,
|
|
3155
|
+
})
|
|
3156
|
+
}
|
|
3157
|
+
|
|
3077
3158
|
type PrStateLike = Awaited<ReturnType<FakeForge['getPrState']>> & { nativeAutoMerge?: boolean }
|
|
3078
3159
|
/** The bounded replaced-head record rides in the saved build facts: a warm
|
|
3079
3160
|
* read touches no event rows, and its size is fixed at any rewrite count. */
|
|
@@ -3694,3 +3775,397 @@ export async function repositoryEventsReadBudget() {
|
|
|
3694
3775
|
expect(counter.rows).toBe(0)
|
|
3695
3776
|
return pages
|
|
3696
3777
|
}
|
|
3778
|
+
|
|
3779
|
+
/**
|
|
3780
|
+
* Configured hooks (`processes/hooks.ts`) cost the same at every growth
|
|
3781
|
+
* setting: journal length, this repository's historical terminal builds,
|
|
3782
|
+
* foreign-repository builds and records already delivered. With two active
|
|
3783
|
+
* builds and fixed new work, it measures
|
|
3784
|
+
*
|
|
3785
|
+
* 1. idle intervals — exactly one `getRepoChangePosition` per interval for
|
|
3786
|
+
* every hook together, zero event rows and zero reduced reads;
|
|
3787
|
+
* 2. a changed pass — only the new rows;
|
|
3788
|
+
* 3. a fresh process resuming over the same store, discovering a build from
|
|
3789
|
+
* the journal;
|
|
3790
|
+
* 4. a build announced, escalated and finished between two passes, which is
|
|
3791
|
+
* delivered and then retires;
|
|
3792
|
+
* 5. a long non-matching interval followed by graceful and crashed resumes,
|
|
3793
|
+
* which read none of the old interval; and
|
|
3794
|
+
* 6. a brand-new hook's first initialization while a preparation is in flight;
|
|
3795
|
+
* and
|
|
3796
|
+
* 7. fresh one-shot invocations (the hosted cron's `drainOnce`, with a new
|
|
3797
|
+
* supervisor each time and no shared change gate): zero event rows and an
|
|
3798
|
+
* identical request vector while unchanged, only the new rows when
|
|
3799
|
+
* changed, and no store request at all with no hooks configured.
|
|
3800
|
+
*
|
|
3801
|
+
* No measured path lists builds; only (6) reads the repository's digests.
|
|
3802
|
+
*/
|
|
3803
|
+
export async function hookReadBudget(): Promise<void> {
|
|
3804
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
3805
|
+
const { manualClock } = await import('./fixed')
|
|
3806
|
+
const { HookSupervisor } = await import('../processes/hooks')
|
|
3807
|
+
const repo = '/budget/hooks'
|
|
3808
|
+
const storeRef = '/budget/hooks.store'
|
|
3809
|
+
const settings = [
|
|
3810
|
+
{ journal: 100, history: 3, foreign: 0, delivered: 0 },
|
|
3811
|
+
{ journal: 100_000, history: 1_000, foreign: 1_000, delivered: 50 },
|
|
3812
|
+
]
|
|
3813
|
+
type Store = InstanceType<typeof MemoryBuildStore>
|
|
3814
|
+
const ticket = (attempt: string) => ({ source: 'fake', id: `T-${attempt}` })
|
|
3815
|
+
const announce = async (store: Store, slug: string, attempt: string, events = 1) => {
|
|
3816
|
+
await store.appendRepo(repo, {
|
|
3817
|
+
actor: DISPATCHER,
|
|
3818
|
+
type: 'ticket-preparation.intended',
|
|
3819
|
+
payload: { attempt, ticket: ticket(attempt), readyState: 'ready', claimedState: 'claimed' },
|
|
3820
|
+
})
|
|
3821
|
+
await store.appendRepo(repo, {
|
|
3822
|
+
actor: DISPATCHER,
|
|
3823
|
+
type: 'ticket-preparation.creation-selected',
|
|
3824
|
+
payload: { attempt, ticket: ticket(attempt), slug },
|
|
3825
|
+
})
|
|
3826
|
+
await store.createBuild({ slug, repo })
|
|
3827
|
+
for (let i = 0; i < events; i++) await attach(store, slug)
|
|
3828
|
+
await store.appendRepo(repo, {
|
|
3829
|
+
actor: DISPATCHER,
|
|
3830
|
+
type: 'ticket-preparation.resolved',
|
|
3831
|
+
payload: { attempt, ticket: ticket(attempt), outcome: 'owned' },
|
|
3832
|
+
})
|
|
3833
|
+
}
|
|
3834
|
+
const attach = (store: Store, slug: string) =>
|
|
3835
|
+
store.append(slug, {
|
|
3836
|
+
actor: KERNEL,
|
|
3837
|
+
type: 'runner.attached',
|
|
3838
|
+
payload: { instance: 'i', host: 'h', resumedFromSeq: 0 },
|
|
3839
|
+
})
|
|
3840
|
+
const escalate = (store: Store, slug: string, id: string) =>
|
|
3841
|
+
store.append(slug, {
|
|
3842
|
+
actor: KERNEL,
|
|
3843
|
+
type: 'escalation.raised',
|
|
3844
|
+
payload: { id, phase: 'implement', round: 1, source: 'agent', question: 'q?' },
|
|
3845
|
+
})
|
|
3846
|
+
const finish = (store: Store, slug: string) =>
|
|
3847
|
+
store.append(slug, {
|
|
3848
|
+
actor: DISPATCHER,
|
|
3849
|
+
type: 'build.completed',
|
|
3850
|
+
payload: { outcome: 'merged' },
|
|
3851
|
+
})
|
|
3852
|
+
const filler = (store: Store) =>
|
|
3853
|
+
store.appendRepo(repo, {
|
|
3854
|
+
actor: humanActor('operator'),
|
|
3855
|
+
type: 'dispatcher.intake-set',
|
|
3856
|
+
payload: { enabled: true },
|
|
3857
|
+
})
|
|
3858
|
+
const settle = async () => {
|
|
3859
|
+
for (let i = 0; i < 20; i++) await new Promise((resolve) => setTimeout(resolve, 0))
|
|
3860
|
+
}
|
|
3861
|
+
const supervisorFor = (
|
|
3862
|
+
store: Store,
|
|
3863
|
+
clock: ReturnType<typeof manualClock>,
|
|
3864
|
+
delivered: string[],
|
|
3865
|
+
) =>
|
|
3866
|
+
new HookSupervisor({
|
|
3867
|
+
store,
|
|
3868
|
+
repo,
|
|
3869
|
+
storeRef,
|
|
3870
|
+
checkout: repo,
|
|
3871
|
+
clock,
|
|
3872
|
+
invoke: async (_hook, line) => {
|
|
3873
|
+
delivered.push(JSON.parse(line).id)
|
|
3874
|
+
return { ok: true }
|
|
3875
|
+
},
|
|
3876
|
+
warn: (line) => {
|
|
3877
|
+
throw new Error(`unexpected hook warning: ${line}`)
|
|
3878
|
+
},
|
|
3879
|
+
appendRepo: (event) => store.appendRepo(repo, event),
|
|
3880
|
+
intervalMs: 1000,
|
|
3881
|
+
interval: (signal) =>
|
|
3882
|
+
new Promise((resolve) => signal.addEventListener('abort', () => resolve(), { once: true })),
|
|
3883
|
+
backoff: async () => {},
|
|
3884
|
+
})
|
|
3885
|
+
const hooks = {
|
|
3886
|
+
notify: { command: 'true', timeoutSeconds: 30 },
|
|
3887
|
+
selective: { command: 'true', timeoutSeconds: 30, events: ['escalation.*', 'hook.*'] },
|
|
3888
|
+
}
|
|
3889
|
+
const quiet = { quiet: { command: 'true', timeoutSeconds: 30, events: ['pr.merged'] } }
|
|
3890
|
+
const pulse = async (supervisor: InstanceType<typeof HookSupervisor>) => {
|
|
3891
|
+
await settle()
|
|
3892
|
+
await supervisor.pulse()
|
|
3893
|
+
await settle()
|
|
3894
|
+
}
|
|
3895
|
+
const listing = (vector: Record<string, number>) => [
|
|
3896
|
+
vector.listBuilds ?? 0,
|
|
3897
|
+
vector.listBuildsForRepo ?? 0,
|
|
3898
|
+
vector.getRepoBuildDigests ?? 0,
|
|
3899
|
+
]
|
|
3900
|
+
const measured: unknown[] = []
|
|
3901
|
+
for (const setting of settings) {
|
|
3902
|
+
const clock = manualClock()
|
|
3903
|
+
const store = new MemoryBuildStore({ clock })
|
|
3904
|
+
await store.ensureRepo(repo)
|
|
3905
|
+
for (let i = 0; i < setting.foreign; i++)
|
|
3906
|
+
await store.createBuild({ slug: `foreign-${i}`, repo: '/budget/foreign' })
|
|
3907
|
+
for (let i = 0; i < setting.history; i++) {
|
|
3908
|
+
await announce(store, `history-${i}`, `h${i}`)
|
|
3909
|
+
await finish(store, `history-${i}`)
|
|
3910
|
+
}
|
|
3911
|
+
const seeded = setting.history * 6
|
|
3912
|
+
for (let i = seeded; i < setting.journal; i++) await filler(store)
|
|
3913
|
+
await announce(store, 'active-a', 'aa')
|
|
3914
|
+
await announce(store, 'active-b', 'ab')
|
|
3915
|
+
// Canonical repository values exist before any hook runs, as they do
|
|
3916
|
+
// under a running dispatcher; reducing them is not hook cost.
|
|
3917
|
+
await readRepositoryFacts(store, repo)
|
|
3918
|
+
await readRepositoryAttention(store, repo)
|
|
3919
|
+
await readBuildDigests(store, repo)
|
|
3920
|
+
|
|
3921
|
+
const delivered: string[] = []
|
|
3922
|
+
let supervisor = supervisorFor(store, clock, delivered)
|
|
3923
|
+
await supervisor.reconcile(hooks)
|
|
3924
|
+
await pulse(supervisor)
|
|
3925
|
+
for (let i = 0; i < setting.delivered; i++) await escalate(store, 'active-a', `warm-${i}`)
|
|
3926
|
+
await pulse(supervisor)
|
|
3927
|
+
await pulse(supervisor)
|
|
3928
|
+
expect(delivered).toHaveLength(2 * setting.delivered)
|
|
3929
|
+
|
|
3930
|
+
// 1. Idle intervals.
|
|
3931
|
+
let rows = memoryRepositoryReadCounter(store, repo)
|
|
3932
|
+
let requests = memoryStoreRequestCounter(store)
|
|
3933
|
+
for (let i = 0; i < 5; i++) await pulse(supervisor)
|
|
3934
|
+
const idle = {
|
|
3935
|
+
rows: rows.rows,
|
|
3936
|
+
buildRows: rows.buildRows,
|
|
3937
|
+
reducedCalls: rows.reducedCalls,
|
|
3938
|
+
requests: requests.vector(),
|
|
3939
|
+
}
|
|
3940
|
+
expect(idle).toEqual({
|
|
3941
|
+
rows: 0,
|
|
3942
|
+
buildRows: 0,
|
|
3943
|
+
reducedCalls: 0,
|
|
3944
|
+
requests: { getRepoChangePosition: 5 },
|
|
3945
|
+
})
|
|
3946
|
+
requests.restore()
|
|
3947
|
+
|
|
3948
|
+
// 2. A changed pass with fixed new work.
|
|
3949
|
+
const newWork = async (slug: string, attempt: string) => {
|
|
3950
|
+
await escalate(store, 'active-a', `${attempt}-escalation`)
|
|
3951
|
+
await filler(store)
|
|
3952
|
+
await announce(store, slug, attempt, 3)
|
|
3953
|
+
}
|
|
3954
|
+
const deliveredBefore = delivered.length
|
|
3955
|
+
await newWork('new-c', 'nc')
|
|
3956
|
+
rows = memoryRepositoryReadCounter(store, repo)
|
|
3957
|
+
requests = memoryStoreRequestCounter(store)
|
|
3958
|
+
await pulse(supervisor)
|
|
3959
|
+
await pulse(supervisor)
|
|
3960
|
+
const changed = {
|
|
3961
|
+
rows: rows.rows,
|
|
3962
|
+
bySlug: Object.fromEntries(rows.buildRowsBySlug),
|
|
3963
|
+
requests: requests.vector(),
|
|
3964
|
+
}
|
|
3965
|
+
expect(delivered.slice(deliveredBefore)).toHaveLength(2)
|
|
3966
|
+
// Each new row is read once per hook, plus once by the shared reduced
|
|
3967
|
+
// value's incremental advance.
|
|
3968
|
+
expect(changed.bySlug).toEqual({ 'active-a': 3, 'new-c': 9 })
|
|
3969
|
+
expect(listing(changed.requests)).toEqual([0, 0, 0])
|
|
3970
|
+
requests.restore()
|
|
3971
|
+
|
|
3972
|
+
// 3. A fresh process discovers the same work from the journal.
|
|
3973
|
+
await supervisor.stop()
|
|
3974
|
+
await newWork('new-d', 'nd')
|
|
3975
|
+
rows = memoryRepositoryReadCounter(store, repo)
|
|
3976
|
+
requests = memoryStoreRequestCounter(store)
|
|
3977
|
+
supervisor = supervisorFor(store, clock, delivered)
|
|
3978
|
+
await supervisor.reconcile(hooks)
|
|
3979
|
+
await pulse(supervisor)
|
|
3980
|
+
const fresh = {
|
|
3981
|
+
rows: rows.rows,
|
|
3982
|
+
bySlug: Object.fromEntries(rows.buildRowsBySlug),
|
|
3983
|
+
requests: requests.vector(),
|
|
3984
|
+
}
|
|
3985
|
+
expect(listing(fresh.requests)).toEqual([0, 0, 0])
|
|
3986
|
+
expect(fresh.bySlug['new-d']).toBe(9)
|
|
3987
|
+
expect(Object.keys(fresh.bySlug).filter((slug) => slug.startsWith('history-'))).toEqual([])
|
|
3988
|
+
requests.restore()
|
|
3989
|
+
|
|
3990
|
+
// 4. Announced, escalated and finished between two passes.
|
|
3991
|
+
const beforeQuick = delivered.length
|
|
3992
|
+
await announce(store, 'quick', 'q')
|
|
3993
|
+
await escalate(store, 'quick', 'quick-escalation')
|
|
3994
|
+
await finish(store, 'quick')
|
|
3995
|
+
await pulse(supervisor)
|
|
3996
|
+
await pulse(supervisor)
|
|
3997
|
+
expect(delivered.slice(beforeQuick)).toEqual(['build:quick:2', 'build:quick:2'])
|
|
3998
|
+
rows = memoryRepositoryReadCounter(store, repo)
|
|
3999
|
+
for (let i = 0; i < 3; i++) await pulse(supervisor)
|
|
4000
|
+
expect(rows.buildRowsBySlug.get('quick') ?? 0).toBe(0)
|
|
4001
|
+
expect(rows.rows + rows.buildRows).toBe(0)
|
|
4002
|
+
await supervisor.stop()
|
|
4003
|
+
|
|
4004
|
+
// 5. A long non-matching interval, then graceful and crashed resumes.
|
|
4005
|
+
const longDelivered: string[] = []
|
|
4006
|
+
let selective = supervisorFor(store, clock, longDelivered)
|
|
4007
|
+
await selective.reconcile(quiet)
|
|
4008
|
+
await pulse(selective)
|
|
4009
|
+
const interval = Math.min(setting.journal, 20_000)
|
|
4010
|
+
for (let done = 0; done < interval; done += 500) {
|
|
4011
|
+
for (let i = 0; i < 500; i++) await filler(store)
|
|
4012
|
+
for (let i = 0; i < Math.ceil(setting.history / (interval / 500)); i++) {
|
|
4013
|
+
const slug = `interval-${done}-${i}`
|
|
4014
|
+
await announce(store, slug, `i${done}-${i}`)
|
|
4015
|
+
await finish(store, slug)
|
|
4016
|
+
}
|
|
4017
|
+
clock.advance(1000)
|
|
4018
|
+
await pulse(selective)
|
|
4019
|
+
}
|
|
4020
|
+
clock.advance(30_000)
|
|
4021
|
+
await filler(store)
|
|
4022
|
+
await pulse(selective)
|
|
4023
|
+
// Crash: abandon without a graceful stop; at most the tail after the
|
|
4024
|
+
// last checkpoint replays.
|
|
4025
|
+
const crashTail = 3
|
|
4026
|
+
for (let i = 0; i < crashTail; i++) await filler(store)
|
|
4027
|
+
await pulse(selective)
|
|
4028
|
+
const resume = async () => {
|
|
4029
|
+
// The running dispatcher keeps the canonical repository values current;
|
|
4030
|
+
// their shared incremental advance is not hook cost.
|
|
4031
|
+
await readRepositoryFacts(store, repo)
|
|
4032
|
+
await readRepositoryAttention(store, repo)
|
|
4033
|
+
rows = memoryRepositoryReadCounter(store, repo)
|
|
4034
|
+
requests = memoryStoreRequestCounter(store)
|
|
4035
|
+
const next = supervisorFor(store, clock, longDelivered)
|
|
4036
|
+
await next.reconcile(quiet)
|
|
4037
|
+
await pulse(next)
|
|
4038
|
+
const cost = {
|
|
4039
|
+
rows: rows.rows,
|
|
4040
|
+
buildRows: rows.buildRows,
|
|
4041
|
+
requests: requests.vector(),
|
|
4042
|
+
}
|
|
4043
|
+
requests.restore()
|
|
4044
|
+
return { next, cost }
|
|
4045
|
+
}
|
|
4046
|
+
const crashed = await resume()
|
|
4047
|
+
expect(crashed.cost.rows).toBeLessThanOrEqual(crashTail + 1)
|
|
4048
|
+
expect(crashed.cost.buildRows).toBe(0)
|
|
4049
|
+
expect(listing(crashed.cost.requests)).toEqual([0, 0, 0])
|
|
4050
|
+
await crashed.next.stop()
|
|
4051
|
+
selective = crashed.next
|
|
4052
|
+
const graceful = await resume()
|
|
4053
|
+
expect(graceful.cost.rows).toBe(0)
|
|
4054
|
+
expect(graceful.cost.buildRows).toBe(0)
|
|
4055
|
+
await graceful.next.stop()
|
|
4056
|
+
expect(longDelivered).toEqual([])
|
|
4057
|
+
|
|
4058
|
+
// 6. A brand-new hook initializes while a preparation is in flight.
|
|
4059
|
+
await store.appendRepo(repo, {
|
|
4060
|
+
actor: DISPATCHER,
|
|
4061
|
+
type: 'ticket-preparation.intended',
|
|
4062
|
+
payload: {
|
|
4063
|
+
attempt: 'np',
|
|
4064
|
+
ticket: ticket('np'),
|
|
4065
|
+
readyState: 'ready',
|
|
4066
|
+
claimedState: 'claimed',
|
|
4067
|
+
},
|
|
4068
|
+
})
|
|
4069
|
+
await store.appendRepo(repo, {
|
|
4070
|
+
actor: DISPATCHER,
|
|
4071
|
+
type: 'ticket-preparation.creation-selected',
|
|
4072
|
+
payload: { attempt: 'np', ticket: ticket('np'), slug: 'pending' },
|
|
4073
|
+
})
|
|
4074
|
+
await readRepositoryFacts(store, repo)
|
|
4075
|
+
await readRepositoryAttention(store, repo)
|
|
4076
|
+
rows = memoryRepositoryReadCounter(store, repo)
|
|
4077
|
+
requests = memoryStoreRequestCounter(store)
|
|
4078
|
+
const firstDelivered: string[] = []
|
|
4079
|
+
const brandNew = supervisorFor(store, clock, firstDelivered)
|
|
4080
|
+
await brandNew.reconcile({ brandNew: hooks.notify })
|
|
4081
|
+
await pulse(brandNew)
|
|
4082
|
+
const initialization = {
|
|
4083
|
+
rows: rows.rows,
|
|
4084
|
+
buildRows: rows.buildRows,
|
|
4085
|
+
requests: requests.vector(),
|
|
4086
|
+
}
|
|
4087
|
+
requests.restore()
|
|
4088
|
+
expect(listing(initialization.requests)).toEqual([0, 0, 1])
|
|
4089
|
+
await store.createBuild({ slug: 'pending', repo })
|
|
4090
|
+
await escalate(store, 'pending', 'pending-escalation')
|
|
4091
|
+
await store.appendRepo(repo, {
|
|
4092
|
+
actor: DISPATCHER,
|
|
4093
|
+
type: 'ticket-preparation.resolved',
|
|
4094
|
+
payload: { attempt: 'np', ticket: ticket('np'), outcome: 'owned' },
|
|
4095
|
+
})
|
|
4096
|
+
await pulse(brandNew)
|
|
4097
|
+
expect(firstDelivered).toEqual(['build:pending:1'])
|
|
4098
|
+
expect(
|
|
4099
|
+
(await store.getRepoEvents(repo)).filter((event) => event.type === 'hook.skipped'),
|
|
4100
|
+
).toEqual([])
|
|
4101
|
+
await brandNew.stop()
|
|
4102
|
+
|
|
4103
|
+
// 7. Fresh one-shot (hosted) invocations. Each cron run builds a new
|
|
4104
|
+
// supervisor, resumes from durable progress and makes one feed pass.
|
|
4105
|
+
const urlHooks = {
|
|
4106
|
+
relay: { url: 'https://hooks.example/x', secretEnv: 'HOOK_SECRET', timeoutSeconds: 30 },
|
|
4107
|
+
}
|
|
4108
|
+
const onceDelivered: string[] = []
|
|
4109
|
+
await supervisorFor(store, clock, onceDelivered).drainOnce(urlHooks)
|
|
4110
|
+
await supervisorFor(store, clock, onceDelivered).drainOnce(urlHooks)
|
|
4111
|
+
expect(onceDelivered).toEqual([])
|
|
4112
|
+
await readRepositoryFacts(store, repo)
|
|
4113
|
+
await readRepositoryAttention(store, repo)
|
|
4114
|
+
const unchangedOnce: { rows: number; buildRows: number; requests: Record<string, number> }[] =
|
|
4115
|
+
[]
|
|
4116
|
+
for (let i = 0; i < 3; i++) {
|
|
4117
|
+
rows = memoryRepositoryReadCounter(store, repo)
|
|
4118
|
+
requests = memoryStoreRequestCounter(store)
|
|
4119
|
+
await supervisorFor(store, clock, onceDelivered).drainOnce(urlHooks)
|
|
4120
|
+
unchangedOnce.push({
|
|
4121
|
+
rows: rows.rows,
|
|
4122
|
+
buildRows: rows.buildRows,
|
|
4123
|
+
requests: requests.vector(),
|
|
4124
|
+
})
|
|
4125
|
+
requests.restore()
|
|
4126
|
+
}
|
|
4127
|
+
expect(onceDelivered).toEqual([])
|
|
4128
|
+
for (const cost of unchangedOnce) {
|
|
4129
|
+
expect(cost.rows).toBe(0)
|
|
4130
|
+
expect(cost.buildRows).toBe(0)
|
|
4131
|
+
expect(cost.requests).toEqual(unchangedOnce[0]!.requests)
|
|
4132
|
+
expect(listing(cost.requests)).toEqual([0, 0, 0])
|
|
4133
|
+
}
|
|
4134
|
+
await escalate(store, 'active-a', 'once-escalation')
|
|
4135
|
+
await filler(store)
|
|
4136
|
+
await announce(store, 'once-new', 'on', 3)
|
|
4137
|
+
rows = memoryRepositoryReadCounter(store, repo)
|
|
4138
|
+
requests = memoryStoreRequestCounter(store)
|
|
4139
|
+
await supervisorFor(store, clock, onceDelivered).drainOnce(urlHooks)
|
|
4140
|
+
const changedOnce = {
|
|
4141
|
+
rows: rows.rows,
|
|
4142
|
+
bySlug: Object.fromEntries(rows.buildRowsBySlug),
|
|
4143
|
+
requests: requests.vector(),
|
|
4144
|
+
}
|
|
4145
|
+
requests.restore()
|
|
4146
|
+
expect(onceDelivered).toHaveLength(1)
|
|
4147
|
+
expect(onceDelivered[0]).toStartWith('build:active-a:')
|
|
4148
|
+
expect(Object.keys(changedOnce.bySlug).sort()).toEqual(['active-a', 'once-new'])
|
|
4149
|
+
expect(listing(changedOnce.requests)).toEqual([0, 0, 0])
|
|
4150
|
+
requests = memoryStoreRequestCounter(store)
|
|
4151
|
+
await supervisorFor(store, clock, onceDelivered).drainOnce({})
|
|
4152
|
+
expect(requests.vector()).toEqual({})
|
|
4153
|
+
requests.restore()
|
|
4154
|
+
|
|
4155
|
+
measured.push({
|
|
4156
|
+
changed: { rows: changed.rows, requests: changed.requests },
|
|
4157
|
+
fresh: { rows: fresh.rows, requests: fresh.requests },
|
|
4158
|
+
crashed: crashed.cost,
|
|
4159
|
+
graceful: graceful.cost,
|
|
4160
|
+
initialization: {
|
|
4161
|
+
rows: initialization.rows,
|
|
4162
|
+
buildRows: initialization.buildRows,
|
|
4163
|
+
// The one digest batch read is constant in calls; its internal
|
|
4164
|
+
// per-build reductions are not event rows.
|
|
4165
|
+
requests: initialization.requests,
|
|
4166
|
+
},
|
|
4167
|
+
once: { unchanged: unchangedOnce[0], changed: changedOnce },
|
|
4168
|
+
})
|
|
4169
|
+
}
|
|
4170
|
+
expect(measured[1]).toEqual(measured[0])
|
|
4171
|
+
}
|