/** * @file Path rewiring utilities for testing. Allows tests to override * os.tmpdir() and os.homedir() without directly modifying them. Features: * * - Test-friendly setPath/clearPath/resetPaths that work in * beforeEach/afterEach * - Automatic cache invalidation for path-dependent modules * - Thread-safe for concurrent test execution */ export interface PathRewireState { testOverrides: Map; cacheInvalidationCallbacks: Array<() => void>; } /** * Clear a specific path override. */ export declare function clearPath(key: string): void; /** * Get a path value, checking overrides first. * * Resolution order: * * 1. Test overrides, set via setPath in beforeEach. * 2. Original function call, recomputed on every call. * * `originalFn` is not memoized here: its typical inputs (env vars such as * HOME / SOCKET_HOME, os.homedir(), os.tmpdir()) can change without going * through setPath/clearPath/resetPaths - `env/rewire`'s setEnv/clearEnv, or a * direct process.env write, update those inputs without calling this * module's invalidateCaches(). A memo keyed only on `key` would then serve a * value computed against the OLD input forever, since nothing here observes * the env change to know the memo is stale. `originalFn` is a cheap pure * read (a string join, an env lookup) in every current caller, so recomputing * it every call costs nothing measurable and removes the staleness class * entirely. * * @internal Used by path getters to support test rewiring */ export declare function getPathValue(key: string, originalFn: () => string): string; /** * Check if a path has been overridden. */ export declare function hasOverride(key: string): boolean; /** * Run every registered cache-invalidation callback. Called automatically * when setPath/clearPath/resetPaths are used, so a module that maintains its * OWN cache derived from a path (via registerCacheInvalidation) still gets * to clear it on override changes. getPathValue itself has nothing to * invalidate - it no longer memoizes - so this only reaches other modules' * registered caches. * * @internal Primarily for internal use, but exported for advanced testing */ export declare function invalidateCaches(): void; /** * Register a cache invalidation callback. Called by modules that need to clear * their caches when paths change. * * @internal Used by paths.ts and fs.ts */ export declare function registerCacheInvalidation(callback: () => void): void; /** * Clear all path overrides and reset caches. Useful in afterEach hooks to * ensure clean test state. * * @example * ;```typescript * import { resetPaths } from '#paths/rewire' * * afterEach(() => { * resetPaths() * }) * ``` */ export declare function resetPaths(): void; /** * Set a path override for testing. This triggers cache invalidation for * path-dependent modules. * * @example * ;```typescript * import { setPath, resetPaths } from '#paths/rewire' * import { getOsTmpDir } from './' * * beforeEach(() => { * setPath('tmpdir', '/custom/tmp') * }) * * afterEach(() => { * resetPaths() * }) * * it('should use custom temp directory', () => { * expect(getOsTmpDir()).toBe('/custom/tmp') * }) * ``` */ export declare function setPath(key: string, value: string | undefined): void;