From d0fa8efa55f74af61bd9d0658f950445f0f4884c Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 13 Nov 2026 17:12:47 -0800 Subject: [PATCH 1/2] chore(quest): claim quest/m0/review-test-partial-log.md Quest-Claim: 814f15be3c30eb1d From 9374666c7dc603ca25c22295a3184091eda16468 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 13 Nov 2026 17:16:57 -0800 Subject: [PATCH 2/2] test(review): log each fake call atomically so an aborted fake leaves no cut-off line Co-Authored-By: Claude Sonnet 5.5 --- quest/m0/review-test-partial-log.md | 22 ---------------- test/review.test.ts | 39 ++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 34 deletions(-) delete mode 100644 quest/m0/review-test-partial-log.md diff --git a/quest/m0/review-test-partial-log.md b/quest/m0/review-test-partial-log.md deleted file mode 100644 index 97fdb158..00000000 --- a/quest/m0/review-test-partial-log.md +++ /dev/null @@ -1,22 +0,0 @@ -# [XS] Fix the flaky rejected-login review test at its root - -## Goal - -`test/review.test.ts`'s "a login the API rejects fails as logged out, -whatever the status check said" passes reliably, including its -`(host CLAUDECODE, rejected in turn)` case, with the root cause fixed -rather than its assertions loosened. - -## Plan - -[#706](https://github.com/moq-dev/quest/pull/706) loosened the test's -status-check count assertion, yet it failed once more in -[#716](https://github.com/moq-dev/quest/pull/716)'s validation on a cut-off -line in the fake CLI's log, apparently a fake killed mid-append. Reproduce -the failure first, such as by running the case in a loop under load, then -fix the root: for example, make the fake write each log line atomically, -or have the test wait for the fake to exit before reading its log. -Restore any assertion #706 loosened if the root fix makes it hold again. - -The fixing PR names #706 under `## Caused by` in its body, once the -implementer confirms #706's fix missed the root cause. diff --git a/test/review.test.ts b/test/review.test.ts index 1fc622f3..5fb3bb84 100644 --- a/test/review.test.ts +++ b/test/review.test.ts @@ -1,5 +1,5 @@ import { execFileSync } from "node:child_process"; -import { chmodSync, existsSync, mkdirSync, readFileSync, symlinkSync, writeFileSync } from "node:fs"; +import { chmodSync, existsSync, mkdirSync, readFileSync, readdirSync, symlinkSync, writeFileSync } from "node:fs"; import { basename, dirname, join } from "node:path"; import { afterEach, expect, test, vi } from "vitest"; @@ -72,6 +72,21 @@ try { /** The classifier's reply: FAKE_RISK, or medium. */ const RISK_REPLY = `JSON.stringify(process.env.FAKE_RISK ? JSON.parse(process.env.FAKE_RISK) : { tier: "medium", reason: "It changes what the library returns." })`; +/** + * Records one call as its own file in FAKE_LOG, a directory, renamed into place + * once whole, named by its microsecond start so the files sort in call order. A + * fake the review aborts can die mid-write, and a partial line in one shared + * log would break the reader. + */ +const LOG = ` +const logged = (call) => { + const name = Math.round((performance.timeOrigin + performance.now()) * 1000).toString() + "-" + process.pid; + const file = require("node:path").join(process.env.FAKE_LOG, name); + fs.writeFileSync(file + ".tmp", JSON.stringify(call)); + fs.renameSync(file + ".tmp", file + ".json"); +}; +`; + /** * Fake reviewer CLIs. Each logs its argv, stdin, and the variables it was * given, then answers as the FAKE_* variables say. FAKE_LOGGED_OUT removes the @@ -87,11 +102,11 @@ const RISK_REPLY = `JSON.stringify(process.env.FAKE_RISK ? JSON.parse(process.en */ const FAKES: Record = { claude: ` -const fs = require("node:fs"); +const fs = require("node:fs");${LOG} const argv = process.argv.slice(2); const stdin = fs.readFileSync(0, "utf8"); const env = Object.fromEntries(Object.entries(process.env).filter(([k]) => /^(CLAUDE|CODEX|ANTHROPIC|FAKE_HOST|PATH$)/.test(k))); -fs.appendFileSync(process.env.FAKE_LOG, JSON.stringify({ argv, stdin, env, cwd: process.cwd() }) + "\\n"); +logged({ argv, stdin, env, cwd: process.cwd() }); const credential = ["ANTHROPIC_API_KEY", "ANTHROPIC_AUTH_TOKEN", "CLAUDE_CODE_OAUTH_TOKEN"].some((k) => process.env[k]); const provider = Object.entries(process.env).some(([k, v]) => k.startsWith("CLAUDE_CODE_USE_") && v === "1"); const loggedIn = !process.env.FAKE_LOGGED_OUT || credential || provider; @@ -159,11 +174,11 @@ if (argv.includes("--session-id") && argv.includes("--json-schema")) { } `, codex: ` -const fs = require("node:fs"); +const fs = require("node:fs");${LOG} const argv = process.argv.slice(2); const stdin = fs.readFileSync(0, "utf8"); const env = Object.fromEntries(Object.entries(process.env).filter(([k]) => /^(CLAUDE|CODEX|ANTHROPIC|FAKE_HOST|PATH$)/.test(k))); -fs.appendFileSync(process.env.FAKE_LOG, JSON.stringify({ argv, stdin, env, cwd: process.cwd() }) + "\\n"); +logged({ argv, stdin, env, cwd: process.cwd() }); if (argv[0] === "login") process.exit(process.env.FAKE_LOGGED_OUT && !process.env.CODEX_ACCESS_TOKEN ? 1 : 0); if (process.env.FAKE_HANG) { // It takes a while to exit when asked to, as a CLI saving its session does. @@ -300,7 +315,8 @@ function setup(host: "CLAUDECODE" | "CODEX_THREAD_ID" | null = "CLAUDECODE"): Se write(repo, "src/lib.ts", "export const x = 2;\n"); git(repo, "commit", "-qam", "change"); - const log = join(dir, "calls.log"); + const log = join(dir, "calls"); + mkdirSync(log); vi.stubEnv("PATH", `${bin}:${process.env.PATH}`); vi.stubEnv("FAKE_LOG", log); // The session's own profile would change the logged-out errors. @@ -326,13 +342,12 @@ function setup(host: "CLAUDECODE" | "CODEX_THREAD_ID" | null = "CLAUDECODE"): Se } if (host === "CLAUDECODE") vi.stubEnv("CLAUDECODE", "1"); if (host === "CODEX_THREAD_ID") vi.stubEnv("CODEX_THREAD_ID", "parent"); + // Only whole calls: a fake's unfinished write stays a .tmp file. const read = (path: string) => - existsSync(path) - ? readFileSync(path, "utf8") - .trim() - .split("\n") - .map((line) => JSON.parse(line)) - : []; + readdirSync(path) + .filter((name) => name.endsWith(".json")) + .sort() + .map((name) => JSON.parse(readFileSync(join(path, name), "utf8"))); return { repo, bin, calls: () => read(log) }; }