@ornexus/neocortex 4.60.72 → 4.60.73
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 +24 -24
- 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 +212 -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 +417 -2
- package/packages/client/dist/agent/update-agent-yaml.js +102 -1
- package/packages/client/dist/agent/update-description.js +251 -1
- package/packages/client/dist/cache/crypto-utils.js +78 -1
- package/packages/client/dist/cache/encrypted-cache.js +108 -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 +7200 -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.js +156 -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/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 +90 -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.d.ts +22 -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 +228 -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 +1234 -4
- package/packages/client/dist/git/epic-operational-state.d.ts +198 -0
- package/packages/client/dist/git/epic-operational-state.js +672 -0
- package/packages/client/dist/git/git-lifecycle-step-ids.js +14 -1
- package/packages/client/dist/git/git-lifecycle-store.d.ts +9 -1
- package/packages/client/dist/git/git-lifecycle-store.js +1981 -9
- 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/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 +47 -1
- package/packages/client/dist/invocation/invoke-input.js +24 -1
- package/packages/client/dist/license/index.js +5 -1
- package/packages/client/dist/license/license-client.js +304 -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.js +1007 -40
- package/packages/client/dist/memory/shared-project-memory-types.js +253 -2
- package/packages/client/dist/migrations/epic-lifecycle-backfill.d.ts +97 -0
- package/packages/client/dist/migrations/epic-lifecycle-backfill.js +1060 -0
- 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.d.ts +22 -0
- 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/headless/adapters.js +49 -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 +110 -2
- package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +1236 -8
- package/packages/client/dist/runner/headless/epic-terminal-git-runner.js +318 -2
- package/packages/client/dist/runner/headless/fake-adapter.js +62 -1
- package/packages/client/dist/runner/headless/managed-profile.js +132 -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 +885 -1
- package/packages/client/dist/runner/headless/run-yoloop.js +2574 -2
- package/packages/client/dist/runner/headless/types.js +574 -2
- 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.d.ts +8 -0
- package/packages/client/dist/state/project-state-snapshot.js +1731 -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.js +126 -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.d.ts +65 -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.d.ts +8 -0
- package/packages/client/dist/yoloop/yoloop-client-state-store.js +1920 -1
- package/packages/shared/dist/yolo/spec-envelope.js +3 -6
- package/targets-stubs/antigravity/gemini.md +1 -1
- package/targets-stubs/antigravity/skill/SKILL.md +1 -1
- package/targets-stubs/claude-code/neocortex-root.agent.yaml +1 -1
- package/targets-stubs/claude-code/neocortex-root.md +2 -2
- package/targets-stubs/claude-code/neocortex.agent.yaml +1 -1
- package/targets-stubs/claude-code/neocortex.md +2 -2
- package/targets-stubs/codex/AGENTS.md +1 -1
- package/targets-stubs/cursor/agent.md +2 -2
- package/targets-stubs/gemini-cli/agent.md +2 -2
- package/targets-stubs/opencode/neocortex-root.md +1 -1
- package/targets-stubs/vscode/neocortex.agent.md +2 -2
|
@@ -1 +1,258 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Static first-pass contract for isolated Pact artifacts. Parsing never runs
|
|
3
|
+
* generated code. A passing result is not a Pact execution/QA receipt.
|
|
4
|
+
*/
|
|
5
|
+
import { parse } from '@babel/parser';
|
|
6
|
+
import { lstatSync, realpathSync } from 'node:fs';
|
|
7
|
+
import { join, posix, resolve } from 'node:path';
|
|
8
|
+
const MAX_SOURCE_BYTES = 256 * 1024;
|
|
9
|
+
const MAX_AST_NODES = 100_000;
|
|
10
|
+
function record(value) {
|
|
11
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
12
|
+
}
|
|
13
|
+
function importedNames(node) {
|
|
14
|
+
const names = new Set();
|
|
15
|
+
if (!Array.isArray(node.specifiers))
|
|
16
|
+
return names;
|
|
17
|
+
for (const specifier of node.specifiers) {
|
|
18
|
+
if (!record(specifier) || specifier.type !== 'ImportSpecifier'
|
|
19
|
+
|| !record(specifier.imported) || typeof specifier.imported.name !== 'string')
|
|
20
|
+
continue;
|
|
21
|
+
names.add(specifier.imported.name);
|
|
22
|
+
}
|
|
23
|
+
return names;
|
|
24
|
+
}
|
|
25
|
+
function projectImportNames(node, testPath, projectRoot) {
|
|
26
|
+
const importPath = record(node.source) ? node.source.value : undefined;
|
|
27
|
+
if (typeof importPath !== 'string' || importPath.length > 240
|
|
28
|
+
|| !/^\.\.?\/[A-Za-z0-9_./-]+$/.test(importPath)
|
|
29
|
+
|| node.importKind === 'type' || !Array.isArray(node.specifiers)
|
|
30
|
+
|| node.specifiers.length < 1 || node.specifiers.length > 16) {
|
|
31
|
+
throw new Error('private-execution-pact-source-invalid');
|
|
32
|
+
}
|
|
33
|
+
const relative = posix.normalize(posix.join(posix.dirname(testPath), importPath));
|
|
34
|
+
if (!/^(?:src|app|lib|packages|clients)\/[A-Za-z0-9_./-]+$/.test(relative)
|
|
35
|
+
|| relative.split('/').some((segment) => segment === '..' || segment === '.')) {
|
|
36
|
+
throw new Error('private-execution-pact-source-invalid');
|
|
37
|
+
}
|
|
38
|
+
const root = resolve(projectRoot);
|
|
39
|
+
if (realpathSync(root) !== root || !lstatSync(root).isDirectory()) {
|
|
40
|
+
throw new Error('private-execution-pact-source-invalid');
|
|
41
|
+
}
|
|
42
|
+
const candidates = /\.(?:ts|tsx|js|mjs)$/.test(relative)
|
|
43
|
+
? [relative, ...(relative.endsWith('.js') ? [`${relative.slice(0, -3)}.ts`,
|
|
44
|
+
`${relative.slice(0, -3)}.tsx`] : [])]
|
|
45
|
+
: [`${relative}.ts`, `${relative}.tsx`, `${relative}.js`, `${relative}.mjs`,
|
|
46
|
+
`${relative}/index.ts`, `${relative}/index.tsx`, `${relative}/index.js`];
|
|
47
|
+
const matches = [];
|
|
48
|
+
for (const candidate of candidates) {
|
|
49
|
+
let current = root;
|
|
50
|
+
try {
|
|
51
|
+
const parts = candidate.split('/');
|
|
52
|
+
for (const [index, part] of parts.entries()) {
|
|
53
|
+
current = join(current, part);
|
|
54
|
+
const entry = lstatSync(current);
|
|
55
|
+
if (entry.isSymbolicLink() || (index === parts.length - 1
|
|
56
|
+
? !entry.isFile() || entry.size < 1 || entry.size > 1024 * 1024
|
|
57
|
+
: !entry.isDirectory()))
|
|
58
|
+
throw new Error('private-execution-pact-source-invalid');
|
|
59
|
+
}
|
|
60
|
+
matches.push(candidate);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (error.code !== 'ENOENT') {
|
|
64
|
+
throw new Error('private-execution-pact-source-invalid');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (matches.length !== 1)
|
|
69
|
+
throw new Error('private-execution-pact-source-invalid');
|
|
70
|
+
const names = new Set();
|
|
71
|
+
for (const specifier of node.specifiers) {
|
|
72
|
+
if (!record(specifier) || !['ImportSpecifier', 'ImportDefaultSpecifier'].includes(specifier.type)
|
|
73
|
+
|| specifier.importKind === 'type' || !record(specifier.local)
|
|
74
|
+
|| specifier.local.type !== 'Identifier' || typeof specifier.local.name !== 'string') {
|
|
75
|
+
throw new Error('private-execution-pact-source-invalid');
|
|
76
|
+
}
|
|
77
|
+
names.add(specifier.local.name);
|
|
78
|
+
}
|
|
79
|
+
return names;
|
|
80
|
+
}
|
|
81
|
+
function memberName(node) {
|
|
82
|
+
if (!record(node) || node.type !== 'MemberExpression' || node.computed === true
|
|
83
|
+
|| !record(node.property) || node.property.type !== 'Identifier')
|
|
84
|
+
return undefined;
|
|
85
|
+
return typeof node.property.name === 'string' ? node.property.name : undefined;
|
|
86
|
+
}
|
|
87
|
+
function requestLiterals(node) {
|
|
88
|
+
if (!record(node) || node.type !== 'ObjectExpression' || !Array.isArray(node.properties))
|
|
89
|
+
return undefined;
|
|
90
|
+
let method;
|
|
91
|
+
let path;
|
|
92
|
+
for (const property of node.properties) {
|
|
93
|
+
if (!record(property) || property.type !== 'ObjectProperty' || property.computed === true
|
|
94
|
+
|| !record(property.key) || !record(property.value))
|
|
95
|
+
return undefined;
|
|
96
|
+
const name = property.key.type === 'Identifier' ? property.key.name
|
|
97
|
+
: property.key.type === 'StringLiteral' ? property.key.value : undefined;
|
|
98
|
+
if (name === 'method' || name === 'path') {
|
|
99
|
+
if (property.value.type !== 'StringLiteral' || typeof property.value.value !== 'string')
|
|
100
|
+
return undefined;
|
|
101
|
+
if (name === 'method') {
|
|
102
|
+
if (method !== undefined)
|
|
103
|
+
return undefined;
|
|
104
|
+
method = property.value.value;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
if (path !== undefined)
|
|
108
|
+
return undefined;
|
|
109
|
+
path = property.value.value;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return method !== undefined && path !== undefined ? { method, path } : undefined;
|
|
114
|
+
}
|
|
115
|
+
function matchesEndpointPath(template, actual) {
|
|
116
|
+
if (template.length > 180 || actual.length > 2048 || /[?#]/.test(actual))
|
|
117
|
+
return false;
|
|
118
|
+
const expected = template.split('/');
|
|
119
|
+
const candidate = actual.split('/');
|
|
120
|
+
if (expected.length !== candidate.length)
|
|
121
|
+
return false;
|
|
122
|
+
return expected.every((segment, index) => {
|
|
123
|
+
const value = candidate[index];
|
|
124
|
+
if (!segment.includes('{') && !segment.includes('}'))
|
|
125
|
+
return segment === value;
|
|
126
|
+
// One parameter per segment keeps matching linear and rejects ambiguous
|
|
127
|
+
// adjacent templates instead of relying on a backtracking regex.
|
|
128
|
+
const parameter = /^([^{}]*)\{[^{}]+\}([^{}]*)$/.exec(segment);
|
|
129
|
+
if (!parameter || !value.startsWith(parameter[1]) || !value.endsWith(parameter[2]))
|
|
130
|
+
return false;
|
|
131
|
+
return value.length > parameter[1].length + parameter[2].length;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/** Reject comment-only, malformed and non-Pact files before a root patch effect. */
|
|
135
|
+
export function validatePactTestSource(path, source, brokerUrl, expectedInteraction, projectRoot, matchersAggressive) {
|
|
136
|
+
const kind = path === 'tests/pact/provider/verify.test.ts' ? 'provider' : 'consumer';
|
|
137
|
+
if ((kind === 'consumer' && !/^tests\/pact\/consumer\/[a-z0-9-]+\.test\.ts$/.test(path))
|
|
138
|
+
|| typeof source !== 'string' || Buffer.byteLength(source, 'utf8') < 80
|
|
139
|
+
|| Buffer.byteLength(source, 'utf8') > MAX_SOURCE_BYTES
|
|
140
|
+
|| brokerUrl !== null && source.includes(brokerUrl)) {
|
|
141
|
+
throw new Error('private-execution-pact-source-invalid');
|
|
142
|
+
}
|
|
143
|
+
let ast;
|
|
144
|
+
try {
|
|
145
|
+
ast = parse(source, { sourceType: 'module', plugins: ['typescript'] });
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
throw new Error('private-execution-pact-source-invalid');
|
|
149
|
+
}
|
|
150
|
+
const pactImports = new Set();
|
|
151
|
+
const vitestImports = new Set();
|
|
152
|
+
const appImports = new Set();
|
|
153
|
+
for (const statement of ast.program.body) {
|
|
154
|
+
if (statement.type !== 'ImportDeclaration')
|
|
155
|
+
continue;
|
|
156
|
+
const importPath = statement.source.value;
|
|
157
|
+
if (importPath !== '@pact-foundation/pact' && importPath !== 'vitest') {
|
|
158
|
+
if (kind !== 'consumer' || !projectRoot) {
|
|
159
|
+
throw new Error('private-execution-pact-source-invalid');
|
|
160
|
+
}
|
|
161
|
+
for (const name of projectImportNames(statement, path, projectRoot)) {
|
|
162
|
+
if (appImports.has(name) || ['fetch', 'describe', 'it', 'expect',
|
|
163
|
+
'PactV3', 'MatchersV3', 'Verifier'].includes(name)) {
|
|
164
|
+
throw new Error('private-execution-pact-source-invalid');
|
|
165
|
+
}
|
|
166
|
+
appImports.add(name);
|
|
167
|
+
}
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
const names = importedNames(statement);
|
|
171
|
+
for (const name of names)
|
|
172
|
+
(importPath === '@pact-foundation/pact' ? pactImports : vitestImports).add(name);
|
|
173
|
+
}
|
|
174
|
+
if (!vitestImports.has('describe') || !vitestImports.has('it')
|
|
175
|
+
|| (kind === 'consumer' && (!pactImports.has('PactV3') || !vitestImports.has('expect')))
|
|
176
|
+
|| (kind === 'provider' && !pactImports.has('Verifier'))
|
|
177
|
+
|| [...appImports].some((name) => pactImports.has(name) || vitestImports.has(name))) {
|
|
178
|
+
throw new Error('private-execution-pact-source-invalid');
|
|
179
|
+
}
|
|
180
|
+
// The private root decision is authoritative; generated tests cannot broaden
|
|
181
|
+
// literal contracts with matcher helpers when exact correspondence was chosen.
|
|
182
|
+
if (kind === 'consumer' && matchersAggressive === false
|
|
183
|
+
&& [...pactImports].some((name) => name !== 'PactV3')) {
|
|
184
|
+
throw new Error('private-execution-pact-source-invalid');
|
|
185
|
+
}
|
|
186
|
+
const calls = new Set();
|
|
187
|
+
const constructors = new Set();
|
|
188
|
+
let brokerEnv = false;
|
|
189
|
+
let expectedRequest = false;
|
|
190
|
+
let appClientCalled = false;
|
|
191
|
+
const stack = [
|
|
192
|
+
{ node: ast.program, inExecuteTest: false },
|
|
193
|
+
];
|
|
194
|
+
let visited = 0;
|
|
195
|
+
while (stack.length > 0) {
|
|
196
|
+
const item = stack.pop();
|
|
197
|
+
const current = item.node;
|
|
198
|
+
if (!record(current))
|
|
199
|
+
continue;
|
|
200
|
+
if (++visited > MAX_AST_NODES)
|
|
201
|
+
throw new Error('private-execution-pact-source-invalid');
|
|
202
|
+
if (current.type === 'NewExpression' && record(current.callee)
|
|
203
|
+
&& current.callee.type === 'Identifier' && typeof current.callee.name === 'string') {
|
|
204
|
+
constructors.add(current.callee.name);
|
|
205
|
+
if (item.inExecuteTest && appImports.has(current.callee.name))
|
|
206
|
+
appClientCalled = true;
|
|
207
|
+
}
|
|
208
|
+
if (current.type === 'CallExpression') {
|
|
209
|
+
const callee = current.callee;
|
|
210
|
+
if (record(callee) && callee.type === 'Identifier' && typeof callee.name === 'string') {
|
|
211
|
+
calls.add(callee.name);
|
|
212
|
+
if (item.inExecuteTest && appImports.has(callee.name))
|
|
213
|
+
appClientCalled = true;
|
|
214
|
+
}
|
|
215
|
+
const member = memberName(callee);
|
|
216
|
+
if (member)
|
|
217
|
+
calls.add(member);
|
|
218
|
+
if (member === 'withRequest' && expectedInteraction && Array.isArray(current.arguments)) {
|
|
219
|
+
const request = requestLiterals(current.arguments[0]);
|
|
220
|
+
expectedRequest ||= request?.method.toUpperCase() === expectedInteraction.method
|
|
221
|
+
&& matchesEndpointPath(expectedInteraction.endpointPath, request?.path ?? '');
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (current.type === 'MemberExpression' && memberName(current) === 'PACT_BROKER_URL'
|
|
225
|
+
&& record(current.object) && memberName(current.object) === 'env'
|
|
226
|
+
&& record(current.object.object) && current.object.object.type === 'Identifier'
|
|
227
|
+
&& current.object.object.name === 'process')
|
|
228
|
+
brokerEnv = true;
|
|
229
|
+
for (const [key, value] of Object.entries(current)) {
|
|
230
|
+
if (key === 'loc' || key === 'extra' || key === 'comments'
|
|
231
|
+
|| key === 'leadingComments' || key === 'trailingComments' || key === 'innerComments')
|
|
232
|
+
continue;
|
|
233
|
+
const inExecuteTest = item.inExecuteTest
|
|
234
|
+
|| current.type === 'CallExpression' && memberName(current.callee) === 'executeTest'
|
|
235
|
+
&& key === 'arguments';
|
|
236
|
+
if (Array.isArray(value)) {
|
|
237
|
+
for (const node of value)
|
|
238
|
+
stack.push({ node, inExecuteTest });
|
|
239
|
+
}
|
|
240
|
+
else if (record(value))
|
|
241
|
+
stack.push({ node: value, inExecuteTest });
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const requiredCalls = kind === 'consumer'
|
|
245
|
+
? ['describe', 'it', 'withRequest', 'willRespondWith', 'executeTest', 'expect']
|
|
246
|
+
: ['describe', 'it', 'verifyProvider'];
|
|
247
|
+
if (requiredCalls.some((call) => !calls.has(call))
|
|
248
|
+
|| !constructors.has(kind === 'consumer' ? 'PactV3' : 'Verifier')
|
|
249
|
+
|| kind === 'consumer' && expectedInteraction !== undefined
|
|
250
|
+
&& (expectedInteraction.filePath !== path || !expectedRequest)
|
|
251
|
+
|| kind === 'provider' && brokerUrl !== null && !brokerEnv) {
|
|
252
|
+
throw new Error('private-execution-pact-source-invalid');
|
|
253
|
+
}
|
|
254
|
+
return Object.freeze({ schemaVersion: 1,
|
|
255
|
+
consumerBinding: kind === 'provider' ? 'provider-template'
|
|
256
|
+
: appClientCalled ? 'app-import-candidate' : 'mock-only-scaffold',
|
|
257
|
+
executionVerified: false, publicSafe: true });
|
|
258
|
+
}
|
|
@@ -1,3 +1,290 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Root-owned Pact toolchain inspection and scratch-only npm candidate planning.
|
|
3
|
+
* A matching manifest and lockfile are configuration evidence, never a
|
|
4
|
+
* test-execution/QA receipt.
|
|
5
|
+
*/
|
|
6
|
+
import { spawnSync } from 'node:child_process';
|
|
7
|
+
import { createHash } from 'node:crypto';
|
|
8
|
+
import { constants } from 'node:fs';
|
|
9
|
+
import { closeSync, fstatSync, lstatSync, mkdtempSync, openSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
|
|
10
|
+
import { tmpdir } from 'node:os';
|
|
11
|
+
import { join, resolve } from 'node:path';
|
|
12
|
+
import { parseDocument } from 'yaml';
|
|
13
|
+
function result(outcome, reasonCode) {
|
|
14
|
+
return Object.freeze({ schemaVersion: 1, outcome, reasonCode,
|
|
15
|
+
executionVerified: false, publicSafe: true });
|
|
16
|
+
}
|
|
17
|
+
function record(value) {
|
|
18
|
+
return !!value && typeof value === 'object' && !Array.isArray(value)
|
|
19
|
+
&& Object.getPrototypeOf(value) === Object.prototype;
|
|
20
|
+
}
|
|
21
|
+
function readRegular(root, relative, maxBytes) {
|
|
22
|
+
const path = join(root, relative);
|
|
23
|
+
let handle;
|
|
24
|
+
try {
|
|
25
|
+
handle = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (error.code === 'ENOENT')
|
|
29
|
+
return undefined;
|
|
30
|
+
throw new Error('pact-toolchain-path-unsafe');
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const entry = fstatSync(handle);
|
|
34
|
+
if (!entry.isFile() || entry.size < 1 || entry.size > maxBytes) {
|
|
35
|
+
throw new Error('pact-toolchain-path-unsafe');
|
|
36
|
+
}
|
|
37
|
+
return new TextDecoder('utf-8', { fatal: true }).decode(readFileSync(handle));
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
closeSync(handle);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function parseStrictJson(text) {
|
|
44
|
+
try {
|
|
45
|
+
const document = parseDocument(text, { strict: true, uniqueKeys: true,
|
|
46
|
+
schema: 'core', customTags: [] });
|
|
47
|
+
if (document.errors.length || document.warnings.length)
|
|
48
|
+
return undefined;
|
|
49
|
+
const parsed = JSON.parse(text);
|
|
50
|
+
return record(parsed) ? parsed : undefined;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** No project mutation, dependency installation, script execution, or private values. */
|
|
57
|
+
export function inspectPactToolchain(projectRoot, generateProvider) {
|
|
58
|
+
if (typeof generateProvider !== 'boolean') {
|
|
59
|
+
return result('unsupported', 'manifest-invalid');
|
|
60
|
+
}
|
|
61
|
+
const root = resolve(projectRoot);
|
|
62
|
+
try {
|
|
63
|
+
if (realpathSync(root) !== root || !lstatSync(root).isDirectory()) {
|
|
64
|
+
return result('unsupported', 'manifest-invalid');
|
|
65
|
+
}
|
|
66
|
+
for (const alternate of ['pnpm-lock.yaml', 'yarn.lock', 'bun.lock', 'bun.lockb']) {
|
|
67
|
+
if (readRegular(root, alternate, 8 * 1024 * 1024) !== undefined) {
|
|
68
|
+
return result('unsupported', 'package-manager-unsupported');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const manifestText = readRegular(root, 'package.json', 1024 * 1024);
|
|
72
|
+
if (manifestText === undefined)
|
|
73
|
+
return result('requires-root-integration', 'manifest-missing');
|
|
74
|
+
const manifest = parseStrictJson(manifestText);
|
|
75
|
+
if (!manifest)
|
|
76
|
+
return result('unsupported', 'manifest-invalid');
|
|
77
|
+
if (manifest.packageManager !== undefined
|
|
78
|
+
&& (typeof manifest.packageManager !== 'string'
|
|
79
|
+
|| !/^npm@[0-9]+(?:\.[0-9]+){0,2}$/.test(manifest.packageManager))) {
|
|
80
|
+
return result('unsupported', 'package-manager-unsupported');
|
|
81
|
+
}
|
|
82
|
+
const scripts = manifest.scripts;
|
|
83
|
+
if (!record(scripts) || typeof scripts['pact:consumer'] !== 'string'
|
|
84
|
+
|| !/^vitest run(?: --maxWorkers=1)? tests\/pact\/consumer\/$/.test(scripts['pact:consumer'])
|
|
85
|
+
|| generateProvider && (typeof scripts['pact:provider'] !== 'string'
|
|
86
|
+
|| !/^vitest run(?: --maxWorkers=1)? tests\/pact\/provider\/$/.test(scripts['pact:provider']))) {
|
|
87
|
+
return result('requires-root-integration', 'scripts-missing');
|
|
88
|
+
}
|
|
89
|
+
const devDependencies = manifest.devDependencies;
|
|
90
|
+
if (!record(devDependencies)
|
|
91
|
+
|| typeof devDependencies['@pact-foundation/pact'] !== 'string'
|
|
92
|
+
|| typeof devDependencies.vitest !== 'string') {
|
|
93
|
+
return result('requires-root-integration', 'dependencies-missing');
|
|
94
|
+
}
|
|
95
|
+
const boundedVersion = /^(?:\^|~)?[0-9]+\.[0-9]+\.[0-9]+(?:-[a-zA-Z0-9.-]+)?$/;
|
|
96
|
+
if (!boundedVersion.test(devDependencies['@pact-foundation/pact'])
|
|
97
|
+
|| !boundedVersion.test(devDependencies.vitest)) {
|
|
98
|
+
return result('unsupported', 'dependency-spec-unsupported');
|
|
99
|
+
}
|
|
100
|
+
const lockText = readRegular(root, 'package-lock.json', 8 * 1024 * 1024);
|
|
101
|
+
if (lockText === undefined)
|
|
102
|
+
return result('requires-root-integration', 'lockfile-missing');
|
|
103
|
+
const lock = parseStrictJson(lockText);
|
|
104
|
+
if (!lock || !record(lock.packages) || !record(lock.packages[''])
|
|
105
|
+
|| ![2, 3].includes(lock.lockfileVersion)) {
|
|
106
|
+
return result('unsupported', 'lockfile-invalid');
|
|
107
|
+
}
|
|
108
|
+
const lockedDeps = lock.packages[''].devDependencies;
|
|
109
|
+
const lockedPact = lock.packages['node_modules/@pact-foundation/pact'];
|
|
110
|
+
const lockedVitest = lock.packages['node_modules/vitest'];
|
|
111
|
+
if (!record(lockedDeps)
|
|
112
|
+
|| lockedDeps['@pact-foundation/pact'] !== devDependencies['@pact-foundation/pact']
|
|
113
|
+
|| lockedDeps.vitest !== devDependencies.vitest
|
|
114
|
+
|| !record(lockedPact) || typeof lockedPact.version !== 'string'
|
|
115
|
+
|| !boundedVersion.test(lockedPact.version)
|
|
116
|
+
|| !record(lockedVitest) || typeof lockedVitest.version !== 'string'
|
|
117
|
+
|| !boundedVersion.test(lockedVitest.version)) {
|
|
118
|
+
return result('requires-root-integration', 'lockfile-drift');
|
|
119
|
+
}
|
|
120
|
+
return result('manifest-aligned', 'manifest-aligned-unverified');
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return result('unsupported', 'manifest-invalid');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const PACT_VERSION = '17.1.4';
|
|
127
|
+
const VITEST_VERSION = '3.2.4';
|
|
128
|
+
const CONSUMER_SCRIPT = 'vitest run --maxWorkers=1 tests/pact/consumer/';
|
|
129
|
+
const PROVIDER_SCRIPT = 'vitest run --maxWorkers=1 tests/pact/provider/';
|
|
130
|
+
const BOUNDED_NPM_SPEC = /^(?:\^|~)?[0-9]+\.[0-9]+\.[0-9]+$/;
|
|
131
|
+
function safeRegistryLock(text) {
|
|
132
|
+
const lock = parseStrictJson(text);
|
|
133
|
+
if (!lock || ![2, 3].includes(lock.lockfileVersion)
|
|
134
|
+
|| !record(lock.packages) || Object.keys(lock.packages).length > 10_000)
|
|
135
|
+
return false;
|
|
136
|
+
for (const value of Object.values(lock.packages)) {
|
|
137
|
+
if (!record(value) || value.link === true)
|
|
138
|
+
return false;
|
|
139
|
+
if (value.resolved === undefined)
|
|
140
|
+
continue;
|
|
141
|
+
if (typeof value.resolved !== 'string' || typeof value.integrity !== 'string'
|
|
142
|
+
|| !/^sha512-[A-Za-z0-9+/]+={0,2}$/.test(value.integrity))
|
|
143
|
+
return false;
|
|
144
|
+
try {
|
|
145
|
+
const url = new URL(value.resolved);
|
|
146
|
+
if (url.protocol !== 'https:' || url.hostname !== 'registry.npmjs.org'
|
|
147
|
+
|| url.port || url.username || url.password || url.search || url.hash
|
|
148
|
+
|| !url.pathname.startsWith('/') || url.pathname.includes('..'))
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Root-owned manifest proposal. It preserves unrelated keys and refuses
|
|
159
|
+
* conflicting scripts, non-registry dependencies and unsupported workspaces.
|
|
160
|
+
* No filesystem effect occurs here.
|
|
161
|
+
*/
|
|
162
|
+
export function planPactToolchainManifest(projectRoot, generateProvider) {
|
|
163
|
+
try {
|
|
164
|
+
if (process.platform !== 'linux' || typeof generateProvider !== 'boolean') {
|
|
165
|
+
throw new Error('unsupported');
|
|
166
|
+
}
|
|
167
|
+
const root = resolve(projectRoot);
|
|
168
|
+
if (realpathSync(root) !== root || !lstatSync(root).isDirectory())
|
|
169
|
+
throw new Error('root');
|
|
170
|
+
for (const alternate of ['.npmrc', 'npm-shrinkwrap.json', 'pnpm-lock.yaml', 'yarn.lock',
|
|
171
|
+
'bun.lock', 'bun.lockb']) {
|
|
172
|
+
try {
|
|
173
|
+
lstatSync(join(root, alternate));
|
|
174
|
+
throw new Error('alternate');
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
if (error.code !== 'ENOENT')
|
|
178
|
+
throw error;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const sourceText = readRegular(root, 'package.json', 1024 * 1024);
|
|
182
|
+
if (!sourceText)
|
|
183
|
+
throw new Error('manifest');
|
|
184
|
+
const manifest = parseStrictJson(sourceText);
|
|
185
|
+
if (!manifest || typeof manifest.name !== 'string' || !/^[a-z0-9@][a-z0-9@._/-]{0,213}$/.test(manifest.name)
|
|
186
|
+
|| typeof manifest.version !== 'string' || !BOUNDED_NPM_SPEC.test(manifest.version)
|
|
187
|
+
|| manifest.workspaces !== undefined || manifest.overrides !== undefined
|
|
188
|
+
|| (manifest.packageManager !== undefined
|
|
189
|
+
&& (typeof manifest.packageManager !== 'string'
|
|
190
|
+
|| !/^npm@[0-9]+(?:\.[0-9]+){0,2}$/.test(manifest.packageManager)))) {
|
|
191
|
+
throw new Error('manifest');
|
|
192
|
+
}
|
|
193
|
+
for (const section of ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']) {
|
|
194
|
+
const dependencies = manifest[section];
|
|
195
|
+
if (dependencies !== undefined && (!record(dependencies)
|
|
196
|
+
|| Object.values(dependencies).some((value) => typeof value !== 'string'
|
|
197
|
+
|| !BOUNDED_NPM_SPEC.test(value))))
|
|
198
|
+
throw new Error('dependency');
|
|
199
|
+
}
|
|
200
|
+
const runtimeDeps = manifest.dependencies;
|
|
201
|
+
if (record(runtimeDeps) && (runtimeDeps['@pact-foundation/pact'] !== undefined
|
|
202
|
+
|| runtimeDeps.vitest !== undefined))
|
|
203
|
+
throw new Error('placement');
|
|
204
|
+
const scripts = manifest.scripts;
|
|
205
|
+
if (scripts !== undefined && !record(scripts))
|
|
206
|
+
throw new Error('scripts');
|
|
207
|
+
const existingScripts = record(scripts) ? scripts : {};
|
|
208
|
+
for (const name of ['prepact:consumer', 'postpact:consumer', 'prepact:provider', 'postpact:provider']) {
|
|
209
|
+
if (existingScripts[name] !== undefined)
|
|
210
|
+
throw new Error('lifecycle');
|
|
211
|
+
}
|
|
212
|
+
if ((existingScripts['pact:consumer'] !== undefined
|
|
213
|
+
&& existingScripts['pact:consumer'] !== CONSUMER_SCRIPT)
|
|
214
|
+
|| (generateProvider && existingScripts['pact:provider'] !== undefined
|
|
215
|
+
&& existingScripts['pact:provider'] !== PROVIDER_SCRIPT))
|
|
216
|
+
throw new Error('script-conflict');
|
|
217
|
+
const devDependencies = record(manifest.devDependencies) ? manifest.devDependencies : {};
|
|
218
|
+
const pact = devDependencies['@pact-foundation/pact'] ?? PACT_VERSION;
|
|
219
|
+
const vitest = devDependencies.vitest ?? VITEST_VERSION;
|
|
220
|
+
if (typeof pact !== 'string' || !BOUNDED_NPM_SPEC.test(pact)
|
|
221
|
+
|| typeof vitest !== 'string' || !BOUNDED_NPM_SPEC.test(vitest))
|
|
222
|
+
throw new Error('version');
|
|
223
|
+
const candidate = { ...manifest,
|
|
224
|
+
scripts: { ...existingScripts, 'pact:consumer': CONSUMER_SCRIPT,
|
|
225
|
+
...(generateProvider ? { 'pact:provider': PROVIDER_SCRIPT } : {}) },
|
|
226
|
+
devDependencies: { ...devDependencies, '@pact-foundation/pact': pact, vitest },
|
|
227
|
+
};
|
|
228
|
+
const indentation = /^\{\r?\n([ \t]+)\S/m.exec(sourceText)?.[1] ?? ' ';
|
|
229
|
+
const candidateText = JSON.stringify(candidate, null, indentation)
|
|
230
|
+
+ (sourceText.endsWith('\n') ? '\n' : '');
|
|
231
|
+
const sourceLockText = readRegular(root, 'package-lock.json', 8 * 1024 * 1024) ?? null;
|
|
232
|
+
if (sourceLockText !== null && !safeRegistryLock(sourceLockText))
|
|
233
|
+
throw new Error('lock');
|
|
234
|
+
return Object.freeze({ sourceText, candidateText, sourceLockText });
|
|
235
|
+
}
|
|
236
|
+
catch {
|
|
237
|
+
throw new Error('pact-toolchain-manifest-unsupported');
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Resolve a lockfile from metadata alone in a private temporary directory.
|
|
242
|
+
* npm never sees project source, local credentials, .npmrc or generated tests;
|
|
243
|
+
* ignore-scripts and package-lock-only prevent package code execution.
|
|
244
|
+
*/
|
|
245
|
+
export function preparePactToolchainCandidate(projectRoot, generateProvider) {
|
|
246
|
+
const planned = planPactToolchainManifest(projectRoot, generateProvider);
|
|
247
|
+
const scratch = mkdtempSync(join(tmpdir(), 'p222-pact-toolchain-'));
|
|
248
|
+
try {
|
|
249
|
+
writeFileSync(join(scratch, 'package.json'), planned.candidateText, { mode: 0o600 });
|
|
250
|
+
writeFileSync(join(scratch, 'user.npmrc'), '', { mode: 0o600 });
|
|
251
|
+
writeFileSync(join(scratch, 'global.npmrc'), '', { mode: 0o600 });
|
|
252
|
+
if (planned.sourceLockText !== null) {
|
|
253
|
+
writeFileSync(join(scratch, 'package-lock.json'), planned.sourceLockText, { mode: 0o600 });
|
|
254
|
+
}
|
|
255
|
+
const command = spawnSync('npm', ['install', '--package-lock-only', '--ignore-scripts',
|
|
256
|
+
'--no-audit', '--no-fund', '--registry=https://registry.npmjs.org/',
|
|
257
|
+
`--userconfig=${join(scratch, 'user.npmrc')}`,
|
|
258
|
+
`--globalconfig=${join(scratch, 'global.npmrc')}`], {
|
|
259
|
+
cwd: scratch, encoding: 'utf8', timeout: 120_000, maxBuffer: 256 * 1024,
|
|
260
|
+
env: { PATH: process.env.PATH, HOME: scratch, TMPDIR: scratch,
|
|
261
|
+
npm_config_cache: join(scratch, '.npm-cache'), CI: 'true', NO_UPDATE_NOTIFIER: '1' },
|
|
262
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
263
|
+
});
|
|
264
|
+
if (command.error || command.status !== 0)
|
|
265
|
+
throw new Error('npm');
|
|
266
|
+
const manifestText = readRegular(scratch, 'package.json', 1024 * 1024);
|
|
267
|
+
const lockText = readRegular(scratch, 'package-lock.json', 8 * 1024 * 1024);
|
|
268
|
+
const inspection = inspectPactToolchain(scratch, generateProvider);
|
|
269
|
+
if (manifestText !== planned.candidateText || !lockText || !safeRegistryLock(lockText)
|
|
270
|
+
|| inspection.outcome !== 'manifest-aligned') {
|
|
271
|
+
throw new Error('candidate');
|
|
272
|
+
}
|
|
273
|
+
const root = resolve(projectRoot);
|
|
274
|
+
if (readRegular(root, 'package.json', 1024 * 1024) !== planned.sourceText
|
|
275
|
+
|| (readRegular(root, 'package-lock.json', 8 * 1024 * 1024) ?? null) !== planned.sourceLockText) {
|
|
276
|
+
throw new Error('source-raced');
|
|
277
|
+
}
|
|
278
|
+
const sha = (value) => createHash('sha256').update(value).digest('hex');
|
|
279
|
+
return Object.freeze({ schemaVersion: 1, outcome: 'candidate-unverified',
|
|
280
|
+
sourceManifestSha256: sha(planned.sourceText),
|
|
281
|
+
sourceLockSha256: planned.sourceLockText === null ? null : sha(planned.sourceLockText),
|
|
282
|
+
manifestText, lockText, executionVerified: false });
|
|
283
|
+
}
|
|
284
|
+
catch {
|
|
285
|
+
throw new Error('pact-toolchain-candidate-unavailable');
|
|
286
|
+
}
|
|
287
|
+
finally {
|
|
288
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
289
|
+
}
|
|
290
|
+
}
|