@defrex/autobuild 1.16.0 → 1.18.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.
Files changed (97) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +132 -9
  3. package/docs/answering-blocked-builds.md +34 -1
  4. package/docs/architecture.md +42 -3
  5. package/docs/configuration.md +44 -7
  6. package/docs/dispatcher-hosting.md +5 -3
  7. package/docs/operator-api.md +29 -6
  8. package/docs/plugin-authoring.md +30 -1
  9. package/docs/remote-store-protocol.md +13 -3
  10. package/docs/remote-ticket-protocol.md +37 -2
  11. package/docs/restacking.md +46 -1
  12. package/docs/setup.md +24 -9
  13. package/docs/ticket-sources.md +28 -1
  14. package/docs/troubleshooting.md +54 -2
  15. package/docs/workspaces.md +3 -1
  16. package/package.json +4 -4
  17. package/packages/core/src/cli/accounts.ts +3 -0
  18. package/packages/core/src/cli/binary-direct.ts +14 -1
  19. package/packages/core/src/cli/binary.ts +10 -7
  20. package/packages/core/src/cli/dashboard/refresh.ts +8 -0
  21. package/packages/core/src/cli/dispatch.ts +503 -334
  22. package/packages/core/src/cli/secrets.ts +2 -0
  23. package/packages/core/src/config/schema.ts +17 -3
  24. package/packages/core/src/events/payloads.ts +8 -5
  25. package/packages/core/src/events/repository.ts +37 -1
  26. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/d41044cb2e54809c.json +194 -0
  27. package/packages/core/src/kernel/__snapshots__/reducer-identity-records/e0f89f52e48cbf62.json +197 -0
  28. package/packages/core/src/kernel/engine.ts +118 -0
  29. package/packages/core/src/kernel/reconcile-restack.ts +72 -9
  30. package/packages/core/src/kernel/reducer-revisions.ts +5 -0
  31. package/packages/core/src/kernel/repository-read-facts.ts +9 -2
  32. package/packages/core/src/kernel/ticket-preparation.ts +10 -0
  33. package/packages/core/src/kernel/tracked-dirt.ts +173 -0
  34. package/packages/core/src/ontology.ts +1 -0
  35. package/packages/core/src/operator/index.ts +10 -0
  36. package/packages/core/src/operator/merged-builds.ts +51 -0
  37. package/packages/core/src/operator/registry.ts +254 -110
  38. package/packages/core/src/operator/repo-argument.ts +43 -0
  39. package/packages/core/src/operator/tickets.ts +139 -25
  40. package/packages/core/src/plugin-sdk/index.ts +4 -0
  41. package/packages/core/src/plugins/manifest.ts +1 -1
  42. package/packages/core/src/ports/tickets/completion.ts +71 -0
  43. package/packages/core/src/ports/tickets/contract.ts +73 -0
  44. package/packages/core/src/ports/tickets/github-fake.ts +8 -0
  45. package/packages/core/src/ports/tickets/github-issues.ts +1 -0
  46. package/packages/core/src/ports/tickets/github.ts +18 -6
  47. package/packages/core/src/ports/tickets/grants.ts +2 -0
  48. package/packages/core/src/ports/tickets/hosted-index.ts +8 -0
  49. package/packages/core/src/ports/tickets/linear.ts +18 -2
  50. package/packages/core/src/ports/tickets/remote-protocol.ts +37 -8
  51. package/packages/core/src/ports/tickets/remote.ts +43 -3
  52. package/packages/core/src/ports/tickets/tree.ts +11 -1
  53. package/packages/core/src/ports/types.ts +47 -4
  54. package/packages/core/src/ports/workspace/vercel-command-diagnostics.ts +144 -0
  55. package/packages/core/src/ports/workspace/vercel-sandbox.ts +649 -160
  56. package/packages/core/src/processes/build-child.ts +15 -1
  57. package/packages/core/src/processes/build-runner.ts +349 -20
  58. package/packages/core/src/processes/dispatcher.ts +880 -283
  59. package/packages/core/src/processes/harvest-child.ts +21 -1
  60. package/packages/core/src/processes/harvest-runner.ts +82 -35
  61. package/packages/core/src/processes/pass-stages.ts +32 -6
  62. package/packages/core/src/processes/phase-failure-budget.ts +1 -0
  63. package/packages/core/src/processes/provisioning-progress.ts +23 -0
  64. package/packages/core/src/processes/repo-view.ts +25 -4
  65. package/packages/core/src/processes/workspace-preparation.ts +1 -0
  66. package/packages/core/src/store/adapter.ts +34 -5
  67. package/packages/core/src/store/build-feed.ts +148 -22
  68. package/packages/core/src/store/build-scope.ts +12 -3
  69. package/packages/core/src/store/caller-attribution.ts +170 -0
  70. package/packages/core/src/store/contract.ts +1038 -165
  71. package/packages/core/src/store/local/schema.ts +12 -1
  72. package/packages/core/src/store/local/store.ts +260 -25
  73. package/packages/core/src/store/memory.ts +156 -9
  74. package/packages/core/src/store/phase-session.ts +23 -3
  75. package/packages/core/src/store/reducer-value-shapes.json +8196 -8118
  76. package/packages/core/src/store/remote/client.ts +90 -11
  77. package/packages/core/src/store/remote/credentials.ts +2 -0
  78. package/packages/core/src/store/remote/index.ts +31 -5
  79. package/packages/core/src/store/remote/protocol.ts +45 -8
  80. package/packages/core/src/store/remote/released-clients.json +22 -0
  81. package/packages/core/src/store/remote/released-reducer-values/1.17.0.json +36367 -0
  82. package/packages/core/src/store/remote/released-reducer-values/1.18.0.json +36436 -0
  83. package/packages/core/src/store/remote/released-reducer-values/index.ts +20 -16
  84. package/packages/core/src/store/session-handle.ts +12 -3
  85. package/packages/core/src/store/types.ts +48 -3
  86. package/packages/core/src/testing/dispatch-read-budget.ts +143 -16
  87. package/packages/core/src/testing/index.ts +2 -0
  88. package/packages/core/src/testing/reduced-read-budget.ts +420 -6
  89. package/skills/guide/SKILL.md +67 -13
  90. package/skills/guide/references/operator-api.md +29 -6
  91. package/skills/guide/references/plugin-authoring.md +30 -1
  92. package/skills/guide/references/remote-store-protocol.md +13 -3
  93. package/skills/guide/references/remote-ticket-protocol.md +37 -2
  94. package/skills/guide/references/restacking.md +46 -1
  95. package/skills/guide/references/setup.md +24 -9
  96. package/skills/operate/SKILL.md +42 -4
  97. package/templates/hosted-service/package.json +2 -2
