@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,112 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Negative-assertion lock-in: bridge SHALL NOT honor queue-mutation messages.
|
|
3
|
-
*
|
|
4
|
-
* Pi's ExtensionAPI (verified through 0.76.0) exposes no queue-mutation
|
|
5
|
-
* primitives. The dashboard's honest policy is to reject these messages
|
|
6
|
-
* entirely — no handler in the bridge, no side effect, no shadow drift.
|
|
7
|
-
*
|
|
8
|
-
* This test verifies the absence: a stale client sending any of the six
|
|
9
|
-
* deprecated message types must NOT cause pi.sendUserMessage, pi.clear*,
|
|
10
|
-
* shadow mutation, or queue_update emission.
|
|
11
|
-
*
|
|
12
|
-
* See change: honest-mid-turn-queue-surface (spec mid-turn-prompt-queue:
|
|
13
|
-
* "Queue mutation is not exposed by pi; dashboard SHALL NOT pretend it is").
|
|
14
|
-
*/
|
|
15
|
-
import { describe, it, expect, vi } from "vitest";
|
|
16
|
-
|
|
17
|
-
// Mirror of bridge.ts message-router shape for queue-mutation types. The
|
|
18
|
-
// real bridge has NO case arm for any of these — the discriminated union
|
|
19
|
-
// in browser-protocol.ts no longer defines them, and a fall-through to
|
|
20
|
-
// commandHandler.handle() ignores them silently.
|
|
21
|
-
type MockFn = ReturnType<typeof vi.fn> & ((...args: unknown[]) => unknown);
|
|
22
|
-
|
|
23
|
-
function routeMessage(msg: any, opts: {
|
|
24
|
-
pi: {
|
|
25
|
-
sendUserMessage: MockFn;
|
|
26
|
-
clearSteeringQueue: MockFn;
|
|
27
|
-
clearFollowUpQueue: MockFn;
|
|
28
|
-
};
|
|
29
|
-
bridgeSteering: string[];
|
|
30
|
-
bridgeFollowUp: string[];
|
|
31
|
-
emitQueueUpdate: MockFn;
|
|
32
|
-
}): void {
|
|
33
|
-
// Bridge has zero handlers for queue-mutation message types. Anything
|
|
34
|
-
// not matched by any other arm reaches the default commandHandler arm,
|
|
35
|
-
// which in turn falls through (no `case "clear_steering_queue"` etc.)
|
|
36
|
-
// and the message is silently dropped.
|
|
37
|
-
//
|
|
38
|
-
// For this test, we model the bridge by NOT defining any handler for
|
|
39
|
-
// the six removed types and asserting no side effects.
|
|
40
|
-
if (msg.type === "send_prompt") {
|
|
41
|
-
// legitimate path — not under test here
|
|
42
|
-
opts.pi.sendUserMessage(msg.text, { deliverAs: msg.delivery ?? "followUp" });
|
|
43
|
-
if (msg.delivery === "steer") opts.bridgeSteering.push(msg.text);
|
|
44
|
-
else opts.bridgeFollowUp.push(msg.text);
|
|
45
|
-
opts.emitQueueUpdate();
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
// All other types fall through silently. No handler exists for queue
|
|
49
|
-
// mutation. Test verifies the absence of side effects below.
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
describe("bridge: stale queue-mutation messages produce zero side effects", () => {
|
|
53
|
-
// Names that stay PERMANENTLY DELETED (pi-mutation semantics, never
|
|
54
|
-
// re-introduced). See change: rework-mid-turn-prompt-queue.
|
|
55
|
-
//
|
|
56
|
-
// NOTE: edit_followup_entry / remove_followup_entry /
|
|
57
|
-
// promote_followup_entry are NOT in this list — they are reused with
|
|
58
|
-
// new bridge-buffer-only semantics in rework-mid-turn-prompt-queue
|
|
59
|
-
// §2-§3. Their positive behavior is covered by
|
|
60
|
-
// bridge-followup-mutation.test.ts.
|
|
61
|
-
const QUEUE_MUTATION_TYPES = [
|
|
62
|
-
"clear_steering_queue",
|
|
63
|
-
"clear_followup_slot",
|
|
64
|
-
"edit_followup_slot",
|
|
65
|
-
] as const;
|
|
66
|
-
|
|
67
|
-
for (const type of QUEUE_MUTATION_TYPES) {
|
|
68
|
-
it(`${type}: pi.sendUserMessage not called, pi.clear* not called, shadow unchanged, no queue_update`, () => {
|
|
69
|
-
const pi = {
|
|
70
|
-
sendUserMessage: vi.fn(),
|
|
71
|
-
clearSteeringQueue: vi.fn(),
|
|
72
|
-
clearFollowUpQueue: vi.fn(),
|
|
73
|
-
};
|
|
74
|
-
const bridgeSteering = ["existing-steer"];
|
|
75
|
-
const bridgeFollowUp = ["existing-followup"];
|
|
76
|
-
const emitQueueUpdate = vi.fn();
|
|
77
|
-
|
|
78
|
-
routeMessage(
|
|
79
|
-
{ type, sessionId: "s1", index: 0, text: "new", images: undefined },
|
|
80
|
-
{ pi, bridgeSteering, bridgeFollowUp, emitQueueUpdate },
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
expect(pi.sendUserMessage).not.toHaveBeenCalled();
|
|
84
|
-
expect(pi.clearSteeringQueue).not.toHaveBeenCalled();
|
|
85
|
-
expect(pi.clearFollowUpQueue).not.toHaveBeenCalled();
|
|
86
|
-
expect(bridgeSteering).toEqual(["existing-steer"]);
|
|
87
|
-
expect(bridgeFollowUp).toEqual(["existing-followup"]);
|
|
88
|
-
expect(emitQueueUpdate).not.toHaveBeenCalled();
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
it("legitimate send_prompt path still works — sanity check that the negative tests aren't vacuous", () => {
|
|
93
|
-
const pi = {
|
|
94
|
-
sendUserMessage: vi.fn(),
|
|
95
|
-
clearSteeringQueue: vi.fn(),
|
|
96
|
-
clearFollowUpQueue: vi.fn(),
|
|
97
|
-
};
|
|
98
|
-
const bridgeSteering: string[] = [];
|
|
99
|
-
const bridgeFollowUp: string[] = [];
|
|
100
|
-
const emitQueueUpdate = vi.fn();
|
|
101
|
-
|
|
102
|
-
routeMessage(
|
|
103
|
-
{ type: "send_prompt", sessionId: "s1", text: "hello", delivery: "followUp" },
|
|
104
|
-
{ pi, bridgeSteering, bridgeFollowUp, emitQueueUpdate },
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
expect(pi.sendUserMessage).toHaveBeenCalledWith("hello", { deliverAs: "followUp" });
|
|
108
|
-
expect(pi.clearFollowUpQueue).not.toHaveBeenCalled(); // honest append, no pretense
|
|
109
|
-
expect(bridgeFollowUp).toEqual(["hello"]);
|
|
110
|
-
expect(emitQueueUpdate).toHaveBeenCalledTimes(1);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bridge `plugin_emit_event` relay (shape contract).
|
|
3
|
-
*
|
|
4
|
-
* Mirrors the bridge onMessage branch: a server-side plugin action emits a
|
|
5
|
-
* configured event into this session; the bridge re-emits it on pi.events.
|
|
6
|
-
* A missing/non-string eventType is ignored. See change:
|
|
7
|
-
* automation-emit-configured-event.
|
|
8
|
-
*/
|
|
9
|
-
import { describe, it, expect, vi } from "vitest";
|
|
10
|
-
|
|
11
|
-
// Mirrors the bridge onMessage `plugin_emit_event` branch.
|
|
12
|
-
function onPluginEmitEvent(
|
|
13
|
-
events: { emit: (t: string, d: unknown) => void } | undefined,
|
|
14
|
-
msg: { eventType?: unknown; data?: unknown },
|
|
15
|
-
): void {
|
|
16
|
-
if (!events) return;
|
|
17
|
-
const eventType = msg.eventType;
|
|
18
|
-
if (typeof eventType === "string" && eventType.length > 0) {
|
|
19
|
-
const data = msg.data;
|
|
20
|
-
events.emit(eventType, data && typeof data === "object" ? (data as Record<string, unknown>) : {});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
describe("bridge plugin_emit_event relay", () => {
|
|
25
|
-
it("re-emits the configured event with its data", () => {
|
|
26
|
-
const emit = vi.fn();
|
|
27
|
-
onPluginEmitEvent({ emit }, { eventType: "flow:run", data: { flowName: "test:x", task: "go" } });
|
|
28
|
-
expect(emit).toHaveBeenCalledWith("flow:run", { flowName: "test:x", task: "go" });
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("defaults data to {} when absent", () => {
|
|
32
|
-
const emit = vi.fn();
|
|
33
|
-
onPluginEmitEvent({ emit }, { eventType: "flow:abort" });
|
|
34
|
-
expect(emit).toHaveBeenCalledWith("flow:abort", {});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("ignores a missing/non-string eventType", () => {
|
|
38
|
-
const emit = vi.fn();
|
|
39
|
-
onPluginEmitEvent({ emit }, {});
|
|
40
|
-
onPluginEmitEvent({ emit }, { eventType: "" });
|
|
41
|
-
onPluginEmitEvent({ emit }, { eventType: 42 as unknown as string });
|
|
42
|
-
expect(emit).not.toHaveBeenCalled();
|
|
43
|
-
});
|
|
44
|
-
});
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests that the bridge forwards pi's `queue_update` event as a typed
|
|
3
|
-
* QueueUpdateToServerMessage. Also covers idempotent listener registration
|
|
4
|
-
* via pi.on("queue_update", ...).
|
|
5
|
-
*
|
|
6
|
-
* See change: add-followup-edit-and-steer-cancel.
|
|
7
|
-
*/
|
|
8
|
-
import { describe, it, expect, vi } from "vitest";
|
|
9
|
-
|
|
10
|
-
// We don't test the full bridge here (too much wiring) — we drive the
|
|
11
|
-
// listener-registration-and-forward shape directly with a fake pi.
|
|
12
|
-
|
|
13
|
-
describe("bridge queue_update forwarding (shape contract)", () => {
|
|
14
|
-
it("registered queue_update listener emits a typed QueueUpdateToServerMessage on event", () => {
|
|
15
|
-
// Simulate the listener registration the bridge performs.
|
|
16
|
-
const listeners: Record<string, (event: any) => void> = {};
|
|
17
|
-
const fakePi = {
|
|
18
|
-
on: vi.fn((eventType: string, handler: any) => { listeners[eventType] = handler; }),
|
|
19
|
-
};
|
|
20
|
-
const sent: any[] = [];
|
|
21
|
-
const fakeConnection = { send: (m: any) => sent.push(m) };
|
|
22
|
-
const sessionId = "S1";
|
|
23
|
-
|
|
24
|
-
// Equivalent of the bridge's pi.on("queue_update", ...) registration.
|
|
25
|
-
fakePi.on("queue_update", (event: any) => {
|
|
26
|
-
const steering = Array.isArray(event?.steering) ? Array.from(event.steering as readonly string[]) : [];
|
|
27
|
-
const followUp = Array.isArray(event?.followUp) ? Array.from(event.followUp as readonly string[]) : [];
|
|
28
|
-
fakeConnection.send({ type: "queue_update", sessionId, steering, followUp });
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
// Fire pi's queue_update event.
|
|
32
|
-
listeners["queue_update"]({ type: "queue_update", steering: ["a", "b"], followUp: ["c"] });
|
|
33
|
-
|
|
34
|
-
expect(sent).toHaveLength(1);
|
|
35
|
-
expect(sent[0]).toEqual({
|
|
36
|
-
type: "queue_update",
|
|
37
|
-
sessionId: "S1",
|
|
38
|
-
steering: ["a", "b"],
|
|
39
|
-
followUp: ["c"],
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("forwards empty arrays when pi reports empty queues", () => {
|
|
44
|
-
const listeners: Record<string, (event: any) => void> = {};
|
|
45
|
-
const fakePi = { on: vi.fn((t: string, h: any) => { listeners[t] = h; }) };
|
|
46
|
-
const sent: any[] = [];
|
|
47
|
-
const sessionId = "S2";
|
|
48
|
-
|
|
49
|
-
fakePi.on("queue_update", (event: any) => {
|
|
50
|
-
const steering = Array.isArray(event?.steering) ? Array.from(event.steering as readonly string[]) : [];
|
|
51
|
-
const followUp = Array.isArray(event?.followUp) ? Array.from(event.followUp as readonly string[]) : [];
|
|
52
|
-
sent.push({ type: "queue_update", sessionId, steering, followUp });
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
listeners["queue_update"]({ type: "queue_update", steering: [], followUp: [] });
|
|
56
|
-
|
|
57
|
-
expect(sent).toEqual([{ type: "queue_update", sessionId: "S2", steering: [], followUp: [] }]);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("defends against malformed event payloads (missing arrays)", () => {
|
|
61
|
-
const listeners: Record<string, (event: any) => void> = {};
|
|
62
|
-
const fakePi = { on: vi.fn((t: string, h: any) => { listeners[t] = h; }) };
|
|
63
|
-
const sent: any[] = [];
|
|
64
|
-
const sessionId = "S3";
|
|
65
|
-
|
|
66
|
-
fakePi.on("queue_update", (event: any) => {
|
|
67
|
-
const steering = Array.isArray(event?.steering) ? Array.from(event.steering as readonly string[]) : [];
|
|
68
|
-
const followUp = Array.isArray(event?.followUp) ? Array.from(event.followUp as readonly string[]) : [];
|
|
69
|
-
sent.push({ type: "queue_update", sessionId, steering, followUp });
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// Pi returns object missing the expected fields.
|
|
73
|
-
listeners["queue_update"]({ type: "queue_update" });
|
|
74
|
-
|
|
75
|
-
expect(sent).toEqual([{ type: "queue_update", sessionId: "S3", steering: [], followUp: [] }]);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
@@ -1,333 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Regression suite for #393 — bridge permanently disconnects on in-TUI
|
|
3
|
-
* resume/switch/fork.
|
|
4
|
-
*
|
|
5
|
-
* Mechanism (spike-confirmed, design.md §Fix): the `session_start` handler
|
|
6
|
-
* calls `handleSessionChange(ctx)` (session-sync.ts) BEFORE
|
|
7
|
-
* `connection.connect()`. `handleSessionChange` reads `ctx.cwd` — a guarded
|
|
8
|
-
* getter on pi's ExtensionRunner that THROWS once the session is replaced
|
|
9
|
-
* (new/fork/resume/reload). The throw is swallowed by the bridge's `safe()`
|
|
10
|
-
* wrapper, so the remainder of the `session_start` body — including
|
|
11
|
-
* `connection.connect()` — is abandoned. The preceding `session_shutdown`
|
|
12
|
-
* already called `connection.disconnect()`, so the socket stays terminally
|
|
13
|
-
* closed: the exact #393 behaviour.
|
|
14
|
-
*
|
|
15
|
-
* Pattern: the repo's L1 model-mirror + fake-WS approach. The `session_start`
|
|
16
|
-
* ordering (handleSessionChange → connect(), under `safe()`) is mirrored here;
|
|
17
|
-
* the REAL `handleSessionChange` (session-sync.ts) and REAL `ConnectionManager`
|
|
18
|
-
* are exercised against a fake WebSocket. X1 injects the throwing `ctx.cwd`
|
|
19
|
-
* getter — it FAILS on the pre-fix code and PASSES after the `safeCwd` fix.
|
|
20
|
-
*
|
|
21
|
-
* Exemplars: connection.test.ts (fake WebSocket), bridge-shutdown-reset.test.ts
|
|
22
|
-
* (pure-model shutdown handler).
|
|
23
|
-
*
|
|
24
|
-
* See change: fix-bridge-resume-disconnect.
|
|
25
|
-
*/
|
|
26
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
27
|
-
import { tmpdir } from "node:os";
|
|
28
|
-
import { join } from "node:path";
|
|
29
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
30
|
-
import { ConnectionManager } from "../connection.js";
|
|
31
|
-
import { handleSessionChange } from "../session-sync.js";
|
|
32
|
-
|
|
33
|
-
// ── Fake WebSocket: opens asynchronously via onopen, like a real socket ──
|
|
34
|
-
class FakeWebSocket {
|
|
35
|
-
static instances: FakeWebSocket[] = [];
|
|
36
|
-
readyState = 0; // CONNECTING
|
|
37
|
-
onopen: (() => void) | null = null;
|
|
38
|
-
onclose: (() => void) | null = null;
|
|
39
|
-
onmessage: ((ev: { data: string }) => void) | null = null;
|
|
40
|
-
onerror: ((ev: unknown) => void) | null = null;
|
|
41
|
-
sent: string[] = [];
|
|
42
|
-
|
|
43
|
-
constructor(public url: string) {
|
|
44
|
-
FakeWebSocket.instances.push(this);
|
|
45
|
-
// Open on the next macrotask — the register frame is buffered until then.
|
|
46
|
-
setTimeout(() => {
|
|
47
|
-
this.readyState = 1; // OPEN
|
|
48
|
-
this.onopen?.();
|
|
49
|
-
}, 0);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
send(data: string) {
|
|
53
|
-
this.sent.push(data);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
close() {
|
|
57
|
-
this.readyState = 3; // CLOSED
|
|
58
|
-
this.onclose?.();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Bounded, non-throwing poll for connection convergence. The socket opens
|
|
64
|
-
* asynchronously via onopen (spec: "poll `connection.isConnected` rather than
|
|
65
|
-
* read it synchronously at handler return"), so we poll up to `timeoutMs`
|
|
66
|
-
* instead of relying on a fixed delay. Returns whether or not it converged; the
|
|
67
|
-
* caller's `expect(conn.isConnected)` makes the actual assertion (so the #X1
|
|
68
|
-
* red repro still fails cleanly instead of throwing a timeout).
|
|
69
|
-
*/
|
|
70
|
-
async function waitForConnected(conn: ConnectionManager, timeoutMs = 500): Promise<void> {
|
|
71
|
-
const start = Date.now();
|
|
72
|
-
while (!conn.isConnected && Date.now() - start < timeoutMs) {
|
|
73
|
-
await new Promise((r) => setTimeout(r, 1));
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function makeConnection(): ConnectionManager {
|
|
78
|
-
return new ConnectionManager({
|
|
79
|
-
url: "ws://localhost:9999",
|
|
80
|
-
WebSocketImpl: FakeWebSocket as unknown as typeof WebSocket,
|
|
81
|
-
watchdogTimeout: 0,
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Mirror the bridge's `session_start` handler ordering under `safe()`: run the
|
|
87
|
-
* steps in sequence; a throw in any step abandons the remaining steps (exactly
|
|
88
|
-
* what `safe()` does — it catches the rejection at the handler boundary, so the
|
|
89
|
-
* body after the throw never executes). Returns the caught error (or undefined
|
|
90
|
-
* when every step ran) so callers can distinguish the expected abort from an
|
|
91
|
-
* unexpected setup/cleanup failure.
|
|
92
|
-
*/
|
|
93
|
-
function runSessionStartUnderSafe(steps: Array<() => void>): Error | undefined {
|
|
94
|
-
try {
|
|
95
|
-
for (const step of steps) step();
|
|
96
|
-
return undefined;
|
|
97
|
-
} catch (err) {
|
|
98
|
-
/* safe() swallows — remaining steps (incl. connection.connect()) are skipped */
|
|
99
|
-
return err as Error;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function makeCtx(sessionId: string, cwd: string | (() => never)) {
|
|
104
|
-
const ctx: Record<string, unknown> = {
|
|
105
|
-
sessionManager: {
|
|
106
|
-
getSessionId: () => sessionId,
|
|
107
|
-
getSessionFile: () => undefined,
|
|
108
|
-
getSessionDir: () => undefined,
|
|
109
|
-
getBranch: () => [],
|
|
110
|
-
getEntries: () => [],
|
|
111
|
-
},
|
|
112
|
-
model: { provider: "anthropic", id: "claude-sonnet-4-6" },
|
|
113
|
-
};
|
|
114
|
-
if (typeof cwd === "string") {
|
|
115
|
-
ctx.cwd = cwd;
|
|
116
|
-
} else {
|
|
117
|
-
// The #393 fault: reading ctx.cwd throws after session replacement.
|
|
118
|
-
Object.defineProperty(ctx, "cwd", { get: cwd });
|
|
119
|
-
}
|
|
120
|
-
return ctx as any;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function makeBc(connection: ConnectionManager, sessionId: string, ctx: any) {
|
|
124
|
-
return {
|
|
125
|
-
pi: {
|
|
126
|
-
getSessionName: () => "resumed-session",
|
|
127
|
-
getCommands: () => [],
|
|
128
|
-
getThinkingLevel: () => undefined,
|
|
129
|
-
},
|
|
130
|
-
connection,
|
|
131
|
-
sessionId,
|
|
132
|
-
attachedChange: null,
|
|
133
|
-
cachedCtx: ctx,
|
|
134
|
-
cachedModelRegistry: null,
|
|
135
|
-
cachedHasUI: false,
|
|
136
|
-
dashboardSpawned: false,
|
|
137
|
-
} as any;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function registerFrameFor(
|
|
141
|
-
ws: FakeWebSocket | undefined,
|
|
142
|
-
sessionId: string,
|
|
143
|
-
): { cwd?: unknown } | undefined {
|
|
144
|
-
if (!ws) return undefined;
|
|
145
|
-
for (const s of ws.sent) {
|
|
146
|
-
try {
|
|
147
|
-
const m = JSON.parse(s);
|
|
148
|
-
if (m.type === "session_register" && m.sessionId === sessionId) return m;
|
|
149
|
-
} catch {
|
|
150
|
-
/* skip non-JSON */
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return undefined;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function registeredFor(ws: FakeWebSocket | undefined, sessionId: string): boolean {
|
|
157
|
-
return registerFrameFor(ws, sessionId) !== undefined;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/** Model a session_shutdown that ends by disconnecting (replacement reason). */
|
|
161
|
-
async function shutdownThenDisconnect(conn: ConnectionManager, sessionId: string): Promise<void> {
|
|
162
|
-
conn.send({ type: "session_unregister", sessionId });
|
|
163
|
-
await new Promise((r) => setTimeout(r, 0)); // mirror the 100 ms settle window
|
|
164
|
-
conn.disconnect();
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
describe("bridge resume/switch/fork survives session replacement (#393)", () => {
|
|
168
|
-
afterEach(() => {
|
|
169
|
-
FakeWebSocket.instances = [];
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
// ── Frontend-quirk F1/F2/F3: replacement ends live + registered ──
|
|
173
|
-
for (const reason of ["resume", "new", "fork"] as const) {
|
|
174
|
-
it(`${reason} ends with a live, re-registered connection`, async () => {
|
|
175
|
-
FakeWebSocket.instances = [];
|
|
176
|
-
const dir = mkdtempSync(join(tmpdir(), `pi-${reason}-`));
|
|
177
|
-
const conn = makeConnection();
|
|
178
|
-
try {
|
|
179
|
-
// Session A live.
|
|
180
|
-
conn.connect();
|
|
181
|
-
await waitForConnected(conn);
|
|
182
|
-
expect(conn.isConnected).toBe(true);
|
|
183
|
-
|
|
184
|
-
// session_shutdown(reason) — full disconnect completes first.
|
|
185
|
-
await shutdownThenDisconnect(conn, "A");
|
|
186
|
-
expect(conn.isConnected).toBe(false);
|
|
187
|
-
|
|
188
|
-
// session_start(reason) for B: handleSessionChange BEFORE connect().
|
|
189
|
-
const ctxB = makeCtx("B", dir);
|
|
190
|
-
const bc = makeBc(conn, "A", ctxB);
|
|
191
|
-
const err = runSessionStartUnderSafe([
|
|
192
|
-
() => handleSessionChange(bc, ctxB, () => []),
|
|
193
|
-
() => conn.connect(),
|
|
194
|
-
]);
|
|
195
|
-
expect(err).toBeUndefined(); // no throw on the happy path
|
|
196
|
-
|
|
197
|
-
await waitForConnected(conn);
|
|
198
|
-
expect(conn.isConnected).toBe(true);
|
|
199
|
-
const last = FakeWebSocket.instances.at(-1);
|
|
200
|
-
// Registered for B with the real ctx.cwd (a valid string dir).
|
|
201
|
-
expect(registerFrameFor(last, "B")?.cwd).toBe(dir);
|
|
202
|
-
} finally {
|
|
203
|
-
conn.disconnect();
|
|
204
|
-
rmSync(dir, { recursive: true, force: true });
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// ── Error-handling X1: RED repro of #393 — a mid-path ctx.cwd throw ──
|
|
210
|
-
it("resume survives a mid-path ctx.cwd throw (reproduces #393)", async () => {
|
|
211
|
-
FakeWebSocket.instances = [];
|
|
212
|
-
const conn = makeConnection();
|
|
213
|
-
try {
|
|
214
|
-
conn.connect();
|
|
215
|
-
await waitForConnected(conn);
|
|
216
|
-
expect(conn.isConnected).toBe(true);
|
|
217
|
-
|
|
218
|
-
await shutdownThenDisconnect(conn, "A");
|
|
219
|
-
expect(conn.isConnected).toBe(false);
|
|
220
|
-
|
|
221
|
-
// The documented fault: ctx.cwd throws once the session is replaced.
|
|
222
|
-
const throwingCwd = () => {
|
|
223
|
-
throw new Error("ctx.cwd: session replaced");
|
|
224
|
-
};
|
|
225
|
-
const ctxB = makeCtx("B", throwingCwd);
|
|
226
|
-
const bc = makeBc(conn, "A", ctxB);
|
|
227
|
-
const err = runSessionStartUnderSafe([
|
|
228
|
-
() => handleSessionChange(bc, ctxB, () => []),
|
|
229
|
-
() => conn.connect(),
|
|
230
|
-
]);
|
|
231
|
-
// After the fix, safeCwd swallows the getter throw, so handleSessionChange
|
|
232
|
-
// runs to completion — no error abandons the body before connect().
|
|
233
|
-
expect(err).toBeUndefined();
|
|
234
|
-
|
|
235
|
-
await waitForConnected(conn);
|
|
236
|
-
// Pre-fix: handleSessionChange throws at `cwd: ctx.cwd`, safe() swallows
|
|
237
|
-
// it, connect() is skipped, and the socket stays terminally closed.
|
|
238
|
-
expect(conn.isConnected).toBe(true);
|
|
239
|
-
const last = FakeWebSocket.instances.at(-1);
|
|
240
|
-
// Registered for B, and safeCwd fell back to process.cwd() on the throw.
|
|
241
|
-
expect(registerFrameFor(last, "B")?.cwd).toBe(process.cwd());
|
|
242
|
-
} finally {
|
|
243
|
-
conn.disconnect();
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
// ── Frontend-quirk F4: reload ends connected ──
|
|
248
|
-
it("reload re-init ends with a live, re-registered connection", async () => {
|
|
249
|
-
FakeWebSocket.instances = [];
|
|
250
|
-
const conn = makeConnection();
|
|
251
|
-
try {
|
|
252
|
-
conn.connect();
|
|
253
|
-
await waitForConnected(conn);
|
|
254
|
-
expect(conn.isConnected).toBe(true);
|
|
255
|
-
|
|
256
|
-
// session_shutdown(reason: "reload") → state.cleanup disconnects.
|
|
257
|
-
conn.send({ type: "session_unregister", sessionId: "A" });
|
|
258
|
-
conn.disconnect();
|
|
259
|
-
expect(conn.isConnected).toBe(false);
|
|
260
|
-
|
|
261
|
-
// Reload re-init: connect() + re-register.
|
|
262
|
-
conn.connect();
|
|
263
|
-
conn.send({ type: "session_register", sessionId: "A" });
|
|
264
|
-
await waitForConnected(conn);
|
|
265
|
-
expect(conn.isConnected).toBe(true);
|
|
266
|
-
expect(registeredFor(FakeWebSocket.instances.at(-1), "A")).toBe(true);
|
|
267
|
-
} finally {
|
|
268
|
-
conn.disconnect();
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
// ── Edge-case E1: quit tears down, cleanup ran ──
|
|
273
|
-
it("quit tears down and runs the always-run cleanup", async () => {
|
|
274
|
-
FakeWebSocket.instances = [];
|
|
275
|
-
const conn = makeConnection();
|
|
276
|
-
conn.connect();
|
|
277
|
-
await waitForConnected(conn);
|
|
278
|
-
|
|
279
|
-
const timers = { metrics: true, heartbeat: true, gitPoll: true };
|
|
280
|
-
const subagentBufferReset = vi.fn();
|
|
281
|
-
const attachmentsCleaned = vi.fn();
|
|
282
|
-
|
|
283
|
-
// Model session_shutdown(reason: "quit") cleanup (bridge.ts inline handler).
|
|
284
|
-
conn.send({ type: "session_unregister", sessionId: "A" });
|
|
285
|
-
timers.metrics = timers.heartbeat = timers.gitPoll = false;
|
|
286
|
-
subagentBufferReset();
|
|
287
|
-
attachmentsCleaned();
|
|
288
|
-
await new Promise((r) => setTimeout(r, 0));
|
|
289
|
-
conn.disconnect(); // teardown is permitted for quit — MAY close.
|
|
290
|
-
|
|
291
|
-
const first = FakeWebSocket.instances[0];
|
|
292
|
-
expect(first.sent.some((s) => JSON.parse(s).type === "session_unregister")).toBe(true);
|
|
293
|
-
expect(timers).toEqual({ metrics: false, heartbeat: false, gitPoll: false });
|
|
294
|
-
expect(subagentBufferReset).toHaveBeenCalledTimes(1);
|
|
295
|
-
expect(attachmentsCleaned).toHaveBeenCalledTimes(1);
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
// ── Error-handling X2: cleanup runs regardless of reason under a later throw ──
|
|
299
|
-
it("shutdown cleanup completes for every replacement reason even when a later start step throws", async () => {
|
|
300
|
-
for (const reason of ["resume", "new", "fork"] as const) {
|
|
301
|
-
FakeWebSocket.instances = [];
|
|
302
|
-
const conn = makeConnection();
|
|
303
|
-
conn.connect();
|
|
304
|
-
await waitForConnected(conn);
|
|
305
|
-
|
|
306
|
-
const timers = { metrics: true, heartbeat: true, gitPoll: true };
|
|
307
|
-
const subagentBufferReset = vi.fn();
|
|
308
|
-
const attachmentsCleaned = vi.fn();
|
|
309
|
-
|
|
310
|
-
// session_shutdown(reason) — the always-run cleanup.
|
|
311
|
-
conn.send({ type: "session_unregister", sessionId: `A-${reason}` });
|
|
312
|
-
timers.metrics = timers.heartbeat = timers.gitPoll = false;
|
|
313
|
-
subagentBufferReset();
|
|
314
|
-
attachmentsCleaned();
|
|
315
|
-
await new Promise((r) => setTimeout(r, 0));
|
|
316
|
-
conn.disconnect();
|
|
317
|
-
|
|
318
|
-
// A subsequent session_start step throws — must not undo the cleanup.
|
|
319
|
-
const err = runSessionStartUnderSafe([
|
|
320
|
-
() => {
|
|
321
|
-
throw new Error("later session_start step boom");
|
|
322
|
-
},
|
|
323
|
-
() => conn.connect(),
|
|
324
|
-
]);
|
|
325
|
-
expect(err?.message).toBe("later session_start step boom"); // the deliberate throw surfaced
|
|
326
|
-
|
|
327
|
-
expect(timers).toEqual({ metrics: false, heartbeat: false, gitPoll: false });
|
|
328
|
-
expect(subagentBufferReset).toHaveBeenCalledTimes(1);
|
|
329
|
-
expect(attachmentsCleaned).toHaveBeenCalledTimes(1);
|
|
330
|
-
conn.disconnect();
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
});
|