@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,836 @@
|
|
|
1
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
+
import { closeSync, constants, fstatSync, lstatSync, openSync, readSync, realpathSync } from 'node:fs';
|
|
3
|
+
import { link, lstat, mkdir, open, realpath, unlink } from 'node:fs/promises';
|
|
4
|
+
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
5
|
+
import { PiFailure, refuse } from './errors.js';
|
|
6
|
+
export const CAS_CHUNK_BYTES = 1_048_576;
|
|
7
|
+
export const RAW_ARTIFACT_MAX_BYTES = 67_108_864;
|
|
8
|
+
export const RAW_AGGREGATE_MAX_BYTES = 268_435_456;
|
|
9
|
+
export const WORKSPACE_NDJSON_MAX_BYTES = 33_554_432;
|
|
10
|
+
const UNBOUNDED_GENERIC_SECRET_PATTERNS = Object.freeze([
|
|
11
|
+
/gh[pousr]_[A-Za-z0-9]{20,}/,
|
|
12
|
+
/github_pat_[A-Za-z0-9_]{20,}/,
|
|
13
|
+
/-----BEGIN (?:RSA |EC |DSA |OPENSSH |ENCRYPTED )?PRIVATE KEY-----/,
|
|
14
|
+
/sk-(?:ant-|proj-)[A-Za-z0-9_-]{20,}/,
|
|
15
|
+
]);
|
|
16
|
+
const BOUNDED_GENERIC_SECRET_PATTERNS = Object.freeze([
|
|
17
|
+
/(?<![0-9A-Za-z])AKIA[0-9A-Z]{16}(?![0-9A-Za-z])/g,
|
|
18
|
+
]);
|
|
19
|
+
function derivePiSecretFormBuffers(secrets) {
|
|
20
|
+
const formSet = new Set();
|
|
21
|
+
for (const token of secrets) {
|
|
22
|
+
if (typeof token !== 'string' || token.length === 0)
|
|
23
|
+
continue;
|
|
24
|
+
const jsonEscaped = JSON.stringify(token).slice(1, -1);
|
|
25
|
+
formSet.add(token);
|
|
26
|
+
formSet.add(jsonEscaped);
|
|
27
|
+
formSet.add(jsonEscaped.replaceAll('/', '\\/'));
|
|
28
|
+
try {
|
|
29
|
+
formSet.add(encodeURIComponent(token));
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// Ignore lone-surrogate URIError on untrusted standalone inputs.
|
|
33
|
+
}
|
|
34
|
+
formSet.add(Buffer.from(token, 'utf8').toString('base64'));
|
|
35
|
+
}
|
|
36
|
+
formSet.delete('');
|
|
37
|
+
return Object.freeze([...formSet].map(form => Buffer.from(form, 'utf8')));
|
|
38
|
+
}
|
|
39
|
+
function hasGenericSecretPattern(bytes, isFinal, minMatchEnd = 0) {
|
|
40
|
+
const textWindow = bytes.toString('latin1');
|
|
41
|
+
if (UNBOUNDED_GENERIC_SECRET_PATTERNS.some(pattern => pattern.test(textWindow))) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
for (const pattern of BOUNDED_GENERIC_SECRET_PATTERNS) {
|
|
45
|
+
pattern.lastIndex = 0;
|
|
46
|
+
let match;
|
|
47
|
+
while ((match = pattern.exec(textWindow)) !== null) {
|
|
48
|
+
const matchEnd = match.index + match[0].length;
|
|
49
|
+
if (matchEnd < minMatchEnd)
|
|
50
|
+
continue;
|
|
51
|
+
if (isFinal || matchEnd < textWindow.length) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
export function createBuiltInPiStreamChecker(resolvedSecrets, options) {
|
|
59
|
+
const includeGeneric = options?.includeGeneric !== false;
|
|
60
|
+
const formBuffers = derivePiSecretFormBuffers(resolvedSecrets);
|
|
61
|
+
const maxDerivedFormByteLength = formBuffers.reduce((max, buf) => Math.max(max, buf.byteLength), 0);
|
|
62
|
+
const overlap = Math.max(16_384, maxDerivedFormByteLength);
|
|
63
|
+
let carryTail = Buffer.alloc(0);
|
|
64
|
+
return Object.freeze({
|
|
65
|
+
push: (chunk) => {
|
|
66
|
+
if (chunk.byteLength === 0)
|
|
67
|
+
return;
|
|
68
|
+
const view = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
69
|
+
const prevCarryLen = carryTail.byteLength;
|
|
70
|
+
const combined = prevCarryLen === 0 ? view : Buffer.concat([carryTail, view]);
|
|
71
|
+
if (formBuffers.some(form => combined.includes(form))
|
|
72
|
+
|| (includeGeneric && hasGenericSecretPattern(combined, false, prevCarryLen))) {
|
|
73
|
+
if (carryTail.byteLength > 0)
|
|
74
|
+
carryTail.fill(0);
|
|
75
|
+
carryTail = Buffer.alloc(0);
|
|
76
|
+
refuse('CONTEXT_UNSAFE', '/candidate/artifacts', { phase: 'restore' });
|
|
77
|
+
}
|
|
78
|
+
const keep = Math.min(overlap, combined.byteLength);
|
|
79
|
+
if (carryTail.byteLength > 0)
|
|
80
|
+
carryTail.fill(0);
|
|
81
|
+
carryTail = Buffer.from(combined.subarray(combined.byteLength - keep));
|
|
82
|
+
},
|
|
83
|
+
finish: () => {
|
|
84
|
+
const tail = carryTail;
|
|
85
|
+
carryTail = Buffer.alloc(0);
|
|
86
|
+
try {
|
|
87
|
+
if (tail.byteLength > 0
|
|
88
|
+
&& (formBuffers.some(form => tail.includes(form))
|
|
89
|
+
|| (includeGeneric && hasGenericSecretPattern(tail, true, tail.byteLength)))) {
|
|
90
|
+
refuse('CONTEXT_UNSAFE', '/candidate/artifacts', { phase: 'restore' });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
if (tail.byteLength > 0)
|
|
95
|
+
tail.fill(0);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
export function composeCandidateStreamCheckers(primary, secondary) {
|
|
101
|
+
if (!primary)
|
|
102
|
+
return secondary;
|
|
103
|
+
return Object.freeze({
|
|
104
|
+
push: (chunk) => {
|
|
105
|
+
primary.push(chunk);
|
|
106
|
+
secondary.push(chunk);
|
|
107
|
+
},
|
|
108
|
+
finish: () => {
|
|
109
|
+
let firstError = null;
|
|
110
|
+
try {
|
|
111
|
+
primary.finish();
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
firstError = error;
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
secondary.finish();
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
if (firstError === null)
|
|
121
|
+
firstError = error;
|
|
122
|
+
}
|
|
123
|
+
if (firstError !== null)
|
|
124
|
+
throw firstError;
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
const absent = (error) => error.code === 'ENOENT';
|
|
129
|
+
export async function writeAll(handle, chunk) {
|
|
130
|
+
let offset = 0;
|
|
131
|
+
while (offset < chunk.byteLength) {
|
|
132
|
+
const written = await handle.write(chunk, offset, chunk.byteLength - offset);
|
|
133
|
+
if (written.bytesWritten <= 0)
|
|
134
|
+
refuse('RECOVERY_REQUIRED', '', { phase: 'restore' });
|
|
135
|
+
offset += written.bytesWritten;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
export async function fsyncDir(dirPath) {
|
|
139
|
+
const fd = await open(dirPath, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
140
|
+
try {
|
|
141
|
+
await fd.sync();
|
|
142
|
+
}
|
|
143
|
+
finally {
|
|
144
|
+
await fd.close();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
export function checkOwnerAndMode(uid, mode, forbiddenBits) {
|
|
148
|
+
const currentUid = process.getuid?.();
|
|
149
|
+
if (currentUid !== undefined && uid !== currentUid)
|
|
150
|
+
return false;
|
|
151
|
+
return (mode & forbiddenBits) === 0;
|
|
152
|
+
}
|
|
153
|
+
export async function ensureCasSha256Dir(artifactsDirectory) {
|
|
154
|
+
const rootInfo = await lstat(artifactsDirectory).catch(() => null);
|
|
155
|
+
if (!rootInfo
|
|
156
|
+
|| !rootInfo.isDirectory()
|
|
157
|
+
|| rootInfo.isSymbolicLink()
|
|
158
|
+
|| !checkOwnerAndMode(rootInfo.uid, rootInfo.mode, 0o022)
|
|
159
|
+
|| (await realpath(artifactsDirectory)) !== resolve(artifactsDirectory)) {
|
|
160
|
+
refuse('INPUT_INVALID', '/host/artifactsDirectory', { phase: 'restore' });
|
|
161
|
+
}
|
|
162
|
+
const blobsDir = join(artifactsDirectory, 'blobs');
|
|
163
|
+
try {
|
|
164
|
+
await mkdir(blobsDir, { mode: 0o700 });
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
if (error.code !== 'EEXIST')
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
170
|
+
const blobsInfo = await lstat(blobsDir);
|
|
171
|
+
if (!blobsInfo.isDirectory() || blobsInfo.isSymbolicLink() || !checkOwnerAndMode(blobsInfo.uid, blobsInfo.mode, 0o077)) {
|
|
172
|
+
refuse('RECOVERY_REQUIRED', '/host/artifactsDirectory', { phase: 'restore' });
|
|
173
|
+
}
|
|
174
|
+
const sha256Dir = join(blobsDir, 'sha256');
|
|
175
|
+
try {
|
|
176
|
+
await mkdir(sha256Dir, { mode: 0o700 });
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
if (error.code !== 'EEXIST')
|
|
180
|
+
throw error;
|
|
181
|
+
}
|
|
182
|
+
const sha256Info = await lstat(sha256Dir);
|
|
183
|
+
if (!sha256Info.isDirectory() || sha256Info.isSymbolicLink() || !checkOwnerAndMode(sha256Info.uid, sha256Info.mode, 0o077)) {
|
|
184
|
+
refuse('RECOVERY_REQUIRED', '/host/artifactsDirectory', { phase: 'restore' });
|
|
185
|
+
}
|
|
186
|
+
return sha256Dir;
|
|
187
|
+
}
|
|
188
|
+
export async function verifyCasSha256DirAsync(artifactsDirectory, errorPath = '/artifactsDirectory') {
|
|
189
|
+
let rootInfo;
|
|
190
|
+
try {
|
|
191
|
+
rootInfo = await lstat(artifactsDirectory);
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
refuse('RECOVERY_REQUIRED', errorPath, { phase: 'restore' });
|
|
195
|
+
}
|
|
196
|
+
if (!rootInfo.isDirectory()
|
|
197
|
+
|| rootInfo.isSymbolicLink()
|
|
198
|
+
|| !checkOwnerAndMode(rootInfo.uid, rootInfo.mode, 0o022)
|
|
199
|
+
|| (await realpath(artifactsDirectory).catch(() => '')) !== resolve(artifactsDirectory)) {
|
|
200
|
+
refuse('RECOVERY_REQUIRED', errorPath, { phase: 'restore' });
|
|
201
|
+
}
|
|
202
|
+
const blobsDir = join(artifactsDirectory, 'blobs');
|
|
203
|
+
const sha256Dir = join(blobsDir, 'sha256');
|
|
204
|
+
for (const dir of [blobsDir, sha256Dir]) {
|
|
205
|
+
let info;
|
|
206
|
+
try {
|
|
207
|
+
info = await lstat(dir);
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
refuse('RECOVERY_REQUIRED', errorPath, { phase: 'restore' });
|
|
211
|
+
}
|
|
212
|
+
if (!info.isDirectory() || info.isSymbolicLink() || !checkOwnerAndMode(info.uid, info.mode, 0o077)) {
|
|
213
|
+
refuse('RECOVERY_REQUIRED', errorPath, { phase: 'restore' });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return sha256Dir;
|
|
217
|
+
}
|
|
218
|
+
export const verifyCasSha256Dir = verifyCasSha256DirAsync;
|
|
219
|
+
export function verifyCasSha256DirSync(artifactsDirectory, errorPath = '/restore') {
|
|
220
|
+
let rootInfo;
|
|
221
|
+
try {
|
|
222
|
+
rootInfo = lstatSync(artifactsDirectory);
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
refuse('RECOVERY_REQUIRED', errorPath, { phase: 'restore' });
|
|
226
|
+
}
|
|
227
|
+
let resolvedRoot = '';
|
|
228
|
+
try {
|
|
229
|
+
resolvedRoot = realpathSync(artifactsDirectory);
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
refuse('RECOVERY_REQUIRED', errorPath, { phase: 'restore' });
|
|
233
|
+
}
|
|
234
|
+
if (!rootInfo.isDirectory()
|
|
235
|
+
|| rootInfo.isSymbolicLink()
|
|
236
|
+
|| !checkOwnerAndMode(rootInfo.uid, rootInfo.mode, 0o022)
|
|
237
|
+
|| resolvedRoot !== resolve(artifactsDirectory)) {
|
|
238
|
+
refuse('RECOVERY_REQUIRED', errorPath, { phase: 'restore' });
|
|
239
|
+
}
|
|
240
|
+
const blobsDir = join(artifactsDirectory, 'blobs');
|
|
241
|
+
const sha256Dir = join(blobsDir, 'sha256');
|
|
242
|
+
for (const dir of [blobsDir, sha256Dir]) {
|
|
243
|
+
let info;
|
|
244
|
+
try {
|
|
245
|
+
info = lstatSync(dir);
|
|
246
|
+
}
|
|
247
|
+
catch {
|
|
248
|
+
refuse('RECOVERY_REQUIRED', errorPath, { phase: 'restore' });
|
|
249
|
+
}
|
|
250
|
+
if (!info.isDirectory() || info.isSymbolicLink() || !checkOwnerAndMode(info.uid, info.mode, 0o077)) {
|
|
251
|
+
refuse('RECOVERY_REQUIRED', errorPath, { phase: 'restore' });
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return sha256Dir;
|
|
255
|
+
}
|
|
256
|
+
export function verifyRegularFileSync(filePath, options) {
|
|
257
|
+
let linfo;
|
|
258
|
+
try {
|
|
259
|
+
linfo = lstatSync(filePath);
|
|
260
|
+
}
|
|
261
|
+
catch {
|
|
262
|
+
refuse(options.structuralCode, options.errorPath);
|
|
263
|
+
}
|
|
264
|
+
if (linfo.isSymbolicLink() || !linfo.isFile() || linfo.nlink !== 1) {
|
|
265
|
+
refuse(options.structuralCode, options.errorPath);
|
|
266
|
+
}
|
|
267
|
+
if (options.requireReadOnly && (linfo.mode & 0o222) !== 0) {
|
|
268
|
+
refuse(options.structuralCode, options.errorPath);
|
|
269
|
+
}
|
|
270
|
+
if (linfo.size !== options.byteLength) {
|
|
271
|
+
refuse(options.contentCode, options.errorPath);
|
|
272
|
+
}
|
|
273
|
+
let fd;
|
|
274
|
+
try {
|
|
275
|
+
fd = openSync(filePath, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
276
|
+
}
|
|
277
|
+
catch {
|
|
278
|
+
refuse(options.structuralCode, options.errorPath);
|
|
279
|
+
}
|
|
280
|
+
try {
|
|
281
|
+
const before = fstatSync(fd);
|
|
282
|
+
if (!before.isFile()
|
|
283
|
+
|| before.nlink !== 1
|
|
284
|
+
|| before.dev !== linfo.dev
|
|
285
|
+
|| before.ino !== linfo.ino
|
|
286
|
+
|| !checkOwnerAndMode(before.uid, options.requireReadOnly ? before.mode : 0, options.requireReadOnly ? 0o222 : 0)) {
|
|
287
|
+
refuse(options.structuralCode, options.errorPath);
|
|
288
|
+
}
|
|
289
|
+
if (before.size !== options.byteLength) {
|
|
290
|
+
refuse(options.contentCode, options.errorPath);
|
|
291
|
+
}
|
|
292
|
+
const sha256 = createHash('sha256');
|
|
293
|
+
const gitHash = options.gitObjectFormat
|
|
294
|
+
? createHash(options.gitObjectFormat).update(`blob ${options.byteLength}\0`)
|
|
295
|
+
: null;
|
|
296
|
+
const chunkBuf = Buffer.allocUnsafe(Math.min(CAS_CHUNK_BYTES, Math.max(1, options.byteLength + 1)));
|
|
297
|
+
let totalRead = 0;
|
|
298
|
+
for (;;) {
|
|
299
|
+
const n = readSync(fd, chunkBuf, 0, chunkBuf.length, totalRead);
|
|
300
|
+
if (n === 0)
|
|
301
|
+
break;
|
|
302
|
+
const slice = chunkBuf.subarray(0, n);
|
|
303
|
+
totalRead += n;
|
|
304
|
+
if (totalRead > options.byteLength) {
|
|
305
|
+
refuse(options.contentCode, options.errorPath);
|
|
306
|
+
}
|
|
307
|
+
sha256.update(slice);
|
|
308
|
+
gitHash?.update(slice);
|
|
309
|
+
}
|
|
310
|
+
const after = fstatSync(fd);
|
|
311
|
+
if (!after.isFile()
|
|
312
|
+
|| after.nlink !== 1
|
|
313
|
+
|| after.dev !== before.dev
|
|
314
|
+
|| after.ino !== before.ino
|
|
315
|
+
|| after.size !== before.size
|
|
316
|
+
|| after.mtimeMs !== before.mtimeMs
|
|
317
|
+
|| after.ctimeMs !== before.ctimeMs
|
|
318
|
+
|| (options.requireReadOnly && (after.mode & 0o222) !== 0)) {
|
|
319
|
+
refuse(options.structuralCode, options.errorPath);
|
|
320
|
+
}
|
|
321
|
+
if (totalRead !== options.byteLength || sha256.digest('hex') !== options.sha256Hex) {
|
|
322
|
+
refuse(options.contentCode, options.errorPath);
|
|
323
|
+
}
|
|
324
|
+
return { gitOid: gitHash ? gitHash.digest('hex') : null };
|
|
325
|
+
}
|
|
326
|
+
finally {
|
|
327
|
+
closeSync(fd);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
export async function verifyRegularFileAsync(filePath, options) {
|
|
331
|
+
let linfo;
|
|
332
|
+
try {
|
|
333
|
+
linfo = await lstat(filePath);
|
|
334
|
+
}
|
|
335
|
+
catch {
|
|
336
|
+
refuse(options.structuralCode, options.errorPath);
|
|
337
|
+
}
|
|
338
|
+
if (linfo.isSymbolicLink() || !linfo.isFile() || linfo.nlink !== 1) {
|
|
339
|
+
refuse(options.structuralCode, options.errorPath);
|
|
340
|
+
}
|
|
341
|
+
if (options.requireReadOnly && (linfo.mode & 0o222) !== 0) {
|
|
342
|
+
refuse(options.structuralCode, options.errorPath);
|
|
343
|
+
}
|
|
344
|
+
if (linfo.size !== options.byteLength) {
|
|
345
|
+
refuse(options.contentCode, options.errorPath);
|
|
346
|
+
}
|
|
347
|
+
let fh;
|
|
348
|
+
try {
|
|
349
|
+
fh = await open(filePath, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
350
|
+
}
|
|
351
|
+
catch {
|
|
352
|
+
refuse(options.structuralCode, options.errorPath);
|
|
353
|
+
}
|
|
354
|
+
try {
|
|
355
|
+
const before = await fh.stat();
|
|
356
|
+
if (!before.isFile()
|
|
357
|
+
|| before.nlink !== 1
|
|
358
|
+
|| before.dev !== linfo.dev
|
|
359
|
+
|| before.ino !== linfo.ino
|
|
360
|
+
|| !checkOwnerAndMode(before.uid, options.requireReadOnly ? before.mode : 0, options.requireReadOnly ? 0o222 : 0)) {
|
|
361
|
+
refuse(options.structuralCode, options.errorPath);
|
|
362
|
+
}
|
|
363
|
+
if (before.size !== options.byteLength) {
|
|
364
|
+
refuse(options.contentCode, options.errorPath);
|
|
365
|
+
}
|
|
366
|
+
const sha256 = createHash('sha256');
|
|
367
|
+
const gitHash = options.gitObjectFormat
|
|
368
|
+
? createHash(options.gitObjectFormat).update(`blob ${options.byteLength}\0`)
|
|
369
|
+
: null;
|
|
370
|
+
const chunkBuf = Buffer.allocUnsafe(Math.min(CAS_CHUNK_BYTES, Math.max(1, options.byteLength)));
|
|
371
|
+
let totalRead = 0;
|
|
372
|
+
while (totalRead < options.byteLength) {
|
|
373
|
+
const toRead = Math.min(chunkBuf.length, options.byteLength - totalRead);
|
|
374
|
+
const { bytesRead } = await fh.read(chunkBuf, 0, toRead, totalRead);
|
|
375
|
+
if (bytesRead <= 0)
|
|
376
|
+
break;
|
|
377
|
+
const slice = chunkBuf.subarray(0, bytesRead);
|
|
378
|
+
totalRead += bytesRead;
|
|
379
|
+
sha256.update(slice);
|
|
380
|
+
gitHash?.update(slice);
|
|
381
|
+
}
|
|
382
|
+
const probe = Buffer.allocUnsafe(1);
|
|
383
|
+
const { bytesRead: extraBytes } = await fh.read(probe, 0, 1, totalRead);
|
|
384
|
+
if (extraBytes !== 0) {
|
|
385
|
+
refuse(options.contentCode, options.errorPath);
|
|
386
|
+
}
|
|
387
|
+
const after = await fh.stat();
|
|
388
|
+
if (!after.isFile()
|
|
389
|
+
|| after.nlink !== 1
|
|
390
|
+
|| after.dev !== before.dev
|
|
391
|
+
|| after.ino !== before.ino
|
|
392
|
+
|| after.size !== before.size
|
|
393
|
+
|| after.mtimeMs !== before.mtimeMs
|
|
394
|
+
|| after.ctimeMs !== before.ctimeMs
|
|
395
|
+
|| (options.requireReadOnly && (after.mode & 0o222) !== 0)) {
|
|
396
|
+
refuse(options.structuralCode, options.errorPath);
|
|
397
|
+
}
|
|
398
|
+
if (totalRead !== options.byteLength || sha256.digest('hex') !== options.sha256Hex) {
|
|
399
|
+
refuse(options.contentCode, options.errorPath);
|
|
400
|
+
}
|
|
401
|
+
return { gitOid: gitHash ? gitHash.digest('hex') : null };
|
|
402
|
+
}
|
|
403
|
+
finally {
|
|
404
|
+
await fh.close();
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
export async function readBlobChunkAsync(blobPath, expectedLength, offset, length) {
|
|
408
|
+
let fh;
|
|
409
|
+
try {
|
|
410
|
+
fh = await open(blobPath, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
411
|
+
}
|
|
412
|
+
catch {
|
|
413
|
+
refuse('RECOVERY_REQUIRED', '/restore/workspace');
|
|
414
|
+
}
|
|
415
|
+
try {
|
|
416
|
+
const before = await fh.stat();
|
|
417
|
+
if (!before.isFile()
|
|
418
|
+
|| before.nlink !== 1
|
|
419
|
+
|| !checkOwnerAndMode(before.uid, before.mode, 0o222)
|
|
420
|
+
|| before.size !== expectedLength) {
|
|
421
|
+
refuse('RECOVERY_REQUIRED', '/restore/workspace');
|
|
422
|
+
}
|
|
423
|
+
const buf = Buffer.allocUnsafe(length);
|
|
424
|
+
let readTotal = 0;
|
|
425
|
+
while (readTotal < length) {
|
|
426
|
+
const toRead = Math.min(CAS_CHUNK_BYTES, length - readTotal);
|
|
427
|
+
const { bytesRead } = await fh.read(buf, readTotal, toRead, offset + readTotal);
|
|
428
|
+
if (bytesRead <= 0)
|
|
429
|
+
refuse('RESOURCE_MISMATCH', '/restore/workspace');
|
|
430
|
+
readTotal += bytesRead;
|
|
431
|
+
}
|
|
432
|
+
const after = await fh.stat();
|
|
433
|
+
if (!after.isFile()
|
|
434
|
+
|| after.nlink !== 1
|
|
435
|
+
|| (after.mode & 0o222) !== 0
|
|
436
|
+
|| after.dev !== before.dev
|
|
437
|
+
|| after.ino !== before.ino
|
|
438
|
+
|| after.size !== before.size
|
|
439
|
+
|| after.mtimeMs !== before.mtimeMs
|
|
440
|
+
|| after.ctimeMs !== before.ctimeMs) {
|
|
441
|
+
refuse('RECOVERY_REQUIRED', '/restore/workspace');
|
|
442
|
+
}
|
|
443
|
+
return buf;
|
|
444
|
+
}
|
|
445
|
+
finally {
|
|
446
|
+
await fh.close();
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
export async function verifyCasBlobAsync(blobPath, expected, errorPath = '/workspace') {
|
|
450
|
+
let linfo;
|
|
451
|
+
try {
|
|
452
|
+
linfo = await lstat(blobPath);
|
|
453
|
+
}
|
|
454
|
+
catch {
|
|
455
|
+
refuse('RECOVERY_REQUIRED', errorPath, { phase: 'restore' });
|
|
456
|
+
}
|
|
457
|
+
if (linfo.isSymbolicLink() || !linfo.isFile() || linfo.nlink !== 1 || !checkOwnerAndMode(linfo.uid, linfo.mode, 0o222)) {
|
|
458
|
+
refuse('RECOVERY_REQUIRED', errorPath, { phase: 'restore' });
|
|
459
|
+
}
|
|
460
|
+
if (linfo.size !== expected.byteLength) {
|
|
461
|
+
refuse('RESOURCE_MISMATCH', errorPath, { phase: 'restore' });
|
|
462
|
+
}
|
|
463
|
+
let fd;
|
|
464
|
+
try {
|
|
465
|
+
fd = await open(blobPath, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
466
|
+
}
|
|
467
|
+
catch {
|
|
468
|
+
refuse('RECOVERY_REQUIRED', errorPath, { phase: 'restore' });
|
|
469
|
+
}
|
|
470
|
+
try {
|
|
471
|
+
const before = await fd.stat();
|
|
472
|
+
if (!before.isFile()
|
|
473
|
+
|| before.nlink !== 1
|
|
474
|
+
|| !checkOwnerAndMode(before.uid, before.mode, 0o222)
|
|
475
|
+
|| before.dev !== linfo.dev
|
|
476
|
+
|| before.ino !== linfo.ino) {
|
|
477
|
+
refuse('RECOVERY_REQUIRED', errorPath, { phase: 'restore' });
|
|
478
|
+
}
|
|
479
|
+
if (before.size !== expected.byteLength) {
|
|
480
|
+
refuse('RESOURCE_MISMATCH', errorPath, { phase: 'restore' });
|
|
481
|
+
}
|
|
482
|
+
const sha256 = createHash('sha256');
|
|
483
|
+
const collected = expected.collectBytes ? Buffer.allocUnsafe(expected.byteLength) : null;
|
|
484
|
+
const chunkBuf = Buffer.allocUnsafe(Math.min(CAS_CHUNK_BYTES, Math.max(1, expected.byteLength + 1)));
|
|
485
|
+
let totalRead = 0;
|
|
486
|
+
for (;;) {
|
|
487
|
+
const part = await fd.read(chunkBuf, 0, chunkBuf.length, totalRead);
|
|
488
|
+
if (part.bytesRead === 0)
|
|
489
|
+
break;
|
|
490
|
+
const slice = chunkBuf.subarray(0, part.bytesRead);
|
|
491
|
+
if (totalRead + slice.length > expected.byteLength) {
|
|
492
|
+
refuse('RESOURCE_MISMATCH', errorPath, { phase: 'restore' });
|
|
493
|
+
}
|
|
494
|
+
expected.streamChecker?.push(slice);
|
|
495
|
+
if (collected !== null) {
|
|
496
|
+
slice.copy(collected, totalRead);
|
|
497
|
+
}
|
|
498
|
+
totalRead += slice.length;
|
|
499
|
+
sha256.update(slice);
|
|
500
|
+
}
|
|
501
|
+
expected.streamChecker?.finish();
|
|
502
|
+
const after = await fd.stat();
|
|
503
|
+
if (!after.isFile()
|
|
504
|
+
|| after.nlink !== 1
|
|
505
|
+
|| (after.mode & 0o222) !== 0
|
|
506
|
+
|| after.dev !== before.dev
|
|
507
|
+
|| after.ino !== before.ino
|
|
508
|
+
|| after.size !== before.size
|
|
509
|
+
|| after.mtimeMs !== before.mtimeMs
|
|
510
|
+
|| after.ctimeMs !== before.ctimeMs) {
|
|
511
|
+
refuse('RECOVERY_REQUIRED', errorPath, { phase: 'restore' });
|
|
512
|
+
}
|
|
513
|
+
if (totalRead !== expected.byteLength || sha256.digest('hex') !== expected.sha256Hex) {
|
|
514
|
+
refuse('RESOURCE_MISMATCH', errorPath, { phase: 'restore' });
|
|
515
|
+
}
|
|
516
|
+
return collected;
|
|
517
|
+
}
|
|
518
|
+
finally {
|
|
519
|
+
await fd.close();
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
export async function publishCandidateFileToCas(sourcePath, sha256Dir, expected, signal, createCandidateStreamChecker = () => createBuiltInPiStreamChecker(new Set())) {
|
|
523
|
+
if (signal.aborted)
|
|
524
|
+
refuse('CANCELLED', '', { phase: 'restore' });
|
|
525
|
+
const tmpPath = join(sha256Dir, '.tmp-' + randomBytes(16).toString('hex'));
|
|
526
|
+
let sourceFd = null;
|
|
527
|
+
let tmpHandle = null;
|
|
528
|
+
let tmpCreated = false;
|
|
529
|
+
let checker = null;
|
|
530
|
+
let checkerFinished = false;
|
|
531
|
+
try {
|
|
532
|
+
try {
|
|
533
|
+
sourceFd = await open(sourcePath, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
534
|
+
}
|
|
535
|
+
catch {
|
|
536
|
+
refuse('RECOVERY_REQUIRED', '', { phase: 'restore' });
|
|
537
|
+
}
|
|
538
|
+
const before = await sourceFd.stat();
|
|
539
|
+
if (!before.isFile() || before.nlink !== 1 || before.size !== expected.byteLength) {
|
|
540
|
+
refuse('RECOVERY_REQUIRED', '', { phase: 'restore' });
|
|
541
|
+
}
|
|
542
|
+
tmpHandle = await open(tmpPath, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | constants.O_NOFOLLOW, 0o600);
|
|
543
|
+
tmpCreated = true;
|
|
544
|
+
checker = createCandidateStreamChecker();
|
|
545
|
+
const hash = createHash('sha256');
|
|
546
|
+
const chunkBuf = Buffer.allocUnsafe(Math.min(CAS_CHUNK_BYTES, Math.max(1, expected.byteLength + 1)));
|
|
547
|
+
let totalRead = 0;
|
|
548
|
+
for (;;) {
|
|
549
|
+
if (signal.aborted)
|
|
550
|
+
refuse('CANCELLED', '', { phase: 'restore' });
|
|
551
|
+
const part = await sourceFd.read(chunkBuf, 0, chunkBuf.length, totalRead);
|
|
552
|
+
if (part.bytesRead === 0)
|
|
553
|
+
break;
|
|
554
|
+
const slice = chunkBuf.subarray(0, part.bytesRead);
|
|
555
|
+
totalRead += slice.length;
|
|
556
|
+
if (totalRead > expected.byteLength) {
|
|
557
|
+
refuse('RECOVERY_REQUIRED', '', { phase: 'restore' });
|
|
558
|
+
}
|
|
559
|
+
checker.push(slice);
|
|
560
|
+
hash.update(slice);
|
|
561
|
+
await writeAll(tmpHandle, slice);
|
|
562
|
+
}
|
|
563
|
+
checker.finish();
|
|
564
|
+
checkerFinished = true;
|
|
565
|
+
const after = await sourceFd.stat();
|
|
566
|
+
const hex = hash.digest('hex');
|
|
567
|
+
if (!after.isFile()
|
|
568
|
+
|| after.nlink !== 1
|
|
569
|
+
|| after.dev !== before.dev
|
|
570
|
+
|| after.ino !== before.ino
|
|
571
|
+
|| after.size !== before.size
|
|
572
|
+
|| after.mtimeMs !== before.mtimeMs
|
|
573
|
+
|| after.ctimeMs !== before.ctimeMs
|
|
574
|
+
|| totalRead !== expected.byteLength
|
|
575
|
+
|| hex !== expected.sha256Hex) {
|
|
576
|
+
refuse('RECOVERY_REQUIRED', '', { phase: 'restore' });
|
|
577
|
+
}
|
|
578
|
+
await tmpHandle.chmod(0o400);
|
|
579
|
+
await tmpHandle.sync();
|
|
580
|
+
await tmpHandle.close();
|
|
581
|
+
tmpHandle = null;
|
|
582
|
+
if (signal.aborted)
|
|
583
|
+
refuse('CANCELLED', '', { phase: 'restore' });
|
|
584
|
+
const finalPath = join(sha256Dir, hex);
|
|
585
|
+
let linked = false;
|
|
586
|
+
try {
|
|
587
|
+
await link(tmpPath, finalPath);
|
|
588
|
+
linked = true;
|
|
589
|
+
}
|
|
590
|
+
catch (error) {
|
|
591
|
+
if (error.code !== 'EEXIST') {
|
|
592
|
+
refuse('RECOVERY_REQUIRED', '', { phase: 'restore' });
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
await unlink(tmpPath);
|
|
596
|
+
tmpCreated = false;
|
|
597
|
+
if (!linked) {
|
|
598
|
+
// Allow a racing publisher's link()+unlink() pair to settle nlink from 2 -> 1.
|
|
599
|
+
for (let attempt = 0; attempt < 20; attempt++) {
|
|
600
|
+
if (signal.aborted)
|
|
601
|
+
refuse('CANCELLED', '', { phase: 'restore' });
|
|
602
|
+
const st = await lstat(finalPath).catch(() => null);
|
|
603
|
+
if (st === null || st.isSymbolicLink() || !st.isFile() || st.nlink <= 1) {
|
|
604
|
+
break;
|
|
605
|
+
}
|
|
606
|
+
await new Promise(resolveDelay => setTimeout(resolveDelay, 5));
|
|
607
|
+
}
|
|
608
|
+
if (signal.aborted)
|
|
609
|
+
refuse('CANCELLED', '', { phase: 'restore' });
|
|
610
|
+
const dedupChecker = createCandidateStreamChecker();
|
|
611
|
+
let dedupCheckerError = null;
|
|
612
|
+
let dedupCheckerFinished = false;
|
|
613
|
+
const wrappedChecker = {
|
|
614
|
+
push: chunk => {
|
|
615
|
+
try {
|
|
616
|
+
dedupChecker.push(chunk);
|
|
617
|
+
}
|
|
618
|
+
catch (err) {
|
|
619
|
+
dedupCheckerError = err;
|
|
620
|
+
throw err;
|
|
621
|
+
}
|
|
622
|
+
},
|
|
623
|
+
finish: () => {
|
|
624
|
+
try {
|
|
625
|
+
dedupChecker.finish();
|
|
626
|
+
dedupCheckerFinished = true;
|
|
627
|
+
}
|
|
628
|
+
catch (err) {
|
|
629
|
+
dedupCheckerError = err;
|
|
630
|
+
throw err;
|
|
631
|
+
}
|
|
632
|
+
},
|
|
633
|
+
};
|
|
634
|
+
try {
|
|
635
|
+
await verifyCasBlobAsync(finalPath, {
|
|
636
|
+
byteLength: expected.byteLength,
|
|
637
|
+
sha256Hex: hex,
|
|
638
|
+
collectBytes: false,
|
|
639
|
+
streamChecker: wrappedChecker,
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
catch {
|
|
643
|
+
if (!dedupCheckerFinished) {
|
|
644
|
+
try {
|
|
645
|
+
dedupChecker.finish();
|
|
646
|
+
}
|
|
647
|
+
catch {
|
|
648
|
+
// Ignore cleanup error after stream verification failure.
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
if (dedupCheckerError !== null)
|
|
652
|
+
throw dedupCheckerError;
|
|
653
|
+
refuse('RECOVERY_REQUIRED', '', { phase: 'restore' });
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
return finalPath;
|
|
657
|
+
}
|
|
658
|
+
finally {
|
|
659
|
+
if (checker && !checkerFinished) {
|
|
660
|
+
try {
|
|
661
|
+
checker.finish();
|
|
662
|
+
}
|
|
663
|
+
catch {
|
|
664
|
+
// Ignore cleanup error after ingestion failure.
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
if (sourceFd) {
|
|
668
|
+
await sourceFd.close().catch(() => { });
|
|
669
|
+
}
|
|
670
|
+
if (tmpHandle) {
|
|
671
|
+
await tmpHandle.close().catch(() => { });
|
|
672
|
+
}
|
|
673
|
+
if (tmpCreated) {
|
|
674
|
+
await unlink(tmpPath).catch(() => { });
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
export async function streamCopyVerifiedBlob(sourcePath, targetPath, expected, mode, options) {
|
|
679
|
+
void options;
|
|
680
|
+
if (typeof sourcePath !== 'string'
|
|
681
|
+
|| !isAbsolute(sourcePath)
|
|
682
|
+
|| sourcePath.length > 4096
|
|
683
|
+
|| /[\0\r\n]/.test(sourcePath)
|
|
684
|
+
|| typeof targetPath !== 'string'
|
|
685
|
+
|| !isAbsolute(targetPath)
|
|
686
|
+
|| targetPath.length > 4096
|
|
687
|
+
|| /[\0\r\n]/.test(targetPath)) {
|
|
688
|
+
refuse('RECOVERY_REQUIRED', '/candidate');
|
|
689
|
+
}
|
|
690
|
+
let targetExists = false;
|
|
691
|
+
try {
|
|
692
|
+
await lstat(targetPath);
|
|
693
|
+
targetExists = true;
|
|
694
|
+
}
|
|
695
|
+
catch (error) {
|
|
696
|
+
if (!absent(error))
|
|
697
|
+
refuse('RECOVERY_REQUIRED', '/candidate');
|
|
698
|
+
}
|
|
699
|
+
if (targetExists) {
|
|
700
|
+
refuse('RECOVERY_REQUIRED', '/candidate');
|
|
701
|
+
}
|
|
702
|
+
const tmpPath = join(dirname(targetPath), `.lw-stage-${randomBytes(12).toString('hex')}`);
|
|
703
|
+
let srcHandle = null;
|
|
704
|
+
let tmpHandle = null;
|
|
705
|
+
let destVerify = null;
|
|
706
|
+
let tmpCreated = false;
|
|
707
|
+
let tmpUnlinked = false;
|
|
708
|
+
try {
|
|
709
|
+
srcHandle = await open(sourcePath, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
710
|
+
const srcBefore = await srcHandle.stat();
|
|
711
|
+
if (srcBefore.isSymbolicLink()
|
|
712
|
+
|| !srcBefore.isFile()
|
|
713
|
+
|| srcBefore.nlink !== 1
|
|
714
|
+
|| !checkOwnerAndMode(srcBefore.uid, srcBefore.mode, 0o222)
|
|
715
|
+
|| srcBefore.size !== expected.byteLength) {
|
|
716
|
+
refuse('RECOVERY_REQUIRED', '/candidate');
|
|
717
|
+
}
|
|
718
|
+
tmpHandle = await open(tmpPath, constants.O_CREAT | constants.O_EXCL | constants.O_RDWR | constants.O_NOFOLLOW, 0o600);
|
|
719
|
+
tmpCreated = true;
|
|
720
|
+
const createdStat = await tmpHandle.stat();
|
|
721
|
+
if (!createdStat.isFile()
|
|
722
|
+
|| createdStat.isSymbolicLink()
|
|
723
|
+
|| createdStat.nlink !== 1
|
|
724
|
+
|| (createdStat.dev === srcBefore.dev && createdStat.ino === srcBefore.ino)) {
|
|
725
|
+
refuse('RECOVERY_REQUIRED', '/candidate');
|
|
726
|
+
}
|
|
727
|
+
const buf = Buffer.allocUnsafe(Math.min(CAS_CHUNK_BYTES, Math.max(1, expected.byteLength + 1)));
|
|
728
|
+
const writeSha = createHash('sha256');
|
|
729
|
+
let writtenBytes = 0;
|
|
730
|
+
for (;;) {
|
|
731
|
+
const part = await srcHandle.read(buf, 0, buf.length, writtenBytes);
|
|
732
|
+
if (part.bytesRead === 0)
|
|
733
|
+
break;
|
|
734
|
+
const slice = buf.subarray(0, part.bytesRead);
|
|
735
|
+
writtenBytes += slice.length;
|
|
736
|
+
if (writtenBytes > expected.byteLength) {
|
|
737
|
+
refuse('RESOURCE_MISMATCH', '/candidate');
|
|
738
|
+
}
|
|
739
|
+
writeSha.update(slice);
|
|
740
|
+
await writeAll(tmpHandle, slice);
|
|
741
|
+
}
|
|
742
|
+
const srcAfter = await srcHandle.stat();
|
|
743
|
+
if (!srcAfter.isFile()
|
|
744
|
+
|| srcAfter.isSymbolicLink()
|
|
745
|
+
|| srcAfter.nlink !== 1
|
|
746
|
+
|| (srcAfter.mode & 0o222) !== 0
|
|
747
|
+
|| srcAfter.dev !== srcBefore.dev
|
|
748
|
+
|| srcAfter.ino !== srcBefore.ino
|
|
749
|
+
|| srcAfter.size !== srcBefore.size
|
|
750
|
+
|| srcAfter.mtimeMs !== srcBefore.mtimeMs
|
|
751
|
+
|| srcAfter.ctimeMs !== srcBefore.ctimeMs) {
|
|
752
|
+
refuse('RECOVERY_REQUIRED', '/candidate');
|
|
753
|
+
}
|
|
754
|
+
const writeShaHex = writeSha.digest('hex');
|
|
755
|
+
if (writtenBytes !== expected.byteLength || writeShaHex !== expected.sha256Hex) {
|
|
756
|
+
refuse('RESOURCE_MISMATCH', '/candidate');
|
|
757
|
+
}
|
|
758
|
+
const storedSha = createHash('sha256');
|
|
759
|
+
let readOffset = 0;
|
|
760
|
+
while (readOffset < writtenBytes) {
|
|
761
|
+
const toRead = Math.min(buf.byteLength, writtenBytes - readOffset);
|
|
762
|
+
const part = await tmpHandle.read(buf, 0, toRead, readOffset);
|
|
763
|
+
if (part.bytesRead === 0)
|
|
764
|
+
break;
|
|
765
|
+
storedSha.update(buf.subarray(0, part.bytesRead));
|
|
766
|
+
readOffset += part.bytesRead;
|
|
767
|
+
}
|
|
768
|
+
const probe = Buffer.allocUnsafe(1);
|
|
769
|
+
const extraTmpRead = (await tmpHandle.read(probe, 0, 1, readOffset)).bytesRead;
|
|
770
|
+
const tmpAfterRead = await tmpHandle.stat();
|
|
771
|
+
if (extraTmpRead !== 0
|
|
772
|
+
|| readOffset !== writtenBytes
|
|
773
|
+
|| !tmpAfterRead.isFile()
|
|
774
|
+
|| tmpAfterRead.isSymbolicLink()
|
|
775
|
+
|| tmpAfterRead.dev !== createdStat.dev
|
|
776
|
+
|| tmpAfterRead.ino !== createdStat.ino
|
|
777
|
+
|| tmpAfterRead.nlink !== 1
|
|
778
|
+
|| tmpAfterRead.size !== writtenBytes) {
|
|
779
|
+
refuse('RECOVERY_REQUIRED', '/candidate');
|
|
780
|
+
}
|
|
781
|
+
if (storedSha.digest('hex') !== writeShaHex) {
|
|
782
|
+
refuse('RESOURCE_MISMATCH', '/candidate');
|
|
783
|
+
}
|
|
784
|
+
await tmpHandle.chmod(mode);
|
|
785
|
+
await tmpHandle.sync();
|
|
786
|
+
const sealedStat = await tmpHandle.stat();
|
|
787
|
+
if (!sealedStat.isFile()
|
|
788
|
+
|| sealedStat.isSymbolicLink()
|
|
789
|
+
|| sealedStat.dev !== createdStat.dev
|
|
790
|
+
|| sealedStat.ino !== createdStat.ino
|
|
791
|
+
|| sealedStat.nlink !== 1
|
|
792
|
+
|| sealedStat.size !== writtenBytes
|
|
793
|
+
|| (sealedStat.mode & 0o777) !== (mode & 0o777)) {
|
|
794
|
+
refuse('RECOVERY_REQUIRED', '/candidate');
|
|
795
|
+
}
|
|
796
|
+
await link(tmpPath, targetPath);
|
|
797
|
+
await unlink(tmpPath);
|
|
798
|
+
tmpUnlinked = true;
|
|
799
|
+
destVerify = await open(targetPath, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
800
|
+
const destStat = await destVerify.stat();
|
|
801
|
+
const pinnedStat = await tmpHandle.stat();
|
|
802
|
+
if (!destStat.isFile()
|
|
803
|
+
|| destStat.isSymbolicLink()
|
|
804
|
+
|| destStat.nlink !== 1
|
|
805
|
+
|| destStat.dev !== createdStat.dev
|
|
806
|
+
|| destStat.ino !== createdStat.ino
|
|
807
|
+
|| destStat.size !== writtenBytes
|
|
808
|
+
|| (destStat.mode & 0o777) !== (mode & 0o777)
|
|
809
|
+
|| pinnedStat.nlink !== 1) {
|
|
810
|
+
refuse('RECOVERY_REQUIRED', '/candidate');
|
|
811
|
+
}
|
|
812
|
+
await destVerify.close();
|
|
813
|
+
destVerify = null;
|
|
814
|
+
await tmpHandle.close();
|
|
815
|
+
tmpHandle = null;
|
|
816
|
+
}
|
|
817
|
+
catch (error) {
|
|
818
|
+
if (error instanceof PiFailure)
|
|
819
|
+
throw error;
|
|
820
|
+
refuse('RECOVERY_REQUIRED', '/candidate');
|
|
821
|
+
}
|
|
822
|
+
finally {
|
|
823
|
+
if (destVerify) {
|
|
824
|
+
await destVerify.close().catch(() => { });
|
|
825
|
+
}
|
|
826
|
+
if (tmpHandle) {
|
|
827
|
+
await tmpHandle.close().catch(() => { });
|
|
828
|
+
}
|
|
829
|
+
if (srcHandle) {
|
|
830
|
+
await srcHandle.close().catch(() => { });
|
|
831
|
+
}
|
|
832
|
+
if (tmpCreated && !tmpUnlinked) {
|
|
833
|
+
await unlink(tmpPath).catch(() => { });
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
}
|