@jam-overture/loom 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/application/application.d.ts +109 -0
- package/dist/application/application.js +97 -0
- package/dist/application/memory.d.ts +20 -0
- package/dist/application/memory.js +79 -0
- package/dist/application/store.d.ts +101 -0
- package/dist/application/store.js +25 -0
- package/dist/audience/audience.d.ts +36 -0
- package/dist/audience/audience.js +41 -0
- package/dist/audience/compose.d.ts +112 -0
- package/dist/audience/compose.js +134 -0
- package/dist/audience/memory.d.ts +14 -0
- package/dist/audience/memory.js +71 -0
- package/dist/audience/overlay-store.d.ts +343 -0
- package/dist/audience/overlay-store.js +217 -0
- package/dist/audience/rule.d.ts +121 -0
- package/dist/audience/rule.js +78 -0
- package/dist/cli/index.d.ts +3 -4
- package/dist/cli/index.js +3 -4
- package/dist/cli/templates.js +19 -0
- package/dist/data/adapter.d.ts +9 -1
- package/dist/data/adapter.js +2 -0
- package/dist/data/plan.js +0 -0
- package/dist/data/resolution.d.ts +23 -1
- package/dist/data/resolve.d.ts +31 -4
- package/dist/data/resolve.js +11 -3
- package/dist/ids.d.ts +10 -0
- package/dist/ids.js +11 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interpretation/anthropic.d.ts +1 -1
- package/dist/interpretation/anthropic.js +2 -22
- package/dist/interpretation/client.d.ts +1 -1
- package/dist/interpretation/materialize.js +67 -22
- package/dist/interpretation/openai-compatible.d.ts +36 -0
- package/dist/interpretation/openai-compatible.js +79 -0
- package/dist/interpretation/status.d.ts +19 -0
- package/dist/interpretation/status.js +26 -0
- package/dist/live/index.d.ts +73 -0
- package/dist/live/index.js +73 -0
- package/dist/live/pages.d.ts +187 -0
- package/dist/live/pages.js +161 -0
- package/dist/live/pull.d.ts +147 -0
- package/dist/live/pull.js +398 -0
- package/dist/live/pulling.d.ts +79 -0
- package/dist/live/pulling.js +117 -0
- package/dist/live/window.d.ts +129 -0
- package/dist/live/window.js +132 -0
- package/dist/patch.d.ts +54 -0
- package/dist/patch.js +44 -0
- package/dist/project/closing.d.ts +51 -0
- package/dist/project/closing.js +53 -0
- package/dist/project/memory.d.ts +20 -0
- package/dist/project/memory.js +97 -0
- package/dist/project/project.d.ts +90 -0
- package/dist/project/project.js +91 -0
- package/dist/project/store.d.ts +135 -0
- package/dist/project/store.js +41 -0
- package/dist/registered.d.ts +64 -0
- package/dist/registered.js +118 -0
- package/dist/render/addressed.d.ts +35 -0
- package/dist/render/addressed.js +79 -0
- package/dist/render/behaviour-adjust.d.ts +11 -19
- package/dist/render/behaviour-adjust.js +75 -21
- package/dist/render/behaviour-present.d.ts +8 -0
- package/dist/render/behaviour-present.js +57 -6
- package/dist/render/behaviour.d.ts +98 -17
- package/dist/render/behaviour.js +91 -26
- package/dist/render/control-name.d.ts +68 -0
- package/dist/render/control-name.js +37 -0
- package/dist/render/diagnostics.d.ts +72 -0
- package/dist/render/diagnostics.js +7 -0
- package/dist/render/document-theme.d.ts +70 -0
- package/dist/render/document-theme.js +139 -0
- package/dist/render/editable.d.ts +15 -1
- package/dist/render/editable.js +13 -1
- package/dist/render/expected.d.ts +98 -0
- package/dist/render/expected.js +88 -0
- package/dist/render/index.d.ts +4 -0
- package/dist/render/index.js +4 -0
- package/dist/render/reads.d.ts +11 -0
- package/dist/render/reads.js +12 -1
- package/dist/render/render.d.ts +11 -0
- package/dist/render/render.js +294 -53
- package/dist/render/request.d.ts +8 -1
- package/dist/render/request.js +1 -0
- package/dist/render/slots.d.ts +52 -0
- package/dist/render/slots.js +24 -0
- package/dist/render/theme.d.ts +54 -1
- package/dist/render/theme.js +23 -1
- package/dist/render/unshown.d.ts +152 -0
- package/dist/render/unshown.js +80 -0
- package/dist/runtime/analysis.d.ts +94 -9
- package/dist/runtime/analysis.js +54 -9
- package/dist/runtime/assessment.d.ts +36 -2
- package/dist/runtime/assessment.js +27 -2
- package/dist/runtime/auto-apply-ceiling.d.ts +54 -0
- package/dist/runtime/auto-apply-ceiling.js +66 -0
- package/dist/runtime/checks.d.ts +148 -0
- package/dist/runtime/checks.js +112 -0
- package/dist/runtime/disposition.d.ts +96 -0
- package/dist/runtime/disposition.js +46 -0
- package/dist/runtime/gate.js +91 -10
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/index.js +4 -0
- package/dist/runtime/irreversibility.d.ts +64 -0
- package/dist/runtime/irreversibility.js +45 -0
- package/dist/runtime/nesting.d.ts +13 -1
- package/dist/runtime/nesting.js +41 -24
- package/dist/runtime/pipeline.d.ts +43 -0
- package/dist/runtime/pipeline.js +10 -2
- package/dist/runtime/policy-change.d.ts +93 -0
- package/dist/runtime/policy-change.js +305 -0
- package/dist/runtime/policy-log.d.ts +406 -0
- package/dist/runtime/policy-log.js +285 -0
- package/dist/runtime/policy.d.ts +8 -6
- package/dist/runtime/policy.js +5 -2
- package/dist/runtime/repointing.js +0 -0
- package/dist/runtime/reversibility.d.ts +11 -9
- package/dist/runtime/stakes.d.ts +129 -1
- package/dist/runtime/stakes.js +240 -26
- package/dist/runtime/vocabulary.d.ts +164 -7
- package/dist/runtime/vocabulary.js +181 -8
- package/dist/sdk/audit.d.ts +174 -3
- package/dist/sdk/audit.js +176 -17
- package/dist/sdk/catalogue.d.ts +9 -1
- package/dist/sdk/conformance.d.ts +37 -3
- package/dist/sdk/conformance.js +25 -4
- package/dist/sdk/definition.d.ts +129 -5
- package/dist/sdk/definition.js +66 -0
- package/dist/sdk/registry.d.ts +45 -2
- package/dist/sdk/registry.js +102 -1
- package/dist/signals/acted.contract.d.ts +21 -0
- package/dist/signals/acted.contract.js +236 -0
- package/dist/signals/acted.d.ts +359 -0
- package/dist/signals/acted.js +135 -0
- package/dist/signals/action-change.d.ts +507 -0
- package/dist/signals/action-change.js +265 -0
- package/dist/signals/action.d.ts +331 -0
- package/dist/signals/action.js +182 -0
- package/dist/signals/agenda.d.ts +585 -0
- package/dist/signals/agenda.js +295 -0
- package/dist/signals/applied-window.contract.d.ts +23 -0
- package/dist/signals/applied-window.contract.js +160 -0
- package/dist/signals/arrivals.contract.d.ts +21 -0
- package/dist/signals/arrivals.contract.js +180 -0
- package/dist/signals/arrivals.d.ts +375 -0
- package/dist/signals/arrivals.js +254 -0
- package/dist/signals/arriving.d.ts +210 -0
- package/dist/signals/arriving.js +133 -0
- package/dist/signals/audiences.d.ts +528 -0
- package/dist/signals/audiences.js +255 -0
- package/dist/signals/broadcast.d.ts +33 -17
- package/dist/signals/broadcast.js +255 -32
- package/dist/signals/change.d.ts +378 -0
- package/dist/signals/change.js +327 -0
- package/dist/signals/collect.d.ts +169 -34
- package/dist/signals/collect.js +186 -38
- package/dist/signals/conversion.d.ts +348 -0
- package/dist/signals/conversion.js +235 -0
- package/dist/signals/copy-change.d.ts +553 -0
- package/dist/signals/copy-change.js +377 -0
- package/dist/signals/copy.d.ts +337 -0
- package/dist/signals/copy.js +211 -0
- package/dist/signals/correlated.contract.d.ts +24 -0
- package/dist/signals/correlated.contract.js +94 -0
- package/dist/signals/counters.d.ts +97 -0
- package/dist/signals/counters.js +160 -0
- package/dist/signals/deliver.d.ts +23 -4
- package/dist/signals/deliver.js +34 -6
- package/dist/signals/deployment-change.d.ts +395 -0
- package/dist/signals/deployment-change.js +309 -0
- package/dist/signals/deployment.d.ts +278 -0
- package/dist/signals/deployment.js +178 -0
- package/dist/signals/door.d.ts +114 -0
- package/dist/signals/door.js +77 -0
- package/dist/signals/expire.d.ts +192 -0
- package/dist/signals/expire.js +213 -0
- package/dist/signals/fold.d.ts +10 -0
- package/dist/signals/fold.js +5 -1
- package/dist/signals/form-action.d.ts +302 -0
- package/dist/signals/form-action.js +169 -0
- package/dist/signals/form-copy.d.ts +523 -0
- package/dist/signals/form-copy.js +346 -0
- package/dist/signals/forms.d.ts +247 -0
- package/dist/signals/forms.js +147 -0
- package/dist/signals/frontier.d.ts +268 -0
- package/dist/signals/frontier.js +145 -0
- package/dist/signals/funnel-change.d.ts +548 -0
- package/dist/signals/funnel-change.js +361 -0
- package/dist/signals/funnel-hours.contract.d.ts +21 -0
- package/dist/signals/funnel-hours.contract.js +221 -0
- package/dist/signals/funnel-hours.d.ts +293 -0
- package/dist/signals/funnel-hours.js +99 -0
- package/dist/signals/funnel.d.ts +592 -0
- package/dist/signals/funnel.js +231 -0
- package/dist/signals/health.d.ts +694 -0
- package/dist/signals/health.js +573 -0
- package/dist/signals/index.d.ts +60 -0
- package/dist/signals/index.js +60 -0
- package/dist/signals/ingest.d.ts +56 -1
- package/dist/signals/ingest.js +91 -1
- package/dist/signals/inside.d.ts +190 -0
- package/dist/signals/inside.js +263 -0
- package/dist/signals/join.d.ts +56 -0
- package/dist/signals/join.js +60 -0
- package/dist/signals/journal.d.ts +123 -9
- package/dist/signals/kept.contract.d.ts +22 -0
- package/dist/signals/kept.contract.js +111 -0
- package/dist/signals/kinds.d.ts +8 -6
- package/dist/signals/kinds.js +14 -6
- package/dist/signals/library-action.d.ts +430 -0
- package/dist/signals/library-action.js +336 -0
- package/dist/signals/library-agenda-change.d.ts +324 -0
- package/dist/signals/library-agenda-change.js +199 -0
- package/dist/signals/library-agenda.d.ts +258 -0
- package/dist/signals/library-agenda.js +167 -0
- package/dist/signals/library-change.d.ts +477 -0
- package/dist/signals/library-change.js +335 -0
- package/dist/signals/library-copy-change.d.ts +498 -0
- package/dist/signals/library-copy-change.js +476 -0
- package/dist/signals/library-pace.d.ts +319 -0
- package/dist/signals/library-pace.js +305 -0
- package/dist/signals/library-reach-change.d.ts +646 -0
- package/dist/signals/library-reach-change.js +542 -0
- package/dist/signals/library-reach.d.ts +377 -0
- package/dist/signals/library-reach.js +227 -0
- package/dist/signals/library-senders-change.d.ts +457 -0
- package/dist/signals/library-senders-change.js +367 -0
- package/dist/signals/library-senders-reach-change.d.ts +486 -0
- package/dist/signals/library-senders-reach-change.js +538 -0
- package/dist/signals/library-senders-reach.d.ts +340 -0
- package/dist/signals/library-senders-reach.js +252 -0
- package/dist/signals/library-senders.d.ts +271 -0
- package/dist/signals/library-senders.js +180 -0
- package/dist/signals/library-word-reach-change.d.ts +567 -0
- package/dist/signals/library-word-reach-change.js +564 -0
- package/dist/signals/library.d.ts +306 -0
- package/dist/signals/library.js +178 -0
- package/dist/signals/memory.d.ts +9 -0
- package/dist/signals/memory.js +246 -14
- package/dist/signals/migrate.d.ts +20 -4
- package/dist/signals/migrate.js +269 -8
- package/dist/signals/notice.d.ts +389 -0
- package/dist/signals/notice.js +250 -0
- package/dist/signals/pace-change.d.ts +501 -0
- package/dist/signals/pace-change.js +310 -0
- package/dist/signals/pace.d.ts +296 -0
- package/dist/signals/pace.js +291 -0
- package/dist/signals/page-views.d.ts +365 -0
- package/dist/signals/page-views.js +218 -0
- package/dist/signals/part-pace.d.ts +378 -0
- package/dist/signals/part-pace.js +333 -0
- package/dist/signals/parts.d.ts +354 -0
- package/dist/signals/parts.js +232 -0
- package/dist/signals/postgres.d.ts +16 -2
- package/dist/signals/postgres.js +753 -76
- package/dist/signals/progress.d.ts +212 -0
- package/dist/signals/progress.js +150 -0
- package/dist/signals/ratios.d.ts +108 -0
- package/dist/signals/ratios.js +40 -0
- package/dist/signals/reach.d.ts +309 -0
- package/dist/signals/reach.js +93 -0
- package/dist/signals/readable.d.ts +34 -0
- package/dist/signals/readable.js +34 -0
- package/dist/signals/readership.d.ts +381 -0
- package/dist/signals/readership.js +308 -0
- package/dist/signals/region-pages.d.ts +173 -0
- package/dist/signals/region-pages.js +62 -0
- package/dist/signals/region.d.ts +287 -0
- package/dist/signals/region.js +198 -0
- package/dist/signals/retention.d.ts +163 -0
- package/dist/signals/retention.js +75 -0
- package/dist/signals/rhythm.d.ts +302 -0
- package/dist/signals/rhythm.js +262 -0
- package/dist/signals/rollup.d.ts +194 -4
- package/dist/signals/rollup.js +0 -0
- package/dist/signals/schema.d.ts +1069 -1
- package/dist/signals/schema.js +393 -3
- package/dist/signals/signal.d.ts +237 -11
- package/dist/signals/signal.js +70 -10
- package/dist/signals/silence-census.d.ts +205 -0
- package/dist/signals/silence-census.js +87 -0
- package/dist/signals/silences.d.ts +1147 -0
- package/dist/signals/silences.js +996 -0
- package/dist/signals/subtrees.d.ts +123 -0
- package/dist/signals/subtrees.js +102 -0
- package/dist/signals/tally.d.ts +262 -12
- package/dist/signals/unread.d.ts +292 -0
- package/dist/signals/unread.js +137 -0
- package/dist/signals/window-agenda.d.ts +276 -0
- package/dist/signals/window-agenda.js +83 -0
- package/dist/signals/window-figures.d.ts +148 -0
- package/dist/signals/window-figures.js +42 -0
- package/dist/signals/window-funnels.d.ts +88 -0
- package/dist/signals/window-funnels.js +47 -0
- package/dist/signals/window.d.ts +866 -0
- package/dist/signals/window.js +693 -0
- package/dist/signals/words.d.ts +24 -0
- package/dist/signals/words.js +24 -0
- package/dist/store/cache.d.ts +101 -0
- package/dist/store/cache.js +149 -0
- package/dist/store/history.d.ts +82 -0
- package/dist/store/history.js +36 -0
- package/dist/store/index.d.ts +30 -0
- package/dist/store/index.js +30 -0
- package/dist/store/memory.d.ts +2 -1
- package/dist/store/memory.js +48 -12
- package/dist/store/migrate.d.ts +106 -0
- package/dist/store/migrate.js +323 -7
- package/dist/store/postgres-applications.d.ts +4 -0
- package/dist/store/postgres-applications.js +197 -0
- package/dist/store/postgres-audience.d.ts +14 -0
- package/dist/store/postgres-audience.js +272 -0
- package/dist/store/postgres-holds.d.ts +10 -1
- package/dist/store/postgres-holds.js +116 -101
- package/dist/store/postgres-policy-log.d.ts +14 -0
- package/dist/store/postgres-policy-log.js +240 -0
- package/dist/store/postgres-projects.d.ts +4 -0
- package/dist/store/postgres-projects.js +217 -0
- package/dist/store/postgres.d.ts +17 -1
- package/dist/store/postgres.js +60 -9
- package/dist/store/replay.d.ts +102 -1
- package/dist/store/replay.js +190 -19
- package/dist/store/reseed.d.ts +238 -0
- package/dist/store/reseed.js +308 -0
- package/dist/store/schema.d.ts +762 -2
- package/dist/store/schema.js +218 -5
- package/dist/store/source.d.ts +57 -1
- package/dist/store/source.js +65 -1
- package/dist/store/store.d.ts +29 -6
- package/dist/submit/resolve.d.ts +1 -1
- package/dist/submit/resolve.js +2 -1
- package/dist/telemetry/calibration.d.ts +25 -0
- package/dist/telemetry/calibration.js +27 -1
- package/dist/telemetry/event.d.ts +391 -33
- package/dist/telemetry/event.js +84 -20
- package/dist/telemetry/index.d.ts +2 -0
- package/dist/telemetry/index.js +2 -0
- package/dist/telemetry/journal.d.ts +104 -3
- package/dist/telemetry/journal.js +9 -0
- package/dist/telemetry/lookup.d.ts +27 -0
- package/dist/telemetry/lookup.js +18 -0
- package/dist/telemetry/memory.js +33 -1
- package/dist/telemetry/migrate.js +22 -1
- package/dist/telemetry/postgres.d.ts +10 -1
- package/dist/telemetry/postgres.js +188 -90
- package/dist/telemetry/remeasure.d.ts +78 -0
- package/dist/telemetry/remeasure.js +83 -0
- package/dist/telemetry/retention.d.ts +2 -2
- package/dist/telemetry/schema.d.ts +17 -0
- package/dist/telemetry/schema.js +27 -1
- package/dist/telemetry/sink.d.ts +2 -2
- package/dist/telemetry/window.d.ts +135 -0
- package/dist/telemetry/window.js +101 -0
- package/dist/testing/application-contract.d.ts +14 -0
- package/dist/testing/application-contract.js +270 -0
- package/dist/testing/audience-overlay-contract.d.ts +31 -0
- package/dist/testing/audience-overlay-contract.js +354 -0
- package/dist/testing/contracts.d.ts +13 -7
- package/dist/testing/contracts.js +13 -7
- package/dist/testing/definitions.d.ts +78 -0
- package/dist/testing/definitions.js +134 -9
- package/dist/testing/doubles.d.ts +103 -0
- package/dist/testing/doubles.js +143 -0
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +2 -2
- package/dist/testing/journal-contract.js +297 -6
- package/dist/testing/model-contract.d.ts +110 -0
- package/dist/testing/model-contract.js +150 -0
- package/dist/testing/policy-log-contract.d.ts +26 -0
- package/dist/testing/policy-log-contract.js +344 -0
- package/dist/testing/project-contract.d.ts +14 -0
- package/dist/testing/project-contract.js +266 -0
- package/dist/testing/reader-signal-contract.d.ts +27 -2
- package/dist/testing/reader-signal-contract.js +475 -5
- package/dist/testing/store-contract.d.ts +7 -1
- package/dist/testing/store-contract.js +84 -3
- package/dist/theme/apply.d.ts +20 -1
- package/dist/theme/apply.js +5 -3
- package/dist/theme/contrast.d.ts +19 -14
- package/dist/theme/contrast.js +181 -17
- package/dist/theme/derive.d.ts +22 -0
- package/dist/theme/derive.js +54 -1
- package/dist/theme/library.js +1 -1
- package/dist/theme/measure.d.ts +34 -0
- package/dist/theme/measure.js +30 -1
- package/dist/theme/palettes.js +7 -7
- package/dist/theme/ramp.d.ts +64 -0
- package/dist/theme/ramp.js +114 -0
- package/dist/theme/registry.d.ts +9 -0
- package/dist/theme/registry.js +11 -1
- package/dist/theme/separation.d.ts +97 -3
- package/dist/theme/separation.js +75 -0
- package/dist/tree/apply.js +13 -0
- package/dist/tree/compare.d.ts +9 -0
- package/dist/tree/compare.js +18 -0
- package/dist/tree/mutation.d.ts +18 -0
- package/dist/tree/mutation.js +24 -12
- package/dist/tree/navigation.d.ts +5 -0
- package/dist/tree/navigation.js +32 -10
- package/dist/tree/outline.d.ts +7 -0
- package/dist/tree/outline.js +9 -5
- package/dist/write/computed.d.ts +60 -0
- package/dist/write/computed.js +61 -0
- package/dist/write/held.d.ts +59 -0
- package/dist/write/index.d.ts +5 -2
- package/dist/write/index.js +5 -2
- package/dist/write/reseed.d.ts +151 -0
- package/dist/write/reseed.js +184 -0
- package/dist/write/revert.js +2 -16
- package/package.json +25 -3
- package/dist/runtime/inverse-interpreter.d.ts +0 -90
- package/dist/runtime/inverse-interpreter.js +0 -56
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
import { MAX_POLICY_REVISION_LIMIT, policyFingerprintOf, policyShapeOf, } from "../runtime/index.js";
|
|
3
|
+
import { gatePolicySchema } from "../runtime/policy.js";
|
|
4
|
+
import { FIXED_INSTANT } from "./doubles.js";
|
|
5
|
+
/**
|
|
6
|
+
* One suite, run against every `PolicyLog`.
|
|
7
|
+
*
|
|
8
|
+
* The same argument as `store-contract.ts` and `journal-contract.ts`: the
|
|
9
|
+
* promises are not in the type. That a policy's revisions are dense and
|
|
10
|
+
* ascending, that recording what is already current appends nothing, that a
|
|
11
|
+
* digest naming two revisions is reported as naming two — a host discovering any
|
|
12
|
+
* of those from a production incident is the seam being offered without the
|
|
13
|
+
* thing that makes it safe to take.
|
|
14
|
+
*
|
|
15
|
+
* The outcome rules themselves live in `recordOutcomeOf`, shared by both
|
|
16
|
+
* implementations, so this suite is checking that a backend *applies* them: that
|
|
17
|
+
* it finds the right head, writes when told to and not when not, and reads back
|
|
18
|
+
* what it wrote.
|
|
19
|
+
*/
|
|
20
|
+
export const policyNamed = (policyId, overrides = {}) => gatePolicySchema.parse({ policyId, ...overrides });
|
|
21
|
+
/**
|
|
22
|
+
* A recording, with the two fields a caller always has to supply already filled
|
|
23
|
+
* in. `actor` is required by the type and is spelled out in every fixture rather
|
|
24
|
+
* than defaulted somewhere a test could forget it.
|
|
25
|
+
*/
|
|
26
|
+
export const recordingOf = (policy, overrides = {}) => ({
|
|
27
|
+
policy,
|
|
28
|
+
actor: "dana@example.com",
|
|
29
|
+
recordedAt: FIXED_INSTANT,
|
|
30
|
+
...overrides,
|
|
31
|
+
});
|
|
32
|
+
const expectRevision = (result) => {
|
|
33
|
+
expect(result.ok, result.ok ? "" : JSON.stringify(result.error)).toBe(true);
|
|
34
|
+
if (!result.ok)
|
|
35
|
+
throw new Error("unreachable");
|
|
36
|
+
return result.value;
|
|
37
|
+
};
|
|
38
|
+
export const describePolicyLogContract = (name, build) => {
|
|
39
|
+
describe(`${name} — PolicyLog contract`, () => {
|
|
40
|
+
let log;
|
|
41
|
+
beforeEach(async () => {
|
|
42
|
+
log = await build();
|
|
43
|
+
});
|
|
44
|
+
describe("recording", () => {
|
|
45
|
+
it("calls the first recording first, with no change to describe", async () => {
|
|
46
|
+
const recorded = await log.record(recordingOf(policyNamed("house")));
|
|
47
|
+
expect(recorded.ok).toBe(true);
|
|
48
|
+
if (!recorded.ok)
|
|
49
|
+
return;
|
|
50
|
+
expect(recorded.value.outcome).toBe("first");
|
|
51
|
+
expect(recorded.value.revision.revision).toBe(1);
|
|
52
|
+
expect(recorded.value.revision.policyId).toBe("house");
|
|
53
|
+
expect(recorded.value.revision.actor).toBe("dana@example.com");
|
|
54
|
+
});
|
|
55
|
+
it("stamps the fingerprint of the policy it recorded", async () => {
|
|
56
|
+
const policy = policyNamed("house", { minimumConfidence: 0.9 });
|
|
57
|
+
const recorded = await log.record(recordingOf(policy));
|
|
58
|
+
expect(recorded.ok && recorded.value.revision.fingerprint).toBe(policyFingerprintOf(policy));
|
|
59
|
+
});
|
|
60
|
+
it("numbers revisions densely from one", async () => {
|
|
61
|
+
await log.record(recordingOf(policyNamed("house")));
|
|
62
|
+
await log.record(recordingOf(policyNamed("house", { breadthThreshold: 9 })));
|
|
63
|
+
await log.record(recordingOf(policyNamed("house", { breadthThreshold: 10 })));
|
|
64
|
+
const page = await log.revisions("house");
|
|
65
|
+
expect(page.ok && page.value.revisions.map((entry) => entry.revision)).toEqual([1, 2, 3]);
|
|
66
|
+
});
|
|
67
|
+
it("describes an edit as a change, with the revision it replaced", async () => {
|
|
68
|
+
await log.record(recordingOf(policyNamed("house")));
|
|
69
|
+
const recorded = await log.record(recordingOf(policyNamed("house", { minimumConfidence: 0.9 }), { actor: "sam" }));
|
|
70
|
+
expect(recorded.ok).toBe(true);
|
|
71
|
+
if (!recorded.ok || recorded.value.outcome !== "changed") {
|
|
72
|
+
expect.fail(`expected a change, got ${recorded.ok ? recorded.value.outcome : "an error"}`);
|
|
73
|
+
}
|
|
74
|
+
expect(recorded.value.from.revision).toBe(1);
|
|
75
|
+
expect(recorded.value.revision.revision).toBe(2);
|
|
76
|
+
expect(recorded.value.revision.actor).toBe("sam");
|
|
77
|
+
expect(recorded.value.change.direction).toBe("stricter");
|
|
78
|
+
expect(recorded.value.change.fields.map((field) => field.field)).toEqual([
|
|
79
|
+
"minimumConfidence",
|
|
80
|
+
]);
|
|
81
|
+
});
|
|
82
|
+
/**
|
|
83
|
+
* The property that stops a deployment writing a revision per boot, and the
|
|
84
|
+
* reason the outcome is three-valued rather than a revision.
|
|
85
|
+
*/
|
|
86
|
+
it("appends nothing when the head already says this, and hands back the head", async () => {
|
|
87
|
+
const first = await log.record(recordingOf(policyNamed("house")));
|
|
88
|
+
const again = await log.record(recordingOf(policyNamed("house"), { actor: "someone else" }));
|
|
89
|
+
expect(again.ok).toBe(true);
|
|
90
|
+
if (!again.ok)
|
|
91
|
+
return;
|
|
92
|
+
expect(again.value.outcome).toBe("unchanged");
|
|
93
|
+
expect(again.value.revision.revision).toBe(1);
|
|
94
|
+
expect(again.value.revision.actor).toBe("dana@example.com");
|
|
95
|
+
expect(first.ok && first.value.revision.recordedAt).toBe(again.value.revision.recordedAt);
|
|
96
|
+
const page = await log.revisions("house");
|
|
97
|
+
expect(page.ok && page.value.revisions).toHaveLength(1);
|
|
98
|
+
});
|
|
99
|
+
/**
|
|
100
|
+
* Idempotence is against the head and never against history: going back to
|
|
101
|
+
* an earlier policy is a decision somebody made at a time, and a log that
|
|
102
|
+
* swallowed it would lose the revert.
|
|
103
|
+
*/
|
|
104
|
+
it("records a return to an earlier policy as its own revision", async () => {
|
|
105
|
+
const open = policyNamed("house");
|
|
106
|
+
await log.record(recordingOf(open));
|
|
107
|
+
await log.record(recordingOf(policyNamed("house", { minimumConfidence: 0.9 })));
|
|
108
|
+
const back = await log.record(recordingOf(open, { actor: "sam" }));
|
|
109
|
+
expect(back.ok && back.value.outcome).toBe("changed");
|
|
110
|
+
expect(back.ok && back.value.revision.revision).toBe(3);
|
|
111
|
+
const page = await log.revisions("house");
|
|
112
|
+
expect(page.ok && page.value.revisions.map((entry) => entry.revision)).toEqual([1, 2, 3]);
|
|
113
|
+
});
|
|
114
|
+
/** A rename is an edit, which is what a host is asked to do (0033). */
|
|
115
|
+
it("records a rename, although the rules are byte for byte the same", async () => {
|
|
116
|
+
await log.record(recordingOf(policyNamed("house", { minimumConfidence: 0.9 })));
|
|
117
|
+
const renamed = await log.record(recordingOf(policyNamed("house-v2", { minimumConfidence: 0.9 })));
|
|
118
|
+
expect(renamed.ok && renamed.value.outcome).toBe("first");
|
|
119
|
+
expect(renamed.ok && renamed.value.revision.revision).toBe(1);
|
|
120
|
+
});
|
|
121
|
+
it("keeps a note when one was given, and omits the key when none was", async () => {
|
|
122
|
+
const noted = await log.record(recordingOf(policyNamed("house"), { note: "after the October incident" }));
|
|
123
|
+
await log.record(recordingOf(policyNamed("house", { breadthThreshold: 9 })));
|
|
124
|
+
expect(noted.ok && noted.value.revision.note).toBe("after the October incident");
|
|
125
|
+
const page = await log.revisions("house");
|
|
126
|
+
expect(page.ok && page.value.revisions[1] && "note" in page.value.revisions[1]).toBe(false);
|
|
127
|
+
});
|
|
128
|
+
it("reads a policy back whole, with every knob it was recorded with", async () => {
|
|
129
|
+
const policy = policyNamed("house", {
|
|
130
|
+
protectedPrimitiveTypes: ["loom.card"],
|
|
131
|
+
interactiveTypes: { "loom.link": { whenProps: ["href"] } },
|
|
132
|
+
removalThresholds: { medium: 4, high: 16 },
|
|
133
|
+
autoApplyCeiling: { developer: "critical" },
|
|
134
|
+
refusalFloor: "high",
|
|
135
|
+
});
|
|
136
|
+
await log.record(recordingOf(policy));
|
|
137
|
+
const head = expectRevision(await log.current("house"));
|
|
138
|
+
expect(head.policy).toEqual(policy);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
describe("recording against an expected revision", () => {
|
|
142
|
+
it("accepts the recording when the head is the one the caller expected", async () => {
|
|
143
|
+
await log.record(recordingOf(policyNamed("house")));
|
|
144
|
+
const next = await log.record(recordingOf(policyNamed("house", { breadthThreshold: 9 }), { expectedRevision: 1 }));
|
|
145
|
+
expect(next.ok && next.value.revision.revision).toBe(2);
|
|
146
|
+
});
|
|
147
|
+
it("accepts zero as the caller saying nothing is recorded yet", async () => {
|
|
148
|
+
const first = await log.record(recordingOf(policyNamed("house"), { expectedRevision: 0 }));
|
|
149
|
+
expect(first.ok && first.value.outcome).toBe("first");
|
|
150
|
+
});
|
|
151
|
+
it("refuses and writes nothing when somebody recorded in between", async () => {
|
|
152
|
+
await log.record(recordingOf(policyNamed("house")));
|
|
153
|
+
await log.record(recordingOf(policyNamed("house", { breadthThreshold: 9 })));
|
|
154
|
+
const stale = await log.record(recordingOf(policyNamed("house", { breadthThreshold: 20 }), { expectedRevision: 1 }));
|
|
155
|
+
expect(stale.ok).toBe(false);
|
|
156
|
+
if (stale.ok)
|
|
157
|
+
return;
|
|
158
|
+
expect(stale.error).toEqual({
|
|
159
|
+
code: "out-of-date",
|
|
160
|
+
policyId: "house",
|
|
161
|
+
expected: 1,
|
|
162
|
+
current: 2,
|
|
163
|
+
});
|
|
164
|
+
const page = await log.revisions("house");
|
|
165
|
+
expect(page.ok && page.value.revisions).toHaveLength(2);
|
|
166
|
+
});
|
|
167
|
+
it("refuses a first recording that expected a head", async () => {
|
|
168
|
+
const stale = await log.record(recordingOf(policyNamed("house"), { expectedRevision: 1 }));
|
|
169
|
+
expect(stale.ok).toBe(false);
|
|
170
|
+
expect(!stale.ok && stale.error.code).toBe("out-of-date");
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
describe("reading the head", () => {
|
|
174
|
+
it("says so when nothing was ever recorded under the name", async () => {
|
|
175
|
+
const missing = await log.current("never-written");
|
|
176
|
+
expect(missing.ok).toBe(false);
|
|
177
|
+
expect(!missing.ok && missing.error).toEqual({
|
|
178
|
+
code: "no-such-policy",
|
|
179
|
+
policyId: "never-written",
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
it("answers with the newest revision", async () => {
|
|
183
|
+
await log.record(recordingOf(policyNamed("house")));
|
|
184
|
+
await log.record(recordingOf(policyNamed("house", { minimumConfidence: 0.9 })));
|
|
185
|
+
const head = expectRevision(await log.current("house"));
|
|
186
|
+
expect(head.revision).toBe(2);
|
|
187
|
+
expect(head.policy.minimumConfidence).toBe(0.9);
|
|
188
|
+
});
|
|
189
|
+
it("keeps two names apart", async () => {
|
|
190
|
+
await log.record(recordingOf(policyNamed("house")));
|
|
191
|
+
await log.record(recordingOf(policyNamed("tenant-a", { breadthThreshold: 2 })));
|
|
192
|
+
await log.record(recordingOf(policyNamed("tenant-a", { breadthThreshold: 3 })));
|
|
193
|
+
expect(expectRevision(await log.current("house")).revision).toBe(1);
|
|
194
|
+
expect(expectRevision(await log.current("tenant-a")).revision).toBe(2);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
describe("paging a history", () => {
|
|
198
|
+
const twelve = async (target) => {
|
|
199
|
+
await target.record(recordingOf(policyNamed("house")));
|
|
200
|
+
for (let threshold = 9; threshold <= 19; threshold += 1) {
|
|
201
|
+
await target.record(recordingOf(policyNamed("house", { breadthThreshold: threshold })));
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
it("says so when nothing was ever recorded under the name", async () => {
|
|
205
|
+
const missing = await log.revisions("never-written");
|
|
206
|
+
expect(!missing.ok && missing.error.code).toBe("no-such-policy");
|
|
207
|
+
});
|
|
208
|
+
it("pages from the oldest end by default", async () => {
|
|
209
|
+
await twelve(log);
|
|
210
|
+
const page = await log.revisions("house", { limit: 5 });
|
|
211
|
+
expect(page.ok && page.value.revisions.map((entry) => entry.revision)).toEqual([
|
|
212
|
+
1, 2, 3, 4, 5,
|
|
213
|
+
]);
|
|
214
|
+
expect(page.ok && page.value.older).toBeNull();
|
|
215
|
+
expect(page.ok && page.value.newer).not.toBeNull();
|
|
216
|
+
});
|
|
217
|
+
it("pages from the newest end when asked, and still answers ascending", async () => {
|
|
218
|
+
await twelve(log);
|
|
219
|
+
const page = await log.revisions("house", { direction: "older", limit: 5 });
|
|
220
|
+
expect(page.ok && page.value.revisions.map((entry) => entry.revision)).toEqual([
|
|
221
|
+
8, 9, 10, 11, 12,
|
|
222
|
+
]);
|
|
223
|
+
expect(page.ok && page.value.newer).toBeNull();
|
|
224
|
+
expect(page.ok && page.value.older).not.toBeNull();
|
|
225
|
+
});
|
|
226
|
+
it("walks the whole log in either direction, with no gap and no repeat", async () => {
|
|
227
|
+
await twelve(log);
|
|
228
|
+
for (const direction of ["newer", "older"]) {
|
|
229
|
+
const seen = [];
|
|
230
|
+
let cursor;
|
|
231
|
+
for (let page = 0; page < 10; page += 1) {
|
|
232
|
+
const read = await log.revisions("house", {
|
|
233
|
+
direction,
|
|
234
|
+
limit: 5,
|
|
235
|
+
...(cursor === undefined ? {} : { cursor }),
|
|
236
|
+
});
|
|
237
|
+
expect(read.ok).toBe(true);
|
|
238
|
+
if (!read.ok)
|
|
239
|
+
return;
|
|
240
|
+
seen.push(...read.value.revisions.map((entry) => entry.revision));
|
|
241
|
+
const next = direction === "newer" ? read.value.newer : read.value.older;
|
|
242
|
+
if (next === null)
|
|
243
|
+
break;
|
|
244
|
+
cursor = next;
|
|
245
|
+
}
|
|
246
|
+
expect(seen.slice().sort((left, right) => left - right)).toEqual(Array.from({ length: 12 }, (_, index) => index + 1));
|
|
247
|
+
expect(new Set(seen).size).toBe(12);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
it("honours a limit", async () => {
|
|
251
|
+
await twelve(log);
|
|
252
|
+
const page = await log.revisions("house", { limit: 3 });
|
|
253
|
+
expect(page.ok && page.value.revisions.map((entry) => entry.revision)).toEqual([1, 2, 3]);
|
|
254
|
+
});
|
|
255
|
+
/**
|
|
256
|
+
* The ceiling is weakly observable here and strongly observable in
|
|
257
|
+
* `policy-log.test.ts`, which drives a log past it: a suite that has to run
|
|
258
|
+
* against Postgres cannot afford to record a hundred and one revisions, and
|
|
259
|
+
* a suite that never exceeds the ceiling cannot see it. Both
|
|
260
|
+
* implementations clamp through `clampPolicyRevisionLimit`, which is tested
|
|
261
|
+
* on its own; this holds the call sites to using it at all.
|
|
262
|
+
*/
|
|
263
|
+
it("clamps a limit nobody should be able to ask for", async () => {
|
|
264
|
+
await twelve(log);
|
|
265
|
+
const page = await log.revisions("house", { limit: 10_000 });
|
|
266
|
+
expect(page.ok && page.value.revisions.length).toBeLessThanOrEqual(MAX_POLICY_REVISION_LIMIT);
|
|
267
|
+
});
|
|
268
|
+
it("starts from the end the direction begins at when a cursor is nonsense", async () => {
|
|
269
|
+
await twelve(log);
|
|
270
|
+
const page = await log.revisions("house", { cursor: "not-a-position", limit: 3 });
|
|
271
|
+
expect(page.ok && page.value.revisions.map((entry) => entry.revision)).toEqual([1, 2, 3]);
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
describe("the fingerprint join", () => {
|
|
275
|
+
it("finds the revision a judgment ran under", async () => {
|
|
276
|
+
const open = policyNamed("house");
|
|
277
|
+
const strict = policyNamed("house", { minimumConfidence: 0.9 });
|
|
278
|
+
await log.record(recordingOf(open));
|
|
279
|
+
await log.record(recordingOf(strict));
|
|
280
|
+
const found = await log.judgedUnder("house", policyFingerprintOf(open));
|
|
281
|
+
expect(found.ok).toBe(true);
|
|
282
|
+
if (!found.ok || found.value.outcome !== "recorded") {
|
|
283
|
+
expect.fail(`expected one match, got ${found.ok ? found.value.outcome : "an error"}`);
|
|
284
|
+
}
|
|
285
|
+
expect(found.value.revision.revision).toBe(1);
|
|
286
|
+
expect(found.value.revision.policy).toEqual(open);
|
|
287
|
+
});
|
|
288
|
+
/**
|
|
289
|
+
* The outcome a single-answer signature would have got wrong. A policy
|
|
290
|
+
* taken to B and back to A has two revisions with one digest — correctly,
|
|
291
|
+
* they are the same rules — and nothing can say which of them a judgment
|
|
292
|
+
* ran under.
|
|
293
|
+
*/
|
|
294
|
+
it("refuses to choose when a policy was changed and changed back", async () => {
|
|
295
|
+
const open = policyNamed("house");
|
|
296
|
+
await log.record(recordingOf(open));
|
|
297
|
+
await log.record(recordingOf(policyNamed("house", { minimumConfidence: 0.9 })));
|
|
298
|
+
await log.record(recordingOf(open));
|
|
299
|
+
const found = await log.judgedUnder("house", policyFingerprintOf(open));
|
|
300
|
+
expect(found.ok).toBe(true);
|
|
301
|
+
if (!found.ok || found.value.outcome !== "ambiguous") {
|
|
302
|
+
expect.fail(`expected ambiguity, got ${found.ok ? found.value.outcome : "an error"}`);
|
|
303
|
+
}
|
|
304
|
+
expect(found.value.revisions.map((entry) => entry.revision)).toEqual([1, 3]);
|
|
305
|
+
});
|
|
306
|
+
it("reports a judgment whose policy was never recorded, and says what is held", async () => {
|
|
307
|
+
const recorded = policyNamed("house");
|
|
308
|
+
await log.record(recordingOf(recorded));
|
|
309
|
+
const elsewhere = policyFingerprintOf(policyNamed("house", { breadthThreshold: 99 }));
|
|
310
|
+
const found = await log.judgedUnder("house", elsewhere);
|
|
311
|
+
expect(found.ok).toBe(true);
|
|
312
|
+
if (!found.ok || found.value.outcome !== "unrecorded") {
|
|
313
|
+
expect.fail(`expected unrecorded, got ${found.ok ? found.value.outcome : "an error"}`);
|
|
314
|
+
}
|
|
315
|
+
expect(found.value.fingerprint).toBe(elsewhere);
|
|
316
|
+
expect(found.value.heldShapes).toEqual([
|
|
317
|
+
policyShapeOf(policyFingerprintOf(recorded)),
|
|
318
|
+
]);
|
|
319
|
+
});
|
|
320
|
+
/**
|
|
321
|
+
* An empty `heldShapes` is the fact that separates *nothing was recorded
|
|
322
|
+
* under this name* from *everything recorded here came from another build*,
|
|
323
|
+
* and it is a reading rather than an error: a judgment that ran under an
|
|
324
|
+
* unlogged policy is exactly the case this field exists to describe.
|
|
325
|
+
*/
|
|
326
|
+
it("answers for a name with nothing in it rather than failing", async () => {
|
|
327
|
+
const found = await log.judgedUnder("never-written", "abcdef12:0123456789abcdef");
|
|
328
|
+
expect(found.ok).toBe(true);
|
|
329
|
+
if (!found.ok || found.value.outcome !== "unrecorded") {
|
|
330
|
+
expect.fail("expected unrecorded");
|
|
331
|
+
}
|
|
332
|
+
expect(found.value.heldShapes).toEqual([]);
|
|
333
|
+
});
|
|
334
|
+
it("does not reach into another policy's revisions", async () => {
|
|
335
|
+
const shared = policyNamed("tenant-a", { breadthThreshold: 9 });
|
|
336
|
+
await log.record(recordingOf(policyNamed("house")));
|
|
337
|
+
await log.record(recordingOf(shared));
|
|
338
|
+
const found = await log.judgedUnder("house", policyFingerprintOf(shared));
|
|
339
|
+
expect(found.ok && found.value.outcome).toBe("unrecorded");
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
};
|
|
344
|
+
//# sourceMappingURL=policy-log-contract.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Project } from "../project/project.js";
|
|
2
|
+
import type { ProjectStore } from "../project/store.js";
|
|
3
|
+
/**
|
|
4
|
+
* One suite, two implementations.
|
|
5
|
+
*
|
|
6
|
+
* `memoryProjectStore` calls itself the reference implementation; this is what
|
|
7
|
+
* makes that claim checkable rather than aspirational, on the same terms
|
|
8
|
+
* `store-contract.ts` and `hold-contract.ts` already set. The alternative —
|
|
9
|
+
* each store asserted against its own expectations — is how two stores that
|
|
10
|
+
* disagree both stay green.
|
|
11
|
+
*/
|
|
12
|
+
export declare const projectFixture: (over?: Partial<Project>) => Project;
|
|
13
|
+
export declare const describeProjectStoreContract: (name: string, make: () => Promise<ProjectStore> | ProjectStore) => void;
|
|
14
|
+
//# sourceMappingURL=project-contract.d.ts.map
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { projectIdSchema, projectSchema } from "../project/project.js";
|
|
3
|
+
/**
|
|
4
|
+
* One suite, two implementations.
|
|
5
|
+
*
|
|
6
|
+
* `memoryProjectStore` calls itself the reference implementation; this is what
|
|
7
|
+
* makes that claim checkable rather than aspirational, on the same terms
|
|
8
|
+
* `store-contract.ts` and `hold-contract.ts` already set. The alternative —
|
|
9
|
+
* each store asserted against its own expectations — is how two stores that
|
|
10
|
+
* disagree both stay green.
|
|
11
|
+
*/
|
|
12
|
+
export const projectFixture = (over = {}) => projectSchema.parse({
|
|
13
|
+
projectId: projectIdSchema.parse("prj_fixture"),
|
|
14
|
+
name: "A fixture",
|
|
15
|
+
createdAt: "2026-10-12T12:00:00.000Z",
|
|
16
|
+
...over,
|
|
17
|
+
});
|
|
18
|
+
export const describeProjectStoreContract = (name, make) => {
|
|
19
|
+
describe(`${name} — the project store contract`, () => {
|
|
20
|
+
it("reads back what it recorded", async () => {
|
|
21
|
+
const store = await make();
|
|
22
|
+
const project = projectFixture({ name: "The bakery" });
|
|
23
|
+
expect(await store.create(project)).toEqual({ ok: true, value: project });
|
|
24
|
+
expect(await store.get(project.projectId)).toEqual({ ok: true, value: project });
|
|
25
|
+
});
|
|
26
|
+
it("refuses an id already taken rather than overwriting the rows under it", async () => {
|
|
27
|
+
const store = await make();
|
|
28
|
+
const first = projectFixture({ name: "The first" });
|
|
29
|
+
await store.create(first);
|
|
30
|
+
const second = await store.create(projectFixture({ name: "The second" }));
|
|
31
|
+
expect(second).toEqual({
|
|
32
|
+
ok: false,
|
|
33
|
+
error: { code: "already-exists", projectId: first.projectId },
|
|
34
|
+
});
|
|
35
|
+
const read = await store.get(first.projectId);
|
|
36
|
+
expect(read.ok && read.value.name).toBe("The first");
|
|
37
|
+
});
|
|
38
|
+
it("says not-found rather than returning nothing", async () => {
|
|
39
|
+
const store = await make();
|
|
40
|
+
const missing = projectIdSchema.parse("prj_nobody");
|
|
41
|
+
expect(await store.get(missing)).toEqual({
|
|
42
|
+
ok: false,
|
|
43
|
+
error: { code: "not-found", projectId: missing },
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
it("lists nothing before anything is recorded", async () => {
|
|
47
|
+
const store = await make();
|
|
48
|
+
expect(await store.list()).toEqual({ ok: true, value: [] });
|
|
49
|
+
});
|
|
50
|
+
it("lists oldest first, whatever order they were written in", async () => {
|
|
51
|
+
const store = await make();
|
|
52
|
+
await store.create(projectFixture({
|
|
53
|
+
projectId: projectIdSchema.parse("prj_third"),
|
|
54
|
+
createdAt: "2026-10-12T14:00:00.000Z",
|
|
55
|
+
}));
|
|
56
|
+
await store.create(projectFixture({
|
|
57
|
+
projectId: projectIdSchema.parse("prj_first"),
|
|
58
|
+
createdAt: "2026-10-12T10:00:00.000Z",
|
|
59
|
+
}));
|
|
60
|
+
await store.create(projectFixture({
|
|
61
|
+
projectId: projectIdSchema.parse("prj_second"),
|
|
62
|
+
createdAt: "2026-10-12T12:00:00.000Z",
|
|
63
|
+
}));
|
|
64
|
+
const listed = await store.list();
|
|
65
|
+
expect(listed.ok && listed.value.map((project) => project.projectId)).toEqual([
|
|
66
|
+
"prj_first",
|
|
67
|
+
"prj_second",
|
|
68
|
+
"prj_third",
|
|
69
|
+
]);
|
|
70
|
+
});
|
|
71
|
+
it("renames without touching anything else", async () => {
|
|
72
|
+
const store = await make();
|
|
73
|
+
const project = projectFixture({ name: "Before" });
|
|
74
|
+
await store.create(project);
|
|
75
|
+
const renamed = await store.rename(project.projectId, { name: "After" });
|
|
76
|
+
expect(renamed).toEqual({
|
|
77
|
+
ok: true,
|
|
78
|
+
value: { ...project, name: "After" },
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
it("refuses to rename a project that is not there", async () => {
|
|
82
|
+
const store = await make();
|
|
83
|
+
const missing = projectIdSchema.parse("prj_nobody");
|
|
84
|
+
expect(await store.rename(missing, { name: "Anything" })).toEqual({
|
|
85
|
+
ok: false,
|
|
86
|
+
error: { code: "not-found", projectId: missing },
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
/**
|
|
90
|
+
* The two stores have to agree about what a project is, not merely about
|
|
91
|
+
* what they store. An empty name is the cheapest way to ask: `projectSchema`
|
|
92
|
+
* refuses it, and a store that spread the change instead of parsing it would
|
|
93
|
+
* accept it here and be refused by the column somewhere else.
|
|
94
|
+
*/
|
|
95
|
+
it("refuses a rename the project schema would not accept", async () => {
|
|
96
|
+
const store = await make();
|
|
97
|
+
const project = projectFixture();
|
|
98
|
+
await store.create(project);
|
|
99
|
+
const refused = await store.rename(project.projectId, { name: "" });
|
|
100
|
+
expect(refused.ok).toBe(false);
|
|
101
|
+
const read = await store.get(project.projectId);
|
|
102
|
+
expect(read.ok && read.value.name).toBe(project.name);
|
|
103
|
+
});
|
|
104
|
+
/**
|
|
105
|
+
* ## The repository (0292)
|
|
106
|
+
*
|
|
107
|
+
* At most one per project, and at most one project per repository. The
|
|
108
|
+
* second half is the one with teeth: two projects naming one repository
|
|
109
|
+
* would be two write-back destinations for one pull request, and nothing
|
|
110
|
+
* afterwards could say which was meant.
|
|
111
|
+
*/
|
|
112
|
+
describe("the repository", () => {
|
|
113
|
+
it("keeps the repository it was given", async () => {
|
|
114
|
+
const store = await make();
|
|
115
|
+
const project = projectFixture({ repository: "jam-overture/loom" });
|
|
116
|
+
expect(await store.create(project)).toEqual({ ok: true, value: project });
|
|
117
|
+
const read = await store.get(project.projectId);
|
|
118
|
+
expect(read.ok && read.value.repository).toBe("jam-overture/loom");
|
|
119
|
+
});
|
|
120
|
+
it("takes a project with no repository, which is the ordinary first state", async () => {
|
|
121
|
+
const store = await make();
|
|
122
|
+
const project = projectFixture();
|
|
123
|
+
expect(await store.create(project)).toEqual({ ok: true, value: project });
|
|
124
|
+
const read = await store.get(project.projectId);
|
|
125
|
+
expect(read.ok && read.value.repository).toBeUndefined();
|
|
126
|
+
});
|
|
127
|
+
it("refuses a repository another project already names", async () => {
|
|
128
|
+
const store = await make();
|
|
129
|
+
await store.create(projectFixture({
|
|
130
|
+
projectId: projectIdSchema.parse("prj_first"),
|
|
131
|
+
repository: "jam-overture/loom",
|
|
132
|
+
}));
|
|
133
|
+
const second = await store.create(projectFixture({
|
|
134
|
+
projectId: projectIdSchema.parse("prj_second"),
|
|
135
|
+
repository: "jam-overture/loom",
|
|
136
|
+
}));
|
|
137
|
+
expect(second.ok).toBe(false);
|
|
138
|
+
expect(!second.ok && second.error.code).toBe("repository-taken");
|
|
139
|
+
});
|
|
140
|
+
/**
|
|
141
|
+
* The partial index's reason. A plain unique index would admit exactly
|
|
142
|
+
* one project with no repository, which is the state almost every
|
|
143
|
+
* project starts in.
|
|
144
|
+
*/
|
|
145
|
+
it("lets any number of projects have none", async () => {
|
|
146
|
+
const store = await make();
|
|
147
|
+
await store.create(projectFixture({ projectId: projectIdSchema.parse("prj_a") }));
|
|
148
|
+
await store.create(projectFixture({ projectId: projectIdSchema.parse("prj_b") }));
|
|
149
|
+
const listed = await store.list();
|
|
150
|
+
expect(listed.ok && listed.value).toHaveLength(2);
|
|
151
|
+
});
|
|
152
|
+
/**
|
|
153
|
+
* An id collision with a repository set must not be reported as a taken
|
|
154
|
+
* repository. They are different faults and a screen puts them on
|
|
155
|
+
* different inputs.
|
|
156
|
+
*/
|
|
157
|
+
it("calls an id collision an id collision, even with a repository set", async () => {
|
|
158
|
+
const store = await make();
|
|
159
|
+
const first = projectFixture({ repository: "jam-overture/loom" });
|
|
160
|
+
await store.create(first);
|
|
161
|
+
const again = await store.create({ ...first, name: "A second" });
|
|
162
|
+
expect(again.ok).toBe(false);
|
|
163
|
+
expect(!again.ok && again.error.code).toBe("already-exists");
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
/**
|
|
167
|
+
* ## Closing (0289)
|
|
168
|
+
*
|
|
169
|
+
* What this store has instead of a delete. The failure these guard is the
|
|
170
|
+
* one a soft delete usually ships with: a row that has stopped according to
|
|
171
|
+
* one read and is still there according to another.
|
|
172
|
+
*/
|
|
173
|
+
describe("closing", () => {
|
|
174
|
+
const AT = "2026-10-16T09:00:00.000Z";
|
|
175
|
+
const LATER = "2026-10-16T10:00:00.000Z";
|
|
176
|
+
it("stamps when it was closed", async () => {
|
|
177
|
+
const store = await make();
|
|
178
|
+
const project = projectFixture();
|
|
179
|
+
await store.create(project);
|
|
180
|
+
const closed = await store.close(project.projectId, AT);
|
|
181
|
+
expect(closed.ok && closed.value.closedAt).toBe(AT);
|
|
182
|
+
});
|
|
183
|
+
/**
|
|
184
|
+
* A closed project is still there, and `get` says so. A store that
|
|
185
|
+
* answered `not-found` about a row it is holding would be lying about its
|
|
186
|
+
* contents, and the first casualty is the audit that goes looking for
|
|
187
|
+
* exactly those rows.
|
|
188
|
+
*/
|
|
189
|
+
it("still answers for it by id", async () => {
|
|
190
|
+
const store = await make();
|
|
191
|
+
const project = projectFixture();
|
|
192
|
+
await store.create(project);
|
|
193
|
+
await store.close(project.projectId, AT);
|
|
194
|
+
const read = await store.get(project.projectId);
|
|
195
|
+
expect(read.ok && read.value.projectId).toBe(project.projectId);
|
|
196
|
+
expect(read.ok && read.value.closedAt).toBe(AT);
|
|
197
|
+
});
|
|
198
|
+
it("leaves it out of a listing that did not ask for it", async () => {
|
|
199
|
+
const store = await make();
|
|
200
|
+
const project = projectFixture();
|
|
201
|
+
await store.create(project);
|
|
202
|
+
await store.close(project.projectId, AT);
|
|
203
|
+
const listed = await store.list();
|
|
204
|
+
expect(listed.ok && listed.value).toEqual([]);
|
|
205
|
+
});
|
|
206
|
+
it("lists it when asked for closed, and not the open ones", async () => {
|
|
207
|
+
const store = await make();
|
|
208
|
+
const open = projectFixture({ projectId: projectIdSchema.parse("prj_open") });
|
|
209
|
+
const shut = projectFixture({ projectId: projectIdSchema.parse("prj_shut") });
|
|
210
|
+
await store.create(open);
|
|
211
|
+
await store.create(shut);
|
|
212
|
+
await store.close(shut.projectId, AT);
|
|
213
|
+
const listed = await store.list({ closed: true });
|
|
214
|
+
expect(listed.ok && listed.value.map((project) => project.projectId)).toEqual([
|
|
215
|
+
shut.projectId,
|
|
216
|
+
]);
|
|
217
|
+
});
|
|
218
|
+
it("lists both when asked for everything", async () => {
|
|
219
|
+
const store = await make();
|
|
220
|
+
const open = projectFixture({ projectId: projectIdSchema.parse("prj_open") });
|
|
221
|
+
const shut = projectFixture({ projectId: projectIdSchema.parse("prj_shut") });
|
|
222
|
+
await store.create(open);
|
|
223
|
+
await store.create(shut);
|
|
224
|
+
await store.close(shut.projectId, AT);
|
|
225
|
+
const listed = await store.list({ closed: "all" });
|
|
226
|
+
expect(listed.ok && listed.value).toHaveLength(2);
|
|
227
|
+
});
|
|
228
|
+
/**
|
|
229
|
+
* The instant must not move. *When did this stop* is the question a
|
|
230
|
+
* closed project is asked, and a second press is not a second stopping.
|
|
231
|
+
*/
|
|
232
|
+
it("does not move the instant when it is closed again", async () => {
|
|
233
|
+
const store = await make();
|
|
234
|
+
const project = projectFixture();
|
|
235
|
+
await store.create(project);
|
|
236
|
+
await store.close(project.projectId, AT);
|
|
237
|
+
const again = await store.close(project.projectId, LATER);
|
|
238
|
+
expect(again.ok && again.value.closedAt).toBe(AT);
|
|
239
|
+
});
|
|
240
|
+
it("opens it again, and the stamp goes rather than emptying", async () => {
|
|
241
|
+
const store = await make();
|
|
242
|
+
const project = projectFixture();
|
|
243
|
+
await store.create(project);
|
|
244
|
+
await store.close(project.projectId, AT);
|
|
245
|
+
const reopened = await store.reopen(project.projectId);
|
|
246
|
+
expect(reopened.ok && reopened.value.closedAt).toBeUndefined();
|
|
247
|
+
const listed = await store.list();
|
|
248
|
+
expect(listed.ok && listed.value).toHaveLength(1);
|
|
249
|
+
});
|
|
250
|
+
it("reopens one that was never closed without complaining", async () => {
|
|
251
|
+
const store = await make();
|
|
252
|
+
const project = projectFixture();
|
|
253
|
+
await store.create(project);
|
|
254
|
+
const reopened = await store.reopen(project.projectId);
|
|
255
|
+
expect(reopened.ok && reopened.value.closedAt).toBeUndefined();
|
|
256
|
+
});
|
|
257
|
+
it("says so when there is no such project to close", async () => {
|
|
258
|
+
const store = await make();
|
|
259
|
+
const closed = await store.close(projectIdSchema.parse("prj_nothing"), AT);
|
|
260
|
+
expect(closed.ok).toBe(false);
|
|
261
|
+
expect(!closed.ok && closed.error.code).toBe("not-found");
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
};
|
|
266
|
+
//# sourceMappingURL=project-contract.js.map
|