@attalabs/vinaya 0.37.0 → 0.38.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/aeg-root/enforcement.md +5 -4
- package/aeg-root/roles/developer/reference.md +24 -22
- package/aeg-root/roles/developer.md +4 -4
- package/aeg-root/roles/planner/reference.md +11 -0
- package/aeg-root/roles/reviewer.md +5 -3
- package/aeg-root/roles/security.md +3 -2
- package/aeg-root/state-machine.md +1 -1
- package/aeg-root/templates/brief-template.md +4 -4
- package/aeg-root/tranche-model.md +6 -0
- package/dist/checks/bin/check-body-bare-digits.js +139 -12
- package/dist/checks/bin/check-branch-topology.js +171 -13
- package/dist/checks/bin/check-brief-shape.js +139 -12
- package/dist/checks/bin/check-changeset-coverage.js +177 -17
- package/dist/checks/bin/check-closes-n.js +171 -13
- package/dist/checks/bin/check-coherence.js +171 -13
- package/dist/checks/bin/check-dead-branch-push.js +139 -12
- package/dist/checks/bin/check-dispatch-readiness.js +195 -23
- package/dist/checks/bin/check-doc-coverage-push.js +173 -13
- package/dist/checks/bin/check-doc-coverage.js +180 -13
- package/dist/checks/bin/check-doctrine-no-procedures.js +139 -12
- package/dist/checks/bin/check-doctrine-portability.js +173 -13
- package/dist/checks/bin/check-evidence-fresh.js +173 -13
- package/dist/checks/bin/check-exec-bits.js +173 -13
- package/dist/checks/bin/check-first-push-dispatch.js +171 -13
- package/dist/checks/bin/check-issue-assignment.js +171 -13
- package/dist/checks/bin/check-issue-milestone-attach.js +139 -12
- package/dist/checks/bin/check-issue-objectives-numbering.js +139 -12
- package/dist/checks/bin/check-issue-parts-coverage.js +139 -12
- package/dist/checks/bin/check-issue-surface-globs.js +171 -13
- package/dist/checks/bin/check-issue-title-grammar.js +139 -12
- package/dist/checks/bin/check-issue-tranche-label.js +139 -12
- package/dist/checks/bin/check-main-branch-refusal.js +139 -12
- package/dist/checks/bin/check-no-disk-state.js +139 -12
- package/dist/checks/bin/check-pr-premise-reassert.js +139 -12
- package/dist/checks/bin/check-pr-report-density.js +139 -12
- package/dist/checks/bin/check-principal-test-plan-wait.js +139 -12
- package/dist/checks/bin/check-quoted-command.js +173 -13
- package/dist/checks/bin/check-reader-resolvable-prose.js +173 -13
- package/dist/checks/bin/check-registry-gates.js +406 -68
- package/dist/checks/bin/check-retired-vocabulary.js +173 -13
- package/dist/checks/bin/check-review-gate.js +139 -12
- package/dist/checks/bin/check-single-plan-pr.js +139 -12
- package/dist/checks/bin/check-surface-scope.js +171 -13
- package/dist/checks/bin/check-test-plan.js +139 -12
- package/dist/checks/bin/check-token-collection-wired.js +139 -12
- package/dist/checks/bin/check-workspace-escape.js +173 -13
- package/dist/checks/bin/verify-dispatch.js +3849 -0
- package/dist/index.js +7348 -2095
- package/dist/lib/pre-push-cache-test-run.js +42 -2
- package/dist/lib/pre-push-changed-files.js +16 -11
- package/dist/lib/pre-push-select-tests.js +177 -21
- package/package.json +1 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/anchored-region.ts +7 -6
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-render.ts +33 -15
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-validation.ts +51 -12
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/index.ts +1 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/local.ts +31 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/records.ts +31 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/assess-round.ts +214 -24
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/fakes.ts +11 -3
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/index.ts +5 -4
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/journal-reconstruction.ts +13 -13
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/render-summary.ts +46 -145
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/types.ts +63 -14
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/index.ts +3 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/published-prose.ts +30 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doctrine-portability.ts +6 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/gate-audience.ts +0 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/index.ts +56 -7
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-validation.ts +7 -7
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/leftover-detection.ts +24 -6
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/custom.ts +157 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/envelope.ts +44 -6
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/fixtures/executions.ts +493 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/fixtures/fact-sheets.ts +111 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/fixtures/generator.ts +155 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/fixtures/index.ts +12 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/index.ts +128 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/catches.ts +63 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/checks.ts +146 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/common.ts +137 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/completion.ts +137 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/convergence.ts +420 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/determinism.ts +65 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/index.ts +69 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/judgment.ts +132 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/labels.ts +21 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/time.ts +167 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/usage.ts +139 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/schema.ts +219 -15
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/store.ts +7 -7
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/cache-contract.ts +207 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/contracts.ts +105 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/engine.ts +308 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/index.ts +34 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/measured.ts +20 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/memory-cache.ts +78 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/normalize.ts +156 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/row.ts +103 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/reader-resolvable-prose.ts +34 -6
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/registry-checks.ts +70 -6
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-input-manifest.ts +19 -14
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-policy.ts +38 -3
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-status.ts +5 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-phase-history.ts +46 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-tools.ts +15 -28
- package/studio-standalone/apps/vinaya-studio/web/.next/BUILD_ID +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/build-manifest.json +3 -3
- package/studio-standalone/apps/vinaya-studio/web/.next/prerender-manifest.json +3 -3
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.html +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page/server-reference-manifest.json +3 -3
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/1q96_modules_@clerk_nextjs_dist_esm_app-router_client_keyless-creator-reader_0lom2js.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__04adkz-._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__08e39jo._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0h9yhwx._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__14ui9sz._.js → [root-of-the-server]__0jdjsxe._.js} +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0ls23oh._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1gjqmhq._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1wc4-ip._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_08onyya._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_096f46i._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0af2one._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0e5tkdd._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0kf2g72._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0zf4d27._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1-wo68i._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1achbh9._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/node_modules_@clerk_nextjs_dist_esm_app-router_server-actions_1x7vfhn.js +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/middleware-build-manifest.js +3 -3
- package/studio-standalone/apps/vinaya-studio/web/.next/server/pages/500.html +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.json +4 -4
- package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/1-acpmtfmrc35.js +1 -0
- package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{3qtt1v3ya-ofe.js → 2f2y8xxok8zph.js} +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{3l56x8wjdzvaw.js → 2xevgia1h8g0y.js} +4 -4
- package/studio-standalone/apps/vinaya-studio/web/package.json +2 -2
- package/dist/checks/bin/check-token-report.js +0 -6526
- package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0vtfb0g813gki.js +0 -1
- /package/studio-standalone/apps/vinaya-studio/web/.next/static/{yR5RsCxb1OGnYggiaO09S → yNZEFRSjP9BLUfdf96Eol}/_buildManifest.js +0 -0
- /package/studio-standalone/apps/vinaya-studio/web/.next/static/{yR5RsCxb1OGnYggiaO09S → yNZEFRSjP9BLUfdf96Eol}/_clientMiddlewareManifest.js +0 -0
- /package/studio-standalone/apps/vinaya-studio/web/.next/static/{yR5RsCxb1OGnYggiaO09S → yNZEFRSjP9BLUfdf96Eol}/_ssgManifest.js +0 -0
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
* same thing) or `2` (adds `event_id`, `process_id`, `lineage`,
|
|
17
17
|
* `input_versions`, `provenance` — O1's "task/run/attempt/parent lineage,
|
|
18
18
|
* producer sequence, opaque role and process identifiers, input versions
|
|
19
|
-
* and trust provenance")
|
|
20
|
-
*
|
|
19
|
+
* and trust provenance") or `3` (adds `work`, `flow`, `runtime`, `source`).
|
|
20
|
+
* `buildHeader` (`envelope.ts`) builds `3` for every event; `1` and `2`
|
|
21
|
+
* exist so a line already on disk
|
|
21
22
|
* (or a fixture recorded before this task) keeps parsing, never a schema
|
|
22
23
|
* violation just because it predates these fields (O1's "compatible").
|
|
23
24
|
* Absent per-field data on a `2` header is `null`, never invented — the
|
|
@@ -43,6 +44,14 @@
|
|
|
43
44
|
*/
|
|
44
45
|
|
|
45
46
|
import { z } from 'zod'
|
|
47
|
+
import {
|
|
48
|
+
CUSTOM_EVENT_MAX_FIELDS,
|
|
49
|
+
CUSTOM_EVENT_NAME_MAX_LENGTH,
|
|
50
|
+
CUSTOM_EVENT_NAME_PATTERN,
|
|
51
|
+
CUSTOM_FIELD_NAME_MAX_LENGTH,
|
|
52
|
+
CUSTOM_FIELD_NAME_PATTERN,
|
|
53
|
+
CUSTOM_TEXT_MAX_LENGTH
|
|
54
|
+
} from './custom'
|
|
46
55
|
|
|
47
56
|
/**
|
|
48
57
|
* The one bound shared by `gate_result_read.confidence_reason` below and the
|
|
@@ -146,10 +155,58 @@ const HeaderMetaV2Schema = z
|
|
|
146
155
|
})
|
|
147
156
|
.strict()
|
|
148
157
|
|
|
149
|
-
|
|
150
|
-
|
|
158
|
+
/** The unit of work an event belongs to (schema 3). `ref` is opaque — an Issue number as text, a ticket key, a branch name; the log never parses it. Each part is `null` until a caller names it, never guessed. */
|
|
159
|
+
const WorkSchema = z
|
|
160
|
+
.object({
|
|
161
|
+
ref: z.string().nullable(),
|
|
162
|
+
repo: z.string().nullable(),
|
|
163
|
+
change: z.string().nullable(),
|
|
164
|
+
revision: z.string().nullable()
|
|
165
|
+
})
|
|
166
|
+
.strict()
|
|
167
|
+
|
|
168
|
+
/** The way of working an event belongs to (schema 3): an opaque id and a version. Vinaya's own process reads `id: 'vinaya'`; a foreign one names itself or stays `null`. */
|
|
169
|
+
const FlowSchema = z
|
|
170
|
+
.object({
|
|
171
|
+
id: z.string().nullable(),
|
|
172
|
+
version: z.string().nullable()
|
|
173
|
+
})
|
|
174
|
+
.strict()
|
|
175
|
+
|
|
176
|
+
/** Schema 3 = every schema 2 field, unchanged, plus `work`, `flow`, `runtime` and `source`. A new version rather than extra fields on 2: a server that knows only 1 and 2 keeps a 3 line as an unknown-version record, where an extra field on 2 would be rejected as invalid. */
|
|
177
|
+
const HeaderMetaV3Schema = z
|
|
178
|
+
.object({
|
|
179
|
+
schema: z.literal(3),
|
|
180
|
+
...headerMetaCore,
|
|
181
|
+
event_id: z.string().min(1),
|
|
182
|
+
process_id: z.string().min(1),
|
|
183
|
+
actor_id: z.string().nullable(),
|
|
184
|
+
lineage: LineageSchema,
|
|
185
|
+
input_versions: InputVersionsSchema,
|
|
186
|
+
provenance: ProvenanceSchema,
|
|
187
|
+
work: WorkSchema,
|
|
188
|
+
flow: FlowSchema,
|
|
189
|
+
runtime: z.string().nullable(),
|
|
190
|
+
source: z.string().nullable()
|
|
191
|
+
})
|
|
192
|
+
.strict()
|
|
193
|
+
|
|
194
|
+
const HeaderMetaSchema = z.discriminatedUnion('schema', [HeaderMetaV1Schema, HeaderMetaV2Schema, HeaderMetaV3Schema])
|
|
195
|
+
export {
|
|
196
|
+
HeaderMetaV1Schema,
|
|
197
|
+
HeaderMetaV2Schema,
|
|
198
|
+
HeaderMetaV3Schema,
|
|
199
|
+
WorkSchema,
|
|
200
|
+
FlowSchema,
|
|
201
|
+
LineageSchema,
|
|
202
|
+
InputVersionsSchema,
|
|
203
|
+
ProvenanceSchema
|
|
204
|
+
}
|
|
151
205
|
export type HeaderMetaV1 = z.infer<typeof HeaderMetaV1Schema>
|
|
152
206
|
export type HeaderMetaV2 = z.infer<typeof HeaderMetaV2Schema>
|
|
207
|
+
export type HeaderMetaV3 = z.infer<typeof HeaderMetaV3Schema>
|
|
208
|
+
export type Work = z.infer<typeof WorkSchema>
|
|
209
|
+
export type Flow = z.infer<typeof FlowSchema>
|
|
153
210
|
export type Lineage = z.infer<typeof LineageSchema>
|
|
154
211
|
export type InputVersions = z.infer<typeof InputVersionsSchema>
|
|
155
212
|
export type Provenance = z.infer<typeof ProvenanceSchema>
|
|
@@ -300,8 +357,29 @@ export const DispatchEventSchema = z.discriminatedUnion('event', [
|
|
|
300
357
|
export type DispatchEvent = z.infer<typeof DispatchEventSchema>
|
|
301
358
|
|
|
302
359
|
// ---------------------------------------------------------------------------
|
|
303
|
-
// `dev_review_loop` family (§5.2) —
|
|
304
|
-
//
|
|
360
|
+
// `dev_review_loop` family (§5.2) — `loop_id` shared on each. Later
|
|
361
|
+
// additions widened it past the spec's original set: `cancelled`,
|
|
362
|
+
// `infrastructure_retry`, and the `driver_heartbeat`/`driver_exited`
|
|
363
|
+
// liveness pair that lets a reader tell a running loop from a dead one.
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* A short code token: letters, digits, dot, dash, underscore, 64 characters
|
|
367
|
+
* at most. The shape carries no path separator, no whitespace and no room for
|
|
368
|
+
* a sentence, so a pause code or an error class can never hold a path or a
|
|
369
|
+
* message. Used by `paused.reason_code` and `driver_exited.error_class`.
|
|
370
|
+
*/
|
|
371
|
+
export const CODE_TOKEN_PATTERN = /^[A-Za-z0-9._-]{1,64}$/
|
|
372
|
+
const CodeTokenSchema = z.string().regex(CODE_TOKEN_PATTERN)
|
|
373
|
+
|
|
374
|
+
/** One reviewer role's outcome in a round's `verdicts_read`: the role, one of three words, and how many blocking verdicts it contributed (0 or 1). */
|
|
375
|
+
const ReviewerVerdictSchema = z
|
|
376
|
+
.object({
|
|
377
|
+
role: RoleSchema,
|
|
378
|
+
outcome: z.enum(['approve', 'changes_requested', 'not_reviewed']),
|
|
379
|
+
blockers: z.number().int().nonnegative()
|
|
380
|
+
})
|
|
381
|
+
.strict()
|
|
382
|
+
export type ReviewerVerdict = z.infer<typeof ReviewerVerdictSchema>
|
|
305
383
|
|
|
306
384
|
const loopShared = {
|
|
307
385
|
meta: HeaderMetaSchema,
|
|
@@ -370,7 +448,12 @@ export const DevReviewLoopEventSchema = z.discriminatedUnion('event', [
|
|
|
370
448
|
// — a schema change is additive here, never a reason an old line on
|
|
371
449
|
// disk starts reading as corrupt. This task's own producer
|
|
372
450
|
// (`assess-round.ts`) always sets it explicitly, `[]` included.
|
|
373
|
-
findings: z.array(ReviewFindingSchema).optional()
|
|
451
|
+
findings: z.array(ReviewFindingSchema).optional(),
|
|
452
|
+
// One entry per reviewer role the loop held or expected a verdict from,
|
|
453
|
+
// so a reader tells a role that approved with no findings from one that
|
|
454
|
+
// never reported. The entries' `blockers` add up to `blockers` above.
|
|
455
|
+
// Optional: a line recorded before it existed still parses.
|
|
456
|
+
reviewers: z.array(ReviewerVerdictSchema).optional()
|
|
374
457
|
})
|
|
375
458
|
.strict(),
|
|
376
459
|
z
|
|
@@ -399,6 +482,9 @@ export const DevReviewLoopEventSchema = z.discriminatedUnion('event', [
|
|
|
399
482
|
// consecutive attempts ending on the same mechanical failure, are each
|
|
400
483
|
// their own condition too — never folded into `no_progress`, whose own
|
|
401
484
|
// (removed) rule paused on any round that resolved nothing.
|
|
485
|
+
// `time_budget` widens it once more, and is the only member that counts
|
|
486
|
+
// neither rounds nor findings: the task's wall clock passed its
|
|
487
|
+
// configured budget, whatever the time went to.
|
|
402
488
|
condition: z.enum([
|
|
403
489
|
'green',
|
|
404
490
|
'max_rounds',
|
|
@@ -408,7 +494,8 @@ export const DevReviewLoopEventSchema = z.discriminatedUnion('event', [
|
|
|
408
494
|
'confidence',
|
|
409
495
|
'reappearance',
|
|
410
496
|
'repeat_finding',
|
|
411
|
-
'repeat_failure'
|
|
497
|
+
'repeat_failure',
|
|
498
|
+
'time_budget'
|
|
412
499
|
])
|
|
413
500
|
})
|
|
414
501
|
.strict(),
|
|
@@ -417,7 +504,12 @@ export const DevReviewLoopEventSchema = z.discriminatedUnion('event', [
|
|
|
417
504
|
...loopShared,
|
|
418
505
|
event: z.literal('paused'),
|
|
419
506
|
round: z.number().int(),
|
|
420
|
-
reason: z.enum(['escalation', 'principal_item', 'refreeze_needed'])
|
|
507
|
+
reason: z.enum(['escalation', 'principal_item', 'refreeze_needed']),
|
|
508
|
+
// The loop's own pause reason code (`confidence`, `max_rounds`,
|
|
509
|
+
// `infrastructure`, …) as a short string, never prose and never a closed
|
|
510
|
+
// list: a new pause reason needs no schema change. Optional: a line
|
|
511
|
+
// recorded before it existed still parses.
|
|
512
|
+
reason_code: CodeTokenSchema.optional()
|
|
421
513
|
})
|
|
422
514
|
.strict(),
|
|
423
515
|
z
|
|
@@ -518,6 +610,53 @@ export const DevReviewLoopEventSchema = z.discriminatedUnion('event', [
|
|
|
518
610
|
attempts: z.number().int().positive(),
|
|
519
611
|
outcome: z.enum(['recovered', 'exhausted'])
|
|
520
612
|
})
|
|
613
|
+
.strict(),
|
|
614
|
+
// (O1/O3) A liveness ping the driver emits at most every five
|
|
615
|
+
// minutes while its process is alive — the Log's one positive signal that
|
|
616
|
+
// a loop is running, as opposed to finished, paused or dead. Before it, a
|
|
617
|
+
// loop in its first Developer turn and one that died before pushing both
|
|
618
|
+
// looked identical from the Log (`loop_started` with nothing after). A NEW,
|
|
619
|
+
// additive member: a line written before this task carries none of these
|
|
620
|
+
// fields and parses exactly as it always did. `task` is the task Issue
|
|
621
|
+
// (the same number `subject.issue` carries, repeated here so a reader has
|
|
622
|
+
// it without resolving the envelope); `pr` is the pull request once one
|
|
623
|
+
// exists (absent on a first turn before any PR has opened); `round` and
|
|
624
|
+
// `phase` are the loop's current round and phase (`phase` the same
|
|
625
|
+
// free-form string the control store's own `loop_state.phase` carries —
|
|
626
|
+
// `dispatch_developer`, `publish`, `pause`, …). The machine it runs on is
|
|
627
|
+
// `meta.machine`, on every line already.
|
|
628
|
+
z
|
|
629
|
+
.object({
|
|
630
|
+
...loopShared,
|
|
631
|
+
event: z.literal('driver_heartbeat'),
|
|
632
|
+
task: z.number().int(),
|
|
633
|
+
pr: z.number().int().positive().optional(),
|
|
634
|
+
round: z.number().int(),
|
|
635
|
+
phase: z.string()
|
|
636
|
+
})
|
|
637
|
+
.strict(),
|
|
638
|
+
// (O2/O3) Emitted exactly once when a review-loop driver process
|
|
639
|
+
// ends, on every exit path the driver already traces in its role log
|
|
640
|
+
// (a re-exec hand-off, an uncaught error, an OS signal) plus a normal
|
|
641
|
+
// return (a clean `publish` is `finished`, a decided pause is `paused`).
|
|
642
|
+
// The twin of `driver_heartbeat` above: a heartbeat says "still alive," a
|
|
643
|
+
// `driver_exited` says "stopped, and why." `last_decision` is the driver's
|
|
644
|
+
// last decision in the same form its role-log line records it — `publish`,
|
|
645
|
+
// or `pause(<reason>)`. A NEW, additive member; an earlier line parses
|
|
646
|
+
// unchanged.
|
|
647
|
+
z
|
|
648
|
+
.object({
|
|
649
|
+
...loopShared,
|
|
650
|
+
event: z.literal('driver_exited'),
|
|
651
|
+
task: z.number().int(),
|
|
652
|
+
reason: z.enum(['finished', 'paused', 'reexec', 'error', 'signal']),
|
|
653
|
+
last_decision: z.string(),
|
|
654
|
+
// The process exit code when the driver ends with one, and — when it
|
|
655
|
+
// ends on an error — the error's own code or constructor name, never its
|
|
656
|
+
// message. Both optional: a line recorded before them still parses.
|
|
657
|
+
exit_code: z.number().int().optional(),
|
|
658
|
+
error_class: CodeTokenSchema.optional()
|
|
659
|
+
})
|
|
521
660
|
.strict()
|
|
522
661
|
])
|
|
523
662
|
export type DevReviewLoopEvent = z.infer<typeof DevReviewLoopEventSchema>
|
|
@@ -566,7 +705,8 @@ export const ForgeWriteEventSchema = z.discriminatedUnion('event', [
|
|
|
566
705
|
export type ForgeWriteEvent = z.infer<typeof ForgeWriteEventSchema>
|
|
567
706
|
|
|
568
707
|
// ---------------------------------------------------------------------------
|
|
569
|
-
// `gate` family (O2) — one gate runner's
|
|
708
|
+
// `gate` family (O2) — one gate runner's check run: a `summary` per run and a
|
|
709
|
+
// `checked` event for each check that did not pass. `loop` (the
|
|
570
710
|
// spec's "loop coordinator") is already typed by `dev_review_loop` above;
|
|
571
711
|
// this task does not introduce a second loop schema for it.
|
|
572
712
|
|
|
@@ -601,6 +741,27 @@ export const GateEventSchema = z.discriminatedUnion('event', [
|
|
|
601
741
|
outcome: GateOutcomeSchema,
|
|
602
742
|
reason: z.string().optional()
|
|
603
743
|
})
|
|
744
|
+
.strict(),
|
|
745
|
+
// One per check run. A run records this and a `checked` event only for a
|
|
746
|
+
// check that did not pass, so the Log's volume tracks failures, not the
|
|
747
|
+
// number of checks. `ran` counts the checks that executed (`passed` +
|
|
748
|
+
// `failed`); `skipped` are not in it. `failed` is every executed check that
|
|
749
|
+
// did not pass — a failure, a wait, a timeout or an error — and
|
|
750
|
+
// `failed_checks` names them. The run's total time is the envelope's
|
|
751
|
+
// `duration_ms`.
|
|
752
|
+
z
|
|
753
|
+
.object({
|
|
754
|
+
meta: HeaderMetaSchema,
|
|
755
|
+
subject: SubjectSchema,
|
|
756
|
+
kind: z.literal('gate'),
|
|
757
|
+
...envelopeTail,
|
|
758
|
+
event: z.literal('summary'),
|
|
759
|
+
ran: z.number().int().nonnegative(),
|
|
760
|
+
passed: z.number().int().nonnegative(),
|
|
761
|
+
failed: z.number().int().nonnegative(),
|
|
762
|
+
skipped: z.number().int().nonnegative(),
|
|
763
|
+
failed_checks: z.array(z.string())
|
|
764
|
+
})
|
|
604
765
|
.strict()
|
|
605
766
|
])
|
|
606
767
|
export type GateEvent = z.infer<typeof GateEventSchema>
|
|
@@ -628,7 +789,12 @@ export const OperationEventSchema = z.discriminatedUnion('event', [
|
|
|
628
789
|
...operationShared,
|
|
629
790
|
event: z.literal('completed'),
|
|
630
791
|
result: OperationResultSchema,
|
|
631
|
-
error_class: z.string().nullable()
|
|
792
|
+
error_class: z.string().nullable(),
|
|
793
|
+
// The field NAMES an operation's outcome concerns — a refused `custom`
|
|
794
|
+
// event's missing, extra or mistyped fields — never their values,
|
|
795
|
+
// since a rejected value may be the secret. Optional: no other
|
|
796
|
+
// operation sets it, and a line written before it existed still parses.
|
|
797
|
+
field_names: z.array(z.string().max(CUSTOM_FIELD_NAME_MAX_LENGTH)).max(CUSTOM_EVENT_MAX_FIELDS).optional()
|
|
632
798
|
})
|
|
633
799
|
.strict()
|
|
634
800
|
])
|
|
@@ -756,8 +922,10 @@ export type HandoffEvent = z.infer<typeof HandoffEventSchema>
|
|
|
756
922
|
|
|
757
923
|
// ---------------------------------------------------------------------------
|
|
758
924
|
// `effect` family (O2) — the spec's "shared effect executor": a generic
|
|
759
|
-
// external effect's
|
|
760
|
-
//
|
|
925
|
+
// external effect's outcome, including failure and uncertainty. The
|
|
926
|
+
// executor records ONE `verified` event per write, carrying its final
|
|
927
|
+
// outcome; `attempted` and `observed` stay parseable so a line stored
|
|
928
|
+
// before that change still reads, but nothing emits them any more. This is additive to, and does not replace, the existing
|
|
761
929
|
// `forge_write` family, which stays exactly as it was — a forge write is
|
|
762
930
|
// one specific effect this schema does not yet generalize `forge_write`
|
|
763
931
|
// into; "telemetry never substitutes for required intent" (the spec's own
|
|
@@ -791,9 +959,44 @@ export const EffectEventSchema = z.discriminatedUnion('event', [
|
|
|
791
959
|
])
|
|
792
960
|
export type EffectEvent = z.infer<typeof EffectEventSchema>
|
|
793
961
|
|
|
962
|
+
// ---------------------------------------------------------------------------
|
|
963
|
+
// `custom` family — an event a consumer declared under `logs.events` in its
|
|
964
|
+
// own `vinaya.config.json` (`custom.ts`). `kind` and `event` are fixed; the
|
|
965
|
+
// declared name is data in `name`, and the values sit flat under `fields`,
|
|
966
|
+
// never nested. Whether `name` is declared and each value matches its
|
|
967
|
+
// declared type is the writer's check (`checkCustomEvent`) — this schema
|
|
968
|
+
// holds only the shape every declaration shares. Valid under a schema 3
|
|
969
|
+
// header only: the family is newer than 1 and 2, so a line claiming either
|
|
970
|
+
// with a `custom` body is not one this log ever wrote.
|
|
971
|
+
|
|
972
|
+
const CustomFieldValueSchema = z.union([z.string().max(CUSTOM_TEXT_MAX_LENGTH), z.number().finite(), z.boolean()])
|
|
973
|
+
|
|
974
|
+
const customShared = {
|
|
975
|
+
meta: HeaderMetaV3Schema,
|
|
976
|
+
subject: SubjectSchema,
|
|
977
|
+
kind: z.literal('custom'),
|
|
978
|
+
...envelopeTail
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
export const CustomEventSchema = z.discriminatedUnion('event', [
|
|
982
|
+
z
|
|
983
|
+
.object({
|
|
984
|
+
...customShared,
|
|
985
|
+
event: z.literal('recorded'),
|
|
986
|
+
name: z.string().max(CUSTOM_EVENT_NAME_MAX_LENGTH).regex(CUSTOM_EVENT_NAME_PATTERN),
|
|
987
|
+
fields: z
|
|
988
|
+
.record(z.string().max(CUSTOM_FIELD_NAME_MAX_LENGTH).regex(CUSTOM_FIELD_NAME_PATTERN), CustomFieldValueSchema)
|
|
989
|
+
.refine((f) => Object.keys(f).length <= CUSTOM_EVENT_MAX_FIELDS, {
|
|
990
|
+
message: `custom: at most ${CUSTOM_EVENT_MAX_FIELDS} fields`
|
|
991
|
+
})
|
|
992
|
+
})
|
|
993
|
+
.strict()
|
|
994
|
+
])
|
|
995
|
+
export type CustomEvent = z.infer<typeof CustomEventSchema>
|
|
996
|
+
|
|
794
997
|
// ---------------------------------------------------------------------------
|
|
795
998
|
|
|
796
|
-
/** Every family shipped so far: the first three (`dispatch`, `dev_review_loop`, `forge_write`)
|
|
999
|
+
/** Every family shipped so far: the first three (`dispatch`, `dev_review_loop`, `forge_write`), the six after them (`gate`, `operation`, `usage`, `role_attempt`, `handoff`, `effect`), and `custom`, a consumer's own declared event. `kind: 'command' | 'tokens'` is still refused — `command` folds into `operation`, `tokens` into `usage`, so neither name is a separate family. */
|
|
797
1000
|
export const LogEventSchema = z.union([
|
|
798
1001
|
DispatchEventSchema,
|
|
799
1002
|
DevReviewLoopEventSchema,
|
|
@@ -803,6 +1006,7 @@ export const LogEventSchema = z.union([
|
|
|
803
1006
|
UsageEventSchema,
|
|
804
1007
|
RoleAttemptEventSchema,
|
|
805
1008
|
HandoffEventSchema,
|
|
806
|
-
EffectEventSchema
|
|
1009
|
+
EffectEventSchema,
|
|
1010
|
+
CustomEventSchema
|
|
807
1011
|
])
|
|
808
1012
|
export type LogEvent = z.infer<typeof LogEventSchema>
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* overflow past a store's capacity is REPORTED (`AppendOutcome.overflow`),
|
|
20
20
|
* never the silent single-slot overwrite the outbox rotation performed.
|
|
21
21
|
* Read-back (`readPage` / `classifyStoredLine`) validates each line's schema
|
|
22
|
-
* version and — for a `schema: 2` line — its provenance, re-applies
|
|
22
|
+
* version and — for a `schema: 2` or `3` line — its provenance, re-applies
|
|
23
23
|
* `redact()` at the read (transport) boundary, and PRESERVES a record whose
|
|
24
24
|
* schema version this build has never heard of as an `unknown_version`
|
|
25
25
|
* record for diagnosis rather than dropping it or failing the whole page.
|
|
@@ -32,14 +32,14 @@ import { LogEventSchema, type LogEvent, type Provenance } from './schema'
|
|
|
32
32
|
* The schema versions this build validates in full. A stored line carrying a
|
|
33
33
|
* `meta.schema` outside this set is neither trusted nor discarded — it is
|
|
34
34
|
* kept as an `unknown_version` read record (O3). Mirrors the
|
|
35
|
-
* `HeaderMetaSchema` discriminated union in `schema.ts` (`1` | `2`); a future
|
|
35
|
+
* `HeaderMetaSchema` discriminated union in `schema.ts` (`1` | `2` | `3`); a future
|
|
36
36
|
* task widening that union widens this set in the same change.
|
|
37
37
|
*/
|
|
38
|
-
export const KNOWN_SCHEMA_VERSIONS = [1, 2] as const
|
|
38
|
+
export const KNOWN_SCHEMA_VERSIONS = [1, 2, 3] as const
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* A record's stable identity across retry, concurrent append and a lost
|
|
42
|
-
* acknowledgement (O2). A `schema: 2` line carries a per-event `event_id`,
|
|
42
|
+
* acknowledgement (O2). A `schema: 2` or `3` line carries a per-event `event_id`,
|
|
43
43
|
* generated once per `log()` call — that is the identity. A `schema: 1` line
|
|
44
44
|
* predates `event_id`; its identity is `${run_id}:${seq}`, the same
|
|
45
45
|
* `run_id`/`seq` pair the flush's `<!-- aeg:log:<run_id>:<seq> -->` marker is
|
|
@@ -94,7 +94,7 @@ export type ReadRecord =
|
|
|
94
94
|
runId: string
|
|
95
95
|
seq: number
|
|
96
96
|
schema: number
|
|
97
|
-
/** Trust provenance for a `schema: 2` line; `null` for a `schema: 1` line, which has no such field. */
|
|
97
|
+
/** Trust provenance for a `schema: 2` or `3` line; `null` for a `schema: 1` line, which has no such field. */
|
|
98
98
|
provenance: Provenance | null
|
|
99
99
|
/** The re-validated event. */
|
|
100
100
|
event: LogEvent
|
|
@@ -119,7 +119,7 @@ export type ReadRecord =
|
|
|
119
119
|
|
|
120
120
|
/**
|
|
121
121
|
* Classifies one stored line: validates its schema version and (for
|
|
122
|
-
* `schema: 2`) its provenance, re-applies `redact(event, home)` at this read
|
|
122
|
+
* `schema: 2` or `3`) its provenance, re-applies `redact(event, home)` at this read
|
|
123
123
|
* (transport) boundary, and distinguishes three outcomes:
|
|
124
124
|
*
|
|
125
125
|
* - `ok` — a known schema version that fully re-validated. `postLine` is the
|
|
@@ -177,7 +177,7 @@ export function classifyStoredLine(raw: string, home: string): ReadRecord {
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
const redacted = redact(event, home)
|
|
180
|
-
const provenance = version
|
|
180
|
+
const provenance = version >= 2 ? ((event.meta as { provenance?: Provenance }).provenance ?? null) : null
|
|
181
181
|
return {
|
|
182
182
|
status: 'ok',
|
|
183
183
|
identity,
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cache contract's behaviours, written once (`apps/cli/specs/log-sync.md`).
|
|
3
|
+
* Every `LogCache` backend's own test runs each case against a fresh
|
|
4
|
+
* instance of that backend:
|
|
5
|
+
*
|
|
6
|
+
* for (const c of cacheContractCases) it(c.name, () => c.run(createMyCache()))
|
|
7
|
+
*
|
|
8
|
+
* A case throws on the first broken expectation. No test framework is
|
|
9
|
+
* imported here, so a backend in any package can run the same list.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { LogCache } from './contracts'
|
|
13
|
+
import { unknownBecause, known } from './measured'
|
|
14
|
+
import { normalizeStoredLine } from './normalize'
|
|
15
|
+
import type { NormalizedLine, RowOrigin } from './row'
|
|
16
|
+
|
|
17
|
+
export type CacheContractCase = {
|
|
18
|
+
name: string
|
|
19
|
+
run(cache: LogCache): void
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function check(condition: boolean, message: string): void {
|
|
23
|
+
if (!condition) throw new Error(`cache contract: ${message}`)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function same(actual: unknown, expected: unknown, message: string): void {
|
|
27
|
+
const a = JSON.stringify(actual)
|
|
28
|
+
const e = JSON.stringify(expected)
|
|
29
|
+
check(a === e, `${message} — expected ${e}, got ${a}`)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** A valid schema 3 `operation` line with the given identity, time and result. */
|
|
33
|
+
function line(eventId: string, ts: string, result = 'ok', origin: RowOrigin | null = null): NormalizedLine {
|
|
34
|
+
const raw = JSON.stringify({
|
|
35
|
+
meta: {
|
|
36
|
+
schema: 3,
|
|
37
|
+
ts,
|
|
38
|
+
run_id: 'contract-run',
|
|
39
|
+
seq: 0,
|
|
40
|
+
repo: 'owner/repo',
|
|
41
|
+
vinaya: '0.36.0',
|
|
42
|
+
doctrine: 'aeg-root@contract',
|
|
43
|
+
host: 'cli',
|
|
44
|
+
machine: 'contract-machine',
|
|
45
|
+
event_id: eventId,
|
|
46
|
+
process_id: 'contract-process',
|
|
47
|
+
actor_id: null,
|
|
48
|
+
lineage: { run: null, attempt: null, parent: null },
|
|
49
|
+
input_versions: { objectives_version: null, brief_hash: null, ruling_ordinal: null, policy_digest: null },
|
|
50
|
+
provenance: 'unavailable',
|
|
51
|
+
work: { ref: null, repo: null, change: null, revision: null },
|
|
52
|
+
flow: { id: 'vinaya', version: null },
|
|
53
|
+
runtime: null,
|
|
54
|
+
source: null
|
|
55
|
+
},
|
|
56
|
+
subject: { issue: null, role: 'unattributed' },
|
|
57
|
+
kind: 'operation',
|
|
58
|
+
event: 'completed',
|
|
59
|
+
payload: {},
|
|
60
|
+
operation: 'contract',
|
|
61
|
+
target: null,
|
|
62
|
+
result,
|
|
63
|
+
error_class: null
|
|
64
|
+
})
|
|
65
|
+
const normalized = normalizeStoredLine(raw, origin)
|
|
66
|
+
check(normalized.type === 'row', 'fixture line must normalise into a row')
|
|
67
|
+
return normalized
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function quarantined(raw: string, origin: RowOrigin | null = null): NormalizedLine {
|
|
71
|
+
const normalized = normalizeStoredLine(raw, origin)
|
|
72
|
+
check(normalized.type === 'quarantine', 'fixture line must normalise into a quarantine record')
|
|
73
|
+
return normalized
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const T1 = '2026-09-20T10:00:00.000Z'
|
|
77
|
+
const T2 = '2026-09-20T11:00:00.000Z'
|
|
78
|
+
|
|
79
|
+
export const cacheContractCases: readonly CacheContractCase[] = [
|
|
80
|
+
{
|
|
81
|
+
name: 'storing one identity twice leaves one row',
|
|
82
|
+
run(cache) {
|
|
83
|
+
same(
|
|
84
|
+
cache.put(line('e-1', T1, 'ok', { source: 'a', position: '1' })),
|
|
85
|
+
{ type: 'row', result: 'inserted' },
|
|
86
|
+
'first put'
|
|
87
|
+
)
|
|
88
|
+
same(
|
|
89
|
+
cache.put(line('e-1', T1, 'ok', { source: 'b', position: '9' })),
|
|
90
|
+
{ type: 'row', result: 'duplicate' },
|
|
91
|
+
'second put'
|
|
92
|
+
)
|
|
93
|
+
const rows = cache.dataset().rows()
|
|
94
|
+
same(
|
|
95
|
+
rows.map((r) => r.identity),
|
|
96
|
+
['e-1'],
|
|
97
|
+
'rows'
|
|
98
|
+
)
|
|
99
|
+
same(rows[0]?.origin, { source: 'a', position: '1' }, 'the first origin is kept')
|
|
100
|
+
same(cache.edits(), [], 'no edit for identical content')
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
name: 'storing one identity with different content keeps the first row and records one edit',
|
|
105
|
+
run(cache) {
|
|
106
|
+
const first = line('e-1', T1, 'ok')
|
|
107
|
+
const edited = line('e-1', T1, 'error', { source: 'b', position: '2' })
|
|
108
|
+
cache.put(first)
|
|
109
|
+
same(cache.put(edited), { type: 'row', result: 'edited' }, 'edited put')
|
|
110
|
+
same(cache.put(edited), { type: 'row', result: 'edited' }, 'repeated edited put')
|
|
111
|
+
const rows = cache.dataset().rows()
|
|
112
|
+
same(rows.length, 1, 'row count')
|
|
113
|
+
check(first.type === 'row' && edited.type === 'row', 'fixtures are rows')
|
|
114
|
+
if (first.type !== 'row' || edited.type !== 'row') return
|
|
115
|
+
same(rows[0]?.contentHash, first.row.contentHash, 'the kept row is the first')
|
|
116
|
+
same(
|
|
117
|
+
cache.edits(),
|
|
118
|
+
[
|
|
119
|
+
{
|
|
120
|
+
identity: 'e-1',
|
|
121
|
+
keptHash: first.row.contentHash,
|
|
122
|
+
editedHash: edited.row.contentHash,
|
|
123
|
+
origin: { source: 'b', position: '2' }
|
|
124
|
+
}
|
|
125
|
+
],
|
|
126
|
+
'edits'
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: 'rows read back ordered by time, then identity',
|
|
132
|
+
run(cache) {
|
|
133
|
+
cache.put(line('e-3', T2))
|
|
134
|
+
cache.put(line('e-2', T1))
|
|
135
|
+
cache.put(line('e-1', T2))
|
|
136
|
+
same(
|
|
137
|
+
cache
|
|
138
|
+
.dataset()
|
|
139
|
+
.rows()
|
|
140
|
+
.map((r) => r.identity),
|
|
141
|
+
['e-2', 'e-1', 'e-3'],
|
|
142
|
+
'order'
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: 'a row reads back exactly as stored',
|
|
148
|
+
run(cache) {
|
|
149
|
+
const stored = line('e-1', T1, 'ok', { source: 'a', position: '7' })
|
|
150
|
+
cache.put(stored)
|
|
151
|
+
check(stored.type === 'row', 'fixture is a row')
|
|
152
|
+
if (stored.type !== 'row') return
|
|
153
|
+
same(cache.dataset().rows()[0], stored.row, 'row')
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
name: 'a source cursor reads back as written, per source',
|
|
158
|
+
run(cache) {
|
|
159
|
+
same(cache.cursor('folder:/logs'), null, 'no cursor yet')
|
|
160
|
+
cache.setCursor('folder:/logs', 'a.ndjson:10')
|
|
161
|
+
cache.setCursor('server:https://logs', '42')
|
|
162
|
+
cache.setCursor('folder:/logs', 'b.ndjson:3')
|
|
163
|
+
same(cache.cursor('folder:/logs'), 'b.ndjson:3', 'folder cursor')
|
|
164
|
+
same(cache.cursor('server:https://logs'), '42', 'server cursor')
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
name: 'a gap reads back as written, and recording it twice keeps one',
|
|
169
|
+
run(cache) {
|
|
170
|
+
const counted = {
|
|
171
|
+
source: 'folder:/logs',
|
|
172
|
+
from: 'a.ndjson:1',
|
|
173
|
+
to: 'a.ndjson:90',
|
|
174
|
+
reason: 'rotated away',
|
|
175
|
+
lost: known(90)
|
|
176
|
+
}
|
|
177
|
+
const uncounted = {
|
|
178
|
+
source: 'server:https://logs',
|
|
179
|
+
from: null,
|
|
180
|
+
to: '100',
|
|
181
|
+
reason: 'past retention',
|
|
182
|
+
lost: unknownBecause<number>('the server does not count expired events')
|
|
183
|
+
}
|
|
184
|
+
cache.recordGap(counted)
|
|
185
|
+
cache.recordGap(uncounted)
|
|
186
|
+
cache.recordGap(counted)
|
|
187
|
+
same(cache.dataset().gaps(), [counted, uncounted], 'gaps')
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
name: 'a quarantine record reads back as written, once, and adds no row',
|
|
192
|
+
run(cache) {
|
|
193
|
+
const unknownVersion = quarantined(
|
|
194
|
+
JSON.stringify({ meta: { schema: 99, event_id: 'future-1', run_id: 'r', seq: 0 } }),
|
|
195
|
+
{ source: 'a', position: '3' }
|
|
196
|
+
)
|
|
197
|
+
const torn = quarantined('{"meta": torn')
|
|
198
|
+
same(cache.put(unknownVersion), { type: 'quarantine', result: 'inserted' }, 'first quarantine put')
|
|
199
|
+
same(cache.put(torn), { type: 'quarantine', result: 'inserted' }, 'second quarantine put')
|
|
200
|
+
same(cache.put(unknownVersion), { type: 'quarantine', result: 'duplicate' }, 'repeated quarantine put')
|
|
201
|
+
check(unknownVersion.type === 'quarantine' && torn.type === 'quarantine', 'fixtures are quarantine records')
|
|
202
|
+
if (unknownVersion.type !== 'quarantine' || torn.type !== 'quarantine') return
|
|
203
|
+
same(cache.dataset().quarantined(), [unknownVersion.record, torn.record], 'quarantine')
|
|
204
|
+
same(cache.dataset().rows(), [], 'no rows')
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
]
|