






















@@ -1,10 +1,11 @@
11import { spawnSync } from "node:child_process";
2-import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
2+import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
33import { tmpdir } from "node:os";
44import path from "node:path";
55import { describe, expect, it } from "vitest";
6677const ASSERTIONS_SCRIPT = "scripts/e2e/lib/kitchen-sink-plugin/assertions.mjs";
8+const SWEEP_SCRIPT = "scripts/e2e/lib/kitchen-sink-plugin/sweep.sh";
89const REQUIRED_FULL_DIAGNOSTIC_CANARIES = [
910"only bundled plugins can register trusted tool policies",
1011"plugin must declare contracts.tools for: kitchen-sink-tool",
@@ -114,6 +115,17 @@ function runAssertInstalled({
114115}
115116}
116117118+function runScanLogs({ home, scratchRoot }: { home: string; scratchRoot: string }) {
119+return spawnSync(process.execPath, [ASSERTIONS_SCRIPT, "scan-logs"], {
120+encoding: "utf8",
121+env: {
122+ ...process.env,
123+HOME: home,
124+KITCHEN_SINK_TMP_DIR: scratchRoot,
125+},
126+});
127+}
128+117129describe("kitchen-sink plugin assertions", () => {
118130it("fails full-surface installs when stable diagnostic canaries disappear", () => {
119131const result = runAssertInstalled();
@@ -143,4 +155,74 @@ describe("kitchen-sink plugin assertions", () => {
143155"cli registration missing explicit commands metadata",
144156);
145157});
158+159+it("scans only the configured kitchen-sink scratch root", () => {
160+const parent = mkdtempSync(path.join(tmpdir(), "openclaw-kitchen-sink-scan-"));
161+const home = path.join(parent, "home");
162+const scratchRoot = path.join(parent, "scratch");
163+const siblingRoot = path.join(parent, "sibling");
164+try {
165+mkdirSync(home, { recursive: true });
166+mkdirSync(scratchRoot, { recursive: true });
167+mkdirSync(siblingRoot, { recursive: true });
168+writeFileSync(path.join(scratchRoot, "large.log"), `${"x".repeat(70 * 1024)}\n0 errors\n`);
169+writeFileSync(path.join(siblingRoot, "stale.log"), "[ERROR] stale sibling failure\n");
170+171+const result = runScanLogs({ home, scratchRoot });
172+173+expect(result.status).toBe(0);
174+expect(result.stdout).toContain("log scan passed");
175+expect(`${result.stdout}\n${result.stderr}`).not.toContain("stale sibling failure");
176+} finally {
177+rmSync(parent, { force: true, recursive: true });
178+}
179+});
180+181+it("bounds repeated kitchen-sink log scan findings", () => {
182+const parent = mkdtempSync(path.join(tmpdir(), "openclaw-kitchen-sink-scan-"));
183+const home = path.join(parent, "home");
184+const scratchRoot = path.join(parent, "scratch");
185+try {
186+mkdirSync(home, { recursive: true });
187+mkdirSync(scratchRoot, { recursive: true });
188+writeFileSync(
189+path.join(scratchRoot, "errors.log"),
190+Array.from({ length: 105 }, (_, index) => `[ERROR] failure ${index}`).join("\n"),
191+);
192+193+const result = runScanLogs({ home, scratchRoot });
194+195+expect(result.status).not.toBe(0);
196+expect(`${result.stdout}\n${result.stderr}`).toContain("additional findings omitted");
197+expect(`${result.stdout}\n${result.stderr}`).not.toContain("[ERROR] failure 104");
198+} finally {
199+rmSync(parent, { force: true, recursive: true });
200+}
201+});
202+203+it("rejects kitchen-sink log scans without an isolated scratch root", () => {
204+const parent = mkdtempSync(path.join(tmpdir(), "openclaw-kitchen-sink-scan-"));
205+try {
206+const spawnEnv = { ...process.env, HOME: parent };
207+delete spawnEnv.KITCHEN_SINK_TMP_DIR;
208+const result = spawnSync(process.execPath, [ASSERTIONS_SCRIPT, "scan-logs"], {
209+encoding: "utf8",
210+env: spawnEnv,
211+});
212+213+expect(result.status).not.toBe(0);
214+expect(`${result.stdout}\n${result.stderr}`).toContain("KITCHEN_SINK_TMP_DIR is required");
215+} finally {
216+rmSync(parent, { force: true, recursive: true });
217+}
218+});
219+220+it("allocates an isolated scratch root by default", () => {
221+const sweep = readFileSync(SWEEP_SCRIPT, "utf8");
222+223+expect(sweep).toContain('mktemp -d "/tmp/openclaw-kitchen-sink.XXXXXX"');
224+expect(sweep).toContain('mktemp -d "${KITCHEN_SINK_TMP_DIR}/clawhub.XXXXXX"');
225+expect(sweep).not.toContain('KITCHEN_SINK_TMP_DIR="${KITCHEN_SINK_TMP_DIR:-/tmp}"');
226+expect(sweep).not.toContain('mktemp -d "/tmp/openclaw-kitchen-sink-clawhub.XXXXXX"');
227+});
146228});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。