惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

腾讯CDC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - Franky
博客园_首页
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
IT之家
IT之家
The Cloudflare Blog
V
Visual Studio Blog
罗磊的独立博客
T
Tailwind CSS Blog
S
SegmentFault 最新的问题
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
阮一峰的网络日志
阮一峰的网络日志
D
Docker
Last Week in AI
Last Week in AI
B
Blog RSS Feed
C
Check Point Blog
J
Java Code Geeks
The GitHub Blog
The GitHub Blog
有赞技术团队
有赞技术团队
博客园 - 聂微东
MongoDB | Blog
MongoDB | Blog
雷峰网
雷峰网

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(e2e): bound bundled runtime log scans · openclaw/open...
vincentkoc · 2026-05-27 · via Recent Commits to openclaw:main

@@ -11,6 +11,10 @@ const OUTPUT_CAPTURE_CHARS = readPositiveInt(

1111

process.env.OPENCLAW_BUNDLED_PLUGIN_RUNTIME_OUTPUT_CHARS,

1212

1024 * 1024,

1313

);

14+

const LOG_SCAN_BYTES = readPositiveInt(

15+

process.env.OPENCLAW_BUNDLED_PLUGIN_RUNTIME_LOG_SCAN_BYTES,

16+

256 * 1024,

17+

);

1418

const WATCHDOG_MS = readPositiveInt(process.env.OPENCLAW_BUNDLED_PLUGIN_RUNTIME_WATCHDOG_MS, 1000);

1519

