From 3583cd27dccda1b35fe80d9411a95a7217cc8176 Mon Sep 17 00:00:00 2001 From: "t3-code[bot]" <269035359+t3-code[bot]@users.noreply.github.com> Date: Sun, 16 Aug 2026 10:06:38 +0200 Subject: [PATCH] test: favor behavior over implementation details (#7157) --- .../terminal/terminalLaunchContext.test.ts | 10 +---- .../terminal/terminalLaunchContext.ts | 6 --- .../terminal/threadTerminalPanelModel.test.ts | 40 ------------------- .../terminal/threadTerminalPanelModel.ts | 12 ------ .../components/chat/MessagesTimeline.test.tsx | 8 +--- .../src/components/chat/MessagesTimeline.tsx | 2 +- .../components/composerFooterLayout.test.ts | 13 +++--- .../src/components/composerFooterLayout.ts | 4 +- packages/shared/src/terminalLabels.test.ts | 1 - 9 files changed, 9 insertions(+), 87 deletions(-) delete mode 100644 apps/mobile/src/features/terminal/threadTerminalPanelModel.test.ts diff --git a/apps/mobile/src/features/terminal/terminalLaunchContext.test.ts b/apps/mobile/src/features/terminal/terminalLaunchContext.test.ts index cbd446a88d1a94b4fc2602347850f0e791648fab..470acffa3d43163d9f04dbb07c3039d8e2f9f56c 100644 --- a/apps/mobile/src/features/terminal/terminalLaunchContext.test.ts +++ b/apps/mobile/src/features/terminal/terminalLaunchContext.test.ts @@ -2,7 +2,6 @@ import { describe, expect, it } from "vite-plus/test"; import { EnvironmentId, ThreadId } from "@t3tools/contracts"; import { - peekPendingTerminalLaunch, resolvePreferredThreadWorktreePath, resolveTerminalOpenLocation, stagePendingTerminalLaunch, @@ -82,19 +81,13 @@ describe("pending terminal launches", () => { }, }); - expect(peekPendingTerminalLaunch(target)).toEqual({ - cwd: "/repo/worktrees/feature", - worktreePath: "/repo/worktrees/feature", - env: { FOO: "bar" }, - initialInput: "pnpm dev\r", - }); expect(takePendingTerminalLaunch(target)).toEqual({ cwd: "/repo/worktrees/feature", worktreePath: "/repo/worktrees/feature", env: { FOO: "bar" }, initialInput: "pnpm dev\r", }); - expect(peekPendingTerminalLaunch(target)).toBeNull(); + expect(takePendingTerminalLaunch(target)).toBeNull(); }); it("keeps pending launches isolated per terminal target", () => { @@ -118,7 +111,6 @@ describe("pending terminal launches", () => { }, }); - expect(peekPendingTerminalLaunch(otherTarget)).toBeNull(); expect(takePendingTerminalLaunch(otherTarget)).toBeNull(); expect(takePendingTerminalLaunch(primaryTarget)).toEqual({ cwd: "/repo/root", diff --git a/apps/mobile/src/features/terminal/terminalLaunchContext.ts b/apps/mobile/src/features/terminal/terminalLaunchContext.ts index c1a77492039502d38cb7146c9eb20c33df7cfa8e..af67497a3d22eb66265a40ae188f65c60ecc3f15 100644 --- a/apps/mobile/src/features/terminal/terminalLaunchContext.ts +++ b/apps/mobile/src/features/terminal/terminalLaunchContext.ts @@ -36,12 +36,6 @@ export function stagePendingTerminalLaunch(input: { }); } -export function peekPendingTerminalLaunch( - target: PendingTerminalLaunchTarget, -): PendingTerminalLaunch | null { - return pendingTerminalLaunches.get(pendingTerminalLaunchKey(target)) ?? null; -} - export function takePendingTerminalLaunch( target: PendingTerminalLaunchTarget, ): PendingTerminalLaunch | null { diff --git a/apps/mobile/src/features/terminal/threadTerminalPanelModel.test.ts b/apps/mobile/src/features/terminal/threadTerminalPanelModel.test.ts deleted file mode 100644 index 871a28d852802d0698b632ea07b945bbad58da1b..0000000000000000000000000000000000000000 --- a/apps/mobile/src/features/terminal/threadTerminalPanelModel.test.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { EnvironmentId, ThreadId } from "@t3tools/contracts"; -import { describe, expect, it } from "vite-plus/test"; - -import { - buildThreadTerminalAttachInput, - threadTerminalSubscriptionKey, - type ThreadTerminalSubscriptionIdentity, -} from "./threadTerminalPanelModel"; - -const identity: ThreadTerminalSubscriptionIdentity = { - environmentId: EnvironmentId.make("env-1"), - threadId: ThreadId.make("thread-1"), - terminalId: "default", - cwd: "/repo", - worktreePath: "/repo", -}; - -describe("threadTerminalSubscriptionKey", () => { - it("does not include mutable terminal dimensions", () => { - const initialAttach = buildThreadTerminalAttachInput(identity, { cols: 80, rows: 24 }); - const resizedAttach = buildThreadTerminalAttachInput(identity, { cols: 132, rows: 40 }); - - expect(initialAttach).not.toEqual(resizedAttach); - expect(threadTerminalSubscriptionKey({ ...identity, ...initialAttach })).toBe( - threadTerminalSubscriptionKey({ ...identity, ...resizedAttach }), - ); - }); - - it.each([ - ["environment", { environmentId: EnvironmentId.make("env-2") }], - ["thread", { threadId: ThreadId.make("thread-2") }], - ["terminal", { terminalId: "term-2" }], - ["cwd", { cwd: "/repo/packages/app" }], - ["worktree", { worktreePath: "/repo/worktrees/feature" }], - ])("changes when the %s identity changes", (_label, update) => { - expect(threadTerminalSubscriptionKey({ ...identity, ...update })).not.toBe( - threadTerminalSubscriptionKey(identity), - ); - }); -}); diff --git a/apps/mobile/src/features/terminal/threadTerminalPanelModel.ts b/apps/mobile/src/features/terminal/threadTerminalPanelModel.ts index 9f1d032d2641b990de8aca8c51d1dccdadbe2def..07ef46a7bc6d3b791922e1c96d599ce6b14ebb98 100644 --- a/apps/mobile/src/features/terminal/threadTerminalPanelModel.ts +++ b/apps/mobile/src/features/terminal/threadTerminalPanelModel.ts @@ -13,18 +13,6 @@ export interface TerminalGridSize { readonly rows: number; } -export function threadTerminalSubscriptionKey( - identity: ThreadTerminalSubscriptionIdentity, -): string { - return JSON.stringify([ - identity.environmentId, - identity.threadId, - identity.terminalId, - identity.cwd, - identity.worktreePath, - ]); -} - export function buildThreadTerminalAttachInput( identity: ThreadTerminalSubscriptionIdentity, gridSize: TerminalGridSize, diff --git a/apps/web/src/components/chat/MessagesTimeline.test.tsx b/apps/web/src/components/chat/MessagesTimeline.test.tsx index e51095bb00add7fe273656295bf4774443c1af62..617ee0b80d1cfda69a03e99c91d3bcaa0ea39dda 100644 --- a/apps/web/src/components/chat/MessagesTimeline.test.tsx +++ b/apps/web/src/components/chat/MessagesTimeline.test.tsx @@ -134,7 +134,6 @@ function matchMedia() { } let MessagesTimeline: typeof import("./MessagesTimeline").MessagesTimeline; -let toolCallExpandedBodyClassName: typeof import("./MessagesTimeline").toolCallExpandedBodyClassName; beforeAll(async () => { const classList = { @@ -168,7 +167,7 @@ beforeAll(async () => { }, }); - ({ MessagesTimeline, toolCallExpandedBodyClassName } = await import("./MessagesTimeline")); + ({ MessagesTimeline } = await import("./MessagesTimeline")); }, 30_000); const ACTIVE_THREAD_ENVIRONMENT_ID = EnvironmentId.make("environment-local"); @@ -238,11 +237,6 @@ function buildAssistantTimelineEntry(text: string) { } describe("MessagesTimeline", () => { - it("sizes expanded tool details with the configured code font size", () => { - expect(toolCallExpandedBodyClassName).toContain("var(--font-size-code"); - expect(toolCallExpandedBodyClassName).not.toContain("text-[11px]"); - }); - it("uses the larger leading inset only when the top fade is enabled", () => { const timelineEntries = [buildUserTimelineEntry("Hello")]; diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsx index b1b665ab7bf69112c3a25ae715fb07f51467ad70..c90aa771f8d1ba933be49749b07b475925a637fd 100644 --- a/apps/web/src/components/chat/MessagesTimeline.tsx +++ b/apps/web/src/components/chat/MessagesTimeline.tsx @@ -2063,7 +2063,7 @@ function buildToolCallExpandedBody( return blocks.length > 0 ? blocks.join("\n\n") : null; } -export const toolCallExpandedBodyClassName = +const toolCallExpandedBodyClassName = "max-h-64 cursor-text overflow-auto whitespace-pre-wrap break-words font-mono text-secondary-label text-[length:var(--font-size-code,0.6875rem)] leading-relaxed select-text"; function workEntryIconName(workEntry: TimelineWorkEntry): WorkEntryIconName { diff --git a/apps/web/src/components/composerFooterLayout.test.ts b/apps/web/src/components/composerFooterLayout.test.ts index b9f2a6b6a244f48341672a246e36b464c9e0fe89..92e054df52dc7274300ed0bda3cdf0c1f9537049 100644 --- a/apps/web/src/components/composerFooterLayout.test.ts +++ b/apps/web/src/components/composerFooterLayout.test.ts @@ -3,7 +3,6 @@ import { describe, expect, it } from "vite-plus/test"; import { COMPOSER_FOOTER_COMPACT_BREAKPOINT_PX, COMPOSER_FOOTER_WIDE_ACTIONS_COMPACT_BREAKPOINT_PX, - COMPOSER_PRIMARY_ACTIONS_COMPACT_BREAKPOINT_PX, shouldUseCompactComposerPrimaryActions, shouldUseCompactComposerFooter, } from "./composerFooterLayout"; @@ -38,16 +37,14 @@ describe("shouldUseCompactComposerFooter", () => { describe("shouldUseCompactComposerPrimaryActions", () => { it("matches the wide footer breakpoint", () => { - expect(COMPOSER_PRIMARY_ACTIONS_COMPACT_BREAKPOINT_PX).toBe( - COMPOSER_FOOTER_WIDE_ACTIONS_COMPACT_BREAKPOINT_PX, - ); expect( - shouldUseCompactComposerPrimaryActions(COMPOSER_PRIMARY_ACTIONS_COMPACT_BREAKPOINT_PX - 1, { - hasWideActions: true, - }), + shouldUseCompactComposerPrimaryActions( + COMPOSER_FOOTER_WIDE_ACTIONS_COMPACT_BREAKPOINT_PX - 1, + { hasWideActions: true }, + ), ).toBe(true); expect( - shouldUseCompactComposerPrimaryActions(COMPOSER_PRIMARY_ACTIONS_COMPACT_BREAKPOINT_PX, { + shouldUseCompactComposerPrimaryActions(COMPOSER_FOOTER_WIDE_ACTIONS_COMPACT_BREAKPOINT_PX, { hasWideActions: true, }), ).toBe(false); diff --git a/apps/web/src/components/composerFooterLayout.ts b/apps/web/src/components/composerFooterLayout.ts index ae5fd56669f42bc79735c6f4dc513efc8836fe36..5e0b3a8ea379f0616a8bfbedbef63cf0045e1f13 100644 --- a/apps/web/src/components/composerFooterLayout.ts +++ b/apps/web/src/components/composerFooterLayout.ts @@ -1,7 +1,5 @@ export const COMPOSER_FOOTER_COMPACT_BREAKPOINT_PX = 620; export const COMPOSER_FOOTER_WIDE_ACTIONS_COMPACT_BREAKPOINT_PX = 780; -export const COMPOSER_PRIMARY_ACTIONS_COMPACT_BREAKPOINT_PX = - COMPOSER_FOOTER_WIDE_ACTIONS_COMPACT_BREAKPOINT_PX; export function shouldUseCompactComposerFooter( width: number | null, @@ -20,5 +18,5 @@ export function shouldUseCompactComposerPrimaryActions( if (!options?.hasWideActions) { return false; } - return width !== null && width < COMPOSER_PRIMARY_ACTIONS_COMPACT_BREAKPOINT_PX; + return width !== null && width < COMPOSER_FOOTER_WIDE_ACTIONS_COMPACT_BREAKPOINT_PX; } diff --git a/packages/shared/src/terminalLabels.test.ts b/packages/shared/src/terminalLabels.test.ts index 4621f3af80894fd0729e5de4cd869deff87a9acc..b8a146b0cc2e3c7151a335ef37807623460025c1 100644 --- a/packages/shared/src/terminalLabels.test.ts +++ b/packages/shared/src/terminalLabels.test.ts @@ -34,7 +34,6 @@ describe("resolveTerminalSessionLabel", () => { describe("nextTerminalId", () => { it("allocates term-1 when no terminals are listed yet", () => { expect(nextTerminalId([])).toBe(DEFAULT_TERMINAL_ID); - expect(nextTerminalId([])).toBe("term-1"); }); it("allocates term-2 when only term-1 exists", () => { -- 2.54.0