diff --git a/changelog.d/3235-palette-part-dedupe.fixed.md b/changelog.d/3235-palette-part-dedupe.fixed.md new file mode 100644 index 000000000..4cee0c63f --- /dev/null +++ b/changelog.d/3235-palette-part-dedupe.fixed.md @@ -0,0 +1 @@ +⌘K search no longer drops a message from an older part when that part's turn number repeats one the current part already matched. Two parts of the same chat render as two rows, and each row opens the part it came from ([#3235](https://github.com/ThinkFlowLab/FlyBot/issues/3235)). diff --git a/core/client.js b/core/client.js index bc6156c5f..77c6cbf19 100644 --- a/core/client.js +++ b/core/client.js @@ -16909,11 +16909,13 @@ function CommandPalette({ start, token, roster, actions, useSessions }) { })); if (agents.length) sections.push(["DSH Agent", agents]); const outlineRead = JSON.parse(found); + const partOf2 = (chat, part) => typeof part === "string" ? part : currentPart(roster.byId[chat] ?? { id: chat }); + const rowKey = (chat, part, turn) => `${chat}:${partOf2(chat, part)}:${turn}`; const messages = outlineRead.hits.map(([id, turn, snippet]) => { const bot = roster.byId[id]; const room2 = roster.roomsById[id]; return { - key: `${chatOf2(id)}:${turn}`, + key: rowKey(chatOf2(id), id, turn), title: bot?.name ?? room2?.name ?? t("Bot"), subtitle: snippet, avatar: bot ? (0, import_react35.createElement)(BotAvatar, { bot, size: 24, badge: false, live: false }) : (0, import_react35.createElement)(RoomAvatar, { room: room2, roster, size: 24 }), @@ -16927,11 +16929,11 @@ function CommandPalette({ start, token, roster, actions, useSessions }) { return Array.isArray(held) && held.length > 0 ? held.includes(turn) : void 0; }; const keyCounts = /* @__PURE__ */ new Map(); - const fullText = (wholeText?.rows ?? []).filter((row) => row?.chat !== void 0 && (roster.byId[row.chat] || roster.roomsById[row.chat]) && !outlined.has(`${row.chat}:${row.turn}`)).map((row) => { + const fullText = (wholeText?.rows ?? []).filter((row) => row?.chat !== void 0 && (roster.byId[row.chat] || roster.roomsById[row.chat]) && !outlined.has(rowKey(row.chat, row.part, row.turn))).map((row) => { const bot = roster.byId[row.chat]; const room2 = roster.roomsById[row.chat]; const earlier = typeof row.part === "string" ? bot !== void 0 && row.part !== currentPart(bot) : inPart(row.chat, row.turn) === false; - const at = `${row.chat}:${row.turn}`; + const at = rowKey(row.chat, row.part, row.turn); const count = (keyCounts.get(at) ?? 0) + 1; keyCounts.set(at, count); return { diff --git a/core/src/client/palette.js b/core/src/client/palette.js index 5bd7804b8..522116e57 100644 --- a/core/src/client/palette.js +++ b/core/src/client/palette.js @@ -100,11 +100,16 @@ export function CommandPalette({ start, token, roster, actions, useSessions }) { })) if (agents.length) sections.push(['DSH Agent', agents]) const outlineRead = JSON.parse(found) + // A row's identity is the part that holds it, not chat+turn: turn numbers restart in every + // part, so an older part's turn 1 is a different message from this part's turn 1 (#3235). + // A row that names no part is the part the client holds; a room has none and keeps its id. + const partOf = (chat, part) => typeof part === 'string' ? part : currentPart(roster.byId[chat] ?? { id: chat }) + const rowKey = (chat, part, turn) => `${chat}:${partOf(chat, part)}:${turn}` const messages = outlineRead.hits.map(([id, turn, snippet]) => { const bot = roster.byId[id] const room = roster.roomsById[id] return { - key: `${chatOf(id)}:${turn}`, title: bot?.name ?? room?.name ?? t('Bot'), subtitle: snippet, + key: rowKey(chatOf(id), id, turn), title: bot?.name ?? room?.name ?? t('Bot'), subtitle: snippet, avatar: bot ? h(BotAvatar, { bot, size: 24, badge: false, live: false }) : h(RoomAvatar, { room, roster, size: 24 }), run: () => actions.openSession(id, { turn }), } @@ -121,13 +126,13 @@ export function CommandPalette({ start, token, roster, actions, useSessions }) { return Array.isArray(held) && held.length > 0 ? held.includes(turn) : undefined } const keyCounts = new Map() - const fullText = (wholeText?.rows ?? []).filter(row => row?.chat !== undefined && (roster.byId[row.chat] || roster.roomsById[row.chat]) && !outlined.has(`${row.chat}:${row.turn}`)).map(row => { + const fullText = (wholeText?.rows ?? []).filter(row => row?.chat !== undefined && (roster.byId[row.chat] || roster.roomsById[row.chat]) && !outlined.has(rowKey(row.chat, row.part, row.turn))).map(row => { const bot = roster.byId[row.chat] const room = roster.roomsById[row.chat] // A row that names its part is placed by that part (#3114); a row without one keeps the // outline's answer, the only proof the client has about what the part it holds contains. const earlier = typeof row.part === 'string' ? bot !== undefined && row.part !== currentPart(bot) : inPart(row.chat, row.turn) === false - const at = `${row.chat}:${row.turn}` + const at = rowKey(row.chat, row.part, row.turn) const count = (keyCounts.get(at) ?? 0) + 1 keyCounts.set(at, count) return { diff --git a/core/test/palette-preview.test.js b/core/test/palette-preview.test.js index 7757487b6..decb381c4 100644 --- a/core/test/palette-preview.test.js +++ b/core/test/palette-preview.test.js @@ -260,8 +260,26 @@ function livePalette({ start = '', raw = '', rows = [], more = 0, outline, roste walk(live, node => { if (node.props?.className === className) out.push([node.props.children].flat().join('')) }) return out } + // Rows grouped by the section they render under: #3235's acceptance reads a row by the + // section it is in, never by a key, because two sections can otherwise look swapped. + const grouped = () => { + const out = [] + for (const node of flips()) { + const flip = node.props['data-flip'] + if (flip.startsWith('section:')) { out.push({ title: flip.slice('section:'.length), keys: [], badges: [], nodes: [] }); continue } + const section = out.at(-1) + if (section === undefined) continue + let badge + walk(node, child => { if (badge === undefined && child.props?.className === 'bt-palette-badge') badge = [child.props.children].flat().join('') }) + section.keys.push(flip) + section.badges.push(badge) + section.nodes.push(node) + } + return out + } return { - calls, settle, run, + calls, settle, run, grouped, + chooseAt: (title, index) => { grouped().find(section => section.title === title)?.nodes[index]?.props.onClick?.() }, sections: () => flips().map(node => node.props['data-flip']).filter(flip => flip.startsWith('section:')).map(flip => flip.slice('section:'.length)), rows: () => flips().map(node => node.props['data-flip']).filter(flip => !flip.startsWith('section:')), notes: () => texts('bt-palette-note'), @@ -279,13 +297,13 @@ test('P-820: a hit past the outline preview budget is found by the whole-text gr await palette.settle() assert.deepEqual(palette.calls.search.map(([query]) => query), ['needle'], 'the host search was asked for the query') assert.deepEqual(palette.sections(), ['Messages (full text)'], JSON.stringify(palette.sections())) - assert.deepEqual(palette.rows(), ['s1:7']) + assert.deepEqual(palette.rows(), ['s1:s1:7']) }) test('P-820: choosing a whole-text row opens the chat at that turn', async () => { const palette = livePalette({ start: 'needle', raw: 'a plain turn', outline: [{ turn: 7, prompt: 'a plain turn' }], rows: [{ chat: 's1', turn: 7, text: 'NEEDLE at the far end' }] }) await palette.settle() - palette.choose('s1:7') + palette.choose('s1:s1:7') // The row object comes from the palette's realm, so the fields are read, not deep-equalled. assert.equal(palette.calls.openSession.length, 1) assert.equal(palette.calls.openSession[0][0], 's1') @@ -298,7 +316,7 @@ test('P-820: a row the outline already found is not shown twice', async () => { const palette = livePalette({ start: 'needle', raw: 'the needle is right here', rows: [{ chat: 's1', turn: 1, text: 'the needle is right here' }, { chat: 's1', turn: 9, text: 'another NEEDLE far past the budget' }] }) await palette.settle() assert.deepEqual(palette.sections(), ['Messages', 'Messages (full text)'], JSON.stringify(palette.sections())) - assert.deepEqual(palette.rows(), ['s1:1', 's1:9'], JSON.stringify(palette.rows())) + assert.deepEqual(palette.rows(), ['s1:s1:1', 's1:s1:9'], JSON.stringify(palette.rows())) }) // #3114. Each row now says what it is and lands where it points: an outline hit names its own @@ -307,8 +325,8 @@ test('P-820: a row the outline already found is not shown twice', async () => { // and a Bot whose current part id is not its own id still shows one row. test('#3114: choosing an outline message row opens the chat at that turn', () => { const palette = livePalette({ start: 'needle', raw: 'the needle is right here' }) - assert.deepEqual(palette.rows(), ['s1:1'], JSON.stringify(palette.rows())) - palette.choose('s1:1') + assert.deepEqual(palette.rows(), ['s1:s1:1'], JSON.stringify(palette.rows())) + palette.choose('s1:s1:1') assert.equal(palette.calls.openSession.length, 1) assert.equal(palette.calls.openSession[0][0], 's1') assert.equal(palette.calls.openSession[0][1]?.turn, 1) @@ -332,7 +350,7 @@ test('#3114: the whole-text rows say how many the cap left out', async () => { test('#3114: two hits in one turn are two rows, each with its own key', async () => { const palette = livePalette({ start: 'needle', raw: 'a plain turn', rows: [{ chat: 's1', turn: 5, text: 'NEEDLE in the question' }, { chat: 's1', turn: 5, text: 'NEEDLE in the reply' }] }) await palette.settle() - assert.deepEqual(palette.rows(), ['s1:5', 's1:5:2'], JSON.stringify(palette.rows())) + assert.deepEqual(palette.rows(), ['s1:s1:5', 's1:s1:5:2'], JSON.stringify(palette.rows())) }) // The current part's outline is the only list of turns the client can prove it holds. A hit @@ -341,7 +359,7 @@ test('#3114: a hit the current part does not hold is marked as an earlier part', const elsewhere = livePalette({ start: 'needle', raw: 'a plain turn', rows: [{ chat: 's1', turn: 12, text: 'NEEDLE far past this part' }] }) await elsewhere.settle() assert.deepEqual(elsewhere.badges(), ['Earlier part']) - elsewhere.choose('s1:12') + elsewhere.choose('s1:s1:12') assert.equal(elsewhere.calls.openSession.length, 1) assert.equal(elsewhere.calls.openSession[0][0], 's1') assert.equal(elsewhere.calls.openSession[0][1], undefined, 'no turn is passed for a row the current part does not hold') @@ -349,7 +367,7 @@ test('#3114: a hit the current part does not hold is marked as an earlier part', const here = livePalette({ start: 'needle', raw: 'a plain turn', outline: [{ turn: 12, prompt: 'a plain turn' }], rows: [{ chat: 's1', turn: 12, text: 'NEEDLE inside this part' }] }) await here.settle() assert.deepEqual(here.badges(), []) - here.choose('s1:12') + here.choose('s1:s1:12') assert.equal(here.calls.openSession[0][1]?.turn, 12) }) @@ -361,7 +379,7 @@ test('#3114: a Bot whose part id is not its id is still deduped once', async () const palette = livePalette({ start: 'needle', raw: 'the needle is right here', roster, rows: [{ chat: 'a', turn: 1, text: 'the needle is right here' }] }) await palette.settle() assert.deepEqual(palette.sections(), ['Messages'], JSON.stringify(palette.sections())) - assert.deepEqual(palette.rows(), ['a:1'], JSON.stringify(palette.rows())) + assert.deepEqual(palette.rows(), ['a:pc:1'], JSON.stringify(palette.rows())) }) // An exchange turn is inside the current part: its position is in the flow, so it keeps its @@ -371,7 +389,7 @@ test('#3114: a hidden exchange turn keeps its turn, with no badge', async () => const palette = livePalette({ start: 'needle', raw: 'a plain turn', outline: [{ turn: 5, prompt: 'a plain turn' }], roster, rows: [{ chat: 's1', turn: 5, text: 'NEEDLE in the hidden reply' }] }) await palette.settle() assert.deepEqual(palette.badges(), []) - palette.choose('s1:5') + palette.choose('s1:s1:5') assert.equal(palette.calls.openSession[0][1]?.turn, 5) }) @@ -391,7 +409,7 @@ test('#3114: a hit the host places in an earlier part opens that part at its tur const palette = livePalette({ start: 'needle', raw: 'a plain turn', rows: [{ chat: 's1', turn: 12, part: 's1-old', text: 'NEEDLE far past this part' }] }) await palette.settle() assert.deepEqual(palette.badges(), ['Earlier part']) - palette.choose('s1:12') + palette.choose('s1:s1-old:12') assert.equal(palette.calls.openSession.length, 1) assert.equal(palette.calls.openSession[0][0], 's1') assert.equal(palette.calls.openSession[0][1]?.part, 's1-old') @@ -405,7 +423,49 @@ test('#3114: a hit in the current part keeps its own seek', async () => { const palette = livePalette({ start: 'needle', raw: 'a plain turn', outline: [{ turn: 1, prompt: 'a plain turn' }], rows: [{ chat: 's1', turn: 1, part: 's1', text: 'NEEDLE inside this part' }] }) await palette.settle() assert.deepEqual(palette.badges(), []) - palette.choose('s1:1') + palette.choose('s1:s1:1') assert.equal(palette.calls.openSession[0][1]?.turn, 1) assert.equal(palette.calls.openSession[0][1]?.part, undefined, 'the current part is not named as another part') }) + +// #3235. Turn numbers restart in every part, so `chat:turn` is not an identity: an older part's +// turn 1 is a different message from this part's turn 1. The dedupe used to eat it, and with it +// the whole `Messages (full text)` section; the row must render, keep its badge, and open the +// part it came from. +test('#3235: an older part\'s hit survives a same-numbered hit in this part', async () => { + const palette = livePalette({ + start: 'needle', raw: 'the needle is right here', outline: [{ turn: 1, prompt: 'the needle is right here' }], + rows: [{ chat: 's1', turn: 1, part: 's1-old', text: 'NEEDLE said in an older part' }], + }) + await palette.settle() + const sections = palette.grouped() + assert.deepEqual(sections.map(section => section.title), ['Messages', 'Messages (full text)'], JSON.stringify(sections.map(section => section.title))) + assert.equal(sections[1].keys.length, 1, JSON.stringify(sections[1].keys)) + assert.deepEqual(sections[1].badges, ['Earlier part']) + assert.notEqual(sections[0].keys[0], sections[1].keys[0], 'the two rows must not share one key') + palette.chooseAt('Messages (full text)', 0) + assert.equal(palette.calls.openSession.length, 1) + assert.equal(palette.calls.openSession[0][0], 's1') + assert.equal(palette.calls.openSession[0][1]?.part, 's1-old') + assert.equal(palette.calls.openSession[0][1]?.turn, 1) +}) + +// Two parts can both hold a turn 5. They are two messages: their keys must differ, and each row +// still opens the part it names. +test('#3235: the same chat and turn in two parts get keys of their own', async () => { + const rows = [ + { chat: 's1', turn: 5, part: 's1-a', text: 'NEEDLE in part A' }, + { chat: 's1', turn: 5, part: 's1-b', text: 'NEEDLE in part B' }, + ] + const palette = livePalette({ start: 'needle', raw: 'a plain turn', rows }) + await palette.settle() + const [whole] = palette.grouped() + assert.deepEqual(whole.title, 'Messages (full text)') + assert.deepEqual(whole.keys, ['s1:s1-a:5', 's1:s1-b:5'], JSON.stringify(whole.keys)) + palette.chooseAt('Messages (full text)', 0) + assert.equal(palette.calls.openSession[0][1]?.part, 's1-a') + const second = livePalette({ start: 'needle', raw: 'a plain turn', rows }) + await second.settle() + second.chooseAt('Messages (full text)', 1) + assert.equal(second.calls.openSession[0][1]?.part, 's1-b') +}) diff --git a/patches/ds-bot/0003-flybot-api-client.patch b/patches/ds-bot/0003-flybot-api-client.patch index 50b89726d..245afe481 100644 --- a/patches/ds-bot/0003-flybot-api-client.patch +++ b/patches/ds-bot/0003-flybot-api-client.patch @@ -2905,18 +2905,23 @@ diff --git a/src/client/palette.js b/src/client/palette.js badge: room.hidden ? t('Hidden') : undefined, run: async () => { if (room.hidden) await actions.setFlags(room.id, { hidden: false }); actions.openSession(room.id) }, })), -@@ -67,21 +67,56 @@ export function CommandPalette({ start, token, roster, actions, useSessions }) { +@@ -67,21 +67,61 @@ export function CommandPalette({ start, token, roster, actions, useSessions }) { run: () => actions.openAgent(agent.id), })) if (agents.length) sections.push(['DSH Agent', agents]) - const messages = JSON.parse(found).map(([id, turn, snippet]) => { + const outlineRead = JSON.parse(found) ++ // A row's identity is the part that holds it, not chat+turn: turn numbers restart in every ++ // part, so an older part's turn 1 is a different message from this part's turn 1 (#3235). ++ // A row that names no part is the part the client holds; a room has none and keeps its id. ++ const partOf = (chat, part) => typeof part === 'string' ? part : currentPart(roster.byId[chat] ?? { id: chat }) ++ const rowKey = (chat, part, turn) => `${chat}:${partOf(chat, part)}:${turn}` + const messages = outlineRead.hits.map(([id, turn, snippet]) => { const bot = roster.byId[id] const room = roster.roomsById[id] return { - key: `${id}:${turn}`, title: bot?.name ?? room?.name ?? t('Bot'), subtitle: snippet, -+ key: `${chatOf(id)}:${turn}`, title: bot?.name ?? room?.name ?? t('Bot'), subtitle: snippet, ++ key: rowKey(chatOf(id), id, turn), title: bot?.name ?? room?.name ?? t('Bot'), subtitle: snippet, avatar: bot ? h(BotAvatar, { bot, size: 24, badge: false, live: false }) : h(RoomAvatar, { room, roster, size: 24 }), - run: () => actions.openSession(id), + run: () => actions.openSession(id, { turn }), @@ -2934,13 +2939,13 @@ diff --git a/src/client/palette.js b/src/client/palette.js + return Array.isArray(held) && held.length > 0 ? held.includes(turn) : undefined + } + const keyCounts = new Map() -+ const fullText = (wholeText?.rows ?? []).filter(row => row?.chat !== undefined && (roster.byId[row.chat] || roster.roomsById[row.chat]) && !outlined.has(`${row.chat}:${row.turn}`)).map(row => { ++ const fullText = (wholeText?.rows ?? []).filter(row => row?.chat !== undefined && (roster.byId[row.chat] || roster.roomsById[row.chat]) && !outlined.has(rowKey(row.chat, row.part, row.turn))).map(row => { + const bot = roster.byId[row.chat] + const room = roster.roomsById[row.chat] + // A row that names its part is placed by that part (#3114); a row without one keeps the + // outline's answer, the only proof the client has about what the part it holds contains. + const earlier = typeof row.part === 'string' ? bot !== undefined && row.part !== currentPart(bot) : inPart(row.chat, row.turn) === false -+ const at = `${row.chat}:${row.turn}` ++ const at = rowKey(row.chat, row.part, row.turn) + const count = (keyCounts.get(at) ?? 0) + 1 + keyCounts.set(at, count) + return { diff --git a/patches/ds-bot/0008-client-bundle.patch b/patches/ds-bot/0008-client-bundle.patch index 797507687..19bccd803 100644 --- a/patches/ds-bot/0008-client-bundle.patch +++ b/patches/ds-bot/0008-client-bundle.patch @@ -20573,7 +20573,7 @@ diff --git a/client.js b/client.js } }; window.addEventListener("mousedown", onDown); -@@ -7646,514 +7646,1050 @@ function MemoryDialog({ bot, actions, leaving = false }) { +@@ -7646,514 +7646,1052 @@ function MemoryDialog({ bot, actions, leaving = false }) { window.removeEventListener("mousedown", onDown); window.removeEventListener("keydown", onKey, true); }; @@ -21800,11 +21800,13 @@ diff --git a/client.js b/client.js + })); + if (agents.length) sections.push(["DSH Agent", agents]); + const outlineRead = JSON.parse(found); ++ const partOf2 = (chat, part) => typeof part === "string" ? part : currentPart(roster.byId[chat] ?? { id: chat }); ++ const rowKey = (chat, part, turn) => `${chat}:${partOf2(chat, part)}:${turn}`; + const messages = outlineRead.hits.map(([id, turn, snippet]) => { + const bot = roster.byId[id]; + const room2 = roster.roomsById[id]; + return { -+ key: `${chatOf2(id)}:${turn}`, ++ key: rowKey(chatOf2(id), id, turn), + title: bot?.name ?? room2?.name ?? t("Bot"), + subtitle: snippet, + avatar: bot ? (0, import_react35.createElement)(BotAvatar, { bot, size: 24, badge: false, live: false }) : (0, import_react35.createElement)(RoomAvatar, { room: room2, roster, size: 24 }), @@ -21822,11 +21824,11 @@ diff --git a/client.js b/client.js - }, [bot.id]); - return (0, import_react18.createElement)( + const keyCounts = /* @__PURE__ */ new Map(); -+ const fullText = (wholeText?.rows ?? []).filter((row) => row?.chat !== void 0 && (roster.byId[row.chat] || roster.roomsById[row.chat]) && !outlined.has(`${row.chat}:${row.turn}`)).map((row) => { ++ const fullText = (wholeText?.rows ?? []).filter((row) => row?.chat !== void 0 && (roster.byId[row.chat] || roster.roomsById[row.chat]) && !outlined.has(rowKey(row.chat, row.part, row.turn))).map((row) => { + const bot = roster.byId[row.chat]; + const room2 = roster.roomsById[row.chat]; + const earlier = typeof row.part === "string" ? bot !== void 0 && row.part !== currentPart(bot) : inPart(row.chat, row.turn) === false; -+ const at = `${row.chat}:${row.turn}`; ++ const at = rowKey(row.chat, row.part, row.turn); + const count = (keyCounts.get(at) ?? 0) + 1; + keyCounts.set(at, count); + return { diff --git a/patches/ds-bot/files/test/palette-preview.test.js b/patches/ds-bot/files/test/palette-preview.test.js index 7757487b6..decb381c4 100644 --- a/patches/ds-bot/files/test/palette-preview.test.js +++ b/patches/ds-bot/files/test/palette-preview.test.js @@ -260,8 +260,26 @@ function livePalette({ start = '', raw = '', rows = [], more = 0, outline, roste walk(live, node => { if (node.props?.className === className) out.push([node.props.children].flat().join('')) }) return out } + // Rows grouped by the section they render under: #3235's acceptance reads a row by the + // section it is in, never by a key, because two sections can otherwise look swapped. + const grouped = () => { + const out = [] + for (const node of flips()) { + const flip = node.props['data-flip'] + if (flip.startsWith('section:')) { out.push({ title: flip.slice('section:'.length), keys: [], badges: [], nodes: [] }); continue } + const section = out.at(-1) + if (section === undefined) continue + let badge + walk(node, child => { if (badge === undefined && child.props?.className === 'bt-palette-badge') badge = [child.props.children].flat().join('') }) + section.keys.push(flip) + section.badges.push(badge) + section.nodes.push(node) + } + return out + } return { - calls, settle, run, + calls, settle, run, grouped, + chooseAt: (title, index) => { grouped().find(section => section.title === title)?.nodes[index]?.props.onClick?.() }, sections: () => flips().map(node => node.props['data-flip']).filter(flip => flip.startsWith('section:')).map(flip => flip.slice('section:'.length)), rows: () => flips().map(node => node.props['data-flip']).filter(flip => !flip.startsWith('section:')), notes: () => texts('bt-palette-note'), @@ -279,13 +297,13 @@ test('P-820: a hit past the outline preview budget is found by the whole-text gr await palette.settle() assert.deepEqual(palette.calls.search.map(([query]) => query), ['needle'], 'the host search was asked for the query') assert.deepEqual(palette.sections(), ['Messages (full text)'], JSON.stringify(palette.sections())) - assert.deepEqual(palette.rows(), ['s1:7']) + assert.deepEqual(palette.rows(), ['s1:s1:7']) }) test('P-820: choosing a whole-text row opens the chat at that turn', async () => { const palette = livePalette({ start: 'needle', raw: 'a plain turn', outline: [{ turn: 7, prompt: 'a plain turn' }], rows: [{ chat: 's1', turn: 7, text: 'NEEDLE at the far end' }] }) await palette.settle() - palette.choose('s1:7') + palette.choose('s1:s1:7') // The row object comes from the palette's realm, so the fields are read, not deep-equalled. assert.equal(palette.calls.openSession.length, 1) assert.equal(palette.calls.openSession[0][0], 's1') @@ -298,7 +316,7 @@ test('P-820: a row the outline already found is not shown twice', async () => { const palette = livePalette({ start: 'needle', raw: 'the needle is right here', rows: [{ chat: 's1', turn: 1, text: 'the needle is right here' }, { chat: 's1', turn: 9, text: 'another NEEDLE far past the budget' }] }) await palette.settle() assert.deepEqual(palette.sections(), ['Messages', 'Messages (full text)'], JSON.stringify(palette.sections())) - assert.deepEqual(palette.rows(), ['s1:1', 's1:9'], JSON.stringify(palette.rows())) + assert.deepEqual(palette.rows(), ['s1:s1:1', 's1:s1:9'], JSON.stringify(palette.rows())) }) // #3114. Each row now says what it is and lands where it points: an outline hit names its own @@ -307,8 +325,8 @@ test('P-820: a row the outline already found is not shown twice', async () => { // and a Bot whose current part id is not its own id still shows one row. test('#3114: choosing an outline message row opens the chat at that turn', () => { const palette = livePalette({ start: 'needle', raw: 'the needle is right here' }) - assert.deepEqual(palette.rows(), ['s1:1'], JSON.stringify(palette.rows())) - palette.choose('s1:1') + assert.deepEqual(palette.rows(), ['s1:s1:1'], JSON.stringify(palette.rows())) + palette.choose('s1:s1:1') assert.equal(palette.calls.openSession.length, 1) assert.equal(palette.calls.openSession[0][0], 's1') assert.equal(palette.calls.openSession[0][1]?.turn, 1) @@ -332,7 +350,7 @@ test('#3114: the whole-text rows say how many the cap left out', async () => { test('#3114: two hits in one turn are two rows, each with its own key', async () => { const palette = livePalette({ start: 'needle', raw: 'a plain turn', rows: [{ chat: 's1', turn: 5, text: 'NEEDLE in the question' }, { chat: 's1', turn: 5, text: 'NEEDLE in the reply' }] }) await palette.settle() - assert.deepEqual(palette.rows(), ['s1:5', 's1:5:2'], JSON.stringify(palette.rows())) + assert.deepEqual(palette.rows(), ['s1:s1:5', 's1:s1:5:2'], JSON.stringify(palette.rows())) }) // The current part's outline is the only list of turns the client can prove it holds. A hit @@ -341,7 +359,7 @@ test('#3114: a hit the current part does not hold is marked as an earlier part', const elsewhere = livePalette({ start: 'needle', raw: 'a plain turn', rows: [{ chat: 's1', turn: 12, text: 'NEEDLE far past this part' }] }) await elsewhere.settle() assert.deepEqual(elsewhere.badges(), ['Earlier part']) - elsewhere.choose('s1:12') + elsewhere.choose('s1:s1:12') assert.equal(elsewhere.calls.openSession.length, 1) assert.equal(elsewhere.calls.openSession[0][0], 's1') assert.equal(elsewhere.calls.openSession[0][1], undefined, 'no turn is passed for a row the current part does not hold') @@ -349,7 +367,7 @@ test('#3114: a hit the current part does not hold is marked as an earlier part', const here = livePalette({ start: 'needle', raw: 'a plain turn', outline: [{ turn: 12, prompt: 'a plain turn' }], rows: [{ chat: 's1', turn: 12, text: 'NEEDLE inside this part' }] }) await here.settle() assert.deepEqual(here.badges(), []) - here.choose('s1:12') + here.choose('s1:s1:12') assert.equal(here.calls.openSession[0][1]?.turn, 12) }) @@ -361,7 +379,7 @@ test('#3114: a Bot whose part id is not its id is still deduped once', async () const palette = livePalette({ start: 'needle', raw: 'the needle is right here', roster, rows: [{ chat: 'a', turn: 1, text: 'the needle is right here' }] }) await palette.settle() assert.deepEqual(palette.sections(), ['Messages'], JSON.stringify(palette.sections())) - assert.deepEqual(palette.rows(), ['a:1'], JSON.stringify(palette.rows())) + assert.deepEqual(palette.rows(), ['a:pc:1'], JSON.stringify(palette.rows())) }) // An exchange turn is inside the current part: its position is in the flow, so it keeps its @@ -371,7 +389,7 @@ test('#3114: a hidden exchange turn keeps its turn, with no badge', async () => const palette = livePalette({ start: 'needle', raw: 'a plain turn', outline: [{ turn: 5, prompt: 'a plain turn' }], roster, rows: [{ chat: 's1', turn: 5, text: 'NEEDLE in the hidden reply' }] }) await palette.settle() assert.deepEqual(palette.badges(), []) - palette.choose('s1:5') + palette.choose('s1:s1:5') assert.equal(palette.calls.openSession[0][1]?.turn, 5) }) @@ -391,7 +409,7 @@ test('#3114: a hit the host places in an earlier part opens that part at its tur const palette = livePalette({ start: 'needle', raw: 'a plain turn', rows: [{ chat: 's1', turn: 12, part: 's1-old', text: 'NEEDLE far past this part' }] }) await palette.settle() assert.deepEqual(palette.badges(), ['Earlier part']) - palette.choose('s1:12') + palette.choose('s1:s1-old:12') assert.equal(palette.calls.openSession.length, 1) assert.equal(palette.calls.openSession[0][0], 's1') assert.equal(palette.calls.openSession[0][1]?.part, 's1-old') @@ -405,7 +423,49 @@ test('#3114: a hit in the current part keeps its own seek', async () => { const palette = livePalette({ start: 'needle', raw: 'a plain turn', outline: [{ turn: 1, prompt: 'a plain turn' }], rows: [{ chat: 's1', turn: 1, part: 's1', text: 'NEEDLE inside this part' }] }) await palette.settle() assert.deepEqual(palette.badges(), []) - palette.choose('s1:1') + palette.choose('s1:s1:1') assert.equal(palette.calls.openSession[0][1]?.turn, 1) assert.equal(palette.calls.openSession[0][1]?.part, undefined, 'the current part is not named as another part') }) + +// #3235. Turn numbers restart in every part, so `chat:turn` is not an identity: an older part's +// turn 1 is a different message from this part's turn 1. The dedupe used to eat it, and with it +// the whole `Messages (full text)` section; the row must render, keep its badge, and open the +// part it came from. +test('#3235: an older part\'s hit survives a same-numbered hit in this part', async () => { + const palette = livePalette({ + start: 'needle', raw: 'the needle is right here', outline: [{ turn: 1, prompt: 'the needle is right here' }], + rows: [{ chat: 's1', turn: 1, part: 's1-old', text: 'NEEDLE said in an older part' }], + }) + await palette.settle() + const sections = palette.grouped() + assert.deepEqual(sections.map(section => section.title), ['Messages', 'Messages (full text)'], JSON.stringify(sections.map(section => section.title))) + assert.equal(sections[1].keys.length, 1, JSON.stringify(sections[1].keys)) + assert.deepEqual(sections[1].badges, ['Earlier part']) + assert.notEqual(sections[0].keys[0], sections[1].keys[0], 'the two rows must not share one key') + palette.chooseAt('Messages (full text)', 0) + assert.equal(palette.calls.openSession.length, 1) + assert.equal(palette.calls.openSession[0][0], 's1') + assert.equal(palette.calls.openSession[0][1]?.part, 's1-old') + assert.equal(palette.calls.openSession[0][1]?.turn, 1) +}) + +// Two parts can both hold a turn 5. They are two messages: their keys must differ, and each row +// still opens the part it names. +test('#3235: the same chat and turn in two parts get keys of their own', async () => { + const rows = [ + { chat: 's1', turn: 5, part: 's1-a', text: 'NEEDLE in part A' }, + { chat: 's1', turn: 5, part: 's1-b', text: 'NEEDLE in part B' }, + ] + const palette = livePalette({ start: 'needle', raw: 'a plain turn', rows }) + await palette.settle() + const [whole] = palette.grouped() + assert.deepEqual(whole.title, 'Messages (full text)') + assert.deepEqual(whole.keys, ['s1:s1-a:5', 's1:s1-b:5'], JSON.stringify(whole.keys)) + palette.chooseAt('Messages (full text)', 0) + assert.equal(palette.calls.openSession[0][1]?.part, 's1-a') + const second = livePalette({ start: 'needle', raw: 'a plain turn', rows }) + await second.settle() + second.chooseAt('Messages (full text)', 1) + assert.equal(second.calls.openSession[0][1]?.part, 's1-b') +})