Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions test/ai-conversation-lifecycle.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const Module = require('node:module');
const realExpress = require('express');
const originalLoad = Module._load;
const originalWrite = http.ServerResponse.prototype.write;
const originalConsoleLog = console.log;
const root = process.cwd();
const serverPath = path.resolve(root, 'server.js');
const serverModulesDir = path.resolve(root, 'src/server') + path.sep;
Expand Down Expand Up @@ -49,6 +50,17 @@ function spyOnResponseWrites() {
};
}

// Node 22 的 node:test 父进程读完一帧之后不再找帧头,直接把紧跟的 4 个字节当下一帧长度
// (nodejs/node#64061;修复 #64706 只进了 v24+,v22.x 未回移,见 #65934)。server.js 的
// 启动日志以 emoji 开头,恰好落在一帧后面时会被算成负长度,整个测试文件当场崩溃。
// 只给这一行补 ASCII 前缀,日志内容和其余输出原样保留;afterEach 负责还原。
function prefixStartupLog() {
console.log = (first, ...rest) => {
const line = typeof first === 'string' && first.startsWith('🍳 Kitchen Manager') ? `[server] ${first}` : first;
return originalConsoleLog.call(console, line, ...rest);
};
}

// 真 express,只在 listen 上挂一个钩子拿到 http.Server(server.js 不导出它),
// 端口用 0 由内核分配。
async function startRealServer({ streams = [], env = {} } = {}) {
Expand Down Expand Up @@ -99,6 +111,8 @@ async function startRealServer({ streams = [], env = {} } = {}) {
...env
};
spyOnResponseWrites();
// 启动日志在 listen 回调里打印,比 require 返回更晚,所以要在 require 之前装上。
prefixStartupLog();
clearServerRequireCache();
require(serverPath);

Expand All @@ -117,6 +131,7 @@ afterEach(async () => {
while (pendingGates.length) pendingGates.pop()();
await new Promise((r) => setTimeout(r, 10));
http.ServerResponse.prototype.write = originalWrite;
console.log = originalConsoleLog;
if (runningServer) {
runningServer.closeAllConnections?.();
await new Promise((resolveClose) => runningServer.close(resolveClose));
Expand Down
Loading