@gate-forge/cli 0.13.10 → 0.15.0

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 (107) hide show
  1. package/CHANGELOG.md +415 -0
  2. package/README.md +13 -1
  3. package/bin/gateforge.js +3 -1
  4. package/dist/additional-app-origins.d.ts +38 -0
  5. package/dist/additional-app-origins.d.ts.map +1 -0
  6. package/dist/additional-app-origins.js +46 -0
  7. package/dist/additional-app-origins.js.map +1 -0
  8. package/dist/adopted-baseline.d.ts +2 -0
  9. package/dist/adopted-baseline.d.ts.map +1 -1
  10. package/dist/adopted-baseline.js +1 -0
  11. package/dist/adopted-baseline.js.map +1 -1
  12. package/dist/args.d.ts.map +1 -1
  13. package/dist/args.js +1 -0
  14. package/dist/args.js.map +1 -1
  15. package/dist/candidate-tree.d.ts +1 -1
  16. package/dist/candidate-tree.d.ts.map +1 -1
  17. package/dist/candidate-tree.js +24 -2
  18. package/dist/candidate-tree.js.map +1 -1
  19. package/dist/ci-witnessed-template.d.ts.map +1 -1
  20. package/dist/ci-witnessed-template.js +7 -5
  21. package/dist/ci-witnessed-template.js.map +1 -1
  22. package/dist/cli.d.ts +1 -1
  23. package/dist/cli.d.ts.map +1 -1
  24. package/dist/cli.js +4 -1
  25. package/dist/cli.js.map +1 -1
  26. package/dist/commands/adapters.d.ts.map +1 -1
  27. package/dist/commands/adapters.js +17 -12
  28. package/dist/commands/adapters.js.map +1 -1
  29. package/dist/commands/adopt.d.ts.map +1 -1
  30. package/dist/commands/adopt.js +163 -13
  31. package/dist/commands/adopt.js.map +1 -1
  32. package/dist/commands/baseline.d.ts.map +1 -1
  33. package/dist/commands/baseline.js +23 -5
  34. package/dist/commands/baseline.js.map +1 -1
  35. package/dist/commands/blocking.d.ts.map +1 -1
  36. package/dist/commands/blocking.js +1 -0
  37. package/dist/commands/blocking.js.map +1 -1
  38. package/dist/commands/check.d.ts.map +1 -1
  39. package/dist/commands/check.js +60 -76
  40. package/dist/commands/check.js.map +1 -1
  41. package/dist/commands/config.d.ts +3 -0
  42. package/dist/commands/config.d.ts.map +1 -0
  43. package/dist/commands/config.js +106 -0
  44. package/dist/commands/config.js.map +1 -0
  45. package/dist/commands/enforcement.d.ts +12 -1
  46. package/dist/commands/enforcement.d.ts.map +1 -1
  47. package/dist/commands/enforcement.js +85 -34
  48. package/dist/commands/enforcement.js.map +1 -1
  49. package/dist/commands/init-presets.d.ts +11 -0
  50. package/dist/commands/init-presets.d.ts.map +1 -1
  51. package/dist/commands/init-presets.js +6 -0
  52. package/dist/commands/init-presets.js.map +1 -1
  53. package/dist/commands/init.d.ts.map +1 -1
  54. package/dist/commands/init.js +13 -1
  55. package/dist/commands/init.js.map +1 -1
  56. package/dist/commands/next.d.ts.map +1 -1
  57. package/dist/commands/next.js +33 -4
  58. package/dist/commands/next.js.map +1 -1
  59. package/dist/commands/test-gates.d.ts +90 -0
  60. package/dist/commands/test-gates.d.ts.map +1 -1
  61. package/dist/commands/test-gates.js +156 -50
  62. package/dist/commands/test-gates.js.map +1 -1
  63. package/dist/endpoint-compiler.d.ts.map +1 -1
  64. package/dist/endpoint-compiler.js +73 -6
  65. package/dist/endpoint-compiler.js.map +1 -1
  66. package/dist/evaluate.d.ts +40 -1
  67. package/dist/evaluate.d.ts.map +1 -1
  68. package/dist/evaluate.js +91 -4
  69. package/dist/evaluate.js.map +1 -1
  70. package/dist/evidence-authority.d.ts +68 -0
  71. package/dist/evidence-authority.d.ts.map +1 -0
  72. package/dist/evidence-authority.js +114 -0
  73. package/dist/evidence-authority.js.map +1 -0
  74. package/dist/execution.d.ts +0 -25
  75. package/dist/execution.d.ts.map +1 -1
  76. package/dist/execution.js +16 -11
  77. package/dist/execution.js.map +1 -1
  78. package/dist/git-ignored.d.ts +22 -0
  79. package/dist/git-ignored.d.ts.map +1 -1
  80. package/dist/git-ignored.js +49 -0
  81. package/dist/git-ignored.js.map +1 -1
  82. package/dist/pipeline.d.ts.map +1 -1
  83. package/dist/pipeline.js +1 -0
  84. package/dist/pipeline.js.map +1 -1
  85. package/dist/providers.d.ts +22 -0
  86. package/dist/providers.d.ts.map +1 -1
  87. package/dist/providers.js +60 -11
  88. package/dist/providers.js.map +1 -1
  89. package/dist/reseal.d.ts.map +1 -1
  90. package/dist/reseal.js +30 -14
  91. package/dist/reseal.js.map +1 -1
  92. package/dist/run-evidence.d.ts +1 -1
  93. package/dist/run-evidence.d.ts.map +1 -1
  94. package/dist/run-evidence.js +7 -3
  95. package/dist/run-evidence.js.map +1 -1
  96. package/dist/runtime-reuse.d.ts +8 -0
  97. package/dist/runtime-reuse.d.ts.map +1 -1
  98. package/dist/runtime-reuse.js +40 -0
  99. package/dist/runtime-reuse.js.map +1 -1
  100. package/dist/state.d.ts +19 -1
  101. package/dist/state.d.ts.map +1 -1
  102. package/dist/state.js +39 -1
  103. package/dist/state.js.map +1 -1
  104. package/guides/QUICKSTART.md +7 -7
  105. package/guides/REFERENCE.md +301 -1
  106. package/guides/TEST-ENVIRONMENT.md +15 -8
  107. package/package.json +11 -11
