test: favor behavior over implementation details (#7157)

This commit is contained in:
t3-code[bot] authored and GitHub committed 2026-08-16 10:06:38 +02:00
1 parent 2773229337
commit 3583cd27dc
9 files changed
+9 -87

No files matched your search

@@ -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",
@@ -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 {
@@ -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),
);
});
});
@@ -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,
@@ -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")];
@@ -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 {
@@ -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);
@@ -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;
}
@@ -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", () => {