@ornexus/neocortex 4.60.78 → 4.60.80
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/dist/release-source.json +1 -1
- package/dist/sbom.cdx.json +1193 -1206
- package/install.ps1 +1 -1
- package/install.sh +1 -1
- package/package.json +2 -2
- package/packages/client/dist/adapters/adapter-registry.js +108 -1
- package/packages/client/dist/adapters/antigravity-adapter.js +77 -2
- package/packages/client/dist/adapters/claude-code-adapter.js +79 -3
- package/packages/client/dist/adapters/codex-adapter.js +80 -2
- package/packages/client/dist/adapters/cursor-adapter.js +115 -4
- package/packages/client/dist/adapters/gemini-adapter.js +71 -2
- package/packages/client/dist/adapters/grok-adapter.js +42 -2
- package/packages/client/dist/adapters/index.js +22 -1
- package/packages/client/dist/adapters/platform-detector.js +214 -1
- package/packages/client/dist/adapters/target-adapter.js +12 -0
- package/packages/client/dist/adapters/vscode-adapter.js +72 -2
- package/packages/client/dist/agent/refresh-stubs.js +443 -2
- package/packages/client/dist/agent/update-agent-yaml.js +102 -1
- package/packages/client/dist/agent/update-description.js +260 -1
- package/packages/client/dist/cache/crypto-utils.js +78 -1
- package/packages/client/dist/cache/encrypted-cache.js +338 -1
- package/packages/client/dist/cache/in-memory-asset-cache.js +73 -1
- package/packages/client/dist/cache/index.js +13 -1
- package/packages/client/dist/cache/protected-pi-boundary.js +44 -1
- package/packages/client/dist/checkpoint/checkpoint-client-reader.js +127 -2
- package/packages/client/dist/checkpoint/index.js +11 -1
- package/packages/client/dist/checkpoint/shared-checkpoint-types.js +32 -1
- package/packages/client/dist/cli.js +358 -5
- package/packages/client/dist/commands/activate.js +394 -8
- package/packages/client/dist/commands/architecture-answers.js +274 -7
- package/packages/client/dist/commands/architecture-memory-terminal.js +253 -4
- package/packages/client/dist/commands/architecture-non-ui-continuation.js +100 -1
- package/packages/client/dist/commands/architecture-root-binding.js +51 -1
- package/packages/client/dist/commands/cache-status.js +112 -2
- package/packages/client/dist/commands/config.js +88 -1
- package/packages/client/dist/commands/doctor.js +635 -2
- package/packages/client/dist/commands/invoke.js +7712 -143
- package/packages/client/dist/commands/legacy-epic-terminal.js +71 -1
- package/packages/client/dist/commands/legacy-story-branch.js +96 -1
- package/packages/client/dist/commands/legacy-story-pr.js +276 -1
- package/packages/client/dist/commands/mutation-qa-checkpoint.js +285 -5
- package/packages/client/dist/commands/mutation-qa-gate.js +54 -1
- package/packages/client/dist/commands/mutation-qa-git.js +41 -1
- package/packages/client/dist/commands/mutation-qa-policy.js +102 -1
- package/packages/client/dist/commands/mutation-qa-run.js +219 -3
- package/packages/client/dist/commands/mutation-qa-verdict.js +149 -1
- package/packages/client/dist/commands/mutation-qa.js +220 -1
- package/packages/client/dist/commands/native-agent.js +136 -2
- package/packages/client/dist/commands/planning-diagnosis.js +43 -1
- package/packages/client/dist/commands/planning-generation.js +53 -1
- package/packages/client/dist/commands/planning-memory.js +40 -1
- package/packages/client/dist/commands/planning-research.js +42 -1
- package/packages/client/dist/commands/private-session.js +75 -1
- package/packages/client/dist/commands/property-qa.js +139 -1
- package/packages/client/dist/commands/qa-control.js +16 -1
- package/packages/client/dist/commands/qa-scan-browser-launch.js +55 -1
- package/packages/client/dist/commands/qa-scan-browser-route.js +28 -1
- package/packages/client/dist/commands/qa-scan-capture.js +663 -5
- package/packages/client/dist/commands/qa-scan-discovery.js +376 -3
- package/packages/client/dist/commands/qa-scan-review.js +826 -5
- package/packages/client/dist/commands/qa-synthetic-backend-capture.js +266 -1
- package/packages/client/dist/commands/qa-synthetic-backend-review.js +297 -1
- package/packages/client/dist/commands/qa-synthetic-backend.js +340 -2
- package/packages/client/dist/commands/qa-synthetic-broker-port.js +85 -1
- package/packages/client/dist/commands/qa-synthetic-browser.js +39 -1
- package/packages/client/dist/commands/refactor-characterization.js +671 -21
- package/packages/client/dist/commands/refactor-commit.js +399 -13
- package/packages/client/dist/commands/refactor-control.js +142 -3
- package/packages/client/dist/commands/refactor-cpp-assertions.js +93 -3
- package/packages/client/dist/commands/refactor-review.js +283 -5
- package/packages/client/dist/commands/refactor-root.js +588 -7
- package/packages/client/dist/commands/refresh-memory.d.ts +3 -1
- package/packages/client/dist/commands/refresh-memory.js +174 -3
- package/packages/client/dist/commands/shared-architecture-non-ui.js +24 -1
- package/packages/client/dist/commands/story-checkpoint.js +171 -1
- package/packages/client/dist/config/host-auth-broker.js +60 -1
- package/packages/client/dist/config/host-auth-reference.js +93 -1
- package/packages/client/dist/config/profile-directory.js +13 -1
- package/packages/client/dist/config/resolver-selection.js +278 -1
- package/packages/client/dist/config/secure-config.js +281 -12
- package/packages/client/dist/config.js +223 -2
- package/packages/client/dist/constants.js +25 -1
- package/packages/client/dist/context/context-collector.js +222 -2
- package/packages/client/dist/context/context-sanitizer.js +145 -1
- package/packages/client/dist/continuity/autonomous-governance.js +285 -1
- package/packages/client/dist/continuity/continuity-client-state-store.js +1587 -1
- package/packages/client/dist/continuity/invoke-hooks.js +129 -1
- package/packages/client/dist/continuity/migrations/001-initial-schema.js +12 -2
- package/packages/client/dist/continuity/migrations/002-processing-output-summary-indexes.js +12 -2
- package/packages/client/dist/continuity/migrations/003-headless-execution-attempts.js +12 -2
- package/packages/client/dist/continuity/migrations/004-outbox-delivery-state.js +12 -2
- package/packages/client/dist/continuity/migrations/005-bounded-headless-queue.js +12 -2
- package/packages/client/dist/continuity/migrations/006-native-agent-dispatches.js +10 -2
- package/packages/client/dist/continuity/native-agent-store.js +69 -1
- package/packages/client/dist/continuity/native-agent-types.js +105 -1
- package/packages/client/dist/continuity/outbox.js +117 -1
- package/packages/client/dist/continuity/runner-bootstrap-policy.js +172 -1
- package/packages/client/dist/continuity/sqlite-store.js +2612 -81
- package/packages/client/dist/effects/invoke-effect-gateways.js +62 -1
- package/packages/client/dist/errors/error-messages.js +258 -2
- package/packages/client/dist/errors/frontmatter-diagnostics.js +125 -1
- package/packages/client/dist/evidence/collector.js +347 -1
- package/packages/client/dist/evidence/index.js +1 -1
- package/packages/client/dist/evidence/types.js +2 -0
- package/packages/client/dist/fs/atomic-state-replace.js +152 -1
- package/packages/client/dist/generated/command-registry.generated.js +4076 -1
- package/packages/client/dist/generated/public-projections.generated.js +149 -1
- package/packages/client/dist/git/direct-yolo-c01-retry.js +138 -4
- package/packages/client/dist/git/direct-yolo-checkpoint.js +1456 -4
- package/packages/client/dist/git/epic-operational-state.js +672 -2
- package/packages/client/dist/git/git-lifecycle-step-ids.js +14 -1
- package/packages/client/dist/git/git-lifecycle-store.js +2188 -10
- package/packages/client/dist/git/legacy-story-branch-checkpoint.js +259 -9
- package/packages/client/dist/git/legacy-story-branch-setup.js +348 -4
- package/packages/client/dist/git/legacy-story-pr.js +3538 -70
- package/packages/client/dist/git/neocortex-trailers.d.ts +26 -0
- package/packages/client/dist/git/neocortex-trailers.js +53 -0
- package/packages/client/dist/git/secure-filesystem-boundary.js +182 -5
- package/packages/client/dist/graph-retrieval/pre-command-hook.js +284 -1
- package/packages/client/dist/graph-retrieval/shared-graph-retrieval-contract.js +237 -1
- package/packages/client/dist/i18n/first-run.js +60 -2
- package/packages/client/dist/index.js +50 -1
- package/packages/client/dist/invocation/invoke-input.js +24 -1
- package/packages/client/dist/license/host-auth-recovery.js +401 -1
- package/packages/client/dist/license/index.js +5 -1
- package/packages/client/dist/license/license-client.js +337 -1
- package/packages/client/dist/machine/fingerprint.js +163 -2
- package/packages/client/dist/machine/index.js +5 -1
- package/packages/client/dist/memory/project-memory-path-scope.js +62 -1
- package/packages/client/dist/memory/project-memory-writer.d.ts +16 -1
- package/packages/client/dist/memory/project-memory-writer.js +1117 -41
- package/packages/client/dist/memory/shared-project-memory-types.js +259 -2
- package/packages/client/dist/migrations/epic-lifecycle-backfill.js +1060 -3
- package/packages/client/dist/migrations/project-identity-capability.js +50 -1
- package/packages/client/dist/migrations/project-identity.js +493 -7
- package/packages/client/dist/migrations/state-json.js +393 -4
- package/packages/client/dist/policy/architecture-policy.js +184 -2
- package/packages/client/dist/policy/index.js +7 -1
- package/packages/client/dist/policy/shared-policy-types.js +38 -0
- package/packages/client/dist/policy/subagent-approval-policy.js +55 -1
- package/packages/client/dist/private-execution/clean-baseline.js +279 -2
- package/packages/client/dist/private-execution/codex-executor.js +574 -4
- package/packages/client/dist/private-execution/codex-host-runtime.js +137 -1
- package/packages/client/dist/private-execution/codex-lifecycle-guard.js +97 -1
- package/packages/client/dist/private-execution/codex-scoped-permissions.js +128 -1
- package/packages/client/dist/private-execution/delivery.js +410 -13
- package/packages/client/dist/private-execution/diagnosis-root-review.js +294 -2
- package/packages/client/dist/private-execution/frozen-handoff.js +19 -6
- package/packages/client/dist/private-execution/implementation-validation.js +106 -2
- package/packages/client/dist/private-execution/isolated-admission.js +1432 -23
- package/packages/client/dist/private-execution/isolated-session.js +725 -5
- package/packages/client/dist/private-execution/isolated-workspace.js +122 -1
- package/packages/client/dist/private-execution/pact-consumer-runtime.js +409 -3
- package/packages/client/dist/private-execution/pact-test-source.js +258 -1
- package/packages/client/dist/private-execution/pact-toolchain.js +290 -3
- package/packages/client/dist/private-execution/pact-write-set.js +172 -1
- package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.js +406 -5
- package/packages/client/dist/private-execution/planning-generation-checkpoint.js +462 -5
- package/packages/client/dist/private-execution/planning-memory-checkpoint.js +139 -3
- package/packages/client/dist/private-execution/planning-research-checkpoint.js +325 -4
- package/packages/client/dist/private-execution/private-report-store.js +42 -1
- package/packages/client/dist/private-execution/property-test-candidate.js +103 -1
- package/packages/client/dist/private-execution/property-test-choices.js +147 -3
- package/packages/client/dist/private-execution/property-test-plan.js +271 -7
- package/packages/client/dist/private-execution/property-test-review.js +258 -4
- package/packages/client/dist/private-execution/property-test-runtime.js +372 -9
- package/packages/client/dist/private-execution/property-test-source.js +139 -1
- package/packages/client/dist/private-execution/root-checkpoint.js +80 -1
- package/packages/client/dist/private-execution/root-memory-git-evidence.js +135 -3
- package/packages/client/dist/private-execution/root-memory-recovery.js +93 -1
- package/packages/client/dist/private-execution/root-memory-request.js +29 -1
- package/packages/client/dist/private-execution/root-memory-scope.js +178 -1
- package/packages/client/dist/private-execution/root-memory-writer.js +102 -1
- package/packages/client/dist/private-execution/session-lease.js +63 -1
- package/packages/client/dist/private-execution/shared-private-admission-types.js +50 -1
- package/packages/client/dist/private-execution/shared-project-validation.js +66 -1
- package/packages/client/dist/private-execution/shared-root-memory-types.js +61 -1
- package/packages/client/dist/private-execution/ux-source-validation.js +372 -1
- package/packages/client/dist/private-execution/ux-write-set.js +191 -2
- package/packages/client/dist/registry/registry-reconciliation.js +234 -1
- package/packages/client/dist/resilience/circuit-breaker.js +170 -1
- package/packages/client/dist/resilience/degradation-manager.js +164 -1
- package/packages/client/dist/resilience/freshness-indicator.js +100 -1
- package/packages/client/dist/resilience/index.js +8 -1
- package/packages/client/dist/resilience/recovery-detector.js +74 -1
- package/packages/client/dist/resolvers/asset-resolver.js +13 -0
- package/packages/client/dist/resolvers/local-resolver.js +255 -8
- package/packages/client/dist/resolvers/remote-resolver.js +233 -1
- package/packages/client/dist/runner/binary.js +404 -1
- package/packages/client/dist/runner/cli.js +1571 -17
- package/packages/client/dist/runner/epic-background-dispatcher.js +124 -1
- package/packages/client/dist/runner/headless/adapters.js +49 -1
- package/packages/client/dist/runner/headless/background-root.js +85 -1
- package/packages/client/dist/runner/headless/claude-code-adapter.js +79 -1
- package/packages/client/dist/runner/headless/continuous-story-workspace.js +1628 -11
- package/packages/client/dist/runner/headless/epic-git-reconciliation-inventory.js +69 -1
- package/packages/client/dist/runner/headless/epic-merge-candidate-qa.js +111 -2
- package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +1464 -10
- package/packages/client/dist/runner/headless/epic-terminal-git-runner.js +357 -2
- package/packages/client/dist/runner/headless/fake-adapter.js +62 -1
- package/packages/client/dist/runner/headless/managed-environment-cleanup.js +274 -1
- package/packages/client/dist/runner/headless/managed-profile.js +149 -1
- package/packages/client/dist/runner/headless/opencode-adapter.js +145 -2
- package/packages/client/dist/runner/headless/prepared-story-bundle.js +43 -1
- package/packages/client/dist/runner/headless/resolver.js +231 -1
- package/packages/client/dist/runner/headless/run-yolo.js +886 -1
- package/packages/client/dist/runner/headless/run-yoloop.js +2586 -2
- package/packages/client/dist/runner/headless/types.js +575 -2
- package/packages/client/dist/runner/host-capacity.js +59 -1
- package/packages/client/dist/runner/local-console.js +396 -13
- package/packages/client/dist/runner/portal-sync-worker.js +1487 -1
- package/packages/client/dist/runner/project-identity.js +106 -1
- package/packages/client/dist/runner/scheduler.js +995 -7
- package/packages/client/dist/runner-cli.js +18 -2
- package/packages/client/dist/state/invocation-shape.js +13 -1
- package/packages/client/dist/state/project-state-snapshot.js +1751 -1
- package/packages/client/dist/state/state-json-repair.js +785 -3
- package/packages/client/dist/state/structural-dag-projection.js +118 -1
- package/packages/client/dist/telemetry/index.js +5 -1
- package/packages/client/dist/telemetry/offline-queue.js +131 -1
- package/packages/client/dist/tier/index.js +5 -1
- package/packages/client/dist/tier/tier-aware-client.js +405 -1
- package/packages/client/dist/types/index.js +38 -1
- package/packages/client/dist/version.js +27 -1
- package/packages/client/dist/yolo/change-evidence-collector.d.ts +1 -1
- package/packages/client/dist/yolo/change-evidence-collector.js +245 -1
- package/packages/client/dist/yolo/invoke-envelope-capability.js +62 -1
- package/packages/client/dist/yolo/spec-envelope-collector.js +184 -5
- package/packages/client/dist/yoloop/discovery-hook.js +300 -2
- package/packages/client/dist/yoloop/index.js +8 -1
- package/packages/client/dist/yoloop/invoke-hooks.js +669 -12
- package/packages/client/dist/yoloop/shared-discover-epics.js +1007 -1
- package/packages/client/dist/yoloop/shared-yoloop-types.js +33 -1
- package/packages/client/dist/yoloop/target-normalization.js +180 -1
- package/packages/client/dist/yoloop/yoloop-client-state-store.js +1920 -1
- package/packages/shared/dist/yoloop/epic-terminal-git.js +12 -0
- package/targets-stubs/antigravity/gemini.md +1 -1
- package/targets-stubs/antigravity/skill/SKILL.md +1 -1
- package/targets-stubs/claude-code/neocortex-root.agent.yaml +1 -1
- package/targets-stubs/claude-code/neocortex-root.md +2 -2
- package/targets-stubs/claude-code/neocortex.agent.yaml +1 -1
- package/targets-stubs/claude-code/neocortex.md +2 -2
- package/targets-stubs/codex/AGENTS.md +1 -1
- package/targets-stubs/cursor/agent.md +2 -2
- package/targets-stubs/gemini-cli/agent.md +2 -2
- package/targets-stubs/opencode/neocortex-root.md +1 -1
- package/targets-stubs/vscode/neocortex.agent.md +2 -2
|
@@ -1 +1,103 @@
|
|
|
1
|
-
|
|
1
|
+
/** Root-owned read-only inspection after a private property-test candidate is applied. */
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { lstatSync, readFileSync } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
6
|
+
import { mutationQaGit } from '../commands/mutation-qa-git.js';
|
|
7
|
+
import { loadPropertyTestCandidatePlan } from './property-test-choices.js';
|
|
8
|
+
import { inspectPropertyTestCatalog, renderPropertyTestConfiguration } from './property-test-plan.js';
|
|
9
|
+
import { validatePropertyTestTypeScriptSource } from './property-test-source.js';
|
|
10
|
+
function digest(value) {
|
|
11
|
+
return createHash('sha256').update(value).digest('hex');
|
|
12
|
+
}
|
|
13
|
+
function regularBytes(root, relative) {
|
|
14
|
+
let current = root;
|
|
15
|
+
const parts = relative.split('/');
|
|
16
|
+
if (parts.some((part) => !/^[A-Za-z0-9_.-]+$/.test(part) || part === '.' || part === '..')) {
|
|
17
|
+
throw new Error('property-test-candidate-path-invalid');
|
|
18
|
+
}
|
|
19
|
+
for (const [index, part] of parts.entries()) {
|
|
20
|
+
current = join(current, part);
|
|
21
|
+
const stat = lstatSync(current);
|
|
22
|
+
if (stat.isSymbolicLink() || (index === parts.length - 1
|
|
23
|
+
? !stat.isFile() || stat.size < 1 || stat.size > 2_000_000 : !stat.isDirectory())) {
|
|
24
|
+
throw new Error('property-test-candidate-path-invalid');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return readFileSync(current);
|
|
28
|
+
}
|
|
29
|
+
function status(root) {
|
|
30
|
+
return mutationQaGit(root, ['status', '--porcelain=v1', '-z', '--untracked-files=all'])
|
|
31
|
+
.toString('utf8').split('\0').filter(Boolean).sort();
|
|
32
|
+
}
|
|
33
|
+
/** No test execution, state write or semantic QA; only exact physical candidate bytes. */
|
|
34
|
+
export function inspectPropertyTestCandidate(projectRoot) {
|
|
35
|
+
try {
|
|
36
|
+
const { root, head, choices, plan } = loadPropertyTestCandidatePlan(projectRoot);
|
|
37
|
+
if (plan.schemaVersion !== 1 || !['prd.md', 'docs/architecture/prd.md'].includes(plan.prdPath)
|
|
38
|
+
|| plan.planSha256.length !== 64 || plan.writeSet.length < 1
|
|
39
|
+
|| plan.writeSet.length !== plan.aggregates.length
|
|
40
|
+
|| plan.checkpointAccepted !== false || plan.publicSafe !== true
|
|
41
|
+
|| plan.prdSha256 !== choices.prdSha256 || plan.language !== choices.language
|
|
42
|
+
|| plan.numRuns !== choices.numRuns || plan.aggregates.some((item) => choices.mappings[item.name] !== item.implementationFile
|
|
43
|
+
|| !Number.isSafeInteger(item.invariantCount) || item.invariantCount < 1)
|
|
44
|
+
|| !isDeepStrictEqual(plan.writeSet, plan.aggregates.map((item) => item.testFile).sort())) {
|
|
45
|
+
throw new Error('property-test-candidate-plan-invalid');
|
|
46
|
+
}
|
|
47
|
+
const { planSha256: _sha, checkpointAccepted: _checkpoint, publicSafe: _publicSafe, ...basis } = plan;
|
|
48
|
+
if (digest(JSON.stringify(basis)) !== plan.planSha256) {
|
|
49
|
+
throw new Error('property-test-candidate-plan-invalid');
|
|
50
|
+
}
|
|
51
|
+
const catalog = inspectPropertyTestCatalog(root);
|
|
52
|
+
if (catalog.prdPath !== plan.prdPath || !isDeepStrictEqual(catalog.aggregates.map(({ name, invariantCount }) => ({ name, invariantCount })), plan.aggregates.map(({ name, invariantCount }) => ({ name, invariantCount }))))
|
|
53
|
+
throw new Error('property-test-candidate-plan-invalid');
|
|
54
|
+
const trackedPrd = mutationQaGit(root, ['show', `HEAD:${plan.prdPath}`]);
|
|
55
|
+
if (digest(trackedPrd) !== plan.prdSha256)
|
|
56
|
+
throw new Error('property-test-candidate-preimage-drift');
|
|
57
|
+
const currentPrd = regularBytes(root, plan.prdPath);
|
|
58
|
+
const currentText = new TextDecoder('utf-8', { fatal: true }).decode(currentPrd);
|
|
59
|
+
const dates = [...currentText.matchAll(/^- Generated at: (\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)$/gm)];
|
|
60
|
+
if (dates.length !== 1 || currentText.split('## Property Test Configuration').length !== 2
|
|
61
|
+
|| currentText !== renderPropertyTestConfiguration(new TextDecoder('utf-8', { fatal: true }).decode(trackedPrd), plan, dates[0][1])) {
|
|
62
|
+
throw new Error('property-test-candidate-prd-invalid');
|
|
63
|
+
}
|
|
64
|
+
const expectedPaths = [plan.prdPath, ...plan.writeSet].sort();
|
|
65
|
+
const before = status(root);
|
|
66
|
+
if (!isDeepStrictEqual(before.map((entry) => entry.slice(3)).sort(), expectedPaths)
|
|
67
|
+
|| before.some((entry) => ![' M ', '?? '].includes(entry.slice(0, 3)))) {
|
|
68
|
+
throw new Error('property-test-candidate-scope-invalid');
|
|
69
|
+
}
|
|
70
|
+
const artifacts = [[plan.prdPath, digest(currentPrd)]];
|
|
71
|
+
for (const item of plan.aggregates) {
|
|
72
|
+
const implementation = regularBytes(root, item.implementationFile);
|
|
73
|
+
if (digest(implementation) !== item.implementationSha256) {
|
|
74
|
+
throw new Error('property-test-candidate-preimage-drift');
|
|
75
|
+
}
|
|
76
|
+
const source = new TextDecoder('utf-8', { fatal: true })
|
|
77
|
+
.decode(regularBytes(root, item.testFile));
|
|
78
|
+
if (plan.language === 'typescript') {
|
|
79
|
+
validatePropertyTestTypeScriptSource({ source, testFile: item.testFile,
|
|
80
|
+
implementationFile: item.implementationFile, invariantCount: item.invariantCount,
|
|
81
|
+
numRuns: plan.numRuns });
|
|
82
|
+
}
|
|
83
|
+
else if ((source.match(/^def\s+test_[A-Za-z0-9_]+\s*\(/gm) ?? []).length < item.invariantCount
|
|
84
|
+
|| !source.includes(String(plan.numRuns))) {
|
|
85
|
+
throw new Error('property-test-candidate-source-invalid');
|
|
86
|
+
}
|
|
87
|
+
artifacts.push([item.testFile, digest(source)]);
|
|
88
|
+
}
|
|
89
|
+
if (mutationQaGit(root, ['rev-parse', '--verify', 'HEAD']).toString('utf8').trim() !== head
|
|
90
|
+
|| !isDeepStrictEqual(status(root), before)
|
|
91
|
+
|| artifacts.some(([path, sha]) => digest(regularBytes(root, path)) !== sha)) {
|
|
92
|
+
throw new Error('property-test-candidate-physical-drift');
|
|
93
|
+
}
|
|
94
|
+
return Object.freeze({ schemaVersion: 1, kind: 'property-test-candidate-inspection',
|
|
95
|
+
sourceHead: head, planSha256: plan.planSha256,
|
|
96
|
+
artifactSha256: digest(`property-test-candidate-v1\0${JSON.stringify(artifacts)}`),
|
|
97
|
+
testFileCount: plan.writeSet.length, sourceSyntaxChecked: plan.language === 'typescript',
|
|
98
|
+
executionVerified: false, qaAccepted: false, publicSafe: true });
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
throw new Error('property-test-candidate-unverified');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -1,3 +1,147 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/** Private, root-owned operator choices for one plan-bound property-test run. */
|
|
2
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
3
|
+
import { closeSync, existsSync, fsyncSync, lstatSync, mkdirSync, openSync, readFileSync, realpathSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { isAbsolute, join, resolve } from 'node:path';
|
|
5
|
+
import { confirmPropertyTestPlan } from './property-test-plan.js';
|
|
6
|
+
import { mutationQaGit } from '../commands/mutation-qa-git.js';
|
|
7
|
+
function digest(value) {
|
|
8
|
+
return createHash('sha256').update(value).digest('hex');
|
|
9
|
+
}
|
|
10
|
+
function git(root, args) {
|
|
11
|
+
return mutationQaGit(root, args).toString('utf8').trim();
|
|
12
|
+
}
|
|
13
|
+
function context(projectRoot, create) {
|
|
14
|
+
const root = resolve(projectRoot);
|
|
15
|
+
const top = git(root, ['rev-parse', '--show-toplevel']);
|
|
16
|
+
const head = git(root, ['rev-parse', '--verify', 'HEAD']);
|
|
17
|
+
const commonRaw = git(root, ['rev-parse', '--git-common-dir']);
|
|
18
|
+
const common = isAbsolute(commonRaw) ? resolve(commonRaw) : resolve(root, commonRaw);
|
|
19
|
+
if (realpathSync(root) !== root || resolve(top) !== root
|
|
20
|
+
|| !/^[a-f0-9]{40,64}$/.test(head)
|
|
21
|
+
|| realpathSync(common) !== common || lstatSync(common).isSymbolicLink()
|
|
22
|
+
|| lstatSync(common).uid !== process.getuid?.()) {
|
|
23
|
+
throw new Error('property-test-private-store-invalid');
|
|
24
|
+
}
|
|
25
|
+
const directory = join(common, 'neocortex-property-test');
|
|
26
|
+
if (create)
|
|
27
|
+
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
28
|
+
if (existsSync(directory)) {
|
|
29
|
+
const entry = lstatSync(directory);
|
|
30
|
+
if (!entry.isDirectory() || entry.isSymbolicLink()
|
|
31
|
+
|| entry.uid !== process.getuid?.() || (entry.mode & 0o077) !== 0) {
|
|
32
|
+
throw new Error('property-test-private-store-invalid');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return { root, directory, head };
|
|
36
|
+
}
|
|
37
|
+
function recordFor(head, choices, plan) {
|
|
38
|
+
const normalized = {
|
|
39
|
+
prdSha256: choices.prdSha256, language: choices.language, numRuns: choices.numRuns,
|
|
40
|
+
mappings: Object.fromEntries(Object.entries(choices.mappings).sort(([a], [b]) => a.localeCompare(b))),
|
|
41
|
+
};
|
|
42
|
+
const payload = { schemaVersion: 'PropertyTestChoices/2',
|
|
43
|
+
sourceHead: head, choices: normalized, planSha256: plan.planSha256, plan };
|
|
44
|
+
return { ...payload, checksumSha256: digest(`property-test-choices-v2\0${JSON.stringify(payload)}`) };
|
|
45
|
+
}
|
|
46
|
+
function readRecord(path) {
|
|
47
|
+
const entry = lstatSync(path);
|
|
48
|
+
if (!entry.isFile() || entry.isSymbolicLink() || entry.uid !== process.getuid?.()
|
|
49
|
+
|| (entry.mode & 0o077) !== 0 || entry.size < 1 || entry.size > 32_768) {
|
|
50
|
+
throw new Error('property-test-private-store-invalid');
|
|
51
|
+
}
|
|
52
|
+
const raw = readFileSync(path, 'utf8');
|
|
53
|
+
const value = JSON.parse(raw);
|
|
54
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
55
|
+
throw new Error('property-test-private-store-invalid');
|
|
56
|
+
}
|
|
57
|
+
const record = value;
|
|
58
|
+
const v2 = record.schemaVersion === 'PropertyTestChoices/2';
|
|
59
|
+
if (Object.keys(record).sort().join(',') !== ['schemaVersion', 'sourceHead',
|
|
60
|
+
'choices', 'planSha256', ...(v2 ? ['plan'] : []), 'checksumSha256'].sort().join(',')
|
|
61
|
+
|| !['PropertyTestChoices/1', 'PropertyTestChoices/2'].includes(String(record.schemaVersion))
|
|
62
|
+
|| typeof record.sourceHead !== 'string' || !/^[a-f0-9]{40,64}$/.test(record.sourceHead)
|
|
63
|
+
|| typeof record.planSha256 !== 'string' || !/^[a-f0-9]{64}$/.test(record.planSha256)
|
|
64
|
+
|| typeof record.checksumSha256 !== 'string' || !/^[a-f0-9]{64}$/.test(record.checksumSha256)
|
|
65
|
+
|| !record.choices || typeof record.choices !== 'object' || Array.isArray(record.choices)
|
|
66
|
+
|| v2 && (!record.plan || typeof record.plan !== 'object' || Array.isArray(record.plan)
|
|
67
|
+
|| record.plan.planSha256 !== record.planSha256)) {
|
|
68
|
+
throw new Error('property-test-private-store-invalid');
|
|
69
|
+
}
|
|
70
|
+
const payload = { schemaVersion: record.schemaVersion, sourceHead: record.sourceHead,
|
|
71
|
+
choices: record.choices, planSha256: record.planSha256,
|
|
72
|
+
...(v2 ? { plan: record.plan } : {}) };
|
|
73
|
+
if (record.checksumSha256 !== digest(`property-test-choices-v${v2 ? '2' : '1'}\0${JSON.stringify(payload)}`)
|
|
74
|
+
|| raw !== `${JSON.stringify(record)}\n`)
|
|
75
|
+
throw new Error('property-test-private-store-invalid');
|
|
76
|
+
return record;
|
|
77
|
+
}
|
|
78
|
+
/** Save an explicit local choice, replacing only this private record. No tracked file is touched. */
|
|
79
|
+
export function savePropertyTestChoices(projectRoot, choices) {
|
|
80
|
+
const { root, directory, head } = context(projectRoot, true);
|
|
81
|
+
const plan = confirmPropertyTestPlan(root, choices);
|
|
82
|
+
const record = recordFor(head, choices, plan);
|
|
83
|
+
const target = join(directory, 'choices.json');
|
|
84
|
+
if (existsSync(target)) {
|
|
85
|
+
const previous = readRecord(target);
|
|
86
|
+
if (JSON.stringify(previous) === JSON.stringify(record))
|
|
87
|
+
return plan;
|
|
88
|
+
}
|
|
89
|
+
const temporary = join(directory, `choices-${randomUUID()}.tmp`);
|
|
90
|
+
const handle = openSync(temporary, 'wx', 0o600);
|
|
91
|
+
try {
|
|
92
|
+
writeFileSync(handle, `${JSON.stringify(record)}\n`);
|
|
93
|
+
fsyncSync(handle);
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
closeSync(handle);
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
if (git(root, ['rev-parse', '--verify', 'HEAD']) !== head
|
|
100
|
+
|| confirmPropertyTestPlan(root, choices).planSha256 !== plan.planSha256) {
|
|
101
|
+
throw new Error('property-test-choices-stale');
|
|
102
|
+
}
|
|
103
|
+
renameSync(temporary, target);
|
|
104
|
+
const directoryHandle = openSync(directory, 'r');
|
|
105
|
+
try {
|
|
106
|
+
fsyncSync(directoryHandle);
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
closeSync(directoryHandle);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
if (existsSync(temporary))
|
|
114
|
+
unlinkSync(temporary);
|
|
115
|
+
}
|
|
116
|
+
return plan;
|
|
117
|
+
}
|
|
118
|
+
/** Load only a plan still bound to the current physical HEAD and file preimages. */
|
|
119
|
+
export function loadPropertyTestChoices(projectRoot) {
|
|
120
|
+
const { root, directory, head } = context(projectRoot, false);
|
|
121
|
+
if (!existsSync(directory))
|
|
122
|
+
return undefined;
|
|
123
|
+
const target = join(directory, 'choices.json');
|
|
124
|
+
if (!existsSync(target))
|
|
125
|
+
return undefined;
|
|
126
|
+
const record = readRecord(target);
|
|
127
|
+
if (record.sourceHead !== head)
|
|
128
|
+
throw new Error('property-test-choices-stale');
|
|
129
|
+
const plan = confirmPropertyTestPlan(root, record.choices);
|
|
130
|
+
if (plan.planSha256 !== record.planSha256)
|
|
131
|
+
throw new Error('property-test-choices-stale');
|
|
132
|
+
if (record.plan && JSON.stringify(record.plan) !== JSON.stringify(plan)) {
|
|
133
|
+
throw new Error('property-test-choices-stale');
|
|
134
|
+
}
|
|
135
|
+
return { choices: record.choices, plan };
|
|
136
|
+
}
|
|
137
|
+
/** A v2 plan remains readable after its authorized PRD/test patch; no acceptance is inferred. */
|
|
138
|
+
export function loadPropertyTestCandidatePlan(projectRoot) {
|
|
139
|
+
const { root, directory, head } = context(projectRoot, false);
|
|
140
|
+
const target = join(directory, 'choices.json');
|
|
141
|
+
if (!existsSync(target))
|
|
142
|
+
throw new Error('property-test-choices-missing');
|
|
143
|
+
const record = readRecord(target);
|
|
144
|
+
if (record.sourceHead !== head || !record.plan)
|
|
145
|
+
throw new Error('property-test-choices-stale');
|
|
146
|
+
return { root, head, choices: record.choices, plan: record.plan };
|
|
147
|
+
}
|
|
@@ -1,7 +1,271 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Root-owned, local-only preflight for the protected property-test command.
|
|
3
|
+
* This module never emits PRD expressions or generated workflow bytes. It is
|
|
4
|
+
* not a private-execution grant and does not accept a QA checkpoint.
|
|
5
|
+
*/
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
7
|
+
import { lstatSync, readFileSync, realpathSync } from 'node:fs';
|
|
8
|
+
import { join, relative, resolve, sep } from 'node:path';
|
|
9
|
+
const PRD_PATHS = ['prd.md', 'docs/architecture/prd.md'];
|
|
10
|
+
const TYPES = new Set(['Range', 'Cardinality', 'SumEquality', 'Format', 'Temporal']);
|
|
11
|
+
const AGGREGATE = /^[A-Z][A-Za-z0-9]{0,79}$/;
|
|
12
|
+
const SHA256 = /^[a-f0-9]{64}$/;
|
|
13
|
+
function digest(value) {
|
|
14
|
+
return createHash('sha256').update(value).digest('hex');
|
|
15
|
+
}
|
|
16
|
+
function safeFile(root, path) {
|
|
17
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._/-]{0,255}$/.test(path)
|
|
18
|
+
|| path.split('/').some((part) => part === '.' || part === '..' || part.length === 0)) {
|
|
19
|
+
throw new Error('property-test-invalid-path');
|
|
20
|
+
}
|
|
21
|
+
const absolute = resolve(root, path);
|
|
22
|
+
const rel = relative(root, absolute);
|
|
23
|
+
if (rel.startsWith(`..${sep}`) || rel === '..' || rel === '')
|
|
24
|
+
throw new Error('property-test-path-escape');
|
|
25
|
+
let current = root;
|
|
26
|
+
for (const part of path.split('/')) {
|
|
27
|
+
current = join(current, part);
|
|
28
|
+
const stat = lstatSync(current);
|
|
29
|
+
if (stat.isSymbolicLink())
|
|
30
|
+
throw new Error('property-test-symlink');
|
|
31
|
+
}
|
|
32
|
+
if (!lstatSync(absolute).isFile())
|
|
33
|
+
throw new Error('property-test-not-regular');
|
|
34
|
+
return absolute;
|
|
35
|
+
}
|
|
36
|
+
function slug(name) {
|
|
37
|
+
return name.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
|
|
38
|
+
}
|
|
39
|
+
function tableCells(line) {
|
|
40
|
+
const cells = [];
|
|
41
|
+
let cell = '';
|
|
42
|
+
for (let index = 1; index < line.length - 1; index++) {
|
|
43
|
+
const char = line[index];
|
|
44
|
+
if (char === '\\' && line[index + 1] === '|') {
|
|
45
|
+
cell += '|';
|
|
46
|
+
index++;
|
|
47
|
+
}
|
|
48
|
+
else if (char === '|') {
|
|
49
|
+
cells.push(cell.trim());
|
|
50
|
+
cell = '';
|
|
51
|
+
}
|
|
52
|
+
else
|
|
53
|
+
cell += char;
|
|
54
|
+
}
|
|
55
|
+
cells.push(cell.trim());
|
|
56
|
+
return cells;
|
|
57
|
+
}
|
|
58
|
+
function testPreimageSha256(root, path) {
|
|
59
|
+
let current = root;
|
|
60
|
+
for (const part of path.split('/')) {
|
|
61
|
+
current = join(current, part);
|
|
62
|
+
try {
|
|
63
|
+
const stat = lstatSync(current);
|
|
64
|
+
if (stat.isSymbolicLink())
|
|
65
|
+
throw new Error('property-test-symlink');
|
|
66
|
+
if (current === join(root, path) && !stat.isFile())
|
|
67
|
+
throw new Error('property-test-invalid-destination');
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
if (error.code === 'ENOENT')
|
|
71
|
+
return null;
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return digest(readFileSync(current));
|
|
76
|
+
}
|
|
77
|
+
function parseCatalog(markdown) {
|
|
78
|
+
const lines = markdown.split(/\r?\n/);
|
|
79
|
+
const start = lines.findIndex((line) => /^## Aggregate Invariants\s*$/.test(line));
|
|
80
|
+
if (start < 0)
|
|
81
|
+
throw new Error('property-test-no-invariants-section');
|
|
82
|
+
const counts = new Map();
|
|
83
|
+
const rows = [];
|
|
84
|
+
let sectionAggregate;
|
|
85
|
+
let header;
|
|
86
|
+
for (const line of lines.slice(start + 1)) {
|
|
87
|
+
if (/^##\s/.test(line))
|
|
88
|
+
break;
|
|
89
|
+
const heading = /^###\s+(.+?)\s*$/.exec(line);
|
|
90
|
+
if (heading) {
|
|
91
|
+
sectionAggregate = heading[1];
|
|
92
|
+
if (!AGGREGATE.test(sectionAggregate))
|
|
93
|
+
throw new Error('property-test-invalid-aggregate');
|
|
94
|
+
header = undefined;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (!line.startsWith('|') || !line.endsWith('|'))
|
|
98
|
+
continue;
|
|
99
|
+
const cells = tableCells(line);
|
|
100
|
+
if (cells.every((cell) => /^:?-{3,}:?$/.test(cell)))
|
|
101
|
+
continue;
|
|
102
|
+
if (cells.includes('Expression') && cells.includes('Type')) {
|
|
103
|
+
header = cells;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (!header || cells.length !== header.length)
|
|
107
|
+
throw new Error('property-test-invalid-table');
|
|
108
|
+
const columns = header;
|
|
109
|
+
const field = (key) => cells[columns.indexOf(key)] ?? '';
|
|
110
|
+
const aggregate = sectionAggregate ?? field('Aggregate');
|
|
111
|
+
if (!AGGREGATE.test(aggregate) || !field('Expression') || !TYPES.has(field('Type'))
|
|
112
|
+
|| !field('Description') || (sectionAggregate && field('Aggregate') && field('Aggregate') !== sectionAggregate)) {
|
|
113
|
+
throw new Error('property-test-invalid-invariant');
|
|
114
|
+
}
|
|
115
|
+
const ordinal = (counts.get(aggregate) ?? 0) + 1;
|
|
116
|
+
counts.set(aggregate, ordinal);
|
|
117
|
+
rows.push(Object.freeze({ aggregate, ordinal,
|
|
118
|
+
invariantSha256: digest(`property-test-invariant-v1\0${JSON.stringify({
|
|
119
|
+
aggregate, ordinal, expression: field('Expression'), type: field('Type'),
|
|
120
|
+
description: field('Description'),
|
|
121
|
+
})}`),
|
|
122
|
+
}));
|
|
123
|
+
if (counts.size > 64 || [...counts.values()].reduce((sum, count) => sum + count, 0) > 1024) {
|
|
124
|
+
throw new Error('property-test-catalog-too-large');
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (counts.size === 0)
|
|
128
|
+
throw new Error('property-test-no-aggregates');
|
|
129
|
+
return { counts, rows };
|
|
130
|
+
}
|
|
131
|
+
/** Closed identifiers for root semantic review; the PRD text stays local. */
|
|
132
|
+
export function propertyTestInvariantRefs(markdown) {
|
|
133
|
+
return parseCatalog(markdown).rows;
|
|
134
|
+
}
|
|
135
|
+
function readCatalog(projectRoot) {
|
|
136
|
+
const root = realpathSync(projectRoot);
|
|
137
|
+
const matches = [];
|
|
138
|
+
for (const path of PRD_PATHS) {
|
|
139
|
+
let markdown;
|
|
140
|
+
let bytes;
|
|
141
|
+
try {
|
|
142
|
+
bytes = readFileSync(safeFile(root, path));
|
|
143
|
+
markdown = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
if (error.code === 'ENOENT')
|
|
147
|
+
continue;
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
if (bytes.length > 2_000_000)
|
|
151
|
+
throw new Error('property-test-prd-too-large');
|
|
152
|
+
if (!/^## Aggregate Invariants\s*$/m.test(markdown))
|
|
153
|
+
continue;
|
|
154
|
+
matches.push({ path, sha: digest(bytes), counts: parseCatalog(markdown).counts });
|
|
155
|
+
}
|
|
156
|
+
if (matches.length !== 1)
|
|
157
|
+
throw new Error(matches.length ? 'property-test-ambiguous-prd' : 'property-test-no-invariants-section');
|
|
158
|
+
return { root, ...matches[0] };
|
|
159
|
+
}
|
|
160
|
+
function suggestedFiles(root, name) {
|
|
161
|
+
const lower = slug(name);
|
|
162
|
+
const candidates = [
|
|
163
|
+
`src/domain/${lower}.ts`, `src/aggregates/${lower}.ts`, `src/${lower}.ts`,
|
|
164
|
+
`src/domain/${lower.replaceAll('-', '_')}.py`, `aggregates/${lower.replaceAll('-', '_')}.py`,
|
|
165
|
+
];
|
|
166
|
+
return candidates.filter((path) => {
|
|
167
|
+
try {
|
|
168
|
+
safeFile(root, path);
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
export function inspectPropertyTestCatalog(projectRoot) {
|
|
177
|
+
const source = readCatalog(projectRoot);
|
|
178
|
+
const aggregates = [...source.counts].sort(([a], [b]) => a.localeCompare(b)).map(([name, invariantCount]) => ({
|
|
179
|
+
name, invariantCount, suggestedFiles: suggestedFiles(source.root, name),
|
|
180
|
+
}));
|
|
181
|
+
return {
|
|
182
|
+
schemaVersion: 1, prdPath: source.path, prdSha256: source.sha,
|
|
183
|
+
aggregates, invariantCount: aggregates.reduce((sum, item) => sum + item.invariantCount, 0),
|
|
184
|
+
publicSafe: true,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
export function confirmPropertyTestPlan(projectRoot, choices) {
|
|
188
|
+
const source = readCatalog(projectRoot);
|
|
189
|
+
if (!choices || !SHA256.test(choices.prdSha256) || choices.prdSha256 !== source.sha
|
|
190
|
+
|| !['typescript', 'python'].includes(choices.language)
|
|
191
|
+
|| ![100, 1000, 10000].includes(choices.numRuns)
|
|
192
|
+
|| !choices.mappings || typeof choices.mappings !== 'object' || Array.isArray(choices.mappings)
|
|
193
|
+
|| Object.keys(choices).sort().join('\0') !== ['language', 'mappings', 'numRuns', 'prdSha256'].join('\0')
|
|
194
|
+
|| Object.keys(choices.mappings).sort().join('\0') !== [...source.counts.keys()].sort().join('\0')) {
|
|
195
|
+
throw new Error('property-test-choices-mismatch');
|
|
196
|
+
}
|
|
197
|
+
const paths = new Set();
|
|
198
|
+
const aggregates = [...source.counts].sort(([a], [b]) => a.localeCompare(b)).map(([name, invariantCount]) => {
|
|
199
|
+
const implementationFile = choices.mappings[name];
|
|
200
|
+
if (typeof implementationFile !== 'string'
|
|
201
|
+
|| !/^(?:src|aggregates)\/[A-Za-z0-9_./-]+\.(?:ts|py)$/.test(implementationFile)
|
|
202
|
+
|| (choices.language === 'typescript' ? !implementationFile.endsWith('.ts') : !implementationFile.endsWith('.py'))) {
|
|
203
|
+
throw new Error('property-test-invalid-mapping');
|
|
204
|
+
}
|
|
205
|
+
const implementationSha256 = digest(readFileSync(safeFile(source.root, implementationFile)));
|
|
206
|
+
const stem = slug(name);
|
|
207
|
+
const testFile = choices.language === 'typescript'
|
|
208
|
+
? `tests/property/${stem}.property.test.ts`
|
|
209
|
+
: `tests/property/test_${stem.replaceAll('-', '_')}_properties.py`;
|
|
210
|
+
if (paths.has(testFile))
|
|
211
|
+
throw new Error('property-test-write-collision');
|
|
212
|
+
const testPreimage = testPreimageSha256(source.root, testFile);
|
|
213
|
+
paths.add(testFile);
|
|
214
|
+
return { name, invariantCount, implementationFile, implementationSha256,
|
|
215
|
+
testFile, testPreimageSha256: testPreimage };
|
|
216
|
+
});
|
|
217
|
+
const writeSet = [...paths].sort();
|
|
218
|
+
const basis = { schemaVersion: 1, prdPath: source.path, prdSha256: source.sha,
|
|
219
|
+
language: choices.language, numRuns: choices.numRuns, aggregates, writeSet };
|
|
220
|
+
return { ...basis, planSha256: digest(JSON.stringify(basis)), checkpointAccepted: false, publicSafe: true };
|
|
221
|
+
}
|
|
222
|
+
export function propertyTestExecutionInput(plan) {
|
|
223
|
+
if (!PRD_PATHS.includes(plan.prdPath)
|
|
224
|
+
|| !SHA256.test(plan.planSha256) || !SHA256.test(plan.prdSha256)
|
|
225
|
+
|| plan.aggregates.length < 1 || plan.aggregates.length > 64
|
|
226
|
+
|| plan.writeSet.length !== plan.aggregates.length
|
|
227
|
+
|| plan.aggregates.reduce((sum, item) => sum + item.invariantCount, 0) > 1024) {
|
|
228
|
+
throw new Error('property-test-plan-invalid');
|
|
229
|
+
}
|
|
230
|
+
return {
|
|
231
|
+
schemaVersion: 1,
|
|
232
|
+
prdPath: plan.prdPath,
|
|
233
|
+
prdSha256: plan.prdSha256,
|
|
234
|
+
planSha256: plan.planSha256,
|
|
235
|
+
pathsSha256: digest(JSON.stringify(plan.writeSet)),
|
|
236
|
+
aggregateCount: plan.aggregates.length,
|
|
237
|
+
invariantCount: plan.aggregates.reduce((sum, item) => sum + item.invariantCount, 0),
|
|
238
|
+
pathCount: plan.writeSet.length,
|
|
239
|
+
language: plan.language,
|
|
240
|
+
numRuns: plan.numRuns,
|
|
241
|
+
publicSafe: true,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/** Build root-owned PRD configuration bytes; no invariant expression leaves the local PRD. */
|
|
245
|
+
export function renderPropertyTestConfiguration(currentPrd, plan, generatedAt) {
|
|
246
|
+
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(generatedAt)
|
|
247
|
+
|| !Number.isFinite(Date.parse(generatedAt))
|
|
248
|
+
|| !SHA256.test(plan.planSha256)
|
|
249
|
+
|| digest(currentPrd) !== plan.prdSha256
|
|
250
|
+
|| /^## Property Test Configuration\s*$/m.test(currentPrd)
|
|
251
|
+
|| currentPrd.includes('\0')) {
|
|
252
|
+
throw new Error('property-test-configuration-conflict');
|
|
253
|
+
}
|
|
254
|
+
const newline = currentPrd.includes('\r\n') ? '\r\n' : '\n';
|
|
255
|
+
if (newline === '\r\n' && currentPrd.replaceAll('\r\n', '').includes('\n')) {
|
|
256
|
+
throw new Error('property-test-configuration-conflict');
|
|
257
|
+
}
|
|
258
|
+
const lines = [
|
|
259
|
+
'## Property Test Configuration', '',
|
|
260
|
+
`- Language: ${plan.language}`,
|
|
261
|
+
`- numRuns: ${plan.numRuns}`,
|
|
262
|
+
`- Generated at: ${generatedAt}`,
|
|
263
|
+
'- Step: property-test (P112.03)',
|
|
264
|
+
`- Confirmed plan SHA-256: ${plan.planSha256}`,
|
|
265
|
+
'', '| Aggregate | Implementation File | Invariants |',
|
|
266
|
+
'|---|---|---|',
|
|
267
|
+
...plan.aggregates.map((item) => `| ${item.name} | ${item.implementationFile} | ${item.invariantCount} |`),
|
|
268
|
+
'',
|
|
269
|
+
];
|
|
270
|
+
return `${currentPrd.replace(/(?:\r?\n)*$/, '')}${newline}${newline}${lines.join(newline)}`;
|
|
271
|
+
}
|