@gpustack/loopwright 0.0.0-stage → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +191 -0
- package/README.md +356 -2
- package/bin/loopwright.js +3 -0
- package/node_modules/@loopwright/agent-pi/dist/adapter-v2.d.ts +9 -0
- package/node_modules/@loopwright/agent-pi/dist/adapter-v2.js +122 -0
- package/node_modules/@loopwright/agent-pi/dist/adapter.d.ts +30 -0
- package/node_modules/@loopwright/agent-pi/dist/adapter.js +340 -0
- package/node_modules/@loopwright/agent-pi/dist/admission.d.ts +25 -0
- package/node_modules/@loopwright/agent-pi/dist/admission.js +65 -0
- package/node_modules/@loopwright/agent-pi/dist/artifacts.d.ts +15 -0
- package/node_modules/@loopwright/agent-pi/dist/artifacts.js +76 -0
- package/node_modules/@loopwright/agent-pi/dist/boundary.d.ts +18 -0
- package/node_modules/@loopwright/agent-pi/dist/boundary.js +113 -0
- package/node_modules/@loopwright/agent-pi/dist/broker-channel.d.ts +4 -0
- package/node_modules/@loopwright/agent-pi/dist/broker-channel.js +121 -0
- package/node_modules/@loopwright/agent-pi/dist/candidate.d.ts +96 -0
- package/node_modules/@loopwright/agent-pi/dist/candidate.js +1712 -0
- package/node_modules/@loopwright/agent-pi/dist/capture.d.ts +39 -0
- package/node_modules/@loopwright/agent-pi/dist/capture.js +146 -0
- package/node_modules/@loopwright/agent-pi/dist/cas.d.ts +51 -0
- package/node_modules/@loopwright/agent-pi/dist/cas.js +836 -0
- package/node_modules/@loopwright/agent-pi/dist/catalog-api.d.ts +3 -0
- package/node_modules/@loopwright/agent-pi/dist/catalog-api.js +2 -0
- package/node_modules/@loopwright/agent-pi/dist/catalog.d.ts +39 -0
- package/node_modules/@loopwright/agent-pi/dist/catalog.js +280 -0
- package/node_modules/@loopwright/agent-pi/dist/circuit-breaker-limits.d.ts +9 -0
- package/node_modules/@loopwright/agent-pi/dist/circuit-breaker-limits.js +12 -0
- package/node_modules/@loopwright/agent-pi/dist/containers.d.ts +29 -0
- package/node_modules/@loopwright/agent-pi/dist/containers.js +160 -0
- package/node_modules/@loopwright/agent-pi/dist/context.d.ts +56 -0
- package/node_modules/@loopwright/agent-pi/dist/context.js +351 -0
- package/node_modules/@loopwright/agent-pi/dist/daemon.d.ts +8 -0
- package/node_modules/@loopwright/agent-pi/dist/daemon.js +52 -0
- package/node_modules/@loopwright/agent-pi/dist/deadline.d.ts +6 -0
- package/node_modules/@loopwright/agent-pi/dist/deadline.js +18 -0
- package/node_modules/@loopwright/agent-pi/dist/decode-capture.d.ts +39 -0
- package/node_modules/@loopwright/agent-pi/dist/decode-capture.js +287 -0
- package/node_modules/@loopwright/agent-pi/dist/descriptor.d.ts +12 -0
- package/node_modules/@loopwright/agent-pi/dist/descriptor.js +17 -0
- package/node_modules/@loopwright/agent-pi/dist/docker-absence.d.ts +2 -0
- package/node_modules/@loopwright/agent-pi/dist/docker-absence.js +9 -0
- package/node_modules/@loopwright/agent-pi/dist/errors.d.ts +7 -0
- package/node_modules/@loopwright/agent-pi/dist/errors.js +19 -0
- package/node_modules/@loopwright/agent-pi/dist/event-sequence.d.ts +6 -0
- package/node_modules/@loopwright/agent-pi/dist/event-sequence.js +64 -0
- package/node_modules/@loopwright/agent-pi/dist/events.d.ts +19 -0
- package/node_modules/@loopwright/agent-pi/dist/events.js +132 -0
- package/node_modules/@loopwright/agent-pi/dist/execution-guard.d.ts +9 -0
- package/node_modules/@loopwright/agent-pi/dist/execution-guard.js +25 -0
- package/node_modules/@loopwright/agent-pi/dist/execution-lease.d.ts +24 -0
- package/node_modules/@loopwright/agent-pi/dist/execution-lease.js +316 -0
- package/node_modules/@loopwright/agent-pi/dist/execution.d.ts +32 -0
- package/node_modules/@loopwright/agent-pi/dist/execution.js +476 -0
- package/node_modules/@loopwright/agent-pi/dist/external-mcp.d.ts +87 -0
- package/node_modules/@loopwright/agent-pi/dist/external-mcp.js +526 -0
- package/node_modules/@loopwright/agent-pi/dist/factory-bootstrap.d.ts +15 -0
- package/node_modules/@loopwright/agent-pi/dist/factory-bootstrap.js +74 -0
- package/node_modules/@loopwright/agent-pi/dist/host-session.d.ts +51 -0
- package/node_modules/@loopwright/agent-pi/dist/host-session.js +2094 -0
- package/node_modules/@loopwright/agent-pi/dist/http-mcp.d.ts +32 -0
- package/node_modules/@loopwright/agent-pi/dist/http-mcp.js +353 -0
- package/node_modules/@loopwright/agent-pi/dist/index.d.ts +7 -0
- package/node_modules/@loopwright/agent-pi/dist/index.js +4 -0
- package/node_modules/@loopwright/agent-pi/dist/lifecycle.d.ts +13 -0
- package/node_modules/@loopwright/agent-pi/dist/lifecycle.js +11 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp-process.d.ts +35 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp-process.js +92 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp-transport.d.ts +25 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp-transport.js +63 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp.d.ts +23 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp.js +212 -0
- package/node_modules/@loopwright/agent-pi/dist/operation.d.ts +5 -0
- package/node_modules/@loopwright/agent-pi/dist/operation.js +28 -0
- package/node_modules/@loopwright/agent-pi/dist/policy-v2.d.ts +10 -0
- package/node_modules/@loopwright/agent-pi/dist/policy-v2.js +64 -0
- package/node_modules/@loopwright/agent-pi/dist/policy.d.ts +13 -0
- package/node_modules/@loopwright/agent-pi/dist/policy.js +260 -0
- package/node_modules/@loopwright/agent-pi/dist/preflight.d.ts +60 -0
- package/node_modules/@loopwright/agent-pi/dist/preflight.js +700 -0
- package/node_modules/@loopwright/agent-pi/dist/progress-summary.d.ts +1 -0
- package/node_modules/@loopwright/agent-pi/dist/progress-summary.js +119 -0
- package/node_modules/@loopwright/agent-pi/dist/protocol.d.ts +17 -0
- package/node_modules/@loopwright/agent-pi/dist/protocol.js +131 -0
- package/node_modules/@loopwright/agent-pi/dist/provider.d.ts +62 -0
- package/node_modules/@loopwright/agent-pi/dist/provider.js +217 -0
- package/node_modules/@loopwright/agent-pi/dist/receipt.d.ts +3 -0
- package/node_modules/@loopwright/agent-pi/dist/receipt.js +64 -0
- package/node_modules/@loopwright/agent-pi/dist/recovery.d.ts +6 -0
- package/node_modules/@loopwright/agent-pi/dist/recovery.js +188 -0
- package/node_modules/@loopwright/agent-pi/dist/resources.d.ts +13 -0
- package/node_modules/@loopwright/agent-pi/dist/resources.js +81 -0
- package/node_modules/@loopwright/agent-pi/dist/response.d.ts +20 -0
- package/node_modules/@loopwright/agent-pi/dist/response.js +259 -0
- package/node_modules/@loopwright/agent-pi/dist/runtime-profile.d.ts +6 -0
- package/node_modules/@loopwright/agent-pi/dist/runtime-profile.js +37 -0
- package/node_modules/@loopwright/agent-pi/dist/sdk-worker.d.ts +14 -0
- package/node_modules/@loopwright/agent-pi/dist/sdk-worker.js +633 -0
- package/node_modules/@loopwright/agent-pi/dist/sender.d.ts +46 -0
- package/node_modules/@loopwright/agent-pi/dist/sender.js +553 -0
- package/node_modules/@loopwright/agent-pi/dist/session-host.d.ts +21 -0
- package/node_modules/@loopwright/agent-pi/dist/session-host.js +315 -0
- package/node_modules/@loopwright/agent-pi/dist/snapshot-transfer.d.ts +14 -0
- package/node_modules/@loopwright/agent-pi/dist/snapshot-transfer.js +102 -0
- package/node_modules/@loopwright/agent-pi/dist/snapshot.d.ts +19 -0
- package/node_modules/@loopwright/agent-pi/dist/snapshot.js +121 -0
- package/node_modules/@loopwright/agent-pi/dist/tool-process.d.ts +32 -0
- package/node_modules/@loopwright/agent-pi/dist/tool-process.js +85 -0
- package/node_modules/@loopwright/agent-pi/dist/tool-worker.d.ts +2 -0
- package/node_modules/@loopwright/agent-pi/dist/tool-worker.js +105 -0
- package/node_modules/@loopwright/agent-pi/dist/tools.d.ts +36 -0
- package/node_modules/@loopwright/agent-pi/dist/tools.js +128 -0
- package/node_modules/@loopwright/agent-pi/dist/types-v2.d.ts +71 -0
- package/node_modules/@loopwright/agent-pi/dist/types-v2.js +1 -0
- package/node_modules/@loopwright/agent-pi/dist/types.d.ts +314 -0
- package/node_modules/@loopwright/agent-pi/dist/types.js +1 -0
- package/node_modules/@loopwright/agent-pi/dist/usage.d.ts +18 -0
- package/node_modules/@loopwright/agent-pi/dist/usage.js +314 -0
- package/node_modules/@loopwright/agent-pi/dist/workspace-mcp.d.ts +27 -0
- package/node_modules/@loopwright/agent-pi/dist/workspace-mcp.js +142 -0
- package/node_modules/@loopwright/agent-pi/package.json +24 -0
- package/node_modules/@loopwright/agent-pi/runtime/Dockerfile +8 -0
- package/node_modules/@loopwright/agent-pi/runtime/seccomp.json +1 -0
- package/node_modules/@loopwright/cli/dist/arguments.d.ts +19 -0
- package/node_modules/@loopwright/cli/dist/arguments.js +358 -0
- package/node_modules/@loopwright/cli/dist/closure.d.ts +93 -0
- package/node_modules/@loopwright/cli/dist/closure.js +230 -0
- package/node_modules/@loopwright/cli/dist/draft.d.ts +9 -0
- package/node_modules/@loopwright/cli/dist/draft.js +106 -0
- package/node_modules/@loopwright/cli/dist/failure-matrix.d.ts +9 -0
- package/node_modules/@loopwright/cli/dist/failure-matrix.js +701 -0
- package/node_modules/@loopwright/cli/dist/index.d.ts +6 -0
- package/node_modules/@loopwright/cli/dist/index.js +5 -0
- package/node_modules/@loopwright/cli/dist/main.d.ts +22 -0
- package/node_modules/@loopwright/cli/dist/main.js +1855 -0
- package/node_modules/@loopwright/cli/package.json +16 -0
- package/node_modules/@loopwright/controller/dist/acceptance.d.ts +43 -0
- package/node_modules/@loopwright/controller/dist/acceptance.js +446 -0
- package/node_modules/@loopwright/controller/dist/benchmark-gate.d.ts +273 -0
- package/node_modules/@loopwright/controller/dist/benchmark-gate.js +3147 -0
- package/node_modules/@loopwright/controller/dist/budget-observations.d.ts +25 -0
- package/node_modules/@loopwright/controller/dist/budget-observations.js +139 -0
- package/node_modules/@loopwright/controller/dist/bundle.d.ts +26 -0
- package/node_modules/@loopwright/controller/dist/bundle.js +64 -0
- package/node_modules/@loopwright/controller/dist/capture.d.ts +89 -0
- package/node_modules/@loopwright/controller/dist/capture.js +587 -0
- package/node_modules/@loopwright/controller/dist/compile.d.ts +3 -0
- package/node_modules/@loopwright/controller/dist/compile.js +402 -0
- package/node_modules/@loopwright/controller/dist/config.d.ts +22 -0
- package/node_modules/@loopwright/controller/dist/config.js +255 -0
- package/node_modules/@loopwright/controller/dist/controller.d.ts +177 -0
- package/node_modules/@loopwright/controller/dist/controller.js +2135 -0
- package/node_modules/@loopwright/controller/dist/credentials.d.ts +29 -0
- package/node_modules/@loopwright/controller/dist/credentials.js +189 -0
- package/node_modules/@loopwright/controller/dist/deadlines.d.ts +18 -0
- package/node_modules/@loopwright/controller/dist/deadlines.js +71 -0
- package/node_modules/@loopwright/controller/dist/errors.d.ts +27 -0
- package/node_modules/@loopwright/controller/dist/errors.js +41 -0
- package/node_modules/@loopwright/controller/dist/events.d.ts +52 -0
- package/node_modules/@loopwright/controller/dist/events.js +228 -0
- package/node_modules/@loopwright/controller/dist/files.d.ts +51 -0
- package/node_modules/@loopwright/controller/dist/files.js +386 -0
- package/node_modules/@loopwright/controller/dist/finalize.d.ts +25 -0
- package/node_modules/@loopwright/controller/dist/finalize.js +32 -0
- package/node_modules/@loopwright/controller/dist/gate.d.ts +84 -0
- package/node_modules/@loopwright/controller/dist/gate.js +640 -0
- package/node_modules/@loopwright/controller/dist/git-objects.d.ts +11 -0
- package/node_modules/@loopwright/controller/dist/git-objects.js +59 -0
- package/node_modules/@loopwright/controller/dist/git-reader.d.ts +17 -0
- package/node_modules/@loopwright/controller/dist/git-reader.js +40 -0
- package/node_modules/@loopwright/controller/dist/handlers.d.ts +6 -0
- package/node_modules/@loopwright/controller/dist/handlers.js +45 -0
- package/node_modules/@loopwright/controller/dist/handoff.d.ts +71 -0
- package/node_modules/@loopwright/controller/dist/handoff.js +554 -0
- package/node_modules/@loopwright/controller/dist/index.d.ts +41 -0
- package/node_modules/@loopwright/controller/dist/index.js +21 -0
- package/node_modules/@loopwright/controller/dist/inspect.d.ts +30 -0
- package/node_modules/@loopwright/controller/dist/inspect.js +372 -0
- package/node_modules/@loopwright/controller/dist/interpolation.d.ts +9 -0
- package/node_modules/@loopwright/controller/dist/interpolation.js +79 -0
- package/node_modules/@loopwright/controller/dist/ownership.d.ts +41 -0
- package/node_modules/@loopwright/controller/dist/ownership.js +666 -0
- package/node_modules/@loopwright/controller/dist/parser.d.ts +5 -0
- package/node_modules/@loopwright/controller/dist/parser.js +200 -0
- package/node_modules/@loopwright/controller/dist/progress.d.ts +41 -0
- package/node_modules/@loopwright/controller/dist/progress.js +904 -0
- package/node_modules/@loopwright/controller/dist/publication.d.ts +60 -0
- package/node_modules/@loopwright/controller/dist/publication.js +329 -0
- package/node_modules/@loopwright/controller/dist/reconcile.d.ts +26 -0
- package/node_modules/@loopwright/controller/dist/reconcile.js +1378 -0
- package/node_modules/@loopwright/controller/dist/recovery.d.ts +10 -0
- package/node_modules/@loopwright/controller/dist/recovery.js +315 -0
- package/node_modules/@loopwright/controller/dist/refusal-record.d.ts +43 -0
- package/node_modules/@loopwright/controller/dist/refusal-record.js +150 -0
- package/node_modules/@loopwright/controller/dist/registry.d.ts +6 -0
- package/node_modules/@loopwright/controller/dist/registry.js +374 -0
- package/node_modules/@loopwright/controller/dist/repair.d.ts +31 -0
- package/node_modules/@loopwright/controller/dist/repair.js +102 -0
- package/node_modules/@loopwright/controller/dist/report.d.ts +64 -0
- package/node_modules/@loopwright/controller/dist/report.js +596 -0
- package/node_modules/@loopwright/controller/dist/retained.d.ts +284 -0
- package/node_modules/@loopwright/controller/dist/retained.js +193 -0
- package/node_modules/@loopwright/controller/dist/rules.d.ts +31 -0
- package/node_modules/@loopwright/controller/dist/rules.js +110 -0
- package/node_modules/@loopwright/controller/dist/run-eval.d.ts +115 -0
- package/node_modules/@loopwright/controller/dist/run-eval.js +959 -0
- package/node_modules/@loopwright/controller/dist/scheduler.d.ts +10 -0
- package/node_modules/@loopwright/controller/dist/scheduler.js +41 -0
- package/node_modules/@loopwright/controller/dist/schema.d.ts +17 -0
- package/node_modules/@loopwright/controller/dist/schema.js +78 -0
- package/node_modules/@loopwright/controller/dist/source.d.ts +69 -0
- package/node_modules/@loopwright/controller/dist/source.js +872 -0
- package/node_modules/@loopwright/controller/dist/step.d.ts +38 -0
- package/node_modules/@loopwright/controller/dist/step.js +1776 -0
- package/node_modules/@loopwright/controller/dist/storage.d.ts +90 -0
- package/node_modules/@loopwright/controller/dist/storage.js +1345 -0
- package/node_modules/@loopwright/controller/dist/submission.d.ts +51 -0
- package/node_modules/@loopwright/controller/dist/submission.js +292 -0
- package/node_modules/@loopwright/controller/dist/types.d.ts +585 -0
- package/node_modules/@loopwright/controller/dist/types.js +9 -0
- package/node_modules/@loopwright/controller/dist/verification.d.ts +124 -0
- package/node_modules/@loopwright/controller/dist/verification.js +1308 -0
- package/node_modules/@loopwright/controller/dist/verifier-protocol.d.ts +105 -0
- package/node_modules/@loopwright/controller/dist/verifier-protocol.js +1312 -0
- package/node_modules/@loopwright/controller/dist/verifier-worker.d.ts +1 -0
- package/node_modules/@loopwright/controller/dist/verifier-worker.js +33 -0
- package/node_modules/@loopwright/controller/package.json +12 -0
- package/node_modules/@loopwright/core/dist/acceptance.d.ts +108 -0
- package/node_modules/@loopwright/core/dist/acceptance.js +327 -0
- package/node_modules/@loopwright/core/dist/artifacts.d.ts +63 -0
- package/node_modules/@loopwright/core/dist/artifacts.js +356 -0
- package/node_modules/@loopwright/core/dist/boundary.d.ts +21 -0
- package/node_modules/@loopwright/core/dist/boundary.js +484 -0
- package/node_modules/@loopwright/core/dist/contracts.d.ts +287 -0
- package/node_modules/@loopwright/core/dist/contracts.js +694 -0
- package/node_modules/@loopwright/core/dist/diagnostics.d.ts +21 -0
- package/node_modules/@loopwright/core/dist/diagnostics.js +51 -0
- package/node_modules/@loopwright/core/dist/evidence.d.ts +92 -0
- package/node_modules/@loopwright/core/dist/evidence.js +85 -0
- package/node_modules/@loopwright/core/dist/graph.d.ts +8 -0
- package/node_modules/@loopwright/core/dist/graph.js +44 -0
- package/node_modules/@loopwright/core/dist/identity.d.ts +162 -0
- package/node_modules/@loopwright/core/dist/identity.js +80 -0
- package/node_modules/@loopwright/core/dist/index.d.ts +30 -0
- package/node_modules/@loopwright/core/dist/index.js +39 -0
- package/node_modules/@loopwright/core/dist/limits.d.ts +99 -0
- package/node_modules/@loopwright/core/dist/limits.js +59 -0
- package/node_modules/@loopwright/core/dist/results.d.ts +161 -0
- package/node_modules/@loopwright/core/dist/results.js +98 -0
- package/node_modules/@loopwright/core/dist/scope.d.ts +13 -0
- package/node_modules/@loopwright/core/dist/scope.js +154 -0
- package/node_modules/@loopwright/core/dist/scrubber.d.ts +13 -0
- package/node_modules/@loopwright/core/dist/scrubber.js +63 -0
- package/node_modules/@loopwright/core/dist/usage.d.ts +68 -0
- package/node_modules/@loopwright/core/dist/usage.js +56 -0
- package/node_modules/@loopwright/core/package.json +12 -0
- package/node_modules/@loopwright/decisions/dist/benchmark.d.ts +23 -0
- package/node_modules/@loopwright/decisions/dist/benchmark.js +337 -0
- package/node_modules/@loopwright/decisions/dist/client.d.ts +74 -0
- package/node_modules/@loopwright/decisions/dist/client.js +292 -0
- package/node_modules/@loopwright/decisions/dist/index.d.ts +15 -0
- package/node_modules/@loopwright/decisions/dist/index.js +8 -0
- package/node_modules/@loopwright/decisions/dist/nodes.d.ts +63 -0
- package/node_modules/@loopwright/decisions/dist/nodes.js +282 -0
- package/node_modules/@loopwright/decisions/dist/primitives.d.ts +36 -0
- package/node_modules/@loopwright/decisions/dist/primitives.js +300 -0
- package/node_modules/@loopwright/decisions/dist/redaction.d.ts +23 -0
- package/node_modules/@loopwright/decisions/dist/redaction.js +146 -0
- package/node_modules/@loopwright/decisions/dist/router.d.ts +55 -0
- package/node_modules/@loopwright/decisions/dist/router.js +248 -0
- package/node_modules/@loopwright/decisions/dist/schema.d.ts +25 -0
- package/node_modules/@loopwright/decisions/dist/schema.js +536 -0
- package/node_modules/@loopwright/decisions/dist/types.d.ts +394 -0
- package/node_modules/@loopwright/decisions/dist/types.js +80 -0
- package/node_modules/@loopwright/decisions/package.json +12 -0
- package/node_modules/@loopwright/github-app/dist/action.d.ts +90 -0
- package/node_modules/@loopwright/github-app/dist/action.js +2429 -0
- package/node_modules/@loopwright/github-app/dist/config.d.ts +23 -0
- package/node_modules/@loopwright/github-app/dist/config.js +297 -0
- package/node_modules/@loopwright/github-app/dist/digests.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/digests.js +1 -0
- package/node_modules/@loopwright/github-app/dist/index.d.ts +14 -0
- package/node_modules/@loopwright/github-app/dist/index.js +13 -0
- package/node_modules/@loopwright/github-app/dist/models-config.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/models-config.js +1 -0
- package/node_modules/@loopwright/github-app/dist/output-format.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/output-format.js +1 -0
- package/node_modules/@loopwright/github-app/dist/preflight.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/preflight.js +1 -0
- package/node_modules/@loopwright/github-app/dist/publisher.d.ts +58 -0
- package/node_modules/@loopwright/github-app/dist/publisher.js +1368 -0
- package/node_modules/@loopwright/github-app/dist/qualification.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/qualification.js +1 -0
- package/node_modules/@loopwright/github-app/dist/sandbox.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/sandbox.js +1 -0
- package/node_modules/@loopwright/github-app/dist/schema.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/schema.js +1 -0
- package/node_modules/@loopwright/github-app/dist/service.d.ts +52 -0
- package/node_modules/@loopwright/github-app/dist/service.js +1658 -0
- package/node_modules/@loopwright/github-app/dist/suite-pr-lookup.d.ts +90 -0
- package/node_modules/@loopwright/github-app/dist/suite-pr-lookup.js +392 -0
- package/node_modules/@loopwright/github-app/dist/taskpack.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/taskpack.js +1 -0
- package/node_modules/@loopwright/github-app/dist/tenant-queue.d.ts +44 -0
- package/node_modules/@loopwright/github-app/dist/tenant-queue.js +423 -0
- package/node_modules/@loopwright/github-app/dist/token-broker.d.ts +50 -0
- package/node_modules/@loopwright/github-app/dist/token-broker.js +262 -0
- package/node_modules/@loopwright/github-app/dist/turnkey-memory.d.ts +35 -0
- package/node_modules/@loopwright/github-app/dist/turnkey-memory.js +1654 -0
- package/node_modules/@loopwright/github-app/dist/turnkey.d.ts +16 -0
- package/node_modules/@loopwright/github-app/dist/turnkey.js +34 -0
- package/node_modules/@loopwright/github-app/dist/types.d.ts +220 -0
- package/node_modules/@loopwright/github-app/dist/types.js +14 -0
- package/node_modules/@loopwright/github-app/dist/upstreams.d.ts +13 -0
- package/node_modules/@loopwright/github-app/dist/upstreams.js +65 -0
- package/node_modules/@loopwright/github-app/dist/webhook.d.ts +34 -0
- package/node_modules/@loopwright/github-app/dist/webhook.js +241 -0
- package/node_modules/@loopwright/github-app/dist/yaml.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/yaml.js +1 -0
- package/node_modules/@loopwright/github-app/package.json +12 -0
- package/node_modules/@loopwright/hardware-runner/dist/config.d.ts +48 -0
- package/node_modules/@loopwright/hardware-runner/dist/config.js +719 -0
- package/node_modules/@loopwright/hardware-runner/dist/evaluator.d.ts +230 -0
- package/node_modules/@loopwright/hardware-runner/dist/evaluator.js +3178 -0
- package/node_modules/@loopwright/hardware-runner/dist/index.d.ts +13 -0
- package/node_modules/@loopwright/hardware-runner/dist/index.js +9 -0
- package/node_modules/@loopwright/hardware-runner/dist/provenance.d.ts +128 -0
- package/node_modules/@loopwright/hardware-runner/dist/provenance.js +1500 -0
- package/node_modules/@loopwright/hardware-runner/dist/queue.d.ts +81 -0
- package/node_modules/@loopwright/hardware-runner/dist/queue.js +1081 -0
- package/node_modules/@loopwright/hardware-runner/dist/relay-server.d.ts +13 -0
- package/node_modules/@loopwright/hardware-runner/dist/relay-server.js +2997 -0
- package/node_modules/@loopwright/hardware-runner/dist/types.d.ts +239 -0
- package/node_modules/@loopwright/hardware-runner/dist/types.js +12 -0
- package/node_modules/@loopwright/hardware-runner/dist/worker.d.ts +49 -0
- package/node_modules/@loopwright/hardware-runner/dist/worker.js +1648 -0
- package/node_modules/@loopwright/hardware-runner/package.json +12 -0
- package/node_modules/@loopwright/memory/dist/cas.d.ts +21 -0
- package/node_modules/@loopwright/memory/dist/cas.js +510 -0
- package/node_modules/@loopwright/memory/dist/compaction.d.ts +18 -0
- package/node_modules/@loopwright/memory/dist/compaction.js +110 -0
- package/node_modules/@loopwright/memory/dist/finalizer.d.ts +23 -0
- package/node_modules/@loopwright/memory/dist/finalizer.js +538 -0
- package/node_modules/@loopwright/memory/dist/index.d.ts +9 -0
- package/node_modules/@loopwright/memory/dist/index.js +8 -0
- package/node_modules/@loopwright/memory/dist/schema.d.ts +36 -0
- package/node_modules/@loopwright/memory/dist/schema.js +510 -0
- package/node_modules/@loopwright/memory/dist/selector.d.ts +7 -0
- package/node_modules/@loopwright/memory/dist/selector.js +157 -0
- package/node_modules/@loopwright/memory/dist/store.d.ts +51 -0
- package/node_modules/@loopwright/memory/dist/store.js +554 -0
- package/node_modules/@loopwright/memory/dist/types.d.ts +442 -0
- package/node_modules/@loopwright/memory/dist/types.js +8 -0
- package/node_modules/@loopwright/memory/dist/verifier.d.ts +5 -0
- package/node_modules/@loopwright/memory/dist/verifier.js +328 -0
- package/node_modules/@loopwright/memory/package.json +12 -0
- package/node_modules/@loopwright/state/dist/admission.d.ts +321 -0
- package/node_modules/@loopwright/state/dist/admission.js +199 -0
- package/node_modules/@loopwright/state/dist/boundary.d.ts +53 -0
- package/node_modules/@loopwright/state/dist/boundary.js +194 -0
- package/node_modules/@loopwright/state/dist/checkpoint.d.ts +16 -0
- package/node_modules/@loopwright/state/dist/checkpoint.js +84 -0
- package/node_modules/@loopwright/state/dist/clock.d.ts +8 -0
- package/node_modules/@loopwright/state/dist/clock.js +27 -0
- package/node_modules/@loopwright/state/dist/connection.d.ts +55 -0
- package/node_modules/@loopwright/state/dist/connection.js +391 -0
- package/node_modules/@loopwright/state/dist/errors.d.ts +13 -0
- package/node_modules/@loopwright/state/dist/errors.js +34 -0
- package/node_modules/@loopwright/state/dist/index.d.ts +3 -0
- package/node_modules/@loopwright/state/dist/index.js +1 -0
- package/node_modules/@loopwright/state/dist/journal.d.ts +119 -0
- package/node_modules/@loopwright/state/dist/journal.js +72 -0
- package/node_modules/@loopwright/state/dist/model.d.ts +40 -0
- package/node_modules/@loopwright/state/dist/model.js +58 -0
- package/node_modules/@loopwright/state/dist/ownership.d.ts +14 -0
- package/node_modules/@loopwright/state/dist/ownership.js +45 -0
- package/node_modules/@loopwright/state/dist/pages.d.ts +11 -0
- package/node_modules/@loopwright/state/dist/pages.js +41 -0
- package/node_modules/@loopwright/state/dist/receipts.d.ts +33 -0
- package/node_modules/@loopwright/state/dist/receipts.js +97 -0
- package/node_modules/@loopwright/state/dist/schema.d.ts +28 -0
- package/node_modules/@loopwright/state/dist/schema.js +41 -0
- package/node_modules/@loopwright/state/dist/settlement.d.ts +10 -0
- package/node_modules/@loopwright/state/dist/settlement.js +129 -0
- package/node_modules/@loopwright/state/dist/store.d.ts +52 -0
- package/node_modules/@loopwright/state/dist/store.js +100 -0
- package/node_modules/@loopwright/state/dist/types.d.ts +315 -0
- package/node_modules/@loopwright/state/dist/types.js +1 -0
- package/node_modules/@loopwright/state/package.json +12 -0
- package/node_modules/@loopwright/taskpack/dist/baseline-align.d.ts +195 -0
- package/node_modules/@loopwright/taskpack/dist/baseline-align.js +1847 -0
- package/node_modules/@loopwright/taskpack/dist/digests.d.ts +61 -0
- package/node_modules/@loopwright/taskpack/dist/digests.js +715 -0
- package/node_modules/@loopwright/taskpack/dist/index.d.ts +18 -0
- package/node_modules/@loopwright/taskpack/dist/index.js +17 -0
- package/node_modules/@loopwright/taskpack/dist/models-config.d.ts +112 -0
- package/node_modules/@loopwright/taskpack/dist/models-config.js +1026 -0
- package/node_modules/@loopwright/taskpack/dist/output-format.d.ts +28 -0
- package/node_modules/@loopwright/taskpack/dist/output-format.js +157 -0
- package/node_modules/@loopwright/taskpack/dist/preflight.d.ts +130 -0
- package/node_modules/@loopwright/taskpack/dist/preflight.js +1497 -0
- package/node_modules/@loopwright/taskpack/dist/qualification.d.ts +23 -0
- package/node_modules/@loopwright/taskpack/dist/qualification.js +120 -0
- package/node_modules/@loopwright/taskpack/dist/sandbox.d.ts +121 -0
- package/node_modules/@loopwright/taskpack/dist/sandbox.js +2642 -0
- package/node_modules/@loopwright/taskpack/dist/schema.d.ts +197 -0
- package/node_modules/@loopwright/taskpack/dist/schema.js +4189 -0
- package/node_modules/@loopwright/taskpack/dist/scrubber.d.ts +47 -0
- package/node_modules/@loopwright/taskpack/dist/scrubber.js +283 -0
- package/node_modules/@loopwright/taskpack/dist/suite.d.ts +124 -0
- package/node_modules/@loopwright/taskpack/dist/suite.js +3256 -0
- package/node_modules/@loopwright/taskpack/dist/taskpack.d.ts +154 -0
- package/node_modules/@loopwright/taskpack/dist/taskpack.js +3634 -0
- package/node_modules/@loopwright/taskpack/dist/turnkey-memory.d.ts +122 -0
- package/node_modules/@loopwright/taskpack/dist/turnkey-memory.js +483 -0
- package/node_modules/@loopwright/taskpack/dist/turnkey.d.ts +437 -0
- package/node_modules/@loopwright/taskpack/dist/turnkey.js +7335 -0
- package/node_modules/@loopwright/taskpack/dist/types.d.ts +1274 -0
- package/node_modules/@loopwright/taskpack/dist/types.js +99 -0
- package/node_modules/@loopwright/taskpack/dist/upstreams.d.ts +261 -0
- package/node_modules/@loopwright/taskpack/dist/upstreams.js +2242 -0
- package/node_modules/@loopwright/taskpack/dist/yaml.d.ts +18 -0
- package/node_modules/@loopwright/taskpack/dist/yaml.js +167 -0
- package/node_modules/@loopwright/taskpack/package.json +12 -0
- package/node_modules/@loopwright/taskpack-runner/dist/compile-taskpack.d.ts +137 -0
- package/node_modules/@loopwright/taskpack-runner/dist/compile-taskpack.js +474 -0
- package/node_modules/@loopwright/taskpack-runner/dist/corpus.d.ts +8 -0
- package/node_modules/@loopwright/taskpack-runner/dist/corpus.js +129 -0
- package/node_modules/@loopwright/taskpack-runner/dist/index.d.ts +13 -0
- package/node_modules/@loopwright/taskpack-runner/dist/index.js +7 -0
- package/node_modules/@loopwright/taskpack-runner/dist/intake.d.ts +149 -0
- package/node_modules/@loopwright/taskpack-runner/dist/intake.js +135 -0
- package/node_modules/@loopwright/taskpack-runner/dist/parity.d.ts +130 -0
- package/node_modules/@loopwright/taskpack-runner/dist/parity.js +927 -0
- package/node_modules/@loopwright/taskpack-runner/dist/python-bridge.d.ts +68 -0
- package/node_modules/@loopwright/taskpack-runner/dist/python-bridge.js +517 -0
- package/node_modules/@loopwright/taskpack-runner/dist/service.d.ts +149 -0
- package/node_modules/@loopwright/taskpack-runner/dist/service.js +1796 -0
- package/node_modules/@loopwright/taskpack-runner/dist/types.d.ts +29 -0
- package/node_modules/@loopwright/taskpack-runner/dist/types.js +11 -0
- package/node_modules/@loopwright/taskpack-runner/package.json +12 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/README.md +77 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/docs/support-records.md +57 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/docs/supported-runners.md +98 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/manifest.json +205 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pack/expand_matrix.sh +273 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pack/matrix.yaml +280 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pack/resolve_dockerfile.sh +24 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pyproject.toml +46 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/runtime_runner/runner.py.json +5270 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/discovery/legacy-support.md +86 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/github/service.py +401 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/proposals/analysis.json +95 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/proposals/ready.json +109 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_assemble.py +263 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_check_draft.py +333 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_checks.py +1099 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_discovery.py +817 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_proposal.py +658 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_publish.py +987 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_summary.py +107 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/agent.py +610 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/assemble.py +84 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/check_draft.py +94 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/checks.py +1002 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/discovery.py +789 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/model.py +557 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/progress.py +174 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/prompts/analysis.md +40 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/prompts/proposal.md +65 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/prompts/repair.md +17 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/proposal.py +903 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/publish.py +997 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/summary.py +131 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/tool-versions.json +133 -0
- package/node_modules/package-lock.json +3025 -0
- package/package-lock.json +3025 -0
- package/package.json +52 -4
|
@@ -0,0 +1,1345 @@
|
|
|
1
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
+
import { constants } from 'node:fs';
|
|
3
|
+
import { link, lstat, mkdir, open, readdir, rename, unlink } from 'node:fs/promises';
|
|
4
|
+
import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
|
|
5
|
+
import { types } from 'node:util';
|
|
6
|
+
import { OVERLAY_LIMITS, SecretScrubber, VERIFIER_ARTIFACT_LIMITS, digestArtifact, digestArtifactFromMetadata, validateRelativePath, } from '@loopwright/core';
|
|
7
|
+
import { ControllerFailure, refuse } from './errors.js';
|
|
8
|
+
import { STREAM_CHUNK_BYTES, canonicalComponents, inside, readBoundedFile, streamRegularFile, writeAllToHandle, } from './files.js';
|
|
9
|
+
import { canonical, checkedRef, hash, isRecord, same } from './schema.js';
|
|
10
|
+
export { checkedRef };
|
|
11
|
+
const EMPTY_SHA256_HEX = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855';
|
|
12
|
+
export const MAX_EXTRA_SECRET_LENGTH = 4_096;
|
|
13
|
+
const LONE_SURROGATE_RE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/u;
|
|
14
|
+
const MARKER_TMP_FILE_RE = /\.(?:binding|proof|reconcile-receipt)\.json\.tmp-[0-9a-f]{12,64}$/;
|
|
15
|
+
function deriveExtraSecretBuffers(extraSecrets, scrubber, phase) {
|
|
16
|
+
if (extraSecrets === undefined)
|
|
17
|
+
return Object.freeze([]);
|
|
18
|
+
const formSet = new Set();
|
|
19
|
+
for (const secret of extraSecrets) {
|
|
20
|
+
if (typeof secret !== 'string' || secret.length === 0)
|
|
21
|
+
continue;
|
|
22
|
+
if (secret.length > MAX_EXTRA_SECRET_LENGTH || LONE_SURROGATE_RE.test(secret)) {
|
|
23
|
+
refuse('CONFIG_CREDENTIAL_INVALID', '/spec/credentials', phase);
|
|
24
|
+
}
|
|
25
|
+
scrubber.register(secret);
|
|
26
|
+
const jsonEscaped = JSON.stringify(secret).slice(1, -1);
|
|
27
|
+
const candidates = [
|
|
28
|
+
secret,
|
|
29
|
+
jsonEscaped,
|
|
30
|
+
jsonEscaped.replaceAll('/', '\\/'),
|
|
31
|
+
encodeURIComponent(secret),
|
|
32
|
+
Buffer.from(secret, 'utf8').toString('base64'),
|
|
33
|
+
];
|
|
34
|
+
for (const form of candidates) {
|
|
35
|
+
if (form.length > 0 && (form === secret || form.length >= 8)) {
|
|
36
|
+
formSet.add(form);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return Object.freeze([...formSet].map(form => Buffer.from(form, 'utf8')));
|
|
41
|
+
}
|
|
42
|
+
export function createBinarySecretStreamScanner(vault, logicalName, phase, extraSecrets) {
|
|
43
|
+
const vaultChecker = vault.createStreamChecker();
|
|
44
|
+
const scrubber = new SecretScrubber();
|
|
45
|
+
const extraFormBuffers = deriveExtraSecretBuffers(extraSecrets, scrubber, phase);
|
|
46
|
+
const maxFormBytes = extraFormBuffers.reduce((max, buf) => Math.max(max, buf.byteLength), 0);
|
|
47
|
+
const overlap = Math.min(262_144, Math.max(16_384, maxFormBytes, vaultChecker.overlapBytes ?? 16_384));
|
|
48
|
+
const maxWindowSlice = STREAM_CHUNK_BYTES - overlap;
|
|
49
|
+
let carryTail = Buffer.alloc(0);
|
|
50
|
+
let maxWindowBytes = 0;
|
|
51
|
+
const hasRegisteredOrGenericSecret = (windowBuf) => {
|
|
52
|
+
if (extraFormBuffers.some(form => windowBuf.includes(form)))
|
|
53
|
+
return true;
|
|
54
|
+
if (scrubber.containsSecret(windowBuf.toString('latin1')))
|
|
55
|
+
return true;
|
|
56
|
+
if (scrubber.containsSecret(windowBuf.toString('utf8')))
|
|
57
|
+
return true;
|
|
58
|
+
return false;
|
|
59
|
+
};
|
|
60
|
+
return Object.freeze({
|
|
61
|
+
overlapBytes: overlap,
|
|
62
|
+
get maxObservedWindowBytes() {
|
|
63
|
+
return Math.max(maxWindowBytes, vaultChecker.maxObservedWindowBytes ?? 0);
|
|
64
|
+
},
|
|
65
|
+
push: (chunk) => {
|
|
66
|
+
if (chunk.byteLength === 0)
|
|
67
|
+
return;
|
|
68
|
+
const view = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
69
|
+
for (let offset = 0; offset < view.byteLength; offset += maxWindowSlice) {
|
|
70
|
+
const sub = view.subarray(offset, Math.min(view.byteLength, offset + maxWindowSlice));
|
|
71
|
+
try {
|
|
72
|
+
vaultChecker.push(sub);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
if (carryTail.byteLength > 0)
|
|
76
|
+
carryTail.fill(0);
|
|
77
|
+
carryTail = Buffer.alloc(0);
|
|
78
|
+
if (error instanceof ControllerFailure && error.diagnostic.code === 'CONFIG_CREDENTIAL_INVALID') {
|
|
79
|
+
refuse('ARTIFACT_INVALID', logicalName, phase);
|
|
80
|
+
}
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
const combined = carryTail.byteLength === 0 ? sub : Buffer.concat([carryTail, sub]);
|
|
84
|
+
if (combined.byteLength > maxWindowBytes) {
|
|
85
|
+
maxWindowBytes = combined.byteLength;
|
|
86
|
+
}
|
|
87
|
+
if (hasRegisteredOrGenericSecret(combined)) {
|
|
88
|
+
if (carryTail.byteLength > 0)
|
|
89
|
+
carryTail.fill(0);
|
|
90
|
+
carryTail = Buffer.alloc(0);
|
|
91
|
+
refuse('ARTIFACT_INVALID', logicalName, phase);
|
|
92
|
+
}
|
|
93
|
+
const keep = Math.min(overlap, combined.byteLength);
|
|
94
|
+
if (carryTail.byteLength > 0)
|
|
95
|
+
carryTail.fill(0);
|
|
96
|
+
carryTail = Buffer.from(combined.subarray(combined.byteLength - keep));
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
finish: () => {
|
|
100
|
+
const tail = carryTail;
|
|
101
|
+
carryTail = Buffer.alloc(0);
|
|
102
|
+
try {
|
|
103
|
+
try {
|
|
104
|
+
vaultChecker.finish();
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
if (error instanceof ControllerFailure && error.diagnostic.code === 'CONFIG_CREDENTIAL_INVALID') {
|
|
108
|
+
refuse('ARTIFACT_INVALID', logicalName, phase);
|
|
109
|
+
}
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
if (tail.byteLength > maxWindowBytes) {
|
|
113
|
+
maxWindowBytes = tail.byteLength;
|
|
114
|
+
}
|
|
115
|
+
if (tail.byteLength > 0 && hasRegisteredOrGenericSecret(tail)) {
|
|
116
|
+
refuse('ARTIFACT_INVALID', logicalName, phase);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
if (tail.byteLength > 0)
|
|
121
|
+
tail.fill(0);
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
export function stateValue(result) {
|
|
127
|
+
if (result.ok)
|
|
128
|
+
return result.value;
|
|
129
|
+
const code = result.error.commit === 'unknown' || /CLOCK/.test(result.error.code) ? 'RECOVERY_REQUIRED' : /OWNER|AUTHORITY/.test(result.error.code) ? 'AUTHORITY_REFUSED'
|
|
130
|
+
: /DEADLINE/.test(result.error.code) ? 'DEADLINE' : /BUDGET|LIMIT/.test(result.error.code) ? 'BUDGET_EXHAUSTED' : 'STATE_UNAVAILABLE';
|
|
131
|
+
refuse(code, '', 'recovery', { stateCode: result.error.code, effect: result.error.commit === 'unknown' ? 'possible' : 'none', retryable: result.error.retryable });
|
|
132
|
+
}
|
|
133
|
+
export async function privateDirectory(path, excluded = []) {
|
|
134
|
+
if (resolve(path) !== path || excluded.some(root => inside(path, resolve(root))))
|
|
135
|
+
refuse('ARTIFACT_INVALID', '', 'admission');
|
|
136
|
+
await mkdir(path, { recursive: true, mode: 0o700 });
|
|
137
|
+
await canonicalComponents(path);
|
|
138
|
+
const info = await lstat(path);
|
|
139
|
+
if (!info.isDirectory() || info.uid !== process.getuid?.() || info.mode & 0o077)
|
|
140
|
+
refuse('ARTIFACT_INVALID', '', 'admission');
|
|
141
|
+
}
|
|
142
|
+
export function parseCasUri(uri, phase = 'verification') {
|
|
143
|
+
if (typeof uri !== 'string')
|
|
144
|
+
refuse('ARTIFACT_INVALID', '', phase);
|
|
145
|
+
const match = /^cas:\/\/sha256\/([0-9a-f]{64})$/.exec(uri);
|
|
146
|
+
if (!match)
|
|
147
|
+
refuse('ARTIFACT_INVALID', '', phase);
|
|
148
|
+
return match[1];
|
|
149
|
+
}
|
|
150
|
+
export async function resolveCanonicalCasBlobPath(artifactsDir, sha256Hex, hintedPath, phase = 'verification') {
|
|
151
|
+
if (typeof artifactsDir !== 'string'
|
|
152
|
+
|| !isAbsolute(artifactsDir)
|
|
153
|
+
|| resolve(artifactsDir) !== artifactsDir
|
|
154
|
+
|| typeof sha256Hex !== 'string'
|
|
155
|
+
|| !/^[0-9a-f]{64}$/.test(sha256Hex)) {
|
|
156
|
+
refuse('ARTIFACT_INVALID', '', phase);
|
|
157
|
+
}
|
|
158
|
+
const canonicalPath = join(artifactsDir, 'blobs', 'sha256', sha256Hex);
|
|
159
|
+
if (!inside(canonicalPath, artifactsDir) || canonicalPath === artifactsDir) {
|
|
160
|
+
refuse('ARTIFACT_INVALID', '', phase);
|
|
161
|
+
}
|
|
162
|
+
if (hintedPath !== undefined) {
|
|
163
|
+
if (typeof hintedPath !== 'string' || !isAbsolute(hintedPath) || resolve(hintedPath) !== canonicalPath) {
|
|
164
|
+
refuse('ARTIFACT_INVALID', '', phase);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
await canonicalComponents(canonicalPath, true);
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
refuse('ARTIFACT_INVALID', '', phase);
|
|
172
|
+
}
|
|
173
|
+
return canonicalPath;
|
|
174
|
+
}
|
|
175
|
+
async function streamVerifiedCasBlobWithSummary(artifactsDir, pointer, onChunk, phase = 'verification', gitObjectFormat) {
|
|
176
|
+
if (!isRecord(pointer)
|
|
177
|
+
|| typeof pointer.sha256 !== 'string'
|
|
178
|
+
|| !/^[0-9a-f]{64}$/.test(pointer.sha256)
|
|
179
|
+
|| !Number.isSafeInteger(pointer.byteLength)
|
|
180
|
+
|| Object.is(pointer.byteLength, -0)
|
|
181
|
+
|| pointer.byteLength < 0
|
|
182
|
+
|| pointer.byteLength > OVERLAY_LIMITS.maxMaxBytes
|
|
183
|
+
|| (pointer.byteLength === 0) !== (pointer.sha256 === EMPTY_SHA256_HEX)) {
|
|
184
|
+
refuse('ARTIFACT_INVALID', '', phase);
|
|
185
|
+
}
|
|
186
|
+
if (pointer.name !== undefined && !validateRelativePath(pointer.name).ok) {
|
|
187
|
+
refuse('ARTIFACT_INVALID', '', phase);
|
|
188
|
+
}
|
|
189
|
+
const expectedUri = 'cas://sha256/' + pointer.sha256;
|
|
190
|
+
if (pointer.uri !== undefined && pointer.uri !== expectedUri) {
|
|
191
|
+
refuse('ARTIFACT_INVALID', '', phase);
|
|
192
|
+
}
|
|
193
|
+
if (pointer.blobRef !== undefined) {
|
|
194
|
+
if (!isRecord(pointer.blobRef))
|
|
195
|
+
refuse('ARTIFACT_INVALID', '', phase);
|
|
196
|
+
for (const key of Reflect.ownKeys(pointer.blobRef)) {
|
|
197
|
+
if (typeof key !== 'string' || !['name', 'digest', 'byteLength', 'uri', 'mediaType'].includes(key)) {
|
|
198
|
+
refuse('ARTIFACT_INVALID', '', phase);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const refMetadata = {
|
|
202
|
+
digest: pointer.blobRef.digest,
|
|
203
|
+
byteLength: pointer.blobRef.byteLength,
|
|
204
|
+
...(pointer.blobRef.uri !== undefined ? { uri: pointer.blobRef.uri } : {}),
|
|
205
|
+
...(pointer.blobRef.mediaType !== undefined ? { mediaType: pointer.blobRef.mediaType } : {}),
|
|
206
|
+
};
|
|
207
|
+
const refCheck = digestArtifactFromMetadata(pointer.blobRef.name, refMetadata);
|
|
208
|
+
if (!refCheck.ok
|
|
209
|
+
|| pointer.blobRef.digest.algorithm !== 'sha256'
|
|
210
|
+
|| pointer.blobRef.digest.hex !== pointer.sha256
|
|
211
|
+
|| pointer.blobRef.byteLength !== pointer.byteLength
|
|
212
|
+
|| (pointer.blobRef.uri !== undefined && pointer.blobRef.uri !== expectedUri)
|
|
213
|
+
|| (pointer.name !== undefined && pointer.blobRef.name !== pointer.name)) {
|
|
214
|
+
refuse('ARTIFACT_INVALID', '', phase);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
const canonicalBlobPath = await resolveCanonicalCasBlobPath(artifactsDir, pointer.sha256, pointer.path, phase);
|
|
218
|
+
let beforeStat;
|
|
219
|
+
try {
|
|
220
|
+
beforeStat = await lstat(canonicalBlobPath);
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
refuse('ARTIFACT_INVALID', '', phase);
|
|
224
|
+
}
|
|
225
|
+
if (beforeStat.isSymbolicLink()
|
|
226
|
+
|| !beforeStat.isFile()
|
|
227
|
+
|| beforeStat.nlink !== 1
|
|
228
|
+
|| beforeStat.uid !== process.getuid?.()
|
|
229
|
+
|| (beforeStat.mode & 0o7777) !== 0o400
|
|
230
|
+
|| beforeStat.size !== pointer.byteLength) {
|
|
231
|
+
refuse('ARTIFACT_INVALID', '', phase);
|
|
232
|
+
}
|
|
233
|
+
const sha = createHash('sha256');
|
|
234
|
+
const gitHasher = gitObjectFormat !== undefined
|
|
235
|
+
? createHash(gitObjectFormat).update(`blob ${pointer.byteLength}\0`, 'utf8')
|
|
236
|
+
: null;
|
|
237
|
+
const summary = await streamRegularFile(canonicalBlobPath, {
|
|
238
|
+
expectedBytes: pointer.byteLength,
|
|
239
|
+
maxBytes: OVERLAY_LIMITS.maxMaxBytes,
|
|
240
|
+
owned: true,
|
|
241
|
+
requireReadOnly: true,
|
|
242
|
+
code: 'ARTIFACT_INVALID',
|
|
243
|
+
limitCode: 'ARTIFACT_INVALID',
|
|
244
|
+
phase,
|
|
245
|
+
}, async (slice) => {
|
|
246
|
+
sha.update(slice);
|
|
247
|
+
gitHasher?.update(slice);
|
|
248
|
+
if (onChunk !== undefined) {
|
|
249
|
+
await onChunk(slice);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
if ((summary.rawMode & 0o7777) !== 0o400 || summary.dev !== beforeStat.dev || summary.ino !== beforeStat.ino || sha.digest('hex') !== pointer.sha256) {
|
|
253
|
+
refuse('ARTIFACT_INVALID', '', phase);
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
canonicalBlobPath,
|
|
257
|
+
summary,
|
|
258
|
+
gitOid: gitHasher !== null ? gitHasher.digest('hex') : null,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
export async function streamVerifiedCasBlob(artifactsDir, pointer, onChunk, phase = 'verification') {
|
|
262
|
+
await streamVerifiedCasBlobWithSummary(artifactsDir, pointer, onChunk, phase);
|
|
263
|
+
}
|
|
264
|
+
export async function syncDirectory(dirPath) {
|
|
265
|
+
const dirHandle = await open(dirPath, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
266
|
+
try {
|
|
267
|
+
await dirHandle.sync();
|
|
268
|
+
}
|
|
269
|
+
finally {
|
|
270
|
+
await dirHandle.close();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
export async function unlinkIfOwnedInode(targetPath, expectedDev, expectedIno) {
|
|
274
|
+
let st;
|
|
275
|
+
try {
|
|
276
|
+
st = await lstat(targetPath);
|
|
277
|
+
}
|
|
278
|
+
catch (error) {
|
|
279
|
+
if (error.code === 'ENOENT')
|
|
280
|
+
return false;
|
|
281
|
+
throw error;
|
|
282
|
+
}
|
|
283
|
+
if (st.isSymbolicLink()
|
|
284
|
+
|| !st.isFile()
|
|
285
|
+
|| st.dev !== expectedDev
|
|
286
|
+
|| st.ino !== expectedIno
|
|
287
|
+
|| st.uid !== process.getuid?.()) {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
try {
|
|
291
|
+
await unlink(targetPath);
|
|
292
|
+
return true;
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
if (error.code === 'ENOENT')
|
|
296
|
+
return false;
|
|
297
|
+
throw error;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
export async function cleanMarkerTempFilesInDirectory(artifactsDir, owner) {
|
|
301
|
+
await owner.assertCurrent();
|
|
302
|
+
try {
|
|
303
|
+
const info = await lstat(artifactsDir);
|
|
304
|
+
if (info.isSymbolicLink() || !info.isDirectory())
|
|
305
|
+
refuse('ARTIFACT_INVALID', '', 'recovery');
|
|
306
|
+
}
|
|
307
|
+
catch (error) {
|
|
308
|
+
if (error instanceof ControllerFailure)
|
|
309
|
+
throw error;
|
|
310
|
+
if (error.code === 'ENOENT')
|
|
311
|
+
return 0;
|
|
312
|
+
refuse('ARTIFACT_INVALID', '', 'recovery');
|
|
313
|
+
}
|
|
314
|
+
try {
|
|
315
|
+
await canonicalComponents(artifactsDir, true);
|
|
316
|
+
}
|
|
317
|
+
catch {
|
|
318
|
+
refuse('ARTIFACT_INVALID', '', 'recovery');
|
|
319
|
+
}
|
|
320
|
+
const entries = await readdir(artifactsDir);
|
|
321
|
+
let removed = 0;
|
|
322
|
+
for (const entry of entries) {
|
|
323
|
+
if (!MARKER_TMP_FILE_RE.test(entry))
|
|
324
|
+
continue;
|
|
325
|
+
const candidatePath = join(artifactsDir, entry);
|
|
326
|
+
let stat;
|
|
327
|
+
try {
|
|
328
|
+
stat = await lstat(candidatePath);
|
|
329
|
+
}
|
|
330
|
+
catch (error) {
|
|
331
|
+
if (error.code === 'ENOENT')
|
|
332
|
+
continue;
|
|
333
|
+
throw error;
|
|
334
|
+
}
|
|
335
|
+
if (!stat.isSymbolicLink() && stat.isFile() && stat.uid === process.getuid?.()) {
|
|
336
|
+
await unlink(candidatePath).catch(error => {
|
|
337
|
+
if (error.code !== 'ENOENT')
|
|
338
|
+
throw error;
|
|
339
|
+
});
|
|
340
|
+
removed++;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (removed > 0) {
|
|
344
|
+
await syncDirectory(artifactsDir);
|
|
345
|
+
}
|
|
346
|
+
return removed;
|
|
347
|
+
}
|
|
348
|
+
export async function publishAtomicMarker(targetPath, value, vault, phase) {
|
|
349
|
+
const bytes = Buffer.from(canonical(value), 'utf8');
|
|
350
|
+
if (bytes.byteLength > 1_048_576)
|
|
351
|
+
refuse('OUTPUT_LIMIT', '', phase);
|
|
352
|
+
vault.assertClean(bytes);
|
|
353
|
+
const parentDir = dirname(targetPath);
|
|
354
|
+
const tmpPath = `${targetPath}.tmp-${randomBytes(16).toString('hex')}`;
|
|
355
|
+
const tmpHandle = await open(tmpPath, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | constants.O_NOFOLLOW, 0o600);
|
|
356
|
+
let tmpClosed = false;
|
|
357
|
+
let tmpUnlinked = false;
|
|
358
|
+
let createdDev = -1;
|
|
359
|
+
let createdIno = -1;
|
|
360
|
+
try {
|
|
361
|
+
const createdInfo = await tmpHandle.stat();
|
|
362
|
+
createdDev = createdInfo.dev;
|
|
363
|
+
createdIno = createdInfo.ino;
|
|
364
|
+
if (!createdInfo.isFile()
|
|
365
|
+
|| createdInfo.isSymbolicLink()
|
|
366
|
+
|| createdInfo.uid !== process.getuid?.()
|
|
367
|
+
|| createdInfo.nlink !== 1) {
|
|
368
|
+
refuse('RECOVERY_REQUIRED', '', phase);
|
|
369
|
+
}
|
|
370
|
+
await writeAllToHandle(tmpHandle, bytes);
|
|
371
|
+
await tmpHandle.sync();
|
|
372
|
+
const sealedInfo = await tmpHandle.stat();
|
|
373
|
+
if (!sealedInfo.isFile()
|
|
374
|
+
|| sealedInfo.isSymbolicLink()
|
|
375
|
+
|| sealedInfo.dev !== createdDev
|
|
376
|
+
|| sealedInfo.ino !== createdIno
|
|
377
|
+
|| sealedInfo.uid !== process.getuid?.()
|
|
378
|
+
|| sealedInfo.nlink !== 1
|
|
379
|
+
|| sealedInfo.size !== bytes.byteLength
|
|
380
|
+
|| (sealedInfo.mode & 0o7777) !== 0o600) {
|
|
381
|
+
refuse('RECOVERY_REQUIRED', '', phase);
|
|
382
|
+
}
|
|
383
|
+
const beforeLink = await lstat(tmpPath).catch(() => null);
|
|
384
|
+
if (!beforeLink
|
|
385
|
+
|| beforeLink.isSymbolicLink()
|
|
386
|
+
|| !beforeLink.isFile()
|
|
387
|
+
|| beforeLink.dev !== createdDev
|
|
388
|
+
|| beforeLink.ino !== createdIno) {
|
|
389
|
+
tmpUnlinked = true;
|
|
390
|
+
refuse('RECOVERY_REQUIRED', '', phase);
|
|
391
|
+
}
|
|
392
|
+
let linked = false;
|
|
393
|
+
try {
|
|
394
|
+
await link(tmpPath, targetPath);
|
|
395
|
+
linked = true;
|
|
396
|
+
}
|
|
397
|
+
catch (error) {
|
|
398
|
+
if (error.code !== 'EEXIST')
|
|
399
|
+
throw error;
|
|
400
|
+
}
|
|
401
|
+
if (linked) {
|
|
402
|
+
await unlinkIfOwnedInode(tmpPath, createdDev, createdIno);
|
|
403
|
+
tmpUnlinked = true;
|
|
404
|
+
let verifyHandle = null;
|
|
405
|
+
try {
|
|
406
|
+
verifyHandle = await open(targetPath, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
407
|
+
const committed = await verifyHandle.stat();
|
|
408
|
+
const pinned = await tmpHandle.stat();
|
|
409
|
+
if (!committed.isFile()
|
|
410
|
+
|| committed.isSymbolicLink()
|
|
411
|
+
|| committed.dev !== createdDev
|
|
412
|
+
|| committed.ino !== createdIno
|
|
413
|
+
|| committed.uid !== process.getuid?.()
|
|
414
|
+
|| committed.nlink !== 1
|
|
415
|
+
|| committed.size !== bytes.byteLength
|
|
416
|
+
|| (committed.mode & 0o7777) !== 0o600
|
|
417
|
+
|| pinned.dev !== createdDev
|
|
418
|
+
|| pinned.ino !== createdIno
|
|
419
|
+
|| pinned.nlink !== 1) {
|
|
420
|
+
if (committed.dev === createdDev && committed.ino === createdIno && committed.uid === process.getuid?.()) {
|
|
421
|
+
await unlinkIfOwnedInode(targetPath, createdDev, createdIno);
|
|
422
|
+
}
|
|
423
|
+
refuse('RECOVERY_REQUIRED', '', phase);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
finally {
|
|
427
|
+
if (verifyHandle)
|
|
428
|
+
await verifyHandle.close().catch(() => { });
|
|
429
|
+
}
|
|
430
|
+
await tmpHandle.close();
|
|
431
|
+
tmpClosed = true;
|
|
432
|
+
await syncDirectory(parentDir);
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
await tmpHandle.close();
|
|
436
|
+
tmpClosed = true;
|
|
437
|
+
await unlinkIfOwnedInode(tmpPath, createdDev, createdIno);
|
|
438
|
+
tmpUnlinked = true;
|
|
439
|
+
// If an interrupted prior publish left a sibling .tmp-* hardlink (nlink === 2), drop only sibling .tmp-* links.
|
|
440
|
+
const existingStat = await lstat(targetPath).catch(() => null);
|
|
441
|
+
if (existingStat && !existingStat.isSymbolicLink() && existingStat.isFile() && existingStat.nlink > 1) {
|
|
442
|
+
const basePrefix = basename(targetPath) + '.tmp-';
|
|
443
|
+
const siblings = await readdir(parentDir).catch(() => []);
|
|
444
|
+
for (const sib of siblings) {
|
|
445
|
+
if (sib.startsWith(basePrefix) && MARKER_TMP_FILE_RE.test(sib)) {
|
|
446
|
+
await unlinkIfOwnedInode(join(parentDir, sib), existingStat.dev, existingStat.ino);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
let existingBytes;
|
|
451
|
+
try {
|
|
452
|
+
existingBytes = await readBoundedFile(targetPath, 1_048_576, true, 0o600);
|
|
453
|
+
}
|
|
454
|
+
catch {
|
|
455
|
+
refuse('RECOVERY_REQUIRED', '', phase);
|
|
456
|
+
}
|
|
457
|
+
if (!Buffer.from(existingBytes).equals(bytes)) {
|
|
458
|
+
refuse('RECOVERY_REQUIRED', '', phase);
|
|
459
|
+
}
|
|
460
|
+
await syncDirectory(parentDir);
|
|
461
|
+
}
|
|
462
|
+
finally {
|
|
463
|
+
if (!tmpClosed) {
|
|
464
|
+
await tmpHandle.close().catch(() => { });
|
|
465
|
+
}
|
|
466
|
+
if (!tmpUnlinked && createdDev !== -1) {
|
|
467
|
+
await unlinkIfOwnedInode(tmpPath, createdDev, createdIno).catch(() => { });
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
/** Atomically replaces an existing controller marker JSON file via fsynced temp + rename + parent dir sync. */
|
|
472
|
+
export async function overwriteAtomicMarker(targetPath, value, vault, phase) {
|
|
473
|
+
const bytes = Buffer.from(canonical(value), 'utf8');
|
|
474
|
+
if (bytes.byteLength > 1_048_576)
|
|
475
|
+
refuse('OUTPUT_LIMIT', '', phase);
|
|
476
|
+
vault.assertClean(bytes);
|
|
477
|
+
const parentDir = dirname(targetPath);
|
|
478
|
+
const tmpPath = `${targetPath}.tmp-${randomBytes(16).toString('hex')}`;
|
|
479
|
+
const tmpHandle = await open(tmpPath, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | constants.O_NOFOLLOW, 0o600);
|
|
480
|
+
let tmpClosed = false;
|
|
481
|
+
let renamed = false;
|
|
482
|
+
let createdDev = -1;
|
|
483
|
+
let createdIno = -1;
|
|
484
|
+
try {
|
|
485
|
+
const initStat = await tmpHandle.stat();
|
|
486
|
+
createdDev = initStat.dev;
|
|
487
|
+
createdIno = initStat.ino;
|
|
488
|
+
if (!initStat.isFile() || initStat.uid !== process.getuid?.() || initStat.nlink !== 1) {
|
|
489
|
+
refuse('RECOVERY_REQUIRED', '', phase);
|
|
490
|
+
}
|
|
491
|
+
await writeAllToHandle(tmpHandle, bytes);
|
|
492
|
+
await tmpHandle.sync();
|
|
493
|
+
const sealedInfo = await tmpHandle.stat();
|
|
494
|
+
if (!sealedInfo.isFile()
|
|
495
|
+
|| sealedInfo.isSymbolicLink()
|
|
496
|
+
|| sealedInfo.dev !== createdDev
|
|
497
|
+
|| sealedInfo.ino !== createdIno
|
|
498
|
+
|| sealedInfo.uid !== process.getuid?.()
|
|
499
|
+
|| sealedInfo.nlink !== 1
|
|
500
|
+
|| sealedInfo.size !== bytes.byteLength
|
|
501
|
+
|| (sealedInfo.mode & 0o7777) !== 0o600) {
|
|
502
|
+
refuse('RECOVERY_REQUIRED', '', phase);
|
|
503
|
+
}
|
|
504
|
+
await rename(tmpPath, targetPath);
|
|
505
|
+
renamed = true;
|
|
506
|
+
let verifyHandle = null;
|
|
507
|
+
try {
|
|
508
|
+
verifyHandle = await open(targetPath, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
509
|
+
const committed = await verifyHandle.stat();
|
|
510
|
+
const pinned = await tmpHandle.stat();
|
|
511
|
+
if (!committed.isFile()
|
|
512
|
+
|| committed.isSymbolicLink()
|
|
513
|
+
|| committed.dev !== createdDev
|
|
514
|
+
|| committed.ino !== createdIno
|
|
515
|
+
|| committed.uid !== process.getuid?.()
|
|
516
|
+
|| committed.nlink !== 1
|
|
517
|
+
|| committed.size !== bytes.byteLength
|
|
518
|
+
|| (committed.mode & 0o7777) !== 0o600
|
|
519
|
+
|| !pinned.isFile()
|
|
520
|
+
|| pinned.dev !== createdDev
|
|
521
|
+
|| pinned.ino !== createdIno
|
|
522
|
+
|| pinned.uid !== process.getuid?.()
|
|
523
|
+
|| pinned.nlink !== 1
|
|
524
|
+
|| pinned.size !== bytes.byteLength
|
|
525
|
+
|| (pinned.mode & 0o7777) !== 0o600) {
|
|
526
|
+
refuse('RECOVERY_REQUIRED', '', phase);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
catch (error) {
|
|
530
|
+
if (error instanceof ControllerFailure)
|
|
531
|
+
throw error;
|
|
532
|
+
refuse('RECOVERY_REQUIRED', '', phase);
|
|
533
|
+
}
|
|
534
|
+
finally {
|
|
535
|
+
if (verifyHandle)
|
|
536
|
+
await verifyHandle.close().catch(() => { });
|
|
537
|
+
}
|
|
538
|
+
await tmpHandle.close();
|
|
539
|
+
tmpClosed = true;
|
|
540
|
+
await syncDirectory(parentDir);
|
|
541
|
+
}
|
|
542
|
+
finally {
|
|
543
|
+
if (!tmpClosed) {
|
|
544
|
+
await tmpHandle.close().catch(() => { });
|
|
545
|
+
}
|
|
546
|
+
if (!renamed && createdDev !== -1) {
|
|
547
|
+
await unlinkIfOwnedInode(tmpPath, createdDev, createdIno).catch(() => { });
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
export async function cleanCasTempFilesInDirectory(artifactsDir, owner) {
|
|
552
|
+
const markerRemoved = await cleanMarkerTempFilesInDirectory(artifactsDir, owner);
|
|
553
|
+
await owner.assertCurrent();
|
|
554
|
+
const blobsDir = join(artifactsDir, 'blobs');
|
|
555
|
+
const sha256Dir = join(blobsDir, 'sha256');
|
|
556
|
+
try {
|
|
557
|
+
const info = await lstat(sha256Dir);
|
|
558
|
+
if (info.isSymbolicLink() || !info.isDirectory())
|
|
559
|
+
refuse('ARTIFACT_INVALID', '', 'recovery');
|
|
560
|
+
}
|
|
561
|
+
catch (error) {
|
|
562
|
+
if (error instanceof ControllerFailure)
|
|
563
|
+
throw error;
|
|
564
|
+
if (error.code === 'ENOENT')
|
|
565
|
+
return markerRemoved;
|
|
566
|
+
refuse('ARTIFACT_INVALID', '', 'recovery');
|
|
567
|
+
}
|
|
568
|
+
try {
|
|
569
|
+
await canonicalComponents(sha256Dir, true);
|
|
570
|
+
}
|
|
571
|
+
catch {
|
|
572
|
+
refuse('ARTIFACT_INVALID', '', 'recovery');
|
|
573
|
+
}
|
|
574
|
+
const entries = await readdir(sha256Dir);
|
|
575
|
+
let removed = 0;
|
|
576
|
+
for (const entry of entries) {
|
|
577
|
+
if (!entry.startsWith('.tmp-'))
|
|
578
|
+
continue;
|
|
579
|
+
const candidatePath = join(sha256Dir, entry);
|
|
580
|
+
let stat;
|
|
581
|
+
try {
|
|
582
|
+
stat = await lstat(candidatePath);
|
|
583
|
+
}
|
|
584
|
+
catch (error) {
|
|
585
|
+
if (error.code === 'ENOENT')
|
|
586
|
+
continue;
|
|
587
|
+
throw error;
|
|
588
|
+
}
|
|
589
|
+
if (!stat.isSymbolicLink() && stat.isFile() && stat.uid === process.getuid?.()) {
|
|
590
|
+
await unlink(candidatePath).catch(error => {
|
|
591
|
+
if (error.code !== 'ENOENT')
|
|
592
|
+
throw error;
|
|
593
|
+
});
|
|
594
|
+
removed++;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
if (removed > 0) {
|
|
598
|
+
await syncDirectory(sha256Dir);
|
|
599
|
+
}
|
|
600
|
+
return markerRemoved + removed;
|
|
601
|
+
}
|
|
602
|
+
export async function readArtifact(directory, unowned, maximum = 8388608) {
|
|
603
|
+
const ref = checkedRef(unowned);
|
|
604
|
+
if (ref.name.length > 128 || ref.byteLength > maximum || maximum > 100_663_296)
|
|
605
|
+
refuse('ARTIFACT_INVALID', '', 'recovery');
|
|
606
|
+
try {
|
|
607
|
+
const bytes = await readBoundedFile(join(directory, ref.name), maximum, true), actual = digestArtifact(ref.name, bytes);
|
|
608
|
+
if (!actual.ok || !same(actual.value, ref))
|
|
609
|
+
refuse('ARTIFACT_INVALID', '', 'recovery');
|
|
610
|
+
return new Uint8Array(bytes);
|
|
611
|
+
}
|
|
612
|
+
catch (error) {
|
|
613
|
+
if (error instanceof ControllerFailure && error.diagnostic.code === 'ARTIFACT_INVALID')
|
|
614
|
+
throw error;
|
|
615
|
+
refuse('ARTIFACT_INVALID', '', 'recovery');
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
export class ArtifactStore {
|
|
619
|
+
directory;
|
|
620
|
+
owner;
|
|
621
|
+
vault;
|
|
622
|
+
constructor(directory, owner, vault) {
|
|
623
|
+
this.directory = directory;
|
|
624
|
+
this.owner = owner;
|
|
625
|
+
this.vault = vault;
|
|
626
|
+
}
|
|
627
|
+
async put(kind, bytes, maximum = 8388608) {
|
|
628
|
+
await this.owner.assertCurrent();
|
|
629
|
+
if (!/^[a-z][a-z0-9-]{0,23}$/.test(kind) || bytes.byteLength > maximum || maximum > 100_663_296)
|
|
630
|
+
refuse('OUTPUT_LIMIT', '', 'execution');
|
|
631
|
+
this.vault.assertClean(bytes);
|
|
632
|
+
const name = kind + '-' + hash('loopwright.dev/controller/artifact/' + kind + '/v1\0' + hash(bytes).hex).hex + '.bin';
|
|
633
|
+
const ref = digestArtifact(name, bytes);
|
|
634
|
+
if (!ref.ok)
|
|
635
|
+
refuse('ARTIFACT_INVALID', '', 'execution');
|
|
636
|
+
let file;
|
|
637
|
+
try {
|
|
638
|
+
file = await open(join(this.directory, name), constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | constants.O_NOFOLLOW, 0o600);
|
|
639
|
+
}
|
|
640
|
+
catch (error) {
|
|
641
|
+
if (error.code !== 'EEXIST')
|
|
642
|
+
throw error;
|
|
643
|
+
const known = await this.read(ref.value, maximum);
|
|
644
|
+
if (!Buffer.from(known).equals(Buffer.from(bytes)))
|
|
645
|
+
refuse('ARTIFACT_INVALID', '', 'recovery');
|
|
646
|
+
return ref.value;
|
|
647
|
+
}
|
|
648
|
+
try {
|
|
649
|
+
await file.writeFile(bytes);
|
|
650
|
+
await file.sync();
|
|
651
|
+
}
|
|
652
|
+
finally {
|
|
653
|
+
await file.close();
|
|
654
|
+
}
|
|
655
|
+
await syncDirectory(this.directory);
|
|
656
|
+
return ref.value;
|
|
657
|
+
}
|
|
658
|
+
json(kind, value, maximum = 65536) {
|
|
659
|
+
return this.put(kind, Buffer.from(canonical(value)), maximum);
|
|
660
|
+
}
|
|
661
|
+
async read(unowned, maximum = 8388608) {
|
|
662
|
+
return readArtifact(this.directory, unowned, maximum);
|
|
663
|
+
}
|
|
664
|
+
async putCasBlobFromFile(logicalName, sourcePath, maxBytes = OVERLAY_LIMITS.maxMaxBytes, options) {
|
|
665
|
+
return this.#ingestCasBlob(logicalName, maxBytes, async (consumeChunk) => {
|
|
666
|
+
await streamRegularFile(sourcePath, {
|
|
667
|
+
maxBytes,
|
|
668
|
+
code: 'ARTIFACT_INVALID',
|
|
669
|
+
limitCode: 'OUTPUT_LIMIT',
|
|
670
|
+
path: logicalName,
|
|
671
|
+
phase: 'execution',
|
|
672
|
+
}, consumeChunk);
|
|
673
|
+
}, options);
|
|
674
|
+
}
|
|
675
|
+
async putCasBlobFromBytes(logicalName, bytes, maxBytes = OVERLAY_LIMITS.maxMaxBytes, options) {
|
|
676
|
+
if (!ArrayBuffer.isView(bytes)
|
|
677
|
+
|| types.isProxy(bytes)
|
|
678
|
+
|| ![Uint8Array.prototype, Buffer.prototype].includes(Object.getPrototypeOf(bytes))
|
|
679
|
+
|| types.isSharedArrayBuffer(bytes.buffer)) {
|
|
680
|
+
refuse('ARTIFACT_INVALID', logicalName, 'execution');
|
|
681
|
+
}
|
|
682
|
+
const view = new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
683
|
+
return this.#ingestCasBlob(logicalName, maxBytes, async (consumeChunk) => {
|
|
684
|
+
if (view.byteLength > maxBytes)
|
|
685
|
+
refuse('OUTPUT_LIMIT', logicalName, 'execution');
|
|
686
|
+
for (let offset = 0; offset < view.byteLength; offset += STREAM_CHUNK_BYTES) {
|
|
687
|
+
await consumeChunk(view.subarray(offset, Math.min(view.byteLength, offset + STREAM_CHUNK_BYTES)));
|
|
688
|
+
}
|
|
689
|
+
}, options);
|
|
690
|
+
}
|
|
691
|
+
async tryReuseCasBlob(logicalName, sha256, expectedByteLength, options) {
|
|
692
|
+
await this.owner.assertCurrent();
|
|
693
|
+
if (typeof sha256 !== 'string'
|
|
694
|
+
|| !/^[0-9a-f]{64}$/.test(sha256)
|
|
695
|
+
|| !Number.isSafeInteger(expectedByteLength)
|
|
696
|
+
|| Object.is(expectedByteLength, -0)
|
|
697
|
+
|| expectedByteLength < 0
|
|
698
|
+
|| expectedByteLength > OVERLAY_LIMITS.maxMaxBytes
|
|
699
|
+
|| (expectedByteLength === 0) !== (sha256 === EMPTY_SHA256_HEX)) {
|
|
700
|
+
refuse('ARTIFACT_INVALID', logicalName, 'execution');
|
|
701
|
+
}
|
|
702
|
+
const blobRefRes = digestArtifactFromMetadata(logicalName, {
|
|
703
|
+
digest: { algorithm: 'sha256', hex: sha256 },
|
|
704
|
+
byteLength: expectedByteLength,
|
|
705
|
+
uri: 'cas://sha256/' + sha256,
|
|
706
|
+
});
|
|
707
|
+
if (!blobRefRes.ok) {
|
|
708
|
+
refuse('ARTIFACT_INVALID', logicalName, 'execution');
|
|
709
|
+
}
|
|
710
|
+
const canonicalPath = join(this.directory, 'blobs', 'sha256', sha256);
|
|
711
|
+
if (!inside(canonicalPath, this.directory) || canonicalPath === this.directory) {
|
|
712
|
+
refuse('ARTIFACT_INVALID', logicalName, 'execution');
|
|
713
|
+
}
|
|
714
|
+
try {
|
|
715
|
+
await lstat(canonicalPath);
|
|
716
|
+
}
|
|
717
|
+
catch (error) {
|
|
718
|
+
if (error.code === 'ENOENT')
|
|
719
|
+
return null;
|
|
720
|
+
refuse('ARTIFACT_INVALID', logicalName, 'execution');
|
|
721
|
+
}
|
|
722
|
+
const gitObjectFormat = options?.gitObjectFormat;
|
|
723
|
+
const streamChecker = this.vault.createStreamChecker();
|
|
724
|
+
let verified;
|
|
725
|
+
try {
|
|
726
|
+
verified = await streamVerifiedCasBlobWithSummary(this.directory, {
|
|
727
|
+
name: logicalName,
|
|
728
|
+
sha256,
|
|
729
|
+
byteLength: expectedByteLength,
|
|
730
|
+
uri: blobRefRes.value.uri,
|
|
731
|
+
path: canonicalPath,
|
|
732
|
+
blobRef: blobRefRes.value,
|
|
733
|
+
}, chunk => {
|
|
734
|
+
streamChecker.push(chunk);
|
|
735
|
+
}, 'execution', gitObjectFormat);
|
|
736
|
+
streamChecker.finish();
|
|
737
|
+
}
|
|
738
|
+
finally {
|
|
739
|
+
streamChecker.finish();
|
|
740
|
+
}
|
|
741
|
+
const verifiedSeal = gitObjectFormat !== undefined
|
|
742
|
+
? Object.freeze({
|
|
743
|
+
blobPath: verified.canonicalBlobPath,
|
|
744
|
+
dev: verified.summary.dev,
|
|
745
|
+
ino: verified.summary.ino,
|
|
746
|
+
size: verified.summary.byteLength,
|
|
747
|
+
mtimeMs: verified.summary.mtimeMs,
|
|
748
|
+
ctimeMs: verified.summary.ctimeMs,
|
|
749
|
+
sha256,
|
|
750
|
+
gitOid: verified.gitOid,
|
|
751
|
+
objectFormat: gitObjectFormat,
|
|
752
|
+
})
|
|
753
|
+
: undefined;
|
|
754
|
+
return Object.freeze({
|
|
755
|
+
path: canonicalPath,
|
|
756
|
+
sha256,
|
|
757
|
+
byteLength: expectedByteLength,
|
|
758
|
+
blobRef: blobRefRes.value,
|
|
759
|
+
...(verifiedSeal !== undefined ? { verifiedSeal } : {}),
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
async cleanCasTempFiles() {
|
|
763
|
+
return cleanCasTempFilesInDirectory(this.directory, this.owner);
|
|
764
|
+
}
|
|
765
|
+
async #verifyExistingVerifierCasBlob(options) {
|
|
766
|
+
const phase = options.phase ?? 'verification';
|
|
767
|
+
const maxBytes = options.maxBytes ?? VERIFIER_ARTIFACT_LIMITS.maxFileBytes;
|
|
768
|
+
const { logicalName, expectedSha256, expectedByteLength, mediaType, extraSecrets } = options;
|
|
769
|
+
await this.owner.assertCurrent();
|
|
770
|
+
if (typeof expectedSha256 !== 'string'
|
|
771
|
+
|| !/^[0-9a-f]{64}$/.test(expectedSha256)
|
|
772
|
+
|| !Number.isSafeInteger(expectedByteLength)
|
|
773
|
+
|| Object.is(expectedByteLength, -0)
|
|
774
|
+
|| expectedByteLength < 0
|
|
775
|
+
|| expectedByteLength > maxBytes
|
|
776
|
+
|| maxBytes > VERIFIER_ARTIFACT_LIMITS.maxFileBytes
|
|
777
|
+
|| (expectedByteLength === 0) !== (expectedSha256 === EMPTY_SHA256_HEX)) {
|
|
778
|
+
refuse('ARTIFACT_INVALID', logicalName, phase);
|
|
779
|
+
}
|
|
780
|
+
const blobRefRes = digestArtifactFromMetadata(logicalName, {
|
|
781
|
+
digest: { algorithm: 'sha256', hex: expectedSha256 },
|
|
782
|
+
byteLength: expectedByteLength,
|
|
783
|
+
uri: 'cas://sha256/' + expectedSha256,
|
|
784
|
+
...(mediaType !== undefined ? { mediaType } : {}),
|
|
785
|
+
});
|
|
786
|
+
if (!blobRefRes.ok) {
|
|
787
|
+
refuse('ARTIFACT_INVALID', logicalName, phase);
|
|
788
|
+
}
|
|
789
|
+
const canonicalPath = join(this.directory, 'blobs', 'sha256', expectedSha256);
|
|
790
|
+
if (!inside(canonicalPath, this.directory) || canonicalPath === this.directory) {
|
|
791
|
+
refuse('ARTIFACT_INVALID', logicalName, phase);
|
|
792
|
+
}
|
|
793
|
+
try {
|
|
794
|
+
const st = await lstat(canonicalPath);
|
|
795
|
+
if (st.isSymbolicLink()
|
|
796
|
+
|| !st.isFile()
|
|
797
|
+
|| st.nlink !== 1
|
|
798
|
+
|| st.uid !== process.getuid?.()
|
|
799
|
+
|| (st.mode & 0o7777) !== 0o400
|
|
800
|
+
|| st.size !== expectedByteLength) {
|
|
801
|
+
refuse('ARTIFACT_INVALID', logicalName, phase);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
catch (error) {
|
|
805
|
+
if (error instanceof ControllerFailure)
|
|
806
|
+
throw error;
|
|
807
|
+
if (error.code === 'ENOENT')
|
|
808
|
+
return null;
|
|
809
|
+
refuse('ARTIFACT_INVALID', logicalName, phase);
|
|
810
|
+
}
|
|
811
|
+
if (options.signal?.aborted) {
|
|
812
|
+
refuse('CANCELLED', '', phase);
|
|
813
|
+
}
|
|
814
|
+
if (options.onProgress) {
|
|
815
|
+
await options.onProgress();
|
|
816
|
+
}
|
|
817
|
+
const scanner = createBinarySecretStreamScanner(this.vault, logicalName, phase, extraSecrets);
|
|
818
|
+
let finished = false;
|
|
819
|
+
let verified;
|
|
820
|
+
try {
|
|
821
|
+
verified = await streamVerifiedCasBlobWithSummary(this.directory, {
|
|
822
|
+
name: logicalName,
|
|
823
|
+
sha256: expectedSha256,
|
|
824
|
+
byteLength: expectedByteLength,
|
|
825
|
+
uri: blobRefRes.value.uri,
|
|
826
|
+
path: canonicalPath,
|
|
827
|
+
blobRef: blobRefRes.value,
|
|
828
|
+
}, async (chunk) => {
|
|
829
|
+
if (options.signal?.aborted) {
|
|
830
|
+
refuse('CANCELLED', '', phase);
|
|
831
|
+
}
|
|
832
|
+
if (options.onProgress) {
|
|
833
|
+
await options.onProgress();
|
|
834
|
+
}
|
|
835
|
+
scanner.push(chunk);
|
|
836
|
+
}, phase);
|
|
837
|
+
if (options.signal?.aborted) {
|
|
838
|
+
refuse('CANCELLED', '', phase);
|
|
839
|
+
}
|
|
840
|
+
if (options.onProgress) {
|
|
841
|
+
await options.onProgress();
|
|
842
|
+
}
|
|
843
|
+
scanner.finish();
|
|
844
|
+
finished = true;
|
|
845
|
+
}
|
|
846
|
+
finally {
|
|
847
|
+
if (!finished) {
|
|
848
|
+
try {
|
|
849
|
+
scanner.finish();
|
|
850
|
+
}
|
|
851
|
+
catch {
|
|
852
|
+
// Ignore cleanup error after failure.
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
return {
|
|
857
|
+
pointer: Object.freeze({
|
|
858
|
+
path: canonicalPath,
|
|
859
|
+
sha256: expectedSha256,
|
|
860
|
+
byteLength: expectedByteLength,
|
|
861
|
+
blobRef: blobRefRes.value,
|
|
862
|
+
}),
|
|
863
|
+
summary: verified.summary,
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
async verifyOrReuseVerifierCasBlob(options) {
|
|
867
|
+
const verified = await this.#verifyExistingVerifierCasBlob(options);
|
|
868
|
+
return verified ? verified.pointer : null;
|
|
869
|
+
}
|
|
870
|
+
async ingestVerifiedCasBlobStream(options, streamSource) {
|
|
871
|
+
const phase = options.phase ?? 'verification';
|
|
872
|
+
const maxBytes = options.maxBytes ?? VERIFIER_ARTIFACT_LIMITS.maxFileBytes;
|
|
873
|
+
const { logicalName, expectedSha256, expectedByteLength, mediaType, extraSecrets } = options;
|
|
874
|
+
await this.owner.assertCurrent();
|
|
875
|
+
if (!Number.isSafeInteger(maxBytes)
|
|
876
|
+
|| Object.is(maxBytes, -0)
|
|
877
|
+
|| maxBytes < 0
|
|
878
|
+
|| maxBytes > VERIFIER_ARTIFACT_LIMITS.maxFileBytes
|
|
879
|
+
|| typeof expectedSha256 !== 'string'
|
|
880
|
+
|| !/^[0-9a-f]{64}$/.test(expectedSha256)
|
|
881
|
+
|| !Number.isSafeInteger(expectedByteLength)
|
|
882
|
+
|| Object.is(expectedByteLength, -0)
|
|
883
|
+
|| expectedByteLength < 0
|
|
884
|
+
|| expectedByteLength > maxBytes
|
|
885
|
+
|| (expectedByteLength === 0) !== (expectedSha256 === EMPTY_SHA256_HEX)) {
|
|
886
|
+
refuse('ARTIFACT_INVALID', logicalName, phase);
|
|
887
|
+
}
|
|
888
|
+
const blobRefRes = digestArtifactFromMetadata(logicalName, {
|
|
889
|
+
digest: { algorithm: 'sha256', hex: expectedSha256 },
|
|
890
|
+
byteLength: expectedByteLength,
|
|
891
|
+
uri: 'cas://sha256/' + expectedSha256,
|
|
892
|
+
...(mediaType !== undefined ? { mediaType } : {}),
|
|
893
|
+
});
|
|
894
|
+
if (!blobRefRes.ok) {
|
|
895
|
+
refuse('ARTIFACT_INVALID', logicalName, phase);
|
|
896
|
+
}
|
|
897
|
+
const blobsDir = join(this.directory, 'blobs');
|
|
898
|
+
const sha256Dir = join(blobsDir, 'sha256');
|
|
899
|
+
await privateDirectory(blobsDir);
|
|
900
|
+
await privateDirectory(sha256Dir);
|
|
901
|
+
// Fast path for already-sealed 0o400 CAS blobs: still stream, secret-scan, and SHA-256 verify the incoming
|
|
902
|
+
// payload end-to-end, while binding return strictly to the originally verified inode + timestamps.
|
|
903
|
+
const existingVerified = await this.#verifyExistingVerifierCasBlob(options);
|
|
904
|
+
if (existingVerified !== null) {
|
|
905
|
+
const dupScanner = createBinarySecretStreamScanner(this.vault, logicalName, phase, extraSecrets);
|
|
906
|
+
const dupSha = createHash('sha256');
|
|
907
|
+
let dupByteLength = 0;
|
|
908
|
+
let dupFinished = false;
|
|
909
|
+
try {
|
|
910
|
+
await streamSource(async (rawChunk) => {
|
|
911
|
+
if (rawChunk.byteLength === 0)
|
|
912
|
+
return;
|
|
913
|
+
for (let offset = 0; offset < rawChunk.byteLength; offset += STREAM_CHUNK_BYTES) {
|
|
914
|
+
if (options.signal?.aborted) {
|
|
915
|
+
refuse('CANCELLED', '', phase);
|
|
916
|
+
}
|
|
917
|
+
if (options.onProgress) {
|
|
918
|
+
await options.onProgress();
|
|
919
|
+
}
|
|
920
|
+
const slice = rawChunk.subarray(offset, Math.min(rawChunk.byteLength, offset + STREAM_CHUNK_BYTES));
|
|
921
|
+
dupByteLength += slice.byteLength;
|
|
922
|
+
if (dupByteLength > expectedByteLength || dupByteLength > maxBytes) {
|
|
923
|
+
refuse('ARTIFACT_INVALID', logicalName, phase);
|
|
924
|
+
}
|
|
925
|
+
dupScanner.push(slice);
|
|
926
|
+
dupSha.update(slice);
|
|
927
|
+
}
|
|
928
|
+
});
|
|
929
|
+
dupScanner.finish();
|
|
930
|
+
dupFinished = true;
|
|
931
|
+
}
|
|
932
|
+
finally {
|
|
933
|
+
if (!dupFinished) {
|
|
934
|
+
try {
|
|
935
|
+
dupScanner.finish();
|
|
936
|
+
}
|
|
937
|
+
catch {
|
|
938
|
+
// Ignore cleanup error after failure.
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
if (dupByteLength !== expectedByteLength || dupSha.digest('hex') !== expectedSha256) {
|
|
943
|
+
refuse('ARTIFACT_INVALID', logicalName, phase);
|
|
944
|
+
}
|
|
945
|
+
await this.owner.assertCurrent();
|
|
946
|
+
const postSt = await lstat(existingVerified.pointer.path).catch(() => null);
|
|
947
|
+
if (!postSt
|
|
948
|
+
|| postSt.isSymbolicLink()
|
|
949
|
+
|| !postSt.isFile()
|
|
950
|
+
|| postSt.nlink !== 1
|
|
951
|
+
|| postSt.uid !== process.getuid?.()
|
|
952
|
+
|| (postSt.mode & 0o7777) !== 0o400
|
|
953
|
+
|| postSt.size !== expectedByteLength
|
|
954
|
+
|| postSt.dev !== existingVerified.summary.dev
|
|
955
|
+
|| postSt.ino !== existingVerified.summary.ino
|
|
956
|
+
|| postSt.mtimeMs !== existingVerified.summary.mtimeMs
|
|
957
|
+
|| postSt.ctimeMs !== existingVerified.summary.ctimeMs) {
|
|
958
|
+
refuse('ARTIFACT_INVALID', logicalName, phase);
|
|
959
|
+
}
|
|
960
|
+
let verifyHandle = null;
|
|
961
|
+
try {
|
|
962
|
+
verifyHandle = await open(existingVerified.pointer.path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
963
|
+
const fdSt = await verifyHandle.stat();
|
|
964
|
+
if (!fdSt.isFile()
|
|
965
|
+
|| fdSt.isSymbolicLink()
|
|
966
|
+
|| fdSt.nlink !== 1
|
|
967
|
+
|| fdSt.uid !== process.getuid?.()
|
|
968
|
+
|| (fdSt.mode & 0o7777) !== 0o400
|
|
969
|
+
|| fdSt.size !== expectedByteLength
|
|
970
|
+
|| fdSt.dev !== existingVerified.summary.dev
|
|
971
|
+
|| fdSt.ino !== existingVerified.summary.ino
|
|
972
|
+
|| fdSt.mtimeMs !== existingVerified.summary.mtimeMs
|
|
973
|
+
|| fdSt.ctimeMs !== existingVerified.summary.ctimeMs) {
|
|
974
|
+
refuse('ARTIFACT_INVALID', logicalName, phase);
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
catch (error) {
|
|
978
|
+
if (error instanceof ControllerFailure && error.diagnostic.code === 'ARTIFACT_INVALID')
|
|
979
|
+
throw error;
|
|
980
|
+
refuse('ARTIFACT_INVALID', logicalName, phase);
|
|
981
|
+
}
|
|
982
|
+
finally {
|
|
983
|
+
if (verifyHandle)
|
|
984
|
+
await verifyHandle.close().catch(() => { });
|
|
985
|
+
}
|
|
986
|
+
return existingVerified.pointer;
|
|
987
|
+
}
|
|
988
|
+
const tmpPath = join(sha256Dir, '.tmp-' + randomBytes(16).toString('hex'));
|
|
989
|
+
const tmpHandle = await open(tmpPath, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | constants.O_NOFOLLOW, 0o600);
|
|
990
|
+
const scanner = createBinarySecretStreamScanner(this.vault, logicalName, phase, extraSecrets);
|
|
991
|
+
const sha = createHash('sha256');
|
|
992
|
+
let byteLength = 0;
|
|
993
|
+
let scannerFinished = false;
|
|
994
|
+
let tmpClosed = false;
|
|
995
|
+
let tmpUnlinked = false;
|
|
996
|
+
let createdDev = -1;
|
|
997
|
+
let createdIno = -1;
|
|
998
|
+
try {
|
|
999
|
+
const createdInfo = await tmpHandle.stat();
|
|
1000
|
+
createdDev = createdInfo.dev;
|
|
1001
|
+
createdIno = createdInfo.ino;
|
|
1002
|
+
if (!createdInfo.isFile()
|
|
1003
|
+
|| createdInfo.isSymbolicLink()
|
|
1004
|
+
|| createdInfo.uid !== process.getuid?.()
|
|
1005
|
+
|| createdInfo.nlink !== 1) {
|
|
1006
|
+
refuse('ARTIFACT_INVALID', logicalName, phase);
|
|
1007
|
+
}
|
|
1008
|
+
await streamSource(async (rawChunk) => {
|
|
1009
|
+
if (rawChunk.byteLength === 0)
|
|
1010
|
+
return;
|
|
1011
|
+
for (let offset = 0; offset < rawChunk.byteLength; offset += STREAM_CHUNK_BYTES) {
|
|
1012
|
+
if (options.signal?.aborted) {
|
|
1013
|
+
refuse('CANCELLED', '', phase);
|
|
1014
|
+
}
|
|
1015
|
+
if (options.onProgress) {
|
|
1016
|
+
await options.onProgress();
|
|
1017
|
+
}
|
|
1018
|
+
const slice = rawChunk.subarray(offset, Math.min(rawChunk.byteLength, offset + STREAM_CHUNK_BYTES));
|
|
1019
|
+
byteLength += slice.byteLength;
|
|
1020
|
+
if (byteLength > expectedByteLength || byteLength > maxBytes) {
|
|
1021
|
+
refuse('ARTIFACT_INVALID', logicalName, phase);
|
|
1022
|
+
}
|
|
1023
|
+
scanner.push(slice);
|
|
1024
|
+
sha.update(slice);
|
|
1025
|
+
await writeAllToHandle(tmpHandle, slice);
|
|
1026
|
+
}
|
|
1027
|
+
});
|
|
1028
|
+
scanner.finish();
|
|
1029
|
+
scannerFinished = true;
|
|
1030
|
+
const observedSha256 = sha.digest('hex');
|
|
1031
|
+
if (byteLength !== expectedByteLength || observedSha256 !== expectedSha256) {
|
|
1032
|
+
refuse('ARTIFACT_INVALID', logicalName, phase);
|
|
1033
|
+
}
|
|
1034
|
+
await tmpHandle.chmod(0o400);
|
|
1035
|
+
await tmpHandle.sync();
|
|
1036
|
+
const sealedInfo = await tmpHandle.stat();
|
|
1037
|
+
if (!sealedInfo.isFile()
|
|
1038
|
+
|| sealedInfo.isSymbolicLink()
|
|
1039
|
+
|| sealedInfo.dev !== createdDev
|
|
1040
|
+
|| sealedInfo.ino !== createdIno
|
|
1041
|
+
|| sealedInfo.uid !== process.getuid?.()
|
|
1042
|
+
|| sealedInfo.nlink !== 1
|
|
1043
|
+
|| sealedInfo.size !== expectedByteLength
|
|
1044
|
+
|| (sealedInfo.mode & 0o7777) !== 0o400) {
|
|
1045
|
+
refuse('ARTIFACT_INVALID', logicalName, phase);
|
|
1046
|
+
}
|
|
1047
|
+
await this.owner.assertCurrent();
|
|
1048
|
+
const beforeLink = await lstat(tmpPath).catch(() => null);
|
|
1049
|
+
if (!beforeLink
|
|
1050
|
+
|| beforeLink.isSymbolicLink()
|
|
1051
|
+
|| !beforeLink.isFile()
|
|
1052
|
+
|| beforeLink.dev !== sealedInfo.dev
|
|
1053
|
+
|| beforeLink.ino !== sealedInfo.ino
|
|
1054
|
+
|| beforeLink.uid !== process.getuid?.()) {
|
|
1055
|
+
tmpUnlinked = true;
|
|
1056
|
+
refuse('ARTIFACT_INVALID', logicalName, phase);
|
|
1057
|
+
}
|
|
1058
|
+
const finalHexPath = join(sha256Dir, expectedSha256);
|
|
1059
|
+
let linked = false;
|
|
1060
|
+
try {
|
|
1061
|
+
await link(tmpPath, finalHexPath);
|
|
1062
|
+
linked = true;
|
|
1063
|
+
}
|
|
1064
|
+
catch (error) {
|
|
1065
|
+
if (error.code !== 'EEXIST')
|
|
1066
|
+
throw error;
|
|
1067
|
+
}
|
|
1068
|
+
if (linked) {
|
|
1069
|
+
await unlinkIfOwnedInode(tmpPath, sealedInfo.dev, sealedInfo.ino);
|
|
1070
|
+
tmpUnlinked = true;
|
|
1071
|
+
let finalVerifyHandle = null;
|
|
1072
|
+
try {
|
|
1073
|
+
finalVerifyHandle = await open(finalHexPath, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
1074
|
+
const committed = await finalVerifyHandle.stat();
|
|
1075
|
+
const pinned = await tmpHandle.stat();
|
|
1076
|
+
if (committed.isSymbolicLink()
|
|
1077
|
+
|| !committed.isFile()
|
|
1078
|
+
|| committed.dev !== sealedInfo.dev
|
|
1079
|
+
|| committed.ino !== sealedInfo.ino
|
|
1080
|
+
|| committed.uid !== process.getuid?.()
|
|
1081
|
+
|| committed.nlink !== 1
|
|
1082
|
+
|| committed.size !== expectedByteLength
|
|
1083
|
+
|| (committed.mode & 0o7777) !== 0o400
|
|
1084
|
+
|| !pinned.isFile()
|
|
1085
|
+
|| pinned.dev !== sealedInfo.dev
|
|
1086
|
+
|| pinned.ino !== sealedInfo.ino
|
|
1087
|
+
|| pinned.uid !== process.getuid?.()
|
|
1088
|
+
|| pinned.nlink !== 1
|
|
1089
|
+
|| pinned.size !== expectedByteLength
|
|
1090
|
+
|| (pinned.mode & 0o7777) !== 0o400) {
|
|
1091
|
+
if (committed.dev === sealedInfo.dev
|
|
1092
|
+
&& committed.ino === sealedInfo.ino
|
|
1093
|
+
&& committed.uid === process.getuid?.()) {
|
|
1094
|
+
await unlinkIfOwnedInode(finalHexPath, sealedInfo.dev, sealedInfo.ino);
|
|
1095
|
+
}
|
|
1096
|
+
refuse('ARTIFACT_INVALID', logicalName, phase);
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
catch (error) {
|
|
1100
|
+
if (error instanceof ControllerFailure && error.diagnostic.code === 'ARTIFACT_INVALID')
|
|
1101
|
+
throw error;
|
|
1102
|
+
refuse('ARTIFACT_INVALID', logicalName, phase);
|
|
1103
|
+
}
|
|
1104
|
+
finally {
|
|
1105
|
+
if (finalVerifyHandle)
|
|
1106
|
+
await finalVerifyHandle.close().catch(() => { });
|
|
1107
|
+
}
|
|
1108
|
+
await tmpHandle.close();
|
|
1109
|
+
tmpClosed = true;
|
|
1110
|
+
}
|
|
1111
|
+
else {
|
|
1112
|
+
await tmpHandle.close();
|
|
1113
|
+
tmpClosed = true;
|
|
1114
|
+
await unlinkIfOwnedInode(tmpPath, sealedInfo.dev, sealedInfo.ino);
|
|
1115
|
+
tmpUnlinked = true;
|
|
1116
|
+
for (let attempt = 0; attempt < 20; attempt++) {
|
|
1117
|
+
const st = await lstat(finalHexPath).catch(() => null);
|
|
1118
|
+
if (!st || st.isSymbolicLink() || !st.isFile() || st.nlink <= 1)
|
|
1119
|
+
break;
|
|
1120
|
+
await new Promise(resolveDelay => setTimeout(resolveDelay, 5));
|
|
1121
|
+
}
|
|
1122
|
+
const existingCheck = await this.verifyOrReuseVerifierCasBlob(options);
|
|
1123
|
+
if (!existingCheck)
|
|
1124
|
+
refuse('ARTIFACT_INVALID', logicalName, phase);
|
|
1125
|
+
}
|
|
1126
|
+
await syncDirectory(sha256Dir);
|
|
1127
|
+
return Object.freeze({
|
|
1128
|
+
path: finalHexPath,
|
|
1129
|
+
sha256: expectedSha256,
|
|
1130
|
+
byteLength: expectedByteLength,
|
|
1131
|
+
blobRef: blobRefRes.value,
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
finally {
|
|
1135
|
+
if (!scannerFinished) {
|
|
1136
|
+
try {
|
|
1137
|
+
scanner.finish();
|
|
1138
|
+
}
|
|
1139
|
+
catch {
|
|
1140
|
+
// Ignore cleanup error after failure.
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
if (!tmpClosed) {
|
|
1144
|
+
await tmpHandle.close().catch(() => { });
|
|
1145
|
+
}
|
|
1146
|
+
if (!tmpUnlinked && createdDev !== -1) {
|
|
1147
|
+
await unlinkIfOwnedInode(tmpPath, createdDev, createdIno).catch(() => { });
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
async #ingestCasBlob(logicalName, maxBytes, streamSource, options) {
|
|
1152
|
+
await this.owner.assertCurrent();
|
|
1153
|
+
if (!Number.isSafeInteger(maxBytes) || Object.is(maxBytes, -0) || maxBytes < 0 || maxBytes > OVERLAY_LIMITS.maxMaxBytes) {
|
|
1154
|
+
refuse('OUTPUT_LIMIT', logicalName, 'execution');
|
|
1155
|
+
}
|
|
1156
|
+
const nameCheck = digestArtifactFromMetadata(logicalName, {
|
|
1157
|
+
digest: { algorithm: 'sha256', hex: EMPTY_SHA256_HEX },
|
|
1158
|
+
byteLength: 0,
|
|
1159
|
+
uri: 'cas://sha256/' + EMPTY_SHA256_HEX,
|
|
1160
|
+
});
|
|
1161
|
+
if (!nameCheck.ok) {
|
|
1162
|
+
refuse('ARTIFACT_INVALID', logicalName, 'execution');
|
|
1163
|
+
}
|
|
1164
|
+
const blobsDir = join(this.directory, 'blobs');
|
|
1165
|
+
const sha256Dir = join(blobsDir, 'sha256');
|
|
1166
|
+
await privateDirectory(blobsDir);
|
|
1167
|
+
await privateDirectory(sha256Dir);
|
|
1168
|
+
const tmpPath = join(sha256Dir, '.tmp-' + randomBytes(16).toString('hex'));
|
|
1169
|
+
const tmpHandle = await open(tmpPath, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | constants.O_NOFOLLOW, 0o600);
|
|
1170
|
+
const streamChecker = this.vault.createStreamChecker();
|
|
1171
|
+
const sha = createHash('sha256');
|
|
1172
|
+
const gitObjectFormat = options?.gitObjectFormat;
|
|
1173
|
+
let byteLength = 0;
|
|
1174
|
+
let checkerFinished = false;
|
|
1175
|
+
let tmpClosed = false;
|
|
1176
|
+
let tmpUnlinked = false;
|
|
1177
|
+
let createdDev = -1;
|
|
1178
|
+
let createdIno = -1;
|
|
1179
|
+
try {
|
|
1180
|
+
const createdInfo = await tmpHandle.stat();
|
|
1181
|
+
createdDev = createdInfo.dev;
|
|
1182
|
+
createdIno = createdInfo.ino;
|
|
1183
|
+
if (!createdInfo.isFile()
|
|
1184
|
+
|| createdInfo.isSymbolicLink()
|
|
1185
|
+
|| createdInfo.uid !== process.getuid?.()
|
|
1186
|
+
|| createdInfo.nlink !== 1) {
|
|
1187
|
+
refuse('ARTIFACT_INVALID', logicalName, 'execution');
|
|
1188
|
+
}
|
|
1189
|
+
await streamSource(async (slice) => {
|
|
1190
|
+
if (slice.byteLength === 0)
|
|
1191
|
+
return;
|
|
1192
|
+
byteLength += slice.byteLength;
|
|
1193
|
+
if (byteLength > maxBytes)
|
|
1194
|
+
refuse('OUTPUT_LIMIT', logicalName, 'execution');
|
|
1195
|
+
streamChecker.push(slice);
|
|
1196
|
+
sha.update(slice);
|
|
1197
|
+
await writeAllToHandle(tmpHandle, slice);
|
|
1198
|
+
});
|
|
1199
|
+
streamChecker.finish();
|
|
1200
|
+
checkerFinished = true;
|
|
1201
|
+
await tmpHandle.chmod(0o400);
|
|
1202
|
+
await tmpHandle.sync();
|
|
1203
|
+
const sealedInfo = await tmpHandle.stat();
|
|
1204
|
+
if (!sealedInfo.isFile()
|
|
1205
|
+
|| sealedInfo.isSymbolicLink()
|
|
1206
|
+
|| sealedInfo.dev !== createdDev
|
|
1207
|
+
|| sealedInfo.ino !== createdIno
|
|
1208
|
+
|| sealedInfo.uid !== process.getuid?.()
|
|
1209
|
+
|| sealedInfo.nlink !== 1
|
|
1210
|
+
|| sealedInfo.size !== byteLength
|
|
1211
|
+
|| (sealedInfo.mode & 0o7777) !== 0o400) {
|
|
1212
|
+
refuse('ARTIFACT_INVALID', logicalName, 'execution');
|
|
1213
|
+
}
|
|
1214
|
+
await this.owner.assertCurrent();
|
|
1215
|
+
const beforeLink = await lstat(tmpPath).catch(() => null);
|
|
1216
|
+
if (!beforeLink
|
|
1217
|
+
|| beforeLink.isSymbolicLink()
|
|
1218
|
+
|| !beforeLink.isFile()
|
|
1219
|
+
|| beforeLink.dev !== sealedInfo.dev
|
|
1220
|
+
|| beforeLink.ino !== sealedInfo.ino
|
|
1221
|
+
|| beforeLink.uid !== process.getuid?.()) {
|
|
1222
|
+
tmpUnlinked = true;
|
|
1223
|
+
refuse('ARTIFACT_INVALID', logicalName, 'execution');
|
|
1224
|
+
}
|
|
1225
|
+
const sha256 = sha.digest('hex');
|
|
1226
|
+
const finalHexPath = join(sha256Dir, sha256);
|
|
1227
|
+
const blobRefRes = digestArtifactFromMetadata(logicalName, {
|
|
1228
|
+
digest: { algorithm: 'sha256', hex: sha256 },
|
|
1229
|
+
byteLength,
|
|
1230
|
+
uri: 'cas://sha256/' + sha256,
|
|
1231
|
+
});
|
|
1232
|
+
if (!blobRefRes.ok)
|
|
1233
|
+
refuse('ARTIFACT_INVALID', logicalName, 'execution');
|
|
1234
|
+
let verifiedSeal;
|
|
1235
|
+
let linked = false;
|
|
1236
|
+
try {
|
|
1237
|
+
await link(tmpPath, finalHexPath);
|
|
1238
|
+
linked = true;
|
|
1239
|
+
}
|
|
1240
|
+
catch (error) {
|
|
1241
|
+
if (error.code !== 'EEXIST')
|
|
1242
|
+
throw error;
|
|
1243
|
+
}
|
|
1244
|
+
if (linked) {
|
|
1245
|
+
// Fresh-write winner: never mint verifiedSeal from the pre-chmod writable write stream.
|
|
1246
|
+
// The first verifier (assertCanonicalMinimalOverlay) will hash the finalized 0o400
|
|
1247
|
+
// nlink===1 descriptor and attach VERIFIED_CAS_SEAL for subsequent O(1) reuse.
|
|
1248
|
+
await unlinkIfOwnedInode(tmpPath, sealedInfo.dev, sealedInfo.ino);
|
|
1249
|
+
tmpUnlinked = true;
|
|
1250
|
+
let finalVerifyHandle = null;
|
|
1251
|
+
try {
|
|
1252
|
+
finalVerifyHandle = await open(finalHexPath, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
1253
|
+
const committed = await finalVerifyHandle.stat();
|
|
1254
|
+
const pinned = await tmpHandle.stat();
|
|
1255
|
+
if (committed.isSymbolicLink()
|
|
1256
|
+
|| !committed.isFile()
|
|
1257
|
+
|| committed.dev !== sealedInfo.dev
|
|
1258
|
+
|| committed.ino !== sealedInfo.ino
|
|
1259
|
+
|| committed.uid !== process.getuid?.()
|
|
1260
|
+
|| committed.nlink !== 1
|
|
1261
|
+
|| committed.size !== byteLength
|
|
1262
|
+
|| (committed.mode & 0o7777) !== 0o400
|
|
1263
|
+
|| !pinned.isFile()
|
|
1264
|
+
|| pinned.dev !== sealedInfo.dev
|
|
1265
|
+
|| pinned.ino !== sealedInfo.ino
|
|
1266
|
+
|| pinned.uid !== process.getuid?.()
|
|
1267
|
+
|| pinned.nlink !== 1
|
|
1268
|
+
|| pinned.size !== byteLength
|
|
1269
|
+
|| (pinned.mode & 0o7777) !== 0o400) {
|
|
1270
|
+
if (committed.dev === sealedInfo.dev
|
|
1271
|
+
&& committed.ino === sealedInfo.ino
|
|
1272
|
+
&& committed.uid === process.getuid?.()) {
|
|
1273
|
+
await unlinkIfOwnedInode(finalHexPath, sealedInfo.dev, sealedInfo.ino);
|
|
1274
|
+
}
|
|
1275
|
+
refuse('ARTIFACT_INVALID', logicalName, 'execution');
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
finally {
|
|
1279
|
+
if (finalVerifyHandle)
|
|
1280
|
+
await finalVerifyHandle.close().catch(() => { });
|
|
1281
|
+
}
|
|
1282
|
+
await tmpHandle.close();
|
|
1283
|
+
tmpClosed = true;
|
|
1284
|
+
}
|
|
1285
|
+
else {
|
|
1286
|
+
await tmpHandle.close();
|
|
1287
|
+
tmpClosed = true;
|
|
1288
|
+
await unlinkIfOwnedInode(tmpPath, sealedInfo.dev, sealedInfo.ino);
|
|
1289
|
+
tmpUnlinked = true;
|
|
1290
|
+
// Allow a racing writer's link()+unlink() pair to finish dropping nlink from 2 -> 1.
|
|
1291
|
+
for (let attempt = 0; attempt < 20; attempt++) {
|
|
1292
|
+
const st = await lstat(finalHexPath).catch(() => null);
|
|
1293
|
+
if (!st || st.isSymbolicLink() || !st.isFile() || st.nlink <= 1)
|
|
1294
|
+
break;
|
|
1295
|
+
await new Promise(resolveDelay => setTimeout(resolveDelay, 5));
|
|
1296
|
+
}
|
|
1297
|
+
const verified = await streamVerifiedCasBlobWithSummary(this.directory, { name: logicalName, sha256, byteLength, uri: blobRefRes.value.uri, path: finalHexPath }, undefined, 'execution', gitObjectFormat);
|
|
1298
|
+
if (gitObjectFormat !== undefined) {
|
|
1299
|
+
verifiedSeal = Object.freeze({
|
|
1300
|
+
blobPath: verified.canonicalBlobPath,
|
|
1301
|
+
dev: verified.summary.dev,
|
|
1302
|
+
ino: verified.summary.ino,
|
|
1303
|
+
size: verified.summary.byteLength,
|
|
1304
|
+
mtimeMs: verified.summary.mtimeMs,
|
|
1305
|
+
ctimeMs: verified.summary.ctimeMs,
|
|
1306
|
+
sha256,
|
|
1307
|
+
gitOid: verified.gitOid,
|
|
1308
|
+
objectFormat: gitObjectFormat,
|
|
1309
|
+
});
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
await syncDirectory(sha256Dir);
|
|
1313
|
+
return Object.freeze({
|
|
1314
|
+
path: finalHexPath,
|
|
1315
|
+
sha256,
|
|
1316
|
+
byteLength,
|
|
1317
|
+
blobRef: blobRefRes.value,
|
|
1318
|
+
...(verifiedSeal !== undefined ? { verifiedSeal } : {}),
|
|
1319
|
+
});
|
|
1320
|
+
}
|
|
1321
|
+
catch (err) {
|
|
1322
|
+
if (!checkerFinished) {
|
|
1323
|
+
checkerFinished = true;
|
|
1324
|
+
streamChecker.finish();
|
|
1325
|
+
}
|
|
1326
|
+
throw err;
|
|
1327
|
+
}
|
|
1328
|
+
finally {
|
|
1329
|
+
if (!checkerFinished) {
|
|
1330
|
+
try {
|
|
1331
|
+
streamChecker.finish();
|
|
1332
|
+
}
|
|
1333
|
+
catch {
|
|
1334
|
+
// Ignore cleanup error after failure.
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
if (!tmpClosed) {
|
|
1338
|
+
await tmpHandle.close().catch(() => { });
|
|
1339
|
+
}
|
|
1340
|
+
if (!tmpUnlinked && createdDev !== -1) {
|
|
1341
|
+
await unlinkIfOwnedInode(tmpPath, createdDev, createdIno).catch(() => { });
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
}
|