fix(platform): replace 3 console.* calls with process.stdout/stderr in cosmos-init + server startup

This commit is contained in:
saravanakumardb1 2026-03-01 17:41:02 -08:00
parent f97f7a0adb
commit a2461fc26a
3 changed files with 9 additions and 9 deletions

View File

@ -38,14 +38,14 @@ describe('initCosmosIfNeeded', () => {
vi.stubEnv('NODE_ENV', 'test'); vi.stubEnv('NODE_ENV', 'test');
cosmosMock.initializeAllContainers.mockResolvedValue(undefined); cosmosMock.initializeAllContainers.mockResolvedValue(undefined);
const infoSpy = vi.spyOn(console, 'info').mockImplementation(() => {}); const writeSpy = vi.spyOn(process.stdout, 'write').mockImplementation(() => true);
const { initCosmosIfNeeded } = await import('./cosmos-init.js'); const { initCosmosIfNeeded } = await import('./cosmos-init.js');
await initCosmosIfNeeded(); await initCosmosIfNeeded();
expect(cosmosMock.registerContainers).toHaveBeenCalledOnce(); expect(cosmosMock.registerContainers).toHaveBeenCalledOnce();
expect(cosmosMock.initializeAllContainers).toHaveBeenCalledOnce(); expect(cosmosMock.initializeAllContainers).toHaveBeenCalledOnce();
expect(infoSpy).toHaveBeenCalledWith('[platform-service] Cosmos containers ensured'); expect(writeSpy).toHaveBeenCalledWith('[platform-service] Cosmos containers ensured\n');
}); });
it('logs warning when initialization fails', async () => { it('logs warning when initialization fails', async () => {
@ -55,13 +55,13 @@ describe('initCosmosIfNeeded', () => {
vi.stubEnv('NODE_ENV', 'test'); vi.stubEnv('NODE_ENV', 'test');
cosmosMock.initializeAllContainers.mockRejectedValue(new Error('boom')); cosmosMock.initializeAllContainers.mockRejectedValue(new Error('boom'));
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); const writeSpy = vi.spyOn(process.stderr, 'write').mockImplementation(() => true);
const { initCosmosIfNeeded } = await import('./cosmos-init.js'); const { initCosmosIfNeeded } = await import('./cosmos-init.js');
await initCosmosIfNeeded(); await initCosmosIfNeeded();
expect(cosmosMock.registerContainers).toHaveBeenCalledOnce(); expect(cosmosMock.registerContainers).toHaveBeenCalledOnce();
expect(cosmosMock.initializeAllContainers).toHaveBeenCalledOnce(); expect(cosmosMock.initializeAllContainers).toHaveBeenCalledOnce();
expect(warnSpy).toHaveBeenCalledWith('[platform-service] Cosmos init failed: boom'); expect(writeSpy).toHaveBeenCalledWith('[platform-service] Cosmos init failed: boom\n');
}); });
}); });

View File

@ -113,11 +113,9 @@ export async function initCosmosIfNeeded(): Promise<void> {
try { try {
await initializeAllContainers(); await initializeAllContainers();
// eslint-disable-next-line no-console process.stdout.write('[platform-service] Cosmos containers ensured\n');
console.info('[platform-service] Cosmos containers ensured');
} catch (err) { } catch (err) {
const msg = err instanceof Error ? err.message : String(err); const msg = err instanceof Error ? err.message : String(err);
// eslint-disable-next-line no-console process.stderr.write(`[platform-service] Cosmos init failed: ${msg}\n`);
console.warn(`[platform-service] Cosmos init failed: ${msg}`);
} }
} }

View File

@ -90,7 +90,9 @@ await initCosmosIfNeeded();
await loadProductCache(); await loadProductCache();
// Seed default feature flags (idempotent, best-effort) // Seed default feature flags (idempotent, best-effort)
seedDefaultFlags({ info: (msg: string) => console.log(`[flags-seed] ${msg}`) }).catch(() => {}); seedDefaultFlags({ info: (msg: string) => process.stdout.write(`[flags-seed] ${msg}\n`) }).catch(
() => {}
);
const app = await createServiceApp({ const app = await createServiceApp({
name: 'platform-service', name: 'platform-service',