@@ -59,8 +59,8 @@ import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync,
59
59
  import { setTimeout as delay } from 'node:timers/promises';
60
60
  import { tmpdir } from 'node:os';
61
61
  import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
62
- import { AttestationSchema, BEHAVIOR_CASE_KIND, BehaviorCasePayloadSchema, BehaviorCatalogRegistrationSchema, CAUSE_NEXT_ACTIONS, canonicalJson, compareStrings, caseExecutionDigestOf, EMPTY_BEHAVIOR_CATALOG_DIGEST, engineBundleDigestOf, EvidenceRecordSchema, GateReceiptSchema, ExecutionResultSchema, executionBoundaryDigestOf, evaluateObligation, LOCAL_UNISOLATED_BOUNDARY, humanMessage, isWitnessedRecord, renderRun, requiredCaseSetDigestOf, repositoryDebtOf, runExitCode, sha256Canonical, selectionDigestOf, targetArtifactDigestOf, verifyAttestationMac, executionResultDigestOf, testOutcomesDigestOf, verifyRunRecord, BLOCKING_VERDICTS, decideStrictness, loadQuarantines, QUARANTINE_DIR, resolveStrictnessMode, strictnessSummaryLine, twinDivergenceDetail, twinLinksFor, twinPathDivergence, withoutQuarantinedBindings, } from '@gate-forge/core';
63
- import { appendFreezeReleaseEvent, armFreezeControl, buildWitnessedPytestChildEnv, canonicalFreezeJson, defaultPlaywrightCommand, diffNativePlaywrightTests, discoverTestCatalog, findPlaywrightConfig, isPlaywrightRunnerInstall, listNativePlaywrightTests, mintFreezeSigningKeyPair, nativeConfigDirOf, playwrightTestModulePath, removeFreezeSpecDir, signFreezeRelease, spoolPathFor, supervisedRunnerChildEnv, writeFreezeRefusal, resolveProjectStorageState, CypressRunnerAdapter, PlaywrightAdapter, PytestRunnerAdapter, readRunnerOutcomes, startSupervisorSpoolDrain, startWitnessProcess, SupervisorClient, TestDiscoveryError, VitestRunnerAdapter, RUN_HEADER, VERIFIER_HEADER, DEFAULT_RUN_TIMEOUT_MS, ENV_CHAOS_MAX_DELAY_MS, ENV_CHAOS_REORDER, ENV_CHAOS_SEED, ENV_PROXY_TARGET, ENV_TWIN_INVENTORY, ENV_TWIN_QUERY_KEYS, ENV_TWIN_SHAPES, } from '@gate-forge/pack-playwright';
62
+ import { AttestationSchema, BEHAVIOR_CASE_KIND, BehaviorCasePayloadSchema, BehaviorCatalogRegistrationSchema, CAUSE_NEXT_ACTIONS, canonicalJson, compareStrings, caseExecutionDigestOf, EMPTY_BEHAVIOR_CATALOG_DIGEST, engineBundleDigestOf, EvidenceRecordSchema, GateReceiptSchema, ExecutionResultSchema, executionBoundaryDigestOf, evaluateObligation, LOCAL_UNISOLATED_BOUNDARY, humanMessage, isWitnessedRecord, renderRun, requiredCaseSetDigestOf, repositoryDebtOf, runExitCode, sha256Canonical, selectionDigestOf, targetArtifactDigestOf, verifyAttestationMac, executionResultDigestOf, testOutcomesDigestOf, verifyRunRecord, BLOCKING_VERDICTS, decideStrictness, loadQuarantines, QUARANTINE_DIR, resolveStrictnessMode, strictnessSummaryLine, twinDivergenceDetail, twinLinksFor, twinPathDivergence, withoutQuarantinedBindings, runnerLogicalKey, } from '@gate-forge/core';
63
+ import { appendFreezeReleaseEvent, armFreezeControl, buildWitnessedPytestChildEnv, canonicalFreezeJson, defaultPlaywrightCommand, diffNativePlaywrightTests, discoverTestCatalog, refreshCatalogAfterRunnerEnumeration, findPlaywrightConfig, isPlaywrightRunnerInstall, listNativePlaywrightTests, mintFreezeSigningKeyPair, nativeConfigDirOf, playwrightTestModulePath, removeFreezeSpecDir, signFreezeRelease, spoolPathFor, supervisedRunnerChildEnv, writeFreezeRefusal, resolveProjectStorageState, CypressRunnerAdapter, PlaywrightAdapter, PytestRunnerAdapter, readRunnerOutcomes, startSupervisorSpoolDrain, startWitnessProcess, SupervisorClient, TestDiscoveryError, VitestRunnerAdapter, RUN_HEADER, VERIFIER_HEADER, DEFAULT_RUN_TIMEOUT_MS, ENV_CHAOS_MAX_DELAY_MS, ENV_CHAOS_REORDER, ENV_CHAOS_SEED, ENV_PROXY_TARGET, ENV_TWIN_INVENTORY, ENV_TWIN_QUERY_KEYS, ENV_TWIN_SHAPES, autoSessionNodeOptions, } from '@gate-forge/pack-playwright';
64
64
  import { parseArgs, repeatableStringFlag, stringFlag } from '../args.js';
65
65
  import { resolveAdoptedBaseline } from '../adopted-baseline.js';
66
66
  import { UsageError } from '../errors.js';