@@ -7,14 +7,16 @@ import release4 from './1.13.0.json'
7
7
  import release5 from './1.14.0.json'
8
8
  import release6 from './1.15.0.json'
9
9
  import release7 from './1.16.0.json'
10
- import release8 from './1.2.0.json'
11
- import release9 from './1.3.0.json'
12
- import release10 from './1.4.0.json'
13
- import release11 from './1.5.0.json'
14
- import release12 from './1.6.0.json'
15
- import release13 from './1.7.0.json'
16
- import release14 from './1.8.0.json'
17
- import release15 from './1.9.0.json'
10
+ import release8 from './1.17.0.json'
11
+ import release9 from './1.18.0.json'
12
+ import release10 from './1.2.0.json'
13
+ import release11 from './1.3.0.json'
14
+ import release12 from './1.4.0.json'
15
+ import release13 from './1.5.0.json'
16
+ import release14 from './1.6.0.json'
17
+ import release15 from './1.7.0.json'
18
+ import release16 from './1.8.0.json'
19
+ import release17 from './1.9.0.json'
18
20
  import type { ReducerValueCatalog } from '../../reducer-value-validation'
19
21
  export interface ReleasedReducerValues extends ReducerValueCatalog {
20
22
  versions: Record<string, number>
@@ -28,12 +30,14 @@ export const RELEASED_REDUCER_VALUES: Readonly<Record<string, ReleasedReducerVal
28
30
  '1.14.0.json': release5,
29
31
  '1.15.0.json': release6,
30
32
  '1.16.0.json': release7,
31
- '1.2.0.json': release8,
32
- '1.3.0.json': release9,
33
- '1.4.0.json': release10,
34
- '1.5.0.json': release11,
35
- '1.6.0.json': release12,
36
- '1.7.0.json': release13,
37
- '1.8.0.json': release14,
38
- '1.9.0.json': release15,
33
+ '1.17.0.json': release8,
34
+ '1.18.0.json': release9,
35
+ '1.2.0.json': release10,
36
+ '1.3.0.json': release11,
37
+ '1.4.0.json': release12,
38
+ '1.5.0.json': release13,
39
+ '1.6.0.json': release14,
40
+ '1.7.0.json': release15,
41
+ '1.8.0.json': release16,
42
+ '1.9.0.json': release17,
39
43
  }
