pi-ext
bugabingas pi extensions
owned by bugabinga
fix(overkill): retry atomic replace on windows
1b4e72ab87c874b851f0ac6ddf772b8b262643ad
Oliver Krylow <o.krylow@isp-insoft.de> ·
unsigned
Browse filesCompare with HEAD
Changed files (2)
extensions/overkill/__tests__/aftermath-acceptance.test.ts
Modified 843 843 expect(stdoutWrites.
length).
toBeGreaterThan(
0);
844 844 expect(stdoutWrites.
every((write)
=> write.fd
=== 1)).
toBe(
true);
845 845 const output
= stdoutWrites.
map((write)
=> write.
text).
join(
"");
846 + const directory
= await runDirectory(fixture);
846 847 expect(output).
toContain(
"Overkill mining");
847 848 expect(output).
toContain(
`Source: ${fixture.skill}`);
848 - expect(output).
toMatch(
/Report: \/.*\/report\.json/u);
849 - expect(output).
toMatch(
/Staged: \/.*\/staged-skill\.md/u);
849 + expect(output).
toContain(
`Report: ${join(directory, "report.json")}`);
850 + expect(output).
toContain(
`Staged: ${join(directory, "staged-skill.md")}`);
850 851 const diff
= output.
slice(output.
lastIndexOf(
`--- ${fixture.skill}`));
851 852 expect(diff).
toContain(
"AFTERMATH-CANDIDATE");
852 853 expect(diff.
split(
"\n").
length).
toBeLessThanOrEqual(
200);
extensions/overkill/lib/run-state.ts
Modified 232 +async function replaceFile(
234 + destination
: string,
236 + for (
let attempt
= 0; ; attempt
++) {
238 + await rename(temporary, destination);
242 + process.
platform !== "win32" || 243 + (error
as NodeJS.
ErrnoException).
code !== "EPERM" || 247 + await new Promise((resolve)
=> setTimeout(resolve,
10 * 2 ** attempt));
232 252 async function atomicWriteJson(
233 253 directory
: string,
234 254 filename
: string,
244 264 encoding:
"utf8",
247 - await rename(temporary, destination);
267 + await replaceFile(temporary, destination);
250 270 function assertFingerprint(
833 853 throw new Error(
"artifact must remain in private run directory");
834 854 const temporary
= join(
root,
`.${filename}.${randomUUID()}.tmp`);
835 855 await writeFile(temporary, content, { encoding:
"utf8", mode:
0o600 });
836 - await rename(temporary, destination);
856 + await replaceFile(temporary, destination);
837 857 return destination;