fix(test): remove immutable runtime contexts at worker exit

Restore directory write access inside the private worker home before removal, without following external directory symlinks.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-10-09 01:24:30 -05:00
1 parent 75abb6a774
commit 0effdedd07
1 file changed
+15 -1
+15 -1
View File
@@ -29,7 +29,21 @@ const paperclipTestHome = fs.mkdtempSync(path.join(os.tmpdir(), "paperclip-vites
process.env.PAPERCLIP_HOME = paperclipTestHome;
// Setup-file afterAll hooks run before suites drain asynchronous heartbeats.
// Cleanup at worker exit, after all suite teardown, avoids deleting live state.
process.once("exit", () => fs.rmSync(paperclipTestHome, { recursive: true, force: true, maxRetries: 8, retryDelay: 50 }));
function makeTestHomeDirectoriesWritable(directory: string): void {
const stat = fs.lstatSync(directory);
if (!stat.isDirectory() || stat.isSymbolicLink()) return;
fs.chmodSync(directory, 0o700);
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
if (entry.isDirectory()) makeTestHomeDirectoriesWritable(path.join(directory, entry.name));
}
}
process.once("exit", () => {
// Runtime context bundles keep their directories read-only during each test.
// At worker exit, restore deletion access only within this owned test home.
makeTestHomeDirectoriesWritable(paperclipTestHome);
fs.rmSync(paperclipTestHome, { recursive: true, force: true, maxRetries: 8, retryDelay: 50 });
});
const require = createRequire(import.meta.url);
const SupertestTest = require("supertest/lib/test.js") as SupertestTestConstructor;