@@ -85,9 +85,10 @@ import { computeEvaluationScope } from '../scope.js';
85
85
  import { candidateTreeCoversCommit, computeCandidateTreeSnapshot, listTrackedPaths, resolveGitDir, sanitizedAuthorityEnv } from '../candidate-tree.js';
86
86
  import { acceptedFreezeRequest, classifyGeneratedTargets, planNativeFreeze, preparedCandidateViolations, unfrozenPrerequisiteState, } from '../native-freeze.js';
87
87
  import { loadRuntimeConfigAt, resolveRuntimeReuseDigest } from '../runtime.js';
88
- import { mergeRequestScopePreflight, resolveProvider } from '../providers.js';
88
+ import { mergeRequestScopePreflight, resolveGithubBaseCommit, resolveProvider } from '../providers.js';
89
89
  import { engineIdentity, reportEngineLine } from '../engine-identity.js';
90
90
  import { assertReceiptApprovedPolicy, evaluateApprovedPolicy, resolveApprovedPolicyDigest } from '../trusted-policy.js';
91
+ import { resolveAdditionalAppOrigins } from '../additional-app-origins.js';
91
92
  import { unstagedPolicyInputs } from './enforcement.js';
92
93
  import { clearGateReceipt, clearRunRecord, httpRoutesView, readJsonArray, readStateDocument, resolveStateDir, stateObligations, writeClaimInjections, writeClassificationsView, writeEnv, writeExecutionResult, writeCandidateTreeEntries, writeGateReceipt, writeHttpRoutesView, writeInputSnapshot, writeManifest, writeObligations, writeLastFullRunSummary, writeReport, writeRunRecord, writeTwinInventory, writeTwinShapes, } from '../state.js';
93
94
  import { engineGeneratedStateFileFilter } from '../state-artifacts.js';
@@ -610,6 +611,7 @@ async function legacyTestGates(io, options) {
610
611
  [VERIFIER_KEY_ENV]: undefined,
611
612
  [VERIFIER_KEY_FILE_ENV]: undefined,
612
613
  ...suiteEnv,
614
+ ...(witnessUrl === undefined ? {} : { NODE_OPTIONS: autoSessionNodeOptions(suiteEnv['NODE_OPTIONS'] ?? io.env['NODE_OPTIONS']) }),
613
615
  },
614
616
  });
615
617
  suiteFailed = suiteStatus !== 0;
@@ -701,6 +703,12 @@ async function legacyTestGates(io, options) {
701
703
  engineLine: reportEngineLine(),
702
704
  lifecycleDerivation: pipeline.lifecycleDerivation,
703
705
  diagnosticContext,
706
+ ...(evaluated.httpCallAdvisories.length === 0
707
+ ? {}
708
+ : { advisories: [...evaluated.httpCallAdvisories] }),
709
+ ...(evaluated.httpLedger === undefined ? {} : { httpLedger: evaluated.httpLedger }),
710
+ ...(evaluated.uiLedger === undefined ? {} : { uiLedger: evaluated.uiLedger }),
711
+ httpCoverage: evaluated.httpCoverage.summary,
704
712
  });
705
713
  writeLine(io.stdout, report);
706
714
  writeReport(stateDir, renderRun(evaluated.verdicts, {
@@ -713,6 +721,12 @@ async function legacyTestGates(io, options) {
713
721
  engineLine: reportEngineLine(),
714
722
  lifecycleDerivation: pipeline.lifecycleDerivation,
715
723
  diagnosticContext,
724
+ ...(evaluated.httpCallAdvisories.length === 0
725
+ ? {}
726
+ : { advisories: [...evaluated.httpCallAdvisories] }),
727
+ ...(evaluated.httpLedger === undefined ? {} : { httpLedger: evaluated.httpLedger }),
728
+ ...(evaluated.uiLedger === undefined ? {} : { uiLedger: evaluated.uiLedger }),
729
+ httpCoverage: evaluated.httpCoverage.summary,
716
730
  }));
717
731
  const gateCode = runExitCode({ verdicts: evaluated.verdicts, blocking: evaluated.blocking });
718
732
  return suiteFailed && gateCode === 0 ? 1 : gateCode;
@@ -778,6 +792,7 @@ function runOptionsJson(options) {
778
792
  inventory: [...options.twinShapes.inventory],
779
793
  },
780
794
  }),
795
+ ...(options.responseShape === undefined ? {} : { responseShape: { ...options.responseShape } }),
781
796
  };
782
797
  }
783
798
  /**
@@ -866,7 +881,7 @@ export function twinPairNotComparedLine(link, witnessedObserved, rawObserved) {
866
881
  ].join(' and ');
867
882
  const fix = rawObserved
868
883
  ? ''
869
- : ' — a raw twin is observed only when it runs with the Gateforge test fixture, which opens an observation-only session for it (it issues no evidence)';
884
+ : ' — use a supported Playwright test import (@playwright/test or playwright/test) for automatic sessions, or the explicit Gateforge test fixture, and send browser requests through the session proxy; linked raw twins are observation-only (they issue no evidence)';
870
885
  return `test-gates: twin pair not compared: ${unobserved} sent no request through the witness${fix}`;
871
886
  }
872
887
  /** Candidate keys listed in an unresolved-selector error are capped at this many. */
