onto-mcp 0.3.2 → 0.4.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/.onto/processes/reconstruct/actionable-ontology-seed-recomposition-design.md +447 -0
- package/.onto/processes/reconstruct/foundry-style-ontology-seed-contract.md +934 -0
- package/.onto/processes/reconstruct/reconstruct-boundary-contract.md +303 -725
- package/.onto/processes/reconstruct/reconstruct-contract-registry.yaml +1645 -0
- package/.onto/processes/reconstruct/reconstruct-execution-ux-contract.md +26 -22
- package/.onto/processes/reconstruct/source-profile-contract.md +49 -23
- package/.onto/processes/reconstruct/source-profiles/code.md +6 -3
- package/.onto/processes/reconstruct/source-profiles/database.md +5 -2
- package/.onto/processes/reconstruct/source-profiles/document.md +5 -2
- package/.onto/processes/reconstruct/source-profiles/spreadsheet.md +5 -4
- package/.onto/processes/review/review-execution-ux-contract.md +40 -0
- package/.onto/processes/shared/pipeline-execution-ledger-contract.md +26 -10
- package/.onto/processes/shared/target-material-kind-contract.md +29 -16
- package/AGENTS.md +6 -4
- package/README.md +135 -76
- package/dist/cli.js +8 -8
- package/dist/core-api/reconstruct-api.js +117 -31
- package/dist/core-api/review-api.js +47 -0
- package/dist/core-runtime/cli/codex-review-unit-executor.js +39 -2
- package/dist/core-runtime/cli/complete-review-session.js +2 -2
- package/dist/core-runtime/cli/mock-review-unit-executor.js +1 -1
- package/dist/core-runtime/cli/review-invoke.js +9 -9
- package/dist/core-runtime/cli/run-review-prompt-execution.js +39 -5
- package/dist/core-runtime/cli/spawn-watcher.js +266 -47
- package/dist/core-runtime/cli/start-review-session.js +3 -3
- package/dist/core-runtime/llm/llm-caller.js +11 -0
- package/dist/core-runtime/llm/llm-tool-loop.js +2 -0
- package/dist/core-runtime/observability/runtime-stream-observation.js +118 -0
- package/dist/core-runtime/onboard/cli-host.js +149 -0
- package/dist/core-runtime/onboard/host-target.js +22 -0
- package/dist/core-runtime/onboard/json-config-host.js +122 -0
- package/dist/core-runtime/onboard/path-scan.js +26 -0
- package/dist/core-runtime/onboard/prompt.js +51 -0
- package/dist/core-runtime/onboard/register.js +207 -0
- package/dist/core-runtime/onboard/types.js +27 -0
- package/dist/core-runtime/reconstruct/actionable-seed-validation.js +1777 -0
- package/dist/core-runtime/reconstruct/artifact-types.js +10 -4
- package/dist/core-runtime/reconstruct/contract-registry.js +623 -0
- package/dist/core-runtime/reconstruct/domain-id.js +10 -0
- package/dist/core-runtime/reconstruct/governing-snapshot.js +716 -0
- package/dist/core-runtime/reconstruct/material-profile-validation.js +191 -0
- package/dist/core-runtime/reconstruct/materialize-preparation.js +49 -11
- package/dist/core-runtime/reconstruct/pipeline-execution-ledger.js +269 -79
- package/dist/core-runtime/reconstruct/post-seed-validation.js +1194 -51
- package/dist/core-runtime/reconstruct/record.js +104 -20
- package/dist/core-runtime/reconstruct/run.js +2107 -413
- package/dist/core-runtime/reconstruct/seed-claim-projections.js +268 -0
- package/dist/core-runtime/reconstruct/source-profiles.js +93 -4
- package/dist/core-runtime/reconstruct/terminal-validation.js +807 -0
- package/dist/core-runtime/review/review-invocation-runner.js +4 -4
- package/dist/mcp/server.js +110 -38
- package/dist/mcp/tool-schemas.js +20 -6
- package/package.json +8 -17
- package/scripts/onto-review-watch.sh +486 -0
- package/scripts/onto-runtime-watch.sh +122 -0
- package/scripts/postinstall-hint.js +22 -0
- package/.onto/processes/reconstruct/top-level-concept-discovery-contract.md +0 -387
- package/dist/core-runtime/cli/bootstrap-review-binding.js +0 -186
- package/dist/core-runtime/cli/codex-nested-dispatch.test.js +0 -390
- package/dist/core-runtime/cli/codex-nested-teamlead-executor.test.js +0 -335
- package/dist/core-runtime/cli/coordinator-helpers.js +0 -583
- package/dist/core-runtime/cli/coordinator-state-machine-deliberation.test.js +0 -167
- package/dist/core-runtime/cli/coordinator-state-machine.js +0 -794
- package/dist/core-runtime/cli/e2e-codex-multi-agent-fixes.test.js +0 -615
- package/dist/core-runtime/cli/e2e-start-review-session.test.js +0 -312
- package/dist/core-runtime/cli/health.js +0 -44
- package/dist/core-runtime/cli/inline-http-review-unit-executor.test.js +0 -567
- package/dist/core-runtime/cli/materialize-review-execution-preparation.js +0 -104
- package/dist/core-runtime/cli/migrate-session-roots.js +0 -118
- package/dist/core-runtime/cli/repo-layout-migration-replace.smoke.test.js +0 -106
- package/dist/core-runtime/cli/review-invoke-auto-resolution.test.js +0 -268
- package/dist/core-runtime/cli/review-invoke-coordinator-topology.test.js +0 -136
- package/dist/core-runtime/cli/review-invoke-resolver-caching.test.js +0 -201
- package/dist/core-runtime/cli/review-invoke-topology-dispatch.test.js +0 -192
- package/dist/core-runtime/cli/session-root-guard.js +0 -168
- package/dist/core-runtime/cli/spawn-watcher.test.js +0 -457
- package/dist/core-runtime/cli/strip-wrapping-code-fence.test.js +0 -79
- package/dist/core-runtime/cli/teamcreate-lens-deliberation-executor.js +0 -412
- package/dist/core-runtime/cli/teamcreate-lens-deliberation-executor.test.js +0 -351
- package/dist/core-runtime/cli/topology-executor-mapping.js +0 -139
- package/dist/core-runtime/cli/topology-executor-mapping.test.js +0 -173
- package/dist/core-runtime/cli/write-review-interpretation.js +0 -81
- package/dist/core-runtime/config/onto-config-cli.js +0 -278
- package/dist/core-runtime/config/onto-config-key-path.js +0 -288
- package/dist/core-runtime/config/onto-config-key-path.test.js +0 -195
- package/dist/core-runtime/config/onto-config-preview.js +0 -108
- package/dist/core-runtime/config/onto-config-preview.test.js +0 -132
- package/dist/core-runtime/discovery/config-chain.js +0 -118
- package/dist/core-runtime/discovery/config-chain.test.js +0 -103
- package/dist/core-runtime/discovery/config-profile.js +0 -199
- package/dist/core-runtime/discovery/config-profile.test.js +0 -233
- package/dist/core-runtime/discovery/host-detection.test.js +0 -186
- package/dist/core-runtime/discovery/installation-paths.test.js +0 -65
- package/dist/core-runtime/discovery/lens-registry.test.js +0 -81
- package/dist/core-runtime/discovery/path-normalization.test.js +0 -22
- package/dist/core-runtime/discovery/plugin-path.js +0 -72
- package/dist/core-runtime/discovery/plugin-path.test.js +0 -95
- package/dist/core-runtime/evolve/adapters/code-product/compile/compile-defense.js +0 -344
- package/dist/core-runtime/evolve/adapters/code-product/compile/compile-defense.test.js +0 -915
- package/dist/core-runtime/evolve/adapters/code-product/compile/compile.js +0 -564
- package/dist/core-runtime/evolve/adapters/code-product/compile/compile.test.js +0 -708
- package/dist/core-runtime/evolve/adapters/code-product/parsers/brief-parser.js +0 -165
- package/dist/core-runtime/evolve/adapters/code-product/parsers/brief-parser.test.js +0 -227
- package/dist/core-runtime/evolve/adapters/code-product/validators/validate.js +0 -59
- package/dist/core-runtime/evolve/adapters/code-product/validators/validate.test.js +0 -205
- package/dist/core-runtime/evolve/adapters/methodology/adapter.js +0 -16
- package/dist/core-runtime/evolve/adapters/methodology/adapter.test.js +0 -9
- package/dist/core-runtime/evolve/adapters/methodology/perspectives/authority-consistency.js +0 -298
- package/dist/core-runtime/evolve/adapters/methodology/perspectives/authority-consistency.test.js +0 -70
- package/dist/core-runtime/evolve/adapters/methodology/scope-types/process.js +0 -46
- package/dist/core-runtime/evolve/adapters/methodology/scope-types/process.test.js +0 -73
- package/dist/core-runtime/evolve/adapters/registry.js +0 -47
- package/dist/core-runtime/evolve/adapters/registry.test.js +0 -67
- package/dist/core-runtime/evolve/cli.js +0 -256
- package/dist/core-runtime/evolve/commands/align.js +0 -194
- package/dist/core-runtime/evolve/commands/align.test.js +0 -82
- package/dist/core-runtime/evolve/commands/apply.js +0 -161
- package/dist/core-runtime/evolve/commands/apply.test.js +0 -138
- package/dist/core-runtime/evolve/commands/close.js +0 -39
- package/dist/core-runtime/evolve/commands/close.test.js +0 -99
- package/dist/core-runtime/evolve/commands/defer.js +0 -40
- package/dist/core-runtime/evolve/commands/defer.test.js +0 -134
- package/dist/core-runtime/evolve/commands/draft.js +0 -323
- package/dist/core-runtime/evolve/commands/draft.test.js +0 -178
- package/dist/core-runtime/evolve/commands/e2e-evolve-full-cycle.test.js +0 -208
- package/dist/core-runtime/evolve/commands/error-messages.js +0 -125
- package/dist/core-runtime/evolve/commands/error-messages.test.js +0 -167
- package/dist/core-runtime/evolve/commands/propose-align.js +0 -222
- package/dist/core-runtime/evolve/commands/propose-align.test.js +0 -136
- package/dist/core-runtime/evolve/commands/reconstruct.js +0 -330
- package/dist/core-runtime/evolve/commands/reconstruct.test.js +0 -278
- package/dist/core-runtime/evolve/commands/shared.js +0 -22
- package/dist/core-runtime/evolve/commands/stale-check.js +0 -103
- package/dist/core-runtime/evolve/commands/stale-check.test.js +0 -84
- package/dist/core-runtime/evolve/commands/start.js +0 -887
- package/dist/core-runtime/evolve/commands/start.test.js +0 -396
- package/dist/core-runtime/evolve/config/project-config.js +0 -99
- package/dist/core-runtime/evolve/config/project-config.test.js +0 -170
- package/dist/core-runtime/evolve/renderers/align-packet.js +0 -280
- package/dist/core-runtime/evolve/renderers/align-packet.test.js +0 -332
- package/dist/core-runtime/evolve/renderers/draft-packet.js +0 -303
- package/dist/core-runtime/evolve/renderers/draft-packet.test.js +0 -377
- package/dist/core-runtime/evolve/renderers/format.js +0 -5
- package/dist/core-runtime/evolve/renderers/scope-md.js +0 -237
- package/dist/core-runtime/evolve/renderers/scope-md.test.js +0 -306
- package/dist/core-runtime/govern/cli.js +0 -369
- package/dist/core-runtime/govern/cli.test.js +0 -314
- package/dist/core-runtime/govern/drift-engine.js +0 -103
- package/dist/core-runtime/govern/drift-engine.test.js +0 -319
- package/dist/core-runtime/govern/promote-principle.js +0 -206
- package/dist/core-runtime/govern/promote-principle.test.js +0 -368
- package/dist/core-runtime/govern/queue.js +0 -81
- package/dist/core-runtime/govern/types.js +0 -16
- package/dist/core-runtime/install/cli.js +0 -530
- package/dist/core-runtime/install/detect.js +0 -128
- package/dist/core-runtime/install/detect.test.js +0 -155
- package/dist/core-runtime/install/gitignore-update.js +0 -74
- package/dist/core-runtime/install/gitignore-update.test.js +0 -64
- package/dist/core-runtime/install/install-integration.test.js +0 -373
- package/dist/core-runtime/install/prompts.js +0 -389
- package/dist/core-runtime/install/prompts.test.js +0 -293
- package/dist/core-runtime/install/types.js +0 -26
- package/dist/core-runtime/install/validation.js +0 -295
- package/dist/core-runtime/install/validation.test.js +0 -313
- package/dist/core-runtime/install/writer.js +0 -254
- package/dist/core-runtime/install/writer.test.js +0 -218
- package/dist/core-runtime/learning/extractor.js +0 -461
- package/dist/core-runtime/learning/feedback.js +0 -179
- package/dist/core-runtime/learning/health-report.js +0 -165
- package/dist/core-runtime/learning/health-report.test.js +0 -169
- package/dist/core-runtime/learning/loader.js +0 -388
- package/dist/core-runtime/learning/loader.test.js +0 -102
- package/dist/core-runtime/learning/promote/apply-state.js +0 -240
- package/dist/core-runtime/learning/promote/audit-obligation.js +0 -195
- package/dist/core-runtime/learning/promote/collector.js +0 -432
- package/dist/core-runtime/learning/promote/degraded-state.js +0 -125
- package/dist/core-runtime/learning/promote/domain-doc-proposer.js +0 -166
- package/dist/core-runtime/learning/promote/e2e-promote.test.js +0 -6385
- package/dist/core-runtime/learning/promote/health-snapshot.js +0 -150
- package/dist/core-runtime/learning/promote/insight-reclassifier.js +0 -544
- package/dist/core-runtime/learning/promote/judgment-auditor.js +0 -517
- package/dist/core-runtime/learning/promote/panel-reviewer.js +0 -1158
- package/dist/core-runtime/learning/promote/promote-executor.js +0 -1675
- package/dist/core-runtime/learning/promote/promoter.js +0 -307
- package/dist/core-runtime/learning/promote/retirement.js +0 -122
- package/dist/core-runtime/learning/promote/types.js +0 -23
- package/dist/core-runtime/learning/prompt-sections.js +0 -51
- package/dist/core-runtime/learning/shared/artifact-registry-init.js +0 -45
- package/dist/core-runtime/learning/shared/artifact-registry.js +0 -254
- package/dist/core-runtime/learning/shared/audit-obligation-kernel.js +0 -73
- package/dist/core-runtime/learning/shared/audit-state.js +0 -99
- package/dist/core-runtime/learning/shared/duplicate-check.js +0 -28
- package/dist/core-runtime/learning/shared/llm-caller.js +0 -831
- package/dist/core-runtime/learning/shared/llm-caller.test.js +0 -601
- package/dist/core-runtime/learning/shared/llm-tool-loop.js +0 -393
- package/dist/core-runtime/learning/shared/mode.js +0 -25
- package/dist/core-runtime/learning/shared/paths.js +0 -84
- package/dist/core-runtime/learning/shared/paths.test.js +0 -79
- package/dist/core-runtime/learning/shared/patterns.js +0 -37
- package/dist/core-runtime/learning/shared/recoverability.js +0 -355
- package/dist/core-runtime/learning/shared/recovery-context.js +0 -374
- package/dist/core-runtime/learning/shared/scope.js +0 -1
- package/dist/core-runtime/learning/shared/semantic-classifier.js +0 -94
- package/dist/core-runtime/learning/shared/specs/apply-execution-state-spec.js +0 -42
- package/dist/core-runtime/learning/shared/specs/audit-state-spec.js +0 -37
- package/dist/core-runtime/learning/shared/specs/backup-metadata-spec.js +0 -39
- package/dist/core-runtime/learning/shared/specs/emergency-log-spec.js +0 -41
- package/dist/core-runtime/learning/shared/specs/layout-version-spec.js +0 -38
- package/dist/core-runtime/learning/shared/specs/promote-decisions-spec.js +0 -43
- package/dist/core-runtime/learning/shared/specs/promote-report-spec.js +0 -113
- package/dist/core-runtime/learning/shared/specs/prune-log-spec.js +0 -36
- package/dist/core-runtime/learning/shared/specs/recovery-resolution-spec.js +0 -48
- package/dist/core-runtime/learning/shared/specs/restore-manifest-spec.js +0 -43
- package/dist/core-runtime/learning/shared/specs/spec-helpers.js +0 -64
- package/dist/core-runtime/learning/usage-tracker.js +0 -190
- package/dist/core-runtime/learning/usage-tracker.test.js +0 -176
- package/dist/core-runtime/onboard/detect-review-axes.js +0 -122
- package/dist/core-runtime/onboard/detect-review-axes.test.js +0 -127
- package/dist/core-runtime/onboard/write-review-block.js +0 -188
- package/dist/core-runtime/onboard/write-review-block.test.js +0 -240
- package/dist/core-runtime/readers/brownfield-builder.js +0 -150
- package/dist/core-runtime/readers/brownfield-builder.test.js +0 -136
- package/dist/core-runtime/readers/code-chunk-collector.js +0 -53
- package/dist/core-runtime/readers/code-chunk-collector.test.js +0 -136
- package/dist/core-runtime/readers/file-utils.js +0 -240
- package/dist/core-runtime/readers/file-utils.test.js +0 -146
- package/dist/core-runtime/readers/lexicon-citation-check.js +0 -93
- package/dist/core-runtime/readers/lexicon-citation-check.test.js +0 -77
- package/dist/core-runtime/readers/mcp-figma.js +0 -30
- package/dist/core-runtime/readers/mcp-figma.test.js +0 -82
- package/dist/core-runtime/readers/mcp-generic.js +0 -31
- package/dist/core-runtime/readers/mcp-generic.test.js +0 -76
- package/dist/core-runtime/readers/ontology-index.js +0 -148
- package/dist/core-runtime/readers/ontology-index.test.js +0 -245
- package/dist/core-runtime/readers/ontology-query.js +0 -168
- package/dist/core-runtime/readers/ontology-query.test.js +0 -311
- package/dist/core-runtime/readers/ontology-resolve.js +0 -48
- package/dist/core-runtime/readers/ontology-resolve.test.js +0 -48
- package/dist/core-runtime/readers/patterns/index.js +0 -7
- package/dist/core-runtime/readers/review-log.js +0 -213
- package/dist/core-runtime/readers/review-log.test.js +0 -313
- package/dist/core-runtime/readers/scan-local.js +0 -102
- package/dist/core-runtime/readers/scan-local.test.js +0 -102
- package/dist/core-runtime/readers/scan-tarball.js +0 -121
- package/dist/core-runtime/readers/scan-tarball.test.js +0 -283
- package/dist/core-runtime/readers/scan-vault.js +0 -34
- package/dist/core-runtime/readers/scan-vault.test.js +0 -81
- package/dist/core-runtime/readers/types.js +0 -42
- package/dist/core-runtime/readers/types.test.js +0 -94
- package/dist/core-runtime/readers/viewpoint-collectors.js +0 -229
- package/dist/core-runtime/reconstruct/seed-candidate-validation.js +0 -385
- package/dist/core-runtime/review/citation-audit.test.js +0 -165
- package/dist/core-runtime/review/execution-plan-resolver.js +0 -247
- package/dist/core-runtime/review/execution-plan-resolver.test.js +0 -243
- package/dist/core-runtime/review/execution-topology-resolver-axis-first.test.js +0 -246
- package/dist/core-runtime/review/execution-topology-resolver.js +0 -401
- package/dist/core-runtime/review/execution-topology-resolver.test.js +0 -315
- package/dist/core-runtime/review/inline-context-embedder.test.js +0 -154
- package/dist/core-runtime/review/legacy-mode-policy.js +0 -88
- package/dist/core-runtime/review/materializers-effort-persist.test.js +0 -79
- package/dist/core-runtime/review/ontology-path-classifier.js +0 -179
- package/dist/core-runtime/review/ontology-path-classifier.test.js +0 -216
- package/dist/core-runtime/review/packet-boundary-policy.test.js +0 -107
- package/dist/core-runtime/review/participating-lens-paths.test.js +0 -73
- package/dist/core-runtime/review/review-config-legacy-translate.js +0 -244
- package/dist/core-runtime/review/review-config-legacy-translate.test.js +0 -161
- package/dist/core-runtime/review/review-config-validator.js +0 -289
- package/dist/core-runtime/review/review-config-validator.test.js +0 -236
- package/dist/core-runtime/review/shape-pipeline-audit.test.js +0 -311
- package/dist/core-runtime/review/shape-to-topology-id.js +0 -117
- package/dist/core-runtime/review/shape-to-topology-id.test.js +0 -132
- package/dist/core-runtime/review/topology-shape-derivation.js +0 -155
- package/dist/core-runtime/review/topology-shape-derivation.test.js +0 -195
- package/dist/core-runtime/scope-runtime/constants.js +0 -12
- package/dist/core-runtime/scope-runtime/constraint-pool.js +0 -166
- package/dist/core-runtime/scope-runtime/constraint-pool.test.js +0 -674
- package/dist/core-runtime/scope-runtime/domain-validation-log.js +0 -135
- package/dist/core-runtime/scope-runtime/domain-validation-log.test.js +0 -156
- package/dist/core-runtime/scope-runtime/eval-persistence.js +0 -65
- package/dist/core-runtime/scope-runtime/eval-persistence.test.js +0 -84
- package/dist/core-runtime/scope-runtime/event-pipeline.js +0 -64
- package/dist/core-runtime/scope-runtime/event-pipeline.test.js +0 -450
- package/dist/core-runtime/scope-runtime/event-store.js +0 -39
- package/dist/core-runtime/scope-runtime/event-store.test.js +0 -95
- package/dist/core-runtime/scope-runtime/gate-guard.js +0 -348
- package/dist/core-runtime/scope-runtime/gate-guard.test.js +0 -1047
- package/dist/core-runtime/scope-runtime/hash.js +0 -4
- package/dist/core-runtime/scope-runtime/hash.test.js +0 -33
- package/dist/core-runtime/scope-runtime/id.js +0 -4
- package/dist/core-runtime/scope-runtime/id.test.js +0 -17
- package/dist/core-runtime/scope-runtime/reducer.js +0 -297
- package/dist/core-runtime/scope-runtime/reducer.test.js +0 -759
- package/dist/core-runtime/scope-runtime/scope-manager.js +0 -161
- package/dist/core-runtime/scope-runtime/state-machine.js +0 -309
- package/dist/core-runtime/scope-runtime/state-machine.test.js +0 -704
- package/dist/core-runtime/scope-runtime/types.js +0 -116
- package/dist/core-runtime/scope-runtime/types.test.js +0 -69
- package/dist/core-runtime/translate/render-for-user.js +0 -169
- package/dist/core-runtime/translate/render-for-user.test.js +0 -122
- package/dist/providers/capability-contract.js +0 -1
|
@@ -1,450 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
2
|
-
import { mkdtempSync, rmSync, readFileSync, existsSync } from "node:fs";
|
|
3
|
-
import { join, resolve } from "node:path";
|
|
4
|
-
import { appendScopeEvent } from "./event-pipeline.js";
|
|
5
|
-
import { createScope, resolveScopePaths } from "./scope-manager.js";
|
|
6
|
-
import { readEvents } from "./event-store.js";
|
|
7
|
-
import { reduce } from "./reducer.js";
|
|
8
|
-
// ─── Temp dir management ───
|
|
9
|
-
let tempDir;
|
|
10
|
-
let paths;
|
|
11
|
-
function setup() {
|
|
12
|
-
tempDir = mkdtempSync(join(process.cwd(), ".tmp-test-"));
|
|
13
|
-
paths = createScope(tempDir, "SC-TEST");
|
|
14
|
-
}
|
|
15
|
-
function teardown() {
|
|
16
|
-
rmSync(tempDir, { recursive: true, force: true });
|
|
17
|
-
}
|
|
18
|
-
// ─── Event input factory (simplified — type + actor + payload only) ───
|
|
19
|
-
function input(type, payload, actor = "system") {
|
|
20
|
-
return { type, actor, payload };
|
|
21
|
-
}
|
|
22
|
-
// ─── Scope manager tests ───
|
|
23
|
-
describe("scope-manager", () => {
|
|
24
|
-
beforeEach(setup);
|
|
25
|
-
afterEach(teardown);
|
|
26
|
-
it("creates scope directory structure", () => {
|
|
27
|
-
expect(existsSync(paths.base)).toBe(true);
|
|
28
|
-
expect(existsSync(paths.state)).toBe(true);
|
|
29
|
-
expect(existsSync(paths.surface)).toBe(true);
|
|
30
|
-
expect(existsSync(paths.build)).toBe(true);
|
|
31
|
-
expect(existsSync(paths.inputs)).toBe(true);
|
|
32
|
-
});
|
|
33
|
-
it("resolveScopePaths returns correct paths and scopeId", () => {
|
|
34
|
-
const resolved = resolveScopePaths(tempDir, "SC-TEST");
|
|
35
|
-
expect(resolved.scopeId).toBe("SC-TEST");
|
|
36
|
-
expect(resolved.events).toContain("events.ndjson");
|
|
37
|
-
expect(resolved.constraintPool).toContain("constraint-pool.json");
|
|
38
|
-
expect(resolved.verdictLog).toContain("verdict-log.json");
|
|
39
|
-
});
|
|
40
|
-
it("createScope is idempotent", () => {
|
|
41
|
-
const paths2 = createScope(tempDir, "SC-TEST");
|
|
42
|
-
expect(paths2.base).toBe(paths.base);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
// ─── Pipeline: sequential event recording ───
|
|
46
|
-
describe("event-pipeline — sequential recording", () => {
|
|
47
|
-
beforeEach(setup);
|
|
48
|
-
afterEach(teardown);
|
|
49
|
-
it("records scope.created as first event", () => {
|
|
50
|
-
const result = appendScopeEvent(paths, input("scope.created", {
|
|
51
|
-
title: "Test", description: "Test scope", entry_mode: "experience",
|
|
52
|
-
}, "user"));
|
|
53
|
-
expect(result.success).toBe(true);
|
|
54
|
-
if (result.success) {
|
|
55
|
-
expect(result.event.revision).toBe(1);
|
|
56
|
-
expect(result.next_state).toBe("draft");
|
|
57
|
-
expect(result.event.scope_id).toBe("SC-TEST");
|
|
58
|
-
expect(result.event.event_id).toBe("evt_001");
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
it("records 3 sequential events: created → grounding → grounded", () => {
|
|
62
|
-
appendScopeEvent(paths, input("scope.created", {
|
|
63
|
-
title: "Test", description: "d", entry_mode: "experience",
|
|
64
|
-
}, "user"));
|
|
65
|
-
appendScopeEvent(paths, input("grounding.started", {
|
|
66
|
-
sources: [{ type: "add-dir", path_or_url: "/test" }],
|
|
67
|
-
}));
|
|
68
|
-
const r3 = appendScopeEvent(paths, input("grounding.completed", {
|
|
69
|
-
snapshot_revision: 1,
|
|
70
|
-
source_hashes: { src: "hash1" },
|
|
71
|
-
perspective_summary: { experience: 1, code: 2, policy: 1 },
|
|
72
|
-
}));
|
|
73
|
-
expect(r3.success).toBe(true);
|
|
74
|
-
if (r3.success) {
|
|
75
|
-
expect(r3.next_state).toBe("grounded");
|
|
76
|
-
expect(r3.event.revision).toBe(3);
|
|
77
|
-
}
|
|
78
|
-
const events = readEvents(paths.events);
|
|
79
|
-
expect(events).toHaveLength(3);
|
|
80
|
-
expect(events[2].state_after).toBe("grounded");
|
|
81
|
-
});
|
|
82
|
-
it("auto-generates envelope fields", () => {
|
|
83
|
-
const result = appendScopeEvent(paths, input("scope.created", {
|
|
84
|
-
title: "T", description: "d", entry_mode: "experience",
|
|
85
|
-
}, "user"));
|
|
86
|
-
if (result.success) {
|
|
87
|
-
expect(result.event.event_id).toBeDefined();
|
|
88
|
-
expect(result.event.scope_id).toBe("SC-TEST");
|
|
89
|
-
expect(result.event.ts).toBeDefined();
|
|
90
|
-
expect(result.event.revision).toBe(1);
|
|
91
|
-
expect(result.event.state_before).toBeNull();
|
|
92
|
-
expect(result.event.state_after).toBe("draft");
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
it("sets state_before from current state", () => {
|
|
96
|
-
appendScopeEvent(paths, input("scope.created", {
|
|
97
|
-
title: "T", description: "d", entry_mode: "experience",
|
|
98
|
-
}, "user"));
|
|
99
|
-
const r2 = appendScopeEvent(paths, input("grounding.started", { sources: [] }));
|
|
100
|
-
if (r2.success) {
|
|
101
|
-
expect(r2.event.state_before).toBe("draft");
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
// ─── Pipeline: rejection ───
|
|
106
|
-
describe("event-pipeline — rejection", () => {
|
|
107
|
-
beforeEach(setup);
|
|
108
|
-
afterEach(teardown);
|
|
109
|
-
it("rejects invalid transition", () => {
|
|
110
|
-
appendScopeEvent(paths, input("scope.created", {
|
|
111
|
-
title: "T", description: "d", entry_mode: "experience",
|
|
112
|
-
}, "user"));
|
|
113
|
-
const result = appendScopeEvent(paths, input("align.locked", {
|
|
114
|
-
locked_direction: "d",
|
|
115
|
-
locked_scope_boundaries: { in: [], out: [] },
|
|
116
|
-
locked_in_out: true,
|
|
117
|
-
}, "user"));
|
|
118
|
-
expect(result.success).toBe(false);
|
|
119
|
-
if (!result.success)
|
|
120
|
-
expect(result.reason).toContain("Transition denied");
|
|
121
|
-
});
|
|
122
|
-
it("rejects scope.created when events exist", () => {
|
|
123
|
-
appendScopeEvent(paths, input("scope.created", {
|
|
124
|
-
title: "T", description: "d", entry_mode: "experience",
|
|
125
|
-
}, "user"));
|
|
126
|
-
const result = appendScopeEvent(paths, input("scope.created", {
|
|
127
|
-
title: "T2", description: "d2", entry_mode: "interface",
|
|
128
|
-
}, "user"));
|
|
129
|
-
expect(result.success).toBe(false);
|
|
130
|
-
});
|
|
131
|
-
it("does not write event on rejection", () => {
|
|
132
|
-
appendScopeEvent(paths, input("scope.created", {
|
|
133
|
-
title: "T", description: "d", entry_mode: "experience",
|
|
134
|
-
}, "user"));
|
|
135
|
-
appendScopeEvent(paths, input("align.locked", {
|
|
136
|
-
locked_direction: "d",
|
|
137
|
-
locked_scope_boundaries: { in: [], out: [] },
|
|
138
|
-
locked_in_out: true,
|
|
139
|
-
}, "user"));
|
|
140
|
-
expect(readEvents(paths.events)).toHaveLength(1);
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
// ─── Pipeline: materialized views ───
|
|
144
|
-
describe("event-pipeline — materialized views", () => {
|
|
145
|
-
beforeEach(setup);
|
|
146
|
-
afterEach(teardown);
|
|
147
|
-
it("writes constraint-pool.json after event", () => {
|
|
148
|
-
appendScopeEvent(paths, input("scope.created", {
|
|
149
|
-
title: "T", description: "d", entry_mode: "experience",
|
|
150
|
-
}, "user"));
|
|
151
|
-
expect(existsSync(paths.constraintPool)).toBe(true);
|
|
152
|
-
const pool = JSON.parse(readFileSync(paths.constraintPool, "utf-8"));
|
|
153
|
-
expect(pool.summary.total).toBe(0);
|
|
154
|
-
});
|
|
155
|
-
it("writes verdict-log.json after event", () => {
|
|
156
|
-
appendScopeEvent(paths, input("scope.created", {
|
|
157
|
-
title: "T", description: "d", entry_mode: "experience",
|
|
158
|
-
}, "user"));
|
|
159
|
-
expect(existsSync(paths.verdictLog)).toBe(true);
|
|
160
|
-
const log = JSON.parse(readFileSync(paths.verdictLog, "utf-8"));
|
|
161
|
-
expect(log).toHaveLength(0);
|
|
162
|
-
});
|
|
163
|
-
it("updates constraint-pool.json when constraints are added", () => {
|
|
164
|
-
appendScopeEvent(paths, input("scope.created", { title: "T", description: "d", entry_mode: "experience" }, "user"));
|
|
165
|
-
appendScopeEvent(paths, input("grounding.completed", { snapshot_revision: 1, source_hashes: {}, perspective_summary: { experience: 0, code: 0, policy: 0 } }));
|
|
166
|
-
appendScopeEvent(paths, input("align.proposed", { packet_path: "p", packet_hash: "h", snapshot_revision: 1 }));
|
|
167
|
-
appendScopeEvent(paths, input("align.locked", { locked_direction: "dir", locked_scope_boundaries: { in: [], out: [] }, locked_in_out: true }, "user"));
|
|
168
|
-
appendScopeEvent(paths, input("surface.generated", { surface_type: "experience", surface_path: "s", content_hash: "h", based_on_snapshot: 1 }));
|
|
169
|
-
appendScopeEvent(paths, input("surface.confirmed", { final_surface_path: "s", final_content_hash: "h", total_revisions: 0 }, "user"));
|
|
170
|
-
appendScopeEvent(paths, input("constraint.discovered", {
|
|
171
|
-
constraint_id: "CST-001", perspective: "code", summary: "test",
|
|
172
|
-
severity: "required", discovery_stage: "draft_phase2",
|
|
173
|
-
decision_owner: "builder", impact_if_ignored: "bad", source_refs: [],
|
|
174
|
-
}));
|
|
175
|
-
const pool = JSON.parse(readFileSync(paths.constraintPool, "utf-8"));
|
|
176
|
-
expect(pool.summary.total).toBe(1);
|
|
177
|
-
expect(pool.summary.undecided).toBe(1);
|
|
178
|
-
});
|
|
179
|
-
it("updates verdict-log.json when decisions are made", () => {
|
|
180
|
-
appendScopeEvent(paths, input("scope.created", { title: "T", description: "d", entry_mode: "experience" }, "user"));
|
|
181
|
-
appendScopeEvent(paths, input("grounding.completed", { snapshot_revision: 1, source_hashes: {}, perspective_summary: { experience: 0, code: 0, policy: 0 } }));
|
|
182
|
-
appendScopeEvent(paths, input("align.proposed", { packet_path: "p", packet_hash: "h", snapshot_revision: 1 }));
|
|
183
|
-
appendScopeEvent(paths, input("align.locked", { locked_direction: "dir", locked_scope_boundaries: { in: [], out: [] }, locked_in_out: true }, "user"));
|
|
184
|
-
appendScopeEvent(paths, input("surface.generated", { surface_type: "experience", surface_path: "s", content_hash: "h", based_on_snapshot: 1 }));
|
|
185
|
-
appendScopeEvent(paths, input("surface.confirmed", { final_surface_path: "s", final_content_hash: "h", total_revisions: 0 }, "user"));
|
|
186
|
-
appendScopeEvent(paths, input("constraint.discovered", {
|
|
187
|
-
constraint_id: "CST-001", perspective: "code", summary: "test",
|
|
188
|
-
severity: "required", discovery_stage: "draft_phase2",
|
|
189
|
-
decision_owner: "builder", impact_if_ignored: "bad", source_refs: [],
|
|
190
|
-
}));
|
|
191
|
-
appendScopeEvent(paths, input("constraint.decision_recorded", {
|
|
192
|
-
constraint_id: "CST-001", decision: "inject", selected_option: "opt",
|
|
193
|
-
decision_owner: "builder", rationale: "needed",
|
|
194
|
-
}, "agent"));
|
|
195
|
-
const log = JSON.parse(readFileSync(paths.verdictLog, "utf-8"));
|
|
196
|
-
expect(log).toHaveLength(2);
|
|
197
|
-
expect(log[0].type).toBe("align.locked");
|
|
198
|
-
expect(log[1].type).toBe("constraint.decision_recorded");
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
// ─── Pipeline: state returned for caller rendering ───
|
|
202
|
-
describe("event-pipeline — state for caller rendering", () => {
|
|
203
|
-
beforeEach(setup);
|
|
204
|
-
afterEach(teardown);
|
|
205
|
-
it("returns updatedState so caller can render scope.md", async () => {
|
|
206
|
-
const result = appendScopeEvent(paths, input("scope.created", {
|
|
207
|
-
title: "Test Scope", description: "d", entry_mode: "experience",
|
|
208
|
-
}, "user"));
|
|
209
|
-
expect(result.success).toBe(true);
|
|
210
|
-
if (result.success) {
|
|
211
|
-
expect(result.state).toBeDefined();
|
|
212
|
-
expect(result.state.title).toBe("Test Scope");
|
|
213
|
-
expect(result.state.current_state).toBe("draft");
|
|
214
|
-
// Caller can render scope.md using returned state
|
|
215
|
-
const { renderScopeMd } = await import("../evolve/renderers/scope-md.js");
|
|
216
|
-
const md = renderScopeMd(result.state);
|
|
217
|
-
expect(md).toContain("# Scope: Test Scope");
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
// ─── Pipeline: rejection recovery ───
|
|
222
|
-
describe("event-pipeline — rejection recovery", () => {
|
|
223
|
-
beforeEach(setup);
|
|
224
|
-
afterEach(teardown);
|
|
225
|
-
it("rejects invalid event then accepts valid event", () => {
|
|
226
|
-
appendScopeEvent(paths, input("scope.created", {
|
|
227
|
-
title: "T", description: "d", entry_mode: "experience",
|
|
228
|
-
}, "user"));
|
|
229
|
-
// Invalid: align.locked not allowed from draft
|
|
230
|
-
const rejected = appendScopeEvent(paths, input("align.locked", {
|
|
231
|
-
locked_direction: "d",
|
|
232
|
-
locked_scope_boundaries: { in: [], out: [] },
|
|
233
|
-
locked_in_out: true,
|
|
234
|
-
}, "user"));
|
|
235
|
-
expect(rejected.success).toBe(false);
|
|
236
|
-
// Valid: grounding.started is allowed from draft
|
|
237
|
-
const accepted = appendScopeEvent(paths, input("grounding.started", {
|
|
238
|
-
sources: [{ type: "add-dir", path_or_url: "/test" }],
|
|
239
|
-
}));
|
|
240
|
-
expect(accepted.success).toBe(true);
|
|
241
|
-
if (accepted.success) {
|
|
242
|
-
expect(accepted.event.revision).toBe(2);
|
|
243
|
-
expect(accepted.next_state).toBe("draft");
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
// ─── Pipeline: terminal state rejection ───
|
|
248
|
-
describe("event-pipeline — terminal state rejection", () => {
|
|
249
|
-
beforeEach(setup);
|
|
250
|
-
afterEach(teardown);
|
|
251
|
-
it("rejects events after scope.deferred (terminal state)", () => {
|
|
252
|
-
appendScopeEvent(paths, input("scope.created", {
|
|
253
|
-
title: "T", description: "d", entry_mode: "experience",
|
|
254
|
-
}, "user"));
|
|
255
|
-
appendScopeEvent(paths, input("scope.deferred", {
|
|
256
|
-
reason: "postponed", resume_condition: "next quarter",
|
|
257
|
-
}, "user"));
|
|
258
|
-
const result = appendScopeEvent(paths, input("grounding.started", {
|
|
259
|
-
sources: [{ type: "add-dir", path_or_url: "/test" }],
|
|
260
|
-
}));
|
|
261
|
-
expect(result.success).toBe(false);
|
|
262
|
-
if (!result.success)
|
|
263
|
-
expect(result.reason).toContain("Transition denied");
|
|
264
|
-
});
|
|
265
|
-
it("rejects events after scope.rejected (terminal state)", () => {
|
|
266
|
-
appendScopeEvent(paths, input("scope.created", {
|
|
267
|
-
title: "T", description: "d", entry_mode: "experience",
|
|
268
|
-
}, "user"));
|
|
269
|
-
appendScopeEvent(paths, input("scope.rejected", {
|
|
270
|
-
reason: "not feasible", rejection_basis: "cost",
|
|
271
|
-
}, "user"));
|
|
272
|
-
const result = appendScopeEvent(paths, input("grounding.started", {
|
|
273
|
-
sources: [{ type: "add-dir", path_or_url: "/test" }],
|
|
274
|
-
}));
|
|
275
|
-
expect(result.success).toBe(false);
|
|
276
|
-
if (!result.success)
|
|
277
|
-
expect(result.reason).toContain("Transition denied");
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
// ─── Pipeline: constraint lifecycle with materialized views ───
|
|
281
|
-
describe("event-pipeline — constraint lifecycle materialized views", () => {
|
|
282
|
-
beforeEach(setup);
|
|
283
|
-
afterEach(teardown);
|
|
284
|
-
it("discovered → decided: constraint-pool.json has decided constraint", () => {
|
|
285
|
-
appendScopeEvent(paths, input("scope.created", { title: "T", description: "d", entry_mode: "experience" }, "user"));
|
|
286
|
-
appendScopeEvent(paths, input("grounding.completed", { snapshot_revision: 1, source_hashes: {}, perspective_summary: { experience: 0, code: 0, policy: 0 } }));
|
|
287
|
-
appendScopeEvent(paths, input("align.proposed", { packet_path: "p", packet_hash: "h", snapshot_revision: 1 }));
|
|
288
|
-
appendScopeEvent(paths, input("align.locked", { locked_direction: "dir", locked_scope_boundaries: { in: [], out: [] }, locked_in_out: true }, "user"));
|
|
289
|
-
appendScopeEvent(paths, input("surface.generated", { surface_type: "experience", surface_path: "s", content_hash: "h", based_on_snapshot: 1 }));
|
|
290
|
-
appendScopeEvent(paths, input("surface.confirmed", { final_surface_path: "s", final_content_hash: "h", total_revisions: 0 }, "user"));
|
|
291
|
-
appendScopeEvent(paths, input("constraint.discovered", {
|
|
292
|
-
constraint_id: "CST-001", perspective: "code", summary: "test",
|
|
293
|
-
severity: "required", discovery_stage: "draft_phase2",
|
|
294
|
-
decision_owner: "builder", impact_if_ignored: "bad", source_refs: [],
|
|
295
|
-
}));
|
|
296
|
-
appendScopeEvent(paths, input("constraint.decision_recorded", {
|
|
297
|
-
constraint_id: "CST-001", decision: "inject", selected_option: "opt",
|
|
298
|
-
decision_owner: "builder", rationale: "needed",
|
|
299
|
-
}, "agent"));
|
|
300
|
-
const pool = JSON.parse(readFileSync(paths.constraintPool, "utf-8"));
|
|
301
|
-
expect(pool.summary.total).toBe(1);
|
|
302
|
-
expect(pool.summary.decided).toBe(1);
|
|
303
|
-
expect(pool.summary.undecided).toBe(0);
|
|
304
|
-
expect(pool.constraints[0].status).toBe("decided");
|
|
305
|
-
expect(pool.constraints[0].decision).toBe("inject");
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
// ─── Pipeline: verdict-log clarify_resolved ───
|
|
309
|
-
describe("event-pipeline — verdict-log clarify_resolved", () => {
|
|
310
|
-
beforeEach(setup);
|
|
311
|
-
afterEach(teardown);
|
|
312
|
-
it("verdict-log includes clarify_resolved entries", () => {
|
|
313
|
-
appendScopeEvent(paths, input("scope.created", { title: "T", description: "d", entry_mode: "experience" }, "user"));
|
|
314
|
-
appendScopeEvent(paths, input("grounding.completed", { snapshot_revision: 1, source_hashes: {}, perspective_summary: { experience: 0, code: 0, policy: 0 } }));
|
|
315
|
-
appendScopeEvent(paths, input("align.proposed", { packet_path: "p", packet_hash: "h", snapshot_revision: 1 }));
|
|
316
|
-
appendScopeEvent(paths, input("align.locked", { locked_direction: "dir", locked_scope_boundaries: { in: [], out: [] }, locked_in_out: true }, "user"));
|
|
317
|
-
appendScopeEvent(paths, input("surface.generated", { surface_type: "experience", surface_path: "s", content_hash: "h", based_on_snapshot: 1 }));
|
|
318
|
-
appendScopeEvent(paths, input("surface.confirmed", { final_surface_path: "s", final_content_hash: "h", total_revisions: 0 }, "user"));
|
|
319
|
-
appendScopeEvent(paths, input("constraint.discovered", {
|
|
320
|
-
constraint_id: "CST-001", perspective: "code", summary: "test",
|
|
321
|
-
severity: "required", discovery_stage: "draft_phase2",
|
|
322
|
-
decision_owner: "product_owner", impact_if_ignored: "bad", source_refs: [],
|
|
323
|
-
}));
|
|
324
|
-
appendScopeEvent(paths, input("constraint.clarify_requested", {
|
|
325
|
-
constraint_id: "CST-001", question: "clarify this?", asked_to: "team",
|
|
326
|
-
}, "agent"));
|
|
327
|
-
appendScopeEvent(paths, input("constraint.clarify_resolved", {
|
|
328
|
-
constraint_id: "CST-001", resolution: "resolved", decision: "inject",
|
|
329
|
-
selected_option: "opt", decision_owner: "product_owner", rationale: "clear now",
|
|
330
|
-
}, "user"));
|
|
331
|
-
const log = JSON.parse(readFileSync(paths.verdictLog, "utf-8"));
|
|
332
|
-
const clarifyEntries = log.filter(e => e.type === "constraint.clarify_resolved");
|
|
333
|
-
expect(clarifyEntries.length).toBeGreaterThanOrEqual(1);
|
|
334
|
-
expect(clarifyEntries[0].type).toBe("constraint.clarify_resolved");
|
|
335
|
-
});
|
|
336
|
-
});
|
|
337
|
-
// ─── Pipeline: golden data replay ───
|
|
338
|
-
describe("event-pipeline — golden data replay", () => {
|
|
339
|
-
beforeEach(setup);
|
|
340
|
-
afterEach(teardown);
|
|
341
|
-
const GOLDEN_DIR = resolve(import.meta.dirname, "__fixtures__/example-tutor-block");
|
|
342
|
-
const GOLDEN_EVENTS_PATH = resolve(GOLDEN_DIR, "events.ndjson");
|
|
343
|
-
const GOLDEN_POOL_PATH = resolve(GOLDEN_DIR, "state/constraint-pool.json");
|
|
344
|
-
const GOLDEN_VERDICT_PATH = resolve(GOLDEN_DIR, "state/verdict-log.json");
|
|
345
|
-
it("replays all 29 golden events and produces matching materialized views", () => {
|
|
346
|
-
const goldenEvents = readFileSync(GOLDEN_EVENTS_PATH, "utf-8")
|
|
347
|
-
.trimEnd()
|
|
348
|
-
.split("\n")
|
|
349
|
-
.map((line) => JSON.parse(line));
|
|
350
|
-
// Replay: extract type/actor/payload from golden events
|
|
351
|
-
for (const evt of goldenEvents) {
|
|
352
|
-
const result = appendScopeEvent(paths, {
|
|
353
|
-
type: evt.type,
|
|
354
|
-
actor: evt.actor,
|
|
355
|
-
payload: evt.payload,
|
|
356
|
-
});
|
|
357
|
-
expect(result.success, `Event ${evt.event_id} (${evt.type}) failed: ${!result.success ? result.reason : ""}`).toBe(true);
|
|
358
|
-
}
|
|
359
|
-
// Verify events count
|
|
360
|
-
const replayedEvents = readEvents(paths.events);
|
|
361
|
-
expect(replayedEvents).toHaveLength(29);
|
|
362
|
-
// Verify constraint-pool.json matches golden
|
|
363
|
-
const expectedPool = JSON.parse(readFileSync(GOLDEN_POOL_PATH, "utf-8"));
|
|
364
|
-
const actualPool = JSON.parse(readFileSync(paths.constraintPool, "utf-8"));
|
|
365
|
-
expect(actualPool.summary).toEqual(expectedPool.summary);
|
|
366
|
-
expect(actualPool.constraints).toEqual(expectedPool.constraints);
|
|
367
|
-
// Verify verdict-log.json matches golden (structure, not timestamps)
|
|
368
|
-
const expectedLog = JSON.parse(readFileSync(GOLDEN_VERDICT_PATH, "utf-8"));
|
|
369
|
-
const actualLog = JSON.parse(readFileSync(paths.verdictLog, "utf-8"));
|
|
370
|
-
expect(actualLog).toHaveLength(expectedLog.length);
|
|
371
|
-
for (let i = 0; i < expectedLog.length; i++) {
|
|
372
|
-
// Compare structure but not ts (generated at replay time)
|
|
373
|
-
const { ts: _ets, ...expectedEntry } = expectedLog[i];
|
|
374
|
-
const { ts: _ats, ...actualEntry } = actualLog[i];
|
|
375
|
-
expect(actualEntry).toEqual(expectedEntry);
|
|
376
|
-
}
|
|
377
|
-
// Verify final state
|
|
378
|
-
const finalState = reduce(replayedEvents);
|
|
379
|
-
expect(finalState.current_state).toBe("compiled");
|
|
380
|
-
expect(finalState.latest_revision).toBe(29);
|
|
381
|
-
});
|
|
382
|
-
});
|
|
383
|
-
// ─── Pipeline: structured rejection (PR-9) ───
|
|
384
|
-
describe("event-pipeline — structured rejection fields", () => {
|
|
385
|
-
beforeEach(setup);
|
|
386
|
-
afterEach(teardown);
|
|
387
|
-
it("rejection includes current_state and rejected_type for invalid transition", () => {
|
|
388
|
-
// Set up: create scope in draft state
|
|
389
|
-
appendScopeEvent(paths, input("scope.created", {
|
|
390
|
-
title: "T", description: "d", entry_mode: "experience",
|
|
391
|
-
}, "user"));
|
|
392
|
-
// draft does not allow align.locked
|
|
393
|
-
const result = appendScopeEvent(paths, input("align.locked", {
|
|
394
|
-
locked_direction: "dir", locked_scope_boundaries: { in: [], out: [] }, locked_in_out: true,
|
|
395
|
-
}, "user"));
|
|
396
|
-
expect(result.success).toBe(false);
|
|
397
|
-
if (!result.success) {
|
|
398
|
-
expect(result.current_state).toBe("draft");
|
|
399
|
-
expect(result.rejected_type).toBe("align.locked");
|
|
400
|
-
expect(result.reason).toContain("Transition denied");
|
|
401
|
-
}
|
|
402
|
-
});
|
|
403
|
-
it("compile.started rejection after retry limit includes structured fields", () => {
|
|
404
|
-
// Build up to target_locked state with golden events
|
|
405
|
-
appendScopeEvent(paths, input("scope.created", { title: "T", description: "d", entry_mode: "experience" }, "user"));
|
|
406
|
-
appendScopeEvent(paths, input("grounding.started", { sources: [] }));
|
|
407
|
-
appendScopeEvent(paths, input("grounding.completed", { snapshot_revision: 1, source_hashes: {}, perspective_summary: { experience: 0, code: 0, policy: 0 } }));
|
|
408
|
-
appendScopeEvent(paths, input("align.proposed", { packet_path: "p", packet_hash: "h", snapshot_revision: 1 }));
|
|
409
|
-
appendScopeEvent(paths, input("align.locked", { locked_direction: "dir", locked_scope_boundaries: { in: [], out: [] }, locked_in_out: true }, "user"));
|
|
410
|
-
appendScopeEvent(paths, input("surface.generated", { surface_type: "experience", surface_path: "s", content_hash: "h", based_on_snapshot: 1 }));
|
|
411
|
-
appendScopeEvent(paths, input("surface.confirmed", { final_surface_path: "s", final_content_hash: "h", total_revisions: 0 }, "user"));
|
|
412
|
-
// Add a constraint + decide it so we can lock target
|
|
413
|
-
appendScopeEvent(paths, input("constraint.discovered", {
|
|
414
|
-
constraint_id: "CST-001", perspective: "code", summary: "test",
|
|
415
|
-
severity: "required", discovery_stage: "draft_phase2",
|
|
416
|
-
decision_owner: "builder", impact_if_ignored: "bad", source_refs: [],
|
|
417
|
-
}));
|
|
418
|
-
appendScopeEvent(paths, input("constraint.decision_recorded", {
|
|
419
|
-
constraint_id: "CST-001", decision: "inject", selected_option: "opt",
|
|
420
|
-
decision_owner: "builder", rationale: "needed",
|
|
421
|
-
}, "agent"));
|
|
422
|
-
// Lock target
|
|
423
|
-
appendScopeEvent(paths, input("target.locked", {
|
|
424
|
-
surface_hash: "h",
|
|
425
|
-
constraint_decisions: [{ constraint_id: "CST-001", decision: "inject" }],
|
|
426
|
-
}));
|
|
427
|
-
// Simulate 3 compile gap_found cycles to hit retry limit
|
|
428
|
-
// Each cycle: compile.started → compile.constraint_gap_found (→ constraints_resolved)
|
|
429
|
-
// then re-lock target to get back to target_locked
|
|
430
|
-
for (let i = 0; i < 3; i++) {
|
|
431
|
-
appendScopeEvent(paths, input("compile.started", { snapshot_revision: 1, surface_hash: "h" }));
|
|
432
|
-
appendScopeEvent(paths, input("compile.constraint_gap_found", {
|
|
433
|
-
new_constraint_id: `CST-GAP-${i}`, perspective: "code", summary: "gap",
|
|
434
|
-
}));
|
|
435
|
-
// gap_found transitions to constraints_resolved; re-lock to get back to target_locked
|
|
436
|
-
appendScopeEvent(paths, input("target.locked", {
|
|
437
|
-
surface_hash: "h",
|
|
438
|
-
constraint_decisions: [{ constraint_id: "CST-001", decision: "inject" }],
|
|
439
|
-
}));
|
|
440
|
-
}
|
|
441
|
-
// 4th compile.started should be rejected (retry_count_compile === 3)
|
|
442
|
-
const result = appendScopeEvent(paths, input("compile.started", { snapshot_revision: 1, surface_hash: "h" }));
|
|
443
|
-
expect(result.success).toBe(false);
|
|
444
|
-
if (!result.success) {
|
|
445
|
-
expect(result.current_state).toBe("target_locked");
|
|
446
|
-
expect(result.rejected_type).toBe("compile.started");
|
|
447
|
-
expect(result.reason).toContain("Compile retry limit");
|
|
448
|
-
}
|
|
449
|
-
});
|
|
450
|
-
});
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { readFileSync, appendFileSync, existsSync, mkdirSync } from "node:fs";
|
|
2
|
-
import { dirname } from "node:path";
|
|
3
|
-
/**
|
|
4
|
-
* Read all events from an ndjson file.
|
|
5
|
-
* Returns an empty array if the file does not exist.
|
|
6
|
-
*/
|
|
7
|
-
export function readEvents(filePath) {
|
|
8
|
-
if (!existsSync(filePath)) {
|
|
9
|
-
return [];
|
|
10
|
-
}
|
|
11
|
-
const content = readFileSync(filePath, "utf-8").trimEnd();
|
|
12
|
-
if (content === "") {
|
|
13
|
-
return [];
|
|
14
|
-
}
|
|
15
|
-
return content.split("\n").map((line) => JSON.parse(line));
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Append a single event to the ndjson file.
|
|
19
|
-
* Creates the file and parent directories if they don't exist.
|
|
20
|
-
* Returns the event with revision set.
|
|
21
|
-
*/
|
|
22
|
-
export function appendEvent(filePath, event) {
|
|
23
|
-
const dir = dirname(filePath);
|
|
24
|
-
if (!existsSync(dir)) {
|
|
25
|
-
mkdirSync(dir, { recursive: true });
|
|
26
|
-
}
|
|
27
|
-
appendFileSync(filePath, JSON.stringify(event) + "\n", "utf-8");
|
|
28
|
-
return event;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Get the next revision number for a scope's event file.
|
|
32
|
-
* Returns 1 if the file is empty or doesn't exist.
|
|
33
|
-
*/
|
|
34
|
-
export function nextRevision(filePath) {
|
|
35
|
-
const events = readEvents(filePath);
|
|
36
|
-
if (events.length === 0)
|
|
37
|
-
return 1;
|
|
38
|
-
return events[events.length - 1].revision + 1;
|
|
39
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
2
|
-
import { mkdtempSync, rmSync, readFileSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import { readEvents, appendEvent, nextRevision } from "./event-store.js";
|
|
6
|
-
function makeEvent(revision, overrides) {
|
|
7
|
-
return {
|
|
8
|
-
event_id: `evt_${revision}`,
|
|
9
|
-
scope_id: "SC-TEST-001",
|
|
10
|
-
type: "scope.created",
|
|
11
|
-
ts: new Date().toISOString(),
|
|
12
|
-
revision,
|
|
13
|
-
actor: "user",
|
|
14
|
-
state_before: null,
|
|
15
|
-
state_after: "draft",
|
|
16
|
-
payload: {
|
|
17
|
-
title: "test",
|
|
18
|
-
description: "test scope",
|
|
19
|
-
entry_mode: "experience",
|
|
20
|
-
},
|
|
21
|
-
...overrides,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
describe("event-store", () => {
|
|
25
|
-
let tmpDir;
|
|
26
|
-
let filePath;
|
|
27
|
-
beforeEach(() => {
|
|
28
|
-
tmpDir = mkdtempSync(join(tmpdir(), "sprint-kit-test-"));
|
|
29
|
-
filePath = join(tmpDir, "events.ndjson");
|
|
30
|
-
});
|
|
31
|
-
afterEach(() => {
|
|
32
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
33
|
-
});
|
|
34
|
-
describe("readEvents", () => {
|
|
35
|
-
it("returns empty array for non-existent file", () => {
|
|
36
|
-
expect(readEvents(filePath)).toEqual([]);
|
|
37
|
-
});
|
|
38
|
-
it("reads golden data successfully", () => {
|
|
39
|
-
const goldenPath = join(import.meta.dirname, "__fixtures__/example-tutor-block/events.ndjson");
|
|
40
|
-
const events = readEvents(goldenPath);
|
|
41
|
-
expect(events).toHaveLength(29);
|
|
42
|
-
expect(events[0].type).toBe("scope.created");
|
|
43
|
-
expect(events[28].type).toBe("compile.completed");
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
describe("appendEvent", () => {
|
|
47
|
-
it("creates file and writes event", () => {
|
|
48
|
-
const evt = makeEvent(1);
|
|
49
|
-
appendEvent(filePath, evt);
|
|
50
|
-
const content = readFileSync(filePath, "utf-8");
|
|
51
|
-
const parsed = JSON.parse(content.trimEnd());
|
|
52
|
-
expect(parsed.event_id).toBe("evt_1");
|
|
53
|
-
});
|
|
54
|
-
it("appends multiple events", () => {
|
|
55
|
-
appendEvent(filePath, makeEvent(1));
|
|
56
|
-
appendEvent(filePath, makeEvent(2, {
|
|
57
|
-
event_id: "evt_2",
|
|
58
|
-
type: "grounding.started",
|
|
59
|
-
state_before: "draft",
|
|
60
|
-
state_after: "draft",
|
|
61
|
-
payload: {
|
|
62
|
-
sources: [{ type: "add-dir", path_or_url: "/test" }],
|
|
63
|
-
},
|
|
64
|
-
}));
|
|
65
|
-
const events = readEvents(filePath);
|
|
66
|
-
expect(events).toHaveLength(2);
|
|
67
|
-
expect(events[0].revision).toBe(1);
|
|
68
|
-
expect(events[1].revision).toBe(2);
|
|
69
|
-
});
|
|
70
|
-
it("creates parent directories if needed", () => {
|
|
71
|
-
const nestedPath = join(tmpDir, "deep", "nested", "events.ndjson");
|
|
72
|
-
appendEvent(nestedPath, makeEvent(1));
|
|
73
|
-
const events = readEvents(nestedPath);
|
|
74
|
-
expect(events).toHaveLength(1);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
describe("nextRevision", () => {
|
|
78
|
-
it("returns 1 for non-existent file", () => {
|
|
79
|
-
expect(nextRevision(filePath)).toBe(1);
|
|
80
|
-
});
|
|
81
|
-
it("returns next number after last event", () => {
|
|
82
|
-
appendEvent(filePath, makeEvent(1));
|
|
83
|
-
appendEvent(filePath, makeEvent(2, {
|
|
84
|
-
event_id: "evt_2",
|
|
85
|
-
type: "grounding.started",
|
|
86
|
-
state_before: "draft",
|
|
87
|
-
state_after: "draft",
|
|
88
|
-
payload: {
|
|
89
|
-
sources: [{ type: "add-dir", path_or_url: "/test" }],
|
|
90
|
-
},
|
|
91
|
-
}));
|
|
92
|
-
expect(nextRevision(filePath)).toBe(3);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
});
|