@gpustack/loopwright 0.0.0-stage → 0.0.2
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 +2083 -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 +1646 -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 +2605 -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 +7313 -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 +3021 -0
- package/package-lock.json +3021 -0
- package/package.json +52 -4
|
@@ -0,0 +1,1658 @@
|
|
|
1
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
+
import { createServer } from 'node:http';
|
|
3
|
+
import { LIMITS } from '@loopwright/core';
|
|
4
|
+
import { assertManifestScopeInvariants, assertMultiTenantManifestAuthority, COMMIT_SHA_PATTERN, DEFAULT_COMMENT_PREFIXES, fetchBoundedText, GITHUB_PROTECTED_AUTOMATION_PATHS, headBranchPrefixesCollide, isGitHubTriggerDeclared, isPlainRecord, loadTaskpackSuite, LOCAL_PROTECTED_AUTOMATION_PATHS, MULTI_TENANT_HOST_POLICY, REPOSITORY_FULL_NAME_PATTERN, resolveGitCommitSha, resolveManifestControlRoot, resolveTaskpackSuite, validateTaskpackV2Manifest, } from '@loopwright/taskpack';
|
|
5
|
+
import { DEFAULT_GITHUB_API_BASE_URL, validateGitHubApiBaseUrl, verifySuiteCommentPullRequest, } from './suite-pr-lookup.js';
|
|
6
|
+
import { SecretScrubber } from './token-broker.js';
|
|
7
|
+
import { intakeWebhookDelivery, verifyWebhookSignature, WebhookDeliveryStore } from './webhook.js';
|
|
8
|
+
import { TenantAdmissionQueue } from './tenant-queue.js';
|
|
9
|
+
import { GitHubAppError, WEBHOOK_DELIVERY_ID_PATTERN, } from './types.js';
|
|
10
|
+
export { assertMultiTenantManifestAuthority, MULTI_TENANT_HOST_POLICY };
|
|
11
|
+
function systemSample() {
|
|
12
|
+
return { wallMs: Date.now(), monotonicMs: (process.hrtime.bigint() / 1000000n).toString() };
|
|
13
|
+
}
|
|
14
|
+
const STATUS_BY_CODE = Object.freeze({
|
|
15
|
+
WEBHOOK_SIGNATURE_INVALID: 401,
|
|
16
|
+
WEBHOOK_PAYLOAD_TOO_LARGE: 413,
|
|
17
|
+
WEBHOOK_DELIVERY_CONFLICT: 409,
|
|
18
|
+
WEBHOOK_DELIVERY_INVALID: 400,
|
|
19
|
+
WEBHOOK_ACTOR_UNAUTHORIZED: 403,
|
|
20
|
+
WEBHOOK_GUIDANCE_INVALID: 403,
|
|
21
|
+
TASKPACK_MANIFEST_INVALID: 400,
|
|
22
|
+
TASKPACK_UNTRUSTED_INTERPOLATION: 400,
|
|
23
|
+
TASKPACK_SCOPE_VIOLATION: 400,
|
|
24
|
+
TASKPACK_HOST_BINDING_INVALID: 400,
|
|
25
|
+
TASKPACK_TRIGGER_UNSUPPORTED: 400,
|
|
26
|
+
TENANT_IDENTITY_INVALID: 400,
|
|
27
|
+
TENANT_BOUNDARY_VIOLATION: 403,
|
|
28
|
+
QUEUE_CAPACITY_EXCEEDED: 429,
|
|
29
|
+
QUEUE_LEASE_FENCED: 409,
|
|
30
|
+
QUEUE_STATE_INVALID: 409,
|
|
31
|
+
TENANT_INSTALLATION_REVOKED: 410,
|
|
32
|
+
TOKEN_BROKER_CONFIG_INVALID: 503,
|
|
33
|
+
TOKEN_SCOPE_VIOLATION: 403,
|
|
34
|
+
TOKEN_SECRET_LEAK_DETECTED: 500,
|
|
35
|
+
TOKEN_TTL_EXCEEDED: 403,
|
|
36
|
+
ACTION_INPUT_INVALID: 400,
|
|
37
|
+
SERVICE_FAULT: 500,
|
|
38
|
+
HOST_PROFILE_UNQUALIFIED: 422,
|
|
39
|
+
HOST_CLOCK_UNTRUSTED: 422,
|
|
40
|
+
STORAGE_PROFILE_INSUFFICIENT: 422,
|
|
41
|
+
MCP_OAUTH_UNSUPPORTED: 422,
|
|
42
|
+
MCP_AUTHENTICATION_REQUIRED: 422,
|
|
43
|
+
PROVIDER_OAUTH_UNSUPPORTED: 422,
|
|
44
|
+
});
|
|
45
|
+
function statusForError(code) {
|
|
46
|
+
return STATUS_BY_CODE[code] ?? 500;
|
|
47
|
+
}
|
|
48
|
+
const TENANT_PATH_PATTERN = /^\/tenants\/([0-9]+)\/([0-9]+)\/([a-z][a-z0-9]*(?:[._-][a-z0-9]+)*)\/(lease|settle)$/;
|
|
49
|
+
const IDENTIFIER_PATTERN = /^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/;
|
|
50
|
+
const SHA256_HEX_PATTERN = /^[0-9a-f]{64}$/;
|
|
51
|
+
const SUPPORTED_WEBHOOK_EVENTS = new Set([
|
|
52
|
+
'issue_comment', 'pull_request_review', 'release', 'schedule', 'workflow_dispatch',
|
|
53
|
+
'repository_dispatch', 'installation', 'installation_repositories',
|
|
54
|
+
]);
|
|
55
|
+
function isClockSample(value) {
|
|
56
|
+
if (!isPlainRecord(value))
|
|
57
|
+
return false;
|
|
58
|
+
return typeof value['wallMs'] === 'number' && typeof value['monotonicMs'] === 'string';
|
|
59
|
+
}
|
|
60
|
+
/** Re-read the revise command binding (comment id, head sha, body digest) from the raw webhook payload. */
|
|
61
|
+
function readReviseBinding(rawBody, overrideHeadSha) {
|
|
62
|
+
try {
|
|
63
|
+
const payload = JSON.parse(rawBody.toString('utf8'));
|
|
64
|
+
if (!isPlainRecord(payload))
|
|
65
|
+
return null;
|
|
66
|
+
const container = payload['comment'] ?? payload['review'];
|
|
67
|
+
if (!isPlainRecord(container))
|
|
68
|
+
return null;
|
|
69
|
+
const id = container['id'];
|
|
70
|
+
const issue = isPlainRecord(payload['issue']) ? payload['issue'] : null;
|
|
71
|
+
const pullRequest = isPlainRecord(payload['pull_request'])
|
|
72
|
+
? payload['pull_request']
|
|
73
|
+
: (issue !== null && isPlainRecord(issue['pull_request']) ? issue['pull_request'] : null);
|
|
74
|
+
const head = pullRequest !== null && isPlainRecord(pullRequest['head']) ? pullRequest['head'] : null;
|
|
75
|
+
const headSha = overrideHeadSha
|
|
76
|
+
?? (head !== null && typeof head['sha'] === 'string' && head['sha'].length > 0 ? head['sha'] : null);
|
|
77
|
+
return {
|
|
78
|
+
commandId: typeof id === 'number' && Number.isSafeInteger(id) && id > 0 ? id : 0,
|
|
79
|
+
headSha: headSha ?? 'unknown',
|
|
80
|
+
commandDigest: createHash('sha256').update(rawBody).digest('hex'),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function canonicalJson(value) {
|
|
88
|
+
if (value === null || typeof value !== 'object') {
|
|
89
|
+
if (typeof value === 'number')
|
|
90
|
+
return JSON.stringify(Object.is(value, -0) ? 0 : value);
|
|
91
|
+
return JSON.stringify(value);
|
|
92
|
+
}
|
|
93
|
+
if (Array.isArray(value))
|
|
94
|
+
return `[${value.map(canonicalJson).join(',')}]`;
|
|
95
|
+
const record = value;
|
|
96
|
+
const keys = Object.keys(record).filter(key => record[key] !== undefined).sort();
|
|
97
|
+
return `{${keys.map(key => `${JSON.stringify(key)}:${canonicalJson(record[key])}`).join(',')}}`;
|
|
98
|
+
}
|
|
99
|
+
function summarizeItem(item) {
|
|
100
|
+
if (item === undefined)
|
|
101
|
+
return null;
|
|
102
|
+
return {
|
|
103
|
+
queueItemId: item.queueItemId,
|
|
104
|
+
runId: item.runId,
|
|
105
|
+
kind: item.kind,
|
|
106
|
+
baseRevision: item.baseRevision,
|
|
107
|
+
...(item.domainId !== undefined ? { domainId: item.domainId } : {}),
|
|
108
|
+
...(item.manifestDigest !== undefined ? { manifestDigest: item.manifestDigest } : {}),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const MAX_TRACKED_FANOUT_DELIVERIES = 4_096;
|
|
112
|
+
function validateSuiteControlPlaneAuthority(suite) {
|
|
113
|
+
if (!isPlainRecord(suite.manifest)
|
|
114
|
+
|| suite.manifest.kind !== 'TaskpackSuite'
|
|
115
|
+
|| !isPlainRecord(suite.manifest.metadata)
|
|
116
|
+
|| !IDENTIFIER_PATTERN.test(suite.manifest.metadata.name)) {
|
|
117
|
+
throw new GitHubAppError('TASKPACK_MANIFEST_INVALID', 'invalid TaskpackSuite manifest bound to control plane', '/');
|
|
118
|
+
}
|
|
119
|
+
if (!Array.isArray(suite.domains) || suite.domains.length < 1) {
|
|
120
|
+
throw new GitHubAppError('TASKPACK_MANIFEST_INVALID', 'suite must contain at least one loaded domain', '/spec/domains');
|
|
121
|
+
}
|
|
122
|
+
if (!Array.isArray(suite.suiteProtectedPaths) || suite.suiteProtectedPaths.length > LIMITS.patterns) {
|
|
123
|
+
throw new GitHubAppError('TASKPACK_MANIFEST_INVALID', `suite-wide mandatory protected path union exceeds ${LIMITS.patterns} patterns`, '/spec/domains');
|
|
124
|
+
}
|
|
125
|
+
const builtInProtectedSet = new Set([
|
|
126
|
+
...LOCAL_PROTECTED_AUTOMATION_PATHS,
|
|
127
|
+
...GITHUB_PROTECTED_AUTOMATION_PATHS,
|
|
128
|
+
]);
|
|
129
|
+
const byDomainId = new Map();
|
|
130
|
+
const byTaskpackName = new Map();
|
|
131
|
+
const prByTarget = new Map();
|
|
132
|
+
for (const [idx, domain] of suite.domains.entries()) {
|
|
133
|
+
if (byDomainId.has(domain.id)) {
|
|
134
|
+
throw new GitHubAppError('TASKPACK_MANIFEST_INVALID', `duplicate suite domain id "${domain.id}"`, `/spec/domains/${idx}/id`);
|
|
135
|
+
}
|
|
136
|
+
if (byTaskpackName.has(domain.manifest.metadata.name)) {
|
|
137
|
+
throw new GitHubAppError('TASKPACK_MANIFEST_INVALID', `duplicate taskpack metadata.name "${domain.manifest.metadata.name}" across suite`, `/spec/domains/${idx}`);
|
|
138
|
+
}
|
|
139
|
+
assertMultiTenantManifestAuthority(domain.manifest);
|
|
140
|
+
if (!Array.isArray(domain.protectedPaths)
|
|
141
|
+
|| domain.protectedPaths.length > LIMITS.patterns
|
|
142
|
+
|| !domain.protectedPaths.includes(suite.suitePath)) {
|
|
143
|
+
throw new GitHubAppError('TASKPACK_MANIFEST_INVALID', `domain "${domain.id}" is missing suite-wide mandatory protected paths`, `/spec/domains/${idx}`);
|
|
144
|
+
}
|
|
145
|
+
const manifestProtectedSet = new Set(domain.manifest.spec.scope.protected);
|
|
146
|
+
for (const requiredProtected of suite.suiteProtectedPaths) {
|
|
147
|
+
if (!builtInProtectedSet.has(requiredProtected) && !manifestProtectedSet.has(requiredProtected)) {
|
|
148
|
+
throw new GitHubAppError('TASKPACK_HOST_BINDING_INVALID', `domain "${domain.id}" manifest is missing suite-augmented protected path "${requiredProtected}"`, `/spec/domains/${idx}/scope/protected`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const resolvedControl = resolveManifestControlRoot(domain.manifest, domain.taskpackPath);
|
|
152
|
+
assertManifestScopeInvariants(domain.manifest, {
|
|
153
|
+
controlRoot: resolvedControl.controlRoot,
|
|
154
|
+
manifestPath: resolvedControl.manifestPath,
|
|
155
|
+
extraProtectedPaths: domain.protectedPaths,
|
|
156
|
+
policyProfile: 'github',
|
|
157
|
+
hostPolicy: MULTI_TENANT_HOST_POLICY,
|
|
158
|
+
enforceHostAuthority: true,
|
|
159
|
+
});
|
|
160
|
+
if (domain.manifest.spec.publication.mode === 'pull_request') {
|
|
161
|
+
const tb = domain.manifest.spec.publication.targetBranch;
|
|
162
|
+
const list = prByTarget.get(tb) ?? [];
|
|
163
|
+
for (const prev of list) {
|
|
164
|
+
const prevPrefix = prev.manifest.spec.publication.mode === 'pull_request'
|
|
165
|
+
? prev.manifest.spec.publication.headBranchPrefix
|
|
166
|
+
: '';
|
|
167
|
+
if (headBranchPrefixesCollide(prevPrefix, domain.manifest.spec.publication.headBranchPrefix)) {
|
|
168
|
+
throw new GitHubAppError('TASKPACK_MANIFEST_INVALID', `domains "${prev.id}" and "${domain.id}" declare colliding headBranchPrefix values on targetBranch "${tb}"`, `/spec/domains/${idx}`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
list.push(domain);
|
|
172
|
+
prByTarget.set(tb, list);
|
|
173
|
+
}
|
|
174
|
+
const canonicalManifest = canonicalJson(domain.manifest);
|
|
175
|
+
const manifestDigest = createHash('sha256').update(canonicalManifest, 'utf8').digest('hex');
|
|
176
|
+
const rec = Object.freeze({
|
|
177
|
+
domain,
|
|
178
|
+
manifestDigest,
|
|
179
|
+
canonicalManifest,
|
|
180
|
+
});
|
|
181
|
+
byDomainId.set(domain.id, rec);
|
|
182
|
+
byTaskpackName.set(domain.manifest.metadata.name, rec);
|
|
183
|
+
}
|
|
184
|
+
return { byDomainId, byTaskpackName };
|
|
185
|
+
}
|
|
186
|
+
function readWebhookInstallationId(payload) {
|
|
187
|
+
const installation = isPlainRecord(payload['installation']) ? payload['installation'] : null;
|
|
188
|
+
const id = installation?.['id'];
|
|
189
|
+
return typeof id === 'number' && Number.isSafeInteger(id) && id > 0 ? id : null;
|
|
190
|
+
}
|
|
191
|
+
function readWebhookRepository(payload) {
|
|
192
|
+
const repository = isPlainRecord(payload['repository']) ? payload['repository'] : null;
|
|
193
|
+
const id = repository?.['id'];
|
|
194
|
+
const fullName = repository?.['full_name'];
|
|
195
|
+
if (typeof id !== 'number'
|
|
196
|
+
|| !Number.isSafeInteger(id)
|
|
197
|
+
|| id <= 0
|
|
198
|
+
|| typeof fullName !== 'string'
|
|
199
|
+
|| !REPOSITORY_FULL_NAME_PATTERN.test(fullName)) {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
return { id, fullName };
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Bounded loopback HTTP control plane: constant-time webhook admission, tenant-scoped lease/settle
|
|
206
|
+
* dispatch with scoped installation tokens, and scrubbed structured JSON on every response.
|
|
207
|
+
*/
|
|
208
|
+
export async function startGitHubAppControlPlane(options) {
|
|
209
|
+
if (options.manifest !== undefined && (options.suite !== undefined || options.suitePath !== undefined)) {
|
|
210
|
+
throw new GitHubAppError('TASKPACK_HOST_BINDING_INVALID', 'control plane cannot bind both single-taskpack manifest and multi-domain suite', '/suite');
|
|
211
|
+
}
|
|
212
|
+
if (options.suite !== undefined && options.suitePath !== undefined) {
|
|
213
|
+
throw new GitHubAppError('TASKPACK_HOST_BINDING_INVALID', 'control plane cannot specify both preloaded suite and suitePath', '/suitePath');
|
|
214
|
+
}
|
|
215
|
+
let effectiveSuite = options.suite;
|
|
216
|
+
if (effectiveSuite === undefined && options.suitePath !== undefined) {
|
|
217
|
+
if (options.repositoryRoot === undefined || options.repositoryRoot.trim().length === 0) {
|
|
218
|
+
throw new GitHubAppError('TASKPACK_HOST_BINDING_INVALID', 'control plane suitePath requires repositoryRoot', '/repositoryRoot');
|
|
219
|
+
}
|
|
220
|
+
effectiveSuite = await loadTaskpackSuite({
|
|
221
|
+
repositoryRoot: options.repositoryRoot,
|
|
222
|
+
suitePath: options.suitePath,
|
|
223
|
+
policyProfile: 'github',
|
|
224
|
+
hostPolicy: MULTI_TENANT_HOST_POLICY,
|
|
225
|
+
enforceHostAuthority: true,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
const suiteRegistry = effectiveSuite !== undefined
|
|
229
|
+
? validateSuiteControlPlaneAuthority(effectiveSuite)
|
|
230
|
+
: null;
|
|
231
|
+
if (options.manifest !== undefined) {
|
|
232
|
+
assertMultiTenantManifestAuthority(options.manifest);
|
|
233
|
+
const resolvedControl = resolveManifestControlRoot(options.manifest, options.manifest.manifestPath);
|
|
234
|
+
assertManifestScopeInvariants(options.manifest, {
|
|
235
|
+
controlRoot: resolvedControl.controlRoot,
|
|
236
|
+
manifestPath: resolvedControl.manifestPath,
|
|
237
|
+
policyProfile: 'github',
|
|
238
|
+
hostPolicy: MULTI_TENANT_HOST_POLICY,
|
|
239
|
+
enforceHostAuthority: true,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
const pinnedManifestCanonical = options.manifest !== undefined
|
|
243
|
+
? canonicalJson(options.manifest)
|
|
244
|
+
: null;
|
|
245
|
+
const effectiveTaskpackId = options.taskpackId ?? options.manifest?.metadata.name;
|
|
246
|
+
const effectiveCommentPrefixes = options.commentPrefixes ?? options.manifest?.spec.triggers.commentPrefixes;
|
|
247
|
+
const effectiveCommentCommands = options.commentCommands ?? options.manifest?.spec.triggers.commentCommands;
|
|
248
|
+
const deliveryStore = options.deliveryStore ?? new WebhookDeliveryStore();
|
|
249
|
+
const queue = options.queue ?? new TenantAdmissionQueue({
|
|
250
|
+
maxPendingPerGroup: options.maxPendingPerGroup,
|
|
251
|
+
leaseDurationMs: options.leaseDurationMs,
|
|
252
|
+
});
|
|
253
|
+
const scrubber = options.scrubber ?? options.tokenBroker?.scrubber ?? new SecretScrubber();
|
|
254
|
+
scrubber.register(options.webhookSecret);
|
|
255
|
+
const queueSummary = { enqueued: 0, coalesced: 0, leased: 0, settled: 0, revoked: 0 };
|
|
256
|
+
const effectiveApiBaseUrl = validateGitHubApiBaseUrl(options.apiBaseUrl ?? DEFAULT_GITHUB_API_BASE_URL, 'ACTION_INPUT_INVALID', '/apiBaseUrl');
|
|
257
|
+
const host = options.host ?? '127.0.0.1';
|
|
258
|
+
const port = options.port ?? 0;
|
|
259
|
+
const webhookPath = options.webhookPath ?? '/webhooks/github';
|
|
260
|
+
const maxPayloadBytes = options.maxPayloadBytes ?? 1_048_576;
|
|
261
|
+
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
262
|
+
const MAX_TOTAL_TRACKED_DELIVERY_LINKS = MAX_TRACKED_FANOUT_DELIVERIES * 4;
|
|
263
|
+
const enqueuedByDeliveryDomain = new Map();
|
|
264
|
+
const fanoutDeliveriesById = new Map();
|
|
265
|
+
const deliveryIdsByQueueItemId = new Map();
|
|
266
|
+
const activeInstRevocationWatches = new Map();
|
|
267
|
+
const activeRepoRevocationWatches = new Map();
|
|
268
|
+
let totalTrackedDeliveryLinks = 0;
|
|
269
|
+
const beginRevocationWatch = (installationId, repositoryId) => {
|
|
270
|
+
const watch = { revoked: false };
|
|
271
|
+
let instSet = activeInstRevocationWatches.get(installationId);
|
|
272
|
+
if (instSet === undefined) {
|
|
273
|
+
instSet = new Set();
|
|
274
|
+
activeInstRevocationWatches.set(installationId, instSet);
|
|
275
|
+
}
|
|
276
|
+
instSet.add(watch);
|
|
277
|
+
const repoKey = `${installationId}:${repositoryId}`;
|
|
278
|
+
let repoSet = activeRepoRevocationWatches.get(repoKey);
|
|
279
|
+
if (repoSet === undefined) {
|
|
280
|
+
repoSet = new Set();
|
|
281
|
+
activeRepoRevocationWatches.set(repoKey, repoSet);
|
|
282
|
+
}
|
|
283
|
+
repoSet.add(watch);
|
|
284
|
+
let released = false;
|
|
285
|
+
return {
|
|
286
|
+
watch,
|
|
287
|
+
release: () => {
|
|
288
|
+
if (released)
|
|
289
|
+
return;
|
|
290
|
+
released = true;
|
|
291
|
+
const curInst = activeInstRevocationWatches.get(installationId);
|
|
292
|
+
if (curInst !== undefined) {
|
|
293
|
+
curInst.delete(watch);
|
|
294
|
+
if (curInst.size === 0)
|
|
295
|
+
activeInstRevocationWatches.delete(installationId);
|
|
296
|
+
}
|
|
297
|
+
const curRepo = activeRepoRevocationWatches.get(repoKey);
|
|
298
|
+
if (curRepo !== undefined) {
|
|
299
|
+
curRepo.delete(watch);
|
|
300
|
+
if (curRepo.size === 0)
|
|
301
|
+
activeRepoRevocationWatches.delete(repoKey);
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
};
|
|
305
|
+
};
|
|
306
|
+
const bumpRevocationGeneration = (installationId, repositoryIds) => {
|
|
307
|
+
if (repositoryIds.length === 0) {
|
|
308
|
+
const instWatches = activeInstRevocationWatches.get(installationId);
|
|
309
|
+
if (instWatches !== undefined) {
|
|
310
|
+
for (const watch of instWatches)
|
|
311
|
+
watch.revoked = true;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
for (const repoId of repositoryIds) {
|
|
316
|
+
const repoWatches = activeRepoRevocationWatches.get(`${installationId}:${repoId}`);
|
|
317
|
+
if (repoWatches !== undefined) {
|
|
318
|
+
for (const watch of repoWatches)
|
|
319
|
+
watch.revoked = true;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
const unlinkQueueItemDelivery = (queueItemId, deliveryId) => {
|
|
325
|
+
const linked = deliveryIdsByQueueItemId.get(queueItemId);
|
|
326
|
+
if (linked !== undefined && linked.delete(deliveryId)) {
|
|
327
|
+
totalTrackedDeliveryLinks = Math.max(0, totalTrackedDeliveryLinks - 1);
|
|
328
|
+
if (linked.size === 0)
|
|
329
|
+
deliveryIdsByQueueItemId.delete(queueItemId);
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
const clearQueueItemLinks = (queueItemId) => {
|
|
333
|
+
const linked = deliveryIdsByQueueItemId.get(queueItemId);
|
|
334
|
+
if (linked === undefined)
|
|
335
|
+
return [];
|
|
336
|
+
const ids = [...linked];
|
|
337
|
+
deliveryIdsByQueueItemId.delete(queueItemId);
|
|
338
|
+
totalTrackedDeliveryLinks = Math.max(0, totalTrackedDeliveryLinks - ids.length);
|
|
339
|
+
return ids;
|
|
340
|
+
};
|
|
341
|
+
const evictDeliveryTracking = (deliveryId) => {
|
|
342
|
+
const state = deliveryStore.getDelivery(deliveryId)?.state;
|
|
343
|
+
const isDeliverySettled = state === undefined || state === 'succeeded';
|
|
344
|
+
const tracked = fanoutDeliveriesById.get(deliveryId);
|
|
345
|
+
if (tracked !== undefined) {
|
|
346
|
+
for (const domainId of tracked.expectedDomains) {
|
|
347
|
+
const rec = enqueuedByDeliveryDomain.get(`${deliveryId}\0${domainId}`);
|
|
348
|
+
if (rec !== undefined && (isDeliverySettled || !rec.reconcileRequired)) {
|
|
349
|
+
enqueuedByDeliveryDomain.delete(`${deliveryId}\0${domainId}`);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
for (const entry of tracked.entriesByDomain.values()) {
|
|
353
|
+
unlinkQueueItemDelivery(entry.queueItemId, deliveryId);
|
|
354
|
+
}
|
|
355
|
+
fanoutDeliveriesById.delete(deliveryId);
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
const evictTerminalFanoutDelivery = () => {
|
|
359
|
+
for (const candidateId of fanoutDeliveriesById.keys()) {
|
|
360
|
+
const state = deliveryStore.getDelivery(candidateId)?.state;
|
|
361
|
+
// Never evict retryable ('failed') deliveries: their completed-domain receipts must stay intact
|
|
362
|
+
// so webhook redelivery does not re-enqueue already-completed domains.
|
|
363
|
+
if (state === undefined || state === 'succeeded') {
|
|
364
|
+
evictDeliveryTracking(candidateId);
|
|
365
|
+
return true;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return false;
|
|
369
|
+
};
|
|
370
|
+
const evictTerminalDeliveryLinks = (neededLinks) => {
|
|
371
|
+
if (totalTrackedDeliveryLinks + neededLinks <= MAX_TOTAL_TRACKED_DELIVERY_LINKS
|
|
372
|
+
&& deliveryIdsByQueueItemId.size < MAX_TOTAL_TRACKED_DELIVERY_LINKS) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
for (const [candidateItemId, linkedIds] of deliveryIdsByQueueItemId.entries()) {
|
|
376
|
+
for (const id of [...linkedIds]) {
|
|
377
|
+
const state = deliveryStore.getDelivery(id)?.state;
|
|
378
|
+
if (state === undefined || state === 'succeeded') {
|
|
379
|
+
unlinkQueueItemDelivery(candidateItemId, id);
|
|
380
|
+
if (totalTrackedDeliveryLinks + neededLinks <= MAX_TOTAL_TRACKED_DELIVERY_LINKS
|
|
381
|
+
&& deliveryIdsByQueueItemId.size < MAX_TOTAL_TRACKED_DELIVERY_LINKS) {
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
const reserveDeliveryLinkCapacity = (neededLinks) => {
|
|
389
|
+
evictTerminalDeliveryLinks(neededLinks);
|
|
390
|
+
if (totalTrackedDeliveryLinks + neededLinks > MAX_TOTAL_TRACKED_DELIVERY_LINKS) {
|
|
391
|
+
throw new GitHubAppError('QUEUE_CAPACITY_EXCEEDED', 'active coalesced delivery tracking capacity exceeded', '/webhooks/github');
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
const trackQueueItemDelivery = (queueItemId, deliveryId) => {
|
|
395
|
+
let set = deliveryIdsByQueueItemId.get(queueItemId);
|
|
396
|
+
if (set !== undefined && set.has(deliveryId))
|
|
397
|
+
return;
|
|
398
|
+
evictTerminalDeliveryLinks(1);
|
|
399
|
+
if (totalTrackedDeliveryLinks + 1 > MAX_TOTAL_TRACKED_DELIVERY_LINKS
|
|
400
|
+
|| (set === undefined && deliveryIdsByQueueItemId.size >= MAX_TOTAL_TRACKED_DELIVERY_LINKS)) {
|
|
401
|
+
throw new GitHubAppError('QUEUE_CAPACITY_EXCEEDED', 'active coalesced delivery tracking capacity exceeded', '/webhooks/github');
|
|
402
|
+
}
|
|
403
|
+
if (set === undefined) {
|
|
404
|
+
set = new Set();
|
|
405
|
+
deliveryIdsByQueueItemId.set(queueItemId, set);
|
|
406
|
+
}
|
|
407
|
+
set.add(deliveryId);
|
|
408
|
+
totalTrackedDeliveryLinks += 1;
|
|
409
|
+
};
|
|
410
|
+
const settleRevokedQueueItems = (cancelledQueueItemIds, fencedQueueItemIds) => {
|
|
411
|
+
const affectedDeliveries = new Set();
|
|
412
|
+
const fencedItemSet = new Set(fencedQueueItemIds);
|
|
413
|
+
for (const queueItemId of cancelledQueueItemIds) {
|
|
414
|
+
for (const deliveryId of clearQueueItemLinks(queueItemId)) {
|
|
415
|
+
affectedDeliveries.add(deliveryId);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
for (const queueItemId of fencedQueueItemIds) {
|
|
419
|
+
for (const deliveryId of clearQueueItemLinks(queueItemId)) {
|
|
420
|
+
affectedDeliveries.add(deliveryId);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
for (const deliveryId of affectedDeliveries) {
|
|
424
|
+
const tracked = fanoutDeliveriesById.get(deliveryId);
|
|
425
|
+
if (tracked !== undefined && tracked.expectedDomains.size > 0) {
|
|
426
|
+
let hasActive = false;
|
|
427
|
+
let hasUnadmitted = false;
|
|
428
|
+
let hasReconcileRequired = false;
|
|
429
|
+
let firstRetryableFailure = null;
|
|
430
|
+
for (const expectedDomainId of tracked.expectedDomains) {
|
|
431
|
+
const fEntry = tracked.entriesByDomain.get(expectedDomainId);
|
|
432
|
+
if (fEntry === undefined) {
|
|
433
|
+
hasUnadmitted = true;
|
|
434
|
+
continue;
|
|
435
|
+
}
|
|
436
|
+
if (fencedItemSet.has(fEntry.queueItemId)) {
|
|
437
|
+
const rec = enqueuedByDeliveryDomain.get(`${deliveryId}\0${expectedDomainId}`);
|
|
438
|
+
if (rec !== undefined)
|
|
439
|
+
rec.reconcileRequired = true;
|
|
440
|
+
hasReconcileRequired = true;
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
443
|
+
const fState = queue.getItem(fEntry.tenant, fEntry.queueItemId)?.state;
|
|
444
|
+
if (fState === undefined) {
|
|
445
|
+
hasUnadmitted = true;
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
if (fState === 'pending' || fState === 'leased') {
|
|
449
|
+
hasActive = true;
|
|
450
|
+
}
|
|
451
|
+
else if (fState === 'reconcile_required') {
|
|
452
|
+
hasReconcileRequired = true;
|
|
453
|
+
}
|
|
454
|
+
else if (fState !== 'completed' && fState !== 'cancelled' && firstRetryableFailure === null) {
|
|
455
|
+
firstRetryableFailure = fState;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
if (!hasActive) {
|
|
459
|
+
if (hasUnadmitted || firstRetryableFailure !== null) {
|
|
460
|
+
deliveryStore.markDeliveryState(deliveryId, 'failed', firstRetryableFailure ?? 'partial_fanout');
|
|
461
|
+
}
|
|
462
|
+
else {
|
|
463
|
+
// Terminal cancellation or fenced reconciliation-only state: settle delivery and release slots.
|
|
464
|
+
void hasReconcileRequired;
|
|
465
|
+
deliveryStore.markDeliveryState(deliveryId, 'succeeded');
|
|
466
|
+
evictDeliveryTracking(deliveryId);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
if (deliveryStore.getDelivery(deliveryId) !== undefined) {
|
|
472
|
+
deliveryStore.markDeliveryState(deliveryId, 'succeeded');
|
|
473
|
+
}
|
|
474
|
+
evictDeliveryTracking(deliveryId);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
const settleExpiredQueueItem = (expiredItem) => {
|
|
479
|
+
const affectedDeliveries = new Set();
|
|
480
|
+
if (expiredItem.deliveryId !== null)
|
|
481
|
+
affectedDeliveries.add(expiredItem.deliveryId);
|
|
482
|
+
for (const deliveryId of clearQueueItemLinks(expiredItem.queueItemId)) {
|
|
483
|
+
affectedDeliveries.add(deliveryId);
|
|
484
|
+
}
|
|
485
|
+
for (const deliveryId of affectedDeliveries) {
|
|
486
|
+
if (expiredItem.domainId !== undefined) {
|
|
487
|
+
const rec = enqueuedByDeliveryDomain.get(`${deliveryId}\0${expiredItem.domainId}`);
|
|
488
|
+
if (rec !== undefined)
|
|
489
|
+
rec.reconcileRequired = true;
|
|
490
|
+
}
|
|
491
|
+
const tracked = fanoutDeliveriesById.get(deliveryId);
|
|
492
|
+
if (tracked !== undefined && tracked.expectedDomains.size > 0) {
|
|
493
|
+
let hasActive = false;
|
|
494
|
+
let hasUnadmitted = false;
|
|
495
|
+
let firstRetryableFailure = null;
|
|
496
|
+
for (const expectedDomainId of tracked.expectedDomains) {
|
|
497
|
+
const fEntry = tracked.entriesByDomain.get(expectedDomainId);
|
|
498
|
+
if (fEntry === undefined) {
|
|
499
|
+
hasUnadmitted = true;
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
const fState = fEntry.queueItemId === expiredItem.queueItemId
|
|
503
|
+
? 'reconcile_required'
|
|
504
|
+
: queue.getItem(fEntry.tenant, fEntry.queueItemId)?.state;
|
|
505
|
+
if (fState === undefined) {
|
|
506
|
+
hasUnadmitted = true;
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
if (fState === 'pending' || fState === 'leased') {
|
|
510
|
+
hasActive = true;
|
|
511
|
+
}
|
|
512
|
+
else if (fState !== 'completed'
|
|
513
|
+
&& fState !== 'cancelled'
|
|
514
|
+
&& fState !== 'reconcile_required'
|
|
515
|
+
&& firstRetryableFailure === null) {
|
|
516
|
+
firstRetryableFailure = fState;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
if (!hasActive) {
|
|
520
|
+
if (hasUnadmitted || firstRetryableFailure !== null) {
|
|
521
|
+
deliveryStore.markDeliveryState(deliveryId, 'failed', firstRetryableFailure ?? 'partial_fanout');
|
|
522
|
+
}
|
|
523
|
+
else {
|
|
524
|
+
deliveryStore.markDeliveryState(deliveryId, 'succeeded');
|
|
525
|
+
evictDeliveryTracking(deliveryId);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
else {
|
|
530
|
+
if (deliveryStore.getDelivery(deliveryId) !== undefined) {
|
|
531
|
+
deliveryStore.markDeliveryState(deliveryId, 'succeeded');
|
|
532
|
+
}
|
|
533
|
+
evictDeliveryTracking(deliveryId);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
queue.setOnLeaseExpiredListener(settleExpiredQueueItem);
|
|
538
|
+
const ensureBoundedFanoutDelivery = (deliveryId, expectedDomainIds) => {
|
|
539
|
+
let existing = fanoutDeliveriesById.get(deliveryId);
|
|
540
|
+
if (existing === undefined) {
|
|
541
|
+
if (fanoutDeliveriesById.size >= MAX_TRACKED_FANOUT_DELIVERIES && !evictTerminalFanoutDelivery()) {
|
|
542
|
+
throw new GitHubAppError('QUEUE_CAPACITY_EXCEEDED', 'active fan-out delivery tracking capacity exceeded', '/webhooks/github');
|
|
543
|
+
}
|
|
544
|
+
existing = {
|
|
545
|
+
expectedDomains: new Set(expectedDomainIds),
|
|
546
|
+
entriesByDomain: new Map(),
|
|
547
|
+
};
|
|
548
|
+
fanoutDeliveriesById.set(deliveryId, existing);
|
|
549
|
+
}
|
|
550
|
+
else {
|
|
551
|
+
for (const id of expectedDomainIds)
|
|
552
|
+
existing.expectedDomains.add(id);
|
|
553
|
+
}
|
|
554
|
+
return existing;
|
|
555
|
+
};
|
|
556
|
+
const respond = (response, status, payload, deliverRaw) => {
|
|
557
|
+
// Scrub before computing content-length: tracked secrets shrink the body. A deliberate raw field
|
|
558
|
+
// (the lease-delivered installation token) is re-inserted after scrubbing as the sanctioned channel.
|
|
559
|
+
const marker = deliverRaw?.marker ?? '';
|
|
560
|
+
const scrubbed = scrubber.scrub(JSON.stringify(payload));
|
|
561
|
+
const body = deliverRaw === undefined ? scrubbed : scrubbed.replace(`"${marker}"`, JSON.stringify(deliverRaw.value));
|
|
562
|
+
response.writeHead(status, {
|
|
563
|
+
'content-type': 'application/json', 'content-length': Buffer.byteLength(body), connection: 'close',
|
|
564
|
+
});
|
|
565
|
+
response.end(body);
|
|
566
|
+
};
|
|
567
|
+
const readBody = async (request) => {
|
|
568
|
+
const chunks = [];
|
|
569
|
+
let size = 0;
|
|
570
|
+
for await (const chunk of request) {
|
|
571
|
+
size += chunk.byteLength;
|
|
572
|
+
if (size > maxPayloadBytes)
|
|
573
|
+
return { ok: false };
|
|
574
|
+
chunks.push(chunk);
|
|
575
|
+
}
|
|
576
|
+
return { ok: true, bytes: Buffer.concat(chunks) };
|
|
577
|
+
};
|
|
578
|
+
const parseJsonBody = async (request) => {
|
|
579
|
+
const raw = await readBody(request);
|
|
580
|
+
if (!raw.ok)
|
|
581
|
+
return { ok: false, status: 413, detail: `request body exceeds ${maxPayloadBytes} bytes` };
|
|
582
|
+
try {
|
|
583
|
+
const parsed = JSON.parse(raw.bytes.toString('utf8'));
|
|
584
|
+
if (!isPlainRecord(parsed)) {
|
|
585
|
+
return { ok: false, status: 400, detail: 'request body must be a JSON object' };
|
|
586
|
+
}
|
|
587
|
+
return { ok: true, body: parsed };
|
|
588
|
+
}
|
|
589
|
+
catch {
|
|
590
|
+
return { ok: false, status: 400, detail: 'request body is not valid JSON' };
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
const respondError = (response, error) => {
|
|
594
|
+
if (error !== null && typeof error === 'object' && 'code' in error) {
|
|
595
|
+
const code = error.code;
|
|
596
|
+
const message = error instanceof Error ? error.message.slice(0, 200) : String(code);
|
|
597
|
+
respond(response, statusForError(code), { error: { code, message } });
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
throw error;
|
|
601
|
+
};
|
|
602
|
+
const server = createServer((request, response) => {
|
|
603
|
+
request.on('error', () => undefined);
|
|
604
|
+
response.on('error', () => undefined);
|
|
605
|
+
void handle(request, response).catch((error) => {
|
|
606
|
+
if (error !== null && typeof error === 'object' && 'code' in error)
|
|
607
|
+
return respondError(response, error);
|
|
608
|
+
const message = error instanceof Error ? error.message.slice(0, 200) : 'unknown control-plane failure';
|
|
609
|
+
respond(response, 500, { error: { code: 'SERVICE_FAULT', message } });
|
|
610
|
+
});
|
|
611
|
+
});
|
|
612
|
+
// Keep-alive socket resets are routine between cycles; they must never crash the control plane.
|
|
613
|
+
server.on('clientError', (error, socket) => {
|
|
614
|
+
if (socket.writable)
|
|
615
|
+
socket.end('HTTP/1.1 400 Bad Request\r\nconnection: close\r\n\r\n');
|
|
616
|
+
else
|
|
617
|
+
socket.destroy();
|
|
618
|
+
void error;
|
|
619
|
+
});
|
|
620
|
+
const handleSuiteWebhook = async (suite, registry, request, response, rawBytes, headerDeliveryId) => {
|
|
621
|
+
const eventName = String(request.headers['x-github-event'] ?? '');
|
|
622
|
+
const signatureHeader = request.headers['x-hub-signature-256'];
|
|
623
|
+
if (eventName === 'installation' || eventName === 'installation_repositories') {
|
|
624
|
+
const revOutcome = intakeWebhookDelivery({
|
|
625
|
+
rawBody: rawBytes,
|
|
626
|
+
signatureHeader,
|
|
627
|
+
secret: options.webhookSecret,
|
|
628
|
+
eventName,
|
|
629
|
+
deliveryId: headerDeliveryId,
|
|
630
|
+
receivedAtMs: Date.now(),
|
|
631
|
+
operatorAllowlist: options.operatorAllowlist,
|
|
632
|
+
}, deliveryStore);
|
|
633
|
+
if (revOutcome.kind === 'signature_rejected') {
|
|
634
|
+
return respond(response, revOutcome.code === 'WEBHOOK_PAYLOAD_TOO_LARGE' ? 413 : 401, { error: { code: revOutcome.code, message: revOutcome.detail } });
|
|
635
|
+
}
|
|
636
|
+
if (revOutcome.kind === 'delivery_conflict') {
|
|
637
|
+
return respond(response, 409, { error: { code: 'WEBHOOK_DELIVERY_CONFLICT', message: revOutcome.detail } });
|
|
638
|
+
}
|
|
639
|
+
if (revOutcome.kind === 'duplicate') {
|
|
640
|
+
return respond(response, 200, { kind: 'duplicate', state: revOutcome.state, deliveryId: revOutcome.entry.deliveryId, attemptCount: revOutcome.entry.attemptCount });
|
|
641
|
+
}
|
|
642
|
+
if (revOutcome.kind === 'ignored') {
|
|
643
|
+
if (deliveryStore.getDelivery(headerDeliveryId) !== undefined)
|
|
644
|
+
deliveryStore.markDeliveryState(headerDeliveryId, 'succeeded');
|
|
645
|
+
return respond(response, 200, { kind: 'ignored', reason: revOutcome.reason });
|
|
646
|
+
}
|
|
647
|
+
if (revOutcome.kind === 'revoked') {
|
|
648
|
+
const installationId = revOutcome.installationId ?? 0;
|
|
649
|
+
const revoked = revOutcome.repositoryIds.length === 0
|
|
650
|
+
? queue.revokeInstallationScope(installationId)
|
|
651
|
+
: queue.revokeRepositoryScope(installationId, revOutcome.repositoryIds);
|
|
652
|
+
bumpRevocationGeneration(installationId, revOutcome.repositoryIds);
|
|
653
|
+
settleRevokedQueueItems(revoked.cancelledQueueItemIds, revoked.fencedQueueItemIds);
|
|
654
|
+
if (options.tokenBroker !== undefined) {
|
|
655
|
+
if (revOutcome.repositoryIds.length === 0)
|
|
656
|
+
options.tokenBroker.revokeInstallationTokens(installationId);
|
|
657
|
+
else
|
|
658
|
+
options.tokenBroker.revokeRepositoryTokens(installationId, revOutcome.repositoryIds);
|
|
659
|
+
}
|
|
660
|
+
queueSummary.revoked += 1;
|
|
661
|
+
if (deliveryStore.getDelivery(headerDeliveryId) !== undefined)
|
|
662
|
+
deliveryStore.markDeliveryState(headerDeliveryId, 'succeeded');
|
|
663
|
+
return respond(response, 202, {
|
|
664
|
+
kind: 'revoked',
|
|
665
|
+
installationId: revOutcome.installationId,
|
|
666
|
+
repositoryIds: revOutcome.repositoryIds,
|
|
667
|
+
cancelled: revoked.cancelled,
|
|
668
|
+
fenced: revoked.fenced,
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
return respond(response, 200, { kind: 'ignored', reason: 'unhandled revocation state' });
|
|
672
|
+
}
|
|
673
|
+
const verification = verifyWebhookSignature(rawBytes, signatureHeader, options.webhookSecret);
|
|
674
|
+
if (!verification.ok) {
|
|
675
|
+
return respond(response, verification.code === 'WEBHOOK_PAYLOAD_TOO_LARGE' ? 413 : 401, {
|
|
676
|
+
error: { code: verification.code, message: verification.detail },
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
if (!WEBHOOK_DELIVERY_ID_PATTERN.test(headerDeliveryId)) {
|
|
680
|
+
throw new GitHubAppError('WEBHOOK_DELIVERY_INVALID', `delivery id "${headerDeliveryId}" must match ^[A-Za-z0-9-]{8,128}$`);
|
|
681
|
+
}
|
|
682
|
+
let payload;
|
|
683
|
+
try {
|
|
684
|
+
const parsed = JSON.parse(rawBytes.toString('utf8'));
|
|
685
|
+
if (!isPlainRecord(parsed)) {
|
|
686
|
+
return respond(response, 200, { kind: 'ignored', reason: 'payload is not a JSON object' });
|
|
687
|
+
}
|
|
688
|
+
payload = parsed;
|
|
689
|
+
}
|
|
690
|
+
catch {
|
|
691
|
+
return respond(response, 200, { kind: 'ignored', reason: 'payload is not valid JSON' });
|
|
692
|
+
}
|
|
693
|
+
if (!SUPPORTED_WEBHOOK_EVENTS.has(eventName)) {
|
|
694
|
+
return respond(response, 200, { kind: 'ignored', reason: `unsupported event ${eventName}` });
|
|
695
|
+
}
|
|
696
|
+
const installationId = readWebhookInstallationId(payload);
|
|
697
|
+
if (installationId === null) {
|
|
698
|
+
return respond(response, 200, { kind: 'ignored', reason: 'missing installation attribution' });
|
|
699
|
+
}
|
|
700
|
+
const repository = readWebhookRepository(payload);
|
|
701
|
+
if (repository === null) {
|
|
702
|
+
return respond(response, 200, { kind: 'ignored', reason: 'missing repository attribution' });
|
|
703
|
+
}
|
|
704
|
+
let delivery;
|
|
705
|
+
try {
|
|
706
|
+
delivery = deliveryStore.recordDelivery({
|
|
707
|
+
deliveryId: headerDeliveryId,
|
|
708
|
+
eventName,
|
|
709
|
+
payloadDigest: verification.payloadDigest,
|
|
710
|
+
installationId,
|
|
711
|
+
repositoryFullName: repository.fullName,
|
|
712
|
+
receivedAtMs: Date.now(),
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
catch (error) {
|
|
716
|
+
if (error instanceof GitHubAppError && error.code === 'WEBHOOK_DELIVERY_CONFLICT') {
|
|
717
|
+
return respond(response, 409, { error: { code: 'WEBHOOK_DELIVERY_CONFLICT', message: error.message } });
|
|
718
|
+
}
|
|
719
|
+
throw error;
|
|
720
|
+
}
|
|
721
|
+
if (delivery.kind === 'duplicate') {
|
|
722
|
+
return respond(response, 200, {
|
|
723
|
+
kind: 'duplicate',
|
|
724
|
+
state: delivery.state,
|
|
725
|
+
deliveryId: delivery.entry.deliveryId,
|
|
726
|
+
attemptCount: delivery.entry.attemptCount,
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
const entry = delivery.entry;
|
|
730
|
+
const admissionWatch = beginRevocationWatch(installationId, repository.id);
|
|
731
|
+
try {
|
|
732
|
+
let matchedDomains;
|
|
733
|
+
let action = 'discover';
|
|
734
|
+
let verifiedPrHeadSha;
|
|
735
|
+
let verifiedPrBaseSha;
|
|
736
|
+
let deferredCellsOut = [];
|
|
737
|
+
const mintReadOnlyToken = async (targetTaskpackId) => {
|
|
738
|
+
if (options.tokenBroker === undefined)
|
|
739
|
+
return undefined;
|
|
740
|
+
const lookupTenant = {
|
|
741
|
+
installationId,
|
|
742
|
+
repositoryId: repository.id,
|
|
743
|
+
repositoryFullName: repository.fullName,
|
|
744
|
+
taskpackId: targetTaskpackId ?? suite.domains[0].manifest.metadata.name,
|
|
745
|
+
};
|
|
746
|
+
const minted = await options.tokenBroker.mint(lookupTenant, 'read_only');
|
|
747
|
+
scrubber.register(minted.token);
|
|
748
|
+
return minted.token;
|
|
749
|
+
};
|
|
750
|
+
const resolvedBranchShas = new Map();
|
|
751
|
+
let cachedDefaultBranch;
|
|
752
|
+
const resolveRepositoryDefaultBranch = async (targetTaskpackId) => {
|
|
753
|
+
if (typeof cachedDefaultBranch === 'string')
|
|
754
|
+
return { ok: true, branch: cachedDefaultBranch };
|
|
755
|
+
const repoObj = isPlainRecord(payload['repository']) ? payload['repository'] : null;
|
|
756
|
+
const payloadDefault = typeof repoObj?.['default_branch'] === 'string' ? repoObj['default_branch'].trim() : '';
|
|
757
|
+
if (payloadDefault.length > 0) {
|
|
758
|
+
cachedDefaultBranch = payloadDefault;
|
|
759
|
+
return { ok: true, branch: payloadDefault };
|
|
760
|
+
}
|
|
761
|
+
if (options.tokenBroker !== undefined) {
|
|
762
|
+
try {
|
|
763
|
+
const token = await mintReadOnlyToken(targetTaskpackId);
|
|
764
|
+
const headers = {
|
|
765
|
+
accept: 'application/vnd.github+json',
|
|
766
|
+
'user-agent': 'loopwright-github-app',
|
|
767
|
+
...(token !== undefined ? { authorization: `Bearer ${token}` } : {}),
|
|
768
|
+
};
|
|
769
|
+
const res = await fetchBoundedText(`${effectiveApiBaseUrl}/repos/${repository.fullName}`, fetchImpl, headers, 15_000, scrubber);
|
|
770
|
+
if (!res.ok) {
|
|
771
|
+
return {
|
|
772
|
+
ok: false,
|
|
773
|
+
status: 502,
|
|
774
|
+
message: scrubber.scrub(`failed to query repository default branch (HTTP ${res.status})`),
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
const parsedRepo = JSON.parse(res.text);
|
|
778
|
+
const defBranch = isPlainRecord(parsedRepo) && typeof parsedRepo['default_branch'] === 'string'
|
|
779
|
+
? parsedRepo['default_branch'].trim()
|
|
780
|
+
: '';
|
|
781
|
+
if (defBranch.length > 0) {
|
|
782
|
+
cachedDefaultBranch = defBranch;
|
|
783
|
+
return { ok: true, branch: defBranch };
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
catch (error) {
|
|
787
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
788
|
+
return {
|
|
789
|
+
ok: false,
|
|
790
|
+
status: 502,
|
|
791
|
+
message: scrubber.scrub(`failed to query repository default branch: ${detail}`),
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
if (options.repositoryRoot !== undefined) {
|
|
796
|
+
cachedDefaultBranch = 'HEAD';
|
|
797
|
+
return { ok: true, branch: 'HEAD' };
|
|
798
|
+
}
|
|
799
|
+
return {
|
|
800
|
+
ok: false,
|
|
801
|
+
status: 400,
|
|
802
|
+
message: scrubber.scrub('cannot determine repository default branch for publication-disabled domain'),
|
|
803
|
+
};
|
|
804
|
+
};
|
|
805
|
+
const resolveRefToCommitSha = async (refName, targetTaskpackId) => {
|
|
806
|
+
const trimmedRef = refName.trim();
|
|
807
|
+
if (COMMIT_SHA_PATTERN.test(trimmedRef)) {
|
|
808
|
+
return { ok: true, sha: trimmedRef.toLowerCase() };
|
|
809
|
+
}
|
|
810
|
+
const cached = resolvedBranchShas.get(trimmedRef);
|
|
811
|
+
if (cached !== undefined)
|
|
812
|
+
return { ok: true, sha: cached };
|
|
813
|
+
if (options.tokenBroker !== undefined && trimmedRef !== 'HEAD') {
|
|
814
|
+
try {
|
|
815
|
+
const token = await mintReadOnlyToken(targetTaskpackId);
|
|
816
|
+
const headers = {
|
|
817
|
+
accept: 'application/vnd.github+json',
|
|
818
|
+
'user-agent': 'loopwright-github-app',
|
|
819
|
+
...(token !== undefined ? { authorization: `Bearer ${token}` } : {}),
|
|
820
|
+
};
|
|
821
|
+
const normalizedBranch = trimmedRef.replace(/^refs\/heads\//, '');
|
|
822
|
+
const refPath = normalizedBranch.split('/').map(seg => encodeURIComponent(seg)).join('/');
|
|
823
|
+
const res = await fetchBoundedText(`${effectiveApiBaseUrl}/repos/${repository.fullName}/git/ref/heads/${refPath}`, fetchImpl, headers, 15_000, scrubber);
|
|
824
|
+
if (!res.ok) {
|
|
825
|
+
return {
|
|
826
|
+
ok: false,
|
|
827
|
+
status: 502,
|
|
828
|
+
message: scrubber.scrub(`failed to resolve branch "${trimmedRef}" head SHA (HTTP ${res.status})`),
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
const parsedRef = JSON.parse(res.text);
|
|
832
|
+
const obj = isPlainRecord(parsedRef) && isPlainRecord(parsedRef['object']) ? parsedRef['object'] : null;
|
|
833
|
+
const sha = typeof obj?.['sha'] === 'string' ? obj['sha'].trim() : '';
|
|
834
|
+
if (!COMMIT_SHA_PATTERN.test(sha)) {
|
|
835
|
+
return {
|
|
836
|
+
ok: false,
|
|
837
|
+
status: 502,
|
|
838
|
+
message: scrubber.scrub(`GitHub ref response for "${trimmedRef}" did not contain a valid 40-hex commit SHA`),
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
const lower = sha.toLowerCase();
|
|
842
|
+
resolvedBranchShas.set(trimmedRef, lower);
|
|
843
|
+
return { ok: true, sha: lower };
|
|
844
|
+
}
|
|
845
|
+
catch (error) {
|
|
846
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
847
|
+
return {
|
|
848
|
+
ok: false,
|
|
849
|
+
status: 502,
|
|
850
|
+
message: scrubber.scrub(`failed to resolve branch "${trimmedRef}" head SHA: ${detail}`),
|
|
851
|
+
};
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
if (options.repositoryRoot !== undefined) {
|
|
855
|
+
try {
|
|
856
|
+
const localSha = await resolveGitCommitSha(options.repositoryRoot, trimmedRef, 15_000);
|
|
857
|
+
resolvedBranchShas.set(trimmedRef, localSha);
|
|
858
|
+
return { ok: true, sha: localSha };
|
|
859
|
+
}
|
|
860
|
+
catch {
|
|
861
|
+
// Fall through to fail-closed error below.
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
return {
|
|
865
|
+
ok: false,
|
|
866
|
+
status: 400,
|
|
867
|
+
message: scrubber.scrub(`cannot establish pinned baseRevision commit SHA for ref "${trimmedRef}"`),
|
|
868
|
+
};
|
|
869
|
+
};
|
|
870
|
+
const resolveTargetBranchBaseSha = async (domain) => {
|
|
871
|
+
if (options.baseRevision !== undefined && options.baseRevision.trim().length > 0) {
|
|
872
|
+
const overrideRes = await resolveRefToCommitSha(options.baseRevision, domain.manifest.metadata.name);
|
|
873
|
+
if (!overrideRes.ok)
|
|
874
|
+
return overrideRes;
|
|
875
|
+
if (action !== 'status'
|
|
876
|
+
&& verifiedPrBaseSha !== undefined
|
|
877
|
+
&& COMMIT_SHA_PATTERN.test(verifiedPrBaseSha)
|
|
878
|
+
&& overrideRes.sha.toLowerCase() !== verifiedPrBaseSha.toLowerCase()) {
|
|
879
|
+
return {
|
|
880
|
+
ok: false,
|
|
881
|
+
status: 400,
|
|
882
|
+
message: scrubber.scrub(`configured baseRevision "${overrideRes.sha}" disagrees with verified pull request base SHA "${verifiedPrBaseSha}"`),
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
return overrideRes;
|
|
886
|
+
}
|
|
887
|
+
if (verifiedPrBaseSha !== undefined && COMMIT_SHA_PATTERN.test(verifiedPrBaseSha)) {
|
|
888
|
+
return { ok: true, sha: verifiedPrBaseSha.toLowerCase() };
|
|
889
|
+
}
|
|
890
|
+
const payloadAfter = typeof payload['after'] === 'string' ? payload['after'].trim() : '';
|
|
891
|
+
if (COMMIT_SHA_PATTERN.test(payloadAfter)) {
|
|
892
|
+
return { ok: true, sha: payloadAfter.toLowerCase() };
|
|
893
|
+
}
|
|
894
|
+
if (domain.manifest.spec.publication.mode === 'pull_request') {
|
|
895
|
+
return resolveRefToCommitSha(domain.manifest.spec.publication.targetBranch, domain.manifest.metadata.name);
|
|
896
|
+
}
|
|
897
|
+
const defBranchRes = await resolveRepositoryDefaultBranch(domain.manifest.metadata.name);
|
|
898
|
+
if (!defBranchRes.ok)
|
|
899
|
+
return defBranchRes;
|
|
900
|
+
return resolveRefToCommitSha(defBranchRes.branch, domain.manifest.metadata.name);
|
|
901
|
+
};
|
|
902
|
+
let verifiedPrHeadRef;
|
|
903
|
+
let verifiedPrBaseRef;
|
|
904
|
+
let verifiedScheduleKey;
|
|
905
|
+
if (eventName === 'issue_comment' || eventName === 'pull_request_review') {
|
|
906
|
+
const prCheck = await verifySuiteCommentPullRequest({
|
|
907
|
+
suite,
|
|
908
|
+
eventName,
|
|
909
|
+
eventPayload: payload,
|
|
910
|
+
repositoryFullName: repository.fullName,
|
|
911
|
+
apiBaseUrl: effectiveApiBaseUrl,
|
|
912
|
+
commentPrefixes: options.commentPrefixes,
|
|
913
|
+
commentCommands: options.commentCommands,
|
|
914
|
+
operatorAllowlist: options.operatorAllowlist,
|
|
915
|
+
fetchImpl,
|
|
916
|
+
scrubber,
|
|
917
|
+
resolveToken: options.tokenBroker !== undefined ? mintReadOnlyToken : undefined,
|
|
918
|
+
});
|
|
919
|
+
if (prCheck.kind === 'ignored' || prCheck.kind === 'missing_attribution') {
|
|
920
|
+
deliveryStore.markDeliveryState(headerDeliveryId, 'succeeded');
|
|
921
|
+
return respond(response, 200, {
|
|
922
|
+
kind: 'ignored',
|
|
923
|
+
reason: prCheck.kind === 'ignored' ? prCheck.reason : 'comment payload is unreadable',
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
if (prCheck.kind === 'unauthorized' || prCheck.kind === 'invalid_guidance') {
|
|
927
|
+
deliveryStore.markDeliveryState(headerDeliveryId, 'succeeded');
|
|
928
|
+
return respond(response, 403, {
|
|
929
|
+
kind: 'rejected',
|
|
930
|
+
code: prCheck.code,
|
|
931
|
+
detail: prCheck.detail,
|
|
932
|
+
});
|
|
933
|
+
}
|
|
934
|
+
if (prCheck.kind === 'lookup_failed') {
|
|
935
|
+
deliveryStore.markDeliveryState(headerDeliveryId, 'failed', 'ACTION_INPUT_INVALID');
|
|
936
|
+
return respond(response, 502, {
|
|
937
|
+
error: {
|
|
938
|
+
code: 'ACTION_INPUT_INVALID',
|
|
939
|
+
reason: prCheck.reason,
|
|
940
|
+
message: prCheck.detail,
|
|
941
|
+
},
|
|
942
|
+
});
|
|
943
|
+
}
|
|
944
|
+
if (prCheck.kind === 'metadata_unavailable') {
|
|
945
|
+
deliveryStore.markDeliveryState(headerDeliveryId, 'succeeded');
|
|
946
|
+
return respond(response, 400, {
|
|
947
|
+
error: {
|
|
948
|
+
code: 'ACTION_INPUT_INVALID',
|
|
949
|
+
reason: prCheck.reason,
|
|
950
|
+
message: prCheck.detail,
|
|
951
|
+
},
|
|
952
|
+
});
|
|
953
|
+
}
|
|
954
|
+
if (prCheck.kind === 'cross_fork' || prCheck.kind === 'scope_violation') {
|
|
955
|
+
deliveryStore.markDeliveryState(headerDeliveryId, 'succeeded');
|
|
956
|
+
return respond(response, 400, {
|
|
957
|
+
error: {
|
|
958
|
+
code: 'TASKPACK_SCOPE_VIOLATION',
|
|
959
|
+
reason: prCheck.reason,
|
|
960
|
+
message: prCheck.detail,
|
|
961
|
+
},
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
const targetDomain = prCheck.value.domain;
|
|
965
|
+
const parsedCmd = prCheck.value.comment;
|
|
966
|
+
verifiedPrHeadSha = prCheck.value.prHeadSha;
|
|
967
|
+
verifiedPrBaseSha = prCheck.value.prBaseSha;
|
|
968
|
+
verifiedPrHeadRef = prCheck.value.prHeadRef;
|
|
969
|
+
verifiedPrBaseRef = prCheck.value.prBaseRef;
|
|
970
|
+
if (!targetDomain.enabled) {
|
|
971
|
+
deliveryStore.markDeliveryState(headerDeliveryId, 'succeeded');
|
|
972
|
+
return respond(response, 200, { kind: 'ignored', reason: `suite domain "${targetDomain.id}" is disabled` });
|
|
973
|
+
}
|
|
974
|
+
const domainPrefixes = targetDomain.manifest.spec.triggers.commentPrefixes.length > 0
|
|
975
|
+
? targetDomain.manifest.spec.triggers.commentPrefixes
|
|
976
|
+
: DEFAULT_COMMENT_PREFIXES;
|
|
977
|
+
if (options.commentPrefixes === undefined && !domainPrefixes.includes(parsedCmd.prefix)) {
|
|
978
|
+
deliveryStore.markDeliveryState(headerDeliveryId, 'succeeded');
|
|
979
|
+
return respond(response, 200, { kind: 'ignored', reason: `prefix "${parsedCmd.prefix}" is not configured on domain "${targetDomain.id}"` });
|
|
980
|
+
}
|
|
981
|
+
if (!isGitHubTriggerDeclared(targetDomain.manifest.spec.triggers, {
|
|
982
|
+
eventName,
|
|
983
|
+
commentCommand: parsedCmd.command,
|
|
984
|
+
})) {
|
|
985
|
+
deliveryStore.markDeliveryState(headerDeliveryId, 'succeeded');
|
|
986
|
+
return respond(response, 200, {
|
|
987
|
+
kind: 'ignored',
|
|
988
|
+
code: 'TASKPACK_TRIGGER_UNSUPPORTED',
|
|
989
|
+
reason: `comment command "${parsedCmd.command}" is not enabled on domain "${targetDomain.id}"`,
|
|
990
|
+
});
|
|
991
|
+
}
|
|
992
|
+
matchedDomains = [targetDomain];
|
|
993
|
+
action = parsedCmd.command === 'retry' ? 'discover' : parsedCmd.command === 'revise' ? 'revise' : 'status';
|
|
994
|
+
}
|
|
995
|
+
else {
|
|
996
|
+
if (eventName === 'release') {
|
|
997
|
+
const releaseAction = typeof payload['action'] === 'string' ? payload['action'] : '';
|
|
998
|
+
if (releaseAction !== 'published') {
|
|
999
|
+
deliveryStore.markDeliveryState(headerDeliveryId, 'succeeded');
|
|
1000
|
+
return respond(response, 200, { kind: 'ignored', reason: `release action ${releaseAction} is not published` });
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
verifiedScheduleKey = eventName === 'schedule' && typeof payload['schedule'] === 'string' && payload['schedule'].length > 0
|
|
1004
|
+
? payload['schedule']
|
|
1005
|
+
: undefined;
|
|
1006
|
+
matchedDomains = suite.domains.filter(dom => {
|
|
1007
|
+
if (!dom.enabled)
|
|
1008
|
+
return false;
|
|
1009
|
+
if (!isGitHubTriggerDeclared(dom.manifest.spec.triggers, { eventName }))
|
|
1010
|
+
return false;
|
|
1011
|
+
if (eventName === 'schedule') {
|
|
1012
|
+
return verifiedScheduleKey !== undefined
|
|
1013
|
+
? (dom.schedules !== undefined && dom.schedules.includes(verifiedScheduleKey))
|
|
1014
|
+
: (dom.schedules === undefined || dom.schedules.length > 0);
|
|
1015
|
+
}
|
|
1016
|
+
return true;
|
|
1017
|
+
});
|
|
1018
|
+
if (matchedDomains.length === 0) {
|
|
1019
|
+
deliveryStore.markDeliveryState(headerDeliveryId, 'succeeded');
|
|
1020
|
+
return respond(response, 200, {
|
|
1021
|
+
kind: 'ignored',
|
|
1022
|
+
code: 'TASKPACK_TRIGGER_UNSUPPORTED',
|
|
1023
|
+
reason: `trigger "${eventName}" matched zero enabled suite domains`,
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
const baseShaByDomain = new Map();
|
|
1028
|
+
for (const domain of matchedDomains) {
|
|
1029
|
+
const baseRes = await resolveTargetBranchBaseSha(domain);
|
|
1030
|
+
if (!baseRes.ok) {
|
|
1031
|
+
if (baseRes.status === 502) {
|
|
1032
|
+
deliveryStore.markDeliveryState(headerDeliveryId, 'failed', 'ACTION_INPUT_INVALID');
|
|
1033
|
+
}
|
|
1034
|
+
else {
|
|
1035
|
+
deliveryStore.markDeliveryState(headerDeliveryId, 'succeeded');
|
|
1036
|
+
}
|
|
1037
|
+
return respond(response, baseRes.status, {
|
|
1038
|
+
error: { code: 'ACTION_INPUT_INVALID', message: baseRes.message },
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
baseShaByDomain.set(domain.id, baseRes.sha);
|
|
1042
|
+
}
|
|
1043
|
+
// Evaluate stage readiness for every execution-triggering event with staged domains (including
|
|
1044
|
+
// single-stage readiness probes and comment-triggered retry/revise) against each domain's pinned SHA.
|
|
1045
|
+
const stagedMatchedDomains = action !== 'status'
|
|
1046
|
+
? matchedDomains.filter(dom => dom.stage !== undefined)
|
|
1047
|
+
: [];
|
|
1048
|
+
if (stagedMatchedDomains.length > 0) {
|
|
1049
|
+
const parsedApiUrl = new URL(effectiveApiBaseUrl);
|
|
1050
|
+
const allowLoopbackForStage = parsedApiUrl.protocol === 'http:'
|
|
1051
|
+
&& (parsedApiUrl.hostname === '127.0.0.1'
|
|
1052
|
+
|| parsedApiUrl.hostname === 'localhost'
|
|
1053
|
+
|| parsedApiUrl.hostname === '[::1]'
|
|
1054
|
+
|| parsedApiUrl.hostname === '::1');
|
|
1055
|
+
const eligibleIds = new Set(matchedDomains.filter(dom => dom.stage === undefined).map(d => d.id));
|
|
1056
|
+
const deferredList = [];
|
|
1057
|
+
let lastStageReason = 'stage_not_ready';
|
|
1058
|
+
let lastStageDetail;
|
|
1059
|
+
const stagedDomainsBySha = new Map();
|
|
1060
|
+
for (const stagedDom of stagedMatchedDomains) {
|
|
1061
|
+
const domainBaseSha = baseShaByDomain.get(stagedDom.id);
|
|
1062
|
+
const list = stagedDomainsBySha.get(domainBaseSha);
|
|
1063
|
+
if (list !== undefined)
|
|
1064
|
+
list.push(stagedDom);
|
|
1065
|
+
else
|
|
1066
|
+
stagedDomainsBySha.set(domainBaseSha, [stagedDom]);
|
|
1067
|
+
}
|
|
1068
|
+
for (const [domainBaseSha, shaGroup] of stagedDomainsBySha.entries()) {
|
|
1069
|
+
let stageResolution;
|
|
1070
|
+
try {
|
|
1071
|
+
stageResolution = await resolveTaskpackSuite({
|
|
1072
|
+
repositoryRoot: options.repositoryRoot ?? process.cwd(),
|
|
1073
|
+
loadedSuite: suite,
|
|
1074
|
+
policyProfile: 'github',
|
|
1075
|
+
hostPolicy: MULTI_TENANT_HOST_POLICY,
|
|
1076
|
+
allowLoopbackHttp: allowLoopbackForStage,
|
|
1077
|
+
baseRevision: domainBaseSha,
|
|
1078
|
+
remoteBaseRevision: true,
|
|
1079
|
+
eventName,
|
|
1080
|
+
eventPayload: payload,
|
|
1081
|
+
schedule: verifiedScheduleKey,
|
|
1082
|
+
...(shaGroup.length === 1
|
|
1083
|
+
? { domain: shaGroup[0].id }
|
|
1084
|
+
: { domains: shaGroup.map(d => d.id) }),
|
|
1085
|
+
...(options.commentPrefixes !== undefined ? { commentPrefixes: options.commentPrefixes } : {}),
|
|
1086
|
+
...(verifiedPrHeadRef !== undefined ? { prHeadRef: verifiedPrHeadRef } : {}),
|
|
1087
|
+
...(verifiedPrBaseRef !== undefined ? { prBaseRef: verifiedPrBaseRef } : {}),
|
|
1088
|
+
...(verifiedPrHeadSha !== undefined ? { prHeadSha: verifiedPrHeadSha } : {}),
|
|
1089
|
+
...(verifiedPrHeadRef !== undefined ? { prHeadRepoFullName: repository.fullName, prHeadRepoFork: false } : {}),
|
|
1090
|
+
operatorAllowlist: options.operatorAllowlist,
|
|
1091
|
+
repositoryFullName: repository.fullName,
|
|
1092
|
+
apiBaseUrl: effectiveApiBaseUrl,
|
|
1093
|
+
githubToken: options.tokenBroker !== undefined
|
|
1094
|
+
? () => mintReadOnlyToken(shaGroup[0].manifest.metadata.name)
|
|
1095
|
+
: undefined,
|
|
1096
|
+
fetchImpl,
|
|
1097
|
+
scrubber,
|
|
1098
|
+
discoverUpstreamUpdates: true,
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
catch (error) {
|
|
1102
|
+
const detail = scrubber.scrub(error instanceof Error ? error.message : String(error));
|
|
1103
|
+
deliveryStore.markDeliveryState(headerDeliveryId, 'failed', 'ACTION_INPUT_INVALID');
|
|
1104
|
+
return respond(response, 502, {
|
|
1105
|
+
error: {
|
|
1106
|
+
code: 'ACTION_INPUT_INVALID',
|
|
1107
|
+
reason: 'stage_resolution_failed',
|
|
1108
|
+
message: detail,
|
|
1109
|
+
},
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
if (stageResolution.disposition === 'blocked') {
|
|
1113
|
+
const isStaticError = stageResolution.code === 'TASKPACK_SCOPE_VIOLATION'
|
|
1114
|
+
|| stageResolution.code === 'TASKPACK_MANIFEST_INVALID';
|
|
1115
|
+
if (isStaticError) {
|
|
1116
|
+
deliveryStore.markDeliveryState(headerDeliveryId, 'succeeded');
|
|
1117
|
+
}
|
|
1118
|
+
else {
|
|
1119
|
+
deliveryStore.markDeliveryState(headerDeliveryId, 'failed', stageResolution.code ?? 'ACTION_INPUT_INVALID');
|
|
1120
|
+
}
|
|
1121
|
+
return respond(response, isStaticError ? 400 : 502, {
|
|
1122
|
+
kind: 'blocked',
|
|
1123
|
+
code: stageResolution.code ?? 'ACTION_INPUT_INVALID',
|
|
1124
|
+
reason: stageResolution.reason,
|
|
1125
|
+
detail: stageResolution.detail,
|
|
1126
|
+
cells: stageResolution.cells,
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
for (const stagedDom of shaGroup) {
|
|
1130
|
+
if (stageResolution.eligibleCells.some(c => c.domainId === stagedDom.id)) {
|
|
1131
|
+
eligibleIds.add(stagedDom.id);
|
|
1132
|
+
}
|
|
1133
|
+
else {
|
|
1134
|
+
lastStageReason = stageResolution.reason;
|
|
1135
|
+
lastStageDetail ??= stageResolution.detail;
|
|
1136
|
+
const cell = stageResolution.cells.find(c => c.domainId === stagedDom.id);
|
|
1137
|
+
deferredList.push({
|
|
1138
|
+
domainId: stagedDom.id,
|
|
1139
|
+
reason: cell?.reason ?? stageResolution.reason,
|
|
1140
|
+
...(cell?.detail !== undefined
|
|
1141
|
+
? { detail: cell.detail }
|
|
1142
|
+
: (stageResolution.detail !== undefined ? { detail: stageResolution.detail } : {})),
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
deferredCellsOut = deferredList;
|
|
1148
|
+
matchedDomains = matchedDomains.filter(dom => eligibleIds.has(dom.id));
|
|
1149
|
+
if (matchedDomains.length === 0) {
|
|
1150
|
+
deliveryStore.markDeliveryState(headerDeliveryId, 'succeeded');
|
|
1151
|
+
return respond(response, 200, {
|
|
1152
|
+
kind: 'deferred',
|
|
1153
|
+
reason: lastStageReason,
|
|
1154
|
+
...(lastStageDetail !== undefined ? { detail: lastStageDetail } : {}),
|
|
1155
|
+
deferredDomains: deferredCellsOut,
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
if (admissionWatch.watch.revoked) {
|
|
1160
|
+
deliveryStore.markDeliveryState(entry.deliveryId, 'succeeded');
|
|
1161
|
+
return respond(response, 200, {
|
|
1162
|
+
kind: 'ignored',
|
|
1163
|
+
reason: 'installation_revoked_during_admission',
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
deliveryStore.markDeliveryState(entry.deliveryId, 'processing');
|
|
1167
|
+
try {
|
|
1168
|
+
const trackedDelivery = ensureBoundedFanoutDelivery(entry.deliveryId, matchedDomains.map(d => d.id));
|
|
1169
|
+
const kind = action === 'revise' ? 'revise' : action === 'status' ? 'status' : 'discover';
|
|
1170
|
+
const reviseBinding = kind === 'revise' ? readReviseBinding(rawBytes, verifiedPrHeadSha) : null;
|
|
1171
|
+
const admitted = [];
|
|
1172
|
+
for (const domain of matchedDomains) {
|
|
1173
|
+
const domainRec = registry.byDomainId.get(domain.id);
|
|
1174
|
+
const tenant = {
|
|
1175
|
+
installationId,
|
|
1176
|
+
repositoryId: repository.id,
|
|
1177
|
+
repositoryFullName: repository.fullName,
|
|
1178
|
+
taskpackId: domain.manifest.metadata.name,
|
|
1179
|
+
};
|
|
1180
|
+
const dedupKey = `${entry.deliveryId}\0${domain.id}`;
|
|
1181
|
+
let enqueuedRecord = enqueuedByDeliveryDomain.get(dedupKey);
|
|
1182
|
+
if (enqueuedRecord !== undefined && delivery.kind === 'retry_failed') {
|
|
1183
|
+
const liveItem = queue.getItem(tenant, enqueuedRecord.item.queueItemId);
|
|
1184
|
+
const isReconcileLocked = enqueuedRecord.reconcileRequired || liveItem?.state === 'reconcile_required';
|
|
1185
|
+
if (!isReconcileLocked
|
|
1186
|
+
&& (liveItem === null
|
|
1187
|
+
|| liveItem.state === 'failed'
|
|
1188
|
+
|| liveItem.state === 'blocked'
|
|
1189
|
+
|| liveItem.state === 'cancelled')) {
|
|
1190
|
+
enqueuedByDeliveryDomain.delete(dedupKey);
|
|
1191
|
+
enqueuedRecord = undefined;
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
if (enqueuedRecord === undefined) {
|
|
1195
|
+
reserveDeliveryLinkCapacity(1);
|
|
1196
|
+
const outcome = queue.enqueue(tenant, {
|
|
1197
|
+
kind,
|
|
1198
|
+
baseRevision: baseShaByDomain.get(domain.id),
|
|
1199
|
+
deliveryId: entry.deliveryId,
|
|
1200
|
+
payloadDigest: entry.payloadDigest,
|
|
1201
|
+
domainId: domain.id,
|
|
1202
|
+
manifestDigest: domainRec.manifestDigest,
|
|
1203
|
+
...(kind === 'revise'
|
|
1204
|
+
? {
|
|
1205
|
+
command: reviseBinding ?? {
|
|
1206
|
+
commandId: 0,
|
|
1207
|
+
headSha: verifiedPrHeadSha ?? tenant.repositoryFullName,
|
|
1208
|
+
commandDigest: entry.payloadDigest,
|
|
1209
|
+
},
|
|
1210
|
+
}
|
|
1211
|
+
: {}),
|
|
1212
|
+
});
|
|
1213
|
+
enqueuedRecord = { item: outcome.item, coalesced: outcome.kind === 'coalesced', reconcileRequired: false };
|
|
1214
|
+
enqueuedByDeliveryDomain.set(dedupKey, enqueuedRecord);
|
|
1215
|
+
queueSummary.enqueued += outcome.kind === 'coalesced' ? 0 : 1;
|
|
1216
|
+
queueSummary.coalesced += outcome.kind === 'coalesced' ? 1 : 0;
|
|
1217
|
+
trackedDelivery.entriesByDomain.set(domain.id, {
|
|
1218
|
+
tenant,
|
|
1219
|
+
domainId: domain.id,
|
|
1220
|
+
queueItemId: outcome.item.queueItemId,
|
|
1221
|
+
});
|
|
1222
|
+
trackQueueItemDelivery(outcome.item.queueItemId, entry.deliveryId);
|
|
1223
|
+
}
|
|
1224
|
+
admitted.push({
|
|
1225
|
+
domainId: domain.id,
|
|
1226
|
+
taskpackId: domain.manifest.metadata.name,
|
|
1227
|
+
manifestDigest: domainRec.manifestDigest,
|
|
1228
|
+
queueItemId: enqueuedRecord.item.queueItemId,
|
|
1229
|
+
runId: enqueuedRecord.item.runId,
|
|
1230
|
+
coalesced: enqueuedRecord.coalesced,
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
// Recompute live delivery state after admission (critical on retry_failed when a previously
|
|
1234
|
+
// failed sibling domain is now deferred and only already-completed domains matched).
|
|
1235
|
+
let hasActiveWork = false;
|
|
1236
|
+
let hasUnadmittedOrFailed = deferredCellsOut.length > 0;
|
|
1237
|
+
let firstFailureReason = deferredCellsOut.length > 0 ? 'stage_not_ready' : null;
|
|
1238
|
+
for (const expectedDomainId of trackedDelivery.expectedDomains) {
|
|
1239
|
+
const fEntry = trackedDelivery.entriesByDomain.get(expectedDomainId);
|
|
1240
|
+
if (fEntry === undefined) {
|
|
1241
|
+
hasUnadmittedOrFailed = true;
|
|
1242
|
+
firstFailureReason ??= 'partial_fanout';
|
|
1243
|
+
continue;
|
|
1244
|
+
}
|
|
1245
|
+
const fState = queue.getItem(fEntry.tenant, fEntry.queueItemId)?.state;
|
|
1246
|
+
if (fState === undefined) {
|
|
1247
|
+
hasUnadmittedOrFailed = true;
|
|
1248
|
+
firstFailureReason ??= 'partial_fanout';
|
|
1249
|
+
continue;
|
|
1250
|
+
}
|
|
1251
|
+
if (fState === 'pending' || fState === 'leased') {
|
|
1252
|
+
hasActiveWork = true;
|
|
1253
|
+
}
|
|
1254
|
+
else if (fState !== 'completed' && fState !== 'cancelled' && fState !== 'reconcile_required') {
|
|
1255
|
+
hasUnadmittedOrFailed = true;
|
|
1256
|
+
firstFailureReason ??= fState;
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
if (!hasActiveWork) {
|
|
1260
|
+
if (hasUnadmittedOrFailed) {
|
|
1261
|
+
// Preserve completed receipts while leaving delivery retryable for deferred/failed siblings.
|
|
1262
|
+
deliveryStore.markDeliveryState(entry.deliveryId, 'failed', firstFailureReason ?? 'partial_fanout');
|
|
1263
|
+
return respond(response, 200, {
|
|
1264
|
+
kind: 'deferred',
|
|
1265
|
+
reason: firstFailureReason ?? 'stage_not_ready',
|
|
1266
|
+
...(deferredCellsOut.length > 0 ? { deferredDomains: deferredCellsOut } : {}),
|
|
1267
|
+
domains: admitted,
|
|
1268
|
+
});
|
|
1269
|
+
}
|
|
1270
|
+
deliveryStore.markDeliveryState(entry.deliveryId, 'succeeded');
|
|
1271
|
+
evictDeliveryTracking(entry.deliveryId);
|
|
1272
|
+
}
|
|
1273
|
+
return respond(response, 202, {
|
|
1274
|
+
kind: 'accepted',
|
|
1275
|
+
action,
|
|
1276
|
+
suiteName: suite.manifest.metadata.name,
|
|
1277
|
+
domains: admitted,
|
|
1278
|
+
...(deferredCellsOut.length > 0 ? { deferredDomains: deferredCellsOut } : {}),
|
|
1279
|
+
queueItemId: admitted[0].queueItemId,
|
|
1280
|
+
runId: admitted[0].runId,
|
|
1281
|
+
coalesced: admitted.every(a => a.coalesced),
|
|
1282
|
+
attemptCount: entry.attemptCount,
|
|
1283
|
+
});
|
|
1284
|
+
}
|
|
1285
|
+
catch (error) {
|
|
1286
|
+
const failedTracker = fanoutDeliveriesById.get(entry.deliveryId);
|
|
1287
|
+
if (failedTracker !== undefined && failedTracker.entriesByDomain.size === 0) {
|
|
1288
|
+
fanoutDeliveriesById.delete(entry.deliveryId);
|
|
1289
|
+
}
|
|
1290
|
+
if (error !== null && typeof error === 'object' && 'code' in error) {
|
|
1291
|
+
if (WEBHOOK_DELIVERY_ID_TEST.test(entry.deliveryId)) {
|
|
1292
|
+
deliveryStore.markDeliveryState(entry.deliveryId, 'failed', String(error.code));
|
|
1293
|
+
}
|
|
1294
|
+
return respondError(response, error);
|
|
1295
|
+
}
|
|
1296
|
+
throw error;
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
catch (outerError) {
|
|
1300
|
+
const currentState = deliveryStore.getDelivery(entry.deliveryId)?.state;
|
|
1301
|
+
if (currentState !== 'succeeded' && currentState !== 'failed') {
|
|
1302
|
+
const errCode = (outerError !== null && typeof outerError === 'object' && 'code' in outerError)
|
|
1303
|
+
? String(outerError.code)
|
|
1304
|
+
: 'SERVICE_FAULT';
|
|
1305
|
+
deliveryStore.markDeliveryState(entry.deliveryId, 'failed', errCode);
|
|
1306
|
+
}
|
|
1307
|
+
throw outerError;
|
|
1308
|
+
}
|
|
1309
|
+
finally {
|
|
1310
|
+
admissionWatch.release();
|
|
1311
|
+
}
|
|
1312
|
+
};
|
|
1313
|
+
const handle = async (request, response) => {
|
|
1314
|
+
const url = new URL(request.url ?? '/', 'http://127.0.0.1');
|
|
1315
|
+
const method = request.method ?? 'GET';
|
|
1316
|
+
const headerDeliveryId = String(request.headers['x-github-delivery'] ?? '');
|
|
1317
|
+
if (url.pathname === '/healthz') {
|
|
1318
|
+
if (method !== 'GET')
|
|
1319
|
+
return respond(response, 405, { error: { code: 'SERVICE_FAULT', message: 'method not allowed' } });
|
|
1320
|
+
return respond(response, 200, { ok: true, queue: { ...queueSummary }, deliveries: deliveryStore.counts() });
|
|
1321
|
+
}
|
|
1322
|
+
if (url.pathname === webhookPath) {
|
|
1323
|
+
if (method !== 'POST')
|
|
1324
|
+
return respond(response, 405, { error: { code: 'SERVICE_FAULT', message: 'method not allowed' } });
|
|
1325
|
+
const raw = await readBody(request);
|
|
1326
|
+
if (!raw.ok)
|
|
1327
|
+
return respond(response, 413, { error: { code: 'WEBHOOK_PAYLOAD_TOO_LARGE', message: `webhook body exceeds ${maxPayloadBytes} bytes` } });
|
|
1328
|
+
if (effectiveSuite !== undefined && suiteRegistry !== null) {
|
|
1329
|
+
return handleSuiteWebhook(effectiveSuite, suiteRegistry, request, response, raw.bytes, headerDeliveryId);
|
|
1330
|
+
}
|
|
1331
|
+
const outcome = intakeWebhookDelivery({
|
|
1332
|
+
rawBody: raw.bytes,
|
|
1333
|
+
signatureHeader: request.headers['x-hub-signature-256'],
|
|
1334
|
+
secret: options.webhookSecret,
|
|
1335
|
+
eventName: String(request.headers['x-github-event'] ?? ''),
|
|
1336
|
+
deliveryId: headerDeliveryId,
|
|
1337
|
+
receivedAtMs: Date.now(),
|
|
1338
|
+
taskpackId: effectiveTaskpackId,
|
|
1339
|
+
commentPrefixes: effectiveCommentPrefixes,
|
|
1340
|
+
commentCommands: effectiveCommentCommands,
|
|
1341
|
+
operatorAllowlist: options.operatorAllowlist,
|
|
1342
|
+
}, deliveryStore);
|
|
1343
|
+
if (outcome.kind === 'signature_rejected') {
|
|
1344
|
+
return respond(response, outcome.code === 'WEBHOOK_PAYLOAD_TOO_LARGE' ? 413 : 401, { error: { code: outcome.code, message: outcome.detail } });
|
|
1345
|
+
}
|
|
1346
|
+
if (outcome.kind === 'delivery_conflict') {
|
|
1347
|
+
return respond(response, 409, { error: { code: 'WEBHOOK_DELIVERY_CONFLICT', message: outcome.detail } });
|
|
1348
|
+
}
|
|
1349
|
+
if (outcome.kind === 'duplicate') {
|
|
1350
|
+
return respond(response, 200, { kind: 'duplicate', state: outcome.state, deliveryId: outcome.entry.deliveryId, attemptCount: outcome.entry.attemptCount });
|
|
1351
|
+
}
|
|
1352
|
+
if (outcome.kind === 'ignored') {
|
|
1353
|
+
if (deliveryStore.getDelivery(headerDeliveryId) !== undefined)
|
|
1354
|
+
deliveryStore.markDeliveryState(headerDeliveryId, 'succeeded');
|
|
1355
|
+
return respond(response, 200, { kind: 'ignored', reason: outcome.reason });
|
|
1356
|
+
}
|
|
1357
|
+
if (outcome.kind === 'rejected') {
|
|
1358
|
+
if (deliveryStore.getDelivery(headerDeliveryId) !== undefined)
|
|
1359
|
+
deliveryStore.markDeliveryState(headerDeliveryId, 'succeeded');
|
|
1360
|
+
return respond(response, 403, { kind: 'rejected', code: outcome.code, detail: outcome.detail });
|
|
1361
|
+
}
|
|
1362
|
+
if (outcome.kind === 'revoked') {
|
|
1363
|
+
const installationId = outcome.installationId ?? 0;
|
|
1364
|
+
// installation.deleted / suspend revoke the whole installation; installation_repositories.removed
|
|
1365
|
+
// revokes only the removed repositories and leaves sibling repositories untouched.
|
|
1366
|
+
const revoked = outcome.repositoryIds.length === 0
|
|
1367
|
+
? queue.revokeInstallationScope(installationId)
|
|
1368
|
+
: queue.revokeRepositoryScope(installationId, outcome.repositoryIds);
|
|
1369
|
+
bumpRevocationGeneration(installationId, outcome.repositoryIds);
|
|
1370
|
+
settleRevokedQueueItems(revoked.cancelledQueueItemIds, revoked.fencedQueueItemIds);
|
|
1371
|
+
if (options.tokenBroker !== undefined) {
|
|
1372
|
+
if (outcome.repositoryIds.length === 0)
|
|
1373
|
+
options.tokenBroker.revokeInstallationTokens(installationId);
|
|
1374
|
+
else
|
|
1375
|
+
options.tokenBroker.revokeRepositoryTokens(installationId, outcome.repositoryIds);
|
|
1376
|
+
}
|
|
1377
|
+
queueSummary.revoked += 1;
|
|
1378
|
+
if (deliveryStore.getDelivery(headerDeliveryId) !== undefined)
|
|
1379
|
+
deliveryStore.markDeliveryState(headerDeliveryId, 'succeeded');
|
|
1380
|
+
return respond(response, 202, { kind: 'revoked', installationId: outcome.installationId, repositoryIds: outcome.repositoryIds, cancelled: revoked.cancelled, fenced: revoked.fenced });
|
|
1381
|
+
}
|
|
1382
|
+
if (outcome.kind === 'retry_failed') {
|
|
1383
|
+
// intakeWebhookDelivery re-dispatches redelivered failures internally; this shape never escapes it.
|
|
1384
|
+
return respond(response, 202, { kind: 'retry_failed', attemptCount: outcome.entry.attemptCount });
|
|
1385
|
+
}
|
|
1386
|
+
// Unconfigured control planes without a pinned manifest must not admit actionable triggers into tenant queues.
|
|
1387
|
+
if (options.manifest === undefined) {
|
|
1388
|
+
if (deliveryStore.getDelivery(headerDeliveryId) !== undefined) {
|
|
1389
|
+
deliveryStore.markDeliveryState(headerDeliveryId, 'succeeded');
|
|
1390
|
+
}
|
|
1391
|
+
return respond(response, 200, {
|
|
1392
|
+
kind: 'ignored',
|
|
1393
|
+
code: 'TASKPACK_TRIGGER_UNSUPPORTED',
|
|
1394
|
+
reason: 'control plane has no pinned taskpack manifest to authorize actionable triggers',
|
|
1395
|
+
});
|
|
1396
|
+
}
|
|
1397
|
+
// Enforce manifest spec.triggers eligibility strictly BEFORE admitting into the tenant queue.
|
|
1398
|
+
if (!isGitHubTriggerDeclared(options.manifest.spec.triggers, {
|
|
1399
|
+
eventName: outcome.eventName,
|
|
1400
|
+
commentCommand: outcome.command?.command,
|
|
1401
|
+
})) {
|
|
1402
|
+
if (deliveryStore.getDelivery(headerDeliveryId) !== undefined) {
|
|
1403
|
+
deliveryStore.markDeliveryState(headerDeliveryId, 'succeeded');
|
|
1404
|
+
}
|
|
1405
|
+
return respond(response, 200, {
|
|
1406
|
+
kind: 'ignored',
|
|
1407
|
+
code: 'TASKPACK_TRIGGER_UNSUPPORTED',
|
|
1408
|
+
reason: `trigger "${outcome.eventName}" is not enabled in spec.triggers`,
|
|
1409
|
+
});
|
|
1410
|
+
}
|
|
1411
|
+
// Accepted (including failed-redelivery retries): enqueue the actionable trigger for the tenant.
|
|
1412
|
+
const tenant = outcome.tenant;
|
|
1413
|
+
if (tenant === null)
|
|
1414
|
+
return respond(response, 400, { error: { code: 'TENANT_IDENTITY_INVALID', message: 'accepted webhook without tenant attribution' } });
|
|
1415
|
+
const kind = outcome.action === 'revise' ? 'revise' : outcome.action === 'status' ? 'status' : 'discover';
|
|
1416
|
+
const entry = outcome.entry;
|
|
1417
|
+
if (WEBHOOK_DELIVERY_ID_TEST.test(entry.deliveryId))
|
|
1418
|
+
deliveryStore.markDeliveryState(entry.deliveryId, 'processing');
|
|
1419
|
+
try {
|
|
1420
|
+
reserveDeliveryLinkCapacity(1);
|
|
1421
|
+
const reviseBinding = kind === 'revise' ? readReviseBinding(raw.bytes) : null;
|
|
1422
|
+
const enqueued = queue.enqueue(tenant, {
|
|
1423
|
+
kind,
|
|
1424
|
+
baseRevision: options.baseRevision ?? entry.payloadDigest.slice(0, 12),
|
|
1425
|
+
deliveryId: entry.deliveryId,
|
|
1426
|
+
payloadDigest: entry.payloadDigest,
|
|
1427
|
+
...(kind === 'revise'
|
|
1428
|
+
? { command: reviseBinding ?? { commandId: 0, headSha: tenant.repositoryFullName, commandDigest: entry.payloadDigest } }
|
|
1429
|
+
: {}),
|
|
1430
|
+
});
|
|
1431
|
+
queueSummary.enqueued += enqueued.kind === 'coalesced' ? 0 : 1;
|
|
1432
|
+
queueSummary.coalesced += enqueued.kind === 'coalesced' ? 1 : 0;
|
|
1433
|
+
trackQueueItemDelivery(enqueued.item.queueItemId, entry.deliveryId);
|
|
1434
|
+
return respond(response, 202, {
|
|
1435
|
+
kind: 'accepted', action: outcome.action, queueItemId: enqueued.item.queueItemId,
|
|
1436
|
+
runId: enqueued.item.runId, coalesced: enqueued.kind === 'coalesced', attemptCount: entry.attemptCount,
|
|
1437
|
+
});
|
|
1438
|
+
}
|
|
1439
|
+
catch (error) {
|
|
1440
|
+
if (error !== null && typeof error === 'object' && 'code' in error) {
|
|
1441
|
+
if (WEBHOOK_DELIVERY_ID_TEST.test(entry.deliveryId)) {
|
|
1442
|
+
deliveryStore.markDeliveryState(entry.deliveryId, 'failed', String(error.code));
|
|
1443
|
+
}
|
|
1444
|
+
return respondError(response, error);
|
|
1445
|
+
}
|
|
1446
|
+
throw error;
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
const tenantMatch = TENANT_PATH_PATTERN.exec(url.pathname);
|
|
1450
|
+
if (tenantMatch !== null) {
|
|
1451
|
+
const [, installationIdRaw, repositoryIdRaw, taskpackId, action] = tenantMatch;
|
|
1452
|
+
if (!IDENTIFIER_PATTERN.test(taskpackId))
|
|
1453
|
+
return respond(response, 400, { error: { code: 'TENANT_IDENTITY_INVALID', message: 'taskpackId must be a lowercase identifier' } });
|
|
1454
|
+
const tenant = { installationId: Number(installationIdRaw), repositoryId: Number(repositoryIdRaw), repositoryFullName: '', taskpackId: taskpackId };
|
|
1455
|
+
const parsed = await parseJsonBody(request);
|
|
1456
|
+
if (!parsed.ok)
|
|
1457
|
+
return respond(response, parsed.status, { error: { code: 'ACTION_INPUT_INVALID', message: parsed.detail } });
|
|
1458
|
+
tenant.repositoryFullName = typeof parsed.body['repositoryFullName'] === 'string' ? parsed.body['repositoryFullName'] : '';
|
|
1459
|
+
const nowSample = isClockSample(parsed.body['nowSample']) ? parsed.body['nowSample'] : systemSample();
|
|
1460
|
+
const workerId = typeof parsed.body['workerId'] === 'string' ? parsed.body['workerId'] : '';
|
|
1461
|
+
try {
|
|
1462
|
+
if (action === 'lease') {
|
|
1463
|
+
const suiteDomainRecord = suiteRegistry?.byTaskpackName.get(taskpackId);
|
|
1464
|
+
if (suiteRegistry !== null && suiteDomainRecord === undefined) {
|
|
1465
|
+
throw new GitHubAppError('TASKPACK_HOST_BINDING_INVALID', `taskpackId "${taskpackId}" is not registered in control-plane suite`, '/taskpackId');
|
|
1466
|
+
}
|
|
1467
|
+
const hasManifestDigest = Object.hasOwn(parsed.body, 'manifestDigest') && parsed.body['manifestDigest'] !== undefined;
|
|
1468
|
+
const hasManifest = Object.hasOwn(parsed.body, 'manifest') && parsed.body['manifest'] !== undefined;
|
|
1469
|
+
if (suiteDomainRecord !== undefined && !hasManifestDigest && !hasManifest) {
|
|
1470
|
+
throw new GitHubAppError('TASKPACK_HOST_BINDING_INVALID', 'suite control-plane lease requires manifestDigest or suite-augmented manifest', '/manifestDigest');
|
|
1471
|
+
}
|
|
1472
|
+
if (hasManifestDigest) {
|
|
1473
|
+
const requestedDigest = parsed.body['manifestDigest'];
|
|
1474
|
+
if (typeof requestedDigest !== 'string'
|
|
1475
|
+
|| !SHA256_HEX_PATTERN.test(requestedDigest)
|
|
1476
|
+
|| (suiteDomainRecord !== undefined && requestedDigest !== suiteDomainRecord.manifestDigest)) {
|
|
1477
|
+
throw new GitHubAppError('TASKPACK_HOST_BINDING_INVALID', 'leased manifestDigest does not match control-plane pinned domain manifest digest', '/manifestDigest');
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
if (hasManifest) {
|
|
1481
|
+
const tenantManifest = validateTaskpackV2Manifest(parsed.body['manifest'], {
|
|
1482
|
+
...(suiteDomainRecord !== undefined
|
|
1483
|
+
? {
|
|
1484
|
+
controlRoot: suiteDomainRecord.domain.controlRoot,
|
|
1485
|
+
manifestPath: suiteDomainRecord.domain.taskpackPath,
|
|
1486
|
+
}
|
|
1487
|
+
: {}),
|
|
1488
|
+
policyProfile: 'github',
|
|
1489
|
+
hostPolicy: MULTI_TENANT_HOST_POLICY,
|
|
1490
|
+
enforceHostAuthority: true,
|
|
1491
|
+
});
|
|
1492
|
+
assertMultiTenantManifestAuthority(tenantManifest);
|
|
1493
|
+
if (tenantManifest.metadata.name !== taskpackId) {
|
|
1494
|
+
throw new GitHubAppError('TASKPACK_HOST_BINDING_INVALID', `leased manifest metadata.name "${tenantManifest.metadata.name}" does not match tenant taskpackId "${taskpackId}"`, '/metadata/name');
|
|
1495
|
+
}
|
|
1496
|
+
const tenantCanonical = canonicalJson(tenantManifest);
|
|
1497
|
+
if (pinnedManifestCanonical !== null && tenantCanonical !== pinnedManifestCanonical) {
|
|
1498
|
+
throw new GitHubAppError('TASKPACK_HOST_BINDING_INVALID', 'leased manifest does not match control-plane pinned manifest', '/manifest');
|
|
1499
|
+
}
|
|
1500
|
+
if (suiteDomainRecord !== undefined && tenantCanonical !== suiteDomainRecord.canonicalManifest) {
|
|
1501
|
+
throw new GitHubAppError('TASKPACK_HOST_BINDING_INVALID', `leased manifest does not match suite-augmented control-plane domain "${suiteDomainRecord.domain.id}"`, '/manifest');
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
if (options.tokenBroker === undefined) {
|
|
1505
|
+
return respond(response, 503, { error: { code: 'TOKEN_BROKER_CONFIG_INVALID', message: 'this control plane has no installation token broker configured' } });
|
|
1506
|
+
}
|
|
1507
|
+
const grant = queue.leaseNext(tenant, workerId, nowSample);
|
|
1508
|
+
if (grant === null)
|
|
1509
|
+
return respond(response, 200, { item: null });
|
|
1510
|
+
const leaseWatch = beginRevocationWatch(tenant.installationId, tenant.repositoryId);
|
|
1511
|
+
const mintStartNs = process.hrtime.bigint();
|
|
1512
|
+
let token;
|
|
1513
|
+
try {
|
|
1514
|
+
token = await options.tokenBroker.mint(tenant, 'read_only');
|
|
1515
|
+
if (leaseWatch.watch.revoked) {
|
|
1516
|
+
options.tokenBroker.revokeRepositoryTokens(tenant.installationId, [tenant.repositoryId]);
|
|
1517
|
+
throw new GitHubAppError('TENANT_INSTALLATION_REVOKED', `lease on ${grant.queueItemId} was revoked while minting installation credentials`);
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
finally {
|
|
1521
|
+
leaseWatch.release();
|
|
1522
|
+
}
|
|
1523
|
+
const mintElapsedMs = Math.max(0, Math.floor(Number(process.hrtime.bigint() - mintStartNs) / 1_000_000));
|
|
1524
|
+
const postMintSample = isClockSample(parsed.body['nowSample'])
|
|
1525
|
+
? {
|
|
1526
|
+
wallMs: nowSample.wallMs + mintElapsedMs,
|
|
1527
|
+
monotonicMs: String(BigInt(nowSample.monotonicMs) + BigInt(mintElapsedMs)),
|
|
1528
|
+
}
|
|
1529
|
+
: systemSample();
|
|
1530
|
+
const item = queue.assertActiveLease(tenant, grant.queueItemId, grant.leaseEpoch, workerId, postMintSample);
|
|
1531
|
+
queueSummary.leased += 1;
|
|
1532
|
+
if (item.deliveryId !== null && deliveryStore.getDelivery(item.deliveryId)?.state !== 'succeeded') {
|
|
1533
|
+
deliveryStore.markDeliveryState(item.deliveryId, 'processing');
|
|
1534
|
+
}
|
|
1535
|
+
const tokenMarker = `lw-token-${randomBytes(8).toString('hex')}`;
|
|
1536
|
+
const leaseOut = suiteDomainRecord !== undefined
|
|
1537
|
+
? {
|
|
1538
|
+
...grant,
|
|
1539
|
+
domainId: grant.domainId ?? suiteDomainRecord.domain.id,
|
|
1540
|
+
manifestDigest: grant.manifestDigest ?? suiteDomainRecord.manifestDigest,
|
|
1541
|
+
}
|
|
1542
|
+
: { ...grant };
|
|
1543
|
+
return respond(response, 200, {
|
|
1544
|
+
lease: leaseOut, item: summarizeItem(item),
|
|
1545
|
+
installationToken: { token: tokenMarker, expiresAtMs: token.expiresAtMs, profile: token.profile },
|
|
1546
|
+
}, { marker: tokenMarker, value: token.token });
|
|
1547
|
+
}
|
|
1548
|
+
const queueItemId = typeof parsed.body['queueItemId'] === 'string' ? parsed.body['queueItemId'] : '';
|
|
1549
|
+
const leaseEpoch = typeof parsed.body['leaseEpoch'] === 'number' ? parsed.body['leaseEpoch'] : Number.NaN;
|
|
1550
|
+
const settleOutcome = parsed.body['outcome'];
|
|
1551
|
+
if (settleOutcome !== 'completed' && settleOutcome !== 'failed' && settleOutcome !== 'blocked' && settleOutcome !== 'reconcile_required') {
|
|
1552
|
+
return respond(response, 400, { error: { code: 'ACTION_INPUT_INVALID', message: 'outcome must be completed, failed, blocked, or reconcile_required' } });
|
|
1553
|
+
}
|
|
1554
|
+
const settled = queue.settleLease(tenant, queueItemId, leaseEpoch, workerId, settleOutcome, nowSample);
|
|
1555
|
+
queueSummary.settled += 1;
|
|
1556
|
+
const affectedDeliveryIds = new Set();
|
|
1557
|
+
if (settled.deliveryId !== null)
|
|
1558
|
+
affectedDeliveryIds.add(settled.deliveryId);
|
|
1559
|
+
for (const linkedId of clearQueueItemLinks(settled.queueItemId)) {
|
|
1560
|
+
affectedDeliveryIds.add(linkedId);
|
|
1561
|
+
}
|
|
1562
|
+
for (const deliveryId of affectedDeliveryIds) {
|
|
1563
|
+
if (settled.domainId !== undefined) {
|
|
1564
|
+
const dedupKey = `${deliveryId}\0${settled.domainId}`;
|
|
1565
|
+
if (settleOutcome === 'reconcile_required') {
|
|
1566
|
+
const existingRec = enqueuedByDeliveryDomain.get(dedupKey);
|
|
1567
|
+
if (existingRec !== undefined) {
|
|
1568
|
+
existingRec.reconcileRequired = true;
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
else if (settleOutcome === 'failed' || settleOutcome === 'blocked') {
|
|
1572
|
+
enqueuedByDeliveryDomain.delete(dedupKey);
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
const tracked = fanoutDeliveriesById.get(deliveryId);
|
|
1576
|
+
if (tracked !== undefined && tracked.expectedDomains.size > 0) {
|
|
1577
|
+
let hasActive = false;
|
|
1578
|
+
let hasUnadmitted = false;
|
|
1579
|
+
let hasReconcileRequired = false;
|
|
1580
|
+
let firstRetryableFailure = null;
|
|
1581
|
+
for (const expectedDomainId of tracked.expectedDomains) {
|
|
1582
|
+
const fEntry = tracked.entriesByDomain.get(expectedDomainId);
|
|
1583
|
+
if (fEntry === undefined) {
|
|
1584
|
+
hasUnadmitted = true;
|
|
1585
|
+
continue;
|
|
1586
|
+
}
|
|
1587
|
+
const fState = fEntry.queueItemId === settled.queueItemId
|
|
1588
|
+
? settled.state
|
|
1589
|
+
: queue.getItem(fEntry.tenant, fEntry.queueItemId)?.state;
|
|
1590
|
+
if (fState === undefined) {
|
|
1591
|
+
hasUnadmitted = true;
|
|
1592
|
+
continue;
|
|
1593
|
+
}
|
|
1594
|
+
if (fState === 'pending' || fState === 'leased') {
|
|
1595
|
+
hasActive = true;
|
|
1596
|
+
}
|
|
1597
|
+
else if (fState === 'reconcile_required') {
|
|
1598
|
+
hasReconcileRequired = true;
|
|
1599
|
+
}
|
|
1600
|
+
else if (fState !== 'completed' && firstRetryableFailure === null) {
|
|
1601
|
+
firstRetryableFailure = fState;
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
if (!hasActive) {
|
|
1605
|
+
if (!hasUnadmitted && !hasReconcileRequired && firstRetryableFailure === null) {
|
|
1606
|
+
deliveryStore.markDeliveryState(deliveryId, 'succeeded');
|
|
1607
|
+
evictDeliveryTracking(deliveryId);
|
|
1608
|
+
}
|
|
1609
|
+
else if (hasUnadmitted || firstRetryableFailure !== null) {
|
|
1610
|
+
deliveryStore.markDeliveryState(deliveryId, 'failed', firstRetryableFailure ?? 'partial_fanout');
|
|
1611
|
+
}
|
|
1612
|
+
else {
|
|
1613
|
+
// Only reconcile_required remains: suppress redelivery until explicit reconciliation.
|
|
1614
|
+
deliveryStore.markDeliveryState(deliveryId, 'succeeded');
|
|
1615
|
+
evictDeliveryTracking(deliveryId);
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
else {
|
|
1620
|
+
const suppressRedelivery = settleOutcome === 'completed' || settleOutcome === 'reconcile_required';
|
|
1621
|
+
deliveryStore.markDeliveryState(deliveryId, suppressRedelivery ? 'succeeded' : 'failed', suppressRedelivery ? null : settleOutcome);
|
|
1622
|
+
if (suppressRedelivery) {
|
|
1623
|
+
evictDeliveryTracking(deliveryId);
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
return respond(response, 200, { kind: 'settled', queueItemId: settled.queueItemId, state: settled.state });
|
|
1628
|
+
}
|
|
1629
|
+
catch (error) {
|
|
1630
|
+
if (error !== null && typeof error === 'object' && 'code' in error)
|
|
1631
|
+
return respondError(response, error);
|
|
1632
|
+
throw error;
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
return respond(response, 404, { error: { code: 'SERVICE_FAULT', message: `no route for ${method} ${url.pathname}` } });
|
|
1636
|
+
};
|
|
1637
|
+
let listening = false;
|
|
1638
|
+
await new Promise((resolveListen, rejectListen) => {
|
|
1639
|
+
server.on('error', error => {
|
|
1640
|
+
if (listening)
|
|
1641
|
+
return; // post-listen socket failures surface per-request, never as process crashes
|
|
1642
|
+
rejectListen(error);
|
|
1643
|
+
});
|
|
1644
|
+
server.listen(port, host, () => {
|
|
1645
|
+
listening = true;
|
|
1646
|
+
resolveListen();
|
|
1647
|
+
});
|
|
1648
|
+
});
|
|
1649
|
+
const address = server.address();
|
|
1650
|
+
const boundPort = typeof address === 'object' && address !== null ? address.port : port;
|
|
1651
|
+
return {
|
|
1652
|
+
host, port: boundPort, url: `http://${host}:${boundPort}`, webhookPath, queue, deliveryStore,
|
|
1653
|
+
close: async () => new Promise((resolveClose, rejectClose) => {
|
|
1654
|
+
server.close(error => (error === undefined ? resolveClose() : rejectClose(error)));
|
|
1655
|
+
}),
|
|
1656
|
+
};
|
|
1657
|
+
}
|
|
1658
|
+
const WEBHOOK_DELIVERY_ID_TEST = /^[A-Za-z0-9-]{8,128}$/;
|