@halonicjs/testing 0.0.0-stage → 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 +40 -2
- 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 +35 -4
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { isPlainObject } from "./plain-data.js";
|
|
2
|
+
/** What a secret value is replaced with wherever a scrubber finds it. */
|
|
3
|
+
export const secretRemoved = "[secret removed]";
|
|
4
|
+
/**
|
|
5
|
+
* The forms one secret commonly takes in text: as it is, URL-encoded (with
|
|
6
|
+
* upper- and lowercase escapes), form-encoded, and JSON-escaped (with `/`
|
|
7
|
+
* as it is and as `\/`). Base64, reversed, split or otherwise transformed
|
|
8
|
+
* copies are not here: those can't be found by matching text.
|
|
9
|
+
*
|
|
10
|
+
* Not covered either: JSON that escapes non-ASCII as `\uXXXX` (Python's
|
|
11
|
+
* default `json.dumps`), form-encoding with lowercase escapes, and
|
|
12
|
+
* URL-encoding that mixes upper- and lowercase escapes (`%2f%2F`).
|
|
13
|
+
*
|
|
14
|
+
* The forms come in the order shown, which stays the same. They can
|
|
15
|
+
* repeat, for example when the value has nothing to encode. An empty value
|
|
16
|
+
* has no forms, because an empty match is everywhere.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* secretTextForms("a b"); // ["a b", "a%20b", "a%20b", "a+b", "a b", "a b"]
|
|
20
|
+
*/
|
|
21
|
+
export function secretTextForms(value) {
|
|
22
|
+
if (value === "")
|
|
23
|
+
return [];
|
|
24
|
+
// `encodeURIComponent` throws on a lone surrogate; the URL and form
|
|
25
|
+
// encoders of the web platform write it as U+FFFD, so do the same.
|
|
26
|
+
const urlEncoded = encodeURIComponent(value.toWellFormed());
|
|
27
|
+
const json = JSON.stringify(value).slice(1, -1);
|
|
28
|
+
return [
|
|
29
|
+
value,
|
|
30
|
+
urlEncoded,
|
|
31
|
+
urlEncoded.replace(/%[0-9A-F]{2}/g, (hex) => hex.toLowerCase()),
|
|
32
|
+
formEncoded(urlEncoded),
|
|
33
|
+
json,
|
|
34
|
+
json.replaceAll("/", "\\/"),
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The value as `application/x-www-form-urlencoded` writes it, as
|
|
39
|
+
* `URLSearchParams` does, built from its URL-encoded form: a space becomes
|
|
40
|
+
* `+`, and `!'()~`, which `encodeURIComponent` leaves alone, are escaped.
|
|
41
|
+
*/
|
|
42
|
+
function formEncoded(urlEncoded) {
|
|
43
|
+
return urlEncoded
|
|
44
|
+
.replaceAll("%20", "+")
|
|
45
|
+
.replace(/[!'()~]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Replaces every secret it has been told about with `[secret removed]`, in
|
|
49
|
+
* each form {@link secretTextForms} lists. It finds every copy of every form
|
|
50
|
+
* in the text as given, so copies that touch or overlap become one
|
|
51
|
+
* `[secret removed]` and no part of either secret is left, and a short
|
|
52
|
+
* secret is never found inside a marker the scrubber wrote itself.
|
|
53
|
+
*
|
|
54
|
+
* Every non-empty secret is matched, however short: a one-letter secret
|
|
55
|
+
* mangles the text, but leaking it would be worse. Scrub a whole text
|
|
56
|
+
* before splitting it into lines, so a secret that holds a line break is
|
|
57
|
+
* still found.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* const scrubber = new SecretScrubber();
|
|
61
|
+
* scrubber.remember(apiKey);
|
|
62
|
+
* scrubber.scrub(`GET /v1?key=${apiKey} failed`); // "GET /v1?key=[secret removed] failed"
|
|
63
|
+
*/
|
|
64
|
+
export class SecretScrubber {
|
|
65
|
+
#forms = new Set();
|
|
66
|
+
/** Adds a secret to scrub from now on. An empty value is ignored. */
|
|
67
|
+
remember(value) {
|
|
68
|
+
for (const form of secretTextForms(value))
|
|
69
|
+
this.#forms.add(form);
|
|
70
|
+
}
|
|
71
|
+
/** The text with every form of every remembered secret replaced. */
|
|
72
|
+
scrub(text) {
|
|
73
|
+
const hidden = this.#hiddenCharacters(text);
|
|
74
|
+
let scrubbed = "";
|
|
75
|
+
let at = 0;
|
|
76
|
+
while (at < text.length) {
|
|
77
|
+
if (!hidden[at]) {
|
|
78
|
+
scrubbed += text[at];
|
|
79
|
+
at += 1;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
scrubbed += secretRemoved;
|
|
83
|
+
while (at < text.length && hidden[at])
|
|
84
|
+
at += 1;
|
|
85
|
+
}
|
|
86
|
+
return scrubbed;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* A copy of JSON-shaped data with {@link scrub} applied to every string in
|
|
90
|
+
* it, object keys included, at any depth. Numbers, booleans, `null` and
|
|
91
|
+
* anything that isn't a string, an array or a plain object are kept as
|
|
92
|
+
* they are. The value given is not changed.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* scrubber.scrubValue({ headers: [`Bearer ${token}`] }); // { headers: ["Bearer [secret removed]"] }
|
|
96
|
+
*/
|
|
97
|
+
scrubValue(value) {
|
|
98
|
+
if (typeof value === "string")
|
|
99
|
+
return this.scrub(value);
|
|
100
|
+
if (Array.isArray(value))
|
|
101
|
+
return value.map((item) => this.scrubValue(item));
|
|
102
|
+
if (!isPlainObject(value))
|
|
103
|
+
return value;
|
|
104
|
+
const scrubbed = {};
|
|
105
|
+
for (const [key, item] of Object.entries(value)) {
|
|
106
|
+
scrubbed[this.scrub(key)] = this.scrubValue(item);
|
|
107
|
+
}
|
|
108
|
+
return scrubbed;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* One flag per UTF-16 code unit of the text, set where any copy of any
|
|
112
|
+
* form covers it. Copies of one form may overlap (`aa` in `aaa`), so the
|
|
113
|
+
* search moves on one code unit at a time, not past the whole copy.
|
|
114
|
+
*/
|
|
115
|
+
#hiddenCharacters(text) {
|
|
116
|
+
const hidden = new Uint8Array(text.length);
|
|
117
|
+
for (const form of this.#forms) {
|
|
118
|
+
for (let at = text.indexOf(form); at !== -1; at = text.indexOf(form, at + 1)) {
|
|
119
|
+
hidden.fill(1, at, at + form.length);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return hidden;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The kinds of secret `findSecretShape` spots. Only the kind leaves the
|
|
3
|
+
* check, never the text that matched, so a caller can't log or keep the key
|
|
4
|
+
* by accident.
|
|
5
|
+
*/
|
|
6
|
+
export type SecretShape = "ai-provider-key" | "google-client-secret" | "google-api-key" | "github-token" | "slack-token";
|
|
7
|
+
/**
|
|
8
|
+
* Finds text shaped like an API key or other secret, so Studio can hold a
|
|
9
|
+
* message before it is sent, saved or logged. The Assistant, Try it chats and
|
|
10
|
+
* the Inbox all ask this one check, so they spot the same formats. When the
|
|
11
|
+
* text holds more than one, the kind that comes first in the text wins.
|
|
12
|
+
*
|
|
13
|
+
* The answer is the kind only. When it finds something, never put the text
|
|
14
|
+
* in a log or an error report: the text holds the key.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* findSecretShape(`my key is sk-${"a".repeat(16)}`); // "ai-provider-key"
|
|
18
|
+
* findSecretShape("we use sk-learn for this"); // undefined
|
|
19
|
+
*/
|
|
20
|
+
export declare function findSecretShape(text: string): SecretShape | undefined;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Each pattern is a prefix at the start of a run of key characters (letters,
|
|
3
|
+
* digits, `-` and `_`), so `task-…` or `xGOCSPX-…` never match, followed by
|
|
4
|
+
* at least 16 more key characters, so words such as `sk-learn` or a prefix
|
|
5
|
+
* named in a sentence don't count either.
|
|
6
|
+
*
|
|
7
|
+
* The run after the prefix must also hold a digit or a capital letter.
|
|
8
|
+
* Lowercase slugs such as `sk-learn-tutorial-for-beginners` are long enough
|
|
9
|
+
* to pass the 16-character floor, but real keys are random mixed-case text
|
|
10
|
+
* and almost never lack both. A digit alone would miss about 1 in 140 Google
|
|
11
|
+
* client secrets.
|
|
12
|
+
*
|
|
13
|
+
* `sk-` covers OpenAI and Anthropic keys (`sk-proj-…`, `sk-ant-…`). `GOCSPX-`
|
|
14
|
+
* is a Google OAuth client secret, which Studio sends to the Google setup's
|
|
15
|
+
* secret field instead of the providers page.
|
|
16
|
+
*/
|
|
17
|
+
const notAfterKeyCharacter = "(?<![A-Za-z0-9_-])";
|
|
18
|
+
const keyBody = "(?=[a-z_-]*[A-Z0-9])[A-Za-z0-9_-]{16,}";
|
|
19
|
+
function keyPattern(prefix) {
|
|
20
|
+
return new RegExp(notAfterKeyCharacter + prefix + keyBody);
|
|
21
|
+
}
|
|
22
|
+
const patterns = [
|
|
23
|
+
["ai-provider-key", keyPattern("sk-")],
|
|
24
|
+
["google-client-secret", keyPattern("GOCSPX-")],
|
|
25
|
+
["google-api-key", keyPattern("AIza")],
|
|
26
|
+
["github-token", keyPattern("(?:ghp_|github_pat_)")],
|
|
27
|
+
["slack-token", keyPattern("xoxb-")],
|
|
28
|
+
];
|
|
29
|
+
/**
|
|
30
|
+
* Finds text shaped like an API key or other secret, so Studio can hold a
|
|
31
|
+
* message before it is sent, saved or logged. The Assistant, Try it chats and
|
|
32
|
+
* the Inbox all ask this one check, so they spot the same formats. When the
|
|
33
|
+
* text holds more than one, the kind that comes first in the text wins.
|
|
34
|
+
*
|
|
35
|
+
* The answer is the kind only. When it finds something, never put the text
|
|
36
|
+
* in a log or an error report: the text holds the key.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* findSecretShape(`my key is sk-${"a".repeat(16)}`); // "ai-provider-key"
|
|
40
|
+
* findSecretShape("we use sk-learn for this"); // undefined
|
|
41
|
+
*/
|
|
42
|
+
export function findSecretShape(text) {
|
|
43
|
+
let found;
|
|
44
|
+
let foundAt = Number.POSITIVE_INFINITY;
|
|
45
|
+
for (const [shape, pattern] of patterns) {
|
|
46
|
+
const match = pattern.exec(text);
|
|
47
|
+
if (match !== null && match.index < foundAt) {
|
|
48
|
+
found = shape;
|
|
49
|
+
foundAt = match.index;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return found;
|
|
53
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tells work that it should stop, and why. It does what an `AbortSignal`
|
|
3
|
+
* does for code that can't create one: core packages see the Web types but
|
|
4
|
+
* not their values, so they have no `AbortController`.
|
|
5
|
+
*/
|
|
6
|
+
export interface StopSignal {
|
|
7
|
+
/** Whether the work was told to stop. */
|
|
8
|
+
readonly stopped: boolean;
|
|
9
|
+
/** Why it was told to stop; `undefined` until then. */
|
|
10
|
+
readonly reason: Error | undefined;
|
|
11
|
+
/** @throws the reason, once the work was told to stop */
|
|
12
|
+
throwIfStopped(): void;
|
|
13
|
+
/**
|
|
14
|
+
* Calls `listener` once, when the work is told to stop, or soon after this
|
|
15
|
+
* returns when it already was. Returns a function that removes it; a
|
|
16
|
+
* listener removed during the stop, by an earlier listener, isn't called.
|
|
17
|
+
*
|
|
18
|
+
* A listener added after the stop runs outside any `stop` call, so if it
|
|
19
|
+
* throws, nothing catches the error: it becomes an unhandled rejection,
|
|
20
|
+
* which ends a Node process by default.
|
|
21
|
+
*/
|
|
22
|
+
onStop(listener: () => void): () => void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Gives out a {@link StopSignal} and tells it to stop.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* const source = new StopSource();
|
|
29
|
+
* void runHarness(source.signal);
|
|
30
|
+
* source.stop(new Error("The engine stopped."));
|
|
31
|
+
*/
|
|
32
|
+
export declare class StopSource {
|
|
33
|
+
#private;
|
|
34
|
+
readonly signal: StopSignal;
|
|
35
|
+
constructor();
|
|
36
|
+
/**
|
|
37
|
+
* Tells the signal to stop with `reason`, and each listener once. A second
|
|
38
|
+
* call changes nothing.
|
|
39
|
+
*
|
|
40
|
+
* @throws the error of the one listener that threw, or an `AggregateError`
|
|
41
|
+
* when several did; the other listeners still run
|
|
42
|
+
*/
|
|
43
|
+
stop(reason: Error): void;
|
|
44
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gives out a {@link StopSignal} and tells it to stop.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* const source = new StopSource();
|
|
6
|
+
* void runHarness(source.signal);
|
|
7
|
+
* source.stop(new Error("The engine stopped."));
|
|
8
|
+
*/
|
|
9
|
+
export class StopSource {
|
|
10
|
+
signal;
|
|
11
|
+
#reason;
|
|
12
|
+
#listeners = new Set();
|
|
13
|
+
constructor() {
|
|
14
|
+
const source = this;
|
|
15
|
+
this.signal = {
|
|
16
|
+
get stopped() {
|
|
17
|
+
return source.#reason !== undefined;
|
|
18
|
+
},
|
|
19
|
+
get reason() {
|
|
20
|
+
return source.#reason;
|
|
21
|
+
},
|
|
22
|
+
throwIfStopped() {
|
|
23
|
+
if (source.#reason !== undefined)
|
|
24
|
+
throw source.#reason;
|
|
25
|
+
},
|
|
26
|
+
onStop: (listener) => this.#onStop(listener),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Tells the signal to stop with `reason`, and each listener once. A second
|
|
31
|
+
* call changes nothing.
|
|
32
|
+
*
|
|
33
|
+
* @throws the error of the one listener that threw, or an `AggregateError`
|
|
34
|
+
* when several did; the other listeners still run
|
|
35
|
+
*/
|
|
36
|
+
stop(reason) {
|
|
37
|
+
if (this.#reason !== undefined)
|
|
38
|
+
return;
|
|
39
|
+
this.#reason = reason;
|
|
40
|
+
this.#callListeners();
|
|
41
|
+
}
|
|
42
|
+
#onStop(listener) {
|
|
43
|
+
// Wrapped, so adding the same function twice gives two independent listeners.
|
|
44
|
+
const entry = () => listener();
|
|
45
|
+
this.#listeners.add(entry);
|
|
46
|
+
if (this.#reason !== undefined) {
|
|
47
|
+
// Called later rather than now, so the caller has its remove function
|
|
48
|
+
// first. A listener that throws here is an unhandled rejection.
|
|
49
|
+
void Promise.resolve().then(() => this.#callListeners());
|
|
50
|
+
}
|
|
51
|
+
return () => {
|
|
52
|
+
this.#listeners.delete(entry);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** Calls and removes every listener, like `Emitter.emit` does with errors. */
|
|
56
|
+
#callListeners() {
|
|
57
|
+
const listeners = [...this.#listeners];
|
|
58
|
+
const errors = [];
|
|
59
|
+
for (const listener of listeners) {
|
|
60
|
+
// A listener that an earlier one removed is skipped, as `AbortSignal` does.
|
|
61
|
+
if (!this.#listeners.delete(listener))
|
|
62
|
+
continue;
|
|
63
|
+
try {
|
|
64
|
+
listener();
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
errors.push(error);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (errors.length === 1) {
|
|
71
|
+
throw errors[0];
|
|
72
|
+
}
|
|
73
|
+
if (errors.length > 1) {
|
|
74
|
+
throw new AggregateError(errors, `${errors.length} stop listeners failed.`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns a display name into a file-safe id: lowercase ASCII letters and digits
|
|
3
|
+
* joined by single hyphens. Spaces and underscores both become hyphens
|
|
4
|
+
* ("snake_case" becomes "snake-case"), and accents are dropped ("Café" becomes
|
|
5
|
+
* "cafe"), as in the old Studio. Hyphens at either end are dropped, so the id
|
|
6
|
+
* can't be read as a command-line flag ("_a_" becomes "a"). A name with nothing
|
|
7
|
+
* usable left ("___", "!!! - !!!") becomes "item".
|
|
8
|
+
*
|
|
9
|
+
* @param name - the name a person typed
|
|
10
|
+
* @returns the id
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* slugify("Weekly Report"); // "weekly-report"
|
|
14
|
+
* slugify("Café crème!"); // "cafe-creme"
|
|
15
|
+
*/
|
|
16
|
+
export declare function slugify(name: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Returns `base` when no existing name uses it, otherwise the first free
|
|
19
|
+
* `base-2`, `base-3` and so on.
|
|
20
|
+
*
|
|
21
|
+
* @param base - the name to start from, usually a slug
|
|
22
|
+
* @param taken - the names already in use
|
|
23
|
+
* @returns a name that isn't in `taken`
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* uniqueName("report", ["report", "report-2"]); // "report-3"
|
|
27
|
+
*/
|
|
28
|
+
export declare function uniqueName(base: string, taken: Iterable<string>): string;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** What `slugify` returns when nothing usable is left of the name. */
|
|
2
|
+
const fallbackSlug = "item";
|
|
3
|
+
/**
|
|
4
|
+
* Turns a display name into a file-safe id: lowercase ASCII letters and digits
|
|
5
|
+
* joined by single hyphens. Spaces and underscores both become hyphens
|
|
6
|
+
* ("snake_case" becomes "snake-case"), and accents are dropped ("Café" becomes
|
|
7
|
+
* "cafe"), as in the old Studio. Hyphens at either end are dropped, so the id
|
|
8
|
+
* can't be read as a command-line flag ("_a_" becomes "a"). A name with nothing
|
|
9
|
+
* usable left ("___", "!!! - !!!") becomes "item".
|
|
10
|
+
*
|
|
11
|
+
* @param name - the name a person typed
|
|
12
|
+
* @returns the id
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* slugify("Weekly Report"); // "weekly-report"
|
|
16
|
+
* slugify("Café crème!"); // "cafe-creme"
|
|
17
|
+
*/
|
|
18
|
+
export function slugify(name) {
|
|
19
|
+
const slug = name
|
|
20
|
+
.toLowerCase()
|
|
21
|
+
// Splits "é" into "e" and a combining accent, which the next step removes.
|
|
22
|
+
.normalize("NFKD")
|
|
23
|
+
.replace(/[^\w\s-]/g, "")
|
|
24
|
+
.trim()
|
|
25
|
+
.replace(/[\s_]+/g, "-")
|
|
26
|
+
.replace(/-+/g, "-")
|
|
27
|
+
.replace(/^-|-$/g, "");
|
|
28
|
+
if (slug === "") {
|
|
29
|
+
return fallbackSlug;
|
|
30
|
+
}
|
|
31
|
+
return slug;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Returns `base` when no existing name uses it, otherwise the first free
|
|
35
|
+
* `base-2`, `base-3` and so on.
|
|
36
|
+
*
|
|
37
|
+
* @param base - the name to start from, usually a slug
|
|
38
|
+
* @param taken - the names already in use
|
|
39
|
+
* @returns a name that isn't in `taken`
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* uniqueName("report", ["report", "report-2"]); // "report-3"
|
|
43
|
+
*/
|
|
44
|
+
export function uniqueName(base, taken) {
|
|
45
|
+
const used = new Set(taken);
|
|
46
|
+
if (!used.has(base)) {
|
|
47
|
+
return base;
|
|
48
|
+
}
|
|
49
|
+
let suffix = 2;
|
|
50
|
+
while (used.has(`${base}-${suffix}`)) {
|
|
51
|
+
suffix++;
|
|
52
|
+
}
|
|
53
|
+
return `${base}-${suffix}`;
|
|
54
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes text as UTF-8. A lone surrogate, which has no UTF-8 form, becomes
|
|
3
|
+
* U+FFFD, as `TextEncoder` does.
|
|
4
|
+
*
|
|
5
|
+
* @param text - the text to encode
|
|
6
|
+
* @returns the UTF-8 bytes
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* encodeUtf8("é"); // Uint8Array [0xc3, 0xa9]
|
|
10
|
+
*/
|
|
11
|
+
export declare function encodeUtf8(text: string): Uint8Array;
|
|
12
|
+
/**
|
|
13
|
+
* Decodes UTF-8 bytes as text. Each invalid sequence becomes one U+FFFD, the
|
|
14
|
+
* same way `TextDecoder` does it. A byte order mark at the start is dropped,
|
|
15
|
+
* as `TextDecoder` drops it by default.
|
|
16
|
+
*
|
|
17
|
+
* @param bytes - the bytes to decode
|
|
18
|
+
* @returns the text
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* decodeUtf8(new Uint8Array([0xc3, 0xa9])); // "é"
|
|
22
|
+
*/
|
|
23
|
+
export declare function decodeUtf8(bytes: Uint8Array): string;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// The core has no TextEncoder or TextDecoder (they come from the DOM and Node
|
|
2
|
+
// type libraries, which the core doesn't load), so UTF-8 is written here. Both
|
|
3
|
+
// directions follow the WHATWG Encoding Standard, so they give exactly the same
|
|
4
|
+
// bytes and text as TextEncoder and TextDecoder.
|
|
5
|
+
/** U+FFFD, written in place of anything that isn't valid. */
|
|
6
|
+
const replacementCharacter = 0xfffd;
|
|
7
|
+
/**
|
|
8
|
+
* Encodes text as UTF-8. A lone surrogate, which has no UTF-8 form, becomes
|
|
9
|
+
* U+FFFD, as `TextEncoder` does.
|
|
10
|
+
*
|
|
11
|
+
* @param text - the text to encode
|
|
12
|
+
* @returns the UTF-8 bytes
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* encodeUtf8("é"); // Uint8Array [0xc3, 0xa9]
|
|
16
|
+
*/
|
|
17
|
+
export function encodeUtf8(text) {
|
|
18
|
+
const bytes = [];
|
|
19
|
+
for (const character of text) {
|
|
20
|
+
// for…of walks code points, so a valid surrogate pair arrives as one.
|
|
21
|
+
let codePoint = character.codePointAt(0) ?? replacementCharacter;
|
|
22
|
+
if (codePoint >= 0xd800 && codePoint <= 0xdfff) {
|
|
23
|
+
codePoint = replacementCharacter;
|
|
24
|
+
}
|
|
25
|
+
if (codePoint < 0x80) {
|
|
26
|
+
bytes.push(codePoint);
|
|
27
|
+
}
|
|
28
|
+
else if (codePoint < 0x800) {
|
|
29
|
+
bytes.push(0xc0 | (codePoint >> 6), 0x80 | (codePoint & 0x3f));
|
|
30
|
+
}
|
|
31
|
+
else if (codePoint < 0x10000) {
|
|
32
|
+
bytes.push(0xe0 | (codePoint >> 12), 0x80 | ((codePoint >> 6) & 0x3f), 0x80 | (codePoint & 0x3f));
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
bytes.push(0xf0 | (codePoint >> 18), 0x80 | ((codePoint >> 12) & 0x3f), 0x80 | ((codePoint >> 6) & 0x3f), 0x80 | (codePoint & 0x3f));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return Uint8Array.from(bytes);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Decodes UTF-8 bytes as text. Each invalid sequence becomes one U+FFFD, the
|
|
42
|
+
* same way `TextDecoder` does it. A byte order mark at the start is dropped,
|
|
43
|
+
* as `TextDecoder` drops it by default.
|
|
44
|
+
*
|
|
45
|
+
* @param bytes - the bytes to decode
|
|
46
|
+
* @returns the text
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* decodeUtf8(new Uint8Array([0xc3, 0xa9])); // "é"
|
|
50
|
+
*/
|
|
51
|
+
export function decodeUtf8(bytes) {
|
|
52
|
+
const codePoints = [];
|
|
53
|
+
let index = startsWithByteOrderMark(bytes) ? 3 : 0;
|
|
54
|
+
while (index < bytes.length) {
|
|
55
|
+
const sequence = readSequence(bytes, index);
|
|
56
|
+
codePoints.push(sequence.codePoint);
|
|
57
|
+
index += sequence.length;
|
|
58
|
+
}
|
|
59
|
+
let text = "";
|
|
60
|
+
// In chunks, because String.fromCodePoint takes its arguments on the stack.
|
|
61
|
+
const chunkSize = 8192;
|
|
62
|
+
for (let start = 0; start < codePoints.length; start += chunkSize) {
|
|
63
|
+
text += String.fromCodePoint(...codePoints.slice(start, start + chunkSize));
|
|
64
|
+
}
|
|
65
|
+
return text;
|
|
66
|
+
}
|
|
67
|
+
function startsWithByteOrderMark(bytes) {
|
|
68
|
+
return bytes[0] === 0xef && bytes[1] === 0xbb && bytes[2] === 0xbf;
|
|
69
|
+
}
|
|
70
|
+
/** Reads the sequence that starts at `start`, following the WHATWG UTF-8 decoder. */
|
|
71
|
+
function readSequence(bytes, start) {
|
|
72
|
+
const lead = bytes[start] ?? 0;
|
|
73
|
+
if (lead < 0x80) {
|
|
74
|
+
return { codePoint: lead, length: 1 };
|
|
75
|
+
}
|
|
76
|
+
const shape = sequenceShape(lead);
|
|
77
|
+
if (shape === undefined) {
|
|
78
|
+
return { codePoint: replacementCharacter, length: 1 };
|
|
79
|
+
}
|
|
80
|
+
let codePoint = lead & shape.leadMask;
|
|
81
|
+
let lower = shape.secondLower;
|
|
82
|
+
let upper = shape.secondUpper;
|
|
83
|
+
for (let offset = 1; offset < shape.length; offset++) {
|
|
84
|
+
const next = bytes[start + offset];
|
|
85
|
+
if (next === undefined || next < lower || next > upper) {
|
|
86
|
+
// The bytes read so far are one invalid sequence; `next` starts a new one.
|
|
87
|
+
return { codePoint: replacementCharacter, length: offset };
|
|
88
|
+
}
|
|
89
|
+
codePoint = (codePoint << 6) | (next & 0x3f);
|
|
90
|
+
lower = 0x80;
|
|
91
|
+
upper = 0xbf;
|
|
92
|
+
}
|
|
93
|
+
return { codePoint, length: shape.length };
|
|
94
|
+
}
|
|
95
|
+
function sequenceShape(lead) {
|
|
96
|
+
if (lead >= 0xc2 && lead <= 0xdf) {
|
|
97
|
+
return { length: 2, leadMask: 0x1f, secondLower: 0x80, secondUpper: 0xbf };
|
|
98
|
+
}
|
|
99
|
+
if (lead >= 0xe0 && lead <= 0xef) {
|
|
100
|
+
const secondLower = lead === 0xe0 ? 0xa0 : 0x80;
|
|
101
|
+
const secondUpper = lead === 0xed ? 0x9f : 0xbf;
|
|
102
|
+
return { length: 3, leadMask: 0x0f, secondLower, secondUpper };
|
|
103
|
+
}
|
|
104
|
+
if (lead >= 0xf0 && lead <= 0xf4) {
|
|
105
|
+
const secondLower = lead === 0xf0 ? 0x90 : 0x80;
|
|
106
|
+
const secondUpper = lead === 0xf4 ? 0x8f : 0xbf;
|
|
107
|
+
return { length: 4, leadMask: 0x07, secondLower, secondUpper };
|
|
108
|
+
}
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A version in semver's form, such as 0.169.0-alpha.6: three numbers and
|
|
3
|
+
* the pieces of an optional pre-release part. A build part (`+…`) is read
|
|
4
|
+
* but not kept, because it never changes the order.
|
|
5
|
+
*/
|
|
6
|
+
export interface Version {
|
|
7
|
+
readonly major: number;
|
|
8
|
+
readonly minor: number;
|
|
9
|
+
readonly patch: number;
|
|
10
|
+
/** The pre-release pieces, such as `["alpha", 6]`; empty for a release. */
|
|
11
|
+
readonly prerelease: readonly (string | number)[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Reads a version from text that is nothing but the version. Finding it in a
|
|
15
|
+
* program's output, such as "codex-cli 0.167.0", is the caller's part.
|
|
16
|
+
*
|
|
17
|
+
* @param text - the version, such as "0.169.0-alpha.6"
|
|
18
|
+
* @returns the version, or `undefined` when the text is anything else
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* readVersion("0.169.0-alpha.6"); // { major: 0, minor: 169, patch: 0, prerelease: ["alpha", 6] }
|
|
22
|
+
* readVersion("v0.169.0"); // undefined
|
|
23
|
+
*/
|
|
24
|
+
export declare function readVersion(text: string): Version | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Writes a version the usual way, such as "0.169.0-alpha.6".
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* formatVersion({ major: 2, minor: 1, patch: 321, prerelease: [] }); // "2.1.321"
|
|
30
|
+
*/
|
|
31
|
+
export declare function formatVersion(version: Version): string;
|
|
32
|
+
/**
|
|
33
|
+
* Compares two versions in semver's order.
|
|
34
|
+
*
|
|
35
|
+
* @returns a negative number when `a` comes first, a positive one when `b`
|
|
36
|
+
* does, and 0 when they are equal
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* compareVersions(readVersion("0.167.0-alpha.6")!, readVersion("0.167.0")!); // negative
|
|
40
|
+
*/
|
|
41
|
+
export declare function compareVersions(a: Version, b: Version): number;
|
|
42
|
+
/**
|
|
43
|
+
* Whether `version` is `minimum` or newer.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* isAtLeast(readVersion("0.167.0")!, readVersion("0.166.0")!); // true
|
|
47
|
+
*/
|
|
48
|
+
export declare function isAtLeast(version: Version, minimum: Version): boolean;
|