const READY_TIMEOUT_MS = readPositiveInt(

1620

process.env.OPENCLAW_BUNDLED_PLUGIN_RUNTIME_READY_MS,

@@ -29,6 +33,13 @@ const HTTP_PROBE_TIMEOUT_MS = readPositiveInt(

2933

process.env.OPENCLAW_BUNDLED_PLUGIN_RUNTIME_HTTP_MS,

3034

5000,

3135

);

36+

const GATEWAY_READY_LOG_NEEDLE = Buffer.from("[gateway] ready");

37+

const READY_OFFSET_LOG_NEEDLES = [

38+

GATEWAY_READY_LOG_NEEDLE,

39+

Buffer.from("listening on ws://"),

40+

Buffer.from("[gateway] http server listening"),

41+

];

42+

const FORBIDDEN_POST_READY_DEPS_WORK = [/\b(?:npm|pnpm|yarn|corepack) install\b/iu];

32433344

function readPositiveInt(raw, fallback) {

3445

const parsed = Number.parseInt(String(raw || ""), 10);

@@ -44,6 +55,132 @@ function writeJson(file, value) {

4455

fs.writeFileSync(file, `${JSON.stringify(value, null, 2)}\n`);

4556

}

465758+

function readFileChunk(file, startOffset, maxBytes) {

59+

let stat;

60+

try {

61+

stat = fs.statSync(file);

62+

} catch {

63+

return { buffer: Buffer.alloc(0), startOffset: 0, size: 0 };

64+

}

65+

if (!stat.isFile() || stat.size <= 0) {

66+

return { buffer: Buffer.alloc(0), startOffset: 0, size: stat.size };

67+

}

68+69+

const safeMaxBytes = Math.max(1, Math.floor(Number(maxBytes) || LOG_SCAN_BYTES));

70+

const safeStartOffset = Math.min(Math.max(0, Math.floor(Number(startOffset) || 0)), stat.size);

71+

const bytesToRead = Math.min(safeMaxBytes, stat.size - safeStartOffset);

72+

if (bytesToRead <= 0) {

73+

return { buffer: Buffer.alloc(0), startOffset: safeStartOffset, size: stat.size };

74+

}

75+76+

const buffer = Buffer.alloc(bytesToRead);

77+

const fd = fs.openSync(file, "r");

78+

try {

79+

const bytesRead = fs.readSync(fd, buffer, 0, bytesToRead, safeStartOffset);

80+

return { buffer: buffer.subarray(0, bytesRead), startOffset: safeStartOffset, size: stat.size };

81+

} finally {

82+

fs.closeSync(fd);

83+

}

84+

}

85+86+

function readFileTailBuffer(file, maxBytes = LOG_SCAN_BYTES) {

87+

let stat;

88+

try {

89+

stat = fs.statSync(file);

90+

} catch {

91+

return { buffer: Buffer.alloc(0), startOffset: 0, size: 0 };

92+

}

93+

const safeMaxBytes = Math.max(1, Math.floor(Number(maxBytes) || LOG_SCAN_BYTES));

94+

const startOffset = Math.max(0, stat.size - safeMaxBytes);

95+

return readFileChunk(file, startOffset, safeMaxBytes);

96+

}

97+98+

export function readFileTail(file, maxBytes = LOG_SCAN_BYTES) {

99+

return readFileTailBuffer(file, maxBytes).buffer.toString("utf8");

100+

}

101+102+

function findFirstNeedleOffset(file, needles) {

103+

let stat;

104+

try {

105+

stat = fs.statSync(file);

106+

} catch {

107+

return 0;

108+

}

109+

if (!stat.isFile() || stat.size <= 0) {

110+

return 0;

111+

}

112+113+

const carryBytes = Math.max(0, ...needles.map((needle) => needle.length - 1));

114+

const chunk = Buffer.alloc(Math.min(LOG_SCAN_BYTES, stat.size));

115+

const fd = fs.openSync(file, "r");

116+

let carry = Buffer.alloc(0);

117+

let offset = 0;

118+

try {

119+

while (offset < stat.size) {

120+

const bytesToRead = Math.min(chunk.length, stat.size - offset);

121+

const bytesRead = fs.readSync(fd, chunk, 0, bytesToRead, offset);

122+

if (bytesRead <= 0) {

123+

break;

124+

}

125+

const view = chunk.subarray(0, bytesRead);

126+

const combined = carry.length > 0 ? Buffer.concat([carry, view]) : view;

127+

const combinedOffset = offset - carry.length;

128+

const indexes = needles

129+

.map((needle) => combined.indexOf(needle))

130+

.filter((index) => index >= 0);

131+

if (indexes.length > 0) {

132+

return combinedOffset + Math.min(...indexes);

133+

}

134+

carry = combined.subarray(Math.max(0, combined.length - carryBytes));

135+

offset += bytesRead;

136+

}

137+

} finally {

138+

fs.closeSync(fd);

139+

}

140+

return 0;

141+

}

142+143+

export function createReadyLogScanner(file) {

144+

const carryBytes = GATEWAY_READY_LOG_NEEDLE.length - 1;

145+

let carry = Buffer.alloc(0);

146+

let offset = 0;

147+

let seen = false;

148+149+

return () => {

150+

if (seen) {

151+

return true;

152+

}

153+

let stat;

154+

try {

155+

stat = fs.statSync(file);

156+

} catch {

157+

return false;

158+

}

159+

if (!stat.isFile() || stat.size <= 0) {

160+

return false;

161+

}

162+

if (stat.size < offset) {

163+

carry = Buffer.alloc(0);

164+

offset = 0;

165+

}

166+

while (offset < stat.size) {

167+

const { buffer } = readFileChunk(file, offset, LOG_SCAN_BYTES);

168+

if (buffer.length === 0) {

169+

break;

170+

}

171+

const combined = carry.length > 0 ? Buffer.concat([carry, buffer]) : buffer;

172+

const matched = combined.includes(GATEWAY_READY_LOG_NEEDLE);

173+

if (matched) {

174+

seen = true;

175+

return true;

176+

}

177+

carry = combined.subarray(Math.max(0, combined.length - carryBytes));

178+

offset += buffer.length;

179+

}

180+

return false;

181+

};

182+

}

183+47184

function manifestPath(pluginDir, pluginRoot) {

48185

const candidates = [

49186

...(isNonEmptyString(pluginRoot) ? [path.join(pluginRoot, "openclaw.plugin.json")] : []),

@@ -278,6 +415,7 @@ async function stopGateway(child) {

278415

async function waitForReady(params) {

279416

const started = Date.now();

280417

let lastError = "";

418+

const readyLogSeen = createReadyLogScanner(params.logPath);

281419

while (Date.now() - started < READY_TIMEOUT_MS) {

282420

if (params.child.exitCode !== null) {

283421

throw new Error(`gateway exited before ready\n${tailFile(params.logPath)}`);

@@ -291,19 +429,14 @@ async function waitForReady(params) {

291429

} catch (error) {

292430

lastError = error instanceof Error ? error.message : String(error);

293431

}

294-

if (logShowsGatewayReady(params.logPath) && (await httpOk(params.port, "/healthz"))) {

432+

if (readyLogSeen() && (await httpOk(params.port, "/healthz"))) {

295433

return;

296434

}

297435

await delay(250);

298436

}

299437

throw new Error(`gateway did not become ready: ${lastError}\n${tailFile(params.logPath)}`);

300438

}

301439302-

function logShowsGatewayReady(logPath) {

303-

const log = fs.existsSync(logPath) ? fs.readFileSync(logPath, "utf8") : "";

304-

return log.includes("[gateway] ready");

305-

}

306-307440

async function fetchHttpProbeStatus(port, pathName, options = {}) {

308441

const { timeoutMs = HTTP_PROBE_TIMEOUT_MS } = options;

309442

const controller = new AbortController();

@@ -638,32 +771,47 @@ function assertSpeechProviderVisible(payload, provider, label) {

638771

}

639772640773

async function runWatchdog(options) {

641-

const readyIndex = findReadyLogIndex(options.logPath);

774+

const readyOffset = findReadyLogOffset(options.logPath);

642775

await delay(WATCHDOG_MS);

643776

if (options.child.exitCode !== null) {

644777

throw new Error(

645778

`gateway exited after ready for ${options.pluginId}\n${tailFile(options.logPath)}`,

646779

);

647780

}

648781

await retryRpcCall("health", {}, options);

649-

assertNoPostReadyRuntimeDepsWork(options.logPath, readyIndex);

782+

assertNoPostReadyRuntimeDepsWork(options.logPath, readyOffset);

650783

await assertNoPackageManagerChildren(options.child.pid);

651784

}

652785653-

function findReadyLogIndex(logPath) {

654-

const log = fs.existsSync(logPath) ? fs.readFileSync(logPath, "utf8") : "";

655-

const candidates = ["[gateway] ready", "listening on ws://", "[gateway] http server listening"];

656-

const indexes = candidates.map((needle) => log.indexOf(needle)).filter((index) => index >= 0);

657-

return indexes.length > 0 ? Math.min(...indexes) : 0;

786+

export function findReadyLogOffset(logPath) {

787+

return findFirstNeedleOffset(logPath, READY_OFFSET_LOG_NEEDLES);

658788

}

659789660-

function assertNoPostReadyRuntimeDepsWork(logPath, readyIndex) {

661-

const log = fs.existsSync(logPath) ? fs.readFileSync(logPath, "utf8") : "";

662-

const postReady = log.slice(Math.max(0, readyIndex));

663-

const forbidden = [/\b(?:npm|pnpm|yarn|corepack) install\b/iu];

664-

const match = forbidden.find((pattern) => pattern.test(postReady));

665-

if (match) {

666-

throw new Error(`post-ready runtime dependency work matched ${match}: ${tailText(postReady)}`);

790+

export function assertNoPostReadyRuntimeDepsWork(logPath, readyOffset) {

791+

let stat;

792+

try {

793+

stat = fs.statSync(logPath);

794+

} catch {

795+

return;

796+

}

797+

if (!stat.isFile() || stat.size <= 0) {

798+

return;

799+

}

800+801+

let offset = Math.min(Math.max(0, Math.floor(Number(readyOffset) || 0)), stat.size);

802+

let carry = "";

803+

while (offset < stat.size) {

804+

const { buffer } = readFileChunk(logPath, offset, LOG_SCAN_BYTES);

805+

if (buffer.length === 0) {

806+

break;

807+

}

808+

const text = carry + buffer.toString("utf8");

809+

const match = FORBIDDEN_POST_READY_DEPS_WORK.find((pattern) => pattern.test(text));

810+

if (match) {

811+

throw new Error(`post-ready runtime dependency work matched ${match}: ${tailText(text)}`);

812+

}

813+

carry = text.slice(-256);

814+

offset += buffer.length;

667815

}

668816

}

669817

@@ -831,10 +979,7 @@ export function createIsolatedStateEnv(label) {

831979

}

832980833981

function tailFile(file) {

834-

if (!fs.existsSync(file)) {

835-

return "";

836-

}

837-

return tailText(fs.readFileSync(file, "utf8"));

982+

return tailText(readFileTail(file));

838983

}

839984840985

function tailText(text) {