From 2fb09382c604135fc74e7ed443d87ca018de46dd Mon Sep 17 00:00:00 2001 From: Zane Bong Date: Fri, 30 Oct 2026 13:51:32 +1030 Subject: [PATCH] Stop search crashing on repeated session codes within an event The Ignite 2026 catalog lists some sessions once per time slot (77 codes today, mostly labs and lightning talks), so MiniSearch throws "duplicate ID" and every msevents search fails. Index only the first row per event::sessionCode; findSession still returns every slot. Drop the M365 build's unique-code check, which existed only because of this crash. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: dc8d0c3c-e6a7-4a74-bee9-cf99887b72b5 --- cli/scripts/build-m365-plugin.mjs | 5 ----- cli/src/search/index.ts | 11 ++++++++++- cli/test/search.test.ts | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/cli/scripts/build-m365-plugin.mjs b/cli/scripts/build-m365-plugin.mjs index 7e90f7e..9f07645 100644 --- a/cli/scripts/build-m365-plugin.mjs +++ b/cli/scripts/build-m365-plugin.mjs @@ -207,15 +207,10 @@ async function readCachedEvent(dir, event) { const sessions = await readJson(file); if (!Array.isArray(sessions) || sessions.length === 0) fail(`${file} has no sessions`); - const seen = new Set(); for (const session of sessions) { if (typeof session?.sessionCode !== 'string' || !session.sessionCode || session.event !== event.id) { fail(`${file} contains a record that isn't a normalized ${event.id} session`); } - if (seen.has(session.sessionCode)) { - fail(`${file} repeats session code ${session.sessionCode}; the search index needs unique codes per event`); - } - seen.add(session.sessionCode); } const metaFile = join(dir, `${event.id}-meta.json`); diff --git a/cli/src/search/index.ts b/cli/src/search/index.ts index 6586f3d..307bacf 100644 --- a/cli/src/search/index.ts +++ b/cli/src/search/index.ts @@ -34,7 +34,16 @@ export function buildIndex(sessions: Session[]): void { return (doc as unknown as Record)[fieldName] ?? ''; }, }); - index.addAll(sessions); + // Some catalogs list a session once per time slot. Index only the first row + // per ID, because MiniSearch throws on duplicate IDs; findSession still + // returns every row. + const seen = new Set(); + index.addAll(sessions.filter((s) => { + const id = `${s.event}::${s.sessionCode}`; + if (seen.has(id)) return false; + seen.add(id); + return true; + })); } export interface SearchOptions { diff --git a/cli/test/search.test.ts b/cli/test/search.test.ts index 40e81d8..5fb7978 100644 --- a/cli/test/search.test.ts +++ b/cli/test/search.test.ts @@ -123,3 +123,23 @@ describe('Ignite 2026 catalog', () => { expect(results.every((r) => r.session.event === 'ignite-2026')).toBe(true); }); }); + +describe('repeated session code within an event', () => { + beforeAll(() => { + const ignitePath = join(import.meta.dirname, 'fixtures', 'ignite-2026-sample.json'); + const igniteRaw: RawSession[] = JSON.parse(readFileSync(ignitePath, 'utf-8')); + const laterSlot: RawSession = { ...igniteRaw[0]!, TimeSlot: '17:45 - 19:00' }; + buildIndex(normalizeCatalog([...igniteRaw, laterSlot], 'ignite-2026')); + }); + + it('indexes without throwing and returns the session once from search', () => { + const results = searchSessions({ query: 'Salesforce migration', event: 'ignite-2026' }); + expect(results.filter((r) => r.session.sessionCode === 'LAB700')).toHaveLength(1); + }); + + it('returns every time slot from findSession', () => { + const slots = findSession('LAB700', 'ignite-2026').map((s) => s.timeSlot); + expect(slots).toHaveLength(2); + expect(slots).toContain('17:45 - 19:00'); + }); +});