|
38 | 38 | // - CONTROL: a package whose names the environment does not hold boots on a |
39 | 39 | // database whose environment holds others, and restarts. |
40 | 40 | // |
41 | | -// Each case boots its own database file. A refused boot leaves no kernel to |
42 | | -// stop, so the files live in this test file's own working directory, which the |
43 | | -// dogfood run removes at its end, rather than being removed here. |
| 41 | +// Each case boots its own database file, in a directory of its own directly |
| 42 | +// under the system temp directory. A refused boot leaves no kernel to stop, but |
| 43 | +// its directory can still be removed, so this file removes every directory it |
| 44 | +// created in its `afterAll`, once `afterEach` has stopped the last kernel. The |
| 45 | +// harness leaves a `databaseFile`'s lifetime to its caller. |
| 46 | +// |
| 47 | +// The base is spelled `join(tmpdir(), ...)` on purpose: the tree's |
| 48 | +// scratch-directory scan must be able to read every `mkdtempSync` base |
| 49 | +// (`scripts/pm/dispatch-gates.mjs`, "no mkdtempSync site in this tree takes a |
| 50 | +// base the scan cannot read"), and `process.cwd()` is not a base it reads. |
44 | 51 |
|
45 | 52 | import { describe, it, expect, beforeAll, afterAll, afterEach } from 'vitest'; |
46 | | -import { mkdtempSync } from 'node:fs'; |
| 53 | +import { mkdtempSync, rmSync } from 'node:fs'; |
| 54 | +import { tmpdir } from 'node:os'; |
47 | 55 | import { join } from 'node:path'; |
48 | 56 | import { composeStacks, defineStack } from '@objectstack/spec'; |
49 | 57 | import { ObjectSchema, Field } from '@objectstack/spec/data'; |
@@ -104,15 +112,25 @@ const environmentConflicts = (set: string, position: string) => [ |
104 | 112 | { catalogType: 'permission', name: set, incomingPackageId: ADDON_ID, existingHolder: { kind: 'environment' } }, |
105 | 113 | ]; |
106 | 114 |
|
107 | | -/** A fresh database file in this test file's working directory (see the header). */ |
108 | | -const databaseFile = () => join(mkdtempSync(join(process.cwd(), 'catalog-cold-boot-')), 'deployment.db'); |
| 115 | +/** Every directory `databaseFile()` created; the `afterAll` below removes them (see the header). */ |
| 116 | +const createdRoots: string[] = []; |
| 117 | + |
| 118 | +/** A fresh database file in a directory of its own under the system temp directory (see the header). */ |
| 119 | +const databaseFile = () => { |
| 120 | + const root = mkdtempSync(join(tmpdir(), 'catalog-cold-boot-')); |
| 121 | + createdRoots.push(root); |
| 122 | + return join(root, 'deployment.db'); |
| 123 | +}; |
109 | 124 |
|
110 | 125 | describe('ADR-0048 N.3: a package-held position or permission-set name the environment catalog holds refuses the cold boot, as it refuses a hot install', () => { |
111 | 126 | let stack: VerifyStack | undefined; |
112 | 127 | afterEach(async () => { |
113 | 128 | await stack?.stop(); |
114 | 129 | stack = undefined; |
115 | 130 | }); |
| 131 | + afterAll(() => { |
| 132 | + for (const root of createdRoots.splice(0)) rmSync(root, { recursive: true, force: true }); |
| 133 | + }); |
116 | 134 |
|
117 | 135 | // The built-in control saves under two built-in position names, which the |
118 | 136 | // platform's package registers, so the save needs the documented hatch. The |
|
0 commit comments