Files
PaperClipAI/tests/runner-e2e/directory-cleanup.ts
T
DottaandPaperclip 8679fa7646 test(evals): remove immutable caches during controller retirement
Share the launcher cleanup traversal with rolling replacement. Make stopped controller directories removable without following dependency symlinks, then delete the entire predecessor home. Cover immutable bundles and external symlink protection with real filesystem tests.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-11-01 06:43:42 -06:00

14 lines
773 B
TypeScript

import { chmod, lstat, readdir } from "node:fs/promises";
import path from "node:path";
/** Cleanup of a stopped, test-owned tree. Never follow links to dependencies
* or external workspaces when making immutable bundle directories removable. */
export async function makeDirectoryTreeRemovable(directory: string): Promise<void> {
const stat = await lstat(directory);
if (!stat.isDirectory() || stat.isSymbolicLink()) throw new Error("Cleanup requires an owned directory, not a symlink");
await chmod(directory, 0o700);
const entries = await readdir(directory, { withFileTypes: true });
await Promise.all(entries.filter(entry => entry.isDirectory() && !entry.isSymbolicLink())
.map(entry => makeDirectoryTreeRemovable(path.join(directory, entry.name))));
}