Files
pi2d/web/tests/chat.commands.test.tsx
yuez 3789394c85 refactor(web): remove the dead right-panel and subagent-preview code
v0.1.1 replaced both surfaces: the session tray took the right panel's
todo/tasks, and the in-place `?sub=` child view took the subagent preview.

- delete `features/chat/side-panel.tsx` (nothing imported it since the tray
  landed)
- delete `SubagentModal` and its private helpers (`SUB_BADGE`, `SUB_DOT`,
  `SubagentEntry`, `parseSubagentLines`, `SUB_ROLES`); the child view builds its
  timeline from the parent's entries instead of `subagent.read`
- drop `chatCommands.readSubagent` (its only caller is gone)
- drop the deprecated store slice `PreviewTarget` / `preview` / `setPreview`,
  including the session-migration re-key and the `PanelTab` alias
- drop their exclusive CSS (`.sub-item*`, `.sub-preview*`, `.sub-steer`) and the
  6 orphan catalog keys (chat.subagentTitle, chat.preview, chat.previewNote,
  chat.task, chat.currentSubagents, chat.steerRequired)
- tests: remove the two SubagentModal cases and the preview/readSubagent
  expectations (295 tests, down from 297 — exactly the deleted cases)

Verification: typecheck clean, vitest 295/295, vite build green, visual matrix
24/24 clean.
2026-10-27 09:26:36 +08:00

135 lines
5.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
cancelResponse,
chatCommands,
confirmResponse,
diffAnswer,
diffResponse,
selectResponse,
} from "@/features/chat/commands";
/**
* Payload shapes are owned by the plugin
* (`pi2.nvim-web/lua/pi/web/commands.lua`); these assertions are the contract.
*/
describe("chat command payloads", () => {
it("sends prompts with the plugin's modes and images", () => {
const plain = chatCommands.sendPrompt("s1", "hi");
expect(plain).toMatchObject({ method: "prompt.send", sessionId: "s1", params: { text: "hi" } });
// A prompt while idle is a plain prompt: no follow-up/steer wrapper.
expect(plain.params).not.toHaveProperty("mode");
expect(chatCommands.sendPrompt("s1", "hi", [], "follow_up").params).toMatchObject({
text: "hi",
mode: "follow_up",
});
expect(chatCommands.sendPrompt("s1", "hi", [], "steer").params).toMatchObject({
text: "hi",
mode: "steer",
});
expect(
chatCommands.sendPrompt("s1", "hi", [{ mimeType: "image/png", data: "AAA" }], "follow_up").params,
).toMatchObject({
text: "hi",
mode: "follow_up",
images: [{ mimeType: "image/png", data: "AAA" }],
});
});
it("addresses queue entries by id and sets the steering mode", () => {
expect(chatCommands.removeQueued("s1", "q1")).toMatchObject({
method: "queue.remove",
params: { id: "q1" },
});
expect(chatCommands.setQueueSteer("s1", true)).toMatchObject({
method: "queue.setSteer",
params: { mode: "all" },
});
expect(chatCommands.setQueueSteer("s1", false)).toMatchObject({
method: "queue.setSteer",
params: { mode: "one-at-a-time" },
});
});
it("wraps model and thinking changes in the plugin's fields", () => {
expect(chatCommands.setModel("s1", { provider: "anthropic", id: "m" })).toMatchObject({
method: "session.setModel",
params: { model: { provider: "anthropic", id: "m" } },
});
expect(chatCommands.setThinking("s1", "high")).toMatchObject({
method: "session.setThinking",
params: { level: "high" },
});
});
it("builds attention answers in the `pi.attention.resolve` shape", () => {
expect(selectResponse("allow-once")).toEqual({ value: "allow-once" });
expect(confirmResponse(true)).toEqual({ confirmed: true });
expect(confirmResponse(false)).toEqual({ confirmed: false });
expect(cancelResponse()).toEqual({ cancelled: true });
expect(chatCommands.respondAttention("s1", "att-1", selectResponse("allow-once"))).toMatchObject({
method: "attention.respond",
params: { requestId: "att-1", response: { value: "allow-once" } },
});
expect(chatCommands.respondAttention("s1", "att-1", confirmResponse(true))).toMatchObject({
params: { requestId: "att-1", response: { confirmed: true } },
});
// Diff review: the JSON `{result, path?}` string rides inside `value`.
expect(diffResponse("Accepted")).toBe(JSON.stringify({ result: "Accepted" }));
expect(diffResponse("Rejected", "src/auth.ts")).toBe(
JSON.stringify({ result: "Rejected", path: "src/auth.ts" }),
);
expect(diffAnswer("Accepted")).toEqual({ value: diffResponse("Accepted") });
expect(chatCommands.respondAttention("s1", "att-2", diffAnswer("Accepted"))).toMatchObject({
params: { requestId: "att-2", response: { value: diffResponse("Accepted") } },
});
});
it("dispatches one batch item with the snake_case contract", () => {
expect(
chatCommands.dispatchSubagent("s1", {
task: "do it",
name: "worker",
model: { provider: "anthropic", id: "m" },
thinking: "low",
wait: true,
cancelSiblingsOnFail: true,
}),
).toMatchObject({
method: "subagent.dispatch",
params: {
items: [
{
task: "do it",
name: "worker",
model: { provider: "anthropic", id: "m" },
thinking_level: "low",
},
],
wait: true,
cancel_siblings_on_fail: true,
},
});
expect(chatCommands.dispatchSubagent("s1", { task: "solo" }).params).toEqual({
items: [{ task: "solo" }],
wait: false,
cancel_siblings_on_fail: false,
});
});
it("reads task output by id", () => {
expect(chatCommands.stopTask("s1", "t1")).toMatchObject({
method: "task.stop",
params: { taskId: "t1" },
});
expect(chatCommands.taskOutput("s1", "t1")).toMatchObject({
method: "task.output",
params: { taskId: "t1" },
});
});
});