@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,3 +1,219 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/** Root-owned Stryker execution. Runs project code only after explicit local authorization. */
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { homedir, tmpdir } from 'node:os';
|
|
6
|
+
import { isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
7
|
+
import { mutationQaGit } from './mutation-qa-git.js';
|
|
8
|
+
import { planMutationQa } from './mutation-qa.js';
|
|
9
|
+
import { evaluateMutationQaReport } from './mutation-qa-verdict.js';
|
|
10
|
+
const REPORT_RELATIVE_PATH = 'reports/mutation/mutation.json';
|
|
11
|
+
const MAX_REPORT_BYTES = 8 * 1024 * 1024;
|
|
12
|
+
const MAX_PROCESS_MS = 30 * 60 * 1000;
|
|
13
|
+
const MAX_PREPARE_MS = 5 * 60 * 1000;
|
|
14
|
+
function ensureInside(root, path) {
|
|
15
|
+
const rel = relative(root, path);
|
|
16
|
+
return rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel);
|
|
17
|
+
}
|
|
18
|
+
function readSafeReport(root) {
|
|
19
|
+
const path = join(root, REPORT_RELATIVE_PATH);
|
|
20
|
+
if (!existsSync(path))
|
|
21
|
+
return null;
|
|
22
|
+
const real = realpathSync(path);
|
|
23
|
+
if (real !== path || !ensureInside(root, real))
|
|
24
|
+
throw new Error('mutation-qa-report-path-unsafe');
|
|
25
|
+
const stat = lstatSync(path);
|
|
26
|
+
if (!stat.isFile() || stat.size === 0 || stat.size > MAX_REPORT_BYTES) {
|
|
27
|
+
throw new Error('mutation-qa-report-size-invalid');
|
|
28
|
+
}
|
|
29
|
+
return readFileSync(path);
|
|
30
|
+
}
|
|
31
|
+
function assertPhysicalAfterRun(root, plan) {
|
|
32
|
+
const head = mutationQaGit(root, ['rev-parse', '--verify', 'HEAD']).toString('utf8').trim();
|
|
33
|
+
const baseRevision = plan.baseRef.startsWith('sha:') ? plan.baseSha : plan.baseRef;
|
|
34
|
+
const base = mutationQaGit(root, ['rev-parse', '--verify', '--end-of-options', `${baseRevision}^{commit}`])
|
|
35
|
+
.toString('utf8').trim();
|
|
36
|
+
if (head !== plan.headSha || base !== plan.baseSha)
|
|
37
|
+
throw new Error('mutation-qa-physical-drift');
|
|
38
|
+
const entries = mutationQaGit(root, ['status', '--porcelain=v1', '-z', '--untracked-files=all'])
|
|
39
|
+
.toString('utf8').split('\0').filter(Boolean);
|
|
40
|
+
if (entries.some((entry) => !entry.startsWith('?? ')
|
|
41
|
+
|| !(entry.slice(3).startsWith('node_modules/')
|
|
42
|
+
|| entry.slice(3).startsWith('reports/mutation/')
|
|
43
|
+
|| entry.slice(3).startsWith('.stryker-tmp/')))) {
|
|
44
|
+
throw new Error('mutation-qa-checkout-drift');
|
|
45
|
+
}
|
|
46
|
+
for (const file of plan.eligibleFiles) {
|
|
47
|
+
const path = resolve(root, file.path);
|
|
48
|
+
if (!ensureInside(root, path) || realpathSync(path) !== path || !lstatSync(path).isFile()
|
|
49
|
+
|| mutationQaGit(root, ['hash-object', '--', file.path]).toString('utf8').trim() !== file.blobSha) {
|
|
50
|
+
throw new Error('mutation-qa-source-drift');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function trustedTool(name) {
|
|
55
|
+
for (const directory of (process.env.PATH ?? '').split(':')) {
|
|
56
|
+
if (!isAbsolute(directory))
|
|
57
|
+
continue;
|
|
58
|
+
const candidate = join(directory, name);
|
|
59
|
+
if (!existsSync(candidate))
|
|
60
|
+
continue;
|
|
61
|
+
try {
|
|
62
|
+
const tool = realpathSync(candidate);
|
|
63
|
+
if ((tool.startsWith('/usr/') || tool.startsWith('/home/linuxbrew/.linuxbrew/'))
|
|
64
|
+
&& lstatSync(tool).isFile() && (name !== 'npm' || tool.endsWith('.js')))
|
|
65
|
+
return tool;
|
|
66
|
+
}
|
|
67
|
+
catch { /* The first matching tool on PATH is not trusted. */ }
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
function sandboxArgs(sandbox, privateHome, hostsPath, sourceEnv, cachePath) {
|
|
73
|
+
const executable = realpathSync(process.execPath);
|
|
74
|
+
const brewRoot = '/home/linuxbrew/.linuxbrew';
|
|
75
|
+
if (!executable.startsWith('/usr/') && !executable.startsWith(`${brewRoot}/`))
|
|
76
|
+
return null;
|
|
77
|
+
const args = ['--die-with-parent', '--unshare-net', '--unshare-pid', '--new-session',
|
|
78
|
+
'--ro-bind', '/usr', '/usr'];
|
|
79
|
+
for (const path of ['/bin', '/lib', '/lib64']) {
|
|
80
|
+
if (existsSync(path))
|
|
81
|
+
args.push('--ro-bind', path, path);
|
|
82
|
+
}
|
|
83
|
+
if (executable.startsWith(`${brewRoot}/`)) {
|
|
84
|
+
if (!existsSync(brewRoot))
|
|
85
|
+
return null;
|
|
86
|
+
args.push('--dir', '/home', '--dir', '/home/linuxbrew', '--ro-bind', brewRoot, brewRoot);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
args.push('--dir', '/home');
|
|
90
|
+
}
|
|
91
|
+
args.push('--bind', privateHome, '/home/worker');
|
|
92
|
+
if (cachePath)
|
|
93
|
+
args.push('--dir', '/npm-cache', '--overlay-src', cachePath, '--tmp-overlay', '/npm-cache');
|
|
94
|
+
args.push('--dir', '/etc', '--ro-bind', hostsPath, '/etc/hosts', '--proc', '/proc', '--dev', '/dev', '--tmpfs', '/tmp', '--dir', '/work', '--bind', sandbox, '/work', '--chdir', '/work', '--clearenv');
|
|
95
|
+
for (const [key, value] of Object.entries(sourceEnv)) {
|
|
96
|
+
args.push('--setenv', key, value);
|
|
97
|
+
}
|
|
98
|
+
return args;
|
|
99
|
+
}
|
|
100
|
+
/** Installs only from the local npm cache in a disposable clone; never mutates the source checkout. */
|
|
101
|
+
export function runMutationQa(projectRoot, baseRef, expectedPlanSha256) {
|
|
102
|
+
if (!/^[a-f0-9]{64}$/.test(expectedPlanSha256))
|
|
103
|
+
throw new Error('mutation-qa-plan-digest-invalid');
|
|
104
|
+
const root = resolve(projectRoot);
|
|
105
|
+
const plan = planMutationQa(root, baseRef);
|
|
106
|
+
if (plan.planSha256 !== expectedPlanSha256)
|
|
107
|
+
throw new Error('mutation-qa-plan-drift');
|
|
108
|
+
const base = { schemaVersion: 1, kind: 'mutation-qa-run',
|
|
109
|
+
planSha256: plan.planSha256, headSha: plan.headSha,
|
|
110
|
+
checkpointAccepted: false, localOnly: true,
|
|
111
|
+
executionEnvironment: 'os-sandbox-clone' };
|
|
112
|
+
if (plan.outcome === 'skipped-no-files')
|
|
113
|
+
return Object.freeze({ ...base, outcome: 'skipped-no-files' });
|
|
114
|
+
if (!existsSync(join(root, 'package-lock.json'))) {
|
|
115
|
+
return Object.freeze({ ...base, outcome: 'skipped-dependencies-unavailable' });
|
|
116
|
+
}
|
|
117
|
+
const tempRoot = mkdtempSync(join(tmpdir(), 'mutation-qa-run-'));
|
|
118
|
+
const sandbox = join(tempRoot, 'checkout');
|
|
119
|
+
const privateHome = join(tempRoot, 'home');
|
|
120
|
+
mkdirSync(privateHome, { mode: 0o700 });
|
|
121
|
+
const hostsPath = join(tempRoot, 'hosts');
|
|
122
|
+
writeFileSync(hostsPath, '127.0.0.1 localhost\n::1 localhost\n', { mode: 0o600 });
|
|
123
|
+
const environment = { PATH: process.env.PATH ?? '/usr/bin:/bin', HOME: '/home/worker',
|
|
124
|
+
TMPDIR: '/tmp', CI: 'true', LANG: 'C.UTF-8', NO_COLOR: '1',
|
|
125
|
+
npm_config_offline: 'true', npm_config_yes: 'false', npm_config_ignore_scripts: 'true',
|
|
126
|
+
npm_config_audit: 'false', npm_config_fund: 'false',
|
|
127
|
+
npm_config_userconfig: '/dev/null', npm_config_globalconfig: '/tmp/npm-global.npmrc' };
|
|
128
|
+
try {
|
|
129
|
+
mutationQaGit(root, ['clone', '--local', '--no-hardlinks', '--no-checkout', root, sandbox]);
|
|
130
|
+
mutationQaGit(sandbox, ['checkout', '--detach', plan.headSha]);
|
|
131
|
+
if (!plan.baseRef.startsWith('sha:')) {
|
|
132
|
+
mutationQaGit(sandbox, ['update-ref', plan.baseRef, plan.baseSha]);
|
|
133
|
+
}
|
|
134
|
+
const npmCli = trustedTool('npm');
|
|
135
|
+
const bwrap = trustedTool('bwrap');
|
|
136
|
+
const npmCache = join(homedir(), '.npm');
|
|
137
|
+
if (!npmCli || !bwrap || !existsSync(npmCache)) {
|
|
138
|
+
return Object.freeze({ ...base, outcome: 'skipped-host-isolation-unavailable' });
|
|
139
|
+
}
|
|
140
|
+
const confined = sandboxArgs(sandbox, privateHome, hostsPath, environment);
|
|
141
|
+
const installConfined = sandboxArgs(sandbox, privateHome, hostsPath, {
|
|
142
|
+
...environment, npm_config_cache: '/npm-cache', npm_config_logs_dir: '/tmp/npm-logs',
|
|
143
|
+
}, realpathSync(npmCache));
|
|
144
|
+
if (!confined || !installConfined) {
|
|
145
|
+
return Object.freeze({ ...base, outcome: 'skipped-host-isolation-unavailable' });
|
|
146
|
+
}
|
|
147
|
+
const executable = realpathSync(process.execPath);
|
|
148
|
+
const sandboxProbe = spawnSync(bwrap, [...confined, '--', executable, '-e', 'process.exit(0)'], {
|
|
149
|
+
cwd: sandbox, timeout: 10_000, maxBuffer: 4096,
|
|
150
|
+
stdio: ['ignore', 'pipe', 'pipe'], env: { PATH: process.env.PATH ?? '/usr/bin:/bin' },
|
|
151
|
+
});
|
|
152
|
+
if (sandboxProbe.error || sandboxProbe.signal || sandboxProbe.status !== 0) {
|
|
153
|
+
return Object.freeze({ ...base, outcome: 'skipped-host-isolation-unavailable' });
|
|
154
|
+
}
|
|
155
|
+
const install = spawnSync(bwrap, [...installConfined, '--', executable, npmCli,
|
|
156
|
+
'ci', '--offline', '--ignore-scripts', '--no-audit', '--no-fund'], {
|
|
157
|
+
cwd: sandbox, timeout: MAX_PREPARE_MS, maxBuffer: 2 * 1024 * 1024,
|
|
158
|
+
stdio: ['ignore', 'pipe', 'pipe'], env: { PATH: process.env.PATH ?? '/usr/bin:/bin' },
|
|
159
|
+
});
|
|
160
|
+
if (install.error || install.signal || install.status !== 0) {
|
|
161
|
+
return Object.freeze({ ...base, outcome: 'skipped-dependencies-unavailable' });
|
|
162
|
+
}
|
|
163
|
+
const binary = join(sandbox, 'node_modules/.bin/stryker');
|
|
164
|
+
if (!existsSync(binary))
|
|
165
|
+
return Object.freeze({ ...base, outcome: 'skipped-stryker-missing' });
|
|
166
|
+
const realBinary = realpathSync(binary);
|
|
167
|
+
if (!ensureInside(sandbox, realBinary) || !lstatSync(realBinary).isFile()) {
|
|
168
|
+
throw new Error('mutation-qa-stryker-path-unsafe');
|
|
169
|
+
}
|
|
170
|
+
const binaryInside = `/work/${relative(sandbox, realBinary).split(sep).join('/')}`;
|
|
171
|
+
const priorReport = readSafeReport(sandbox);
|
|
172
|
+
const priorDigest = priorReport ? createHash('sha256').update(priorReport).digest('hex') : null;
|
|
173
|
+
const previousUmask = process.umask(0o077);
|
|
174
|
+
let exitStatus = null;
|
|
175
|
+
let processError = false;
|
|
176
|
+
let hostIsolationUnavailable = false;
|
|
177
|
+
try {
|
|
178
|
+
const result = spawnSync(bwrap, [...confined, '--', executable, binaryInside, 'run', '--mutate',
|
|
179
|
+
plan.eligibleFiles.map((file) => file.path).join(','), '--reporters', 'json',
|
|
180
|
+
'--timeoutMS', '600000', '--concurrency', '4', '--coverageAnalysis', 'off'], {
|
|
181
|
+
cwd: sandbox, timeout: MAX_PROCESS_MS, maxBuffer: 2 * 1024 * 1024,
|
|
182
|
+
stdio: ['ignore', 'pipe', 'pipe'], env: { PATH: process.env.PATH ?? '/usr/bin:/bin' },
|
|
183
|
+
});
|
|
184
|
+
exitStatus = result.status;
|
|
185
|
+
processError = !!result.error || !!result.signal;
|
|
186
|
+
hostIsolationUnavailable = result.error?.code === 'ENOENT';
|
|
187
|
+
}
|
|
188
|
+
finally {
|
|
189
|
+
process.umask(previousUmask);
|
|
190
|
+
}
|
|
191
|
+
assertPhysicalAfterRun(sandbox, plan);
|
|
192
|
+
if (planMutationQa(root, baseRef).planSha256 !== plan.planSha256) {
|
|
193
|
+
throw new Error('mutation-qa-physical-drift');
|
|
194
|
+
}
|
|
195
|
+
if (hostIsolationUnavailable) {
|
|
196
|
+
return Object.freeze({ ...base, outcome: 'skipped-host-isolation-unavailable' });
|
|
197
|
+
}
|
|
198
|
+
if (processError || (exitStatus !== 0 && exitStatus !== 1)) {
|
|
199
|
+
return Object.freeze({ ...base, outcome: 'skipped-stryker-error' });
|
|
200
|
+
}
|
|
201
|
+
const rawReport = readSafeReport(sandbox);
|
|
202
|
+
if (!rawReport || createHash('sha256').update(rawReport).digest('hex') === priorDigest) {
|
|
203
|
+
if (exitStatus === 1)
|
|
204
|
+
return Object.freeze({ ...base, outcome: 'skipped-stryker-error' });
|
|
205
|
+
throw new Error('mutation-qa-report-stale');
|
|
206
|
+
}
|
|
207
|
+
const verdict = evaluateMutationQaReport(plan, rawReport);
|
|
208
|
+
// StrykerJS may exit 1 only because its configured break threshold was
|
|
209
|
+
// crossed. Never infer that from an exit code alone: require a fresh,
|
|
210
|
+
// fully validated report whose own score proves that exact condition.
|
|
211
|
+
if (exitStatus === 1 && !verdict.runnerBreakCrossed) {
|
|
212
|
+
return Object.freeze({ ...base, outcome: 'skipped-stryker-error' });
|
|
213
|
+
}
|
|
214
|
+
return Object.freeze({ ...base, outcome: 'verified', verdict });
|
|
215
|
+
}
|
|
216
|
+
finally {
|
|
217
|
+
rmSync(tempRoot, { recursive: true, force: true });
|
|
218
|
+
}
|
|
219
|
+
}
|
|
@@ -1 +1,149 @@
|
|
|
1
|
-
|
|
1
|
+
/** Strict local-only Stryker report validation against one immutable source plan. */
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
function score(killed, survived, noCoverage, timeout) {
|
|
4
|
+
const valid = killed + survived + noCoverage + timeout;
|
|
5
|
+
return valid === 0 ? 0 : Math.round(((killed + timeout) / valid) * 10_000) / 100;
|
|
6
|
+
}
|
|
7
|
+
function gitBlobSha(source, objectFormat) {
|
|
8
|
+
const content = Buffer.from(source, 'utf8');
|
|
9
|
+
return createHash(objectFormat).update(`blob ${content.byteLength}\0`).update(content).digest('hex');
|
|
10
|
+
}
|
|
11
|
+
function areaThreshold(path, thresholds) {
|
|
12
|
+
const area = path.match(/^src\/([^/]+)\//)?.[1];
|
|
13
|
+
if (area && thresholds.perAreaThreshold[area] !== undefined)
|
|
14
|
+
return thresholds.perAreaThreshold[area];
|
|
15
|
+
if (area === 'adapters' && thresholds.perAreaThreshold.infrastructure !== undefined) {
|
|
16
|
+
return thresholds.perAreaThreshold.infrastructure;
|
|
17
|
+
}
|
|
18
|
+
return thresholds.defaultThreshold;
|
|
19
|
+
}
|
|
20
|
+
/** Reject partial/foreign reports; never project file names, source, mutants or test details. */
|
|
21
|
+
export function evaluateMutationQaReport(plan, rawReport) {
|
|
22
|
+
const thresholds = plan.policy.thresholds;
|
|
23
|
+
if (plan.outcome !== 'ready' || plan.eligibleFiles.length === 0) {
|
|
24
|
+
throw new Error('mutation-qa-plan-not-ready');
|
|
25
|
+
}
|
|
26
|
+
if (rawReport.byteLength === 0 || rawReport.byteLength > 8 * 1024 * 1024) {
|
|
27
|
+
throw new Error('mutation-qa-report-size-invalid');
|
|
28
|
+
}
|
|
29
|
+
if ([thresholds.defaultThreshold, thresholds.blockThreshold,
|
|
30
|
+
...Object.values(thresholds.perAreaThreshold)].some((value) => !Number.isFinite(value)
|
|
31
|
+
|| value < 0 || value > 100)
|
|
32
|
+
|| thresholds.blockThreshold > thresholds.defaultThreshold) {
|
|
33
|
+
throw new Error('mutation-qa-thresholds-invalid');
|
|
34
|
+
}
|
|
35
|
+
let parsed;
|
|
36
|
+
try {
|
|
37
|
+
parsed = JSON.parse(rawReport.toString('utf8'));
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
throw new Error('mutation-qa-report-invalid');
|
|
41
|
+
}
|
|
42
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
43
|
+
throw new Error('mutation-qa-report-invalid');
|
|
44
|
+
}
|
|
45
|
+
const record = parsed;
|
|
46
|
+
if (typeof record.schemaVersion !== 'string' || !/^[12](?:\.\d+){0,2}$/.test(record.schemaVersion)
|
|
47
|
+
|| !record.thresholds || typeof record.thresholds !== 'object' || Array.isArray(record.thresholds)
|
|
48
|
+
|| !record.files || typeof record.files !== 'object'
|
|
49
|
+
|| Array.isArray(record.files))
|
|
50
|
+
throw new Error('mutation-qa-report-invalid');
|
|
51
|
+
const runnerThresholds = record.thresholds;
|
|
52
|
+
const runnerHigh = runnerThresholds.high;
|
|
53
|
+
const runnerLow = runnerThresholds.low;
|
|
54
|
+
const runnerBreakThreshold = runnerThresholds.break === undefined || runnerThresholds.break === null
|
|
55
|
+
? null : runnerThresholds.break;
|
|
56
|
+
if (typeof runnerHigh !== 'number' || !Number.isFinite(runnerHigh)
|
|
57
|
+
|| runnerHigh < 0 || runnerHigh > 100
|
|
58
|
+
|| typeof runnerLow !== 'number' || !Number.isFinite(runnerLow)
|
|
59
|
+
|| runnerLow < 0 || runnerLow > runnerHigh
|
|
60
|
+
|| runnerBreakThreshold !== null && (typeof runnerBreakThreshold !== 'number'
|
|
61
|
+
|| !Number.isFinite(runnerBreakThreshold) || runnerBreakThreshold < 0
|
|
62
|
+
|| runnerBreakThreshold > runnerLow))
|
|
63
|
+
throw new Error('mutation-qa-report-invalid');
|
|
64
|
+
const files = record.files;
|
|
65
|
+
const expected = plan.eligibleFiles.map((file) => file.path).sort();
|
|
66
|
+
const actual = Object.keys(files).sort();
|
|
67
|
+
if (expected.length !== actual.length || expected.some((path, index) => path !== actual[index])) {
|
|
68
|
+
throw new Error('mutation-qa-report-scope-mismatch');
|
|
69
|
+
}
|
|
70
|
+
let killed = 0;
|
|
71
|
+
let survived = 0;
|
|
72
|
+
let noCoverage = 0;
|
|
73
|
+
let timeout = 0;
|
|
74
|
+
let invalid = 0;
|
|
75
|
+
let belowAreaThresholdCount = 0;
|
|
76
|
+
for (const path of expected) {
|
|
77
|
+
const file = files[path];
|
|
78
|
+
if (!file || typeof file !== 'object' || Array.isArray(file)
|
|
79
|
+
|| typeof file.language !== 'string'
|
|
80
|
+
|| typeof file.source !== 'string'
|
|
81
|
+
|| !Array.isArray(file.mutants)) {
|
|
82
|
+
throw new Error('mutation-qa-report-invalid');
|
|
83
|
+
}
|
|
84
|
+
const expectedBlob = plan.eligibleFiles.find((entry) => entry.path === path)?.blobSha;
|
|
85
|
+
if (!expectedBlob || gitBlobSha(file.source, expectedBlob.length === 64 ? 'sha256' : 'sha1') !== expectedBlob) {
|
|
86
|
+
throw new Error('mutation-qa-report-source-mismatch');
|
|
87
|
+
}
|
|
88
|
+
const mutants = file.mutants;
|
|
89
|
+
if (mutants.length === 0 || mutants.length > 100_000)
|
|
90
|
+
throw new Error('mutation-qa-report-invalid');
|
|
91
|
+
let fileKilled = 0;
|
|
92
|
+
let fileSurvived = 0;
|
|
93
|
+
let fileNoCoverage = 0;
|
|
94
|
+
let fileTimeout = 0;
|
|
95
|
+
for (const mutant of mutants) {
|
|
96
|
+
if (!mutant || typeof mutant !== 'object' || Array.isArray(mutant)) {
|
|
97
|
+
throw new Error('mutation-qa-report-invalid');
|
|
98
|
+
}
|
|
99
|
+
const record = mutant;
|
|
100
|
+
if (typeof record.id !== 'string' || !record.id
|
|
101
|
+
|| typeof record.mutatorName !== 'string' || !record.mutatorName
|
|
102
|
+
|| !record.location || typeof record.location !== 'object' || Array.isArray(record.location)) {
|
|
103
|
+
throw new Error('mutation-qa-report-invalid');
|
|
104
|
+
}
|
|
105
|
+
switch (mutant.status) {
|
|
106
|
+
case 'Killed':
|
|
107
|
+
killed++;
|
|
108
|
+
fileKilled++;
|
|
109
|
+
break;
|
|
110
|
+
case 'Survived':
|
|
111
|
+
survived++;
|
|
112
|
+
fileSurvived++;
|
|
113
|
+
break;
|
|
114
|
+
case 'NoCoverage':
|
|
115
|
+
noCoverage++;
|
|
116
|
+
fileNoCoverage++;
|
|
117
|
+
break;
|
|
118
|
+
case 'Timeout':
|
|
119
|
+
timeout++;
|
|
120
|
+
fileTimeout++;
|
|
121
|
+
break;
|
|
122
|
+
case 'RuntimeError':
|
|
123
|
+
case 'CompileError':
|
|
124
|
+
invalid++;
|
|
125
|
+
break;
|
|
126
|
+
case 'Ignored': break;
|
|
127
|
+
default: throw new Error('mutation-qa-report-status-unsupported');
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (fileKilled + fileSurvived + fileNoCoverage + fileTimeout === 0) {
|
|
131
|
+
throw new Error('mutation-qa-report-no-scored-mutants');
|
|
132
|
+
}
|
|
133
|
+
if (score(fileKilled, fileSurvived, fileNoCoverage, fileTimeout) < areaThreshold(path, thresholds)) {
|
|
134
|
+
belowAreaThresholdCount++;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const mutationScore = score(killed, survived, noCoverage, timeout);
|
|
138
|
+
const runnerBreakCrossed = runnerBreakThreshold !== null
|
|
139
|
+
&& (killed + timeout) * 100
|
|
140
|
+
< runnerBreakThreshold * (killed + survived + noCoverage + timeout);
|
|
141
|
+
const outcome = mutationScore < thresholds.blockThreshold ? 'failed'
|
|
142
|
+
: mutationScore < thresholds.defaultThreshold || belowAreaThresholdCount > 0 || invalid > 0
|
|
143
|
+
? 'warned' : 'passed';
|
|
144
|
+
return Object.freeze({ schemaVersion: 1, kind: 'mutation-qa-verdict', planSha256: plan.planSha256,
|
|
145
|
+
reportSha256: createHash('sha256').update(rawReport).digest('hex'),
|
|
146
|
+
runnerBreakThreshold, runnerBreakCrossed,
|
|
147
|
+
outcome, mutationScore, killed, survived, noCoverage, timeout, invalid, belowAreaThresholdCount,
|
|
148
|
+
checkpointAccepted: false, localOnly: true });
|
|
149
|
+
}
|
|
@@ -1 +1,220 @@
|
|
|
1
|
-
|
|
1
|
+
/** Root-owned, read-only source scope for the protected mutation-test workflow. */
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { lstatSync, realpathSync } from 'node:fs';
|
|
4
|
+
import { resolve } from 'node:path';
|
|
5
|
+
import { mutationQaGit } from './mutation-qa-git.js';
|
|
6
|
+
import { loadMutationQaPolicy, policyExcludesPath } from './mutation-qa-policy.js';
|
|
7
|
+
function value(root, args) {
|
|
8
|
+
return mutationQaGit(root, args).toString('utf8').trim();
|
|
9
|
+
}
|
|
10
|
+
function eligiblePath(path) {
|
|
11
|
+
return path.length > 0 && path.length <= 240
|
|
12
|
+
&& /^[A-Za-z0-9_.-]+(?:\/[A-Za-z0-9_.-]+)*$/.test(path)
|
|
13
|
+
&& !path.split('/').some((part) => part === '.' || part === '..')
|
|
14
|
+
&& /\.(?:ts|tsx|js|jsx)$/.test(path)
|
|
15
|
+
&& !/\.d\.ts$|\.(?:test|spec)\.[jt]sx?$|(?:^|\/)__tests__\/|(?:^|\/)migrations\//.test(path);
|
|
16
|
+
}
|
|
17
|
+
function isSourceCandidate(path) {
|
|
18
|
+
return /\.(?:ts|tsx|js|jsx)$/.test(path)
|
|
19
|
+
&& !/\.d\.ts$|\.(?:test|spec)\.[jt]sx?$|(?:^|\/)__tests__\/|(?:^|\/)migrations\//.test(path);
|
|
20
|
+
}
|
|
21
|
+
/** No test execution, package installation, network, project write or QA verdict. */
|
|
22
|
+
export function planMutationQa(projectRoot, baseRef) {
|
|
23
|
+
const exactBaseSha = /^sha:([a-f0-9]{40}|[a-f0-9]{64})$/.exec(baseRef)?.[1];
|
|
24
|
+
const remoteRef = /^refs\/remotes\/[A-Za-z0-9][A-Za-z0-9_-]{0,63}\/[A-Za-z0-9][A-Za-z0-9/_-]{0,127}$/.test(baseRef)
|
|
25
|
+
&& !baseRef.includes('..') && !baseRef.includes('//') && !baseRef.endsWith('/');
|
|
26
|
+
if (!exactBaseSha && !remoteRef) {
|
|
27
|
+
throw new Error('mutation-qa-base-ref-invalid');
|
|
28
|
+
}
|
|
29
|
+
const root = resolve(projectRoot);
|
|
30
|
+
try {
|
|
31
|
+
if (realpathSync(root) !== root || !lstatSync(root).isDirectory()
|
|
32
|
+
|| value(root, ['rev-parse', '--show-toplevel']) !== root) {
|
|
33
|
+
throw new Error('mutation-qa-project-root-invalid');
|
|
34
|
+
}
|
|
35
|
+
const headSha = value(root, ['rev-parse', '--verify', 'HEAD']);
|
|
36
|
+
const baseRevision = exactBaseSha ?? baseRef;
|
|
37
|
+
const baseSha = value(root, ['rev-parse', '--verify', '--end-of-options', `${baseRevision}^{commit}`]);
|
|
38
|
+
if (exactBaseSha) {
|
|
39
|
+
try {
|
|
40
|
+
mutationQaGit(root, ['merge-base', '--is-ancestor', baseSha, headSha]);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
throw new Error('mutation-qa-base-not-ancestor');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const mergeBaseSha = value(root, ['merge-base', baseSha, headSha]);
|
|
47
|
+
if (![headSha, baseSha, mergeBaseSha].every((sha) => /^[a-f0-9]{40,64}$/.test(sha))) {
|
|
48
|
+
throw new Error('mutation-qa-revision-invalid');
|
|
49
|
+
}
|
|
50
|
+
if (exactBaseSha && (baseSha !== exactBaseSha || mergeBaseSha !== baseSha)) {
|
|
51
|
+
throw new Error('mutation-qa-base-not-ancestor');
|
|
52
|
+
}
|
|
53
|
+
if (mutationQaGit(root, ['status', '--porcelain=v1', '-z', '--untracked-files=all']).byteLength !== 0) {
|
|
54
|
+
throw new Error('mutation-qa-checkout-dirty');
|
|
55
|
+
}
|
|
56
|
+
const policy = loadMutationQaPolicy(root);
|
|
57
|
+
const changedPaths = mutationQaGit(root, ['diff', '--name-only', '-z', '--diff-filter=ACMR', mergeBaseSha, headSha])
|
|
58
|
+
.toString('utf8').split('\0').filter(Boolean);
|
|
59
|
+
if (changedPaths.length > 512)
|
|
60
|
+
throw new Error('mutation-qa-scope-too-large');
|
|
61
|
+
const sourcePaths = changedPaths.filter(isSourceCandidate);
|
|
62
|
+
if (sourcePaths.some((path) => !eligiblePath(path)))
|
|
63
|
+
throw new Error('mutation-qa-source-path-unsafe');
|
|
64
|
+
if (sourcePaths.length > 128)
|
|
65
|
+
throw new Error('mutation-qa-scope-too-large');
|
|
66
|
+
const eligibleFiles = sourcePaths.filter((path) => !policyExcludesPath(policy, path)).sort().map((path) => {
|
|
67
|
+
const entry = value(root, ['ls-tree', 'HEAD', '--', path]);
|
|
68
|
+
const match = entry.match(/^(100644|100755) blob ([a-f0-9]{40,64})\t(.+)$/);
|
|
69
|
+
if (!match || match[3] !== path)
|
|
70
|
+
throw new Error('mutation-qa-source-not-regular');
|
|
71
|
+
return Object.freeze({ path, blobSha: match[2] });
|
|
72
|
+
});
|
|
73
|
+
if (value(root, ['rev-parse', '--verify', 'HEAD']) !== headSha
|
|
74
|
+
|| value(root, ['rev-parse', '--verify', '--end-of-options', `${baseRevision}^{commit}`]) !== baseSha
|
|
75
|
+
|| mutationQaGit(root, ['status', '--porcelain=v1', '-z', '--untracked-files=all']).byteLength !== 0) {
|
|
76
|
+
throw new Error('mutation-qa-physical-drift');
|
|
77
|
+
}
|
|
78
|
+
const fields = { schemaVersion: 1, kind: 'mutation-qa-plan',
|
|
79
|
+
outcome: eligibleFiles.length > 0 ? 'ready' : 'skipped-no-files',
|
|
80
|
+
baseRef, baseSha, headSha, mergeBaseSha, policy, eligibleFiles,
|
|
81
|
+
checkpointAccepted: false, localOnly: true };
|
|
82
|
+
return Object.freeze({ ...fields,
|
|
83
|
+
planSha256: createHash('sha256').update('mutation-qa-plan-v1\0')
|
|
84
|
+
.update(JSON.stringify(fields)).digest('hex'),
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (error instanceof Error && error.message.startsWith('mutation-qa-'))
|
|
89
|
+
throw error;
|
|
90
|
+
throw new Error('mutation-qa-plan-unavailable');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export async function mutationQaCliHandler(args) {
|
|
94
|
+
let projectRoot = process.cwd();
|
|
95
|
+
let baseRef = '';
|
|
96
|
+
let baseSha = '';
|
|
97
|
+
let planSha = '';
|
|
98
|
+
let authorizeRun = false;
|
|
99
|
+
let recordCheckpoint = false;
|
|
100
|
+
let format = 'plain';
|
|
101
|
+
const seen = new Set();
|
|
102
|
+
try {
|
|
103
|
+
if (args[0] !== 'plan' && args[0] !== 'run' && args[0] !== 'execute' && args[0] !== 'checkpoint'
|
|
104
|
+
&& args[0] !== 'gate') {
|
|
105
|
+
throw new Error('mutation-qa-action-invalid');
|
|
106
|
+
}
|
|
107
|
+
for (let index = 1; index < args.length; index++) {
|
|
108
|
+
const arg = args[index];
|
|
109
|
+
if (seen.has(arg))
|
|
110
|
+
throw new Error('mutation-qa-argument-duplicate');
|
|
111
|
+
seen.add(arg);
|
|
112
|
+
const next = () => args[++index] ?? '';
|
|
113
|
+
if (arg === '--project-root')
|
|
114
|
+
projectRoot = next();
|
|
115
|
+
else if (arg === '--base-ref')
|
|
116
|
+
baseRef = next();
|
|
117
|
+
else if (arg === '--base-sha')
|
|
118
|
+
baseSha = next();
|
|
119
|
+
else if (arg === '--plan-sha')
|
|
120
|
+
planSha = next();
|
|
121
|
+
else if (arg === '--authorize-run')
|
|
122
|
+
authorizeRun = true;
|
|
123
|
+
else if (arg === '--record-checkpoint')
|
|
124
|
+
recordCheckpoint = true;
|
|
125
|
+
else if (arg === '--format') {
|
|
126
|
+
const selected = next();
|
|
127
|
+
if (selected !== 'plain' && selected !== 'json')
|
|
128
|
+
throw new Error('mutation-qa-format-invalid');
|
|
129
|
+
format = selected;
|
|
130
|
+
}
|
|
131
|
+
else
|
|
132
|
+
throw new Error('mutation-qa-argument-invalid');
|
|
133
|
+
}
|
|
134
|
+
if (!projectRoot || Boolean(baseRef) === Boolean(baseSha)) {
|
|
135
|
+
throw new Error('mutation-qa-target-required');
|
|
136
|
+
}
|
|
137
|
+
if (baseSha && !/^([a-f0-9]{40}|[a-f0-9]{64})$/.test(baseSha)) {
|
|
138
|
+
throw new Error('mutation-qa-base-ref-invalid');
|
|
139
|
+
}
|
|
140
|
+
const baseSelector = baseSha ? `sha:${baseSha}` : baseRef;
|
|
141
|
+
if (args[0] === 'execute') {
|
|
142
|
+
if (!authorizeRun || !planSha || recordCheckpoint) {
|
|
143
|
+
throw new Error('mutation-qa-execute-authorization-required');
|
|
144
|
+
}
|
|
145
|
+
const { executeMutationQaPlan } = await import('./mutation-qa-gate.js');
|
|
146
|
+
const execution = executeMutationQaPlan(projectRoot, baseSelector, planSha);
|
|
147
|
+
if (format === 'json')
|
|
148
|
+
console.log(JSON.stringify({ ok: true, execution }));
|
|
149
|
+
else
|
|
150
|
+
console.log(`mutation-qa execute: ${execution.decision.status} head=${execution.headSha} debt=${execution.followUpDebt ? 'recorded' : 'none'} qaPassed=${execution.decision.qaPassed}`);
|
|
151
|
+
// Exit 2 is a recorded-debt continuation signal, never a shell-level QA pass.
|
|
152
|
+
return execution.decision.safeToContinueLocalQa ? 0
|
|
153
|
+
: execution.continuationAuthorized ? 2 : 1;
|
|
154
|
+
}
|
|
155
|
+
if (args[0] === 'gate') {
|
|
156
|
+
if (!planSha || authorizeRun || recordCheckpoint) {
|
|
157
|
+
throw new Error('mutation-qa-gate-options-invalid');
|
|
158
|
+
}
|
|
159
|
+
const { classifyMutationQaGate } = await import('./mutation-qa-gate.js');
|
|
160
|
+
const decision = classifyMutationQaGate(projectRoot, baseSelector, planSha);
|
|
161
|
+
if (format === 'json')
|
|
162
|
+
console.log(JSON.stringify({ ok: true, decision }));
|
|
163
|
+
else
|
|
164
|
+
console.log(`mutation-qa gate: ${decision.status} head=${decision.headSha}`);
|
|
165
|
+
// This action is also a shell/CI gate. A typed decision is not a pass:
|
|
166
|
+
// warned and unobserved still need a separate durable debt checkpoint.
|
|
167
|
+
return decision.safeToContinueLocalQa ? 0 : 1;
|
|
168
|
+
}
|
|
169
|
+
if (args[0] === 'checkpoint') {
|
|
170
|
+
if (!planSha || authorizeRun || recordCheckpoint) {
|
|
171
|
+
throw new Error('mutation-qa-checkpoint-options-invalid');
|
|
172
|
+
}
|
|
173
|
+
const { readMutationQaCheckpoint } = await import('./mutation-qa-checkpoint.js');
|
|
174
|
+
const checkpoint = readMutationQaCheckpoint(projectRoot, baseSelector, planSha);
|
|
175
|
+
if (format === 'json')
|
|
176
|
+
console.log(JSON.stringify({ ok: true, checkpoint: checkpoint ?? null }));
|
|
177
|
+
else
|
|
178
|
+
console.log(`mutation-qa checkpoint: ${checkpoint ? checkpoint.verdict : 'none'}`);
|
|
179
|
+
return 0;
|
|
180
|
+
}
|
|
181
|
+
if (args[0] === 'run') {
|
|
182
|
+
if (!authorizeRun || !planSha)
|
|
183
|
+
throw new Error('mutation-qa-run-authorization-required');
|
|
184
|
+
if (recordCheckpoint) {
|
|
185
|
+
const { runAndRecordMutationQa } = await import('./mutation-qa-checkpoint.js');
|
|
186
|
+
const { result, checkpoint } = runAndRecordMutationQa(projectRoot, baseSelector, planSha);
|
|
187
|
+
if (format === 'json')
|
|
188
|
+
console.log(JSON.stringify({ ok: true, result, checkpoint: checkpoint ?? null }));
|
|
189
|
+
else
|
|
190
|
+
console.log(`mutation-qa run: ${result.outcome} head=${result.headSha} checkpoint=${checkpoint ? 'accepted' : 'none'}`);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
const { runMutationQa } = await import('./mutation-qa-run.js');
|
|
194
|
+
const result = runMutationQa(projectRoot, baseSelector, planSha);
|
|
195
|
+
if (format === 'json')
|
|
196
|
+
console.log(JSON.stringify({ ok: true, result }));
|
|
197
|
+
else
|
|
198
|
+
console.log(`mutation-qa run: ${result.outcome} head=${result.headSha}`);
|
|
199
|
+
}
|
|
200
|
+
return 0;
|
|
201
|
+
}
|
|
202
|
+
if (authorizeRun || planSha || recordCheckpoint)
|
|
203
|
+
throw new Error('mutation-qa-plan-options-invalid');
|
|
204
|
+
const plan = planMutationQa(projectRoot, baseSelector);
|
|
205
|
+
if (format === 'json')
|
|
206
|
+
console.log(JSON.stringify({ ok: true, plan }));
|
|
207
|
+
else
|
|
208
|
+
console.log(`mutation-qa plan: ${plan.outcome} files=${plan.eligibleFiles.length} head=${plan.headSha}`);
|
|
209
|
+
return 0;
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
const reason = error instanceof Error && /^mutation-qa-[a-z0-9-]+$/.test(error.message)
|
|
213
|
+
? error.message : 'mutation-qa-unavailable';
|
|
214
|
+
if (format === 'json')
|
|
215
|
+
console.log(JSON.stringify({ ok: false, reasonCode: reason }));
|
|
216
|
+
else
|
|
217
|
+
console.error(`mutation-qa: ${reason}`);
|
|
218
|
+
return 1;
|
|
219
|
+
}
|
|
220
|
+
}
|