Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions packages/client-runtime/src/composerThreadItems.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";

import { matchComposerThreadItems } from "./composerThreadItems.ts";

const env = EnvironmentId.make("env-1");
const shell = (id: string, title: string) => ({
environmentId: env,
id: ThreadId.make(id),
title,
updatedAt: "2026-01-01T00:00:00.000Z",
archivedAt: null,
});

describe("matchComposerThreadItems", () => {
it("finds a thread by its pasted ID without matching other IDs that share its prefix", () => {
const pasted =
"thread:project:6f1c2a4e-8b7d-4d3a-9c5e-1a2b3c4d5e6f:0b9d7c1a-3e5f-4a6b-8c2d-7e9f1a3b5c7d";
const sibling =
"thread:project:6f1c2a4e-8b7d-4d3a-9c5e-1a2b3c4d5e6f:0b9d7c1a-3e5f-4a6b-8c2d-7e9f1a3b5c7e";
const items = matchComposerThreadItems({
shells: [shell(pasted, "Fix login"), shell(sibling, "Fix logout")],
environmentId: env,
excludeThreadId: null,
query: pasted,
});
expect(items.map((item) => item.thread.threadId)).toEqual([pasted]);
});

it("does not match an ID that differs from the pasted one only by case", () => {
const pasted = "import:opencode:ses_AbC123";
const items = matchComposerThreadItems({
shells: [shell(pasted, "Imported A"), shell("import:opencode:ses_abc123", "Imported B")],
environmentId: env,
excludeThreadId: null,
query: pasted,
});
expect(items.map((item) => item.thread.threadId)).toEqual([pasted]);
});
});
6 changes: 4 additions & 2 deletions packages/client-runtime/src/composerThreadItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ export function matchComposerThreadItems(input: {
excludeThreadId: ThreadId | null;
query: string;
}): ComposerThreadItem[] {
const query = input.query.trim().toLowerCase();
const pastedId = input.query.trim();
const query = pastedId.toLowerCase();
if (query.length === 0) return [];
return input.shells
.filter(
(shell) =>
shell.environmentId === input.environmentId &&
shell.id !== input.excludeThreadId &&
shell.archivedAt === null &&
shell.title.toLowerCase().includes(query),
// Thread IDs share long prefixes and are case-sensitive, so only the exact ID matches.
(shell.title.toLowerCase().includes(query) || shell.id === pastedId),
)
.sort((left, right) => right.updatedAt.localeCompare(left.updatedAt))
.slice(0, COMPOSER_THREAD_RESULT_LIMIT)
Expand Down
Loading