@ornexus/neocortex 4.60.68 → 4.60.69
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 +1194 -1194
- package/install.ps1 +1 -1
- package/install.sh +1 -1
- package/package.json +2 -2
- package/packages/client/dist/adapters/adapter-registry.js +1 -108
- package/packages/client/dist/adapters/antigravity-adapter.js +2 -77
- package/packages/client/dist/adapters/claude-code-adapter.js +3 -79
- package/packages/client/dist/adapters/codex-adapter.js +2 -80
- package/packages/client/dist/adapters/cursor-adapter.js +4 -115
- package/packages/client/dist/adapters/gemini-adapter.js +2 -71
- package/packages/client/dist/adapters/grok-adapter.js +2 -42
- package/packages/client/dist/adapters/index.js +1 -22
- package/packages/client/dist/adapters/platform-detector.js +1 -212
- package/packages/client/dist/adapters/target-adapter.js +0 -12
- package/packages/client/dist/adapters/vscode-adapter.js +2 -72
- package/packages/client/dist/agent/refresh-stubs.js +2 -417
- package/packages/client/dist/agent/update-agent-yaml.js +1 -102
- package/packages/client/dist/agent/update-description.js +1 -251
- package/packages/client/dist/cache/crypto-utils.js +1 -78
- package/packages/client/dist/cache/encrypted-cache.js +1 -108
- package/packages/client/dist/cache/in-memory-asset-cache.js +1 -73
- package/packages/client/dist/cache/index.js +1 -13
- package/packages/client/dist/cache/protected-pi-boundary.js +1 -44
- package/packages/client/dist/checkpoint/checkpoint-client-reader.js +2 -127
- package/packages/client/dist/checkpoint/index.js +1 -11
- package/packages/client/dist/checkpoint/shared-checkpoint-types.js +1 -32
- package/packages/client/dist/cli.js +3 -290
- package/packages/client/dist/commands/activate.js +8 -394
- package/packages/client/dist/commands/architecture-answers.js +7 -274
- package/packages/client/dist/commands/architecture-memory-terminal.js +4 -253
- package/packages/client/dist/commands/architecture-non-ui-continuation.js +1 -100
- package/packages/client/dist/commands/architecture-root-binding.js +1 -51
- package/packages/client/dist/commands/cache-status.js +2 -112
- package/packages/client/dist/commands/config.js +1 -88
- package/packages/client/dist/commands/doctor.js +2 -635
- package/packages/client/dist/commands/invoke.d.ts +6 -0
- package/packages/client/dist/commands/invoke.js +142 -7140
- package/packages/client/dist/commands/legacy-epic-terminal.js +1 -71
- package/packages/client/dist/commands/legacy-story-branch.js +1 -96
- package/packages/client/dist/commands/legacy-story-pr.js +1 -276
- package/packages/client/dist/commands/mutation-qa-checkpoint.js +5 -285
- package/packages/client/dist/commands/mutation-qa-gate.js +1 -54
- package/packages/client/dist/commands/mutation-qa-git.js +1 -41
- package/packages/client/dist/commands/mutation-qa-policy.js +1 -102
- package/packages/client/dist/commands/mutation-qa-run.js +3 -219
- package/packages/client/dist/commands/mutation-qa-verdict.js +1 -149
- package/packages/client/dist/commands/mutation-qa.js +1 -220
- package/packages/client/dist/commands/native-agent.js +2 -136
- package/packages/client/dist/commands/planning-diagnosis.js +1 -43
- package/packages/client/dist/commands/planning-generation.js +1 -53
- package/packages/client/dist/commands/planning-memory.js +1 -40
- package/packages/client/dist/commands/planning-research.js +1 -42
- package/packages/client/dist/commands/private-session.js +1 -75
- package/packages/client/dist/commands/property-qa.js +1 -139
- package/packages/client/dist/commands/qa-control.js +1 -16
- package/packages/client/dist/commands/qa-scan-browser-launch.js +1 -55
- package/packages/client/dist/commands/qa-scan-browser-route.js +1 -28
- package/packages/client/dist/commands/qa-scan-capture.js +5 -663
- package/packages/client/dist/commands/qa-scan-discovery.js +3 -376
- package/packages/client/dist/commands/qa-scan-review.js +5 -826
- package/packages/client/dist/commands/qa-synthetic-backend-capture.js +1 -266
- package/packages/client/dist/commands/qa-synthetic-backend-review.js +1 -297
- package/packages/client/dist/commands/qa-synthetic-backend.js +2 -340
- package/packages/client/dist/commands/qa-synthetic-broker-port.js +1 -85
- package/packages/client/dist/commands/qa-synthetic-browser.js +1 -39
- package/packages/client/dist/commands/refactor-characterization.js +21 -671
- package/packages/client/dist/commands/refactor-commit.js +13 -399
- package/packages/client/dist/commands/refactor-control.js +3 -142
- package/packages/client/dist/commands/refactor-cpp-assertions.js +3 -93
- package/packages/client/dist/commands/refactor-review.js +5 -283
- package/packages/client/dist/commands/refactor-root.js +7 -588
- package/packages/client/dist/commands/refresh-memory.js +3 -156
- package/packages/client/dist/commands/shared-architecture-non-ui.js +1 -24
- package/packages/client/dist/commands/story-checkpoint.js +1 -171
- package/packages/client/dist/config/profile-directory.js +1 -13
- package/packages/client/dist/config/resolver-selection.js +1 -278
- package/packages/client/dist/config/secure-config.js +12 -281
- package/packages/client/dist/config.js +2 -223
- package/packages/client/dist/constants.js +1 -25
- package/packages/client/dist/context/context-collector.js +2 -222
- package/packages/client/dist/context/context-sanitizer.js +1 -145
- package/packages/client/dist/continuity/autonomous-governance.js +1 -285
- package/packages/client/dist/continuity/continuity-client-state-store.js +1 -1587
- package/packages/client/dist/continuity/invoke-hooks.js +1 -129
- package/packages/client/dist/continuity/migrations/001-initial-schema.js +2 -12
- package/packages/client/dist/continuity/migrations/002-processing-output-summary-indexes.js +2 -12
- package/packages/client/dist/continuity/migrations/003-headless-execution-attempts.js +2 -12
- package/packages/client/dist/continuity/migrations/004-outbox-delivery-state.js +2 -12
- package/packages/client/dist/continuity/migrations/005-bounded-headless-queue.js +2 -12
- package/packages/client/dist/continuity/migrations/006-native-agent-dispatches.js +2 -10
- package/packages/client/dist/continuity/native-agent-store.js +1 -69
- package/packages/client/dist/continuity/native-agent-types.js +1 -90
- package/packages/client/dist/continuity/outbox.js +1 -117
- package/packages/client/dist/continuity/runner-bootstrap-policy.js +1 -172
- package/packages/client/dist/continuity/sqlite-store.js +81 -2536
- package/packages/client/dist/effects/invoke-effect-gateways.js +1 -62
- package/packages/client/dist/errors/error-messages.js +2 -228
- package/packages/client/dist/errors/frontmatter-diagnostics.js +1 -125
- package/packages/client/dist/evidence/collector.js +1 -347
- package/packages/client/dist/evidence/index.js +1 -1
- package/packages/client/dist/evidence/types.js +0 -2
- package/packages/client/dist/fs/atomic-state-replace.js +1 -152
- package/packages/client/dist/generated/command-registry.generated.js +1 -4076
- package/packages/client/dist/generated/public-projections.generated.js +1 -149
- package/packages/client/dist/git/direct-yolo-c01-retry.js +4 -138
- package/packages/client/dist/git/direct-yolo-checkpoint.js +4 -1234
- package/packages/client/dist/git/git-lifecycle-step-ids.js +1 -14
- package/packages/client/dist/git/git-lifecycle-store.js +9 -1938
- package/packages/client/dist/git/legacy-story-branch-checkpoint.js +9 -259
- package/packages/client/dist/git/legacy-story-branch-setup.js +4 -348
- package/packages/client/dist/git/legacy-story-pr.js +70 -3538
- package/packages/client/dist/git/secure-filesystem-boundary.js +5 -182
- package/packages/client/dist/graph-retrieval/pre-command-hook.js +1 -284
- package/packages/client/dist/graph-retrieval/shared-graph-retrieval-contract.js +1 -237
- package/packages/client/dist/i18n/first-run.js +2 -60
- package/packages/client/dist/index.js +1 -47
- package/packages/client/dist/invocation/invoke-input.js +1 -24
- package/packages/client/dist/license/index.js +1 -5
- package/packages/client/dist/license/license-client.js +1 -304
- package/packages/client/dist/machine/fingerprint.js +2 -163
- package/packages/client/dist/machine/index.js +1 -5
- package/packages/client/dist/memory/project-memory-path-scope.js +1 -62
- package/packages/client/dist/memory/project-memory-writer.js +40 -1007
- package/packages/client/dist/memory/shared-project-memory-types.js +2 -253
- package/packages/client/dist/migrations/project-identity-capability.js +1 -50
- package/packages/client/dist/migrations/project-identity.js +7 -493
- package/packages/client/dist/migrations/state-json.js +4 -344
- package/packages/client/dist/policy/architecture-policy.js +2 -184
- package/packages/client/dist/policy/index.js +1 -7
- package/packages/client/dist/policy/shared-policy-types.js +0 -38
- package/packages/client/dist/policy/subagent-approval-policy.js +1 -55
- package/packages/client/dist/private-execution/clean-baseline.js +2 -279
- package/packages/client/dist/private-execution/codex-executor.js +4 -574
- package/packages/client/dist/private-execution/codex-host-runtime.js +1 -137
- package/packages/client/dist/private-execution/codex-lifecycle-guard.js +1 -97
- package/packages/client/dist/private-execution/codex-scoped-permissions.js +1 -128
- package/packages/client/dist/private-execution/delivery.js +13 -410
- package/packages/client/dist/private-execution/diagnosis-root-review.js +2 -294
- package/packages/client/dist/private-execution/frozen-handoff.js +6 -19
- package/packages/client/dist/private-execution/implementation-validation.js +2 -106
- package/packages/client/dist/private-execution/isolated-admission.js +23 -1432
- package/packages/client/dist/private-execution/isolated-session.js +5 -725
- package/packages/client/dist/private-execution/isolated-workspace.js +1 -122
- package/packages/client/dist/private-execution/pact-consumer-runtime.js +3 -409
- package/packages/client/dist/private-execution/pact-test-source.js +1 -258
- package/packages/client/dist/private-execution/pact-toolchain.js +3 -290
- package/packages/client/dist/private-execution/pact-write-set.js +1 -172
- package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.js +5 -406
- package/packages/client/dist/private-execution/planning-generation-checkpoint.js +5 -462
- package/packages/client/dist/private-execution/planning-memory-checkpoint.js +3 -139
- package/packages/client/dist/private-execution/planning-research-checkpoint.js +4 -325
- package/packages/client/dist/private-execution/private-report-store.js +1 -42
- package/packages/client/dist/private-execution/property-test-candidate.js +1 -103
- package/packages/client/dist/private-execution/property-test-choices.js +3 -147
- package/packages/client/dist/private-execution/property-test-plan.js +7 -271
- package/packages/client/dist/private-execution/property-test-review.js +4 -258
- package/packages/client/dist/private-execution/property-test-runtime.js +9 -372
- package/packages/client/dist/private-execution/property-test-source.js +1 -139
- package/packages/client/dist/private-execution/root-checkpoint.js +1 -80
- package/packages/client/dist/private-execution/root-memory-git-evidence.js +3 -135
- package/packages/client/dist/private-execution/root-memory-recovery.js +1 -93
- package/packages/client/dist/private-execution/root-memory-request.js +1 -29
- package/packages/client/dist/private-execution/root-memory-scope.js +1 -178
- package/packages/client/dist/private-execution/root-memory-writer.js +1 -102
- package/packages/client/dist/private-execution/session-lease.js +1 -63
- package/packages/client/dist/private-execution/shared-private-admission-types.js +1 -50
- package/packages/client/dist/private-execution/shared-project-validation.js +1 -66
- package/packages/client/dist/private-execution/shared-root-memory-types.js +1 -61
- package/packages/client/dist/private-execution/ux-source-validation.js +1 -372
- package/packages/client/dist/private-execution/ux-write-set.js +2 -191
- package/packages/client/dist/resilience/circuit-breaker.js +1 -170
- package/packages/client/dist/resilience/degradation-manager.js +1 -164
- package/packages/client/dist/resilience/freshness-indicator.js +1 -100
- package/packages/client/dist/resilience/index.js +1 -8
- package/packages/client/dist/resilience/recovery-detector.js +1 -74
- package/packages/client/dist/resolvers/asset-resolver.js +0 -13
- package/packages/client/dist/resolvers/local-resolver.js +8 -255
- package/packages/client/dist/resolvers/remote-resolver.js +1 -233
- package/packages/client/dist/runner/binary.js +1 -404
- package/packages/client/dist/runner/cli.js +17 -1571
- package/packages/client/dist/runner/headless/adapters.js +1 -49
- package/packages/client/dist/runner/headless/claude-code-adapter.js +1 -79
- package/packages/client/dist/runner/headless/continuous-story-workspace.js +11 -1628
- package/packages/client/dist/runner/headless/epic-git-reconciliation-inventory.js +1 -69
- package/packages/client/dist/runner/headless/epic-merge-candidate-qa.js +2 -110
- package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +8 -1236
- package/packages/client/dist/runner/headless/epic-terminal-git-runner.js +2 -318
- package/packages/client/dist/runner/headless/fake-adapter.js +1 -62
- package/packages/client/dist/runner/headless/managed-profile.js +1 -132
- package/packages/client/dist/runner/headless/opencode-adapter.js +2 -145
- package/packages/client/dist/runner/headless/prepared-story-bundle.js +1 -43
- package/packages/client/dist/runner/headless/resolver.js +1 -231
- package/packages/client/dist/runner/headless/run-yolo.js +1 -885
- package/packages/client/dist/runner/headless/run-yoloop.js +2 -2574
- package/packages/client/dist/runner/headless/types.js +2 -574
- package/packages/client/dist/runner/local-console.js +13 -396
- package/packages/client/dist/runner/portal-sync-worker.js +1 -1487
- package/packages/client/dist/runner/project-identity.js +1 -106
- package/packages/client/dist/runner/scheduler.js +7 -995
- package/packages/client/dist/runner-cli.js +2 -18
- package/packages/client/dist/state/invocation-shape.js +1 -13
- package/packages/client/dist/state/project-state-snapshot.js +1 -1677
- package/packages/client/dist/state/state-json-repair.js +3 -785
- package/packages/client/dist/state/structural-dag-projection.js +1 -118
- package/packages/client/dist/telemetry/index.js +1 -5
- package/packages/client/dist/telemetry/offline-queue.js +1 -131
- package/packages/client/dist/tier/index.js +1 -5
- package/packages/client/dist/tier/tier-aware-client.js +1 -405
- package/packages/client/dist/types/index.js +1 -38
- package/packages/client/dist/version.js +1 -27
- package/packages/client/dist/yolo/change-evidence-collector.js +1 -126
- package/packages/client/dist/yolo/invoke-envelope-capability.js +1 -62
- package/packages/client/dist/yolo/spec-envelope-collector.js +5 -185
- package/packages/client/dist/yoloop/discovery-hook.js +2 -300
- package/packages/client/dist/yoloop/index.js +1 -8
- package/packages/client/dist/yoloop/invoke-hooks.js +12 -669
- package/packages/client/dist/yoloop/shared-discover-epics.js +1 -1007
- package/packages/client/dist/yoloop/shared-yoloop-types.js +1 -33
- package/packages/client/dist/yoloop/target-normalization.js +1 -180
- package/packages/client/dist/yoloop/yoloop-client-state-store.js +1 -1723
- 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,285 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { planMutationQa } from './mutation-qa.js';
|
|
7
|
-
import { runMutationQa } from './mutation-qa-run.js';
|
|
8
|
-
function context(projectRoot, create) {
|
|
9
|
-
const root = resolve(projectRoot);
|
|
10
|
-
const top = mutationQaGit(root, ['rev-parse', '--show-toplevel']).toString('utf8').trim();
|
|
11
|
-
const raw = mutationQaGit(root, ['rev-parse', '--git-common-dir']).toString('utf8').trim();
|
|
12
|
-
const common = isAbsolute(raw) ? resolve(raw) : resolve(root, raw);
|
|
13
|
-
if (realpathSync(root) !== root || top !== root || realpathSync(common) !== common
|
|
14
|
-
|| lstatSync(common).isSymbolicLink() || lstatSync(common).uid !== process.getuid?.()) {
|
|
15
|
-
throw new Error('mutation-qa-checkpoint-store-invalid');
|
|
16
|
-
}
|
|
17
|
-
const directory = join(common, 'neocortex-mutation-qa');
|
|
18
|
-
let created = false;
|
|
19
|
-
if (create && !lstatSync(directory, { throwIfNoEntry: false })) {
|
|
20
|
-
try {
|
|
21
|
-
mkdirSync(directory, { mode: 0o700 });
|
|
22
|
-
created = true;
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
if (error.code !== 'EEXIST')
|
|
26
|
-
throw error;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
const stat = lstatSync(directory, { throwIfNoEntry: false });
|
|
30
|
-
if (stat) {
|
|
31
|
-
if (!stat.isDirectory() || stat.isSymbolicLink() || stat.uid !== process.getuid?.()
|
|
32
|
-
|| (stat.mode & 0o077) !== 0)
|
|
33
|
-
throw new Error('mutation-qa-checkpoint-store-invalid');
|
|
34
|
-
}
|
|
35
|
-
if (created) {
|
|
36
|
-
const commonHandle = openSync(common, 'r');
|
|
37
|
-
try {
|
|
38
|
-
fsyncSync(commonHandle);
|
|
39
|
-
}
|
|
40
|
-
finally {
|
|
41
|
-
closeSync(commonHandle);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return { root, directory };
|
|
45
|
-
}
|
|
46
|
-
function checkedRecord(path) {
|
|
47
|
-
const stat = lstatSync(path);
|
|
48
|
-
if (!stat.isFile() || stat.isSymbolicLink() || stat.uid !== process.getuid?.()
|
|
49
|
-
|| (stat.mode & 0o077) !== 0 || stat.size < 1 || stat.size > 4096) {
|
|
50
|
-
throw new Error('mutation-qa-checkpoint-record-invalid');
|
|
51
|
-
}
|
|
52
|
-
const raw = readFileSync(path, 'utf8');
|
|
53
|
-
let parsed;
|
|
54
|
-
try {
|
|
55
|
-
parsed = JSON.parse(raw);
|
|
56
|
-
}
|
|
57
|
-
catch {
|
|
58
|
-
throw new Error('mutation-qa-checkpoint-record-invalid');
|
|
59
|
-
}
|
|
60
|
-
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
61
|
-
throw new Error('mutation-qa-checkpoint-record-invalid');
|
|
62
|
-
}
|
|
63
|
-
const record = parsed;
|
|
64
|
-
const { checksumSha256, ...payload } = record;
|
|
65
|
-
const expected = createHash('sha256').update(`mutation-qa-checkpoint-v1\0${JSON.stringify(payload)}`)
|
|
66
|
-
.digest('hex');
|
|
67
|
-
if (Object.keys(record).sort().join(',') !== [
|
|
68
|
-
'schemaVersion', 'kind', 'planSha256', 'headSha', 'baseSha', 'reportSha256',
|
|
69
|
-
'verdict', 'mutationScore', 'checkpointAccepted', 'qaPassed', 'localOnly', 'checksumSha256',
|
|
70
|
-
].sort().join(',') || record.schemaVersion !== 1 || record.kind !== 'mutation-qa-checkpoint'
|
|
71
|
-
|| typeof record.planSha256 !== 'string' || !/^[a-f0-9]{64}$/.test(record.planSha256)
|
|
72
|
-
|| typeof record.headSha !== 'string' || !/^[a-f0-9]{40,64}$/.test(record.headSha)
|
|
73
|
-
|| typeof record.baseSha !== 'string' || !/^[a-f0-9]{40,64}$/.test(record.baseSha)
|
|
74
|
-
|| typeof record.reportSha256 !== 'string' || !/^[a-f0-9]{64}$/.test(record.reportSha256)
|
|
75
|
-
|| !['passed', 'warned', 'failed'].includes(String(record.verdict))
|
|
76
|
-
|| typeof record.mutationScore !== 'number' || !Number.isFinite(record.mutationScore)
|
|
77
|
-
|| record.mutationScore < 0 || record.mutationScore > 100
|
|
78
|
-
|| record.checkpointAccepted !== true || record.qaPassed !== (record.verdict === 'passed')
|
|
79
|
-
|| record.localOnly !== true || checksumSha256 !== expected
|
|
80
|
-
|| raw !== `${JSON.stringify(record)}\n`) {
|
|
81
|
-
throw new Error('mutation-qa-checkpoint-record-invalid');
|
|
82
|
-
}
|
|
83
|
-
return record;
|
|
84
|
-
}
|
|
85
|
-
function checkedDebt(path) {
|
|
86
|
-
const stat = lstatSync(path);
|
|
87
|
-
if (!stat.isFile() || stat.isSymbolicLink() || stat.uid !== process.getuid?.()
|
|
88
|
-
|| (stat.mode & 0o077) !== 0 || stat.size < 1 || stat.size > 4096) {
|
|
89
|
-
throw new Error('mutation-qa-debt-record-invalid');
|
|
90
|
-
}
|
|
91
|
-
const raw = readFileSync(path, 'utf8');
|
|
92
|
-
let parsed;
|
|
93
|
-
try {
|
|
94
|
-
parsed = JSON.parse(raw);
|
|
95
|
-
}
|
|
96
|
-
catch {
|
|
97
|
-
throw new Error('mutation-qa-debt-record-invalid');
|
|
98
|
-
}
|
|
99
|
-
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
100
|
-
throw new Error('mutation-qa-debt-record-invalid');
|
|
101
|
-
}
|
|
102
|
-
const record = parsed;
|
|
103
|
-
const { checksumSha256, ...payload } = record;
|
|
104
|
-
const expected = createHash('sha256').update(`mutation-qa-debt-v1\0${JSON.stringify(payload)}`).digest('hex');
|
|
105
|
-
if (Object.keys(record).sort().join(',') !== [
|
|
106
|
-
'schemaVersion', 'kind', 'planSha256', 'headSha', 'status', 'reasonCode',
|
|
107
|
-
'runOutcome', 'owner', 'severity', 'publicSafe', 'localOnly', 'checksumSha256',
|
|
108
|
-
].sort().join(',') || record.schemaVersion !== 1 || record.kind !== 'mutation-qa-follow-up-debt'
|
|
109
|
-
|| typeof record.planSha256 !== 'string' || !/^[a-f0-9]{64}$/.test(record.planSha256)
|
|
110
|
-
|| typeof record.headSha !== 'string' || !/^[a-f0-9]{40,64}$/.test(record.headSha)
|
|
111
|
-
|| !['warned', 'unobserved'].includes(String(record.status))
|
|
112
|
-
|| record.reasonCode !== (record.status === 'warned'
|
|
113
|
-
? 'mutation-qa-warned' : 'mutation-qa-observation-missing')
|
|
114
|
-
|| !['not-run', 'skipped-no-files', 'skipped-stryker-missing',
|
|
115
|
-
'skipped-dependencies-unavailable', 'skipped-host-isolation-unavailable',
|
|
116
|
-
'skipped-stryker-error', 'verified'].includes(String(record.runOutcome))
|
|
117
|
-
|| record.owner !== 'root-qa'
|
|
118
|
-
|| record.severity !== (record.status === 'warned' ? 'P2' : 'P3')
|
|
119
|
-
|| record.publicSafe !== true || record.localOnly !== true
|
|
120
|
-
|| checksumSha256 !== expected || raw !== `${JSON.stringify(record)}\n`) {
|
|
121
|
-
throw new Error('mutation-qa-debt-record-invalid');
|
|
122
|
-
}
|
|
123
|
-
return record;
|
|
124
|
-
}
|
|
125
|
-
/** Persist optional-QA debt separately from the verdict before allowing root continuation. */
|
|
126
|
-
export function recordMutationQaFollowUpDebt(projectRoot, baseRef, planSha256, status, runOutcome, durableRoot) {
|
|
127
|
-
const plan = planMutationQa(projectRoot, baseRef);
|
|
128
|
-
if (plan.planSha256 !== planSha256)
|
|
129
|
-
throw new Error('mutation-qa-debt-plan-drift');
|
|
130
|
-
const checkpoint = readMutationQaCheckpoint(projectRoot, baseRef, planSha256);
|
|
131
|
-
if (status === 'warned' && (runOutcome !== 'verified' || checkpoint?.verdict !== 'warned')) {
|
|
132
|
-
throw new Error('mutation-qa-debt-run-invalid');
|
|
133
|
-
}
|
|
134
|
-
if (status === 'unobserved' && (plan.outcome !== 'ready' || checkpoint
|
|
135
|
-
|| !['skipped-stryker-missing', 'skipped-dependencies-unavailable',
|
|
136
|
-
'skipped-stryker-error'].includes(runOutcome))) {
|
|
137
|
-
throw new Error('mutation-qa-debt-run-invalid');
|
|
138
|
-
}
|
|
139
|
-
const { root, directory } = context(durableRoot ?? projectRoot, true);
|
|
140
|
-
if (durableRoot && mutationQaGit(root, ['rev-parse', '--verify', 'HEAD'])
|
|
141
|
-
.toString('utf8').trim() !== plan.baseSha) {
|
|
142
|
-
throw new Error('mutation-qa-debt-root-drift');
|
|
143
|
-
}
|
|
144
|
-
const payload = { schemaVersion: 1, kind: 'mutation-qa-follow-up-debt',
|
|
145
|
-
planSha256, headSha: plan.headSha, status,
|
|
146
|
-
reasonCode: status === 'warned' ? 'mutation-qa-warned'
|
|
147
|
-
: 'mutation-qa-observation-missing',
|
|
148
|
-
runOutcome, owner: 'root-qa',
|
|
149
|
-
severity: status === 'warned' ? 'P2' : 'P3',
|
|
150
|
-
publicSafe: true, localOnly: true };
|
|
151
|
-
const record = Object.freeze({ ...payload, checksumSha256: createHash('sha256')
|
|
152
|
-
.update(`mutation-qa-debt-v1\0${JSON.stringify(payload)}`).digest('hex') });
|
|
153
|
-
const target = join(directory, `debt-${planSha256}.json`);
|
|
154
|
-
if (lstatSync(target, { throwIfNoEntry: false })) {
|
|
155
|
-
const previous = checkedDebt(target);
|
|
156
|
-
if (JSON.stringify(previous) !== JSON.stringify(record))
|
|
157
|
-
throw new Error('mutation-qa-debt-conflict');
|
|
158
|
-
return previous;
|
|
159
|
-
}
|
|
160
|
-
const temporary = join(directory, `debt-${randomUUID()}.tmp`);
|
|
161
|
-
try {
|
|
162
|
-
const handle = openSync(temporary, 'wx', 0o600);
|
|
163
|
-
try {
|
|
164
|
-
writeFileSync(handle, `${JSON.stringify(record)}\n`);
|
|
165
|
-
fsyncSync(handle);
|
|
166
|
-
}
|
|
167
|
-
finally {
|
|
168
|
-
closeSync(handle);
|
|
169
|
-
}
|
|
170
|
-
if (planMutationQa(projectRoot, baseRef).planSha256 !== planSha256
|
|
171
|
-
|| (durableRoot && mutationQaGit(root, ['rev-parse', '--verify', 'HEAD'])
|
|
172
|
-
.toString('utf8').trim() !== plan.baseSha)) {
|
|
173
|
-
throw new Error('mutation-qa-debt-plan-drift');
|
|
174
|
-
}
|
|
175
|
-
try {
|
|
176
|
-
linkSync(temporary, target);
|
|
177
|
-
}
|
|
178
|
-
catch (error) {
|
|
179
|
-
if (error.code !== 'EEXIST')
|
|
180
|
-
throw error;
|
|
181
|
-
const previous = checkedDebt(target);
|
|
182
|
-
if (JSON.stringify(previous) !== JSON.stringify(record))
|
|
183
|
-
throw new Error('mutation-qa-debt-conflict');
|
|
184
|
-
}
|
|
185
|
-
const directoryHandle = openSync(directory, 'r');
|
|
186
|
-
try {
|
|
187
|
-
fsyncSync(directoryHandle);
|
|
188
|
-
}
|
|
189
|
-
finally {
|
|
190
|
-
closeSync(directoryHandle);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
finally {
|
|
194
|
-
if (lstatSync(temporary, { throwIfNoEntry: false }))
|
|
195
|
-
unlinkSync(temporary);
|
|
196
|
-
}
|
|
197
|
-
return record;
|
|
198
|
-
}
|
|
199
|
-
function recordMutationQaCheckpoint(projectRoot, baseRef, run) {
|
|
200
|
-
if (run.outcome !== 'verified' || !run.verdict
|
|
201
|
-
|| run.verdict.planSha256 !== run.planSha256 || run.verdict.checkpointAccepted !== false) {
|
|
202
|
-
throw new Error('mutation-qa-checkpoint-verdict-unavailable');
|
|
203
|
-
}
|
|
204
|
-
const plan = planMutationQa(projectRoot, baseRef);
|
|
205
|
-
if (plan.outcome !== 'ready' || plan.planSha256 !== run.planSha256
|
|
206
|
-
|| plan.headSha !== run.headSha)
|
|
207
|
-
throw new Error('mutation-qa-checkpoint-plan-drift');
|
|
208
|
-
const { root, directory } = context(projectRoot, true);
|
|
209
|
-
const payload = { schemaVersion: 1, kind: 'mutation-qa-checkpoint',
|
|
210
|
-
planSha256: plan.planSha256, headSha: plan.headSha, baseSha: plan.baseSha,
|
|
211
|
-
reportSha256: run.verdict.reportSha256, verdict: run.verdict.outcome,
|
|
212
|
-
mutationScore: run.verdict.mutationScore, checkpointAccepted: true,
|
|
213
|
-
qaPassed: run.verdict.outcome === 'passed', localOnly: true };
|
|
214
|
-
const record = Object.freeze({ ...payload, checksumSha256: createHash('sha256')
|
|
215
|
-
.update(`mutation-qa-checkpoint-v1\0${JSON.stringify(payload)}`).digest('hex') });
|
|
216
|
-
const target = join(directory, `${plan.planSha256}.json`);
|
|
217
|
-
if (lstatSync(target, { throwIfNoEntry: false })) {
|
|
218
|
-
const previous = checkedRecord(target);
|
|
219
|
-
if (JSON.stringify(previous) !== JSON.stringify(record)) {
|
|
220
|
-
throw new Error('mutation-qa-checkpoint-conflict');
|
|
221
|
-
}
|
|
222
|
-
return previous;
|
|
223
|
-
}
|
|
224
|
-
const temporary = join(directory, `checkpoint-${randomUUID()}.tmp`);
|
|
225
|
-
try {
|
|
226
|
-
const handle = openSync(temporary, 'wx', 0o600);
|
|
227
|
-
try {
|
|
228
|
-
writeFileSync(handle, `${JSON.stringify(record)}\n`);
|
|
229
|
-
fsyncSync(handle);
|
|
230
|
-
}
|
|
231
|
-
finally {
|
|
232
|
-
closeSync(handle);
|
|
233
|
-
}
|
|
234
|
-
if (planMutationQa(root, baseRef).planSha256 !== plan.planSha256) {
|
|
235
|
-
throw new Error('mutation-qa-checkpoint-plan-drift');
|
|
236
|
-
}
|
|
237
|
-
try {
|
|
238
|
-
linkSync(temporary, target);
|
|
239
|
-
}
|
|
240
|
-
catch (error) {
|
|
241
|
-
if (error.code !== 'EEXIST')
|
|
242
|
-
throw error;
|
|
243
|
-
const previous = checkedRecord(target);
|
|
244
|
-
if (JSON.stringify(previous) !== JSON.stringify(record)) {
|
|
245
|
-
throw new Error('mutation-qa-checkpoint-conflict');
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
const directoryHandle = openSync(directory, 'r');
|
|
249
|
-
try {
|
|
250
|
-
fsyncSync(directoryHandle);
|
|
251
|
-
}
|
|
252
|
-
finally {
|
|
253
|
-
closeSync(directoryHandle);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
finally {
|
|
257
|
-
if (lstatSync(temporary, { throwIfNoEntry: false }))
|
|
258
|
-
unlinkSync(temporary);
|
|
259
|
-
}
|
|
260
|
-
return record;
|
|
261
|
-
}
|
|
262
|
-
/** An authorized root run is the only producer; skips never create a checkpoint. */
|
|
263
|
-
export function runAndRecordMutationQa(projectRoot, baseRef, planSha256) {
|
|
264
|
-
const result = runMutationQa(projectRoot, baseRef, planSha256);
|
|
265
|
-
return result.outcome === 'verified'
|
|
266
|
-
? { result, checkpoint: recordMutationQaCheckpoint(projectRoot, baseRef, result) }
|
|
267
|
-
: { result };
|
|
268
|
-
}
|
|
269
|
-
/** Revalidate the exact physical plan before projecting a private checkpoint. */
|
|
270
|
-
export function readMutationQaCheckpoint(projectRoot, baseRef, planSha256) {
|
|
271
|
-
if (!/^[a-f0-9]{64}$/.test(planSha256))
|
|
272
|
-
throw new Error('mutation-qa-plan-digest-invalid');
|
|
273
|
-
const plan = planMutationQa(projectRoot, baseRef);
|
|
274
|
-
if (plan.planSha256 !== planSha256)
|
|
275
|
-
throw new Error('mutation-qa-checkpoint-plan-drift');
|
|
276
|
-
const { directory } = context(projectRoot, false);
|
|
277
|
-
const target = join(directory, `${planSha256}.json`);
|
|
278
|
-
if (!lstatSync(target, { throwIfNoEntry: false }))
|
|
279
|
-
return undefined;
|
|
280
|
-
const record = checkedRecord(target);
|
|
281
|
-
if (record.planSha256 !== planSha256 || record.headSha !== plan.headSha
|
|
282
|
-
|| record.baseSha !== plan.baseSha)
|
|
283
|
-
throw new Error('mutation-qa-checkpoint-plan-drift');
|
|
284
|
-
return record;
|
|
285
|
-
}
|
|
1
|
+
import{createHash as b,randomUUID as J}from"node:crypto";import{closeSync as S,fsyncSync as w,lstatSync as h,mkdirSync as D,openSync as k,readFileSync as x,realpathSync as A,linkSync as I,unlinkSync as j,writeFileSync as P}from"node:fs";import{isAbsolute as F,join as y,resolve as q}from"node:path";import{mutationQaGit as g}from"./mutation-qa-git.js";import{planMutationQa as v}from"./mutation-qa.js";import{runMutationQa as H}from"./mutation-qa-run.js";function E(n,o){const e=q(n),r=g(e,["rev-parse","--show-toplevel"]).toString("utf8").trim(),t=g(e,["rev-parse","--git-common-dir"]).toString("utf8").trim(),a=F(t)?q(t):q(e,t);if(A(e)!==e||r!==e||A(a)!==a||h(a).isSymbolicLink()||h(a).uid!==process.getuid?.())throw new Error("mutation-qa-checkpoint-store-invalid");const i=y(a,"neocortex-mutation-qa");let c=!1;if(o&&!h(i,{throwIfNoEntry:!1}))try{D(i,{mode:448}),c=!0}catch(s){if(s.code!=="EEXIST")throw s}const d=h(i,{throwIfNoEntry:!1});if(d&&(!d.isDirectory()||d.isSymbolicLink()||d.uid!==process.getuid?.()||(d.mode&63)!==0))throw new Error("mutation-qa-checkpoint-store-invalid");if(c){const s=k(a,"r");try{w(s)}finally{S(s)}}return{root:e,directory:i}}function O(n){const o=h(n);if(!o.isFile()||o.isSymbolicLink()||o.uid!==process.getuid?.()||(o.mode&63)!==0||o.size<1||o.size>4096)throw new Error("mutation-qa-checkpoint-record-invalid");const e=x(n,"utf8");let r;try{r=JSON.parse(e)}catch{throw new Error("mutation-qa-checkpoint-record-invalid")}if(!r||typeof r!="object"||Array.isArray(r))throw new Error("mutation-qa-checkpoint-record-invalid");const t=r,{checksumSha256:a,...i}=t,c=b("sha256").update(`mutation-qa-checkpoint-v1\0${JSON.stringify(i)}`).digest("hex");if(Object.keys(t).sort().join(",")!==["schemaVersion","kind","planSha256","headSha","baseSha","reportSha256","verdict","mutationScore","checkpointAccepted","qaPassed","localOnly","checksumSha256"].sort().join(",")||t.schemaVersion!==1||t.kind!=="mutation-qa-checkpoint"||typeof t.planSha256!="string"||!/^[a-f0-9]{64}$/.test(t.planSha256)||typeof t.headSha!="string"||!/^[a-f0-9]{40,64}$/.test(t.headSha)||typeof t.baseSha!="string"||!/^[a-f0-9]{40,64}$/.test(t.baseSha)||typeof t.reportSha256!="string"||!/^[a-f0-9]{64}$/.test(t.reportSha256)||!["passed","warned","failed"].includes(String(t.verdict))||typeof t.mutationScore!="number"||!Number.isFinite(t.mutationScore)||t.mutationScore<0||t.mutationScore>100||t.checkpointAccepted!==!0||t.qaPassed!==(t.verdict==="passed")||t.localOnly!==!0||a!==c||e!==`${JSON.stringify(t)}
|
|
2
|
+
`)throw new Error("mutation-qa-checkpoint-record-invalid");return t}function Q(n){const o=h(n);if(!o.isFile()||o.isSymbolicLink()||o.uid!==process.getuid?.()||(o.mode&63)!==0||o.size<1||o.size>4096)throw new Error("mutation-qa-debt-record-invalid");const e=x(n,"utf8");let r;try{r=JSON.parse(e)}catch{throw new Error("mutation-qa-debt-record-invalid")}if(!r||typeof r!="object"||Array.isArray(r))throw new Error("mutation-qa-debt-record-invalid");const t=r,{checksumSha256:a,...i}=t,c=b("sha256").update(`mutation-qa-debt-v1\0${JSON.stringify(i)}`).digest("hex");if(Object.keys(t).sort().join(",")!==["schemaVersion","kind","planSha256","headSha","status","reasonCode","runOutcome","owner","severity","publicSafe","localOnly","checksumSha256"].sort().join(",")||t.schemaVersion!==1||t.kind!=="mutation-qa-follow-up-debt"||typeof t.planSha256!="string"||!/^[a-f0-9]{64}$/.test(t.planSha256)||typeof t.headSha!="string"||!/^[a-f0-9]{40,64}$/.test(t.headSha)||!["warned","unobserved"].includes(String(t.status))||t.reasonCode!==(t.status==="warned"?"mutation-qa-warned":"mutation-qa-observation-missing")||!["not-run","skipped-no-files","skipped-stryker-missing","skipped-dependencies-unavailable","skipped-host-isolation-unavailable","skipped-stryker-error","verified"].includes(String(t.runOutcome))||t.owner!=="root-qa"||t.severity!==(t.status==="warned"?"P2":"P3")||t.publicSafe!==!0||t.localOnly!==!0||a!==c||e!==`${JSON.stringify(t)}
|
|
3
|
+
`)throw new Error("mutation-qa-debt-record-invalid");return t}function B(n,o,e,r,t,a){const i=v(n,o);if(i.planSha256!==e)throw new Error("mutation-qa-debt-plan-drift");const c=V(n,o,e);if(r==="warned"&&(t!=="verified"||c?.verdict!=="warned"))throw new Error("mutation-qa-debt-run-invalid");if(r==="unobserved"&&(i.outcome!=="ready"||c||!["skipped-stryker-missing","skipped-dependencies-unavailable","skipped-stryker-error"].includes(t)))throw new Error("mutation-qa-debt-run-invalid");const{root:d,directory:s}=E(a??n,!0);if(a&&g(d,["rev-parse","--verify","HEAD"]).toString("utf8").trim()!==i.baseSha)throw new Error("mutation-qa-debt-root-drift");const l={schemaVersion:1,kind:"mutation-qa-follow-up-debt",planSha256:e,headSha:i.headSha,status:r,reasonCode:r==="warned"?"mutation-qa-warned":"mutation-qa-observation-missing",runOutcome:t,owner:"root-qa",severity:r==="warned"?"P2":"P3",publicSafe:!0,localOnly:!0},f=Object.freeze({...l,checksumSha256:b("sha256").update(`mutation-qa-debt-v1\0${JSON.stringify(l)}`).digest("hex")}),p=y(s,`debt-${e}.json`);if(h(p,{throwIfNoEntry:!1})){const m=Q(p);if(JSON.stringify(m)!==JSON.stringify(f))throw new Error("mutation-qa-debt-conflict");return m}const u=y(s,`debt-${J()}.tmp`);try{const m=k(u,"wx",384);try{P(m,`${JSON.stringify(f)}
|
|
4
|
+
`),w(m)}finally{S(m)}if(v(n,o).planSha256!==e||a&&g(d,["rev-parse","--verify","HEAD"]).toString("utf8").trim()!==i.baseSha)throw new Error("mutation-qa-debt-plan-drift");try{I(u,p)}catch($){if($.code!=="EEXIST")throw $;const z=Q(p);if(JSON.stringify(z)!==JSON.stringify(f))throw new Error("mutation-qa-debt-conflict")}const N=k(s,"r");try{w(N)}finally{S(N)}}finally{h(u,{throwIfNoEntry:!1})&&j(u)}return f}function M(n,o,e){if(e.outcome!=="verified"||!e.verdict||e.verdict.planSha256!==e.planSha256||e.verdict.checkpointAccepted!==!1)throw new Error("mutation-qa-checkpoint-verdict-unavailable");const r=v(n,o);if(r.outcome!=="ready"||r.planSha256!==e.planSha256||r.headSha!==e.headSha)throw new Error("mutation-qa-checkpoint-plan-drift");const{root:t,directory:a}=E(n,!0),i={schemaVersion:1,kind:"mutation-qa-checkpoint",planSha256:r.planSha256,headSha:r.headSha,baseSha:r.baseSha,reportSha256:e.verdict.reportSha256,verdict:e.verdict.outcome,mutationScore:e.verdict.mutationScore,checkpointAccepted:!0,qaPassed:e.verdict.outcome==="passed",localOnly:!0},c=Object.freeze({...i,checksumSha256:b("sha256").update(`mutation-qa-checkpoint-v1\0${JSON.stringify(i)}`).digest("hex")}),d=y(a,`${r.planSha256}.json`);if(h(d,{throwIfNoEntry:!1})){const l=O(d);if(JSON.stringify(l)!==JSON.stringify(c))throw new Error("mutation-qa-checkpoint-conflict");return l}const s=y(a,`checkpoint-${J()}.tmp`);try{const l=k(s,"wx",384);try{P(l,`${JSON.stringify(c)}
|
|
5
|
+
`),w(l)}finally{S(l)}if(v(t,o).planSha256!==r.planSha256)throw new Error("mutation-qa-checkpoint-plan-drift");try{I(s,d)}catch(p){if(p.code!=="EEXIST")throw p;const u=O(d);if(JSON.stringify(u)!==JSON.stringify(c))throw new Error("mutation-qa-checkpoint-conflict")}const f=k(a,"r");try{w(f)}finally{S(f)}}finally{h(s,{throwIfNoEntry:!1})&&j(s)}return c}function K(n,o,e){const r=H(n,o,e);return r.outcome==="verified"?{result:r,checkpoint:M(n,o,r)}:{result:r}}function V(n,o,e){if(!/^[a-f0-9]{64}$/.test(e))throw new Error("mutation-qa-plan-digest-invalid");const r=v(n,o);if(r.planSha256!==e)throw new Error("mutation-qa-checkpoint-plan-drift");const{directory:t}=E(n,!1),a=y(t,`${e}.json`);if(!h(a,{throwIfNoEntry:!1}))return;const i=O(a);if(i.planSha256!==e||i.headSha!==r.headSha||i.baseSha!==r.baseSha)throw new Error("mutation-qa-checkpoint-plan-drift");return i}export{V as readMutationQaCheckpoint,B as recordMutationQaFollowUpDebt,K as runAndRecordMutationQa};
|
|
@@ -1,54 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { readMutationQaCheckpoint, recordMutationQaFollowUpDebt, runAndRecordMutationQa } from './mutation-qa-checkpoint.js';
|
|
3
|
-
import { planMutationQa } from './mutation-qa.js';
|
|
4
|
-
/** A skip is never a passing verdict; the caller must persist required debt separately. */
|
|
5
|
-
export function classifyMutationQaGate(projectRoot, baseRef, expectedPlanSha256) {
|
|
6
|
-
const plan = planMutationQa(projectRoot, baseRef);
|
|
7
|
-
if (plan.planSha256 !== expectedPlanSha256)
|
|
8
|
-
throw new Error('mutation-qa-gate-plan-drift');
|
|
9
|
-
const checkpoint = readMutationQaCheckpoint(projectRoot, baseRef, expectedPlanSha256);
|
|
10
|
-
if (planMutationQa(projectRoot, baseRef).planSha256 !== plan.planSha256) {
|
|
11
|
-
throw new Error('mutation-qa-gate-plan-drift');
|
|
12
|
-
}
|
|
13
|
-
const status = checkpoint?.verdict ?? (plan.outcome === 'skipped-no-files'
|
|
14
|
-
? 'not-applicable' : 'unobserved');
|
|
15
|
-
const reasonCode = status === 'passed' ? 'mutation-qa-passed'
|
|
16
|
-
: status === 'warned' ? 'mutation-qa-warned'
|
|
17
|
-
: status === 'failed' ? 'mutation-qa-failed'
|
|
18
|
-
: status === 'not-applicable' ? 'mutation-qa-no-eligible-files'
|
|
19
|
-
: 'mutation-qa-observation-missing';
|
|
20
|
-
return Object.freeze({ schemaVersion: 1, kind: 'mutation-qa-gate-decision',
|
|
21
|
-
planSha256: plan.planSha256, headSha: plan.headSha, status, reasonCode,
|
|
22
|
-
checkpointAccepted: checkpoint !== undefined, qaPassed: status === 'passed',
|
|
23
|
-
blocksLocalQa: status === 'failed',
|
|
24
|
-
followUpDebtRequired: status === 'warned' || status === 'unobserved',
|
|
25
|
-
safeToContinueLocalQa: status === 'passed' || status === 'not-applicable',
|
|
26
|
-
publicSafe: true, localOnly: true });
|
|
27
|
-
}
|
|
28
|
-
/** One root transaction from a reviewed physical plan to verdict or durable debt. */
|
|
29
|
-
export function executeMutationQaPlan(projectRoot, baseRef, expectedPlanSha256) {
|
|
30
|
-
const plan = planMutationQa(projectRoot, baseRef);
|
|
31
|
-
if (plan.planSha256 !== expectedPlanSha256)
|
|
32
|
-
throw new Error('mutation-qa-plan-drift');
|
|
33
|
-
const run = plan.outcome === 'ready'
|
|
34
|
-
? runAndRecordMutationQa(projectRoot, baseRef, expectedPlanSha256)
|
|
35
|
-
: undefined;
|
|
36
|
-
if (run?.result.outcome === 'skipped-host-isolation-unavailable') {
|
|
37
|
-
throw new Error('mutation-qa-host-isolation-unavailable');
|
|
38
|
-
}
|
|
39
|
-
const decision = classifyMutationQaGate(projectRoot, baseRef, expectedPlanSha256);
|
|
40
|
-
const followUpDebt = decision.followUpDebtRequired
|
|
41
|
-
? recordMutationQaFollowUpDebt(projectRoot, baseRef, expectedPlanSha256, decision.status, run?.result.outcome ?? 'not-run')
|
|
42
|
-
: undefined;
|
|
43
|
-
if (planMutationQa(projectRoot, baseRef).planSha256 !== expectedPlanSha256) {
|
|
44
|
-
throw new Error('mutation-qa-root-execution-drift');
|
|
45
|
-
}
|
|
46
|
-
return Object.freeze({ schemaVersion: 1, kind: 'mutation-qa-root-execution',
|
|
47
|
-
planSha256: expectedPlanSha256, headSha: plan.headSha,
|
|
48
|
-
runOutcome: run?.result.outcome ?? 'not-run', decision,
|
|
49
|
-
...(run?.checkpoint ? { checkpoint: run.checkpoint } : {}),
|
|
50
|
-
...(followUpDebt ? { followUpDebt } : {}),
|
|
51
|
-
continuationAuthorized: decision.safeToContinueLocalQa
|
|
52
|
-
|| (!!followUpDebt && !decision.blocksLocalQa),
|
|
53
|
-
publicSafe: true, localOnly: true });
|
|
54
|
-
}
|
|
1
|
+
import{readMutationQaCheckpoint as l,recordMutationQaFollowUpDebt as s,runAndRecordMutationQa as c}from"./mutation-qa-checkpoint.js";import{planMutationQa as u}from"./mutation-qa.js";function d(n,t,o){const i=u(n,t);if(i.planSha256!==o)throw new Error("mutation-qa-gate-plan-drift");const e=l(n,t,o);if(u(n,t).planSha256!==i.planSha256)throw new Error("mutation-qa-gate-plan-drift");const a=e?.verdict??(i.outcome==="skipped-no-files"?"not-applicable":"unobserved"),r=a==="passed"?"mutation-qa-passed":a==="warned"?"mutation-qa-warned":a==="failed"?"mutation-qa-failed":a==="not-applicable"?"mutation-qa-no-eligible-files":"mutation-qa-observation-missing";return Object.freeze({schemaVersion:1,kind:"mutation-qa-gate-decision",planSha256:i.planSha256,headSha:i.headSha,status:a,reasonCode:r,checkpointAccepted:e!==void 0,qaPassed:a==="passed",blocksLocalQa:a==="failed",followUpDebtRequired:a==="warned"||a==="unobserved",safeToContinueLocalQa:a==="passed"||a==="not-applicable",publicSafe:!0,localOnly:!0})}function f(n,t,o){const i=u(n,t);if(i.planSha256!==o)throw new Error("mutation-qa-plan-drift");const e=i.outcome==="ready"?c(n,t,o):void 0;if(e?.result.outcome==="skipped-host-isolation-unavailable")throw new Error("mutation-qa-host-isolation-unavailable");const a=d(n,t,o),r=a.followUpDebtRequired?s(n,t,o,a.status,e?.result.outcome??"not-run"):void 0;if(u(n,t).planSha256!==o)throw new Error("mutation-qa-root-execution-drift");return Object.freeze({schemaVersion:1,kind:"mutation-qa-root-execution",planSha256:o,headSha:i.headSha,runOutcome:e?.result.outcome??"not-run",decision:a,...e?.checkpoint?{checkpoint:e.checkpoint}:{},...r?{followUpDebt:r}:{},continuationAuthorized:a.safeToContinueLocalQa||!!r&&!a.blocksLocalQa,publicSafe:!0,localOnly:!0})}export{d as classifyMutationQaGate,f as executeMutationQaPlan};
|
|
@@ -1,41 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { execFileSync } from 'node:child_process';
|
|
3
|
-
import { existsSync, lstatSync, realpathSync } from 'node:fs';
|
|
4
|
-
import { isAbsolute, join } from 'node:path';
|
|
5
|
-
function trustedGit() {
|
|
6
|
-
for (const directory of (process.env.PATH ?? '').split(':')) {
|
|
7
|
-
if (!isAbsolute(directory))
|
|
8
|
-
continue;
|
|
9
|
-
const candidate = join(directory, 'git');
|
|
10
|
-
if (!existsSync(candidate))
|
|
11
|
-
continue;
|
|
12
|
-
try {
|
|
13
|
-
const resolved = realpathSync(candidate);
|
|
14
|
-
if ((resolved.startsWith('/usr/') || resolved.startsWith('/home/linuxbrew/.linuxbrew/'))
|
|
15
|
-
&& lstatSync(resolved).isFile())
|
|
16
|
-
return resolved;
|
|
17
|
-
}
|
|
18
|
-
catch { /* The first matching Git on PATH is untrusted. */ }
|
|
19
|
-
break;
|
|
20
|
-
}
|
|
21
|
-
throw new Error('mutation-qa-git-untrusted');
|
|
22
|
-
}
|
|
23
|
-
/** Exclude ambient Git configuration and executable shadowing; disable local hook/fsmonitor execution. */
|
|
24
|
-
export function mutationQaGit(root, args) {
|
|
25
|
-
return execFileSync(trustedGit(), [
|
|
26
|
-
'-c', 'core.fsmonitor=false', '-c', 'core.hooksPath=/dev/null',
|
|
27
|
-
'-c', 'protocol.ext.allow=never', ...args,
|
|
28
|
-
], {
|
|
29
|
-
cwd: root,
|
|
30
|
-
env: {
|
|
31
|
-
PATH: '/usr/bin:/bin',
|
|
32
|
-
GIT_CONFIG_NOSYSTEM: '1',
|
|
33
|
-
GIT_CONFIG_GLOBAL: '/dev/null',
|
|
34
|
-
GIT_CONFIG_SYSTEM: '/dev/null',
|
|
35
|
-
GIT_TERMINAL_PROMPT: '0',
|
|
36
|
-
GIT_OPTIONAL_LOCKS: '0',
|
|
37
|
-
GIT_LFS_SKIP_SMUDGE: '1',
|
|
38
|
-
},
|
|
39
|
-
stdio: ['ignore', 'pipe', 'pipe'], timeout: 15_000, maxBuffer: 8 * 1024 * 1024,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
1
|
+
import{execFileSync as r}from"node:child_process";import{existsSync as i,lstatSync as n,realpathSync as s}from"node:fs";import{isAbsolute as c,join as u}from"node:path";function l(){for(const t of(process.env.PATH??"").split(":")){if(!c(t))continue;const e=u(t,"git");if(i(e)){try{const o=s(e);if((o.startsWith("/usr/")||o.startsWith("/home/linuxbrew/.linuxbrew/"))&&n(o).isFile())return o}catch{}break}}throw new Error("mutation-qa-git-untrusted")}function G(t,e){return r(l(),["-c","core.fsmonitor=false","-c","core.hooksPath=/dev/null","-c","protocol.ext.allow=never",...e],{cwd:t,env:{PATH:"/usr/bin:/bin",GIT_CONFIG_NOSYSTEM:"1",GIT_CONFIG_GLOBAL:"/dev/null",GIT_CONFIG_SYSTEM:"/dev/null",GIT_TERMINAL_PROMPT:"0",GIT_OPTIONAL_LOCKS:"0",GIT_LFS_SKIP_SMUDGE:"1"},stdio:["ignore","pipe","pipe"],timeout:15e3,maxBuffer:8*1024*1024})}export{G as mutationQaGit};
|
|
@@ -1,102 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
import { createHash } from 'node:crypto';
|
|
3
|
-
import { lstatSync, readFileSync, realpathSync } from 'node:fs';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
const DEFAULT_FIELDS = Object.freeze({ schema_version: 1, default_threshold: 75,
|
|
6
|
-
block_threshold: 50,
|
|
7
|
-
exclude_paths: ['**/*.test.ts', '**/*.spec.ts', '**/__tests__/**', '**/migrations/**', '**/*.d.ts'],
|
|
8
|
-
per_area_threshold: { domain: 90, infrastructure: 60 } });
|
|
9
|
-
const MAX_POLICY_BYTES = 16 * 1024;
|
|
10
|
-
function validScore(value) {
|
|
11
|
-
return typeof value === 'number' && Number.isFinite(value) && value >= 0 && value <= 100;
|
|
12
|
-
}
|
|
13
|
-
function globRegex(pattern) {
|
|
14
|
-
if (pattern.length === 0 || pattern.length > 240 || pattern.startsWith('/')
|
|
15
|
-
|| pattern.includes('..') || pattern.includes('//')
|
|
16
|
-
|| !/^[A-Za-z0-9_./*?-]+$/.test(pattern)) {
|
|
17
|
-
throw new Error('mutation-qa-policy-pattern-invalid');
|
|
18
|
-
}
|
|
19
|
-
let expression = '^';
|
|
20
|
-
for (let index = 0; index < pattern.length; index++) {
|
|
21
|
-
const current = pattern[index];
|
|
22
|
-
if (current === '*') {
|
|
23
|
-
if (pattern[index + 1] === '*') {
|
|
24
|
-
if (pattern[index + 2] === '/') {
|
|
25
|
-
expression += '(?:.*/)?';
|
|
26
|
-
index += 2;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
expression += '.*';
|
|
30
|
-
index++;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
else
|
|
34
|
-
expression += '[^/]*';
|
|
35
|
-
}
|
|
36
|
-
else if (current === '?')
|
|
37
|
-
expression += '[^/]';
|
|
38
|
-
else if (current === '/')
|
|
39
|
-
expression += '/';
|
|
40
|
-
else
|
|
41
|
-
expression += current.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
42
|
-
}
|
|
43
|
-
return new RegExp(`${expression}$`);
|
|
44
|
-
}
|
|
45
|
-
export function policyExcludesPath(policy, path) {
|
|
46
|
-
return policy.excludePaths.some((pattern) => globRegex(pattern).test(path));
|
|
47
|
-
}
|
|
48
|
-
/** Accept a bounded subset of the published policy schema, failing closed on unknown semantics. */
|
|
49
|
-
export function loadMutationQaPolicy(projectRoot) {
|
|
50
|
-
const path = join(projectRoot, '.neocortex', 'mutation-policy.json');
|
|
51
|
-
let source = 'default';
|
|
52
|
-
let raw = Buffer.from(JSON.stringify(DEFAULT_FIELDS));
|
|
53
|
-
const stat = lstatSync(path, { throwIfNoEntry: false });
|
|
54
|
-
if (stat) {
|
|
55
|
-
if (realpathSync(path) !== path)
|
|
56
|
-
throw new Error('mutation-qa-policy-path-unsafe');
|
|
57
|
-
if (!stat.isFile() || stat.size === 0 || stat.size > MAX_POLICY_BYTES) {
|
|
58
|
-
throw new Error('mutation-qa-policy-size-invalid');
|
|
59
|
-
}
|
|
60
|
-
raw = readFileSync(path);
|
|
61
|
-
if (raw.byteLength === 0 || raw.byteLength > MAX_POLICY_BYTES) {
|
|
62
|
-
throw new Error('mutation-qa-policy-size-invalid');
|
|
63
|
-
}
|
|
64
|
-
source = 'project';
|
|
65
|
-
}
|
|
66
|
-
let parsed;
|
|
67
|
-
try {
|
|
68
|
-
parsed = JSON.parse(raw.toString('utf8').replace(/^\uFEFF/, ''));
|
|
69
|
-
}
|
|
70
|
-
catch {
|
|
71
|
-
throw new Error('mutation-qa-policy-invalid');
|
|
72
|
-
}
|
|
73
|
-
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
74
|
-
throw new Error('mutation-qa-policy-invalid');
|
|
75
|
-
}
|
|
76
|
-
const policy = parsed;
|
|
77
|
-
const allowed = new Set(['$schema', '_comment', 'schema_version', 'default_threshold',
|
|
78
|
-
'block_threshold', 'exclude_paths', 'per_area_threshold']);
|
|
79
|
-
if (Object.keys(policy).some((key) => !allowed.has(key)) || policy.schema_version !== 1
|
|
80
|
-
|| !validScore(policy.default_threshold) || !validScore(policy.block_threshold)
|
|
81
|
-
|| policy.block_threshold > policy.default_threshold
|
|
82
|
-
|| !Array.isArray(policy.exclude_paths) || policy.exclude_paths.length > 32
|
|
83
|
-
|| policy.exclude_paths.some((entry) => typeof entry !== 'string')) {
|
|
84
|
-
throw new Error('mutation-qa-policy-invalid');
|
|
85
|
-
}
|
|
86
|
-
const exclusions = policy.exclude_paths.map((entry) => {
|
|
87
|
-
globRegex(entry);
|
|
88
|
-
return entry;
|
|
89
|
-
});
|
|
90
|
-
const areas = policy.per_area_threshold ?? {};
|
|
91
|
-
if (!areas || typeof areas !== 'object' || Array.isArray(areas)
|
|
92
|
-
|| Object.keys(areas).length > 32
|
|
93
|
-
|| Object.entries(areas).some(([key, value]) => !/^[a-z][a-z0-9-]{0,63}$/.test(key)
|
|
94
|
-
|| !validScore(value)))
|
|
95
|
-
throw new Error('mutation-qa-policy-invalid');
|
|
96
|
-
const perAreaThreshold = Object.freeze({ ...areas });
|
|
97
|
-
return Object.freeze({ schemaVersion: 1, source,
|
|
98
|
-
sha256: createHash('sha256').update(raw).digest('hex'),
|
|
99
|
-
thresholds: Object.freeze({ defaultThreshold: policy.default_threshold,
|
|
100
|
-
blockThreshold: policy.block_threshold, perAreaThreshold }),
|
|
101
|
-
excludePaths: Object.freeze(exclusions), });
|
|
102
|
-
}
|
|
1
|
+
import{createHash as m}from"node:crypto";import{lstatSync as y,readFileSync as b,realpathSync as w}from"node:fs";import{join as x}from"node:path";const g=Object.freeze({schema_version:1,default_threshold:75,block_threshold:50,exclude_paths:["**/*.test.ts","**/*.spec.ts","**/__tests__/**","**/migrations/**","**/*.d.ts"],per_area_threshold:{domain:90,infrastructure:60}}),h=16*1024;function c(e){return typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=100}function d(e){if(e.length===0||e.length>240||e.startsWith("/")||e.includes("..")||e.includes("//")||!/^[A-Za-z0-9_./*?-]+$/.test(e))throw new Error("mutation-qa-policy-pattern-invalid");let t="^";for(let o=0;o<e.length;o++){const s=e[o];s==="*"?e[o+1]==="*"?e[o+2]==="/"?(t+="(?:.*/)?",o+=2):(t+=".*",o++):t+="[^/]*":s==="?"?t+="[^/]":s==="/"?t+="/":t+=s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}return new RegExp(`${t}$`)}function O(e,t){return e.excludePaths.some(o=>d(o).test(t))}function A(e){const t=x(e,".neocortex","mutation-policy.json");let o="default",s=Buffer.from(JSON.stringify(g));const n=y(t,{throwIfNoEntry:!1});if(n){if(w(t)!==t)throw new Error("mutation-qa-policy-path-unsafe");if(!n.isFile()||n.size===0||n.size>h)throw new Error("mutation-qa-policy-size-invalid");if(s=b(t),s.byteLength===0||s.byteLength>h)throw new Error("mutation-qa-policy-size-invalid");o="project"}let a;try{a=JSON.parse(s.toString("utf8").replace(/^\uFEFF/,""))}catch{throw new Error("mutation-qa-policy-invalid")}if(!a||typeof a!="object"||Array.isArray(a))throw new Error("mutation-qa-policy-invalid");const r=a,f=new Set(["$schema","_comment","schema_version","default_threshold","block_threshold","exclude_paths","per_area_threshold"]);if(Object.keys(r).some(i=>!f.has(i))||r.schema_version!==1||!c(r.default_threshold)||!c(r.block_threshold)||r.block_threshold>r.default_threshold||!Array.isArray(r.exclude_paths)||r.exclude_paths.length>32||r.exclude_paths.some(i=>typeof i!="string"))throw new Error("mutation-qa-policy-invalid");const u=r.exclude_paths.map(i=>(d(i),i)),l=r.per_area_threshold??{};if(!l||typeof l!="object"||Array.isArray(l)||Object.keys(l).length>32||Object.entries(l).some(([i,_])=>!/^[a-z][a-z0-9-]{0,63}$/.test(i)||!c(_)))throw new Error("mutation-qa-policy-invalid");const p=Object.freeze({...l});return Object.freeze({schemaVersion:1,source:o,sha256:m("sha256").update(s).digest("hex"),thresholds:Object.freeze({defaultThreshold:r.default_threshold,blockThreshold:r.block_threshold,perAreaThreshold:p}),excludePaths:Object.freeze(u)})}export{A as loadMutationQaPolicy,O as policyExcludesPath};
|