源码快照 @ 2026-09-02 (source-only, 剔除非源码素材)
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
|
||||
import type { OpenworkSessionMessage } from "../src/app/lib/openwork-server";
|
||||
import {
|
||||
createSessionSearcher,
|
||||
type SearchableSession,
|
||||
type SessionSearchMatch,
|
||||
} from "../src/react-app/domains/session/search/session-search";
|
||||
|
||||
const session: SearchableSession = {
|
||||
workspaceId: "workspace-a",
|
||||
sessionId: "session-a",
|
||||
title: "Searchable session",
|
||||
workspaceTitle: "Workspace A",
|
||||
updatedAt: 1,
|
||||
};
|
||||
|
||||
function textMessage(id: string, role: "user" | "assistant", text: string) {
|
||||
return {
|
||||
info: {
|
||||
id,
|
||||
role,
|
||||
sessionID: session.sessionId,
|
||||
time: { created: 1 },
|
||||
},
|
||||
parts: [
|
||||
{
|
||||
id: `part-${id}`,
|
||||
type: "text",
|
||||
text,
|
||||
sessionID: session.sessionId,
|
||||
messageID: id,
|
||||
},
|
||||
],
|
||||
} satisfies OpenworkSessionMessage;
|
||||
}
|
||||
|
||||
describe("session search", () => {
|
||||
test("includes the matching message id", async () => {
|
||||
const searcher = createSessionSearcher(async () => [
|
||||
textMessage("msg-user", "user", "Find this exact phrase"),
|
||||
]);
|
||||
const matches: SessionSearchMatch[] = [];
|
||||
const run = searcher.search({
|
||||
query: "exact",
|
||||
sessions: [session],
|
||||
onMatch: (match) => matches.push(match),
|
||||
onProgress: () => {},
|
||||
concurrency: 1,
|
||||
});
|
||||
|
||||
await run.done;
|
||||
|
||||
expect(matches[0]?.kind).toBe("message");
|
||||
expect(matches[0]?.messageId).toBe("msg-user");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user