/** * @file One scratch-directory fixture, with a delete that refuses any target * outside the OS temp dir. * A suite that redirects a path constant into a throwaway tree, then deletes * that tree in its teardown, is one failed redirect away from deleting the * real one. The redirect usually lives in a HOISTED mock factory, and a * factory that throws — `mkdtempSync` under fork pressure, for one — leaves * the constant pointing at the live checkout. The teardown then runs against * a real path with full recursion. * `path.isAbsolute` does NOT catch that: a live checkout is absolute too. * Containment in `os.tmpdir()` is the invariant that does. */ /** * A throwaway directory and the operations a fixture needs on it. */ export interface ScratchDir { /** * Remove the tree. Safe to call twice; the second call is a no-op. */ cleanup(): Promise; /** * The absolute directory path. */ dir: string; /** * An absolute path inside the tree. */ join(...segments: string[]): string; /** * Write a file inside the tree, creating parent directories, and answer its * absolute path. */ write(relativePath: string, contents: string): string; } /** * Delete a scratch tree, or throw when it is not one. * * Throwing beats a silent skip: a suite whose redirect failed has already been * asserting against the live tree, and a loud cleanup failure is the only * signal that says so. */ export declare function deleteScratchTree(target: string): Promise; /** * Whether a path sits inside the OS temp dir, and is not the temp dir itself. * * Compared by path SEGMENT, so a sibling whose name merely starts with the * temp dir's name does not read as contained. */ export declare function isScratchPath(target: string): boolean; /** * Create a throwaway directory under the OS temp dir. * * `prefix` names the suite so a leaked tree is traceable to its owner. The * returned `cleanup` is guarded, so it cannot recurse over the live checkout * even when a caller hands it a path the fixture did not create. */ export declare function makeScratchDir(prefix: string): ScratchDir;