@@ -955,19 +970,20 @@ export function resolveTestSelectors(selectors, rows) {
955
970
  * Returns:
956
971
  * string | null: verified 40-character base commit, or null when unavailable.
957
972
  */
958
- function resolveCarryForwardBaseSha(io, provider) {
973
+ export function resolveCarryForwardBaseSha(io, provider) {
959
974
  if (provider === 'gitlab-mr') {
960
975
  const sha = io.env['CI_MERGE_REQUEST_DIFF_BASE_SHA']?.trim() ?? '';
961
976
  return /^[0-9a-f]{40}$/.test(sha) ? sha : null;
962
977
  }
963
978
  if (provider !== 'github-pr')
964
979
  return null;
965
- const baseRef = io.env['GITHUB_BASE_REF']?.trim() ?? '';
966
- if (baseRef.length === 0 || baseRef.startsWith('-') || /[\\s\\0]/.test(baseRef))
980
+ const authorityEnv = sanitizedAuthorityEnv(io.env);
981
+ const baseCommit = resolveGithubBaseCommit(io.cwd, io.env['GITHUB_BASE_REF'] ?? '', authorityEnv);
982
+ if (baseCommit === null)
967
983
  return null;
968
- const result = spawnSync('git', ['--no-replace-objects', 'merge-base', 'HEAD', baseRef], {
984
+ const result = spawnSync('git', ['--no-replace-objects', 'merge-base', 'HEAD', baseCommit], {
969
985
  cwd: io.cwd,
970
- env: sanitizedAuthorityEnv(io.env),
986
+ env: authorityEnv,
971
987
  encoding: 'utf8',
972
988
  });
973
989
  const sha = (result.stdout ?? '').trim();
@@ -1087,7 +1103,7 @@ function verifyCarryForwardParent(input) {
1087
1103
  const treeId = receipt.candidateTreeId;
1088
1104
  if (input.gitDir === null ||
1089
1105
  treeId === null ||
1090
- !candidateTreeCoversCommit(input.gitDir, input.io.env, treeId, `${bound.sha}^{tree}`, input.docsExclusions, input.cacheExclusions)) {
1106
+ !candidateTreeCoversCommit(input.gitDir, input.io.env, treeId, `${bound.sha}^{tree}`, input.io.cwd, input.docsExclusions, input.cacheExclusions)) {
1091
1107
  return refuse(`its sealed tree is not the tree of commit ${shortSha(bound.sha)} (uncommitted changes were tested)`);
1092
1108
  }
1093
1109
  if (input.parentCommitBinding !== 'own-ancestor-commit' && receipt.gitSha !== input.baseSha) {
@@ -1231,7 +1247,7 @@ function verifyRunRecordParent(input) {
1231
1247
  const treeId = record.candidateTreeId;
1232
1248
  if (input.gitDir === null ||
1233
1249
  treeId === null ||
1234
- !candidateTreeCoversCommit(input.gitDir, input.io.env, treeId, `${bound.sha}^{tree}`, input.docsExclusions, input.cacheExclusions)) {
1250
+ !candidateTreeCoversCommit(input.gitDir, input.io.env, treeId, `${bound.sha}^{tree}`, input.io.cwd, input.docsExclusions, input.cacheExclusions)) {
1235
1251
  return refuse(`its sealed tree is not the tree of commit ${shortSha(bound.sha)} (uncommitted changes were tested)`);
1236
1252
  }
1237
1253
  if (input.parentCommitBinding !== 'own-ancestor-commit' && record.gitSha !== input.baseSha) {
@@ -1674,7 +1690,7 @@ function quarantinedInstanceKeys(catalog, quarantinedKeys) {
1674
1690
  for (const entry of catalog.entries) {
1675
1691
  if (!quarantinedKeys.has(entry.logicalKey))
1676
1692
  continue;
1677
- keys.add(`${entry.file}#${entry.titlePath.join('>')}`);
1693
+ keys.add(runnerLogicalKey(entry.file, entry.titlePath));
1678
1694
  }
1679
1695
  return keys;
1680
1696
  }
@@ -1766,7 +1782,7 @@ function plannedRowOfIdentity(test) {
1766
1782
  * @throws UsageError on a runner name with no adapter (the config
1767
1783
  * schema rejects unknown values first — this is a defensive seam).
1768
1784
  */
1769
- function runnerAdapterFor(runner, wiring = {}) {
1785
+ function runnerAdapterFor(runner, wiring = {}, adapterOptions = {}) {
1770
1786
  const witness = {
1771
1787
  ...(wiring.witnessUrl !== undefined && wiring.witnessUrl !== '' ? { url: wiring.witnessUrl } : {}),
1772
1788
  ...(wiring.runToken !== undefined && wiring.runToken !== '' ? { token: wiring.runToken } : {}),
@@ -1784,7 +1800,12 @@ function runnerAdapterFor(runner, wiring = {}) {
1784
1800
  case 'pytest':
1785
1801
  return new PytestRunnerAdapter({ witness, ...appBaseUrl });
1786
1802
  case 'vitest':
1787
- return new VitestRunnerAdapter({ witness: sessionWiring });
1803
+ return new VitestRunnerAdapter({
1804
+ witness: sessionWiring,
1805
+ ...(adapterOptions.enumerationTimeoutMs === undefined
1806
+ ? {}
1807
+ : { enumerationTimeoutMs: adapterOptions.enumerationTimeoutMs }),
1808
+ });
1788
1809
  case 'cypress':
1789
1810
  return new CypressRunnerAdapter({ witness: sessionWiring });
1790
1811
  default:
@@ -1877,6 +1898,9 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
1877
1898
  // RunnerAdapter contract behind the SAME witness session, run token,
1878
1899
  // supervision, receipts, and strictness machinery.
1879
1900
  const runnerName = config.runner;
1901
+ const vitestEnumerationTimeoutMs = config.witness.enumerationTimeoutSeconds !== undefined
1902
+ ? config.witness.enumerationTimeoutSeconds * 1000
1903
+ : undefined;
1880
1904
  // The timing-chaos plan for THIS run (E63). Null without the flag:
1881
1905
  // then the witness is spawned with no plan and every byte of the run
1882
1906
  // is exactly what it was before chaos existed. The bounds come from
@@ -2062,6 +2086,9 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
2062
2086
  cwd: io.cwd,
2063
2087
  config,
2064
2088
  collectPytest: true,
2089
+ ...(vitestEnumerationTimeoutMs === undefined
2090
+ ? {}
2091
+ : { vitestEnumerationTimeoutMs }),
2065
2092
  // The state directory this run ACTUALLY resolved (`--out` aware):
2066
2093
  // the supervised run's own generated config — and, for a
2067
2094
  // repository carrying one, an earlier build's freeze control files
@@ -2494,7 +2521,7 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
2494
2521
  // again. Nothing about the enumeration is assumed — an adapter that
2495
2522
  // cannot list its tests returns `status: 'unavailable'`, and that
2496
2523
  // plans nothing rather than planning a guessed half-set.
2497
- const enumeration = await runnerAdapterFor(runnerName).enumerate(io.cwd);
2524
+ const enumeration = await runnerAdapterFor(runnerName, {}, vitestEnumerationTimeoutMs === undefined ? {} : { enumerationTimeoutMs: vitestEnumerationTimeoutMs }).enumerate(io.cwd);
2498
2525
  runnerEnumeration = enumeration;
2499
2526
  if (enumeration.status === 'discovered') {
2500
2527
  const enumeratedRows = enumeration.tests.map(plannedRowOfIdentity);
@@ -2503,6 +2530,9 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
2503
2530
  options.scope === 'changed'
2504
2531
  ? enumeratedRows.filter((row) => affectedRequiredFiles.includes(row.planned.file))
2505
2532
  : enumeratedRows;
2533
+ if (catalog !== null && (runnerName === 'vitest' || runnerName === 'cypress')) {
2534
+ catalog = refreshCatalogAfterRunnerEnumeration(catalog, runnerName, enumeration, io.cwd);
2535
+ }
2506
2536
  }
2507
2537
  }
2508
2538
  // Named selection (`--test`): the plan is built from the FULL planned
@@ -2796,6 +2826,12 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
2796
2826
  },
2797
2827
  }),
2798
2828
  },
2829
+ ...(evaluated.httpCallAdvisories.length === 0
2830
+ ? {}
2831
+ : { advisories: [...evaluated.httpCallAdvisories] }),
2832
+ ...(evaluated.httpLedger === undefined ? {} : { httpLedger: evaluated.httpLedger }),
2833
+ ...(evaluated.uiLedger === undefined ? {} : { uiLedger: evaluated.uiLedger }),
2834
+ httpCoverage: evaluated.httpCoverage.summary,
2799
2835
  });
2800
2836
  writeLine(io.stdout, report);
2801
2837
  const gateCode = runExitCode({ verdicts: evaluated.verdicts, blocking: evaluated.blocking });
@@ -3197,6 +3233,11 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
3197
3233
  },
3198
3234
  }),
3199
3235
  },
3236
+ ...(evaluated.httpCallAdvisories.length === 0
3237
+ ? {}
3238
+ : { advisories: [...evaluated.httpCallAdvisories] }),
3239
+ ...(evaluated.httpLedger === undefined ? {} : { httpLedger: evaluated.httpLedger }),
3240
+ httpCoverage: evaluated.httpCoverage.summary,
3200
3241
  });
3201
3242
  writeLine(io.stdout, report);
3202
3243
  writeLine(io.stderr, 'test-gates: --scope changed produced no runnable slice — nothing was executed and no receipt was sealed');
@@ -3246,6 +3287,12 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
3246
3287
  const adapterBase = io.env['GATEFORGE_ADAPTER_BASE_URL'] !== undefined && io.env['GATEFORGE_ADAPTER_BASE_URL'] !== ''
3247
3288
  ? io.env['GATEFORGE_ADAPTER_BASE_URL']
3248
3289
  : targetBase;
3290
+ // The owner's DECLARED additional app origins (0.15.0), resolved
3291
+ // fail-closed from the trusted orchestrator environment. Each one
3292
+ // becomes an extra attested upstream with its own per-session
3293
+ // proxy; absent declaration = the variable is not passed at all and
3294
+ // the witness is byte-identical to every earlier one.
3295
+ const additionalAppOrigins = resolveAdditionalAppOrigins(config, io.env);
3249
3296
  spawnedWitness = await startWitnessProcess({
3250
3297
  GATEFORGE_RUN_ID: manifest.runId,
3251
3298
  GATEFORGE_RUN_TOKEN: runToken,
@@ -3258,6 +3305,9 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
3258
3305
  GATEFORGE_CLASSIFICATIONS: join(stateDir, 'classifications.json'),
3259
3306
  ...(targetBase !== '' ? { GATEFORGE_TARGET_BASE_URL: targetBase } : {}),
3260
3307
  ...(adapterBase !== '' ? { GATEFORGE_ADAPTER_BASE_URL: adapterBase } : {}),
3308
+ ...(additionalAppOrigins.length > 0
3309
+ ? { GATEFORGE_ADDITIONAL_APP_ORIGINS: JSON.stringify(additionalAppOrigins) }
3310
+ : {}),
3261
3311
  ...(io.env['GATEFORGE_TARGET_FINGERPRINT'] !== undefined && io.env['GATEFORGE_TARGET_FINGERPRINT'] !== ''
3262
3312
  ? { GATEFORGE_TARGET_FINGERPRINT: io.env['GATEFORGE_TARGET_FINGERPRINT'] }
3263
3313
  : {}),
@@ -3366,6 +3416,9 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
3366
3416
  },
3367
3417
  }
3368
3418
  : {}),
