fix: generate distinct task collaboration titles
Use verified task names until Agent generates a specific conversation title. Repair legacy names without changing manual titles or history ordering. Bound page repairs to 30 entries and a shared two-second deadline, and re-read titles after task access validation to avoid stale reuse receipts. Validation: bun run check; 40 focused tests across six files.
This commit is contained in:
@@ -81,6 +81,26 @@ describe("shouldGenerateSessionTitle", () => {
|
||||
});
|
||||
|
||||
describe("generateSessionTitle", () => {
|
||||
it("uses the task name to distinguish collaboration titles and keeps it when generation is empty", async () => {
|
||||
let titlePrompt = "";
|
||||
let generatedTitle = "南桥爆管现场采样核对";
|
||||
const runtime = {
|
||||
createSession: async () => ({ id: "title-session" }),
|
||||
prompt: async (_id: string, prompt: string) => { titlePrompt = prompt; },
|
||||
waitForSessionIdle: async () => undefined,
|
||||
messages: async () => [{ info: { role: "assistant" }, parts: [{ type: "text", text: generatedTitle }] }],
|
||||
removeSession: async () => undefined,
|
||||
} as unknown as OpencodeRuntimeAdapter;
|
||||
const input = { sessionId: "collaboration-session", latestUserMessage: "目前进展如何?",
|
||||
latestAssistantMessage: "等待现场采样核对。", taskTitle: "南桥管道爆管调查", fallbackTitle: "南桥管道爆管调查" };
|
||||
expect(await generateSessionTitle(runtime, input)).toBe("南桥爆管现场采样核对");
|
||||
expect(titlePrompt).toContain("关联任务:南桥管道爆管调查");
|
||||
expect(titlePrompt).toContain("用户:目前进展如何?");
|
||||
generatedTitle = "";
|
||||
expect(await generateSessionTitle(runtime, input)).toBe("南桥管道爆管调查");
|
||||
generatedTitle = "任务协作";
|
||||
expect(await generateSessionTitle(runtime, input)).toBe("南桥管道爆管调查");
|
||||
});
|
||||
it("uses the current user and assistant turn instead of reading wrapped runtime context", async () => {
|
||||
let titlePrompt = "";
|
||||
const runtime = {
|
||||
|
||||
Reference in New Issue
Block a user