@ornexus/neocortex 4.60.73 → 4.60.74

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.
Files changed (241) hide show
  1. package/dist/release-source.json +1 -1
  2. package/dist/sbom.cdx.json +1216 -1210
  3. package/install.ps1 +1 -1
  4. package/install.sh +1 -1
  5. package/package.json +2 -2
  6. package/packages/client/dist/adapters/adapter-registry.js +1 -108
  7. package/packages/client/dist/adapters/antigravity-adapter.js +2 -77
  8. package/packages/client/dist/adapters/claude-code-adapter.js +3 -79
  9. package/packages/client/dist/adapters/codex-adapter.js +2 -80
  10. package/packages/client/dist/adapters/cursor-adapter.js +4 -115
  11. package/packages/client/dist/adapters/gemini-adapter.js +2 -71
  12. package/packages/client/dist/adapters/grok-adapter.js +2 -42
  13. package/packages/client/dist/adapters/index.js +1 -22
  14. package/packages/client/dist/adapters/platform-detector.js +1 -212
  15. package/packages/client/dist/adapters/target-adapter.js +0 -12
  16. package/packages/client/dist/adapters/vscode-adapter.js +2 -72
  17. package/packages/client/dist/agent/refresh-stubs.js +2 -417
  18. package/packages/client/dist/agent/update-agent-yaml.js +1 -102
  19. package/packages/client/dist/agent/update-description.js +1 -251
  20. package/packages/client/dist/cache/crypto-utils.js +1 -78
  21. package/packages/client/dist/cache/encrypted-cache.js +1 -108
  22. package/packages/client/dist/cache/in-memory-asset-cache.js +1 -73
  23. package/packages/client/dist/cache/index.js +1 -13
  24. package/packages/client/dist/cache/protected-pi-boundary.js +1 -44
  25. package/packages/client/dist/checkpoint/checkpoint-client-reader.js +2 -127
  26. package/packages/client/dist/checkpoint/index.js +1 -11
  27. package/packages/client/dist/checkpoint/shared-checkpoint-types.js +1 -32
  28. package/packages/client/dist/cli.js +5 -358
  29. package/packages/client/dist/commands/activate.js +8 -394
  30. package/packages/client/dist/commands/architecture-answers.js +7 -274
  31. package/packages/client/dist/commands/architecture-memory-terminal.js +4 -253
  32. package/packages/client/dist/commands/architecture-non-ui-continuation.js +1 -100
  33. package/packages/client/dist/commands/architecture-root-binding.js +1 -51
  34. package/packages/client/dist/commands/cache-status.js +2 -112
  35. package/packages/client/dist/commands/config.js +1 -88
  36. package/packages/client/dist/commands/doctor.js +2 -635
  37. package/packages/client/dist/commands/invoke.js +143 -7200
  38. package/packages/client/dist/commands/legacy-epic-terminal.js +1 -71
  39. package/packages/client/dist/commands/legacy-story-branch.js +1 -96
  40. package/packages/client/dist/commands/legacy-story-pr.js +1 -276
  41. package/packages/client/dist/commands/mutation-qa-checkpoint.js +5 -285
  42. package/packages/client/dist/commands/mutation-qa-gate.js +1 -54
  43. package/packages/client/dist/commands/mutation-qa-git.js +1 -41
  44. package/packages/client/dist/commands/mutation-qa-policy.js +1 -102
  45. package/packages/client/dist/commands/mutation-qa-run.js +3 -219
  46. package/packages/client/dist/commands/mutation-qa-verdict.js +1 -149
  47. package/packages/client/dist/commands/mutation-qa.js +1 -220
  48. package/packages/client/dist/commands/native-agent.js +2 -136
  49. package/packages/client/dist/commands/planning-diagnosis.js +1 -43
  50. package/packages/client/dist/commands/planning-generation.js +1 -53
  51. package/packages/client/dist/commands/planning-memory.js +1 -40
  52. package/packages/client/dist/commands/planning-research.js +1 -42
  53. package/packages/client/dist/commands/private-session.js +1 -75
  54. package/packages/client/dist/commands/property-qa.js +1 -139
  55. package/packages/client/dist/commands/qa-control.js +1 -16
  56. package/packages/client/dist/commands/qa-scan-browser-launch.js +1 -55
  57. package/packages/client/dist/commands/qa-scan-browser-route.js +1 -28
  58. package/packages/client/dist/commands/qa-scan-capture.js +5 -663
  59. package/packages/client/dist/commands/qa-scan-discovery.js +3 -376
  60. package/packages/client/dist/commands/qa-scan-review.js +5 -826
  61. package/packages/client/dist/commands/qa-synthetic-backend-capture.js +1 -266
  62. package/packages/client/dist/commands/qa-synthetic-backend-review.js +1 -297
  63. package/packages/client/dist/commands/qa-synthetic-backend.js +2 -340
  64. package/packages/client/dist/commands/qa-synthetic-broker-port.js +1 -85
  65. package/packages/client/dist/commands/qa-synthetic-browser.js +1 -39
  66. package/packages/client/dist/commands/refactor-characterization.js +21 -671
  67. package/packages/client/dist/commands/refactor-commit.js +13 -399
  68. package/packages/client/dist/commands/refactor-control.js +3 -142
  69. package/packages/client/dist/commands/refactor-cpp-assertions.js +3 -93
  70. package/packages/client/dist/commands/refactor-review.js +5 -283
  71. package/packages/client/dist/commands/refactor-root.js +7 -588
  72. package/packages/client/dist/commands/refresh-memory.js +3 -156
  73. package/packages/client/dist/commands/shared-architecture-non-ui.js +1 -24
  74. package/packages/client/dist/commands/story-checkpoint.js +1 -171
  75. package/packages/client/dist/config/profile-directory.js +1 -13
  76. package/packages/client/dist/config/resolver-selection.js +1 -278
  77. package/packages/client/dist/config/secure-config.js +12 -281
  78. package/packages/client/dist/config.js +2 -223
  79. package/packages/client/dist/constants.js +1 -25
  80. package/packages/client/dist/context/context-collector.js +2 -222
  81. package/packages/client/dist/context/context-sanitizer.js +1 -145
  82. package/packages/client/dist/continuity/autonomous-governance.js +1 -285
  83. package/packages/client/dist/continuity/continuity-client-state-store.js +1 -1587
  84. package/packages/client/dist/continuity/invoke-hooks.js +1 -129
  85. package/packages/client/dist/continuity/migrations/001-initial-schema.js +2 -12
  86. package/packages/client/dist/continuity/migrations/002-processing-output-summary-indexes.js +2 -12
  87. package/packages/client/dist/continuity/migrations/003-headless-execution-attempts.js +2 -12
  88. package/packages/client/dist/continuity/migrations/004-outbox-delivery-state.js +2 -12
  89. package/packages/client/dist/continuity/migrations/005-bounded-headless-queue.js +2 -12
  90. package/packages/client/dist/continuity/migrations/006-native-agent-dispatches.js +2 -10
  91. package/packages/client/dist/continuity/native-agent-store.js +1 -69
  92. package/packages/client/dist/continuity/native-agent-types.js +1 -90
  93. package/packages/client/dist/continuity/outbox.js +1 -117
  94. package/packages/client/dist/continuity/runner-bootstrap-policy.js +1 -172
  95. package/packages/client/dist/continuity/sqlite-store.js +81 -2612
  96. package/packages/client/dist/effects/invoke-effect-gateways.js +1 -62
  97. package/packages/client/dist/errors/error-messages.js +2 -228
  98. package/packages/client/dist/errors/frontmatter-diagnostics.js +1 -125
  99. package/packages/client/dist/evidence/collector.js +1 -347
  100. package/packages/client/dist/evidence/index.js +1 -1
  101. package/packages/client/dist/evidence/types.js +0 -2
  102. package/packages/client/dist/fs/atomic-state-replace.js +1 -152
  103. package/packages/client/dist/generated/command-registry.generated.js +1 -4076
  104. package/packages/client/dist/generated/public-projections.generated.js +1 -149
  105. package/packages/client/dist/git/direct-yolo-c01-retry.js +4 -138
  106. package/packages/client/dist/git/direct-yolo-checkpoint.js +4 -1234
  107. package/packages/client/dist/git/epic-operational-state.js +2 -672
  108. package/packages/client/dist/git/git-lifecycle-step-ids.js +1 -14
  109. package/packages/client/dist/git/git-lifecycle-store.d.ts +23 -0
  110. package/packages/client/dist/git/git-lifecycle-store.js +10 -1981
  111. package/packages/client/dist/git/legacy-story-branch-checkpoint.js +9 -259
  112. package/packages/client/dist/git/legacy-story-branch-setup.js +4 -348
  113. package/packages/client/dist/git/legacy-story-pr.js +70 -3538
  114. package/packages/client/dist/git/secure-filesystem-boundary.js +5 -182
  115. package/packages/client/dist/graph-retrieval/pre-command-hook.js +1 -284
  116. package/packages/client/dist/graph-retrieval/shared-graph-retrieval-contract.js +1 -237
  117. package/packages/client/dist/i18n/first-run.js +2 -60
  118. package/packages/client/dist/index.js +1 -47
  119. package/packages/client/dist/invocation/invoke-input.js +1 -24
  120. package/packages/client/dist/license/index.js +1 -5
  121. package/packages/client/dist/license/license-client.js +1 -304
  122. package/packages/client/dist/machine/fingerprint.js +2 -163
  123. package/packages/client/dist/machine/index.js +1 -5
  124. package/packages/client/dist/memory/project-memory-path-scope.js +1 -62
  125. package/packages/client/dist/memory/project-memory-writer.js +40 -1007
  126. package/packages/client/dist/memory/shared-project-memory-types.js +2 -253
  127. package/packages/client/dist/migrations/epic-lifecycle-backfill.js +3 -1060
  128. package/packages/client/dist/migrations/project-identity-capability.js +1 -50
  129. package/packages/client/dist/migrations/project-identity.js +7 -493
  130. package/packages/client/dist/migrations/state-json.js +4 -393
  131. package/packages/client/dist/policy/architecture-policy.js +2 -184
  132. package/packages/client/dist/policy/index.js +1 -7
  133. package/packages/client/dist/policy/shared-policy-types.js +0 -38
  134. package/packages/client/dist/policy/subagent-approval-policy.js +1 -55
  135. package/packages/client/dist/private-execution/clean-baseline.js +2 -279
  136. package/packages/client/dist/private-execution/codex-executor.js +4 -574
  137. package/packages/client/dist/private-execution/codex-host-runtime.js +1 -137
  138. package/packages/client/dist/private-execution/codex-lifecycle-guard.js +1 -97
  139. package/packages/client/dist/private-execution/codex-scoped-permissions.js +1 -128
  140. package/packages/client/dist/private-execution/delivery.js +13 -410
  141. package/packages/client/dist/private-execution/diagnosis-root-review.js +2 -294
  142. package/packages/client/dist/private-execution/frozen-handoff.js +6 -19
  143. package/packages/client/dist/private-execution/implementation-validation.js +2 -106
  144. package/packages/client/dist/private-execution/isolated-admission.js +23 -1432
  145. package/packages/client/dist/private-execution/isolated-session.js +5 -725
  146. package/packages/client/dist/private-execution/isolated-workspace.js +1 -122
  147. package/packages/client/dist/private-execution/pact-consumer-runtime.js +3 -409
  148. package/packages/client/dist/private-execution/pact-test-source.js +1 -258
  149. package/packages/client/dist/private-execution/pact-toolchain.js +3 -290
  150. package/packages/client/dist/private-execution/pact-write-set.js +1 -172
  151. package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.js +5 -406
  152. package/packages/client/dist/private-execution/planning-generation-checkpoint.js +5 -462
  153. package/packages/client/dist/private-execution/planning-memory-checkpoint.js +3 -139
  154. package/packages/client/dist/private-execution/planning-research-checkpoint.js +4 -325
  155. package/packages/client/dist/private-execution/private-report-store.js +1 -42
  156. package/packages/client/dist/private-execution/property-test-candidate.js +1 -103
  157. package/packages/client/dist/private-execution/property-test-choices.js +3 -147
  158. package/packages/client/dist/private-execution/property-test-plan.js +7 -271
  159. package/packages/client/dist/private-execution/property-test-review.js +4 -258
  160. package/packages/client/dist/private-execution/property-test-runtime.js +9 -372
  161. package/packages/client/dist/private-execution/property-test-source.js +1 -139
  162. package/packages/client/dist/private-execution/root-checkpoint.js +1 -80
  163. package/packages/client/dist/private-execution/root-memory-git-evidence.js +3 -135
  164. package/packages/client/dist/private-execution/root-memory-recovery.js +1 -93
  165. package/packages/client/dist/private-execution/root-memory-request.js +1 -29
  166. package/packages/client/dist/private-execution/root-memory-scope.js +1 -178
  167. package/packages/client/dist/private-execution/root-memory-writer.js +1 -102
  168. package/packages/client/dist/private-execution/session-lease.js +1 -63
  169. package/packages/client/dist/private-execution/shared-private-admission-types.js +1 -50
  170. package/packages/client/dist/private-execution/shared-project-validation.js +1 -66
  171. package/packages/client/dist/private-execution/shared-root-memory-types.js +1 -61
  172. package/packages/client/dist/private-execution/ux-source-validation.js +1 -372
  173. package/packages/client/dist/private-execution/ux-write-set.js +2 -191
  174. package/packages/client/dist/registry/registry-reconciliation.js +1 -234
  175. package/packages/client/dist/resilience/circuit-breaker.js +1 -170
  176. package/packages/client/dist/resilience/degradation-manager.js +1 -164
  177. package/packages/client/dist/resilience/freshness-indicator.js +1 -100
  178. package/packages/client/dist/resilience/index.js +1 -8
  179. package/packages/client/dist/resilience/recovery-detector.js +1 -74
  180. package/packages/client/dist/resolvers/asset-resolver.js +0 -13
  181. package/packages/client/dist/resolvers/local-resolver.js +8 -255
  182. package/packages/client/dist/resolvers/remote-resolver.js +1 -233
  183. package/packages/client/dist/runner/binary.js +1 -404
  184. package/packages/client/dist/runner/cli.js +17 -1571
  185. package/packages/client/dist/runner/headless/adapters.js +1 -49
  186. package/packages/client/dist/runner/headless/claude-code-adapter.js +1 -79
  187. package/packages/client/dist/runner/headless/continuous-story-workspace.js +11 -1628
  188. package/packages/client/dist/runner/headless/epic-git-reconciliation-inventory.js +1 -69
  189. package/packages/client/dist/runner/headless/epic-merge-candidate-qa.d.ts +1 -1
  190. package/packages/client/dist/runner/headless/epic-merge-candidate-qa.js +2 -110
  191. package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.d.ts +2 -0
  192. package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +10 -1236
  193. package/packages/client/dist/runner/headless/epic-terminal-git-runner.d.ts +18 -2
  194. package/packages/client/dist/runner/headless/epic-terminal-git-runner.js +2 -318
  195. package/packages/client/dist/runner/headless/fake-adapter.js +1 -62
  196. package/packages/client/dist/runner/headless/managed-profile.js +1 -132
  197. package/packages/client/dist/runner/headless/opencode-adapter.js +2 -145
  198. package/packages/client/dist/runner/headless/prepared-story-bundle.js +1 -43
  199. package/packages/client/dist/runner/headless/resolver.js +1 -231
  200. package/packages/client/dist/runner/headless/run-yolo.js +1 -885
  201. package/packages/client/dist/runner/headless/run-yoloop.d.ts +1 -0
  202. package/packages/client/dist/runner/headless/run-yoloop.js +2 -2574
  203. package/packages/client/dist/runner/headless/types.js +2 -574
  204. package/packages/client/dist/runner/local-console.js +13 -396
  205. package/packages/client/dist/runner/portal-sync-worker.js +1 -1487
  206. package/packages/client/dist/runner/project-identity.js +1 -106
  207. package/packages/client/dist/runner/scheduler.js +7 -995
  208. package/packages/client/dist/runner-cli.js +2 -18
  209. package/packages/client/dist/state/invocation-shape.js +1 -13
  210. package/packages/client/dist/state/project-state-snapshot.js +1 -1731
  211. package/packages/client/dist/state/state-json-repair.js +3 -785
  212. package/packages/client/dist/state/structural-dag-projection.js +1 -118
  213. package/packages/client/dist/telemetry/index.js +1 -5
  214. package/packages/client/dist/telemetry/offline-queue.js +1 -131
  215. package/packages/client/dist/tier/index.js +1 -5
  216. package/packages/client/dist/tier/tier-aware-client.js +1 -405
  217. package/packages/client/dist/types/index.js +1 -38
  218. package/packages/client/dist/version.js +1 -27
  219. package/packages/client/dist/yolo/change-evidence-collector.js +1 -126
  220. package/packages/client/dist/yolo/invoke-envelope-capability.js +1 -62
  221. package/packages/client/dist/yolo/spec-envelope-collector.js +5 -184
  222. package/packages/client/dist/yoloop/discovery-hook.js +2 -300
  223. package/packages/client/dist/yoloop/index.js +1 -8
  224. package/packages/client/dist/yoloop/invoke-hooks.js +12 -669
  225. package/packages/client/dist/yoloop/shared-discover-epics.js +1 -1007
  226. package/packages/client/dist/yoloop/shared-yoloop-types.js +1 -33
  227. package/packages/client/dist/yoloop/target-normalization.js +1 -180
  228. package/packages/client/dist/yoloop/yoloop-client-state-store.js +1 -1920
  229. package/packages/shared/dist/yolo/change-evidence.js +1 -1
  230. package/packages/shared/dist/yoloop/epic-terminal-git.js +144 -2
  231. package/targets-stubs/antigravity/gemini.md +1 -1
  232. package/targets-stubs/antigravity/skill/SKILL.md +1 -1
  233. package/targets-stubs/claude-code/neocortex-root.agent.yaml +1 -1
  234. package/targets-stubs/claude-code/neocortex-root.md +2 -2
  235. package/targets-stubs/claude-code/neocortex.agent.yaml +1 -1
  236. package/targets-stubs/claude-code/neocortex.md +2 -2
  237. package/targets-stubs/codex/AGENTS.md +1 -1
  238. package/targets-stubs/cursor/agent.md +2 -2
  239. package/targets-stubs/gemini-cli/agent.md +2 -2
  240. package/targets-stubs/opencode/neocortex-root.md +1 -1
  241. package/targets-stubs/vscode/neocortex.agent.md +2 -2
