@gpustack/loopwright 0.0.0-stage → 0.0.3
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/LICENSE +191 -0
- package/README.md +356 -2
- package/bin/loopwright.js +3 -0
- package/node_modules/@loopwright/agent-pi/dist/adapter-v2.d.ts +9 -0
- package/node_modules/@loopwright/agent-pi/dist/adapter-v2.js +122 -0
- package/node_modules/@loopwright/agent-pi/dist/adapter.d.ts +30 -0
- package/node_modules/@loopwright/agent-pi/dist/adapter.js +340 -0
- package/node_modules/@loopwright/agent-pi/dist/admission.d.ts +25 -0
- package/node_modules/@loopwright/agent-pi/dist/admission.js +65 -0
- package/node_modules/@loopwright/agent-pi/dist/artifacts.d.ts +15 -0
- package/node_modules/@loopwright/agent-pi/dist/artifacts.js +76 -0
- package/node_modules/@loopwright/agent-pi/dist/boundary.d.ts +18 -0
- package/node_modules/@loopwright/agent-pi/dist/boundary.js +113 -0
- package/node_modules/@loopwright/agent-pi/dist/broker-channel.d.ts +4 -0
- package/node_modules/@loopwright/agent-pi/dist/broker-channel.js +121 -0
- package/node_modules/@loopwright/agent-pi/dist/candidate.d.ts +96 -0
- package/node_modules/@loopwright/agent-pi/dist/candidate.js +1712 -0
- package/node_modules/@loopwright/agent-pi/dist/capture.d.ts +39 -0
- package/node_modules/@loopwright/agent-pi/dist/capture.js +146 -0
- package/node_modules/@loopwright/agent-pi/dist/cas.d.ts +51 -0
- package/node_modules/@loopwright/agent-pi/dist/cas.js +836 -0
- package/node_modules/@loopwright/agent-pi/dist/catalog-api.d.ts +3 -0
- package/node_modules/@loopwright/agent-pi/dist/catalog-api.js +2 -0
- package/node_modules/@loopwright/agent-pi/dist/catalog.d.ts +39 -0
- package/node_modules/@loopwright/agent-pi/dist/catalog.js +280 -0
- package/node_modules/@loopwright/agent-pi/dist/circuit-breaker-limits.d.ts +9 -0
- package/node_modules/@loopwright/agent-pi/dist/circuit-breaker-limits.js +12 -0
- package/node_modules/@loopwright/agent-pi/dist/containers.d.ts +29 -0
- package/node_modules/@loopwright/agent-pi/dist/containers.js +160 -0
- package/node_modules/@loopwright/agent-pi/dist/context.d.ts +56 -0
- package/node_modules/@loopwright/agent-pi/dist/context.js +351 -0
- package/node_modules/@loopwright/agent-pi/dist/daemon.d.ts +8 -0
- package/node_modules/@loopwright/agent-pi/dist/daemon.js +52 -0
- package/node_modules/@loopwright/agent-pi/dist/deadline.d.ts +6 -0
- package/node_modules/@loopwright/agent-pi/dist/deadline.js +18 -0
- package/node_modules/@loopwright/agent-pi/dist/decode-capture.d.ts +39 -0
- package/node_modules/@loopwright/agent-pi/dist/decode-capture.js +287 -0
- package/node_modules/@loopwright/agent-pi/dist/descriptor.d.ts +12 -0
- package/node_modules/@loopwright/agent-pi/dist/descriptor.js +17 -0
- package/node_modules/@loopwright/agent-pi/dist/docker-absence.d.ts +2 -0
- package/node_modules/@loopwright/agent-pi/dist/docker-absence.js +9 -0
- package/node_modules/@loopwright/agent-pi/dist/errors.d.ts +7 -0
- package/node_modules/@loopwright/agent-pi/dist/errors.js +19 -0
- package/node_modules/@loopwright/agent-pi/dist/event-sequence.d.ts +6 -0
- package/node_modules/@loopwright/agent-pi/dist/event-sequence.js +64 -0
- package/node_modules/@loopwright/agent-pi/dist/events.d.ts +19 -0
- package/node_modules/@loopwright/agent-pi/dist/events.js +132 -0
- package/node_modules/@loopwright/agent-pi/dist/execution-guard.d.ts +9 -0
- package/node_modules/@loopwright/agent-pi/dist/execution-guard.js +25 -0
- package/node_modules/@loopwright/agent-pi/dist/execution-lease.d.ts +24 -0
- package/node_modules/@loopwright/agent-pi/dist/execution-lease.js +316 -0
- package/node_modules/@loopwright/agent-pi/dist/execution.d.ts +32 -0
- package/node_modules/@loopwright/agent-pi/dist/execution.js +476 -0
- package/node_modules/@loopwright/agent-pi/dist/external-mcp.d.ts +87 -0
- package/node_modules/@loopwright/agent-pi/dist/external-mcp.js +526 -0
- package/node_modules/@loopwright/agent-pi/dist/factory-bootstrap.d.ts +15 -0
- package/node_modules/@loopwright/agent-pi/dist/factory-bootstrap.js +74 -0
- package/node_modules/@loopwright/agent-pi/dist/host-session.d.ts +51 -0
- package/node_modules/@loopwright/agent-pi/dist/host-session.js +2094 -0
- package/node_modules/@loopwright/agent-pi/dist/http-mcp.d.ts +32 -0
- package/node_modules/@loopwright/agent-pi/dist/http-mcp.js +353 -0
- package/node_modules/@loopwright/agent-pi/dist/index.d.ts +7 -0
- package/node_modules/@loopwright/agent-pi/dist/index.js +4 -0
- package/node_modules/@loopwright/agent-pi/dist/lifecycle.d.ts +13 -0
- package/node_modules/@loopwright/agent-pi/dist/lifecycle.js +11 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp-process.d.ts +35 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp-process.js +92 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp-transport.d.ts +25 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp-transport.js +63 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp.d.ts +23 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp.js +212 -0
- package/node_modules/@loopwright/agent-pi/dist/operation.d.ts +5 -0
- package/node_modules/@loopwright/agent-pi/dist/operation.js +28 -0
- package/node_modules/@loopwright/agent-pi/dist/policy-v2.d.ts +10 -0
- package/node_modules/@loopwright/agent-pi/dist/policy-v2.js +64 -0
- package/node_modules/@loopwright/agent-pi/dist/policy.d.ts +13 -0
- package/node_modules/@loopwright/agent-pi/dist/policy.js +260 -0
- package/node_modules/@loopwright/agent-pi/dist/preflight.d.ts +60 -0
- package/node_modules/@loopwright/agent-pi/dist/preflight.js +700 -0
- package/node_modules/@loopwright/agent-pi/dist/progress-summary.d.ts +1 -0
- package/node_modules/@loopwright/agent-pi/dist/progress-summary.js +119 -0
- package/node_modules/@loopwright/agent-pi/dist/protocol.d.ts +17 -0
- package/node_modules/@loopwright/agent-pi/dist/protocol.js +131 -0
- package/node_modules/@loopwright/agent-pi/dist/provider.d.ts +62 -0
- package/node_modules/@loopwright/agent-pi/dist/provider.js +217 -0
- package/node_modules/@loopwright/agent-pi/dist/receipt.d.ts +3 -0
- package/node_modules/@loopwright/agent-pi/dist/receipt.js +64 -0
- package/node_modules/@loopwright/agent-pi/dist/recovery.d.ts +6 -0
- package/node_modules/@loopwright/agent-pi/dist/recovery.js +188 -0
- package/node_modules/@loopwright/agent-pi/dist/resources.d.ts +13 -0
- package/node_modules/@loopwright/agent-pi/dist/resources.js +81 -0
- package/node_modules/@loopwright/agent-pi/dist/response.d.ts +20 -0
- package/node_modules/@loopwright/agent-pi/dist/response.js +259 -0
- package/node_modules/@loopwright/agent-pi/dist/runtime-profile.d.ts +6 -0
- package/node_modules/@loopwright/agent-pi/dist/runtime-profile.js +37 -0
- package/node_modules/@loopwright/agent-pi/dist/sdk-worker.d.ts +14 -0
- package/node_modules/@loopwright/agent-pi/dist/sdk-worker.js +633 -0
- package/node_modules/@loopwright/agent-pi/dist/sender.d.ts +46 -0
- package/node_modules/@loopwright/agent-pi/dist/sender.js +553 -0
- package/node_modules/@loopwright/agent-pi/dist/session-host.d.ts +21 -0
- package/node_modules/@loopwright/agent-pi/dist/session-host.js +315 -0
- package/node_modules/@loopwright/agent-pi/dist/snapshot-transfer.d.ts +14 -0
- package/node_modules/@loopwright/agent-pi/dist/snapshot-transfer.js +102 -0
- package/node_modules/@loopwright/agent-pi/dist/snapshot.d.ts +19 -0
- package/node_modules/@loopwright/agent-pi/dist/snapshot.js +121 -0
- package/node_modules/@loopwright/agent-pi/dist/tool-process.d.ts +32 -0
- package/node_modules/@loopwright/agent-pi/dist/tool-process.js +85 -0
- package/node_modules/@loopwright/agent-pi/dist/tool-worker.d.ts +2 -0
- package/node_modules/@loopwright/agent-pi/dist/tool-worker.js +105 -0
- package/node_modules/@loopwright/agent-pi/dist/tools.d.ts +36 -0
- package/node_modules/@loopwright/agent-pi/dist/tools.js +128 -0
- package/node_modules/@loopwright/agent-pi/dist/types-v2.d.ts +71 -0
- package/node_modules/@loopwright/agent-pi/dist/types-v2.js +1 -0
- package/node_modules/@loopwright/agent-pi/dist/types.d.ts +314 -0
- package/node_modules/@loopwright/agent-pi/dist/types.js +1 -0
- package/node_modules/@loopwright/agent-pi/dist/usage.d.ts +18 -0
- package/node_modules/@loopwright/agent-pi/dist/usage.js +314 -0
- package/node_modules/@loopwright/agent-pi/dist/workspace-mcp.d.ts +27 -0
- package/node_modules/@loopwright/agent-pi/dist/workspace-mcp.js +142 -0
- package/node_modules/@loopwright/agent-pi/package.json +24 -0
- package/node_modules/@loopwright/agent-pi/runtime/Dockerfile +8 -0
- package/node_modules/@loopwright/agent-pi/runtime/seccomp.json +1 -0
- package/node_modules/@loopwright/cli/dist/arguments.d.ts +19 -0
- package/node_modules/@loopwright/cli/dist/arguments.js +358 -0
- package/node_modules/@loopwright/cli/dist/closure.d.ts +93 -0
- package/node_modules/@loopwright/cli/dist/closure.js +230 -0
- package/node_modules/@loopwright/cli/dist/draft.d.ts +9 -0
- package/node_modules/@loopwright/cli/dist/draft.js +106 -0
- package/node_modules/@loopwright/cli/dist/failure-matrix.d.ts +9 -0
- package/node_modules/@loopwright/cli/dist/failure-matrix.js +701 -0
- package/node_modules/@loopwright/cli/dist/index.d.ts +6 -0
- package/node_modules/@loopwright/cli/dist/index.js +5 -0
- package/node_modules/@loopwright/cli/dist/main.d.ts +22 -0
- package/node_modules/@loopwright/cli/dist/main.js +1855 -0
- package/node_modules/@loopwright/cli/package.json +16 -0
- package/node_modules/@loopwright/controller/dist/acceptance.d.ts +43 -0
- package/node_modules/@loopwright/controller/dist/acceptance.js +446 -0
- package/node_modules/@loopwright/controller/dist/benchmark-gate.d.ts +273 -0
- package/node_modules/@loopwright/controller/dist/benchmark-gate.js +3147 -0
- package/node_modules/@loopwright/controller/dist/budget-observations.d.ts +25 -0
- package/node_modules/@loopwright/controller/dist/budget-observations.js +139 -0
- package/node_modules/@loopwright/controller/dist/bundle.d.ts +26 -0
- package/node_modules/@loopwright/controller/dist/bundle.js +64 -0
- package/node_modules/@loopwright/controller/dist/capture.d.ts +89 -0
- package/node_modules/@loopwright/controller/dist/capture.js +587 -0
- package/node_modules/@loopwright/controller/dist/compile.d.ts +3 -0
- package/node_modules/@loopwright/controller/dist/compile.js +402 -0
- package/node_modules/@loopwright/controller/dist/config.d.ts +22 -0
- package/node_modules/@loopwright/controller/dist/config.js +255 -0
- package/node_modules/@loopwright/controller/dist/controller.d.ts +177 -0
- package/node_modules/@loopwright/controller/dist/controller.js +2135 -0
- package/node_modules/@loopwright/controller/dist/credentials.d.ts +29 -0
- package/node_modules/@loopwright/controller/dist/credentials.js +189 -0
- package/node_modules/@loopwright/controller/dist/deadlines.d.ts +18 -0
- package/node_modules/@loopwright/controller/dist/deadlines.js +71 -0
- package/node_modules/@loopwright/controller/dist/errors.d.ts +27 -0
- package/node_modules/@loopwright/controller/dist/errors.js +41 -0
- package/node_modules/@loopwright/controller/dist/events.d.ts +52 -0
- package/node_modules/@loopwright/controller/dist/events.js +228 -0
- package/node_modules/@loopwright/controller/dist/files.d.ts +51 -0
- package/node_modules/@loopwright/controller/dist/files.js +386 -0
- package/node_modules/@loopwright/controller/dist/finalize.d.ts +25 -0
- package/node_modules/@loopwright/controller/dist/finalize.js +32 -0
- package/node_modules/@loopwright/controller/dist/gate.d.ts +84 -0
- package/node_modules/@loopwright/controller/dist/gate.js +640 -0
- package/node_modules/@loopwright/controller/dist/git-objects.d.ts +11 -0
- package/node_modules/@loopwright/controller/dist/git-objects.js +59 -0
- package/node_modules/@loopwright/controller/dist/git-reader.d.ts +17 -0
- package/node_modules/@loopwright/controller/dist/git-reader.js +40 -0
- package/node_modules/@loopwright/controller/dist/handlers.d.ts +6 -0
- package/node_modules/@loopwright/controller/dist/handlers.js +45 -0
- package/node_modules/@loopwright/controller/dist/handoff.d.ts +71 -0
- package/node_modules/@loopwright/controller/dist/handoff.js +554 -0
- package/node_modules/@loopwright/controller/dist/index.d.ts +41 -0
- package/node_modules/@loopwright/controller/dist/index.js +21 -0
- package/node_modules/@loopwright/controller/dist/inspect.d.ts +30 -0
- package/node_modules/@loopwright/controller/dist/inspect.js +372 -0
- package/node_modules/@loopwright/controller/dist/interpolation.d.ts +9 -0
- package/node_modules/@loopwright/controller/dist/interpolation.js +79 -0
- package/node_modules/@loopwright/controller/dist/ownership.d.ts +41 -0
- package/node_modules/@loopwright/controller/dist/ownership.js +666 -0
- package/node_modules/@loopwright/controller/dist/parser.d.ts +5 -0
- package/node_modules/@loopwright/controller/dist/parser.js +200 -0
- package/node_modules/@loopwright/controller/dist/progress.d.ts +41 -0
- package/node_modules/@loopwright/controller/dist/progress.js +904 -0
- package/node_modules/@loopwright/controller/dist/publication.d.ts +60 -0
- package/node_modules/@loopwright/controller/dist/publication.js +329 -0
- package/node_modules/@loopwright/controller/dist/reconcile.d.ts +26 -0
- package/node_modules/@loopwright/controller/dist/reconcile.js +1378 -0
- package/node_modules/@loopwright/controller/dist/recovery.d.ts +10 -0
- package/node_modules/@loopwright/controller/dist/recovery.js +315 -0
- package/node_modules/@loopwright/controller/dist/refusal-record.d.ts +43 -0
- package/node_modules/@loopwright/controller/dist/refusal-record.js +150 -0
- package/node_modules/@loopwright/controller/dist/registry.d.ts +6 -0
- package/node_modules/@loopwright/controller/dist/registry.js +374 -0
- package/node_modules/@loopwright/controller/dist/repair.d.ts +31 -0
- package/node_modules/@loopwright/controller/dist/repair.js +102 -0
- package/node_modules/@loopwright/controller/dist/report.d.ts +64 -0
- package/node_modules/@loopwright/controller/dist/report.js +596 -0
- package/node_modules/@loopwright/controller/dist/retained.d.ts +284 -0
- package/node_modules/@loopwright/controller/dist/retained.js +193 -0
- package/node_modules/@loopwright/controller/dist/rules.d.ts +31 -0
- package/node_modules/@loopwright/controller/dist/rules.js +110 -0
- package/node_modules/@loopwright/controller/dist/run-eval.d.ts +115 -0
- package/node_modules/@loopwright/controller/dist/run-eval.js +959 -0
- package/node_modules/@loopwright/controller/dist/scheduler.d.ts +10 -0
- package/node_modules/@loopwright/controller/dist/scheduler.js +41 -0
- package/node_modules/@loopwright/controller/dist/schema.d.ts +17 -0
- package/node_modules/@loopwright/controller/dist/schema.js +78 -0
- package/node_modules/@loopwright/controller/dist/source.d.ts +69 -0
- package/node_modules/@loopwright/controller/dist/source.js +872 -0
- package/node_modules/@loopwright/controller/dist/step.d.ts +38 -0
- package/node_modules/@loopwright/controller/dist/step.js +1776 -0
- package/node_modules/@loopwright/controller/dist/storage.d.ts +90 -0
- package/node_modules/@loopwright/controller/dist/storage.js +1345 -0
- package/node_modules/@loopwright/controller/dist/submission.d.ts +51 -0
- package/node_modules/@loopwright/controller/dist/submission.js +292 -0
- package/node_modules/@loopwright/controller/dist/types.d.ts +585 -0
- package/node_modules/@loopwright/controller/dist/types.js +9 -0
- package/node_modules/@loopwright/controller/dist/verification.d.ts +124 -0
- package/node_modules/@loopwright/controller/dist/verification.js +1308 -0
- package/node_modules/@loopwright/controller/dist/verifier-protocol.d.ts +105 -0
- package/node_modules/@loopwright/controller/dist/verifier-protocol.js +1312 -0
- package/node_modules/@loopwright/controller/dist/verifier-worker.d.ts +1 -0
- package/node_modules/@loopwright/controller/dist/verifier-worker.js +33 -0
- package/node_modules/@loopwright/controller/package.json +12 -0
- package/node_modules/@loopwright/core/dist/acceptance.d.ts +108 -0
- package/node_modules/@loopwright/core/dist/acceptance.js +327 -0
- package/node_modules/@loopwright/core/dist/artifacts.d.ts +63 -0
- package/node_modules/@loopwright/core/dist/artifacts.js +356 -0
- package/node_modules/@loopwright/core/dist/boundary.d.ts +21 -0
- package/node_modules/@loopwright/core/dist/boundary.js +484 -0
- package/node_modules/@loopwright/core/dist/contracts.d.ts +287 -0
- package/node_modules/@loopwright/core/dist/contracts.js +694 -0
- package/node_modules/@loopwright/core/dist/diagnostics.d.ts +21 -0
- package/node_modules/@loopwright/core/dist/diagnostics.js +51 -0
- package/node_modules/@loopwright/core/dist/evidence.d.ts +92 -0
- package/node_modules/@loopwright/core/dist/evidence.js +85 -0
- package/node_modules/@loopwright/core/dist/graph.d.ts +8 -0
- package/node_modules/@loopwright/core/dist/graph.js +44 -0
- package/node_modules/@loopwright/core/dist/identity.d.ts +162 -0
- package/node_modules/@loopwright/core/dist/identity.js +80 -0
- package/node_modules/@loopwright/core/dist/index.d.ts +30 -0
- package/node_modules/@loopwright/core/dist/index.js +39 -0
- package/node_modules/@loopwright/core/dist/limits.d.ts +99 -0
- package/node_modules/@loopwright/core/dist/limits.js +59 -0
- package/node_modules/@loopwright/core/dist/results.d.ts +161 -0
- package/node_modules/@loopwright/core/dist/results.js +98 -0
- package/node_modules/@loopwright/core/dist/scope.d.ts +13 -0
- package/node_modules/@loopwright/core/dist/scope.js +154 -0
- package/node_modules/@loopwright/core/dist/scrubber.d.ts +13 -0
- package/node_modules/@loopwright/core/dist/scrubber.js +63 -0
- package/node_modules/@loopwright/core/dist/usage.d.ts +68 -0
- package/node_modules/@loopwright/core/dist/usage.js +56 -0
- package/node_modules/@loopwright/core/package.json +12 -0
- package/node_modules/@loopwright/decisions/dist/benchmark.d.ts +23 -0
- package/node_modules/@loopwright/decisions/dist/benchmark.js +337 -0
- package/node_modules/@loopwright/decisions/dist/client.d.ts +74 -0
- package/node_modules/@loopwright/decisions/dist/client.js +292 -0
- package/node_modules/@loopwright/decisions/dist/index.d.ts +15 -0
- package/node_modules/@loopwright/decisions/dist/index.js +8 -0
- package/node_modules/@loopwright/decisions/dist/nodes.d.ts +63 -0
- package/node_modules/@loopwright/decisions/dist/nodes.js +282 -0
- package/node_modules/@loopwright/decisions/dist/primitives.d.ts +36 -0
- package/node_modules/@loopwright/decisions/dist/primitives.js +300 -0
- package/node_modules/@loopwright/decisions/dist/redaction.d.ts +23 -0
- package/node_modules/@loopwright/decisions/dist/redaction.js +146 -0
- package/node_modules/@loopwright/decisions/dist/router.d.ts +55 -0
- package/node_modules/@loopwright/decisions/dist/router.js +248 -0
- package/node_modules/@loopwright/decisions/dist/schema.d.ts +25 -0
- package/node_modules/@loopwright/decisions/dist/schema.js +536 -0
- package/node_modules/@loopwright/decisions/dist/types.d.ts +394 -0
- package/node_modules/@loopwright/decisions/dist/types.js +80 -0
- package/node_modules/@loopwright/decisions/package.json +12 -0
- package/node_modules/@loopwright/github-app/dist/action.d.ts +90 -0
- package/node_modules/@loopwright/github-app/dist/action.js +2429 -0
- package/node_modules/@loopwright/github-app/dist/config.d.ts +23 -0
- package/node_modules/@loopwright/github-app/dist/config.js +297 -0
- package/node_modules/@loopwright/github-app/dist/digests.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/digests.js +1 -0
- package/node_modules/@loopwright/github-app/dist/index.d.ts +14 -0
- package/node_modules/@loopwright/github-app/dist/index.js +13 -0
- package/node_modules/@loopwright/github-app/dist/models-config.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/models-config.js +1 -0
- package/node_modules/@loopwright/github-app/dist/output-format.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/output-format.js +1 -0
- package/node_modules/@loopwright/github-app/dist/preflight.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/preflight.js +1 -0
- package/node_modules/@loopwright/github-app/dist/publisher.d.ts +58 -0
- package/node_modules/@loopwright/github-app/dist/publisher.js +1368 -0
- package/node_modules/@loopwright/github-app/dist/qualification.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/qualification.js +1 -0
- package/node_modules/@loopwright/github-app/dist/sandbox.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/sandbox.js +1 -0
- package/node_modules/@loopwright/github-app/dist/schema.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/schema.js +1 -0
- package/node_modules/@loopwright/github-app/dist/service.d.ts +52 -0
- package/node_modules/@loopwright/github-app/dist/service.js +1658 -0
- package/node_modules/@loopwright/github-app/dist/suite-pr-lookup.d.ts +90 -0
- package/node_modules/@loopwright/github-app/dist/suite-pr-lookup.js +392 -0
- package/node_modules/@loopwright/github-app/dist/taskpack.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/taskpack.js +1 -0
- package/node_modules/@loopwright/github-app/dist/tenant-queue.d.ts +44 -0
- package/node_modules/@loopwright/github-app/dist/tenant-queue.js +423 -0
- package/node_modules/@loopwright/github-app/dist/token-broker.d.ts +50 -0
- package/node_modules/@loopwright/github-app/dist/token-broker.js +262 -0
- package/node_modules/@loopwright/github-app/dist/turnkey-memory.d.ts +35 -0
- package/node_modules/@loopwright/github-app/dist/turnkey-memory.js +1654 -0
- package/node_modules/@loopwright/github-app/dist/turnkey.d.ts +16 -0
- package/node_modules/@loopwright/github-app/dist/turnkey.js +34 -0
- package/node_modules/@loopwright/github-app/dist/types.d.ts +220 -0
- package/node_modules/@loopwright/github-app/dist/types.js +14 -0
- package/node_modules/@loopwright/github-app/dist/upstreams.d.ts +13 -0
- package/node_modules/@loopwright/github-app/dist/upstreams.js +65 -0
- package/node_modules/@loopwright/github-app/dist/webhook.d.ts +34 -0
- package/node_modules/@loopwright/github-app/dist/webhook.js +241 -0
- package/node_modules/@loopwright/github-app/dist/yaml.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/yaml.js +1 -0
- package/node_modules/@loopwright/github-app/package.json +12 -0
- package/node_modules/@loopwright/hardware-runner/dist/config.d.ts +48 -0
- package/node_modules/@loopwright/hardware-runner/dist/config.js +719 -0
- package/node_modules/@loopwright/hardware-runner/dist/evaluator.d.ts +230 -0
- package/node_modules/@loopwright/hardware-runner/dist/evaluator.js +3178 -0
- package/node_modules/@loopwright/hardware-runner/dist/index.d.ts +13 -0
- package/node_modules/@loopwright/hardware-runner/dist/index.js +9 -0
- package/node_modules/@loopwright/hardware-runner/dist/provenance.d.ts +128 -0
- package/node_modules/@loopwright/hardware-runner/dist/provenance.js +1500 -0
- package/node_modules/@loopwright/hardware-runner/dist/queue.d.ts +81 -0
- package/node_modules/@loopwright/hardware-runner/dist/queue.js +1081 -0
- package/node_modules/@loopwright/hardware-runner/dist/relay-server.d.ts +13 -0
- package/node_modules/@loopwright/hardware-runner/dist/relay-server.js +2997 -0
- package/node_modules/@loopwright/hardware-runner/dist/types.d.ts +239 -0
- package/node_modules/@loopwright/hardware-runner/dist/types.js +12 -0
- package/node_modules/@loopwright/hardware-runner/dist/worker.d.ts +49 -0
- package/node_modules/@loopwright/hardware-runner/dist/worker.js +1648 -0
- package/node_modules/@loopwright/hardware-runner/package.json +12 -0
- package/node_modules/@loopwright/memory/dist/cas.d.ts +21 -0
- package/node_modules/@loopwright/memory/dist/cas.js +510 -0
- package/node_modules/@loopwright/memory/dist/compaction.d.ts +18 -0
- package/node_modules/@loopwright/memory/dist/compaction.js +110 -0
- package/node_modules/@loopwright/memory/dist/finalizer.d.ts +23 -0
- package/node_modules/@loopwright/memory/dist/finalizer.js +538 -0
- package/node_modules/@loopwright/memory/dist/index.d.ts +9 -0
- package/node_modules/@loopwright/memory/dist/index.js +8 -0
- package/node_modules/@loopwright/memory/dist/schema.d.ts +36 -0
- package/node_modules/@loopwright/memory/dist/schema.js +510 -0
- package/node_modules/@loopwright/memory/dist/selector.d.ts +7 -0
- package/node_modules/@loopwright/memory/dist/selector.js +157 -0
- package/node_modules/@loopwright/memory/dist/store.d.ts +51 -0
- package/node_modules/@loopwright/memory/dist/store.js +554 -0
- package/node_modules/@loopwright/memory/dist/types.d.ts +442 -0
- package/node_modules/@loopwright/memory/dist/types.js +8 -0
- package/node_modules/@loopwright/memory/dist/verifier.d.ts +5 -0
- package/node_modules/@loopwright/memory/dist/verifier.js +328 -0
- package/node_modules/@loopwright/memory/package.json +12 -0
- package/node_modules/@loopwright/state/dist/admission.d.ts +321 -0
- package/node_modules/@loopwright/state/dist/admission.js +199 -0
- package/node_modules/@loopwright/state/dist/boundary.d.ts +53 -0
- package/node_modules/@loopwright/state/dist/boundary.js +194 -0
- package/node_modules/@loopwright/state/dist/checkpoint.d.ts +16 -0
- package/node_modules/@loopwright/state/dist/checkpoint.js +84 -0
- package/node_modules/@loopwright/state/dist/clock.d.ts +8 -0
- package/node_modules/@loopwright/state/dist/clock.js +27 -0
- package/node_modules/@loopwright/state/dist/connection.d.ts +55 -0
- package/node_modules/@loopwright/state/dist/connection.js +391 -0
- package/node_modules/@loopwright/state/dist/errors.d.ts +13 -0
- package/node_modules/@loopwright/state/dist/errors.js +34 -0
- package/node_modules/@loopwright/state/dist/index.d.ts +3 -0
- package/node_modules/@loopwright/state/dist/index.js +1 -0
- package/node_modules/@loopwright/state/dist/journal.d.ts +119 -0
- package/node_modules/@loopwright/state/dist/journal.js +72 -0
- package/node_modules/@loopwright/state/dist/model.d.ts +40 -0
- package/node_modules/@loopwright/state/dist/model.js +58 -0
- package/node_modules/@loopwright/state/dist/ownership.d.ts +14 -0
- package/node_modules/@loopwright/state/dist/ownership.js +45 -0
- package/node_modules/@loopwright/state/dist/pages.d.ts +11 -0
- package/node_modules/@loopwright/state/dist/pages.js +41 -0
- package/node_modules/@loopwright/state/dist/receipts.d.ts +33 -0
- package/node_modules/@loopwright/state/dist/receipts.js +97 -0
- package/node_modules/@loopwright/state/dist/schema.d.ts +28 -0
- package/node_modules/@loopwright/state/dist/schema.js +41 -0
- package/node_modules/@loopwright/state/dist/settlement.d.ts +10 -0
- package/node_modules/@loopwright/state/dist/settlement.js +129 -0
- package/node_modules/@loopwright/state/dist/store.d.ts +52 -0
- package/node_modules/@loopwright/state/dist/store.js +100 -0
- package/node_modules/@loopwright/state/dist/types.d.ts +315 -0
- package/node_modules/@loopwright/state/dist/types.js +1 -0
- package/node_modules/@loopwright/state/package.json +12 -0
- package/node_modules/@loopwright/taskpack/dist/baseline-align.d.ts +195 -0
- package/node_modules/@loopwright/taskpack/dist/baseline-align.js +1847 -0
- package/node_modules/@loopwright/taskpack/dist/digests.d.ts +61 -0
- package/node_modules/@loopwright/taskpack/dist/digests.js +715 -0
- package/node_modules/@loopwright/taskpack/dist/index.d.ts +18 -0
- package/node_modules/@loopwright/taskpack/dist/index.js +17 -0
- package/node_modules/@loopwright/taskpack/dist/models-config.d.ts +112 -0
- package/node_modules/@loopwright/taskpack/dist/models-config.js +1026 -0
- package/node_modules/@loopwright/taskpack/dist/output-format.d.ts +28 -0
- package/node_modules/@loopwright/taskpack/dist/output-format.js +157 -0
- package/node_modules/@loopwright/taskpack/dist/preflight.d.ts +130 -0
- package/node_modules/@loopwright/taskpack/dist/preflight.js +1497 -0
- package/node_modules/@loopwright/taskpack/dist/qualification.d.ts +23 -0
- package/node_modules/@loopwright/taskpack/dist/qualification.js +120 -0
- package/node_modules/@loopwright/taskpack/dist/sandbox.d.ts +121 -0
- package/node_modules/@loopwright/taskpack/dist/sandbox.js +2642 -0
- package/node_modules/@loopwright/taskpack/dist/schema.d.ts +197 -0
- package/node_modules/@loopwright/taskpack/dist/schema.js +4189 -0
- package/node_modules/@loopwright/taskpack/dist/scrubber.d.ts +47 -0
- package/node_modules/@loopwright/taskpack/dist/scrubber.js +283 -0
- package/node_modules/@loopwright/taskpack/dist/suite.d.ts +124 -0
- package/node_modules/@loopwright/taskpack/dist/suite.js +3256 -0
- package/node_modules/@loopwright/taskpack/dist/taskpack.d.ts +154 -0
- package/node_modules/@loopwright/taskpack/dist/taskpack.js +3634 -0
- package/node_modules/@loopwright/taskpack/dist/turnkey-memory.d.ts +122 -0
- package/node_modules/@loopwright/taskpack/dist/turnkey-memory.js +483 -0
- package/node_modules/@loopwright/taskpack/dist/turnkey.d.ts +437 -0
- package/node_modules/@loopwright/taskpack/dist/turnkey.js +7335 -0
- package/node_modules/@loopwright/taskpack/dist/types.d.ts +1274 -0
- package/node_modules/@loopwright/taskpack/dist/types.js +99 -0
- package/node_modules/@loopwright/taskpack/dist/upstreams.d.ts +261 -0
- package/node_modules/@loopwright/taskpack/dist/upstreams.js +2242 -0
- package/node_modules/@loopwright/taskpack/dist/yaml.d.ts +18 -0
- package/node_modules/@loopwright/taskpack/dist/yaml.js +167 -0
- package/node_modules/@loopwright/taskpack/package.json +12 -0
- package/node_modules/@loopwright/taskpack-runner/dist/compile-taskpack.d.ts +137 -0
- package/node_modules/@loopwright/taskpack-runner/dist/compile-taskpack.js +474 -0
- package/node_modules/@loopwright/taskpack-runner/dist/corpus.d.ts +8 -0
- package/node_modules/@loopwright/taskpack-runner/dist/corpus.js +129 -0
- package/node_modules/@loopwright/taskpack-runner/dist/index.d.ts +13 -0
- package/node_modules/@loopwright/taskpack-runner/dist/index.js +7 -0
- package/node_modules/@loopwright/taskpack-runner/dist/intake.d.ts +149 -0
- package/node_modules/@loopwright/taskpack-runner/dist/intake.js +135 -0
- package/node_modules/@loopwright/taskpack-runner/dist/parity.d.ts +130 -0
- package/node_modules/@loopwright/taskpack-runner/dist/parity.js +927 -0
- package/node_modules/@loopwright/taskpack-runner/dist/python-bridge.d.ts +68 -0
- package/node_modules/@loopwright/taskpack-runner/dist/python-bridge.js +517 -0
- package/node_modules/@loopwright/taskpack-runner/dist/service.d.ts +149 -0
- package/node_modules/@loopwright/taskpack-runner/dist/service.js +1796 -0
- package/node_modules/@loopwright/taskpack-runner/dist/types.d.ts +29 -0
- package/node_modules/@loopwright/taskpack-runner/dist/types.js +11 -0
- package/node_modules/@loopwright/taskpack-runner/package.json +12 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/README.md +77 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/docs/support-records.md +57 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/docs/supported-runners.md +98 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/manifest.json +205 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pack/expand_matrix.sh +273 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pack/matrix.yaml +280 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pack/resolve_dockerfile.sh +24 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pyproject.toml +46 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/runtime_runner/runner.py.json +5270 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/discovery/legacy-support.md +86 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/github/service.py +401 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/proposals/analysis.json +95 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/proposals/ready.json +109 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_assemble.py +263 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_check_draft.py +333 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_checks.py +1099 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_discovery.py +817 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_proposal.py +658 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_publish.py +987 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_summary.py +107 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/agent.py +610 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/assemble.py +84 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/check_draft.py +94 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/checks.py +1002 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/discovery.py +789 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/model.py +557 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/progress.py +174 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/prompts/analysis.md +40 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/prompts/proposal.md +65 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/prompts/repair.md +17 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/proposal.py +903 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/publish.py +997 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/summary.py +131 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/tool-versions.json +133 -0
- package/node_modules/package-lock.json +3025 -0
- package/package-lock.json +3025 -0
- package/package.json +52 -4
|
@@ -0,0 +1,1368 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { createHash, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
3
|
+
import { constants as fsConstants } from 'node:fs';
|
|
4
|
+
import { chmod, lstat, mkdtemp, open, realpath, rm } from 'node:fs/promises';
|
|
5
|
+
import { createServer } from 'node:http';
|
|
6
|
+
import { tmpdir } from 'node:os';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { signPayload, verifySignedPayload } from '@loopwright/controller';
|
|
9
|
+
import { assertNoSymlinkSegments, buildGitAuthEnv, COMMIT_SHA_PATTERN, CONTROLLER_ID_PATTERN, DEFAULT_GIT_COMMIT_IDENTITY, ensureCarryBlobsInGitObjectStore, execGit, fetchBoundedText, hasBaselineConflictResource, hasSymlinkAtOrAbove, insideRoot, inspectAndVerifyCandidate, isAllowedCandidateWrite, isPlainRecord, listTreeEntriesAtRevision, MAX_REASON_CODEPOINTS, normalizeCandidateRelativePath, removePathsFromIndex, resolveGitExecutable, SAFE_BRANCH_PATTERN, sanitizeReportText, SecretScrubber, stageEntriesInIndex, truncateCodePoints, validateGitCommitIdentity, validateGitRemoteSource, verifyBaseTreeAnchor, verifyCandidateBaselinePrePublication, } from '@loopwright/taskpack';
|
|
10
|
+
import { GitHubAppError } from './types.js';
|
|
11
|
+
const CAS_STREAM_CHUNK_BYTES = 1_048_576; // 1 MiB
|
|
12
|
+
const MAX_REQUEST_BODY_BYTES = 262_144;
|
|
13
|
+
const LOCAL_GATE_HTTP_HEADERS_TIMEOUT_MS = 60_000;
|
|
14
|
+
const MAX_PROPOSAL_JSON_BYTES = 2 * 1024 * 1024;
|
|
15
|
+
const MAX_PR_BODY_CODEPOINTS = 32_000;
|
|
16
|
+
const MAX_PR_TABLE_CELL_CODEPOINTS = 500;
|
|
17
|
+
const MAX_PR_NOTES_CODEPOINTS = 2_000;
|
|
18
|
+
const MAX_VERSION_TABLE_ENTRIES = 500;
|
|
19
|
+
const MAX_MODIFIED_PATHS_INPUT = 10_000;
|
|
20
|
+
const HEX_DIGEST_VERSION_PATTERN = /^[0-9a-f]{40}(?:[0-9a-f]{24})?$/i;
|
|
21
|
+
const RUNNER_ENGINE_KEYS = ['engine_version', 'engineVersion', 'engine'];
|
|
22
|
+
const RUNNER_PLUGIN_KEYS = ['plugin_version', 'pluginVersion', 'plugin'];
|
|
23
|
+
const RUNNER_SUBSCRIPTION_KEYS = ['status', ...RUNNER_ENGINE_KEYS, ...RUNNER_PLUGIN_KEYS, 'reason'];
|
|
24
|
+
function stripUndefinedFields(value) {
|
|
25
|
+
if (Array.isArray(value))
|
|
26
|
+
return value.map(stripUndefinedFields);
|
|
27
|
+
if (value !== null && typeof value === 'object') {
|
|
28
|
+
const out = {};
|
|
29
|
+
for (const key of Object.keys(value)) {
|
|
30
|
+
const entry = value[key];
|
|
31
|
+
if (entry === undefined)
|
|
32
|
+
continue;
|
|
33
|
+
out[key] = stripUndefinedFields(entry);
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
function canonicalJson(value) {
|
|
40
|
+
const cleaned = stripUndefinedFields(value);
|
|
41
|
+
const serialize = (node) => {
|
|
42
|
+
if (node === null || typeof node !== 'object') {
|
|
43
|
+
if (typeof node === 'number') {
|
|
44
|
+
return JSON.stringify(Object.is(node, -0) ? 0 : node);
|
|
45
|
+
}
|
|
46
|
+
return JSON.stringify(node);
|
|
47
|
+
}
|
|
48
|
+
if (Array.isArray(node))
|
|
49
|
+
return `[${node.map(serialize).join(',')}]`;
|
|
50
|
+
return `{${Object.keys(node).sort().map(key => `${JSON.stringify(key)}:${serialize(node[key])}`).join(',')}}`;
|
|
51
|
+
};
|
|
52
|
+
return serialize(cleaned);
|
|
53
|
+
}
|
|
54
|
+
async function readIncomingBody(req, maxBytes) {
|
|
55
|
+
const chunks = [];
|
|
56
|
+
let total = 0;
|
|
57
|
+
for await (const rawChunk of req) {
|
|
58
|
+
const chunk = Buffer.isBuffer(rawChunk) ? rawChunk : Buffer.from(rawChunk);
|
|
59
|
+
total += chunk.byteLength;
|
|
60
|
+
if (total > maxBytes) {
|
|
61
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', `request body exceeded ${maxBytes} bytes`);
|
|
62
|
+
}
|
|
63
|
+
chunks.push(chunk);
|
|
64
|
+
}
|
|
65
|
+
return Buffer.concat(chunks);
|
|
66
|
+
}
|
|
67
|
+
function writeSignedJsonResponse(res, statusCode, signingSecret, payload) {
|
|
68
|
+
if (res.destroyed || res.writableEnded)
|
|
69
|
+
return;
|
|
70
|
+
const cleaned = stripUndefinedFields(payload);
|
|
71
|
+
const body = Buffer.from(canonicalJson(cleaned), 'utf8');
|
|
72
|
+
const signature = signPayload(signingSecret, body);
|
|
73
|
+
res.writeHead(statusCode, {
|
|
74
|
+
'content-type': 'application/json',
|
|
75
|
+
'content-length': String(body.byteLength),
|
|
76
|
+
'x-loopwright-signature': signature,
|
|
77
|
+
});
|
|
78
|
+
res.end(body);
|
|
79
|
+
}
|
|
80
|
+
function writePlainJsonResponse(res, statusCode, payload) {
|
|
81
|
+
if (res.destroyed || res.writableEnded)
|
|
82
|
+
return;
|
|
83
|
+
const body = Buffer.from(JSON.stringify(payload), 'utf8');
|
|
84
|
+
res.writeHead(statusCode, {
|
|
85
|
+
'content-type': 'application/json',
|
|
86
|
+
'content-length': String(body.byteLength),
|
|
87
|
+
});
|
|
88
|
+
res.end(body);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Anti-TOCTOU single-FD streaming `git -c core.bigFileThreshold=1m hash-object -w --stdin`:
|
|
92
|
+
* Opens `<realRunRoot>/<runId>/artifacts/blobs/sha256/<file.sha256>` ONCE with `O_RDONLY | O_NOFOLLOW`,
|
|
93
|
+
* verifies inode/mode/nlink/size, computes SHA-256 and expected Git blob OID in bounded `1 MiB` positional
|
|
94
|
+
* reads (leaving the kernel file offset at 0), checks pre-spawn stat stability and SHA-256 equality, then
|
|
95
|
+
* passes the pinned regular-file descriptor directly as `stdin` (`S_ISREG`) so Git streams large blobs
|
|
96
|
+
* directly into a packfile via `index_fd()` -> `stream_to_pack()` in constant O(1) RSS, and finally
|
|
97
|
+
* re-verifies `handle.stat()` stability and Git OID equality.
|
|
98
|
+
*/
|
|
99
|
+
async function streamVerifiedCasBlobToGitObject(options) {
|
|
100
|
+
const { realRunRoot, runId, repositoryRoot, objectFormat, file, gitEnv, captureProposalBytes } = options;
|
|
101
|
+
if (!CONTROLLER_ID_PATTERN.test(runId) || runId.length > 128) {
|
|
102
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', `invalid controller runId "${runId}"`);
|
|
103
|
+
}
|
|
104
|
+
const expectedCasDir = join(realRunRoot, runId, 'artifacts', 'blobs', 'sha256');
|
|
105
|
+
const canonicalBlobPath = join(expectedCasDir, file.sha256);
|
|
106
|
+
if (file.canonicalBlobPath !== canonicalBlobPath || !insideRoot(canonicalBlobPath, expectedCasDir)) {
|
|
107
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', `CAS blob path for "${file.name}" does not match canonical run blob directory`);
|
|
108
|
+
}
|
|
109
|
+
assertNoSymlinkSegments(realRunRoot, canonicalBlobPath);
|
|
110
|
+
const before = await lstat(canonicalBlobPath).catch((err) => {
|
|
111
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', `unable to stat CAS blob for "${file.name}": ${err.code ?? err.message}`);
|
|
112
|
+
});
|
|
113
|
+
if (before.isSymbolicLink()
|
|
114
|
+
|| !before.isFile()
|
|
115
|
+
|| before.nlink !== 1
|
|
116
|
+
|| (before.mode & 0o222) !== 0
|
|
117
|
+
|| before.size !== file.byteLength) {
|
|
118
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', `CAS blob for "${file.name}" failed symlink, nlink, read-only, or size verification`);
|
|
119
|
+
}
|
|
120
|
+
const noFollow = 'O_NOFOLLOW' in fsConstants ? fsConstants.O_NOFOLLOW : 0;
|
|
121
|
+
const handle = await open(canonicalBlobPath, fsConstants.O_RDONLY | noFollow).catch((err) => {
|
|
122
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', `unable to open CAS blob for "${file.name}": ${err.code ?? err.message}`);
|
|
123
|
+
});
|
|
124
|
+
try {
|
|
125
|
+
const info = await handle.stat();
|
|
126
|
+
if (!info.isFile()
|
|
127
|
+
|| info.dev !== before.dev
|
|
128
|
+
|| info.ino !== before.ino
|
|
129
|
+
|| info.size !== file.byteLength
|
|
130
|
+
|| info.nlink !== 1
|
|
131
|
+
|| (info.mode & 0o222) !== 0) {
|
|
132
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', `CAS blob descriptor for "${file.name}" failed post-open stat verification`);
|
|
133
|
+
}
|
|
134
|
+
const sha256Hasher = createHash('sha256');
|
|
135
|
+
const gitBlobHasher = createHash(objectFormat).update(`blob ${file.byteLength}\0`);
|
|
136
|
+
const shouldCaptureProposal = captureProposalBytes && file.byteLength <= MAX_PROPOSAL_JSON_BYTES;
|
|
137
|
+
const proposalChunks = shouldCaptureProposal ? [] : null;
|
|
138
|
+
const chunkBuf = Buffer.allocUnsafe(Math.min(CAS_STREAM_CHUNK_BYTES, Math.max(1, file.byteLength)));
|
|
139
|
+
let offset = 0;
|
|
140
|
+
while (offset < file.byteLength) {
|
|
141
|
+
const toRead = Math.min(chunkBuf.byteLength, file.byteLength - offset);
|
|
142
|
+
const { bytesRead } = await handle.read(chunkBuf, 0, toRead, offset);
|
|
143
|
+
if (bytesRead <= 0)
|
|
144
|
+
break;
|
|
145
|
+
const slice = bytesRead === chunkBuf.byteLength ? chunkBuf : chunkBuf.subarray(0, bytesRead);
|
|
146
|
+
offset += bytesRead;
|
|
147
|
+
sha256Hasher.update(slice);
|
|
148
|
+
gitBlobHasher.update(slice);
|
|
149
|
+
if (proposalChunks !== null) {
|
|
150
|
+
proposalChunks.push(Buffer.from(slice));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const trailingProbe = Buffer.allocUnsafe(1);
|
|
154
|
+
const trailing = await handle.read(trailingProbe, 0, 1, offset);
|
|
155
|
+
const midStat = await handle.stat();
|
|
156
|
+
if (offset !== file.byteLength
|
|
157
|
+
|| trailing.bytesRead !== 0
|
|
158
|
+
|| !midStat.isFile()
|
|
159
|
+
|| midStat.dev !== info.dev
|
|
160
|
+
|| midStat.ino !== info.ino
|
|
161
|
+
|| midStat.size !== file.byteLength
|
|
162
|
+
|| midStat.nlink !== 1
|
|
163
|
+
|| (midStat.mode & 0o222) !== 0
|
|
164
|
+
|| midStat.mtimeMs !== info.mtimeMs
|
|
165
|
+
|| midStat.ctimeMs !== info.ctimeMs) {
|
|
166
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', `CAS blob for "${file.name}" mutated or truncated during single-FD read`);
|
|
167
|
+
}
|
|
168
|
+
const actualSha256 = sha256Hasher.digest('hex');
|
|
169
|
+
if (actualSha256 !== file.sha256) {
|
|
170
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', `CAS blob SHA-256 mismatch for "${file.name}" (expected ${file.sha256}, got ${actualSha256})`);
|
|
171
|
+
}
|
|
172
|
+
const expectedGitOid = gitBlobHasher.digest('hex');
|
|
173
|
+
const gitBin = resolveGitExecutable();
|
|
174
|
+
const timeoutMs = Math.min(600_000, Math.max(60_000, Math.ceil(file.byteLength / (4 * 1024 * 1024)) * 1_000 + 30_000));
|
|
175
|
+
const child = spawn(gitBin, ['-c', 'core.hooksPath=/dev/null', '-c', 'core.bigFileThreshold=1m', '-C', repositoryRoot, 'hash-object', '-w', '--stdin'], { env: gitEnv, stdio: [handle.fd, 'pipe', 'pipe'] });
|
|
176
|
+
const stdoutChunks = [];
|
|
177
|
+
const stderrChunks = [];
|
|
178
|
+
let stdoutBytes = 0;
|
|
179
|
+
let stderrBytes = 0;
|
|
180
|
+
let stdoutOverflow = false;
|
|
181
|
+
let timedOut = false;
|
|
182
|
+
const timer = setTimeout(() => {
|
|
183
|
+
timedOut = true;
|
|
184
|
+
child.kill('SIGKILL');
|
|
185
|
+
}, timeoutMs);
|
|
186
|
+
timer.unref?.();
|
|
187
|
+
child.stdout?.on('data', (chunk) => {
|
|
188
|
+
stdoutBytes += chunk.byteLength;
|
|
189
|
+
if (stdoutBytes > 1024) {
|
|
190
|
+
stdoutOverflow = true;
|
|
191
|
+
child.kill('SIGKILL');
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
stdoutChunks.push(chunk);
|
|
195
|
+
});
|
|
196
|
+
child.stderr?.on('data', (chunk) => {
|
|
197
|
+
if (stderrBytes >= 16_384)
|
|
198
|
+
return;
|
|
199
|
+
const take = Math.min(chunk.byteLength, 16_384 - stderrBytes);
|
|
200
|
+
stderrBytes += take;
|
|
201
|
+
stderrChunks.push(chunk.subarray(0, take));
|
|
202
|
+
});
|
|
203
|
+
const exited = new Promise(resolvePromise => {
|
|
204
|
+
let settled = false;
|
|
205
|
+
const finish = (res) => {
|
|
206
|
+
if (settled)
|
|
207
|
+
return;
|
|
208
|
+
settled = true;
|
|
209
|
+
clearTimeout(timer);
|
|
210
|
+
resolvePromise(res);
|
|
211
|
+
};
|
|
212
|
+
child.once('error', err => finish({ code: null, signal: null, spawnError: err.message }));
|
|
213
|
+
child.once('close', (code, signal) => finish({ code, signal, spawnError: null }));
|
|
214
|
+
});
|
|
215
|
+
try {
|
|
216
|
+
const exit = await exited;
|
|
217
|
+
if (exit.spawnError !== null) {
|
|
218
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', `git hash-object failed to spawn: ${exit.spawnError}`);
|
|
219
|
+
}
|
|
220
|
+
if (timedOut) {
|
|
221
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', `git hash-object timed out after ${timeoutMs}ms for "${file.name}"`);
|
|
222
|
+
}
|
|
223
|
+
if (stdoutOverflow) {
|
|
224
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', `git hash-object stdout exceeded limit for "${file.name}"`);
|
|
225
|
+
}
|
|
226
|
+
if (exit.code !== 0 || exit.signal !== null) {
|
|
227
|
+
const stderrText = Buffer.concat(stderrChunks).toString('utf8').trim();
|
|
228
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', `git hash-object exited with ${exit.code ?? exit.signal} for "${file.name}"${stderrText ? `: ${stderrText}` : ''}`);
|
|
229
|
+
}
|
|
230
|
+
const afterStat = await handle.stat();
|
|
231
|
+
if (!afterStat.isFile()
|
|
232
|
+
|| afterStat.dev !== info.dev
|
|
233
|
+
|| afterStat.ino !== info.ino
|
|
234
|
+
|| afterStat.size !== file.byteLength
|
|
235
|
+
|| afterStat.nlink !== 1
|
|
236
|
+
|| (afterStat.mode & 0o222) !== 0
|
|
237
|
+
|| afterStat.mtimeMs !== info.mtimeMs
|
|
238
|
+
|| afterStat.ctimeMs !== info.ctimeMs) {
|
|
239
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', `CAS blob for "${file.name}" mutated during git hash-object`);
|
|
240
|
+
}
|
|
241
|
+
const oidPattern = objectFormat === 'sha1' ? /^[0-9a-f]{40}$/ : /^[0-9a-f]{64}$/;
|
|
242
|
+
const returnedGitOid = Buffer.concat(stdoutChunks).toString('utf8').trim();
|
|
243
|
+
if (!oidPattern.test(returnedGitOid) || returnedGitOid !== expectedGitOid) {
|
|
244
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', `git hash-object OID mismatch for "${file.name}"`);
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
oid: returnedGitOid,
|
|
248
|
+
...(proposalChunks !== null ? { proposalBytes: Buffer.concat(proposalChunks) } : {}),
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
finally {
|
|
252
|
+
clearTimeout(timer);
|
|
253
|
+
if (child.exitCode === null && child.signalCode === null) {
|
|
254
|
+
child.kill('SIGKILL');
|
|
255
|
+
await exited.catch(() => undefined);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
finally {
|
|
260
|
+
await handle.close();
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
function compareLexical(a, b) {
|
|
264
|
+
if (a === b)
|
|
265
|
+
return 0;
|
|
266
|
+
return a < b ? -1 : 1;
|
|
267
|
+
}
|
|
268
|
+
function firstNonEmptyString(...values) {
|
|
269
|
+
for (const value of values) {
|
|
270
|
+
if (typeof value === 'string') {
|
|
271
|
+
const trimmed = value.trim();
|
|
272
|
+
if (trimmed.length > 0)
|
|
273
|
+
return trimmed;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
function toScalarVersionString(value) {
|
|
279
|
+
if (typeof value === 'string')
|
|
280
|
+
return value;
|
|
281
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
282
|
+
return String(value);
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
function firstDefinedEntryField(entry, keys) {
|
|
286
|
+
for (const key of keys) {
|
|
287
|
+
const value = entry[key];
|
|
288
|
+
if (value !== undefined && value !== null)
|
|
289
|
+
return value;
|
|
290
|
+
}
|
|
291
|
+
return undefined;
|
|
292
|
+
}
|
|
293
|
+
function stripDisallowedControls(text, allowNewline) {
|
|
294
|
+
let out = '';
|
|
295
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
296
|
+
const code = text.charCodeAt(i);
|
|
297
|
+
if (code === 10 && allowNewline) {
|
|
298
|
+
out += '\n';
|
|
299
|
+
}
|
|
300
|
+
else if (code === 9 || code === 10 || code === 13) {
|
|
301
|
+
out += ' ';
|
|
302
|
+
}
|
|
303
|
+
else if (code <= 31 || (code >= 127 && code <= 159)) {
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
out += text[i];
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return out;
|
|
311
|
+
}
|
|
312
|
+
function escapeMarkdownTableCell(value, scrubber) {
|
|
313
|
+
if (value === null || value === undefined)
|
|
314
|
+
return '-';
|
|
315
|
+
let raw = '';
|
|
316
|
+
if (typeof value === 'string') {
|
|
317
|
+
raw = scrubber.scrub(value);
|
|
318
|
+
}
|
|
319
|
+
else if (typeof value === 'number' || typeof value === 'boolean') {
|
|
320
|
+
raw = String(value);
|
|
321
|
+
}
|
|
322
|
+
const cleaned = stripDisallowedControls(raw, false)
|
|
323
|
+
.replace(/\s+/g, ' ')
|
|
324
|
+
.trim();
|
|
325
|
+
if (cleaned.length === 0)
|
|
326
|
+
return '-';
|
|
327
|
+
const bounded = truncateCodePoints(cleaned, MAX_PR_TABLE_CELL_CODEPOINTS);
|
|
328
|
+
return bounded.replace(/\\/g, '\\\\').replace(/\|/g, '\\|');
|
|
329
|
+
}
|
|
330
|
+
function escapeInlineCode(raw) {
|
|
331
|
+
return stripDisallowedControls(raw, false).replace(/\s+/g, ' ').trim().replace(/`/g, '\'').replace(/\\/g, '/');
|
|
332
|
+
}
|
|
333
|
+
function escapeMarkdownInlineProse(raw, maxCodePoints) {
|
|
334
|
+
const collapsed = stripDisallowedControls(raw, false).replace(/\s+/g, ' ').trim();
|
|
335
|
+
if (collapsed.length === 0)
|
|
336
|
+
return '';
|
|
337
|
+
const escaped = collapsed
|
|
338
|
+
.replace(/&/g, '&')
|
|
339
|
+
.replace(/\\/g, '\\\\')
|
|
340
|
+
.replace(/([`*_[\]|])/g, '\\$1')
|
|
341
|
+
.replace(/</g, '<')
|
|
342
|
+
.replace(/>/g, '>')
|
|
343
|
+
.replace(/^(#+|[-+])/, '\\$1');
|
|
344
|
+
const bounded = truncateCodePoints(escaped, maxCodePoints);
|
|
345
|
+
if (bounded === escaped)
|
|
346
|
+
return bounded;
|
|
347
|
+
return bounded
|
|
348
|
+
.replace(/&(?:amp|lt|gt|[a-z]{0,3})$/, '')
|
|
349
|
+
.replace(/\\+$/, match => (match.length % 2 === 1 ? match.slice(0, -1) : match))
|
|
350
|
+
.trim();
|
|
351
|
+
}
|
|
352
|
+
function formatInlineCodeTableCell(raw) {
|
|
353
|
+
const cleaned = escapeInlineCode(raw);
|
|
354
|
+
if (cleaned.length === 0)
|
|
355
|
+
return '-';
|
|
356
|
+
const bounded = truncateCodePoints(cleaned, MAX_PR_TABLE_CELL_CODEPOINTS);
|
|
357
|
+
return `\`${bounded.replace(/\\/g, '\\\\').replace(/\|/g, '\\|')}\``;
|
|
358
|
+
}
|
|
359
|
+
function formatVersionTableCell(raw, scrubber) {
|
|
360
|
+
if (raw === null)
|
|
361
|
+
return '-';
|
|
362
|
+
const cleaned = stripDisallowedControls(scrubber.scrub(raw), false).replace(/\s+/g, ' ').trim();
|
|
363
|
+
if (cleaned.length === 0)
|
|
364
|
+
return '-';
|
|
365
|
+
if (HEX_DIGEST_VERSION_PATTERN.test(cleaned)) {
|
|
366
|
+
return `\`${cleaned.slice(0, 12)}\``;
|
|
367
|
+
}
|
|
368
|
+
return formatInlineCodeTableCell(cleaned);
|
|
369
|
+
}
|
|
370
|
+
function sanitizeProposalLeadText(raw) {
|
|
371
|
+
return stripDisallowedControls(raw.replace(/\r\n?/g, '\n'), true).trim();
|
|
372
|
+
}
|
|
373
|
+
function findLastStructuralDetailsOpen(text) {
|
|
374
|
+
const blockIdx = text.lastIndexOf('\n<details>\n');
|
|
375
|
+
if (blockIdx !== -1)
|
|
376
|
+
return blockIdx + 1;
|
|
377
|
+
return text.startsWith('<details>\n') ? 0 : -1;
|
|
378
|
+
}
|
|
379
|
+
function computeVersionDiffStatus(hasBase, previous, target) {
|
|
380
|
+
if (!hasBase)
|
|
381
|
+
return 'Tracked';
|
|
382
|
+
if (previous === null)
|
|
383
|
+
return 'Added';
|
|
384
|
+
if (target === null)
|
|
385
|
+
return 'Removed';
|
|
386
|
+
return previous !== target ? 'Updated' : 'Unchanged';
|
|
387
|
+
}
|
|
388
|
+
function renderVersionDiffTable(rows, options) {
|
|
389
|
+
const headers = [options.primaryHeader];
|
|
390
|
+
if (options.hasSecondary)
|
|
391
|
+
headers.push(options.secondaryHeader);
|
|
392
|
+
if (options.hasBase)
|
|
393
|
+
headers.push('Previous');
|
|
394
|
+
headers.push('Target');
|
|
395
|
+
if (options.hasBase)
|
|
396
|
+
headers.push('Status');
|
|
397
|
+
const lines = [
|
|
398
|
+
`| ${headers.join(' | ')} |`,
|
|
399
|
+
`| ${headers.map(() => '---').join(' | ')} |`,
|
|
400
|
+
];
|
|
401
|
+
for (const row of rows) {
|
|
402
|
+
const cells = [formatInlineCodeTableCell(options.scrubber.scrub(row.id))];
|
|
403
|
+
if (options.hasSecondary) {
|
|
404
|
+
cells.push(row.secondary !== null ? formatInlineCodeTableCell(options.scrubber.scrub(row.secondary)) : '-');
|
|
405
|
+
}
|
|
406
|
+
if (options.hasBase) {
|
|
407
|
+
cells.push(formatVersionTableCell(row.previous, options.scrubber));
|
|
408
|
+
}
|
|
409
|
+
cells.push(formatVersionTableCell(row.target, options.scrubber));
|
|
410
|
+
if (options.hasBase) {
|
|
411
|
+
cells.push(row.status);
|
|
412
|
+
}
|
|
413
|
+
lines.push(`| ${cells.join(' | ')} |`);
|
|
414
|
+
}
|
|
415
|
+
return lines.join('\n');
|
|
416
|
+
}
|
|
417
|
+
function renderVersionChangesSection(rows, options) {
|
|
418
|
+
if (rows.length === 0)
|
|
419
|
+
return null;
|
|
420
|
+
const hasSecondary = rows.some(row => row.secondary !== null);
|
|
421
|
+
const tableOpts = {
|
|
422
|
+
primaryHeader: options.primaryHeader,
|
|
423
|
+
secondaryHeader: options.secondaryHeader,
|
|
424
|
+
hasSecondary,
|
|
425
|
+
hasBase: options.hasBase,
|
|
426
|
+
scrubber: options.scrubber,
|
|
427
|
+
};
|
|
428
|
+
let omittedSuffix = '';
|
|
429
|
+
if (options.omittedKeyCount > 0) {
|
|
430
|
+
const entryWord = options.omittedKeyCount === 1 ? 'entry' : 'entries';
|
|
431
|
+
omittedSuffix = `\n\n_...and ${options.omittedKeyCount} additional version ${entryWord} omitted._`;
|
|
432
|
+
}
|
|
433
|
+
if (!options.hasBase) {
|
|
434
|
+
return `## Version Changes\n\n${renderVersionDiffTable(rows, tableOpts)}${omittedSuffix}`;
|
|
435
|
+
}
|
|
436
|
+
const changed = rows.filter(row => row.status !== 'Unchanged');
|
|
437
|
+
const unchanged = rows.filter(row => row.status === 'Unchanged');
|
|
438
|
+
if (changed.length > 0 && unchanged.length > 0) {
|
|
439
|
+
return [
|
|
440
|
+
'## Version Changes',
|
|
441
|
+
'',
|
|
442
|
+
renderVersionDiffTable(changed, tableOpts),
|
|
443
|
+
'',
|
|
444
|
+
'<details>',
|
|
445
|
+
`<summary>Unchanged ${options.unchangedLabel} (${unchanged.length})</summary>`,
|
|
446
|
+
'',
|
|
447
|
+
renderVersionDiffTable(unchanged, tableOpts),
|
|
448
|
+
'</details>',
|
|
449
|
+
].join('\n') + omittedSuffix;
|
|
450
|
+
}
|
|
451
|
+
if (changed.length === 0 && unchanged.length > 0) {
|
|
452
|
+
return [
|
|
453
|
+
'## Version Changes',
|
|
454
|
+
'',
|
|
455
|
+
`_All ${unchanged.length} ${options.unchangedLabel} match base._`,
|
|
456
|
+
'',
|
|
457
|
+
renderVersionDiffTable(unchanged, tableOpts),
|
|
458
|
+
].join('\n') + omittedSuffix;
|
|
459
|
+
}
|
|
460
|
+
return `## Version Changes\n\n${renderVersionDiffTable(changed, tableOpts)}${omittedSuffix}`;
|
|
461
|
+
}
|
|
462
|
+
function extractUpstreamsMap(record) {
|
|
463
|
+
const map = new Map();
|
|
464
|
+
const raw = record['upstreams'];
|
|
465
|
+
if (!isPlainRecord(raw))
|
|
466
|
+
return map;
|
|
467
|
+
for (const [key, entry] of Object.entries(raw)) {
|
|
468
|
+
if (map.size >= MAX_VERSION_TABLE_ENTRIES)
|
|
469
|
+
break;
|
|
470
|
+
const id = key.trim();
|
|
471
|
+
if (id.length === 0)
|
|
472
|
+
continue;
|
|
473
|
+
if (typeof entry === 'string') {
|
|
474
|
+
map.set(id, { pkg: null, version: entry });
|
|
475
|
+
}
|
|
476
|
+
else if (isPlainRecord(entry)) {
|
|
477
|
+
const version = toScalarVersionString(entry['version']);
|
|
478
|
+
if (version === null)
|
|
479
|
+
continue;
|
|
480
|
+
const pkg = firstNonEmptyString(entry['package']);
|
|
481
|
+
map.set(id, { pkg, version });
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
return map;
|
|
485
|
+
}
|
|
486
|
+
function extractVersionsMap(record) {
|
|
487
|
+
const map = new Map();
|
|
488
|
+
const raw = record['versions'];
|
|
489
|
+
if (!isPlainRecord(raw))
|
|
490
|
+
return map;
|
|
491
|
+
for (const [key, val] of Object.entries(raw)) {
|
|
492
|
+
if (map.size >= MAX_VERSION_TABLE_ENTRIES)
|
|
493
|
+
break;
|
|
494
|
+
const id = key.trim();
|
|
495
|
+
if (id.length === 0)
|
|
496
|
+
continue;
|
|
497
|
+
const version = toScalarVersionString(val);
|
|
498
|
+
if (version !== null) {
|
|
499
|
+
map.set(id, version);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
return map;
|
|
503
|
+
}
|
|
504
|
+
function extractSubscriptionEntryName(item) {
|
|
505
|
+
return firstNonEmptyString(item['subscription'], item['id'], item['name']);
|
|
506
|
+
}
|
|
507
|
+
function extractSubscriptionSources(record, out) {
|
|
508
|
+
if (record === null)
|
|
509
|
+
return;
|
|
510
|
+
const raw = record['subscriptions'];
|
|
511
|
+
if (Array.isArray(raw)) {
|
|
512
|
+
for (const item of raw) {
|
|
513
|
+
if (out.size >= MAX_VERSION_TABLE_ENTRIES)
|
|
514
|
+
break;
|
|
515
|
+
if (!isPlainRecord(item))
|
|
516
|
+
continue;
|
|
517
|
+
const id = extractSubscriptionEntryName(item);
|
|
518
|
+
const source = firstNonEmptyString(item['source']);
|
|
519
|
+
if (id !== null && source !== null && !out.has(id)) {
|
|
520
|
+
out.set(id, source);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
else if (isPlainRecord(raw)) {
|
|
525
|
+
for (const [key, entry] of Object.entries(raw)) {
|
|
526
|
+
if (out.size >= MAX_VERSION_TABLE_ENTRIES)
|
|
527
|
+
break;
|
|
528
|
+
const id = key.trim();
|
|
529
|
+
if (id.length === 0 || !isPlainRecord(entry))
|
|
530
|
+
continue;
|
|
531
|
+
const source = firstNonEmptyString(entry['source']);
|
|
532
|
+
if (source !== null && !out.has(id)) {
|
|
533
|
+
out.set(id, source);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
function collectBoundedOrderedKeys(candidateMap, baseMap) {
|
|
539
|
+
const allOrderedKeys = [...candidateMap.keys()];
|
|
540
|
+
for (const baseKey of baseMap.keys()) {
|
|
541
|
+
if (!candidateMap.has(baseKey)) {
|
|
542
|
+
allOrderedKeys.push(baseKey);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
const orderedKeys = allOrderedKeys.slice(0, MAX_VERSION_TABLE_ENTRIES);
|
|
546
|
+
const omittedKeyCount = Math.max(0, allOrderedKeys.length - MAX_VERSION_TABLE_ENTRIES);
|
|
547
|
+
return { orderedKeys, omittedKeyCount };
|
|
548
|
+
}
|
|
549
|
+
function hasRunnerSubscriptionFields(entry) {
|
|
550
|
+
return RUNNER_SUBSCRIPTION_KEYS.some(key => Object.hasOwn(entry, key) && entry[key] !== undefined);
|
|
551
|
+
}
|
|
552
|
+
export function buildNativePullRequestBody(options) {
|
|
553
|
+
const provenanceFooter = options.scrubber.scrub(`Automated Loopwright update for run \`${options.runId}\` (\`${options.candidateDigest.slice(0, 12)}\`).`);
|
|
554
|
+
if (options.proposalPath === undefined || options.proposalPath.trim().length === 0) {
|
|
555
|
+
return provenanceFooter;
|
|
556
|
+
}
|
|
557
|
+
let cleanProposalPath;
|
|
558
|
+
try {
|
|
559
|
+
cleanProposalPath = normalizeCandidateRelativePath(options.proposalPath.trim().replace(/^(?:\.\/)+/, ''));
|
|
560
|
+
}
|
|
561
|
+
catch {
|
|
562
|
+
return provenanceFooter;
|
|
563
|
+
}
|
|
564
|
+
if (options.stagedPaths !== undefined && !options.stagedPaths.has(cleanProposalPath)) {
|
|
565
|
+
return provenanceFooter;
|
|
566
|
+
}
|
|
567
|
+
const proposalFile = options.files.find(file => file.name === cleanProposalPath);
|
|
568
|
+
if (proposalFile === undefined
|
|
569
|
+
|| proposalFile.bytes.byteLength === 0
|
|
570
|
+
|| proposalFile.bytes.byteLength > MAX_PROPOSAL_JSON_BYTES) {
|
|
571
|
+
return provenanceFooter;
|
|
572
|
+
}
|
|
573
|
+
let parsed;
|
|
574
|
+
try {
|
|
575
|
+
const decoded = new TextDecoder('utf-8', { fatal: true }).decode(proposalFile.bytes);
|
|
576
|
+
parsed = JSON.parse(decoded);
|
|
577
|
+
}
|
|
578
|
+
catch {
|
|
579
|
+
return provenanceFooter;
|
|
580
|
+
}
|
|
581
|
+
if (!isPlainRecord(parsed)) {
|
|
582
|
+
return provenanceFooter;
|
|
583
|
+
}
|
|
584
|
+
let baseParsed = null;
|
|
585
|
+
if (options.baseProposalBytes !== undefined
|
|
586
|
+
&& options.baseProposalBytes.byteLength > 0
|
|
587
|
+
&& options.baseProposalBytes.byteLength <= MAX_PROPOSAL_JSON_BYTES) {
|
|
588
|
+
try {
|
|
589
|
+
const decodedBase = new TextDecoder('utf-8', { fatal: true }).decode(options.baseProposalBytes);
|
|
590
|
+
const candidateBase = JSON.parse(decodedBase);
|
|
591
|
+
if (isPlainRecord(candidateBase)) {
|
|
592
|
+
baseParsed = candidateBase;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
catch {
|
|
596
|
+
baseParsed = null;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
const hasBase = baseParsed !== null;
|
|
600
|
+
const sections = [];
|
|
601
|
+
const summaryParts = [];
|
|
602
|
+
if (typeof parsed['summary'] === 'string') {
|
|
603
|
+
const cleanSummary = sanitizeProposalLeadText(options.scrubber.scrub(parsed['summary']));
|
|
604
|
+
if (cleanSummary.length > 0) {
|
|
605
|
+
summaryParts.push(cleanSummary);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
const metaBullets = [];
|
|
609
|
+
if (typeof parsed['stage'] === 'string') {
|
|
610
|
+
const cleanStage = escapeInlineCode(options.scrubber.scrub(parsed['stage']));
|
|
611
|
+
if (cleanStage.length > 0) {
|
|
612
|
+
metaBullets.push(`- **Stage**: \`${cleanStage}\``);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
if (typeof parsed['notes'] === 'string') {
|
|
616
|
+
const cleanNotes = escapeMarkdownInlineProse(options.scrubber.scrub(parsed['notes']), MAX_PR_NOTES_CODEPOINTS);
|
|
617
|
+
if (cleanNotes.length > 0) {
|
|
618
|
+
metaBullets.push(`- **Notes**: ${cleanNotes}`);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
else if (Array.isArray(parsed['notes'])) {
|
|
622
|
+
const noteItems = [];
|
|
623
|
+
for (const item of parsed['notes']) {
|
|
624
|
+
if (noteItems.length >= 10)
|
|
625
|
+
break;
|
|
626
|
+
if (typeof item !== 'string')
|
|
627
|
+
continue;
|
|
628
|
+
const cleanNote = escapeMarkdownInlineProse(options.scrubber.scrub(item), MAX_PR_TABLE_CELL_CODEPOINTS);
|
|
629
|
+
if (cleanNote.length > 0) {
|
|
630
|
+
noteItems.push(cleanNote);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
if (noteItems.length > 0) {
|
|
634
|
+
metaBullets.push('- **Notes**:');
|
|
635
|
+
for (const note of noteItems) {
|
|
636
|
+
metaBullets.push(` - ${note}`);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
if (metaBullets.length > 0) {
|
|
641
|
+
summaryParts.push(metaBullets.join('\n'));
|
|
642
|
+
}
|
|
643
|
+
if (summaryParts.length > 0) {
|
|
644
|
+
sections.push(`## Summary\n\n${summaryParts.join('\n\n')}`);
|
|
645
|
+
}
|
|
646
|
+
let hasVersionTable = false;
|
|
647
|
+
const candidateUpstreams = extractUpstreamsMap(parsed);
|
|
648
|
+
const baseUpstreams = baseParsed !== null
|
|
649
|
+
? extractUpstreamsMap(baseParsed)
|
|
650
|
+
: new Map();
|
|
651
|
+
if (candidateUpstreams.size > 0 || (hasBase && baseUpstreams.size > 0)) {
|
|
652
|
+
const { orderedKeys, omittedKeyCount } = collectBoundedOrderedKeys(candidateUpstreams, baseUpstreams);
|
|
653
|
+
const rows = orderedKeys.map(id => {
|
|
654
|
+
const cand = candidateUpstreams.get(id);
|
|
655
|
+
const base = baseUpstreams.get(id);
|
|
656
|
+
const previous = base?.version ?? null;
|
|
657
|
+
const target = cand?.version ?? null;
|
|
658
|
+
return {
|
|
659
|
+
id,
|
|
660
|
+
secondary: cand?.pkg ?? base?.pkg ?? null,
|
|
661
|
+
previous,
|
|
662
|
+
target,
|
|
663
|
+
status: computeVersionDiffStatus(hasBase, previous, target),
|
|
664
|
+
};
|
|
665
|
+
});
|
|
666
|
+
const versionSection = renderVersionChangesSection(rows, {
|
|
667
|
+
primaryHeader: 'Upstream',
|
|
668
|
+
secondaryHeader: 'Package',
|
|
669
|
+
hasBase,
|
|
670
|
+
unchangedLabel: 'tracked upstream pins',
|
|
671
|
+
omittedKeyCount,
|
|
672
|
+
scrubber: options.scrubber,
|
|
673
|
+
});
|
|
674
|
+
if (versionSection !== null) {
|
|
675
|
+
sections.push(versionSection);
|
|
676
|
+
hasVersionTable = true;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
if (!hasVersionTable) {
|
|
680
|
+
const candidateVersions = extractVersionsMap(parsed);
|
|
681
|
+
const baseVersions = baseParsed !== null
|
|
682
|
+
? extractVersionsMap(baseParsed)
|
|
683
|
+
: new Map();
|
|
684
|
+
if (candidateVersions.size > 0 || (hasBase && baseVersions.size > 0)) {
|
|
685
|
+
const sourceMap = new Map();
|
|
686
|
+
extractSubscriptionSources(parsed, sourceMap);
|
|
687
|
+
extractSubscriptionSources(baseParsed, sourceMap);
|
|
688
|
+
const { orderedKeys, omittedKeyCount } = collectBoundedOrderedKeys(candidateVersions, baseVersions);
|
|
689
|
+
const rows = orderedKeys.map(id => {
|
|
690
|
+
const previous = baseVersions.get(id) ?? null;
|
|
691
|
+
const target = candidateVersions.get(id) ?? null;
|
|
692
|
+
return {
|
|
693
|
+
id,
|
|
694
|
+
secondary: sourceMap.get(id) ?? null,
|
|
695
|
+
previous,
|
|
696
|
+
target,
|
|
697
|
+
status: computeVersionDiffStatus(hasBase, previous, target),
|
|
698
|
+
};
|
|
699
|
+
});
|
|
700
|
+
const versionSection = renderVersionChangesSection(rows, {
|
|
701
|
+
primaryHeader: 'Component',
|
|
702
|
+
secondaryHeader: 'Source',
|
|
703
|
+
hasBase,
|
|
704
|
+
unchangedLabel: 'tracked versions',
|
|
705
|
+
omittedKeyCount,
|
|
706
|
+
scrubber: options.scrubber,
|
|
707
|
+
});
|
|
708
|
+
if (versionSection !== null) {
|
|
709
|
+
sections.push(versionSection);
|
|
710
|
+
hasVersionTable = true;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
const rawSubscriptions = parsed['subscriptions'];
|
|
715
|
+
const subRows = [];
|
|
716
|
+
if (isPlainRecord(rawSubscriptions)) {
|
|
717
|
+
for (const [key, entry] of Object.entries(rawSubscriptions)) {
|
|
718
|
+
if (subRows.length >= MAX_VERSION_TABLE_ENTRIES)
|
|
719
|
+
break;
|
|
720
|
+
const rawName = key.trim();
|
|
721
|
+
if (rawName.length > 0 && isPlainRecord(entry)) {
|
|
722
|
+
subRows.push({ name: rawName, entry });
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
else if (Array.isArray(rawSubscriptions)) {
|
|
727
|
+
for (const item of rawSubscriptions) {
|
|
728
|
+
if (subRows.length >= MAX_VERSION_TABLE_ENTRIES)
|
|
729
|
+
break;
|
|
730
|
+
if (!isPlainRecord(item))
|
|
731
|
+
continue;
|
|
732
|
+
const rawName = extractSubscriptionEntryName(item);
|
|
733
|
+
if (rawName !== null) {
|
|
734
|
+
subRows.push({ name: rawName, entry: item });
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
if (subRows.length > 0 && (!hasVersionTable || subRows.some(row => hasRunnerSubscriptionFields(row.entry)))) {
|
|
739
|
+
const tableLines = [
|
|
740
|
+
'## Subscriptions',
|
|
741
|
+
'',
|
|
742
|
+
'| Subscription | Status | Engine | Plugin | Reason |',
|
|
743
|
+
'| --- | --- | --- | --- | --- |',
|
|
744
|
+
];
|
|
745
|
+
for (const { name, entry } of subRows) {
|
|
746
|
+
const subCell = escapeMarkdownTableCell(name, options.scrubber);
|
|
747
|
+
const statusCell = escapeMarkdownTableCell(entry['status'], options.scrubber);
|
|
748
|
+
const engineCell = escapeMarkdownTableCell(firstDefinedEntryField(entry, RUNNER_ENGINE_KEYS), options.scrubber);
|
|
749
|
+
const pluginCell = escapeMarkdownTableCell(firstDefinedEntryField(entry, RUNNER_PLUGIN_KEYS), options.scrubber);
|
|
750
|
+
const reasonCell = escapeMarkdownTableCell(entry['reason'], options.scrubber);
|
|
751
|
+
tableLines.push(`| ${subCell} | ${statusCell} | ${engineCell} | ${pluginCell} | ${reasonCell} |`);
|
|
752
|
+
}
|
|
753
|
+
sections.push(tableLines.join('\n'));
|
|
754
|
+
}
|
|
755
|
+
if (options.modifiedPaths !== undefined && options.modifiedPaths.length > 0) {
|
|
756
|
+
const cleanPaths = [];
|
|
757
|
+
const seenPaths = new Set();
|
|
758
|
+
const omittedInputCount = Math.max(0, options.modifiedPaths.length - MAX_MODIFIED_PATHS_INPUT);
|
|
759
|
+
for (const rawPath of options.modifiedPaths.slice(0, MAX_MODIFIED_PATHS_INPUT)) {
|
|
760
|
+
const scrubbedPath = options.scrubber.scrub(rawPath);
|
|
761
|
+
const cleaned = stripDisallowedControls(scrubbedPath, false).replace(/\s+/g, ' ').trim();
|
|
762
|
+
if (cleaned.length > 0 && !seenPaths.has(cleaned)) {
|
|
763
|
+
seenPaths.add(cleaned);
|
|
764
|
+
cleanPaths.push(cleaned);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
if (cleanPaths.length > 0) {
|
|
768
|
+
const count = cleanPaths.length;
|
|
769
|
+
const countLabel = omittedInputCount > 0 ? `${count}+` : String(count);
|
|
770
|
+
const fileLines = [`## Modified Files (${countLabel})`, ''];
|
|
771
|
+
if (count <= 15) {
|
|
772
|
+
for (const p of cleanPaths) {
|
|
773
|
+
fileLines.push(`- \`${escapeInlineCode(p)}\``);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
else {
|
|
777
|
+
const dirCounts = new Map();
|
|
778
|
+
for (const p of cleanPaths) {
|
|
779
|
+
const slashIdx = p.indexOf('/');
|
|
780
|
+
const topDir = slashIdx > 0 ? `${p.slice(0, slashIdx)}/` : '(root)';
|
|
781
|
+
dirCounts.set(topDir, (dirCounts.get(topDir) ?? 0) + 1);
|
|
782
|
+
}
|
|
783
|
+
const sortedDirs = [...dirCounts.entries()].sort((a, b) => compareLexical(a[0], b[0]));
|
|
784
|
+
for (const [dir, dirCount] of sortedDirs) {
|
|
785
|
+
const label = dir === '(root)' ? '`(root)`' : `\`${escapeInlineCode(dir)}\``;
|
|
786
|
+
fileLines.push(`- ${label}: ${dirCount} ${dirCount === 1 ? 'file' : 'files'}`);
|
|
787
|
+
}
|
|
788
|
+
fileLines.push('');
|
|
789
|
+
fileLines.push('<details>');
|
|
790
|
+
fileLines.push(`<summary>View modified files (${countLabel})</summary>`);
|
|
791
|
+
fileLines.push('');
|
|
792
|
+
for (const p of cleanPaths.slice(0, 100)) {
|
|
793
|
+
fileLines.push(`- \`${escapeInlineCode(p)}\``);
|
|
794
|
+
}
|
|
795
|
+
if (cleanPaths.length > 100) {
|
|
796
|
+
fileLines.push(`- ...and ${cleanPaths.length - 100} more`);
|
|
797
|
+
}
|
|
798
|
+
fileLines.push('</details>');
|
|
799
|
+
}
|
|
800
|
+
if (omittedInputCount > 0) {
|
|
801
|
+
const pathWord = omittedInputCount === 1 ? 'path' : 'paths';
|
|
802
|
+
fileLines.push('');
|
|
803
|
+
fileLines.push(`_...and ${omittedInputCount} additional ${pathWord} omitted._`);
|
|
804
|
+
}
|
|
805
|
+
sections.push(fileLines.join('\n'));
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
if (sections.length === 0) {
|
|
809
|
+
return provenanceFooter;
|
|
810
|
+
}
|
|
811
|
+
const scrubbedLead = options.scrubber.scrub(sections.join('\n\n')).trim();
|
|
812
|
+
if (scrubbedLead.length === 0) {
|
|
813
|
+
return provenanceFooter;
|
|
814
|
+
}
|
|
815
|
+
const footerWithSeparator = `\n\n---\n\n${provenanceFooter}`;
|
|
816
|
+
const footerCodePoints = Array.from(footerWithSeparator).length;
|
|
817
|
+
const maxLeadCodePoints = Math.max(1, MAX_PR_BODY_CODEPOINTS - footerCodePoints);
|
|
818
|
+
if (Array.from(scrubbedLead).length <= maxLeadCodePoints) {
|
|
819
|
+
return `${scrubbedLead}${footerWithSeparator}`;
|
|
820
|
+
}
|
|
821
|
+
let boundedLead = truncateCodePoints(scrubbedLead, maxLeadCodePoints);
|
|
822
|
+
boundedLead = boundedLead.replace(/<[a-z/!][^>]*$/i, '').trimEnd();
|
|
823
|
+
const openDetails = findLastStructuralDetailsOpen(boundedLead);
|
|
824
|
+
if (openDetails !== -1 && boundedLead.indexOf('\n</details>', openDetails) === -1) {
|
|
825
|
+
boundedLead = boundedLead.slice(0, openDetails).trimEnd();
|
|
826
|
+
}
|
|
827
|
+
if (boundedLead.length === 0) {
|
|
828
|
+
return provenanceFooter;
|
|
829
|
+
}
|
|
830
|
+
return `${boundedLead}${footerWithSeparator}`;
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* Start a loopback HTTP server implementing Loopwright's signed publication protocol
|
|
834
|
+
* using pure Git index/tree plumbing over a private temporary `GIT_INDEX_FILE`
|
|
835
|
+
* (preserving repository `HEAD`, working tree, `.git/worktrees`, and protected
|
|
836
|
+
* paths/symlinks), single-FD `1 MiB` streaming `git hash-object -w --stdin`,
|
|
837
|
+
* and `--force-with-lease` push protection.
|
|
838
|
+
*/
|
|
839
|
+
export async function startNativePullRequestPublisherServer(options) {
|
|
840
|
+
const commitIdentity = options.gitCommitIdentity !== undefined
|
|
841
|
+
? validateGitCommitIdentity(options.gitCommitIdentity)
|
|
842
|
+
: DEFAULT_GIT_COMMIT_IDENTITY;
|
|
843
|
+
const scrubber = options.scrubber ?? new SecretScrubber();
|
|
844
|
+
const signingSecret = options.signingSecret ?? randomBytes(32).toString('hex');
|
|
845
|
+
const authToken = options.authToken ?? randomBytes(32).toString('hex');
|
|
846
|
+
scrubber.register(signingSecret);
|
|
847
|
+
scrubber.register(authToken);
|
|
848
|
+
if (options.gitWriteToken)
|
|
849
|
+
scrubber.register(options.gitWriteToken);
|
|
850
|
+
const host = options.host ?? '127.0.0.1';
|
|
851
|
+
if (host !== '127.0.0.1' && host !== '::1' && host !== 'localhost') {
|
|
852
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', `native pull request publisher must bind a loopback host, got "${host}"`);
|
|
853
|
+
}
|
|
854
|
+
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
855
|
+
const ownedScratch = options.scratchRoot === undefined;
|
|
856
|
+
const rawScratchBase = options.scratchRoot ?? await mkdtemp(join(tmpdir(), 'loopwright-pub-'));
|
|
857
|
+
await chmod(rawScratchBase, 0o700);
|
|
858
|
+
const scratchBase = await realpath(rawScratchBase);
|
|
859
|
+
const MAX_RECEIPT_CACHE_ENTRIES = 4_096;
|
|
860
|
+
const receiptCache = new Map();
|
|
861
|
+
let lastPublishedPullRequest = null;
|
|
862
|
+
const inFlightReceipts = new Map();
|
|
863
|
+
const expectedBearerBuf = Buffer.from(`Bearer ${authToken}`, 'utf8');
|
|
864
|
+
const server = createServer(async (req, res) => {
|
|
865
|
+
const pathname = (req.url ?? '/').split('?')[0];
|
|
866
|
+
if (req.method !== 'POST' || pathname !== '/publish') {
|
|
867
|
+
writePlainJsonResponse(res, 404, { error: 'not_found' });
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
870
|
+
let rawBody;
|
|
871
|
+
try {
|
|
872
|
+
rawBody = await readIncomingBody(req, MAX_REQUEST_BODY_BYTES);
|
|
873
|
+
}
|
|
874
|
+
catch {
|
|
875
|
+
writePlainJsonResponse(res, 413, { error: 'payload_too_large' });
|
|
876
|
+
return;
|
|
877
|
+
}
|
|
878
|
+
const signatureHeader = req.headers['x-loopwright-signature'];
|
|
879
|
+
const signature = typeof signatureHeader === 'string' ? signatureHeader : '';
|
|
880
|
+
if (!verifySignedPayload(signingSecret, rawBody, signature)) {
|
|
881
|
+
writePlainJsonResponse(res, 401, { error: 'invalid_signature' });
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
884
|
+
const authHeader = req.headers['authorization'];
|
|
885
|
+
const providedBearerBuf = Buffer.from(typeof authHeader === 'string' ? authHeader : '', 'utf8');
|
|
886
|
+
if (providedBearerBuf.length !== expectedBearerBuf.length
|
|
887
|
+
|| !timingSafeEqual(providedBearerBuf, expectedBearerBuf)) {
|
|
888
|
+
writePlainJsonResponse(res, 401, { error: 'invalid_bearer_token' });
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
891
|
+
let request;
|
|
892
|
+
try {
|
|
893
|
+
request = JSON.parse(rawBody.toString('utf8'));
|
|
894
|
+
}
|
|
895
|
+
catch {
|
|
896
|
+
writePlainJsonResponse(res, 400, { error: 'invalid_json' });
|
|
897
|
+
return;
|
|
898
|
+
}
|
|
899
|
+
if (!isPlainRecord(request)) {
|
|
900
|
+
writePlainJsonResponse(res, 400, { error: 'invalid_request' });
|
|
901
|
+
return;
|
|
902
|
+
}
|
|
903
|
+
const storeId = String(request['storeId'] ?? '');
|
|
904
|
+
const runId = String(request['runId'] ?? '');
|
|
905
|
+
const lockHash = request['lockHash'] ?? null;
|
|
906
|
+
const operationId = String(request['operationId'] ?? '');
|
|
907
|
+
const dispatchId = String(request['dispatchId'] ?? '');
|
|
908
|
+
const dispatchGeneration = request['dispatchGeneration'] ?? null;
|
|
909
|
+
const idempotencyKey = String(request['idempotencyKey'] ?? '');
|
|
910
|
+
const candidateDigest = String(request['candidateDigest'] ?? '');
|
|
911
|
+
const cleanRunId = stripDisallowedControls(scrubber.scrub(runId), false).replace(/\s+/g, ' ').trim();
|
|
912
|
+
const rawTitle = typeof request['title'] === 'string'
|
|
913
|
+
? stripDisallowedControls(scrubber.scrub(request['title']), true).trim()
|
|
914
|
+
: '';
|
|
915
|
+
const expandedTemplate = options.titleTemplate?.trim()
|
|
916
|
+
? stripDisallowedControls(scrubber.scrub(options.titleTemplate.trim()
|
|
917
|
+
.replace(/\$\{repository\}/g, options.repositoryFullName)
|
|
918
|
+
.replace(/\$\{runId\}/g, cleanRunId)
|
|
919
|
+
.replace(/\$\{candidateDigest\}/g, candidateDigest.slice(0, 12))), false).replace(/\s+/g, ' ').trim()
|
|
920
|
+
: '';
|
|
921
|
+
const fallbackTitle = `chore(loopwright): automated update (${truncateCodePoints(cleanRunId || 'run', 34)})`;
|
|
922
|
+
const title = scrubber.scrub(firstNonEmptyString(rawTitle, expandedTemplate) ?? fallbackTitle);
|
|
923
|
+
const prTitle = stripDisallowedControls(title, false).replace(/\s+/g, ' ').trim();
|
|
924
|
+
const targetBranch = String(request['targetBranch'] ?? options.targetBranch);
|
|
925
|
+
if (idempotencyKey.length > 0) {
|
|
926
|
+
const cached = receiptCache.get(idempotencyKey);
|
|
927
|
+
if (cached !== undefined) {
|
|
928
|
+
if (cached.storeId !== storeId
|
|
929
|
+
|| cached.runId !== runId
|
|
930
|
+
|| cached.operationId !== operationId
|
|
931
|
+
|| cached.candidateDigest !== candidateDigest) {
|
|
932
|
+
writePlainJsonResponse(res, 409, { error: 'idempotency_key_conflict' });
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
935
|
+
writeSignedJsonResponse(res, 200, signingSecret, cached);
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
938
|
+
const inFlight = inFlightReceipts.get(idempotencyKey);
|
|
939
|
+
if (inFlight !== undefined) {
|
|
940
|
+
if (inFlight.storeId !== storeId
|
|
941
|
+
|| inFlight.runId !== runId
|
|
942
|
+
|| inFlight.operationId !== operationId
|
|
943
|
+
|| inFlight.candidateDigest !== candidateDigest) {
|
|
944
|
+
writePlainJsonResponse(res, 409, { error: 'idempotency_key_conflict' });
|
|
945
|
+
return;
|
|
946
|
+
}
|
|
947
|
+
const sharedReceipt = await inFlight.promise;
|
|
948
|
+
writeSignedJsonResponse(res, 200, signingSecret, sharedReceipt);
|
|
949
|
+
return;
|
|
950
|
+
}
|
|
951
|
+
if (receiptCache.size + inFlightReceipts.size >= MAX_RECEIPT_CACHE_ENTRIES) {
|
|
952
|
+
writePlainJsonResponse(res, 503, { error: 'receipt_cache_exhausted' });
|
|
953
|
+
return;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
const makeReceipt = (outcome, externalUrl, reason) => ({
|
|
957
|
+
version: 1,
|
|
958
|
+
kind: 'publication_receipt',
|
|
959
|
+
storeId,
|
|
960
|
+
runId,
|
|
961
|
+
lockHash,
|
|
962
|
+
operationId,
|
|
963
|
+
dispatchId,
|
|
964
|
+
dispatchGeneration,
|
|
965
|
+
idempotencyKey,
|
|
966
|
+
outcome,
|
|
967
|
+
externalUrl,
|
|
968
|
+
reason,
|
|
969
|
+
candidateDigest,
|
|
970
|
+
});
|
|
971
|
+
let resolveInFlight;
|
|
972
|
+
if (idempotencyKey.length > 0) {
|
|
973
|
+
const inFlightPromise = new Promise(resolveReceipt => {
|
|
974
|
+
resolveInFlight = resolveReceipt;
|
|
975
|
+
});
|
|
976
|
+
inFlightReceipts.set(idempotencyKey, {
|
|
977
|
+
storeId,
|
|
978
|
+
runId,
|
|
979
|
+
operationId,
|
|
980
|
+
candidateDigest,
|
|
981
|
+
promise: inFlightPromise,
|
|
982
|
+
});
|
|
983
|
+
}
|
|
984
|
+
const emitReceipt = (receipt) => {
|
|
985
|
+
if (idempotencyKey.length > 0) {
|
|
986
|
+
receiptCache.set(idempotencyKey, receipt);
|
|
987
|
+
inFlightReceipts.delete(idempotencyKey);
|
|
988
|
+
resolveInFlight?.(receipt);
|
|
989
|
+
}
|
|
990
|
+
writeSignedJsonResponse(res, 200, signingSecret, receipt);
|
|
991
|
+
};
|
|
992
|
+
let workRoot;
|
|
993
|
+
let mutationStarted = false;
|
|
994
|
+
try {
|
|
995
|
+
workRoot = await mkdtemp(join(scratchBase, 'idx-'));
|
|
996
|
+
await chmod(workRoot, 0o700);
|
|
997
|
+
const indexFile = join(workRoot, 'index');
|
|
998
|
+
const gitEnv = buildGitAuthEnv(options.gitWriteToken);
|
|
999
|
+
const gitRepo = (args, extraOpts) => execGit(options.repositoryRoot, args, { env: gitEnv, ...extraOpts });
|
|
1000
|
+
const gitWithIndex = (args, extraOpts) => execGit(options.repositoryRoot, args, { env: { ...gitEnv, GIT_INDEX_FILE: indexFile }, ...extraOpts });
|
|
1001
|
+
const realRunRoot = await realpath(options.runRoot);
|
|
1002
|
+
const snapshot = await inspectAndVerifyCandidate(realRunRoot, runId, candidateDigest, workRoot);
|
|
1003
|
+
const baseRevision = String(request['baseRevision'] ?? snapshot.baseRevision);
|
|
1004
|
+
const sourceRevision = String(request['sourceRevision'] ?? snapshot.sourceRevision);
|
|
1005
|
+
if (!COMMIT_SHA_PATTERN.test(baseRevision) || !COMMIT_SHA_PATTERN.test(sourceRevision)) {
|
|
1006
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', 'baseRevision and sourceRevision must be 40-hex commit SHAs');
|
|
1007
|
+
}
|
|
1008
|
+
const branchName = options.openManagedPr?.headRef ?? `${options.headBranchPrefix}${targetBranch}`;
|
|
1009
|
+
if (!SAFE_BRANCH_PATTERN.test(branchName) || branchName.includes('..') || branchName.startsWith('-')) {
|
|
1010
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', `unsafe target branch name "${branchName}"`);
|
|
1011
|
+
}
|
|
1012
|
+
await gitRepo(['rev-parse', '--verify', '--end-of-options', `${baseRevision}^{commit}`]);
|
|
1013
|
+
await gitRepo(['rev-parse', '--verify', '--end-of-options', `${sourceRevision}^{commit}`]);
|
|
1014
|
+
if (snapshot.manifest.spec.baseTree !== undefined) {
|
|
1015
|
+
await verifyBaseTreeAnchor(options.repositoryRoot, snapshot.manifest.spec.baseTree, gitEnv, sourceRevision);
|
|
1016
|
+
}
|
|
1017
|
+
const baseTreeOid = (await gitRepo(['rev-parse', '--verify', '--end-of-options', `${baseRevision}^{tree}`])).toString('utf8').trim();
|
|
1018
|
+
await gitWithIndex(['read-tree', `${baseRevision}^{tree}`]);
|
|
1019
|
+
const baseEntries = await listTreeEntriesAtRevision(options.repositoryRoot, baseRevision, gitEnv);
|
|
1020
|
+
const sourceEntries = sourceRevision === baseRevision
|
|
1021
|
+
? baseEntries
|
|
1022
|
+
: await listTreeEntriesAtRevision(options.repositoryRoot, sourceRevision, gitEnv);
|
|
1023
|
+
for (const file of snapshot.files) {
|
|
1024
|
+
if (!isAllowedCandidateWrite(file.name, snapshot)) {
|
|
1025
|
+
continue;
|
|
1026
|
+
}
|
|
1027
|
+
if (hasSymlinkAtOrAbove(file.name, baseEntries, sourceEntries)) {
|
|
1028
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', 'Refusing to overwrite symlinked candidate path during native PR publication.');
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
const objectFormat = snapshot.manifest.spec.baseTree?.objectFormat ?? 'sha1';
|
|
1032
|
+
const oidPattern = objectFormat === 'sha1' ? /^[0-9a-f]{40}$/ : /^[0-9a-f]{64}$/;
|
|
1033
|
+
const carriedUpdatesByPath = new Map();
|
|
1034
|
+
let carryRemovalsList = [];
|
|
1035
|
+
let filesToStageInput = snapshot.files;
|
|
1036
|
+
if (sourceRevision !== baseRevision
|
|
1037
|
+
|| (options.extractedConflictPaths?.length ?? 0) > 0
|
|
1038
|
+
|| hasBaselineConflictResource(snapshot.contract)) {
|
|
1039
|
+
const effectiveSnapshot = (snapshot.baseRevision === baseRevision && snapshot.sourceRevision === sourceRevision)
|
|
1040
|
+
? snapshot
|
|
1041
|
+
: { ...snapshot, baseRevision, sourceRevision };
|
|
1042
|
+
const prePub = await verifyCandidateBaselinePrePublication({
|
|
1043
|
+
repositoryRoot: options.repositoryRoot,
|
|
1044
|
+
snapshot: effectiveSnapshot,
|
|
1045
|
+
extractedConflictPaths: options.extractedConflictPaths,
|
|
1046
|
+
scratchRoot: workRoot,
|
|
1047
|
+
gitEnv,
|
|
1048
|
+
scrubber,
|
|
1049
|
+
});
|
|
1050
|
+
carryRemovalsList = prePub.carryRemovals;
|
|
1051
|
+
if (prePub.carryRemovals.length > 0) {
|
|
1052
|
+
await removePathsFromIndex(options.repositoryRoot, indexFile, prePub.carryRemovals, gitEnv);
|
|
1053
|
+
}
|
|
1054
|
+
if (prePub.carryUpdates.length > 0) {
|
|
1055
|
+
await ensureCarryBlobsInGitObjectStore({
|
|
1056
|
+
repositoryRoot: options.repositoryRoot,
|
|
1057
|
+
carryUpdates: prePub.carryUpdates,
|
|
1058
|
+
objectFormat,
|
|
1059
|
+
gitEnv,
|
|
1060
|
+
});
|
|
1061
|
+
await stageEntriesInIndex(options.repositoryRoot, indexFile, prePub.carryUpdates, gitEnv);
|
|
1062
|
+
for (const entry of prePub.carryUpdates) {
|
|
1063
|
+
carriedUpdatesByPath.set(entry.path, entry);
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
filesToStageInput = prePub.reconciledOverlayFiles;
|
|
1067
|
+
}
|
|
1068
|
+
let cleanProposalPath;
|
|
1069
|
+
if (options.proposalPath !== undefined && options.proposalPath.trim().length > 0) {
|
|
1070
|
+
try {
|
|
1071
|
+
cleanProposalPath = normalizeCandidateRelativePath(options.proposalPath.trim().replace(/^(?:\.\/)+/, ''));
|
|
1072
|
+
}
|
|
1073
|
+
catch {
|
|
1074
|
+
cleanProposalPath = undefined;
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
const candidateNames = new Set(snapshot.files.map(file => file.name));
|
|
1078
|
+
const stagedFiles = [];
|
|
1079
|
+
let candidateProposalBytes;
|
|
1080
|
+
for (const file of filesToStageInput) {
|
|
1081
|
+
if (!isAllowedCandidateWrite(file.name, snapshot)) {
|
|
1082
|
+
continue;
|
|
1083
|
+
}
|
|
1084
|
+
const isTargetProposal = cleanProposalPath !== undefined && file.name === cleanProposalPath;
|
|
1085
|
+
let blobOid;
|
|
1086
|
+
if (file.kind === 'cas') {
|
|
1087
|
+
const captureProposalBytes = isTargetProposal && file.byteLength > 0 && file.byteLength <= MAX_PROPOSAL_JSON_BYTES;
|
|
1088
|
+
const streamed = await streamVerifiedCasBlobToGitObject({
|
|
1089
|
+
realRunRoot,
|
|
1090
|
+
runId,
|
|
1091
|
+
repositoryRoot: options.repositoryRoot,
|
|
1092
|
+
objectFormat,
|
|
1093
|
+
file,
|
|
1094
|
+
gitEnv,
|
|
1095
|
+
captureProposalBytes,
|
|
1096
|
+
});
|
|
1097
|
+
blobOid = streamed.oid;
|
|
1098
|
+
if (streamed.proposalBytes !== undefined) {
|
|
1099
|
+
candidateProposalBytes = streamed.proposalBytes;
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
else {
|
|
1103
|
+
const computedGitOid = createHash(objectFormat)
|
|
1104
|
+
.update(`blob ${file.bytes.byteLength}\0`)
|
|
1105
|
+
.update(file.bytes)
|
|
1106
|
+
.digest('hex');
|
|
1107
|
+
blobOid = (await gitRepo(['hash-object', '-w', '--stdin'], { input: Buffer.from(file.bytes) })).toString('utf8').trim();
|
|
1108
|
+
if (!oidPattern.test(blobOid) || blobOid !== computedGitOid) {
|
|
1109
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', `git hash-object returned invalid oid for "${file.name}"`);
|
|
1110
|
+
}
|
|
1111
|
+
if (isTargetProposal && file.bytes.byteLength > 0 && file.bytes.byteLength <= MAX_PROPOSAL_JSON_BYTES) {
|
|
1112
|
+
candidateProposalBytes = file.bytes;
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
const baselineEntryMode = sourceEntries.get(file.name)?.mode ?? baseEntries.get(file.name)?.mode;
|
|
1116
|
+
const mode = file.kind === 'cas'
|
|
1117
|
+
? file.mode
|
|
1118
|
+
: (file.mode ?? (baselineEntryMode === '100755' ? '100755' : '100644'));
|
|
1119
|
+
stagedFiles.push({ path: file.name, mode, oid: blobOid });
|
|
1120
|
+
}
|
|
1121
|
+
const filesToRemove = [];
|
|
1122
|
+
if (snapshot.manifest.spec.baseTree !== undefined) {
|
|
1123
|
+
for (const rawDeleted of snapshot.manifest.spec.deleted ?? []) {
|
|
1124
|
+
const deletedName = normalizeCandidateRelativePath(rawDeleted);
|
|
1125
|
+
if (!candidateNames.has(deletedName)
|
|
1126
|
+
&& isAllowedCandidateWrite(deletedName, snapshot)
|
|
1127
|
+
&& !hasSymlinkAtOrAbove(deletedName, baseEntries, sourceEntries)) {
|
|
1128
|
+
filesToRemove.push(deletedName);
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
else {
|
|
1133
|
+
for (const [sourceName, sourceEntry] of sourceEntries.entries()) {
|
|
1134
|
+
if (sourceEntry.mode !== '100644' && sourceEntry.mode !== '100755')
|
|
1135
|
+
continue;
|
|
1136
|
+
if (!candidateNames.has(sourceName)
|
|
1137
|
+
&& isAllowedCandidateWrite(sourceName, snapshot)
|
|
1138
|
+
&& !hasSymlinkAtOrAbove(sourceName, baseEntries, sourceEntries)) {
|
|
1139
|
+
filesToRemove.push(sourceName);
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
if (filesToRemove.length > 0) {
|
|
1144
|
+
await removePathsFromIndex(options.repositoryRoot, indexFile, filesToRemove, gitEnv);
|
|
1145
|
+
}
|
|
1146
|
+
if (stagedFiles.length > 0) {
|
|
1147
|
+
await stageEntriesInIndex(options.repositoryRoot, indexFile, stagedFiles, gitEnv);
|
|
1148
|
+
}
|
|
1149
|
+
const treeOid = (await gitWithIndex(['write-tree'])).toString('utf8').trim();
|
|
1150
|
+
if (treeOid === baseTreeOid && (options.openManagedPr === undefined || options.openManagedPr === null)) {
|
|
1151
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', 'candidate tree matches base tree; refusing to push empty pull request branch');
|
|
1152
|
+
}
|
|
1153
|
+
let headOid = baseRevision;
|
|
1154
|
+
if (treeOid !== baseTreeOid) {
|
|
1155
|
+
const signoffLine = `Signed-off-by: ${commitIdentity.name} <${commitIdentity.email}>`;
|
|
1156
|
+
const normalizedTitle = title.replace(/\r\n?/g, '\n').trimEnd();
|
|
1157
|
+
const hasExactSignoff = normalizedTitle.split('\n').some(line => line.trim() === signoffLine);
|
|
1158
|
+
const commitMessage = hasExactSignoff
|
|
1159
|
+
? `${normalizedTitle}\n`
|
|
1160
|
+
: `${normalizedTitle}\n\n${signoffLine}\n`;
|
|
1161
|
+
headOid = (await gitRepo([
|
|
1162
|
+
'-c', `user.name=${commitIdentity.name}`,
|
|
1163
|
+
'-c', `user.email=${commitIdentity.email}`,
|
|
1164
|
+
'commit-tree',
|
|
1165
|
+
treeOid,
|
|
1166
|
+
'-p',
|
|
1167
|
+
baseRevision,
|
|
1168
|
+
], { input: commitMessage })).toString('utf8').trim();
|
|
1169
|
+
}
|
|
1170
|
+
const remote = options.remoteUrl ?? 'origin';
|
|
1171
|
+
const remoteKind = remote === 'origin'
|
|
1172
|
+
? 'https'
|
|
1173
|
+
: validateGitRemoteSource(remote);
|
|
1174
|
+
const protocolArgs = remoteKind === 'local-dir'
|
|
1175
|
+
? ['-c', 'protocol.file.allow=always', '-c', 'protocol.ext.allow=never', '-c', 'protocol.ssh.allow=never']
|
|
1176
|
+
: ['-c', 'protocol.ext.allow=never', '-c', 'protocol.ssh.allow=never'];
|
|
1177
|
+
let expectedRemoteOid = '';
|
|
1178
|
+
if (options.openManagedPr !== undefined && options.openManagedPr !== null) {
|
|
1179
|
+
expectedRemoteOid = options.openManagedPr.headSha;
|
|
1180
|
+
}
|
|
1181
|
+
else {
|
|
1182
|
+
const remoteOut = (await gitRepo([...protocolArgs, 'ls-remote', '--', remote, `refs/heads/${branchName}`])).toString('utf8');
|
|
1183
|
+
const existingRef = remoteOut.split(/\r?\n/).some(line => line.trim().length > 0);
|
|
1184
|
+
if (existingRef) {
|
|
1185
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', `refusing to overwrite existing remote branch refs/heads/${branchName} without an associated open managed PR`);
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
mutationStarted = true;
|
|
1189
|
+
await gitRepo([
|
|
1190
|
+
...protocolArgs,
|
|
1191
|
+
'push',
|
|
1192
|
+
`--force-with-lease=refs/heads/${branchName}:${expectedRemoteOid}`,
|
|
1193
|
+
'--',
|
|
1194
|
+
remote,
|
|
1195
|
+
`${headOid}:refs/heads/${branchName}`,
|
|
1196
|
+
], { timeoutMs: 25_000 });
|
|
1197
|
+
let externalUrl = null;
|
|
1198
|
+
let pullRequestNumber = options.openManagedPr?.number ?? null;
|
|
1199
|
+
const apiBaseUrl = options.apiBaseUrl?.trim().replace(/\/+$/, '');
|
|
1200
|
+
if (apiBaseUrl && apiBaseUrl.length > 0) {
|
|
1201
|
+
const apiHeaders = {
|
|
1202
|
+
accept: 'application/vnd.github+json',
|
|
1203
|
+
'content-type': 'application/json',
|
|
1204
|
+
'user-agent': 'loopwright-github-app',
|
|
1205
|
+
};
|
|
1206
|
+
if (options.gitWriteToken) {
|
|
1207
|
+
apiHeaders['authorization'] = `Bearer ${options.gitWriteToken}`;
|
|
1208
|
+
}
|
|
1209
|
+
const stagedPathSet = new Set(stagedFiles.map(entry => entry.path));
|
|
1210
|
+
const finalEntryByPath = new Map();
|
|
1211
|
+
for (const [path, entry] of carriedUpdatesByPath) {
|
|
1212
|
+
finalEntryByPath.set(path, { mode: entry.mode, oid: entry.oid });
|
|
1213
|
+
}
|
|
1214
|
+
for (const entry of stagedFiles) {
|
|
1215
|
+
finalEntryByPath.set(entry.path, { mode: entry.mode, oid: entry.oid });
|
|
1216
|
+
}
|
|
1217
|
+
const modifiedPathSet = new Set();
|
|
1218
|
+
for (const removedPath of carryRemovalsList) {
|
|
1219
|
+
if (!finalEntryByPath.has(removedPath) && baseEntries.has(removedPath)) {
|
|
1220
|
+
modifiedPathSet.add(removedPath);
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
for (const removedPath of filesToRemove) {
|
|
1224
|
+
finalEntryByPath.delete(removedPath);
|
|
1225
|
+
if (baseEntries.has(removedPath)) {
|
|
1226
|
+
modifiedPathSet.add(removedPath);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
for (const [path, finalEntry] of finalEntryByPath) {
|
|
1230
|
+
const baseEntry = baseEntries.get(path);
|
|
1231
|
+
if (baseEntry === undefined || baseEntry.oid !== finalEntry.oid || baseEntry.mode !== finalEntry.mode) {
|
|
1232
|
+
modifiedPathSet.add(path);
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
const modifiedPaths = [...modifiedPathSet].sort(compareLexical);
|
|
1236
|
+
const readBoundedProposalBlob = async (oid, warnLabel) => {
|
|
1237
|
+
if (!/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(oid))
|
|
1238
|
+
return undefined;
|
|
1239
|
+
try {
|
|
1240
|
+
const sizeText = (await gitRepo(['cat-file', '-s', oid])).toString('utf8').trim();
|
|
1241
|
+
const byteSize = Number(sizeText);
|
|
1242
|
+
if (Number.isSafeInteger(byteSize) && byteSize > 0 && byteSize <= MAX_PROPOSAL_JSON_BYTES) {
|
|
1243
|
+
return await execGit(options.repositoryRoot, ['cat-file', 'blob', oid], { env: gitEnv, maxStdoutBytes: MAX_PROPOSAL_JSON_BYTES });
|
|
1244
|
+
}
|
|
1245
|
+
if (warnLabel !== undefined && Number.isSafeInteger(byteSize) && byteSize > MAX_PROPOSAL_JSON_BYTES) {
|
|
1246
|
+
process.stderr.write(`${scrubber.scrub(`[loopwright] warning: ${warnLabel} (${byteSize} bytes) exceeds ${MAX_PROPOSAL_JSON_BYTES} byte limit; falling back to provenance footer`)}\n`);
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
catch (error) {
|
|
1250
|
+
if (warnLabel !== undefined) {
|
|
1251
|
+
const detail = (error instanceof Error ? error.message : String(error)).replace(/[\r\n]+/g, ' ');
|
|
1252
|
+
process.stderr.write(`${scrubber.scrub(`[loopwright] warning: failed to read ${warnLabel} from ${oid}: ${detail}`)}\n`);
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
return undefined;
|
|
1256
|
+
};
|
|
1257
|
+
let baseProposalBytes;
|
|
1258
|
+
if (cleanProposalPath !== undefined) {
|
|
1259
|
+
const baseProposalEntry = baseEntries.get(cleanProposalPath);
|
|
1260
|
+
if (baseProposalEntry !== undefined
|
|
1261
|
+
&& (baseProposalEntry.mode === '100644' || baseProposalEntry.mode === '100755')) {
|
|
1262
|
+
baseProposalBytes = await readBoundedProposalBlob(baseProposalEntry.oid);
|
|
1263
|
+
}
|
|
1264
|
+
if (!stagedPathSet.has(cleanProposalPath)
|
|
1265
|
+
&& !filesToRemove.includes(cleanProposalPath)) {
|
|
1266
|
+
const carriedProposal = carriedUpdatesByPath.get(cleanProposalPath);
|
|
1267
|
+
if (carriedProposal !== undefined) {
|
|
1268
|
+
const carriedBytes = await readBoundedProposalBlob(carriedProposal.oid, `carried proposal "${cleanProposalPath}"`);
|
|
1269
|
+
if (carriedBytes !== undefined) {
|
|
1270
|
+
stagedPathSet.add(cleanProposalPath);
|
|
1271
|
+
candidateProposalBytes = carriedBytes;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
const prBodyFiles = cleanProposalPath !== undefined && candidateProposalBytes !== undefined
|
|
1277
|
+
? [{ name: cleanProposalPath, bytes: candidateProposalBytes }]
|
|
1278
|
+
: [];
|
|
1279
|
+
const prBody = buildNativePullRequestBody({
|
|
1280
|
+
runId,
|
|
1281
|
+
candidateDigest,
|
|
1282
|
+
proposalPath: options.proposalPath,
|
|
1283
|
+
files: prBodyFiles,
|
|
1284
|
+
stagedPaths: stagedPathSet,
|
|
1285
|
+
baseProposalBytes,
|
|
1286
|
+
modifiedPaths,
|
|
1287
|
+
scrubber,
|
|
1288
|
+
});
|
|
1289
|
+
const isUpdate = options.openManagedPr !== undefined && options.openManagedPr !== null;
|
|
1290
|
+
const prUrl = isUpdate
|
|
1291
|
+
? `${apiBaseUrl}/repos/${options.repositoryFullName}/pulls/${options.openManagedPr.number}`
|
|
1292
|
+
: `${apiBaseUrl}/repos/${options.repositoryFullName}/pulls`;
|
|
1293
|
+
const prRes = await fetchBoundedText(prUrl, fetchImpl, apiHeaders, 15_000, scrubber, {
|
|
1294
|
+
method: isUpdate ? 'PATCH' : 'POST',
|
|
1295
|
+
body: JSON.stringify(isUpdate
|
|
1296
|
+
? { title: prTitle, body: prBody }
|
|
1297
|
+
: { title: prTitle, head: branchName, base: targetBranch, body: prBody }),
|
|
1298
|
+
});
|
|
1299
|
+
if (!prRes.ok) {
|
|
1300
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', `pull request API failed (${prRes.status}): ${scrubber.scrub(prRes.text)}`);
|
|
1301
|
+
}
|
|
1302
|
+
const parsedPr = JSON.parse(prRes.text);
|
|
1303
|
+
if (isPlainRecord(parsedPr)) {
|
|
1304
|
+
if (typeof parsedPr['html_url'] === 'string') {
|
|
1305
|
+
externalUrl = parsedPr['html_url'];
|
|
1306
|
+
}
|
|
1307
|
+
const rawPrNumber = parsedPr['number'];
|
|
1308
|
+
if (typeof rawPrNumber === 'number' && Number.isSafeInteger(rawPrNumber) && rawPrNumber > 0) {
|
|
1309
|
+
pullRequestNumber = rawPrNumber;
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
lastPublishedPullRequest = Object.freeze({
|
|
1314
|
+
runId,
|
|
1315
|
+
branchName,
|
|
1316
|
+
headSha: headOid.toLowerCase(),
|
|
1317
|
+
pullRequestUrl: externalUrl,
|
|
1318
|
+
pullRequestNumber,
|
|
1319
|
+
});
|
|
1320
|
+
emitReceipt(makeReceipt('succeeded', externalUrl, null));
|
|
1321
|
+
}
|
|
1322
|
+
catch (error) {
|
|
1323
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
1324
|
+
const scrubbed = truncateCodePoints(sanitizeReportText(detail, { scrub: text => scrubber.scrub(text), singleLine: true }), MAX_REASON_CODEPOINTS);
|
|
1325
|
+
emitReceipt(makeReceipt(mutationStarted ? 'failed' : 'not_executed', null, scrubbed.length > 0 ? scrubbed : 'publication aborted'));
|
|
1326
|
+
}
|
|
1327
|
+
finally {
|
|
1328
|
+
if (workRoot !== undefined) {
|
|
1329
|
+
await rm(workRoot, { recursive: true, force: true }).catch(() => undefined);
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
});
|
|
1333
|
+
server.requestTimeout = 0;
|
|
1334
|
+
server.headersTimeout = LOCAL_GATE_HTTP_HEADERS_TIMEOUT_MS;
|
|
1335
|
+
await new Promise((resolvePromise, reject) => {
|
|
1336
|
+
server.once('error', reject);
|
|
1337
|
+
server.listen(0, host, () => resolvePromise());
|
|
1338
|
+
});
|
|
1339
|
+
const address = server.address();
|
|
1340
|
+
if (address === null || typeof address === 'string') {
|
|
1341
|
+
await new Promise(resolveClose => server.close(() => resolveClose()));
|
|
1342
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', 'native pull request publisher server failed to bind TCP port');
|
|
1343
|
+
}
|
|
1344
|
+
const boundLoopbackHost = host === '127.0.0.1'
|
|
1345
|
+
? '127.0.0.1'
|
|
1346
|
+
: (address.address.includes(':') ? `[${address.address}]` : address.address);
|
|
1347
|
+
const url = `http://${boundLoopbackHost}:${address.port}/publish`;
|
|
1348
|
+
return {
|
|
1349
|
+
url,
|
|
1350
|
+
signingSecret,
|
|
1351
|
+
authToken,
|
|
1352
|
+
endpointPlan: {
|
|
1353
|
+
id: 'default',
|
|
1354
|
+
url,
|
|
1355
|
+
signingCredentialRef: 'taskpack-publication-signing',
|
|
1356
|
+
authCredentialRef: 'taskpack-publication-auth',
|
|
1357
|
+
timeoutMs: 60_000,
|
|
1358
|
+
},
|
|
1359
|
+
getLastPublishedPullRequest: () => lastPublishedPullRequest,
|
|
1360
|
+
close: async () => {
|
|
1361
|
+
server.closeIdleConnections?.();
|
|
1362
|
+
await new Promise(resolveClose => server.close(() => resolveClose()));
|
|
1363
|
+
if (ownedScratch) {
|
|
1364
|
+
await rm(scratchBase, { recursive: true, force: true }).catch(() => undefined);
|
|
1365
|
+
}
|
|
1366
|
+
},
|
|
1367
|
+
};
|
|
1368
|
+
}
|