@defrex/autobuild 1.11.1 → 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 +601 -203
- package/bin/ab-build-runner.ts +8 -0
- package/docs/answering-blocked-builds.md +32 -2
- package/docs/architecture.md +188 -57
- package/docs/assets/headline-wide.png +0 -0
- package/docs/cli.md +1 -1
- package/docs/configuration.md +120 -23
- package/docs/dispatcher.md +19 -8
- package/docs/integration-overview.md +1 -1
- package/docs/integration-tree.md +33 -18
- package/docs/merge-policy.md +7 -2
- package/docs/operating.md +5 -3
- package/docs/operator-api.md +48 -25
- package/docs/operator-surfaces.md +39 -3
- package/docs/optimization-nodes.md +10 -8
- 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/ambient-errors.ts +17 -0
- package/packages/core/src/cli/bounded-io.ts +174 -0
- 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 +93 -29
- package/packages/core/src/cli/dashboard/poll.ts +231 -34
- package/packages/core/src/cli/dashboard/queue.ts +21 -10
- package/packages/core/src/cli/dashboard/render.ts +14 -37
- package/packages/core/src/cli/dashboard/row-text.ts +26 -8
- package/packages/core/src/cli/dashboard/tone-ansi.ts +39 -0
- package/packages/core/src/cli/dashboard/vocabulary.ts +165 -20
- package/packages/core/src/cli/dispatch-frontend.ts +2 -1
- 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-tickets.ts +33 -12
- 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 +595 -149
- package/packages/core/src/cli/env.ts +2 -15
- package/packages/core/src/cli/help.ts +43 -28
- package/packages/core/src/cli/main.ts +11 -7
- package/packages/core/src/cli/production-store.ts +102 -0
- 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/repo-state.ts +2 -3
- package/packages/core/src/cli/repository-status.ts +44 -28
- package/packages/core/src/cli/sessionless-store.ts +26 -0
- package/packages/core/src/cli/status.ts +188 -47
- package/packages/core/src/cli/store-opening.ts +26 -57
- package/packages/core/src/cli/store-ref.ts +6 -1
- 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/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 +85 -14
- package/packages/core/src/events/policy.ts +3 -0
- package/packages/core/src/events/repository.ts +15 -4
- 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 +36 -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/3064e337cc75f8d6.json +310 -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/a1e90a969d32a367.json +307 -0
- package/packages/core/src/kernel/__snapshots__/reducer-identity-records/c7c94fbe7f63cf07.json +84 -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/clean-restack-policy.ts +40 -0
- package/packages/core/src/kernel/discard-in-flight.ts +13 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +578 -235
- package/packages/core/src/kernel/done-escalations.ts +269 -0
- package/packages/core/src/kernel/engine.ts +30 -17
- 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/measurement.ts +24 -0
- package/packages/core/src/kernel/open-pr-backpressure.ts +3 -3
- package/packages/core/src/kernel/read-facts.ts +8 -370
- package/packages/core/src/kernel/reducer-registry.ts +43 -125
- package/packages/core/src/kernel/reducer-revisions.ts +18 -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 +84 -16
- package/packages/core/src/kernel/reopen-state.ts +10 -0
- package/packages/core/src/kernel/repository-attention.ts +14 -5
- package/packages/core/src/kernel/repository-read-facts.ts +375 -0
- package/packages/core/src/kernel/ticket-starts.ts +15 -4
- package/packages/core/src/kernel/verify-stage-state.ts +145 -3
- 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 +14 -1
- package/packages/core/src/operator/protocol.ts +8 -5
- package/packages/core/src/operator/query.ts +72 -57
- package/packages/core/src/operator/registry.ts +19 -15
- 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/fake.ts +15 -3
- 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 +777 -288
- package/packages/core/src/processes/execution-no-progress.ts +1 -0
- 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/local/capabilities.ts +115 -0
- package/packages/core/src/store/local/store.ts +86 -56
- package/packages/core/src/store/reduced-reads.ts +32 -1
- package/packages/core/src/store/reducer-value-read.ts +235 -0
- package/packages/core/src/store/reducer-value-shapes.json +6722 -6475
- package/packages/core/src/store/reducer-value-validation.ts +181 -33
- package/packages/core/src/store/reducer-values.ts +36 -204
- 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 +22 -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/1.13.0.json +35966 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +20 -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/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 +409 -14
- package/packages/core/src/testing/import-graph.ts +78 -0
- 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 +602 -40
- package/packages/core/src/testing/released-value-coverage.ts +423 -0
- package/packages/core/src/testing/slot-agreement.ts +52 -0
- package/packages/core/src/web/assets/app.js +5 -5
- package/packages/core/src/web/overview-source.ts +19 -6
- package/skills/guide/SKILL.md +245 -103
- package/skills/guide/references/integration-tree.md +33 -18
- package/skills/guide/references/merge-policy.md +7 -2
- package/skills/guide/references/operator-api.md +48 -25
- package/skills/guide/references/optimization-nodes.md +10 -8
- 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 +114 -65
- 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
|
@@ -11,6 +11,8 @@ import { DISPATCHER, humanActor, KERNEL } from '../events/envelope'
|
|
|
11
11
|
import { WebModelHub } from '../web/hub'
|
|
12
12
|
import { readOnlyStore } from '../web/read-only'
|
|
13
13
|
import { OverviewFrameSource } from '../web/overview-source'
|
|
14
|
+
import { DashboardBuildPollCache, type DashboardPollSnapshot } from '../cli/dashboard/poll'
|
|
15
|
+
import { configSchema } from '../config/schema'
|
|
14
16
|
import { projectRepositoryFrame } from '../web/repository-source'
|
|
15
17
|
import { finishedOutcomeText } from '../cli/dashboard/vocabulary'
|
|
16
18
|
import { measureStoreReads } from './reduced-read-budget'
|
|
@@ -967,12 +969,16 @@ const OVERVIEW_BUDGET_CONFIG = {
|
|
|
967
969
|
|
|
968
970
|
/**
|
|
969
971
|
* `ab web`'s overview costs the same at 100 and 100,000 builds (5 live, the
|
|
970
|
-
* rest finished
|
|
971
|
-
*
|
|
972
|
-
*
|
|
973
|
-
*
|
|
974
|
-
*
|
|
975
|
-
*
|
|
972
|
+
* rest finished, one finished long ago with an open escalation): a fresh
|
|
973
|
+
* process reads the `buildRoster` and `doneEscalations` rollups and only the
|
|
974
|
+
* live and escalated builds; an idle poll reads the change position; a change
|
|
975
|
+
* to one build reads that build only, plus one roster read when the build
|
|
976
|
+
* starts or finishes, including one created and finished between two polls,
|
|
977
|
+
* or is acknowledged; and no read scans history. The terminal dashboard's
|
|
978
|
+
* poll cache then measures the same repositories: cold start, idle refresh,
|
|
979
|
+
* one live change and an acknowledgement each cost the same at both sizes and
|
|
980
|
+
* never list builds or read events (#1372). Row metrics need a memory
|
|
981
|
+
* backing, so other backings skip it.
|
|
976
982
|
*/
|
|
977
983
|
async function webOverviewReadBudget(store: BuildStore, backing: BuildStore): Promise<void> {
|
|
978
984
|
const { MemoryBuildStore } = await import('../store/memory')
|
|
@@ -1009,6 +1015,27 @@ async function webOverviewReadBudget(store: BuildStore, backing: BuildStore): Pr
|
|
|
1009
1015
|
} else await complete(slug)
|
|
1010
1016
|
}
|
|
1011
1017
|
for (let i = 0; i < 5; i++) await create(live(i))
|
|
1018
|
+
// A post-completion escalation on a build far older than the roster's
|
|
1019
|
+
// newest finished entries.
|
|
1020
|
+
const escalated = `${prefix}done-000000`
|
|
1021
|
+
const raise = (slug: string) =>
|
|
1022
|
+
backing.append(slug, {
|
|
1023
|
+
actor: KERNEL,
|
|
1024
|
+
type: 'escalation.raised',
|
|
1025
|
+
payload: {
|
|
1026
|
+
id: 'integration-audit-op',
|
|
1027
|
+
phase: 'verify:integration',
|
|
1028
|
+
source: 'agent',
|
|
1029
|
+
question: 'Integration result requires attention',
|
|
1030
|
+
},
|
|
1031
|
+
})
|
|
1032
|
+
const acknowledge = (slug: string) =>
|
|
1033
|
+
backing.append(slug, {
|
|
1034
|
+
actor: humanActor('op'),
|
|
1035
|
+
type: 'escalation.answered',
|
|
1036
|
+
payload: { id: 'integration-audit-op', answer: 'ack', resolution: 'retry' },
|
|
1037
|
+
})
|
|
1038
|
+
await raise(escalated)
|
|
1012
1039
|
const config = await backing.putRepoArtifact(repo, {
|
|
1013
1040
|
kind: 'config',
|
|
1014
1041
|
content: JSON.stringify(OVERVIEW_BUDGET_CONFIG),
|
|
@@ -1026,7 +1053,9 @@ async function webOverviewReadBudget(store: BuildStore, backing: BuildStore): Pr
|
|
|
1026
1053
|
// The canonical materializations happen once, before any measured read.
|
|
1027
1054
|
await readRepositoryFacts(store, repo)
|
|
1028
1055
|
await store.getReducerValue({ kind: 'rollup', repo }, { reducer: 'buildRoster' })
|
|
1056
|
+
await store.getReducerValue({ kind: 'rollup', repo }, { reducer: 'doneEscalations' })
|
|
1029
1057
|
for (let i = 0; i < 5; i++) await readBuildFacts(store, live(i))
|
|
1058
|
+
await readBuildFacts(store, escalated)
|
|
1030
1059
|
|
|
1031
1060
|
const counter = countingStore(store, { slugs: true })
|
|
1032
1061
|
// A fresh process: no state but the saved values.
|
|
@@ -1068,13 +1097,18 @@ async function webOverviewReadBudget(store: BuildStore, backing: BuildStore): Pr
|
|
|
1068
1097
|
const named = (calls: Record<string, number>, slug: string) =>
|
|
1069
1098
|
Object.keys(buildScope(calls)).every((name) => name.endsWith(`:${slug.replace(prefix, '')}`))
|
|
1070
1099
|
|
|
1071
|
-
// (a) The first read:
|
|
1100
|
+
// (a) The first read: both rollups, the five live builds and the
|
|
1101
|
+
// escalated done build.
|
|
1072
1102
|
const first = await measure('first')
|
|
1073
|
-
expect(first.calls['getReducerValue:rollup']).toBe(
|
|
1074
|
-
expect(buildScope(first.calls)).toEqual(reads(...[0, 1, 2, 3, 4].map(live)))
|
|
1103
|
+
expect(first.calls['getReducerValue:rollup']).toBe(2)
|
|
1104
|
+
expect(buildScope(first.calls)).toEqual(reads(...[0, 1, 2, 3, 4].map(live), escalated))
|
|
1075
1105
|
expect(first.rows).toBe(0)
|
|
1076
1106
|
expect(first.repoRows).toBe(0)
|
|
1077
|
-
expect(frame.overview!.active.length + frame.overview!.queued.length).toBe(
|
|
1107
|
+
expect(frame.overview!.active.length + frame.overview!.queued.length).toBe(6)
|
|
1108
|
+
expect(frame.overview!.active.find((row) => row.slug === escalated)?.status).toMatchObject({
|
|
1109
|
+
word: 'BLOCKED',
|
|
1110
|
+
note: 'done',
|
|
1111
|
+
})
|
|
1078
1112
|
expect(frame.overview!.finished).toHaveLength(10)
|
|
1079
1113
|
|
|
1080
1114
|
// (b) Idle: the change position only.
|
|
@@ -1131,11 +1165,58 @@ async function webOverviewReadBudget(store: BuildStore, backing: BuildStore): Pr
|
|
|
1131
1165
|
word: finishedOutcomeText('merged').word,
|
|
1132
1166
|
})
|
|
1133
1167
|
expect(shown()).not.toContain(blinked)
|
|
1168
|
+
|
|
1169
|
+
// (g) Acknowledging the escalation: that build's reads, and it leaves.
|
|
1170
|
+
await acknowledge(escalated)
|
|
1171
|
+
const acknowledged = await measure('acknowledged')
|
|
1172
|
+
expect(named(acknowledged.calls, escalated)).toBe(true)
|
|
1173
|
+
expect(shown()).not.toContain(escalated)
|
|
1134
1174
|
expect(await measure('after')).toEqual({
|
|
1135
1175
|
calls: { getRepoChangePosition: 1 },
|
|
1136
1176
|
rows: 0,
|
|
1137
1177
|
repoRows: 0,
|
|
1138
1178
|
})
|
|
1179
|
+
|
|
1180
|
+
// The terminal dashboard over the same repository, as a fresh process.
|
|
1181
|
+
const terminalEscalated = `${prefix}done-000004`
|
|
1182
|
+
await raise(terminalEscalated)
|
|
1183
|
+
const terminalConfig = configSchema.parse(OVERVIEW_BUDGET_CONFIG)
|
|
1184
|
+
// Warm-up: an earlier process saved every value the cold start reads.
|
|
1185
|
+
await new DashboardBuildPollCache(store, repo, terminalConfig).refresh()
|
|
1186
|
+
const terminalCounter = countingStore(store, { slugs: true })
|
|
1187
|
+
const cache = new DashboardBuildPollCache(terminalCounter.proxy, repo, terminalConfig)
|
|
1188
|
+
let snapshot!: DashboardPollSnapshot
|
|
1189
|
+
const refresh = async (phase: string) => {
|
|
1190
|
+
terminalCounter.calls.length = 0
|
|
1191
|
+
const metrics = await measureStoreReads(backing, async () => {
|
|
1192
|
+
snapshot = await cache.refresh()
|
|
1193
|
+
})
|
|
1194
|
+
for (const name of terminalCounter.calls) expect(HISTORY_READS.has(name)).toBe(false)
|
|
1195
|
+
const calls = Object.fromEntries(
|
|
1196
|
+
Object.entries(terminalCounter.histogram()).map(([name, count]) => [
|
|
1197
|
+
name.replaceAll(prefix, ''),
|
|
1198
|
+
count,
|
|
1199
|
+
]),
|
|
1200
|
+
)
|
|
1201
|
+
phases[`terminal-${phase}`] = { calls, rows: metrics.rows, repoRows: metrics.repoRows }
|
|
1202
|
+
return phases[`terminal-${phase}`]!
|
|
1203
|
+
}
|
|
1204
|
+
const visible = () => snapshot.builds.map((build) => build.slug)
|
|
1205
|
+
const holding = () => (snapshot.capacityBuilds ?? []).map((build) => build.record.slug)
|
|
1206
|
+
const cold = await refresh('cold')
|
|
1207
|
+
expect(cold.rows).toBe(0)
|
|
1208
|
+
expect(visible()).toContain(terminalEscalated)
|
|
1209
|
+
expect(holding()).not.toContain(terminalEscalated)
|
|
1210
|
+
expect(await refresh('idle')).toEqual({
|
|
1211
|
+
calls: { listBuildsChangedSince: 1 },
|
|
1212
|
+
rows: 0,
|
|
1213
|
+
repoRows: 0,
|
|
1214
|
+
})
|
|
1215
|
+
await backing.append(live(2), { actor: KERNEL, type: 'plan.started', payload: { round: 1 } })
|
|
1216
|
+
expect(named((await refresh('change')).calls, live(2))).toBe(true)
|
|
1217
|
+
await acknowledge(terminalEscalated)
|
|
1218
|
+
expect(named((await refresh('acknowledged')).calls, terminalEscalated)).toBe(true)
|
|
1219
|
+
expect(visible()).not.toContain(terminalEscalated)
|
|
1139
1220
|
results[n] = phases
|
|
1140
1221
|
}
|
|
1141
1222
|
expect(results[100_000]).toEqual(results[100]!)
|
|
@@ -1504,7 +1585,9 @@ steps = []
|
|
|
1504
1585
|
|
|
1505
1586
|
/** Script a minute at both launcher cadences using the real runtime reader and
|
|
1506
1587
|
* launcher cache. Each helper gets a fresh facade; private reads use that same
|
|
1507
|
-
* instrumented receiver rather than escaping into an uncounted reducer.
|
|
1588
|
+
* instrumented receiver rather than escaping into an uncounted reducer. The
|
|
1589
|
+
* sibling budgets `upgradeGenerationReadBudget` and `releaseObservationBudget`
|
|
1590
|
+
* cover completed generations and successor release observation. */
|
|
1508
1591
|
export async function upgradeReadBudget(store: BuildStore): Promise<void> {
|
|
1509
1592
|
const { readUpgradeProjection } = await import('../cli/dispatch-handoff')
|
|
1510
1593
|
const { conditionalUpgradeClient } = await import('../cli/dispatch-launch-contract')
|
|
@@ -1621,17 +1704,80 @@ export async function upgradeReadBudget(store: BuildStore): Promise<void> {
|
|
|
1621
1704
|
metrics.reducer = 0
|
|
1622
1705
|
await check()
|
|
1623
1706
|
expect(metrics.reducer).toBeGreaterThan(0)
|
|
1707
|
+
await preparationObservationBudget(store, repo, check, metrics)
|
|
1624
1708
|
}
|
|
1625
|
-
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
/** A durably detected, unresolved preparation earns the launcher's bounded
|
|
1712
|
+
* fast cadence. Each observation stays position-only while nothing changes,
|
|
1713
|
+
* the count is finite, and resolution returns to the idle cadence. */
|
|
1714
|
+
async function preparationObservationBudget(
|
|
1715
|
+
store: BuildStore,
|
|
1716
|
+
repo: string,
|
|
1717
|
+
check: () => Promise<{ preparing?: string }>,
|
|
1718
|
+
metrics: Record<'position' | 'metadata' | 'reducer' | 'events' | 'rows', number>,
|
|
1719
|
+
): Promise<void> {
|
|
1720
|
+
const { supervisionCadence, PREPARATION_OBSERVATION_LIMIT, PREPARATION_OBSERVATION_MS } =
|
|
1721
|
+
await import('../cli/dispatch-launcher-cadence')
|
|
1722
|
+
const { upgradeRuntime, upgradeTarget } = await import('./upgrade-generations')
|
|
1723
|
+
const reset = () => {
|
|
1724
|
+
for (const key of Object.keys(metrics) as (keyof typeof metrics)[]) metrics[key] = 0
|
|
1725
|
+
}
|
|
1726
|
+
const identity = {
|
|
1727
|
+
correlation: `prepare-${repo}`,
|
|
1728
|
+
run: 'budget',
|
|
1729
|
+
lineage: 'budget',
|
|
1730
|
+
from: upgradeRuntime('1.0.0'),
|
|
1731
|
+
target: upgradeTarget('next'),
|
|
1732
|
+
}
|
|
1733
|
+
await store.appendRepo(repo, {
|
|
1734
|
+
actor: DISPATCHER,
|
|
1735
|
+
type: 'dispatcher.upgrade-detected',
|
|
1736
|
+
payload: identity,
|
|
1737
|
+
})
|
|
1738
|
+
reset()
|
|
1739
|
+
const cadence = supervisionCadence()
|
|
1740
|
+
const first = await check()
|
|
1741
|
+
expect(first.preparing).toBe(identity.correlation)
|
|
1742
|
+
expect(metrics.position).toBe(1)
|
|
1743
|
+
expect(metrics.reducer).toBeLessThanOrEqual(1)
|
|
1744
|
+
expect(cadence(first, false)).toBe(PREPARATION_OBSERVATION_MS)
|
|
1745
|
+
reset()
|
|
1746
|
+
const delays: number[] = []
|
|
1747
|
+
for (let i = 0; i < PREPARATION_OBSERVATION_LIMIT; i++) delays.push(cadence(await check(), false))
|
|
1748
|
+
expect(delays.slice(0, -1).every((delay) => delay === PREPARATION_OBSERVATION_MS)).toBe(true)
|
|
1749
|
+
expect(delays.at(-1)).toBe(1_000)
|
|
1750
|
+
expect(metrics).toEqual({
|
|
1751
|
+
position: PREPARATION_OBSERVATION_LIMIT,
|
|
1752
|
+
metadata: 0,
|
|
1753
|
+
reducer: 0,
|
|
1754
|
+
events: 0,
|
|
1755
|
+
rows: 0,
|
|
1756
|
+
})
|
|
1757
|
+
await store.appendRepo(repo, {
|
|
1758
|
+
actor: DISPATCHER,
|
|
1759
|
+
type: 'dispatcher.upgrade-failed',
|
|
1760
|
+
payload: { ...identity, reason: 'budget' },
|
|
1761
|
+
})
|
|
1762
|
+
const failed = await check()
|
|
1763
|
+
expect(failed.preparing).toBeUndefined()
|
|
1764
|
+
expect(cadence(failed, false)).toBe(1_000)
|
|
1765
|
+
reset()
|
|
1766
|
+
for (let i = 0; i < 10; i++) await check()
|
|
1767
|
+
expect(metrics).toEqual({ position: 10, metadata: 0, reducer: 0, events: 0, rows: 0 })
|
|
1626
1768
|
}
|
|
1627
1769
|
|
|
1628
1770
|
/** Completed dispatcher generations must not grow the saved upgrade values or
|
|
1629
1771
|
* the idle cost of any recurring reader: a dispatch tick, a dashboard poll, an
|
|
1630
|
-
* `ab watch` liveness check
|
|
1631
|
-
|
|
1772
|
+
* `ab watch` liveness check, `ab repository status`, one step of the
|
|
1773
|
+
* between-tick yield observation and one step of successor release
|
|
1774
|
+
* observation. */
|
|
1775
|
+
export async function upgradeGenerationReadBudget(): Promise<void> {
|
|
1632
1776
|
const { MemoryBuildStore } = await import('../store/memory')
|
|
1633
1777
|
const { manualClock } = await import('./fixed')
|
|
1634
1778
|
const { readDispatchUpgrade } = await import('../store/reduced-reads')
|
|
1779
|
+
const { observeYield } = await import('../cli/dispatch-yield-observer')
|
|
1780
|
+
const { observeSuccessorRelease } = await import('../cli/dispatch-release-observer')
|
|
1635
1781
|
const { memoryRepositoryReadCounter } = await import('./reduced-read-budget')
|
|
1636
1782
|
const { upgradeGenerationRun, upgradeGenerationWrites, resolutionOnlyWrites } = await import(
|
|
1637
1783
|
'./upgrade-generations'
|
|
@@ -1730,6 +1876,8 @@ async function upgradeGenerationReadBudget(): Promise<void> {
|
|
|
1730
1876
|
dashboard: () => getOperatorDashboard({ store, repo, clock }),
|
|
1731
1877
|
watch,
|
|
1732
1878
|
status,
|
|
1879
|
+
yieldObservation: () => observeYield(store, repo, current, 'budget-correlation', 'launcher'),
|
|
1880
|
+
releaseObservation: () => observeSuccessorRelease(store, repo, current),
|
|
1733
1881
|
}
|
|
1734
1882
|
// The one serialized reduction per key, and each reader's own first
|
|
1735
1883
|
// appends, happen before measurement.
|
|
@@ -1766,6 +1914,79 @@ async function upgradeGenerationReadBudget(): Promise<void> {
|
|
|
1766
1914
|
}
|
|
1767
1915
|
}
|
|
1768
1916
|
|
|
1917
|
+
/** A successor waiting for its predecessor's release observes at the bounded
|
|
1918
|
+
* cadence: a finite fast window, a short backoff, then the idle pause. Every
|
|
1919
|
+
* unchanged observation reads zero event rows and makes the same reduced reads
|
|
1920
|
+
* at any journal length, and the release itself is seen at bounded cost.
|
|
1921
|
+
*
|
|
1922
|
+
* One call observes one `part` of `parts` equal slices of the observation
|
|
1923
|
+
* steps, at both journal lengths; calling every part covers every step. The
|
|
1924
|
+
* cadence schedule and the release itself are asserted in full by every part. */
|
|
1925
|
+
export async function releaseObservationBudget(part: number, parts: number): Promise<void> {
|
|
1926
|
+
if (!Number.isInteger(parts) || parts < 1) throw new Error(`invalid parts ${parts}`)
|
|
1927
|
+
if (!Number.isInteger(part) || part < 0 || part >= parts) throw new Error(`invalid part ${part}`)
|
|
1928
|
+
const { MemoryBuildStore } = await import('../store/memory')
|
|
1929
|
+
const {
|
|
1930
|
+
observeSuccessorRelease,
|
|
1931
|
+
releaseObservationCadence,
|
|
1932
|
+
RELEASE_OBSERVATION_FAST_LIMIT,
|
|
1933
|
+
RELEASE_OBSERVATION_FAST_MS,
|
|
1934
|
+
RELEASE_OBSERVATION_IDLE_MS,
|
|
1935
|
+
} = await import('../cli/dispatch-release-observer')
|
|
1936
|
+
const { memoryRepositoryReadCounter } = await import('./reduced-read-budget')
|
|
1937
|
+
const { upgradeGenerationRun, upgradeGenerationWrites } = await import('./upgrade-generations')
|
|
1938
|
+
const costs = new Map<string, number>()
|
|
1939
|
+
// About 100 and 10,000 filler events before the waiting predecessor.
|
|
1940
|
+
for (const generations of [10, 1_000]) {
|
|
1941
|
+
const repo = '/release-observation-budget'
|
|
1942
|
+
const store = new MemoryBuildStore()
|
|
1943
|
+
await store.ensureRepo(repo)
|
|
1944
|
+
for (let i = 0; i < generations; i++)
|
|
1945
|
+
for (const write of upgradeGenerationWrites(i)) await store.appendRepo(repo, write)
|
|
1946
|
+
const predecessor = upgradeGenerationRun(generations)
|
|
1947
|
+
const writes = upgradeGenerationWrites(generations)
|
|
1948
|
+
// Start, resolve, prepare and request yield; the release is still pending.
|
|
1949
|
+
for (const write of writes.slice(0, 5)) await store.appendRepo(repo, write)
|
|
1950
|
+
const observe = () => observeSuccessorRelease(store, repo, predecessor)
|
|
1951
|
+
expect((await observe()).current?.request).toBeDefined()
|
|
1952
|
+
const counter = memoryRepositoryReadCounter(store, repo)
|
|
1953
|
+
const cadence = releaseObservationCadence()
|
|
1954
|
+
const delays: number[] = []
|
|
1955
|
+
const steps = RELEASE_OBSERVATION_FAST_LIMIT + 4 + 20
|
|
1956
|
+
let observed = 0
|
|
1957
|
+
for (let step = 0; step < steps; step++) {
|
|
1958
|
+
if (Math.floor((step * parts) / steps) === part) {
|
|
1959
|
+
observed++
|
|
1960
|
+
const { current } = await observe()
|
|
1961
|
+
expect(current?.released).toBeUndefined()
|
|
1962
|
+
}
|
|
1963
|
+
delays.push(cadence(0))
|
|
1964
|
+
}
|
|
1965
|
+
expect(observed).toBeGreaterThan(0)
|
|
1966
|
+
expect(counter.rows).toBe(0)
|
|
1967
|
+
expect(counter.reducedCalls % observed).toBe(0)
|
|
1968
|
+
const perStep = counter.reducedCalls / observed
|
|
1969
|
+
if (generations === 10) costs.set('step', perStep)
|
|
1970
|
+
else expect(perStep).toBe(costs.get('step')!)
|
|
1971
|
+
const steady = delays.indexOf(RELEASE_OBSERVATION_IDLE_MS)
|
|
1972
|
+
expect(steady).toBe(RELEASE_OBSERVATION_FAST_LIMIT + 4)
|
|
1973
|
+
expect(delays.slice(0, RELEASE_OBSERVATION_FAST_LIMIT)).toEqual(
|
|
1974
|
+
Array(RELEASE_OBSERVATION_FAST_LIMIT).fill(RELEASE_OBSERVATION_FAST_MS),
|
|
1975
|
+
)
|
|
1976
|
+
expect(delays.slice(RELEASE_OBSERVATION_FAST_LIMIT, steady)).toEqual([50, 100, 200, 400])
|
|
1977
|
+
expect(delays.slice(steady).every((delay) => delay === RELEASE_OBSERVATION_IDLE_MS)).toBe(true)
|
|
1978
|
+
// handoff-started and terminal-released for the waiting correlation.
|
|
1979
|
+
for (const write of writes.slice(5, 7)) await store.appendRepo(repo, write)
|
|
1980
|
+
counter.reset()
|
|
1981
|
+
const { current } = await observe()
|
|
1982
|
+
expect(current?.handoff?.payload.correlation).toBe(`c-${predecessor}`)
|
|
1983
|
+
expect(current?.released?.payload.correlation).toBe(`c-${predecessor}`)
|
|
1984
|
+
if (generations === 10) costs.set('release', counter.rows)
|
|
1985
|
+
else expect(counter.rows).toBe(costs.get('release')!)
|
|
1986
|
+
await store.close()
|
|
1987
|
+
}
|
|
1988
|
+
}
|
|
1989
|
+
|
|
1769
1990
|
/** Measure real ticket-source operations through an injected statement boundary.
|
|
1770
1991
|
* Each fixture is fresh, so a source-local cache cannot conceal target reads.
|
|
1771
1992
|
* Listed rows carry one `closes #1` issue link on even-titled tickets and none
|
|
@@ -2270,6 +2491,59 @@ export async function githubTicketSearchRequestBudget(
|
|
|
2270
2491
|
expect(sequences[1]).toEqual(sequences[0]!)
|
|
2271
2492
|
}
|
|
2272
2493
|
|
|
2494
|
+
export interface TicketPriorityLabelFixture {
|
|
2495
|
+
/** A raw source without native priority. */
|
|
2496
|
+
source: TicketSource
|
|
2497
|
+
/** The ready criteria dispatch lists with. */
|
|
2498
|
+
criteria: import('../ports/types').TicketCriteria
|
|
2499
|
+
/** A seeded ready ticket carrying the `priority:high` label. */
|
|
2500
|
+
highId: string
|
|
2501
|
+
reset(): void
|
|
2502
|
+
/** Provider requests since the last reset, in order. */
|
|
2503
|
+
requests(): string[]
|
|
2504
|
+
}
|
|
2505
|
+
|
|
2506
|
+
/** The label fallback reads priority from data a read already returned: for
|
|
2507
|
+
* every recurring read the raw source offers, at 1 and 100 tickets, the
|
|
2508
|
+
* facade issues exactly the raw source's request sequence (none when the raw
|
|
2509
|
+
* read issues none), so it adds zero requests whatever the raw read costs. A
|
|
2510
|
+
* seeded `priority:high` label reads as `high` and never appears among
|
|
2511
|
+
* `labels`. */
|
|
2512
|
+
export async function ticketPriorityLabelReadBudget(
|
|
2513
|
+
fixture: (population: number) => Promise<TicketPriorityLabelFixture>,
|
|
2514
|
+
): Promise<void> {
|
|
2515
|
+
const { compatibleTicketSource } = await import('../ports/tickets/tree')
|
|
2516
|
+
for (const population of [1, 100]) {
|
|
2517
|
+
const { source, criteria, highId, reset, requests } = await fixture(population)
|
|
2518
|
+
expect(source.priority).toBeFalsy()
|
|
2519
|
+
const facade = compatibleTicketSource(source)
|
|
2520
|
+
expect(facade.priority).toBe(true)
|
|
2521
|
+
const reads: Array<[string, (from: TicketSource) => Promise<unknown>]> = [
|
|
2522
|
+
['listReady', (from) => from.listReady(criteria)],
|
|
2523
|
+
['get', (from) => from.get(highId)],
|
|
2524
|
+
['dependencyStates', (from) => from.dependencyStates([highId])],
|
|
2525
|
+
]
|
|
2526
|
+
if (source.listAll) reads.push(['listAll', (from) => from.listAll!()])
|
|
2527
|
+
if (source.listPage) reads.push(['listPage', (from) => from.listPage!(criteria, { limit: 10 })])
|
|
2528
|
+
for (const [name, read] of reads) {
|
|
2529
|
+
await read(source)
|
|
2530
|
+
reset()
|
|
2531
|
+
await read(source)
|
|
2532
|
+
const raw = requests()
|
|
2533
|
+
reset()
|
|
2534
|
+
await read(facade)
|
|
2535
|
+
expect({ name, requests: requests() }).toEqual({ name, requests: raw })
|
|
2536
|
+
}
|
|
2537
|
+
const high = await facade.get(highId)
|
|
2538
|
+
expect(high?.priority).toBe('high')
|
|
2539
|
+
expect(high?.labels.some((label) => label.toLowerCase().startsWith('priority:'))).toBe(false)
|
|
2540
|
+
const ready = (await facade.listReady(criteria)).tickets.find(
|
|
2541
|
+
(ticket) => ticket.ref.id === highId,
|
|
2542
|
+
)
|
|
2543
|
+
expect(ready?.priority).toBe('high')
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
|
|
2273
2547
|
/** Builds one dispatcher pass's observation inputs for a node build over a
|
|
2274
2548
|
* fresh memory store, reporting which listing path the source decided on
|
|
2275
2549
|
* before the pass; `observe` then observes the node with those inputs. */
|
|
@@ -2593,3 +2867,124 @@ export async function warmRestoreReadBudget(
|
|
|
2593
2867
|
for (const report of reports.slice(1, 3)) expect(report.missing).toEqual(reports[0]!.missing)
|
|
2594
2868
|
return reports
|
|
2595
2869
|
}
|
|
2870
|
+
|
|
2871
|
+
/**
|
|
2872
|
+
* Store calls of every runtime-owned reader command, at 100 and 10,000
|
|
2873
|
+
* journal events. Each reader runs in a fresh process, so its cost per
|
|
2874
|
+
* occurrence is its whole cost:
|
|
2875
|
+
*
|
|
2876
|
+
* - `--read-journal` (once per cold start, once per handoff target for
|
|
2877
|
+
* `supportsRollback`): `ensureRepo` and `getRepo`; 0 event rows, 0 reducer
|
|
2878
|
+
* reads.
|
|
2879
|
+
* - `--read-handoff` without a run or lineage (the install probe, once per
|
|
2880
|
+
* prepared target): opens no store.
|
|
2881
|
+
* - `--read-handoff` with a run and lineage (once per generation exit):
|
|
2882
|
+
* `getRepo` and one `dispatchUpgrade` value, advanced incrementally; an
|
|
2883
|
+
* unprepared run reads no `dispatcherRunFacts`, and an unchanged journal
|
|
2884
|
+
* reads 0 event rows.
|
|
2885
|
+
*
|
|
2886
|
+
* `--read-upgrade` (every 1 s, 250 ms with a pending successor) is bounded by
|
|
2887
|
+
* `upgradeReadBudget`. Nothing here may grow with the journal.
|
|
2888
|
+
*/
|
|
2889
|
+
export async function readerCommandReadBudget(store: BuildStore): Promise<void> {
|
|
2890
|
+
const { readGenerationJournal, readHandoff } = await import('../cli/dispatch-handoff')
|
|
2891
|
+
const { readDispatchUpgrade } = await import('../store/reduced-reads')
|
|
2892
|
+
for (const length of [100, 10_000]) {
|
|
2893
|
+
const repo = `/reader-budget-${length}`
|
|
2894
|
+
await store.ensureRepo(repo)
|
|
2895
|
+
for (let i = 0; i < length; i++)
|
|
2896
|
+
await store.appendRepo(repo, {
|
|
2897
|
+
actor: humanActor('budget'),
|
|
2898
|
+
type: 'dispatcher.intake-set',
|
|
2899
|
+
payload: { enabled: false },
|
|
2900
|
+
})
|
|
2901
|
+
// The saved value exists, as it does after the first reader of this key.
|
|
2902
|
+
await readDispatchUpgrade(store, repo)
|
|
2903
|
+
const launch = {
|
|
2904
|
+
version: 1 as const,
|
|
2905
|
+
runtimeRoot: '/runtime',
|
|
2906
|
+
checkout: repo,
|
|
2907
|
+
journal: { repo, storeRef: '/memory' },
|
|
2908
|
+
run: 'budget',
|
|
2909
|
+
lineage: 'budget',
|
|
2910
|
+
}
|
|
2911
|
+
const counted = countedStore(store)
|
|
2912
|
+
let opened = 0
|
|
2913
|
+
const openStore = () => {
|
|
2914
|
+
opened++
|
|
2915
|
+
return counted.store
|
|
2916
|
+
}
|
|
2917
|
+
|
|
2918
|
+
const journal = await readGenerationJournal(launch, ['dispatch'], {}, { openStore })
|
|
2919
|
+
expect(journal.journal).toEqual({ storeRef: '/memory', repo })
|
|
2920
|
+
expect(counted.take()).toEqual({ calls: ['ensureRepo', 'getRepo'], reducers: [], rows: 0 })
|
|
2921
|
+
|
|
2922
|
+
const probe = { ...launch, run: undefined, lineage: undefined }
|
|
2923
|
+
expect(await readHandoff(probe, ['dispatch'], {}, false, { openStore })).toBeUndefined()
|
|
2924
|
+
expect(opened).toBe(1)
|
|
2925
|
+
|
|
2926
|
+
expect(await readHandoff(launch, ['dispatch'], {}, true, { openStore })).toBeUndefined()
|
|
2927
|
+
expect(counted.take()).toEqual({
|
|
2928
|
+
calls: ['getRepo', 'getReducerValue'],
|
|
2929
|
+
reducers: ['dispatchUpgrade'],
|
|
2930
|
+
rows: 0,
|
|
2931
|
+
})
|
|
2932
|
+
}
|
|
2933
|
+
}
|
|
2934
|
+
|
|
2935
|
+
/** `store` with every method call, requested reducer and event row counted,
|
|
2936
|
+
* including the memory adapter's private reducer-storage slices. */
|
|
2937
|
+
function countedStore(store: BuildStore) {
|
|
2938
|
+
let calls: string[] = []
|
|
2939
|
+
let reducers: string[] = []
|
|
2940
|
+
let rows = 0
|
|
2941
|
+
const counted = new Proxy(store, {
|
|
2942
|
+
get(target, key, receiver) {
|
|
2943
|
+
if (key === 'close') return async () => {}
|
|
2944
|
+
if (key === 'repoState')
|
|
2945
|
+
return (...args: unknown[]) => {
|
|
2946
|
+
const state = Reflect.get(target, key).apply(receiver, args)
|
|
2947
|
+
return new Proxy(state, {
|
|
2948
|
+
get(state, field) {
|
|
2949
|
+
const value = Reflect.get(state, field)
|
|
2950
|
+
if (field !== 'events') return value
|
|
2951
|
+
return new Proxy(value, {
|
|
2952
|
+
get(events, method) {
|
|
2953
|
+
if (method !== 'slice') return Reflect.get(events, method)
|
|
2954
|
+
return (since: number, through: number) => {
|
|
2955
|
+
const sliced = events.slice(since, through)
|
|
2956
|
+
rows += sliced.length
|
|
2957
|
+
return sliced
|
|
2958
|
+
}
|
|
2959
|
+
},
|
|
2960
|
+
})
|
|
2961
|
+
},
|
|
2962
|
+
})
|
|
2963
|
+
}
|
|
2964
|
+
const value = Reflect.get(target, key, receiver)
|
|
2965
|
+
if (typeof value !== 'function' || typeof key !== 'string') return value
|
|
2966
|
+
// Count the store's public reads and writes; the adapter's own private
|
|
2967
|
+
// helpers run unwrapped through the same receiver.
|
|
2968
|
+
if (!/^(get|list|append|put|ensure|create|finish|claim|release)/.test(key))
|
|
2969
|
+
return value.bind(receiver)
|
|
2970
|
+
return async (...args: unknown[]) => {
|
|
2971
|
+
calls.push(key)
|
|
2972
|
+
if (key === 'getReducerValue') reducers.push((args[1] as { reducer: string }).reducer)
|
|
2973
|
+
const result = await value.apply(receiver, args)
|
|
2974
|
+
if ((key === 'getRepoEvents' || key === 'getRepoStateEvents') && Array.isArray(result))
|
|
2975
|
+
rows += result.length
|
|
2976
|
+
return result
|
|
2977
|
+
}
|
|
2978
|
+
},
|
|
2979
|
+
})
|
|
2980
|
+
return {
|
|
2981
|
+
store: counted,
|
|
2982
|
+
take() {
|
|
2983
|
+
const taken = { calls, reducers, rows }
|
|
2984
|
+
calls = []
|
|
2985
|
+
reducers = []
|
|
2986
|
+
rows = 0
|
|
2987
|
+
return taken
|
|
2988
|
+
},
|
|
2989
|
+
}
|
|
2990
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static value-import graph over `packages/core/src` for import-boundary
|
|
3
|
+
* tests. It reads source files, so only integration tests use it. An edge is
|
|
4
|
+
* a static value import, a side-effect import or a value re-export; type-only
|
|
5
|
+
* imports, dynamic `import()` and `typeof import()` are not edges.
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
8
|
+
import { dirname, join, relative, resolve } from 'node:path'
|
|
9
|
+
|
|
10
|
+
export const SRC = resolve(import.meta.dir, '..')
|
|
11
|
+
|
|
12
|
+
/** `path` relative to `packages/core/src`. */
|
|
13
|
+
export const rel = (path: string): string => relative(SRC, path)
|
|
14
|
+
|
|
15
|
+
function resolveSpecifier(from: string, specifier: string): string | undefined {
|
|
16
|
+
if (!specifier.startsWith('.')) return undefined
|
|
17
|
+
const base = resolve(dirname(from), specifier)
|
|
18
|
+
const candidates = /\.(tsx?|json)$/.test(base)
|
|
19
|
+
? [base]
|
|
20
|
+
: [`${base}.ts`, `${base}.tsx`, join(base, 'index.ts')]
|
|
21
|
+
for (const candidate of candidates) if (existsSync(candidate)) return candidate
|
|
22
|
+
throw new Error(`cannot resolve ${specifier} from ${rel(from)}`)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const edgeCache = new Map<string, string[]>()
|
|
26
|
+
const transpiler = new Bun.Transpiler({ loader: 'ts' })
|
|
27
|
+
|
|
28
|
+
/** Modules `path` evaluates at load. */
|
|
29
|
+
export function valueEdges(path: string): string[] {
|
|
30
|
+
const cached = edgeCache.get(path)
|
|
31
|
+
if (cached !== undefined) return cached
|
|
32
|
+
if (path.endsWith('.json')) return []
|
|
33
|
+
const edges = new Set<string>()
|
|
34
|
+
for (const entry of transpiler.scanImports(readFileSync(path, 'utf8'))) {
|
|
35
|
+
if (entry.kind !== 'import-statement') continue
|
|
36
|
+
const target = resolveSpecifier(path, entry.path)
|
|
37
|
+
if (target !== undefined) edges.add(target)
|
|
38
|
+
}
|
|
39
|
+
const result = [...edges]
|
|
40
|
+
edgeCache.set(path, result)
|
|
41
|
+
return result
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Every module `entry` statically evaluates, each mapped to the module that
|
|
45
|
+
* first reached it (breadth-first; the entry maps to `''`). */
|
|
46
|
+
export function staticGraph(entry: string): Map<string, string> {
|
|
47
|
+
const predecessor = new Map<string, string>([[entry, '']])
|
|
48
|
+
const queue = [entry]
|
|
49
|
+
while (queue.length > 0) {
|
|
50
|
+
const current = queue.shift() as string
|
|
51
|
+
for (const next of valueEdges(current)) {
|
|
52
|
+
if (predecessor.has(next)) continue
|
|
53
|
+
predecessor.set(next, current)
|
|
54
|
+
queue.push(next)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return predecessor
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The import chain from the graph's entry to `target`, for failure messages. */
|
|
61
|
+
export function importChain(graph: Map<string, string>, target: string): string {
|
|
62
|
+
const chain: string[] = []
|
|
63
|
+
for (let at = target; at !== ''; at = graph.get(at) ?? '') chain.unshift(rel(at))
|
|
64
|
+
return chain.join(' → ')
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Each excluded module (`src`-relative; a trailing `/` excludes a directory)
|
|
68
|
+
* the entry statically reaches, named by its import chain. */
|
|
69
|
+
export function reachedExclusions(entry: string, excluded: readonly string[]): string[] {
|
|
70
|
+
const graph = staticGraph(join(SRC, entry))
|
|
71
|
+
return [...graph.keys()]
|
|
72
|
+
.filter((path) =>
|
|
73
|
+
excluded.some((name) =>
|
|
74
|
+
name.endsWith('/') ? rel(path).startsWith(name) : rel(path) === name,
|
|
75
|
+
),
|
|
76
|
+
)
|
|
77
|
+
.map((path) => importChain(graph, path))
|
|
78
|
+
}
|
|
@@ -74,11 +74,13 @@ export {
|
|
|
74
74
|
targetedCompletenessParity,
|
|
75
75
|
ticketListReadBudget,
|
|
76
76
|
ticketPageReadBudget,
|
|
77
|
+
ticketPriorityLabelReadBudget,
|
|
77
78
|
ticketSearchReadBudget,
|
|
78
79
|
ticketSearchRequestBudget,
|
|
79
80
|
ticketSearchRows,
|
|
80
81
|
ticketTargetingReadBudget,
|
|
81
82
|
type TicketPageFixture,
|
|
83
|
+
type TicketPriorityLabelFixture,
|
|
82
84
|
type TicketSearchFixture,
|
|
83
85
|
type TicketSearchRequestFixture,
|
|
84
86
|
type TicketSearchRow,
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { PluginFactoryContext } from '../plugins/manifest'
|
|
2
|
+
import { InvocationDeadlineError, withInvocationSignal } from '../processes/invocation-budget'
|
|
3
|
+
|
|
4
|
+
/** A base fetch whose every request stalls until its signal aborts, recording
|
|
5
|
+
* the signal each request carried. No network, no timers. */
|
|
6
|
+
export function stallingFetch(): { base: typeof fetch; signals: (AbortSignal | undefined)[] } {
|
|
7
|
+
const signals: (AbortSignal | undefined)[] = []
|
|
8
|
+
const base = ((_input: unknown, init?: RequestInit) => {
|
|
9
|
+
const signal = init?.signal ?? undefined
|
|
10
|
+
signals.push(signal)
|
|
11
|
+
return new Promise<Response>((_, reject) =>
|
|
12
|
+
signal?.addEventListener('abort', () => reject(signal.reason), { once: true }),
|
|
13
|
+
)
|
|
14
|
+
}) as unknown as typeof fetch
|
|
15
|
+
return { base, signals }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Drive a cooperative plugin through the plugin API 1.12 factory context:
|
|
19
|
+
* inside a work phase it reads `invocationSignal()` and fetches through the
|
|
20
|
+
* host `fetch`; the phase then hits its deadline. Returns what the plugin
|
|
21
|
+
* observed so each port's test can assert the contract. */
|
|
22
|
+
export async function cancelCooperativePluginCall(
|
|
23
|
+
context: PluginFactoryContext,
|
|
24
|
+
signals: (AbortSignal | undefined)[],
|
|
25
|
+
): Promise<{
|
|
26
|
+
seen: AbortSignal | undefined
|
|
27
|
+
requestSignal: AbortSignal | undefined
|
|
28
|
+
error: unknown
|
|
29
|
+
}> {
|
|
30
|
+
const work = new AbortController()
|
|
31
|
+
let seen: AbortSignal | undefined
|
|
32
|
+
const call = withInvocationSignal(work.signal, async () => {
|
|
33
|
+
seen = context.invocationSignal?.()
|
|
34
|
+
return context.fetch!('https://provider.plugin.test/call')
|
|
35
|
+
})
|
|
36
|
+
work.abort(new InvocationDeadlineError('work'))
|
|
37
|
+
const error = await call.then(
|
|
38
|
+
() => undefined,
|
|
39
|
+
(rejection: unknown) => rejection,
|
|
40
|
+
)
|
|
41
|
+
return { seen, requestSignal: signals.at(-1), error }
|
|
42
|
+
}
|