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
15 changes: 9 additions & 6 deletions apps/web/__tests__/ai-meeting-briefing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ function getMeetingBriefingData(
}

describe("buildPrompt", () => {
const mockEmailAccount = getEmailAccount({ timezone: "America/New_York" });
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The getEmailAccount helper doesn't apply the timezone override - it's hardcoded to null. Both mockEmailAccount and mockEmailAccountNoTz will have timezone: null, so tests expecting a timezone won't actually validate timezone handling. The helper in apps/web/__tests__/helpers.ts needs to be updated to use timezone: overrides.timezone ?? null.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/web/__tests__/ai-meeting-briefing.test.ts, line 54:

<comment>The `getEmailAccount` helper doesn't apply the `timezone` override - it's hardcoded to `null`. Both `mockEmailAccount` and `mockEmailAccountNoTz` will have `timezone: null`, so tests expecting a timezone won't actually validate timezone handling. The helper in `apps/web/__tests__/helpers.ts` needs to be updated to use `timezone: overrides.timezone ?? null`.</comment>

<file context>
@@ -51,9 +51,12 @@ function getMeetingBriefingData(
 }
 
 describe("buildPrompt", () => {
+  const mockEmailAccount = getEmailAccount({ timezone: "America/New_York" });
+  const mockEmailAccountNoTz = getEmailAccount({ timezone: null });
+
</file context>
Fix with Cubic

const mockEmailAccountNoTz = getEmailAccount({ timezone: null });

test("builds prompt with meeting title and description", () => {
const data = getMeetingBriefingData();
const prompt = buildPrompt(data, "America/New_York");
const prompt = buildPrompt(data, mockEmailAccount);

expect(prompt).toContain("Product Discussion");
expect(prompt).toContain("Q1 roadmap");
Expand All @@ -63,7 +66,7 @@ describe("buildPrompt", () => {
const data = getMeetingBriefingData({
externalGuests: [{ email: "bob@company.com", name: "Bob Smith" }],
});
const prompt = buildPrompt(data, null);
const prompt = buildPrompt(data, mockEmailAccountNoTz);

expect(prompt).toContain("bob@company.com");
expect(prompt).toContain("Bob Smith");
Expand All @@ -75,7 +78,7 @@ describe("buildPrompt", () => {
emailThreads: [],
pastMeetings: [],
});
const prompt = buildPrompt(data, null);
const prompt = buildPrompt(data, mockEmailAccountNoTz);

expect(prompt).toContain("<no_prior_context>");
expect(prompt).toContain("New Contact");
Expand All @@ -99,7 +102,7 @@ describe("buildPrompt", () => {
},
],
});
const prompt = buildPrompt(data, null);
const prompt = buildPrompt(data, mockEmailAccountNoTz);

expect(prompt).toContain("<recent_emails>");
expect(prompt).toContain("Partnership proposal");
Expand All @@ -121,7 +124,7 @@ describe("buildPrompt", () => {
externalGuests: [{ email: "alice@external.com", name: "Alice External" }],
pastMeetings: [pastMeeting],
});
const prompt = buildPrompt(data, "America/New_York");
const prompt = buildPrompt(data, mockEmailAccount);

expect(prompt).toContain("<recent_meetings>");
expect(prompt).toContain("Initial Discussion");
Expand All @@ -134,7 +137,7 @@ describe("buildPrompt", () => {
{ email: "bob@acme.com", name: "Bob Jones" },
],
});
const prompt = buildPrompt(data, null);
const prompt = buildPrompt(data, mockEmailAccountNoTz);

expect(prompt).toContain("alice@acme.com");
expect(prompt).toContain("Alice Smith");
Expand Down
34 changes: 32 additions & 2 deletions apps/web/utils/ai/meeting-briefs/generate-briefing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ vi.mock("@/env", () => ({
}));
vi.mock("@/utils/llms/model", () => ({ getModel: vi.fn() }));
vi.mock("@/utils/llms", () => ({ createGenerateObject: vi.fn() }));
vi.mock("@/utils/ai/helpers", () => ({
getUserInfoPrompt: vi.fn(
({ emailAccount }) =>
`The user you are acting on behalf of is:
<user_info>
<email>${emailAccount.email}</email>
<about>${emailAccount.about}</about>
</user_info>`,
),
}));
vi.mock("@/utils/stringify-email", () => ({
stringifyEmailSimple: vi.fn(
(email) =>
Expand All @@ -27,12 +37,18 @@ vi.mock("@/utils/get-email-from-message", () => ({
vi.doUnmock("@/utils/date");

import { buildPrompt } from "./generate-briefing";
import type { EmailAccountWithAI } from "@/utils/llms/types";

beforeEach(() => {
vi.clearAllMocks();
});

describe("buildPrompt timezone handling", () => {
const mockEmailAccount = {
email: "user@company.com",
timezone: "America/Sao_Paulo",
about: "I am a product manager at Company Inc.",
} as EmailAccountWithAI;
it("formats past meeting times in the user's timezone (not UTC)", () => {
// This test documents the timezone bug fix:
// - Calendar API stores times in UTC
Expand All @@ -54,6 +70,7 @@ describe("buildPrompt timezone handling", () => {
],
},
externalGuests: [{ email: "client@acme.com", name: "John Smith" }],
internalTeamMembers: [],
emailThreads: [],
pastMeetings: [
{
Expand All @@ -67,12 +84,18 @@ describe("buildPrompt timezone handling", () => {
],
};

const prompt = buildPrompt(briefingData, "America/Sao_Paulo");
const prompt = buildPrompt(briefingData, mockEmailAccount);

// The past meeting should show "4:00 PM" (Brazil time), NOT "7:00 PM" (UTC)
expect(prompt).toMatchInlineSnapshot(`
"Prepare a concise briefing for this upcoming meeting.

The user you are acting on behalf of is:
<user_info>
<email>user@company.com</email>
<about>I am a product manager at Company Inc.</about>
</user_info>

<upcoming_meeting>
Title: Strategy Review
Description: Discuss Q1 roadmap
Expand Down Expand Up @@ -117,15 +140,22 @@ describe("buildPrompt timezone handling", () => {
],
},
externalGuests: [{ email: "newcontact@other.com", name: "New Person" }],
internalTeamMembers: [],
emailThreads: [],
pastMeetings: [],
};

const prompt = buildPrompt(briefingData, "America/Sao_Paulo");
const prompt = buildPrompt(briefingData, mockEmailAccount);

expect(prompt).toMatchInlineSnapshot(`
"Prepare a concise briefing for this upcoming meeting.

The user you are acting on behalf of is:
<user_info>
<email>user@company.com</email>
<about>I am a product manager at Company Inc.</about>
</user_info>

<upcoming_meeting>
Title: Intro Meeting

Expand Down
9 changes: 6 additions & 3 deletions apps/web/utils/ai/meeting-briefs/generate-briefing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { env } from "@/env";
import { getModel } from "@/utils/llms/model";
import { createGenerateText } from "@/utils/llms";
import type { EmailAccountWithAI } from "@/utils/llms/types";
import { getUserInfoPrompt } from "@/utils/ai/helpers";
import type { CalendarEvent } from "@/utils/calendar/event-types";
import type { MeetingBriefingData } from "@/utils/meeting-briefs/gather-context";
import { stringifyEmailSimple } from "@/utils/stringify-email";
Expand Down Expand Up @@ -94,7 +95,7 @@ export async function aiGenerateMeetingBriefing({
);
}

const prompt = buildPrompt(briefingData, emailAccount.timezone);
const prompt = buildPrompt(briefingData, emailAccount);
const modelOptions = getModel(emailAccount.user);

const generateText = createGenerateText({
Expand Down Expand Up @@ -342,7 +343,7 @@ function createWebSearchTool({
// Exported for testing
export function buildPrompt(
briefingData: MeetingBriefingData,
timezone: string | null,
emailAccount: EmailAccountWithAI,
): string {
const { event, externalGuests, emailThreads, pastMeetings } = briefingData;

Expand All @@ -354,7 +355,7 @@ export function buildPrompt(
name: guest.name,
recentEmails: selectRecentEmailsForGuest(allMessages, guest.email),
recentMeetings: selectRecentMeetingsForGuest(pastMeetings, guest.email),
timezone,
timezone: emailAccount.timezone,
}),
);

Expand All @@ -376,6 +377,8 @@ export function buildPrompt(

const prompt = `Prepare a concise briefing for this upcoming meeting.

${getUserInfoPrompt({ emailAccount })}

<upcoming_meeting>
Title: ${event.title}
${event.description ? `Description: ${event.description}` : ""}
Expand Down
Loading