From b46c130dad73fa58c3d43e579dfe131992e09573 Mon Sep 17 00:00:00 2001 From: Val Alexander Date: Fri, 27 Mar 2026 22:25:59 -0500 Subject: [PATCH 1/2] refactor: enhance type safety and improve keybinding assertions in WebSocket server tests - Update imports in wsServer.test.ts to include GitActionProgressReporter for better type handling. - Refine type assertions in logSpy mock calls to ensure correct message types. - Modify keybinding assertions to validate specific command bindings and ensure non-existent commands are excluded. --- apps/server/src/wsServer.test.ts | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/apps/server/src/wsServer.test.ts b/apps/server/src/wsServer.test.ts index 98236db54..e4c3c0351 100644 --- a/apps/server/src/wsServer.test.ts +++ b/apps/server/src/wsServer.test.ts @@ -47,7 +47,11 @@ import { SqlClient, SqlError } from "effect/unstable/sql"; import { ProviderService, type ProviderServiceShape } from "./provider/Services/ProviderService"; import { ProviderHealth, type ProviderHealthShape } from "./provider/Services/ProviderHealth"; import { Open, type OpenShape } from "./open"; -import { GitManager, type GitManagerShape } from "./git/Services/GitManager.ts"; +import { + GitActionProgressReporter, + GitManager, + type GitManagerShape, +} from "./git/Services/GitManager.ts"; import type { GitCoreShape } from "./git/Services/GitCore.ts"; import { GitCore } from "./git/Services/GitCore.ts"; import { GitCommandError, GitManagerError } from "./git/Errors.ts"; @@ -813,7 +817,7 @@ describe("WebSocket Server", () => { connections.push(ws); expect( - logSpy.mock.calls.some(([message]) => { + logSpy.mock.calls.some(([message]: [unknown]) => { if (typeof message !== "string") return false; return ( message.includes("[ws]") && @@ -957,9 +961,19 @@ describe("WebSocket Server", () => { message: expect.any(String), }, ]); - expect(result.keybindings).toHaveLength(DEFAULT_RESOLVED_KEYBINDINGS.length); - expect(result.keybindings.some((entry) => entry.command === "terminal.toggle")).toBe(true); + const expectedTerminalToggle = compileResolvedKeybindingRule({ + key: "mod+j", + command: "terminal.toggle", + }); + expect(expectedTerminalToggle).not.toBeNull(); + expect(result.keybindings.filter((entry) => entry.command === "terminal.toggle")).toEqual([ + expectedTerminalToggle, + ]); expect(result.keybindings.some((entry) => entry.command === "terminal.new")).toBe(true); + expect(result.keybindings.some((entry) => entry.command === "terminal.split")).toBe(true); + expect(result.keybindings.some((entry) => String(entry.command) === "not-a-real-command")).toBe( + false, + ); expect(result.providers).toEqual(defaultProviderStatuses); expectAvailableEditors(result.availableEditors); }); @@ -1878,10 +1892,13 @@ describe("WebSocket Server", () => { it("publishes git action progress only to the initiating websocket", async () => { const runStackedAction = vi.fn( - (_input, options) => + ( + _input: GitRunStackedActionInput, + options?: { actionId?: string; progressReporter?: GitActionProgressReporter } | undefined, + ) => options?.progressReporter ?.publish({ - actionId: options.actionId ?? "action-1", + actionId: options?.actionId ?? "action-1", cwd: "/test", action: "commit", kind: "phase_started", From dcf51b3732e6189841c70b450a66ca8842636ba5 Mon Sep 17 00:00:00 2001 From: Val Alexander Date: Fri, 27 Mar 2026 22:29:46 -0500 Subject: [PATCH 2/2] Refine ws server test stubs for keybinding and git progress - Simplify keybinding assertion with a named invalid command - Tighten git action progress stub to use the request input --- apps/server/src/wsServer.test.ts | 65 +++++++++++++------------------- 1 file changed, 27 insertions(+), 38 deletions(-) diff --git a/apps/server/src/wsServer.test.ts b/apps/server/src/wsServer.test.ts index e4c3c0351..9dab50d33 100644 --- a/apps/server/src/wsServer.test.ts +++ b/apps/server/src/wsServer.test.ts @@ -47,11 +47,7 @@ import { SqlClient, SqlError } from "effect/unstable/sql"; import { ProviderService, type ProviderServiceShape } from "./provider/Services/ProviderService"; import { ProviderHealth, type ProviderHealthShape } from "./provider/Services/ProviderHealth"; import { Open, type OpenShape } from "./open"; -import { - GitActionProgressReporter, - GitManager, - type GitManagerShape, -} from "./git/Services/GitManager.ts"; +import { GitManager, type GitManagerShape } from "./git/Services/GitManager.ts"; import type { GitCoreShape } from "./git/Services/GitCore.ts"; import { GitCore } from "./git/Services/GitCore.ts"; import { GitCommandError, GitManagerError } from "./git/Errors.ts"; @@ -817,7 +813,8 @@ describe("WebSocket Server", () => { connections.push(ws); expect( - logSpy.mock.calls.some(([message]: [unknown]) => { + logSpy.mock.calls.some((call) => { + const [message] = call; if (typeof message !== "string") return false; return ( message.includes("[ws]") && @@ -971,9 +968,8 @@ describe("WebSocket Server", () => { ]); expect(result.keybindings.some((entry) => entry.command === "terminal.new")).toBe(true); expect(result.keybindings.some((entry) => entry.command === "terminal.split")).toBe(true); - expect(result.keybindings.some((entry) => String(entry.command) === "not-a-real-command")).toBe( - false, - ); + const invalidUserCommand: string = "not-a-real-command"; + expect(result.keybindings.some((entry) => entry.command === invalidUserCommand)).toBe(false); expect(result.providers).toEqual(defaultProviderStatuses); expectAvailableEditors(result.availableEditors); }); @@ -1891,36 +1887,29 @@ describe("WebSocket Server", () => { }); it("publishes git action progress only to the initiating websocket", async () => { - const runStackedAction = vi.fn( + const runStackedAction: GitManagerShape["runStackedAction"] = (input, options) => ( - _input: GitRunStackedActionInput, - options?: { actionId?: string; progressReporter?: GitActionProgressReporter } | undefined, - ) => - options?.progressReporter - ?.publish({ - actionId: options?.actionId ?? "action-1", - cwd: "/test", - action: "commit", - kind: "phase_started", - phase: "commit", - label: "Committing...", - }) - .pipe( - Effect.flatMap(() => - Effect.succeed({ - action: "commit" as const, - branch: { status: "skipped_not_requested" as const }, - commit: { - status: "created" as const, - commitSha: "abc1234", - subject: "Test commit", - }, - push: { status: "skipped_not_requested" as const }, - pr: { status: "skipped_not_requested" as const }, - }), - ), - ) ?? Effect.void, - ); + options?.progressReporter?.publish({ + actionId: options?.actionId ?? input.actionId, + cwd: input.cwd, + action: "commit", + kind: "phase_started", + phase: "commit", + label: "Committing...", + }) ?? Effect.void + ).pipe( + Effect.as({ + action: "commit" as const, + branch: { status: "skipped_not_requested" as const }, + commit: { + status: "created" as const, + commitSha: "abc1234", + subject: "Test commit", + }, + push: { status: "skipped_not_requested" as const }, + pr: { status: "skipped_not_requested" as const }, + }), + ); const gitManager: GitManagerShape = { status: vi.fn(() => Effect.void as any), resolvePullRequest: vi.fn(() => Effect.void as any),