fix(server): reconcile auth split with main

This commit is contained in:
RainbowBird
2026-08-12 23:33:58 +08:00
parent d5c95dca13
commit 27111382b4
2 changed files with 29 additions and 3 deletions
+3 -3
View File
@@ -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<HonoEnv>()
+26
View File
@@ -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
}