fix(tui): use canonical session handles (#6455)

This commit is contained in:
chengyongru authored and GitHub committed 2026-10-25 21:52:58 +08:00
1 parent 424d2debc2
commit b048cf44f7
6 files changed
+146 -38

No files matched your search

+28 -8
View File
@@ -8,19 +8,20 @@ const candidates: MentionCandidate[] = [
{ kind: "mcp", name: "linear", displayName: "Linear", description: "MCP" },
{
kind: "session",
name: "release-plan",
name: "luma",
displayName: "Release plan",
description: "Session",
session: { name: "release-plan", session_key: "websocket:release", title: "Release plan" },
session: { id: "handle_release", name: "luma", session_key: "websocket:release", title: "Release plan" },
},
]
describe("mention projection", () => {
test("finds and replaces only the mention under the cursor", () => {
const value = "ask @rel about this"
const query = mentionQuery(value, 8)
expect(query).toEqual({ query: "rel", start: 4, end: 8 })
expect(insertMention(value, candidates[2]!, query!).value).toBe("ask @release-plan about this")
const value = "ask @lu about this"
const query = mentionQuery(value, 7)
expect(query).toEqual({ query: "lu", start: 4, end: 7 })
const completed = insertMention(value, candidates[2]!, query!).value
expect(completed).toBe("ask @luma about this")
})
test("keeps namespaced completion aliases separate from gateway capability ids", () => {
@@ -35,12 +36,31 @@ describe("mention projection", () => {
expect(options.mcpPresets).toEqual([{ name: "github" }])
})
test("does not mix a canonical session with colliding tool completion aliases", () => {
const colliding: MentionCandidate[] = [
candidates[2]!,
{ kind: "cli", name: "luma-2", targetName: "luma", displayName: "Luma CLI", description: "CLI" },
{ kind: "mcp", name: "luma-3", targetName: "luma", displayName: "Luma MCP", description: "MCP" },
]
expect(mentionOptions("ask @LUMA", colliding)).toEqual({
cliApps: [],
mcpPresets: [],
sessionMentions: [candidates[2]!.session!],
})
expect(mentionOptions("use @luma-2 and @luma-3", colliding)).toEqual({
cliApps: [{ name: "luma" }],
mcpPresets: [{ name: "luma" }],
sessionMentions: [],
})
})
test("maps visible mentions onto the gateway metadata lanes", () => {
expect(mentionOptions("Use @github with @linear and @release-plan", candidates)).toEqual({
expect(mentionOptions("Use @github with @linear and @luma", candidates)).toEqual({
cliApps: [{ name: "github" }],
mcpPresets: [{ name: "linear" }],
sessionMentions: [{
name: "release-plan",
id: "handle_release",
name: "luma",
session_key: "websocket:release",
title: "Release plan",
}],
+12 -1
View File
@@ -6,7 +6,9 @@ import type { SessionSummary } from "../client"
const sessions: SessionSummary[] = [
{
key: "websocket:one",
chatId: "one",
handle: { id: "handle_one", name: "luma" },
title: "API migration",
preview: "Move authentication to the new client",
createdAt: "2026-08-12T10:00:00Z",
@@ -17,7 +19,9 @@ const sessions: SessionSummary[] = [
archived: false,
},
{
key: "websocket:two",
chatId: "two",
handle: { id: "handle_two", name: "bime" },
title: "Release checklist",
preview: "Prepare the stable release",
createdAt: "2026-08-11T10:00:00Z",
@@ -55,7 +59,7 @@ describe("SessionMenu", () => {
menu.open(sessions, "one", 6, "Codex")
await setup.renderOnce()
expect(setup.captureCharFrame()).toContain("› ● API migration")
expect(setup.captureCharFrame()).toContain("› ● API migration @luma")
expect(setup.captureCharFrame()).not.toContain("Move authentication")
expect(setup.captureCharFrame()).not.toContain("Codex")
expect(menu.choose()?.chatId).toBe("one")
@@ -64,6 +68,13 @@ describe("SessionMenu", () => {
await setup.renderOnce()
expect(setup.captureCharFrame()).toContain("⚠ Release checklist")
expect(menu.choose()?.chatId).toBe("two")
for (const query of ["luma", "@luma"]) {
menu.update(query, 6)
await setup.renderOnce()
expect(menu.choose()?.key).toBe("websocket:one")
expect(setup.captureCharFrame()).toContain("API migration @luma")
}
})
test("keeps generated multi-line titles on one terminal row", () => {
+2
View File
@@ -49,6 +49,7 @@ export class SessionMenu {
key: (session) => session.chatId,
searchText: (session) => [
sessionLabel(session),
session.handle ? `@${session.handle.name}` : "",
session.modelPreset || "",
session.preview,
session.chatId,
@@ -60,6 +61,7 @@ export class SessionMenu {
render: (session, selected) => {
const age = updatedLabel(session.updatedAt)
const detail = [
session.handle ? `@${session.handle.name}` : "",
this.showWorkspaces ? this.workspaceLabel(session) : "",
this.modelOverride(session),
]