From 5fe47e7be677eac9dfb3a5b2baf2fc0b38e2873c Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 16 Feb 2026 01:07:09 +0000 Subject: [PATCH] perf(test): fold ports + terminal note suites --- ...ers.normalizetextforcomparison.e2e.test.ts | 28 --------------- src/infra/ports-inspect.test.ts | 35 ------------------- src/infra/ports.test.ts | 35 ++++++++++++++++++- src/terminal/note.test.ts | 35 ------------------- src/terminal/table.test.ts | 34 ++++++++++++++++++ 5 files changed, 68 insertions(+), 99 deletions(-) delete mode 100644 src/agents/pi-embedded-helpers.normalizetextforcomparison.e2e.test.ts delete mode 100644 src/infra/ports-inspect.test.ts delete mode 100644 src/terminal/note.test.ts diff --git a/src/agents/pi-embedded-helpers.normalizetextforcomparison.e2e.test.ts b/src/agents/pi-embedded-helpers.normalizetextforcomparison.e2e.test.ts deleted file mode 100644 index 300dd234b..000000000 --- a/src/agents/pi-embedded-helpers.normalizetextforcomparison.e2e.test.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { normalizeTextForComparison } from "./pi-embedded-helpers.js"; -import { DEFAULT_AGENTS_FILENAME } from "./workspace.js"; - -const _makeFile = (overrides: Partial): WorkspaceBootstrapFile => ({ - name: DEFAULT_AGENTS_FILENAME, - path: "/tmp/AGENTS.md", - content: "", - missing: false, - ...overrides, -}); -describe("normalizeTextForComparison", () => { - it("lowercases text", () => { - expect(normalizeTextForComparison("Hello World")).toBe("hello world"); - }); - it("trims whitespace", () => { - expect(normalizeTextForComparison(" hello ")).toBe("hello"); - }); - it("collapses multiple spaces", () => { - expect(normalizeTextForComparison("hello world")).toBe("hello world"); - }); - it("strips emoji", () => { - expect(normalizeTextForComparison("Hello 👋 World 🌍")).toBe("hello world"); - }); - it("handles mixed normalization", () => { - expect(normalizeTextForComparison(" Hello 👋 WORLD 🌍 ")).toBe("hello world"); - }); -}); diff --git a/src/infra/ports-inspect.test.ts b/src/infra/ports-inspect.test.ts deleted file mode 100644 index 8aaeff424..000000000 --- a/src/infra/ports-inspect.test.ts +++ /dev/null @@ -1,35 +0,0 @@ -import net from "node:net"; -import { beforeEach, describe, expect, it, vi } from "vitest"; - -const runCommandWithTimeoutMock = vi.fn(); - -vi.mock("../process/exec.js", () => ({ - runCommandWithTimeout: (...args: unknown[]) => runCommandWithTimeoutMock(...args), -})); - -const describeUnix = process.platform === "win32" ? describe.skip : describe; - -describeUnix("inspectPortUsage", () => { - beforeEach(() => { - runCommandWithTimeoutMock.mockReset(); - }); - - it("reports busy when lsof is missing but loopback listener exists", async () => { - const server = net.createServer(); - await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve)); - const port = (server.address() as net.AddressInfo).port; - - runCommandWithTimeoutMock.mockRejectedValueOnce( - Object.assign(new Error("spawn lsof ENOENT"), { code: "ENOENT" }), - ); - - try { - const { inspectPortUsage } = await import("./ports-inspect.js"); - const result = await inspectPortUsage(port); - expect(result.status).toBe("busy"); - expect(result.errors?.some((err) => err.includes("ENOENT"))).toBe(true); - } finally { - server.close(); - } - }); -}); diff --git a/src/infra/ports.test.ts b/src/infra/ports.test.ts index 399ccd398..d3cf0ebce 100644 --- a/src/infra/ports.test.ts +++ b/src/infra/ports.test.ts @@ -1,5 +1,12 @@ import net from "node:net"; -import { describe, expect, it, vi } from "vitest"; +import { beforeEach, describe, expect, it, vi } from "vitest"; + +const runCommandWithTimeoutMock = vi.hoisted(() => vi.fn()); + +vi.mock("../process/exec.js", () => ({ + runCommandWithTimeout: (...args: unknown[]) => runCommandWithTimeoutMock(...args), +})); +import { inspectPortUsage } from "./ports-inspect.js"; import { buildPortHints, classifyPortListener, @@ -9,6 +16,8 @@ import { PortInUseError, } from "./ports.js"; +const describeUnix = process.platform === "win32" ? describe.skip : describe; + describe("ports helpers", () => { it("ensurePortAvailable rejects when port busy", async () => { const server = net.createServer(); @@ -58,3 +67,27 @@ describe("ports helpers", () => { expect(lines.some((line) => line.includes("SSH tunnel"))).toBe(true); }); }); + +describeUnix("inspectPortUsage", () => { + beforeEach(() => { + runCommandWithTimeoutMock.mockReset(); + }); + + it("reports busy when lsof is missing but loopback listener exists", async () => { + const server = net.createServer(); + await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve)); + const port = (server.address() as net.AddressInfo).port; + + runCommandWithTimeoutMock.mockRejectedValueOnce( + Object.assign(new Error("spawn lsof ENOENT"), { code: "ENOENT" }), + ); + + try { + const result = await inspectPortUsage(port); + expect(result.status).toBe("busy"); + expect(result.errors?.some((err) => err.includes("ENOENT"))).toBe(true); + } finally { + server.close(); + } + }); +}); diff --git a/src/terminal/note.test.ts b/src/terminal/note.test.ts deleted file mode 100644 index 7e5103748..000000000 --- a/src/terminal/note.test.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { wrapNoteMessage } from "./note.js"; - -describe("wrapNoteMessage", () => { - it("preserves long filesystem paths without inserting spaces/newlines", () => { - const input = - "/Users/user/Documents/Github/impact-signals-pipeline/with/really/long/segments/file.txt"; - const wrapped = wrapNoteMessage(input, { maxWidth: 22, columns: 80 }); - - expect(wrapped).toBe(input); - }); - - it("preserves long urls without inserting spaces/newlines", () => { - const input = - "https://example.com/this/is/a/very/long/url/segment/that/should/not/be/split/for-copy"; - const wrapped = wrapNoteMessage(input, { maxWidth: 24, columns: 80 }); - - expect(wrapped).toBe(input); - }); - - it("preserves long file-like underscore tokens for copy safety", () => { - const input = "administrators_authorized_keys_with_extra_suffix"; - const wrapped = wrapNoteMessage(input, { maxWidth: 14, columns: 80 }); - - expect(wrapped).toBe(input); - }); - - it("still chunks generic long opaque tokens to avoid pathological line width", () => { - const input = "x".repeat(70); - const wrapped = wrapNoteMessage(input, { maxWidth: 20, columns: 80 }); - - expect(wrapped).toContain("\n"); - expect(wrapped.replace(/\n/g, "")).toBe(input); - }); -}); diff --git a/src/terminal/table.test.ts b/src/terminal/table.test.ts index 3c0d22b35..644f6be23 100644 --- a/src/terminal/table.test.ts +++ b/src/terminal/table.test.ts @@ -1,5 +1,6 @@ import { describe, expect, it } from "vitest"; import { visibleWidth } from "./ansi.js"; +import { wrapNoteMessage } from "./note.js"; import { renderTable } from "./table.js"; describe("renderTable", () => { @@ -130,3 +131,36 @@ describe("renderTable", () => { expect(line2Index).toBe(line1Index + 1); }); }); + +describe("wrapNoteMessage", () => { + it("preserves long filesystem paths without inserting spaces/newlines", () => { + const input = + "/Users/user/Documents/Github/impact-signals-pipeline/with/really/long/segments/file.txt"; + const wrapped = wrapNoteMessage(input, { maxWidth: 22, columns: 80 }); + + expect(wrapped).toBe(input); + }); + + it("preserves long urls without inserting spaces/newlines", () => { + const input = + "https://example.com/this/is/a/very/long/url/segment/that/should/not/be/split/for-copy"; + const wrapped = wrapNoteMessage(input, { maxWidth: 24, columns: 80 }); + + expect(wrapped).toBe(input); + }); + + it("preserves long file-like underscore tokens for copy safety", () => { + const input = "administrators_authorized_keys_with_extra_suffix"; + const wrapped = wrapNoteMessage(input, { maxWidth: 14, columns: 80 }); + + expect(wrapped).toBe(input); + }); + + it("still chunks generic long opaque tokens to avoid pathological line width", () => { + const input = "x".repeat(70); + const wrapped = wrapNoteMessage(input, { maxWidth: 20, columns: 80 }); + + expect(wrapped).toContain("\n"); + expect(wrapped.replace(/\n/g, "")).toBe(input); + }); +});