Skip to content

Commit 02d0775

Browse files
committed
test(dogfood): the cold-boot catalog file takes its database roots under tmpdir() and removes them itself (ported from PR #22416)
Ported verbatim from PR #22416 (branch claude/issue-22400-cold-boot-dogfood-tmpdir, head d8eee21): its one-file diff against its merge base 83e7ae9, applied with git apply. The resulting blob equals that head's blob byte for byte (ac01935). Main carries the same file blob as that merge base, so the hunks are identical and a later merge of main that brings PR #22416 is a no-op here. It moves the mkdtempSync base from process.cwd() to join(tmpdir(), ...), which the dispatch-gates scratch-directory scan reads, and removes the created roots in an afterAll. Claude-Session: https://claude.ai/code/session_01VZqqwTj2wsihZEbfT6yyYN Co-authored-by: Claude <noreply@anthropic.com>
1 parent 577ac3d commit 02d0775

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)