@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,217 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for the bridge-owned-follow-up MUTATION handlers.
|
|
3
|
-
*
|
|
4
|
-
* Each of edit / remove / promote / clear / pull mutates `bridgeFollowUp`
|
|
5
|
-
* locally + emits `queue_update`. NONE of them call `pi.sendUserMessage`,
|
|
6
|
-
* `pi.clear*Queue`, or any other pi method. Pure-mirror of bridge.ts
|
|
7
|
-
* message-router arms.
|
|
8
|
-
*
|
|
9
|
-
* Out-of-range indices emit `command_feedback { status: "error" }` with no
|
|
10
|
-
* buffer mutation and no `queue_update`. `promote_followup_entry` with
|
|
11
|
-
* `index <= 0` is a silent no-op (no emit).
|
|
12
|
-
*
|
|
13
|
-
* Spec: mid-turn-prompt-queue — Requirement "Per-entry follow-up mutation
|
|
14
|
-
* mutates ONLY the bridge buffer" + "Pull-to-editor splices the entry and
|
|
15
|
-
* round-trips text to the client draft".
|
|
16
|
-
*
|
|
17
|
-
* See change: rework-mid-turn-prompt-queue.
|
|
18
|
-
*/
|
|
19
|
-
import { describe, it, expect, vi } from "vitest";
|
|
20
|
-
|
|
21
|
-
type AnyMock = ((...args: any[]) => any) & ReturnType<typeof vi.fn>;
|
|
22
|
-
|
|
23
|
-
interface Sink {
|
|
24
|
-
emit: AnyMock;
|
|
25
|
-
feedback: AnyMock;
|
|
26
|
-
pi: {
|
|
27
|
-
sendUserMessage: AnyMock;
|
|
28
|
-
clearSteeringQueue: AnyMock;
|
|
29
|
-
clearFollowUpQueue: AnyMock;
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function makeSink(): Sink {
|
|
34
|
-
return {
|
|
35
|
-
emit: vi.fn() as AnyMock,
|
|
36
|
-
feedback: vi.fn() as AnyMock,
|
|
37
|
-
pi: {
|
|
38
|
-
sendUserMessage: vi.fn() as AnyMock,
|
|
39
|
-
clearSteeringQueue: vi.fn() as AnyMock,
|
|
40
|
-
clearFollowUpQueue: vi.fn() as AnyMock,
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Pure handlers mirroring bridge.ts message-router arms. Each accepts the
|
|
47
|
-
* current buffer (mutated in place) + the sink for side effects.
|
|
48
|
-
*/
|
|
49
|
-
const handlers = {
|
|
50
|
-
edit(buffer: string[], msg: { index: number; text: string }, sink: Sink): void {
|
|
51
|
-
if (typeof msg.index !== "number" || msg.index < 0 || msg.index >= buffer.length) {
|
|
52
|
-
sink.feedback({ command: "edit_followup_entry", status: "error", message: "Index out of range" });
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
buffer[msg.index] = msg.text;
|
|
56
|
-
sink.emit([...buffer]);
|
|
57
|
-
},
|
|
58
|
-
remove(buffer: string[], msg: { index: number }, sink: Sink): void {
|
|
59
|
-
if (typeof msg.index !== "number" || msg.index < 0 || msg.index >= buffer.length) {
|
|
60
|
-
sink.feedback({ command: "remove_followup_entry", status: "error", message: "Index out of range" });
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
buffer.splice(msg.index, 1);
|
|
64
|
-
sink.emit([...buffer]);
|
|
65
|
-
},
|
|
66
|
-
promote(buffer: string[], msg: { index: number }, sink: Sink): void {
|
|
67
|
-
// index <= 0 is a silent no-op (no emit, no feedback).
|
|
68
|
-
if (typeof msg.index !== "number" || msg.index <= 0 || msg.index >= buffer.length) return;
|
|
69
|
-
const [entry] = buffer.splice(msg.index, 1);
|
|
70
|
-
buffer.unshift(entry);
|
|
71
|
-
sink.emit([...buffer]);
|
|
72
|
-
},
|
|
73
|
-
clear(buffer: string[], msg: { indices: number[] | "all" }, sink: Sink): string[] {
|
|
74
|
-
if (msg.indices === "all") {
|
|
75
|
-
if (buffer.length > 0) {
|
|
76
|
-
const cleared: string[] = [];
|
|
77
|
-
sink.emit([...cleared]);
|
|
78
|
-
return cleared;
|
|
79
|
-
}
|
|
80
|
-
return buffer;
|
|
81
|
-
}
|
|
82
|
-
if (!Array.isArray(msg.indices)) return buffer;
|
|
83
|
-
const sorted = [...msg.indices].sort((a, b) => b - a);
|
|
84
|
-
let mutated = false;
|
|
85
|
-
for (const i of sorted) {
|
|
86
|
-
if (typeof i === "number" && i >= 0 && i < buffer.length) {
|
|
87
|
-
buffer.splice(i, 1);
|
|
88
|
-
mutated = true;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (mutated) sink.emit([...buffer]);
|
|
92
|
-
return buffer;
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
function assertNoPiCalls(sink: Sink): void {
|
|
97
|
-
expect(sink.pi.sendUserMessage).not.toHaveBeenCalled();
|
|
98
|
-
expect(sink.pi.clearSteeringQueue).not.toHaveBeenCalled();
|
|
99
|
-
expect(sink.pi.clearFollowUpQueue).not.toHaveBeenCalled();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
describe("edit_followup_entry", () => {
|
|
103
|
-
it("mutates buffer + emits, never touches pi", () => {
|
|
104
|
-
const sink = makeSink();
|
|
105
|
-
const buffer = ["alpha", "beta", "gamma"];
|
|
106
|
-
handlers.edit(buffer, { index: 1, text: "BETA" }, sink);
|
|
107
|
-
expect(buffer).toEqual(["alpha", "BETA", "gamma"]);
|
|
108
|
-
expect(sink.emit).toHaveBeenCalledTimes(1);
|
|
109
|
-
expect(sink.emit).toHaveBeenCalledWith(["alpha", "BETA", "gamma"]);
|
|
110
|
-
assertNoPiCalls(sink);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("out-of-range index emits command_feedback error, no mutation, no queue_update", () => {
|
|
114
|
-
const sink = makeSink();
|
|
115
|
-
const buffer = ["a"];
|
|
116
|
-
handlers.edit(buffer, { index: 5, text: "x" }, sink);
|
|
117
|
-
expect(buffer).toEqual(["a"]);
|
|
118
|
-
expect(sink.emit).not.toHaveBeenCalled();
|
|
119
|
-
expect(sink.feedback).toHaveBeenCalledWith({
|
|
120
|
-
command: "edit_followup_entry",
|
|
121
|
-
status: "error",
|
|
122
|
-
message: "Index out of range",
|
|
123
|
-
});
|
|
124
|
-
assertNoPiCalls(sink);
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
describe("remove_followup_entry", () => {
|
|
129
|
-
it("splices the entry + emits", () => {
|
|
130
|
-
const sink = makeSink();
|
|
131
|
-
const buffer = ["alpha", "beta", "gamma"];
|
|
132
|
-
handlers.remove(buffer, { index: 0 }, sink);
|
|
133
|
-
expect(buffer).toEqual(["beta", "gamma"]);
|
|
134
|
-
expect(sink.emit).toHaveBeenCalledWith(["beta", "gamma"]);
|
|
135
|
-
assertNoPiCalls(sink);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it("out-of-range emits error, no mutation", () => {
|
|
139
|
-
const sink = makeSink();
|
|
140
|
-
const buffer = ["a"];
|
|
141
|
-
handlers.remove(buffer, { index: 99 }, sink);
|
|
142
|
-
expect(buffer).toEqual(["a"]);
|
|
143
|
-
expect(sink.emit).not.toHaveBeenCalled();
|
|
144
|
-
expect(sink.feedback).toHaveBeenCalled();
|
|
145
|
-
assertNoPiCalls(sink);
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
describe("promote_followup_entry", () => {
|
|
150
|
-
it("moves the entry to head + emits", () => {
|
|
151
|
-
const sink = makeSink();
|
|
152
|
-
const buffer = ["alpha", "beta", "gamma"];
|
|
153
|
-
handlers.promote(buffer, { index: 2 }, sink);
|
|
154
|
-
expect(buffer).toEqual(["gamma", "alpha", "beta"]);
|
|
155
|
-
expect(sink.emit).toHaveBeenCalledWith(["gamma", "alpha", "beta"]);
|
|
156
|
-
assertNoPiCalls(sink);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it("index 0 is a silent no-op (no emit, no error feedback)", () => {
|
|
160
|
-
const sink = makeSink();
|
|
161
|
-
const buffer = ["alpha", "beta"];
|
|
162
|
-
handlers.promote(buffer, { index: 0 }, sink);
|
|
163
|
-
expect(buffer).toEqual(["alpha", "beta"]);
|
|
164
|
-
expect(sink.emit).not.toHaveBeenCalled();
|
|
165
|
-
expect(sink.feedback).not.toHaveBeenCalled();
|
|
166
|
-
assertNoPiCalls(sink);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it("out-of-range index is also a silent no-op", () => {
|
|
170
|
-
const sink = makeSink();
|
|
171
|
-
const buffer = ["a"];
|
|
172
|
-
handlers.promote(buffer, { index: 99 }, sink);
|
|
173
|
-
expect(buffer).toEqual(["a"]);
|
|
174
|
-
expect(sink.emit).not.toHaveBeenCalled();
|
|
175
|
-
expect(sink.feedback).not.toHaveBeenCalled();
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
describe("clear_followup_entries", () => {
|
|
180
|
-
it("'all' empties the buffer + emits", () => {
|
|
181
|
-
const sink = makeSink();
|
|
182
|
-
let buffer = ["a", "b", "c"];
|
|
183
|
-
buffer = handlers.clear(buffer, { indices: "all" }, sink);
|
|
184
|
-
expect(buffer).toEqual([]);
|
|
185
|
-
expect(sink.emit).toHaveBeenCalledWith([]);
|
|
186
|
-
assertNoPiCalls(sink);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it("'all' on empty buffer does not emit", () => {
|
|
190
|
-
const sink = makeSink();
|
|
191
|
-
let buffer: string[] = [];
|
|
192
|
-
buffer = handlers.clear(buffer, { indices: "all" }, sink);
|
|
193
|
-
expect(buffer).toEqual([]);
|
|
194
|
-
expect(sink.emit).not.toHaveBeenCalled();
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it("indices array splices descending, single emit", () => {
|
|
198
|
-
const sink = makeSink();
|
|
199
|
-
const buffer = ["a", "b", "c", "d"];
|
|
200
|
-
handlers.clear(buffer, { indices: [0, 2] }, sink);
|
|
201
|
-
// descending splice: 2 first → ["a","b","d"], then 0 → ["b","d"]
|
|
202
|
-
expect(buffer).toEqual(["b", "d"]);
|
|
203
|
-
expect(sink.emit).toHaveBeenCalledTimes(1);
|
|
204
|
-
expect(sink.emit).toHaveBeenCalledWith(["b", "d"]);
|
|
205
|
-
assertNoPiCalls(sink);
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it("indices array with all out-of-range values does not emit", () => {
|
|
209
|
-
const sink = makeSink();
|
|
210
|
-
const buffer = ["a", "b"];
|
|
211
|
-
handlers.clear(buffer, { indices: [99, 100] }, sink);
|
|
212
|
-
expect(buffer).toEqual(["a", "b"]);
|
|
213
|
-
expect(sink.emit).not.toHaveBeenCalled();
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
|
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for the bridge-owned-follow-up drain loop.
|
|
3
|
-
*
|
|
4
|
-
* Pure mirror of bridge.ts `drainFollowupQueue()`:
|
|
5
|
-
*
|
|
6
|
-
* 1. Re-entrancy lock (isDraining boolean, set→try→finally clear)
|
|
7
|
-
* 2. TUI-coexistence gate (ctx.hasPendingMessages() === false)
|
|
8
|
-
* 3. Empty-buffer gate (bridgeFollowUp.length > 0)
|
|
9
|
-
* 4. POP FIRST (bridgeFollowUp.shift() before any pi call)
|
|
10
|
-
* 5. Emit BEFORE send (emitQueueUpdate runs before pi.sendUserMessage)
|
|
11
|
-
* 6. Single send, no deliverAs (fresh-turn semantics)
|
|
12
|
-
* 7. Catch + drop on pi error (no re-push)
|
|
13
|
-
*
|
|
14
|
-
* NOTE: an earlier draft included `ctx.isIdle()` as a gate. Smoke test
|
|
15
|
-
* showed that `ctx.isIdle()` returns false at microtask time even though
|
|
16
|
-
* `agent_end` has already fired, blocking the drain. The gate was
|
|
17
|
-
* removed: `agent_end` by definition means the agent ended, and the
|
|
18
|
-
* `ctx.hasPendingMessages()` gate handles the TUI-coexistence concern.
|
|
19
|
-
*
|
|
20
|
-
* Spec: mid-turn-prompt-queue — Requirement "Bridge follow-up drain loop
|
|
21
|
-
* runs on agent_end with pop-before-send invariant".
|
|
22
|
-
*
|
|
23
|
-
* See change: rework-mid-turn-prompt-queue.
|
|
24
|
-
*/
|
|
25
|
-
import { describe, it, expect, vi } from "vitest";
|
|
26
|
-
|
|
27
|
-
type AnyMock = ((...args: any[]) => any) & ReturnType<typeof vi.fn>;
|
|
28
|
-
|
|
29
|
-
interface PiLike {
|
|
30
|
-
sendUserMessage: AnyMock;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface CtxLike {
|
|
34
|
-
hasPendingMessages?: AnyMock;
|
|
35
|
-
isIdle?: AnyMock;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
interface Harness {
|
|
39
|
-
pi: PiLike;
|
|
40
|
-
ctx: CtxLike;
|
|
41
|
-
buffer: string[];
|
|
42
|
-
emit: AnyMock;
|
|
43
|
-
callLog: string[];
|
|
44
|
-
drainOnce: () => void;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function makeHarness(opts: {
|
|
48
|
-
initial?: string[];
|
|
49
|
-
hasPendingMessages?: boolean | undefined; // undefined => method absent
|
|
50
|
-
throwOnSend?: boolean;
|
|
51
|
-
idle?: boolean; // default true
|
|
52
|
-
}): Harness {
|
|
53
|
-
const callLog: string[] = [];
|
|
54
|
-
|
|
55
|
-
const pi: PiLike = {
|
|
56
|
-
sendUserMessage: vi.fn((entry: unknown) => {
|
|
57
|
-
callLog.push(`pi.sendUserMessage:${entry}`);
|
|
58
|
-
if (opts.throwOnSend) throw new Error("pi exploded");
|
|
59
|
-
}) as AnyMock,
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const ctx: CtxLike = {
|
|
63
|
-
isIdle: vi.fn(() => {
|
|
64
|
-
callLog.push("ctx.isIdle");
|
|
65
|
-
return opts.idle ?? true;
|
|
66
|
-
}) as AnyMock,
|
|
67
|
-
};
|
|
68
|
-
if (opts.hasPendingMessages !== undefined) {
|
|
69
|
-
ctx.hasPendingMessages = vi.fn(() => {
|
|
70
|
-
callLog.push("ctx.hasPendingMessages");
|
|
71
|
-
return opts.hasPendingMessages!;
|
|
72
|
-
}) as AnyMock;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const buffer: string[] = [...(opts.initial ?? [])];
|
|
76
|
-
const emit = vi.fn(() => {
|
|
77
|
-
callLog.push(`emit:${JSON.stringify([...buffer])}`);
|
|
78
|
-
}) as AnyMock;
|
|
79
|
-
|
|
80
|
-
// Mirror bridge.ts drainFollowupQueue 1:1 (post-smoke-fix #3:
|
|
81
|
-
// sendUserMessage with NO deliverAs after ctx.isIdle() returns true).
|
|
82
|
-
// The retry loop is omitted from this synchronous harness; tests that
|
|
83
|
-
// exercise the not-idle branch verify no-pi-call directly.
|
|
84
|
-
let isDraining = false;
|
|
85
|
-
const drainOnce = (): void => {
|
|
86
|
-
if (isDraining) return;
|
|
87
|
-
if (buffer.length === 0) return;
|
|
88
|
-
if (typeof ctx.hasPendingMessages === "function") {
|
|
89
|
-
try { if (ctx.hasPendingMessages()) return; } catch { /* swallow */ }
|
|
90
|
-
}
|
|
91
|
-
const idle = (() => {
|
|
92
|
-
try { return ctx.isIdle?.() === true; } catch { return false; }
|
|
93
|
-
})();
|
|
94
|
-
if (!idle) return; // real code retries via setTimeout; harness just bails
|
|
95
|
-
isDraining = true;
|
|
96
|
-
try {
|
|
97
|
-
// POP FIRST.
|
|
98
|
-
const entry = buffer.shift()!;
|
|
99
|
-
callLog.push(`buffer.shift:${entry}`);
|
|
100
|
-
// EMIT BEFORE SEND.
|
|
101
|
-
emit();
|
|
102
|
-
// SEND with NO deliverAs (fresh turn).
|
|
103
|
-
try {
|
|
104
|
-
pi.sendUserMessage(entry);
|
|
105
|
-
} catch {
|
|
106
|
-
// INTENTIONAL no re-push.
|
|
107
|
-
}
|
|
108
|
-
} finally {
|
|
109
|
-
isDraining = false;
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
return { pi, ctx, buffer, emit, callLog, drainOnce };
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
describe("drainFollowupQueue: pop-before-send invariant", () => {
|
|
117
|
-
it("calls buffer.shift BEFORE pi.sendUserMessage in the call log", () => {
|
|
118
|
-
const h = makeHarness({ initial: ["a"], hasPendingMessages: false });
|
|
119
|
-
h.drainOnce();
|
|
120
|
-
const shiftIdx = h.callLog.findIndex((s) => s.startsWith("buffer.shift:"));
|
|
121
|
-
const sendIdx = h.callLog.findIndex((s) => s.startsWith("pi.sendUserMessage:"));
|
|
122
|
-
expect(shiftIdx).toBeGreaterThanOrEqual(0);
|
|
123
|
-
expect(sendIdx).toBeGreaterThan(shiftIdx);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("emits queue_update BEFORE pi.sendUserMessage", () => {
|
|
127
|
-
const h = makeHarness({ initial: ["a"], hasPendingMessages: false });
|
|
128
|
-
h.drainOnce();
|
|
129
|
-
const emitIdx = h.callLog.findIndex((s) => s.startsWith("emit:"));
|
|
130
|
-
const sendIdx = h.callLog.findIndex((s) => s.startsWith("pi.sendUserMessage:"));
|
|
131
|
-
expect(emitIdx).toBeGreaterThanOrEqual(0);
|
|
132
|
-
expect(sendIdx).toBeGreaterThan(emitIdx);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it("calls pi.sendUserMessage with NO deliverAs (fresh-turn semantics)", () => {
|
|
136
|
-
const h = makeHarness({ initial: ["a"], hasPendingMessages: false, idle: true });
|
|
137
|
-
h.drainOnce();
|
|
138
|
-
// After ctx.isIdle()=true, pi.sendUserMessage(entry) starts a fresh
|
|
139
|
-
// turn via Agent.prompt(). deliverAs is intentionally omitted because
|
|
140
|
-
// pi's followUpQueue is no longer being drained post-agent_end.
|
|
141
|
-
expect(h.pi.sendUserMessage).toHaveBeenCalledWith("a");
|
|
142
|
-
expect(h.pi.sendUserMessage.mock.calls[0]).toHaveLength(1);
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
describe("drainFollowupQueue: one entry per agent_end", () => {
|
|
147
|
-
it("drains only ONE entry per call", () => {
|
|
148
|
-
const h = makeHarness({ initial: ["a", "b", "c"], hasPendingMessages: false });
|
|
149
|
-
h.drainOnce();
|
|
150
|
-
expect(h.buffer).toEqual(["b", "c"]);
|
|
151
|
-
expect(h.pi.sendUserMessage).toHaveBeenCalledTimes(1);
|
|
152
|
-
expect(h.pi.sendUserMessage).toHaveBeenCalledWith("a");
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("drains in FIFO order across multiple agent_end fires", () => {
|
|
156
|
-
const h = makeHarness({ initial: ["a", "b", "c"], hasPendingMessages: false });
|
|
157
|
-
h.drainOnce(); // → "a"
|
|
158
|
-
h.drainOnce(); // → "b"
|
|
159
|
-
h.drainOnce(); // → "c"
|
|
160
|
-
expect(h.buffer).toEqual([]);
|
|
161
|
-
expect(h.pi.sendUserMessage.mock.calls.map((c) => c[0])).toEqual(["a", "b", "c"]);
|
|
162
|
-
// No deliverAs option on any call — fresh-turn semantics throughout.
|
|
163
|
-
for (const call of h.pi.sendUserMessage.mock.calls) {
|
|
164
|
-
expect(call).toHaveLength(1);
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it("bails when ctx.isIdle returns false (transition window)", () => {
|
|
169
|
-
const h = makeHarness({ initial: ["a"], hasPendingMessages: false, idle: false });
|
|
170
|
-
h.drainOnce();
|
|
171
|
-
// Pi still in transition — buffer untouched, no pi call.
|
|
172
|
-
expect(h.buffer).toEqual(["a"]);
|
|
173
|
-
expect(h.pi.sendUserMessage).not.toHaveBeenCalled();
|
|
174
|
-
expect(h.emit).not.toHaveBeenCalled();
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
describe("drainFollowupQueue: gates", () => {
|
|
179
|
-
it("TUI gate: bails when ctx.hasPendingMessages() returns true", () => {
|
|
180
|
-
const h = makeHarness({ initial: ["a"], hasPendingMessages: true });
|
|
181
|
-
h.drainOnce();
|
|
182
|
-
expect(h.buffer).toEqual(["a"]);
|
|
183
|
-
expect(h.pi.sendUserMessage).not.toHaveBeenCalled();
|
|
184
|
-
expect(h.emit).not.toHaveBeenCalled();
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it("works when ctx.hasPendingMessages is absent (older pi version)", () => {
|
|
188
|
-
const h = makeHarness({ initial: ["a"], hasPendingMessages: undefined });
|
|
189
|
-
h.drainOnce();
|
|
190
|
-
expect(h.buffer).toEqual([]);
|
|
191
|
-
expect(h.pi.sendUserMessage).toHaveBeenCalledWith("a");
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it("empty-buffer gate: no-op when buffer empty", () => {
|
|
195
|
-
const h = makeHarness({ initial: [], hasPendingMessages: false });
|
|
196
|
-
h.drainOnce();
|
|
197
|
-
expect(h.buffer).toEqual([]);
|
|
198
|
-
expect(h.emit).not.toHaveBeenCalled();
|
|
199
|
-
expect(h.pi.sendUserMessage).not.toHaveBeenCalled();
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
describe("drainFollowupQueue: pi error handling", () => {
|
|
204
|
-
it("entry is LOST when pi.sendUserMessage throws (no re-push)", () => {
|
|
205
|
-
const h = makeHarness({
|
|
206
|
-
initial: ["a"],
|
|
207
|
-
hasPendingMessages: false,
|
|
208
|
-
throwOnSend: true,
|
|
209
|
-
});
|
|
210
|
-
// Suppress the warning log from the drain — it's expected.
|
|
211
|
-
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
212
|
-
h.drainOnce();
|
|
213
|
-
expect(h.buffer).toEqual([]); // entry NOT re-pushed
|
|
214
|
-
expect(h.pi.sendUserMessage).toHaveBeenCalledTimes(1);
|
|
215
|
-
warnSpy.mockRestore();
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it("next drain finds empty buffer and no-ops", () => {
|
|
219
|
-
const h = makeHarness({
|
|
220
|
-
initial: ["a"],
|
|
221
|
-
hasPendingMessages: false,
|
|
222
|
-
throwOnSend: true,
|
|
223
|
-
});
|
|
224
|
-
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
225
|
-
h.drainOnce();
|
|
226
|
-
h.drainOnce(); // empty-buffer gate
|
|
227
|
-
expect(h.pi.sendUserMessage).toHaveBeenCalledTimes(1);
|
|
228
|
-
warnSpy.mockRestore();
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
describe("drainFollowupQueue: re-entrancy lock", () => {
|
|
233
|
-
it("synchronous re-entry inside the drain returns early", () => {
|
|
234
|
-
// Simulate re-entry by having pi.sendUserMessage re-invoke drainOnce().
|
|
235
|
-
// The lock must prevent the inner call from doing any work.
|
|
236
|
-
const callLog: string[] = [];
|
|
237
|
-
const buffer: string[] = ["a", "b"];
|
|
238
|
-
const emit = vi.fn(() => callLog.push(`emit:${JSON.stringify([...buffer])}`));
|
|
239
|
-
|
|
240
|
-
let isDraining = false;
|
|
241
|
-
let reentrySucceeded = false;
|
|
242
|
-
const drainOnce = (): void => {
|
|
243
|
-
if (isDraining) {
|
|
244
|
-
reentrySucceeded = true;
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
isDraining = true;
|
|
248
|
-
try {
|
|
249
|
-
if (buffer.length === 0) return;
|
|
250
|
-
const entry = buffer.shift()!;
|
|
251
|
-
callLog.push(`shift:${entry}`);
|
|
252
|
-
emit();
|
|
253
|
-
// Synchronous re-entry attempt inside the same frame.
|
|
254
|
-
drainOnce();
|
|
255
|
-
callLog.push(`outer-done:${entry}`);
|
|
256
|
-
} finally {
|
|
257
|
-
isDraining = false;
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
drainOnce();
|
|
262
|
-
expect(buffer).toEqual(["b"]); // only one entry consumed
|
|
263
|
-
expect(reentrySucceeded).toBe(true); // re-entry tried but was blocked
|
|
264
|
-
expect(callLog).toEqual(["shift:a", "emit:[\"b\"]", "outer-done:a"]);
|
|
265
|
-
});
|
|
266
|
-
});
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for `flipHasUI` — pure helper invoked by bridge.ts in `session_start`
|
|
3
|
-
* AFTER the PromptBus wrappers have been installed on `ctx.ui.*`. Flips
|
|
4
|
-
* `ctx.hasUI` to `true` so extensions that branch on it (`context-mode`,
|
|
5
|
-
* `pi-agent-browser`, etc.) take their UI-present branch and render output
|
|
6
|
-
* through the proxied `ctx.ui.notify` instead of returning unrendered data.
|
|
7
|
-
*
|
|
8
|
-
* Spec: openspec/changes/fix-bridge-hasui-for-headless-rpc/
|
|
9
|
-
* specs/bridge-extension/spec.md — requirement
|
|
10
|
-
* "Bridge SHALL flip `ctx.hasUI` to `true` after wiring the UI proxy".
|
|
11
|
-
*/
|
|
12
|
-
import { describe, it, expect, vi, afterEach } from "vitest";
|
|
13
|
-
import { flipHasUI } from "../hasui-flip.js";
|
|
14
|
-
|
|
15
|
-
describe("flipHasUI", () => {
|
|
16
|
-
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
17
|
-
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
warnSpy.mockClear();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("headless RPC: flips ctx.hasUI from false to true", () => {
|
|
23
|
-
const ctx: { hasUI: boolean } = { hasUI: false };
|
|
24
|
-
flipHasUI(ctx);
|
|
25
|
-
expect(ctx.hasUI).toBe(true);
|
|
26
|
-
expect(warnSpy).not.toHaveBeenCalled();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("tmux: no-op when ctx.hasUI is already true", () => {
|
|
30
|
-
const ctx: { hasUI: boolean } = { hasUI: true };
|
|
31
|
-
flipHasUI(ctx);
|
|
32
|
-
expect(ctx.hasUI).toBe(true);
|
|
33
|
-
expect(warnSpy).not.toHaveBeenCalled();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("undefined ctx.hasUI is flipped to true", () => {
|
|
37
|
-
const ctx: { hasUI?: boolean } = {};
|
|
38
|
-
flipHasUI(ctx);
|
|
39
|
-
expect(ctx.hasUI).toBe(true);
|
|
40
|
-
expect(warnSpy).not.toHaveBeenCalled();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("pi >=0.80 configurable getter: redefines descriptor, flips to true, no warn", () => {
|
|
44
|
-
// Real shape of pi's extension-context `get hasUI()` — an own accessor
|
|
45
|
-
// that is configurable, so it can be redefined via defineProperty.
|
|
46
|
-
const ctx: Record<string, unknown> = {};
|
|
47
|
-
Object.defineProperty(ctx, "hasUI", {
|
|
48
|
-
configurable: true,
|
|
49
|
-
enumerable: true,
|
|
50
|
-
get: () => false,
|
|
51
|
-
// No setter — assignment throws TypeError; defineProperty must be used.
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
expect(() => flipHasUI(ctx)).not.toThrow();
|
|
55
|
-
expect((ctx as { hasUI: boolean }).hasUI).toBe(true);
|
|
56
|
-
expect(warnSpy).not.toHaveBeenCalled();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("non-configurable getter: swallows error, logs warning exactly once", () => {
|
|
60
|
-
const ctx: Record<string, unknown> = {};
|
|
61
|
-
Object.defineProperty(ctx, "hasUI", {
|
|
62
|
-
configurable: false,
|
|
63
|
-
get: () => false,
|
|
64
|
-
// No setter and non-configurable — cannot assign or redefine.
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
expect(() => flipHasUI(ctx)).not.toThrow();
|
|
68
|
-
expect((ctx as { hasUI: boolean }).hasUI).toBe(false); // unchanged
|
|
69
|
-
expect(warnSpy).toHaveBeenCalledTimes(1);
|
|
70
|
-
expect(warnSpy.mock.calls[0][0]).toContain("[dashboard] failed to flip ctx.hasUI");
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("frozen ctx: swallows error, logs warning", () => {
|
|
74
|
-
const ctx = Object.freeze({ hasUI: false });
|
|
75
|
-
|
|
76
|
-
expect(() => flipHasUI(ctx)).not.toThrow();
|
|
77
|
-
expect(ctx.hasUI).toBe(false);
|
|
78
|
-
expect(warnSpy).toHaveBeenCalledTimes(1);
|
|
79
|
-
expect(warnSpy.mock.calls[0][0]).toContain("[dashboard] failed to flip ctx.hasUI");
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("null ctx: no-op, no throw, no warn", () => {
|
|
83
|
-
expect(() => flipHasUI(null as unknown as { hasUI?: boolean })).not.toThrow();
|
|
84
|
-
expect(warnSpy).not.toHaveBeenCalled();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it("undefined ctx: no-op, no throw, no warn", () => {
|
|
88
|
-
expect(() => flipHasUI(undefined as unknown as { hasUI?: boolean })).not.toThrow();
|
|
89
|
-
expect(warnSpy).not.toHaveBeenCalled();
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("does not mutate sibling fields on ctx", () => {
|
|
93
|
-
const ctx: Record<string, unknown> = {
|
|
94
|
-
hasUI: false,
|
|
95
|
-
cwd: "/tmp/foo",
|
|
96
|
-
ui: { notify: vi.fn() },
|
|
97
|
-
sessionManager: { getSessionId: () => "abc" },
|
|
98
|
-
};
|
|
99
|
-
const uiBefore = ctx.ui;
|
|
100
|
-
const smBefore = ctx.sessionManager;
|
|
101
|
-
|
|
102
|
-
flipHasUI(ctx as { hasUI: boolean });
|
|
103
|
-
|
|
104
|
-
expect(ctx.hasUI).toBe(true);
|
|
105
|
-
expect(ctx.cwd).toBe("/tmp/foo");
|
|
106
|
-
expect(ctx.ui).toBe(uiBefore);
|
|
107
|
-
expect(ctx.sessionManager).toBe(smBefore);
|
|
108
|
-
});
|
|
109
|
-
});
|