@@ -30,7 +30,7 @@ import type {
30
30
  SubscribeOptions,
31
31
  Unsubscribe,
32
32
  } from './types'
33
- import type { BuildPage, ChangedBuilds } from './types'
33
+ import type { BuildPage, ChangedBuilds, MergedBuildPage } from './types'
34
34
  import type {
35
35
  TicketAsset,
36
36
  TicketAssetInput,
@@ -129,6 +129,9 @@ export function createSessionScopedStore(store: BuildStore, scope: string): Sess
129
129
  listBuildsPage(repo: string): Promise<BuildPage> {
130
130
  return Promise.reject(new SessionScopeError(scope, 'listBuildsPage', repo))
131
131
  },
132
+ listMergedBuildsPage(repo: string): Promise<MergedBuildPage> {
133
+ return Promise.reject(new SessionScopeError(scope, 'listMergedBuildsPage', repo))
134
+ },
132
135
  listBuilds(): Promise<BuildRecord[]> {
133
136
  return Promise.reject(new SessionScopeError(scope, 'listBuilds'))
134
137
  },
@@ -229,7 +232,10 @@ export function createSessionScopedStore(store: BuildStore, scope: string): Sess
229
232
  repo: string,
230
233
  _artifacts: ArtifactInput[],
231
234
  _makeEvent: (deposited: RepositoryArtifactMeta[]) => RepositoryEventWrite<T>,
232
- ): Promise<{ event: RepositoryEventEnvelope<T>; artifacts: RepositoryArtifactMeta[] }> {
235
+ ): Promise<{
236
+ event: RepositoryEventEnvelope<T>
237
+ artifacts: RepositoryArtifactMeta[]
238
+ }> {
233
239
  return Promise.reject(new SessionScopeError(scope, 'appendRepoWithArtifacts', repo))
234
240
  },
235
241
  getRepoEvents(repo: string, _sinceSeq?: number): Promise<RepositoryEvent[]> {
@@ -392,7 +398,10 @@ export function createSessionScopedStore(store: BuildStore, scope: string): Sess
392
398
  id: string,
393
399
  artifacts: ArtifactInput[],
394
400
  makeEvent: (deposited: SessionArtifactMeta[]) => SessionEventWrite<T>,
395
- ): Promise<{ event: SessionEventEnvelope<T>; artifacts: SessionArtifactMeta[] }> {
401
+ ): Promise<{
402
+ event: SessionEventEnvelope<T>
403
+ artifacts: SessionArtifactMeta[]
404
+ }> {
396
405
  own('appendSessionWithArtifacts', id)
397
406
  return store.appendSessionWithArtifacts(id, artifacts, makeEvent)
398
407
  },
@@ -2,7 +2,13 @@ import type { ScanCadence } from './scan-cadence'
2
2
  import type { BoundedEventReads } from './event-reads'
3
3
  import type { OperatorIdentity, OperatorPresence } from './operator-presence'
4
4
  export type { OperatorIdentity, OperatorPresence } from './operator-presence'
