@blackbelt-technology/pi-dashboard-extension 0.7.0 → 0.9.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/.pi/skills/browser/SKILL.md +84 -29
- package/.pi/skills/browser/UPSTREAM.md +13 -1
- package/.pi/skills/browser/references/challenge.md +183 -0
- package/.pi/skills/browser/references/dashboard-relay.md +150 -0
- package/.pi/skills/browser/references/electron.agent.md +57 -0
- package/.pi/skills/browser/references/own-browser.md +305 -0
- package/.pi/skills/browser/references/web.agent.md +323 -0
- package/.pi/skills/browser/scripts/check-panerelay.sh +157 -0
- package/.pi/skills/doctor/SKILL.md +4 -9
- package/.pi/skills/doctor/_lib/checks.ts +133 -54
- package/.pi/skills/doctor/_lib/derive-tokens.ts +5 -0
- package/.pi/skills/doctor/modules/apple-tools.knowledge.hash +1 -0
- package/.pi/skills/doctor/modules/apple-tools.md +52 -0
- package/.pi/skills/doctor/modules/mcp-builtin.knowledge.hash +1 -0
- package/.pi/skills/doctor/modules/mcp-builtin.md +61 -0
- package/.pi/skills/doctor/modules/oauth-redirect-base.knowledge.hash +1 -0
- package/.pi/skills/doctor/modules/oauth-redirect-base.md +71 -0
- package/.pi/skills/doctor/modules/pi-resolution.knowledge.hash +1 -1
- package/.pi/skills/doctor/modules/pi-resolution.md +21 -1
- package/.pi/skills/doctor/modules/plugins-bridges.md +14 -1
- package/.pi/skills/pi-dashboard/SKILL.md +10 -3
- package/.pi/skills/pi-dashboard/references/api-reference.agent.md +69 -0
- package/.pi/skills/pi-dashboard/scripts/dashboard-bus.ts +4 -4
- package/.pi/skills/project-init/SKILL.md +41 -34
- package/.pi/skills/project-init/profiles/coding/AGENTS.md.tmpl +0 -23
- package/.pi/skills/project-init/profiles/docs/profile.json +1 -1
- package/README.md +19 -0
- package/agents/DoxTriage.md +80 -0
- package/package.json +30 -16
- package/src/ask-user-tool.ts +4 -0
- package/src/auto-session-namer.ts +486 -70
- package/src/autostart-guard.ts +99 -0
- package/src/autostart-lock.ts +258 -0
- package/src/bridge-activation.ts +26 -0
- package/src/bridge-context.ts +106 -23
- package/src/bridge-default-model-gate.ts +38 -0
- package/src/bridge-polling.ts +148 -0
- package/src/bridge-ticket-client.ts +105 -0
- package/src/bridge.ts +1760 -350
- package/src/canvas-tool.ts +5 -0
- package/src/command-handler.ts +392 -71
- package/src/connect-target.ts +130 -0
- package/src/connection.ts +846 -17
- package/src/custom-entry-forward.ts +92 -0
- package/src/endpoint-resolution.ts +253 -0
- package/src/event-forwarder.ts +42 -0
- package/src/extension-identity.ts +59 -0
- package/src/flow-event-wiring.ts +125 -3
- package/src/followup-buffer.ts +217 -0
- package/src/git-dir-watcher.ts +79 -0
- package/src/git-poll.ts +45 -12
- package/src/git-probe-scheduler.ts +119 -0
- package/src/git-tracker.ts +284 -0
- package/src/instance-verification.ts +156 -0
- package/src/local-token-header.ts +44 -0
- package/src/mcp-token-delivery.ts +147 -0
- package/src/message-update-coalescer.ts +340 -0
- package/src/model-refresh.ts +95 -0
- package/src/model-tracker.ts +118 -35
- package/src/notify-proxy.ts +36 -0
- package/src/path-gate/decide.ts +149 -0
- package/src/path-gate/grant-cache.ts +71 -0
- package/src/path-gate/grant-link.ts +108 -0
- package/src/path-gate/handler.ts +307 -0
- package/src/path-gate/index.ts +155 -0
- package/src/path-gate/resolve.ts +126 -0
- package/src/path-gate/roots.ts +137 -0
- package/src/path-gate/suppression.ts +27 -0
- package/src/pending-prompt-emitter.ts +59 -0
- package/src/pi-env.d.ts +6 -10
- package/src/pi-retry-settings.ts +91 -0
- package/src/plugin-request-client.ts +114 -0
- package/src/poll-cost.ts +40 -0
- package/src/pr-status.ts +338 -0
- package/src/process-metrics.ts +77 -1
- package/src/process-scan-scheduler.ts +137 -0
- package/src/process-scanner.ts +226 -247
- package/src/project-init/dox-kb-config.ts +3 -0
- package/src/project-init/scaffold.ts +1 -4
- package/src/project-init/seed-doctrine.ts +23 -60
- package/src/prompt-bus.ts +13 -0
- package/src/provider-register.ts +92 -21
- package/src/remote-registration-gate.ts +102 -0
- package/src/retry-tracker.ts +258 -86
- package/src/role-manager.ts +38 -91
- package/src/role-model-tools.ts +44 -3
- package/src/server-auto-start.ts +331 -20
- package/src/server-launcher.ts +70 -34
- package/src/server-pin-store.ts +92 -0
- package/src/session-move.ts +275 -0
- package/src/session-sync.ts +75 -20
- package/src/slash-dispatch.ts +66 -81
- package/src/subagent-fanout-admission.ts +234 -0
- package/src/subagent-forward-sites.ts +69 -0
- package/src/subagent-frame-buffer.ts +24 -3
- package/src/subagent-frame-strip.ts +109 -0
- package/src/subagent-saturation.ts +196 -0
- package/src/subagent-tick-throttle.ts +250 -0
- package/src/terminal-reload.ts +298 -0
- package/src/transcript-backfill.ts +151 -0
- package/src/transport-diagnostics.ts +76 -0
- package/src/tui-prompt-adapter.ts +13 -1
- package/src/turn-actionability.ts +20 -0
- package/src/ui-stale-guard.ts +58 -0
- package/src/usage-drain.ts +167 -0
- package/src/vcs-info.ts +261 -63
- package/.pi/skills/doctor/AGENTS.md +0 -27
- package/.pi/skills/project-init/dox-doctrine.md +0 -104
- package/src/AGENTS.md +0 -57
- package/src/__tests__/abort-latch.test.ts +0 -97
- package/src/__tests__/agent-settled.test.ts +0 -82
- package/src/__tests__/artifact-roots.test.ts +0 -83
- package/src/__tests__/ask-user-attachments.test.ts +0 -106
- package/src/__tests__/ask-user-schema-discriminator.test.ts +0 -141
- package/src/__tests__/ask-user-tool.test.ts +0 -571
- package/src/__tests__/auto-session-namer.test.ts +0 -339
- package/src/__tests__/bridge-default-model-apply.test.ts +0 -242
- package/src/__tests__/bridge-default-model-gate.test.ts +0 -50
- package/src/__tests__/bridge-entry-id-pi-070.test.ts +0 -174
- package/src/__tests__/bridge-followup-chat-order.test.ts +0 -215
- package/src/__tests__/bridge-followup-multi-entry.test.ts +0 -202
- package/src/__tests__/bridge-followup-mutation.test.ts +0 -217
- package/src/__tests__/bridge-followup-queue-drain.test.ts +0 -266
- package/src/__tests__/bridge-hasui-flip.test.ts +0 -109
- package/src/__tests__/bridge-no-queue-mutation.test.ts +0 -112
- package/src/__tests__/bridge-plugin-emit-event.test.ts +0 -44
- package/src/__tests__/bridge-queue-update-forward.test.ts +0 -77
- package/src/__tests__/bridge-resume-disconnect.test.ts +0 -333
- package/src/__tests__/bridge-shadow-queue-gate.test.ts +0 -299
- package/src/__tests__/bridge-shutdown-reset.test.ts +0 -159
- package/src/__tests__/bridge-slash-command-routing.test.ts +0 -458
- package/src/__tests__/bridge-stop-after-turn.test.ts +0 -72
- package/src/__tests__/bridge-system-followup.test.ts +0 -163
- package/src/__tests__/bridge-thinking-level-select.test.ts +0 -68
- package/src/__tests__/browser-skill-registered.test.ts +0 -84
- package/src/__tests__/build-provider-catalogue.test.ts +0 -210
- package/src/__tests__/command-handler.test.ts +0 -1180
- package/src/__tests__/commit-draft.test.ts +0 -100
- package/src/__tests__/connection-dropped-frames.test.ts +0 -78
- package/src/__tests__/connection-suppress-auto-start.test.ts +0 -97
- package/src/__tests__/connection.test.ts +0 -344
- package/src/__tests__/credentials-updated.test.ts +0 -26
- package/src/__tests__/custom-provider-apikey-roundtrip.test.ts +0 -128
- package/src/__tests__/cwd-missing-probe.test.ts +0 -82
- package/src/__tests__/dashboard-commands-shipped.test.ts +0 -53
- package/src/__tests__/dashboard-context-injector.test.ts +0 -190
- package/src/__tests__/dashboard-default-adapter.test.ts +0 -77
- package/src/__tests__/dev-build.test.ts +0 -79
- package/src/__tests__/doctor/checks.test.ts +0 -121
- package/src/__tests__/doctor/modules.test.ts +0 -64
- package/src/__tests__/doctor/provenance-hash.test.ts +0 -94
- package/src/__tests__/doctor/router.test.ts +0 -143
- package/src/__tests__/empty-actionable-guard-config.test.ts +0 -32
- package/src/__tests__/empty-actionable-guard.test.ts +0 -73
- package/src/__tests__/enrich-model-metadata.test.ts +0 -222
- package/src/__tests__/event-forwarder.test.ts +0 -119
- package/src/__tests__/extension-slash-command-detection.test.ts +0 -143
- package/src/__tests__/filter-enabled-models.test.ts +0 -151
- package/src/__tests__/fixtures/turn-actionability-fixtures.ts +0 -69
- package/src/__tests__/fork-entryid-timing.test.ts +0 -88
- package/src/__tests__/git-info-status.test.ts +0 -73
- package/src/__tests__/git-link-builder.test.ts +0 -102
- package/src/__tests__/git-poll.test.ts +0 -69
- package/src/__tests__/markdown-image-inliner.test.ts +0 -392
- package/src/__tests__/model-resolve.test.ts +0 -379
- package/src/__tests__/multiselect-dashboard-routing.test.ts +0 -203
- package/src/__tests__/multiselect-list.test.ts +0 -137
- package/src/__tests__/multiselect-polyfill.test.ts +0 -92
- package/src/__tests__/no-session-replacement-calls.test.ts +0 -99
- package/src/__tests__/no-tui-multiselect-arm-regression.test.ts +0 -81
- package/src/__tests__/openspec-activity-detector.test.ts +0 -337
- package/src/__tests__/openspec-cli-shim.test.ts +0 -145
- package/src/__tests__/openspec-poller.test.ts +0 -124
- package/src/__tests__/pi-version-tracker.test.ts +0 -109
- package/src/__tests__/process-metrics.test.ts +0 -47
- package/src/__tests__/process-scanner-kill.test.ts +0 -61
- package/src/__tests__/process-scanner.test.ts +0 -292
- package/src/__tests__/project-init-detect-stack.test.ts +0 -61
- package/src/__tests__/project-init-dox-kb-config.test.ts +0 -53
- package/src/__tests__/project-init-profiles.test.ts +0 -84
- package/src/__tests__/project-init-scaffold.test.ts +0 -139
- package/src/__tests__/project-init-seed-doctrine.test.ts +0 -100
- package/src/__tests__/project-trust.test.ts +0 -92
- package/src/__tests__/prompt-bus-wiring.test.ts +0 -791
- package/src/__tests__/prompt-bus.test.ts +0 -513
- package/src/__tests__/prompt-expander.test.ts +0 -398
- package/src/__tests__/provider-register-native-models.test.ts +0 -182
- package/src/__tests__/provider-register-reload.test.ts +0 -498
- package/src/__tests__/provider-register-thinking-levels.test.ts +0 -104
- package/src/__tests__/retry-tracker.test.ts +0 -152
- package/src/__tests__/role-manager.test.ts +0 -585
- package/src/__tests__/role-model-tools-registry-readiness.test.ts +0 -114
- package/src/__tests__/role-model-tools.test.ts +0 -229
- package/src/__tests__/search-files-completeness.test.ts +0 -111
- package/src/__tests__/search-files-ranking.test.ts +0 -168
- package/src/__tests__/server-auto-start.test.ts +0 -375
- package/src/__tests__/server-launcher-launch.test.ts +0 -96
- package/src/__tests__/server-launcher.test.ts +0 -101
- package/src/__tests__/server-probe.test.ts +0 -25
- package/src/__tests__/session-switch.test.ts +0 -139
- package/src/__tests__/session-sync.test.ts +0 -243
- package/src/__tests__/single-derivation-guard.test.ts +0 -39
- package/src/__tests__/source-detector.test.ts +0 -88
- package/src/__tests__/stats-extractor.test.ts +0 -92
- package/src/__tests__/subagent-frame-buffer.test.ts +0 -239
- package/src/__tests__/tool-result-image-inliner.test.ts +0 -206
- package/src/__tests__/tui-prompt-adapter.test.ts +0 -213
- package/src/__tests__/turn-actionability.test.ts +0 -86
- package/src/__tests__/ui-decorators.test.ts +0 -309
- package/src/__tests__/ui-modules.test.ts +0 -293
- package/src/__tests__/vcs-info.test.ts +0 -265
- package/src/__tests__/visibility-intent.test.ts +0 -43
- package/src/__tests__/watchdog.test.ts +0 -161
- package/src/abort-latch.ts.AGENTS.md +0 -3
- package/src/agent-settled.ts +0 -72
- package/src/agent-settled.ts.AGENTS.md +0 -3
- package/src/artifact-roots.ts.AGENTS.md +0 -3
- package/src/ask-user-attachments.ts.AGENTS.md +0 -3
- package/src/ask-user-tool.ts.AGENTS.md +0 -3
- package/src/auto-session-namer.ts.AGENTS.md +0 -3
- package/src/bridge-context.ts.AGENTS.md +0 -3
- package/src/bridge-default-model-gate.ts.AGENTS.md +0 -3
- package/src/bridge.ts.AGENTS.md +0 -3
- package/src/command-handler.ts.AGENTS.md +0 -3
- package/src/commit-draft-agent.ts.AGENTS.md +0 -3
- package/src/commit-draft.ts.AGENTS.md +0 -3
- package/src/connection.ts.AGENTS.md +0 -3
- package/src/dashboard-context-injector.ts.AGENTS.md +0 -3
- package/src/dashboard-default-adapter.ts.AGENTS.md +0 -3
- package/src/dev-build.ts.AGENTS.md +0 -3
- package/src/empty-actionable-guard-config.ts.AGENTS.md +0 -3
- package/src/empty-actionable-guard.ts.AGENTS.md +0 -3
- package/src/event-forwarder.ts.AGENTS.md +0 -3
- package/src/flow-event-wiring.ts.AGENTS.md +0 -3
- package/src/git-link-builder.ts.AGENTS.md +0 -3
- package/src/git-poll.ts.AGENTS.md +0 -3
- package/src/hasui-flip.ts.AGENTS.md +0 -3
- package/src/markdown-image-inliner.ts.AGENTS.md +0 -3
- package/src/model-tracker.ts.AGENTS.md +0 -3
- package/src/multiselect-decode.ts.AGENTS.md +0 -3
- package/src/multiselect-list.ts.AGENTS.md +0 -3
- package/src/multiselect-polyfill.ts.AGENTS.md +0 -3
- package/src/openspec-cli-shim.ts.AGENTS.md +0 -7
- package/src/process-metrics.ts.AGENTS.md +0 -3
- package/src/process-scanner.ts.AGENTS.md +0 -3
- package/src/project-init/AGENTS.md +0 -12
- package/src/project-trust.ts.AGENTS.md +0 -3
- package/src/prompt-bus.ts.AGENTS.md +0 -3
- package/src/prompt-expander.ts.AGENTS.md +0 -3
- package/src/provider-register.ts.AGENTS.md +0 -3
- package/src/retry-tracker.ts.AGENTS.md +0 -3
- package/src/role-manager.ts.AGENTS.md +0 -3
- package/src/role-model-tools.ts.AGENTS.md +0 -3
- package/src/server-auto-start.ts.AGENTS.md +0 -3
- package/src/server-launcher.ts.AGENTS.md +0 -3
- package/src/session-sync.ts.AGENTS.md +0 -3
- package/src/slash-dispatch.ts.AGENTS.md +0 -3
- package/src/source-detector.ts.AGENTS.md +0 -3
- package/src/subagent-frame-buffer.ts.AGENTS.md +0 -3
- package/src/tool-result-image-inliner.ts.AGENTS.md +0 -3
- package/src/tui-prompt-adapter.ts.AGENTS.md +0 -3
- package/src/turn-actionability.ts.AGENTS.md +0 -3
- package/src/ui-modules.ts.AGENTS.md +0 -3
- package/src/vcs-info.ts.AGENTS.md +0 -3
- package/src/visibility-intent.ts.AGENTS.md +0 -3
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for the commit-draft fallback ladder (fork-subagent → diff-only → stub)
|
|
3
|
-
* using a stub agent. Verifies timeout degrades to a fallback and never hangs.
|
|
4
|
-
* See change: add-session-uncommitted-indicator-and-commit.
|
|
5
|
-
*/
|
|
6
|
-
import { describe, expect, it, vi } from "vitest";
|
|
7
|
-
import {
|
|
8
|
-
clampDiff,
|
|
9
|
-
draftCommitMessage,
|
|
10
|
-
sanitizeDraft,
|
|
11
|
-
stubMessage,
|
|
12
|
-
} from "../commit-draft.js";
|
|
13
|
-
|
|
14
|
-
describe("stubMessage", () => {
|
|
15
|
-
it("single file", () => expect(stubMessage(["a.ts"])).toBe("chore: update a.ts"));
|
|
16
|
-
it("many files lists them", () => {
|
|
17
|
-
const m = stubMessage(["a.ts", "b.ts"]);
|
|
18
|
-
expect(m).toContain("chore: update 2 files");
|
|
19
|
-
expect(m).toContain("- a.ts");
|
|
20
|
-
});
|
|
21
|
-
it("empty", () => expect(stubMessage([])).toBe("chore: update files"));
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe("clampDiff / sanitizeDraft", () => {
|
|
25
|
-
it("clamps oversized diffs", () => {
|
|
26
|
-
const out = clampDiff("x".repeat(100), 10);
|
|
27
|
-
expect(out).toContain("[diff truncated at 10 bytes]");
|
|
28
|
-
});
|
|
29
|
-
it("strips code fences", () => {
|
|
30
|
-
expect(sanitizeDraft("```\nfeat: x\n```")).toBe("feat: x");
|
|
31
|
-
expect(sanitizeDraft("```diff\nfeat: y\n```")).toBe("feat: y");
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe("draftCommitMessage ladder", () => {
|
|
36
|
-
const buildDiff = () => "diff --git a/x b/x";
|
|
37
|
-
|
|
38
|
-
it("rung 1: fork-subagent with context", async () => {
|
|
39
|
-
const runAgent = vi.fn(async (_seed: string) => "feat: add thing");
|
|
40
|
-
const res = await draftCommitMessage({
|
|
41
|
-
files: ["x.ts"], buildDiff, buildContext: () => "ctx", runAgent,
|
|
42
|
-
});
|
|
43
|
-
expect(res).toEqual({ message: "feat: add thing", source: "fork-subagent" });
|
|
44
|
-
expect(runAgent.mock.calls[0][0]).toContain("Session context");
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("rung 2: diff-only when no context", async () => {
|
|
48
|
-
const runAgent = vi.fn(async (_seed: string) => "fix: y");
|
|
49
|
-
const res = await draftCommitMessage({
|
|
50
|
-
files: ["x.ts"], buildDiff, buildContext: () => undefined, runAgent,
|
|
51
|
-
});
|
|
52
|
-
expect(res).toEqual({ message: "fix: y", source: "diff-only" });
|
|
53
|
-
expect(runAgent.mock.calls[0][0]).not.toContain("Session context");
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("rung 2: falls to diff-only when the context rung throws", async () => {
|
|
57
|
-
const runAgent = vi.fn()
|
|
58
|
-
.mockRejectedValueOnce(new Error("boom"))
|
|
59
|
-
.mockResolvedValueOnce("chore: recovered");
|
|
60
|
-
const res = await draftCommitMessage({
|
|
61
|
-
files: ["x.ts"], buildDiff, buildContext: () => "ctx", runAgent,
|
|
62
|
-
});
|
|
63
|
-
expect(res.source).toBe("diff-only");
|
|
64
|
-
expect(res.message).toBe("chore: recovered");
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("rung 3: stub when no agent", async () => {
|
|
68
|
-
const res = await draftCommitMessage({ files: ["x.ts"], buildDiff });
|
|
69
|
-
expect(res.source).toBe("stub");
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("rung 3: stub when the agent always fails", async () => {
|
|
73
|
-
const runAgent = vi.fn(async () => { throw new Error("nope"); });
|
|
74
|
-
const res = await draftCommitMessage({
|
|
75
|
-
files: ["a.ts", "b.ts"], buildDiff, buildContext: () => "ctx", runAgent,
|
|
76
|
-
});
|
|
77
|
-
expect(res.source).toBe("stub");
|
|
78
|
-
expect(res.message).toContain("2 files");
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("timeout degrades to a fallback (never hangs)", async () => {
|
|
82
|
-
// Context rung hangs; diff-only resolves fast → diff-only wins.
|
|
83
|
-
const runAgent = vi.fn()
|
|
84
|
-
.mockImplementationOnce(() => new Promise(() => {})) // never resolves
|
|
85
|
-
.mockResolvedValueOnce("fix: after-timeout");
|
|
86
|
-
const res = await draftCommitMessage({
|
|
87
|
-
files: ["x.ts"], buildDiff, buildContext: () => "ctx", runAgent, timeoutMs: 20,
|
|
88
|
-
});
|
|
89
|
-
expect(res.source).toBe("diff-only");
|
|
90
|
-
expect(res.message).toBe("fix: after-timeout");
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it("both rungs time out → stub", async () => {
|
|
94
|
-
const runAgent = vi.fn(() => new Promise<string>(() => {}));
|
|
95
|
-
const res = await draftCommitMessage({
|
|
96
|
-
files: ["x.ts"], buildDiff, buildContext: () => "ctx", runAgent, timeoutMs: 20,
|
|
97
|
-
});
|
|
98
|
-
expect(res.source).toBe("stub");
|
|
99
|
-
});
|
|
100
|
-
});
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Task 3.4 (bridge side) for change: fix-stuck-tool-card-on-dropped-event.
|
|
3
|
-
*
|
|
4
|
-
* The bridge buffers outgoing messages while the WS is not OPEN in a bounded
|
|
5
|
-
* ring; on overflow `buffer.shift()` evicts the oldest. This suite proves the
|
|
6
|
-
* eviction is now COUNTED (`getDroppedBufferedCount`) and rate-limited-LOGGED
|
|
7
|
-
* with `hop:"bridge→server"` + the dropped message type.
|
|
8
|
-
*/
|
|
9
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
10
|
-
import { ConnectionManager } from "../connection.js";
|
|
11
|
-
|
|
12
|
-
class MockWebSocket {
|
|
13
|
-
static instances: MockWebSocket[] = [];
|
|
14
|
-
readyState = 0;
|
|
15
|
-
onopen: (() => void) | null = null;
|
|
16
|
-
onclose: (() => void) | null = null;
|
|
17
|
-
onmessage: ((ev: { data: string }) => void) | null = null;
|
|
18
|
-
onerror: ((ev: unknown) => void) | null = null;
|
|
19
|
-
constructor(public url: string) {
|
|
20
|
-
MockWebSocket.instances.push(this);
|
|
21
|
-
}
|
|
22
|
-
send() {}
|
|
23
|
-
close() {
|
|
24
|
-
this.readyState = 3;
|
|
25
|
-
this.onclose?.();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
describe("ConnectionManager dropped-frame instrumentation", () => {
|
|
30
|
-
beforeEach(() => {
|
|
31
|
-
MockWebSocket.instances = [];
|
|
32
|
-
vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
33
|
-
});
|
|
34
|
-
afterEach(() => {
|
|
35
|
-
vi.restoreAllMocks();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("counts each ring-buffer eviction on overflow", () => {
|
|
39
|
-
const cm = new ConnectionManager({
|
|
40
|
-
url: "ws://localhost:9999",
|
|
41
|
-
WebSocketImpl: MockWebSocket as any,
|
|
42
|
-
maxBufferSize: 10,
|
|
43
|
-
});
|
|
44
|
-
// Never connect → everything buffers. 15 sends over a cap of 10 → 5 evicted.
|
|
45
|
-
for (let i = 0; i < 15; i++) {
|
|
46
|
-
cm.send({ type: "event_forward", sessionId: "s1", event: { i } });
|
|
47
|
-
}
|
|
48
|
-
expect(cm.getDroppedBufferedCount()).toBe(5);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it("starts at zero and stays zero under the cap", () => {
|
|
52
|
-
const cm = new ConnectionManager({
|
|
53
|
-
url: "ws://localhost:9999",
|
|
54
|
-
WebSocketImpl: MockWebSocket as any,
|
|
55
|
-
maxBufferSize: 10,
|
|
56
|
-
});
|
|
57
|
-
for (let i = 0; i < 10; i++) cm.send({ type: "event_forward", event: { i } });
|
|
58
|
-
expect(cm.getDroppedBufferedCount()).toBe(0);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("logs a rate-limited warning with hop + dropped message type", () => {
|
|
62
|
-
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
63
|
-
const cm = new ConnectionManager({
|
|
64
|
-
url: "ws://localhost:9999",
|
|
65
|
-
WebSocketImpl: MockWebSocket as any,
|
|
66
|
-
maxBufferSize: 2,
|
|
67
|
-
});
|
|
68
|
-
// Fill then overflow. The oldest evicted message is an `event_forward`.
|
|
69
|
-
for (let i = 0; i < 6; i++) {
|
|
70
|
-
cm.send({ type: "event_forward", sessionId: "s1", event: { i } });
|
|
71
|
-
}
|
|
72
|
-
const warns = warnSpy.mock.calls.map((c) => String(c[0])).filter((m) => m.includes("dropped buffered message"));
|
|
73
|
-
// Rate-limited: at most one warning inside the window despite 4 evictions.
|
|
74
|
-
expect(warns.length).toBe(1);
|
|
75
|
-
expect(warns[0]).toContain("hop=bridge→server");
|
|
76
|
-
expect(warns[0]).toContain("droppedType=event_forward");
|
|
77
|
-
});
|
|
78
|
-
});
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for the auto-start suppression window driven by `server_restarting`.
|
|
3
|
-
* See change: fix-restart-bridge-auto-start-race.
|
|
4
|
-
*/
|
|
5
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
6
|
-
import { ConnectionManager } from "../connection.js";
|
|
7
|
-
import { autoStartServer, type AutoStartDeps } from "../server-auto-start.js";
|
|
8
|
-
|
|
9
|
-
describe("ConnectionManager.pauseAutoStart", () => {
|
|
10
|
-
let cm: ConnectionManager;
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
cm = new ConnectionManager({
|
|
14
|
-
url: "ws://localhost:9999",
|
|
15
|
-
WebSocketImpl: class FakeWS { constructor() { /* never connects */ } onopen?: any; onmessage?: any; onclose?: any; onerror?: any; close() { /* no-op */ } },
|
|
16
|
-
watchdogTimeout: 0,
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("returns false when no pause has been issued", () => {
|
|
21
|
-
expect(cm.shouldSuppressAutoStart()).toBe(false);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it("returns true within the requested window", () => {
|
|
25
|
-
cm.pauseAutoStart(5000);
|
|
26
|
-
expect(cm.shouldSuppressAutoStart()).toBe(true);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("returns false after the window expires", async () => {
|
|
30
|
-
vi.useFakeTimers();
|
|
31
|
-
cm.pauseAutoStart(100);
|
|
32
|
-
expect(cm.shouldSuppressAutoStart()).toBe(true);
|
|
33
|
-
vi.advanceTimersByTime(150);
|
|
34
|
-
expect(cm.shouldSuppressAutoStart()).toBe(false);
|
|
35
|
-
vi.useRealTimers();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("ignores non-positive durations", () => {
|
|
39
|
-
cm.pauseAutoStart(0);
|
|
40
|
-
expect(cm.shouldSuppressAutoStart()).toBe(false);
|
|
41
|
-
cm.pauseAutoStart(-1000);
|
|
42
|
-
expect(cm.shouldSuppressAutoStart()).toBe(false);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("only extends the window — overlapping pauses don't shrink it", () => {
|
|
46
|
-
vi.useFakeTimers();
|
|
47
|
-
cm.pauseAutoStart(10_000);
|
|
48
|
-
cm.pauseAutoStart(100); // shorter — must not shrink
|
|
49
|
-
vi.advanceTimersByTime(500);
|
|
50
|
-
expect(cm.shouldSuppressAutoStart()).toBe(true);
|
|
51
|
-
vi.useRealTimers();
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe("autoStartServer respects shouldSuppressAutoStart", () => {
|
|
56
|
-
function makeDeps(overrides: Partial<AutoStartDeps> = {}): AutoStartDeps {
|
|
57
|
-
return {
|
|
58
|
-
discoverDashboard: vi.fn().mockResolvedValue([]),
|
|
59
|
-
isDashboardRunning: vi.fn().mockResolvedValue({ running: false }),
|
|
60
|
-
launchServer: vi.fn().mockResolvedValue({ success: true, message: "ok" }),
|
|
61
|
-
notify: vi.fn(),
|
|
62
|
-
...overrides,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const baseConfig = { piPort: 9999, port: 8000, autoStart: true };
|
|
67
|
-
|
|
68
|
-
it("skips launchServer while suppression is active", async () => {
|
|
69
|
-
const deps = makeDeps({ shouldSuppressAutoStart: () => true });
|
|
70
|
-
const result = await autoStartServer(baseConfig, deps);
|
|
71
|
-
expect(deps.launchServer).not.toHaveBeenCalled();
|
|
72
|
-
expect(result.server).toBeUndefined();
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it("still runs discovery + health check when suppressed", async () => {
|
|
76
|
-
const deps = makeDeps({
|
|
77
|
-
shouldSuppressAutoStart: () => true,
|
|
78
|
-
isDashboardRunning: vi.fn().mockResolvedValue({ running: true }),
|
|
79
|
-
});
|
|
80
|
-
const result = await autoStartServer(baseConfig, deps);
|
|
81
|
-
// Health check found the orchestrator-spawned server — return it.
|
|
82
|
-
expect(result.server).toEqual({ host: "localhost", port: 8000, piPort: 9999 });
|
|
83
|
-
expect(deps.launchServer).not.toHaveBeenCalled();
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it("calls launchServer normally when not suppressed", async () => {
|
|
87
|
-
const deps = makeDeps({ shouldSuppressAutoStart: () => false });
|
|
88
|
-
await autoStartServer(baseConfig, deps);
|
|
89
|
-
expect(deps.launchServer).toHaveBeenCalledTimes(1);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("calls launchServer when no predicate is provided (back-compat)", async () => {
|
|
93
|
-
const deps = makeDeps(); // no shouldSuppressAutoStart
|
|
94
|
-
await autoStartServer(baseConfig, deps);
|
|
95
|
-
expect(deps.launchServer).toHaveBeenCalledTimes(1);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
@@ -1,344 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
import { ConnectionManager } from "../connection.js";
|
|
3
|
-
|
|
4
|
-
// Mock WebSocket
|
|
5
|
-
class MockWebSocket {
|
|
6
|
-
static instances: MockWebSocket[] = [];
|
|
7
|
-
readyState = 0; // CONNECTING
|
|
8
|
-
onopen: (() => void) | null = null;
|
|
9
|
-
onclose: (() => void) | null = null;
|
|
10
|
-
onmessage: ((ev: { data: string }) => void) | null = null;
|
|
11
|
-
onerror: ((ev: unknown) => void) | null = null;
|
|
12
|
-
sentMessages: string[] = [];
|
|
13
|
-
|
|
14
|
-
constructor(public url: string) {
|
|
15
|
-
MockWebSocket.instances.push(this);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
send(data: string) {
|
|
19
|
-
this.sentMessages.push(data);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
close() {
|
|
23
|
-
this.readyState = 3; // CLOSED
|
|
24
|
-
this.onclose?.();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
simulateOpen() {
|
|
28
|
-
this.readyState = 1; // OPEN
|
|
29
|
-
this.onopen?.();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
simulateClose() {
|
|
33
|
-
this.readyState = 3;
|
|
34
|
-
this.onclose?.();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
simulateMessage(data: string) {
|
|
38
|
-
this.onmessage?.({ data });
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
describe("ConnectionManager", () => {
|
|
43
|
-
beforeEach(() => {
|
|
44
|
-
MockWebSocket.instances = [];
|
|
45
|
-
vi.useFakeTimers();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("should connect to the configured URL", () => {
|
|
49
|
-
const cm = new ConnectionManager({
|
|
50
|
-
url: "ws://localhost:9999",
|
|
51
|
-
WebSocketImpl: MockWebSocket as any,
|
|
52
|
-
});
|
|
53
|
-
cm.connect();
|
|
54
|
-
|
|
55
|
-
expect(MockWebSocket.instances).toHaveLength(1);
|
|
56
|
-
expect(MockWebSocket.instances[0].url).toBe("ws://localhost:9999");
|
|
57
|
-
cm.disconnect();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("should send buffered messages after connecting", () => {
|
|
61
|
-
const cm = new ConnectionManager({
|
|
62
|
-
url: "ws://localhost:9999",
|
|
63
|
-
WebSocketImpl: MockWebSocket as any,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
cm.send({ type: "session_heartbeat", sessionId: "s1" });
|
|
67
|
-
cm.connect();
|
|
68
|
-
|
|
69
|
-
const ws = MockWebSocket.instances[0];
|
|
70
|
-
ws.simulateOpen();
|
|
71
|
-
|
|
72
|
-
expect(ws.sentMessages).toHaveLength(1);
|
|
73
|
-
expect(JSON.parse(ws.sentMessages[0]).type).toBe("session_heartbeat");
|
|
74
|
-
cm.disconnect();
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it("should reconnect with exponential backoff", async () => {
|
|
78
|
-
const cm = new ConnectionManager({
|
|
79
|
-
url: "ws://localhost:9999",
|
|
80
|
-
WebSocketImpl: MockWebSocket as any,
|
|
81
|
-
});
|
|
82
|
-
cm.connect();
|
|
83
|
-
|
|
84
|
-
const ws1 = MockWebSocket.instances[0];
|
|
85
|
-
ws1.simulateOpen();
|
|
86
|
-
ws1.simulateClose();
|
|
87
|
-
|
|
88
|
-
// First reconnect: 1s
|
|
89
|
-
expect(MockWebSocket.instances).toHaveLength(1);
|
|
90
|
-
vi.advanceTimersByTime(1000);
|
|
91
|
-
expect(MockWebSocket.instances).toHaveLength(2);
|
|
92
|
-
|
|
93
|
-
MockWebSocket.instances[1].simulateClose();
|
|
94
|
-
|
|
95
|
-
// Second reconnect: 2s
|
|
96
|
-
vi.advanceTimersByTime(1000);
|
|
97
|
-
expect(MockWebSocket.instances).toHaveLength(2);
|
|
98
|
-
vi.advanceTimersByTime(1000);
|
|
99
|
-
expect(MockWebSocket.instances).toHaveLength(3);
|
|
100
|
-
|
|
101
|
-
MockWebSocket.instances[2].simulateClose();
|
|
102
|
-
|
|
103
|
-
// Third reconnect: 4s
|
|
104
|
-
vi.advanceTimersByTime(3000);
|
|
105
|
-
expect(MockWebSocket.instances).toHaveLength(3);
|
|
106
|
-
vi.advanceTimersByTime(1000);
|
|
107
|
-
expect(MockWebSocket.instances).toHaveLength(4);
|
|
108
|
-
|
|
109
|
-
cm.disconnect();
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it("should cap backoff at 30s", () => {
|
|
113
|
-
const cm = new ConnectionManager({
|
|
114
|
-
url: "ws://localhost:9999",
|
|
115
|
-
WebSocketImpl: MockWebSocket as any,
|
|
116
|
-
});
|
|
117
|
-
cm.connect();
|
|
118
|
-
|
|
119
|
-
// Simulate many disconnects to exceed 30s cap
|
|
120
|
-
for (let i = 0; i < 10; i++) {
|
|
121
|
-
const ws = MockWebSocket.instances[MockWebSocket.instances.length - 1];
|
|
122
|
-
ws.simulateOpen();
|
|
123
|
-
ws.simulateClose();
|
|
124
|
-
vi.advanceTimersByTime(30000);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// The backoff should never exceed 30s
|
|
128
|
-
// After 10 reconnects: 1, 2, 4, 8, 16, 30, 30, 30, 30, 30
|
|
129
|
-
cm.disconnect();
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it("should reset backoff on successful connect", () => {
|
|
133
|
-
const cm = new ConnectionManager({
|
|
134
|
-
url: "ws://localhost:9999",
|
|
135
|
-
WebSocketImpl: MockWebSocket as any,
|
|
136
|
-
});
|
|
137
|
-
cm.connect();
|
|
138
|
-
|
|
139
|
-
// First connect and disconnect
|
|
140
|
-
MockWebSocket.instances[0].simulateOpen();
|
|
141
|
-
MockWebSocket.instances[0].simulateClose();
|
|
142
|
-
|
|
143
|
-
// Wait for first reconnect (1s)
|
|
144
|
-
vi.advanceTimersByTime(1000);
|
|
145
|
-
expect(MockWebSocket.instances).toHaveLength(2);
|
|
146
|
-
|
|
147
|
-
// Successful reconnect resets backoff
|
|
148
|
-
MockWebSocket.instances[1].simulateOpen();
|
|
149
|
-
MockWebSocket.instances[1].simulateClose();
|
|
150
|
-
|
|
151
|
-
// Next reconnect should be 1s again (reset)
|
|
152
|
-
vi.advanceTimersByTime(1000);
|
|
153
|
-
expect(MockWebSocket.instances).toHaveLength(3);
|
|
154
|
-
|
|
155
|
-
cm.disconnect();
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("should buffer up to 1000 events during disconnect", () => {
|
|
159
|
-
const cm = new ConnectionManager({
|
|
160
|
-
url: "ws://localhost:9999",
|
|
161
|
-
WebSocketImpl: MockWebSocket as any,
|
|
162
|
-
maxBufferSize: 1000,
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
// Send 1001 messages while disconnected
|
|
166
|
-
for (let i = 0; i < 1001; i++) {
|
|
167
|
-
cm.send({ type: "event_forward", sessionId: "s1", event: { i } });
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
cm.connect();
|
|
171
|
-
const ws = MockWebSocket.instances[0];
|
|
172
|
-
ws.simulateOpen();
|
|
173
|
-
|
|
174
|
-
// Should only have 1000 messages (oldest dropped)
|
|
175
|
-
expect(ws.sentMessages).toHaveLength(1000);
|
|
176
|
-
cm.disconnect();
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it("should schedule reconnect when WebSocket constructor throws", () => {
|
|
180
|
-
let callCount = 0;
|
|
181
|
-
const ThrowingWebSocket = function (url: string) {
|
|
182
|
-
callCount++;
|
|
183
|
-
if (callCount <= 2) {
|
|
184
|
-
throw new Error("Connection refused");
|
|
185
|
-
}
|
|
186
|
-
return new MockWebSocket(url);
|
|
187
|
-
} as any;
|
|
188
|
-
|
|
189
|
-
const cm = new ConnectionManager({
|
|
190
|
-
url: "ws://localhost:9999",
|
|
191
|
-
WebSocketImpl: ThrowingWebSocket,
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
// Should not throw
|
|
195
|
-
expect(() => cm.connect()).not.toThrow();
|
|
196
|
-
expect(callCount).toBe(1);
|
|
197
|
-
|
|
198
|
-
// First retry after 1s — still throws
|
|
199
|
-
vi.advanceTimersByTime(1000);
|
|
200
|
-
expect(callCount).toBe(2);
|
|
201
|
-
|
|
202
|
-
// Second retry after 2s — succeeds
|
|
203
|
-
vi.advanceTimersByTime(2000);
|
|
204
|
-
expect(callCount).toBe(3);
|
|
205
|
-
expect(MockWebSocket.instances).toHaveLength(1);
|
|
206
|
-
|
|
207
|
-
cm.disconnect();
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
it("should buffer message when ws.send() throws", () => {
|
|
211
|
-
const cm = new ConnectionManager({
|
|
212
|
-
url: "ws://localhost:9999",
|
|
213
|
-
WebSocketImpl: MockWebSocket as any,
|
|
214
|
-
});
|
|
215
|
-
cm.connect();
|
|
216
|
-
|
|
217
|
-
const ws = MockWebSocket.instances[0];
|
|
218
|
-
ws.simulateOpen();
|
|
219
|
-
|
|
220
|
-
// Make send() throw
|
|
221
|
-
ws.send = () => { throw new Error("Connection reset"); };
|
|
222
|
-
|
|
223
|
-
// Should not throw — buffers instead
|
|
224
|
-
expect(() => cm.send({ type: "test" })).not.toThrow();
|
|
225
|
-
|
|
226
|
-
// Reconnect and verify the buffered message is flushed
|
|
227
|
-
ws.simulateClose();
|
|
228
|
-
vi.advanceTimersByTime(1000);
|
|
229
|
-
const ws2 = MockWebSocket.instances[1];
|
|
230
|
-
ws2.simulateOpen();
|
|
231
|
-
|
|
232
|
-
expect(ws2.sentMessages).toHaveLength(1);
|
|
233
|
-
expect(JSON.parse(ws2.sentMessages[0]).type).toBe("test");
|
|
234
|
-
|
|
235
|
-
cm.disconnect();
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
it("should reconnect when onerror fires without onclose (Node 22 built-in WebSocket)", () => {
|
|
239
|
-
const cm = new ConnectionManager({
|
|
240
|
-
url: "ws://localhost:9999",
|
|
241
|
-
WebSocketImpl: MockWebSocket as any,
|
|
242
|
-
});
|
|
243
|
-
cm.connect();
|
|
244
|
-
|
|
245
|
-
const ws1 = MockWebSocket.instances[0];
|
|
246
|
-
// Simulate Node 22 behavior: onerror fires but onclose does NOT
|
|
247
|
-
ws1.onerror?.({});
|
|
248
|
-
// ws1.onclose is NOT called
|
|
249
|
-
|
|
250
|
-
// Should still schedule reconnect after 1s
|
|
251
|
-
expect(MockWebSocket.instances).toHaveLength(1);
|
|
252
|
-
vi.advanceTimersByTime(1000);
|
|
253
|
-
expect(MockWebSocket.instances).toHaveLength(2);
|
|
254
|
-
|
|
255
|
-
// New connection should work
|
|
256
|
-
MockWebSocket.instances[1].simulateOpen();
|
|
257
|
-
expect(cm.isConnected).toBe(true);
|
|
258
|
-
|
|
259
|
-
cm.disconnect();
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
it("should not double-reconnect when both onerror and onclose fire", () => {
|
|
263
|
-
const cm = new ConnectionManager({
|
|
264
|
-
url: "ws://localhost:9999",
|
|
265
|
-
WebSocketImpl: MockWebSocket as any,
|
|
266
|
-
});
|
|
267
|
-
cm.connect();
|
|
268
|
-
|
|
269
|
-
const ws1 = MockWebSocket.instances[0];
|
|
270
|
-
ws1.simulateOpen();
|
|
271
|
-
|
|
272
|
-
// Simulate normal ws package behavior: onerror then onclose
|
|
273
|
-
ws1.onerror?.({});
|
|
274
|
-
// onerror clears onclose and handles reconnect, so onclose won't fire again
|
|
275
|
-
|
|
276
|
-
vi.advanceTimersByTime(1000);
|
|
277
|
-
// Should only create ONE new connection, not two
|
|
278
|
-
expect(MockWebSocket.instances).toHaveLength(2);
|
|
279
|
-
|
|
280
|
-
cm.disconnect();
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
it("should call onReconnect when reconnecting", () => {
|
|
284
|
-
const onReconnect = vi.fn();
|
|
285
|
-
const cm = new ConnectionManager({
|
|
286
|
-
url: "ws://localhost:9999",
|
|
287
|
-
WebSocketImpl: MockWebSocket as any,
|
|
288
|
-
onReconnect,
|
|
289
|
-
});
|
|
290
|
-
cm.connect();
|
|
291
|
-
|
|
292
|
-
MockWebSocket.instances[0].simulateOpen();
|
|
293
|
-
expect(onReconnect).not.toHaveBeenCalled();
|
|
294
|
-
|
|
295
|
-
MockWebSocket.instances[0].simulateClose();
|
|
296
|
-
vi.advanceTimersByTime(1000);
|
|
297
|
-
|
|
298
|
-
MockWebSocket.instances[1].simulateOpen();
|
|
299
|
-
expect(onReconnect).toHaveBeenCalledTimes(1);
|
|
300
|
-
|
|
301
|
-
cm.disconnect();
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
describe("updateUrl", () => {
|
|
305
|
-
it("triggers reconnect when URL changes", () => {
|
|
306
|
-
const cm = new ConnectionManager({
|
|
307
|
-
url: "ws://localhost:9999",
|
|
308
|
-
WebSocketImpl: MockWebSocket,
|
|
309
|
-
watchdogTimeout: 0,
|
|
310
|
-
});
|
|
311
|
-
cm.connect();
|
|
312
|
-
MockWebSocket.instances[0].simulateOpen();
|
|
313
|
-
expect(MockWebSocket.instances).toHaveLength(1);
|
|
314
|
-
|
|
315
|
-
cm.updateUrl("ws://remote:9999");
|
|
316
|
-
|
|
317
|
-
// Old connection closed, reconnect scheduled
|
|
318
|
-
vi.advanceTimersByTime(1000);
|
|
319
|
-
expect(MockWebSocket.instances.length).toBeGreaterThan(1);
|
|
320
|
-
const last = MockWebSocket.instances[MockWebSocket.instances.length - 1];
|
|
321
|
-
expect(last.url).toBe("ws://remote:9999");
|
|
322
|
-
|
|
323
|
-
cm.disconnect();
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
it("is a no-op when URL is the same", () => {
|
|
327
|
-
const cm = new ConnectionManager({
|
|
328
|
-
url: "ws://localhost:9999",
|
|
329
|
-
WebSocketImpl: MockWebSocket,
|
|
330
|
-
watchdogTimeout: 0,
|
|
331
|
-
});
|
|
332
|
-
cm.connect();
|
|
333
|
-
MockWebSocket.instances[0].simulateOpen();
|
|
334
|
-
const countBefore = MockWebSocket.instances.length;
|
|
335
|
-
|
|
336
|
-
cm.updateUrl("ws://localhost:9999");
|
|
337
|
-
|
|
338
|
-
vi.advanceTimersByTime(2000);
|
|
339
|
-
expect(MockWebSocket.instances.length).toBe(countBefore);
|
|
340
|
-
|
|
341
|
-
cm.disconnect();
|
|
342
|
-
});
|
|
343
|
-
});
|
|
344
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from "vitest";
|
|
2
|
-
|
|
3
|
-
describe("bridge credentials_updated handler", () => {
|
|
4
|
-
it("calls authStorage.reload() when modelRegistry is available", () => {
|
|
5
|
-
const reload = vi.fn();
|
|
6
|
-
const modelRegistry = { authStorage: { reload } };
|
|
7
|
-
|
|
8
|
-
// Simulate the bridge handler logic
|
|
9
|
-
const msg = { type: "credentials_updated" as const };
|
|
10
|
-
if (msg.type === "credentials_updated") {
|
|
11
|
-
try { modelRegistry?.authStorage?.reload?.(); } catch { /* ignore */ }
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
expect(reload).toHaveBeenCalledOnce();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("does not throw when modelRegistry is null", () => {
|
|
18
|
-
const modelRegistry = null;
|
|
19
|
-
const msg = { type: "credentials_updated" as const };
|
|
20
|
-
expect(() => {
|
|
21
|
-
if (msg.type === "credentials_updated") {
|
|
22
|
-
try { (modelRegistry as any)?.authStorage?.reload?.(); } catch { /* ignore */ }
|
|
23
|
-
}
|
|
24
|
-
}).not.toThrow();
|
|
25
|
-
});
|
|
26
|
-
});
|