pi-harness-runtime 1.1.439 → 1.1.441
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/harness/e2e/auto-test-loop.ts +8 -2
- package/harness/e2e/browser-scrapers/base-browser-scraper.ts +2 -0
- package/harness/e2e/browser-scrapers/chrome-profile-manager.ts +2 -0
- package/harness/e2e/browser-scrapers/codex-browser-scraper.ts +2 -0
- package/harness/e2e/tools-detector.ts +2 -0
- package/harness/index.ts +2 -1
- package/harness/key-loader.ts +2 -0
- package/harness/langchain/checkpointer.ts +2 -0
- package/harness/langchain/cron-cli.ts +2 -0
- package/harness/langchain/graph.ts +2 -0
- package/harness/master-planner.ts +1 -1
- package/harness/notification-center.ts +2 -0
- package/harness/output-limit-handler.ts +1 -1
- package/harness/project-detector/detector.ts +2 -4
- package/harness/secret-provider.ts +2 -0
- package/harness/task-graph.ts +460 -113
- package/index.ts +16 -7
- package/package.json +7 -1
- package/packages/a2a-adapter/package.json +1 -1
- package/packages/agent-policy/dist/extension.d.ts.map +1 -1
- package/packages/agent-policy/dist/extension.js +2 -0
- package/packages/agent-policy/dist/extension.js.map +1 -1
- package/packages/agent-policy/package.json +1 -1
- package/packages/agent-policy/src/extension.ts +2 -0
- package/packages/architecture-generator/package.json +1 -1
- package/packages/auth/dist/minimax-browser-auth.d.ts.map +1 -1
- package/packages/auth/dist/minimax-browser-auth.js +23 -1
- package/packages/auth/dist/minimax-browser-auth.js.map +1 -1
- package/packages/auth/package.json +1 -1
- package/packages/auth/src/minimax-browser-auth.ts +30 -5
- package/packages/autonomous-refactor/package.json +1 -1
- package/packages/autonomous-runtime/dist/inbox.d.ts.map +1 -1
- package/packages/autonomous-runtime/dist/inbox.js +2 -0
- package/packages/autonomous-runtime/dist/inbox.js.map +1 -1
- package/packages/autonomous-runtime/package.json +1 -1
- package/packages/autonomous-runtime/src/inbox.ts +2 -0
- package/packages/cache-strategy/package.json +1 -1
- package/packages/capability-registry/package.json +1 -1
- package/packages/checkpoint/package.json +1 -1
- package/packages/cli-plugin-sdk/package.json +1 -1
- package/packages/clipboard/dist/src/clipboard.d.ts.map +1 -1
- package/packages/clipboard/dist/src/clipboard.js +2 -0
- package/packages/clipboard/dist/src/clipboard.js.map +1 -1
- package/packages/clipboard/dist/src/copy-sync.d.ts.map +1 -1
- package/packages/clipboard/dist/src/copy-sync.js +2 -0
- package/packages/clipboard/dist/src/copy-sync.js.map +1 -1
- package/packages/clipboard/dist/src/gist-relay.d.ts.map +1 -1
- package/packages/clipboard/dist/src/gist-relay.js +2 -0
- package/packages/clipboard/dist/src/gist-relay.js.map +1 -1
- package/packages/clipboard/package.json +1 -1
- package/packages/clipboard/src/clipboard.ts +2 -0
- package/packages/clipboard/src/copy-sync.ts +2 -0
- package/packages/clipboard/src/gist-relay.ts +2 -0
- package/packages/clipboard-plugin/dist/types.d.ts +9 -2
- package/packages/clipboard-plugin/dist/types.d.ts.map +1 -1
- package/packages/clipboard-plugin/package.json +1 -1
- package/packages/clipboard-plugin/src/types.ts +9 -2
- package/packages/code-generation/package.json +1 -1
- package/packages/code-review/package.json +1 -1
- package/packages/codex-adapter/package.json +1 -1
- package/packages/codex-watcher/package.json +1 -1
- package/packages/config-capture/package.json +1 -1
- package/packages/connection-runtime/package.json +1 -1
- package/packages/context-compiler/package.json +1 -1
- package/packages/context-discovery/package.json +1 -1
- package/packages/context-manager/package.json +1 -1
- package/packages/contracts/dist/delegation-store.js +1 -4
- package/packages/contracts/dist/workspace-env.js +28 -1
- package/packages/contracts/package.json +1 -1
- package/packages/contracts/src/delegation-store.ts +9 -4
- package/packages/contracts/src/workspace-env.ts +29 -4
- package/packages/cookie-sanitizer/package.json +1 -1
- package/packages/cost-optimizer/package.json +1 -1
- package/packages/dependency-analyzer/package.json +1 -1
- package/packages/django-plugin/package.json +1 -1
- package/packages/doc-generator/package.json +1 -1
- package/packages/durable-review/package.json +1 -1
- package/packages/e2e-tester/package.json +1 -1
- package/packages/evaluation-engine/package.json +1 -1
- package/packages/evaluation-runner/package.json +1 -1
- package/packages/event-bus/package.json +1 -1
- package/packages/event-sink/package.json +1 -1
- package/packages/event-store/dist/src/store.d.ts.map +1 -1
- package/packages/event-store/dist/src/store.js +2 -0
- package/packages/event-store/dist/src/store.js.map +1 -1
- package/packages/event-store/package.json +1 -1
- package/packages/event-store/src/store.ts +3 -0
- package/packages/experience-replay/package.json +1 -1
- package/packages/feedback-collector/package.json +1 -1
- package/packages/file-copy-helper/package.json +1 -1
- package/packages/framework-detector/package.json +1 -1
- package/packages/framework-plugin-sdk/package.json +1 -1
- package/packages/frappe-plugin/package.json +1 -1
- package/packages/generic-web-plugin/dist/analyzer.d.ts.map +1 -1
- package/packages/generic-web-plugin/dist/analyzer.js +2 -0
- package/packages/generic-web-plugin/dist/analyzer.js.map +1 -1
- package/packages/generic-web-plugin/package.json +1 -1
- package/packages/generic-web-plugin/src/analyzer.ts +3 -0
- package/packages/health-monitor/package.json +1 -1
- package/packages/intent-analyzer/package.json +1 -1
- package/packages/jev-judge/package.json +1 -1
- package/packages/knowledge-graph/package.json +1 -1
- package/packages/knowledge-retrieval/dist/mcp-client.d.ts.map +1 -1
- package/packages/knowledge-retrieval/dist/mcp-client.js +0 -1
- package/packages/knowledge-retrieval/dist/mcp-client.js.map +1 -1
- package/packages/knowledge-retrieval/package.json +1 -4
- package/packages/knowledge-retrieval/src/mcp-client.ts +0 -1
- package/packages/laravel-plugin/package.json +1 -1
- package/packages/learning-engine/package.json +1 -1
- package/packages/logging/package.json +1 -1
- package/packages/mcp-adapter/dist/server.d.ts.map +1 -1
- package/packages/mcp-adapter/dist/server.js +2 -0
- package/packages/mcp-adapter/dist/server.js.map +1 -1
- package/packages/mcp-adapter/package.json +1 -1
- package/packages/mcp-adapter/src/server.ts +3 -0
- package/packages/memory-engine/package.json +1 -1
- package/packages/milestone-manager/package.json +1 -1
- package/packages/model-registry/package.json +1 -1
- package/packages/nextjs-plugin/package.json +1 -1
- package/packages/notification/package.json +1 -1
- package/packages/observability/package.json +1 -1
- package/packages/okf-indexer/package.json +1 -1
- package/packages/paperclip-integration/dist/index.d.ts.map +1 -1
- package/packages/paperclip-integration/dist/index.js +2 -0
- package/packages/paperclip-integration/dist/index.js.map +1 -1
- package/packages/paperclip-integration/package.json +1 -1
- package/packages/paperclip-integration/src/index.ts +2 -0
- package/packages/performance-optimizer/package.json +1 -1
- package/packages/permission-mode/package.json +1 -1
- package/packages/privilege-broker/dist/audit.d.ts.map +1 -1
- package/packages/privilege-broker/dist/audit.js +2 -0
- package/packages/privilege-broker/dist/audit.js.map +1 -1
- package/packages/privilege-broker/package.json +1 -1
- package/packages/privilege-broker/src/audit.ts +2 -0
- package/packages/project-analyzer/package.json +1 -1
- package/packages/project-bootstrap/package.json +1 -1
- package/packages/projection-engine/package.json +1 -1
- package/packages/prompt-compiler/dist/compiler.d.ts.map +1 -1
- package/packages/prompt-compiler/dist/compiler.js +2 -0
- package/packages/prompt-compiler/dist/compiler.js.map +1 -1
- package/packages/prompt-compiler/package.json +1 -1
- package/packages/prompt-compiler/src/compiler.ts +2 -0
- package/packages/prompt-versioning/package.json +1 -1
- package/packages/provider-adapter-sdk/package.json +1 -1
- package/packages/provider-router/package.json +1 -1
- package/packages/provider-selector/package.json +1 -1
- package/packages/providers/package.json +1 -1
- package/packages/qdrant-skills/package.json +1 -1
- package/packages/quota-manager/package.json +1 -1
- package/packages/rate-limiter/package.json +1 -1
- package/packages/react-vite-plugin/package.json +1 -1
- package/packages/relay/package.json +1 -1
- package/packages/release-manager/package.json +1 -1
- package/packages/requirement-compiler/package.json +1 -1
- package/packages/runtime/package.json +1 -1
- package/packages/scheduler/package.json +1 -1
- package/packages/scheduler-adapter/package.json +1 -1
- package/packages/session/package.json +1 -1
- package/packages/session-api/package.json +1 -1
- package/packages/session-export/package.json +1 -1
- package/packages/shared-context/package.json +1 -1
- package/packages/skill-mcp-client/dist/client.d.ts.map +1 -1
- package/packages/skill-mcp-client/dist/client.js +0 -1
- package/packages/skill-mcp-client/dist/client.js.map +1 -1
- package/packages/skill-mcp-client/package.json +1 -4
- package/packages/skill-mcp-client/src/client.ts +0 -1
- package/packages/skill-registry/package.json +1 -1
- package/packages/skills/dist/parser.d.ts.map +1 -1
- package/packages/skills/dist/parser.js +2 -0
- package/packages/skills/dist/parser.js.map +1 -1
- package/packages/skills/dist/skill-versioning.d.ts.map +1 -1
- package/packages/skills/dist/skill-versioning.js +2 -0
- package/packages/skills/dist/skill-versioning.js.map +1 -1
- package/packages/skills/package.json +1 -1
- package/packages/skills/src/parser.ts +3 -0
- package/packages/skills/src/skill-versioning.ts +2 -0
- package/packages/sprint-planner/package.json +1 -1
- package/packages/subscription-engine/package.json +1 -1
- package/packages/task-compiler/package.json +1 -1
- package/packages/tencentdb-memory/package.json +1 -1
- package/packages/tencentdb-sync/package.json +1 -1
- package/packages/test-data-generator/package.json +1 -1
- package/packages/test-generator/package.json +1 -1
- package/packages/todo-bd-sync/package.json +1 -1
- package/packages/token-estimation/package.json +1 -1
- package/packages/token-optimizer/package.json +1 -1
- package/packages/tooling-preference/package.json +1 -1
- package/packages/trajectory/package.json +1 -1
- package/packages/tui/package.json +1 -1
- package/packages/two-phase-review/package.json +1 -1
- package/packages/types/package.json +1 -1
- package/packages/voice-api/package.json +1 -1
- package/packages/webmcp-tester/dist/index.js +0 -2
- package/packages/webmcp-tester/package.json +1 -1
- package/packages/webmcp-tester/src/index.ts +0 -3
- package/packages/wiki/package.json +1 -1
- package/packages/workflow-events/package.json +1 -1
- package/packages/workspace-scanner/package.json +1 -1
- package/packages/worktree/package.json +1 -1
- package/packages/write-review/dist/trigger.d.ts.map +1 -1
- package/packages/write-review/dist/trigger.js +1 -2
- package/packages/write-review/dist/trigger.js.map +1 -1
- package/packages/write-review/package.json +1 -1
- package/packages/write-review/src/trigger.ts +1 -2
- package/scripts/lib/runtime-imports.ts +189 -3
- package/scripts/release-all.ts +5 -3
- package/scripts/telegram-webhook-server.ts +2 -0
- package/scripts/typecheck-packages.mjs +7 -4
- package/scripts/verify-package-contents.ts +161 -2
- package/harness/e2e/tools-detector.test.ts +0 -156
- package/harness/glm-quota-countdown.test.ts +0 -323
- package/harness/langchain/agents.test.ts +0 -39
- package/harness/langchain/checkpointer.test.ts +0 -243
- package/harness/langchain/daemon.test.ts +0 -459
- package/harness/langchain/model-router.test.ts +0 -191
- package/harness/langchain/ping-pong-middleware.test.ts +0 -69
- package/harness/langchain/scoreboard.test.ts +0 -245
- package/harness/langchain/status-line.test.ts +0 -106
- package/harness/langchain/surge.test.ts +0 -467
- package/harness/langchain/widget.test.ts +0 -251
- package/harness/skill-sync.test.ts +0 -57
- package/harness/ssh-detach-interceptor.test.ts +0 -263
- package/harness/ssh-hang-recovery.test.ts +0 -86
- package/packages/a2a-adapter/test/a2a.test.ts +0 -151
- package/packages/agent-policy/test/interlock.test.ts +0 -101
- package/packages/agent-policy/test/policy-retention.test.ts +0 -380
- package/packages/agent-policy/test/policy.test.ts +0 -387
- package/packages/auth/test/auth.test.ts +0 -238
- package/packages/autonomous-refactor/test/refactor.test.ts +0 -202
- package/packages/autonomous-runtime/test/types.test.ts +0 -95
- package/packages/cache-strategy/test/cache.test.ts +0 -137
- package/packages/capability-registry/test/registry.test.ts +0 -204
- package/packages/checkpoint/test/engine.test.ts +0 -265
- package/packages/cli-plugin-sdk/test/cli.test.ts +0 -45
- package/packages/code-generation/test/generator.test.ts +0 -238
- package/packages/code-review/test/engine.test.ts +0 -302
- package/packages/codex-adapter/test/provider.test.ts +0 -142
- package/packages/codex-watcher/test/watch.test.ts +0 -453
- package/packages/context-compiler/test/context-compiler.test.ts +0 -746
- package/packages/context-manager/test/context.test.ts +0 -198
- package/packages/contracts/test/delegation.test.ts +0 -350
- package/packages/contracts/test/workspace-env.test.ts +0 -802
- package/packages/cookie-sanitizer/test/infer.test.ts +0 -110
- package/packages/cookie-sanitizer/test/normalize.test.ts +0 -113
- package/packages/cookie-sanitizer/test/parse.test.ts +0 -204
- package/packages/cookie-sanitizer/test/sync.test.ts +0 -237
- package/packages/cookie-sanitizer/test/watcher.test.ts +0 -27
- package/packages/cost-optimizer/test/cost-optimizer.test.ts +0 -438
- package/packages/dependency-analyzer/test/analyzer.test.ts +0 -49
- package/packages/django-plugin/test/analyzer.test.ts +0 -195
- package/packages/doc-generator/test/docs.test.ts +0 -168
- package/packages/durable-review/test/acceptance.test.ts +0 -357
- package/packages/durable-review/test/smoke.test.ts +0 -107
- package/packages/evaluation-engine/test/engine.test.ts +0 -277
- package/packages/evaluation-runner/test/runner.test.ts +0 -168
- package/packages/event-bus/test/bus.test.ts +0 -100
- package/packages/event-store/test/store.test.ts +0 -115
- package/packages/experience-replay/test/replay.test.ts +0 -267
- package/packages/feedback-collector/test/collector.test.ts +0 -142
- package/packages/framework-detector/test/detector.test.ts +0 -75
- package/packages/framework-plugin-sdk/test/manager.test.ts +0 -320
- package/packages/frappe-plugin/test/analyzer.test.ts +0 -250
- package/packages/generic-web-plugin/test/analyzer.test.ts +0 -134
- package/packages/health-monitor/test/health.test.ts +0 -231
- package/packages/intent-analyzer/test/analyzer.test.ts +0 -72
- package/packages/intent-analyzer/test/ping-pong.test.ts +0 -96
- package/packages/jev-judge/tests/auto-continue-context.test.ts +0 -280
- package/packages/jev-judge/tests/continuation-controller.test.ts +0 -1396
- package/packages/jev-judge/tests/jev-provider-chain.test.ts +0 -536
- package/packages/jev-judge/tests/outcome-application.test.ts +0 -132
- package/packages/jev-judge/tests/question-risk.test.ts +0 -129
- package/packages/jev-judge/tests/typesafe-provider.test.ts +0 -640
- package/packages/jev-judge/tests/validation-ledger.test.ts +0 -181
- package/packages/jev-judge/tests/validation-plan.test.ts +0 -170
- package/packages/jev-judge/tests/validation-tie-breaker.test.ts +0 -88
- package/packages/laravel-plugin/test/analyzer.test.ts +0 -220
- package/packages/learning-engine/test/engine.test.ts +0 -331
- package/packages/logging/test/buffer.test.ts +0 -44
- package/packages/logging/test/classification.test.ts +0 -137
- package/packages/logging/test/config.test.ts +0 -97
- package/packages/logging/test/fanout.test.ts +0 -186
- package/packages/logging/test/identity-transport.test.ts +0 -197
- package/packages/logging/test/incidents.test.ts +0 -404
- package/packages/logging/test/ingest-schema.test.ts +0 -184
- package/packages/logging/test/integration.test.ts +0 -140
- package/packages/logging/test/log-http.test.ts +0 -246
- package/packages/logging/test/redact.test.ts +0 -109
- package/packages/logging/test/sampler.test.ts +0 -57
- package/packages/logging/test/server.test.ts +0 -444
- package/packages/logging/test/shipper.test.ts +0 -152
- package/packages/logging/test/spool.test.ts +0 -96
- package/packages/mcp-adapter/test/server.test.ts +0 -91
- package/packages/memory-engine/test/engine.test.ts +0 -456
- package/packages/model-registry/test/registry.test.ts +0 -342
- package/packages/nextjs-plugin/test/analyzer.test.ts +0 -149
- package/packages/notification/test/approval-payload.test.ts +0 -269
- package/packages/notification/test/detail-format.test.ts +0 -106
- package/packages/notification/test/notification.test.ts +0 -375
- package/packages/notification/test/pending-question-lifecycle.test.ts +0 -195
- package/packages/notification/test/pending-question.test.ts +0 -331
- package/packages/notification/test/tooling-proposal-payload.test.ts +0 -212
- package/packages/observability/test/observability.test.ts +0 -1350
- package/packages/performance-optimizer/test/optimizer.test.ts +0 -267
- package/packages/project-analyzer/test/index.test.ts +0 -1719
- package/packages/prompt-compiler/test/prompt-compiler.test.ts +0 -813
- package/packages/prompt-versioning/test/versioning.test.ts +0 -112
- package/packages/provider-adapter-sdk/test/sdk.test.ts +0 -220
- package/packages/provider-router/test/provider-router.test.ts +0 -405
- package/packages/provider-selector/test/selector.test.ts +0 -192
- package/packages/providers/test/providers.test.ts +0 -225
- package/packages/qdrant-skills/test/collection-info.test.ts +0 -165
- package/packages/qdrant-skills/test/embedder-batch.test.ts +0 -184
- package/packages/qdrant-skills/test/embedder.test.ts +0 -97
- package/packages/quota-manager/test/quota.test.ts +0 -432
- package/packages/rate-limiter/test/limiter.test.ts +0 -128
- package/packages/react-vite-plugin/test/analyzer.test.ts +0 -139
- package/packages/relay/test/client.test.ts +0 -446
- package/packages/relay/test/relay-e2e.test.ts +0 -299
- package/packages/relay/test/relay-endpoint.test.ts +0 -278
- package/packages/release-manager/test/release.test.ts +0 -215
- package/packages/requirement-compiler/test/requirement-compiler.test.ts +0 -743
- package/packages/runtime/test/runtime-api.test.ts +0 -169
- package/packages/runtime/test/runtime.test.ts +0 -297
- package/packages/scheduler/test/scheduler.test.ts +0 -125
- package/packages/session/test/manager.test.ts +0 -233
- package/packages/shared-context/test/shared-context.test.ts +0 -114
- package/packages/skill-registry/test/registry.test.ts +0 -508
- package/packages/skills/test/init-skills.test.ts +0 -114
- package/packages/skills/test/remote-skills.test.ts +0 -360
- package/packages/skills/test/remote-source.test.ts +0 -248
- package/packages/skills/test/sanitize.test.ts +0 -250
- package/packages/skills/test/vector-indexing.test.ts +0 -205
- package/packages/skills/test/vector-schema.test.ts +0 -180
- package/packages/skills/test/vector-threshold.test.ts +0 -108
- package/packages/sprint-planner/test/planner.test.ts +0 -187
- package/packages/task-compiler/test/task-compiler.test.ts +0 -628
- package/packages/test-data-generator/test/generator.test.ts +0 -265
- package/packages/test-generator/test/generator.test.ts +0 -156
- package/packages/token-estimation/test/token-estimation.test.ts +0 -207
- package/packages/token-optimizer/test/optimizer.test.ts +0 -141
- package/packages/tooling-preference/tests/changed-files.test.ts +0 -124
- package/packages/tooling-preference/tests/detect.test.ts +0 -188
- package/packages/tooling-preference/tests/proposal.test.ts +0 -107
- package/packages/tooling-preference/tests/quality-check.test.ts +0 -272
- package/packages/tooling-preference/tests/registry.test.ts +0 -51
- package/packages/tooling-preference/tests/store.test.ts +0 -99
- package/packages/trajectory/test/store.test.ts +0 -250
- package/packages/tui/test/harness-footer.test.ts +0 -559
- package/packages/tui/test/harness-header.test.ts +0 -590
- package/packages/two-phase-review/test/classify.test.ts +0 -102
- package/packages/two-phase-review/test/helpers.ts +0 -72
- package/packages/two-phase-review/test/rules.test.ts +0 -150
- package/packages/two-phase-review/test/runtime.test.ts +0 -362
- package/packages/two-phase-review/test/scope.test.ts +0 -186
- package/packages/two-phase-review/test/signals.test.ts +0 -183
- package/packages/two-phase-review/test/state.test.ts +0 -201
- package/packages/wiki/test/basic.test.ts +0 -242
- package/packages/workspace-scanner/test/scanner.test.ts +0 -43
- package/packages/worktree/test/worktree.test.ts +0 -163
|
@@ -1,640 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for the TypeSafe Jev provider.
|
|
3
|
-
*
|
|
4
|
-
* The TypeSafe API is stubbed at the `fetch` boundary, so no network calls and
|
|
5
|
-
* no credentials are involved.
|
|
6
|
-
*
|
|
7
|
-
* Regression coverage:
|
|
8
|
-
*
|
|
9
|
-
* 1. `buildDecision()` used to evaluate the choice answer as
|
|
10
|
-
*
|
|
11
|
-
* answer.choice ?? question.type === "choice" ? options[0] : ""
|
|
12
|
-
*
|
|
13
|
-
* which JS parses as `(answer.choice ?? (question.type === "choice")) …`
|
|
14
|
-
* - so the model's choice was DISCARDED and the first option always won.
|
|
15
|
-
*
|
|
16
|
-
* 2. The request contract: the TypeSafe API rejects a choice question whose
|
|
17
|
-
* `criteria` is an ARRAY ("Input should be a valid dictionary") and a
|
|
18
|
-
* score question without `criteria` ("Field required"). Both used to be
|
|
19
|
-
* sent that way, so every real auto-continue request failed with 422 and
|
|
20
|
-
* the judge silently fell back to its "wait" default.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import { afterEach, describe, expect, it } from "bun:test";
|
|
24
|
-
import { TypeSafeJudge } from "../src/typesafe-provider.js";
|
|
25
|
-
import { JevProviderError } from "../src/provider-error.js";
|
|
26
|
-
import type { JevChoiceResponse, JevNoulResponse, JevScoreResponse } from "../src/types.js";
|
|
27
|
-
|
|
28
|
-
const originalFetch = globalThis.fetch;
|
|
29
|
-
|
|
30
|
-
interface StubAnswer {
|
|
31
|
-
type: "noul" | "choice" | "score";
|
|
32
|
-
noul?: number;
|
|
33
|
-
choice?: string;
|
|
34
|
-
score?: number;
|
|
35
|
-
confidence?: number;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
interface CapturedRequest {
|
|
39
|
-
url: string;
|
|
40
|
-
body: Record<string, unknown>;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
let lastRequest: CapturedRequest | null = null;
|
|
44
|
-
|
|
45
|
-
function stubTypeSafe(answers: Record<string, StubAnswer>): void {
|
|
46
|
-
lastRequest = null;
|
|
47
|
-
globalThis.fetch = (async (url: string, init?: { body?: string }) => {
|
|
48
|
-
lastRequest = {
|
|
49
|
-
url,
|
|
50
|
-
body: init?.body ? (JSON.parse(init.body) as Record<string, unknown>) : {},
|
|
51
|
-
};
|
|
52
|
-
return {
|
|
53
|
-
ok: true,
|
|
54
|
-
status: 200,
|
|
55
|
-
json: async () => ({ answers, model: "test-model", latency_ms: 1 }),
|
|
56
|
-
text: async () => JSON.stringify({ answers }),
|
|
57
|
-
};
|
|
58
|
-
}) as unknown as typeof fetch;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function stubFailure(status: number, body = "boom"): void {
|
|
62
|
-
lastRequest = null;
|
|
63
|
-
globalThis.fetch = (async (url: string, init?: { body?: string }) => {
|
|
64
|
-
lastRequest = {
|
|
65
|
-
url,
|
|
66
|
-
body: init?.body ? (JSON.parse(init.body) as Record<string, unknown>) : {},
|
|
67
|
-
};
|
|
68
|
-
return {
|
|
69
|
-
ok: false,
|
|
70
|
-
status,
|
|
71
|
-
json: async () => ({ detail: body }),
|
|
72
|
-
text: async () => body,
|
|
73
|
-
};
|
|
74
|
-
}) as unknown as typeof fetch;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function stubNetworkError(error?: unknown): void {
|
|
78
|
-
globalThis.fetch = (async () => {
|
|
79
|
-
throw error ?? new Error("fetch failed");
|
|
80
|
-
}) as unknown as typeof fetch;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* The error shape undici produces for a connection failure: a TypeError whose
|
|
85
|
-
* cause carries the system error code.
|
|
86
|
-
*/
|
|
87
|
-
function undiciConnectionError(): Error {
|
|
88
|
-
return Object.assign(new TypeError("fetch failed"), {
|
|
89
|
-
cause: Object.assign(new Error("connect ECONNREFUSED 127.0.0.1:443"), {
|
|
90
|
-
code: "ECONNREFUSED",
|
|
91
|
-
}),
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function makeJudge(): TypeSafeJudge {
|
|
96
|
-
return new TypeSafeJudge({
|
|
97
|
-
apiKey: "test-key",
|
|
98
|
-
baseUrl: "https://typesafe.invalid",
|
|
99
|
-
model: "test-model",
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
afterEach(() => {
|
|
104
|
-
globalThis.fetch = originalFetch;
|
|
105
|
-
lastRequest = null;
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
describe("TypeSafeJudge - choice answers", () => {
|
|
109
|
-
it("uses the choice returned by the model", async () => {
|
|
110
|
-
stubTypeSafe({
|
|
111
|
-
answer: { type: "choice", choice: "gamma", confidence: 0.8 },
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
const result = await makeJudge().evaluate("state", {
|
|
115
|
-
answer: {
|
|
116
|
-
type: "choice",
|
|
117
|
-
instructions: "Pick one",
|
|
118
|
-
options: ["alpha", "beta", "gamma"],
|
|
119
|
-
},
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
const response = result.decisions.answer.response as JevChoiceResponse;
|
|
123
|
-
expect(response.choice).toBe("gamma");
|
|
124
|
-
expect(result.decisions.answer.probability).toBe(0.8);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("sends the choice criteria as a dictionary", async () => {
|
|
128
|
-
stubTypeSafe({
|
|
129
|
-
answer: { type: "choice", choice: "high", confidence: 0.6 },
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
await makeJudge().evaluate("state", {
|
|
133
|
-
answer: {
|
|
134
|
-
type: "choice",
|
|
135
|
-
instructions: "Pick one",
|
|
136
|
-
options: ["critical", "high"],
|
|
137
|
-
optionDescriptions: {
|
|
138
|
-
critical: "it is critical",
|
|
139
|
-
high: "it is high",
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
const questions = lastRequest?.body.questions as Record<
|
|
145
|
-
string,
|
|
146
|
-
{ type: string; criteria: unknown }
|
|
147
|
-
>;
|
|
148
|
-
expect(questions.answer.type).toBe("choice");
|
|
149
|
-
expect(questions.answer.criteria).toEqual({
|
|
150
|
-
critical: "it is critical",
|
|
151
|
-
high: "it is high",
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("accepts a criteria dictionary directly", async () => {
|
|
156
|
-
stubTypeSafe({
|
|
157
|
-
answer: { type: "choice", choice: "high", confidence: 0.6 },
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
await makeJudge().evaluate("state", {
|
|
161
|
-
answer: {
|
|
162
|
-
type: "choice",
|
|
163
|
-
instructions: "Pick one",
|
|
164
|
-
criteria: { critical: "it is critical", high: "it is high" },
|
|
165
|
-
},
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
const questions = lastRequest?.body.questions as Record<
|
|
169
|
-
string,
|
|
170
|
-
{ criteria: unknown }
|
|
171
|
-
>;
|
|
172
|
-
expect(questions.answer.criteria).toEqual({
|
|
173
|
-
critical: "it is critical",
|
|
174
|
-
high: "it is high",
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it("matches the option spelling case insensitively", async () => {
|
|
179
|
-
stubTypeSafe({
|
|
180
|
-
answer: { type: "choice", choice: "GAMMA", confidence: 0.7 },
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
const result = await makeJudge().evaluate("state", {
|
|
184
|
-
answer: {
|
|
185
|
-
type: "choice",
|
|
186
|
-
instructions: "Pick one",
|
|
187
|
-
options: ["alpha", "beta", "gamma"],
|
|
188
|
-
},
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
const response = result.decisions.answer.response as JevChoiceResponse;
|
|
192
|
-
expect(response.choice).toBe("gamma");
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it("passes an unknown choice through instead of substituting an option", async () => {
|
|
196
|
-
stubTypeSafe({
|
|
197
|
-
answer: { type: "choice", choice: "delta", confidence: 0.7 },
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
const result = await makeJudge().evaluate("state", {
|
|
201
|
-
answer: {
|
|
202
|
-
type: "choice",
|
|
203
|
-
instructions: "Pick one",
|
|
204
|
-
options: ["alpha", "beta"],
|
|
205
|
-
},
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
const response = result.decisions.answer.response as JevChoiceResponse;
|
|
209
|
-
expect(response.choice).toBe("delta");
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
describe("TypeSafeJudge - noul and score answers", () => {
|
|
214
|
-
it("keeps noul answers intact", async () => {
|
|
215
|
-
stubTypeSafe({ answer: { type: "noul", noul: 0.75 } });
|
|
216
|
-
|
|
217
|
-
const result = await makeJudge().evaluate("state", {
|
|
218
|
-
answer: { type: "noul", instructions: "Is it true?" },
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
const response = result.decisions.answer.response as JevNoulResponse;
|
|
222
|
-
expect(response.noul).toBe(0.75);
|
|
223
|
-
expect(result.decisions.answer.probability).toBe(0.75);
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it("sends a score question with a rubric", async () => {
|
|
227
|
-
stubTypeSafe({ answer: { type: "score", score: 3, confidence: 0.6 } });
|
|
228
|
-
|
|
229
|
-
await makeJudge().evaluate("state", {
|
|
230
|
-
answer: {
|
|
231
|
-
type: "score",
|
|
232
|
-
instructions: "How bad?",
|
|
233
|
-
min: 1,
|
|
234
|
-
max: 5,
|
|
235
|
-
criteria: ["1 - none", "2 - low", "3 - medium", "4 - high", "5 - severe"],
|
|
236
|
-
},
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
const questions = lastRequest?.body.questions as Record<
|
|
240
|
-
string,
|
|
241
|
-
{ type: string; criteria: unknown }
|
|
242
|
-
>;
|
|
243
|
-
expect(questions.answer.type).toBe("score");
|
|
244
|
-
expect(questions.answer.criteria).toEqual([
|
|
245
|
-
"1 - none",
|
|
246
|
-
"2 - low",
|
|
247
|
-
"3 - medium",
|
|
248
|
-
"4 - high",
|
|
249
|
-
"5 - severe",
|
|
250
|
-
]);
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
it("derives a rubric from min and max when none is given", async () => {
|
|
254
|
-
stubTypeSafe({ answer: { type: "score", score: 3.37, confidence: 0.6 } });
|
|
255
|
-
|
|
256
|
-
const result = await makeJudge().evaluate("state", {
|
|
257
|
-
answer: {
|
|
258
|
-
type: "score",
|
|
259
|
-
instructions: "How bad?",
|
|
260
|
-
min: 1,
|
|
261
|
-
max: 5,
|
|
262
|
-
},
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
const questions = lastRequest?.body.questions as Record<
|
|
266
|
-
string,
|
|
267
|
-
{ criteria: string[] }
|
|
268
|
-
>;
|
|
269
|
-
expect(Array.isArray(questions.answer.criteria)).toBe(true);
|
|
270
|
-
expect(questions.answer.criteria.length).toBe(5);
|
|
271
|
-
|
|
272
|
-
// The API answers with the position in the rubric, the reported value
|
|
273
|
-
// is mapped back onto the min/max scale.
|
|
274
|
-
const response = result.decisions.answer.response as JevScoreResponse;
|
|
275
|
-
expect(response.score).toBeCloseTo(4.37, 5);
|
|
276
|
-
expect(result.decisions.answer.probability).toBeCloseTo(0.8425, 5);
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
it("maps the rubric position onto the min/max scale", async () => {
|
|
280
|
-
stubTypeSafe({ answer: { type: "score", score: 4.5, confidence: 0.6 } });
|
|
281
|
-
|
|
282
|
-
const result = await makeJudge().evaluate("state", {
|
|
283
|
-
answer: {
|
|
284
|
-
type: "score",
|
|
285
|
-
instructions: "How good?",
|
|
286
|
-
min: 0,
|
|
287
|
-
max: 100,
|
|
288
|
-
},
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
const response = result.decisions.answer.response as JevScoreResponse;
|
|
292
|
-
// 10 levels were derived (0..100), 4.5 of 9 steps => 50
|
|
293
|
-
expect(response.score).toBeCloseTo(50, 5);
|
|
294
|
-
expect(result.decisions.answer.probability).toBeCloseTo(0.5, 5);
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
it("clamps a rubric position outside the rubric", async () => {
|
|
298
|
-
stubTypeSafe({ answer: { type: "score", score: 99, confidence: 0.6 } });
|
|
299
|
-
|
|
300
|
-
const result = await makeJudge().evaluate("state", {
|
|
301
|
-
answer: {
|
|
302
|
-
type: "score",
|
|
303
|
-
instructions: "How good?",
|
|
304
|
-
min: 1,
|
|
305
|
-
max: 5,
|
|
306
|
-
},
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
const response = result.decisions.answer.response as JevScoreResponse;
|
|
310
|
-
expect(response.score).toBe(5);
|
|
311
|
-
expect(result.decisions.answer.probability).toBe(1);
|
|
312
|
-
});
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
describe("TypeSafeJudge - request validation", () => {
|
|
316
|
-
it("rejects a choice question without options before sending anything", async () => {
|
|
317
|
-
let called = false;
|
|
318
|
-
globalThis.fetch = (async () => {
|
|
319
|
-
called = true;
|
|
320
|
-
return { ok: true, status: 200, json: async () => ({}), text: async () => "{}" };
|
|
321
|
-
}) as unknown as typeof fetch;
|
|
322
|
-
|
|
323
|
-
const error = (await makeJudge()
|
|
324
|
-
.evaluate("state", {
|
|
325
|
-
answer: { type: "choice", instructions: "Pick one" },
|
|
326
|
-
})
|
|
327
|
-
.catch((e: unknown) => e)) as JevProviderError;
|
|
328
|
-
|
|
329
|
-
expect(error).toBeInstanceOf(JevProviderError);
|
|
330
|
-
expect((error as JevProviderError).retryable).toBe(false);
|
|
331
|
-
expect((error as JevProviderError).message).toContain("options");
|
|
332
|
-
expect(called).toBe(false);
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
it("rejects a score question with too many rubric levels", async () => {
|
|
336
|
-
const error = (await makeJudge()
|
|
337
|
-
.evaluate("state", {
|
|
338
|
-
answer: {
|
|
339
|
-
type: "score",
|
|
340
|
-
instructions: "How good?",
|
|
341
|
-
criteria: Array.from({ length: 12 }, (_, i) => `level ${i}`),
|
|
342
|
-
},
|
|
343
|
-
})
|
|
344
|
-
.catch((e: unknown) => e)) as JevProviderError;
|
|
345
|
-
|
|
346
|
-
expect(error).toBeInstanceOf(JevProviderError);
|
|
347
|
-
expect((error as JevProviderError).retryable).toBe(false);
|
|
348
|
-
});
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
describe("TypeSafeJudge - wire format", () => {
|
|
352
|
-
it("sends only the fields the API accepts", async () => {
|
|
353
|
-
stubTypeSafe({ answer: { type: "noul", noul: 0.5 } });
|
|
354
|
-
|
|
355
|
-
await makeJudge().evaluate("state", {
|
|
356
|
-
answer: { type: "noul", instructions: "Is it true?" },
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
// The API rejects unknown fields with 400 "Invalid request" - a local
|
|
360
|
-
// bookkeeping field that leaks into the body breaks every request.
|
|
361
|
-
expect(Object.keys(lastRequest?.body ?? {}).sort()).toEqual([
|
|
362
|
-
"model",
|
|
363
|
-
"questions",
|
|
364
|
-
"state",
|
|
365
|
-
]);
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
it("sends only the fields the API accepts for a question", async () => {
|
|
369
|
-
stubTypeSafe({ answer: { type: "score", score: 2, confidence: 0.5 } });
|
|
370
|
-
|
|
371
|
-
await makeJudge().evaluate("state", {
|
|
372
|
-
answer: {
|
|
373
|
-
type: "score",
|
|
374
|
-
instructions: "How bad?",
|
|
375
|
-
min: 1,
|
|
376
|
-
max: 5,
|
|
377
|
-
criteria: ["1 - none", "2 - low", "3 - medium", "4 - high", "5 - severe"],
|
|
378
|
-
},
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
const questions = lastRequest?.body.questions as Record<string, Record<string, unknown>>;
|
|
382
|
-
expect(Object.keys(questions.answer).sort()).toEqual([
|
|
383
|
-
"criteria",
|
|
384
|
-
"instructions",
|
|
385
|
-
"type",
|
|
386
|
-
]);
|
|
387
|
-
// The local scale bookkeeping must not reach the wire.
|
|
388
|
-
expect(questions.answer.min).toBeUndefined();
|
|
389
|
-
expect(questions.answer.max).toBeUndefined();
|
|
390
|
-
expect(questions.answer.scoreScales).toBeUndefined();
|
|
391
|
-
});
|
|
392
|
-
|
|
393
|
-
it("sends only the fields the API accepts for a choice question", async () => {
|
|
394
|
-
stubTypeSafe({ answer: { type: "choice", choice: "yes", confidence: 0.5 } });
|
|
395
|
-
|
|
396
|
-
await makeJudge().evaluate("state", {
|
|
397
|
-
answer: {
|
|
398
|
-
type: "choice",
|
|
399
|
-
instructions: "Pick one",
|
|
400
|
-
options: ["yes", "no"],
|
|
401
|
-
},
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
const questions = lastRequest?.body.questions as Record<string, Record<string, unknown>>;
|
|
405
|
-
expect(Object.keys(questions.answer).sort()).toEqual([
|
|
406
|
-
"criteria",
|
|
407
|
-
"instructions",
|
|
408
|
-
"type",
|
|
409
|
-
]);
|
|
410
|
-
expect(questions.answer.options).toBeUndefined();
|
|
411
|
-
});
|
|
412
|
-
|
|
413
|
-
it("describes a named candidate by its name when no description is given", async () => {
|
|
414
|
-
stubTypeSafe({ answer: { type: "choice", choice: "yes", confidence: 0.5 } });
|
|
415
|
-
|
|
416
|
-
await makeJudge().evaluate("state", {
|
|
417
|
-
answer: {
|
|
418
|
-
type: "choice",
|
|
419
|
-
instructions: "Pick one",
|
|
420
|
-
options: ["yes", "no"],
|
|
421
|
-
},
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
const questions = lastRequest?.body.questions as Record<string, { criteria: unknown }>;
|
|
425
|
-
expect(questions.answer.criteria).toEqual({ yes: "yes", no: "no" });
|
|
426
|
-
});
|
|
427
|
-
|
|
428
|
-
it("resolves the candidates of a criteria only question", async () => {
|
|
429
|
-
stubTypeSafe({ answer: { type: "choice", choice: "high", confidence: 0.5 } });
|
|
430
|
-
|
|
431
|
-
const result = await makeJudge().evaluate("state", {
|
|
432
|
-
answer: {
|
|
433
|
-
type: "choice",
|
|
434
|
-
instructions: "Pick one",
|
|
435
|
-
criteria: { critical: "it is critical", high: "it is high" },
|
|
436
|
-
},
|
|
437
|
-
});
|
|
438
|
-
|
|
439
|
-
const response = result.decisions.answer.response as JevChoiceResponse;
|
|
440
|
-
expect(response.choice).toBe("high");
|
|
441
|
-
});
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
describe("TypeSafeJudge - error classification", () => {
|
|
445
|
-
it("marks a contract error (422) as not retryable", async () => {
|
|
446
|
-
stubFailure(422, "Input should be a valid dictionary");
|
|
447
|
-
|
|
448
|
-
const error = (await makeJudge()
|
|
449
|
-
.evaluate("state", {
|
|
450
|
-
answer: { type: "noul", instructions: "Is it true?" },
|
|
451
|
-
})
|
|
452
|
-
.catch((e: unknown) => e)) as JevProviderError;
|
|
453
|
-
|
|
454
|
-
expect(error).toBeInstanceOf(JevProviderError);
|
|
455
|
-
expect((error as JevProviderError).status).toBe(422);
|
|
456
|
-
expect((error as JevProviderError).retryable).toBe(false);
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
it("marks a bad request (400) as not retryable", async () => {
|
|
460
|
-
stubFailure(400, "Invalid request.");
|
|
461
|
-
|
|
462
|
-
const error = (await makeJudge()
|
|
463
|
-
.evaluate("state", {
|
|
464
|
-
answer: { type: "noul", instructions: "Is it true?" },
|
|
465
|
-
})
|
|
466
|
-
.catch((e: unknown) => e)) as JevProviderError;
|
|
467
|
-
|
|
468
|
-
expect((error as JevProviderError).status).toBe(400);
|
|
469
|
-
expect((error as JevProviderError).retryable).toBe(false);
|
|
470
|
-
});
|
|
471
|
-
|
|
472
|
-
it("marks a rate limit (429) as retryable", async () => {
|
|
473
|
-
stubFailure(429, "slow down");
|
|
474
|
-
|
|
475
|
-
const error = (await makeJudge()
|
|
476
|
-
.evaluate("state", {
|
|
477
|
-
answer: { type: "noul", instructions: "Is it true?" },
|
|
478
|
-
})
|
|
479
|
-
.catch((e: unknown) => e)) as JevProviderError;
|
|
480
|
-
|
|
481
|
-
expect((error as JevProviderError).status).toBe(429);
|
|
482
|
-
expect((error as JevProviderError).retryable).toBe(true);
|
|
483
|
-
});
|
|
484
|
-
|
|
485
|
-
it("marks a server error (500) as retryable", async () => {
|
|
486
|
-
stubFailure(500);
|
|
487
|
-
|
|
488
|
-
const error = (await makeJudge()
|
|
489
|
-
.evaluate("state", {
|
|
490
|
-
answer: { type: "noul", instructions: "Is it true?" },
|
|
491
|
-
})
|
|
492
|
-
.catch((e: unknown) => e)) as JevProviderError;
|
|
493
|
-
|
|
494
|
-
expect((error as JevProviderError).status).toBe(500);
|
|
495
|
-
expect((error as JevProviderError).retryable).toBe(true);
|
|
496
|
-
});
|
|
497
|
-
|
|
498
|
-
it("marks an auth error (401) as retryable", async () => {
|
|
499
|
-
stubFailure(401);
|
|
500
|
-
|
|
501
|
-
const error = (await makeJudge()
|
|
502
|
-
.evaluate("state", {
|
|
503
|
-
answer: { type: "noul", instructions: "Is it true?" },
|
|
504
|
-
})
|
|
505
|
-
.catch((e: unknown) => e)) as JevProviderError;
|
|
506
|
-
|
|
507
|
-
expect((error as JevProviderError).status).toBe(401);
|
|
508
|
-
expect((error as JevProviderError).retryable).toBe(true);
|
|
509
|
-
});
|
|
510
|
-
|
|
511
|
-
it("marks a network failure as retryable", async () => {
|
|
512
|
-
stubNetworkError(undiciConnectionError());
|
|
513
|
-
|
|
514
|
-
const error = (await makeJudge()
|
|
515
|
-
.evaluate("state", {
|
|
516
|
-
answer: { type: "noul", instructions: "Is it true?" },
|
|
517
|
-
})
|
|
518
|
-
.catch((e: unknown) => e)) as JevProviderError;
|
|
519
|
-
|
|
520
|
-
expect(error).toBeInstanceOf(JevProviderError);
|
|
521
|
-
expect((error as JevProviderError).retryable).toBe(true);
|
|
522
|
-
});
|
|
523
|
-
|
|
524
|
-
it("marks a timeout as retryable", async () => {
|
|
525
|
-
stubNetworkError(Object.assign(new Error("The operation timed out"), { name: "TimeoutError" }));
|
|
526
|
-
|
|
527
|
-
const error = (await makeJudge()
|
|
528
|
-
.evaluate("state", {
|
|
529
|
-
answer: { type: "noul", instructions: "Is it true?" },
|
|
530
|
-
})
|
|
531
|
-
.catch((e: unknown) => e)) as JevProviderError;
|
|
532
|
-
|
|
533
|
-
expect((error as JevProviderError).retryable).toBe(true);
|
|
534
|
-
});
|
|
535
|
-
|
|
536
|
-
it("does NOT mark a bug of our own as retryable", async () => {
|
|
537
|
-
// A malformed URL is not a provider outage: falling back to another
|
|
538
|
-
// provider would only hide the bug.
|
|
539
|
-
stubNetworkError(new TypeError("Failed to parse URL"));
|
|
540
|
-
|
|
541
|
-
const error = (await makeJudge()
|
|
542
|
-
.evaluate("state", {
|
|
543
|
-
answer: { type: "noul", instructions: "Is it true?" },
|
|
544
|
-
})
|
|
545
|
-
.catch((e: unknown) => e)) as JevProviderError;
|
|
546
|
-
|
|
547
|
-
expect(error).toBeInstanceOf(JevProviderError);
|
|
548
|
-
expect((error as JevProviderError).retryable).toBe(false);
|
|
549
|
-
});
|
|
550
|
-
|
|
551
|
-
it("marks the failure of several addresses as retryable", async () => {
|
|
552
|
-
// undici tries the addresses of a host one after the other and reports
|
|
553
|
-
// the failures as an AggregateError. The cause here is NOT a transport
|
|
554
|
-
// failure: the addresses are what makes the attempt a transport
|
|
555
|
-
// failure.
|
|
556
|
-
const aggregate = new AggregateError(
|
|
557
|
-
[
|
|
558
|
-
Object.assign(new Error("certificate has expired"), { code: "CERT_HAS_EXPIRED" }),
|
|
559
|
-
Object.assign(new Error("connect EHOSTUNREACH 10.0.0.1:443"), {
|
|
560
|
-
code: "EHOSTUNREACH",
|
|
561
|
-
}),
|
|
562
|
-
],
|
|
563
|
-
"all failed"
|
|
564
|
-
);
|
|
565
|
-
Object.assign(aggregate, { cause: new TypeError("Failed to parse URL") });
|
|
566
|
-
stubNetworkError(aggregate);
|
|
567
|
-
|
|
568
|
-
const error = (await makeJudge()
|
|
569
|
-
.evaluate("state", {
|
|
570
|
-
answer: { type: "noul", instructions: "Is it true?" },
|
|
571
|
-
})
|
|
572
|
-
.catch((e: unknown) => e)) as JevProviderError;
|
|
573
|
-
|
|
574
|
-
expect((error as JevProviderError).retryable).toBe(true);
|
|
575
|
-
});
|
|
576
|
-
|
|
577
|
-
it("marks an expired provider certificate as retryable", async () => {
|
|
578
|
-
for (const code of [
|
|
579
|
-
"CERT_HAS_EXPIRED",
|
|
580
|
-
"SELF_SIGNED_CERT_IN_CHAIN",
|
|
581
|
-
"DEPTH_ZERO_SELF_SIGNED_CERT",
|
|
582
|
-
"UNABLE_TO_VERIFY_LEAF_SIGNATURE",
|
|
583
|
-
]) {
|
|
584
|
-
stubNetworkError(Object.assign(new Error(`certificate error ${code}`), { code }));
|
|
585
|
-
|
|
586
|
-
const error = (await makeJudge()
|
|
587
|
-
.evaluate("state", {
|
|
588
|
-
answer: { type: "noul", instructions: "Is it true?" },
|
|
589
|
-
})
|
|
590
|
-
.catch((e: unknown) => e)) as JevProviderError;
|
|
591
|
-
|
|
592
|
-
expect(`${code}: ${(error as JevProviderError).retryable}`).toBe(`${code}: true`);
|
|
593
|
-
}
|
|
594
|
-
});
|
|
595
|
-
|
|
596
|
-
it("does NOT mark a stream bug of our own as retryable", async () => {
|
|
597
|
-
// Writing to a finished stream is our bug, not a provider outage.
|
|
598
|
-
stubNetworkError(
|
|
599
|
-
Object.assign(new Error("write after end"), { code: "ERR_STREAM_WRITE_AFTER_END" })
|
|
600
|
-
);
|
|
601
|
-
|
|
602
|
-
const error = (await makeJudge()
|
|
603
|
-
.evaluate("state", {
|
|
604
|
-
answer: { type: "noul", instructions: "Is it true?" },
|
|
605
|
-
})
|
|
606
|
-
.catch((e: unknown) => e)) as JevProviderError;
|
|
607
|
-
|
|
608
|
-
expect((error as JevProviderError).retryable).toBe(false);
|
|
609
|
-
});
|
|
610
|
-
|
|
611
|
-
it("marks an unreachable network as retryable", async () => {
|
|
612
|
-
stubNetworkError(
|
|
613
|
-
Object.assign(new Error("connect ENETUNREACH 10.0.0.1:443"), { code: "ENETUNREACH" })
|
|
614
|
-
);
|
|
615
|
-
|
|
616
|
-
const error = (await makeJudge()
|
|
617
|
-
.evaluate("state", {
|
|
618
|
-
answer: { type: "noul", instructions: "Is it true?" },
|
|
619
|
-
})
|
|
620
|
-
.catch((e: unknown) => e)) as JevProviderError;
|
|
621
|
-
|
|
622
|
-
expect((error as JevProviderError).retryable).toBe(true);
|
|
623
|
-
});
|
|
624
|
-
|
|
625
|
-
it("marks a TLS failure as retryable", async () => {
|
|
626
|
-
stubNetworkError(
|
|
627
|
-
Object.assign(new Error("certificate altname mismatch"), {
|
|
628
|
-
code: "ERR_TLS_CERT_ALTNAME_INVALID",
|
|
629
|
-
})
|
|
630
|
-
);
|
|
631
|
-
|
|
632
|
-
const error = (await makeJudge()
|
|
633
|
-
.evaluate("state", {
|
|
634
|
-
answer: { type: "noul", instructions: "Is it true?" },
|
|
635
|
-
})
|
|
636
|
-
.catch((e: unknown) => e)) as JevProviderError;
|
|
637
|
-
|
|
638
|
-
expect((error as JevProviderError).retryable).toBe(true);
|
|
639
|
-
});
|
|
640
|
-
});
|