3419
+ ...(config.http.responseShape === 'off'
3420
+ ? {}
3421
+ : { responseShape: { openapiPath: config.http.openapiPath } }),
3369
3422
  };
3370
3423
  let appliedOptions = null;
3371
3424
  if (effectiveWitnessUrl !== undefined &&
@@ -3383,7 +3436,7 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
3383
3436
  // if it had. Say which, rather than reporting the fiction.
3384
3437
  if (chaosRun !== null && appliedOptions?.chaos == null) {
3385
3438
  if (spawnedWitness !== null)
3386
- await stopWitnessProcess(spawnedWitness);
3439
+ await stopWitnessProcess(io, spawnedWitness);
3387
3440
  throw new UsageError(`test-gates: --chaos ${String(chaosRun.seed)} needs a witness that accepts run options; the witness at ` +
3388
3441
  `'${effectiveWitnessUrl ?? ''}' confirmed no chaos plan, so no schedule was applied and this run would ` +
3389
3442
  'report a finding it never made — upgrade the witness');
@@ -3392,6 +3445,10 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
3392
3445
  writeLine(io.stderr, 'test-gates: twin path coverage needs a witness that accepts run options — this witness does not; ' +
3393
3446
  'pairs were not compared');
3394
3447
  }
3448
+ if (config.http.responseShape !== 'off' && appliedOptions?.responseShape == null) {
3449
+ writeLine(io.stderr, 'test-gates: http response-shape checks need a witness that accepts run options — this witness does not; ' +
3450
+ 'no exchange body was checked');
3451
+ }
3395
3452
  // A witness that perturbs timing on its OWN (its environment, never
3396
3453
  // this run's binding) can never serve a run that seals.
3397
3454
  if (chaosRun === null &&
@@ -3433,7 +3490,7 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
3433
3490
  // the suite's own account of execution — refuse it instead.
3434
3491
  if (effectiveWitnessUrl === undefined || witnessVerifierKey === undefined) {
3435
3492
  if (spawnedWitness !== null) {
3436
- await stopWitnessProcess(spawnedWitness);
3493
+ await stopWitnessProcess(io, spawnedWitness);
3437
3494
  }
3438
3495
  throw new UsageError(`test-gates --changed requires ${VERIFIER_KEY_ENV} or ${VERIFIER_KEY_FILE_ENV} in the orchestrating environment: ` +
3439
3496
  'the witness supervisor surface (expected set, session lifecycle, execution trace) is ' +
@@ -3600,7 +3657,7 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
3600
3657
  // a suite-controlled variable can disable observation but can never
3601
3658
  // enable false proof.
3602
3659
  if (pageObservation !== null) {
3603
- writeLine(io.stderr, 'PAGE_OBSERVATION_FIXTURE_REQUIRED: page records are issued only for tests using the Gateforge Playwright fixture; other tests produce no page-observation records.');
3660
+ writeLine(io.stderr, 'PAGE_OBSERVATION_ENABLED: page records are retained for passing tests with session-backed observation, including automatic Playwright sessions; uninstrumented tests produce no page-observation records.');
3604
3661
  const reportedTamperLocations = new Set();
3605
3662
  for (const risk of pageObservation.tamperRisks) {
3606
3663
  const key = `${risk.file}\u0000${risk.locationFile}\u0000${risk.line}`;
@@ -3688,7 +3745,7 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
3688
3745
  }
3689
3746
  catch (error) {
3690
3747
  if (spawnedWitness !== null)
3691
- await stopWitnessProcess(spawnedWitness);
3748
+ await stopWitnessProcess(io, spawnedWitness);
3692
3749
  throw new UsageError(`test-gates: the global native preparation freeze refuses this run — ${error.message}`);
3693
3750
  }
3694
3751
  }
@@ -3797,7 +3854,7 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
3797
3854
  }
3798
3855
  catch (error) {
3799
3856
  if (spawnedWitness !== null)
3800
- await stopWitnessProcess(spawnedWitness);
3857
+ await stopWitnessProcess(io, spawnedWitness);
3801
3858
  if (armedFreeze !== null)
3802
3859
  removeFreezeSpecDir(armedFreeze.control);
3803
3860
  throw error;
@@ -4038,7 +4095,7 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
4038
4095
  // completion signal — exactly as the progress stream below does.
4039
4096
  runActivity.onTestFinished?.(title);
4040
4097
  progress.endTest({
4041
- logicalKey: `${event.file ?? ''}#${event.titlePath.join('>')}`,
4098
+ logicalKey: runnerLogicalKey(event.file ?? '', event.titlePath),
4042
4099
  title,
4043
4100
  outcome: progressOutcomeOf(event.outcome),
4044
4101
  ...(event.errorMessage === undefined ? {} : { message: event.errorMessage }),
@@ -4057,6 +4114,10 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
4057
4114
  let sessionTrace = null;
4058
4115
  let lifecycleConflicts = [];
4059
4116
  let intentFailures = [];
4117
+ // The live attestation envelope (step 8 below) — fetched in the
4118
+ // `finally` while the spawned witness still serves, persisted as the
4119
+ // durable fallback, then the witness is stopped. `null` until then.
4120
+ let liveAttestation = null;
4060
4121
  // The FINAL control-spec verdict, decided in the `finally` below — at
4061
4122
  // the close of the supervised window, which is the last moment the
4062
4123
  // generated spec is read — and consumed below, after the run sealed.
@@ -4146,7 +4207,7 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
4146
4207
  witnessUrl: effectiveWitnessUrl,
4147
4208
  runToken,
4148
4209
  appBaseUrl: io.env['GATEFORGE_APP_BASE_URL'] ?? '',
4149
- }).execute(request);
4210
+ }, vitestEnumerationTimeoutMs === undefined ? {} : { enumerationTimeoutMs: vitestEnumerationTimeoutMs }).execute(request);
4150
4211
  }
4151
4212
  else {
4152
4213
  // The runner could not enumerate its expected set: nothing is
@@ -4371,11 +4432,26 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
4371
4432
  }
4372
4433
  }
