Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdds manual Outlook integration tests gated by env vars, introduces OData escaping for conversationId in thread fetch, hardens removeThreadLabel error handling, enables on-demand label creation during resolution, refines Outlook label conflict handling, updates reply-tracker copy, removes an unused import, adds a test script, and bumps version. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Tester as Manual Test Runner
participant Test as outlook-operations.test.ts
participant DB as Prisma
participant Outlook as OutlookProvider
participant MS as Microsoft Graph
Tester->>Test: Run "vitest outlook-operations" (with TEST_OUTLOOK_EMAIL)
Test->>DB: Load Outlook account by email
DB-->>Test: Account credentials
Test->>Outlook: Initialize provider with credentials
rect rgba(200,235,255,0.3)
note right of Outlook: Thread fetch with escaped conversationId
Test->>Outlook: getThreadMessagesInInbox(conversationId)
Outlook->>MS: GET /messages?$filter=conversationId eq 'escaped(...)'
MS-->>Outlook: Messages
Outlook-->>Test: Messages
end
rect rgba(220,255,220,0.3)
note right of Outlook: Remove thread label with robust handling
Test->>Outlook: removeThreadLabel(threadId, labelId)
Outlook->>MS: GET category by ID → displayName
MS-->>Outlook: category displayName
Outlook->>MS: PATCH thread categories (remove by displayName)
alt Category not found (404)
Outlook-->>Test: Log and return (skip)
else Other error
Outlook-->>Test: Throw error
end
end
sequenceDiagram
autonumber
participant Caller as Any caller
participant Resolver as resolve-label.ts
participant Outlook as outlook/label.ts
participant MS as Microsoft Graph
Caller->>Resolver: resolve({ label })
alt Found by name
Resolver->>Outlook: getLabelByName(label)
Outlook->>MS: Query categories
MS-->>Outlook: Existing category
Outlook-->>Resolver: id
Resolver-->>Caller: id
else Not found -> create
Resolver->>Outlook: createLabel(label)
Outlook->>MS: Create category
alt Conflict (exists)
Outlook-->>Resolver: Fetch existing by name and return id
else Created
MS-->>Outlook: New category
Outlook-->>Resolver: id
end
Resolver-->>Caller: id
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/web/utils/email/microsoft.ts (1)
482-504: Skip empty labelIds before fetching metadataWe already know an empty labelId can’t resolve to a category, so we can short-circuit before hitting Graph. This keeps the “empty id is a no-op” behavior without relying on the SDK to return a specific status code (404 vs 400) and saves an unnecessary network call.
async removeThreadLabel(threadId: string, labelId: string): Promise<void> { - // Get the label to convert ID to name (Outlook uses names) - // NOTE: if we have name already, we can skip this step. But because we let users use custom ids and we're not storing the custom category name, we need to first fetch the name. + if (!labelId?.trim()) { + logger.info("Label id is empty, skipping removal", { threadId, labelId }); + return; + } + // Get the label to convert ID to name (Outlook uses names) + // NOTE: if we have name already, we can skip this step. But because we let users use custom ids and we're not storing the custom category name, we need to first fetch the name. try { const label = await getLabelById({ client: this.client, id: labelId }); const categoryName = label.displayName || ""; await removeThreadLabel({
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
apps/web/__tests__/outlook-operations.test.ts(1 hunks)apps/web/package.json(1 hunks)apps/web/utils/email/microsoft.ts(2 hunks)apps/web/utils/label/resolve-label.ts(2 hunks)apps/web/utils/outlook/label.ts(1 hunks)apps/web/utils/outlook/odata-escape.ts(2 hunks)apps/web/utils/reply-tracker/consts.ts(1 hunks)apps/web/utils/rule/rule.ts(0 hunks)version.txt(1 hunks)
💤 Files with no reviewable changes (1)
- apps/web/utils/rule/rule.ts
🧰 Additional context used
📓 Path-based instructions (14)
apps/web/**/*.{ts,tsx}
📄 CodeRabbit inference engine (apps/web/CLAUDE.md)
apps/web/**/*.{ts,tsx}: Use TypeScript with strict null checks
Path aliases: Use@/for imports from project root
Use proper error handling with try/catch blocks
Format code with Prettier
Leverage TypeScript inference for better DX
Files:
apps/web/utils/email/microsoft.tsapps/web/utils/outlook/odata-escape.tsapps/web/utils/reply-tracker/consts.tsapps/web/utils/label/resolve-label.tsapps/web/utils/outlook/label.tsapps/web/__tests__/outlook-operations.test.ts
!{.cursor/rules/*.mdc}
📄 CodeRabbit inference engine (.cursor/rules/cursor-rules.mdc)
Never place rule files in the project root, in subdirectories outside .cursor/rules, or in any other location
Files:
apps/web/utils/email/microsoft.tsversion.txtapps/web/utils/outlook/odata-escape.tsapps/web/package.jsonapps/web/utils/reply-tracker/consts.tsapps/web/utils/label/resolve-label.tsapps/web/utils/outlook/label.tsapps/web/__tests__/outlook-operations.test.ts
**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/form-handling.mdc)
**/*.ts: The same validation should be done in the server action too
Define validation schemas using Zod
Files:
apps/web/utils/email/microsoft.tsapps/web/utils/outlook/odata-escape.tsapps/web/utils/reply-tracker/consts.tsapps/web/utils/label/resolve-label.tsapps/web/utils/outlook/label.tsapps/web/__tests__/outlook-operations.test.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/logging.mdc)
**/*.{ts,tsx}: UsecreateScopedLoggerfor logging in backend TypeScript files
Typically add the logger initialization at the top of the file when usingcreateScopedLogger
Only use.with()on a logger instance within a specific function, not for a global loggerImport Prisma in the project using
import prisma from "@/utils/prisma";
**/*.{ts,tsx}: Don't use TypeScript enums.
Don't use TypeScript const enum.
Don't use the TypeScript directive @ts-ignore.
Don't use primitive type aliases or misleading types.
Don't use empty type parameters in type aliases and interfaces.
Don't use any or unknown as type constraints.
Don't use implicit any type on variable declarations.
Don't let variables evolve into any type through reassignments.
Don't use non-null assertions with the ! postfix operator.
Don't misuse the non-null assertion operator (!) in TypeScript files.
Don't use user-defined types.
Use as const instead of literal types and type annotations.
Use export type for types.
Use import type for types.
Don't declare empty interfaces.
Don't merge interfaces and classes unsafely.
Don't use overload signatures that aren't next to each other.
Use the namespace keyword instead of the module keyword to declare TypeScript namespaces.
Don't use TypeScript namespaces.
Don't export imported variables.
Don't add type annotations to variables, parameters, and class properties that are initialized with literal expressions.
Don't use parameter properties in class constructors.
Use either T[] or Array consistently.
Initialize each enum member value explicitly.
Make sure all enum members are literal values.
Files:
apps/web/utils/email/microsoft.tsapps/web/utils/outlook/odata-escape.tsapps/web/utils/reply-tracker/consts.tsapps/web/utils/label/resolve-label.tsapps/web/utils/outlook/label.tsapps/web/__tests__/outlook-operations.test.ts
apps/web/utils/**
📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)
Create utility functions in
utils/folder for reusable logic
Files:
apps/web/utils/email/microsoft.tsapps/web/utils/outlook/odata-escape.tsapps/web/utils/reply-tracker/consts.tsapps/web/utils/label/resolve-label.tsapps/web/utils/outlook/label.ts
apps/web/utils/**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)
apps/web/utils/**/*.ts: Use lodash utilities for common operations (arrays, objects, strings)
Import specific lodash functions to minimize bundle size
Files:
apps/web/utils/email/microsoft.tsapps/web/utils/outlook/odata-escape.tsapps/web/utils/reply-tracker/consts.tsapps/web/utils/label/resolve-label.tsapps/web/utils/outlook/label.ts
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)
**/*.{js,jsx,ts,tsx}: Don't useelements in Next.js projects.
Don't use elements in Next.js projects.
Don't use namespace imports.
Don't access namespace imports dynamically.
Don't use global eval().
Don't use console.
Don't use debugger.
Don't use var.
Don't use with statements in non-strict contexts.
Don't use the arguments object.
Don't use consecutive spaces in regular expression literals.
Don't use the comma operator.
Don't use unnecessary boolean casts.
Don't use unnecessary callbacks with flatMap.
Use for...of statements instead of Array.forEach.
Don't create classes that only have static members (like a static namespace).
Don't use this and super in static contexts.
Don't use unnecessary catch clauses.
Don't use unnecessary constructors.
Don't use unnecessary continue statements.
Don't export empty modules that don't change anything.
Don't use unnecessary escape sequences in regular expression literals.
Don't use unnecessary labels.
Don't use unnecessary nested block statements.
Don't rename imports, exports, and destructured assignments to the same name.
Don't use unnecessary string or template literal concatenation.
Don't use String.raw in template literals when there are no escape sequences.
Don't use useless case statements in switch statements.
Don't use ternary operators when simpler alternatives exist.
Don't use useless this aliasing.
Don't initialize variables to undefined.
Don't use the void operators (they're not familiar).
Use arrow functions instead of function expressions.
Use Date.now() to get milliseconds since the Unix Epoch.
Use .flatMap() instead of map().flat() when possible.
Use literal property access instead of computed property access.
Don't use parseInt() or Number.parseInt() when binary, octal, or hexadecimal literals work.
Use concise optional chaining instead of chained logical expressions.
Use regular expression literals instead of the RegExp constructor when possible.
Don't use number literal object member names th...
Files:
apps/web/utils/email/microsoft.tsapps/web/utils/outlook/odata-escape.tsapps/web/utils/reply-tracker/consts.tsapps/web/utils/label/resolve-label.tsapps/web/utils/outlook/label.tsapps/web/__tests__/outlook-operations.test.ts
!pages/_document.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)
!pages/_document.{js,jsx,ts,tsx}: Don't import next/document outside of pages/_document.jsx in Next.js projects.
Don't import next/document outside of pages/_document.jsx in Next.js projects.
Files:
apps/web/utils/email/microsoft.tsversion.txtapps/web/utils/outlook/odata-escape.tsapps/web/package.jsonapps/web/utils/reply-tracker/consts.tsapps/web/utils/label/resolve-label.tsapps/web/utils/outlook/label.tsapps/web/__tests__/outlook-operations.test.ts
**/*.test.{ts,js}
📄 CodeRabbit inference engine (.cursor/rules/security.mdc)
Include security tests in your test suites to verify authentication, authorization, and error handling.
Files:
apps/web/__tests__/outlook-operations.test.ts
**/*.{test,spec}.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)
**/*.{test,spec}.{js,jsx,ts,tsx}: Don't use export or module.exports in test files.
Don't use focused tests.
Don't use disabled tests.
Make sure the assertion function, like expect, is placed inside an it() function call.
Don't nest describe() blocks too deeply in test files.
Don't use focused tests.
Don't use disabled tests.
Don't use export or module.exports in test files.
Files:
apps/web/__tests__/outlook-operations.test.ts
apps/web/__tests__/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/llm.mdc)
Place LLM-specific tests under apps/web/tests/
Files:
apps/web/__tests__/outlook-operations.test.ts
**/*.test.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/testing.mdc)
**/*.test.{ts,tsx}: Use Vitest (vitest) as the testing framework
Colocate tests next to the file under test (e.g., dir/format.ts with dir/format.test.ts)
In tests, mock theserver-onlymodule withvi.mock("server-only", () => ({}));
When testing code that uses Prisma, mock it withvi.mock("@/utils/prisma")and use the mock from@/utils/__mocks__/prisma
Use provided helpers for mocks: import{ getEmail, getEmailAccount, getRule }from@/__tests__/helpers
Each test should be independent
Use descriptive test names
Mock external dependencies in tests
Clean up mocks between tests (e.g.,vi.clearAllMocks()inbeforeEach)
Avoid testing implementation details; focus on observable behavior
Do not mock the Logger
Files:
apps/web/__tests__/outlook-operations.test.ts
**/__tests__/**
📄 CodeRabbit inference engine (.cursor/rules/testing.mdc)
Place AI tests in the
__tests__directory and exclude them from the default test run (they use a real LLM)
Files:
apps/web/__tests__/outlook-operations.test.ts
apps/web/__tests__/**/*.test.ts
📄 CodeRabbit inference engine (.cursor/rules/llm-test.mdc)
apps/web/__tests__/**/*.test.ts: Place all LLM-related tests under apps/web/tests/
Use Vitest in LLM tests and import { describe, expect, test, vi, beforeEach } from "vitest"
Mock the Next.js server runtime marker by adding vi.mock("server-only", () => ({})) in LLM tests
Gate LLM tests behind RUN_AI_TESTS using describe.runIf(process.env.RUN_AI_TESTS === "true")
Call vi.clearAllMocks() in a beforeEach for LLM tests
Set a TIMEOUT of 15_000ms for LLM-related tests and pass it to long-running tests/describe blocks
Create helper functions for common test data (e.g., getUser, getTestData) to reduce duplication
Include standard test cases: happy path, error handling, edge cases (empty/null), different user configurations, and various input formats
Use console.debug to log generated LLM content for inspection (e.g., console.debug("Generated content:\n", result.content))
Do not mock the actual LLM call in these tests; exercise real LLM integrations
Test both AI and non-AI paths, including cases where no AI processing is required
Prefer existing helpers from @/tests/helpers.ts (getEmailAccount, getEmail, getRule, getMockMessage, getMockExecutedRule) over custom helpers
Files:
apps/web/__tests__/outlook-operations.test.ts
🧬 Code graph analysis (3)
apps/web/utils/email/microsoft.ts (3)
apps/web/utils/outlook/odata-escape.ts (1)
escapeODataString(13-20)apps/web/utils/outlook/label.ts (2)
getLabelById(67-77)removeThreadLabel(234-285)apps/web/app/api/outlook/webhook/logger.ts (1)
logger(3-3)
apps/web/utils/label/resolve-label.ts (2)
apps/web/app/api/outlook/webhook/logger.ts (1)
logger(3-3)apps/web/utils/logger.ts (1)
createScopedLogger(17-80)
apps/web/__tests__/outlook-operations.test.ts (2)
apps/web/utils/email/microsoft.ts (1)
OutlookProvider(65-1230)apps/web/utils/email/provider.ts (1)
createEmailProvider(13-29)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: cubic · AI code reviewer
- GitHub Check: Analyze (javascript-typescript)
Summary by CodeRabbit