mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-16 14:01:06 +00:00
feat(coding-agent): improve session picker search (#731)
This commit is contained in:
parent
cc8c51d9ae
commit
537bdb6972
4 changed files with 347 additions and 12 deletions
127
packages/coding-agent/test/session-selector-search.test.ts
Normal file
127
packages/coding-agent/test/session-selector-search.test.ts
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import type { SessionInfo } from "../src/core/session-manager.js";
|
||||
import { filterAndSortSessions } from "../src/modes/interactive/components/session-selector-search.js";
|
||||
|
||||
function makeSession(
|
||||
overrides: Partial<SessionInfo> & { id: string; modified: Date; allMessagesText: string },
|
||||
): SessionInfo {
|
||||
return {
|
||||
path: `/tmp/${overrides.id}.jsonl`,
|
||||
id: overrides.id,
|
||||
cwd: overrides.cwd ?? "",
|
||||
name: overrides.name,
|
||||
created: overrides.created ?? new Date(0),
|
||||
modified: overrides.modified,
|
||||
messageCount: overrides.messageCount ?? 1,
|
||||
firstMessage: overrides.firstMessage ?? "(no messages)",
|
||||
allMessagesText: overrides.allMessagesText,
|
||||
};
|
||||
}
|
||||
|
||||
describe("session selector search", () => {
|
||||
it("filters by quoted phrase with whitespace normalization", () => {
|
||||
const sessions: SessionInfo[] = [
|
||||
makeSession({
|
||||
id: "a",
|
||||
modified: new Date("2026-01-01T00:00:00.000Z"),
|
||||
allMessagesText: "node\n\n cve was discussed",
|
||||
}),
|
||||
makeSession({
|
||||
id: "b",
|
||||
modified: new Date("2026-01-02T00:00:00.000Z"),
|
||||
allMessagesText: "node something else",
|
||||
}),
|
||||
];
|
||||
|
||||
const result = filterAndSortSessions(sessions, '"node cve"', "recent");
|
||||
expect(result.map((s) => s.id)).toEqual(["a"]);
|
||||
});
|
||||
|
||||
it("filters by regex (re:) and is case-insensitive", () => {
|
||||
const sessions: SessionInfo[] = [
|
||||
makeSession({
|
||||
id: "a",
|
||||
modified: new Date("2026-01-02T00:00:00.000Z"),
|
||||
allMessagesText: "Brave is great",
|
||||
}),
|
||||
makeSession({
|
||||
id: "b",
|
||||
modified: new Date("2026-01-03T00:00:00.000Z"),
|
||||
allMessagesText: "bravery is not the same",
|
||||
}),
|
||||
];
|
||||
|
||||
const result = filterAndSortSessions(sessions, "re:\\bbrave\\b", "recent");
|
||||
expect(result.map((s) => s.id)).toEqual(["a"]);
|
||||
});
|
||||
|
||||
it("recent sort preserves input order", () => {
|
||||
const sessions: SessionInfo[] = [
|
||||
makeSession({
|
||||
id: "newer",
|
||||
modified: new Date("2026-01-03T00:00:00.000Z"),
|
||||
allMessagesText: "brave",
|
||||
}),
|
||||
makeSession({
|
||||
id: "older",
|
||||
modified: new Date("2026-01-01T00:00:00.000Z"),
|
||||
allMessagesText: "brave",
|
||||
}),
|
||||
makeSession({
|
||||
id: "nomatch",
|
||||
modified: new Date("2026-01-04T00:00:00.000Z"),
|
||||
allMessagesText: "something else",
|
||||
}),
|
||||
];
|
||||
|
||||
const result = filterAndSortSessions(sessions, '"brave"', "recent");
|
||||
expect(result.map((s) => s.id)).toEqual(["newer", "older"]);
|
||||
});
|
||||
|
||||
it("relevance sort orders by score and tie-breaks by modified desc", () => {
|
||||
const sessions: SessionInfo[] = [
|
||||
makeSession({
|
||||
id: "late",
|
||||
modified: new Date("2026-01-03T00:00:00.000Z"),
|
||||
allMessagesText: "xxxx brave",
|
||||
}),
|
||||
makeSession({
|
||||
id: "early",
|
||||
modified: new Date("2026-01-01T00:00:00.000Z"),
|
||||
allMessagesText: "brave xxxx",
|
||||
}),
|
||||
];
|
||||
|
||||
const result1 = filterAndSortSessions(sessions, '"brave"', "relevance");
|
||||
expect(result1.map((s) => s.id)).toEqual(["early", "late"]);
|
||||
|
||||
const tieSessions: SessionInfo[] = [
|
||||
makeSession({
|
||||
id: "newer",
|
||||
modified: new Date("2026-01-03T00:00:00.000Z"),
|
||||
allMessagesText: "brave",
|
||||
}),
|
||||
makeSession({
|
||||
id: "older",
|
||||
modified: new Date("2026-01-01T00:00:00.000Z"),
|
||||
allMessagesText: "brave",
|
||||
}),
|
||||
];
|
||||
|
||||
const result2 = filterAndSortSessions(tieSessions, '"brave"', "relevance");
|
||||
expect(result2.map((s) => s.id)).toEqual(["newer", "older"]);
|
||||
});
|
||||
|
||||
it("returns empty list for invalid regex", () => {
|
||||
const sessions: SessionInfo[] = [
|
||||
makeSession({
|
||||
id: "a",
|
||||
modified: new Date("2026-01-01T00:00:00.000Z"),
|
||||
allMessagesText: "brave",
|
||||
}),
|
||||
];
|
||||
|
||||
const result = filterAndSortSessions(sessions, "re:(", "recent");
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue