From 27111382b4a79a7e983289d6e983a06af185ed0f Mon Sep 17 00:00:00 2001 From: RainbowBird Date: Wed, 12 Aug 2026 23:31:19 +0800 Subject: [PATCH] fix(server): reconcile auth split with main --- server/apps/api/src/app.ts | 6 +++--- server/apps/auth/src/tests/mock-db.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 server/apps/auth/src/tests/mock-db.ts diff --git a/server/apps/api/src/app.ts b/server/apps/api/src/app.ts index 089d469c3..740569dcf 100644 --- a/server/apps/api/src/app.ts +++ b/server/apps/api/src/app.ts @@ -1,6 +1,6 @@ import type { Database } from './libs/db' import type { Env } from './libs/env' -import type { ApiOtelInstance } from './otel' +import type { OtelInstance } from './otel' import type { StreamingTtsVoiceType } from './routes/audio-speech-ws/session' import type { ConfigKVService } from './services/adapters/config-kv' import type { AdminFluxGrantsService } from './services/domain/admin/flux-grants' @@ -110,7 +110,7 @@ interface AppDeps { envelopeCrypto: EnvelopeCrypto redis: Redis env: Env - otel: ApiOtelInstance | null + otel: OtelInstance | null userDeletionService: UserDeletionService llmRouter: LlmRouterService providerCatalogService: ProviderCatalogService @@ -119,7 +119,7 @@ interface AppDeps { export async function buildApp(deps: AppDeps) { const logger = useLogger('app').useGlobalConfig() const userMetricsRecorder = deps.otel - ? registerUserMetricsSnapshotGauges(deps.otel.user) + ? registerUserMetricsSnapshotGauges(deps.otel.auth) : createDiscardingUserMetricsSnapshotRecorder() const app = new Hono() diff --git a/server/apps/auth/src/tests/mock-db.ts b/server/apps/auth/src/tests/mock-db.ts new file mode 100644 index 000000000..a17f95dfe --- /dev/null +++ b/server/apps/auth/src/tests/mock-db.ts @@ -0,0 +1,26 @@ +import type { pushSchema as PushSchema } from 'drizzle-kit/api' + +import { createRequire } from 'node:module' + +import { PGlite } from '@electric-sql/pglite' +import { drizzle } from 'drizzle-orm/pglite' + +import * as authSchema from '@proj-airi/auth-shared' + +/** Creates an in-memory database with the standalone Auth service schema. */ +export async function createTestDatabase() { + const client = new PGlite() + const database = drizzle(client) + + // NOTICE: + // drizzle-kit's `api` entry is CommonJS while this Vitest project is ESM. + // Loading it via createRequire preserves its public runtime boundary. + // Source/context: server/apps/api/src/libs/mock-db.ts uses the same drizzle-kit API. + // Removal condition: drizzle-kit exposes a working ESM API entry. + const require = createRequire(import.meta.url) + const { pushSchema } = require('drizzle-kit/api') as { pushSchema: typeof PushSchema } + const { apply } = await pushSchema(authSchema, database) + await apply() + + return database +}