4373
4434
  }
4374
- if (spawnedWitness !== null) {
4375
- // Graceful stop (the same contract as the consumer teardown): the
4376
- // witness appends its attested manifest envelope at shutdown, so
4377
- // the durable evidence channel is sealed before evaluation.
4378
- await stopWitnessProcess(spawnedWitness);
4435
+ // 8. Live attestation (same discipline as the legacy path). It is read
4436
+ // while the spawned witness still serves it: a stopped witness refuses
4437
+ // the read, so the stop below must come after it.
4438
+ // The stop sits in its own finally: a throwing read or persist must
4439
+ // still shut the spawned witness down, and the error still propagates.
4440
+ try {
4441
+ liveAttestation = await fetchWitnessAttestation(io, effectiveWitnessUrl, runToken, witnessVerifierKey, expectedDigest === null
4442
+ ? null
4443
+ : { runId: manifest.runId, invocationId, inputDigest: expectedDigest });
4444
+ if (liveAttestation !== null) {
4445
+ persistLiveAttestation(stateDir, liveAttestation);
4446
+ }
4447
+ }
4448
+ finally {
4449
+ if (spawnedWitness !== null) {
4450
+ // Graceful stop (the same contract as the consumer teardown): the
4451
+ // witness appends its attested manifest envelope at shutdown, so
4452
+ // the durable evidence channel is sealed before evaluation.
4453
+ await stopWitnessProcess(io, spawnedWitness);
4454
+ }
4379
4455
  }
4380
4456
  try {
4381
4457
  hostLoadCollector?.stop();
@@ -4482,7 +4558,7 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
4482
4558
  sessionTrace =
4483
4559
  sessionTrace === null
4484
4560
  ? null
4485
- : sessionTrace.filter((traced) => !ungradedKeys.has(`${traced.file}#${traced.titlePath.join('>')}`));
4561
+ : sessionTrace.filter((traced) => !ungradedKeys.has(runnerLogicalKey(traced.file, traced.titlePath)));
4486
4562
  }
4487
4563
  }
