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,915 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { compileDefense, } from "./compile-defense.js";
|
|
3
|
-
// ─── Helpers ───
|
|
4
|
-
function makeEntry(id, overrides = {}) {
|
|
5
|
-
return {
|
|
6
|
-
constraint_id: id, perspective: "code", summary: `summary ${id}`,
|
|
7
|
-
severity: "recommended", discovery_stage: "draft_phase2", decision_owner: "product_owner",
|
|
8
|
-
impact_if_ignored: `impact ${id}`, source_refs: [{ source: "src/test.ts", detail: "d" }],
|
|
9
|
-
evidence_status: "unverified",
|
|
10
|
-
status: "decided", decision: "inject", selected_option: "opt", discovered_at: 1, decided_at: 2,
|
|
11
|
-
...overrides,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
function makePool(...entries) {
|
|
15
|
-
let req = 0, rec = 0, dec = 0, inv = 0;
|
|
16
|
-
for (const e of entries) {
|
|
17
|
-
if (e.severity === "required")
|
|
18
|
-
req++;
|
|
19
|
-
else
|
|
20
|
-
rec++;
|
|
21
|
-
if (e.status === "decided")
|
|
22
|
-
dec++;
|
|
23
|
-
if (e.status === "invalidated")
|
|
24
|
-
inv++;
|
|
25
|
-
}
|
|
26
|
-
return { constraints: entries, summary: { total: entries.length, required: req, recommended: rec, decided: dec, clarify_pending: 0, invalidated: inv, undecided: 0 } };
|
|
27
|
-
}
|
|
28
|
-
function makeState(pool) {
|
|
29
|
-
return {
|
|
30
|
-
scope_id: "SC-TEST", title: "T", description: "d", entry_mode: "experience",
|
|
31
|
-
current_state: "target_locked", constraint_pool: pool,
|
|
32
|
-
stale: false, compile_ready: true, convergence_blocked: false,
|
|
33
|
-
revision_count_align: 0, revision_count_surface: 0, retry_count_compile: 0,
|
|
34
|
-
snapshot_revision: 0, pre_apply_completed: false, prd_review_completed: false,
|
|
35
|
-
verdict_log: [], feedback_history: [], latest_revision: 0,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function makeBuildSpec(section3, section4) {
|
|
39
|
-
return { section3, section4 };
|
|
40
|
-
}
|
|
41
|
-
function makeDeltaSet(changes) {
|
|
42
|
-
return { scope_id: "SC-TEST", surface_hash: "h", build_spec_hash: "h", changes };
|
|
43
|
-
}
|
|
44
|
-
// ─── Layer 1: Checklist ───
|
|
45
|
-
describe("compile-defense — Layer 1 Checklist", () => {
|
|
46
|
-
it("passes when all non-invalidated constraints are in Section 3", () => {
|
|
47
|
-
const pool = makePool(makeEntry("CST-001"), makeEntry("CST-002"), makeEntry("CST-003", { status: "invalidated", decision: undefined }));
|
|
48
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }, { constraint_id: "CST-002", decision: "inject" }], [{ impl_id: "IMPL-001", related_cst: ["CST-001"] }, { impl_id: "IMPL-002", related_cst: ["CST-002"] }]);
|
|
49
|
-
const ds = makeDeltaSet([
|
|
50
|
-
{ change_id: "CHG-001", action: "create", file_path: "a.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
51
|
-
{ change_id: "CHG-002", action: "create", file_path: "b.ts", description: "d", related_impl: ["IMPL-002"], related_cst: ["CST-002"] },
|
|
52
|
-
]);
|
|
53
|
-
const vp = [
|
|
54
|
-
{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject", target: "t", method: "m", pass_criteria: "p", fail_action: "f", edge_cases: [{ scenario: "null", expected_result: "error" }] },
|
|
55
|
-
{ val_id: "VAL-002", related_cst: "CST-002", decision_type: "inject", target: "t", method: "m", pass_criteria: "p", fail_action: "f", edge_cases: [{ scenario: "null", expected_result: "error" }] },
|
|
56
|
-
];
|
|
57
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
58
|
-
expect(result.passed).toBe(true);
|
|
59
|
-
});
|
|
60
|
-
it("fails when a constraint is missing from Section 3", () => {
|
|
61
|
-
const pool = makePool(makeEntry("CST-001"), makeEntry("CST-002"));
|
|
62
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }], // CST-002 missing
|
|
63
|
-
[{ impl_id: "IMPL-001", related_cst: ["CST-001"] }]);
|
|
64
|
-
const ds = makeDeltaSet([
|
|
65
|
-
{ change_id: "CHG-001", action: "create", file_path: "a.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
66
|
-
]);
|
|
67
|
-
const vp = [{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject" }];
|
|
68
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
69
|
-
expect(result.passed).toBe(false);
|
|
70
|
-
if (!result.passed) {
|
|
71
|
-
expect(result.violations.some((v) => v.rule === "L1-checklist" && v.detail.includes("CST-002"))).toBe(true);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
it("ignores invalidated constraints", () => {
|
|
75
|
-
const pool = makePool(makeEntry("CST-001"), makeEntry("CST-002", { status: "invalidated", decision: undefined }));
|
|
76
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }], [{ impl_id: "IMPL-001", related_cst: ["CST-001"] }]);
|
|
77
|
-
const ds = makeDeltaSet([
|
|
78
|
-
{ change_id: "CHG-001", action: "create", file_path: "a.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
79
|
-
]);
|
|
80
|
-
const vp = [{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject", target: "t", method: "m", pass_criteria: "p", fail_action: "f", edge_cases: [{ scenario: "null", expected_result: "error" }] }];
|
|
81
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
82
|
-
expect(result.passed).toBe(true);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
// ─── Layer 2: inject ───
|
|
86
|
-
describe("compile-defense — Layer 2 inject", () => {
|
|
87
|
-
it("fails when inject has no IMPL", () => {
|
|
88
|
-
const pool = makePool(makeEntry("CST-001"));
|
|
89
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }], []);
|
|
90
|
-
const ds = makeDeltaSet([]);
|
|
91
|
-
const vp = [];
|
|
92
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
93
|
-
expect(result.passed).toBe(false);
|
|
94
|
-
if (!result.passed) {
|
|
95
|
-
expect(result.violations.some((v) => v.rule === "L2-inject-impl")).toBe(true);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
it("fails when inject has no CHG", () => {
|
|
99
|
-
const pool = makePool(makeEntry("CST-001"));
|
|
100
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }], [{ impl_id: "IMPL-001", related_cst: ["CST-001"] }]);
|
|
101
|
-
const ds = makeDeltaSet([
|
|
102
|
-
{ change_id: "CHG-001", action: "create", file_path: "a.ts", description: "d", related_impl: ["IMPL-001"], related_cst: [] }, // no CST-001
|
|
103
|
-
]);
|
|
104
|
-
const vp = [{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject" }];
|
|
105
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
106
|
-
expect(result.passed).toBe(false);
|
|
107
|
-
if (!result.passed) {
|
|
108
|
-
expect(result.violations.some((v) => v.rule === "L2-inject-chg")).toBe(true);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
it("fails when inject has no VAL", () => {
|
|
112
|
-
const pool = makePool(makeEntry("CST-001"));
|
|
113
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }], [{ impl_id: "IMPL-001", related_cst: ["CST-001"] }]);
|
|
114
|
-
const ds = makeDeltaSet([
|
|
115
|
-
{ change_id: "CHG-001", action: "create", file_path: "a.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
116
|
-
]);
|
|
117
|
-
const vp = []; // no VAL
|
|
118
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
119
|
-
expect(result.passed).toBe(false);
|
|
120
|
-
if (!result.passed) {
|
|
121
|
-
expect(result.violations.some((v) => v.rule === "L2-inject-val")).toBe(true);
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
// ─── Layer 2: defer ───
|
|
126
|
-
describe("compile-defense — Layer 2 defer", () => {
|
|
127
|
-
it("passes when defer source_refs not in delta-set", () => {
|
|
128
|
-
const pool = makePool(makeEntry("CST-001", {
|
|
129
|
-
decision: "defer",
|
|
130
|
-
source_refs: [{ source: "src/untouched.ts", detail: "d" }],
|
|
131
|
-
}));
|
|
132
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "defer" }], []);
|
|
133
|
-
const ds = makeDeltaSet([
|
|
134
|
-
{ change_id: "CHG-001", action: "modify", file_path: "src/other.ts", description: "d", related_impl: [], related_cst: [] },
|
|
135
|
-
]);
|
|
136
|
-
const vp = [{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "defer" }];
|
|
137
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
138
|
-
expect(result.passed).toBe(true);
|
|
139
|
-
});
|
|
140
|
-
it("fails when defer source_refs file is modified", () => {
|
|
141
|
-
const pool = makePool(makeEntry("CST-001", {
|
|
142
|
-
decision: "defer",
|
|
143
|
-
source_refs: [{ source: "src/modified.ts", detail: "d" }],
|
|
144
|
-
}));
|
|
145
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "defer" }], []);
|
|
146
|
-
const ds = makeDeltaSet([
|
|
147
|
-
{ change_id: "CHG-001", action: "modify", file_path: "src/modified.ts", description: "d", related_impl: [], related_cst: [] },
|
|
148
|
-
]);
|
|
149
|
-
const vp = [{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "defer" }];
|
|
150
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
151
|
-
expect(result.passed).toBe(false);
|
|
152
|
-
if (!result.passed) {
|
|
153
|
-
expect(result.violations.some((v) => v.rule === "L2-defer-interfere")).toBe(true);
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
it("fails when defer source_ref matches one of multiple CHGs with same file_path", () => {
|
|
157
|
-
const pool = makePool(makeEntry("CST-001", {
|
|
158
|
-
decision: "defer",
|
|
159
|
-
source_refs: [{ source: "src/shared.ts", detail: "d" }],
|
|
160
|
-
}));
|
|
161
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "defer" }], []);
|
|
162
|
-
const ds = makeDeltaSet([
|
|
163
|
-
{ change_id: "CHG-001", action: "modify", file_path: "src/other.ts", description: "d", related_impl: [], related_cst: [] },
|
|
164
|
-
{ change_id: "CHG-002", action: "modify", file_path: "src/shared.ts", description: "d", related_impl: [], related_cst: [] },
|
|
165
|
-
]);
|
|
166
|
-
const vp = [{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "defer" }];
|
|
167
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
168
|
-
expect(result.passed).toBe(false);
|
|
169
|
-
if (!result.passed) {
|
|
170
|
-
expect(result.violations.some((v) => v.rule === "L2-defer-interfere" && v.detail.includes("src/shared.ts"))).toBe(true);
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
// ─── Layer 2: override ───
|
|
175
|
-
describe("compile-defense — Layer 2 override", () => {
|
|
176
|
-
it("passes when override is not reflected", () => {
|
|
177
|
-
const pool = makePool(makeEntry("CST-001", {
|
|
178
|
-
decision: "override",
|
|
179
|
-
source_refs: [{ source: "src/policy.ts", detail: "d" }],
|
|
180
|
-
}));
|
|
181
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "override" }], []);
|
|
182
|
-
const ds = makeDeltaSet([]); // no changes
|
|
183
|
-
const vp = [{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "override" }];
|
|
184
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
185
|
-
expect(result.passed).toBe(true);
|
|
186
|
-
});
|
|
187
|
-
it("fails when override is reflected in delta-set", () => {
|
|
188
|
-
const pool = makePool(makeEntry("CST-001", {
|
|
189
|
-
decision: "override",
|
|
190
|
-
source_refs: [{ source: "src/policy.ts", detail: "d" }],
|
|
191
|
-
}));
|
|
192
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "override" }], []);
|
|
193
|
-
const ds = makeDeltaSet([
|
|
194
|
-
{ change_id: "CHG-001", action: "modify", file_path: "src/policy.ts", description: "d", related_impl: [], related_cst: ["CST-001"] },
|
|
195
|
-
]);
|
|
196
|
-
const vp = [{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "override" }];
|
|
197
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
198
|
-
expect(result.passed).toBe(false);
|
|
199
|
-
if (!result.passed) {
|
|
200
|
-
expect(result.violations.some((v) => v.rule === "L2-override-reflected")).toBe(true);
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
// ─── Layer 2: traceability ───
|
|
205
|
-
describe("compile-defense — Layer 2 traceability", () => {
|
|
206
|
-
it("fails when IMPL has no CHG", () => {
|
|
207
|
-
const pool = makePool(makeEntry("CST-001"));
|
|
208
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }], [{ impl_id: "IMPL-001", related_cst: ["CST-001"] }]);
|
|
209
|
-
const ds = makeDeltaSet([]); // no changes for IMPL-001
|
|
210
|
-
const vp = [{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject" }];
|
|
211
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
212
|
-
expect(result.passed).toBe(false);
|
|
213
|
-
if (!result.passed) {
|
|
214
|
-
expect(result.violations.some((v) => v.rule === "L2-impl-no-chg")).toBe(true);
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
// ─── Layer 2: unexpected decision ───
|
|
219
|
-
describe("compile-defense — Layer 2 unexpected decision", () => {
|
|
220
|
-
it("fails when decision is clarify", () => {
|
|
221
|
-
const pool = makePool(makeEntry("CST-001", { decision: "clarify" }));
|
|
222
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "clarify" }], []);
|
|
223
|
-
const ds = makeDeltaSet([]);
|
|
224
|
-
const vp = [];
|
|
225
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
226
|
-
expect(result.passed).toBe(false);
|
|
227
|
-
if (!result.passed) {
|
|
228
|
-
expect(result.violations.some((v) => v.rule === "L2-decision-unexpected" && v.detail.includes("clarify"))).toBe(true);
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
it("fails when decision is modify-direction", () => {
|
|
232
|
-
const pool = makePool(makeEntry("CST-001", { decision: "modify-direction" }));
|
|
233
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "modify-direction" }], []);
|
|
234
|
-
const ds = makeDeltaSet([]);
|
|
235
|
-
const vp = [];
|
|
236
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
237
|
-
expect(result.passed).toBe(false);
|
|
238
|
-
if (!result.passed) {
|
|
239
|
-
expect(result.violations.some((v) => v.rule === "L2-decision-unexpected" && v.detail.includes("modify-direction"))).toBe(true);
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
// ─── Layer 2: CHG→IMPL reverse traceability ───
|
|
244
|
-
describe("compile-defense — Layer 2 CHG→IMPL reverse", () => {
|
|
245
|
-
it("fails when CHG references non-existent IMPL", () => {
|
|
246
|
-
const pool = makePool(makeEntry("CST-001"));
|
|
247
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }], [{ impl_id: "IMPL-001", related_cst: ["CST-001"] }]);
|
|
248
|
-
const ds = makeDeltaSet([
|
|
249
|
-
{ change_id: "CHG-001", action: "create", file_path: "a.ts", description: "d", related_impl: ["IMPL-999"], related_cst: ["CST-001"] },
|
|
250
|
-
]);
|
|
251
|
-
const vp = [{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject" }];
|
|
252
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
253
|
-
expect(result.passed).toBe(false);
|
|
254
|
-
if (!result.passed) {
|
|
255
|
-
expect(result.violations.some((v) => v.rule === "L2-chg-orphan-impl" && v.detail.includes("IMPL-999"))).toBe(true);
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
it("allows CHG with empty related_impl (defer/override context)", () => {
|
|
259
|
-
const pool = makePool(makeEntry("CST-001", {
|
|
260
|
-
decision: "defer",
|
|
261
|
-
source_refs: [{ source: "src/untouched.ts", detail: "d" }],
|
|
262
|
-
}));
|
|
263
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "defer" }], []);
|
|
264
|
-
const ds = makeDeltaSet([
|
|
265
|
-
{ change_id: "CHG-001", action: "modify", file_path: "src/other.ts", description: "d", related_impl: [], related_cst: [] },
|
|
266
|
-
]);
|
|
267
|
-
const vp = [{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "defer" }];
|
|
268
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
269
|
-
expect(result.passed).toBe(true);
|
|
270
|
-
});
|
|
271
|
-
it("passes when all CHG.related_impl reference valid IMPLs", () => {
|
|
272
|
-
const pool = makePool(makeEntry("CST-001"));
|
|
273
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }], [{ impl_id: "IMPL-001", related_cst: ["CST-001"] }]);
|
|
274
|
-
const ds = makeDeltaSet([
|
|
275
|
-
{ change_id: "CHG-001", action: "create", file_path: "a.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
276
|
-
]);
|
|
277
|
-
const vp = [{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject", target: "t", method: "m", pass_criteria: "p", fail_action: "f", edge_cases: [{ scenario: "null", expected_result: "error" }] }];
|
|
278
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
279
|
-
expect(result.passed).toBe(true);
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
// ─── Golden data ───
|
|
283
|
-
describe("compile-defense — golden data", () => {
|
|
284
|
-
it("passes for golden example constraints", async () => {
|
|
285
|
-
const { readFileSync } = await import("node:fs");
|
|
286
|
-
const { resolve } = await import("node:path");
|
|
287
|
-
const { reduce } = await import("../../../../scope-runtime/reducer.js");
|
|
288
|
-
const GOLDEN_DIR = resolve(import.meta.dirname, "../../../../scope-runtime/__fixtures__/example-tutor-block");
|
|
289
|
-
const GOLDEN_EVENTS_PATH = resolve(GOLDEN_DIR, "events.ndjson");
|
|
290
|
-
const GOLDEN_DELTA_SET_PATH = resolve(GOLDEN_DIR, "build/delta-set.json");
|
|
291
|
-
const events = readFileSync(GOLDEN_EVENTS_PATH, "utf-8").trimEnd().split("\n").map((l) => JSON.parse(l));
|
|
292
|
-
const state = reduce(events);
|
|
293
|
-
const deltaSet = JSON.parse(readFileSync(GOLDEN_DELTA_SET_PATH, "utf-8"));
|
|
294
|
-
// Build Section 3 from pool (auto-generated)
|
|
295
|
-
const section3 = state.constraint_pool.constraints
|
|
296
|
-
.filter((c) => c.status !== "invalidated")
|
|
297
|
-
.map((c) => ({ constraint_id: c.constraint_id, decision: c.decision }));
|
|
298
|
-
// Build Section 4 from delta-set (reverse-engineer IMPL→CST mapping)
|
|
299
|
-
const implMap = new Map();
|
|
300
|
-
for (const chg of deltaSet.changes) {
|
|
301
|
-
for (const implId of chg.related_impl) {
|
|
302
|
-
if (!implMap.has(implId))
|
|
303
|
-
implMap.set(implId, []);
|
|
304
|
-
for (const cst of chg.related_cst) {
|
|
305
|
-
if (!implMap.get(implId).includes(cst))
|
|
306
|
-
implMap.get(implId).push(cst);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
const section4 = Array.from(implMap.entries()).map(([impl_id, related_cst]) => ({ impl_id, related_cst }));
|
|
311
|
-
const buildSpec = makeBuildSpec(section3, section4);
|
|
312
|
-
// Build validation plan from golden validation-plan.md (simplified: 1 VAL per CST)
|
|
313
|
-
const valPlan = state.constraint_pool.constraints
|
|
314
|
-
.filter((c) => c.status !== "invalidated" && c.decision)
|
|
315
|
-
.map((c, i) => ({
|
|
316
|
-
val_id: `VAL-${String(i + 1).padStart(3, "0")}`,
|
|
317
|
-
related_cst: c.constraint_id,
|
|
318
|
-
decision_type: c.decision === "defer" ? "defer" : "inject",
|
|
319
|
-
target: `${c.summary} 검증`,
|
|
320
|
-
method: `${c.summary} 구현 확인`,
|
|
321
|
-
pass_criteria: `${c.constraint_id} 관련 동작 확인`,
|
|
322
|
-
fail_action: "구현 오류",
|
|
323
|
-
...(c.decision !== "defer" ? { edge_cases: [{ scenario: `${c.constraint_id} 빈 입력`, expected_result: "에러 반환" }] } : {}),
|
|
324
|
-
}));
|
|
325
|
-
const result = compileDefense(state, buildSpec, deltaSet, valPlan);
|
|
326
|
-
expect(result.passed).toBe(true);
|
|
327
|
-
});
|
|
328
|
-
});
|
|
329
|
-
// ─── Layer 2: inject edge_cases (TCOV-3) ───
|
|
330
|
-
describe("compile-defense — L2-inject-edge-case", () => {
|
|
331
|
-
it("fails when inject item has edge_cases: [] (empty array)", () => {
|
|
332
|
-
const pool = makePool(makeEntry("CST-001", { decision: "inject" }));
|
|
333
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }], [{ impl_id: "IMPL-001", related_cst: ["CST-001"] }]);
|
|
334
|
-
const ds = makeDeltaSet([
|
|
335
|
-
{ change_id: "CHG-001", action: "create", file_path: "a.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
336
|
-
]);
|
|
337
|
-
const vp = [
|
|
338
|
-
{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject", target: "t", method: "m", pass_criteria: "p", fail_action: "f", edge_cases: [] },
|
|
339
|
-
];
|
|
340
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
341
|
-
expect(result.passed).toBe(false);
|
|
342
|
-
if (!result.passed) {
|
|
343
|
-
expect(result.violations.some((v) => v.rule === "L2-inject-edge-case" && v.detail.includes("CST-001"))).toBe(true);
|
|
344
|
-
}
|
|
345
|
-
});
|
|
346
|
-
it("fails when inject item has edge_cases: undefined (omitted)", () => {
|
|
347
|
-
const pool = makePool(makeEntry("CST-001", { decision: "inject" }));
|
|
348
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }], [{ impl_id: "IMPL-001", related_cst: ["CST-001"] }]);
|
|
349
|
-
const ds = makeDeltaSet([
|
|
350
|
-
{ change_id: "CHG-001", action: "create", file_path: "a.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
351
|
-
]);
|
|
352
|
-
const vp = [
|
|
353
|
-
{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject", target: "t", method: "m", pass_criteria: "p", fail_action: "f" },
|
|
354
|
-
];
|
|
355
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
356
|
-
expect(result.passed).toBe(false);
|
|
357
|
-
if (!result.passed) {
|
|
358
|
-
expect(result.violations.some((v) => v.rule === "L2-inject-edge-case" && v.detail.includes("CST-001"))).toBe(true);
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
it("passes when inject item has non-empty edge_cases", () => {
|
|
362
|
-
const pool = makePool(makeEntry("CST-001", { decision: "inject" }));
|
|
363
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }], [{ impl_id: "IMPL-001", related_cst: ["CST-001"] }]);
|
|
364
|
-
const ds = makeDeltaSet([
|
|
365
|
-
{ change_id: "CHG-001", action: "create", file_path: "a.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
366
|
-
]);
|
|
367
|
-
const vp = [
|
|
368
|
-
{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject", target: "t", method: "m", pass_criteria: "p", fail_action: "f", edge_cases: [{ scenario: "null", expected_result: "error" }] },
|
|
369
|
-
];
|
|
370
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
371
|
-
expect(result.passed).toBe(true);
|
|
372
|
-
});
|
|
373
|
-
});
|
|
374
|
-
// ─── Additional Edge Cases ───
|
|
375
|
-
describe("compile-defense — additional edge cases", () => {
|
|
376
|
-
it("multiple violations from different rules simultaneously", () => {
|
|
377
|
-
const pool = makePool(makeEntry("CST-001", { decision: "inject" }));
|
|
378
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }], []);
|
|
379
|
-
const ds = makeDeltaSet([]); // no CHG
|
|
380
|
-
const vp = []; // no VAL
|
|
381
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
382
|
-
expect(result.passed).toBe(false);
|
|
383
|
-
if (!result.passed) {
|
|
384
|
-
expect(result.violations.some((v) => v.rule === "L2-inject-impl")).toBe(true);
|
|
385
|
-
expect(result.violations.some((v) => v.rule === "L2-inject-chg")).toBe(true);
|
|
386
|
-
expect(result.violations.some((v) => v.rule === "L2-inject-val")).toBe(true);
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
it("L1 + L2 violations simultaneously", () => {
|
|
390
|
-
const pool = makePool(makeEntry("CST-001"), // missing from Section 3
|
|
391
|
-
makeEntry("CST-002", { decision: "inject" }));
|
|
392
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-002", decision: "inject" }], // CST-001 missing
|
|
393
|
-
[{ impl_id: "IMPL-001", related_cst: ["CST-002"] }]);
|
|
394
|
-
const ds = makeDeltaSet([]); // no CHG for CST-002
|
|
395
|
-
const vp = [{ val_id: "VAL-001", related_cst: "CST-002", decision_type: "inject" }];
|
|
396
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
397
|
-
expect(result.passed).toBe(false);
|
|
398
|
-
if (!result.passed) {
|
|
399
|
-
expect(result.violations.some((v) => v.rule === "L1-checklist")).toBe(true);
|
|
400
|
-
expect(result.violations.some((v) => v.rule === "L2-inject-chg")).toBe(true);
|
|
401
|
-
}
|
|
402
|
-
});
|
|
403
|
-
it("empty pool passes defense", () => {
|
|
404
|
-
const pool = makePool();
|
|
405
|
-
const bs = makeBuildSpec([], []);
|
|
406
|
-
const ds = makeDeltaSet([]);
|
|
407
|
-
const vp = [];
|
|
408
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
409
|
-
expect(result.passed).toBe(true);
|
|
410
|
-
});
|
|
411
|
-
it("CHG with multiple related_impl one valid one invalid", () => {
|
|
412
|
-
const pool = makePool(makeEntry("CST-001", { decision: "inject" }));
|
|
413
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }], [{ impl_id: "IMPL-001", related_cst: ["CST-001"] }]);
|
|
414
|
-
const ds = makeDeltaSet([
|
|
415
|
-
{ change_id: "CHG-001", action: "create", file_path: "a.ts", description: "d", related_impl: ["IMPL-001", "IMPL-999"], related_cst: ["CST-001"] },
|
|
416
|
-
]);
|
|
417
|
-
const vp = [{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject" }];
|
|
418
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
419
|
-
expect(result.passed).toBe(false);
|
|
420
|
-
if (!result.passed) {
|
|
421
|
-
const orphanViolations = result.violations.filter((v) => v.rule === "L2-chg-orphan-impl");
|
|
422
|
-
expect(orphanViolations).toHaveLength(1);
|
|
423
|
-
expect(orphanViolations[0].detail).toContain("IMPL-999");
|
|
424
|
-
}
|
|
425
|
-
});
|
|
426
|
-
it("multiple IMPLs without CHGs", () => {
|
|
427
|
-
const pool = makePool(makeEntry("CST-001", { decision: "inject" }));
|
|
428
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }], [
|
|
429
|
-
{ impl_id: "IMPL-001", related_cst: ["CST-001"] },
|
|
430
|
-
{ impl_id: "IMPL-002", related_cst: ["CST-001"] },
|
|
431
|
-
]);
|
|
432
|
-
const ds = makeDeltaSet([]); // no changes at all
|
|
433
|
-
const vp = [{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject" }];
|
|
434
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
435
|
-
expect(result.passed).toBe(false);
|
|
436
|
-
if (!result.passed) {
|
|
437
|
-
const implNoChg = result.violations.filter((v) => v.rule === "L2-impl-no-chg");
|
|
438
|
-
expect(implNoChg).toHaveLength(2);
|
|
439
|
-
}
|
|
440
|
-
});
|
|
441
|
-
});
|
|
442
|
-
// ─── Layer 3: Evidence Status Warnings ───
|
|
443
|
-
describe("Layer 3 — evidence status warnings", () => {
|
|
444
|
-
const bs = {
|
|
445
|
-
section3: [{ constraint_id: "CST-001", decision: "inject" }],
|
|
446
|
-
section4: [{ impl_id: "IMPL-001", related_cst: ["CST-001"] }],
|
|
447
|
-
};
|
|
448
|
-
const ds = makeDeltaSet([{ change_id: "CHG-001", action: "modify", file_path: "a.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] }]);
|
|
449
|
-
const vp = [{
|
|
450
|
-
val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject",
|
|
451
|
-
target: "t", method: "m", pass_criteria: "p", fail_action: "f",
|
|
452
|
-
edge_cases: [{ scenario: "s", expected_result: "r" }],
|
|
453
|
-
}];
|
|
454
|
-
it("required + inject + unverified → passed:true with L3 warning", () => {
|
|
455
|
-
const pool = makePool(makeEntry("CST-001", { severity: "required", evidence_status: "unverified" }));
|
|
456
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
457
|
-
expect(result.passed).toBe(true);
|
|
458
|
-
if (result.passed) {
|
|
459
|
-
expect(result.warnings).toBeDefined();
|
|
460
|
-
expect(result.warnings.some((w) => w.rule === "L3-unverified-inject")).toBe(true);
|
|
461
|
-
}
|
|
462
|
-
});
|
|
463
|
-
it("required + inject + verified → no L3 warning", () => {
|
|
464
|
-
const pool = makePool(makeEntry("CST-001", { severity: "required", evidence_status: "verified" }));
|
|
465
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
466
|
-
expect(result.passed).toBe(true);
|
|
467
|
-
if (result.passed) {
|
|
468
|
-
expect(result.warnings).toEqual([]);
|
|
469
|
-
}
|
|
470
|
-
});
|
|
471
|
-
it("recommended + inject + unverified → no L3 warning (severity filter)", () => {
|
|
472
|
-
const pool = makePool(makeEntry("CST-001", { severity: "recommended", evidence_status: "unverified" }));
|
|
473
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
474
|
-
expect(result.passed).toBe(true);
|
|
475
|
-
if (result.passed) {
|
|
476
|
-
expect(result.warnings).toEqual([]);
|
|
477
|
-
}
|
|
478
|
-
});
|
|
479
|
-
it("required + defer + unverified → no L3 warning (decision filter)", () => {
|
|
480
|
-
const pool = makePool(makeEntry("CST-001", { severity: "required", decision: "defer", evidence_status: "unverified" }));
|
|
481
|
-
const bs2 = { section3: [{ constraint_id: "CST-001", decision: "defer" }], section4: [] };
|
|
482
|
-
const ds2 = makeDeltaSet([]);
|
|
483
|
-
const vp2 = [];
|
|
484
|
-
const result = compileDefense(makeState(pool), bs2, ds2, vp2);
|
|
485
|
-
expect(result.passed).toBe(true);
|
|
486
|
-
if (result.passed) {
|
|
487
|
-
expect(result.warnings).toEqual([]);
|
|
488
|
-
}
|
|
489
|
-
});
|
|
490
|
-
it("required + inject + brief_claimed → L3 warning", () => {
|
|
491
|
-
const pool = makePool(makeEntry("CST-001", { severity: "required", evidence_status: "brief_claimed" }));
|
|
492
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
493
|
-
expect(result.passed).toBe(true);
|
|
494
|
-
if (result.passed) {
|
|
495
|
-
expect(result.warnings).toBeDefined();
|
|
496
|
-
expect(result.warnings[0].rule).toBe("L3-unverified-inject");
|
|
497
|
-
}
|
|
498
|
-
});
|
|
499
|
-
});
|
|
500
|
-
// ─── Layer 3: L3-policy-change-required ───
|
|
501
|
-
describe("Layer 3 — L3-policy-change-required", () => {
|
|
502
|
-
const bs = {
|
|
503
|
-
section3: [{ constraint_id: "CST-001", decision: "inject" }],
|
|
504
|
-
section4: [{ impl_id: "IMPL-001", related_cst: ["CST-001"] }],
|
|
505
|
-
};
|
|
506
|
-
const ds = makeDeltaSet([{ change_id: "CHG-001", action: "modify", file_path: "a.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] }]);
|
|
507
|
-
const vp = [{
|
|
508
|
-
val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject",
|
|
509
|
-
target: "t", method: "m", pass_criteria: "p", fail_action: "f",
|
|
510
|
-
edge_cases: [{ scenario: "s", expected_result: "r" }],
|
|
511
|
-
}];
|
|
512
|
-
it("requires_policy_change=true + inject → L3 warning", () => {
|
|
513
|
-
const pool = makePool(makeEntry("CST-001", { decision: "inject", requires_policy_change: true, evidence_note: "기존 정책 변경 필요" }));
|
|
514
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
515
|
-
expect(result.passed).toBe(true);
|
|
516
|
-
if (result.passed) {
|
|
517
|
-
expect(result.warnings.some((w) => w.rule === "L3-policy-change-required" && w.detail.includes("CST-001"))).toBe(true);
|
|
518
|
-
}
|
|
519
|
-
});
|
|
520
|
-
it("requires_policy_change=false + inject → no L3-policy-change-required warning", () => {
|
|
521
|
-
const pool = makePool(makeEntry("CST-001", { decision: "inject", requires_policy_change: false }));
|
|
522
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
523
|
-
expect(result.passed).toBe(true);
|
|
524
|
-
if (result.passed) {
|
|
525
|
-
expect(result.warnings.some((w) => w.rule === "L3-policy-change-required")).toBe(false);
|
|
526
|
-
}
|
|
527
|
-
});
|
|
528
|
-
it("requires_policy_change=true + defer → no warning (not inject)", () => {
|
|
529
|
-
const pool = makePool(makeEntry("CST-001", { decision: "defer", requires_policy_change: true }));
|
|
530
|
-
const bs2 = { section3: [{ constraint_id: "CST-001", decision: "defer" }], section4: [] };
|
|
531
|
-
const ds2 = makeDeltaSet([]);
|
|
532
|
-
const vp2 = [];
|
|
533
|
-
const result = compileDefense(makeState(pool), bs2, ds2, vp2);
|
|
534
|
-
expect(result.passed).toBe(true);
|
|
535
|
-
if (result.passed) {
|
|
536
|
-
expect(result.warnings.some((w) => w.rule === "L3-policy-change-required")).toBe(false);
|
|
537
|
-
}
|
|
538
|
-
});
|
|
539
|
-
it("requires_policy_change=true + invalidated → no warning", () => {
|
|
540
|
-
const pool = makePool(makeEntry("CST-001", { status: "invalidated", decision: "inject", requires_policy_change: true }));
|
|
541
|
-
const bs2 = { section3: [], section4: [] };
|
|
542
|
-
const ds2 = makeDeltaSet([]);
|
|
543
|
-
const vp2 = [];
|
|
544
|
-
const result = compileDefense(makeState(pool), bs2, ds2, vp2);
|
|
545
|
-
expect(result.passed).toBe(true);
|
|
546
|
-
if (result.passed) {
|
|
547
|
-
expect(result.warnings.some((w) => w.rule === "L3-policy-change-required")).toBe(false);
|
|
548
|
-
}
|
|
549
|
-
});
|
|
550
|
-
});
|
|
551
|
-
// ─── Layer 3: L3-shared-resource ───
|
|
552
|
-
describe("compile-defense — L3-shared-resource", () => {
|
|
553
|
-
it("warns when same file is modified by separate CHGs from different CSTs", () => {
|
|
554
|
-
const pool = makePool(makeEntry("CST-001", { decision: "inject" }), makeEntry("CST-002", { decision: "inject" }));
|
|
555
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }, { constraint_id: "CST-002", decision: "inject" }], [{ impl_id: "IMPL-001", related_cst: ["CST-001"] }, { impl_id: "IMPL-002", related_cst: ["CST-002"] }]);
|
|
556
|
-
const ds = makeDeltaSet([
|
|
557
|
-
{ change_id: "CHG-001", action: "modify", file_path: "src/shared.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
558
|
-
{ change_id: "CHG-002", action: "modify", file_path: "src/shared.ts", description: "d", related_impl: ["IMPL-002"], related_cst: ["CST-002"] },
|
|
559
|
-
]);
|
|
560
|
-
const vp = [
|
|
561
|
-
{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject", target: "t", method: "m", pass_criteria: "p", fail_action: "f", edge_cases: [{ scenario: "s", expected_result: "r" }] },
|
|
562
|
-
{ val_id: "VAL-002", related_cst: "CST-002", decision_type: "inject", target: "t", method: "m", pass_criteria: "p", fail_action: "f", edge_cases: [{ scenario: "s", expected_result: "r" }] },
|
|
563
|
-
];
|
|
564
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
565
|
-
expect(result.passed).toBe(true);
|
|
566
|
-
expect(result.warnings.some((w) => w.rule === "L3-shared-resource" && w.detail.includes("src/shared.ts"))).toBe(true);
|
|
567
|
-
});
|
|
568
|
-
it("no warning when single CHG references multiple CSTs (one change serving multiple constraints)", () => {
|
|
569
|
-
const pool = makePool(makeEntry("CST-001", { decision: "inject" }), makeEntry("CST-002", { decision: "inject" }));
|
|
570
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }, { constraint_id: "CST-002", decision: "inject" }], [{ impl_id: "IMPL-001", related_cst: ["CST-001", "CST-002"] }]);
|
|
571
|
-
const ds = makeDeltaSet([
|
|
572
|
-
{ change_id: "CHG-001", action: "modify", file_path: "src/shared.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001", "CST-002"] },
|
|
573
|
-
]);
|
|
574
|
-
const vp = [
|
|
575
|
-
{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject", target: "t", method: "m", pass_criteria: "p", fail_action: "f", edge_cases: [{ scenario: "s", expected_result: "r" }] },
|
|
576
|
-
{ val_id: "VAL-002", related_cst: "CST-002", decision_type: "inject", target: "t", method: "m", pass_criteria: "p", fail_action: "f", edge_cases: [{ scenario: "s", expected_result: "r" }] },
|
|
577
|
-
];
|
|
578
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
579
|
-
expect(result.passed).toBe(true);
|
|
580
|
-
expect(result.warnings.some((w) => w.rule === "L3-shared-resource")).toBe(false);
|
|
581
|
-
});
|
|
582
|
-
it("no warning when same file has 2 CHGs from the same CST", () => {
|
|
583
|
-
const pool = makePool(makeEntry("CST-001", { decision: "inject" }));
|
|
584
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }], [{ impl_id: "IMPL-001", related_cst: ["CST-001"] }]);
|
|
585
|
-
const ds = makeDeltaSet([
|
|
586
|
-
{ change_id: "CHG-001", action: "modify", file_path: "src/shared.ts", description: "d1", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
587
|
-
{ change_id: "CHG-002", action: "modify", file_path: "src/shared.ts", description: "d2", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
588
|
-
]);
|
|
589
|
-
const vp = [
|
|
590
|
-
{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject", target: "t", method: "m", pass_criteria: "p", fail_action: "f", edge_cases: [{ scenario: "s", expected_result: "r" }] },
|
|
591
|
-
];
|
|
592
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
593
|
-
expect(result.passed).toBe(true);
|
|
594
|
-
expect(result.warnings.some((w) => w.rule === "L3-shared-resource")).toBe(false);
|
|
595
|
-
});
|
|
596
|
-
it("no warning when CHGs have empty related_cst", () => {
|
|
597
|
-
const pool = makePool(makeEntry("CST-001", { decision: "inject" }));
|
|
598
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }], [{ impl_id: "IMPL-001", related_cst: ["CST-001"] }]);
|
|
599
|
-
const ds = makeDeltaSet([
|
|
600
|
-
{ change_id: "CHG-001", action: "modify", file_path: "src/shared.ts", description: "d", related_impl: ["IMPL-001"], related_cst: [] },
|
|
601
|
-
{ change_id: "CHG-002", action: "modify", file_path: "src/shared.ts", description: "d", related_impl: ["IMPL-001"], related_cst: [] },
|
|
602
|
-
{ change_id: "CHG-003", action: "create", file_path: "src/other.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
603
|
-
]);
|
|
604
|
-
const vp = [
|
|
605
|
-
{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject", target: "t", method: "m", pass_criteria: "p", fail_action: "f", edge_cases: [{ scenario: "s", expected_result: "r" }] },
|
|
606
|
-
];
|
|
607
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
608
|
-
expect(result.passed).toBe(true);
|
|
609
|
-
expect(result.warnings.some((w) => w.rule === "L3-shared-resource")).toBe(false);
|
|
610
|
-
});
|
|
611
|
-
it("no warning when deltaSet has no changes", () => {
|
|
612
|
-
const pool = makePool();
|
|
613
|
-
const bs = makeBuildSpec([], []);
|
|
614
|
-
const ds = makeDeltaSet([]);
|
|
615
|
-
const vp = [];
|
|
616
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
617
|
-
expect(result.passed).toBe(true);
|
|
618
|
-
expect(result.warnings.some((w) => w.rule === "L3-shared-resource")).toBe(false);
|
|
619
|
-
});
|
|
620
|
-
});
|
|
621
|
-
// ─── CompileSuccess.warnings required ───
|
|
622
|
-
describe("compile-defense — warnings always array", () => {
|
|
623
|
-
it("returns empty array (not undefined) when no warnings", () => {
|
|
624
|
-
const pool = makePool(makeEntry("CST-001", { severity: "recommended", evidence_status: "verified" }));
|
|
625
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }], [{ impl_id: "IMPL-001", related_cst: ["CST-001"] }]);
|
|
626
|
-
const ds = makeDeltaSet([
|
|
627
|
-
{ change_id: "CHG-001", action: "create", file_path: "a.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
628
|
-
]);
|
|
629
|
-
const vp = [
|
|
630
|
-
{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject", target: "t", method: "m", pass_criteria: "p", fail_action: "f", edge_cases: [{ scenario: "s", expected_result: "r" }] },
|
|
631
|
-
];
|
|
632
|
-
const result = compileDefense(makeState(pool), bs, ds, vp);
|
|
633
|
-
expect(result.passed).toBe(true);
|
|
634
|
-
if (result.passed) {
|
|
635
|
-
expect(result.warnings).toBeDefined();
|
|
636
|
-
expect(Array.isArray(result.warnings)).toBe(true);
|
|
637
|
-
expect(result.warnings).toEqual([]);
|
|
638
|
-
}
|
|
639
|
-
});
|
|
640
|
-
});
|
|
641
|
-
// ─── Layer 3: L3-invariant-uncovered ───
|
|
642
|
-
describe("compile-defense — L3-invariant-uncovered", () => {
|
|
643
|
-
it("warns when invariant affected_files are in delta-set but invariant is not mentioned", () => {
|
|
644
|
-
const pool = makePool(makeEntry("CST-001", { decision: "inject", summary: "Add feature X" }));
|
|
645
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }], [{ impl_id: "IMPL-001", related_cst: ["CST-001"] }]);
|
|
646
|
-
const ds = makeDeltaSet([
|
|
647
|
-
{ change_id: "CHG-001", action: "modify", file_path: "src/schema.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
648
|
-
]);
|
|
649
|
-
const vp = [
|
|
650
|
-
{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject", target: "t", method: "m", pass_criteria: "p", fail_action: "f", edge_cases: [{ scenario: "s", expected_result: "r" }] },
|
|
651
|
-
];
|
|
652
|
-
const brownfieldDetail = {
|
|
653
|
-
scope_id: "SC-TEST",
|
|
654
|
-
sections: [],
|
|
655
|
-
invariants: [{
|
|
656
|
-
name: "UserSchema",
|
|
657
|
-
source: "src/schema.ts",
|
|
658
|
-
description: "User 테이블 스키마 제약",
|
|
659
|
-
type: "schema",
|
|
660
|
-
affected_files: ["src/schema.ts"],
|
|
661
|
-
}],
|
|
662
|
-
};
|
|
663
|
-
const result = compileDefense(makeState(pool), bs, ds, vp, brownfieldDetail);
|
|
664
|
-
expect(result.passed).toBe(true);
|
|
665
|
-
if (result.passed) {
|
|
666
|
-
expect(result.warnings.some(w => w.rule === "L3-invariant-uncovered" && w.detail.includes("UserSchema"))).toBe(true);
|
|
667
|
-
}
|
|
668
|
-
});
|
|
669
|
-
it("no warning when invariant affected_files are NOT in delta-set", () => {
|
|
670
|
-
const pool = makePool(makeEntry("CST-001", { decision: "inject" }));
|
|
671
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }], [{ impl_id: "IMPL-001", related_cst: ["CST-001"] }]);
|
|
672
|
-
const ds = makeDeltaSet([
|
|
673
|
-
{ change_id: "CHG-001", action: "create", file_path: "src/feature.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
674
|
-
]);
|
|
675
|
-
const vp = [
|
|
676
|
-
{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject", target: "t", method: "m", pass_criteria: "p", fail_action: "f", edge_cases: [{ scenario: "s", expected_result: "r" }] },
|
|
677
|
-
];
|
|
678
|
-
const brownfieldDetail = {
|
|
679
|
-
scope_id: "SC-TEST",
|
|
680
|
-
sections: [],
|
|
681
|
-
invariants: [{
|
|
682
|
-
name: "UserSchema",
|
|
683
|
-
source: "src/schema.ts",
|
|
684
|
-
description: "User 테이블 스키마 제약",
|
|
685
|
-
type: "schema",
|
|
686
|
-
affected_files: ["src/schema.ts"],
|
|
687
|
-
}],
|
|
688
|
-
};
|
|
689
|
-
const result = compileDefense(makeState(pool), bs, ds, vp, brownfieldDetail);
|
|
690
|
-
expect(result.passed).toBe(true);
|
|
691
|
-
if (result.passed) {
|
|
692
|
-
expect(result.warnings.some(w => w.rule === "L3-invariant-uncovered")).toBe(false);
|
|
693
|
-
}
|
|
694
|
-
});
|
|
695
|
-
it("no warning when invariant is mentioned in constraint summary", () => {
|
|
696
|
-
const pool = makePool(makeEntry("CST-001", { decision: "inject", summary: "UserSchema migration" }));
|
|
697
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }], [{ impl_id: "IMPL-001", related_cst: ["CST-001"] }]);
|
|
698
|
-
const ds = makeDeltaSet([
|
|
699
|
-
{ change_id: "CHG-001", action: "modify", file_path: "src/schema.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
700
|
-
]);
|
|
701
|
-
const vp = [
|
|
702
|
-
{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject", target: "t", method: "m", pass_criteria: "p", fail_action: "f", edge_cases: [{ scenario: "s", expected_result: "r" }] },
|
|
703
|
-
];
|
|
704
|
-
const brownfieldDetail = {
|
|
705
|
-
scope_id: "SC-TEST",
|
|
706
|
-
sections: [],
|
|
707
|
-
invariants: [{
|
|
708
|
-
name: "UserSchema",
|
|
709
|
-
source: "src/schema.ts",
|
|
710
|
-
description: "User 테이블 스키마 제약",
|
|
711
|
-
type: "schema",
|
|
712
|
-
affected_files: ["src/schema.ts"],
|
|
713
|
-
}],
|
|
714
|
-
};
|
|
715
|
-
const result = compileDefense(makeState(pool), bs, ds, vp, brownfieldDetail);
|
|
716
|
-
expect(result.passed).toBe(true);
|
|
717
|
-
if (result.passed) {
|
|
718
|
-
expect(result.warnings.some(w => w.rule === "L3-invariant-uncovered")).toBe(false);
|
|
719
|
-
}
|
|
720
|
-
});
|
|
721
|
-
it("no warning when invariants is undefined", () => {
|
|
722
|
-
const pool = makePool(makeEntry("CST-001", { decision: "inject" }));
|
|
723
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }], [{ impl_id: "IMPL-001", related_cst: ["CST-001"] }]);
|
|
724
|
-
const ds = makeDeltaSet([
|
|
725
|
-
{ change_id: "CHG-001", action: "create", file_path: "src/feature.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
726
|
-
]);
|
|
727
|
-
const vp = [
|
|
728
|
-
{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject", target: "t", method: "m", pass_criteria: "p", fail_action: "f", edge_cases: [{ scenario: "s", expected_result: "r" }] },
|
|
729
|
-
];
|
|
730
|
-
const brownfieldDetail = {
|
|
731
|
-
scope_id: "SC-TEST",
|
|
732
|
-
sections: [],
|
|
733
|
-
// no invariants field
|
|
734
|
-
};
|
|
735
|
-
const result = compileDefense(makeState(pool), bs, ds, vp, brownfieldDetail);
|
|
736
|
-
expect(result.passed).toBe(true);
|
|
737
|
-
if (result.passed) {
|
|
738
|
-
expect(result.warnings.some(w => w.rule === "L3-invariant-uncovered")).toBe(false);
|
|
739
|
-
}
|
|
740
|
-
});
|
|
741
|
-
it("no warning when invariants is empty array", () => {
|
|
742
|
-
const pool = makePool(makeEntry("CST-001", { decision: "inject" }));
|
|
743
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }], [{ impl_id: "IMPL-001", related_cst: ["CST-001"] }]);
|
|
744
|
-
const ds = makeDeltaSet([
|
|
745
|
-
{ change_id: "CHG-001", action: "create", file_path: "src/feature.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
746
|
-
]);
|
|
747
|
-
const vp = [
|
|
748
|
-
{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject", target: "t", method: "m", pass_criteria: "p", fail_action: "f", edge_cases: [{ scenario: "s", expected_result: "r" }] },
|
|
749
|
-
];
|
|
750
|
-
const brownfieldDetail = {
|
|
751
|
-
scope_id: "SC-TEST",
|
|
752
|
-
sections: [],
|
|
753
|
-
invariants: [],
|
|
754
|
-
};
|
|
755
|
-
const result = compileDefense(makeState(pool), bs, ds, vp, brownfieldDetail);
|
|
756
|
-
expect(result.passed).toBe(true);
|
|
757
|
-
if (result.passed) {
|
|
758
|
-
expect(result.warnings.some(w => w.rule === "L3-invariant-uncovered")).toBe(false);
|
|
759
|
-
}
|
|
760
|
-
});
|
|
761
|
-
it("warns for invariant without affected_files when no match", () => {
|
|
762
|
-
const pool = makePool(makeEntry("CST-001", { decision: "inject", summary: "Add feature X" }));
|
|
763
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }], [{ impl_id: "IMPL-001", related_cst: ["CST-001"] }]);
|
|
764
|
-
const ds = makeDeltaSet([
|
|
765
|
-
{ change_id: "CHG-001", action: "modify", file_path: "src/schema.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
766
|
-
]);
|
|
767
|
-
const vp = [
|
|
768
|
-
{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject", target: "t", method: "m", pass_criteria: "p", fail_action: "f", edge_cases: [{ scenario: "s", expected_result: "r" }] },
|
|
769
|
-
];
|
|
770
|
-
const brownfieldDetail = {
|
|
771
|
-
scope_id: "SC-TEST",
|
|
772
|
-
sections: [],
|
|
773
|
-
invariants: [{
|
|
774
|
-
name: "PaymentFlow",
|
|
775
|
-
source: "src/payment.ts",
|
|
776
|
-
description: "결제 흐름 불변 규칙",
|
|
777
|
-
type: "business_rule",
|
|
778
|
-
// no affected_files → affected check returns false → no warning
|
|
779
|
-
}],
|
|
780
|
-
};
|
|
781
|
-
const result = compileDefense(makeState(pool), bs, ds, vp, brownfieldDetail);
|
|
782
|
-
expect(result.passed).toBe(true);
|
|
783
|
-
if (result.passed) {
|
|
784
|
-
expect(result.warnings.some(w => w.rule === "L3-invariant-uncovered")).toBe(false);
|
|
785
|
-
}
|
|
786
|
-
});
|
|
787
|
-
});
|
|
788
|
-
// ─── Layer 3: L3-modify-not-in-brownfield ───
|
|
789
|
-
describe("compile-defense — L3-modify-not-in-brownfield", () => {
|
|
790
|
-
function makeBasicInput() {
|
|
791
|
-
const pool = makePool(makeEntry("CST-001"));
|
|
792
|
-
const bs = makeBuildSpec([{ constraint_id: "CST-001", decision: "inject" }], [{ impl_id: "IMPL-001", related_cst: ["CST-001"] }]);
|
|
793
|
-
const vp = [
|
|
794
|
-
{ val_id: "VAL-001", related_cst: "CST-001", decision_type: "inject", target: "t", method: "m", pass_criteria: "p", fail_action: "f", edge_cases: [{ scenario: "s", expected_result: "r" }] },
|
|
795
|
-
];
|
|
796
|
-
return { state: makeState(pool), bs, vp };
|
|
797
|
-
}
|
|
798
|
-
it("no warning when modify file exists in brownfield.related_files", () => {
|
|
799
|
-
const { state, bs, vp } = makeBasicInput();
|
|
800
|
-
const ds = makeDeltaSet([
|
|
801
|
-
{ change_id: "CHG-001", action: "modify", file_path: "src/app.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
802
|
-
]);
|
|
803
|
-
const brownfieldContext = {
|
|
804
|
-
related_files: [{ path: "src/app.ts", role: "source", detail_anchor: "#app" }],
|
|
805
|
-
module_dependencies: [],
|
|
806
|
-
};
|
|
807
|
-
const result = compileDefense(state, bs, ds, vp, undefined, brownfieldContext);
|
|
808
|
-
expect(result.passed).toBe(true);
|
|
809
|
-
if (result.passed) {
|
|
810
|
-
expect(result.warnings.some(w => w.rule === "L3-modify-not-in-brownfield")).toBe(false);
|
|
811
|
-
}
|
|
812
|
-
});
|
|
813
|
-
it("warns when modify file is NOT in brownfield.related_files", () => {
|
|
814
|
-
const { state, bs, vp } = makeBasicInput();
|
|
815
|
-
const ds = makeDeltaSet([
|
|
816
|
-
{ change_id: "CHG-001", action: "modify", file_path: "src/app.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
817
|
-
]);
|
|
818
|
-
const brownfieldContext = {
|
|
819
|
-
related_files: [{ path: "src/other.ts", role: "source", detail_anchor: "#other" }],
|
|
820
|
-
module_dependencies: [],
|
|
821
|
-
};
|
|
822
|
-
const result = compileDefense(state, bs, ds, vp, undefined, brownfieldContext);
|
|
823
|
-
expect(result.passed).toBe(true);
|
|
824
|
-
if (result.passed) {
|
|
825
|
-
expect(result.warnings.some(w => w.rule === "L3-modify-not-in-brownfield" && w.detail.includes("src/app.ts"))).toBe(true);
|
|
826
|
-
}
|
|
827
|
-
});
|
|
828
|
-
it("warns when delete file is NOT in brownfield.related_files", () => {
|
|
829
|
-
const { state, bs, vp } = makeBasicInput();
|
|
830
|
-
const ds = makeDeltaSet([
|
|
831
|
-
{ change_id: "CHG-001", action: "delete", file_path: "src/old.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
832
|
-
]);
|
|
833
|
-
const brownfieldContext = {
|
|
834
|
-
related_files: [{ path: "src/other.ts", role: "source", detail_anchor: "#other" }],
|
|
835
|
-
module_dependencies: [],
|
|
836
|
-
};
|
|
837
|
-
const result = compileDefense(state, bs, ds, vp, undefined, brownfieldContext);
|
|
838
|
-
expect(result.passed).toBe(true);
|
|
839
|
-
if (result.passed) {
|
|
840
|
-
expect(result.warnings.some(w => w.rule === "L3-modify-not-in-brownfield" && w.detail.includes("src/old.ts"))).toBe(true);
|
|
841
|
-
}
|
|
842
|
-
});
|
|
843
|
-
it("no warning for create action even if not in brownfield", () => {
|
|
844
|
-
const { state, bs, vp } = makeBasicInput();
|
|
845
|
-
const ds = makeDeltaSet([
|
|
846
|
-
{ change_id: "CHG-001", action: "create", file_path: "src/new.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
847
|
-
]);
|
|
848
|
-
const brownfieldContext = {
|
|
849
|
-
related_files: [{ path: "src/other.ts", role: "source", detail_anchor: "#other" }],
|
|
850
|
-
module_dependencies: [],
|
|
851
|
-
};
|
|
852
|
-
const result = compileDefense(state, bs, ds, vp, undefined, brownfieldContext);
|
|
853
|
-
expect(result.passed).toBe(true);
|
|
854
|
-
if (result.passed) {
|
|
855
|
-
expect(result.warnings.some(w => w.rule === "L3-modify-not-in-brownfield")).toBe(false);
|
|
856
|
-
}
|
|
857
|
-
});
|
|
858
|
-
it("no warning when brownfieldContext is undefined", () => {
|
|
859
|
-
const { state, bs, vp } = makeBasicInput();
|
|
860
|
-
const ds = makeDeltaSet([
|
|
861
|
-
{ change_id: "CHG-001", action: "modify", file_path: "src/app.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
862
|
-
]);
|
|
863
|
-
const result = compileDefense(state, bs, ds, vp, undefined, undefined);
|
|
864
|
-
expect(result.passed).toBe(true);
|
|
865
|
-
if (result.passed) {
|
|
866
|
-
expect(result.warnings.some(w => w.rule === "L3-modify-not-in-brownfield")).toBe(false);
|
|
867
|
-
}
|
|
868
|
-
});
|
|
869
|
-
it("no warning when brownfield.related_files is empty", () => {
|
|
870
|
-
const { state, bs, vp } = makeBasicInput();
|
|
871
|
-
const ds = makeDeltaSet([
|
|
872
|
-
{ change_id: "CHG-001", action: "modify", file_path: "src/app.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
873
|
-
]);
|
|
874
|
-
const brownfieldContext = { related_files: [], module_dependencies: [] };
|
|
875
|
-
const result = compileDefense(state, bs, ds, vp, undefined, brownfieldContext);
|
|
876
|
-
expect(result.passed).toBe(true);
|
|
877
|
-
if (result.passed) {
|
|
878
|
-
expect(result.warnings.some(w => w.rule === "L3-modify-not-in-brownfield")).toBe(false);
|
|
879
|
-
}
|
|
880
|
-
});
|
|
881
|
-
it("path normalization: ./src/app.ts matches src/app.ts", () => {
|
|
882
|
-
const { state, bs, vp } = makeBasicInput();
|
|
883
|
-
const ds = makeDeltaSet([
|
|
884
|
-
{ change_id: "CHG-001", action: "modify", file_path: "./src/app.ts", description: "d", related_impl: ["IMPL-001"], related_cst: ["CST-001"] },
|
|
885
|
-
]);
|
|
886
|
-
const brownfieldContext = {
|
|
887
|
-
related_files: [{ path: "src/app.ts", role: "source", detail_anchor: "#app" }],
|
|
888
|
-
module_dependencies: [],
|
|
889
|
-
};
|
|
890
|
-
const result = compileDefense(state, bs, ds, vp, undefined, brownfieldContext);
|
|
891
|
-
expect(result.passed).toBe(true);
|
|
892
|
-
if (result.passed) {
|
|
893
|
-
expect(result.warnings.some(w => w.rule === "L3-modify-not-in-brownfield")).toBe(false);
|
|
894
|
-
}
|
|
895
|
-
});
|
|
896
|
-
});
|
|
897
|
-
// ─── normalizeFilePath ───
|
|
898
|
-
import { normalizeFilePath } from "./compile-defense.js";
|
|
899
|
-
describe("normalizeFilePath", () => {
|
|
900
|
-
it("removes leading ./", () => {
|
|
901
|
-
expect(normalizeFilePath("./src/app.ts")).toBe("src/app.ts");
|
|
902
|
-
});
|
|
903
|
-
it("removes trailing /", () => {
|
|
904
|
-
expect(normalizeFilePath("src/components/")).toBe("src/components");
|
|
905
|
-
});
|
|
906
|
-
it("collapses consecutive /", () => {
|
|
907
|
-
expect(normalizeFilePath("src//components///app.ts")).toBe("src/components/app.ts");
|
|
908
|
-
});
|
|
909
|
-
it("handles combination of all normalizations", () => {
|
|
910
|
-
expect(normalizeFilePath("./src//app.ts/")).toBe("src/app.ts");
|
|
911
|
-
});
|
|
912
|
-
it("returns unchanged for already normalized path", () => {
|
|
913
|
-
expect(normalizeFilePath("src/app.ts")).toBe("src/app.ts");
|
|
914
|
-
});
|
|
915
|
-
});
|