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,299 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Relay end-to-end test with a mocked Telegram transport.
|
|
3
|
-
*
|
|
4
|
-
* Flow: mock Telegram webhook (HTTP) -> relay server (WebSocket) -> RelayClient.
|
|
5
|
-
*
|
|
6
|
-
* No production credentials, no real Telegram traffic, no external network.
|
|
7
|
-
* Every wait has a deadline so a broken handshake fails the test instead of
|
|
8
|
-
* hanging the run, and every owned resource is torn down in `finally`.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { describe, it, expect } from "bun:test";
|
|
12
|
-
import { createServer, request, type Server } from "node:http";
|
|
13
|
-
import type { AddressInfo } from "node:net";
|
|
14
|
-
import { RelayServer } from "../src/server.js";
|
|
15
|
-
import { RelayClient } from "../src/client.js";
|
|
16
|
-
import type { CallbackPayload } from "../src/types.js";
|
|
17
|
-
|
|
18
|
-
const AUTH_TOKEN = "e2e-token";
|
|
19
|
-
const WEBHOOK_SECRET = "e2e-webhook-secret";
|
|
20
|
-
const OVERALL_TIMEOUT_MS = 10_000;
|
|
21
|
-
const LOOPBACK_HOSTS = new Set(["127.0.0.1", "localhost", "::1"]);
|
|
22
|
-
|
|
23
|
-
function withTimeout<T>(promise: Promise<T>, ms: number, label: string): Promise<T> {
|
|
24
|
-
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
25
|
-
const timeout = new Promise<T>((_resolve, reject) => {
|
|
26
|
-
timer = setTimeout(() => reject(new Error(`Timeout after ${ms}ms waiting for ${label}`)), ms);
|
|
27
|
-
});
|
|
28
|
-
return Promise.race([promise, timeout]).finally(() => {
|
|
29
|
-
// The timer must not outlive the race: a live timer keeps the test
|
|
30
|
-
// process alive for the full timeout after the assertions passed.
|
|
31
|
-
if (timer) clearTimeout(timer);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Outbound calls in this test only ever target the loopback mock server.
|
|
37
|
-
* The request is parameterized by host/port/path - no URL string is built.
|
|
38
|
-
*/
|
|
39
|
-
function postToLoopback(
|
|
40
|
-
port: number,
|
|
41
|
-
path: string,
|
|
42
|
-
secret: string,
|
|
43
|
-
body: unknown,
|
|
44
|
-
): Promise<{ status: number; body: string }> {
|
|
45
|
-
if (!LOOPBACK_HOSTS.has("127.0.0.1")) {
|
|
46
|
-
throw new Error("Unexpected host configuration");
|
|
47
|
-
}
|
|
48
|
-
const payload = JSON.stringify(body);
|
|
49
|
-
|
|
50
|
-
return new Promise((resolve, reject) => {
|
|
51
|
-
const req = request(
|
|
52
|
-
{
|
|
53
|
-
host: "127.0.0.1",
|
|
54
|
-
port,
|
|
55
|
-
path,
|
|
56
|
-
method: "POST",
|
|
57
|
-
headers: {
|
|
58
|
-
"Content-Type": "application/json",
|
|
59
|
-
"Content-Length": Buffer.byteLength(payload),
|
|
60
|
-
"x-telegram-bot-api-secret-token": secret,
|
|
61
|
-
},
|
|
62
|
-
timeout: 5000,
|
|
63
|
-
},
|
|
64
|
-
(res) => {
|
|
65
|
-
const chunks: Buffer[] = [];
|
|
66
|
-
res.on("data", (c) => chunks.push(c as Buffer));
|
|
67
|
-
res.on("end", () =>
|
|
68
|
-
resolve({
|
|
69
|
-
status: res.statusCode ?? 0,
|
|
70
|
-
body: Buffer.concat(chunks).toString("utf8"),
|
|
71
|
-
}),
|
|
72
|
-
);
|
|
73
|
-
},
|
|
74
|
-
);
|
|
75
|
-
req.on("timeout", () => req.destroy(new Error("webhook request timed out")));
|
|
76
|
-
req.on("error", reject);
|
|
77
|
-
req.end(payload);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
interface MockTelegram {
|
|
82
|
-
url: string;
|
|
83
|
-
port: number;
|
|
84
|
-
deliver: (payload: CallbackPayload) => void;
|
|
85
|
-
close: () => Promise<void>;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Mock Telegram webhook: accepts a callback_query POST, validates the secret
|
|
90
|
-
* header and hands the parsed callback to the relay server.
|
|
91
|
-
*/
|
|
92
|
-
async function startMockTelegram(
|
|
93
|
-
onCallback: (payload: CallbackPayload) => void,
|
|
94
|
-
): Promise<MockTelegram> {
|
|
95
|
-
const server: Server = createServer((req, res) => {
|
|
96
|
-
const chunks: Buffer[] = [];
|
|
97
|
-
req.on("data", (c) => chunks.push(c as Buffer));
|
|
98
|
-
req.on("end", () => {
|
|
99
|
-
if (req.headers["x-telegram-bot-api-secret-token"] !== WEBHOOK_SECRET) {
|
|
100
|
-
res.writeHead(403).end(JSON.stringify({ ok: false, error: "bad secret" }));
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
let body: {
|
|
105
|
-
callback_query?: {
|
|
106
|
-
id: string;
|
|
107
|
-
from: { id: number; username?: string; first_name?: string };
|
|
108
|
-
message?: { message_id?: number; chat?: { id: number } };
|
|
109
|
-
data: string;
|
|
110
|
-
};
|
|
111
|
-
};
|
|
112
|
-
try {
|
|
113
|
-
body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
114
|
-
} catch {
|
|
115
|
-
res.writeHead(400).end(JSON.stringify({ ok: false, error: "bad json" }));
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const q = body.callback_query;
|
|
120
|
-
if (!q) {
|
|
121
|
-
res.writeHead(400).end(JSON.stringify({ ok: false, error: "no callback_query" }));
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const [action, ...rest] = q.data.split(":");
|
|
126
|
-
onCallback({
|
|
127
|
-
id: `cb-${q.id}`,
|
|
128
|
-
type: "telegram_callback",
|
|
129
|
-
action,
|
|
130
|
-
targetId: rest.join(":"),
|
|
131
|
-
userId: q.from.id,
|
|
132
|
-
username: q.from.username,
|
|
133
|
-
messageId: q.message?.message_id,
|
|
134
|
-
callbackQueryId: q.id,
|
|
135
|
-
chatId: q.message?.chat?.id,
|
|
136
|
-
timestamp: new Date().toISOString(),
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
res.writeHead(200).end(JSON.stringify({ ok: true }));
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", () => resolve()));
|
|
144
|
-
const port = (server.address() as AddressInfo).port;
|
|
145
|
-
|
|
146
|
-
return {
|
|
147
|
-
url: `http://127.0.0.1:${port}/telegram`,
|
|
148
|
-
port,
|
|
149
|
-
deliver: () => {},
|
|
150
|
-
close: () =>
|
|
151
|
-
new Promise<void>((resolve) => {
|
|
152
|
-
server.close(() => resolve());
|
|
153
|
-
server.closeAllConnections?.();
|
|
154
|
-
}),
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
describe("relay end-to-end (mocked Telegram)", () => {
|
|
159
|
-
it("delivers a Telegram callback to the connected client", async () => {
|
|
160
|
-
const relay = new RelayServer({
|
|
161
|
-
port: 0,
|
|
162
|
-
host: "127.0.0.1",
|
|
163
|
-
authToken: AUTH_TOKEN,
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
const received: CallbackPayload[] = [];
|
|
167
|
-
let deliverToRelay: (payload: CallbackPayload) => void = () => {};
|
|
168
|
-
|
|
169
|
-
const telegram = await startMockTelegram((payload) => deliverToRelay(payload));
|
|
170
|
-
let client: RelayClient | undefined;
|
|
171
|
-
|
|
172
|
-
try {
|
|
173
|
-
await relay.start();
|
|
174
|
-
const relayPort = (relay as unknown as { server: Server }).server.address();
|
|
175
|
-
const port = (relayPort as AddressInfo).port;
|
|
176
|
-
|
|
177
|
-
deliverToRelay = (payload) => {
|
|
178
|
-
relay.broadcastCallback(payload, false);
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
const callbacks: CallbackPayload[] = [];
|
|
182
|
-
const synchronized = new Promise<void>((resolve) => {
|
|
183
|
-
client = new RelayClient(
|
|
184
|
-
{
|
|
185
|
-
serverUrl: `ws://127.0.0.1:${port}`,
|
|
186
|
-
token: AUTH_TOKEN,
|
|
187
|
-
connectTimeout: 5000,
|
|
188
|
-
},
|
|
189
|
-
{
|
|
190
|
-
onCallback: (cb) => {
|
|
191
|
-
callbacks.push(cb);
|
|
192
|
-
received.push(cb);
|
|
193
|
-
},
|
|
194
|
-
onSynchronized: () => resolve(),
|
|
195
|
-
},
|
|
196
|
-
);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
// connect() must resolve once the server confirms authentication
|
|
200
|
-
await withTimeout(client.connect(), OVERALL_TIMEOUT_MS, "client.connect()");
|
|
201
|
-
expect(client.getState().state).toBe("connected");
|
|
202
|
-
|
|
203
|
-
// Live events only start after the synchronized marker
|
|
204
|
-
await withTimeout(synchronized, OVERALL_TIMEOUT_MS, "synchronized marker");
|
|
205
|
-
|
|
206
|
-
const res = await postToLoopback(
|
|
207
|
-
telegram.port,
|
|
208
|
-
"/telegram",
|
|
209
|
-
WEBHOOK_SECRET,
|
|
210
|
-
{
|
|
211
|
-
update_id: 999,
|
|
212
|
-
callback_query: {
|
|
213
|
-
id: "CBQ_TEST_001",
|
|
214
|
-
from: { id: 1234567890, is_bot: false, first_name: "MANOT", username: "manotlj" },
|
|
215
|
-
message: { message_id: 4797, chat: { id: 1234567890, type: "private" } },
|
|
216
|
-
data: "hi:test-uuid-1234",
|
|
217
|
-
},
|
|
218
|
-
},
|
|
219
|
-
);
|
|
220
|
-
expect(res.status).toBe(200);
|
|
221
|
-
|
|
222
|
-
await withTimeout(
|
|
223
|
-
new Promise<void>((resolve) => {
|
|
224
|
-
const check = setInterval(() => {
|
|
225
|
-
if (callbacks.length > 0) {
|
|
226
|
-
clearInterval(check);
|
|
227
|
-
resolve();
|
|
228
|
-
}
|
|
229
|
-
}, 10);
|
|
230
|
-
}),
|
|
231
|
-
OVERALL_TIMEOUT_MS,
|
|
232
|
-
"callback delivery",
|
|
233
|
-
);
|
|
234
|
-
|
|
235
|
-
const cb = callbacks[0];
|
|
236
|
-
expect(cb.action).toBe("hi");
|
|
237
|
-
expect(cb.targetId).toBe("test-uuid-1234");
|
|
238
|
-
expect(cb.userId).toBe(1234567890);
|
|
239
|
-
expect(cb.messageId).toBe(4797);
|
|
240
|
-
expect(cb.callbackQueryId).toBe("CBQ_TEST_001");
|
|
241
|
-
expect(cb.chatId).toBe(1234567890);
|
|
242
|
-
expect(cb.username).toBe("manotlj");
|
|
243
|
-
expect(received.length).toBe(1);
|
|
244
|
-
} finally {
|
|
245
|
-
// Always tear down what this test owns
|
|
246
|
-
client?.disconnect();
|
|
247
|
-
await relay.stop().catch(() => {});
|
|
248
|
-
await telegram.close();
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
it("accepts nobody when no token is configured", async () => {
|
|
253
|
-
// A relay without a token must not accept a public default secret:
|
|
254
|
-
// the server fails closed (packages/relay/src/server.ts).
|
|
255
|
-
const relay = new RelayServer({
|
|
256
|
-
port: 0,
|
|
257
|
-
host: "127.0.0.1",
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
let client: RelayClient | undefined;
|
|
261
|
-
|
|
262
|
-
try {
|
|
263
|
-
await relay.start();
|
|
264
|
-
const relayPort = (relay as unknown as { server: Server }).server.address();
|
|
265
|
-
const port = (relayPort as AddressInfo).port;
|
|
266
|
-
|
|
267
|
-
client = new RelayClient(
|
|
268
|
-
{
|
|
269
|
-
serverUrl: `ws://127.0.0.1:${port}`,
|
|
270
|
-
// The empty token is the dangerous case: without the
|
|
271
|
-
// fail-closed guard the server would accept it.
|
|
272
|
-
token: "",
|
|
273
|
-
connectTimeout: 5000,
|
|
274
|
-
},
|
|
275
|
-
{},
|
|
276
|
-
);
|
|
277
|
-
|
|
278
|
-
await expect(
|
|
279
|
-
withTimeout(client.connect(), OVERALL_TIMEOUT_MS, "client.connect()"),
|
|
280
|
-
).rejects.toThrow();
|
|
281
|
-
expect(client.getState().state).not.toBe("connected");
|
|
282
|
-
} finally {
|
|
283
|
-
client?.disconnect();
|
|
284
|
-
await relay.stop().catch(() => {});
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
it("rejects a webhook POST with the wrong secret", async () => {
|
|
289
|
-
const telegram = await startMockTelegram(() => {});
|
|
290
|
-
try {
|
|
291
|
-
const res = await postToLoopback(telegram.port, "/telegram", "wrong-secret", {
|
|
292
|
-
update_id: 1,
|
|
293
|
-
});
|
|
294
|
-
expect(res.status).toBe(403);
|
|
295
|
-
} finally {
|
|
296
|
-
await telegram.close();
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
});
|
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test";
|
|
2
|
-
import {
|
|
3
|
-
deriveRelayWsUrl,
|
|
4
|
-
describeRelayEndpoint,
|
|
5
|
-
isRelayWsUrl,
|
|
6
|
-
resolveRelayEndpoint,
|
|
7
|
-
} from "../src/relay-endpoint.js";
|
|
8
|
-
|
|
9
|
-
/** Build a fake key directory reader. */
|
|
10
|
-
function makeKeys(files: Record<string, string>) {
|
|
11
|
-
return (path: string): string | undefined => {
|
|
12
|
-
const name = path.split("/").pop() ?? path;
|
|
13
|
-
return Object.prototype.hasOwnProperty.call(files, name) ? files[name] : undefined;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
describe("deriveRelayWsUrl", () => {
|
|
18
|
-
test("maps an https webhook url to the relay websocket url", () => {
|
|
19
|
-
expect(deriveRelayWsUrl("https://webhook.bunchee.online/telegram")).toBe(
|
|
20
|
-
"wss://webhook.bunchee.online/ws",
|
|
21
|
-
);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test("documents the direct-app case: the relay listens on WS_PORT, not on the webhook port", () => {
|
|
25
|
-
// Behind a proxy (nginx `location /ws -> 127.0.0.1:8444`) the derived
|
|
26
|
-
// URL is correct. When the webhook URL addresses the app DIRECTLY the
|
|
27
|
-
// relay listens on WS_PORT (default 8444), so the derived URL is only
|
|
28
|
-
// a starting point - resolveRelayEndpoint() adds a note about it.
|
|
29
|
-
expect(deriveRelayWsUrl("http://127.0.0.1:8443/telegram")).toBe("ws://127.0.0.1:8443/ws");
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test("keeps a wss url on the same host", () => {
|
|
33
|
-
expect(deriveRelayWsUrl("wss://webhook.bunchee.online/ws")).toBe("wss://webhook.bunchee.online/ws");
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test("returns null for garbage", () => {
|
|
37
|
-
expect(deriveRelayWsUrl("not a url")).toBeNull();
|
|
38
|
-
expect(deriveRelayWsUrl("")).toBeNull();
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe("isRelayWsUrl", () => {
|
|
43
|
-
test("accepts ws and wss urls only", () => {
|
|
44
|
-
expect(isRelayWsUrl("ws://127.0.0.1:8444/ws")).toBe(true);
|
|
45
|
-
expect(isRelayWsUrl("wss://host/ws")).toBe(true);
|
|
46
|
-
expect(isRelayWsUrl("https://host/telegram")).toBe(false);
|
|
47
|
-
expect(isRelayWsUrl("")).toBe(false);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test("rejects urls that carry credentials or a query string", () => {
|
|
51
|
-
expect(isRelayWsUrl("wss://user:pass@host/ws")).toBe(false);
|
|
52
|
-
expect(isRelayWsUrl("wss://host/ws?token=secret")).toBe(false);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe("resolveRelayEndpoint", () => {
|
|
57
|
-
test("prefers the environment over the key files", () => {
|
|
58
|
-
const resolution = resolveRelayEndpoint({
|
|
59
|
-
env: { RELAY_WS_URL: "wss://from-env/ws", RELAY_AUTH_TOKEN: "env-token" },
|
|
60
|
-
keysDir: "/keys",
|
|
61
|
-
readFile: makeKeys({
|
|
62
|
-
"relay-ws-url.txt": "wss://from-file/ws",
|
|
63
|
-
"relay-auth-token.txt": "file-token",
|
|
64
|
-
}),
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
expect(resolution.url).toBe("wss://from-env/ws");
|
|
68
|
-
expect(resolution.urlSource).toBe("env RELAY_WS_URL");
|
|
69
|
-
expect(resolution.token).toBe("env-token");
|
|
70
|
-
expect(resolution.tokenSource).toBe("env RELAY_AUTH_TOKEN");
|
|
71
|
-
expect(resolution.missing).toEqual([]);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test("falls back to the dedicated key files", () => {
|
|
75
|
-
const resolution = resolveRelayEndpoint({
|
|
76
|
-
env: {},
|
|
77
|
-
keysDir: "/keys",
|
|
78
|
-
readFile: makeKeys({
|
|
79
|
-
"relay-ws-url.txt": "wss://from-file/ws",
|
|
80
|
-
"relay-auth-token.txt": "file-token",
|
|
81
|
-
}),
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
expect(resolution.url).toBe("wss://from-file/ws");
|
|
85
|
-
expect(resolution.urlSource).toBe("keys/relay-ws-url.txt");
|
|
86
|
-
expect(resolution.token).toBe("file-token");
|
|
87
|
-
expect(resolution.tokenSource).toBe("keys/relay-auth-token.txt");
|
|
88
|
-
expect(resolution.missing).toEqual([]);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test("derives the url from the telegram webhook url and the token from the webhook secret", () => {
|
|
92
|
-
const resolution = resolveRelayEndpoint({
|
|
93
|
-
env: {},
|
|
94
|
-
keysDir: "/keys",
|
|
95
|
-
readFile: makeKeys({
|
|
96
|
-
"telegram-webhook-url.txt": "https://webhook.bunchee.online/telegram",
|
|
97
|
-
"telegram-webhook-secret.txt": "shared-secret",
|
|
98
|
-
}),
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
expect(resolution.url).toBe("wss://webhook.bunchee.online/ws");
|
|
102
|
-
expect(resolution.urlSource).toBe("keys/telegram-webhook-url.txt (derived)");
|
|
103
|
-
expect(resolution.token).toBe("shared-secret");
|
|
104
|
-
expect(resolution.tokenSource).toBe("keys/telegram-webhook-secret.txt");
|
|
105
|
-
expect(resolution.missing).toEqual([]);
|
|
106
|
-
expect(resolution.notes).toEqual([]);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test("reports what is missing when nothing is configured", () => {
|
|
110
|
-
const resolution = resolveRelayEndpoint({
|
|
111
|
-
env: {},
|
|
112
|
-
keysDir: "/keys",
|
|
113
|
-
readFile: makeKeys({}),
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
expect(resolution.url).toBeNull();
|
|
117
|
-
expect(resolution.token).toBeNull();
|
|
118
|
-
expect(resolution.missing).toHaveLength(2);
|
|
119
|
-
expect(resolution.missing[0]).toContain("url");
|
|
120
|
-
expect(resolution.missing[1]).toContain("token");
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
test("treats a blank key file as missing", () => {
|
|
124
|
-
const resolution = resolveRelayEndpoint({
|
|
125
|
-
env: {},
|
|
126
|
-
keysDir: "/keys",
|
|
127
|
-
readFile: makeKeys({
|
|
128
|
-
"relay-ws-url.txt": " \n",
|
|
129
|
-
"relay-auth-token.txt": "",
|
|
130
|
-
}),
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
expect(resolution.url).toBeNull();
|
|
134
|
-
expect(resolution.token).toBeNull();
|
|
135
|
-
expect(resolution.missing).toHaveLength(2);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
test("ignores a key file that does not hold a websocket url", () => {
|
|
139
|
-
const resolution = resolveRelayEndpoint({
|
|
140
|
-
env: {},
|
|
141
|
-
keysDir: "/keys",
|
|
142
|
-
readFile: makeKeys({
|
|
143
|
-
"relay-ws-url.txt": "https://webhook.bunchee.online/telegram",
|
|
144
|
-
"telegram-webhook-url.txt": "https://webhook.bunchee.online/telegram",
|
|
145
|
-
}),
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
expect(resolution.url).toBe("wss://webhook.bunchee.online/ws");
|
|
149
|
-
expect(resolution.urlSource).toBe("keys/telegram-webhook-url.txt (derived)");
|
|
150
|
-
expect(resolution.missing.join(" ")).toContain(
|
|
151
|
-
"rejected source: keys/relay-ws-url.txt (not a ws:// or wss:// URL)",
|
|
152
|
-
);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
test("rejects an env url that carries credentials", () => {
|
|
156
|
-
const resolution = resolveRelayEndpoint({
|
|
157
|
-
env: { RELAY_WS_URL: "wss://user:pass@host/ws" },
|
|
158
|
-
keysDir: "/keys",
|
|
159
|
-
readFile: makeKeys({ "relay-ws-url.txt": "wss://from-file/ws" }),
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
expect(resolution.url).toBe("wss://from-file/ws");
|
|
163
|
-
expect(resolution.missing.join(" ")).toContain("rejected source: env RELAY_WS_URL");
|
|
164
|
-
// The rejected value must not be echoed back - it may hold a secret.
|
|
165
|
-
expect(resolution.missing.join(" ")).not.toContain("user:pass");
|
|
166
|
-
expect(describeRelayEndpoint(resolution)).not.toContain("user:pass");
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
test("warns when a remote host would be used over plaintext ws", () => {
|
|
170
|
-
const resolution = resolveRelayEndpoint({
|
|
171
|
-
env: { RELAY_WS_URL: "ws://relay.example.com/ws" },
|
|
172
|
-
keysDir: "/keys",
|
|
173
|
-
readFile: makeKeys({}),
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
expect(resolution.url).toBe("ws://relay.example.com/ws");
|
|
177
|
-
expect(resolution.notes.join(" ")).toContain("plaintext");
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
test("does not warn about a plaintext ws url on the loopback interface", () => {
|
|
181
|
-
const resolution = resolveRelayEndpoint({
|
|
182
|
-
env: { RELAY_WS_URL: "ws://127.0.0.1:8444/ws" },
|
|
183
|
-
keysDir: "/keys",
|
|
184
|
-
readFile: makeKeys({}),
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
expect(resolution.notes.join(" ")).not.toContain("plaintext");
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
test("never leaks the token in the description", () => {
|
|
191
|
-
const resolution = resolveRelayEndpoint({
|
|
192
|
-
env: {},
|
|
193
|
-
keysDir: "/keys",
|
|
194
|
-
readFile: makeKeys({
|
|
195
|
-
"relay-ws-url.txt": "wss://host/ws",
|
|
196
|
-
"relay-auth-token.txt": "super-secret-token",
|
|
197
|
-
}),
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
const description = describeRelayEndpoint(resolution);
|
|
201
|
-
expect(description).toContain("url from keys/relay-ws-url.txt");
|
|
202
|
-
expect(description).toContain("token from keys/relay-auth-token.txt");
|
|
203
|
-
expect(description).not.toContain("super-secret-token");
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
test("describes a missing endpoint without a secret", () => {
|
|
207
|
-
const resolution = resolveRelayEndpoint({ env: {}, keysDir: "/keys", readFile: makeKeys({}) });
|
|
208
|
-
const description = describeRelayEndpoint(resolution);
|
|
209
|
-
expect(description).toContain("url NOT resolved");
|
|
210
|
-
expect(description).toContain("token NOT resolved");
|
|
211
|
-
// The source list lives in `missing`; the description must not repeat it.
|
|
212
|
-
expect(description).not.toContain("looked at");
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
test("records a rejected env url so the operator can see why it was skipped", () => {
|
|
216
|
-
const resolution = resolveRelayEndpoint({
|
|
217
|
-
env: { RELAY_WS_URL: "https://host/telegram" },
|
|
218
|
-
keysDir: "/keys",
|
|
219
|
-
readFile: makeKeys({ "relay-ws-url.txt": "wss://from-file/ws" }),
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
expect(resolution.url).toBe("wss://from-file/ws");
|
|
223
|
-
expect(resolution.urlSource).toBe("keys/relay-ws-url.txt");
|
|
224
|
-
expect(resolution.missing.join(" ")).toContain("rejected source: env RELAY_WS_URL");
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
test("treats an unreadable key file as absent", () => {
|
|
228
|
-
const resolution = resolveRelayEndpoint({
|
|
229
|
-
env: {},
|
|
230
|
-
keysDir: "/keys",
|
|
231
|
-
readFile: () => {
|
|
232
|
-
throw new Error("EACCES");
|
|
233
|
-
},
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
expect(resolution.url).toBeNull();
|
|
237
|
-
expect(resolution.token).toBeNull();
|
|
238
|
-
expect(resolution.missing).toHaveLength(2);
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
test("resolves nothing when the keys directory does not exist", () => {
|
|
242
|
-
const resolution = resolveRelayEndpoint({
|
|
243
|
-
env: {},
|
|
244
|
-
keysDir: "/definitely/not/a/keys/dir",
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
expect(resolution.url).toBeNull();
|
|
248
|
-
expect(resolution.token).toBeNull();
|
|
249
|
-
expect(resolution.missing).toHaveLength(2);
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
test("trims a token that ends with CRLF", () => {
|
|
253
|
-
const resolution = resolveRelayEndpoint({
|
|
254
|
-
env: {},
|
|
255
|
-
keysDir: "/keys",
|
|
256
|
-
readFile: makeKeys({
|
|
257
|
-
"relay-ws-url.txt": "wss://host/ws",
|
|
258
|
-
"relay-auth-token.txt": "token-with-crlf\r\n",
|
|
259
|
-
}),
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
expect(resolution.token).toBe("token-with-crlf");
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
test("warns when the derived url points at a loopback host", () => {
|
|
266
|
-
const resolution = resolveRelayEndpoint({
|
|
267
|
-
env: {},
|
|
268
|
-
keysDir: "/keys",
|
|
269
|
-
readFile: makeKeys({
|
|
270
|
-
"telegram-webhook-url.txt": "http://127.0.0.1:8443/telegram",
|
|
271
|
-
}),
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
expect(resolution.url).toBe("ws://127.0.0.1:8443/ws");
|
|
275
|
-
expect(resolution.notes.join(" ")).toContain("WS_PORT");
|
|
276
|
-
expect(describeRelayEndpoint(resolution)).toContain("WS_PORT");
|
|
277
|
-
});
|
|
278
|
-
});
|