4488
4564
  if (options.runtimeReuseCheck !== undefined) {
@@ -4516,10 +4592,10 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
4516
4592
  ? rawOutcomesDoc
4517
4593
  : {
4518
4594
  ...rawOutcomesDoc,
4519
- outcomes: rawOutcomesDoc.outcomes.filter((row) => !unrequiredInstances.has(`${row.file}#${row.titlePath.join('>')}`)),
4595
+ outcomes: rawOutcomesDoc.outcomes.filter((row) => !unrequiredInstances.has(runnerLogicalKey(row.file, row.titlePath))),
4520
4596
  };
4521
4597
  if (sessionTrace !== null && unrequiredInstances.size > 0) {
4522
- sessionTrace = sessionTrace.filter((test) => !unrequiredInstances.has(`${test.file}#${test.titlePath.join('>')}`));
4598
+ sessionTrace = sessionTrace.filter((test) => !unrequiredInstances.has(runnerLogicalKey(test.file, test.titlePath)));
4523
4599
  }
4524
4600
  const sealed = sealExecutionResult({
4525
4601
  runId: manifest.runId,
@@ -4564,13 +4640,6 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
4564
4640
  changedInputs = true;
4565
4641
  }
4566
4642
  }
4567
- // 8. Live attestation (same discipline as the legacy path).
4568
- const liveAttestation = await fetchWitnessAttestation(io, effectiveWitnessUrl, runToken, witnessVerifierKey, expectedDigest === null
4569
- ? null
4570
- : { runId: manifest.runId, invocationId, inputDigest: expectedDigest });
4571
- if (liveAttestation !== null) {
4572
- persistLiveAttestation(stateDir, liveAttestation);
4573
- }
4574
4643
  // 9. Evaluate + project supervision/mapping/inventory/lifecycle findings
4575
4644
  // into blocking entries (never diff-scoped, never waived). Lifecycle
4576
4645
  // conflicts (duplicate begins, lone ends) are worker-side forgery or
@@ -4992,7 +5061,11 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
4992
5061
  }
4993
5062
  return 1;
4994
5063
  }
5064
+ if (envelope.startupDiagnostic !== undefined) {
5065
+ writeLine(io.stderr, envelope.incompleteDetail ?? 'RUNNER_STARTUP_FAILED');
5066
+ }
4995
5067
  const diagnosticContext = {
5068
+ ...(envelope.startupDiagnostic === undefined ? {} : { runnerStartup: envelope.startupDiagnostic }),
4996
5069
  scope: namedTestIds !== null ? 'named' : options.scope,
4997
5070
  candidateTreeId: testedTreeId,
4998
5071
  inputDigest: expectedDigest,
@@ -5043,7 +5116,9 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
5043
5116
  // Twin path coverage (E64): reported, never blocking, in advisory
5044
5117
  // mode. An empty list adds no report key, so a run without twin
5045
5118
  // findings keeps exactly the document it always had.
5046
- ...(runAdvisories.length === 0 ? {} : { advisories: runAdvisories }),
5119
+ ...([...evaluated.httpCallAdvisories, ...runAdvisories].length === 0
5120
+ ? {}
5121
+ : { advisories: [...evaluated.httpCallAdvisories, ...runAdvisories] }),
5047
5122
  waiverCounts: evaluated.waiverCounts,
5048
5123
  run: manifest,
5049
5124
  toolVersion: VERSION,
@@ -5062,6 +5137,9 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
5062
5137
  ? {}
5063
5138
  : { chaos: { ...chaosRun, ...(chaosSchedule === null ? {} : { schedule: chaosSchedule }) } }),
5064
5139
  ...(localFailures.length === 0 ? {} : { failedTests: localFailures }),
5140
+ ...(evaluated.httpLedger === undefined ? {} : { httpLedger: evaluated.httpLedger }),
5141
+ ...(evaluated.uiLedger === undefined ? {} : { uiLedger: evaluated.uiLedger }),
5142
+ httpCoverage: evaluated.httpCoverage.summary,
5065
5143
  });
