@halonicjs/testing 0.0.0 → 0.1.0
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 +202 -0
- package/NOTICE +1 -0
- package/README.md +41 -1
- package/dist/adapters/http-kit/src/address-class.d.ts +34 -0
- package/dist/adapters/http-kit/src/address-class.js +109 -0
- package/dist/adapters/http-kit/src/index.d.ts +2 -0
- package/dist/adapters/http-kit/src/index.js +2 -0
- package/dist/adapters/http-kit/src/ip-address.d.ts +23 -0
- package/dist/adapters/http-kit/src/ip-address.js +89 -0
- package/dist/adapters/integration-kit/src/declaration.d.ts +14 -0
- package/dist/adapters/integration-kit/src/declaration.js +77 -0
- package/dist/adapters/integration-kit/src/host.d.ts +28 -0
- package/dist/adapters/integration-kit/src/host.js +30 -0
- package/dist/adapters/integration-kit/src/index.d.ts +14 -0
- package/dist/adapters/integration-kit/src/index.js +21 -0
- package/dist/adapters/integration-kit/src/leak-attempt.d.ts +14 -0
- package/dist/adapters/integration-kit/src/leak-attempt.js +16 -0
- package/dist/adapters/integration-kit/src/limited-http.d.ts +49 -0
- package/dist/adapters/integration-kit/src/limited-http.js +182 -0
- package/dist/adapters/integration-kit/src/load-problem.d.ts +20 -0
- package/dist/adapters/integration-kit/src/load-problem.js +1 -0
- package/dist/adapters/integration-kit/src/loader.d.ts +104 -0
- package/dist/adapters/integration-kit/src/loader.js +219 -0
- package/dist/adapters/integration-kit/src/local-address.d.ts +15 -0
- package/dist/adapters/integration-kit/src/local-address.js +25 -0
- package/dist/adapters/integration-kit/src/own-request.d.ts +33 -0
- package/dist/adapters/integration-kit/src/own-request.js +36 -0
- package/dist/adapters/integration-kit/src/plugin-load.d.ts +14 -0
- package/dist/adapters/integration-kit/src/plugin-load.js +58 -0
- package/dist/adapters/integration-kit/src/policy.d.ts +55 -0
- package/dist/adapters/integration-kit/src/policy.js +37 -0
- package/dist/adapters/integration-kit/src/request-body.d.ts +38 -0
- package/dist/adapters/integration-kit/src/request-body.js +68 -0
- package/dist/adapters/integration-kit/src/request-log.d.ts +25 -0
- package/dist/adapters/integration-kit/src/request-log.js +17 -0
- package/dist/adapters/integration-kit/src/response-body.d.ts +23 -0
- package/dist/adapters/integration-kit/src/response-body.js +117 -0
- package/dist/adapters/integration-kit/src/scoped-tokens.d.ts +14 -0
- package/dist/adapters/integration-kit/src/scoped-tokens.js +27 -0
- package/dist/adapters/integration-kit/src/secret-filter.d.ts +84 -0
- package/dist/adapters/integration-kit/src/secret-filter.js +205 -0
- package/dist/adapters/integration-kit/src/secret-in-request.d.ts +59 -0
- package/dist/adapters/integration-kit/src/secret-in-request.js +133 -0
- package/dist/adapters/integration-kit/src/secret-placement.d.ts +36 -0
- package/dist/adapters/integration-kit/src/secret-placement.js +190 -0
- package/dist/adapters/integration-kit/src/wait.d.ts +16 -0
- package/dist/adapters/integration-kit/src/wait.js +35 -0
- package/dist/core/events/src/add-usage.d.ts +10 -0
- package/dist/core/events/src/add-usage.js +27 -0
- package/dist/core/events/src/agent-resume.d.ts +24 -0
- package/dist/core/events/src/agent-resume.js +1 -0
- package/dist/core/events/src/home-path.d.ts +13 -0
- package/dist/core/events/src/home-path.js +26 -0
- package/dist/core/events/src/index.d.ts +13 -0
- package/dist/core/events/src/index.js +7 -0
- package/dist/core/events/src/run-basics.d.ts +205 -0
- package/dist/core/events/src/run-basics.js +1 -0
- package/dist/core/events/src/run-event.d.ts +434 -0
- package/dist/core/events/src/run-event.js +1 -0
- package/dist/core/events/src/run-summary.d.ts +108 -0
- package/dist/core/events/src/run-summary.js +1 -0
- package/dist/core/events/src/sandbox-blocked.d.ts +42 -0
- package/dist/core/events/src/sandbox-blocked.js +26 -0
- package/dist/core/events/src/sandbox-opened-read.d.ts +17 -0
- package/dist/core/events/src/sandbox-opened-read.js +63 -0
- package/dist/core/events/src/sandbox-opened.d.ts +94 -0
- package/dist/core/events/src/sandbox-opened.js +52 -0
- package/dist/core/events/src/summarize.d.ts +14 -0
- package/dist/core/events/src/summarize.js +188 -0
- package/dist/core/events/src/timeline-entry.d.ts +21 -0
- package/dist/core/events/src/timeline-entry.js +105 -0
- package/dist/core/events/src/upgrade.d.ts +23 -0
- package/dist/core/events/src/upgrade.js +49 -0
- package/dist/core/format/src/compact.d.ts +30 -0
- package/dist/core/format/src/compact.js +72 -0
- package/dist/core/format/src/index.d.ts +37 -0
- package/dist/core/format/src/index.js +23 -0
- package/dist/core/format/src/integration/index.d.ts +6 -0
- package/dist/core/format/src/integration/index.js +9 -0
- package/dist/core/format/src/json-schema.d.ts +26 -0
- package/dist/core/format/src/json-schema.js +48 -0
- package/dist/core/format/src/kind.d.ts +65 -0
- package/dist/core/format/src/kind.js +1 -0
- package/dist/core/format/src/kinds/agent/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/agent/kind.js +10 -0
- package/dist/core/format/src/kinds/agent/sandbox-fields.d.ts +89 -0
- package/dist/core/format/src/kinds/agent/sandbox-fields.js +197 -0
- package/dist/core/format/src/kinds/agent/schema.d.ts +147 -0
- package/dist/core/format/src/kinds/agent/schema.js +107 -0
- package/dist/core/format/src/kinds/agent/working-folder-start.d.ts +74 -0
- package/dist/core/format/src/kinds/agent/working-folder-start.js +312 -0
- package/dist/core/format/src/kinds/collection/kind.d.ts +8 -0
- package/dist/core/format/src/kinds/collection/kind.js +14 -0
- package/dist/core/format/src/kinds/collection/schema.d.ts +89 -0
- package/dist/core/format/src/kinds/collection/schema.js +90 -0
- package/dist/core/format/src/kinds/connector/is-local.d.ts +10 -0
- package/dist/core/format/src/kinds/connector/is-local.js +43 -0
- package/dist/core/format/src/kinds/connector/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/connector/kind.js +119 -0
- package/dist/core/format/src/kinds/connector/schema.d.ts +50 -0
- package/dist/core/format/src/kinds/connector/schema.js +92 -0
- package/dist/core/format/src/kinds/deployments/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/deployments/kind.js +25 -0
- package/dist/core/format/src/kinds/deployments/schema.d.ts +37 -0
- package/dist/core/format/src/kinds/deployments/schema.js +42 -0
- package/dist/core/format/src/kinds/hub/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/hub/kind.js +10 -0
- package/dist/core/format/src/kinds/hub/schema.d.ts +54 -0
- package/dist/core/format/src/kinds/hub/schema.js +34 -0
- package/dist/core/format/src/kinds/integration/kind.d.ts +16 -0
- package/dist/core/format/src/kinds/integration/kind.js +138 -0
- package/dist/core/format/src/kinds/integration/parse-sheet.d.ts +19 -0
- package/dist/core/format/src/kinds/integration/parse-sheet.js +24 -0
- package/dist/core/format/src/kinds/integration/policy.d.ts +67 -0
- package/dist/core/format/src/kinds/integration/policy.js +268 -0
- package/dist/core/format/src/kinds/integration/schema.d.ts +233 -0
- package/dist/core/format/src/kinds/integration/schema.js +233 -0
- package/dist/core/format/src/kinds/knowledge/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/knowledge/kind.js +13 -0
- package/dist/core/format/src/kinds/knowledge/schema.d.ts +18 -0
- package/dist/core/format/src/kinds/knowledge/schema.js +25 -0
- package/dist/core/format/src/kinds/models/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/models/kind.js +10 -0
- package/dist/core/format/src/kinds/models/schema.d.ts +92 -0
- package/dist/core/format/src/kinds/models/schema.js +38 -0
- package/dist/core/format/src/kinds/plugin/backend.d.ts +22 -0
- package/dist/core/format/src/kinds/plugin/backend.js +31 -0
- package/dist/core/format/src/kinds/plugin/checks.d.ts +13 -0
- package/dist/core/format/src/kinds/plugin/checks.js +131 -0
- package/dist/core/format/src/kinds/plugin/kind.d.ts +8 -0
- package/dist/core/format/src/kinds/plugin/kind.js +16 -0
- package/dist/core/format/src/kinds/plugin/problems.d.ts +24 -0
- package/dist/core/format/src/kinds/plugin/problems.js +65 -0
- package/dist/core/format/src/kinds/plugin/schema.d.ts +542 -0
- package/dist/core/format/src/kinds/plugin/schema.js +261 -0
- package/dist/core/format/src/kinds/plugin/setting-values.d.ts +17 -0
- package/dist/core/format/src/kinds/plugin/setting-values.js +38 -0
- package/dist/core/format/src/kinds/plugin/ui-checks.d.ts +8 -0
- package/dist/core/format/src/kinds/plugin/ui-checks.js +94 -0
- package/dist/core/format/src/kinds/provider/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/provider/kind.js +24 -0
- package/dist/core/format/src/kinds/provider/schema.d.ts +17 -0
- package/dist/core/format/src/kinds/provider/schema.js +22 -0
- package/dist/core/format/src/kinds/routine/kind.d.ts +8 -0
- package/dist/core/format/src/kinds/routine/kind.js +25 -0
- package/dist/core/format/src/kinds/routine/schema.d.ts +84 -0
- package/dist/core/format/src/kinds/routine/schema.js +93 -0
- package/dist/core/format/src/kinds/runtime/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/runtime/kind.js +13 -0
- package/dist/core/format/src/kinds/runtime/schema.d.ts +10 -0
- package/dist/core/format/src/kinds/runtime/schema.js +12 -0
- package/dist/core/format/src/kinds/skill/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/skill/kind.js +10 -0
- package/dist/core/format/src/kinds/skill/schema.d.ts +17 -0
- package/dist/core/format/src/kinds/skill/schema.js +17 -0
- package/dist/core/format/src/kinds/skill/scripts-folder.d.ts +27 -0
- package/dist/core/format/src/kinds/skill/scripts-folder.js +37 -0
- package/dist/core/format/src/kinds/workflow/kind.d.ts +8 -0
- package/dist/core/format/src/kinds/workflow/kind.js +14 -0
- package/dist/core/format/src/kinds/workflow/schema.d.ts +162 -0
- package/dist/core/format/src/kinds/workflow/schema.js +106 -0
- package/dist/core/format/src/kinds/workflow-test/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/workflow-test/kind.js +14 -0
- package/dist/core/format/src/kinds/workflow-test/schema.d.ts +67 -0
- package/dist/core/format/src/kinds/workflow-test/schema.js +59 -0
- package/dist/core/format/src/kinds/workspace/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/workspace/kind.js +10 -0
- package/dist/core/format/src/kinds/workspace/schema.d.ts +72 -0
- package/dist/core/format/src/kinds/workspace/schema.js +66 -0
- package/dist/core/format/src/parse-file.d.ts +69 -0
- package/dist/core/format/src/parse-file.js +105 -0
- package/dist/core/format/src/recording/format.d.ts +81 -0
- package/dist/core/format/src/recording/format.js +102 -0
- package/dist/core/format/src/recording/index.d.ts +1 -0
- package/dist/core/format/src/recording/index.js +3 -0
- package/dist/core/format/src/registry.d.ts +64 -0
- package/dist/core/format/src/registry.js +61 -0
- package/dist/core/format/src/reserved.d.ts +20 -0
- package/dist/core/format/src/reserved.js +30 -0
- package/dist/core/format/src/shared/fields.d.ts +37 -0
- package/dist/core/format/src/shared/fields.js +54 -0
- package/dist/core/format/src/shared/guard.d.ts +32 -0
- package/dist/core/format/src/shared/guard.js +16 -0
- package/dist/core/format/src/shared/key-in-value.d.ts +28 -0
- package/dist/core/format/src/shared/key-in-value.js +82 -0
- package/dist/core/format/src/shared/legacy-keys.d.ts +8 -0
- package/dist/core/format/src/shared/legacy-keys.js +17 -0
- package/dist/core/format/src/shared/program-start.d.ts +60 -0
- package/dist/core/format/src/shared/program-start.js +99 -0
- package/dist/core/format/src/shared/relative-path.d.ts +29 -0
- package/dist/core/format/src/shared/relative-path.js +50 -0
- package/dist/core/format/src/shared/secret-name.d.ts +24 -0
- package/dist/core/format/src/shared/secret-name.js +107 -0
- package/dist/core/format/src/source.d.ts +16 -0
- package/dist/core/format/src/source.js +73 -0
- package/dist/core/ports/src/agent-placement-store.d.ts +74 -0
- package/dist/core/ports/src/agent-placement-store.js +27 -0
- package/dist/core/ports/src/blob-store.d.ts +33 -0
- package/dist/core/ports/src/blob-store.js +2 -0
- package/dist/core/ports/src/cant-try-error.d.ts +35 -0
- package/dist/core/ports/src/cant-try-error.js +44 -0
- package/dist/core/ports/src/chat.d.ts +127 -0
- package/dist/core/ports/src/chat.js +1 -0
- package/dist/core/ports/src/clock.d.ts +7 -0
- package/dist/core/ports/src/clock.js +2 -0
- package/dist/core/ports/src/connection-settings-store.d.ts +57 -0
- package/dist/core/ports/src/connection-settings-store.js +2 -0
- package/dist/core/ports/src/connector-client.d.ts +259 -0
- package/dist/core/ports/src/connector-client.js +2 -0
- package/dist/core/ports/src/coordination.d.ts +84 -0
- package/dist/core/ports/src/coordination.js +2 -0
- package/dist/core/ports/src/definition-store.d.ts +208 -0
- package/dist/core/ports/src/definition-store.js +122 -0
- package/dist/core/ports/src/digest.d.ts +14 -0
- package/dist/core/ports/src/digest.js +2 -0
- package/dist/core/ports/src/folder-reader.d.ts +89 -0
- package/dist/core/ports/src/folder-reader.js +2 -0
- package/dist/core/ports/src/harness-bridge-server.d.ts +189 -0
- package/dist/core/ports/src/harness-bridge-server.js +37 -0
- package/dist/core/ports/src/harness.d.ts +250 -0
- package/dist/core/ports/src/harness.js +45 -0
- package/dist/core/ports/src/http-client.d.ts +27 -0
- package/dist/core/ports/src/http-client.js +2 -0
- package/dist/core/ports/src/id-generator.d.ts +14 -0
- package/dist/core/ports/src/id-generator.js +2 -0
- package/dist/core/ports/src/index.d.ts +37 -0
- package/dist/core/ports/src/index.js +36 -0
- package/dist/core/ports/src/integration.d.ts +178 -0
- package/dist/core/ports/src/integration.js +13 -0
- package/dist/core/ports/src/knowledge-provider.d.ts +65 -0
- package/dist/core/ports/src/knowledge-provider.js +2 -0
- package/dist/core/ports/src/llm-cache.d.ts +13 -0
- package/dist/core/ports/src/llm-cache.js +2 -0
- package/dist/core/ports/src/llm-provider.d.ts +184 -0
- package/dist/core/ports/src/llm-provider.js +136 -0
- package/dist/core/ports/src/model-price.d.ts +34 -0
- package/dist/core/ports/src/model-price.js +25 -0
- package/dist/core/ports/src/password-hasher.d.ts +47 -0
- package/dist/core/ports/src/password-hasher.js +2 -0
- package/dist/core/ports/src/plugin-folder-writer.d.ts +104 -0
- package/dist/core/ports/src/plugin-folder-writer.js +95 -0
- package/dist/core/ports/src/port-versions.d.ts +44 -0
- package/dist/core/ports/src/port-versions.js +74 -0
- package/dist/core/ports/src/program-probe.d.ts +46 -0
- package/dist/core/ports/src/program-probe.js +2 -0
- package/dist/core/ports/src/record-store.d.ts +62 -0
- package/dist/core/ports/src/record-store.js +38 -0
- package/dist/core/ports/src/resource-probe.d.ts +59 -0
- package/dist/core/ports/src/resource-probe.js +2 -0
- package/dist/core/ports/src/run-executor.d.ts +302 -0
- package/dist/core/ports/src/run-executor.js +2 -0
- package/dist/core/ports/src/run-failure-error.d.ts +49 -0
- package/dist/core/ports/src/run-failure-error.js +47 -0
- package/dist/core/ports/src/run-store.d.ts +194 -0
- package/dist/core/ports/src/run-store.js +131 -0
- package/dist/core/ports/src/sandbox.d.ts +247 -0
- package/dist/core/ports/src/sandbox.js +34 -0
- package/dist/core/ports/src/scheduler.d.ts +85 -0
- package/dist/core/ports/src/scheduler.js +2 -0
- package/dist/core/ports/src/secrets.d.ts +128 -0
- package/dist/core/ports/src/secrets.js +144 -0
- package/dist/core/ports/src/token-store.d.ts +19 -0
- package/dist/core/ports/src/token-store.js +2 -0
- package/dist/core/ports/src/tool-approval-store.d.ts +211 -0
- package/dist/core/ports/src/tool-approval-store.js +57 -0
- package/dist/core/ports/src/trust-store.d.ts +72 -0
- package/dist/core/ports/src/trust-store.js +2 -0
- package/dist/core/ports/src/unfenced-run-consent-store.d.ts +43 -0
- package/dist/core/ports/src/unfenced-run-consent-store.js +2 -0
- package/dist/core/ports/src/vcs.d.ts +394 -0
- package/dist/core/ports/src/vcs.js +48 -0
- package/dist/core/schema-kit/src/builders.d.ts +50 -0
- package/dist/core/schema-kit/src/builders.js +72 -0
- package/dist/core/schema-kit/src/depth.d.ts +15 -0
- package/dist/core/schema-kit/src/depth.js +37 -0
- package/dist/core/schema-kit/src/index.d.ts +6 -0
- package/dist/core/schema-kit/src/index.js +6 -0
- package/dist/core/schema-kit/src/issue.d.ts +22 -0
- package/dist/core/schema-kit/src/issue.js +23 -0
- package/dist/core/schema-kit/src/json-schema.d.ts +23 -0
- package/dist/core/schema-kit/src/json-schema.js +22 -0
- package/dist/core/schema-kit/src/parse.d.ts +17 -0
- package/dist/core/schema-kit/src/parse.js +25 -0
- package/dist/core/schema-kit/src/schema.d.ts +12 -0
- package/dist/core/schema-kit/src/schema.js +1 -0
- package/dist/core/std/src/ascii-host.d.ts +18 -0
- package/dist/core/std/src/ascii-host.js +110 -0
- package/dist/core/std/src/assert.d.ts +39 -0
- package/dist/core/std/src/assert.js +59 -0
- package/dist/core/std/src/base64url.d.ts +23 -0
- package/dist/core/std/src/base64url.js +65 -0
- package/dist/core/std/src/canonical-json.d.ts +18 -0
- package/dist/core/std/src/canonical-json.js +56 -0
- package/dist/core/std/src/clock.d.ts +27 -0
- package/dist/core/std/src/clock.js +33 -0
- package/dist/core/std/src/constant-time.d.ts +16 -0
- package/dist/core/std/src/constant-time.js +26 -0
- package/dist/core/std/src/content-digest.d.ts +24 -0
- package/dist/core/std/src/content-digest.js +28 -0
- package/dist/core/std/src/deep-clone.d.ts +15 -0
- package/dist/core/std/src/deep-clone.js +59 -0
- package/dist/core/std/src/deep-equal.d.ts +23 -0
- package/dist/core/std/src/deep-equal.js +64 -0
- package/dist/core/std/src/emitter.d.ts +42 -0
- package/dist/core/std/src/emitter.js +74 -0
- package/dist/core/std/src/error-kind.d.ts +88 -0
- package/dist/core/std/src/error-kind.js +98 -0
- package/dist/core/std/src/hex.d.ts +10 -0
- package/dist/core/std/src/hex.js +16 -0
- package/dist/core/std/src/ids.d.ts +45 -0
- package/dist/core/std/src/ids.js +49 -0
- package/dist/core/std/src/index.d.ts +25 -0
- package/dist/core/std/src/index.js +26 -0
- package/dist/core/std/src/keyed-queue.d.ts +18 -0
- package/dist/core/std/src/keyed-queue.js +32 -0
- package/dist/core/std/src/line-diff.d.ts +83 -0
- package/dist/core/std/src/line-diff.js +179 -0
- package/dist/core/std/src/line-merge.d.ts +63 -0
- package/dist/core/std/src/line-merge.js +138 -0
- package/dist/core/std/src/plain-data.d.ts +32 -0
- package/dist/core/std/src/plain-data.js +57 -0
- package/dist/core/std/src/posix-path.d.ts +61 -0
- package/dist/core/std/src/posix-path.js +121 -0
- package/dist/core/std/src/result.d.ts +55 -0
- package/dist/core/std/src/result.js +52 -0
- package/dist/core/std/src/secret-scrubber.d.ts +54 -0
- package/dist/core/std/src/secret-scrubber.js +124 -0
- package/dist/core/std/src/secret-shape.d.ts +20 -0
- package/dist/core/std/src/secret-shape.js +53 -0
- package/dist/core/std/src/stop-signal.d.ts +44 -0
- package/dist/core/std/src/stop-signal.js +77 -0
- package/dist/core/std/src/text.d.ts +28 -0
- package/dist/core/std/src/text.js +54 -0
- package/dist/core/std/src/utf8.d.ts +23 -0
- package/dist/core/std/src/utf8.js +110 -0
- package/dist/core/std/src/version.d.ts +48 -0
- package/dist/core/std/src/version.js +103 -0
- package/dist/core/yaml/src/depth.d.ts +14 -0
- package/dist/core/yaml/src/depth.js +140 -0
- package/dist/core/yaml/src/edit-data.d.ts +47 -0
- package/dist/core/yaml/src/edit-data.js +286 -0
- package/dist/core/yaml/src/edit-text.d.ts +92 -0
- package/dist/core/yaml/src/edit-text.js +267 -0
- package/dist/core/yaml/src/edit.d.ts +47 -0
- package/dist/core/yaml/src/edit.js +198 -0
- package/dist/core/yaml/src/index.d.ts +5 -0
- package/dist/core/yaml/src/index.js +4 -0
- package/dist/core/yaml/src/problem.d.ts +20 -0
- package/dist/core/yaml/src/problem.js +1 -0
- package/dist/core/yaml/src/read.d.ts +47 -0
- package/dist/core/yaml/src/read.js +130 -0
- package/dist/core/yaml/src/splice-node.d.ts +47 -0
- package/dist/core/yaml/src/splice-node.js +333 -0
- package/dist/core/yaml/src/splice.d.ts +13 -0
- package/dist/core/yaml/src/splice.js +174 -0
- package/dist/core/yaml/src/unsupported.d.ts +26 -0
- package/dist/core/yaml/src/unsupported.js +70 -0
- package/dist/core/yaml/src/write.d.ts +35 -0
- package/dist/core/yaml/src/write.js +44 -0
- package/dist/testing/integration/src/canaries.d.ts +14 -0
- package/dist/testing/integration/src/canaries.js +17 -0
- package/dist/testing/integration/src/checks.d.ts +37 -0
- package/dist/testing/integration/src/checks.js +195 -0
- package/dist/testing/integration/src/describe.d.ts +35 -0
- package/dist/testing/integration/src/describe.js +74 -0
- package/dist/testing/integration/src/failure.d.ts +6 -0
- package/dist/testing/integration/src/failure.js +8 -0
- package/dist/testing/integration/src/fake-wait.d.ts +18 -0
- package/dist/testing/integration/src/fake-wait.js +21 -0
- package/dist/testing/integration/src/index.d.ts +10 -0
- package/dist/testing/integration/src/index.js +11 -0
- package/dist/testing/integration/src/load.d.ts +14 -0
- package/dist/testing/integration/src/load.js +45 -0
- package/dist/testing/integration/src/plugin-folder.d.ts +23 -0
- package/dist/testing/integration/src/plugin-folder.js +59 -0
- package/dist/testing/integration/src/plugin.d.ts +32 -0
- package/dist/testing/integration/src/plugin.js +57 -0
- package/dist/testing/integration/src/recording.d.ts +84 -0
- package/dist/testing/integration/src/recording.js +164 -0
- package/dist/testing/integration/src/run.d.ts +60 -0
- package/dist/testing/integration/src/run.js +81 -0
- package/dist/testing/integration/src/source-scan.d.ts +16 -0
- package/dist/testing/integration/src/source-scan.js +40 -0
- package/package.json +34 -3
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { describeObject, isPlainObject, keyPath } from "./plain-data.js";
|
|
2
|
+
/**
|
|
3
|
+
* Writes plain data as JSON in one canonical form, so equal data always
|
|
4
|
+
* gives the same text and can be hashed: object keys sorted by code unit,
|
|
5
|
+
* arrays kept in order, no spaces. As with `JSON.stringify`, an object key
|
|
6
|
+
* whose value is `undefined` is left out.
|
|
7
|
+
*
|
|
8
|
+
* It throws instead of writing something lossy: a number that isn't finite,
|
|
9
|
+
* `undefined` in an array, or a value JSON can't hold, such as a `Map`, a
|
|
10
|
+
* `Date`, a function or a bigint.
|
|
11
|
+
*
|
|
12
|
+
* @param value - plain data: objects, arrays, strings, finite numbers, booleans and `null`
|
|
13
|
+
* @returns the canonical JSON text
|
|
14
|
+
* @throws when the data isn't plain JSON data, saying where
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* canonicalJson({ b: [2, 1], a: "x" }); // '{"a":"x","b":[2,1]}'
|
|
18
|
+
*/
|
|
19
|
+
export function canonicalJson(value) {
|
|
20
|
+
return write(value, "value");
|
|
21
|
+
}
|
|
22
|
+
function write(value, path) {
|
|
23
|
+
if (value === null || typeof value === "boolean" || typeof value === "string") {
|
|
24
|
+
return JSON.stringify(value);
|
|
25
|
+
}
|
|
26
|
+
if (typeof value === "number") {
|
|
27
|
+
if (!Number.isFinite(value)) {
|
|
28
|
+
throw new TypeError(`Can't write ${path} as JSON: ${value} isn't a finite number.`);
|
|
29
|
+
}
|
|
30
|
+
return JSON.stringify(value);
|
|
31
|
+
}
|
|
32
|
+
if (Array.isArray(value)) {
|
|
33
|
+
const items = value.map((item, index) => {
|
|
34
|
+
if (item === undefined) {
|
|
35
|
+
throw new TypeError(`Can't write ${path}[${index}] as JSON: it is undefined.`);
|
|
36
|
+
}
|
|
37
|
+
return write(item, `${path}[${index}]`);
|
|
38
|
+
});
|
|
39
|
+
return `[${items.join(",")}]`;
|
|
40
|
+
}
|
|
41
|
+
if (isPlainObject(value)) {
|
|
42
|
+
const keys = Object.keys(value)
|
|
43
|
+
.filter((key) => value[key] !== undefined)
|
|
44
|
+
.sort(byCodeUnit);
|
|
45
|
+
const entries = keys.map((key) => `${JSON.stringify(key)}:${write(value[key], keyPath(path, key))}`);
|
|
46
|
+
return `{${entries.join(",")}}`;
|
|
47
|
+
}
|
|
48
|
+
const kind = typeof value === "object" ? describeObject(value) : `a ${typeof value}`;
|
|
49
|
+
throw new TypeError(`Can't write ${path} as JSON: it is ${kind}.`);
|
|
50
|
+
}
|
|
51
|
+
function byCodeUnit(left, right) {
|
|
52
|
+
if (left === right) {
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
55
|
+
return left < right ? -1 : 1;
|
|
56
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tells the current time. Code that needs the time takes a `Clock`, so tests
|
|
3
|
+
* can pass a fixed one and get the same output on every run.
|
|
4
|
+
*/
|
|
5
|
+
export interface Clock {
|
|
6
|
+
/** The current time. */
|
|
7
|
+
now(): Date;
|
|
8
|
+
}
|
|
9
|
+
/** The real clock: the time of the machine it runs on. */
|
|
10
|
+
export declare const systemClock: Clock;
|
|
11
|
+
/** The start of `fixedClock` when no start is given: 2026-01-01T00:00:00Z. */
|
|
12
|
+
export declare const fixedClockStart: number;
|
|
13
|
+
/**
|
|
14
|
+
* A clock for tests. The first call returns `start`, and every later call
|
|
15
|
+
* returns a time `stepMs` later than the call before.
|
|
16
|
+
*
|
|
17
|
+
* @param start - the first time, in milliseconds since 1970 (default 2026-01-01T00:00:00Z)
|
|
18
|
+
* @param stepMs - how far the clock moves on per call, zero or more (default 1000)
|
|
19
|
+
* @returns a new clock with its own position
|
|
20
|
+
* @throws AssertionError when `start` or `stepMs` isn't a valid number of milliseconds
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const clock = fixedClock();
|
|
24
|
+
* clock.now().toISOString(); // "2026-01-01T00:00:00.000Z"
|
|
25
|
+
* clock.now().toISOString(); // "2026-01-01T00:00:01.000Z"
|
|
26
|
+
*/
|
|
27
|
+
export declare function fixedClock(start?: number, stepMs?: number): Clock;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { assert } from "./assert.js";
|
|
2
|
+
/** The real clock: the time of the machine it runs on. */
|
|
3
|
+
export const systemClock = {
|
|
4
|
+
now: () => new Date(),
|
|
5
|
+
};
|
|
6
|
+
/** The start of `fixedClock` when no start is given: 2026-01-01T00:00:00Z. */
|
|
7
|
+
export const fixedClockStart = Date.UTC(2026, 0, 1);
|
|
8
|
+
/**
|
|
9
|
+
* A clock for tests. The first call returns `start`, and every later call
|
|
10
|
+
* returns a time `stepMs` later than the call before.
|
|
11
|
+
*
|
|
12
|
+
* @param start - the first time, in milliseconds since 1970 (default 2026-01-01T00:00:00Z)
|
|
13
|
+
* @param stepMs - how far the clock moves on per call, zero or more (default 1000)
|
|
14
|
+
* @returns a new clock with its own position
|
|
15
|
+
* @throws AssertionError when `start` or `stepMs` isn't a valid number of milliseconds
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const clock = fixedClock();
|
|
19
|
+
* clock.now().toISOString(); // "2026-01-01T00:00:00.000Z"
|
|
20
|
+
* clock.now().toISOString(); // "2026-01-01T00:00:01.000Z"
|
|
21
|
+
*/
|
|
22
|
+
export function fixedClock(start = fixedClockStart, stepMs = 1000) {
|
|
23
|
+
assert(Number.isFinite(start), `fixedClock needs a finite start time, got ${start}.`);
|
|
24
|
+
assert(Number.isFinite(stepMs) && stepMs >= 0, `fixedClock needs a step of zero or more milliseconds, got ${stepMs}.`);
|
|
25
|
+
let current = start;
|
|
26
|
+
return {
|
|
27
|
+
now() {
|
|
28
|
+
const time = new Date(current);
|
|
29
|
+
current += stepMs;
|
|
30
|
+
return time;
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compares two byte arrays in time that depends only on their length, never
|
|
3
|
+
* on where they first differ. Use it to check password hashes and tokens, so
|
|
4
|
+
* an attacker can't learn a secret from how long a comparison takes.
|
|
5
|
+
*
|
|
6
|
+
* Arrays of different lengths are unequal at once: lengths aren't secret
|
|
7
|
+
* here, because hashes and tokens have a fixed length.
|
|
8
|
+
*
|
|
9
|
+
* @param first - the first bytes
|
|
10
|
+
* @param second - the second bytes
|
|
11
|
+
* @returns true when both hold the same bytes
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* constantTimeEqual(storedHash, await hasher.hash(password, salt)); // true or false
|
|
15
|
+
*/
|
|
16
|
+
export declare function constantTimeEqual(first: Uint8Array, second: Uint8Array): boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compares two byte arrays in time that depends only on their length, never
|
|
3
|
+
* on where they first differ. Use it to check password hashes and tokens, so
|
|
4
|
+
* an attacker can't learn a secret from how long a comparison takes.
|
|
5
|
+
*
|
|
6
|
+
* Arrays of different lengths are unequal at once: lengths aren't secret
|
|
7
|
+
* here, because hashes and tokens have a fixed length.
|
|
8
|
+
*
|
|
9
|
+
* @param first - the first bytes
|
|
10
|
+
* @param second - the second bytes
|
|
11
|
+
* @returns true when both hold the same bytes
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* constantTimeEqual(storedHash, await hasher.hash(password, salt)); // true or false
|
|
15
|
+
*/
|
|
16
|
+
export function constantTimeEqual(first, second) {
|
|
17
|
+
if (first.length !== second.length) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
let difference = 0;
|
|
21
|
+
for (let index = 0; index < first.length; index++) {
|
|
22
|
+
// No early exit: every byte is compared, and differences pile up in one number.
|
|
23
|
+
difference |= (first[index] ?? 0) ^ (second[index] ?? 0);
|
|
24
|
+
}
|
|
25
|
+
return difference === 0;
|
|
26
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anything that hashes bytes with SHA-256, such as the `Digest` port. The
|
|
3
|
+
* core has no hash code of its own, so the caller passes one in.
|
|
4
|
+
*/
|
|
5
|
+
export interface Sha256 {
|
|
6
|
+
/** The 32-byte SHA-256 of the bytes. */
|
|
7
|
+
sha256(data: Uint8Array): Promise<Uint8Array>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The digest of a workspace file's text, as `DefinitionStore.write` expects
|
|
11
|
+
* it: `sha256:` and the 64 lowercase hex characters of the SHA-256 of the
|
|
12
|
+
* text's UTF-8 bytes.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* await contentDigest("hello", digest);
|
|
16
|
+
* // "sha256:2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
|
|
17
|
+
*/
|
|
18
|
+
export declare function contentDigest(content: string, digest: Sha256): Promise<`sha256:${string}`>;
|
|
19
|
+
/**
|
|
20
|
+
* Whether a file's text, or `null` when there is no file, is what a caller
|
|
21
|
+
* expects: the {@link contentDigest} of the text it last read, or `"absent"`
|
|
22
|
+
* for no file. Every store calls this before a write with `expected`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function matchesExpected(current: string | null, expected: string, digest: Sha256): Promise<boolean>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// The digest the `DefinitionStore` port's write-if-unchanged check compares.
|
|
2
|
+
// It lives here, not in `@halonicjs/ports`, because the ports package uses no
|
|
3
|
+
// other package and the core has no `TextEncoder`.
|
|
4
|
+
import { bytesToHex } from "./hex.js";
|
|
5
|
+
import { encodeUtf8 } from "./utf8.js";
|
|
6
|
+
/**
|
|
7
|
+
* The digest of a workspace file's text, as `DefinitionStore.write` expects
|
|
8
|
+
* it: `sha256:` and the 64 lowercase hex characters of the SHA-256 of the
|
|
9
|
+
* text's UTF-8 bytes.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* await contentDigest("hello", digest);
|
|
13
|
+
* // "sha256:2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
|
|
14
|
+
*/
|
|
15
|
+
export async function contentDigest(content, digest) {
|
|
16
|
+
return `sha256:${bytesToHex(await digest.sha256(encodeUtf8(content)))}`;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Whether a file's text, or `null` when there is no file, is what a caller
|
|
20
|
+
* expects: the {@link contentDigest} of the text it last read, or `"absent"`
|
|
21
|
+
* for no file. Every store calls this before a write with `expected`.
|
|
22
|
+
*/
|
|
23
|
+
export async function matchesExpected(current, expected, digest) {
|
|
24
|
+
if (expected === "absent" || current === null) {
|
|
25
|
+
return expected === "absent" && current === null;
|
|
26
|
+
}
|
|
27
|
+
return (await contentDigest(current, digest)) === expected;
|
|
28
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copies plain data all the way down: arrays, plain objects, dates and
|
|
3
|
+
* primitives. A value that appears twice, or contains itself, is copied once
|
|
4
|
+
* and shared the same way in the copy, as `structuredClone` does. The core
|
|
5
|
+
* has no `structuredClone`, so this replaces it for run events, records and
|
|
6
|
+
* workflow context.
|
|
7
|
+
*
|
|
8
|
+
* @param value - the data to copy
|
|
9
|
+
* @returns a copy that shares no objects with `value`
|
|
10
|
+
* @throws TypeError for anything that isn't plain data, such as a function, a `Map` or a class instance
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const copy = deepClone({ steps: [{ id: "a" }] });
|
|
14
|
+
*/
|
|
15
|
+
export declare function deepClone<T>(value: T): T;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { describeObject, isPlainObject, keyPath } from "./plain-data.js";
|
|
2
|
+
/**
|
|
3
|
+
* Copies plain data all the way down: arrays, plain objects, dates and
|
|
4
|
+
* primitives. A value that appears twice, or contains itself, is copied once
|
|
5
|
+
* and shared the same way in the copy, as `structuredClone` does. The core
|
|
6
|
+
* has no `structuredClone`, so this replaces it for run events, records and
|
|
7
|
+
* workflow context.
|
|
8
|
+
*
|
|
9
|
+
* @param value - the data to copy
|
|
10
|
+
* @returns a copy that shares no objects with `value`
|
|
11
|
+
* @throws TypeError for anything that isn't plain data, such as a function, a `Map` or a class instance
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const copy = deepClone({ steps: [{ id: "a" }] });
|
|
15
|
+
*/
|
|
16
|
+
export function deepClone(value) {
|
|
17
|
+
return cloneValue(value, new Map(), "value");
|
|
18
|
+
}
|
|
19
|
+
function cloneValue(value, copies, path) {
|
|
20
|
+
if (typeof value === "function" || typeof value === "symbol") {
|
|
21
|
+
throw new TypeError(`deepClone can't copy the ${typeof value} at ${path}.`);
|
|
22
|
+
}
|
|
23
|
+
if (typeof value !== "object" || value === null) {
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
const existing = copies.get(value);
|
|
27
|
+
if (existing !== undefined) {
|
|
28
|
+
return existing;
|
|
29
|
+
}
|
|
30
|
+
if (value instanceof Date) {
|
|
31
|
+
const copy = new Date(value.getTime());
|
|
32
|
+
copies.set(value, copy);
|
|
33
|
+
return copy;
|
|
34
|
+
}
|
|
35
|
+
if (Array.isArray(value)) {
|
|
36
|
+
const copy = [];
|
|
37
|
+
copies.set(value, copy);
|
|
38
|
+
for (let index = 0; index < value.length; index++) {
|
|
39
|
+
copy.push(cloneValue(value[index], copies, `${path}[${index}]`));
|
|
40
|
+
}
|
|
41
|
+
return copy;
|
|
42
|
+
}
|
|
43
|
+
if (isPlainObject(value)) {
|
|
44
|
+
const copy = Object.getPrototypeOf(value) === null ? Object.create(null) : {};
|
|
45
|
+
copies.set(value, copy);
|
|
46
|
+
for (const key of Object.keys(value)) {
|
|
47
|
+
// defineProperty, not assignment: a "__proto__" key from JSON.parse
|
|
48
|
+
// stays a plain key instead of changing the copy's prototype.
|
|
49
|
+
Object.defineProperty(copy, key, {
|
|
50
|
+
value: cloneValue(value[key], copies, keyPath(path, key)),
|
|
51
|
+
enumerable: true,
|
|
52
|
+
writable: true,
|
|
53
|
+
configurable: true,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return copy;
|
|
57
|
+
}
|
|
58
|
+
throw new TypeError(`deepClone copies plain data only, but ${path} is ${describeObject(value)}.`);
|
|
59
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compares two values by content: arrays item by item, plain objects key by
|
|
3
|
+
* key in any order, and dates by time. Numbers compare with `===`, except
|
|
4
|
+
* that `NaN` equals `NaN`. Any other object (a `Map`, a class instance)
|
|
5
|
+
* equals only itself.
|
|
6
|
+
*
|
|
7
|
+
* Unlike comparing `JSON.stringify` output, key order doesn't matter, and a
|
|
8
|
+
* key whose value is `undefined` is still a key: `{ a: undefined }` doesn't
|
|
9
|
+
* equal `{}`.
|
|
10
|
+
*
|
|
11
|
+
* Cyclic data isn't supported: comparing it throws a `RangeError`. JSON can't
|
|
12
|
+
* express cycles, and `@halonicjs/yaml` rejects aliases that refer to
|
|
13
|
+
* themselves. `deepClone` keeps cycles because it mirrors `structuredClone`,
|
|
14
|
+
* while comparing a cycle would need extra bookkeeping on every call.
|
|
15
|
+
*
|
|
16
|
+
* @param first - the first value
|
|
17
|
+
* @param second - the second value
|
|
18
|
+
* @returns true when both have the same content
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* deepEqual({ a: [1, 2], b: "x" }, { b: "x", a: [1, 2] }); // true
|
|
22
|
+
*/
|
|
23
|
+
export declare function deepEqual(first: unknown, second: unknown): boolean;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { isPlainObject } from "./plain-data.js";
|
|
2
|
+
/**
|
|
3
|
+
* Compares two values by content: arrays item by item, plain objects key by
|
|
4
|
+
* key in any order, and dates by time. Numbers compare with `===`, except
|
|
5
|
+
* that `NaN` equals `NaN`. Any other object (a `Map`, a class instance)
|
|
6
|
+
* equals only itself.
|
|
7
|
+
*
|
|
8
|
+
* Unlike comparing `JSON.stringify` output, key order doesn't matter, and a
|
|
9
|
+
* key whose value is `undefined` is still a key: `{ a: undefined }` doesn't
|
|
10
|
+
* equal `{}`.
|
|
11
|
+
*
|
|
12
|
+
* Cyclic data isn't supported: comparing it throws a `RangeError`. JSON can't
|
|
13
|
+
* express cycles, and `@halonicjs/yaml` rejects aliases that refer to
|
|
14
|
+
* themselves. `deepClone` keeps cycles because it mirrors `structuredClone`,
|
|
15
|
+
* while comparing a cycle would need extra bookkeeping on every call.
|
|
16
|
+
*
|
|
17
|
+
* @param first - the first value
|
|
18
|
+
* @param second - the second value
|
|
19
|
+
* @returns true when both have the same content
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* deepEqual({ a: [1, 2], b: "x" }, { b: "x", a: [1, 2] }); // true
|
|
23
|
+
*/
|
|
24
|
+
export function deepEqual(first, second) {
|
|
25
|
+
if (first === second) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
if (typeof first === "number" && typeof second === "number") {
|
|
29
|
+
return Number.isNaN(first) && Number.isNaN(second);
|
|
30
|
+
}
|
|
31
|
+
if (Array.isArray(first) && Array.isArray(second)) {
|
|
32
|
+
return arraysEqual(first, second);
|
|
33
|
+
}
|
|
34
|
+
if (first instanceof Date && second instanceof Date) {
|
|
35
|
+
return Object.is(first.getTime(), second.getTime());
|
|
36
|
+
}
|
|
37
|
+
if (isPlainObject(first) && isPlainObject(second)) {
|
|
38
|
+
return objectsEqual(first, second);
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
function arraysEqual(first, second) {
|
|
43
|
+
if (first.length !== second.length) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
for (let index = 0; index < first.length; index++) {
|
|
47
|
+
if (!deepEqual(first[index], second[index])) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
function objectsEqual(first, second) {
|
|
54
|
+
const firstKeys = Object.keys(first);
|
|
55
|
+
if (firstKeys.length !== Object.keys(second).length) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
for (const key of firstKeys) {
|
|
59
|
+
if (!Object.hasOwn(second, key) || !deepEqual(first[key], second[key])) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** A function that receives one kind of event. */
|
|
2
|
+
export type Listener<Payload> = (payload: Payload) => void;
|
|
3
|
+
/**
|
|
4
|
+
* A small typed event emitter. `Events` maps each event name to the type of
|
|
5
|
+
* its payload, so `emit` and `on` check both.
|
|
6
|
+
*
|
|
7
|
+
* Listeners run in the order they were added. A listener added or removed
|
|
8
|
+
* while an event is being sent takes effect from the next event. If a
|
|
9
|
+
* listener throws, the others still run, and `emit` then throws the error
|
|
10
|
+
* (or an `AggregateError` with all of them).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const changes = new Emitter<{ saved: { path: string }; closed: undefined }>();
|
|
14
|
+
* const stop = changes.on("saved", ({ path }) => console.log(path));
|
|
15
|
+
* changes.emit("saved", { path: "hubs/support/hub.yaml" });
|
|
16
|
+
* stop();
|
|
17
|
+
*/
|
|
18
|
+
export declare class Emitter<Events extends Record<string, unknown>> {
|
|
19
|
+
private readonly listeners;
|
|
20
|
+
/**
|
|
21
|
+
* Adds a listener for one event.
|
|
22
|
+
*
|
|
23
|
+
* @param name - the event to listen to
|
|
24
|
+
* @param listener - called with each payload
|
|
25
|
+
* @returns a function that removes the listener again; calling it twice is harmless
|
|
26
|
+
*/
|
|
27
|
+
on<Name extends keyof Events>(name: Name, listener: Listener<Events[Name]>): () => void;
|
|
28
|
+
/**
|
|
29
|
+
* Sends an event to every listener for it.
|
|
30
|
+
*
|
|
31
|
+
* @param name - the event
|
|
32
|
+
* @param payload - what the listeners receive
|
|
33
|
+
* @throws the error of the one listener that threw, or an `AggregateError` when several did
|
|
34
|
+
*/
|
|
35
|
+
emit<Name extends keyof Events>(name: Name, payload: Events[Name]): void;
|
|
36
|
+
/**
|
|
37
|
+
* How many listeners an event has.
|
|
38
|
+
*
|
|
39
|
+
* @param name - the event
|
|
40
|
+
*/
|
|
41
|
+
listenerCount(name: keyof Events): number;
|
|
42
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small typed event emitter. `Events` maps each event name to the type of
|
|
3
|
+
* its payload, so `emit` and `on` check both.
|
|
4
|
+
*
|
|
5
|
+
* Listeners run in the order they were added. A listener added or removed
|
|
6
|
+
* while an event is being sent takes effect from the next event. If a
|
|
7
|
+
* listener throws, the others still run, and `emit` then throws the error
|
|
8
|
+
* (or an `AggregateError` with all of them).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const changes = new Emitter<{ saved: { path: string }; closed: undefined }>();
|
|
12
|
+
* const stop = changes.on("saved", ({ path }) => console.log(path));
|
|
13
|
+
* changes.emit("saved", { path: "hubs/support/hub.yaml" });
|
|
14
|
+
* stop();
|
|
15
|
+
*/
|
|
16
|
+
export class Emitter {
|
|
17
|
+
listeners = new Map();
|
|
18
|
+
/**
|
|
19
|
+
* Adds a listener for one event.
|
|
20
|
+
*
|
|
21
|
+
* @param name - the event to listen to
|
|
22
|
+
* @param listener - called with each payload
|
|
23
|
+
* @returns a function that removes the listener again; calling it twice is harmless
|
|
24
|
+
*/
|
|
25
|
+
on(name, listener) {
|
|
26
|
+
let forName = this.listeners.get(name);
|
|
27
|
+
if (forName === undefined) {
|
|
28
|
+
forName = new Set();
|
|
29
|
+
this.listeners.set(name, forName);
|
|
30
|
+
}
|
|
31
|
+
// Wrapped, so adding the same function twice gives two independent listeners.
|
|
32
|
+
const entry = (payload) => listener(payload);
|
|
33
|
+
forName.add(entry);
|
|
34
|
+
return () => {
|
|
35
|
+
forName.delete(entry);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Sends an event to every listener for it.
|
|
40
|
+
*
|
|
41
|
+
* @param name - the event
|
|
42
|
+
* @param payload - what the listeners receive
|
|
43
|
+
* @throws the error of the one listener that threw, or an `AggregateError` when several did
|
|
44
|
+
*/
|
|
45
|
+
emit(name, payload) {
|
|
46
|
+
const forName = this.listeners.get(name);
|
|
47
|
+
if (forName === undefined) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const errors = [];
|
|
51
|
+
for (const listener of [...forName]) {
|
|
52
|
+
try {
|
|
53
|
+
listener(payload);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
errors.push(error);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (errors.length === 1) {
|
|
60
|
+
throw errors[0];
|
|
61
|
+
}
|
|
62
|
+
if (errors.length > 1) {
|
|
63
|
+
throw new AggregateError(errors, `${errors.length} listeners for "${String(name)}" failed.`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* How many listeners an event has.
|
|
68
|
+
*
|
|
69
|
+
* @param name - the event
|
|
70
|
+
*/
|
|
71
|
+
listenerCount(name) {
|
|
72
|
+
return this.listeners.get(name)?.size ?? 0;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every kind of error a surface (HTTP, CLI, Studio, MCP) can respond to, in a
|
|
3
|
+
* fixed order for exhaustive tests and docs. Each surface turns a kind into
|
|
4
|
+
* its response in one `switch` that ends in
|
|
5
|
+
* `assertNever(kind, "error kind")`, so a new kind fails the typecheck until
|
|
6
|
+
* every surface handles it.
|
|
7
|
+
*
|
|
8
|
+
* - `invalid_input`: the request or file is wrong; the caller fixes the input.
|
|
9
|
+
* - `not_found`: the thing asked for doesn't exist.
|
|
10
|
+
* - `conflict`: it exists, but its state doesn't allow this now: it already
|
|
11
|
+
* exists, someone else changed it first, or another step must come first.
|
|
12
|
+
* - `unauthenticated`: we don't know who is asking, or their sign-in expired.
|
|
13
|
+
* - `denied`: we know who is asking, but a rule says no.
|
|
14
|
+
* - `limit_reached`: a rate limit, quota or spend budget is used up.
|
|
15
|
+
* - `unavailable`: something we depend on is down or timed out; a retry may work.
|
|
16
|
+
* - `internal`: a bug on our side. Anything without a kind is `internal`.
|
|
17
|
+
*/
|
|
18
|
+
export declare const errorKinds: readonly ["invalid_input", "not_found", "conflict", "unauthenticated", "denied", "limit_reached", "unavailable", "internal"];
|
|
19
|
+
/** One of {@link errorKinds}. */
|
|
20
|
+
export type ErrorKind = (typeof errorKinds)[number];
|
|
21
|
+
/**
|
|
22
|
+
* True when `value` is one of the error kinds. Use it to decode a kind that
|
|
23
|
+
* came over the wire, such as the `kind` in an HTTP error body.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* isErrorKind("not_found"); // true
|
|
27
|
+
* isErrorKind("not-found"); // false
|
|
28
|
+
*/
|
|
29
|
+
export declare function isErrorKind(value: unknown): value is ErrorKind;
|
|
30
|
+
/** What a {@link KindedError} can carry besides its kind and message. */
|
|
31
|
+
export type KindedErrorOptions = {
|
|
32
|
+
/**
|
|
33
|
+
* The one next step that fixes it, as a sentence on its own line, such as
|
|
34
|
+
* "Start Ollama, then run again." Leave it out when there is no step to
|
|
35
|
+
* suggest: surfaces then show no fix and never make one up.
|
|
36
|
+
*/
|
|
37
|
+
readonly fix?: string;
|
|
38
|
+
/** The error this one wraps, for the log. */
|
|
39
|
+
readonly cause?: unknown;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* An error with a kind, for code that fails in a way a person should hear
|
|
43
|
+
* about. Errors that already have their own class don't have to extend this
|
|
44
|
+
* one: a `kind` property is enough for {@link errorKindOf}.
|
|
45
|
+
*
|
|
46
|
+
* The message must be safe to show and to log: no secrets, tokens, internal
|
|
47
|
+
* paths or internal codes. Surfaces show a generic message for `internal`
|
|
48
|
+
* instead of this one, so don't rely on the text of an `internal` error
|
|
49
|
+
* reaching the user; put what helps there in the log. The same rule holds
|
|
50
|
+
* for the optional `fix`, which is kept apart from the message so a surface
|
|
51
|
+
* can show it on its own line or in its own JSON field.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* throw new KindedError("not_found", `There is no routine named "${name}".`);
|
|
55
|
+
* throw new KindedError("unavailable", "Halonic couldn't reach Ollama.", {
|
|
56
|
+
* fix: "Start Ollama, then run again.",
|
|
57
|
+
* });
|
|
58
|
+
*/
|
|
59
|
+
export declare class KindedError extends Error {
|
|
60
|
+
readonly name = "KindedError";
|
|
61
|
+
readonly kind: ErrorKind;
|
|
62
|
+
/** The one next step that fixes it; `undefined` when there is none to suggest. */
|
|
63
|
+
readonly fix: string | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* @param kind - how a surface should respond
|
|
66
|
+
* @param message - safe to show and to log
|
|
67
|
+
* @param options - `fix` is the next step, safe to show and to log; `cause`
|
|
68
|
+
* keeps the error this one wraps, for the log
|
|
69
|
+
*/
|
|
70
|
+
constructor(kind: ErrorKind, message: string, options?: KindedErrorOptions);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The kind of any thrown value, for the one function per surface that turns
|
|
74
|
+
* errors into responses. A value has a kind when it is an object with a
|
|
75
|
+
* valid `kind` string and a `message` string: a `KindedError`, an error class
|
|
76
|
+
* with a `kind` property, or the `{ kind, message }` shape an error takes over
|
|
77
|
+
* HTTP or IPC. Anything else is `internal`, including objects that only have
|
|
78
|
+
* a `kind`, such as events.
|
|
79
|
+
*
|
|
80
|
+
* It reads only the value itself, never its `cause`: code that wraps an error
|
|
81
|
+
* chooses the kind of the wrapper on purpose.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* errorKindOf(new KindedError("conflict", "The run changed.")); // "conflict"
|
|
85
|
+
* errorKindOf({ kind: "not_found", message: "No such hub." }); // "not_found"
|
|
86
|
+
* errorKindOf(new TypeError("x is undefined")); // "internal"
|
|
87
|
+
*/
|
|
88
|
+
export declare function errorKindOf(error: unknown): ErrorKind;
|