|
1 | 1 | import assert from "node:assert/strict"; |
2 | 2 | import test from "node:test"; |
3 | 3 | import { execFileSync, spawnSync } from "node:child_process"; |
4 | | -import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; |
| 4 | +import { chmodSync, existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; |
| 5 | +import { createServer } from "node:http"; |
5 | 6 | import { tmpdir } from "node:os"; |
6 | 7 | import { join } from "node:path"; |
7 | 8 | import { fileURLToPath } from "node:url"; |
@@ -243,3 +244,79 @@ test("review rejects --item-number combined with --local-range", () => { |
243 | 244 | rmSync(dir, { recursive: true, force: true }); |
244 | 245 | } |
245 | 246 | }); |
| 247 | + |
| 248 | +test("--local-range does not host-download proof video URLs from the body", async () => { |
| 249 | + const hits: string[] = []; |
| 250 | + const server = createServer((req, res) => { |
| 251 | + hits.push(req.url ?? ""); |
| 252 | + res.writeHead(404); |
| 253 | + res.end(); |
| 254 | + }); |
| 255 | + await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve)); |
| 256 | + const port = (server.address() as { port: number }).port; |
| 257 | + const dir = initRepo(); |
| 258 | + const codexDir = mkdtempSync(join(tmpdir(), "lrr-codex-")); |
| 259 | + const fakeCodex = join(codexDir, "fake-codex.sh"); |
| 260 | + const fakeCodexMarker = join(codexDir, "fake-codex-ran.txt"); |
| 261 | + writeFileSync(fakeCodex, '#!/bin/sh\nprintf "ran\\n" > "$FAKE_CODEX_MARKER"\nexit 1\n'); |
| 262 | + chmodSync(fakeCodex, 0o755); |
| 263 | + try { |
| 264 | + writeFileSync(join(dir, "a.txt"), "x\n"); |
| 265 | + git(dir, "add", "a.txt"); |
| 266 | + git(dir, "commit", "-q", "-m", "init"); |
| 267 | + git(dir, "branch", "base-ref"); |
| 268 | + writeFileSync(join(dir, "b.txt"), "y\n"); |
| 269 | + git(dir, "add", "b.txt"); |
| 270 | + // a video URL in the commit body that media-proof preprocessing would otherwise curl |
| 271 | + git( |
| 272 | + dir, |
| 273 | + "commit", |
| 274 | + "-q", |
| 275 | + "-m", |
| 276 | + `feat: thing\n\nproof video: http://127.0.0.1:${port}/proof.mp4`, |
| 277 | + ); |
| 278 | + // codex is stubbed (CODEX_BIN exits 1) so no real engine runs; media-proof would still |
| 279 | + // curl the URL BEFORE the engine if it weren't skipped for --local-range. |
| 280 | + const result = spawnSync( |
| 281 | + "node", |
| 282 | + [ |
| 283 | + CLI, |
| 284 | + "review", |
| 285 | + "--local-only", |
| 286 | + "--local-range", |
| 287 | + "--base", |
| 288 | + "base-ref", |
| 289 | + "--target-repo", |
| 290 | + "openclaw/clawsweeper", |
| 291 | + "--target-dir", |
| 292 | + dir, |
| 293 | + "--artifact-dir", |
| 294 | + join(codexDir, "artifacts"), |
| 295 | + ], |
| 296 | + { |
| 297 | + encoding: "utf8", |
| 298 | + env: { |
| 299 | + ...process.env, |
| 300 | + CLAWSWEEPER_CODEX_REVIEW_ATTEMPTS: "1", |
| 301 | + CODEX_BIN: fakeCodex, |
| 302 | + FAKE_CODEX_MARKER: fakeCodexMarker, |
| 303 | + }, |
| 304 | + timeout: 60000, |
| 305 | + }, |
| 306 | + ); |
| 307 | + assert.notEqual(result.status, 0, "fake Codex should make the review fail after setup"); |
| 308 | + assert.equal(readFileSync(fakeCodexMarker, "utf8"), "ran\n"); |
| 309 | + assert.equal( |
| 310 | + hits.length, |
| 311 | + 0, |
| 312 | + `--local-range must not host-download body video URLs (server hits: ${JSON.stringify(hits)})`, |
| 313 | + ); |
| 314 | + } finally { |
| 315 | + if (existsSync(fakeCodexMarker)) rmSync(fakeCodexMarker, { force: true }); |
| 316 | + await new Promise<void>((resolve, reject) => |
| 317 | + server.close((error) => (error ? reject(error) : resolve())), |
| 318 | + ); |
| 319 | + rmSync(codexDir, { recursive: true, force: true }); |
| 320 | + rmSync(dir, { recursive: true, force: true }); |
| 321 | + } |
| 322 | +}); |
0 commit comments