5066
5144
  /**
5067
5145
  * The persisted json document: the same report shape stdout shows for a
@@ -5073,7 +5151,9 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
5073
5151
  ...JSON.parse(renderRun(evaluated.verdicts, {
5074
5152
  format: 'json',
5075
5153
  blocking: evaluated.blocking,
5076
- ...(runAdvisories.length === 0 ? {} : { advisories: runAdvisories }),
5154
+ ...([...evaluated.httpCallAdvisories, ...runAdvisories].length === 0
5155
+ ? {}
5156
+ : { advisories: [...evaluated.httpCallAdvisories, ...runAdvisories] }),
5077
5157
  waiverCounts: evaluated.waiverCounts,
5078
5158
  run: manifest,
5079
5159
  toolVersion: VERSION,
@@ -5087,6 +5167,9 @@ async function runSupervisedTestGatesInner(io, options, declaredRunnerEnvNames)
5087
5167
  ...(chaosRun === null
5088
5168
  ? {}
5089
5169
  : { chaos: { ...chaosRun, ...(chaosSchedule === null ? {} : { schedule: chaosSchedule }) } }),
5170
+ ...(evaluated.httpLedger === undefined ? {} : { httpLedger: evaluated.httpLedger }),
5171
+ ...(evaluated.uiLedger === undefined ? {} : { uiLedger: evaluated.uiLedger }),
5172
+ httpCoverage: evaluated.httpCoverage.summary,
5090
5173
  })),
5091
5174
  ...(gateMode === 'strict'
5092
5175
  ? {}
@@ -5615,6 +5698,8 @@ function runExecutionSummaryOf(input) {
5615
5698
  scope: input.scope,
5616
5699
  mode: input.mode,
5617
5700
  testsPerformedThisInvocation: input.mode === 'executed' ? performed : 0,
5701
+ executedTests: input.executionResult.executedTests ?? performed,
5702
+ measuredTests: input.executionResult.measuredTests ?? input.executionResult.sessionTrace?.filter((test) => test.sessions.length > 0).length ?? 0,
5618
5703
  selectedTests: {
5619
5704
  selected,
5620
5705
  passed,
@@ -5643,26 +5728,46 @@ const EMPTY_CATALOG = {
5643
5728
  inventoryComplete: false,
5644
5729
  runnerSummaries: [],
5645
5730
  };
5731
+ /**
5732
+ * The grace a spawned witness gets between SIGTERM and SIGKILL. The
5733
+ * witness's shutdown sequence is long by design — proxy listeners,
5734
+ * session proxies, page observers, fixture leases, queue channel,
5735
+ * engine browser, HTTP server — and the attested manifest envelope is
5736
+ * appended LAST, so the bound must cover that whole sequence. The wait
5737
+ * itself is on the EXIT event: a witness that shuts down in half a
5738
+ * second is reaped immediately, and only a genuinely hung shutdown
5739
+ * ever reaches the bound.
5740
+ */
5741
+ const WITNESS_STOP_GRACE_MS = 30_000;
5646
5742
  /**
5647
5743
  * Gracefully stops a witness this command spawned (the same contract as
5648
- * the consumer teardown): SIGTERM with a short grace period so the
5649
- * witness appends its attested manifest envelope, then SIGKILL.
5744
+ * the consumer teardown): SIGTERM, then wait for the process to EXIT so
5745
+ * the witness can run its whole shutdown sequence and append the
5746
+ * attested manifest envelope. If the bounded grace expires first, the
5747
+ * SIGKILL is a REPORTED failure on stderr — the envelope is then known
5748
+ * to be absent, and a missing durable attestation must be explainable,
5749
+ * never silent.
5650
5750
  *
5651
5751
  * Args:
5752
+ * io: output target for the reported-SIGKILL failure line.
5652
5753
  * handle: the spawned witness handle.
5653
5754
  */
5654
- async function stopWitnessProcess(handle) {
5755
+ export async function stopWitnessProcess(io, handle) {
5756
+ if (handle.child.exitCode !== null || handle.child.signalCode !== null)
5757
+ return;
5655
5758
  handle.child.kill('SIGTERM');
5656
- await new Promise((resolveWait) => {
5657
- const timer = setTimeout(() => {
5658
- handle.child.kill('SIGKILL');
5659
- resolveWait();
5660
- }, 2000);
5759
+ const exited = await new Promise((resolveWait) => {
5760
+ const timer = setTimeout(() => resolveWait(false), WITNESS_STOP_GRACE_MS);
5661
5761
  handle.child.once('exit', () => {
5662
5762
  clearTimeout(timer);
5663
- resolveWait();
5763
+ resolveWait(true);
5664
5764
  });
5665
5765
  });
5766
+ if (exited)
5767
+ return;
5768
+ handle.child.kill('SIGKILL');
5769
+ writeLine(io.stderr, `test-gates: the spawned witness did not exit within ${String(Math.round(WITNESS_STOP_GRACE_MS / 1000))}s of SIGTERM — ` +
5770
+ 'SIGKILL sent before it appended its manifest envelope, so this run has no durable attestation');
5666
5771
  }
5667
5772
  /**
5668
5773
  * Binds the trusted run context on a wired witness (plan §11.4):
@@ -5960,8 +6065,9 @@ async function fetchWitnessAttestation(io, witnessUrl, runToken, verifierKey, ex
5960
6065
  }
5961
6066
  return attestation;
5962
6067
  }
5963
- catch {
5964
- writeLine(io.stderr, 'test-gates: live attestation unavailable (transport)');
6068
+ catch (error) {
6069
+ const label = error instanceof SyntaxError ? 'parse' : 'transport';
6070
+ writeLine(io.stderr, `test-gates: live attestation unavailable (${label})`);
5965
6071
  return null;
5966
6072
  }
5967
6073
  finally {