fix(platform): replace 3 console.* calls with process.stdout/stderr in cosmos-init + server startup
This commit is contained in:
parent
f97f7a0adb
commit
a2461fc26a
@ -38,14 +38,14 @@ describe('initCosmosIfNeeded', () => {
|
||||
vi.stubEnv('NODE_ENV', 'test');
|
||||
|
||||
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');
|
||||
await initCosmosIfNeeded();
|
||||
|
||||
expect(cosmosMock.registerContainers).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 () => {
|
||||
@ -55,13 +55,13 @@ describe('initCosmosIfNeeded', () => {
|
||||
vi.stubEnv('NODE_ENV', 'test');
|
||||
|
||||
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');
|
||||
await initCosmosIfNeeded();
|
||||
|
||||
expect(cosmosMock.registerContainers).toHaveBeenCalledOnce();
|
||||
expect(cosmosMock.initializeAllContainers).toHaveBeenCalledOnce();
|
||||
expect(warnSpy).toHaveBeenCalledWith('[platform-service] Cosmos init failed: boom');
|
||||
expect(writeSpy).toHaveBeenCalledWith('[platform-service] Cosmos init failed: boom\n');
|
||||
});
|
||||
});
|
||||
|
||||
@ -113,11 +113,9 @@ export async function initCosmosIfNeeded(): Promise<void> {
|
||||
|
||||
try {
|
||||
await initializeAllContainers();
|
||||
// eslint-disable-next-line no-console
|
||||
console.info('[platform-service] Cosmos containers ensured');
|
||||
process.stdout.write('[platform-service] Cosmos containers ensured\n');
|
||||
} catch (err) {
|
||||
const msg = err instanceof Error ? err.message : String(err);
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(`[platform-service] Cosmos init failed: ${msg}`);
|
||||
process.stderr.write(`[platform-service] Cosmos init failed: ${msg}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,7 +90,9 @@ await initCosmosIfNeeded();
|
||||
await loadProductCache();
|
||||
|
||||
// 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({
|
||||
name: 'platform-service',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user