5
- import type { BuildPage, BuildPageOptions, ChangedBuilds } from './build-feed'
5
+ import type {
6
+ BuildPage,
7
+ BuildPageOptions,
8
+ ChangedBuilds,
9
+ MergedBuildPage,
10
+ MergedBuildPageOptions,
11
+ } from './build-feed'
6
12
  export type {
7
13
  BuildPage,
8
14
  BuildPageFilters,
@@ -10,6 +16,10 @@ export type {
10
16
  BuildPageOptions,
11
17
  ChangedBuild,
12
18
  ChangedBuilds,
19
+ MergedBuild,
20
+ MergedBuildPage,
21
+ MergedBuildPageOptions,
22
+ MergedBuildTarget,
13
23
  } from './build-feed'
14
24
  import type { ReducerValueRequest, ReducerValue } from './reducer-values'
15
25
  /**
@@ -214,7 +224,11 @@ export interface RepoTickObservation {
214
224
  run: string
215
225
  open?: { startedAt: string }
216
226
  /** Retained across begin, even when the next run has a different holder. */
217
- finished?: RepoTickCompletion & { run: string; startedAt: string; completedAt: string }
227
+ finished?: RepoTickCompletion & {
228
+ run: string
229
+ startedAt: string
230
+ completedAt: string
231
+ }
218
232
  }
