@shapeshift-labs/frontier-lang-compiler 0.2.150 → 0.2.151
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +315 -9
- package/bench/real-repo-corpus-checkout-identity.mjs +134 -0
- package/bench/real-repo-corpus-checkout-proof.mjs +263 -0
- package/bench/real-repo-corpus-command-execution.mjs +314 -0
- package/bench/real-repo-corpus-evidence.mjs +165 -0
- package/bench/real-repo-corpus-suite.mjs +273 -0
- package/bench/smoke.mjs +109 -7
- package/dist/declarations/import-adapter-core.d.ts +4 -3
- package/dist/declarations/import-adapter-options-native.d.ts +21 -0
- package/dist/declarations/js-ts-project-merge-admission-routes.d.ts +35 -0
- package/dist/declarations/js-ts-project-merge-commonjs-interop.d.ts +29 -0
- package/dist/declarations/js-ts-project-merge-confidence.d.ts +64 -0
- package/dist/declarations/js-ts-project-merge-declaration-emit-parity.d.ts +37 -0
- package/dist/declarations/js-ts-project-merge-declarations.d.ts +65 -0
- package/dist/declarations/js-ts-project-merge-diagnostics.d.ts +97 -0
- package/dist/declarations/js-ts-project-merge-global-augmentation.d.ts +30 -0
- package/dist/declarations/js-ts-project-merge-jsx-render-branch.d.ts +48 -0
- package/dist/declarations/js-ts-project-merge-proof-levels.d.ts +109 -0
- package/dist/declarations/js-ts-project-merge-quality-gates.d.ts +38 -0
- package/dist/declarations/js-ts-project-merge-semantic-equivalence-proof.d.ts +45 -0
- package/dist/declarations/js-ts-project-merge-tsconfig.d.ts +43 -0
- package/dist/declarations/js-ts-safe-merge.d.ts +47 -0
- package/dist/declarations/js-ts-safe-project-merge.d.ts +120 -38
- package/dist/declarations/native-project-compiler-assignability-oracle.d.ts +41 -0
- package/dist/declarations/native-project-compiler-callable-signatures.d.ts +31 -0
- package/dist/declarations/native-project-compiler-class-member-runtime-proof.d.ts +87 -0
- package/dist/declarations/native-project-compiler-composite-types.d.ts +23 -0
- package/dist/declarations/native-project-compiler-enum-proof.d.ts +58 -0
- package/dist/declarations/native-project-compiler-index-signature.d.ts +7 -0
- package/dist/declarations/native-project-compiler-public-api-source-binding.d.ts +8 -0
- package/dist/declarations/native-project-compiler-scope.d.ts +37 -0
- package/dist/declarations/native-project-compiler-type-reference-targets.d.ts +38 -0
- package/dist/declarations/native-project-css-modules.d.ts +90 -0
- package/dist/declarations/native-project-decorator-metadata.d.ts +126 -0
- package/dist/declarations/native-project-jsx-graph.d.ts +313 -0
- package/dist/declarations/native-project-module-declarations.d.ts +52 -0
- package/dist/declarations/native-project-module-resolution.d.ts +76 -1
- package/dist/declarations/native-project-runtime-effect-target.d.ts +29 -0
- package/dist/declarations/native-project-runtime-executable-effect-evidence.d.ts +107 -0
- package/dist/declarations/native-project-runtime-mutation-target.d.ts +33 -0
- package/dist/declarations/native-project-runtime-promise-chain.d.ts +30 -0
- package/dist/declarations/native-project-runtime-promise-combinator.d.ts +22 -0
- package/dist/declarations/native-project-runtime-reachability.d.ts +30 -0
- package/dist/declarations/native-project-runtime-resource-management.d.ts +27 -0
- package/dist/declarations/native-project-runtime-yield-delegation.d.ts +10 -0
- package/dist/declarations/native-project-scope-template-reference.d.ts +13 -0
- package/dist/declarations/native-project-source-evidence.d.ts +8 -0
- package/dist/declarations/native-project.d.ts +40 -39
- package/dist/declarations/semantic-edit-script.d.ts +10 -8
- package/dist/declarations/semantic-graph-layers.d.ts +79 -0
- package/dist/declarations/semantic-sidecar.d.ts +3 -2
- package/dist/declarations/semantic-structural-diff.d.ts +94 -0
- package/dist/declarations/source-preservation.d.ts +32 -1
- package/dist/declarations/target-adapters.d.ts +22 -2
- package/dist/index.d.ts +31 -0
- package/dist/index.js +5 -0
- package/dist/internal/index-impl/compileNativeSource.js +53 -5
- package/dist/internal/index-impl/createLightweightNativeImport.js +58 -4
- package/dist/internal/index-impl/createNativeImportFromSyntaxAst.js +17 -1
- package/dist/internal/index-impl/createNativeImportFromTypeScriptAst.js +28 -4
- package/dist/internal/index-impl/createNativeProjectImportResult.js +31 -27
- package/dist/internal/index-impl/createNativeProjectModuleResolutionFromPackageManifests.js +145 -0
- package/dist/internal/index-impl/createNativeSourcePreservation.js +34 -7
- package/dist/internal/index-impl/createSemanticImportSidecar.js +27 -1
- package/dist/internal/index-impl/createTypeScriptCompilerNativeImporterAdapter.js +16 -5
- package/dist/internal/index-impl/dynamicImportExpressionMetadata.js +80 -0
- package/dist/internal/index-impl/importMetaUrlDependencyMetadata.js +176 -0
- package/dist/internal/index-impl/importNativeSource.js +2 -3
- package/dist/internal/index-impl/moduleImportAttributeMetadata.js +232 -0
- package/dist/internal/index-impl/projectSemanticEditScriptToSource.js +8 -1
- package/dist/internal/index-impl/projectSymbolGraphClassStaticBlocks.js +148 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerAdvancedTypeMetadata.js +45 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerCallableSignatureEquivalence.js +107 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerClassPrivateAccessorRuntimeProof.js +280 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerClassShapeEquivalence.js +103 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerConditionalTypeEquivalence.js +242 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerDecoratorRuntimeProof.js +197 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerEnumEquivalence.js +188 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerFacts.js +244 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerIndexSignatureEquivalence.js +58 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerMetadata.js +168 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerTypeEquivalence.js +199 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerTypeEquivalenceProof.js +204 -0
- package/dist/internal/index-impl/projectSymbolGraphCompilerTypeReferenceTargetEquivalence.js +99 -0
- package/dist/internal/index-impl/projectSymbolGraphCssModuleRecords.js +264 -0
- package/dist/internal/index-impl/projectSymbolGraphCssModuleScanners.js +242 -0
- package/dist/internal/index-impl/projectSymbolGraphCssModuleUtils.js +152 -0
- package/dist/internal/index-impl/projectSymbolGraphCssModules.js +82 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxComponentImports.js +170 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxComponentProviderLookup.js +167 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxComponentWrappers.js +150 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxContextTargets.js +71 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxContextValues.js +212 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxEventHandlers.js +172 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxHookEffects.js +124 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxHooks.js +281 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxMemberComponents.js +139 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxPropFlows.js +320 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxPropValues.js +145 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxProviderFlows.js +133 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxRecords.js +315 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxRenderCollections.js +155 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxRenderReturns.js +291 -0
- package/dist/internal/index-impl/projectSymbolGraphJsxRenderRisk.js +279 -0
- package/dist/internal/index-impl/projectSymbolGraphModuleDeclarationShapes.js +138 -0
- package/dist/internal/index-impl/projectSymbolGraphModuleResolution.js +89 -87
- package/dist/internal/index-impl/projectSymbolGraphPackageConditions.js +314 -0
- package/dist/internal/index-impl/projectSymbolGraphReExportImportTargets.js +43 -0
- package/dist/internal/index-impl/projectSymbolGraphReExports.js +55 -1
- package/dist/internal/index-impl/projectSymbolGraphRuntimeRegions.js +108 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefAliases.js +307 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefLexical.js +320 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefOwners.js +50 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefRecordBuilders.js +112 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefRecords.js +238 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefStructural.js +104 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefStructuralNormalize.js +242 -0
- package/dist/internal/index-impl/projectSymbolGraphScopeUseDefUseHashes.js +107 -0
- package/dist/internal/index-impl/projectSymbolGraphSourceMapGeneratedBoundary.js +111 -0
- package/dist/internal/index-impl/projectSymbolGraphSourceRecords.js +268 -0
- package/dist/internal/index-impl/projectSymbolGraphSourceRecordsOwnership.js +309 -0
- package/dist/internal/index-impl/replaySemanticEditProjection.js +53 -39
- package/dist/internal/index-impl/runtimeOrderEvidenceBinding.js +151 -0
- package/dist/internal/index-impl/runtimeOrderProofSurfaces.js +253 -0
- package/dist/internal/index-impl/semanticEditCallsiteArgumentMerge.js +319 -0
- package/dist/internal/index-impl/semanticEditExplicitSourceReplacement.js +7 -2
- package/dist/internal/index-impl/semanticEditProjectionRecord.js +8 -0
- package/dist/internal/index-impl/semanticEditReplayDiagnostics.js +7 -2
- package/dist/internal/index-impl/semanticEditReplayOutputBinding.js +61 -0
- package/dist/internal/index-impl/semanticEditReplayRerunRoute.js +27 -0
- package/dist/internal/index-impl/semanticEditReplaySourceReplacement.js +6 -1
- package/dist/internal/index-impl/semanticEditRuntimeOrderReasons.js +320 -0
- package/dist/internal/index-impl/semanticEditScriptClassification.js +90 -5
- package/dist/internal/index-impl/semanticEditScripts.js +42 -5
- package/dist/internal/index-impl/semanticEditTypeSyntaxReasons.js +134 -0
- package/dist/internal/index-impl/semanticIndexFromNativeDeclarations.js +11 -5
- package/dist/internal/index-impl/semanticStructuralDiffRecords.js +150 -0
- package/dist/internal/index-impl/sourceMapGeneratedBoundaryGate.js +185 -0
- package/dist/internal/index-impl/staticMemberLiteral.js +31 -0
- package/dist/internal/index-impl/staticOptionalMemberReference.js +22 -0
- package/dist/internal/index-impl/syntaxAstSourcePreservation.js +273 -0
- package/dist/internal/index-impl/syntaxCommonJsModuleDeclarationEntries.js +297 -0
- package/dist/internal/index-impl/syntaxModuleDeclarationEntries.js +56 -132
- package/dist/internal/index-impl/syntaxModuleEntryRecords.js +160 -0
- package/dist/internal/index-impl/typeScriptCompilerAdvancedTypeShapes.js +160 -0
- package/dist/internal/index-impl/typeScriptCompilerAssignabilityOracle.js +97 -0
- package/dist/internal/index-impl/typeScriptCompilerClassApi.js +238 -0
- package/dist/internal/index-impl/typeScriptCompilerDecoratorMetadata.js +290 -0
- package/dist/internal/index-impl/typeScriptCompilerEnumShape.js +279 -0
- package/dist/internal/index-impl/typeScriptCompilerFacts.js +294 -0
- package/dist/internal/index-impl/typeScriptCompilerInferenceSyntax.js +170 -0
- package/dist/internal/index-impl/typeScriptCompilerReferenceGraph.js +186 -0
- package/dist/internal/index-impl/typeScriptCompilerSymbolIdentity.js +294 -0
- package/dist/internal/index-impl/typeScriptCompilerTypeReferenceTargets.js +142 -0
- package/dist/internal/index-impl/typeScriptDeclaration.js +10 -38
- package/dist/internal/index-impl/typeScriptModuleDeclarationEntries.js +52 -15
- package/dist/internal/index-impl/typeScriptSourceFilePreservation.js +296 -0
- package/dist/js-ts-safe-member-class-invariants.js +247 -0
- package/dist/js-ts-safe-member-merge-result.js +23 -3
- package/dist/js-ts-safe-member-merge.js +28 -4
- package/dist/js-ts-safe-merge-binding-patterns.js +170 -0
- package/dist/js-ts-safe-merge-jsx-attribute-fallback.js +151 -157
- package/dist/js-ts-safe-merge-jsx-attribute-parser.js +277 -0
- package/dist/js-ts-safe-merge-jsx-child-expression-fallback.js +161 -0
- package/dist/js-ts-safe-merge-jsx-child-expression-merge.js +319 -0
- package/dist/js-ts-safe-merge-jsx-child-expression-parser.js +300 -0
- package/dist/js-ts-safe-merge-parse-declarations.js +46 -2
- package/dist/js-ts-safe-merge-parse-statements.js +8 -0
- package/dist/js-ts-safe-merge-semantic-edit-fallback.js +13 -5
- package/dist/js-ts-safe-merge-source-shape-fallbacks.js +3 -1
- package/dist/js-ts-safe-merge-top-level-rename-fallback.js +31 -5
- package/dist/js-ts-safe-merge-top-level-rename-result.js +7 -2
- package/dist/js-ts-safe-merge-variable-declarator-fallback.js +124 -6
- package/dist/js-ts-safe-merge-variable-declarator-parser.js +34 -4
- package/dist/js-ts-safe-merge.js +136 -0
- package/dist/js-ts-safe-project-merge-admission-routes.js +216 -0
- package/dist/js-ts-safe-project-merge-admission.js +161 -0
- package/dist/js-ts-safe-project-merge-ambient.js +110 -0
- package/dist/js-ts-safe-project-merge-core.js +85 -0
- package/dist/js-ts-safe-project-merge-css-module-conflicts.js +60 -0
- package/dist/js-ts-safe-project-merge-declaration-emit-parity.js +186 -0
- package/dist/js-ts-safe-project-merge-declarations.js +227 -0
- package/dist/js-ts-safe-project-merge-diagnostics-metadata.js +42 -0
- package/dist/js-ts-safe-project-merge-diagnostics-ts.js +73 -0
- package/dist/js-ts-safe-project-merge-diagnostics.js +283 -0
- package/dist/js-ts-safe-project-merge-evidence-routing.js +38 -0
- package/dist/js-ts-safe-project-merge-files.js +70 -0
- package/dist/js-ts-safe-project-merge-global-augmentation-compatibility.js +99 -0
- package/dist/js-ts-safe-project-merge-graph-conflicts.js +90 -2
- package/dist/js-ts-safe-project-merge-graph-delta-commonjs-interop.js +108 -0
- package/dist/js-ts-safe-project-merge-graph-delta-compiler-conflicts.js +179 -0
- package/dist/js-ts-safe-project-merge-graph-delta-compiler-details.js +189 -0
- package/dist/js-ts-safe-project-merge-graph-delta-conflicts.js +51 -184
- package/dist/js-ts-safe-project-merge-graph-delta-identity-conflicts.js +202 -0
- package/dist/js-ts-safe-project-merge-graph-delta-inference-syntax.js +80 -0
- package/dist/js-ts-safe-project-merge-graph-delta-module-declarations.js +155 -0
- package/dist/js-ts-safe-project-merge-graph-limits.js +16 -1
- package/dist/js-ts-safe-project-merge-graph.js +37 -5
- package/dist/js-ts-safe-project-merge-import-removal.js +292 -0
- package/dist/js-ts-safe-project-merge-jsx-graph-conflict-details.js +235 -0
- package/dist/js-ts-safe-project-merge-jsx-graph-conflicts.js +173 -0
- package/dist/js-ts-safe-project-merge-jsx-prop-contracts.js +86 -0
- package/dist/js-ts-safe-project-merge-jsx-render-branch-proof.js +189 -0
- package/dist/js-ts-safe-project-merge-missing-evidence.js +310 -0
- package/dist/js-ts-safe-project-merge-move-rename.js +209 -0
- package/dist/js-ts-safe-project-merge-proof-conflicts.js +44 -0
- package/dist/js-ts-safe-project-merge-proof-levels.js +320 -0
- package/dist/js-ts-safe-project-merge-quality-gates.js +140 -0
- package/dist/js-ts-safe-project-merge-routing-calibration.js +125 -0
- package/dist/js-ts-safe-project-merge-runtime-region-conflicts.js +156 -0
- package/dist/js-ts-safe-project-merge-scope-use-def-conflicts.js +292 -0
- package/dist/js-ts-safe-project-merge-semantic-equivalence-proof.js +175 -0
- package/dist/js-ts-safe-project-merge-semantic-replay-proof.js +311 -0
- package/dist/js-ts-safe-project-merge-semantic-replay-routes.js +179 -0
- package/dist/js-ts-safe-project-merge-source-span-conflicts.js +310 -0
- package/dist/js-ts-safe-project-merge-source-span-roundtrip-proof.js +172 -0
- package/dist/js-ts-safe-project-merge-split-merge-admission.js +96 -0
- package/dist/js-ts-safe-project-merge-split-merge-records.js +320 -0
- package/dist/js-ts-safe-project-merge-split-merge-shapes.js +234 -0
- package/dist/js-ts-safe-project-merge-split-merge.js +218 -0
- package/dist/js-ts-safe-project-merge-summary.js +320 -0
- package/dist/js-ts-safe-project-merge-symbol-move-admission.js +63 -0
- package/dist/js-ts-safe-project-merge-symbol-move-default-admission.js +143 -0
- package/dist/js-ts-safe-project-merge-symbol-move-risks.js +213 -0
- package/dist/js-ts-safe-project-merge-symbol-move.js +316 -0
- package/dist/js-ts-safe-project-merge-symbol-rename-admission.js +59 -0
- package/dist/js-ts-safe-project-merge-symbol-rename-default-admission.js +111 -0
- package/dist/js-ts-safe-project-merge-symbol-rename.js +319 -0
- package/dist/js-ts-safe-project-merge-ts-options.js +205 -0
- package/dist/js-ts-safe-project-merge-ts-program.js +268 -0
- package/dist/js-ts-safe-project-merge-typed-property-rename-rebase-utils.js +69 -0
- package/dist/js-ts-safe-project-merge-typed-property-rename-rebase.js +317 -0
- package/dist/js-ts-safe-project-merge-unsupported-surfaces.js +319 -0
- package/dist/js-ts-safe-project-merge.js +170 -171
- package/dist/js-ts-semantic-scope-use-def-bindings.js +287 -0
- package/dist/js-ts-semantic-scope-use-def-scan.js +241 -0
- package/dist/js-ts-semantic-scope-use-def-utils.js +132 -0
- package/dist/js-ts-semantic-scope-use-def.js +217 -0
- package/dist/lightweight-dependency-effects.js +28 -4
- package/dist/lightweight-dependency-relations.js +13 -7
- package/dist/lightweight-dependency-top-level.js +63 -0
- package/dist/native-import-language-profiles.js +27 -1
- package/dist/native-js-ts-importers.js +9 -5
- package/dist/native-parser-ast-format-profiles.js +12 -0
- package/dist/native-parser-html-css-format-profiles.js +85 -0
- package/dist/native-region-scanner-core.js +5 -3
- package/dist/native-region-scanner-js-commonjs.js +155 -0
- package/dist/native-region-scanner-js-imports.js +51 -13
- package/dist/native-region-scanner-js-reexports.js +79 -0
- package/dist/native-region-scanner-js-ts-helpers.js +23 -0
- package/dist/native-source-ledger-helpers.js +1 -1
- package/dist/native-source-ledger.js +24 -10
- package/dist/native-source-maps-ecma426.js +316 -0
- package/dist/native-source-maps.js +36 -6
- package/dist/native-source-preservation-ownership.js +292 -0
- package/dist/native-source-preservation-scanner.js +63 -25
- package/dist/native-source-preservation-types.d.ts +3 -0
- package/dist/semantic-import-effect-occurrences.js +242 -0
- package/dist/semantic-import-effect-regions.js +95 -58
- package/dist/semantic-import-graph-layers.js +224 -0
- package/dist/semantic-import-runtime-conditional-evidence.js +135 -0
- package/dist/semantic-import-runtime-effect-target-evidence.js +145 -0
- package/dist/semantic-import-runtime-exit-evidence.js +32 -0
- package/dist/semantic-import-runtime-import-meta-evidence.js +33 -0
- package/dist/semantic-import-runtime-mutation-evidence.js +155 -0
- package/dist/semantic-import-runtime-order-evidence.js +318 -0
- package/dist/semantic-import-runtime-promise-chain-evidence.js +103 -0
- package/dist/semantic-import-runtime-promise-combinator-evidence.js +166 -0
- package/dist/semantic-import-runtime-reachability-evidence.js +269 -0
- package/dist/semantic-import-runtime-resource-management-evidence.js +293 -0
- package/dist/semantic-import-runtime-switch-evidence.js +304 -0
- package/dist/semantic-import-runtime-throw-evidence.js +44 -0
- package/dist/semantic-import-runtime-try-finally-evidence.js +172 -0
- package/dist/semantic-import-sidecar-entry.js +4 -0
- package/dist/semantic-import-source-preservation.js +6 -2
- package/package.json +1 -1
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { readdirSync, statSync } from 'node:fs';
|
|
2
|
+
import { isAbsolute, relative, resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { collectCheckoutIdentityMetadata } from './real-repo-corpus-checkout-identity.mjs';
|
|
5
|
+
|
|
6
|
+
const defaultCheckoutRootEnv = 'FRONTIER_REAL_REPO_CORPUS_ROOT';
|
|
7
|
+
const maxMatchedFilesPerEntry = 64;
|
|
8
|
+
const maxScannedFilesPerGlob = 2_000;
|
|
9
|
+
|
|
10
|
+
function collectExternalCheckoutProofs(manifest, entries) {
|
|
11
|
+
const root = checkoutProofRoot(manifest);
|
|
12
|
+
const rootPresent = root.path ? isDirectory(root.path) : false;
|
|
13
|
+
const packageManagerMatrix = manifest.localBehavior?.packageManagerMatrix ?? [];
|
|
14
|
+
const commandMatrix = summarizePackageManagerCommandMatrix(packageManagerMatrix);
|
|
15
|
+
const rows = entries.map((entry) => collectExternalCheckoutProof(entry, root.path, rootPresent, packageManagerMatrix, commandMatrix));
|
|
16
|
+
const statuses = new Set(rows.map((row) => row.status));
|
|
17
|
+
return {
|
|
18
|
+
rootMode: root.mode,
|
|
19
|
+
rootPath: root.path,
|
|
20
|
+
rootPresent,
|
|
21
|
+
rows,
|
|
22
|
+
statuses,
|
|
23
|
+
proofSkipped: rows.filter((row) => row.checkoutProofExecution === 'skipped').length,
|
|
24
|
+
proofExecuted: rows.filter((row) => row.checkoutProofExecution === 'executed').length,
|
|
25
|
+
skipped: rows.filter((row) => row.status === 'skipped-missing-checkout').length,
|
|
26
|
+
checkedOut: rows.filter((row) => row.status.startsWith('checked-out')).length,
|
|
27
|
+
noProofMatch: rows.filter((row) => row.status === 'checked-out-no-proof-match').length,
|
|
28
|
+
proofMatchedEntries: rows.filter((row) => row.status === 'checked-out').length,
|
|
29
|
+
matchedFiles: rows.reduce((sum, row) => sum + row.matchedFiles, 0),
|
|
30
|
+
maxBytesPerFile: rows.reduce((max, row) => Math.max(max, row.maxObservedBytesPerFile), 0),
|
|
31
|
+
identitySkipped: rows.filter((row) => row.checkoutIdentityExecution === 'skipped').length,
|
|
32
|
+
identityExecuted: rows.filter((row) => row.checkoutIdentityExecution === 'executed').length,
|
|
33
|
+
identityMetadataPresent: rows.filter((row) => row.gitMetadataPresent === true).length,
|
|
34
|
+
identityMatched: rows.filter((row) => row.checkoutIdentityStatus === 'git-identity-matched').length,
|
|
35
|
+
identityRemoteMatched: rows.filter((row) => row.gitRemoteOriginMatchesManifest === true).length,
|
|
36
|
+
identityRefMatched: rows.filter((row) => row.gitRefMatchesManifest === true).length
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function checkoutProofRoot(manifest) {
|
|
41
|
+
const envName = manifest.localBehavior?.checkoutProof?.rootEnv ?? defaultCheckoutRootEnv;
|
|
42
|
+
const envRoot = process.env[envName];
|
|
43
|
+
if (envRoot) return { mode: 'env-override', path: resolve(envRoot) };
|
|
44
|
+
if (typeof manifest.fetchRoot !== 'string') return { mode: 'missing-fetch-root', path: null };
|
|
45
|
+
return { mode: 'manifest-fetch-root', path: fileURLToPath(new URL(`../${manifest.fetchRoot}`, import.meta.url)) };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function collectExternalCheckoutProof(entry, rootPath, rootPresent, packageManagerMatrix, commandMatrix) {
|
|
49
|
+
const missingPresence = missingCheckoutPresence(rootPath, rootPresent, entry);
|
|
50
|
+
const baseRow = {
|
|
51
|
+
entryId: entry.id,
|
|
52
|
+
checkoutDir: entry.checkoutDir ?? null,
|
|
53
|
+
checkoutRootPresent: rootPresent,
|
|
54
|
+
checkoutDirPresent: false,
|
|
55
|
+
checkoutPresenceStatus: missingPresence.status,
|
|
56
|
+
checkoutProofReason: missingPresence.reason,
|
|
57
|
+
plannedSampleFiles: entry.metrics?.sampleFiles ?? 0,
|
|
58
|
+
proofGlobs: entry.pathGlobs?.length ?? 0,
|
|
59
|
+
matchedFiles: 0,
|
|
60
|
+
maxObservedBytesPerFile: 0,
|
|
61
|
+
packageManagerLockFilesPresent: 0,
|
|
62
|
+
packageManagerLockFiles: [],
|
|
63
|
+
packageManagersPresent: [],
|
|
64
|
+
packageManagerCommandMatrixStatus: commandMatrix.status,
|
|
65
|
+
packageManagerCommandMatrixCommands: commandMatrix.commands,
|
|
66
|
+
packageManagerInstallCommands: commandMatrix.installCommands,
|
|
67
|
+
packageManagerBuildCommands: commandMatrix.buildCommands,
|
|
68
|
+
packageManagerTestCommands: commandMatrix.testCommands,
|
|
69
|
+
checkoutIdentityStatus: 'skipped-missing-checkout',
|
|
70
|
+
checkoutIdentityExecution: 'skipped',
|
|
71
|
+
gitMetadataPresent: false,
|
|
72
|
+
gitMetadataKind: 'not-scanned',
|
|
73
|
+
gitDirPointerPresent: false,
|
|
74
|
+
gitHeadPresent: false,
|
|
75
|
+
gitConfigPresent: false,
|
|
76
|
+
gitRemoteOriginUrlPresent: false,
|
|
77
|
+
gitRemoteOriginMatchesManifest: null,
|
|
78
|
+
gitRefMatchesManifest: null
|
|
79
|
+
};
|
|
80
|
+
if (!rootPath || !rootPresent || !entry.checkoutDir) return withCheckoutProofStatus(baseRow, 'skipped-missing-checkout');
|
|
81
|
+
const checkoutPath = resolveInside(rootPath, entry.checkoutDir);
|
|
82
|
+
if (!checkoutPath || !isDirectory(checkoutPath)) return withCheckoutProofStatus(baseRow, 'skipped-missing-checkout');
|
|
83
|
+
|
|
84
|
+
const matched = collectMatchingFileStats(checkoutPath, entry.pathGlobs ?? []);
|
|
85
|
+
const packageManagers = collectPackageManagerMetadata(checkoutPath, packageManagerMatrix);
|
|
86
|
+
const identity = collectCheckoutIdentityMetadata(checkoutPath, entry);
|
|
87
|
+
const hasProofMatch = matched.matchedFiles > 0;
|
|
88
|
+
return withCheckoutProofStatus({
|
|
89
|
+
...baseRow,
|
|
90
|
+
checkoutDirPresent: true,
|
|
91
|
+
checkoutPresenceStatus: 'checkout-dir-present',
|
|
92
|
+
checkoutProofReason: hasProofMatch ? 'declared-proof-globs-matched' : 'declared-proof-globs-missing',
|
|
93
|
+
matchedFiles: matched.matchedFiles,
|
|
94
|
+
maxObservedBytesPerFile: matched.maxObservedBytesPerFile,
|
|
95
|
+
packageManagerLockFilesPresent: packageManagers.lockFiles.length,
|
|
96
|
+
packageManagerLockFiles: packageManagers.lockFiles,
|
|
97
|
+
packageManagersPresent: packageManagers.managers,
|
|
98
|
+
...identity
|
|
99
|
+
}, hasProofMatch ? 'checked-out' : 'checked-out-no-proof-match');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function missingCheckoutPresence(rootPath, rootPresent, entry) {
|
|
103
|
+
if (!rootPath) return { status: 'checkout-root-unconfigured', reason: 'checkout-root-unconfigured' };
|
|
104
|
+
if (!rootPresent) return { status: 'checkout-root-missing', reason: 'checkout-root-missing' };
|
|
105
|
+
if (!entry.checkoutDir) return { status: 'checkout-dir-not-declared', reason: 'checkout-dir-not-declared' };
|
|
106
|
+
return { status: 'checkout-dir-missing', reason: 'checkout-dir-missing' };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function summarizePackageManagerCommandMatrix(matrix = []) {
|
|
110
|
+
const summary = {
|
|
111
|
+
status: matrix.length > 0 && matrix.every((row) => row.status === 'metadata-only') ? 'metadata-only' : 'unknown',
|
|
112
|
+
commands: 0,
|
|
113
|
+
installCommands: 0,
|
|
114
|
+
buildCommands: 0,
|
|
115
|
+
testCommands: 0
|
|
116
|
+
};
|
|
117
|
+
for (const row of matrix) {
|
|
118
|
+
for (const command of row.commands ?? []) {
|
|
119
|
+
summary.commands += 1;
|
|
120
|
+
if (/\b(ci|install)\b/.test(command)) summary.installCommands += 1;
|
|
121
|
+
if (/\bbuild\b/.test(command)) summary.buildCommands += 1;
|
|
122
|
+
if (/\btest\b/.test(command)) summary.testCommands += 1;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return summary;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function collectPackageManagerMetadata(checkoutPath, matrix = []) {
|
|
129
|
+
const lockFiles = [];
|
|
130
|
+
const managers = [];
|
|
131
|
+
for (const row of matrix) {
|
|
132
|
+
const present = (row.lockFiles ?? []).filter((lockFile) => {
|
|
133
|
+
const filePath = resolveInside(checkoutPath, lockFile);
|
|
134
|
+
if (!filePath) return false;
|
|
135
|
+
try { return statSync(filePath).isFile(); } catch { return false; }
|
|
136
|
+
});
|
|
137
|
+
if (!present.length) continue;
|
|
138
|
+
managers.push(row.manager);
|
|
139
|
+
for (const lockFile of present) lockFiles.push(lockFile);
|
|
140
|
+
}
|
|
141
|
+
return { lockFiles, managers };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function withCheckoutProofStatus(row, status) {
|
|
145
|
+
return {
|
|
146
|
+
...row,
|
|
147
|
+
status,
|
|
148
|
+
checkoutProofExecution: status === 'skipped-missing-checkout' ? 'skipped' : 'executed'
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function collectMatchingFileStats(checkoutPath, globs) {
|
|
153
|
+
const matches = new Map();
|
|
154
|
+
for (const glob of globs) {
|
|
155
|
+
if (!hasGlobMagic(glob)) {
|
|
156
|
+
const filePath = resolveInside(checkoutPath, glob);
|
|
157
|
+
addMatchedFile(matches, filePath, checkoutPath);
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
const prefix = staticPrefixForGlob(glob);
|
|
161
|
+
const scanRoot = resolveInside(checkoutPath, prefix);
|
|
162
|
+
if (!scanRoot || !isDirectory(scanRoot)) continue;
|
|
163
|
+
const regex = globToRegExp(toPosix(glob));
|
|
164
|
+
let scannedFiles = 0;
|
|
165
|
+
scanFiles(scanRoot, checkoutPath, (relativePath, filePath) => {
|
|
166
|
+
if (scannedFiles >= maxScannedFilesPerGlob || matches.size >= maxMatchedFilesPerEntry) return false;
|
|
167
|
+
scannedFiles += 1;
|
|
168
|
+
if (regex.test(relativePath)) addMatchedFile(matches, filePath, checkoutPath);
|
|
169
|
+
return true;
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
matchedFiles: matches.size,
|
|
174
|
+
maxObservedBytesPerFile: [...matches.values()].reduce((max, size) => Math.max(max, size), 0)
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function addMatchedFile(matches, filePath, rootPath) {
|
|
179
|
+
if (!filePath || matches.size >= maxMatchedFilesPerEntry) return;
|
|
180
|
+
try {
|
|
181
|
+
const stat = statSync(filePath);
|
|
182
|
+
if (stat.isFile()) matches.set(toPosix(relative(rootPath, filePath)), stat.size);
|
|
183
|
+
} catch {
|
|
184
|
+
// Local external checkouts are optional; races while scanning remain non-fatal.
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function scanFiles(dirPath, rootPath, visit) {
|
|
189
|
+
let entries;
|
|
190
|
+
try {
|
|
191
|
+
entries = readdirSync(dirPath, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name));
|
|
192
|
+
} catch {
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
for (const entry of entries) {
|
|
196
|
+
const childPath = resolve(dirPath, entry.name);
|
|
197
|
+
if (entry.isDirectory()) {
|
|
198
|
+
if (scanFiles(childPath, rootPath, visit) === false) return false;
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
if (entry.isFile() && visit(toPosix(relative(rootPath, childPath)), childPath) === false) return false;
|
|
202
|
+
}
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function staticPrefixForGlob(glob) {
|
|
207
|
+
const prefix = [];
|
|
208
|
+
for (const part of toPosix(glob).split('/')) {
|
|
209
|
+
if (hasGlobMagic(part)) break;
|
|
210
|
+
prefix.push(part);
|
|
211
|
+
}
|
|
212
|
+
return prefix.join('/');
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function globToRegExp(glob) {
|
|
216
|
+
let source = '^';
|
|
217
|
+
for (let index = 0; index < glob.length;) {
|
|
218
|
+
const char = glob[index];
|
|
219
|
+
if (char === '*' && glob[index + 1] === '*') {
|
|
220
|
+
source += glob[index + 2] === '/' ? '(?:[^/]+/)*' : '.*';
|
|
221
|
+
index += glob[index + 2] === '/' ? 3 : 2;
|
|
222
|
+
} else if (char === '*') {
|
|
223
|
+
source += '[^/]*';
|
|
224
|
+
index += 1;
|
|
225
|
+
} else if (char === '?') {
|
|
226
|
+
source += '[^/]';
|
|
227
|
+
index += 1;
|
|
228
|
+
} else {
|
|
229
|
+
source += escapeRegExp(char);
|
|
230
|
+
index += 1;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return new RegExp(`${source}$`);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function hasGlobMagic(value) {
|
|
237
|
+
return /[*?]/.test(value);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function resolveInside(rootPath, requestedPath) {
|
|
241
|
+
const targetPath = resolve(rootPath, requestedPath);
|
|
242
|
+
const relativePath = relative(rootPath, targetPath);
|
|
243
|
+
if (relativePath === '' || (!relativePath.startsWith('..') && !isAbsolute(relativePath))) return targetPath;
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function isDirectory(path) {
|
|
248
|
+
try {
|
|
249
|
+
return statSync(path).isDirectory();
|
|
250
|
+
} catch {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function toPosix(path) {
|
|
256
|
+
return path.replaceAll('\\', '/');
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function escapeRegExp(value) {
|
|
260
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export { collectExternalCheckoutProofs };
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { existsSync, realpathSync, statSync } from 'node:fs';
|
|
4
|
+
import { isAbsolute, relative, resolve } from 'node:path';
|
|
5
|
+
|
|
6
|
+
const defaultPhases = ['dependency-install', 'build', 'test'];
|
|
7
|
+
const defaultTimeoutMs = 15_000;
|
|
8
|
+
const defaultMaxOutputBytes = 4_096;
|
|
9
|
+
const safeEnvKeys = new Set(['PATH', 'HOME', 'USER', 'TMPDIR', 'TEMP', 'TMP']);
|
|
10
|
+
const shellMetacharacters = /[;&|<>$`(){}[\]*?!~"'\\\n\r]/;
|
|
11
|
+
|
|
12
|
+
function collectRealRepoCommandExecution(manifest, checkoutProof, options = {}) {
|
|
13
|
+
const phases = normalizePhases(options.phases);
|
|
14
|
+
const enabled = options.enabled === true;
|
|
15
|
+
const selectedEntryIds = Array.isArray(options.entryIds) ? new Set(options.entryIds) : null;
|
|
16
|
+
const matrixByManager = new Map((manifest.localBehavior?.packageManagerMatrix ?? []).map((row) => [row.manager, row]));
|
|
17
|
+
const rows = (checkoutProof.rows ?? []).map((row) => {
|
|
18
|
+
if (!enabled || (selectedEntryIds && !selectedEntryIds.has(row.entryId))) {
|
|
19
|
+
return createDefaultOffRow(row, phases, 'real-repo-command-opt-in-missing');
|
|
20
|
+
}
|
|
21
|
+
return collectCommandExecutionForRow(row, phases, matrixByManager, checkoutProof, options);
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
enabled,
|
|
25
|
+
rows,
|
|
26
|
+
commandRunRows: rows.length,
|
|
27
|
+
commandRunEnabledRows: rows.filter((row) => row.commandRunEnabled).length,
|
|
28
|
+
commandRunDefaultOffRows: rows.filter((row) => row.commandRunExecutionStatus === 'not-run-default-network-free').length,
|
|
29
|
+
commandRunOptInRequiredRows: rows.filter((row) => row.commandRunStatus === 'blocked-opt-in-required').length,
|
|
30
|
+
commandRunSkippedRows: rows.filter((row) => row.commandRunStatus === 'skipped-missing-checkout').length,
|
|
31
|
+
commandRunBlockedRows: rows.filter((row) => row.commandRunStatus.startsWith('blocked-')).length,
|
|
32
|
+
commandRunExecutedPhases: countPhases(rows, 'executed'),
|
|
33
|
+
commandRunFailedPhases: countPhases(rows, 'failed'),
|
|
34
|
+
commandRunTimedOutPhases: countPhases(rows, 'timed-out'),
|
|
35
|
+
commandRunSkippedPhases: rows.reduce((sum, row) => sum + row.commandRunPhases.filter((phase) => phase.executionStatus.startsWith('skipped-')).length, 0),
|
|
36
|
+
commandRunDefaultOffPhases: rows.reduce((sum, row) => sum + row.commandRunPhases.filter((phase) => phase.defaultExecution === 'not-run-default-network-free').length, 0),
|
|
37
|
+
commandRunOutputTruncatedPhases: rows.reduce((sum, row) => sum + row.commandRunPhases.filter((phase) => phase.stdoutTruncated || phase.stderrTruncated).length, 0)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function collectCommandExecutionForRow(row, phases, matrixByManager, checkoutProof, options) {
|
|
42
|
+
const safety = commandExecutionSafety(row, checkoutProof);
|
|
43
|
+
if (safety.status !== 'ready') return createBlockedRow(row, phases, safety.status, safety.reason);
|
|
44
|
+
|
|
45
|
+
const packageManager = packageManagerForRow(row);
|
|
46
|
+
if (packageManager.status !== 'ready') return createBlockedRow(row, phases, packageManager.status, packageManager.reason);
|
|
47
|
+
|
|
48
|
+
const commandSpecs = commandSpecsForManager(matrixByManager.get(packageManager.manager));
|
|
49
|
+
if (!commandSpecs) return createBlockedRow(row, phases, 'blocked-command-not-allowed', 'real-repo-command-package-manager-unsupported');
|
|
50
|
+
|
|
51
|
+
const commandRunPhases = phases.map((phase) => {
|
|
52
|
+
const spec = commandSpecs.get(phase);
|
|
53
|
+
if (!spec) return createPhase(phase, 'blocked-command-not-allowed', 'real-repo-command-phase-not-allowed');
|
|
54
|
+
if (phase === 'dependency-install' && options.allowDependencyInstall !== true) {
|
|
55
|
+
return createPhase(phase, 'blocked-opt-in-required', 'real-repo-command-network-opt-in-missing', spec);
|
|
56
|
+
}
|
|
57
|
+
return runCommandPhase(phase, spec, safety.checkoutPath, options);
|
|
58
|
+
});
|
|
59
|
+
return createRunRow(row, commandRunPhases, true);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function commandExecutionSafety(row, checkoutProof) {
|
|
63
|
+
if (row.status === 'skipped-missing-checkout') {
|
|
64
|
+
return { status: 'skipped-missing-checkout', reason: 'real-repo-command-checkout-dir-missing' };
|
|
65
|
+
}
|
|
66
|
+
if (row.status !== 'checked-out') {
|
|
67
|
+
return { status: 'blocked-safety-invariant', reason: 'real-repo-command-proof-globs-missing' };
|
|
68
|
+
}
|
|
69
|
+
if (!checkoutProof.rootPath) {
|
|
70
|
+
return { status: 'blocked-safety-invariant', reason: 'real-repo-command-checkout-root-unconfigured' };
|
|
71
|
+
}
|
|
72
|
+
if (!existsSync(checkoutProof.rootPath)) {
|
|
73
|
+
return { status: 'blocked-safety-invariant', reason: 'real-repo-command-checkout-root-missing' };
|
|
74
|
+
}
|
|
75
|
+
if (!row.checkoutDir) {
|
|
76
|
+
return { status: 'blocked-safety-invariant', reason: 'real-repo-command-checkout-dir-not-declared' };
|
|
77
|
+
}
|
|
78
|
+
const contained = realContainedPath(checkoutProof.rootPath, row.checkoutDir);
|
|
79
|
+
if (contained.reason) return { status: 'blocked-safety-invariant', reason: contained.reason };
|
|
80
|
+
const identity = identitySafety(row);
|
|
81
|
+
if (identity.reason) return identity;
|
|
82
|
+
return { status: 'ready', reason: 'real-repo-command-ready-local-checkout', checkoutPath: contained.path };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function identitySafety(row) {
|
|
86
|
+
if (row.gitDirPointerPresent === true) {
|
|
87
|
+
return { status: 'blocked-safety-invariant', reason: 'real-repo-command-gitdir-pointer-unverified' };
|
|
88
|
+
}
|
|
89
|
+
if (row.checkoutIdentityStatus === 'git-identity-matched') return {};
|
|
90
|
+
if (!row.gitMetadataPresent) return { status: 'blocked-identity-mismatch', reason: 'real-repo-command-git-metadata-missing' };
|
|
91
|
+
if (row.gitRemoteOriginMatchesManifest === false) return { status: 'blocked-identity-mismatch', reason: 'real-repo-command-git-remote-mismatch' };
|
|
92
|
+
if (row.gitRefMatchesManifest === false) return { status: 'blocked-identity-mismatch', reason: 'real-repo-command-git-ref-mismatch' };
|
|
93
|
+
return { status: 'blocked-identity-mismatch', reason: 'real-repo-command-git-metadata-missing' };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function packageManagerForRow(row) {
|
|
97
|
+
const managers = row.packageManagersPresent ?? [];
|
|
98
|
+
if (!managers.length) return { status: 'blocked-command-not-allowed', reason: 'real-repo-command-lockfile-missing' };
|
|
99
|
+
if (managers.length > 1) return { status: 'blocked-command-not-allowed', reason: 'real-repo-command-package-manager-ambiguous' };
|
|
100
|
+
return { status: 'ready', manager: managers[0] };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function commandSpecsForManager(row) {
|
|
104
|
+
if (!row?.manager || !Array.isArray(row.commands)) return null;
|
|
105
|
+
const specs = new Map();
|
|
106
|
+
for (const command of row.commands) {
|
|
107
|
+
const parsed = parseAllowedCommand(command);
|
|
108
|
+
if (!parsed) return null;
|
|
109
|
+
const phase = phaseForCommand(command);
|
|
110
|
+
if (phase && !specs.has(phase)) specs.set(phase, { ...parsed, manager: row.manager });
|
|
111
|
+
}
|
|
112
|
+
return specs;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function runCommandPhase(phase, spec, checkoutPath, options) {
|
|
116
|
+
const startedAt = Date.now();
|
|
117
|
+
const result = spawnSync(spec.argv[0], spec.argv.slice(1), {
|
|
118
|
+
cwd: checkoutPath,
|
|
119
|
+
shell: false,
|
|
120
|
+
encoding: 'utf8',
|
|
121
|
+
env: commandEnv(options.env),
|
|
122
|
+
timeout: timeoutMs(options.timeoutMs),
|
|
123
|
+
maxBuffer: Math.max(maxOutputBytes(options.maxOutputBytes) * 16, 1_048_576)
|
|
124
|
+
});
|
|
125
|
+
const durationMs = Date.now() - startedAt;
|
|
126
|
+
const stdout = capOutput(result.stdout ?? '', options.maxOutputBytes);
|
|
127
|
+
const stderr = capOutput(result.stderr ?? '', options.maxOutputBytes);
|
|
128
|
+
const timedOut = result.error?.code === 'ETIMEDOUT';
|
|
129
|
+
const executionStatus = timedOut ? 'timed-out' : result.status === 0 ? 'executed' : 'failed';
|
|
130
|
+
return {
|
|
131
|
+
...createPhase(phase, executionStatus, reasonForExecutionStatus(executionStatus), spec),
|
|
132
|
+
exitCode: typeof result.status === 'number' ? result.status : null,
|
|
133
|
+
signal: result.signal ?? null,
|
|
134
|
+
durationMs,
|
|
135
|
+
timedOut,
|
|
136
|
+
stdoutBytes: stdout.bytes,
|
|
137
|
+
stderrBytes: stderr.bytes,
|
|
138
|
+
stdoutHash: hashText(result.stdout ?? ''),
|
|
139
|
+
stderrHash: hashText(result.stderr ?? ''),
|
|
140
|
+
stdoutPreview: stdout.preview,
|
|
141
|
+
stderrPreview: stderr.preview,
|
|
142
|
+
stdoutTruncated: stdout.truncated,
|
|
143
|
+
stderrTruncated: stderr.truncated
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function createDefaultOffRow(row, phases, reason) {
|
|
148
|
+
return createRunRow(row, phases.map((phase) => createPhase(phase, 'blocked-opt-in-required', reason)), false);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function createBlockedRow(row, phases, status, reason) {
|
|
152
|
+
return createRunRow(row, phases.map((phase) => createPhase(phase, status, reason)), true);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function createRunRow(row, commandRunPhases, enabled) {
|
|
156
|
+
const commandRunStatus = aggregateStatus(commandRunPhases);
|
|
157
|
+
const repositoryPhases = commandRunPhases.filter((phase) => phase.phase === 'build' || phase.phase === 'test');
|
|
158
|
+
const dependencyPhase = commandRunPhases.find((phase) => phase.phase === 'dependency-install');
|
|
159
|
+
return {
|
|
160
|
+
entryId: row.entryId,
|
|
161
|
+
commandRunEnabled: enabled,
|
|
162
|
+
commandRunStatus,
|
|
163
|
+
commandRunExecutionStatus: enabled ? commandRunStatus : 'not-run-default-network-free',
|
|
164
|
+
commandRunReason: aggregateReason(commandRunPhases),
|
|
165
|
+
commandRunPhaseCount: commandRunPhases.length,
|
|
166
|
+
commandRunPhases,
|
|
167
|
+
commandRunExecutedPhases: commandRunPhases.filter((phase) => phase.executionStatus === 'executed').length,
|
|
168
|
+
commandRunFailedPhases: commandRunPhases.filter((phase) => phase.executionStatus === 'failed').length,
|
|
169
|
+
commandRunTimedOutPhases: commandRunPhases.filter((phase) => phase.executionStatus === 'timed-out').length,
|
|
170
|
+
commandRunSkippedPhases: commandRunPhases.filter((phase) => phase.executionStatus.startsWith('skipped-')).length,
|
|
171
|
+
commandRunDefaultOffPhases: commandRunPhases.filter((phase) => phase.defaultExecution === 'not-run-default-network-free').length,
|
|
172
|
+
commandRunOutputTruncatedPhases: commandRunPhases.filter((phase) => phase.stdoutTruncated || phase.stderrTruncated).length,
|
|
173
|
+
dependencyInstallExecution: phaseExecutionForEvidence(dependencyPhase),
|
|
174
|
+
repositoryCommandExecution: repositoryExecutionForEvidence(repositoryPhases)
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function createPhase(phase, executionStatus, reason, spec = null) {
|
|
179
|
+
return {
|
|
180
|
+
phase,
|
|
181
|
+
executionStatus,
|
|
182
|
+
reason,
|
|
183
|
+
defaultExecution: executionStatus === 'blocked-opt-in-required' ? 'not-run-default-network-free' : 'explicit-opt-in',
|
|
184
|
+
command: spec?.command ?? null,
|
|
185
|
+
argv: spec?.argv ?? [],
|
|
186
|
+
manager: spec?.manager ?? null,
|
|
187
|
+
commandHash: spec ? hashText(JSON.stringify(spec.argv)) : null,
|
|
188
|
+
stdoutBytes: 0,
|
|
189
|
+
stderrBytes: 0,
|
|
190
|
+
stdoutHash: null,
|
|
191
|
+
stderrHash: null,
|
|
192
|
+
stdoutPreview: '',
|
|
193
|
+
stderrPreview: '',
|
|
194
|
+
stdoutTruncated: false,
|
|
195
|
+
stderrTruncated: false
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function aggregateStatus(phases) {
|
|
200
|
+
if (phases.some((phase) => phase.executionStatus === 'timed-out')) return 'timed-out';
|
|
201
|
+
if (phases.some((phase) => phase.executionStatus === 'failed')) return 'failed';
|
|
202
|
+
if (phases.some((phase) => phase.executionStatus === 'executed')) return 'executed';
|
|
203
|
+
if (phases.some((phase) => phase.executionStatus === 'skipped-missing-checkout')) return 'skipped-missing-checkout';
|
|
204
|
+
if (phases.some((phase) => phase.executionStatus === 'blocked-identity-mismatch')) return 'blocked-identity-mismatch';
|
|
205
|
+
if (phases.some((phase) => phase.executionStatus === 'blocked-command-not-allowed')) return 'blocked-command-not-allowed';
|
|
206
|
+
if (phases.some((phase) => phase.executionStatus === 'blocked-safety-invariant')) return 'blocked-safety-invariant';
|
|
207
|
+
return 'blocked-opt-in-required';
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function aggregateReason(phases) {
|
|
211
|
+
return phases.find((phase) => phase.executionStatus !== 'executed')?.reason ?? 'real-repo-command-executed';
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function repositoryExecutionForEvidence(phases) {
|
|
215
|
+
if (phases.some((phase) => phase.executionStatus === 'timed-out')) return 'timed-out';
|
|
216
|
+
if (phases.some((phase) => phase.executionStatus === 'failed')) return 'failed';
|
|
217
|
+
if (phases.some((phase) => phase.executionStatus === 'executed')) return 'executed';
|
|
218
|
+
return 'not-run-default-network-free';
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function phaseExecutionForEvidence(phase) {
|
|
222
|
+
if (!phase) return 'not-run-default-network-free';
|
|
223
|
+
if (['executed', 'failed', 'timed-out'].includes(phase.executionStatus)) return phase.executionStatus;
|
|
224
|
+
return 'not-run-default-network-free';
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function parseAllowedCommand(command) {
|
|
228
|
+
if (typeof command !== 'string' || shellMetacharacters.test(command)) return null;
|
|
229
|
+
const argv = command.trim().split(/\s+/).filter(Boolean);
|
|
230
|
+
if (!argv.length || !['npm', 'pnpm', 'yarn'].includes(argv[0])) return null;
|
|
231
|
+
return { command, argv };
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function phaseForCommand(command) {
|
|
235
|
+
if (/\b(ci|install)\b/.test(command)) return 'dependency-install';
|
|
236
|
+
if (/\bbuild\b/.test(command)) return 'build';
|
|
237
|
+
if (/\btest\b/.test(command)) return 'test';
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function realContainedPath(rootPath, checkoutDir) {
|
|
242
|
+
let rootRealPath;
|
|
243
|
+
try {
|
|
244
|
+
rootRealPath = realpathSync(rootPath);
|
|
245
|
+
} catch {
|
|
246
|
+
return { reason: 'real-repo-command-checkout-root-missing' };
|
|
247
|
+
}
|
|
248
|
+
const checkoutPath = resolve(rootRealPath, checkoutDir);
|
|
249
|
+
const lexicalRelative = relative(rootRealPath, checkoutPath);
|
|
250
|
+
if (lexicalRelative.startsWith('..') || isAbsolute(lexicalRelative)) return { reason: 'real-repo-command-checkout-dir-outside-root' };
|
|
251
|
+
try {
|
|
252
|
+
const stat = statSync(checkoutPath);
|
|
253
|
+
if (!stat.isDirectory()) return { reason: 'real-repo-command-checkout-dir-missing' };
|
|
254
|
+
const checkoutRealPath = realpathSync(checkoutPath);
|
|
255
|
+
const realRelative = relative(rootRealPath, checkoutRealPath);
|
|
256
|
+
if (realRelative.startsWith('..') || isAbsolute(realRelative)) return { reason: 'real-repo-command-checkout-realpath-escape' };
|
|
257
|
+
return { path: checkoutRealPath };
|
|
258
|
+
} catch {
|
|
259
|
+
return { reason: 'real-repo-command-checkout-dir-missing' };
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function commandEnv(extra = {}) {
|
|
264
|
+
const env = {};
|
|
265
|
+
for (const key of safeEnvKeys) {
|
|
266
|
+
if (process.env[key] !== undefined) env[key] = process.env[key];
|
|
267
|
+
}
|
|
268
|
+
for (const [key, value] of Object.entries(extra ?? {})) {
|
|
269
|
+
if (safeEnvKeys.has(key) || /^npm_config_[a-z0-9_]+$/i.test(key)) env[key] = String(value);
|
|
270
|
+
}
|
|
271
|
+
env.CI = 'true';
|
|
272
|
+
env.NO_COLOR = '1';
|
|
273
|
+
env.npm_config_audit = 'false';
|
|
274
|
+
env.npm_config_fund = 'false';
|
|
275
|
+
env.npm_config_update_notifier = 'false';
|
|
276
|
+
return env;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function capOutput(value, maxBytesOption) {
|
|
280
|
+
const text = String(value ?? '');
|
|
281
|
+
const bytes = Buffer.byteLength(text);
|
|
282
|
+
const maxBytes = maxOutputBytes(maxBytesOption);
|
|
283
|
+
if (bytes <= maxBytes) return { bytes, preview: text, truncated: false };
|
|
284
|
+
return { bytes, preview: Buffer.from(text).subarray(0, maxBytes).toString('utf8'), truncated: true };
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function normalizePhases(phases) {
|
|
288
|
+
if (!Array.isArray(phases) || phases.length === 0) return defaultPhases;
|
|
289
|
+
return phases.filter((phase) => defaultPhases.includes(phase));
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function timeoutMs(value) {
|
|
293
|
+
return Number.isInteger(value) && value > 0 ? value : defaultTimeoutMs;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function maxOutputBytes(value) {
|
|
297
|
+
return Number.isInteger(value) && value > 0 ? value : defaultMaxOutputBytes;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function countPhases(rows, status) {
|
|
301
|
+
return rows.reduce((sum, row) => sum + row.commandRunPhases.filter((phase) => phase.executionStatus === status).length, 0);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function reasonForExecutionStatus(status) {
|
|
305
|
+
if (status === 'failed') return 'real-repo-command-exit-nonzero';
|
|
306
|
+
if (status === 'timed-out') return 'real-repo-command-timeout';
|
|
307
|
+
return 'real-repo-command-executed';
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function hashText(value) {
|
|
311
|
+
return createHash('sha256').update(String(value)).digest('hex');
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export { collectRealRepoCommandExecution };
|