@@ -1,372 +1,9 @@
1
- /** Root-owned, opt-in runtime proof for admitted TypeScript property tests. */
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 { dirname, join, posix, resolve } from 'node:path';
7
- import { parse } from '@babel/parser';
8
- import { parseDocument } from 'yaml';
9
- import { mutationQaGit } from '../commands/mutation-qa-git.js';
10
- import { loadPropertyTestCandidatePlan } from './property-test-choices.js';
11
- import { inspectPropertyTestCandidate } from './property-test-candidate.js';
12
- const CANARY = 'P222_PROPERTY_CAUSAL_CANARY';
13
- const MAX_SOURCE_FILES = 512;
14
- const MAX_SOURCE_BYTES = 16 * 1024 * 1024;
15
- const MAX_TEST_BYTES = 256 * 1024;
16
- class RuntimeFailure extends Error {
17
- reason;
18
- constructor(reason) {
19
- super(reason);
20
- this.reason = reason;
21
- }
22
- }
23
- function fail(reason) { throw new RuntimeFailure(reason); }
24
- function record(value) {
25
- return value !== null && typeof value === 'object' && !Array.isArray(value);
26
- }
27
- function receipt(reason, head, candidate, files, passed = 0, causal = 0) {
28
- const proven = reason === 'tests-passed';
29
- return Object.freeze({ schemaVersion: 1, kind: 'property-test-runtime',
30
- outcome: proven ? 'execution-proven' : 'unverified', reasonCode: reason,
31
- sourceHead: head, candidateSha256: candidate, testFileCount: files,
32
- passedTests: passed, causalFailedTests: causal,
33
- executionVerified: proven, qaAccepted: false, publicSafe: true });
34
- }
35
- function safeBytes(root, relative, max) {
36
- if (!/^[A-Za-z0-9_.-]+(?:\/[A-Za-z0-9_.-]+)*$/.test(relative)
37
- || relative.split('/').some((part) => part === '.' || part === '..'))
38
- fail('source-unsupported');
39
- let current = root;
40
- const parts = relative.split('/');
41
- for (const [index, part] of parts.entries()) {
42
- current = join(current, part);
43
- const stat = lstatSync(current);
44
- if (stat.isSymbolicLink() || (index === parts.length - 1
45
- ? !stat.isFile() || stat.size < 1 || stat.size > max : !stat.isDirectory())) {
46
- fail('source-unsupported');
47
- }
48
- }
49
- return readFileSync(current);
50
- }
51
- function strictJson(bytes) {
52
- try {
53
- const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
54
- const document = parseDocument(text, { strict: true, uniqueKeys: true,
55
- schema: 'core', customTags: [] });
56
- if (document.errors.length || document.warnings.length)
57
- return null;
58
- const parsed = JSON.parse(text);
59
- return record(parsed) ? parsed : null;
60
- }
61
- catch {
62
- return null;
63
- }
64
- }
65
- function safeNpmToolchain(manifestBytes, lockBytes) {
66
- const manifest = strictJson(manifestBytes);
67
- const lock = strictJson(lockBytes);
68
- if (!manifest || !lock || manifest.workspaces !== undefined
69
- || ![2, 3].includes(Number(lock.lockfileVersion))
70
- || !record(lock.packages) || !record(lock.packages[''])
71
- || Object.keys(lock.packages).length > 10_000)
72
- return false;
73
- const specs = /^(?:\^|~)?[0-9]+\.[0-9]+\.[0-9]+$/;
74
- for (const section of ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']) {
75
- if (manifest[section] !== undefined && (!record(manifest[section])
76
- || Object.values(manifest[section]).some((value) => typeof value !== 'string' || !specs.test(value))))
77
- return false;
78
- }
79
- const deps = { ...(record(manifest.dependencies) ? manifest.dependencies : {}),
80
- ...(record(manifest.devDependencies) ? manifest.devDependencies : {}) };
81
- const lockedRoot = lock.packages[''];
82
- const lockedDeps = record(lockedRoot) ? { ...(record(lockedRoot.dependencies)
83
- ? lockedRoot.dependencies : {}), ...(record(lockedRoot.devDependencies)
84
- ? lockedRoot.devDependencies : {}) } : {};
85
- if (typeof deps.vitest !== 'string' || typeof deps['fast-check'] !== 'string'
86
- || lockedDeps.vitest !== deps.vitest
87
- || lockedDeps['fast-check'] !== deps['fast-check'])
88
- return false;
89
- for (const [packagePath, value] of Object.entries(lock.packages)) {
90
- if (!record(value) || value.link === true)
91
- return false;
92
- if (packagePath === '')
93
- continue;
94
- if (!/^node_modules\/(?:@[^/]+\/)?[^/]+(?:\/node_modules\/(?:@[^/]+\/)?[^/]+)*$/.test(packagePath)
95
- || value.resolved === undefined)
96
- return false;
97
- if (typeof value.resolved !== 'string' || typeof value.integrity !== 'string'
98
- || !/^sha512-[A-Za-z0-9+/]+={0,2}$/.test(value.integrity))
99
- return false;
100
- try {
101
- const url = new URL(value.resolved);
102
- if (url.protocol !== 'https:' || url.hostname !== 'registry.npmjs.org'
103
- || url.port || url.username || url.password || url.search || url.hash
104
- || !url.pathname.startsWith('/') || url.pathname.includes('..'))
105
- return false;
106
- }
107
- catch {
108
- return false;
109
- }
110
- }
111
- return true;
112
- }
113
- /** Resolve the host npm executable without allowing a project-owned PATH shadow. */
114
- function trustedNpmCli() {
115
- for (const directory of (process.env.PATH ?? '').split(':')) {
116
- if (!directory.startsWith('/'))
117
- continue;
118
- const candidate = join(directory, 'npm');
119
- if (!existsSync(candidate))
120
- continue;
121
- try {
122
- const real = realpathSync(candidate);
123
- return ((real.startsWith('/usr/') || real.startsWith('/home/linuxbrew/.linuxbrew/'))
124
- && real.endsWith('.js') && lstatSync(real).isFile()) ? real : null;
125
- }
126
- catch {
127
- return null;
128
- }
129
- }
130
- return null;
131
- }
132
- function importedBindings(testPath, source, implementation) {
133
- const ast = parse(source, { sourceType: 'module', plugins: ['typescript'] });
134
- const names = new Set();
135
- for (const item of ast.program.body) {
136
- if (item.type !== 'ImportDeclaration' || item.importKind === 'type'
137
- || !item.source.value.startsWith('.'))
138
- continue;
139
- const resolved = posix.normalize(posix.join(posix.dirname(testPath), item.source.value))
140
- .replace(/\.(?:ts|js)$/, '');
141
- if (resolved !== implementation.replace(/\.ts$/, ''))
142
- continue;
143
- for (const specifier of item.specifiers) {
144
- if (specifier.type === 'ImportNamespaceSpecifier')
145
- fail('source-unsupported');
146
- const name = specifier.type === 'ImportDefaultSpecifier' ? 'default'
147
- : specifier.imported.type === 'Identifier' ? specifier.imported.name : specifier.imported.value;
148
- if (!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name))
149
- fail('source-unsupported');
150
- names.add(name);
151
- }
152
- }
153
- if (!names.size)
154
- fail('source-unsupported');
155
- return names;
156
- }
157
- function sandboxArgs(scratch, reportDir, paths, node) {
158
- const args = ['--die-with-parent', '--new-session', '--unshare-all', '--clearenv',
159
- '--setenv', 'HOME', '/tmp', '--setenv', 'TMPDIR', '/tmp',
160
- '--setenv', 'PATH', '/home/linuxbrew/.linuxbrew/bin:/usr/bin:/bin',
161
- '--setenv', 'CI', 'true', '--setenv', 'NODE_ENV', 'test',
162
- '--ro-bind', '/usr', '/usr'];
163
- for (const path of ['/lib', '/lib64', '/bin']) {
164
- if (existsSync(path))
165
- args.push('--ro-bind', path, path);
166
- }
167
- if (existsSync('/home/linuxbrew/.linuxbrew')) {
168
- args.push('--ro-bind', '/home/linuxbrew/.linuxbrew', '/home/linuxbrew/.linuxbrew');
169
- }
170
- args.push('--dir', '/etc');
171
- for (const file of ['passwd', 'group', 'hosts', 'nsswitch.conf']) {
172
- args.push('--ro-bind', join(scratch, '.sandbox-etc', file), `/etc/${file}`);
173
- }
174
- return [...args, '--dev', '/dev', '--proc', '/proc', '--tmpfs', '/tmp',
175
- '--ro-bind', scratch, '/work', '--bind', reportDir, '/results',
176
- '--chdir', '/work', '--', node,
177
- 'node_modules/vitest/vitest.mjs', 'run', '--maxWorkers=1',
178
- ...paths, '--reporter=json', '--outputFile=/results/report.json'];
179
- }
180
- /** Dependency preparation has the same no-network boundary as test execution. */
181
- function sandboxInstallArgs(scratch, npmCache, node, npmCli) {
182
- const args = ['--die-with-parent', '--new-session', '--unshare-all', '--clearenv',
183
- '--setenv', 'HOME', '/tmp', '--setenv', 'TMPDIR', '/tmp',
184
- '--setenv', 'PATH', '/home/linuxbrew/.linuxbrew/bin:/usr/bin:/bin',
185
- '--setenv', 'CI', 'true', '--setenv', 'NO_UPDATE_NOTIFIER', '1',
186
- '--setenv', 'npm_config_cache', '/npm-cache',
187
- '--setenv', 'npm_config_userconfig', '/dev/null',
188
- '--setenv', 'npm_config_globalconfig', '/tmp/npm-global.npmrc',
189
- '--ro-bind', '/usr', '/usr'];
190
- for (const path of ['/lib', '/lib64', '/bin']) {
191
- if (existsSync(path))
192
- args.push('--ro-bind', path, path);
193
- }
194
- if (existsSync('/home/linuxbrew/.linuxbrew')) {
195
- args.push('--ro-bind', '/home/linuxbrew/.linuxbrew', '/home/linuxbrew/.linuxbrew');
196
- }
197
- args.push('--dir', '/etc');
198
- for (const file of ['passwd', 'group', 'hosts', 'nsswitch.conf']) {
199
- args.push('--ro-bind', join(scratch, '.sandbox-etc', file), `/etc/${file}`);
200
- }
201
- return [...args, '--dev', '/dev', '--proc', '/proc', '--tmpfs', '/tmp',
202
- '--ro-bind', npmCache, '/npm-cache', '--bind', scratch, '/work',
203
- '--chdir', '/work', '--', node, npmCli, 'ci', '--offline', '--ignore-scripts',
204
- '--no-audit', '--no-fund'];
205
- }
206
- function runSandbox(scratch, reportDir, paths, node) {
207
- const command = spawnSync('/usr/bin/bwrap', sandboxArgs(scratch, reportDir, paths, node), {
208
- env: { PATH: '/usr/bin:/bin' }, timeout: 180_000, stdio: 'ignore',
209
- });
210
- if (command.error || command.signal || command.status === null)
211
- fail('sandbox-unavailable');
212
- return command.status;
213
- }
214
- function assertions(reportDir, paths) {
215
- if (!existsSync(join(reportDir, 'report.json')))
216
- fail('sandbox-unavailable');
217
- const parsed = strictJson(safeBytes(reportDir, 'report.json', 2 * 1024 * 1024));
218
- if (!parsed || !Array.isArray(parsed.testResults)
219
- || parsed.testResults.length !== paths.length)
220
- fail('tests-failed');
221
- const results = new Map();
222
- for (const value of parsed.testResults) {
223
- if (!record(value) || typeof value.name !== 'string'
224
- || !paths.some((path) => value.name === `/work/${path}`)
225
- || results.has(value.name) || !Array.isArray(value.assertionResults))
226
- fail('tests-failed');
227
- results.set(value.name, value.assertionResults);
228
- }
229
- return paths.flatMap((path) => results.get(`/work/${path}`));
230
- }
231
- /** An unavailable host or toolchain yields no verdict; only positive + causal runs prove execution. */
232
- export function verifyPropertyTestRuntime(projectRoot) {
233
- let head = null;
234
- let candidate = null;
235
- let testFileCount = 0;
236
- let passed = 0;
237
- let causal = 0;
238
- let scratch;
239
- const reports = [];
240
- try {
241
- const node = realpathSync(process.execPath);
242
- if (process.platform !== 'linux' || !existsSync('/usr/bin/bwrap')
243
- || !(node.startsWith('/usr/') || node.startsWith('/home/linuxbrew/.linuxbrew/'))
244
- || !lstatSync('/usr/bin/bwrap').isFile())
245
- fail('sandbox-unavailable');
246
- const npmCli = trustedNpmCli();
247
- if (!npmCli)
248
- fail('toolchain-unavailable');
249
- const npmCache = join(homedir(), '.npm');
250
- if (!existsSync(npmCache) || realpathSync(npmCache) !== npmCache
251
- || !lstatSync(npmCache).isDirectory()
252
- || lstatSync(npmCache).uid !== process.getuid?.())
253
- fail('toolchain-unavailable');
254
- const root = resolve(projectRoot);
255
- if (realpathSync(root) !== root || !lstatSync(root).isDirectory())
256
- fail('source-unsupported');
257
- const inspected = inspectPropertyTestCandidate(root);
258
- head = inspected.sourceHead;
259
- candidate = inspected.artifactSha256;
260
- const { plan } = loadPropertyTestCandidatePlan(root);
261
- testFileCount = plan.writeSet.length;
262
- if (plan.language !== 'typescript')
263
- fail('toolchain-unavailable');
264
- for (const alternate of ['.npmrc', 'npm-shrinkwrap.json', 'pnpm-lock.yaml',
265
- 'yarn.lock', 'bun.lock', 'bun.lockb']) {
266
- if (existsSync(join(root, alternate)))
267
- fail('toolchain-unavailable');
268
- }
269
- if (!existsSync(join(root, 'package.json')) || !existsSync(join(root, 'package-lock.json'))) {
270
- fail('toolchain-unavailable');
271
- }
272
- const manifest = safeBytes(root, 'package.json', 1024 * 1024);
273
- const lock = safeBytes(root, 'package-lock.json', 8 * 1024 * 1024);
274
- if (!safeNpmToolchain(manifest, lock))
275
- fail('toolchain-unavailable');
276
- const tracked = mutationQaGit(root, ['ls-files', '-z', '--', 'src', 'app', 'lib', 'packages', 'clients'])
277
- .toString('utf8').split('\0').filter(Boolean);
278
- const sourcePaths = tracked.filter((path) => /^(?:src|app|lib|packages|clients)\//.test(path)
279
- && /\.(?:ts|tsx|js|jsx|mjs|cjs|json)$/.test(path));
280
- if (sourcePaths.length > MAX_SOURCE_FILES)
281
- fail('source-unsupported');
282
- const files = new Map([
283
- ['package.json', manifest], ['package-lock.json', lock],
284
- ]);
285
- for (const path of sourcePaths)
286
- files.set(path, safeBytes(root, path, 1024 * 1024));
287
- const mutations = new Map();
288
- for (const item of plan.aggregates) {
289
- const bytes = safeBytes(root, item.testFile, MAX_TEST_BYTES);
290
- const source = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
291
- const names = importedBindings(item.testFile, source, item.implementationFile);
292
- const selected = mutations.get(item.implementationFile) ?? new Set();
293
- for (const name of names)
294
- selected.add(name);
295
- mutations.set(item.implementationFile, selected);
296
- files.set(item.testFile, bytes);
297
- }
298
- if ([...files.values()].reduce((sum, bytes) => sum + bytes.length, 0) > MAX_SOURCE_BYTES) {
299
- fail('source-unsupported');
300
- }
301
- scratch = mkdtempSync(join(tmpdir(), 'p222-property-runtime-'));
302
- mkdirSync(join(scratch, '.sandbox-etc'), { mode: 0o700 });
303
- const uid = process.getuid?.() ?? 1000;
304
- const gid = process.getgid?.() ?? 1000;
305
- for (const [file, contents] of Object.entries({
306
- passwd: `sandbox:x:${uid}:${gid}:Sandbox:/work:/bin/sh\n`,
307
- group: `sandbox:x:${gid}:\n`,
308
- hosts: '127.0.0.1 localhost\n',
309
- 'nsswitch.conf': 'passwd: files\ngroup: files\nhosts: files\n',
310
- }))
311
- writeFileSync(join(scratch, '.sandbox-etc', file), contents, { mode: 0o600 });
312
- writeFileSync(join(scratch, 'package.json'), manifest, { mode: 0o600 });
313
- writeFileSync(join(scratch, 'package-lock.json'), lock, { mode: 0o600 });
314
- const installed = spawnSync('/usr/bin/bwrap', sandboxInstallArgs(scratch, npmCache, node, npmCli), {
315
- cwd: scratch, env: { PATH: '/usr/bin:/bin' }, timeout: 180_000, stdio: 'ignore',
316
- });
317
- if (installed.error || installed.signal || installed.status !== 0)
318
- fail('install-failed');
319
- for (const [path, bytes] of files) {
320
- if (path === 'package.json' || path === 'package-lock.json')
321
- continue;
322
- mkdirSync(join(scratch, dirname(path)), { recursive: true, mode: 0o700 });
323
- writeFileSync(join(scratch, path), bytes, { mode: 0o600 });
324
- }
325
- const positiveDir = mkdtempSync(join(tmpdir(), 'p222-property-report-'));
326
- reports.push(positiveDir);
327
- const positive = runSandbox(scratch, positiveDir, plan.writeSet, node);
328
- if (positive !== 0)
329
- fail(existsSync(join(positiveDir, 'report.json'))
330
- ? 'tests-failed' : 'sandbox-unavailable');
331
- const first = assertions(positiveDir, plan.writeSet);
332
- if (first.length < plan.aggregates.reduce((sum, item) => sum + item.invariantCount, 0)
333
- || first.some((row) => row.status !== 'passed'))
334
- fail('tests-failed');
335
- passed = first.length;
336
- for (const [path, names] of mutations) {
337
- const stub = [...names].map((name) => name === 'default'
338
- ? `export default function(){throw new Error('${CANARY}')}`
339
- : `export const ${name}=function(){throw new Error('${CANARY}')}`).join('\n');
340
- writeFileSync(join(scratch, path), `${stub}\n`, { mode: 0o600 });
341
- }
342
- const negativeDir = mkdtempSync(join(tmpdir(), 'p222-property-report-'));
343
- reports.push(negativeDir);
344
- const negative = runSandbox(scratch, negativeDir, plan.writeSet, node);
345
- if (negative === 0 || !existsSync(join(negativeDir, 'report.json')))
346
- fail('mutation-not-causal');
347
- const second = assertions(negativeDir, plan.writeSet);
348
- if (second.length !== first.length || second.some((row) => row.status !== 'failed'
349
- || !Array.isArray(row.failureMessages)
350
- || !row.failureMessages.some((message) => typeof message === 'string' && message.includes(CANARY))))
351
- fail('mutation-not-causal');
352
- causal = second.length;
353
- const after = inspectPropertyTestCandidate(root);
354
- if (after.sourceHead !== head || after.artifactSha256 !== candidate
355
- || createHash('sha256').update(manifest).digest('hex')
356
- !== createHash('sha256').update(safeBytes(root, 'package.json', 1024 * 1024)).digest('hex')
357
- || createHash('sha256').update(lock).digest('hex')
358
- !== createHash('sha256').update(safeBytes(root, 'package-lock.json', 8 * 1024 * 1024)).digest('hex')) {
359
- fail('source-unsupported');
360
- }
361
- return receipt('tests-passed', head, candidate, testFileCount, passed, causal);
362
- }
363
- catch (error) {
364
- return receipt(error instanceof RuntimeFailure ? error.reason : 'source-unsupported', head, candidate, testFileCount, passed, causal);
365
- }
366
- finally {
367
- for (const reportDir of reports)
368
- rmSync(reportDir, { recursive: true, force: true });
369
- if (scratch)
370
- rmSync(scratch, { recursive: true, force: true });
371
- }
372
- }
1
+ import{spawnSync as Z}from"node:child_process";import{createHash as $}from"node:crypto";import{existsSync as b,lstatSync as y,mkdirSync as L,mkdtempSync as O,readFileSync as te,realpathSync as F,rmSync as V,writeFileSync as x}from"node:fs";import{homedir as se,tmpdir as M}from"node:os";import{dirname as ne,join as u,posix as I,resolve as oe}from"node:path";import{parse as re}from"@babel/parser";import{parseDocument as ie}from"yaml";import{mutationQaGit as ae}from"../commands/mutation-qa-git.js";import{loadPropertyTestCandidatePlan as ce}from"./property-test-choices.js";import{inspectPropertyTestCandidate as X}from"./property-test-candidate.js";const z="P222_PROPERTY_CAUSAL_CANARY",ue=512,le=16*1024*1024,pe=256*1024;class q extends Error{reason;constructor(o){super(o),this.reason=o}}function c(n){throw new q(n)}function g(n){return n!==null&&typeof n=="object"&&!Array.isArray(n)}function J(n,o,t,r,e=0,s=0){const a=n==="tests-passed";return Object.freeze({schemaVersion:1,kind:"property-test-runtime",outcome:a?"execution-proven":"unverified",reasonCode:n,sourceHead:o,candidateSha256:t,testFileCount:r,passedTests:e,causalFailedTests:s,executionVerified:a,qaAccepted:!1,publicSafe:!0})}function v(n,o,t){(!/^[A-Za-z0-9_.-]+(?:\/[A-Za-z0-9_.-]+)*$/.test(o)||o.split("/").some(s=>s==="."||s===".."))&&c("source-unsupported");let r=n;const e=o.split("/");for(const[s,a]of e.entries()){r=u(r,a);const p=y(r);(p.isSymbolicLink()||(s===e.length-1?!p.isFile()||p.size<1||p.size>t:!p.isDirectory()))&&c("source-unsupported")}return te(r)}function H(n){try{const o=new TextDecoder("utf-8",{fatal:!0}).decode(n),t=ie(o,{strict:!0,uniqueKeys:!0,schema:"core",customTags:[]});if(t.errors.length||t.warnings.length)return null;const r=JSON.parse(o);return g(r)?r:null}catch{return null}}function de(n,o){const t=H(n),r=H(o);if(!t||!r||t.workspaces!==void 0||![2,3].includes(Number(r.lockfileVersion))||!g(r.packages)||!g(r.packages[""])||Object.keys(r.packages).length>1e4)return!1;const e=/^(?:\^|~)?[0-9]+\.[0-9]+\.[0-9]+$/;for(const l of["dependencies","devDependencies","optionalDependencies","peerDependencies"])if(t[l]!==void 0&&(!g(t[l])||Object.values(t[l]).some(h=>typeof h!="string"||!e.test(h))))return!1;const s={...g(t.dependencies)?t.dependencies:{},...g(t.devDependencies)?t.devDependencies:{}},a=r.packages[""],p=g(a)?{...g(a.dependencies)?a.dependencies:{},...g(a.devDependencies)?a.devDependencies:{}}:{};if(typeof s.vitest!="string"||typeof s["fast-check"]!="string"||p.vitest!==s.vitest||p["fast-check"]!==s["fast-check"])return!1;for(const[l,h]of Object.entries(r.packages)){if(!g(h)||h.link===!0)return!1;if(l!==""){if(!/^node_modules\/(?:@[^/]+\/)?[^/]+(?:\/node_modules\/(?:@[^/]+\/)?[^/]+)*$/.test(l)||h.resolved===void 0||typeof h.resolved!="string"||typeof h.integrity!="string"||!/^sha512-[A-Za-z0-9+/]+={0,2}$/.test(h.integrity))return!1;try{const d=new URL(h.resolved);if(d.protocol!=="https:"||d.hostname!=="registry.npmjs.org"||d.port||d.username||d.password||d.search||d.hash||!d.pathname.startsWith("/")||d.pathname.includes(".."))return!1}catch{return!1}}}return!0}function fe(){for(const n of(process.env.PATH??"").split(":")){if(!n.startsWith("/"))continue;const o=u(n,"npm");if(b(o))try{const t=F(o);return(t.startsWith("/usr/")||t.startsWith("/home/linuxbrew/.linuxbrew/"))&&t.endsWith(".js")&&y(t).isFile()?t:null}catch{return null}}return null}function me(n,o,t){const r=re(o,{sourceType:"module",plugins:["typescript"]}),e=new Set;for(const s of r.program.body)if(!(s.type!=="ImportDeclaration"||s.importKind==="type"||!s.source.value.startsWith(".")||I.normalize(I.join(I.dirname(n),s.source.value)).replace(/\.(?:ts|js)$/,"")!==t.replace(/\.ts$/,"")))for(const p of s.specifiers){p.type==="ImportNamespaceSpecifier"&&c("source-unsupported");const l=p.type==="ImportDefaultSpecifier"?"default":p.imported.type==="Identifier"?p.imported.name:p.imported.value;/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(l)||c("source-unsupported"),e.add(l)}return e.size||c("source-unsupported"),e}function he(n,o,t,r){const e=["--die-with-parent","--new-session","--unshare-all","--clearenv","--setenv","HOME","/tmp","--setenv","TMPDIR","/tmp","--setenv","PATH","/home/linuxbrew/.linuxbrew/bin:/usr/bin:/bin","--setenv","CI","true","--setenv","NODE_ENV","test","--ro-bind","/usr","/usr"];for(const s of["/lib","/lib64","/bin"])b(s)&&e.push("--ro-bind",s,s);b("/home/linuxbrew/.linuxbrew")&&e.push("--ro-bind","/home/linuxbrew/.linuxbrew","/home/linuxbrew/.linuxbrew"),e.push("--dir","/etc");for(const s of["passwd","group","hosts","nsswitch.conf"])e.push("--ro-bind",u(n,".sandbox-etc",s),`/etc/${s}`);return[...e,"--dev","/dev","--proc","/proc","--tmpfs","/tmp","--ro-bind",n,"/work","--bind",o,"/results","--chdir","/work","--",r,"node_modules/vitest/vitest.mjs","run","--maxWorkers=1",...t,"--reporter=json","--outputFile=/results/report.json"]}function be(n,o,t,r){const e=["--die-with-parent","--new-session","--unshare-all","--clearenv","--setenv","HOME","/tmp","--setenv","TMPDIR","/tmp","--setenv","PATH","/home/linuxbrew/.linuxbrew/bin:/usr/bin:/bin","--setenv","CI","true","--setenv","NO_UPDATE_NOTIFIER","1","--setenv","npm_config_cache","/npm-cache","--setenv","npm_config_userconfig","/dev/null","--setenv","npm_config_globalconfig","/tmp/npm-global.npmrc","--ro-bind","/usr","/usr"];for(const s of["/lib","/lib64","/bin"])b(s)&&e.push("--ro-bind",s,s);b("/home/linuxbrew/.linuxbrew")&&e.push("--ro-bind","/home/linuxbrew/.linuxbrew","/home/linuxbrew/.linuxbrew"),e.push("--dir","/etc");for(const s of["passwd","group","hosts","nsswitch.conf"])e.push("--ro-bind",u(n,".sandbox-etc",s),`/etc/${s}`);return[...e,"--dev","/dev","--proc","/proc","--tmpfs","/tmp","--ro-bind",o,"/npm-cache","--bind",n,"/work","--chdir","/work","--",t,r,"ci","--offline","--ignore-scripts","--no-audit","--no-fund"]}function K(n,o,t,r){const e=Z("/usr/bin/bwrap",he(n,o,t,r),{env:{PATH:"/usr/bin:/bin"},timeout:18e4,stdio:"ignore"});return(e.error||e.signal||e.status===null)&&c("sandbox-unavailable"),e.status}function G(n,o){b(u(n,"report.json"))||c("sandbox-unavailable");const t=H(v(n,"report.json",2*1024*1024));(!t||!Array.isArray(t.testResults)||t.testResults.length!==o.length)&&c("tests-failed");const r=new Map;for(const e of t.testResults)(!g(e)||typeof e.name!="string"||!o.some(s=>e.name===`/work/${s}`)||r.has(e.name)||!Array.isArray(e.assertionResults))&&c("tests-failed"),r.set(e.name,e.assertionResults);return o.flatMap(e=>r.get(`/work/${e}`))}function Fe(n){let o=null,t=null,r=0,e=0,s=0,a;const p=[];try{const l=F(process.execPath);(process.platform!=="linux"||!b("/usr/bin/bwrap")||!(l.startsWith("/usr/")||l.startsWith("/home/linuxbrew/.linuxbrew/"))||!y("/usr/bin/bwrap").isFile())&&c("sandbox-unavailable");const h=fe();h||c("toolchain-unavailable");const d=u(se(),".npm");(!b(d)||F(d)!==d||!y(d).isDirectory()||y(d).uid!==process.getuid?.())&&c("toolchain-unavailable");const f=oe(n);(F(f)!==f||!y(f).isDirectory())&&c("source-unsupported");const N=X(f);o=N.sourceHead,t=N.artifactSha256;const{plan:w}=ce(f);r=w.writeSet.length,w.language!=="typescript"&&c("toolchain-unavailable");for(const i of[".npmrc","npm-shrinkwrap.json","pnpm-lock.yaml","yarn.lock","bun.lock","bun.lockb"])b(u(f,i))&&c("toolchain-unavailable");(!b(u(f,"package.json"))||!b(u(f,"package-lock.json")))&&c("toolchain-unavailable");const k=v(f,"package.json",1024*1024),j=v(f,"package-lock.json",8*1024*1024);de(k,j)||c("toolchain-unavailable");const W=ae(f,["ls-files","-z","--","src","app","lib","packages","clients"]).toString("utf8").split("\0").filter(Boolean).filter(i=>/^(?:src|app|lib|packages|clients)\//.test(i)&&/\.(?:ts|tsx|js|jsx|mjs|cjs|json)$/.test(i));W.length>ue&&c("source-unsupported");const S=new Map([["package.json",k],["package-lock.json",j]]);for(const i of W)S.set(i,v(f,i,1024*1024));const P=new Map;for(const i of w.aggregates){const m=v(f,i.testFile,pe),E=new TextDecoder("utf-8",{fatal:!0}).decode(m),D=me(i.testFile,E,i.implementationFile),Y=P.get(i.implementationFile)??new Set;for(const ee of D)Y.add(ee);P.set(i.implementationFile,Y),S.set(i.testFile,m)}[...S.values()].reduce((i,m)=>i+m.length,0)>le&&c("source-unsupported"),a=O(u(M(),"p222-property-runtime-")),L(u(a,".sandbox-etc"),{mode:448});const Q=process.getuid?.()??1e3,B=process.getgid?.()??1e3;for(const[i,m]of Object.entries({passwd:`sandbox:x:${Q}:${B}:Sandbox:/work:/bin/sh
2
+ `,group:`sandbox:x:${B}:
3
+ `,hosts:`127.0.0.1 localhost
4
+ `,"nsswitch.conf":`passwd: files
5
+ group: files
6
+ hosts: files
7
+ `}))x(u(a,".sandbox-etc",i),m,{mode:384});x(u(a,"package.json"),k,{mode:384}),x(u(a,"package-lock.json"),j,{mode:384});const R=Z("/usr/bin/bwrap",be(a,d,l,h),{cwd:a,env:{PATH:"/usr/bin:/bin"},timeout:18e4,stdio:"ignore"});(R.error||R.signal||R.status!==0)&&c("install-failed");for(const[i,m]of S)i==="package.json"||i==="package-lock.json"||(L(u(a,ne(i)),{recursive:!0,mode:448}),x(u(a,i),m,{mode:384}));const A=O(u(M(),"p222-property-report-"));p.push(A),K(a,A,w.writeSet,l)!==0&&c(b(u(A,"report.json"))?"tests-failed":"sandbox-unavailable");const _=G(A,w.writeSet);(_.length<w.aggregates.reduce((i,m)=>i+m.invariantCount,0)||_.some(i=>i.status!=="passed"))&&c("tests-failed"),e=_.length;for(const[i,m]of P){const E=[...m].map(D=>D==="default"?`export default function(){throw new Error('${z}')}`:`export const ${D}=function(){throw new Error('${z}')}`).join(`
8
+ `);x(u(a,i),`${E}
9
+ `,{mode:384})}const T=O(u(M(),"p222-property-report-"));p.push(T),(K(a,T,w.writeSet,l)===0||!b(u(T,"report.json")))&&c("mutation-not-causal");const C=G(T,w.writeSet);(C.length!==_.length||C.some(i=>i.status!=="failed"||!Array.isArray(i.failureMessages)||!i.failureMessages.some(m=>typeof m=="string"&&m.includes(z))))&&c("mutation-not-causal"),s=C.length;const U=X(f);return(U.sourceHead!==o||U.artifactSha256!==t||$("sha256").update(k).digest("hex")!==$("sha256").update(v(f,"package.json",1024*1024)).digest("hex")||$("sha256").update(j).digest("hex")!==$("sha256").update(v(f,"package-lock.json",8*1024*1024)).digest("hex"))&&c("source-unsupported"),J("tests-passed",o,t,r,e,s)}catch(l){return J(l instanceof q?l.reason:"source-unsupported",o,t,r,e,s)}finally{for(const l of p)V(l,{recursive:!0,force:!0});a&&V(a,{recursive:!0,force:!0})}}export{Fe as verifyPropertyTestRuntime};
@@ -1,139 +1 @@
1
- /** Static candidate check only: parsing a property test never grants a QA verdict. */
2
- import { parse } from '@babel/parser';
3
- import { posix } from 'node:path';
4
- const MAX_NODES = 100_000;
5
- function object(value) {
6
- return value !== null && typeof value === 'object' && !Array.isArray(value);
7
- }
8
- function identifier(value, name) {
9
- return object(value) && value.type === 'Identifier' && value.name === name;
10
- }
11
- function member(value, owner, name) {
12
- return object(value) && value.type === 'MemberExpression' && value.computed === false
13
- && identifier(value.object, owner) && identifier(value.property, name);
14
- }
15
- function propertyAssertion(value, fastCheckName, numRuns) {
16
- if (!object(value) || value.type !== 'CallExpression' || !member(value.callee, fastCheckName, 'assert')
17
- || !Array.isArray(value.arguments) || value.arguments.length !== 2)
18
- return false;
19
- const property = value.arguments[0];
20
- const options = value.arguments[1];
21
- if (!object(property) || property.type !== 'CallExpression'
22
- || !(member(property.callee, fastCheckName, 'property')
23
- || member(property.callee, fastCheckName, 'asyncProperty'))
24
- || !Array.isArray(property.arguments) || property.arguments.length < 2
25
- || !object(property.arguments[property.arguments.length - 1])
26
- || !['ArrowFunctionExpression', 'FunctionExpression'].includes(String(property.arguments[property.arguments.length - 1].type))
27
- || !object(options) || options.type !== 'ObjectExpression' || !Array.isArray(options.properties))
28
- return false;
29
- const runEntries = options.properties.filter((entry) => object(entry) && entry.type === 'ObjectProperty'
30
- && entry.computed === false && (identifier(entry.key, 'numRuns')
31
- || object(entry.key) && entry.key.type === 'StringLiteral' && entry.key.value === 'numRuns'));
32
- return runEntries.length === 1 && object(runEntries[0]) && object(runEntries[0].value)
33
- && runEntries[0].value.type === 'NumericLiteral' && runEntries[0].value.value === numRuns
34
- && options.properties.every((entry) => object(entry)
35
- && entry.type === 'ObjectProperty' && entry.computed === false);
36
- }
37
- function hasPropertyAssertion(callback, fastCheckName, numRuns) {
38
- const stack = [callback];
39
- let visited = 0;
40
- while (stack.length) {
41
- const node = stack.pop();
42
- if (!object(node))
43
- continue;
44
- if (++visited > MAX_NODES)
45
- throw new Error('property-test-source-invalid');
46
- if (propertyAssertion(node, fastCheckName, numRuns))
47
- return true;
48
- for (const [key, value] of Object.entries(node)) {
49
- if (key === 'loc' || key === 'extra' || key === 'comments'
50
- || key === 'leadingComments' || key === 'trailingComments')
51
- continue;
52
- if (Array.isArray(value))
53
- stack.push(...value);
54
- else if (object(value))
55
- stack.push(value);
56
- }
57
- }
58
- return false;
59
- }
60
- /** Require direct Vitest cases with real fast-check calls and a value import from the mapped module. */
61
- export function validatePropertyTestTypeScriptSource(input) {
62
- let ast;
63
- try {
64
- ast = parse(input.source, { sourceType: 'module', plugins: ['typescript'] });
65
- }
66
- catch {
67
- throw new Error('property-test-source-invalid');
68
- }
69
- const implementation = input.implementationFile.replace(/\.ts$/, '');
70
- let fastCheckName;
71
- const vitestNames = new Set();
72
- let implementationImported = false;
73
- for (const node of ast.program.body) {
74
- if (node.type !== 'ImportDeclaration' || node.importKind === 'type')
75
- continue;
76
- if (node.source.value === 'fast-check') {
77
- if (fastCheckName || node.specifiers.length !== 1
78
- || !['ImportDefaultSpecifier', 'ImportNamespaceSpecifier'].includes(node.specifiers[0].type)) {
79
- throw new Error('property-test-source-invalid');
80
- }
81
- fastCheckName = node.specifiers[0].local.name;
82
- }
83
- else if (node.source.value === 'vitest') {
84
- for (const specifier of node.specifiers) {
85
- if (specifier.type === 'ImportSpecifier'
86
- && specifier.importKind !== 'type'
87
- && specifier.imported.type === 'Identifier'
88
- && ['it', 'test'].includes(specifier.imported.name))
89
- vitestNames.add(specifier.local.name);
90
- }
91
- }
92
- else if (node.source.value.startsWith('.')) {
93
- const resolved = posix.normalize(posix.join(posix.dirname(input.testFile), node.source.value))
94
- .replace(/\.(?:ts|js)$/, '');
95
- if (resolved === implementation && node.specifiers.some((specifier) => specifier.type !== 'ImportSpecifier' || specifier.importKind !== 'type'))
96
- implementationImported = true;
97
- }
98
- }
99
- if (!fastCheckName || vitestNames.size === 0 || !implementationImported) {
100
- throw new Error('property-test-source-invalid');
101
- }
102
- const stack = [ast.program];
103
- let visited = 0;
104
- let verifiedCases = 0;
105
- while (stack.length) {
106
- const node = stack.pop();
107
- if (!object(node))
108
- continue;
109
- if (++visited > MAX_NODES)
110
- throw new Error('property-test-source-invalid');
111
- if (node.type === 'CallExpression') {
112
- const callee = node.callee;
113
- if (object(callee) && callee.type === 'MemberExpression'
114
- && object(callee.object) && callee.object.type === 'Identifier'
115
- && (vitestNames.has(String(callee.object.name)) || callee.object.name === 'describe')
116
- && object(callee.property) && ['skip', 'todo', 'only'].includes(String(callee.property.name))) {
117
- throw new Error('property-test-source-invalid');
118
- }
119
- if (object(callee) && callee.type === 'Identifier' && vitestNames.has(String(callee.name))) {
120
- const args = node.arguments;
121
- if (!Array.isArray(args) || args.length < 2 || !hasPropertyAssertion(args[1], fastCheckName, input.numRuns)) {
122
- throw new Error('property-test-source-invalid');
123
- }
124
- verifiedCases++;
125
- }
126
- }
127
- for (const [key, value] of Object.entries(node)) {
128
- if (key === 'loc' || key === 'extra' || key === 'comments'
129
- || key === 'leadingComments' || key === 'trailingComments')
130
- continue;
131
- if (Array.isArray(value))
132
- stack.push(...value);
133
- else if (object(value))
134
- stack.push(value);
135
- }
136
- }
137
- if (verifiedCases < input.invariantCount)
138
- throw new Error('property-test-source-invalid');
139
- }
1
+ import{parse as h}from"@babel/parser";import{posix as f}from"node:path";const g=1e5;function o(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function u(e,n){return o(e)&&e.type==="Identifier"&&e.name===n}function y(e,n,l){return o(e)&&e.type==="MemberExpression"&&e.computed===!1&&u(e.object,n)&&u(e.property,l)}function w(e,n,l){if(!o(e)||e.type!=="CallExpression"||!y(e.callee,n,"assert")||!Array.isArray(e.arguments)||e.arguments.length!==2)return!1;const i=e.arguments[0],p=e.arguments[1];if(!o(i)||i.type!=="CallExpression"||!(y(i.callee,n,"property")||y(i.callee,n,"asyncProperty"))||!Array.isArray(i.arguments)||i.arguments.length<2||!o(i.arguments[i.arguments.length-1])||!["ArrowFunctionExpression","FunctionExpression"].includes(String(i.arguments[i.arguments.length-1].type))||!o(p)||p.type!=="ObjectExpression"||!Array.isArray(p.properties))return!1;const c=p.properties.filter(t=>o(t)&&t.type==="ObjectProperty"&&t.computed===!1&&(u(t.key,"numRuns")||o(t.key)&&t.key.type==="StringLiteral"&&t.key.value==="numRuns"));return c.length===1&&o(c[0])&&o(c[0].value)&&c[0].value.type==="NumericLiteral"&&c[0].value.value===l&&p.properties.every(t=>o(t)&&t.type==="ObjectProperty"&&t.computed===!1)}function A(e,n,l){const i=[e];let p=0;for(;i.length;){const c=i.pop();if(o(c)){if(++p>g)throw new Error("property-test-source-invalid");if(w(c,n,l))return!0;for(const[t,m]of Object.entries(c))t==="loc"||t==="extra"||t==="comments"||t==="leadingComments"||t==="trailingComments"||(Array.isArray(m)?i.push(...m):o(m)&&i.push(m))}}return!1}function v(e){let n;try{n=h(e.source,{sourceType:"module",plugins:["typescript"]})}catch{throw new Error("property-test-source-invalid")}const l=e.implementationFile.replace(/\.ts$/,"");let i;const p=new Set;let c=!1;for(const s of n.program.body)if(!(s.type!=="ImportDeclaration"||s.importKind==="type"))if(s.source.value==="fast-check"){if(i||s.specifiers.length!==1||!["ImportDefaultSpecifier","ImportNamespaceSpecifier"].includes(s.specifiers[0].type))throw new Error("property-test-source-invalid");i=s.specifiers[0].local.name}else if(s.source.value==="vitest")for(const r of s.specifiers)r.type==="ImportSpecifier"&&r.importKind!=="type"&&r.imported.type==="Identifier"&&["it","test"].includes(r.imported.name)&&p.add(r.local.name);else s.source.value.startsWith(".")&&f.normalize(f.join(f.dirname(e.testFile),s.source.value)).replace(/\.(?:ts|js)$/,"")===l&&s.specifiers.some(a=>a.type!=="ImportSpecifier"||a.importKind!=="type")&&(c=!0);if(!i||p.size===0||!c)throw new Error("property-test-source-invalid");const t=[n.program];let m=0,d=0;for(;t.length;){const s=t.pop();if(o(s)){if(++m>g)throw new Error("property-test-source-invalid");if(s.type==="CallExpression"){const r=s.callee;if(o(r)&&r.type==="MemberExpression"&&o(r.object)&&r.object.type==="Identifier"&&(p.has(String(r.object.name))||r.object.name==="describe")&&o(r.property)&&["skip","todo","only"].includes(String(r.property.name)))throw new Error("property-test-source-invalid");if(o(r)&&r.type==="Identifier"&&p.has(String(r.name))){const a=s.arguments;if(!Array.isArray(a)||a.length<2||!A(a[1],i,e.numRuns))throw new Error("property-test-source-invalid");d++}}for(const[r,a]of Object.entries(s))r==="loc"||r==="extra"||r==="comments"||r==="leadingComments"||r==="trailingComments"||(Array.isArray(a)?t.push(...a):o(a)&&t.push(a))}}if(d<e.invariantCount)throw new Error("property-test-source-invalid")}export{v as validatePropertyTestTypeScriptSource};
@@ -1,80 +1 @@
1
- /** Root-only C08 adapter for the P222.16 private Codex beta. */
2
- import { execFileSync } from 'node:child_process';
3
- import { createHash } from 'node:crypto';
4
- import { resolve } from 'node:path';
5
- import { beginDirectYoloStoryCommit, finalizeDirectYoloStoryCheckpoint, issueDirectYoloSetupLeaseHandoff, } from '../git/direct-yolo-checkpoint.js';
6
- import { verifyPrivateYoloCleanBaseline } from './clean-baseline.js';
7
- import { stagePrivateYoloIsolatedSessionBundle } from './isolated-session.js';
8
- // Public projection of the checkpoint step. Keep the server-owned step name
9
- // out of the npm client while requiring this exact opaque action binding.
10
- const ROOT_CHECKPOINT_PUBLIC_STEP_ID = 'step-5ce2a8c7';
11
- function git(root, args) {
12
- const environment = { ...process.env };
13
- for (const key of [
14
- 'GIT_DIR', 'GIT_WORK_TREE', 'GIT_INDEX_FILE', 'GIT_OBJECT_DIRECTORY',
15
- 'GIT_ALTERNATE_OBJECT_DIRECTORIES', 'GIT_COMMON_DIR', 'GIT_NAMESPACE', 'GIT_CEILING_DIRECTORIES',
16
- ])
17
- delete environment[key];
18
- return execFileSync('git', [...args], {
19
- cwd: root, env: environment, stdio: ['ignore', 'pipe', 'pipe'],
20
- timeout: 30_000, maxBuffer: 16 * 1024 * 1024,
21
- });
22
- }
23
- /**
24
- * The agent cannot write `.git`. The root stages only the exact frozen C01
25
- * claim admitted from the pinned clone, then uses the existing two-phase
26
- * physical checkpoint authority. A failed post-commit checkpoint is never
27
- * silently recovered.
28
- */
29
- export async function runPrivateYoloRootCheckpoint(projectRoot, action) {
30
- const root = resolve(projectRoot);
31
- if (action.schemaVersion !== 1 || action.action !== 'checkpoint-epic-story'
32
- || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(action.storyId)
33
- || !/^[a-f0-9]{64}$/.test(action.graphRevision)
34
- || action.stepId !== ROOT_CHECKPOINT_PUBLIC_STEP_ID
35
- || !/^[A-Za-z0-9][A-Za-z0-9._/-]{0,127}$/.test(action.executionBranch)
36
- || action.executionBranch.includes('..')
37
- || action.publicSafe !== true)
38
- throw new Error('private-execution-root-checkpoint-invalid');
39
- await verifyPrivateYoloCleanBaseline(root, action.storyId, action.executionBranch, action.graphRevision);
40
- const staged = await stagePrivateYoloIsolatedSessionBundle(root, action.storyId, action.graphRevision);
41
- const handoff = await issueDirectYoloSetupLeaseHandoff({ projectRoot: root, storyId: action.storyId });
42
- if (!handoff.ok || handoff.value.bundleDigest !== staged.bundleSha256) {
43
- throw new Error('private-execution-root-checkpoint-handoff-denied', {
44
- cause: new Error(handoff.ok ? 'private-execution-root-checkpoint-handoff-bundle-mismatch' : handoff.reasonCode),
45
- });
46
- }
47
- const begun = await beginDirectYoloStoryCommit({ projectRoot: root, storyId: action.storyId });
48
- if (!begun.ok)
49
- throw new Error('private-execution-root-checkpoint-begin-denied');
50
- if (begun.value.graphRevision !== action.graphRevision
51
- || begun.value.executionBranch !== action.executionBranch) {
52
- throw new Error('private-execution-root-checkpoint-authority-drift');
53
- }
54
- try {
55
- const physicalHead = git(root, ['rev-parse', 'HEAD']).toString('utf8').trim();
56
- const physicalBranch = git(root, ['symbolic-ref', '--quiet', '--short', 'HEAD']).toString('utf8').trim();
57
- const stagedBundle = git(root, ['diff', '--cached', '--binary', '--full-index']);
58
- const stagedDigest = createHash('sha256').update(stagedBundle).digest('hex');
59
- if (physicalHead !== begun.value.baseSha || physicalBranch !== begun.value.executionBranch
60
- || stagedDigest !== begun.value.bundleDigest || stagedDigest !== staged.bundleSha256) {
61
- throw new Error('private-execution-root-checkpoint-bundle-drift');
62
- }
63
- git(root, [
64
- 'commit', '-m', `fix(${action.storyId}): checkpoint direct yolo`,
65
- ...begun.value.trailers.flatMap((trailer) => ['-m', trailer]),
66
- ]);
67
- }
68
- catch (error) {
69
- if (error instanceof Error && error.message === 'private-execution-root-checkpoint-bundle-drift')
70
- throw error;
71
- throw new Error('private-execution-root-checkpoint-commit-failed');
72
- }
73
- const finalized = await finalizeDirectYoloStoryCheckpoint({ projectRoot: root, storyId: action.storyId, push: true });
74
- if (!finalized.ok)
75
- throw new Error('private-execution-root-checkpoint-finalize-denied');
76
- return Object.freeze({
77
- schemaVersion: 1, outcome: 'checkpoint-validated', storyId: action.storyId,
78
- headSha: finalized.value.headSha, publicSafe: true,
79
- });
80
- }
1
+ import{execFileSync as f}from"node:child_process";import{createHash as l}from"node:crypto";import{resolve as I}from"node:path";import{beginDirectYoloStoryCommit as v,finalizeDirectYoloStoryCheckpoint as m,issueDirectYoloSetupLeaseHandoff as E}from"../git/direct-yolo-checkpoint.js";import{verifyPrivateYoloCleanBaseline as y}from"./clean-baseline.js";import{stagePrivateYoloIsolatedSessionBundle as g}from"./isolated-session.js";const w="step-5ce2a8c7";function a(c,e){const o={...process.env};for(const i of["GIT_DIR","GIT_WORK_TREE","GIT_INDEX_FILE","GIT_OBJECT_DIRECTORY","GIT_ALTERNATE_OBJECT_DIRECTORIES","GIT_COMMON_DIR","GIT_NAMESPACE","GIT_CEILING_DIRECTORIES"])delete o[i];return f("git",[...e],{cwd:c,env:o,stdio:["ignore","pipe","pipe"],timeout:3e4,maxBuffer:16*1024*1024})}async function b(c,e){const o=I(c);if(e.schemaVersion!==1||e.action!=="checkpoint-epic-story"||!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(e.storyId)||!/^[a-f0-9]{64}$/.test(e.graphRevision)||e.stepId!==w||!/^[A-Za-z0-9][A-Za-z0-9._/-]{0,127}$/.test(e.executionBranch)||e.executionBranch.includes("..")||e.publicSafe!==!0)throw new Error("private-execution-root-checkpoint-invalid");await y(o,e.storyId,e.executionBranch,e.graphRevision);const i=await g(o,e.storyId,e.graphRevision),n=await E({projectRoot:o,storyId:e.storyId});if(!n.ok||n.value.bundleDigest!==i.bundleSha256)throw new Error("private-execution-root-checkpoint-handoff-denied",{cause:new Error(n.ok?"private-execution-root-checkpoint-handoff-bundle-mismatch":n.reasonCode)});const t=await v({projectRoot:o,storyId:e.storyId});if(!t.ok)throw new Error("private-execution-root-checkpoint-begin-denied");if(t.value.graphRevision!==e.graphRevision||t.value.executionBranch!==e.executionBranch)throw new Error("private-execution-root-checkpoint-authority-drift");try{const r=a(o,["rev-parse","HEAD"]).toString("utf8").trim(),h=a(o,["symbolic-ref","--quiet","--short","HEAD"]).toString("utf8").trim(),u=a(o,["diff","--cached","--binary","--full-index"]),d=l("sha256").update(u).digest("hex");if(r!==t.value.baseSha||h!==t.value.executionBranch||d!==t.value.bundleDigest||d!==i.bundleSha256)throw new Error("private-execution-root-checkpoint-bundle-drift");a(o,["commit","-m",`fix(${e.storyId}): checkpoint direct yolo`,...t.value.trailers.flatMap(p=>["-m",p])])}catch(r){throw r instanceof Error&&r.message==="private-execution-root-checkpoint-bundle-drift"?r:new Error("private-execution-root-checkpoint-commit-failed")}const s=await m({projectRoot:o,storyId:e.storyId,push:!0});if(!s.ok)throw new Error("private-execution-root-checkpoint-finalize-denied");return Object.freeze({schemaVersion:1,outcome:"checkpoint-validated",storyId:e.storyId,headSha:s.value.headSha,publicSafe:!0})}export{b as runPrivateYoloRootCheckpoint};