fix(server): use in-process pino-pretty stream to avoid worker transport startup failure

- switch createServerLogger from pino transport target to in-process pretty stream\n- update changeset to cover @moonshot-ai/server\n- add test asserting pretty logger does not use ThreadStream\n- rename cli server test description
This commit is contained in:
haozhe.yang 2026-06-11 19:04:51 +08:00
parent 59b5e69308
commit 37d415d081
4 changed files with 27 additions and 13 deletions

View file

@ -1,5 +1,6 @@
---
"@moonshot-ai/kimi-code": patch
"@moonshot-ai/server": patch
---
Fix server startup from npm-installed CLI packages when pretty logging is enabled.

View file

@ -23,7 +23,7 @@ function makeProgram(): Command {
}
describe('kimi server', () => {
it('declares the pino pretty transport as a CLI runtime dependency', () => {
it('declares pino-pretty as a CLI runtime dependency', () => {
const packageJson = JSON.parse(
readFileSync(new URL('../../../package.json', import.meta.url), 'utf-8'),
) as { dependencies?: Record<string, string> };

View file

@ -1,6 +1,7 @@
import { Disposable } from '@moonshot-ai/agent-core';
import { ILogService } from '@moonshot-ai/services';
import { pino, type Logger, type LoggerOptions } from 'pino';
import prettyStream from 'pino-pretty';
export type ServerLogger = Logger;
@ -19,18 +20,16 @@ export function createServerLogger(opts: CreateLoggerOptions): ServerLogger {
timestamp: pino.stdTimeFunctions.isoTime,
};
if (pretty) {
return pino({
...base,
transport: {
target: 'pino-pretty',
options: {
colorize: true,
translateTime: 'SYS:HH:MM:ss.l o',
ignore: 'pid,hostname',
singleLine: false,
},
},
});
return pino(
base,
prettyStream({
colorize: true,
translateTime: 'SYS:HH:MM:ss.l o',
ignore: 'pid,hostname',
singleLine: false,
destination: process.stdout,
}),
);
}
return pino(base);
}

View file

@ -38,6 +38,7 @@ import {
ISessionClientsService,
IWSBroadcastService,
IWSGateway,
createServerLogger,
startServer,
type LockContents,
type RunningServer,
@ -112,6 +113,19 @@ describe('startServer — lock + healthz smoke', () => {
});
});
describe('createServerLogger', () => {
it('uses an in-process pretty stream instead of pino worker transport', () => {
const logger = createServerLogger({ level: 'info', pretty: true });
const streamSym = (pino as unknown as { symbols: { streamSym: symbol } }).symbols.streamSym;
const stream = logger[streamSym as keyof typeof logger] as unknown as NodeJS.WritableStream & {
constructor?: { name?: string };
};
expect(stream.constructor?.name).not.toBe('ThreadStream');
stream.end();
});
});
describe('startServer — web assets', () => {
it('serves web assets from the server root without shadowing API routes', async () => {
const assetsDir = join(tmpDir, 'web-assets');