test(integration): clean up background-removal test-harness leftovers (#281)
backgroundRemoval.integration.test.ts exported seedSubmission for no reason — nothing imports it, since draftingBackgroundRemoval.integration.test.ts and adminItemDrafts.integration.test.ts each wrote their own seeding helpers. Dropped the export, kept the function for local use. All three of these suites create a temporary uploads directory with mkdtemp and point UPLOADS_DIR at it, but none of them removed the directory afterward or restored the previous UPLOADS_DIR value — checked and the leak existed in all three, not just the one the review flagged. Each afterEach now removes its temp directory with fs.rm and restores (or deletes) UPLOADS_DIR to what it held before the test touched it, so this suite no longer leaves rubbish in the OS temp directory or a stale environment variable for whatever runs after it in the same process. This is test scaffolding cleanup, not a feature change — no runtime path in the application deletes anything. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -317,10 +317,12 @@ describe('the review queue’s background-removal control', () => {
|
||||
|
||||
let uploads = '';
|
||||
let stub: http.Server | null = null;
|
||||
let previousUploadsDir: string | undefined;
|
||||
|
||||
/** A stub sidecar on an ephemeral port, and a temporary uploads directory. */
|
||||
async function startStub(status: number, body: Buffer | string): Promise<void> {
|
||||
uploads = await fsp.mkdtemp(path.join(os.tmpdir(), 'adminbg-'));
|
||||
previousUploadsDir = process.env.UPLOADS_DIR;
|
||||
process.env.UPLOADS_DIR = uploads;
|
||||
|
||||
stub = http.createServer((req, res) => {
|
||||
@@ -340,6 +342,13 @@ describe('the review queue’s background-removal control', () => {
|
||||
await new Promise<void>((resolve) => stub!.close(() => resolve()));
|
||||
stub = null;
|
||||
}
|
||||
if (uploads !== '') {
|
||||
await fsp.rm(uploads, { recursive: true, force: true });
|
||||
uploads = '';
|
||||
}
|
||||
if (previousUploadsDir === undefined) delete process.env.UPLOADS_DIR;
|
||||
else process.env.UPLOADS_DIR = previousUploadsDir;
|
||||
previousUploadsDir = undefined;
|
||||
});
|
||||
|
||||
/** A ready draft with one photo, on disk, named to match the assertions. */
|
||||
|
||||
Reference in New Issue
Block a user