fix: refuse to git fetch while the Docker case list cannot be read (release review)

readDockerCases() reads an unreadable or half-written docker-cases.json as [], so a fetch (which runs
repository hooks, and runs unattended on the interval) could run inside a Docker workspace. The fetch
paths now read it through a strict reader: the Fetch button answers a failed run (state 'error') and the
scheduler skips the tick, undoes its picks and logs once. The status and diff routes are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Codeman maintainer committed 2026-10-27 02:58:37 +01:00
1 parent b89f15c12f
commit 1752d7ee2c
8 files changed
+221 -18

No files matched your search

+26
View File
@@ -130,6 +130,32 @@ export async function readDockerCases(configDir: string): Promise<DockerCase[]>
return readJsonArray<DockerCase>(dockerCasesPath(configDir));
}
/**
* The Docker cases for a caller that must fail CLOSED (the git fetch paths): a missing file is no cases,
* but a file that cannot be read, does not parse or is not an array rejects, where {@link readDockerCases}
* reads all of those as `[]`. The writer truncates and rewrites the file in place, so a read can land on an
* empty or half-written file, and to a caller deciding where git may run that must never look like "no
* Docker workspaces". The parser's own message is not repeated (V8 quotes the text around the fault).
*/
export async function readDockerCasesOrThrow(configDir: string): Promise<DockerCase[]> {
const path = dockerCasesPath(configDir);
let raw: string;
try {
raw = await fs.readFile(path, 'utf-8');
} catch (err) {
if ((err as NodeJS.ErrnoException).code === 'ENOENT') return [];
throw err;
}
let parsed: unknown;
try {
parsed = JSON.parse(raw);
} catch {
parsed = undefined;
}
if (!Array.isArray(parsed)) throw new Error(`${path} is not a valid JSON array`);
return parsed as DockerCase[];
}
export async function writeDockerCases(configDir: string, cases: DockerCase[]): Promise<void> {
await writeJsonArray(configDir, dockerCasesPath(configDir), cases);
}