diff options
| author | Adam Malczewski <[email protected]> | 2026-06-11 21:12:03 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-06-11 21:12:03 +0900 |
| commit | e7eada4802ceebd86c83bcd6e3eca70152e7f331 (patch) | |
| tree | 447095fd60b43980358d1565506f3ae2430e5f29 /packages/lsp/src/tool.test.ts | |
| parent | 35937cee7f838e414eb8147c67205e01d85a4da0 (diff) | |
| download | dispatch-e7eada4802ceebd86c83bcd6e3eca70152e7f331.tar.gz dispatch-e7eada4802ceebd86c83bcd6e3eca70152e7f331.zip | |
feat(lsp,cwd): LSP integration + per-conversation cwd; fix cache-warming cache bust
LSP + per-conversation CWD feature:
- new bundled `lsp` extension: hand-rolled JSON-RPC codec (framing/rpc), lazy
one-server-per-(serverID,root), per-cwd config resolution, on-demand `lsp` tool
- `conversation-store`: getCwd/setCwd (cwdKey); `session-orchestrator` defaults a
turn's cwd from the store
- `transport-http`: cwd + lsp status endpoints; wire types in transport-contract
- host-bin: register lsp; config wiring
Cache-warming fix (the warm read 0% on the first reheat after a message):
- warm assembled tools under a different cwd than the real turn (a reheat sends no
cwd, and the warm service had no store fallback). The skills filter rewrites the
cwd-sensitive `load_skill` description, so the tools block — the first bytes of
the prompt-cache prefix — diverged and the cache missed entirely. Warm now
resolves cwd as opts.cwd ?? conversationStore.getCwd(), mirroring handleMessage.
- capture warm sends as `provider.request` spans flagged `warm:true` (thread a
child logger into providerOpts) so warm vs real bodies are diffable (obs §3.1).
- kernel logger: span-close now merges child-bound attrs like span-open, so a
`warm:true` query finds the closed span (with usage/status), not just the open.
Tests: warm forwards a warm-flagged logger; warm falls back to stored cwd; logger
open/close attr consistency. Full suite green (873).
Diffstat (limited to 'packages/lsp/src/tool.test.ts')
| -rw-r--r-- | packages/lsp/src/tool.test.ts | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/packages/lsp/src/tool.test.ts b/packages/lsp/src/tool.test.ts new file mode 100644 index 0000000..03787ae --- /dev/null +++ b/packages/lsp/src/tool.test.ts @@ -0,0 +1,179 @@ +import { describe, expect, it } from "vitest"; +import type { LspManager } from "./manager.js"; +import { createLspTool } from "./tool.js"; + +function stubManager(overrides?: Partial<LspManager>): LspManager { + return { + status: async () => [], + getClient: () => undefined, + shutdownAll: () => {}, + ...overrides, + } as unknown as LspManager; +} + +describe("tool", () => { + it("diagnostics formats errors", async () => { + const tool = createLspTool(stubManager()); + const result = await tool.execute( + { operation: "diagnostics", path: "test.ts" }, + { + toolCallId: "test", + onOutput: () => {}, + signal: AbortSignal.timeout(5000), + log: { + debug: () => {}, + info: () => {}, + warn: () => {}, + error: () => {}, + child: () => ({}) as never, + span: () => ({}) as never, + }, + cwd: "/project", + }, + ); + expect(result.isError).toBe(true); + expect(result.content).toContain("No language server configured"); + }); + + it("position ops convert 1-based to 0-based", async () => { + let receivedPosition: { line: number; character: number } | null = null; + + const mockClient = { + getState: () => "connected" as const, + getStateError: () => undefined, + request: async (method: string, params: unknown) => { + if (method === "textDocument/hover") { + receivedPosition = (params as { position: { line: number; character: number } }).position; + return { contents: { value: "hover result" } }; + } + return null; + }, + waitForDiagnostics: async () => "", + }; + + const tool = createLspTool( + stubManager({ + status: async () => [ + { + id: "ts", + name: "TypeScript", + root: "/project", + extensions: [".ts"], + state: "connected", + }, + ], + getClient: () => mockClient as never, + }), + ); + + const result = await tool.execute( + { operation: "hover", path: "test.ts", line: 5, character: 10 }, + { + toolCallId: "test", + onOutput: () => {}, + signal: AbortSignal.timeout(5000), + log: { + debug: () => {}, + info: () => {}, + warn: () => {}, + error: () => {}, + child: () => ({}) as never, + span: () => ({}) as never, + }, + cwd: "/project", + }, + ); + + expect(receivedPosition).toEqual({ line: 4, character: 9 }); + expect(result.content).toBe("hover result"); + }); + + it("path resolved against ctx.cwd", async () => { + let receivedUri: string | null = null; + + const mockClient = { + getState: () => "connected" as const, + getStateError: () => undefined, + request: async (method: string, params: unknown) => { + if (method === "textDocument/hover") { + receivedUri = (params as { textDocument: { uri: string } }).textDocument.uri; + return { contents: { value: "ok" } }; + } + return null; + }, + waitForDiagnostics: async () => "", + }; + + const tool = createLspTool( + stubManager({ + status: async () => [ + { + id: "ts", + name: "TypeScript", + root: "/project", + extensions: [".ts"], + state: "connected", + }, + ], + getClient: () => mockClient as never, + }), + ); + + await tool.execute( + { operation: "hover", path: "src/test.ts", line: 1, character: 1 }, + { + toolCallId: "test", + onOutput: () => {}, + signal: AbortSignal.timeout(5000), + log: { + debug: () => {}, + info: () => {}, + warn: () => {}, + error: () => {}, + child: () => ({}) as never, + span: () => ({}) as never, + }, + cwd: "/project", + }, + ); + + expect(receivedUri).toBe("file:///project/src/test.ts"); + }); + + it("position op without line/character returns isError", async () => { + const tool = createLspTool( + stubManager({ + status: async () => [ + { + id: "ts", + name: "TypeScript", + root: "/project", + extensions: [".ts"], + state: "connected", + }, + ], + }), + ); + + const result = await tool.execute( + { operation: "hover", path: "test.ts" }, + { + toolCallId: "test", + onOutput: () => {}, + signal: AbortSignal.timeout(5000), + log: { + debug: () => {}, + info: () => {}, + warn: () => {}, + error: () => {}, + child: () => ({}) as never, + span: () => ({}) as never, + }, + cwd: "/project", + }, + ); + + expect(result.isError).toBe(true); + expect(result.content).toContain("requires both"); + }); +}); |
