























@@ -95,6 +95,31 @@ function runRuntimeSmoke(root: string, args: string[]) {
9595});
9696}
979798+async function importRuntimeSmokeWithEnv(env: Record<string, string | undefined>) {
99+const previous = new Map<string, string | undefined>();
100+for (const [key, value] of Object.entries(env)) {
101+previous.set(key, process.env[key]);
102+if (value === undefined) {
103+delete process.env[key];
104+} else {
105+process.env[key] = value;
106+}
107+}
108+try {
109+return await import(
110+`${pathToFileURL(runtimeSmokePath).href}?case=${Date.now()}-${Math.random()}`
111+);
112+} finally {
113+for (const [key, value] of previous.entries()) {
114+if (value === undefined) {
115+delete process.env[key];
116+} else {
117+process.env[key] = value;
118+}
119+}
120+}
121+}
122+98123async function listenOnLoopback(server: HttpServer | NetServer): Promise<number> {
99124return new Promise((resolve, reject) => {
100125const onError = (error: Error) => {
@@ -151,6 +176,17 @@ describe("bundled plugin install/uninstall probe", () => {
151176expect(second).toEqual({ text: "fghij", truncatedChars: 5 });
152177});
153178179+it("rejects loose runtime output limit env values instead of parsing prefixes", async () => {
180+const runtimeSmoke = await importRuntimeSmokeWithEnv({
181+OPENCLAW_BUNDLED_PLUGIN_RUNTIME_OUTPUT_CHARS: "5chars",
182+});
183+184+expect(runtimeSmoke.appendBoundedOutput({ text: "", truncatedChars: 0 }, "abcdef")).toEqual({
185+text: "abcdef",
186+truncatedChars: 0,
187+});
188+});
189+154190it("keeps runtime log tail reads bounded", async () => {
155191const runtimeSmoke = await import(pathToFileURL(runtimeSmokePath).href);
156192const root = makePackageRoot();
@@ -165,6 +201,21 @@ describe("bundled plugin install/uninstall probe", () => {
165201expect(fullRead).not.toHaveBeenCalled();
166202});
167203204+it("rejects loose runtime log scan byte env values instead of parsing prefixes", async () => {
205+const runtimeSmoke = await importRuntimeSmokeWithEnv({
206+OPENCLAW_BUNDLED_PLUGIN_RUNTIME_LOG_SCAN_BYTES: "64bytes",
207+});
208+const root = makePackageRoot();
209+const logPath = path.join(root, "gateway.log");
210+fs.writeFileSync(logPath, `${"old log line\n".repeat(20)}[gateway] ready\n`, "utf8");
211+212+const tail = runtimeSmoke.readFileTail(logPath);
213+214+expect(Buffer.byteLength(tail)).toBeGreaterThan(64);
215+expect(tail).toContain("old log line");
216+expect(tail).toContain("[gateway] ready");
217+});
218+168219it("remembers runtime ready logs after they fall outside the tail", async () => {
169220const runtimeSmoke = await import(pathToFileURL(runtimeSmokePath).href);
170221const root = makePackageRoot();
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。