Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions backend/src/events/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
} from '../calendar/cardInvite';
import { GuestInviteValidationError, isPodcastTemplateType, type GuestInvite } from '../calendar/guestInvite';
import { reportGuestInviteFailure, writeGuestInvite } from '../calendar/guestInviteSync';
import { podcastInviteTitle } from '../calendar/holds';
import { isPodcastInviteTitle, podcastInviteTitle } from '../calendar/holds';
import { resolveHoldGoogleCalendars } from '../calendar/dapierBroker';
import {
createHoldGoogleEvents,
Expand Down Expand Up @@ -747,8 +747,10 @@ async function runTransition(
? {
eventType: template.type,
// Explicit operator input wins over stored episode/card guests, which may hold the stale spelling being corrected.
// A --title only overrides when it is itself canonical ("<Guest> at DataTalks.Club Podcast");
// any other --title (a topic, "Podcast conversation with …") is the Card title, never the invite title.
guestTitle: (input.guestNames?.trim() ? podcastInviteTitle(input.guestNames.trim()) : '')
|| (input.title?.trim() ? input.title.trim() : '')
|| (isPodcastInviteTitle(input.title || '') ? input.title!.trim() : '')
|| await resolvePodcastCardInviteTitle(client, card, template, episode)
|| podcastInviteTitle(current?.renderValues?.guestNames || '') || undefined,
}
Expand Down
10 changes: 9 additions & 1 deletion backend/src/routes/calendarHolds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { CardVersionConflictError, getCardConsistent } from '../db/cards';
import { listPodcastEpisodes, type PodcastEpisode } from '../db/podcastEpisodes';
import { CardInviteConflictError, CardInviteInputError, resolvePodcastCardInviteTitle, syncCardInvite } from '../calendar/cardInvite';
import { recordAutomationRun } from '../automations/runs';
import { getEventRecord } from '../events/store';
import {
EventConflictError,
EventInputError,
Expand Down Expand Up @@ -493,8 +494,15 @@ async function verifyInviteRoute(id: string, event: LambdaEvent, client: DynamoD
const deps = await calendarInviteDeps({}, client);
const card = hold.cardId ? await getCardConsistent(client, hold.cardId) : null;
const guestTitle = card ? await resolvePodcastCardInviteTitle(client, card) : undefined;
// An event-lifecycle invite carries every guest on its event record; a plain hold (no
// lifecycle authority on the shared row) has one guestRef.
const record = await getEventRecord(client, hold.id).catch((error: unknown) => {
if (error instanceof EventConflictError) return null;
throw error;
});
const guests = record?.guestEmails?.length ? record.guestEmails : hold.guestRef ? [hold.guestRef] : [];
const expected = buildGuestInvite({
eventKey: hold.id, title: hold.title, guestTitle, documentUrl: hold.documentUrl, guests: hold.guestRef ? [hold.guestRef] : [],
eventKey: hold.id, title: hold.title, guestTitle, documentUrl: hold.documentUrl, guests,
startIso: hold.startIso, endIso: hold.endIso,
}, deps.calendarIds);
const problems = await validateGuestInviteReadback(expected, hold.googleEventIds || {}, deps);
Expand Down
30 changes: 30 additions & 0 deletions backend/tests/guest-invite-builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,34 @@ describe('shared podcast guest-invite builder (Hub intake 0d56721e)', () => {
assert.ok(bad.problems.some((p: string) => /title is/.test(p)));
assert.equal(google.calls.filter(c => c.method !== 'GET' && c.url.pathname.includes('/events')).length, writesBefore, 'no Google writes');
});

it('a non-canonical --title (placeholder or topic) never becomes the podcast invite title; verify-invite checks every event guest', async () => {
google = holdGoogleProvider();
setCalendarHoldGoogleDepsForTests({ ...deps() });
const SECOND = 'dev+invite-second@dtcdev.click';
const card = await podcastCard();
// The SerpApi repro: propose with the placeholder card title, two guests, approve.
await proposeEvent(client, card.id, {
date: '2026-12-15', time: '18:00', title: 'Podcast conversation with Julien Khaleghy', guestEmails: [GUEST, SECOND], deps: deps(), actor: 'test-operator',
});
const approved = await approveEvent(client, card.id, { deps: deps(), actor: 'test-operator' });
assert.equal(liveInvite(approved.event.googleEventIds).summary, 'Julien Khaleghy at DataTalks.Club Podcast');
// A later `event update --title <topic>` stays canonical and silent.
const writesBefore = google.calls.filter(c => c.method === 'PATCH' && c.url.searchParams.get('sendUpdates') === 'all').length;
const updated = await updateEvent(client, card.id, { title: 'Giving AI Agents Reliable Access to the Web', deps: deps(), actor: 'test-operator' });
const live = liveInvite(updated.event.googleEventIds);
assert.equal(live.summary, 'Julien Khaleghy at DataTalks.Club Podcast');
assert.equal(live.personal.summary, live.summary);
assert.deepEqual(live.attendees, [GUEST, SECOND, OWNER_PERSONAL_CALENDAR, OWNER_WORK_EMAIL].sort());
assert.equal(google.calls.filter(c => c.method === 'PATCH' && c.url.searchParams.get('sendUpdates') === 'all').length, writesBefore, 'update emails no guest');
// A canonical --title still overrides (stale guest spelling fix, #457).
const fixed = await updateEvent(client, card.id, { title: 'Julien Khaleghy-Fixed at DataTalks.Club Podcast', deps: deps(), actor: 'test-operator' });
assert.equal(liveInvite(fixed.event.googleEventIds).summary, 'Julien Khaleghy-Fixed at DataTalks.Club Podcast');
// verify-invite on the approved event's own row expects both guests, not only the hold guestRef.
await updateEvent(client, card.id, { deps: deps(), actor: 'test-operator' });
const holdId = (await getCardConsistent(client, card.id))!.eventTime?.eventKey || `hold_${card.id}`;
const verify = JSON.parse((await handler({ httpMethod: 'GET', path: `/api/calendar-holds/${holdId}/verify-invite`, body: null, headers: { 'x-user-id': 'test-operator' }, queryStringParameters: {} })).body);
assert.equal(verify.ok, true, JSON.stringify(verify.problems));
assert.ok(verify.expected.attendees.includes(SECOND));
});
});
12 changes: 12 additions & 0 deletions frontend/src/surfaces/tasks/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export function createTemplatesSurface(context) {
editorOpen: false,
};

const definitionDetailsOpen = new Map();
let renderedDefinitionDetails = null;

// Selecting a Template re-renders the whole surface (route change plus a
// fresh fetch), which recreates the list element. The list controller owns
// the scroll offset, filter text, and collapsed groups across rerenders.
Expand Down Expand Up @@ -157,6 +160,13 @@ export function createTemplatesSurface(context) {
}

function renderTemplatesSurface() {
// A late work snapshot rebuilds this pane. Read the native disclosure state
// before replacing it, including changes whose toggle event is still queued.
if (renderedDefinitionDetails) {
const { templateId, element } = renderedDefinitionDetails;
definitionDetailsOpen.set(templateId, element.open);
renderedDefinitionDetails = null;
}
return renderRuntimeTemplateInspector();
}

Expand Down Expand Up @@ -354,6 +364,8 @@ export function createTemplatesSurface(context) {

const definitionSection = document.createElement("details");
definitionSection.className = "runtime-template-block runtime-template-provenance";
definitionSection.open = definitionDetailsOpen.get(selected.id) === true;
renderedDefinitionDetails = { templateId: selected.id, element: definitionSection };
const definitionSummary = document.createElement("summary");
definitionSummary.textContent = "Definition details";
const provenanceNote = document.createElement("p");
Expand Down
45 changes: 42 additions & 3 deletions frontend/test/templates-surface-steps.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function walk(node, out = []) {
}
const byClass = (node, name) => walk(node).filter((el) => el.classList?.contains?.(name));

function renderSurface() {
function renderSurface({ templates = [TEMPLATE], state = { workSnapshot: { cards: [] } } } = {}) {
const surface = createTemplatesSurface({
countLabel: (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`,
getAllDocuments: () => [],
Expand All @@ -65,11 +65,11 @@ function renderSurface() {
renderHonestState: (title) => { const el = new FakeElement("div"); el.textContent = title; return el; },
renderEntityLoadState: () => {},
renderTasksSurface: () => {},
request: async () => ({ templates: [TEMPLATE] }),
request: async () => ({ templates }),
refreshOperationsWorkSnapshot: async () => {},
resolveDocReference,
setWorkspaceEntityState: () => {},
state: { workSnapshot: { cards: [] } },
state,
workApiUrl: (path) => path,
});
return surface;
Expand Down Expand Up @@ -132,6 +132,45 @@ describe("templates surface Steps", () => {
assert.deepEqual(remindLinks.map((a) => a.href), ["/03-programs/templates/remind-guest.md"]);
});

test("Definition details stays open through a late work snapshot, and an explicit close stays closed", async () => {
const state = { workSnapshot: { cards: [] } };
const surface = renderSurface({ state });
await surface.refreshRuntimeTemplates();
surface.setRuntimeTemplateRoute({ tasksSection: "templates", params: new URLSearchParams("templateId=tpl-1") }, { templateId: "tpl-1" });
const renderDetails = () => {
const section = surface.renderTemplatesSurface();
root.replaceChildren(section);
return byClass(section, "runtime-template-provenance")[0];
};
const initial = renderDetails();
assert.equal(Boolean(initial.open), false);
initial.open = true;

// The parent rebuilds Templates when its delayed Card/Task snapshot arrives.
// Rebuild immediately: preservation must not depend on a queued toggle event.
state.workSnapshot.cards = [{ id: "late-card", templateId: "tpl-1", status: "active", createdAt: "2026-11-25T12:00:00Z" }];
const refreshed = renderDetails();
assert.notEqual(refreshed, initial);
assert.equal(refreshed.open, true);
refreshed.open = false;
assert.equal(renderDetails().open, false);
});

test("Definition details remembers each template independently across route changes", async () => {
const surface = renderSurface({ templates: [TEMPLATE, { ...TEMPLATE, id: "tpl-2", name: "Another workshop" }] });
await surface.refreshRuntimeTemplates();
const select = (id) => {
surface.setRuntimeTemplateRoute({ tasksSection: "templates", params: new URLSearchParams(`templateId=${id}`) }, { templateId: id });
const section = surface.renderTemplatesSurface();
root.replaceChildren(section);
return byClass(section, "runtime-template-provenance")[0];
};
select("tpl-1").open = true;
assert.equal(select("tpl-2").open, false);
assert.equal(select("tpl-1").open, true);
assert.equal(select("tpl-2").open, false);
});

test("the Templates list scroll is restored after the rebuilt list is attached", async () => {
const surface = renderSurface();
await surface.refreshRuntimeTemplates();
Expand Down