Skip to content

Commit d8eee21

Browse files
committed
test(dogfood): the cold-boot catalog file takes its database roots under tmpdir() and removes them itself
The scratch-directory scan in scripts/pm/dispatch-gates.mjs must be able to read every mkdtempSync base. process.cwd() is not one it reads, so the site came back UNRESOLVED and the pm dispatch-gates self-test failed on main. The base is now join(tmpdir(), 'catalog-cold-boot-'). The per-file cwd sweep no longer covers these directories, so the file records each root it creates and removes them in afterAll, after afterEach has stopped the last kernel. Claude-Session: https://claude.ai/code/session_01WYYhVJ78u7PhwFViWo1EmQ Co-authored-by: Claude <noreply@anthropic.com>
1 parent 83e7ae9 commit d8eee21

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

‎packages/qa/dogfood/test/security-catalog-cold-boot-environment-holder.dogfood.test.ts‎

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,20 @@
3838
// - CONTROL: a package whose names the environment does not hold boots on a
3939
// database whose environment holds others, and restarts.
4040
//
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.
4451

4552
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';
4755
import { join } from 'node:path';
4856
import { composeStacks, defineStack } from '@objectstack/spec';
4957
import { ObjectSchema, Field } from '@objectstack/spec/data';
@@ -104,15 +112,25 @@ const environmentConflicts = (set: string, position: string) => [
104112
{ catalogType: 'permission', name: set, incomingPackageId: ADDON_ID, existingHolder: { kind: 'environment' } },
105113
];
106114

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+
};
109124

110125
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', () => {
111126
let stack: VerifyStack | undefined;
112127
afterEach(async () => {
113128
await stack?.stop();
114129
stack = undefined;
115130
});
131+
afterAll(() => {
132+
for (const root of createdRoots.splice(0)) rmSync(root, { recursive: true, force: true });
133+
});
116134

117135
// The built-in control saves under two built-in position names, which the
118136
// platform's package registers, so the save needs the documented hatch. The

0 commit comments

Comments
 (0)