@sema-agent/core 7.62.0 → 7.64.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/CHANGELOG.md +936 -0
- package/dist/agents/cc-peer-directory.js +1 -0
- package/dist/agents/cc-peer-wire.d.ts +4 -0
- package/dist/agents/cc-peer-wire.js +1 -0
- package/dist/agents/cc-uds-peer-channel.js +5 -0
- package/dist/agents/cross-session-judge.d.ts +3 -1
- package/dist/agents/cross-session-judge.js +4 -1
- package/dist/agents/peer-directory.d.ts +8 -0
- package/dist/agents/peer-directory.js +4 -0
- package/dist/agents/peer-held-queue.d.ts +9 -3
- package/dist/agents/peer-held-queue.js +12 -9
- package/dist/agents/peer-idle.d.ts +20 -1
- package/dist/agents/peer-idle.js +23 -12
- package/dist/agents/peer-notice-route.d.ts +16 -5
- package/dist/agents/peer-notice-route.js +11 -9
- package/dist/agents/peer-notices.d.ts +25 -8
- package/dist/agents/peer-notices.js +6 -1
- package/dist/agents/peer-session-drain.d.ts +32 -6
- package/dist/agents/peer-session-drain.js +100 -26
- package/dist/agents/send-message-tool.d.ts +7 -0
- package/dist/agents/send-message-tool.js +18 -6
- package/dist/agents/subagent-transcript-placement.d.ts +23 -0
- package/dist/agents/subagent-transcript-placement.js +14 -0
- package/dist/agents/subagent.js +102 -54
- package/dist/brain/route-adjudicator.js +9 -4
- package/dist/core/allow-entry.d.ts +4 -0
- package/dist/core/approval-object.js +1 -1
- package/dist/core/arg-summary.js +1 -1
- package/dist/core/ask-origin.d.ts +1 -1
- package/dist/core/ask-origin.js +2 -2
- package/dist/core/ask-question.d.ts +2 -2
- package/dist/core/ask-unresolvable-notice.d.ts +13 -4
- package/dist/core/ask-unresolvable-notice.js +10 -3
- package/dist/core/auto-compaction.d.ts +7 -5
- package/dist/core/background-agent-store.d.ts +7 -0
- package/dist/core/background-agent-store.js +3 -0
- package/dist/core/canonical-json.d.ts +23 -13
- package/dist/core/canonical-json.js +4 -4
- package/dist/core/checkpoint-queries.d.ts +50 -4
- package/dist/core/checkpoint-queries.js +42 -17
- package/dist/core/checkpoint-requirements.d.ts +3 -3
- package/dist/core/checkpoint-requirements.js +2 -1
- package/dist/core/checkpoint-row-verdict.d.ts +15 -4
- package/dist/core/checkpoint-row-verdict.js +22 -2
- package/dist/core/checkpoint-store.d.ts +28 -11
- package/dist/core/checkpoint-store.js +45 -4
- package/dist/core/compliance.d.ts +6 -2
- package/dist/core/compliance.js +3 -3
- package/dist/core/context-settings.d.ts +40 -9
- package/dist/core/context-settings.js +32 -10
- package/dist/core/engine-attestation.d.ts +27 -7
- package/dist/core/engine-attestation.js +5 -1
- package/dist/core/engine-notice.d.ts +43 -5
- package/dist/core/extension-requester.d.ts +9 -0
- package/dist/core/extension-requester.js +7 -0
- package/dist/core/file-history-store.d.ts +28 -0
- package/dist/core/file-history-store.js +48 -5
- package/dist/core/fs-write-gate-policy.js +1 -1
- package/dist/core/gate-fold.js +2 -0
- package/dist/core/gate-lanes.js +2 -0
- package/dist/core/gate-outcome.d.ts +39 -2
- package/dist/core/gate-outcome.js +20 -1
- package/dist/core/git-worktree-env.d.ts +62 -3
- package/dist/core/git-worktree-env.js +91 -30
- package/dist/core/governance-codes.d.ts +9 -3
- package/dist/core/governance-codes.js +17 -3
- package/dist/core/leg-identity.d.ts +19 -1
- package/dist/core/leg-identity.js +12 -0
- package/dist/core/mailbox-store.d.ts +39 -4
- package/dist/core/mailbox-store.js +14 -2
- package/dist/core/memory-engine/consolidation-driver.d.ts +32 -17
- package/dist/core/memory-engine/consolidation-driver.js +99 -98
- package/dist/core/memory-engine/consolidation.d.ts +74 -10
- package/dist/core/memory-engine/consolidation.js +183 -11
- package/dist/core/memory-engine/control-objects.d.ts +25 -0
- package/dist/core/memory-engine/control-objects.js +151 -0
- package/dist/core/memory-engine/control-plane-adoption.d.ts +48 -0
- package/dist/core/memory-engine/control-plane-adoption.js +159 -0
- package/dist/core/memory-engine/data-plane.d.ts +8 -4
- package/dist/core/memory-engine/data-plane.js +11 -6
- package/dist/core/memory-engine/delegation-settlement.d.ts +58 -40
- package/dist/core/memory-engine/delegation-settlement.js +270 -85
- package/dist/core/memory-engine/dual-root.d.ts +12 -6
- package/dist/core/memory-engine/dual-root.js +11 -7
- package/dist/core/memory-engine/engine.d.ts +136 -58
- package/dist/core/memory-engine/engine.js +491 -394
- package/dist/core/memory-engine/entry-scan.d.ts +8 -0
- package/dist/core/memory-engine/entry-scan.js +3 -0
- package/dist/core/memory-engine/file-backend.d.ts +62 -60
- package/dist/core/memory-engine/file-backend.js +122 -198
- package/dist/core/memory-engine/index.d.ts +8 -7
- package/dist/core/memory-engine/index.js +7 -6
- package/dist/core/memory-engine/landing-admission.d.ts +5 -3
- package/dist/core/memory-engine/landing-admission.js +3 -3
- package/dist/core/memory-engine/layout.d.ts +127 -46
- package/dist/core/memory-engine/layout.js +264 -109
- package/dist/core/memory-engine/memory-backend-contract.d.ts +26 -1
- package/dist/core/memory-engine/memory-backend-contract.js +476 -0
- package/dist/core/memory-engine/memory-deployment.d.ts +42 -11
- package/dist/core/memory-engine/memory-deployment.js +54 -15
- package/dist/core/memory-engine/origin-clearance.d.ts +12 -3
- package/dist/core/memory-engine/origin-clearance.js +68 -9
- package/dist/core/memory-engine/scope-contract.d.ts +52 -11
- package/dist/core/memory-engine/scope-contract.js +68 -19
- package/dist/core/memory-engine/session-write-home.d.ts +37 -2
- package/dist/core/memory-engine/session-write-home.js +38 -11
- package/dist/core/memory-engine/sync-client.d.ts +3 -1
- package/dist/core/memory-engine/sync-client.js +7 -0
- package/dist/core/memory-engine/sync-report.d.ts +3 -2
- package/dist/core/memory-engine/sync-report.js +6 -2
- package/dist/core/memory-engine/tools.d.ts +2 -2
- package/dist/core/memory-engine/tools.js +10 -10
- package/dist/core/memory-engine/types.d.ts +155 -19
- package/dist/core/memory-engine/types.js +2 -0
- package/dist/core/memory.js +15 -6
- package/dist/core/mode-policy.js +3 -3
- package/dist/core/mods/agent-stations.d.ts +18 -0
- package/dist/core/mods/agent-stations.js +8 -6
- package/dist/core/mods/extension-call.d.ts +4 -0
- package/dist/core/mods/extension-call.js +8 -0
- package/dist/core/mods/stations.d.ts +20 -1
- package/dist/core/mods/stations.js +21 -2
- package/dist/core/mods/tool-call.js +3 -4
- package/dist/core/parent-spec-seat.d.ts +2 -2
- package/dist/core/park-selfcheck.js +2 -2
- package/dist/core/pause-registry.d.ts +2 -0
- package/dist/core/pause-registry.js +3 -0
- package/dist/core/peer-channel.d.ts +5 -0
- package/dist/core/permission-rule-consent.d.ts +26 -8
- package/dist/core/permission-rule-consent.js +76 -36
- package/dist/core/permission-rule-store.d.ts +72 -13
- package/dist/core/permission-rule-store.js +29 -8
- package/dist/core/read-only-shell.js +3 -2
- package/dist/core/redaction-marks.d.ts +8 -0
- package/dist/core/redaction-marks.js +6 -0
- package/dist/core/refusal-echo.d.ts +20 -0
- package/dist/core/refusal-echo.js +33 -0
- package/dist/core/remote-env.d.ts +12 -1
- package/dist/core/remote-env.js +3 -0
- package/dist/core/retention.d.ts +180 -10
- package/dist/core/retention.js +45 -0
- package/dist/core/retired-keys.d.ts +5 -0
- package/dist/core/retired-keys.js +3 -0
- package/dist/core/rule-offer-read.d.ts +0 -4
- package/dist/core/rule-offer-read.js +2 -18
- package/dist/core/runner/child-tree.d.ts +29 -3
- package/dist/core/runner/child-tree.js +39 -16
- package/dist/core/runner/classifier-ladder.d.ts +7 -1
- package/dist/core/runner/classifier-ladder.js +4 -2
- package/dist/core/runner/compact-session.js +10 -7
- package/dist/core/runner/compaction-call-options.d.ts +7 -7
- package/dist/core/runner/compaction-call-options.js +3 -2
- package/dist/core/runner/contracts.d.ts +39 -11
- package/dist/core/runner/delegation-owner.d.ts +10 -3
- package/dist/core/runner/delegation-owner.js +4 -1
- package/dist/core/runner/gate-exit.d.ts +6 -0
- package/dist/core/runner/gate-exit.js +13 -4
- package/dist/core/runner/inherited-ask-grants.js +1 -1
- package/dist/core/runner/memory-consolidation-driver.d.ts +10 -5
- package/dist/core/runner/memory-consolidation-driver.js +12 -9
- package/dist/core/runner/memory-consolidation-write-judge.d.ts +2 -1
- package/dist/core/runner/memory-consolidation-write-judge.js +3 -2
- package/dist/core/runner/person-path-rows.d.ts +8 -3
- package/dist/core/runner/person-path-rows.js +5 -1
- package/dist/core/runner/placement-fence.d.ts +12 -0
- package/dist/core/runner/placement-fence.js +20 -6
- package/dist/core/runner/prepare-ask-lane.js +5 -5
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +7 -2
- package/dist/core/runner/prepare-caps-and-workflow.js +7 -4
- package/dist/core/runner/prepare-config-doors.js +4 -0
- package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
- package/dist/core/runner/prepare-delegation-surface.js +2 -2
- package/dist/core/runner/prepare-execution-env.js +17 -6
- package/dist/core/runner/prepare-gate-stations.d.ts +5 -0
- package/dist/core/runner/prepare-gate-stations.js +5 -5
- package/dist/core/runner/prepare-hands-readface.d.ts +2 -1
- package/dist/core/runner/prepare-hands-readface.js +5 -4
- package/dist/core/runner/prepare-inherited-gate.d.ts +13 -9
- package/dist/core/runner/prepare-inherited-gate.js +12 -6
- package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -4
- package/dist/core/runner/prepare-memory-engine-session.js +4 -4
- package/dist/core/runner/prepare-memory.d.ts +7 -2
- package/dist/core/runner/prepare-memory.js +41 -39
- package/dist/core/runner/prepare-park-ask.js +4 -3
- package/dist/core/runner/prepare-policy-chain.js +7 -7
- package/dist/core/runner/prepare-prompt-inputs.js +1 -1
- package/dist/core/runner/prepare-task.js +26 -18
- package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -1
- package/dist/core/runner/prepare-wiring-manifest.js +3 -2
- package/dist/core/runner/prepare-workspace-restore.js +3 -6
- package/dist/core/runner/resume-admission.d.ts +2 -2
- package/dist/core/runner/resume-admission.js +2 -23
- package/dist/core/runner/role-resolution-table.d.ts +98 -0
- package/dist/core/runner/role-resolution-table.js +62 -0
- package/dist/core/runner/run-compaction-machinery.js +2 -2
- package/dist/core/runner/run-identity-wiring.js +12 -9
- package/dist/core/runner/run-leg.js +9 -5
- package/dist/core/runner/run-notification-lane.js +22 -22
- package/dist/core/runner/run-recovery-lanes.js +3 -3
- package/dist/core/runner/run-settle-and-teardown.js +3 -2
- package/dist/core/runner/run-terminal-adoption.js +1 -1
- package/dist/core/runner/run-turn-boundary.js +14 -15
- package/dist/core/runner/runtask.js +1 -1
- package/dist/core/runner/terminal-account.js +1 -1
- package/dist/core/runner/tool-occurrence.d.ts +4 -2
- package/dist/core/runner/tool-occurrence.js +2 -2
- package/dist/core/runner-deps.d.ts +7 -3
- package/dist/core/secret-env.d.ts +1 -1
- package/dist/core/secret-env.js +4 -4
- package/dist/core/session-checkout.d.ts +168 -0
- package/dist/core/session-checkout.js +579 -0
- package/dist/core/session-store.d.ts +12 -4
- package/dist/core/session-store.js +23 -3
- package/dist/core/session.d.ts +16 -2
- package/dist/core/session.js +3 -0
- package/dist/core/shell-read-silence.js +8 -0
- package/dist/core/store-contracts/checkpoint-store-contract.d.ts +0 -12
- package/dist/core/store-contracts/checkpoint-store-contract.js +6 -7
- package/dist/core/store-contracts/peer-directory-contract.js +8 -1
- package/dist/core/store-contracts/session-store-contract.js +39 -0
- package/dist/core/task-event.d.ts +30 -5
- package/dist/core/task-notification.d.ts +119 -32
- package/dist/core/task-notification.js +186 -100
- package/dist/core/task-registry-agent.d.ts +25 -2
- package/dist/core/task-registry-agent.js +56 -22
- package/dist/core/task-registry-shared.d.ts +33 -11
- package/dist/core/task-registry.d.ts +33 -9
- package/dist/core/task-registry.js +36 -18
- package/dist/core/task-spec-members.js +1 -1
- package/dist/core/task-spec.d.ts +27 -2
- package/dist/core/tool-errors.d.ts +14 -6
- package/dist/core/tool-errors.js +1 -1
- package/dist/core/tool-policy.d.ts +32 -13
- package/dist/core/tool-policy.js +27 -17
- package/dist/core/tool-result-store.d.ts +20 -0
- package/dist/core/tool-spec.d.ts +42 -19
- package/dist/core/trace.d.ts +3 -2
- package/dist/core/types.d.ts +1 -1
- package/dist/core/untrusted-egress.d.ts +15 -4
- package/dist/core/untrusted-egress.js +23 -22
- package/dist/core/workflow-journal-store.d.ts +11 -0
- package/dist/core/workflow-journal-store.js +7 -0
- package/dist/core/workflow-run-store.d.ts +9 -0
- package/dist/core/workflow-run-store.js +6 -0
- package/dist/core/workspace-snapshot.d.ts +3 -1
- package/dist/core/workspace-snapshot.js +1 -0
- package/dist/engine/compaction/compaction.d.ts +2 -1
- package/dist/engine/harness/types.d.ts +67 -1
- package/dist/engine/harness/types.js +108 -0
- package/dist/engine/session/import-validate.js +6 -1
- package/dist/engine/session/session.d.ts +30 -1
- package/dist/engine/session/session.js +48 -1
- package/dist/index.d.ts +12 -7
- package/dist/index.js +12 -7
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/orchestration/run-workflow-tool.d.ts +8 -1
- package/dist/orchestration/run-workflow-tool.js +8 -0
- package/dist/orchestration/workflow-types.d.ts +2 -1
- package/dist/orchestration/workflow.d.ts +6 -0
- package/dist/orchestration/workflow.js +5 -2
- package/dist/stores/file/checkpoint-store.d.ts +6 -0
- package/dist/stores/file/checkpoint-store.js +4 -1
- package/dist/stores/file/file-history-store.d.ts +13 -0
- package/dist/stores/file/file-history-store.js +75 -13
- package/dist/stores/file/index.d.ts +11 -1
- package/dist/stores/file/index.js +7 -11
- package/dist/stores/file/permission-rule-store.d.ts +23 -0
- package/dist/stores/file/permission-rule-store.js +75 -7
- package/dist/stores/file/session-store.js +2 -1
- package/dist/stores/file/tool-result-store.d.ts +14 -0
- package/dist/stores/file/tool-result-store.js +39 -2
- package/dist/stores/file/workflow-journal-store.d.ts +4 -0
- package/dist/stores/file/workflow-journal-store.js +17 -0
- package/dist/stores/file/workflow-run-store.d.ts +3 -0
- package/dist/stores/file/workflow-run-store.js +15 -0
- package/dist/tools/fs/bash-program-position.js +3 -3
- package/dist/tools/fs/program-read-model.d.ts +34 -10
- package/dist/tools/fs/program-read-model.js +37 -7
- package/dist/tools/fs/program-read-model.rows.js +13 -2
- package/dist/tools/fs/read-deny.d.ts +28 -3
- package/dist/tools/fs/read-deny.js +18 -2
- package/dist/tools/fs/removal-targets.js +3 -3
- package/dist/tools/fs/safety.d.ts +2 -0
- package/dist/tools/fs/safety.js +1 -1
- package/dist/tools/fs/shell-read-argv.d.ts +8 -1
- package/dist/tools/fs/shell-read-argv.js +34 -29
- package/dist/tools/fs/shell-read-bindings.d.ts +2 -0
- package/dist/tools/fs/shell-read-bindings.js +5 -1
- package/dist/tools/fs/shell-read-brace.d.ts +18 -0
- package/dist/tools/fs/shell-read-brace.js +79 -0
- package/dist/tools/fs/shell-read-check.d.ts +8 -2
- package/dist/tools/fs/shell-read-check.js +16 -14
- package/dist/tools/fs/shell-read-establish.js +23 -16
- package/dist/tools/fs/shell-read-judge.d.ts +11 -0
- package/dist/tools/fs/shell-read-judge.js +3 -3
- package/dist/tools/fs/shell-read-plan.d.ts +10 -0
- package/dist/tools/fs/shell-read-plan.js +189 -93
- package/dist/tools/fs/shell-read-start.d.ts +19 -9
- package/dist/tools/fs/shell-read-start.js +20 -12
- package/dist/tools/fs/shell-read-word.d.ts +10 -0
- package/dist/tools/fs/shell-read-word.js +9 -5
- package/dist/tools/fs/shell-read-workdir.d.ts +26 -7
- package/dist/tools/fs/shell-read-workdir.js +73 -12
- package/dist/tools/fs/shell-read-write-targets.js +13 -8
- package/dist/tools/worktree.d.ts +3 -2
- package/dist/tools/worktree.js +7 -35
- package/package.json +3 -2
- package/test/export-surface.snapshot.json +135 -11
- package/wire-changes/core-stores-sql@7.63.0.json +30 -0
- package/wire-changes/core-stores-sql@7.64.0.json +30 -0
- package/wire-changes/core@7.63.0.json +3523 -0
- package/wire-changes/core@7.64.0.json +2653 -0
- package/wire-changes/mods-kernel@7.63.0.json +30 -0
- package/wire-changes/mods-kernel@7.64.0.json +30 -0
- package/wire-changes/primitives@7.63.0.json +445 -0
- package/wire-changes/primitives@7.64.0.json +30 -0
- package/dist/core/credential-vocabulary.d.ts +0 -176
- package/dist/core/credential-vocabulary.js +0 -190
- package/dist/core/redaction-passes.d.ts +0 -82
- package/dist/core/redaction-passes.js +0 -377
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type MemoryBackend, type MemoryControlObjectKind, type MemoryGovernanceDocName, type MemoryGovernanceStore } from "./types.js";
|
|
2
2
|
export interface MemoryBackendContractHooks {
|
|
3
3
|
make: () => Promise<MemoryBackend> | MemoryBackend;
|
|
4
4
|
/** A second backend instance over the SAME storage as the given one (cross-instance CAS cases). */
|
|
@@ -28,6 +28,31 @@ export interface MemoryBackendContractHooks {
|
|
|
28
28
|
}
|
|
29
29
|
/** Run the full conformance suite. Throws (assert) on the first violated contract clause. */
|
|
30
30
|
export declare function memoryBackendContract(hooks: MemoryBackendContractHooks): Promise<void>;
|
|
31
|
+
export interface MemoryGovernanceStoreContractHooks {
|
|
32
|
+
/** A FRESH, EMPTY store per case. */
|
|
33
|
+
make: () => Promise<MemoryGovernanceStore> | MemoryGovernanceStore;
|
|
34
|
+
/** Leave `store`'s record of `record` malformed in its own storage (bytes that are not the record's shape — for a
|
|
35
|
+
* governance document, bytes that do not parse): the fail-closed cases read it back and must be refused, never read
|
|
36
|
+
* as an empty record. For a control object, leave `{ object, name }` standing but unreadable (the File store: a
|
|
37
|
+
* directory or a link to nothing in its place), and `{ listing }` a kind whose names cannot be enumerated (the File
|
|
38
|
+
* store: a file where the kind's directory is). */
|
|
39
|
+
corrupt: (store: MemoryGovernanceStore, record: "gate" | "intents" | "run" | MemoryGovernanceDocName | {
|
|
40
|
+
readonly object: MemoryControlObjectKind;
|
|
41
|
+
readonly name: string;
|
|
42
|
+
} | {
|
|
43
|
+
readonly listing: MemoryControlObjectKind;
|
|
44
|
+
}) => Promise<void> | void;
|
|
45
|
+
/** Wrap each case (vitest `it`, …). Default: run sequentially. */
|
|
46
|
+
runAssertion?: (name: string, fn: () => Promise<void>) => void | Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The consolidation store conformance suite (`MemoryBackend.governance`): what an engine relies on when it keeps its
|
|
50
|
+
* consolidation state in a store — a missing record reads empty and a malformed one is refused, a transaction's reads
|
|
51
|
+
* and writes are not interleaved by another's (the plan owner fence and the seat CAS), the run claim's newer writer
|
|
52
|
+
* wins and the older one stops, and a mint archive can be written, read and erased. Runner-agnostic (node:assert);
|
|
53
|
+
* throws on the first violated clause.
|
|
54
|
+
*/
|
|
55
|
+
export declare function memoryGovernanceStoreContract(hooks: MemoryGovernanceStoreContractHooks): Promise<void>;
|
|
31
56
|
/** Cross-backend value equivalence: same fixture ⇒ IDENTICAL (id, slug, score) search projections on
|
|
32
57
|
* two backends (File vs Pg lexical floor must not drift — assertMemoryValueEquivalence precedent).
|
|
33
58
|
* mtimeMs/sizeBytes are backend-native (fs stat vs column) and deliberately not compared. */
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
2
5
|
import { computeEntryRev } from "./frontmatter.js";
|
|
6
|
+
import { MEMORY_CONTROL_OBJECT_KINDS, MEMORY_GOVERNANCE_DOC_NAMES } from "./types.js";
|
|
7
|
+
import { ControlPlaneCorruptError, STRICT_CONTROL_PLANE_LEDGERS } from "./layout.js";
|
|
8
|
+
import { fileGovernanceStore } from "./consolidation.js";
|
|
9
|
+
import { adoptReplicaControlPlane, readControlPlaneAdoptionReceipt, replicaControlPlaneStrays } from "./control-plane-adoption.js";
|
|
3
10
|
function entry(id, scope, slug, body, fm = {}) {
|
|
4
11
|
const e = { id, scope, slug, frontmatter: { ...fm }, body, rev: "" };
|
|
5
12
|
e.rev = computeEntryRev(e);
|
|
@@ -36,6 +43,15 @@ export async function memoryBackendContract(hooks) {
|
|
|
36
43
|
assert.strictEqual((await b.listHeaders([])).length, 0);
|
|
37
44
|
assert.strictEqual((await b.listHeaders(["nope"])).length, 0);
|
|
38
45
|
});
|
|
46
|
+
defer("search answers only the scopes asked — a query naming s1 never returns an s2 entry", async () => {
|
|
47
|
+
const b = await hooks.make();
|
|
48
|
+
await b.applyPatches([
|
|
49
|
+
{ op: "add", id: "id-sfence1-01", entry: entry("id-sfence1-01", "s1", "lantern-one", "lantern harbor signal") },
|
|
50
|
+
{ op: "add", id: "id-sfence2-01", entry: entry("id-sfence2-01", "s2", "lantern-two", "lantern harbor signal") },
|
|
51
|
+
]);
|
|
52
|
+
assert.deepStrictEqual((await b.search("lantern harbor", ["s1"])).map((h) => h.id), ["id-sfence1-01"], "only the s1 entry answers a query naming s1");
|
|
53
|
+
assert.deepStrictEqual((await b.search("lantern harbor", ["s2"])).map((h) => h.id), ["id-sfence2-01"], "control: the s2 entry is findable, and answers only a query naming s2");
|
|
54
|
+
});
|
|
39
55
|
defer("getByIds silently skips unknown ids", async () => {
|
|
40
56
|
const b = await hooks.make();
|
|
41
57
|
await b.applyPatches([{ op: "add", id: "id-known-01", entry: entry("id-known-01", "s1", "known", "kb") }]);
|
|
@@ -71,6 +87,25 @@ export async function memoryBackendContract(hooks) {
|
|
|
71
87
|
const got = await b.getByIds(["id-cas-0001"]);
|
|
72
88
|
assert.strictEqual(got[0].body.replace(/\s+$/, ""), "v2", "the CAS winner's content must survive");
|
|
73
89
|
});
|
|
90
|
+
defer("update with a STALE baseRev conflicts even when its new bytes equal the committed bytes", async () => {
|
|
91
|
+
const b = await hooks.make();
|
|
92
|
+
const v1 = entry("id-casbyte-01", "s1", "note", "v1");
|
|
93
|
+
await b.applyPatches([{ op: "add", id: v1.id, entry: v1 }]);
|
|
94
|
+
const v2 = entry("id-casbyte-01", "s1", "note", "v2");
|
|
95
|
+
await b.applyPatches([{ op: "update", id: "id-casbyte-01", entry: v2, baseRev: v1.rev }]);
|
|
96
|
+
const same = entry("id-casbyte-01", "s1", "note", "v2");
|
|
97
|
+
assert.strictEqual(same.rev, v2.rev, "the fixture: the stale writer's rev equals the committed rev");
|
|
98
|
+
const rep = await b.applyPatches([{ op: "update", id: "id-casbyte-01", entry: same, baseRev: v1.rev }]);
|
|
99
|
+
assert.strictEqual(rep.applied.length, 0, "a stale baseRev applies nothing, whatever its bytes are");
|
|
100
|
+
assert.strictEqual(rep.conflicts.length, 1);
|
|
101
|
+
assert.strictEqual(rep.conflicts[0].id, "id-casbyte-01");
|
|
102
|
+
assert.strictEqual(rep.conflicts[0].baseRev, v1.rev);
|
|
103
|
+
assert.strictEqual(rep.conflicts[0].currentRev, v2.rev, "the conflict names the committed rev");
|
|
104
|
+
const got = await b.getByIds(["id-casbyte-01"]);
|
|
105
|
+
assert.strictEqual(got.length, 1);
|
|
106
|
+
assert.strictEqual(got[0].rev, v2.rev, "the committed state does not move");
|
|
107
|
+
assert.strictEqual(got[0].body.replace(/\s+$/, ""), "v2");
|
|
108
|
+
});
|
|
74
109
|
defer("delete removes the entry; unknown-id update/delete are conflicts", async () => {
|
|
75
110
|
const b = await hooks.make();
|
|
76
111
|
const e = entry("id-del-0001", "s1", "gone", "bye");
|
|
@@ -85,6 +120,44 @@ export async function memoryBackendContract(hooks) {
|
|
|
85
120
|
assert.strictEqual(rep2.applied.length, 0);
|
|
86
121
|
assert.strictEqual(rep2.conflicts.length, 2);
|
|
87
122
|
});
|
|
123
|
+
defer("a delete leaves the entry in no read face — listHeaders, getByIds and search are all empty of it", async () => {
|
|
124
|
+
const b = await hooks.make();
|
|
125
|
+
const gone = entry("id-faces-gone1", "s1", "faces-gone", "quartz zebra marker");
|
|
126
|
+
const kept = entry("id-faces-kept1", "s1", "faces-kept", "quartz zebra marker too");
|
|
127
|
+
await b.applyPatches([
|
|
128
|
+
{ op: "add", id: gone.id, entry: gone },
|
|
129
|
+
{ op: "add", id: kept.id, entry: kept },
|
|
130
|
+
]);
|
|
131
|
+
const ids = async () => ({
|
|
132
|
+
headers: (await b.listHeaders(["s1"])).map((h) => h.id).sort(),
|
|
133
|
+
got: (await b.getByIds([gone.id, kept.id])).map((x) => x.id).sort(),
|
|
134
|
+
hits: (await b.search("quartz zebra", ["s1"])).map((h) => h.id).sort(),
|
|
135
|
+
});
|
|
136
|
+
const both = [gone.id, kept.id].sort();
|
|
137
|
+
assert.deepStrictEqual(await ids(), { headers: both, got: both, hits: both }, "control: before the delete every face serves both entries");
|
|
138
|
+
const rep = await b.applyPatches([{ op: "delete", id: gone.id, baseRev: gone.rev }]);
|
|
139
|
+
assert.deepStrictEqual(rep.conflicts, []);
|
|
140
|
+
assert.deepStrictEqual(await ids(), { headers: [kept.id], got: [kept.id], hits: [kept.id] }, "after the delete no face serves the deleted entry");
|
|
141
|
+
});
|
|
142
|
+
defer("an evidenced erase leaves the entry in no read face — listHeaders, getByIds and search (optional seat)", async () => {
|
|
143
|
+
const b = await hooks.make();
|
|
144
|
+
const seat = b.eraseWithEvidence;
|
|
145
|
+
if (typeof seat !== "function")
|
|
146
|
+
return;
|
|
147
|
+
const erase = seat;
|
|
148
|
+
const gone = entry("id-efaces-gone1", "s1", "efaces-gone", "quartz zebra marker");
|
|
149
|
+
const kept = entry("id-efaces-kept1", "s1", "efaces-kept", "quartz zebra marker too");
|
|
150
|
+
await b.applyPatches([
|
|
151
|
+
{ op: "add", id: gone.id, entry: gone },
|
|
152
|
+
{ op: "add", id: kept.id, entry: kept },
|
|
153
|
+
]);
|
|
154
|
+
assert.deepStrictEqual((await b.search("quartz zebra", ["s1"])).map((h) => h.id).sort(), [gone.id, kept.id].sort(), "control: the search face serves both entries before the erase");
|
|
155
|
+
const att = await erase.call(b, { requestId: "req-faces-1", select: { ids: [gone.id] } });
|
|
156
|
+
assert.deepStrictEqual(att.erased.map((r) => r.id), [gone.id]);
|
|
157
|
+
assert.deepStrictEqual((await b.listHeaders(["s1"])).map((h) => h.id), [kept.id], "listHeaders no longer lists the erased entry");
|
|
158
|
+
assert.deepStrictEqual((await b.getByIds([gone.id, kept.id])).map((x) => x.id), [kept.id], "getByIds no longer returns the erased entry");
|
|
159
|
+
assert.deepStrictEqual((await b.search("quartz zebra", ["s1"])).map((h) => h.id), [kept.id], "search no longer returns the erased entry");
|
|
160
|
+
});
|
|
88
161
|
defer("at most ONE non-delete op per id per batch — the later one conflicts", async () => {
|
|
89
162
|
const b = await hooks.make();
|
|
90
163
|
const a1 = entry("id-dup-0001", "s1", "one", "first");
|
|
@@ -865,6 +938,409 @@ export async function memoryBackendContract(hooks) {
|
|
|
865
938
|
for (const [name, fn] of cases)
|
|
866
939
|
await run(name, fn);
|
|
867
940
|
}
|
|
941
|
+
function governancePlan(planId, over = {}) {
|
|
942
|
+
return { v: 1, planId, scope: "s1", requestId: "req-1", createdAt: 1, epoch: 0, visibleMarked: false, products: [], productStates: {}, directed: [], intents: [], state: "open", audit: [], ...over };
|
|
943
|
+
}
|
|
944
|
+
function governanceRun(scope, runId, over = {}) {
|
|
945
|
+
return {
|
|
946
|
+
runId,
|
|
947
|
+
scope,
|
|
948
|
+
attempt: 1,
|
|
949
|
+
requestId: `run-${runId}`,
|
|
950
|
+
contractVersion: "v1",
|
|
951
|
+
model: "m",
|
|
952
|
+
startedAt: 1,
|
|
953
|
+
state: "pending",
|
|
954
|
+
cyclesDone: 0,
|
|
955
|
+
entriesSuperseded: 0,
|
|
956
|
+
planIds: [],
|
|
957
|
+
usage: { calls: 0, promptTokens: 0, completionTokens: 0, retries: 0, truncations: 0 },
|
|
958
|
+
repairs: { hallucinatedMembers: 0, duplicateMembers: 0, nonIntegerMembers: 0, emptyGroups: 0, oversizeGroups: 0 },
|
|
959
|
+
writeFailures: [],
|
|
960
|
+
...over,
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
async function rejectsCoded(p, code, what) {
|
|
964
|
+
let err;
|
|
965
|
+
try {
|
|
966
|
+
await p;
|
|
967
|
+
}
|
|
968
|
+
catch (e) {
|
|
969
|
+
err = e;
|
|
970
|
+
}
|
|
971
|
+
assert.ok(err !== undefined, `${what}: expected a refusal, got an answer`);
|
|
972
|
+
const field = (key) => (typeof err === "object" && err !== null ? Reflect.get(err, key) : undefined);
|
|
973
|
+
const got = field("code") ?? field("name");
|
|
974
|
+
if (typeof code === "string")
|
|
975
|
+
assert.strictEqual(got, code, `${what}: refused with ${String(got)}`);
|
|
976
|
+
else
|
|
977
|
+
assert.match(String(got), code, `${what}: refused with ${String(got)}`);
|
|
978
|
+
}
|
|
979
|
+
export async function memoryGovernanceStoreContract(hooks) {
|
|
980
|
+
const cases = [];
|
|
981
|
+
const defer = (name, fn) => cases.push([name, fn]);
|
|
982
|
+
defer("a record never written reads absent / empty — never corrupt", async () => {
|
|
983
|
+
const s = await hooks.make();
|
|
984
|
+
assert.deepStrictEqual(await s.readGate(), {});
|
|
985
|
+
assert.deepStrictEqual(await s.readPlan("plan-absent-0001"), { state: "absent" });
|
|
986
|
+
assert.deepStrictEqual(await s.listPlanIds(), []);
|
|
987
|
+
assert.deepStrictEqual(await s.readIntents(), {});
|
|
988
|
+
assert.strictEqual(await s.readRun("s1"), undefined);
|
|
989
|
+
assert.strictEqual(await s.readMint("0190aaaa-run-a1.json"), undefined);
|
|
990
|
+
assert.strictEqual(await s.eraseMint("0190aaaa-run-a1.json"), false);
|
|
991
|
+
});
|
|
992
|
+
for (const record of ["gate", "intents", "run"]) {
|
|
993
|
+
defer(`a malformed ${record} record is refused (fail-closed), never read as empty`, async () => {
|
|
994
|
+
const s = await hooks.make();
|
|
995
|
+
await hooks.corrupt(s, record);
|
|
996
|
+
const read = record === "gate" ? s.readGate() : record === "intents" ? s.readIntents() : s.readRun("s1");
|
|
997
|
+
await rejectsCoded(read, /ControlPlaneCorruptError|corrupt/i, `${record} read over a malformed record`);
|
|
998
|
+
if (record === "gate")
|
|
999
|
+
await rejectsCoded(s.transact([], () => ({ writeGate: true, result: undefined })), /ControlPlaneCorruptError|corrupt/i, "a transaction over a malformed gate");
|
|
1000
|
+
});
|
|
1001
|
+
}
|
|
1002
|
+
defer("a transaction's row and plan writes land after it returns; a throw inside it writes nothing", async () => {
|
|
1003
|
+
const s = await hooks.make();
|
|
1004
|
+
await assert.rejects(s.transact(["plan-txn-00001"], (tx) => {
|
|
1005
|
+
tx.scopes["s1"] = { sessions: { count: 1, ring: ["a"] }, epoch: 0, openPlanId: "plan-txn-00001" };
|
|
1006
|
+
tx.writePlan(governancePlan("plan-txn-00001"));
|
|
1007
|
+
throw new Error("abort");
|
|
1008
|
+
}), /abort/);
|
|
1009
|
+
assert.deepStrictEqual(await s.readGate(), {});
|
|
1010
|
+
assert.deepStrictEqual(await s.readPlan("plan-txn-00001"), { state: "absent" });
|
|
1011
|
+
const answer = await s.transact(["plan-txn-00001"], (tx) => {
|
|
1012
|
+
assert.deepStrictEqual(tx.plan("plan-txn-00001"), { state: "absent" });
|
|
1013
|
+
tx.scopes["s1"] = { sessions: { count: 1, ring: ["a"] }, epoch: 0, openPlanId: "plan-txn-00001" };
|
|
1014
|
+
tx.writePlan(governancePlan("plan-txn-00001"));
|
|
1015
|
+
return { writeGate: true, result: "done" };
|
|
1016
|
+
});
|
|
1017
|
+
assert.strictEqual(answer, "done");
|
|
1018
|
+
assert.strictEqual((await s.readGate())["s1"]?.openPlanId, "plan-txn-00001");
|
|
1019
|
+
const read = await s.readPlan("plan-txn-00001");
|
|
1020
|
+
assert.strictEqual(read.state, "ok");
|
|
1021
|
+
assert.deepStrictEqual(await s.listPlanIds(), ["plan-txn-00001"]);
|
|
1022
|
+
await s.transact(["plan-txn-00001"], (tx) => {
|
|
1023
|
+
tx.scopes["s1"].epoch = 99;
|
|
1024
|
+
tx.writePlan(governancePlan("plan-txn-00001", { state: "applying" }));
|
|
1025
|
+
return { writeGate: false, result: undefined };
|
|
1026
|
+
});
|
|
1027
|
+
assert.strictEqual((await s.readGate())["s1"]?.epoch, 0);
|
|
1028
|
+
const after = await s.readPlan("plan-txn-00001");
|
|
1029
|
+
assert.ok(after.state === "ok" && after.plan.state === "applying");
|
|
1030
|
+
});
|
|
1031
|
+
defer("takeover cannot land between a transaction's owner read and its plan write (the owner fence)", async () => {
|
|
1032
|
+
const s = await hooks.make();
|
|
1033
|
+
await s.transact([], (tx) => {
|
|
1034
|
+
tx.writePlan(governancePlan("plan-fence-0001", { applier: "first" }));
|
|
1035
|
+
return { writeGate: false, result: undefined };
|
|
1036
|
+
});
|
|
1037
|
+
const holder = (me) => s.transact(["plan-fence-0001"], (tx) => {
|
|
1038
|
+
const cur = tx.plan("plan-fence-0001");
|
|
1039
|
+
if (cur.state !== "ok" || cur.plan.applier !== "first")
|
|
1040
|
+
return { writeGate: false, result: false };
|
|
1041
|
+
tx.writePlan({ ...cur.plan, applier: me });
|
|
1042
|
+
return { writeGate: false, result: true };
|
|
1043
|
+
});
|
|
1044
|
+
const won = await Promise.all([holder("A"), holder("B"), holder("C")]);
|
|
1045
|
+
assert.strictEqual(won.filter(Boolean).length, 1, `exactly one holder may take the plan over the applier it read (got ${JSON.stringify(won)})`);
|
|
1046
|
+
const final = await s.readPlan("plan-fence-0001");
|
|
1047
|
+
assert.ok(final.state === "ok" && final.plan.applier === ["A", "B", "C"][won.indexOf(true)]);
|
|
1048
|
+
});
|
|
1049
|
+
defer("the seat CAS: of racing claims on one scope's row exactly one wins", async () => {
|
|
1050
|
+
const s = await hooks.make();
|
|
1051
|
+
const claim = (planId) => s.transact([], (tx) => {
|
|
1052
|
+
const row = tx.scopes["s1"] ?? { sessions: { count: 0, ring: [] }, epoch: 0 };
|
|
1053
|
+
if (row.openPlanId !== undefined)
|
|
1054
|
+
return { writeGate: false, result: false };
|
|
1055
|
+
row.openPlanId = planId;
|
|
1056
|
+
tx.scopes["s1"] = row;
|
|
1057
|
+
return { writeGate: true, result: true };
|
|
1058
|
+
});
|
|
1059
|
+
const won = await Promise.all(["plan-cas-00001", "plan-cas-00002", "plan-cas-00003", "plan-cas-00004"].map(claim));
|
|
1060
|
+
assert.strictEqual(won.filter(Boolean).length, 1);
|
|
1061
|
+
});
|
|
1062
|
+
defer("the run claim: a pending run is resumed with its attempt bumped; the superseded writer is refused and writes nothing", async () => {
|
|
1063
|
+
const s = await hooks.make();
|
|
1064
|
+
const opened = await s.claimRun("s1", () => governanceRun("s1", "0190aaaa-run1"));
|
|
1065
|
+
assert.strictEqual(opened.resumed, false);
|
|
1066
|
+
assert.strictEqual(opened.row.attempt, 1);
|
|
1067
|
+
const resumed = await s.claimRun("s1", () => governanceRun("s1", "0190aaaa-other"));
|
|
1068
|
+
assert.strictEqual(resumed.resumed, true);
|
|
1069
|
+
assert.strictEqual(resumed.row.runId, "0190aaaa-run1");
|
|
1070
|
+
assert.strictEqual(resumed.row.attempt, 2);
|
|
1071
|
+
await rejectsCoded(s.writeRun({ ...opened.row, cyclesDone: 7 }), "memory.consolidation_driver_superseded", "the attempt-1 writer after the attempt-2 claim");
|
|
1072
|
+
assert.strictEqual((await s.readRun("s1"))?.cyclesDone, 0);
|
|
1073
|
+
await s.writeRun({ ...resumed.row, cyclesDone: 3, state: "settled" });
|
|
1074
|
+
assert.strictEqual((await s.readRun("s1"))?.cyclesDone, 3);
|
|
1075
|
+
const fresh = await s.claimRun("s1", () => governanceRun("s1", "0190aaaa-run2"));
|
|
1076
|
+
assert.strictEqual(fresh.resumed, false, "a settled run is not resumed: the claim opens a new one");
|
|
1077
|
+
assert.strictEqual(fresh.row.runId, "0190aaaa-run2");
|
|
1078
|
+
});
|
|
1079
|
+
defer("intent credentials are idempotent on requestId: the standing row wins", async () => {
|
|
1080
|
+
const s = await hooks.make();
|
|
1081
|
+
const row = { requestId: "intent-1", state: "settled", planId: "plan-int-00001", at: 1, patches: [] };
|
|
1082
|
+
assert.deepStrictEqual(await s.recordIntents([row]), ["intent-1"]);
|
|
1083
|
+
assert.deepStrictEqual(await s.recordIntents([{ ...row, state: "abandoned", planId: "plan-int-00002" }]), []);
|
|
1084
|
+
assert.strictEqual((await s.readIntents())["intent-1"]?.planId, "plan-int-00001");
|
|
1085
|
+
});
|
|
1086
|
+
defer("a discarded plan moves to custody: its bytes kept, out of the workbook", async () => {
|
|
1087
|
+
const s = await hooks.make();
|
|
1088
|
+
await s.transact([], (tx) => {
|
|
1089
|
+
tx.writePlan(governancePlan("plan-qtn-00001"));
|
|
1090
|
+
return { writeGate: false, result: undefined };
|
|
1091
|
+
});
|
|
1092
|
+
const custody = await s.quarantinePlan("plan-qtn-00001");
|
|
1093
|
+
assert.ok(typeof custody === "string" && custody.length > 0);
|
|
1094
|
+
assert.deepStrictEqual(await s.listPlanIds(), []);
|
|
1095
|
+
assert.deepStrictEqual(await s.readPlan("plan-qtn-00001"), { state: "absent" });
|
|
1096
|
+
assert.strictEqual(await s.quarantinePlan("plan-qtn-00001"), undefined);
|
|
1097
|
+
});
|
|
1098
|
+
defer("a mint archive is written, read back verbatim and erased (gone, not moved)", async () => {
|
|
1099
|
+
const s = await hooks.make();
|
|
1100
|
+
const plan = JSON.parse('{"kind":"llm-consolidation-plan","contractVersion":"v1","model":"m","maxInputsPerProduct":4,"products":[],"transcript":[{"role":"user","content":"the shown library"}]}');
|
|
1101
|
+
const name = await s.archiveMint("0190aaaa-run1", 2, plan);
|
|
1102
|
+
assert.deepStrictEqual(await s.readMint(name), plan);
|
|
1103
|
+
assert.strictEqual(await s.eraseMint(name), true);
|
|
1104
|
+
assert.strictEqual(await s.readMint(name), undefined);
|
|
1105
|
+
assert.strictEqual(await s.eraseMint(name), false);
|
|
1106
|
+
});
|
|
1107
|
+
const judgeDoc = (raw) => {
|
|
1108
|
+
if (raw === undefined)
|
|
1109
|
+
return { v: 1, owner: "", n: 0 };
|
|
1110
|
+
if (typeof raw !== "object" || raw === null || Reflect.get(raw, "v") !== 1)
|
|
1111
|
+
throw new ControlPlaneCorruptError("governance document has the wrong shape");
|
|
1112
|
+
return raw;
|
|
1113
|
+
};
|
|
1114
|
+
defer("every governance document never written reads undefined, and its first update is handed undefined", async () => {
|
|
1115
|
+
const s = await hooks.make();
|
|
1116
|
+
for (const name of MEMORY_GOVERNANCE_DOC_NAMES) {
|
|
1117
|
+
assert.strictEqual(await s.readDoc(name), undefined, `${name} before any write`);
|
|
1118
|
+
let handed = "not called";
|
|
1119
|
+
await s.updateDoc(name, (raw) => {
|
|
1120
|
+
handed = raw;
|
|
1121
|
+
return judgeDoc(raw);
|
|
1122
|
+
}, () => ({ result: undefined }));
|
|
1123
|
+
assert.strictEqual(handed, undefined, `${name}: coerce sees the never-written document as undefined`);
|
|
1124
|
+
assert.strictEqual(await s.readDoc(name), undefined, `${name}: an update that answers no \`next\` writes nothing`);
|
|
1125
|
+
}
|
|
1126
|
+
});
|
|
1127
|
+
defer("each governance document is its own: a write lands under its name only, and read back is what was written", async () => {
|
|
1128
|
+
const s = await hooks.make();
|
|
1129
|
+
for (const name of MEMORY_GOVERNANCE_DOC_NAMES) {
|
|
1130
|
+
const result = await s.updateDoc(name, judgeDoc, (cur) => ({ next: { ...cur, owner: name, n: cur.n + 1 }, result: `wrote ${name}` }));
|
|
1131
|
+
assert.strictEqual(result, `wrote ${name}`, `${name}: updateDoc answers fn's result`);
|
|
1132
|
+
}
|
|
1133
|
+
for (const name of MEMORY_GOVERNANCE_DOC_NAMES) {
|
|
1134
|
+
assert.deepStrictEqual(await s.readDoc(name), { v: 1, owner: name, n: 1 }, `${name} read back (no alias, no lost write)`);
|
|
1135
|
+
}
|
|
1136
|
+
});
|
|
1137
|
+
defer("a governance document's answers are copies: changing what was read, or the object handed back as next, changes nothing stored", async () => {
|
|
1138
|
+
const s = await hooks.make();
|
|
1139
|
+
const next = { v: 1, owner: "copy", n: 1 };
|
|
1140
|
+
await s.updateDoc("session-accounts", judgeDoc, () => ({ next, result: undefined }));
|
|
1141
|
+
next.n = 99;
|
|
1142
|
+
const read = (await s.readDoc("session-accounts"));
|
|
1143
|
+
assert.deepStrictEqual(read, { v: 1, owner: "copy", n: 1 }, "the stored document is not the caller's object");
|
|
1144
|
+
read.n = 42;
|
|
1145
|
+
let handed;
|
|
1146
|
+
await s.updateDoc("session-accounts", judgeDoc, (cur) => {
|
|
1147
|
+
handed = cur;
|
|
1148
|
+
return { result: undefined };
|
|
1149
|
+
});
|
|
1150
|
+
assert.strictEqual(handed?.n, 1, "a read answer is not the stored document");
|
|
1151
|
+
assert.deepStrictEqual(await s.readDoc("session-accounts"), { v: 1, owner: "copy", n: 1 });
|
|
1152
|
+
});
|
|
1153
|
+
defer("a throw in coerce or in fn writes nothing and propagates unchanged", async () => {
|
|
1154
|
+
const s = await hooks.make();
|
|
1155
|
+
await s.updateDoc("lineage", judgeDoc, (cur) => ({ next: { ...cur, owner: "kept", n: 1 }, result: undefined }));
|
|
1156
|
+
await assert.rejects(s.updateDoc("lineage", judgeDoc, () => {
|
|
1157
|
+
throw new Error("fn-abort");
|
|
1158
|
+
}), /fn-abort/);
|
|
1159
|
+
await assert.rejects(s.updateDoc("lineage", () => {
|
|
1160
|
+
throw new Error("coerce-abort");
|
|
1161
|
+
}, () => ({ next: { v: 1, owner: "never", n: 9 }, result: undefined })), /coerce-abort/);
|
|
1162
|
+
assert.deepStrictEqual(await s.readDoc("lineage"), { v: 1, owner: "kept", n: 1 });
|
|
1163
|
+
});
|
|
1164
|
+
for (const name of MEMORY_GOVERNANCE_DOC_NAMES) {
|
|
1165
|
+
defer(`a malformed ${name} document is refused (fail-closed) by both faces, never read as missing`, async () => {
|
|
1166
|
+
const s = await hooks.make();
|
|
1167
|
+
await hooks.corrupt(s, name);
|
|
1168
|
+
await rejectsCoded(s.readDoc(name), /ControlPlaneCorruptError|corrupt/i, `${name} read over a malformed document`);
|
|
1169
|
+
let called = false;
|
|
1170
|
+
await rejectsCoded(s.updateDoc(name, (raw) => {
|
|
1171
|
+
called = true;
|
|
1172
|
+
return judgeDoc(raw);
|
|
1173
|
+
}, (cur) => ({ next: cur, result: undefined })), /ControlPlaneCorruptError|corrupt/i, `${name} update over a malformed document`);
|
|
1174
|
+
assert.strictEqual(called, false, `${name}: an unparseable document never reaches coerce as if it were missing`);
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
defer("racing updates of one governance document serialize: none is lost, on every document at once", async () => {
|
|
1178
|
+
const s = await hooks.make();
|
|
1179
|
+
const racers = 8;
|
|
1180
|
+
await Promise.all(MEMORY_GOVERNANCE_DOC_NAMES.flatMap((name) => Array.from({ length: racers }, () => s.updateDoc(name, judgeDoc, (cur) => ({ next: { ...cur, owner: name, n: cur.n + 1 }, result: undefined })))));
|
|
1181
|
+
for (const name of MEMORY_GOVERNANCE_DOC_NAMES)
|
|
1182
|
+
assert.deepStrictEqual(await s.readDoc(name), { v: 1, owner: name, n: racers }, `${name}: ${racers} racing updates all landed`);
|
|
1183
|
+
});
|
|
1184
|
+
defer("a name outside the governance documents is refused, never given storage of its own", async () => {
|
|
1185
|
+
const s = await hooks.make();
|
|
1186
|
+
await assert.rejects(s.readDoc("lineage.json"));
|
|
1187
|
+
await assert.rejects(s.updateDoc("__proto__", judgeDoc, (cur) => ({ next: cur, result: undefined })));
|
|
1188
|
+
});
|
|
1189
|
+
defer("the ledgers a host may rebuild are governance documents the store keeps", async () => {
|
|
1190
|
+
const s = await hooks.make();
|
|
1191
|
+
for (const ledger of STRICT_CONTROL_PLANE_LEDGERS) {
|
|
1192
|
+
assert.ok(MEMORY_GOVERNANCE_DOC_NAMES.includes(ledger), `${ledger} is a governance document`);
|
|
1193
|
+
assert.strictEqual(await s.readDoc(ledger), undefined, `${ledger} before any write`);
|
|
1194
|
+
}
|
|
1195
|
+
});
|
|
1196
|
+
const enc = (text) => new TextEncoder().encode(text);
|
|
1197
|
+
const same = (a, b) => a !== undefined && b !== undefined && Buffer.from(a).equals(Buffer.from(b));
|
|
1198
|
+
defer("every control-object kind never written lists empty, reads absent and deletes nothing", async () => {
|
|
1199
|
+
const s = await hooks.make();
|
|
1200
|
+
for (const kind of MEMORY_CONTROL_OBJECT_KINDS) {
|
|
1201
|
+
assert.deepStrictEqual(await s.listObjects(kind), [], `${kind} before any write`);
|
|
1202
|
+
assert.strictEqual(await s.getObject(kind, "obj-1.json"), undefined, `${kind}/obj-1.json before any write`);
|
|
1203
|
+
assert.strictEqual(await s.deleteObject(kind, "obj-1.json"), false, `${kind}: nothing to delete`);
|
|
1204
|
+
}
|
|
1205
|
+
});
|
|
1206
|
+
defer("an object is written once: a second put of the name answers existed and changes nothing", async () => {
|
|
1207
|
+
const s = await hooks.make();
|
|
1208
|
+
for (const kind of MEMORY_CONTROL_OBJECT_KINDS) {
|
|
1209
|
+
assert.strictEqual(await s.putObject(kind, "once.json", enc(`first ${kind}`), { scope: "s1" }), "created", `${kind}: the first put creates`);
|
|
1210
|
+
assert.strictEqual(await s.putObject(kind, "once.json", enc(`second ${kind}`)), "existed", `${kind}: the second put finds it`);
|
|
1211
|
+
assert.ok(same(await s.getObject(kind, "once.json"), enc(`first ${kind}`)), `${kind}: the first bytes stand`);
|
|
1212
|
+
}
|
|
1213
|
+
});
|
|
1214
|
+
defer("each kind is its own: one name under two kinds is two objects, and a listing answers its kind's names sorted", async () => {
|
|
1215
|
+
const s = await hooks.make();
|
|
1216
|
+
await s.putObject("pollution", "b.json", enc("pollution b"));
|
|
1217
|
+
await s.putObject("pollution", "a.json", enc("pollution a"));
|
|
1218
|
+
await s.putObject("quarantine", "a.json", enc("quarantine a"));
|
|
1219
|
+
assert.deepStrictEqual(await s.listObjects("pollution"), ["a.json", "b.json"]);
|
|
1220
|
+
assert.deepStrictEqual(await s.listObjects("quarantine"), ["a.json"]);
|
|
1221
|
+
assert.deepStrictEqual(await s.listObjects("hold"), []);
|
|
1222
|
+
assert.ok(same(await s.getObject("pollution", "a.json"), enc("pollution a")));
|
|
1223
|
+
assert.ok(same(await s.getObject("quarantine", "a.json"), enc("quarantine a")), "no alias across kinds");
|
|
1224
|
+
});
|
|
1225
|
+
defer("an object's answers are copies: changing the bytes handed in or read back changes nothing stored", async () => {
|
|
1226
|
+
const s = await hooks.make();
|
|
1227
|
+
const bytes = enc("custody");
|
|
1228
|
+
await s.putObject("hold", "h.md", bytes);
|
|
1229
|
+
bytes[0] = 0x58;
|
|
1230
|
+
const read = await s.getObject("hold", "h.md");
|
|
1231
|
+
assert.ok(same(read, enc("custody")), "the stored object is not the caller's buffer");
|
|
1232
|
+
read[0] = 0x59;
|
|
1233
|
+
assert.ok(same(await s.getObject("hold", "h.md"), enc("custody")), "a read answer is not the stored object");
|
|
1234
|
+
});
|
|
1235
|
+
defer("a move lands the bytes at the target and drops the source, a re-run resumes, and nothing is overwritten", async () => {
|
|
1236
|
+
const s = await hooks.make();
|
|
1237
|
+
await s.putObject("hold", "cap.md", enc("captured"));
|
|
1238
|
+
assert.strictEqual(await s.moveObject({ kind: "hold", name: "cap.md" }, { kind: "quarantine", name: "cap-disposed.md" }), "moved");
|
|
1239
|
+
assert.strictEqual(await s.getObject("hold", "cap.md"), undefined, "the source is gone");
|
|
1240
|
+
assert.ok(same(await s.getObject("quarantine", "cap-disposed.md"), enc("captured")), "the target holds the bytes");
|
|
1241
|
+
assert.strictEqual(await s.moveObject({ kind: "hold", name: "cap.md" }, { kind: "quarantine", name: "cap-disposed.md" }), "already-moved", "a re-run of the same move resumes");
|
|
1242
|
+
await rejectsCoded(s.moveObject({ kind: "hold", name: "never.md" }, { kind: "quarantine", name: "never.md" }), /ControlPlaneCorruptError|corrupt/i, "a move with neither side standing");
|
|
1243
|
+
await s.putObject("hold", "x.md", enc("one"));
|
|
1244
|
+
await s.putObject("quarantine", "y.md", enc("two"));
|
|
1245
|
+
await assert.rejects(s.moveObject({ kind: "hold", name: "x.md" }, { kind: "quarantine", name: "y.md" }), "a target with other bytes is never overwritten");
|
|
1246
|
+
assert.ok(same(await s.getObject("hold", "x.md"), enc("one")), "the refused move leaves its source");
|
|
1247
|
+
assert.ok(same(await s.getObject("quarantine", "y.md"), enc("two")), "the refused move leaves its target");
|
|
1248
|
+
});
|
|
1249
|
+
defer("a delete removes the bytes and answers whether they were there", async () => {
|
|
1250
|
+
const s = await hooks.make();
|
|
1251
|
+
await s.putObject("import-receipt", "r.json", enc("receipt"));
|
|
1252
|
+
assert.strictEqual(await s.deleteObject("import-receipt", "r.json"), true);
|
|
1253
|
+
assert.strictEqual(await s.getObject("import-receipt", "r.json"), undefined);
|
|
1254
|
+
assert.deepStrictEqual(await s.listObjects("import-receipt"), []);
|
|
1255
|
+
assert.strictEqual(await s.deleteObject("import-receipt", "r.json"), false);
|
|
1256
|
+
assert.strictEqual(await s.putObject("import-receipt", "r.json", enc("again")), "created", "a deleted name may be written again");
|
|
1257
|
+
});
|
|
1258
|
+
defer("a kind outside the closed set, or a name that is not one opaque segment, is refused memory.control_object_unknown", async () => {
|
|
1259
|
+
const s = await hooks.make();
|
|
1260
|
+
await rejectsCoded(s.putObject("ledger", "a.json", enc("x")), "memory.control_object_unknown", "an unknown kind");
|
|
1261
|
+
await rejectsCoded(s.listObjects("__proto__"), "memory.control_object_unknown", "a prototype key as a kind");
|
|
1262
|
+
for (const name of ["", ".", "..", "a/b", "../x", "a\\b", "a\u0000b"]) {
|
|
1263
|
+
await rejectsCoded(s.putObject("pollution", name, enc("x")), "memory.control_object_unknown", `put of the name ${JSON.stringify(name)}`);
|
|
1264
|
+
await rejectsCoded(s.getObject("pollution", name), "memory.control_object_unknown", `get of the name ${JSON.stringify(name)}`);
|
|
1265
|
+
}
|
|
1266
|
+
assert.deepStrictEqual(await s.listObjects("pollution"), [], "a refused name gave nothing storage");
|
|
1267
|
+
});
|
|
1268
|
+
defer("an object that stands but cannot be read is refused, never read as missing; a kind that cannot be enumerated is refused, never empty", async () => {
|
|
1269
|
+
const s = await hooks.make();
|
|
1270
|
+
await s.putObject("pollution", "kept.json", enc("marker"));
|
|
1271
|
+
await hooks.corrupt(s, { object: "pollution", name: "standing.json" });
|
|
1272
|
+
await rejectsCoded(s.getObject("pollution", "standing.json"), /ControlPlaneCorruptError|corrupt/i, "an unreadable object");
|
|
1273
|
+
assert.strictEqual(await s.putObject("pollution", "standing.json", enc("over it")), "existed", "an unreadable object still stands: a put does not overwrite it");
|
|
1274
|
+
await hooks.corrupt(s, { listing: "quarantine" });
|
|
1275
|
+
await rejectsCoded(s.listObjects("quarantine"), /ControlPlaneCorruptError|corrupt/i, "an enumeration that fails");
|
|
1276
|
+
});
|
|
1277
|
+
const withReplica = async (fn) => {
|
|
1278
|
+
const replica = mkdtempSync(join(tmpdir(), "sema-adopt-"));
|
|
1279
|
+
try {
|
|
1280
|
+
await fn(replica, fileGovernanceStore(replica));
|
|
1281
|
+
}
|
|
1282
|
+
finally {
|
|
1283
|
+
rmSync(replica, { recursive: true, force: true });
|
|
1284
|
+
}
|
|
1285
|
+
};
|
|
1286
|
+
defer("adoption: what the store lacks is written, what it holds the same converges, and the replica keeps its records beside a receipt", async () => {
|
|
1287
|
+
const s = await hooks.make();
|
|
1288
|
+
await withReplica(async (replica, file) => {
|
|
1289
|
+
await file.updateDoc("holds", judgeDoc, () => ({ next: { v: 1, owner: "replica", n: 1 }, result: undefined }));
|
|
1290
|
+
await file.putObject("hold", "cap.md", enc("captured"));
|
|
1291
|
+
await file.putObject("pollution", "s1.json", enc("marker"));
|
|
1292
|
+
await s.putObject("pollution", "s1.json", enc("marker"));
|
|
1293
|
+
const report = await adoptReplicaControlPlane(replica, s);
|
|
1294
|
+
assert.deepStrictEqual(report.refused, []);
|
|
1295
|
+
assert.deepStrictEqual(report.adopted.map((r) => `${r.record}:${r.outcome}`).sort(), ["doc:holds:written", "hold/cap.md:written", "pollution/s1.json:converged"]);
|
|
1296
|
+
assert.deepStrictEqual(await s.readDoc("holds"), { v: 1, owner: "replica", n: 1 });
|
|
1297
|
+
assert.ok(same(await s.getObject("hold", "cap.md"), enc("captured")));
|
|
1298
|
+
assert.deepStrictEqual(replicaControlPlaneStrays(replica), { docs: ["holds"], objects: { hold: 1, pollution: 1 } }, "adoption copies: the replica's records stay where the engine's readers read them");
|
|
1299
|
+
assert.deepStrictEqual(readControlPlaneAdoptionReceipt(replica).map((r) => r.record).sort(), ["doc:holds", "hold/cap.md", "pollution/s1.json"]);
|
|
1300
|
+
});
|
|
1301
|
+
});
|
|
1302
|
+
defer("adoption: a record the store holds with a different value is refused by name and left where it is; the documents wait while an object is refused", async () => {
|
|
1303
|
+
const s = await hooks.make();
|
|
1304
|
+
await withReplica(async (replica, file) => {
|
|
1305
|
+
await file.updateDoc("lineage", judgeDoc, () => ({ next: { v: 1, owner: "replica", n: 1 }, result: undefined }));
|
|
1306
|
+
await s.updateDoc("lineage", judgeDoc, () => ({ next: { v: 1, owner: "carrier", n: 7 }, result: undefined }));
|
|
1307
|
+
await file.updateDoc("holds", judgeDoc, () => ({ next: { v: 1, owner: "replica", n: 3 }, result: undefined }));
|
|
1308
|
+
await file.putObject("quarantine", "q.md", enc("replica bytes"));
|
|
1309
|
+
await s.putObject("quarantine", "q.md", enc("carrier bytes"));
|
|
1310
|
+
const report = await adoptReplicaControlPlane(replica, s);
|
|
1311
|
+
assert.deepStrictEqual(report.adopted, []);
|
|
1312
|
+
assert.deepStrictEqual(report.refused.map((r) => r.record).sort(), ["doc:holds", "doc:lineage", "quarantine/q.md"]);
|
|
1313
|
+
assert.strictEqual(await s.readDoc("holds"), undefined, "a document never reaches the store ahead of an object that was refused");
|
|
1314
|
+
assert.ok(same(await s.getObject("quarantine", "q.md"), enc("carrier bytes")));
|
|
1315
|
+
assert.deepStrictEqual(replicaControlPlaneStrays(replica), { docs: ["lineage", "holds"], objects: { quarantine: 1 } }, "the refused records stay in the replica");
|
|
1316
|
+
await s.deleteObject("quarantine", "q.md");
|
|
1317
|
+
const again = await adoptReplicaControlPlane(replica, s);
|
|
1318
|
+
assert.deepStrictEqual(again.adopted.map((r) => `${r.record}:${r.outcome}`).sort(), ["doc:holds:written", "quarantine/q.md:written"]);
|
|
1319
|
+
assert.deepStrictEqual(again.refused.map((r) => r.record), ["doc:lineage"]);
|
|
1320
|
+
assert.deepStrictEqual(await s.readDoc("lineage"), { v: 1, owner: "carrier", n: 7 }, "no merge is invented");
|
|
1321
|
+
assert.deepStrictEqual(replicaControlPlaneStrays(replica), { docs: ["lineage", "holds"], objects: { quarantine: 1 } }, "adoption copies: nothing leaves the replica");
|
|
1322
|
+
});
|
|
1323
|
+
});
|
|
1324
|
+
defer("adoption: a re-run converges — an interrupted handover converges, a finished one converges again and writes no second receipt row", async () => {
|
|
1325
|
+
const s = await hooks.make();
|
|
1326
|
+
await withReplica(async (replica, file) => {
|
|
1327
|
+
await file.putObject("capture", "s2.json", enc("opted out"));
|
|
1328
|
+
await file.updateDoc("challenges", judgeDoc, () => ({ next: { v: 1, owner: "replica", n: 2 }, result: undefined }));
|
|
1329
|
+
await s.putObject("capture", "s2.json", enc("opted out"));
|
|
1330
|
+
const first = await adoptReplicaControlPlane(replica, s);
|
|
1331
|
+
assert.deepStrictEqual(first.refused, []);
|
|
1332
|
+
assert.deepStrictEqual(first.adopted.map((r) => `${r.record}:${r.outcome}`).sort(), ["capture/s2.json:converged", "doc:challenges:written"]);
|
|
1333
|
+
const again = await adoptReplicaControlPlane(replica, s);
|
|
1334
|
+
assert.deepStrictEqual(again.refused, []);
|
|
1335
|
+
assert.deepStrictEqual(again.adopted.map((r) => `${r.record}:${r.outcome}`).sort(), ["capture/s2.json:converged", "doc:challenges:converged"], "a finished adoption converges again");
|
|
1336
|
+
assert.deepStrictEqual(readControlPlaneAdoptionReceipt(replica).map((r) => r.record).sort(), ["capture/s2.json", "doc:challenges"], "one receipt row per record");
|
|
1337
|
+
assert.deepStrictEqual(await s.readDoc("challenges"), { v: 1, owner: "replica", n: 2 });
|
|
1338
|
+
});
|
|
1339
|
+
});
|
|
1340
|
+
const run = hooks.runAssertion ?? (async (_name, fn) => fn());
|
|
1341
|
+
for (const [name, fn] of cases)
|
|
1342
|
+
await run(name, fn);
|
|
1343
|
+
}
|
|
868
1344
|
export async function assertMemoryBackendSearchEquivalence(a, b) {
|
|
869
1345
|
const fixture = [
|
|
870
1346
|
entry("id-eq-0001", "s1", "notes-alpha", "alpha beta gamma delta", { name: "Alpha notes", description: "about alpha" }),
|