219
233
  export interface RepoTickFinish {
220
234
  observation: RepoTickObservation
@@ -418,6 +432,34 @@ export interface BuildStore extends BoundedEventReads {
418
432
  */
419
433
  listBuildsPage(repo: string, opts?: BuildPageOptions): Promise<BuildPage>
420
434
 
435
+ /**
436
+ * One page of `repo`'s merged builds, most recently merged first: merge
437
+ * time descending, then slug descending. Served from the same per-build
438
+ * listing facts as `listBuildsPage`, each written in the same transaction
439
+ * as the event that changes it:
440
+ *
441
+ * - `mergedAt`: the latest `build.completed` envelope `ts` when its outcome
442
+ * is merged; cleared by a non-merged completion or `build.reopened`. Later
443
+ * writes (workspace release, PR-attachment reclaim, escalations) never
444
+ * move it.
445
+ * - `pr`: number and url of the latest `pr.opened` or `finalize.completed`.
446
+ * - `target`: `build.created`'s target, replaced on a node build by each
447
+ * `node.parent-accepted` `next.target` (null clears it).
448
+ * - `kind`: `node` when `build.created` kind is `node`, else `leaf`.
449
+ *
450
+ * `since` is inclusive and `until` exclusive, both on merge time. Records
451
+ * match `listBuildsForRepo` records, including the ticket projection. A
452
+ * cursor is opaque and continues only a request with the same window. A
453
+ * page is one bounded range scan over at most `limit + 1` entries, and reads
454
+ * zero event rows and zero reduced values, whatever the repository's build
455
+ * count, a build's log length, or the writes after its merge. An unknown
456
+ * repository answers `{builds: [], next: null}` and creates no state. An
457
+ * invalid instant, `since` after `until`, a malformed cursor, a cursor of
458
+ * another order or a limit outside 1..100 rejects with
459
+ * `BuildFeedValidationError`. Scoped handles reject.
460
+ */
461
+ listMergedBuildsPage(repo: string, opts?: MergedBuildPageOptions): Promise<MergedBuildPage>
462
+
421
463
  /**
422
464
  * Append one validated event; the store assigns `seq` (per-build,
423
465
  * monotonic, starting at 1) and `ts` (§15.1). Writes must pass
@@ -785,7 +827,10 @@ export interface BuildStore extends BoundedEventReads {
785
827
  id: string,
786
828
  artifacts: ArtifactInput[],
787
829
  makeEvent: (deposited: SessionArtifactMeta[]) => SessionEventWrite<T>,
788
- ): Promise<{ event: SessionEventEnvelope<T>; artifacts: SessionArtifactMeta[] }>
830
+ ): Promise<{
831
+ event: SessionEventEnvelope<T>
832
+ artifacts: SessionArtifactMeta[]
833
+ }>
789
834
  putSessionArtifact(id: string, artifact: ArtifactInput): Promise<SessionArtifactMeta>
790
835
  /** Latest revision when `rev` is omitted; null if kind (or rev) absent. */
791
836
  getSessionArtifact(id: string, kind: string, rev?: number): Promise<SessionArtifact | null>
@@ -2144,35 +2144,74 @@ export async function ticketTargetingReadBudget(
2144
2144
  expect(costs[1]).toEqual(costs[0]!)
2145
2145
  }
2146
2146
 
2147
- /** One fixture per population and listing path: a fresh source over
2148
- * `population` tickets, all in `Ready`, none urgent. `native` is a service
2149
- * answering `list-page`; `fallback` is one predating it. `requests` are the
2150
- * ticket-service operations the source issued since `reset`, with their
2151
- * response sizes; window rows must not vary in size with the population. */
2147
+ /** One fixture per population and listing path. `native` is a service
2148
+ * answering `list-page` with completion criteria; `fallback` is one predating
2149
+ * `list-page`. For population `P` the backing store holds:
2150
+ *
2151
+ * - `P` `Ready` tickets, none urgent, filed one second apart;
2152
+ * - `P` older `Done` tickets completed in 2025, one second apart, every third
2153
+ * labelled `internal`;
2154
+ * - one node `ENG-900000` in `Doing`, titled `TICKET_PAGE_NODE_TITLE`;
2155
+ * - `TICKET_PAGE_RECENT_DONE` (9) recent `Done` tickets completed on
2156
+ * 2026-06-01, one second apart, every third labelled `internal`, all
2157
+ * targeting the node.
2158
+ *
2159
+ * Ids, titles and timestamps are fixed width, so a window's bytes do not
2160
+ * vary with the population. `requests` are the ticket-service operations the
2161
+ * source issued since `reset`, with their response sizes; `rowsExamined` is
2162
+ * the ticket rows the backing store examined since `reset`, across every
2163
+ * statement. */
2152
2164
  export interface TicketPageFixture {
2153
2165
  source: TicketSource
2154
2166
  reset(): void
2155
2167
  statements(): number
2156
2168
  requests(): { operation: string; bytes: number }[]
2169
+ rowsExamined(): number
2157
2170
  }
2158
2171
 
2172
+ /** The node title every `TicketPageFixture` population carries. */
2173
+ export const TICKET_PAGE_NODE_TITLE = 'node 900000'
2174
+ /** Recent done tickets in every `TicketPageFixture` population. */
2175
+ export const TICKET_PAGE_RECENT_DONE = 9
2176
+
2159
2177
  /** A paged operator listing (per operator request and per dashboard page view)
2160
2178
  * through a hosted service that pages natively costs one `list-page` request
2161
2179
  * whose statements are the same, and whose bytes differ only by the width of
2162
2180
  * the total's digits, at 10 and 10,000 tickets. Against a service predating it,
2163
- * the same listing reads every ticket through one `list-ready`. */
2181
+ * the same listing reads every ticket through one `list-ready`.
2182
+ *
2183
+ * A completion digest (per operator or agent request: `since`/`until`,
2184
+ * `excludeLabels`, order `completed`, `summary`) examines the same ticket
2185
+ * rows at 10 and 10,000, across every statement of the request, the
2186
+ * `states` prerequisite included, and reads no event. A range broader than
2187
+ * `TICKET_COMPLETION_SCAN_LIMIT` refuses after examining at most the cap
2188
+ * plus one rows, before any window statement. */
2164
2189
  export async function ticketPageReadBudget(
2165
2190
  fixture: (population: number, mode: 'native' | 'fallback') => Promise<TicketPageFixture>,
2166
2191
  ): Promise<void> {
2167
2192
  const { MemoryBuildStore } = await import('../store/memory')
2168
2193
  const { listOperatorTickets } = await import('../operator/tickets')
2169
2194
  const { ticketsSchema } = await import('../config/schema')
2170
- const tickets = ticketsSchema.parse({ source: 'hosted', teamKey: 'ENG', readyState: 'Ready' })
2195
+ const { TICKET_COMPLETION_SCAN_LIMIT, TicketCompletionRangeTooBroad } = await import(
2196
+ '../ports/tickets/completion'
2197
+ )
2198
+ const tickets = ticketsSchema.parse({
2199
+ source: 'hosted',
2200
+ teamKey: 'ENG',
2201
+ readyState: 'Ready',
2202
+ doneState: 'Done',
2203
+ })
2204
+ const contextFor = async () => ({ repo: 'repo', tickets, teamKey: 'ENG' })
2171
2205
  const populations = [10, 10_000] as const
2206
+ const recent = TICKET_PAGE_RECENT_DONE
2172
2207
  const costs = new Map<string, { statements: number; bytes: number; ids: string[] }>()
2208
+ const digests = new Map<
2209
+ string,
2210
+ { statements: number; bytes: number; stateBytes: number; rows: number; ids: string[] }
2211
+ >()
2173
2212
  for (const mode of ['native', 'fallback'] as const)
2174
2213
  for (const population of populations) {
2175
- const { source, reset, statements, requests } = await fixture(population, mode)
2214
+ const { source, reset, statements, requests, rowsExamined } = await fixture(population, mode)
2176
2215
  if (mode === 'native') expect(source.listPage).toBeDefined()
2177
2216
  else expect(source.listPage).toBeUndefined()
2178
2217
  for (const order of ['oldest', 'newest'] as const) {
@@ -2182,11 +2221,7 @@ export async function ticketPageReadBudget(
2182
2221
  repo: 'repo',
2183
2222
  state: 'Ready',
2184
2223
  page: { limit: 3, offset: 2, order },
2185
- backend: {
2186
- contextFor: async () => ({ repo: 'repo', tickets, teamKey: 'ENG' }),
2187
- sourceFor: () => source,
2188
- statesFor: () => ['Ready'],
2189
- },
2224
+ backend: { contextFor, sourceFor: () => source, statesFor: () => ['Ready'] },
2190
2225
  })
2191
2226
  expect(queue.tickets).toHaveLength(3)
2192
2227
  expect(queue.total).toBe(population)
@@ -2199,6 +2234,80 @@ export async function ticketPageReadBudget(
2199
2234
  ids: queue.tickets.map((ticket) => ticket.ref.id),
2200
2235
  })
2201
2236
  }
2237
+ // The completion digest, with the operator's `states` prerequisite
2238
+ // served by the source as production serves it.
2239
+ const backend = {
2240
+ contextFor,
2241
+ sourceFor: () => source,
2242
+ statesFor: async () =>
2243
+ source.listStates ? (await source.listStates()).map((state) => state.name) : ['Ready'],
2244
+ }
2245
+ for (const window of [
2246
+ { since: '2026-06-01T00:00:00Z', until: '2026-06-02T00:00:00Z' },
2247
+ { since: '2026-01-01T00:00:00Z' },
2248
+ ]) {
2249
+ reset()
2250
+ const counting = countingStore(new MemoryBuildStore())
2251
+ const queue = await listOperatorTickets({
2252
+ store: counting.proxy,
2253
+ repo: 'repo',
2254
+ state: 'Done',
2255
+ ...window,
2256
+ excludeLabels: ['internal'],
2257
+ summary: true,
2258
+ page: { limit: 3, order: 'completed' },
2259
+ backend,
2260
+ })
2261
+ expect(counting.calls).toEqual([])
2262
+ expect(
2263
+ requests()
2264
+ .map((request) => request.operation)
2265
+ .sort(),
2266
+ ).toEqual([mode === 'native' ? 'list-page' : 'list-ready', 'states'])
2267
+ expect(queue.total).toBe(recent - Math.ceil(recent / 3))
2268
+ expect(queue.tickets).toHaveLength(3)
2269
+ const times = queue.tickets.map((ticket) => Date.parse(ticket.resolvedAt!))
2270
+ for (let i = 1; i < times.length; i++) expect(times[i]!).toBeLessThan(times[i - 1]!)
2271
+ for (const ticket of queue.tickets) {
2272
+ expect('body' in ticket).toBe(false)
2273
+ expect(ticket.labels).not.toContain('internal')
2274
+ expect(ticket.targetTitle).toBe(TICKET_PAGE_NODE_TITLE)
2275
+ }
2276
+ const bytesOf = (states: boolean) =>
2277
+ requests()
2278
+ .filter((request) => (request.operation === 'states') === states)
2279
+ .reduce((total, request) => total + request.bytes, 0)
2280
+ digests.set(`${mode}:${population}:${window.until ?? 'open'}`, {
2281
+ statements: statements(),
2282
+ bytes: bytesOf(false),
2283
+ stateBytes: bytesOf(true),
2284
+ rows: rowsExamined(),
2285
+ ids: queue.tickets.map((ticket) => ticket.ref.id),
2286
+ })
2287
+ }
2288
+ if (mode !== 'native') continue
2289
+ // A range holding more rows than the cap: refused after the capped count
2290
+ // scan. A window statement would examine another capped scan, so an exact
2291
+ // row count of cap + 1 also proves no window ran.
2292
+ reset()
2293
+ const broad = listOperatorTickets({
2294
+ store: new MemoryBuildStore(),
2295
+ repo: 'repo',
2296
+ state: 'Done',
2297
+ since: '2025-01-01T00:00:00Z',
2298
+ page: { limit: 3, order: 'completed' },
2299
+ backend,
2300
+ })
2301
+ if (population + recent > TICKET_COMPLETION_SCAN_LIMIT) {
2302
+ const refusal = await broad.catch((error: unknown) => error)
2303
+ expect(refusal).toBeInstanceOf(TicketCompletionRangeTooBroad)
2304
+ expect((refusal as InstanceType<typeof TicketCompletionRangeTooBroad>).limit).toBe(
2305
+ TICKET_COMPLETION_SCAN_LIMIT,
2306
+ )
2307
+ expect(rowsExamined()).toBe(TICKET_COMPLETION_SCAN_LIMIT + 1)
2308
+ } else {
2309
+ expect((await broad).total).toBe(population + recent)
2310
+ }
2202
2311
  }
2203
2312
  const digits = String(populations[1]).length - String(populations[0]).length
2204
2313
  for (const order of ['oldest', 'newest'] as const) {
@@ -2212,6 +2321,23 @@ export async function ticketPageReadBudget(
2212
2321
  expect(fallback.ids).toEqual(large.ids)
2213
2322
  expect(fallback.bytes).toBeGreaterThan(large.bytes * 100)
2214
2323
  }
2324
+ for (const until of ['2026-06-02T00:00:00Z', 'open']) {
2325
+ const small = digests.get(`native:${populations[0]}:${until}`)!
2326
+ const large = digests.get(`native:${populations[1]}:${until}`)!
2327
+ expect(large.statements).toBe(small.statements)
2328
+ // The page's total is the same at both sizes; the `states` answer differs
2329
+ // only by the digits of its per-state counts.
2330
+ expect(large.bytes).toBe(small.bytes)
2331
+ expect(large.stateBytes - small.stateBytes).toBeLessThanOrEqual(digits * 5)
2332
+ // The capped count scan and the window each examine the range only:
2333
+ // unrelated older done and ready rows never enter any statement.
2334
+ expect(small.rows).toBe(2 * recent)
2335
+ expect(large.rows).toBe(2 * recent)
2336
+ const fallback = digests.get(`fallback:${populations[1]}:${until}`)!
2337
+ expect(fallback.ids).toEqual(large.ids)
2338
+ expect(fallback.rows).toBeGreaterThanOrEqual(large.rows * 100)
2339
+ expect(fallback.bytes).toBeGreaterThan(large.bytes * 100)
2340
+ }
2215
2341
  }
2216
2342
 
2217
2343
  /** One ticket of a search-budget population: fixed-width id and title, a body
@@ -2246,9 +2372,10 @@ export function ticketSearchRows(population: number): TicketSearchRow[] {
2246
2372
  })
2247
2373
  }
2248
2374
 
2249
- /** Same shape as `TicketPageFixture`: a fresh source over `tickets`;
2250
- * `native` is a service answering `search`, `predating` one without it. */
2251
- export type TicketSearchFixture = TicketPageFixture
2375
+ /** Same shape as `TicketPageFixture` without row accounting: a fresh source
2376
+ * over `tickets`; `native` is a service answering `search`, `predating` one
2377
+ * without it. */
2378
+ export type TicketSearchFixture = Omit<TicketPageFixture, 'rowsExamined'>
2252
2379
 
2253
2380
  /** A search page (per operator or agent request) through a hosted service
2254
2381
  * that searches costs exactly one `search` request and one bounded statement,
@@ -74,6 +74,8 @@ export {
74
74
  targetedCompletenessParity,
75
75
  ticketListReadBudget,
76
76
  ticketPageReadBudget,
77
+ TICKET_PAGE_NODE_TITLE,
78
+ TICKET_PAGE_RECENT_DONE,
77
79
  ticketPriorityLabelReadBudget,
78
80
  ticketSearchReadBudget,
79
81
  ticketSearchRequestBudget,