Files
oh-my-pi/packages/coding-agent/test/interactive-mode-lsp-startup.test.ts
T
can1357 16ad914da0 feat(coding-agent): added LSP status updates to welcome banner on warmup completion
- Added real-time LSP server status updates in welcome banner when background warmup completes.
- Changed welcome banner status icon from warning to muted pending symbol for improved visual clarity.
- Extracted LSP server conversion logic into dedicated helper methods for better maintainability.
- Added comprehensive test coverage for interactive mode LSP startup welcome banner updates.
2026-04-08 08:58:39 +02:00

107 lines
3.3 KiB
TypeScript

import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "bun:test";
import * as path from "node:path";
import { Agent } from "@oh-my-pi/pi-agent-core";
import { _resetSettingsForTest, Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
import { initTheme, theme } from "@oh-my-pi/pi-coding-agent/modes/theme/theme";
import { TempDir } from "@oh-my-pi/pi-utils";
import { ModelRegistry } from "../src/config/model-registry";
import { LSP_STARTUP_EVENT_CHANNEL, type LspStartupEvent } from "../src/lsp/startup-events";
import { InteractiveMode } from "../src/modes/interactive-mode";
import { AgentSession } from "../src/session/agent-session";
import { AuthStorage } from "../src/session/auth-storage";
import { SessionManager } from "../src/session/session-manager";
import type { LspStartupServerInfo } from "../src/tools";
import { EventBus } from "../src/utils/event-bus";
describe("InteractiveMode LSP startup welcome banner", () => {
let authStorage: AuthStorage;
let eventBus: EventBus;
let lspServers: LspStartupServerInfo[];
let mode: InteractiveMode;
let session: AgentSession;
let tempDir: TempDir;
beforeAll(() => {
initTheme();
});
beforeEach(async () => {
_resetSettingsForTest();
tempDir = TempDir.createSync("@pi-interactive-mode-lsp-startup-");
await Settings.init({ inMemory: true, cwd: tempDir.path() });
authStorage = await AuthStorage.create(path.join(tempDir.path(), "testauth.db"));
const modelRegistry = new ModelRegistry(authStorage);
const model = modelRegistry.find("anthropic", "claude-sonnet-4-5");
if (!model) {
throw new Error("Expected claude-sonnet-4-5 to exist in registry");
}
session = new AgentSession({
agent: new Agent({
initialState: {
model,
systemPrompt: "Test",
tools: [],
messages: [],
},
}),
sessionManager: SessionManager.create(tempDir.path(), tempDir.path()),
settings: Settings.isolated(),
modelRegistry,
});
eventBus = new EventBus();
lspServers = [
{
name: "rust-analyzer",
status: "connecting",
fileTypes: [".rs"],
},
];
mode = new InteractiveMode(session, "test", undefined, () => {}, lspServers, undefined, eventBus);
});
afterEach(async () => {
vi.restoreAllMocks();
mode?.stop();
await session?.dispose();
authStorage?.close();
tempDir?.removeSync();
_resetSettingsForTest();
});
it("updates the welcome banner when startup warmup completes", async () => {
await mode.init();
const findServerLine = () =>
Bun.stripANSI(mode.ui.render(120).join("\n"))
.split("\n")
.find(line => line.includes("rust-analyzer")) ?? "";
expect(findServerLine()).toContain(theme.status.pending);
const requestRenderSpy = vi.spyOn(mode.ui, "requestRender");
const showStatusSpy = vi.spyOn(mode, "showStatus");
requestRenderSpy.mockClear();
showStatusSpy.mockClear();
lspServers[0].status = "ready";
const event: LspStartupEvent = {
type: "completed",
servers: [
{
name: "rust-analyzer",
status: "ready",
fileTypes: [".rs"],
},
],
};
eventBus.emit(LSP_STARTUP_EVENT_CHANNEL, event);
expect(requestRenderSpy).toHaveBeenCalled();
expect(showStatusSpy).not.toHaveBeenCalled();
expect(findServerLine()).toContain(theme.status.success);
expect(findServerLine()).not.toContain(theme.status.pending);
});
});