@jam-overture/loom 0.1.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/LICENSE +21 -0
- package/README.md +743 -0
- package/dist/catalogue.d.ts +70 -0
- package/dist/catalogue.js +88 -0
- package/dist/cli/args.d.ts +17 -0
- package/dist/cli/args.js +83 -0
- package/dist/cli/filesystem.d.ts +15 -0
- package/dist/cli/filesystem.js +31 -0
- package/dist/cli/index.d.ts +12 -0
- package/dist/cli/index.js +12 -0
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/main.js +30 -0
- package/dist/cli/namespace.d.ts +40 -0
- package/dist/cli/namespace.js +40 -0
- package/dist/cli/plan.d.ts +84 -0
- package/dist/cli/plan.js +113 -0
- package/dist/cli/run.d.ts +17 -0
- package/dist/cli/run.js +75 -0
- package/dist/cli/templates.d.ts +43 -0
- package/dist/cli/templates.js +134 -0
- package/dist/closed-set.d.ts +34 -0
- package/dist/closed-set.js +34 -0
- package/dist/data/adapter.d.ts +123 -0
- package/dist/data/adapter.js +91 -0
- package/dist/data/binding.d.ts +48 -0
- package/dist/data/binding.js +39 -0
- package/dist/data/catalogue.d.ts +26 -0
- package/dist/data/catalogue.js +6 -0
- package/dist/data/index.d.ts +14 -0
- package/dist/data/index.js +14 -0
- package/dist/data/plan.d.ts +58 -0
- package/dist/data/plan.js +0 -0
- package/dist/data/resolution.d.ts +91 -0
- package/dist/data/resolution.js +96 -0
- package/dist/data/resolve.d.ts +46 -0
- package/dist/data/resolve.js +37 -0
- package/dist/data/source.d.ts +40 -0
- package/dist/data/source.js +45 -0
- package/dist/deadline.d.ts +57 -0
- package/dist/deadline.js +78 -0
- package/dist/frame/catalogue.d.ts +24 -0
- package/dist/frame/catalogue.js +5 -0
- package/dist/frame/index.d.ts +12 -0
- package/dist/frame/index.js +12 -0
- package/dist/frame/origin.d.ts +87 -0
- package/dist/frame/origin.js +114 -0
- package/dist/frame/resolution.d.ts +85 -0
- package/dist/frame/resolution.js +79 -0
- package/dist/grammar.d.ts +26 -0
- package/dist/grammar.js +28 -0
- package/dist/ids.d.ts +57 -0
- package/dist/ids.js +104 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +26 -0
- package/dist/interactivity.d.ts +50 -0
- package/dist/interactivity.js +22 -0
- package/dist/interpretation/anthropic.d.ts +22 -0
- package/dist/interpretation/anthropic.js +76 -0
- package/dist/interpretation/client.d.ts +83 -0
- package/dist/interpretation/client.js +2 -0
- package/dist/interpretation/draft.d.ts +234 -0
- package/dist/interpretation/draft.js +84 -0
- package/dist/interpretation/index.d.ts +15 -0
- package/dist/interpretation/index.js +15 -0
- package/dist/interpretation/interpreter.d.ts +62 -0
- package/dist/interpretation/interpreter.js +151 -0
- package/dist/interpretation/materialize.d.ts +42 -0
- package/dist/interpretation/materialize.js +107 -0
- package/dist/interpretation/prompt.d.ts +229 -0
- package/dist/interpretation/prompt.js +285 -0
- package/dist/interpretation/render.d.ts +76 -0
- package/dist/interpretation/render.js +272 -0
- package/dist/interpretation/schema.d.ts +49 -0
- package/dist/interpretation/schema.js +131 -0
- package/dist/json.d.ts +35 -0
- package/dist/json.js +11 -0
- package/dist/paging.d.ts +60 -0
- package/dist/paging.js +49 -0
- package/dist/primitive-type.d.ts +32 -0
- package/dist/primitive-type.js +39 -0
- package/dist/render/addressing.d.ts +59 -0
- package/dist/render/addressing.js +60 -0
- package/dist/render/anchor.d.ts +105 -0
- package/dist/render/anchor.js +84 -0
- package/dist/render/behaviour-adjust.d.ts +62 -0
- package/dist/render/behaviour-adjust.js +78 -0
- package/dist/render/behaviour-copy.d.ts +53 -0
- package/dist/render/behaviour-copy.js +75 -0
- package/dist/render/behaviour-disclose.d.ts +74 -0
- package/dist/render/behaviour-disclose.js +77 -0
- package/dist/render/behaviour-present.d.ts +123 -0
- package/dist/render/behaviour-present.js +173 -0
- package/dist/render/behaviour.d.ts +243 -0
- package/dist/render/behaviour.js +284 -0
- package/dist/render/control.d.ts +81 -0
- package/dist/render/control.js +80 -0
- package/dist/render/decorative.d.ts +62 -0
- package/dist/render/decorative.js +2 -0
- package/dist/render/diagnostics.d.ts +260 -0
- package/dist/render/diagnostics.js +61 -0
- package/dist/render/disclosed.d.ts +37 -0
- package/dist/render/disclosed.js +37 -0
- package/dist/render/editable.d.ts +34 -0
- package/dist/render/editable.js +35 -0
- package/dist/render/frame.d.ts +42 -0
- package/dist/render/frame.js +31 -0
- package/dist/render/index.d.ts +35 -0
- package/dist/render/index.js +35 -0
- package/dist/render/inline-variables.d.ts +77 -0
- package/dist/render/inline-variables.js +220 -0
- package/dist/render/presented.d.ts +82 -0
- package/dist/render/presented.js +82 -0
- package/dist/render/primitive.d.ts +228 -0
- package/dist/render/primitive.js +36 -0
- package/dist/render/props.d.ts +48 -0
- package/dist/render/props.js +2 -0
- package/dist/render/reads.d.ts +73 -0
- package/dist/render/reads.js +45 -0
- package/dist/render/render.d.ts +164 -0
- package/dist/render/render.js +571 -0
- package/dist/render/request.d.ts +111 -0
- package/dist/render/request.js +60 -0
- package/dist/render/text.d.ts +91 -0
- package/dist/render/text.js +44 -0
- package/dist/render/theme.d.ts +61 -0
- package/dist/render/theme.js +52 -0
- package/dist/reserved-props.d.ts +35 -0
- package/dist/reserved-props.js +45 -0
- package/dist/result.d.ts +27 -0
- package/dist/result.js +30 -0
- package/dist/role.d.ts +71 -0
- package/dist/role.js +22 -0
- package/dist/runtime/analysis.d.ts +149 -0
- package/dist/runtime/analysis.js +187 -0
- package/dist/runtime/assessment.d.ts +35 -0
- package/dist/runtime/assessment.js +13 -0
- package/dist/runtime/disposition.d.ts +102 -0
- package/dist/runtime/disposition.js +59 -0
- package/dist/runtime/events.d.ts +187 -0
- package/dist/runtime/events.js +7 -0
- package/dist/runtime/gate.d.ts +43 -0
- package/dist/runtime/gate.js +169 -0
- package/dist/runtime/index.d.ts +27 -0
- package/dist/runtime/index.js +27 -0
- package/dist/runtime/intent.d.ts +60 -0
- package/dist/runtime/intent.js +36 -0
- package/dist/runtime/interpreter.d.ts +117 -0
- package/dist/runtime/interpreter.js +46 -0
- package/dist/runtime/inverse-interpreter.d.ts +90 -0
- package/dist/runtime/inverse-interpreter.js +56 -0
- package/dist/runtime/inverse.d.ts +87 -0
- package/dist/runtime/inverse.js +48 -0
- package/dist/runtime/narration.d.ts +24 -0
- package/dist/runtime/narration.js +36 -0
- package/dist/runtime/nesting.d.ts +31 -0
- package/dist/runtime/nesting.js +46 -0
- package/dist/runtime/pipeline.d.ts +124 -0
- package/dist/runtime/pipeline.js +178 -0
- package/dist/runtime/policy-fingerprint.d.ts +29 -0
- package/dist/runtime/policy-fingerprint.js +119 -0
- package/dist/runtime/policy-source.d.ts +42 -0
- package/dist/runtime/policy-source.js +8 -0
- package/dist/runtime/policy.d.ts +156 -0
- package/dist/runtime/policy.js +107 -0
- package/dist/runtime/proposal.d.ts +423 -0
- package/dist/runtime/proposal.js +109 -0
- package/dist/runtime/redirection.d.ts +53 -0
- package/dist/runtime/redirection.js +38 -0
- package/dist/runtime/repointing.d.ts +71 -0
- package/dist/runtime/repointing.js +0 -0
- package/dist/runtime/reversibility.d.ts +36 -0
- package/dist/runtime/reversibility.js +39 -0
- package/dist/runtime/stake-level.d.ts +33 -0
- package/dist/runtime/stake-level.js +58 -0
- package/dist/runtime/stakes.d.ts +47 -0
- package/dist/runtime/stakes.js +305 -0
- package/dist/runtime/vocabulary.d.ts +122 -0
- package/dist/runtime/vocabulary.js +87 -0
- package/dist/sdk/audit.d.ts +195 -0
- package/dist/sdk/audit.js +128 -0
- package/dist/sdk/catalogue.d.ts +37 -0
- package/dist/sdk/catalogue.js +16 -0
- package/dist/sdk/conformance.d.ts +342 -0
- package/dist/sdk/conformance.js +494 -0
- package/dist/sdk/copy.d.ts +105 -0
- package/dist/sdk/copy.js +90 -0
- package/dist/sdk/definition.d.ts +242 -0
- package/dist/sdk/definition.js +64 -0
- package/dist/sdk/index.d.ts +19 -0
- package/dist/sdk/index.js +19 -0
- package/dist/sdk/interactivity.d.ts +29 -0
- package/dist/sdk/interactivity.js +34 -0
- package/dist/sdk/pairings.d.ts +124 -0
- package/dist/sdk/pairings.js +81 -0
- package/dist/sdk/registry.d.ts +162 -0
- package/dist/sdk/registry.js +329 -0
- package/dist/sdk/selection.d.ts +46 -0
- package/dist/sdk/selection.js +24 -0
- package/dist/sdk/text.d.ts +100 -0
- package/dist/sdk/text.js +105 -0
- package/dist/sdk/vocabulary.d.ts +39 -0
- package/dist/sdk/vocabulary.js +36 -0
- package/dist/signals/broadcast.d.ts +134 -0
- package/dist/signals/broadcast.js +451 -0
- package/dist/signals/collect.d.ts +184 -0
- package/dist/signals/collect.js +196 -0
- package/dist/signals/deliver.d.ts +64 -0
- package/dist/signals/deliver.js +85 -0
- package/dist/signals/fold.d.ts +112 -0
- package/dist/signals/fold.js +76 -0
- package/dist/signals/index.d.ts +31 -0
- package/dist/signals/index.js +31 -0
- package/dist/signals/ingest.d.ts +51 -0
- package/dist/signals/ingest.js +70 -0
- package/dist/signals/intake.d.ts +149 -0
- package/dist/signals/intake.js +154 -0
- package/dist/signals/journal.d.ts +94 -0
- package/dist/signals/journal.js +11 -0
- package/dist/signals/kinds.d.ts +22 -0
- package/dist/signals/kinds.js +22 -0
- package/dist/signals/ledger.d.ts +46 -0
- package/dist/signals/ledger.js +81 -0
- package/dist/signals/memory.d.ts +17 -0
- package/dist/signals/memory.js +99 -0
- package/dist/signals/migrate.d.ts +27 -0
- package/dist/signals/migrate.js +78 -0
- package/dist/signals/postgres.d.ts +7 -0
- package/dist/signals/postgres.js +295 -0
- package/dist/signals/rollup.d.ts +142 -0
- package/dist/signals/rollup.js +0 -0
- package/dist/signals/schema.d.ts +534 -0
- package/dist/signals/schema.js +92 -0
- package/dist/signals/signal.d.ts +381 -0
- package/dist/signals/signal.js +150 -0
- package/dist/signals/tally.d.ts +70 -0
- package/dist/signals/tally.js +2 -0
- package/dist/signals/view.d.ts +51 -0
- package/dist/signals/view.js +54 -0
- package/dist/store/attribution.d.ts +125 -0
- package/dist/store/attribution.js +116 -0
- package/dist/store/database.d.ts +14 -0
- package/dist/store/database.js +2 -0
- package/dist/store/driver.d.ts +29 -0
- package/dist/store/driver.js +39 -0
- package/dist/store/errors.d.ts +56 -0
- package/dist/store/errors.js +37 -0
- package/dist/store/index.d.ts +16 -0
- package/dist/store/index.js +16 -0
- package/dist/store/memory.d.ts +3 -0
- package/dist/store/memory.js +115 -0
- package/dist/store/migrate.d.ts +54 -0
- package/dist/store/migrate.js +122 -0
- package/dist/store/postgres-holds.d.ts +4 -0
- package/dist/store/postgres-holds.js +192 -0
- package/dist/store/postgres.d.ts +8 -0
- package/dist/store/postgres.js +262 -0
- package/dist/store/replay.d.ts +94 -0
- package/dist/store/replay.js +82 -0
- package/dist/store/revert.d.ts +116 -0
- package/dist/store/revert.js +243 -0
- package/dist/store/schema.d.ts +371 -0
- package/dist/store/schema.js +78 -0
- package/dist/store/source.d.ts +23 -0
- package/dist/store/source.js +37 -0
- package/dist/store/store.d.ts +231 -0
- package/dist/store/store.js +52 -0
- package/dist/store/undone.d.ts +18 -0
- package/dist/store/undone.js +89 -0
- package/dist/submit/catalogue.d.ts +20 -0
- package/dist/submit/catalogue.js +5 -0
- package/dist/submit/declaration.d.ts +39 -0
- package/dist/submit/declaration.js +30 -0
- package/dist/submit/endpoint.d.ts +131 -0
- package/dist/submit/endpoint.js +160 -0
- package/dist/submit/index.d.ts +13 -0
- package/dist/submit/index.js +13 -0
- package/dist/submit/plan.d.ts +49 -0
- package/dist/submit/plan.js +47 -0
- package/dist/submit/resolution.d.ts +61 -0
- package/dist/submit/resolution.js +64 -0
- package/dist/submit/resolve.d.ts +45 -0
- package/dist/submit/resolve.js +36 -0
- package/dist/telemetry/calibration.d.ts +132 -0
- package/dist/telemetry/calibration.js +151 -0
- package/dist/telemetry/episode.d.ts +140 -0
- package/dist/telemetry/episode.js +272 -0
- package/dist/telemetry/event.d.ts +2310 -0
- package/dist/telemetry/event.js +405 -0
- package/dist/telemetry/index.d.ts +15 -0
- package/dist/telemetry/index.js +15 -0
- package/dist/telemetry/journal.d.ts +116 -0
- package/dist/telemetry/journal.js +11 -0
- package/dist/telemetry/memory.d.ts +24 -0
- package/dist/telemetry/memory.js +75 -0
- package/dist/telemetry/migrate.d.ts +26 -0
- package/dist/telemetry/migrate.js +40 -0
- package/dist/telemetry/postgres.d.ts +6 -0
- package/dist/telemetry/postgres.js +139 -0
- package/dist/telemetry/retention.d.ts +131 -0
- package/dist/telemetry/retention.js +217 -0
- package/dist/telemetry/schema.d.ts +113 -0
- package/dist/telemetry/schema.js +33 -0
- package/dist/telemetry/sink.d.ts +42 -0
- package/dist/telemetry/sink.js +61 -0
- package/dist/testing/contracts.d.ts +34 -0
- package/dist/testing/contracts.js +34 -0
- package/dist/testing/definitions.d.ts +15 -0
- package/dist/testing/definitions.js +48 -0
- package/dist/testing/doubles.d.ts +94 -0
- package/dist/testing/doubles.js +141 -0
- package/dist/testing/episode-harness.d.ts +49 -0
- package/dist/testing/episode-harness.js +65 -0
- package/dist/testing/filesystem.d.ts +17 -0
- package/dist/testing/filesystem.js +17 -0
- package/dist/testing/fixtures.d.ts +57 -0
- package/dist/testing/fixtures.js +84 -0
- package/dist/testing/hold-contract.d.ts +19 -0
- package/dist/testing/hold-contract.js +374 -0
- package/dist/testing/index.d.ts +41 -0
- package/dist/testing/index.js +41 -0
- package/dist/testing/journal-contract.d.ts +17 -0
- package/dist/testing/journal-contract.js +353 -0
- package/dist/testing/model-replies.d.ts +34 -0
- package/dist/testing/model-replies.js +101 -0
- package/dist/testing/primitives.d.ts +7 -0
- package/dist/testing/primitives.js +29 -0
- package/dist/testing/reader-signal-contract.d.ts +38 -0
- package/dist/testing/reader-signal-contract.js +318 -0
- package/dist/testing/row-security.d.ts +17 -0
- package/dist/testing/row-security.js +21 -0
- package/dist/testing/store-contract.d.ts +25 -0
- package/dist/testing/store-contract.js +500 -0
- package/dist/theme/apply.d.ts +17 -0
- package/dist/theme/apply.js +60 -0
- package/dist/theme/contrast.d.ts +197 -0
- package/dist/theme/contrast.js +259 -0
- package/dist/theme/derive.d.ts +77 -0
- package/dist/theme/derive.js +167 -0
- package/dist/theme/faces.d.ts +73 -0
- package/dist/theme/faces.js +119 -0
- package/dist/theme/font-packs.d.ts +25 -0
- package/dist/theme/font-packs.js +257 -0
- package/dist/theme/index.d.ts +20 -0
- package/dist/theme/index.js +20 -0
- package/dist/theme/lab.d.ts +30 -0
- package/dist/theme/lab.js +46 -0
- package/dist/theme/library.d.ts +114 -0
- package/dist/theme/library.js +300 -0
- package/dist/theme/measure.d.ts +144 -0
- package/dist/theme/measure.js +145 -0
- package/dist/theme/palettes.d.ts +64 -0
- package/dist/theme/palettes.js +497 -0
- package/dist/theme/registry.d.ts +59 -0
- package/dist/theme/registry.js +60 -0
- package/dist/theme/separation.d.ts +177 -0
- package/dist/theme/separation.js +203 -0
- package/dist/theme/style-presets.d.ts +60 -0
- package/dist/theme/style-presets.js +124 -0
- package/dist/theme/theme.d.ts +253 -0
- package/dist/theme/theme.js +171 -0
- package/dist/tree/apply.d.ts +16 -0
- package/dist/tree/apply.js +104 -0
- package/dist/tree/builders.d.ts +19 -0
- package/dist/tree/builders.js +20 -0
- package/dist/tree/compare.d.ts +68 -0
- package/dist/tree/compare.js +75 -0
- package/dist/tree/configuration.d.ts +25 -0
- package/dist/tree/configuration.js +108 -0
- package/dist/tree/delta.d.ts +288 -0
- package/dist/tree/delta.js +88 -0
- package/dist/tree/errors.d.ts +69 -0
- package/dist/tree/errors.js +34 -0
- package/dist/tree/identity.d.ts +117 -0
- package/dist/tree/identity.js +145 -0
- package/dist/tree/index.d.ts +21 -0
- package/dist/tree/index.js +21 -0
- package/dist/tree/inverse.d.ts +24 -0
- package/dist/tree/inverse.js +112 -0
- package/dist/tree/mutation.d.ts +18 -0
- package/dist/tree/mutation.js +49 -0
- package/dist/tree/naming.d.ts +4 -0
- package/dist/tree/naming.js +35 -0
- package/dist/tree/navigation.d.ts +38 -0
- package/dist/tree/navigation.js +83 -0
- package/dist/tree/node.d.ts +103 -0
- package/dist/tree/node.js +46 -0
- package/dist/tree/outline.d.ts +28 -0
- package/dist/tree/outline.js +10 -0
- package/dist/tree/tree.d.ts +83 -0
- package/dist/tree/tree.js +62 -0
- package/dist/write/commit.d.ts +124 -0
- package/dist/write/commit.js +234 -0
- package/dist/write/held.d.ts +674 -0
- package/dist/write/held.js +185 -0
- package/dist/write/index.d.ts +11 -0
- package/dist/write/index.js +11 -0
- package/dist/write/liveness.d.ts +132 -0
- package/dist/write/liveness.js +91 -0
- package/dist/write/revert.d.ts +79 -0
- package/dist/write/revert.js +134 -0
- package/package.json +160 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { sql } from "drizzle-orm";
|
|
2
|
+
import { bigserial, index, jsonb, pgTable, text, timestamp } from "drizzle-orm/pg-core";
|
|
3
|
+
/**
|
|
4
|
+
* The table the telemetry journal is stored in, as Drizzle sees it.
|
|
5
|
+
*
|
|
6
|
+
* The column choices here are the ones the journal's promises rest on — arrival
|
|
7
|
+
* order, and one copy of every fact.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* One table, because a journal is one thing: an append-only list of what the
|
|
11
|
+
* runtime narrated.
|
|
12
|
+
*
|
|
13
|
+
* `seq` is a `bigserial` rather than a timestamp because arrival order is the
|
|
14
|
+
* only order that pages correctly — two serverless instances disagree about the
|
|
15
|
+
* clock by more than the gap between two events in one request.
|
|
16
|
+
*
|
|
17
|
+
* `event` is the whole narrowed event as JSON, and its type and its proposal id
|
|
18
|
+
* are *not* also columns. They would be a second copy of a fact that already
|
|
19
|
+
* lives in the document, and two copies of a fact are two things that can
|
|
20
|
+
* disagree. An index on a JSON path is available the day a query needs one; a
|
|
21
|
+
* duplicated column is a migration away from being wrong.
|
|
22
|
+
*/
|
|
23
|
+
export const loomTelemetry = pgTable("loom_telemetry", {
|
|
24
|
+
seq: bigserial("seq", { mode: "number" }).primaryKey(),
|
|
25
|
+
treeId: text("tree_id").notNull(),
|
|
26
|
+
/** When the runtime said it happened, which is not when the row was written. */
|
|
27
|
+
occurredAt: text("occurred_at").notNull(),
|
|
28
|
+
event: jsonb("event").notNull(),
|
|
29
|
+
recordedAt: timestamp("recorded_at", { withTimezone: true })
|
|
30
|
+
.notNull()
|
|
31
|
+
.default(sql `now()`),
|
|
32
|
+
}, (table) => [index("loom_telemetry_tree_seq_idx").on(table.treeId, table.seq)]);
|
|
33
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type Result } from "../result.js";
|
|
2
|
+
import type { EventSink } from "../runtime/events.js";
|
|
3
|
+
import { type TelemetryRecord } from "./event.js";
|
|
4
|
+
import type { TelemetryError, TelemetryJournal } from "./journal.js";
|
|
5
|
+
/**
|
|
6
|
+
* The seam between a runtime narrating itself and a journal that outlives the
|
|
7
|
+
* request (0024).
|
|
8
|
+
*
|
|
9
|
+
* Emission does no IO. It narrows the envelope and puts it in a list — an
|
|
10
|
+
* awaited write would make an accepted change wait on a database, and an
|
|
11
|
+
* un-awaited write on a serverless host is a promise the platform cancels when
|
|
12
|
+
* the response ends. Writing happens once, at `flush`, at a point the host
|
|
13
|
+
* chooses and can await.
|
|
14
|
+
*
|
|
15
|
+
* The runtime would contain a throw from here anyway (0042), so this sink does
|
|
16
|
+
* not buffer in order to stay safe. It does it in order to stay *countable*:
|
|
17
|
+
* containment loses an event silently, whereas everything this collector cannot
|
|
18
|
+
* hold or cannot write is counted in `dropped`.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* A ceiling on what one collector will hold. A host that forgets to flush leaks
|
|
22
|
+
* memory into the write path, and unbounded telemetry buffers are a worse
|
|
23
|
+
* failure than lost telemetry — so the buffer refuses to grow past this and
|
|
24
|
+
* says how much it dropped.
|
|
25
|
+
*/
|
|
26
|
+
export declare const MAX_BUFFERED_RECORDS = 1000;
|
|
27
|
+
export type TelemetryCollector = {
|
|
28
|
+
readonly sink: EventSink;
|
|
29
|
+
/** Not yet written. Exposed so a host can decide a flush is worth the round trip. */
|
|
30
|
+
readonly pending: () => readonly TelemetryRecord[];
|
|
31
|
+
/** Records this collector could not hold or could not write. */
|
|
32
|
+
readonly dropped: () => number;
|
|
33
|
+
/**
|
|
34
|
+
* Writes what has been collected and empties the buffer, whether or not the
|
|
35
|
+
* write succeeded. Records are not retained for a retry: a journal that is
|
|
36
|
+
* failing will fail the retry too, and a queue that grows while it drains
|
|
37
|
+
* moves the outage into the write path.
|
|
38
|
+
*/
|
|
39
|
+
readonly flush: () => Promise<Result<void, TelemetryError>>;
|
|
40
|
+
};
|
|
41
|
+
export declare const collectTelemetry: (journal: TelemetryJournal) => TelemetryCollector;
|
|
42
|
+
//# sourceMappingURL=sink.d.ts.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ok } from "../result.js";
|
|
2
|
+
import { recordOf } from "./event.js";
|
|
3
|
+
/**
|
|
4
|
+
* The seam between a runtime narrating itself and a journal that outlives the
|
|
5
|
+
* request (0024).
|
|
6
|
+
*
|
|
7
|
+
* Emission does no IO. It narrows the envelope and puts it in a list — an
|
|
8
|
+
* awaited write would make an accepted change wait on a database, and an
|
|
9
|
+
* un-awaited write on a serverless host is a promise the platform cancels when
|
|
10
|
+
* the response ends. Writing happens once, at `flush`, at a point the host
|
|
11
|
+
* chooses and can await.
|
|
12
|
+
*
|
|
13
|
+
* The runtime would contain a throw from here anyway (0042), so this sink does
|
|
14
|
+
* not buffer in order to stay safe. It does it in order to stay *countable*:
|
|
15
|
+
* containment loses an event silently, whereas everything this collector cannot
|
|
16
|
+
* hold or cannot write is counted in `dropped`.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* A ceiling on what one collector will hold. A host that forgets to flush leaks
|
|
20
|
+
* memory into the write path, and unbounded telemetry buffers are a worse
|
|
21
|
+
* failure than lost telemetry — so the buffer refuses to grow past this and
|
|
22
|
+
* says how much it dropped.
|
|
23
|
+
*/
|
|
24
|
+
export const MAX_BUFFERED_RECORDS = 1000;
|
|
25
|
+
export const collectTelemetry = (journal) => {
|
|
26
|
+
let buffered = [];
|
|
27
|
+
let dropped = 0;
|
|
28
|
+
const emit = (envelope) => {
|
|
29
|
+
if (buffered.length >= MAX_BUFFERED_RECORDS) {
|
|
30
|
+
dropped += 1;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
buffered.push(recordOf(envelope));
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
/**
|
|
38
|
+
* `recordOf` is total over `RuntimeEvent`, so reaching here means a host
|
|
39
|
+
* emitted something outside the union. That is a bug in the host, and it
|
|
40
|
+
* must not become a failed change: it is counted and dropped.
|
|
41
|
+
*/
|
|
42
|
+
dropped += 1;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
sink: { emit },
|
|
47
|
+
pending: () => buffered,
|
|
48
|
+
dropped: () => dropped,
|
|
49
|
+
flush: async () => {
|
|
50
|
+
if (buffered.length === 0)
|
|
51
|
+
return ok(undefined);
|
|
52
|
+
const batch = buffered;
|
|
53
|
+
buffered = [];
|
|
54
|
+
const written = await journal.record(batch);
|
|
55
|
+
if (!written.ok)
|
|
56
|
+
dropped += batch.length;
|
|
57
|
+
return written;
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=sink.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The suites a host runs against its own implementation, published as
|
|
3
|
+
* `@jam-overture/loom/testing/contracts`.
|
|
4
|
+
*
|
|
5
|
+
* A `TreeStore`, a `HoldStore` and a `TelemetryJournal` are seams: Loom ships
|
|
6
|
+
* an in-memory implementation of each and a Postgres one, and a host is
|
|
7
|
+
* expected to be able to write a third. What it cannot do from outside this
|
|
8
|
+
* repository is find out whether the third one is *right*. The promises are not
|
|
9
|
+
* in the type — an append is ordered, a hold is exclusive, a journal is
|
|
10
|
+
* append-only — and a host discovering each of them from a production incident
|
|
11
|
+
* is the seam being offered without the thing that makes it safe to take.
|
|
12
|
+
*
|
|
13
|
+
* So the suite this package runs against its own two implementations is the
|
|
14
|
+
* suite it hands anybody writing a third. It is the same code, not a
|
|
15
|
+
* description of it, which is the whole point: a promise checked two different
|
|
16
|
+
* ways is a promise one of them will stop checking.
|
|
17
|
+
*
|
|
18
|
+
* **These import `vitest`, and that is why they are not in
|
|
19
|
+
* [`index.js`](./index.ts).** A test framework in the fixtures' import graph
|
|
20
|
+
* would reach every consumer of `sampleTree`, including the course's in-page
|
|
21
|
+
* runner, which needs to load the fixtures in a browser and has no business
|
|
22
|
+
* loading a test runner to do it. `vitest` is therefore an optional peer
|
|
23
|
+
* dependency: present for anyone importing this module, absent and unmissed for
|
|
24
|
+
* everyone importing the other one.
|
|
25
|
+
*
|
|
26
|
+
* `rowSecurityOn` is here rather than beside the fixtures for the same kind of
|
|
27
|
+
* reason — it asks a live Postgres about a table, so it needs `drizzle-orm`,
|
|
28
|
+
* which the Postgres suites already do.
|
|
29
|
+
*/
|
|
30
|
+
export { describeHoldStoreContract, heldProposalFixture } from "./hold-contract.js";
|
|
31
|
+
export { describeTelemetryJournalContract, sampleEpisode } from "./journal-contract.js";
|
|
32
|
+
export { rowSecurityOn } from "./row-security.js";
|
|
33
|
+
export { appendOf, describeTreeStoreContract, removalOf, treeNamed, } from "./store-contract.js";
|
|
34
|
+
//# sourceMappingURL=contracts.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The suites a host runs against its own implementation, published as
|
|
3
|
+
* `@jam-overture/loom/testing/contracts`.
|
|
4
|
+
*
|
|
5
|
+
* A `TreeStore`, a `HoldStore` and a `TelemetryJournal` are seams: Loom ships
|
|
6
|
+
* an in-memory implementation of each and a Postgres one, and a host is
|
|
7
|
+
* expected to be able to write a third. What it cannot do from outside this
|
|
8
|
+
* repository is find out whether the third one is *right*. The promises are not
|
|
9
|
+
* in the type — an append is ordered, a hold is exclusive, a journal is
|
|
10
|
+
* append-only — and a host discovering each of them from a production incident
|
|
11
|
+
* is the seam being offered without the thing that makes it safe to take.
|
|
12
|
+
*
|
|
13
|
+
* So the suite this package runs against its own two implementations is the
|
|
14
|
+
* suite it hands anybody writing a third. It is the same code, not a
|
|
15
|
+
* description of it, which is the whole point: a promise checked two different
|
|
16
|
+
* ways is a promise one of them will stop checking.
|
|
17
|
+
*
|
|
18
|
+
* **These import `vitest`, and that is why they are not in
|
|
19
|
+
* [`index.js`](./index.ts).** A test framework in the fixtures' import graph
|
|
20
|
+
* would reach every consumer of `sampleTree`, including the course's in-page
|
|
21
|
+
* runner, which needs to load the fixtures in a browser and has no business
|
|
22
|
+
* loading a test runner to do it. `vitest` is therefore an optional peer
|
|
23
|
+
* dependency: present for anyone importing this module, absent and unmissed for
|
|
24
|
+
* everyone importing the other one.
|
|
25
|
+
*
|
|
26
|
+
* `rowSecurityOn` is here rather than beside the fixtures for the same kind of
|
|
27
|
+
* reason — it asks a live Postgres about a table, so it needs `drizzle-orm`,
|
|
28
|
+
* which the Postgres suites already do.
|
|
29
|
+
*/
|
|
30
|
+
export { describeHoldStoreContract, heldProposalFixture } from "./hold-contract.js";
|
|
31
|
+
export { describeTelemetryJournalContract, sampleEpisode } from "./journal-contract.js";
|
|
32
|
+
export { rowSecurityOn } from "./row-security.js";
|
|
33
|
+
export { appendOf, describeTreeStoreContract, removalOf, treeNamed, } from "./store-contract.js";
|
|
34
|
+
//# sourceMappingURL=contracts.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type PrimitiveEntry } from "../sdk/definition.js";
|
|
2
|
+
import { type PrimitiveRegistry } from "../sdk/registry.js";
|
|
3
|
+
export declare const pageDefinition: PrimitiveEntry;
|
|
4
|
+
export declare const cardDefinition: PrimitiveEntry;
|
|
5
|
+
export declare const headerDefinition: PrimitiveEntry;
|
|
6
|
+
export declare const footerDefinition: PrimitiveEntry;
|
|
7
|
+
export declare const testDefinitions: readonly PrimitiveEntry[];
|
|
8
|
+
/**
|
|
9
|
+
* Registration is fallible, and a test that wanted a registry has nothing to say
|
|
10
|
+
* about a failure to build one, so this unwraps loudly rather than making every
|
|
11
|
+
* caller narrow a Result it does not care about.
|
|
12
|
+
*/
|
|
13
|
+
export declare const registryOf: (entries: readonly PrimitiveEntry[]) => PrimitiveRegistry;
|
|
14
|
+
export declare const testRegistry: () => PrimitiveRegistry;
|
|
15
|
+
//# sourceMappingURL=definitions.d.ts.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createElement } from "react";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { definePrimitive } from "../sdk/definition.js";
|
|
4
|
+
import { createPrimitiveRegistry, describeRegistryError } from "../sdk/registry.js";
|
|
5
|
+
/**
|
|
6
|
+
* The primitives of `sampleTree`, declared through the §4 contract, so registry
|
|
7
|
+
* and renderer tests run against real declarations rather than a stand-in for
|
|
8
|
+
* them. `testPrimitives` in `primitives.ts` is the same component set without
|
|
9
|
+
* declarations, which is what §3's tests need.
|
|
10
|
+
*
|
|
11
|
+
* `loom.card` declares its props strictly and `loom.page` does not, because both
|
|
12
|
+
* are legitimate choices a primitive author makes and the render seam has to
|
|
13
|
+
* behave correctly for each.
|
|
14
|
+
*/
|
|
15
|
+
const declared = (type, description, props, tag, slots) => {
|
|
16
|
+
const Primitive = ({ loom, props: bag, children }) => createElement(tag, { ...loom.editable, "data-props": JSON.stringify(bag) }, children, Object.keys(loom.slots).map((name) => loom.slots[name]));
|
|
17
|
+
Primitive.displayName = `declared(${type})`;
|
|
18
|
+
return definePrimitive({
|
|
19
|
+
type,
|
|
20
|
+
description,
|
|
21
|
+
props,
|
|
22
|
+
component: Primitive,
|
|
23
|
+
...(slots ? { slots } : {}),
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
export const pageDefinition = declared("loom.page", "The page shell; everything else lives inside it", z.object({ title: z.string(), subtitle: z.string().optional() }), "main", ["main"]);
|
|
27
|
+
export const cardDefinition = declared("loom.card", "A bounded block of related content", z.object({ variant: z.enum(["outlined", "filled"]), elevation: z.number().optional() }).strict(), "article");
|
|
28
|
+
export const headerDefinition = declared("loom.header", "The banner at the top of a page", z.object({}), "header");
|
|
29
|
+
export const footerDefinition = declared("loom.footer", "The closing band at the bottom of a page", z.object({}), "footer");
|
|
30
|
+
export const testDefinitions = [
|
|
31
|
+
pageDefinition,
|
|
32
|
+
headerDefinition,
|
|
33
|
+
cardDefinition,
|
|
34
|
+
footerDefinition,
|
|
35
|
+
];
|
|
36
|
+
/**
|
|
37
|
+
* Registration is fallible, and a test that wanted a registry has nothing to say
|
|
38
|
+
* about a failure to build one, so this unwraps loudly rather than making every
|
|
39
|
+
* caller narrow a Result it does not care about.
|
|
40
|
+
*/
|
|
41
|
+
export const registryOf = (entries) => {
|
|
42
|
+
const built = createPrimitiveRegistry(entries);
|
|
43
|
+
if (!built.ok)
|
|
44
|
+
throw new Error(`expected a registry, got ${describeRegistryError(built.error)}`);
|
|
45
|
+
return built.value;
|
|
46
|
+
};
|
|
47
|
+
export const testRegistry = () => registryOf(testDefinitions);
|
|
48
|
+
//# sourceMappingURL=definitions.js.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { ModelClient, ModelClientError, ModelCompletion, ModelRequest } from "../interpretation/client.js";
|
|
2
|
+
import type { IdFactory, IntentId, TreeId } from "../ids.js";
|
|
3
|
+
import { type Result } from "../result.js";
|
|
4
|
+
import type { Clock, EventSink, RuntimeEventEnvelope } from "../runtime/events.js";
|
|
5
|
+
import type { EditIntent, IntentOrigin } from "../runtime/intent.js";
|
|
6
|
+
import type { ChangeInterpreter, ChangeRepairer, InterpretationError, RepairRequest } from "../runtime/interpreter.js";
|
|
7
|
+
import type { AuthorKind, ProposedChange } from "../runtime/proposal.js";
|
|
8
|
+
import type { TreeDelta } from "../tree/delta.js";
|
|
9
|
+
/**
|
|
10
|
+
* Test doubles for the impure seams this file owns — the interpreter and its
|
|
11
|
+
* repairer, the clock, and the event sink. The runtime's other two seams are
|
|
12
|
+
* doubled where they are defined: `sequentialIdFactory` in `ids.ts` and
|
|
13
|
+
* `fixedPolicy` in `runtime/policy-source.ts`.
|
|
14
|
+
*
|
|
15
|
+
* They live in `src/testing` rather than beside the tests because the renderer
|
|
16
|
+
* and portal will want the same ones.
|
|
17
|
+
*/
|
|
18
|
+
export declare const FIXED_INSTANT = "2026-07-28T00:00:00.000Z";
|
|
19
|
+
export declare const fixedClock: (instant?: string) => Clock;
|
|
20
|
+
export type CollectingEventSink = EventSink & {
|
|
21
|
+
readonly envelopes: readonly RuntimeEventEnvelope[];
|
|
22
|
+
readonly types: () => readonly string[];
|
|
23
|
+
};
|
|
24
|
+
export declare const collectingEventSink: () => CollectingEventSink;
|
|
25
|
+
/**
|
|
26
|
+
* A sink that fails on the events it was told to fail on and collects the rest,
|
|
27
|
+
* so a test can assert both halves at once: that the change survived, and that
|
|
28
|
+
* narration carried on past the failure rather than stopping at it.
|
|
29
|
+
*
|
|
30
|
+
* `mode` picks how it fails. A synchronous throw is the obvious shape; an
|
|
31
|
+
* `async` sink assigned to a `() => void` signature rejects instead, which is
|
|
32
|
+
* the shape a host reaches by accident (0042).
|
|
33
|
+
*/
|
|
34
|
+
export declare const failingEventSink: (failOn: readonly string[], mode?: "throw" | "reject") => CollectingEventSink;
|
|
35
|
+
export type RecordingModelClient = ModelClient & {
|
|
36
|
+
readonly requests: readonly ModelRequest[];
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* A model that answers from a script and remembers what it was asked, so the
|
|
40
|
+
* interpreter's request assembly and its reply handling can be tested
|
|
41
|
+
* separately, and neither needs a network or a key.
|
|
42
|
+
*/
|
|
43
|
+
export declare const scriptedModelClient: (reply: string | Result<ModelCompletion, ModelClientError>, servedBy?: string) => RecordingModelClient;
|
|
44
|
+
export type HangingModelClient = ModelClient & {
|
|
45
|
+
/** Whether the runtime's ceiling aborted the call, and what it said (0140). */
|
|
46
|
+
readonly abortedWith: () => string | undefined;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* A model that never answers — the failure mode a `try`/`catch` cannot see and
|
|
50
|
+
* the reason `modelInterpreter` has a ceiling (0140).
|
|
51
|
+
*
|
|
52
|
+
* Published because every surface with a prompt box has an "it did not come
|
|
53
|
+
* back" state to show, and this is the only way to reach it without waiting for
|
|
54
|
+
* one. Use it with a small `ceilingMs`: a test that needs three minutes to pass
|
|
55
|
+
* is a test nobody runs.
|
|
56
|
+
*/
|
|
57
|
+
export declare const hangingModelClient: () => HangingModelClient;
|
|
58
|
+
export type RecordingInterpreter = ChangeInterpreter & {
|
|
59
|
+
readonly intents: readonly EditIntent[];
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Returns whatever it was handed, so tests drive the pipeline from a fixed
|
|
63
|
+
* script, and remembers what it was asked — which is how a test asserts that a
|
|
64
|
+
* write refused before interpretation never spent a model call.
|
|
65
|
+
*/
|
|
66
|
+
export declare const scriptedInterpreter: (script: Result<ProposedChange, InterpretationError>) => RecordingInterpreter;
|
|
67
|
+
export type RecordingRepairer = ChangeRepairer & {
|
|
68
|
+
readonly requests: readonly RepairRequest[];
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* A repairer that answers from a script and remembers what it was asked, so a
|
|
72
|
+
* test can assert both that the refusal reached it and that exactly one attempt
|
|
73
|
+
* was made.
|
|
74
|
+
*/
|
|
75
|
+
export declare const scriptedRepairer: (script: Result<ProposedChange, InterpretationError>) => RecordingRepairer;
|
|
76
|
+
export type IntentDraft = {
|
|
77
|
+
readonly treeId: TreeId;
|
|
78
|
+
readonly baseRevision: number;
|
|
79
|
+
readonly utterance?: string;
|
|
80
|
+
readonly origin?: IntentOrigin;
|
|
81
|
+
readonly actor?: string;
|
|
82
|
+
};
|
|
83
|
+
export declare const buildIntent: (idFactory: IdFactory, draft: IntentDraft) => EditIntent;
|
|
84
|
+
export type ProposalDraft = {
|
|
85
|
+
readonly intentId: IntentId;
|
|
86
|
+
readonly delta: TreeDelta;
|
|
87
|
+
readonly rationale?: string;
|
|
88
|
+
readonly origin?: IntentOrigin;
|
|
89
|
+
readonly actor?: string;
|
|
90
|
+
readonly authoredBy?: AuthorKind;
|
|
91
|
+
readonly confidence?: number;
|
|
92
|
+
};
|
|
93
|
+
export declare const buildProposal: (idFactory: IdFactory, draft: ProposalDraft) => ProposedChange;
|
|
94
|
+
//# sourceMappingURL=doubles.d.ts.map
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { ok } from "../result.js";
|
|
2
|
+
/**
|
|
3
|
+
* Test doubles for the impure seams this file owns — the interpreter and its
|
|
4
|
+
* repairer, the clock, and the event sink. The runtime's other two seams are
|
|
5
|
+
* doubled where they are defined: `sequentialIdFactory` in `ids.ts` and
|
|
6
|
+
* `fixedPolicy` in `runtime/policy-source.ts`.
|
|
7
|
+
*
|
|
8
|
+
* They live in `src/testing` rather than beside the tests because the renderer
|
|
9
|
+
* and portal will want the same ones.
|
|
10
|
+
*/
|
|
11
|
+
export const FIXED_INSTANT = "2026-07-28T00:00:00.000Z";
|
|
12
|
+
export const fixedClock = (instant = FIXED_INSTANT) => ({ now: () => instant });
|
|
13
|
+
export const collectingEventSink = () => {
|
|
14
|
+
const envelopes = [];
|
|
15
|
+
return {
|
|
16
|
+
emit: (envelope) => {
|
|
17
|
+
envelopes.push(envelope);
|
|
18
|
+
},
|
|
19
|
+
envelopes,
|
|
20
|
+
types: () => envelopes.map((envelope) => envelope.event.type),
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* A sink that fails on the events it was told to fail on and collects the rest,
|
|
25
|
+
* so a test can assert both halves at once: that the change survived, and that
|
|
26
|
+
* narration carried on past the failure rather than stopping at it.
|
|
27
|
+
*
|
|
28
|
+
* `mode` picks how it fails. A synchronous throw is the obvious shape; an
|
|
29
|
+
* `async` sink assigned to a `() => void` signature rejects instead, which is
|
|
30
|
+
* the shape a host reaches by accident (0042).
|
|
31
|
+
*/
|
|
32
|
+
export const failingEventSink = (failOn, mode = "throw") => {
|
|
33
|
+
const envelopes = [];
|
|
34
|
+
const fail = (type) => {
|
|
35
|
+
const error = new Error(`sink refused ${type}`);
|
|
36
|
+
if (mode === "throw")
|
|
37
|
+
throw error;
|
|
38
|
+
/** Typed `void`, returns a rejected promise: exactly the accidental case. */
|
|
39
|
+
return Promise.reject(error);
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
emit: (envelope) => {
|
|
43
|
+
if (failOn.includes(envelope.event.type))
|
|
44
|
+
return fail(envelope.event.type);
|
|
45
|
+
envelopes.push(envelope);
|
|
46
|
+
},
|
|
47
|
+
envelopes,
|
|
48
|
+
types: () => envelopes.map((envelope) => envelope.event.type),
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* A model that answers from a script and remembers what it was asked, so the
|
|
53
|
+
* interpreter's request assembly and its reply handling can be tested
|
|
54
|
+
* separately, and neither needs a network or a key.
|
|
55
|
+
*/
|
|
56
|
+
export const scriptedModelClient = (reply, servedBy = "claude-test-1") => {
|
|
57
|
+
const requests = [];
|
|
58
|
+
const script = typeof reply === "string" ? ok({ text: reply, servedBy }) : reply;
|
|
59
|
+
return {
|
|
60
|
+
complete: (request) => {
|
|
61
|
+
requests.push(request);
|
|
62
|
+
return Promise.resolve(script);
|
|
63
|
+
},
|
|
64
|
+
requests,
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* A model that never answers — the failure mode a `try`/`catch` cannot see and
|
|
69
|
+
* the reason `modelInterpreter` has a ceiling (0140).
|
|
70
|
+
*
|
|
71
|
+
* Published because every surface with a prompt box has an "it did not come
|
|
72
|
+
* back" state to show, and this is the only way to reach it without waiting for
|
|
73
|
+
* one. Use it with a small `ceilingMs`: a test that needs three minutes to pass
|
|
74
|
+
* is a test nobody runs.
|
|
75
|
+
*/
|
|
76
|
+
export const hangingModelClient = () => {
|
|
77
|
+
let aborted;
|
|
78
|
+
return {
|
|
79
|
+
complete: (_request, options) => new Promise(() => {
|
|
80
|
+
options?.signal?.addEventListener("abort", () => {
|
|
81
|
+
const { reason } = options.signal;
|
|
82
|
+
aborted = reason instanceof Error ? reason.message : "unnamed";
|
|
83
|
+
});
|
|
84
|
+
}),
|
|
85
|
+
abortedWith: () => aborted,
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Returns whatever it was handed, so tests drive the pipeline from a fixed
|
|
90
|
+
* script, and remembers what it was asked — which is how a test asserts that a
|
|
91
|
+
* write refused before interpretation never spent a model call.
|
|
92
|
+
*/
|
|
93
|
+
export const scriptedInterpreter = (script) => {
|
|
94
|
+
const intents = [];
|
|
95
|
+
return {
|
|
96
|
+
interpret: (intent) => {
|
|
97
|
+
intents.push(intent);
|
|
98
|
+
return Promise.resolve(script);
|
|
99
|
+
},
|
|
100
|
+
intents,
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* A repairer that answers from a script and remembers what it was asked, so a
|
|
105
|
+
* test can assert both that the refusal reached it and that exactly one attempt
|
|
106
|
+
* was made.
|
|
107
|
+
*/
|
|
108
|
+
export const scriptedRepairer = (script) => {
|
|
109
|
+
const requests = [];
|
|
110
|
+
return {
|
|
111
|
+
repair: (request) => {
|
|
112
|
+
requests.push(request);
|
|
113
|
+
return Promise.resolve(script);
|
|
114
|
+
},
|
|
115
|
+
requests,
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
export const buildIntent = (idFactory, draft) => ({
|
|
119
|
+
intentId: idFactory.intentId(),
|
|
120
|
+
treeId: draft.treeId,
|
|
121
|
+
baseRevision: draft.baseRevision,
|
|
122
|
+
origin: draft.origin ?? "user-instruction",
|
|
123
|
+
...(draft.actor === undefined ? {} : { actor: draft.actor }),
|
|
124
|
+
utterance: draft.utterance ?? "make it better",
|
|
125
|
+
observedAt: FIXED_INSTANT,
|
|
126
|
+
});
|
|
127
|
+
export const buildProposal = (idFactory, draft) => ({
|
|
128
|
+
proposalId: idFactory.proposalId(),
|
|
129
|
+
intentId: draft.intentId,
|
|
130
|
+
delta: draft.delta,
|
|
131
|
+
rationale: draft.rationale ?? "satisfies the intent",
|
|
132
|
+
provenance: {
|
|
133
|
+
origin: draft.origin ?? "user-instruction",
|
|
134
|
+
...(draft.actor === undefined ? {} : { actor: draft.actor }),
|
|
135
|
+
interpreter: "scripted",
|
|
136
|
+
authoredBy: draft.authoredBy ?? "model",
|
|
137
|
+
confidence: draft.confidence ?? 0.9,
|
|
138
|
+
interpretedAt: FIXED_INSTANT,
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
//# sourceMappingURL=doubles.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type IdFactory } from "../ids.js";
|
|
2
|
+
import { type Result } from "../result.js";
|
|
3
|
+
import type { EditIntent } from "../runtime/intent.js";
|
|
4
|
+
import type { ChangeRepairer, InterpretationError } from "../runtime/interpreter.js";
|
|
5
|
+
import { type GatePolicy } from "../runtime/policy.js";
|
|
6
|
+
import type { ProposedChange } from "../runtime/proposal.js";
|
|
7
|
+
import { type EpisodeFold } from "../telemetry/episode.js";
|
|
8
|
+
import type { TelemetryJournal } from "../telemetry/journal.js";
|
|
9
|
+
import { type TelemetryCollector } from "../telemetry/sink.js";
|
|
10
|
+
import type { TreeDelta } from "../tree/delta.js";
|
|
11
|
+
import type { LoomTree } from "../tree/tree.js";
|
|
12
|
+
import { type WritePath } from "../write/index.js";
|
|
13
|
+
/**
|
|
14
|
+
* A write path wired to a real Gate, a real store and a real journal, with only
|
|
15
|
+
* the model scripted.
|
|
16
|
+
*
|
|
17
|
+
* §6's derivations — the episode fold and the calibration report — are both
|
|
18
|
+
* about what actually happened, so both are exercised through the pipeline
|
|
19
|
+
* rather than over hand-assembled records. A test that wrote its own records
|
|
20
|
+
* would be answering its own question: it would keep passing after the pipeline
|
|
21
|
+
* stopped narrating a stage, or after a disposition changed shape.
|
|
22
|
+
*/
|
|
23
|
+
export type EpisodeHarness = {
|
|
24
|
+
readonly path: WritePath;
|
|
25
|
+
readonly journal: TelemetryJournal;
|
|
26
|
+
readonly collector: TelemetryCollector;
|
|
27
|
+
readonly tree: LoomTree;
|
|
28
|
+
readonly ids: IdFactory;
|
|
29
|
+
readonly intent: EditIntent;
|
|
30
|
+
readonly fold: () => Promise<EpisodeFold>;
|
|
31
|
+
};
|
|
32
|
+
export declare const removalDelta: (tree: LoomTree, ids: IdFactory, nodeId: string) => TreeDelta;
|
|
33
|
+
export declare const harnessWith: (options: {
|
|
34
|
+
readonly script: (tree: LoomTree, ids: IdFactory, intent: EditIntent) => Result<ProposedChange, InterpretationError>;
|
|
35
|
+
readonly repairer?: (tree: LoomTree, ids: IdFactory, intent: EditIntent) => ChangeRepairer;
|
|
36
|
+
readonly baseRevision?: number;
|
|
37
|
+
/**
|
|
38
|
+
* The Gate that judges this run. Defaults to the shipped one, which is what
|
|
39
|
+
* most tests want; a test about attribution needs two hosts that differ, and
|
|
40
|
+
* a policy is the only thing a disposition names.
|
|
41
|
+
*/
|
|
42
|
+
readonly policy?: GatePolicy;
|
|
43
|
+
}) => Promise<EpisodeHarness>;
|
|
44
|
+
/**
|
|
45
|
+
* Confidence is the only knob most of these tests need, because it is what the
|
|
46
|
+
* default policy dispositions on: high accepts, middling holds, low refuses.
|
|
47
|
+
*/
|
|
48
|
+
export declare const proposalScript: (confidence: number) => (tree: LoomTree, ids: IdFactory, intent: EditIntent) => Result<ProposedChange, InterpretationError>;
|
|
49
|
+
//# sourceMappingURL=episode-harness.d.ts.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { sequentialIdFactory } from "../ids.js";
|
|
2
|
+
import { ok } from "../result.js";
|
|
3
|
+
import { fixedPolicy } from "../runtime/policy-source.js";
|
|
4
|
+
import { defaultGatePolicy } from "../runtime/policy.js";
|
|
5
|
+
import { memoryTreeStore } from "../store/memory.js";
|
|
6
|
+
import { episodesOf } from "../telemetry/episode.js";
|
|
7
|
+
import { memoryTelemetryJournal } from "../telemetry/memory.js";
|
|
8
|
+
import { collectTelemetry } from "../telemetry/sink.js";
|
|
9
|
+
import { memoryHoldStore } from "../write/index.js";
|
|
10
|
+
import { buildIntent, buildProposal, fixedClock, scriptedInterpreter } from "./doubles.js";
|
|
11
|
+
import { sampleTree } from "./fixtures.js";
|
|
12
|
+
export const removalDelta = (tree, ids, nodeId) => ({
|
|
13
|
+
deltaId: ids.deltaId(),
|
|
14
|
+
treeId: tree.treeId,
|
|
15
|
+
baseRevision: 0,
|
|
16
|
+
operations: [{ op: "remove", nodeId: nodeId }],
|
|
17
|
+
});
|
|
18
|
+
export const harnessWith = async (options) => {
|
|
19
|
+
const { tree } = sampleTree();
|
|
20
|
+
const ids = sequentialIdFactory("h");
|
|
21
|
+
const store = memoryTreeStore();
|
|
22
|
+
await store.create(tree);
|
|
23
|
+
const journal = memoryTelemetryJournal();
|
|
24
|
+
const collector = collectTelemetry(journal);
|
|
25
|
+
const intent = buildIntent(ids, {
|
|
26
|
+
treeId: tree.treeId,
|
|
27
|
+
baseRevision: options.baseRevision ?? 0,
|
|
28
|
+
});
|
|
29
|
+
const repairer = options.repairer?.(tree, ids, intent);
|
|
30
|
+
const path = {
|
|
31
|
+
store,
|
|
32
|
+
holds: memoryHoldStore(),
|
|
33
|
+
runtime: {
|
|
34
|
+
interpreter: scriptedInterpreter(options.script(tree, ids, intent)),
|
|
35
|
+
policySource: fixedPolicy(options.policy ?? defaultGatePolicy),
|
|
36
|
+
events: collector.sink,
|
|
37
|
+
clock: fixedClock(),
|
|
38
|
+
idFactory: ids,
|
|
39
|
+
...(repairer ? { repairer } : {}),
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
path,
|
|
44
|
+
journal,
|
|
45
|
+
collector,
|
|
46
|
+
tree,
|
|
47
|
+
ids,
|
|
48
|
+
intent,
|
|
49
|
+
fold: async () => {
|
|
50
|
+
await collector.flush();
|
|
51
|
+
const page = await journal.read();
|
|
52
|
+
return episodesOf(page.ok ? page.value.records : []);
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Confidence is the only knob most of these tests need, because it is what the
|
|
58
|
+
* default policy dispositions on: high accepts, middling holds, low refuses.
|
|
59
|
+
*/
|
|
60
|
+
export const proposalScript = (confidence) => (tree, ids, intent) => ok(buildProposal(ids, {
|
|
61
|
+
intentId: intent.intentId,
|
|
62
|
+
delta: removalDelta(tree, ids, sampleTree().ids.footer),
|
|
63
|
+
confidence,
|
|
64
|
+
}));
|
|
65
|
+
//# sourceMappingURL=episode-harness.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { FileSystem } from "../cli/filesystem.js";
|
|
2
|
+
/**
|
|
3
|
+
* A filesystem in memory, so CLI tests assert on what would be written rather
|
|
4
|
+
* than on what a temporary directory ended up containing. Failures are injectable
|
|
5
|
+
* because "wrote two files, then the disk refused" is a path the CLI has to
|
|
6
|
+
* report honestly and no real filesystem will produce on demand.
|
|
7
|
+
*/
|
|
8
|
+
export type MemoryFileSystem = FileSystem & {
|
|
9
|
+
readonly files: ReadonlyMap<string, string>;
|
|
10
|
+
};
|
|
11
|
+
export type MemoryFileSystemOptions = {
|
|
12
|
+
readonly existing?: readonly string[];
|
|
13
|
+
readonly listFails?: string;
|
|
14
|
+
readonly writeFailsAt?: string;
|
|
15
|
+
};
|
|
16
|
+
export declare const memoryFileSystem: (options?: MemoryFileSystemOptions) => MemoryFileSystem;
|
|
17
|
+
//# sourceMappingURL=filesystem.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { err, ok } from "../result.js";
|
|
2
|
+
export const memoryFileSystem = (options = {}) => {
|
|
3
|
+
const files = new Map((options.existing ?? []).map((path) => [path, ""]));
|
|
4
|
+
return {
|
|
5
|
+
files,
|
|
6
|
+
list: (directory) => Promise.resolve(options.listFails === undefined
|
|
7
|
+
? ok([...files.keys()].filter((path) => path.startsWith(`${directory}/`)))
|
|
8
|
+
: err(options.listFails)),
|
|
9
|
+
write: (path, contents) => {
|
|
10
|
+
if (options.writeFailsAt === path)
|
|
11
|
+
return Promise.resolve(err("permission denied"));
|
|
12
|
+
files.set(path, contents);
|
|
13
|
+
return Promise.resolve(ok(undefined));
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=filesystem.js.map
|