An open source design system that's fully customizable and agent ready
TypeScript
test(cli): node tests no longer time out under load (#10740)
Christopher Chedeau3cd23eafbe81
diff --git a/.changeset/cli-node-tests-under-load.md b/.changeset/cli-node-tests-under-load.mdnew file mode 100644index 0000000000..838a4cc6af--- /dev/null+++ b/.changeset/cli-node-tests-under-load.md@@ -0,0 +1,7 @@+---+'@astryxdesign/cli': patch+---++[chore] Internal: the doc importers import each doc file through one small module that the CLI's own test project loads natively, so its tests no longer time out on a busy machine. No change to any command's output.++@vjeuxdiff --git a/packages/cli/api/component/component-replacement.test.mjs b/packages/cli/api/component/component-replacement.test.mjsindex 284cdb102b..fe8aae687e 100644--- a/packages/cli/api/component/component-replacement.test.mjs+++ b/packages/cli/api/component/component-replacement.test.mjs@@ -17,6 +17,7 @@ import {integrationComponentConflicts} from '../integration/authoring-checks.mjsimport {GAP_REPORT_CATEGORIES, gapReport} from '../gap-report/gap-report.mjs';import {Project} from '../../foundation/config/project.mjs';import {COMPONENT_REPLACES_CLI} from '../../foundation/integrations/cli-requirement.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';const SLOW = 60_000;const FLOOR = {'@astryxdesign/cli': `>=${COMPONENT_REPLACES_CLI}`};@@ -26,7 +27,7 @@ let tmpDir;beforeEach(() => {// Under the repository so the project resolves the workspace's Core.tmpDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-component-replacement-'),+ path.join(REPO_ROOT, '.astryx-component-replacement-'),);});diff --git a/packages/cli/api/component/doc-links.test.mjs b/packages/cli/api/component/doc-links.test.mjsindex cdc8c8e7a5..87b76bf094 100644--- a/packages/cli/api/component/doc-links.test.mjs+++ b/packages/cli/api/component/doc-links.test.mjs@@ -14,6 +14,7 @@ import * as fs from 'node:fs';import * as path from 'node:path';import {afterEach, beforeEach, describe, expect, it} from 'vitest';import {requireNatively} from '../../test-utils/native-require.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';const require = requireNatively(import.meta.url);/** @type {typeof import('./component.mjs')} */@@ -108,7 +109,7 @@ function scaffold() {}beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-component-links-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-component-links-'));});afterEach(() => {diff --git a/packages/cli/api/component/integration-export-name.test.mjs b/packages/cli/api/component/integration-export-name.test.mjsindex 3010d05833..a0b7de2ac1 100644--- a/packages/cli/api/component/integration-export-name.test.mjs+++ b/packages/cli/api/component/integration-export-name.test.mjs@@ -20,6 +20,7 @@ import {Project} from '../../foundation/config/project.mjs';import {collectDocInputs} from '../../foundation/doc-compiler/inputs.mjs';import {COMPONENT_REPLACES_CLI} from '../../foundation/integrations/cli-requirement.mjs';import {scopeIntegrationMember} from './_adapter.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';const SLOW = 30_000;@@ -59,7 +60,7 @@ function writeComponent(file, name, source, description, extra = {}) {beforeEach(() => {tmpDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-export-name-test-'),+ path.join(REPO_ROOT, '.astryx-export-name-test-'),);fs.writeFileSync(path.join(tmpDir, 'package.json'),diff --git a/packages/cli/api/component/integration-import-agreement.test.mjs b/packages/cli/api/component/integration-import-agreement.test.mjsindex 77177c1374..4167bb576e 100644--- a/packages/cli/api/component/integration-import-agreement.test.mjs+++ b/packages/cli/api/component/integration-import-agreement.test.mjs@@ -25,6 +25,7 @@ import {afterEach, beforeEach, describe, expect, it} from 'vitest';import * as fs from 'node:fs';import * as path from 'node:path';import {requireNatively} from '../../test-utils/native-require.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';const require = requireNatively(import.meta.url);/** @type {typeof import('./component.mjs')} */@@ -127,7 +128,7 @@ const SUBPATH_EXPORTS = {beforeEach(() => {tmpDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-import-agreement-test-'),+ path.join(REPO_ROOT, '.astryx-import-agreement-test-'),);});diff --git a/packages/cli/api/docs/docs.child-route.test.mjs b/packages/cli/api/docs/docs.child-route.test.mjsindex db091cae68..6dba6715c1 100644--- a/packages/cli/api/docs/docs.child-route.test.mjs+++ b/packages/cli/api/docs/docs.child-route.test.mjs@@ -14,6 +14,7 @@ import * as fs from 'node:fs';import * as path from 'node:path';import {afterEach, beforeEach, describe, expect, it} from 'vitest';import {docs} from './docs.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';const SLOW = 60_000;@@ -79,7 +80,7 @@ function scaffoldTwoOwners() {}beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-child-route-test-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-child-route-test-'));});afterEach(() => {diff --git a/packages/cli/api/docs/guide-route-targets.test.mjs b/packages/cli/api/docs/guide-route-targets.test.mjsindex 3f0bbfeed3..a8a10678a4 100644--- a/packages/cli/api/docs/guide-route-targets.test.mjs+++ b/packages/cli/api/docs/guide-route-targets.test.mjs@@ -23,6 +23,7 @@ import {DocsCatalog,mergeTopic,} from '../../foundation/discovery/docs-discovery.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';const SLOW = 60_000;const CLI = '@astryxdesign/cli';@@ -115,7 +116,7 @@ async function cliJson(args) {beforeEach(() => {tmpDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-guide-route-targets-'),+ path.join(REPO_ROOT, '.astryx-guide-route-targets-'),);});diff --git a/packages/cli/api/docs/integration-tree.test.mjs b/packages/cli/api/docs/integration-tree.test.mjsindex f7dbce4875..eeca8c9437 100644--- a/packages/cli/api/docs/integration-tree.test.mjs+++ b/packages/cli/api/docs/integration-tree.test.mjs@@ -14,6 +14,7 @@ import {loadDocsCatalog} from './_adapter.mjs';import {search} from '../search/search.mjs';import {checkDocsTree} from '../doctor/doctor.mjs';import {integrationDocConflicts} from '../integration/authoring-checks.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';const SLOW = 60_000;@@ -133,7 +134,7 @@ function scaffold(files) {beforeEach(() => {tmpDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-integration-tree-test-'),+ path.join(REPO_ROOT, '.astryx-integration-tree-test-'),);});diff --git a/packages/cli/api/docs/integrationDocs.test.mjs b/packages/cli/api/docs/integrationDocs.test.mjsindex 96c8d4d029..c48f31598b 100644--- a/packages/cli/api/docs/integrationDocs.test.mjs+++ b/packages/cli/api/docs/integrationDocs.test.mjs@@ -23,6 +23,7 @@ import {search} from '../search/search.mjs';import {loadDocsCatalog} from './_adapter.mjs';import {AstryxError} from '../error.mjs';import {discoverCoreTemplates} from '../../foundation/discovery/template-adapter.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';const SLOW = 30_000;@@ -82,7 +83,7 @@ function scaffold(topics, {config} = {}) {}beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-integration-docs-test-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-integration-docs-test-'));});afterEach(() => {diff --git a/packages/cli/api/docs/namespace-section.test.mjs b/packages/cli/api/docs/namespace-section.test.mjsindex d513942281..a766ad8b4f 100644--- a/packages/cli/api/docs/namespace-section.test.mjs+++ b/packages/cli/api/docs/namespace-section.test.mjs@@ -13,6 +13,7 @@ import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';import {Project} from '../../foundation/config/project.mjs';import {docs} from './docs.mjs';import {oneGuide} from './detail/section/section.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';const SLOW = 60_000;@@ -89,7 +90,7 @@ function kit() {beforeEach(() => {tmpDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-namespace-section-test-'),+ path.join(REPO_ROOT, '.astryx-namespace-section-test-'),);});diff --git a/packages/cli/api/docs/reference-blocks.test.mjs b/packages/cli/api/docs/reference-blocks.test.mjsindex 9209222089..a2179838f8 100644--- a/packages/cli/api/docs/reference-blocks.test.mjs+++ b/packages/cli/api/docs/reference-blocks.test.mjs@@ -23,6 +23,7 @@ import {checkDocsTree} from '../doctor/doctor.mjs';import {createDocId} from '../../foundation/identity/provider-identity.mjs';import {CLI_PROVIDER_ID} from '../../foundation/identity/providers.mjs';import {runCli} from '../../test-utils/run-cli.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';const SLOW = 60_000;@@ -119,7 +120,7 @@ const BROKEN = {let tmpDir;beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-reference-test-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-reference-test-'));});afterEach(() => {diff --git a/packages/cli/api/doctor/doctor.test.mjs b/packages/cli/api/doctor/doctor.test.mjsindex 8de100b86d..d06e475dbf 100644--- a/packages/cli/api/doctor/doctor.test.mjs+++ b/packages/cli/api/doctor/doctor.test.mjs@@ -36,6 +36,7 @@ import {import {installCommandFor} from './_adapter.mjs';import {formatCliCommand} from '../../foundation/env/package-manager.mjs';import {Project} from '../../foundation/config/project.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';const REPO = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../..');const cwd = REPO;@@ -679,7 +680,7 @@ describe('checkDocsProgressiveDisclosure', () => {});it('names a section over the budget and a topic that fails to load', async () => {- const dir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-docs-'));+ const dir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-doctor-docs-'));tmpDirs.push(dir);const huge = {name: 'huge',@@ -724,7 +725,7 @@ describe('checkCliDocs', () => {/** A doc tree under the working directory, as the CLI root. */function writeRoot(/** @type {Record<string, any>} */ docsByPath) {- const root = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-cli-docs-'));+ const root = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-doctor-cli-docs-'));tmpDirs.push(root);for (const [rel, doc] of Object.entries(docsByPath)) {const file = path.join(root, rel);@@ -860,7 +861,7 @@ describe('checkAuthoringDocs against the public authoring surface', () => {/** A copy of this repo's authoring tree, to break one piece of at a time. */function copyAuthoring() {const root = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-doctor-authoring-'),+ path.join(REPO_ROOT, '.astryx-doctor-authoring-'),);tmpDirs.push(root);fs.cpSync(AUTHORING_ROOT, root, {@@ -1115,7 +1116,7 @@ describe('doctor docs checks', () => {describe('checkDocsProgressiveDisclosure languages', () => {it('checks every overlay a topic ships, not only English', async () => {- const dir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-lang-'));+ const dir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-doctor-lang-'));tmpDirs.push(dir);const deploying = {name: 'deploying',@@ -1262,7 +1263,7 @@ describe('doctor says why it skipped and what it checked', () => {/** A project under the working directory, so its config can be imported. */function cwdProject(files) {const dir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-doctor-shape-'),+ path.join(REPO_ROOT, '.astryx-doctor-shape-'),);tmpDirs.push(dir);for (const [rel, content] of Object.entries(files)) {@@ -1389,7 +1390,7 @@ describe('a configured integration that cannot load fails the gate', () => {* @param {string} [at]*/async function report(files, at = '.') {- const dir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-gate-'));+ const dir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-doctor-gate-'));tmpDirs.push(dir);for (const [rel, content] of Object.entries(files)) {const abs = path.join(dir, rel);@@ -1487,7 +1488,7 @@ describe('a configured integration that cannot load fails the gate', () => {it('fails when node_modules links the configured name back to the authored package and its manifest throws',async () => {- const dir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-gate-'));+ const dir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-doctor-gate-'));tmpDirs.push(dir);const files = {...CORE_STUB,@@ -1516,9 +1517,9 @@ describe('a configured integration that cannot load fails the gate', () => {it('fails for the self-linked authored package when the working directory is itself a symlink',async () => {- const real = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-gate-'));+ const real = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-doctor-gate-'));tmpDirs.push(real);- const linkParent = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-gate-'));+ const linkParent = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-doctor-gate-'));tmpDirs.push(linkParent);const cwd = path.join(linkParent, 'link');fs.symlinkSync(real, cwd, 'dir');diff --git a/packages/cli/api/doctor/theme-checks.test.mjs b/packages/cli/api/doctor/theme-checks.test.mjsindex f6e1f040d2..1eaaf13f4d 100644--- a/packages/cli/api/doctor/theme-checks.test.mjs+++ b/packages/cli/api/doctor/theme-checks.test.mjs@@ -37,7 +37,7 @@ function write(file, content) {*/async function fixture(themeSpecs = [{slug: 'ocean'}], options = {}) {const dir = fs.mkdtempSync(- path.join(options.root ?? process.cwd(), '.astryx-doctor-themes-'),+ path.join(options.root ?? REPO_ROOT, '.astryx-doctor-themes-'),);dirs.push(dir);fs.mkdirSync(path.join(dir, 'src'), {recursive: true});@@ -153,7 +153,7 @@ describe('the released themes check', () => {/** @param {string} name */function emptyApp(name) {const dir = fs.mkdtempSync(- path.join(process.cwd(), `.astryx-doctor-${name}-`),+ path.join(REPO_ROOT, `.astryx-doctor-${name}-`),);dirs.push(dir);write(path.join(dir, 'package.json'), '{"name":"app","private":true}\n');@@ -1151,7 +1151,7 @@ describe('app-theme doctor checks', () => {it('reports one information check when the CLI manages no themes', async () => {const dir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-doctor-empty-'),+ path.join(REPO_ROOT, '.astryx-doctor-empty-'),);dirs.push(dir);write(path.join(dir, 'package.json'), '{"name":"empty"}\n');@@ -1170,7 +1170,7 @@ describe('app-theme doctor checks', () => {it('reads astryx.theme from the app package when node_modules is hoisted to a workspace root', async () => {const root = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-doctor-monorepo-'),+ path.join(REPO_ROOT, '.astryx-doctor-monorepo-'),);dirs.push(root);write(@@ -1213,7 +1213,7 @@ describe('app-theme doctor checks', () => {it('names an unmigrated copy without failing a project that has no module', async () => {const dir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-doctor-unmigrated-'),+ path.join(REPO_ROOT, '.astryx-doctor-unmigrated-'),);dirs.push(dir);write(path.join(dir, 'package.json'), '{"name":"empty"}\n');diff --git a/packages/cli/api/icon/new-definition/new-definition.undo.test.mjs b/packages/cli/api/icon/new-definition/new-definition.undo.test.mjsindex 860ecd8ef1..39c439c298 100644--- a/packages/cli/api/icon/new-definition/new-definition.undo.test.mjs+++ b/packages/cli/api/icon/new-definition/new-definition.undo.test.mjs@@ -9,6 +9,7 @@import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';import * as fs from 'node:fs';import * as path from 'node:path';+import {REPO_ROOT} from '../../../test-utils/repo-root.mjs';const reread = vi.hoisted(() => ({calls: 0, failOn: 0}));@@ -41,7 +42,7 @@ let tmpDir;beforeEach(() => {tmpDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-add-icon-definition-undo-'),+ path.join(REPO_ROOT, '.astryx-add-icon-definition-undo-'),);fs.writeFileSync(path.join(tmpDir, 'package.json'),diff --git a/packages/cli/api/icon/new-set/new-set.test.mjs b/packages/cli/api/icon/new-set/new-set.test.mjsindex f5229ae7d5..ef407ce954 100644--- a/packages/cli/api/icon/new-set/new-set.test.mjs+++ b/packages/cli/api/icon/new-set/new-set.test.mjs@@ -7,6 +7,7 @@ import {integrationAdd} from '../../integration/add-contribution.mjs';import {iconNewSet} from './new-set.mjs';import {discoverIconSetDirectory} from '../../../foundation/discovery/icon-set-discovery.mjs';import {cliVersion} from '../../../foundation/release/run-context.mjs';+import {REPO_ROOT} from '../../../test-utils/repo-root.mjs';/** @type {string} */let tmpDir;@@ -38,7 +39,7 @@ function setup({const read = file => fs.readFileSync(path.join(tmpDir, file), 'utf-8');beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-add-icon-set-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-add-icon-set-'));});afterEach(() => {diff --git a/packages/cli/api/init/init.test.mjs b/packages/cli/api/init/init.test.mjsindex 8b9f157e54..771e7a1da4 100644--- a/packages/cli/api/init/init.test.mjs+++ b/packages/cli/api/init/init.test.mjs@@ -16,6 +16,7 @@ import {init, getNextSteps} from './init.mjs';import {logger} from '../logger.mjs';import {AstryxError} from '../error.mjs';import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';const MARKER_START = '<!-- ASTRYX:START -->';@@ -305,7 +306,7 @@ describe('init() — write-path safety', () => {});it('refuses a template write that a symlinked src would carry outside cwd (ERR_PATH_TRAVERSAL)', async () => {- const outside = fs.mkdtempSync(path.join(process.cwd(), '.astryx-init-outside-'));+ const outside = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-init-outside-'));try {fs.symlinkSync(outside, path.join(tmpDir, 'src'), 'dir');await expect(diff --git a/packages/cli/api/integration/add-contribution.component-names.test.mjs b/packages/cli/api/integration/add-contribution.component-names.test.mjsindex 4c874d034b..6eb41788f5 100644--- a/packages/cli/api/integration/add-contribution.component-names.test.mjs+++ b/packages/cli/api/integration/add-contribution.component-names.test.mjs@@ -5,11 +5,12 @@ import * as fs from 'node:fs';import * as path from 'node:path';import {integrationAdd, integrationAddComponent} from './add-contribution.mjs';import {discoverIntegrationComponents} from '../../foundation/discovery/component-discovery.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';let tmpDir;beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-add-component-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-add-component-'));fs.writeFileSync(path.join(tmpDir, 'package.json'),`${JSON.stringify({name: '@acme/widgets', version: '1.0.0', files: ['dist']}, null, 2)}\n`,diff --git a/packages/cli/api/integration/add-contribution.test.mjs b/packages/cli/api/integration/add-contribution.test.mjsindex 408f17ae9c..43f1ebff0d 100644--- a/packages/cli/api/integration/add-contribution.test.mjs+++ b/packages/cli/api/integration/add-contribution.test.mjs@@ -14,6 +14,7 @@ import {import {iconNewSet} from '../icon/new-set/new-set.mjs';import {validateLocalIntegration} from './validate-integration.mjs';import {NAMESPACE_DOCS_CLI} from '../../foundation/integrations/cli-requirement.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';let tmpDir;@@ -50,7 +51,7 @@ function setupBare({files, includeFiles = true} = {}) {}beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-add-contrib-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-add-contrib-'));});afterEach(() => {diff --git a/packages/cli/api/integration/add-helpers.test.mjs b/packages/cli/api/integration/add-helpers.test.mjsindex ad02bbac80..7ade930e70 100644--- a/packages/cli/api/integration/add-helpers.test.mjs+++ b/packages/cli/api/integration/add-helpers.test.mjs@@ -4,11 +4,12 @@ import {afterEach, beforeEach, describe, expect, it} from 'vitest';import * as fs from 'node:fs';import * as path from 'node:path';import {applyWrites, packageJsonFilesUpdate} from './add-helpers.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';let tmpDir;beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-add-helpers-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-add-helpers-'));});afterEach(() => {diff --git a/packages/cli/api/integration/add-theme.test.mjs b/packages/cli/api/integration/add-theme.test.mjsindex be5178a4b5..e6c8fd73dc 100644--- a/packages/cli/api/integration/add-theme.test.mjs+++ b/packages/cli/api/integration/add-theme.test.mjs@@ -7,6 +7,7 @@ import * as path from 'node:path';import {CLI_ROOT, findInstalledPackage} from '../../foundation/fs/paths.mjs';import {integrationAddTheme} from './add-theme.mjs';import {validateLocalIntegration} from './validate-integration.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';let tmpDir;@@ -26,7 +27,7 @@ function setup({}beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-add-theme-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-add-theme-'));});afterEach(() => {diff --git a/packages/cli/api/integration/authoring-checks.test.mjs b/packages/cli/api/integration/authoring-checks.test.mjsindex 29de742433..5e88a95702 100644--- a/packages/cli/api/integration/authoring-checks.test.mjs+++ b/packages/cli/api/integration/authoring-checks.test.mjs@@ -8,6 +8,7 @@*/import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';vi.mock('../../foundation/discovery/template-conflict-release.mjs', () => ({expandedTemplateConflictSchemaActive: () => true,@@ -149,7 +150,7 @@ const PASSAGE =beforeEach(() => {tmpDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-template-conflicts-'),+ path.join(REPO_ROOT, '.astryx-template-conflicts-'),);// The fixture is a package with its own TypeScript config, scoped to its// own files. Without one, the prop check reads the repository's rootdiff --git a/packages/cli/api/integration/check/check.test.mjs b/packages/cli/api/integration/check/check.test.mjsindex b97d2e549a..c66e281e4a 100644--- a/packages/cli/api/integration/check/check.test.mjs+++ b/packages/cli/api/integration/check/check.test.mjs@@ -27,6 +27,7 @@ import {} from './check.mjs';import {validateIntegration} from '../validate-integration.mjs';import {discoverCoreTemplates} from '../../../foundation/discovery/template-adapter.mjs';+import {REPO_ROOT} from '../../../test-utils/repo-root.mjs';const IDENTITY = {validated: true, name: '@acme/widgets', version: '1.2.3'};@@ -398,7 +399,7 @@ describe('integrationCheck', () => {beforeEach(() => {// Under the repository, so the components check resolves Core.pkg = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-integration-check-'),+ path.join(REPO_ROOT, '.astryx-integration-check-'),);fs.writeFileSync(path.join(pkg, 'package.json'),diff --git a/packages/cli/api/integration/pack-check.component-replaces.test.mjs b/packages/cli/api/integration/pack-check.component-replaces.test.mjsindex 3c6c7803bb..39e0d21b92 100644--- a/packages/cli/api/integration/pack-check.component-replaces.test.mjs+++ b/packages/cli/api/integration/pack-check.component-replaces.test.mjs@@ -12,6 +12,7 @@ import * as path from 'node:path';import {spawnSync} from 'node:child_process';import {integrationPackCheck} from './pack-check.mjs';import {COMPONENT_REPLACES_CLI} from '../../foundation/integrations/cli-requirement.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';const SLOW = 120_000;@@ -19,7 +20,7 @@ let tmpDir;beforeEach(() => {tmpDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-pack-check-component-replaces-'),+ path.join(REPO_ROOT, '.astryx-pack-check-component-replaces-'),);});diff --git a/packages/cli/api/integration/pack-check.lifecycle-output.test.mjs b/packages/cli/api/integration/pack-check.lifecycle-output.test.mjsindex fbe5e0476c..af4e2595b2 100644--- a/packages/cli/api/integration/pack-check.lifecycle-output.test.mjs+++ b/packages/cli/api/integration/pack-check.lifecycle-output.test.mjs@@ -5,11 +5,12 @@ import {spawnSync} from 'node:child_process';import * as fs from 'node:fs';import * as path from 'node:path';import {integrationPackCheck} from './pack-check.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';let tmpDir;beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-pack-check-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-pack-check-'));});afterEach(() => {diff --git a/packages/cli/api/integration/pack-check.test.mjs b/packages/cli/api/integration/pack-check.test.mjsindex a48254fa2d..dcd539cea7 100644--- a/packages/cli/api/integration/pack-check.test.mjs+++ b/packages/cli/api/integration/pack-check.test.mjs@@ -18,11 +18,12 @@ import {integrationAddTemplate,} from './add-contribution.mjs';import {formatCliCommand} from '../../foundation/env/package-manager.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';let tmpDir;beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-pack-check-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-pack-check-'));});afterEach(() => {@@ -2242,7 +2243,7 @@ describe('integrationPackCheck', () => {const marker = path.join(process.cwd(), 'astryx-pack-check-injected');fs.rmSync(marker, {force: true});const weirdDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-;touch astryx-pack-check-injected;#-'),+ path.join(REPO_ROOT, '.astryx-;touch astryx-pack-check-injected;#-'),);try {const pkg = {name: 'safe-pkg', version: '1.0.0'};diff --git a/packages/cli/api/integration/template-conflict-compatibility.test.mjs b/packages/cli/api/integration/template-conflict-compatibility.test.mjsindex 3b5884083a..7b94bd7dae 100644--- a/packages/cli/api/integration/template-conflict-compatibility.test.mjs+++ b/packages/cli/api/integration/template-conflict-compatibility.test.mjs@@ -11,6 +11,7 @@ import {afterEach, beforeEach, describe, expect, it} from 'vitest';import * as fs from 'node:fs';import * as path from 'node:path';import {requireNatively} from '../../test-utils/native-require.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';const require = requireNatively(import.meta.url);/** @type {typeof import('../../foundation/discovery/template-adapter.mjs')} */@@ -37,7 +38,7 @@ function writeTemplate(pkgDir, id, type, replaces) {beforeEach(() => {tmpDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-template-conflict-compat-'),+ path.join(REPO_ROOT, '.astryx-template-conflict-compat-'),);});diff --git a/packages/cli/api/integration/validate-integration-case-disk.test.mjs b/packages/cli/api/integration/validate-integration-case-disk.test.mjsindex 27505de274..e3fa112920 100644--- a/packages/cli/api/integration/validate-integration-case-disk.test.mjs+++ b/packages/cli/api/integration/validate-integration-case-disk.test.mjs@@ -10,6 +10,7 @@import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';import * as fs from 'node:fs';import * as path from 'node:path';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';vi.mock('../../foundation/discovery/component-discovery.mjs',@@ -41,7 +42,7 @@ const {validateIntegration} = await import('./validate-integration.mjs');let tmpDir;beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-case-disk-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-case-disk-'));});afterEach(() => {diff --git a/packages/cli/api/integration/validate-integration-fixes.test.mjs b/packages/cli/api/integration/validate-integration-fixes.test.mjsindex edd2fe7f63..db88d8f986 100644--- a/packages/cli/api/integration/validate-integration-fixes.test.mjs+++ b/packages/cli/api/integration/validate-integration-fixes.test.mjs@@ -14,12 +14,13 @@ import {afterEach, beforeEach, describe, expect, it} from 'vitest';import * as fs from 'node:fs';import * as path from 'node:path';import {validateLocalIntegration} from './validate-integration.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';let tmpDir;let copies = 0;beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-validate-fix-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-validate-fix-'));});afterEach(() => {diff --git a/packages/cli/api/integration/validate-integration-gaps.test.mjs b/packages/cli/api/integration/validate-integration-gaps.test.mjsindex ee75032150..88f83e5c62 100644--- a/packages/cli/api/integration/validate-integration-gaps.test.mjs+++ b/packages/cli/api/integration/validate-integration-gaps.test.mjs@@ -30,6 +30,7 @@ import {componentDocNamesCheck} from '../../foundation/integrations/validate-conimport {formatCliCommand} from '../../foundation/env/package-manager.mjs';import {runCli} from '../../test-utils/run-cli.mjs';import {warmIntegrationChecks} from '../../test-utils/warm-integration-checks.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';// The checks' one-time start in this file (TypeScript and its lib files) runs// here, while the file is collected, so no test carries it.@@ -39,7 +40,7 @@ let tmpDir;let copies = 0;beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-validate-gaps-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-validate-gaps-'));// The fixture is a package with its own TypeScript config, scoped to its// own files. Without one, the prop check reads the repository's root// config, as `tsc` would for a folder inside it, and compiles everydiff --git a/packages/cli/api/integration/validate-integration.test.mjs b/packages/cli/api/integration/validate-integration.test.mjsindex d2e662ff69..4769552757 100644--- a/packages/cli/api/integration/validate-integration.test.mjs+++ b/packages/cli/api/integration/validate-integration.test.mjs@@ -24,6 +24,7 @@ import {integrationTemplateConflicts,} from './authoring-checks.mjs';import {warmIntegrationChecks} from '../../test-utils/warm-integration-checks.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';// The checks' one-time start in this file (TypeScript and its lib files) runs// here, while the file is collected, so no test carries it.@@ -32,7 +33,7 @@ await warmIntegrationChecks();let tmpDir;beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-validate-it-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-validate-it-'));});afterEach(() => {diff --git a/packages/cli/api/integration/validate-unread-theme-folders.test.mjs b/packages/cli/api/integration/validate-unread-theme-folders.test.mjsindex 3322a44b9d..6f807128c1 100644--- a/packages/cli/api/integration/validate-unread-theme-folders.test.mjs+++ b/packages/cli/api/integration/validate-unread-theme-folders.test.mjs@@ -16,11 +16,12 @@ import * as path from 'node:path';import {validateLocalIntegration} from './validate-integration.mjs';import {integrationAddTheme} from './add-theme.mjs';import {formatCliCommand} from '../../foundation/env/package-manager.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';let tmpDir;beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-unread-theme-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-unread-theme-'));fs.writeFileSync(path.join(tmpDir, 'package.json'),JSON.stringify({name: '@acme/kit', version: '1.0.0'}),diff --git a/packages/cli/api/search/_adapter.test.mjs b/packages/cli/api/search/_adapter.test.mjsindex 6d59e4b7bb..a4fe1afb96 100644--- a/packages/cli/api/search/_adapter.test.mjs+++ b/packages/cli/api/search/_adapter.test.mjs@@ -24,6 +24,7 @@ import {Project} from '../../foundation/config/project.mjs';import * as readRecord from '../../foundation/fs/read-record.mjs';import {gatherCandidates, gatherCandidatesReused} from './_adapter.mjs';import {searchCore} from './search.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';vi.mock('../../foundation/fs/read-record.mjs', async original => {const real = /** @type {typeof readRecord} */ (await original());@@ -132,7 +133,7 @@ describe('gatherCandidatesReused', () => {// A consumer whose integration is a symlink to a package folder// elsewhere, as a workspace package is.const dir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-gather-reuse-'),+ path.join(REPO_ROOT, '.astryx-gather-reuse-'),);const pkg = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-linked-widgets-'),diff --git a/packages/cli/api/search/search.test.mjs b/packages/cli/api/search/search.test.mjsindex 8b016b6512..17d4f5bfce 100644--- a/packages/cli/api/search/search.test.mjs+++ b/packages/cli/api/search/search.test.mjs@@ -25,6 +25,7 @@ import * as os from 'node:os';import * as path from 'node:path';import {fileURLToPath} from 'node:url';import {requireNatively} from '../../test-utils/native-require.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';const require = requireNatively(import.meta.url);/** @type {typeof import('../docs/docs.mjs')} */@@ -674,7 +675,7 @@ describe('search leaf — integration components', () => {* `@acme/widgets` integration that contributes one component.*/function makeConsumerWithIntegrationComponent() {- const dir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-search-it-'));+ const dir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-search-it-'));fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify({name: 'consumer'}));fs.writeFileSync(path.join(dir, 'astryx.config.mjs'),diff --git a/packages/cli/api/template/template-integration.test.mjs b/packages/cli/api/template/template-integration.test.mjsindex 57fb70784b..f7f52e99ee 100644--- a/packages/cli/api/template/template-integration.test.mjs+++ b/packages/cli/api/template/template-integration.test.mjs@@ -13,6 +13,7 @@ import {afterEach, beforeEach, describe, expect, it} from 'vitest';import * as fs from 'node:fs';import * as path from 'node:path';import {requireNatively} from '../../test-utils/native-require.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';const require = requireNatively(import.meta.url);/** @type {typeof import('./template.mjs')} */@@ -32,7 +33,7 @@ let tmpDir;let originalCwd;function makeConsumer() {- const dir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-template-it-'));+ const dir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-template-it-'));fs.writeFileSync(path.join(dir, 'package.json'),JSON.stringify({name: 'consumer'}),diff --git a/packages/cli/api/theme/add/add.test.mjs b/packages/cli/api/theme/add/add.test.mjsindex 5449e75e73..591d3a8dd1 100644--- a/packages/cli/api/theme/add/add.test.mjs+++ b/packages/cli/api/theme/add/add.test.mjs@@ -9,6 +9,7 @@ import {THEME_MODULE_MARKER,parseThemeModuleRecord,} from '../../../foundation/config/theme-state.mjs';+import {REPO_ROOT} from '../../../test-utils/repo-root.mjs';let tmpDir;@@ -110,7 +111,7 @@ function installBuiltThemePackage(slug) {}beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-theme-add-app-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-theme-add-app-'));fs.mkdirSync(path.join(tmpDir, 'src'));fs.writeFileSync(path.join(tmpDir, 'package.json'),diff --git a/packages/cli/api/theme/integration-themes.test.mjs b/packages/cli/api/theme/integration-themes.test.mjsindex d7e6fe557f..d3fc821981 100644--- a/packages/cli/api/theme/integration-themes.test.mjs+++ b/packages/cli/api/theme/integration-themes.test.mjs@@ -5,6 +5,7 @@ import * as fs from 'node:fs';import * as path from 'node:path';import {themeAdd} from './add/add.mjs';import {themeEject} from './eject/eject.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';let tmpDir;@@ -63,7 +64,7 @@ export default {type: 'theme', name: '${slug}', displayName: '${slug === 'neutrabeforeEach(() => {tmpDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-theme-integration-'),+ path.join(REPO_ROOT, '.astryx-theme-integration-'),);fs.writeFileSync(path.join(tmpDir, 'package.json'),@@ -146,7 +147,7 @@ describe('package and integration themes', () => {{'tokens/colors.ts': "export const oceanBlue = '#0064e0';\n"},);const outsideDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-theme-outside-'),+ path.join(REPO_ROOT, '.astryx-theme-outside-'),);try {const targetDir = path.join(tmpDir, 'src', 'themes', 'ocean');diff --git a/packages/cli/api/theme/list/list.test.mjs b/packages/cli/api/theme/list/list.test.mjsindex b83606c2bf..9b1fad93a8 100644--- a/packages/cli/api/theme/list/list.test.mjs+++ b/packages/cli/api/theme/list/list.test.mjs@@ -9,6 +9,7 @@ import {themeListCopySources,} from './list.mjs';import {renderThemeModule} from '../../../foundation/config/theme-state.mjs';+import {REPO_ROOT} from '../../../test-utils/repo-root.mjs';let tmpDir;@@ -44,7 +45,7 @@ export default {type: 'theme', name: '${slug}', displayName: 'Ocean', descriptio}beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-theme-list-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-theme-list-'));fs.writeFileSync(path.join(tmpDir, 'package.json'),JSON.stringify({diff --git a/packages/cli/api/theme/remove/remove.test.mjs b/packages/cli/api/theme/remove/remove.test.mjsindex 976ac1621a..b4076e0647 100644--- a/packages/cli/api/theme/remove/remove.test.mjs+++ b/packages/cli/api/theme/remove/remove.test.mjs@@ -6,6 +6,7 @@ import * as path from 'node:path';import {themeAdd} from '../add/add.mjs';import {themeRemove} from './remove.mjs';import {parseThemeModuleRecord} from '../../../foundation/config/theme-state.mjs';+import {REPO_ROOT} from '../../../test-utils/repo-root.mjs';let tmpDir;@@ -44,7 +45,7 @@ function installThemes() {}beforeEach(async () => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-theme-remove-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-theme-remove-'));fs.mkdirSync(path.join(tmpDir, 'src'));fs.writeFileSync(path.join(tmpDir, 'package.json'),diff --git a/packages/cli/api/theme/use/use.test.mjs b/packages/cli/api/theme/use/use.test.mjsindex e34acd3925..a00d398e2c 100644--- a/packages/cli/api/theme/use/use.test.mjs+++ b/packages/cli/api/theme/use/use.test.mjs@@ -6,6 +6,7 @@ import * as path from 'node:path';import {themeAdd} from '../add/add.mjs';import {themeUse} from './use.mjs';import {parseThemeModuleRecord} from '../../../foundation/config/theme-state.mjs';+import {REPO_ROOT} from '../../../test-utils/repo-root.mjs';let tmpDir;@@ -44,7 +45,7 @@ function installThemes() {}beforeEach(async () => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-theme-use-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-theme-use-'));fs.mkdirSync(path.join(tmpDir, 'src'));fs.writeFileSync(path.join(tmpDir, 'package.json'),diff --git a/packages/cli/api/upgrade/project-context.test.mjs b/packages/cli/api/upgrade/project-context.test.mjsindex f75db0dae9..2c39a201aa 100644--- a/packages/cli/api/upgrade/project-context.test.mjs+++ b/packages/cli/api/upgrade/project-context.test.mjs@@ -12,13 +12,14 @@ import {afterEach, beforeEach, describe, expect, it} from 'vitest';import * as fs from 'node:fs';import * as path from 'node:path';import {loadProjectContext, selectIntegrationCodemodsFor} from './_adapter.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';let tmpDir;let originalCwd;beforeEach(() => {originalCwd = process.cwd();- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-upgrade-context-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-upgrade-context-'));});afterEach(() => {diff --git a/packages/cli/api/upgrade/provider-agreement.test.mjs b/packages/cli/api/upgrade/provider-agreement.test.mjsindex b8e2a1c091..a3c5d40f13 100644--- a/packages/cli/api/upgrade/provider-agreement.test.mjs+++ b/packages/cli/api/upgrade/provider-agreement.test.mjs@@ -19,6 +19,7 @@ import * as fs from 'node:fs';import * as path from 'node:path';import {loadProjectContext} from './_adapter.mjs';import {Project, providerLedgerOf} from '../../foundation/config/project.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';let tmpDir;let originalCwd;@@ -26,7 +27,7 @@ let originalCwd;beforeEach(() => {originalCwd = process.cwd();tmpDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-upgrade-agreement-'),+ path.join(REPO_ROOT, '.astryx-upgrade-agreement-'),);process.chdir(tmpDir);});diff --git a/packages/cli/api/upgrade/run/files-changed.test.mjs b/packages/cli/api/upgrade/run/files-changed.test.mjsindex c31223b198..4d7734414b 100644--- a/packages/cli/api/upgrade/run/files-changed.test.mjs+++ b/packages/cli/api/upgrade/run/files-changed.test.mjs@@ -19,6 +19,7 @@ import {versions,getTransformsBetween,} from '../../../assets/codemods/registry.mjs';+import {REPO_ROOT} from '../../../test-utils/repo-root.mjs';const SLOW = 60_000;@@ -88,7 +89,7 @@ describe('upgrade receipt — filesChanged across core and integration codemods'/** @param {{integrationCodemod: boolean}} options */async function run(options) {- const dir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-files-changed-'));+ const dir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-files-changed-'));dirs.push(dir);seed(dir, options);const tier = await authoringTier();diff --git a/packages/cli/assets/codemods/__tests__/runner.symlinks.test.mjs b/packages/cli/assets/codemods/__tests__/runner.symlinks.test.mjsindex 1d9950db82..946b282aa8 100644--- a/packages/cli/assets/codemods/__tests__/runner.symlinks.test.mjs+++ b/packages/cli/assets/codemods/__tests__/runner.symlinks.test.mjs@@ -11,13 +11,14 @@ import * as fs from 'node:fs';import * as path from 'node:path';import {runCodemods} from '../runner.mjs';import {findSourceFiles as findIntegrationSourceFiles} from '../run-codemod.mjs';+import {REPO_ROOT} from '../../../test-utils/repo-root.mjs';let tmpDir;let originalCwd;beforeEach(() => {originalCwd = process.cwd();- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-runner-test-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-runner-test-'));process.chdir(tmpDir);});diff --git a/packages/cli/assets/codemods/__tests__/runner.test.mjs b/packages/cli/assets/codemods/__tests__/runner.test.mjsindex 8ed47d95bb..a547067e1b 100644--- a/packages/cli/assets/codemods/__tests__/runner.test.mjs+++ b/packages/cli/assets/codemods/__tests__/runner.test.mjs@@ -4,6 +4,7 @@ import {afterEach, beforeEach, describe, expect, it} from 'vitest';import * as fs from 'node:fs';import * as path from 'node:path';import {runCodemods} from '../runner.mjs';+import {REPO_ROOT} from '../../../test-utils/repo-root.mjs';let tmpDir;let originalCwd;@@ -12,7 +13,7 @@ beforeEach(() => {originalCwd = process.cwd();// Repo-local temp dir (not /tmp) to mirror the integration-runner tests and// avoid any Vite dynamic-import quirks with absolute /tmp paths.- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-runner-test-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-runner-test-'));process.chdir(tmpDir);});diff --git a/packages/cli/assets/codemods/__tests__/runner.unparseable.test.mjs b/packages/cli/assets/codemods/__tests__/runner.unparseable.test.mjsindex 19edbef4ee..45afe73eed 100644--- a/packages/cli/assets/codemods/__tests__/runner.unparseable.test.mjs+++ b/packages/cli/assets/codemods/__tests__/runner.unparseable.test.mjs@@ -19,13 +19,14 @@ import migrateThemeSelectors, {import migrateDeprecatedThemeSurface, {meta as migrateDeprecatedThemeSurfaceMeta,} from '../transforms/v0.7.0/migrate-deprecated-theme-surface.mjs';+import {REPO_ROOT} from '../../../test-utils/repo-root.mjs';let tmpDir;let originalCwd;beforeEach(() => {originalCwd = process.cwd();- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-runner-test-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-runner-test-'));process.chdir(tmpDir);});diff --git a/packages/cli/assets/codemods/integration-discovery.test.mjs b/packages/cli/assets/codemods/integration-discovery.test.mjsindex 078586ea85..fdb2f8077b 100644--- a/packages/cli/assets/codemods/integration-discovery.test.mjs+++ b/packages/cli/assets/codemods/integration-discovery.test.mjs@@ -9,6 +9,7 @@ import {selectIntegrationCodemods,} from './integration-discovery.mjs';import {runIntegrationCodemods} from './integration-runner.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';let tmpDir;let originalCwd;@@ -51,7 +52,7 @@ function scaffold(codemodFiles) {// modules in the temp package can import it without node_modules wiring.beforeEach(() => {originalCwd = process.cwd();- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-codemod-test-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-codemod-test-'));process.chdir(tmpDir);});diff --git a/packages/cli/assets/codemods/transforms/v0.1.3/__tests__/migrate-layout-components-to-experimental.test.mjs b/packages/cli/assets/codemods/transforms/v0.1.3/__tests__/migrate-layout-components-to-experimental.test.mjsindex efc4de0a72..9626a0eb75 100644--- a/packages/cli/assets/codemods/transforms/v0.1.3/__tests__/migrate-layout-components-to-experimental.test.mjs+++ b/packages/cli/assets/codemods/transforms/v0.1.3/__tests__/migrate-layout-components-to-experimental.test.mjs@@ -3,6 +3,7 @@import {describe, it, expect} from 'vitest';import * as fs from 'node:fs';import * as path from 'node:path';+import {REPO_ROOT} from '../../../../../test-utils/repo-root.mjs';/*** Invoke the transform directly with a configured jscodeshift api, mirroring@@ -364,7 +365,7 @@ describe('migrate-layout-components-to-experimental — end-to-end via runConfigconst originalCwd = process.cwd();const tmpDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-v013-codemod-test-'),+ path.join(REPO_ROOT, '.astryx-v013-codemod-test-'),);try {process.chdir(tmpDir);@@ -422,7 +423,7 @@ describe('migrate-layout-components-to-experimental — end-to-end via runConfigconst originalCwd = process.cwd();const tmpDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-v013-codemod-test-'),+ path.join(REPO_ROOT, '.astryx-v013-codemod-test-'),);const configSource = `// Generated Astryx config.const config = {@@ -477,7 +478,7 @@ export default config;const originalCwd = process.cwd();const tmpDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-v013-codemod-test-'),+ path.join(REPO_ROOT, '.astryx-v013-codemod-test-'),);const configSource = `const config = {};config.layout = { components: { KpiCard: '@/components/KpiCard' } };@@ -529,7 +530,7 @@ export default config;const originalCwd = process.cwd();const tmpDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-v013-codemod-test-'),+ path.join(REPO_ROOT, '.astryx-v013-codemod-test-'),);try {process.chdir(tmpDir);diff --git a/packages/cli/assets/codemods/transforms/v0.3.0/__tests__/authoring-migration.e2e.test.mjs b/packages/cli/assets/codemods/transforms/v0.3.0/__tests__/authoring-migration.e2e.test.mjsindex fabaf9cf19..75b1d4914e 100644--- a/packages/cli/assets/codemods/transforms/v0.3.0/__tests__/authoring-migration.e2e.test.mjs+++ b/packages/cli/assets/codemods/transforms/v0.3.0/__tests__/authoring-migration.e2e.test.mjs@@ -25,6 +25,7 @@ import {parseIntegration} from '../../../../../authoring/integration/parse.mjs';import {parseDoc} from '../../../../../authoring/doctypes/parse.mjs';import {parseTemplate} from '../../../../../authoring/doctypes/template/parse.mjs';import {parseCodemod} from '../../../../../authoring/codemod/parse.mjs';+import {REPO_ROOT} from '../../../../../test-utils/repo-root.mjs';/** Run the full v0.3.0 authoring migration (both codemods, in release order). */async function migrate(source, filePath = 'input.ts') {@@ -40,7 +41,7 @@ async function migrate(source, filePath = 'input.ts') {let tmpDir;beforeAll(() => {// Repo-local temp dir: Vite's dynamic import blocks /tmp.- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-codemod-e2e-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-codemod-e2e-'));});afterAll(() => {fs.rmSync(tmpDir, {recursive: true, force: true});diff --git a/packages/cli/authoring/doctypes/parse.test.mjs b/packages/cli/authoring/doctypes/parse.test.mjsindex f2e2bb7e42..772750e37c 100644--- a/packages/cli/authoring/doctypes/parse.test.mjs+++ b/packages/cli/authoring/doctypes/parse.test.mjs@@ -18,6 +18,7 @@ import {parseComponent} from './component/parse.mjs';import {parseHook} from './hook/parse.mjs';import {parseReference} from './reference/parse.mjs';import {loadComponentDoc} from '../../foundation/discovery/component-loader.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';const goodComponent = {type: 'component',@@ -340,7 +341,7 @@ describe('loadComponentDoc (end-to-end load boundary)', () => {let tmpDir;beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doc-test-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-doc-test-'));});afterEach(() => {diff --git a/packages/cli/clients/cli/cli-command.test.mjs b/packages/cli/clients/cli/cli-command.test.mjsindex 2daa489ba1..4a8cd182a3 100644--- a/packages/cli/clients/cli/cli-command.test.mjs+++ b/packages/cli/clients/cli/cli-command.test.mjs@@ -18,6 +18,7 @@ import {} from '../../foundation/env/cli-command.mjs';import {getCliInvocation} from '../../foundation/env/package-manager.mjs';import {loadProjectForHelp} from './index.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';const BIN = path.resolve(import.meta.dirname, 'bin', 'astryx.mjs');@@ -26,7 +27,7 @@ let tmpDir;beforeEach(() => {// Repo-local, so Vite permits importing the integration manifest.- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-cli-command-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-cli-command-'));});afterEach(() => {diff --git a/packages/cli/clients/cli/commands/component-replacement.text.test.mjs b/packages/cli/clients/cli/commands/component-replacement.text.test.mjsindex d1897dc9bf..991c7de4be 100644--- a/packages/cli/clients/cli/commands/component-replacement.text.test.mjs+++ b/packages/cli/clients/cli/commands/component-replacement.text.test.mjs@@ -12,6 +12,7 @@ import * as fs from 'node:fs';import * as path from 'node:path';import {runCli} from '../../../test-utils/run-cli.mjs';import {COMPONENT_REPLACES_CLI} from '../../../foundation/integrations/cli-requirement.mjs';+import {REPO_ROOT} from '../../../test-utils/repo-root.mjs';vi.setConfig({testTimeout: 60_000, hookTimeout: 60_000});@@ -63,7 +64,7 @@ function writeIntegration(name, components, peers) {beforeAll(() => {// Under the repository so the project resolves the workspace's Core.tmpDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-component-replacement-text-'),+ path.join(REPO_ROOT, '.astryx-component-replacement-text-'),);writeIntegration('@acme/nav',diff --git a/packages/cli/clients/cli/commands/docs.depth.test.mjs b/packages/cli/clients/cli/commands/docs.depth.test.mjsindex dfb7376f8d..619c63677c 100644--- a/packages/cli/clients/cli/commands/docs.depth.test.mjs+++ b/packages/cli/clients/cli/commands/docs.depth.test.mjs@@ -4,6 +4,7 @@ import * as fs from 'node:fs';import * as path from 'node:path';import {afterEach, beforeEach, describe, expect, it} from 'vitest';import {runCli} from '../../../test-utils/run-cli.mjs';+import {REPO_ROOT} from '../../../test-utils/repo-root.mjs';const SLOW = 60_000;@@ -11,7 +12,7 @@ const SLOW = 60_000;let tmpDir;beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-docs-depth-test-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-docs-depth-test-'));});afterEach(() => {diff --git a/packages/cli/clients/cli/commands/doctor-integration.package-json.test.mjs b/packages/cli/clients/cli/commands/doctor-integration.package-json.test.mjsindex 2f7c67cbf6..4fefd8823d 100644--- a/packages/cli/clients/cli/commands/doctor-integration.package-json.test.mjs+++ b/packages/cli/clients/cli/commands/doctor-integration.package-json.test.mjs@@ -5,13 +5,14 @@ import * as fs from 'node:fs';import * as path from 'node:path';import {runCli} from '../../../test-utils/run-cli.mjs';import {validateIntegration} from '../../../api/integration/validate-integration.mjs';+import {REPO_ROOT} from '../../../test-utils/repo-root.mjs';const NO_MANIFEST = 'No astryx.integration.* found next to package.json.';let tmpDir;beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-pkgjson-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-doctor-pkgjson-'));fs.writeFileSync(path.join(tmpDir, 'package.json'), '{"name": "@acme/widgets",}\n');fs.writeFileSync(path.join(tmpDir, 'astryx.integration.mjs'),diff --git a/packages/cli/clients/cli/commands/doctor.test.mjs b/packages/cli/clients/cli/commands/doctor.test.mjsindex 71c7535441..197bbe51aa 100644--- a/packages/cli/clients/cli/commands/doctor.test.mjs+++ b/packages/cli/clients/cli/commands/doctor.test.mjs@@ -20,6 +20,7 @@ import {} from '../../../api/doctor/doctor.mjs';import {MIN_NODE_VERSION} from '../../../foundation/env/node-version.mjs';import {CLI_VERSION, linkThisCliAsProjectCli} from '../../../test-utils/release-fixtures.mjs';+import {REPO_ROOT} from '../../../test-utils/repo-root.mjs';let tmpDir;let logCalls;@@ -473,7 +474,7 @@ describe('doctor — text output mirrors the JSON', () => {describe('doctor — a configured integration that cannot load', () => {it('sets exit code 1 and reports it in the JSON', async () => {- const dir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-exit-'));+ const dir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-doctor-exit-'));const prevCwd = process.cwd();const prevExit = process.exitCode;process.exitCode = undefined;diff --git a/packages/cli/clients/cli/commands/integration-add.controls.test.mjs b/packages/cli/clients/cli/commands/integration-add.controls.test.mjsindex 218696c5fb..41a8f743da 100644--- a/packages/cli/clients/cli/commands/integration-add.controls.test.mjs+++ b/packages/cli/clients/cli/commands/integration-add.controls.test.mjs@@ -7,12 +7,13 @@ import {createProgram} from '../index.mjs';import {buildManifest} from '../lib/manifest.mjs';import {runCli} from '../../../test-utils/run-cli.mjs';import {doc as fnDoc} from '../../../api/integration/integrationAdd.doc.mjs';+import {REPO_ROOT} from '../../../test-utils/repo-root.mjs';let tmpDir;beforeEach(() => {tmpDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-integration-add-controls-'),+ path.join(REPO_ROOT, '.astryx-integration-add-controls-'),);fs.writeFileSync(path.join(tmpDir, 'package.json'),diff --git a/packages/cli/clients/cli/commands/integration-authoring.test.mjs b/packages/cli/clients/cli/commands/integration-authoring.test.mjsindex 8d63addcc4..3eb30035ed 100644--- a/packages/cli/clients/cli/commands/integration-authoring.test.mjs+++ b/packages/cli/clients/cli/commands/integration-authoring.test.mjs@@ -4,6 +4,7 @@ import {afterEach, beforeEach, describe, expect, it} from 'vitest';import * as fs from 'node:fs';import * as path from 'node:path';import {runCli} from '../../../test-utils/run-cli.mjs';+import {REPO_ROOT} from '../../../test-utils/repo-root.mjs';let tmpDir;@@ -13,7 +14,7 @@ function parseEnvelope(stdout) {beforeEach(() => {tmpDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-integration-authoring-cli-'),+ path.join(REPO_ROOT, '.astryx-integration-authoring-cli-'),);fs.writeFileSync(path.join(tmpDir, 'package.json'),diff --git a/packages/cli/clients/cli/commands/integration-check.test.mjs b/packages/cli/clients/cli/commands/integration-check.test.mjsindex eb115c8ed5..43180ada00 100644--- a/packages/cli/clients/cli/commands/integration-check.test.mjs+++ b/packages/cli/clients/cli/commands/integration-check.test.mjs@@ -13,6 +13,7 @@ import * as path from 'node:path';import {runCli} from '../../../test-utils/run-cli.mjs';import {warmIntegrationChecks} from '../../../test-utils/warm-integration-checks.mjs';import {discoverCoreTemplates} from '../../../foundation/discovery/template-adapter.mjs';+import {REPO_ROOT} from '../../../test-utils/repo-root.mjs';// The checks' one-time start in this file runs here, while the file is// collected, so no test carries it. That start is TypeScript and its lib@@ -28,7 +29,7 @@ let tmpDir;beforeEach(() => {// Under the repository, so the components check resolves Core.tmpDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-integration-check-cli-'),+ path.join(REPO_ROOT, '.astryx-integration-check-cli-'),);});diff --git a/packages/cli/clients/cli/commands/integration-real-world.test.mjs b/packages/cli/clients/cli/commands/integration-real-world.test.mjsindex 07f0c1a743..666d1378c9 100644--- a/packages/cli/clients/cli/commands/integration-real-world.test.mjs+++ b/packages/cli/clients/cli/commands/integration-real-world.test.mjs@@ -12,6 +12,7 @@ import * as fs from 'node:fs';import * as path from 'node:path';import {spawnSync} from 'node:child_process';import {requireNatively} from '../../../test-utils/native-require.mjs';+import {REPO_ROOT} from '../../../test-utils/repo-root.mjs';const require = requireNatively(import.meta.url);/** @type {typeof import('../../../test-utils/run-cli.mjs')} */@@ -77,7 +78,7 @@ afterEach(() => {describe('integration authoring across a real npm package boundary', () => {it('authors, packs, installs, upgrades, and builds contributed source', async () => {rootDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-theme-provider-consumer-'),+ path.join(REPO_ROOT, '.astryx-theme-provider-consumer-'),);const providerDir = path.join(rootDir, 'provider');const consumerDir = path.join(rootDir, 'consumer');diff --git a/packages/cli/clients/cli/commands/upgrade.ascii-output.test.mjs b/packages/cli/clients/cli/commands/upgrade.ascii-output.test.mjsindex da80914b7f..084ef4e17b 100644--- a/packages/cli/clients/cli/commands/upgrade.ascii-output.test.mjs+++ b/packages/cli/clients/cli/commands/upgrade.ascii-output.test.mjs@@ -11,6 +11,7 @@ import * as fs from 'node:fs';import * as path from 'node:path';import {runCli} from '../../../test-utils/run-cli.mjs';import {generateCompressedIndex} from '../../../foundation/agent-docs/agent-docs.mjs';+import {REPO_ROOT} from '../../../test-utils/repo-root.mjs';const NON_ASCII = /[\u0080-\uFFFF]/;@@ -37,7 +38,7 @@ async function nonAsciiLines(args) {beforeEach(() => {// Repo-local so the config module can be imported under Vitest.- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-upgrade-ascii-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-upgrade-ascii-'));write('package.json', JSON.stringify({name: 'consumer', private: true}));write('node_modules/@astryxdesign/core/package.json',diff --git a/packages/cli/clients/cli/commands/upgrade.config-ordering.test.mjs b/packages/cli/clients/cli/commands/upgrade.config-ordering.test.mjsindex b0743d4271..c55e56fa8d 100644--- a/packages/cli/clients/cli/commands/upgrade.config-ordering.test.mjs+++ b/packages/cli/clients/cli/commands/upgrade.config-ordering.test.mjs@@ -31,6 +31,7 @@ import {registerUpgrade} from './upgrade.mjs';import {Project} from '../../../foundation/config/project.mjs';import {generateCompressedIndex} from '../../../foundation/agent-docs/agent-docs.mjs';import {CLI_VERSION} from '../../../test-utils/release-fixtures.mjs';+import {REPO_ROOT} from '../../../test-utils/repo-root.mjs';let tmpDir;let originalCwd;@@ -41,7 +42,7 @@ let exitCode;beforeEach(() => {originalCwd = process.cwd();// Repo-local temp dir: under cwd so Vite allows the astryx.config import.- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-upgrade-order-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-upgrade-order-'));process.chdir(tmpDir);logCalls = [];stdoutCalls = [];diff --git a/packages/cli/clients/cli/commands/upgrade.integration-policy.test.mjs b/packages/cli/clients/cli/commands/upgrade.integration-policy.test.mjsindex 69e4a21664..906186de43 100644--- a/packages/cli/clients/cli/commands/upgrade.integration-policy.test.mjs+++ b/packages/cli/clients/cli/commands/upgrade.integration-policy.test.mjs@@ -23,6 +23,7 @@ import {generateCompressedIndex,renderAgentDocsBlock,} from '../../../foundation/agent-docs/agent-docs.mjs';+import {REPO_ROOT} from '../../../test-utils/repo-root.mjs';let tmpDir;let originalCwd;@@ -33,7 +34,7 @@ let exitCode;beforeEach(() => {originalCwd = process.cwd();// Repo-local temp dir: under cwd so Vite allows config/integration imports.- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-upgrade-policy-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-upgrade-policy-'));process.chdir(tmpDir);logCalls = [];errCalls = [];diff --git a/packages/cli/foundation/agent-docs/agent-docs.test.mjs b/packages/cli/foundation/agent-docs/agent-docs.test.mjsindex 56ef39a1de..e13d8bfea3 100644--- a/packages/cli/foundation/agent-docs/agent-docs.test.mjs+++ b/packages/cli/foundation/agent-docs/agent-docs.test.mjs@@ -25,6 +25,7 @@ import {AgentDocsHomeError,resolveAgentDocsRoot,} from './agent-docs.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';let tmpDir;@@ -355,7 +356,7 @@ describe('generateCompressedIndex', () => {describe('renderAgentDocsBlock', () => {it('produces repeatable target bytes from configured manifests', async () => {const projectDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-agent-doc-render-'),+ path.join(REPO_ROOT, '.astryx-agent-doc-render-'),);try {fs.writeFileSync(@@ -433,7 +434,7 @@ describe('renderAgentDocsBlock', () => {});it('renders doc tokens in an integration line for the project', async () => {const projectDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-agent-doc-tokens-'),+ path.join(REPO_ROOT, '.astryx-agent-doc-tokens-'),);try {fs.writeFileSync(@@ -479,7 +480,7 @@ describe('renderAgentDocsBlock', () => {it('rejects a package label that could alter managed block structure', async () => {const projectDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-agent-doc-label-'),+ path.join(REPO_ROOT, '.astryx-agent-doc-label-'),);try {fs.writeFileSync(diff --git a/packages/cli/foundation/config/config-cache.test.mjs b/packages/cli/foundation/config/config-cache.test.mjsindex 619657f99f..8ac6d74474 100644--- a/packages/cli/foundation/config/config-cache.test.mjs+++ b/packages/cli/foundation/config/config-cache.test.mjs@@ -9,11 +9,12 @@ import {configContentHash,NO_CONFIG_HASH,} from './config-cache.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';let tmpDir;beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-cache-test-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-cache-test-'));});afterEach(() => {diff --git a/packages/cli/foundation/config/project-themes.test.mjs b/packages/cli/foundation/config/project-themes.test.mjsindex de024a2c40..1022ec714d 100644--- a/packages/cli/foundation/config/project-themes.test.mjs+++ b/packages/cli/foundation/config/project-themes.test.mjs@@ -5,6 +5,7 @@ import * as fs from 'node:fs';import * as path from 'node:path';import {Project} from './project.mjs';import {BUNDLED_THEME_PACKAGE} from '../discovery/theme-discovery.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';let tmpDir;@@ -40,7 +41,7 @@ export default {type: 'theme', name: '${slug}', displayName: 'Ocean', descriptio}beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-project-themes-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-project-themes-'));fs.writeFileSync(path.join(tmpDir, 'package.json'),JSON.stringify({diff --git a/packages/cli/foundation/config/project.issues.test.mjs b/packages/cli/foundation/config/project.issues.test.mjsindex 46b48bba3b..32edbd833e 100644--- a/packages/cli/foundation/config/project.issues.test.mjs+++ b/packages/cli/foundation/config/project.issues.test.mjs@@ -14,6 +14,7 @@import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';import * as fs from 'node:fs';import * as path from 'node:path';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';const templateImports = vi.hoisted(() => ({count: 0}));@@ -44,7 +45,7 @@ beforeEach(async () => {originalCwd = process.cwd();// Repo-local, because Vite blocks the dynamic import of modules under /tmp.tmpDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-project-issues-test-'),+ path.join(REPO_ROOT, '.astryx-project-issues-test-'),);process.chdir(tmpDir);fs.writeFileSync(diff --git a/packages/cli/foundation/config/project.test.mjs b/packages/cli/foundation/config/project.test.mjsindex 907473a701..17d490ca09 100644--- a/packages/cli/foundation/config/project.test.mjs+++ b/packages/cli/foundation/config/project.test.mjs@@ -9,6 +9,7 @@ import {InMemoryConfigCache} from './config-cache.mjs';import {getCliInvocation} from '../env/package-manager.mjs';import * as componentDiscovery from '../discovery/component-discovery.mjs';import {discoverCoreTemplates} from '../discovery/template-adapter.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';let tmpDir;let originalCwd;@@ -200,7 +201,7 @@ function scaffoldLocalPackage({name = '@acme/local'} = {}) {beforeEach(() => {originalCwd = process.cwd();- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-project-test-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-project-test-'));process.chdir(tmpDir);});diff --git a/packages/cli/foundation/config/theme-state.test.mjs b/packages/cli/foundation/config/theme-state.test.mjsindex 053b1789c2..3c507bf04d 100644--- a/packages/cli/foundation/config/theme-state.test.mjs+++ b/packages/cli/foundation/config/theme-state.test.mjs@@ -12,12 +12,13 @@ import {renderThemeModule,resolveThemeModule,} from './theme-state.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';/** @type {string[]} */const dirs = [];function project(pkg = {name: 'app'}) {- const dir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-theme-state-'));+ const dir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-theme-state-'));dirs.push(dir);fs.writeFileSync(path.join(dir, 'package.json'), `${JSON.stringify(pkg)}\n`);return dir;@@ -132,7 +133,7 @@ describe('generated theme-module state', () => {it('rejects a generated-module write through a symlink outside the project', () => {const dir = project();const outside = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-theme-state-outside-'),+ path.join(REPO_ROOT, '.astryx-theme-state-outside-'),);dirs.push(outside);fs.symlinkSync(outside, path.join(dir, 'src'));diff --git a/packages/cli/foundation/discovery/authoring-self-docs.test.mjs b/packages/cli/foundation/discovery/authoring-self-docs.test.mjsindex 1f770f7eb9..36c0f09279 100644--- a/packages/cli/foundation/discovery/authoring-self-docs.test.mjs+++ b/packages/cli/foundation/discovery/authoring-self-docs.test.mjs@@ -20,6 +20,7 @@ import {doc as graphFieldsDoc} from '../../authoring/doctypes/base/graph-fields.import {doc as namespaceDoc} from '../../authoring/doctypes/namespace/namespace.doc.mjs';import {doc as referenceDoc} from '../../authoring/doctypes/reference/reference.doc.mjs';import {docs} from '../../api/docs/docs.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';const SLOW = 60_000;@@ -150,7 +151,7 @@ describe('auditAuthoringSelfDocs', () => {let root;beforeEach(() => {- root = fs.mkdtempSync(path.join(process.cwd(), '.astryx-self-docs-'));+ root = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-self-docs-'));fs.mkdirSync(path.join(root, 'kept'));fs.writeFileSync(path.join(root, 'kept', 'kept.doc.mjs'),diff --git a/packages/cli/foundation/discovery/authoring-surface.test.mjs b/packages/cli/foundation/discovery/authoring-surface.test.mjsindex d282741afe..1ab9ec7cdf 100644--- a/packages/cli/foundation/discovery/authoring-surface.test.mjs+++ b/packages/cli/foundation/discovery/authoring-surface.test.mjs@@ -14,6 +14,7 @@ import {tracePublicAuthoringTypes,} from './authoring-surface.mjs';import {docs} from '../../api/docs/docs.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';const SLOW = 60_000;@@ -35,7 +36,7 @@ afterEach(() => {* @returns {string}*/function tree(files) {- const root = fs.mkdtempSync(path.join(process.cwd(), '.astryx-surface-'));+ const root = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-surface-'));roots.push(root);for (const [rel, content] of Object.entries(files)) {const abs = path.join(root, rel);diff --git a/packages/cli/foundation/discovery/cli-self-docs.test.mjs b/packages/cli/foundation/discovery/cli-self-docs.test.mjsindex 33f8bc2892..82973062dd 100644--- a/packages/cli/foundation/discovery/cli-self-docs.test.mjs+++ b/packages/cli/foundation/discovery/cli-self-docs.test.mjs@@ -26,6 +26,7 @@ import {} from './cli-self-docs.mjs';import {routeSegment} from './docs-section-key.mjs';import {formatCliCommand} from '../env/package-manager.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';const SLOW = 60_000;@@ -37,7 +38,7 @@ afterAll(() => {/** Write `files` (relative path -> content) under a fresh directory. */function writeTree(/** @type {Record<string, string>} */ files) {- const root = fs.mkdtempSync(path.join(process.cwd(), '.astryx-cli-docs-'));+ const root = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-cli-docs-'));tmpRoots.push(root);for (const [rel, content] of Object.entries(files)) {const file = path.join(root, rel);diff --git a/packages/cli/foundation/discovery/docs-discovery.test.mjs b/packages/cli/foundation/discovery/docs-discovery.test.mjsindex 361387e8a5..a2a31180b0 100644--- a/packages/cli/foundation/discovery/docs-discovery.test.mjs+++ b/packages/cli/foundation/discovery/docs-discovery.test.mjs@@ -21,6 +21,7 @@ import {mergeTopic,problemsInTopic,} from './docs-discovery.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';let tmpDir;@@ -54,7 +55,7 @@ function integration(name, topics, {docsDir = 'docs'} = {}) {}beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-docs-test-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-docs-test-'));});afterEach(() => {diff --git a/packages/cli/foundation/discovery/theme-imports.test.mjs b/packages/cli/foundation/discovery/theme-imports.test.mjsindex 31009533fc..72f8adce23 100644--- a/packages/cli/foundation/discovery/theme-imports.test.mjs+++ b/packages/cli/foundation/discovery/theme-imports.test.mjs@@ -4,13 +4,14 @@ import {afterEach, describe, expect, it} from 'vitest';import * as fs from 'node:fs';import * as path from 'node:path';import {resolveThemeImports} from './theme-imports.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';/** @type {string[]} */const dirs = [];function project() {const dir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-theme-imports-'),+ path.join(REPO_ROOT, '.astryx-theme-imports-'),);dirs.push(dir);fs.writeFileSync(path.join(dir, 'package.json'), '{"name":"app"}\n');diff --git a/packages/cli/foundation/doc-compiler/doc-loads.test.mjs b/packages/cli/foundation/doc-compiler/doc-loads.test.mjsindex d1cfe3a58d..6bf62718a2 100644--- a/packages/cli/foundation/doc-compiler/doc-loads.test.mjs+++ b/packages/cli/foundation/doc-compiler/doc-loads.test.mjs@@ -346,7 +346,7 @@ const RUNNERS = {sites: ['.import() ×2','createJiti ×2',- 'import(<computed>) ×4',+ 'importUrl ×4','importUserModule ×2',],},@@ -368,6 +368,10 @@ const RUNNERS = {runs: 'the render worker, so a page that never finishes can be stopped',sites: ['worker_threads.Worker'],},+ 'foundation/fs/import-url.mjs': {+ runs: 'the doc file at a file URL, for the doc importers',+ sites: ['import(<computed>)'],+ },'foundation/fs/module-loader.mjs': {runs: 'user modules (config, manifests, handlers, codemods): natively, through jiti, or by require for a fresh CommonJS read',sites: [@@ -435,6 +439,7 @@ const RUNNERS = {*/const LOADER_MODULES = {'foundation/doc-compiler/import.mjs': [],+ 'foundation/fs/import-url.mjs': [],'foundation/fs/module-loader.mjs': ['findPresentFiles'],// loadTopicModule hands back a topic's raw doc.'foundation/discovery/docs-discovery.mjs': [diff --git a/packages/cli/foundation/doc-compiler/import.mjs b/packages/cli/foundation/doc-compiler/import.mjsindex 6edcedea54..e5e23ef273 100644--- a/packages/cli/foundation/doc-compiler/import.mjs+++ b/packages/cli/foundation/doc-compiler/import.mjs@@ -24,6 +24,7 @@import {pathToFileURL} from 'node:url';import {createJiti} from 'jiti';+import {importUrl} from '../fs/import-url.mjs';import {importUserModule} from '../fs/module-loader.mjs';import {fileStamp, recordContentRead} from '../fs/read-record.mjs';@@ -105,14 +106,14 @@ export function importTemplateModule(file) {jsxJiti ??= createJiti(import.meta.url, {jsx: true});return jsxJiti.import(first);}- return import(`file://${first}`);+ return importUrl(`file://${first}`);},changed =>changed.endsWith('.ts')? createJiti(import.meta.url, {jsx: true, moduleCache: false}).import(changed,)- : import(freshUrl(changed)),+ : importUrl(freshUrl(changed)),);}@@ -126,7 +127,7 @@ export function importNativeModule(file) {return importCurrent(file,'native',- first => import(pathToFileURL(first).href),- changed => import(freshUrl(changed)),+ first => importUrl(pathToFileURL(first).href),+ changed => importUrl(freshUrl(changed)),);}diff --git a/packages/cli/foundation/fs/import-url.mjs b/packages/cli/foundation/fs/import-url.mjsnew file mode 100644index 0000000000..064d623102--- /dev/null+++ b/packages/cli/foundation/fs/import-url.mjs@@ -0,0 +1,22 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file The dynamic import of an authored module by its file URL.+ *+ * @input An absolute `file:` URL, with any query its caller adds to name a+ * fresh module.+ * @output The module's namespace object, as a plain `import()` gives it.+ * @position Called by the doc importers (../doc-compiler/import.mjs). The+ * node test project loads this file natively, as the CLI does+ * (vitest.config.ts). The doc files that a catalog command imports then load+ * natively as well, without a request to the test runner for each of them.+ */++/**+ * Import the module at `url`.+ * @param {string} url an absolute `file:` URL+ * @returns {Promise<any>}+ */+export function importUrl(url) {+ return import(url);+}diff --git a/packages/cli/foundation/fs/module-loader.test.mjs b/packages/cli/foundation/fs/module-loader.test.mjsindex df4576fca8..26dfa18df8 100644--- a/packages/cli/foundation/fs/module-loader.test.mjs+++ b/packages/cli/foundation/fs/module-loader.test.mjs@@ -13,11 +13,12 @@ import {importUserModule,loadModuleWithParser,} from './module-loader.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';let tmpDir;beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-module-loader-test-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-module-loader-test-'));});afterEach(() => {diff --git a/packages/cli/foundation/integrations/autolink.test.mjs b/packages/cli/foundation/integrations/autolink.test.mjsindex b0c7c5e362..fb15ed7102 100644--- a/packages/cli/foundation/integrations/autolink.test.mjs+++ b/packages/cli/foundation/integrations/autolink.test.mjs@@ -22,11 +22,12 @@ import {resolveInstalledPackageDir,} from './autolink.mjs';import {Project} from '../config/project.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';let tmpDir;beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-autolink-test-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-autolink-test-'));});afterEach(() => {diff --git a/packages/cli/foundation/integrations/contribution-inventory.test.mjs b/packages/cli/foundation/integrations/contribution-inventory.test.mjsindex ccfdefa7e5..4444900fe0 100644--- a/packages/cli/foundation/integrations/contribution-inventory.test.mjs+++ b/packages/cli/foundation/integrations/contribution-inventory.test.mjs@@ -8,11 +8,12 @@ import {compareIdentities,findSourceOnlyCandidates,} from './contribution-inventory.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';let tmpDir;beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-ci-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-ci-'));});afterEach(() => {diff --git a/packages/cli/foundation/integrations/integration-warnings.test.mjs b/packages/cli/foundation/integrations/integration-warnings.test.mjsindex 9451537846..0686227e2f 100644--- a/packages/cli/foundation/integrations/integration-warnings.test.mjs+++ b/packages/cli/foundation/integrations/integration-warnings.test.mjs@@ -15,13 +15,14 @@ import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';import * as fs from 'node:fs';import * as path from 'node:path';import {warnOnIntegrationIssues} from './integration-warnings.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';let tmpDir;let errSpy;let errLines;beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-warn-it-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-warn-it-'));errLines = [];errSpy = vi.spyOn(console, 'error').mockImplementation((...args) => {errLines.push(args.join(' '));diff --git a/packages/cli/foundation/integrations/integrations.test.mjs b/packages/cli/foundation/integrations/integrations.test.mjsindex 446a7b0537..c3f96edbcd 100644--- a/packages/cli/foundation/integrations/integrations.test.mjs+++ b/packages/cli/foundation/integrations/integrations.test.mjs@@ -10,6 +10,7 @@ import {resolvePackageDir,} from './integrations.mjs';import {discover} from '../../api/discover/discover.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';let tmpDir;let originalCwd;@@ -34,7 +35,7 @@ function writeManifestPackage(beforeEach(() => {originalCwd = process.cwd();tmpDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-integration-test-'),+ path.join(REPO_ROOT, '.astryx-integration-test-'),);fs.writeFileSync(path.join(tmpDir, 'package.json'),diff --git a/packages/cli/foundation/integrations/manifest-writer.test.mjs b/packages/cli/foundation/integrations/manifest-writer.test.mjsindex 0735b97614..d733fb88e6 100644--- a/packages/cli/foundation/integrations/manifest-writer.test.mjs+++ b/packages/cli/foundation/integrations/manifest-writer.test.mjs@@ -9,6 +9,7 @@ import {IntegrationRootConflictError,patchIntegrationRoot,} from './manifest-writer.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';let tmpDir;@@ -20,7 +21,7 @@ function manifest(source = 'export default {};\n', ext = 'mjs') {}beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-manifest-writer-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-manifest-writer-'));});afterEach(() => {@@ -198,7 +199,7 @@ describe('patchIntegrationRoot', () => {it('refuses a manifest symlink whose target escapes the package', async () => {fs.writeFileSync(path.join(tmpDir, 'package.json'), '{"name":"fixture"}\n');const outside = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-manifest-outside-'),+ path.join(REPO_ROOT, '.astryx-manifest-outside-'),);try {const target = path.join(outside, 'integration.mjs');diff --git a/packages/cli/foundation/integrations/provider-conflicts.test.mjs b/packages/cli/foundation/integrations/provider-conflicts.test.mjsindex 9a18796514..a7a5561ca5 100644--- a/packages/cli/foundation/integrations/provider-conflicts.test.mjs+++ b/packages/cli/foundation/integrations/provider-conflicts.test.mjs@@ -14,6 +14,7 @@ import * as fs from 'node:fs';import * as path from 'node:path';import {fileURLToPath} from 'node:url';import {requireNatively} from '../../test-utils/native-require.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';const require = requireNatively(import.meta.url);/** @type {typeof import('../config/project.mjs')} */@@ -39,7 +40,7 @@ let chartsManifest;beforeEach(() => {consumer = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-provider-conflict-'),+ path.join(REPO_ROOT, '.astryx-provider-conflict-'),);const scope = path.join(consumer, 'node_modules', '@astryxdesign');fs.mkdirSync(scope, {recursive: true});diff --git a/packages/cli/foundation/integrations/provider-resolution.test.mjs b/packages/cli/foundation/integrations/provider-resolution.test.mjsindex 29749c1b43..049f2ad8da 100644--- a/packages/cli/foundation/integrations/provider-resolution.test.mjs+++ b/packages/cli/foundation/integrations/provider-resolution.test.mjs@@ -15,12 +15,13 @@ import {packageKey, resolveProviders} from './provider-resolution.mjs';import {markProviderConflicts} from './integrations.mjs';import {autolinkIntegrations} from './autolink.mjs';import {Project, providerLedgerOf} from '../config/project.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';let tmpDir;beforeEach(() => {tmpDir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-provider-resolution-'),+ path.join(REPO_ROOT, '.astryx-provider-resolution-'),);});diff --git a/packages/cli/foundation/integrations/public-imports.test.mjs b/packages/cli/foundation/integrations/public-imports.test.mjsindex c338ffe5ea..4918f182ed 100644--- a/packages/cli/foundation/integrations/public-imports.test.mjs+++ b/packages/cli/foundation/integrations/public-imports.test.mjs@@ -28,6 +28,7 @@ import {strictIssues,} from '../../api/integration/check/check.mjs';import {CLI_ROOT} from '../fs/paths.mjs';+import {REPO_ROOT} from '../../test-utils/repo-root.mjs';const CODES = new Set(['component_import_not_exported',@@ -97,7 +98,7 @@ function writeTsconfig() {}beforeEach(() => {- dir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-public-imports-'));+ dir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-public-imports-'));writeTsconfig();write('package.json',diff --git a/packages/cli/test-utils/repo-root.mjs b/packages/cli/test-utils/repo-root.mjsnew file mode 100644index 0000000000..5c56b61f17--- /dev/null+++ b/packages/cli/test-utils/repo-root.mjs@@ -0,0 +1,18 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file The repository root: the folder that test projects are made in.+ * @input Nothing; the path comes from this file's own place in the repository.+ * @output `REPO_ROOT`, an absolute path without a trailing separator.+ * @position Imported by tests that make a temporary project inside the+ * repository, so that the project resolves the workspace's packages. The path+ * never changes during a run. `process.cwd()` changes while a CLI run that+ * outlived its test still holds the process (run-cli.mjs).+ */++import * as path from 'node:path';+import {fileURLToPath} from 'node:url';++export const REPO_ROOT = path.resolve(+ fileURLToPath(new URL('../../..', import.meta.url)),+);diff --git a/packages/cli/test-utils/run-cli.mjs b/packages/cli/test-utils/run-cli.mjsindex d43ff99ce8..10cf8cc52f 100644--- a/packages/cli/test-utils/run-cli.mjs+++ b/packages/cli/test-utils/run-cli.mjs@@ -17,12 +17,180 @@** The real bin bootstrap + true process boundary are covered separately by a* small e2e smoke that still spawns the binary.+ *+ * Runs take turns. Each run holds the process's working folder, console, exit+ * and argv until it settles. The end of a test waits for its run. A run whose+ * test has already ended, for example by a timeout, does not start. A run still+ * going a test timeout after its test ended is stuck: the harness puts the+ * process back and releases the run. A released run that wakes later cannot+ * end the test worker, move the working folder or write into a later run.*/+import {AsyncLocalStorage} from 'node:async_hooks';+import {clearTimeout, setTimeout} from 'node:timers';import {format} from 'node:util';+import {onTestFinished} from 'vitest';import {createProgram} from '../clients/cli/index.mjs';import {setJsonMode} from '../foundation/response/json.mjs';import {handleCommanderError} from '../clients/cli/lib/json-shim.mjs';+import {REPO_ROOT} from './repo-root.mjs';++/** Settles when the latest run has given the process back. */+let lastTurn = Promise.resolve();++/**+ * One run's hold on the process.+ * @typedef {object} Run+ * @property {boolean} finished the run's test has ended+ * @property {boolean} released the run was stuck when its test ended. The+ * harness put the process back and ignores what the run does after that.+ * @property {(() => void) | null} restore puts back what the run changed in+ * the process, once+ * @property {boolean} [wroteLate] a write of the released run was dropped+ */++/**+ * The run that the calling code belongs to, through each async step of that+ * run, and the calls of released runs that the harness ignored. Copies of this+ * module share them, since a test file can load it natively and through+ * Vitest. Released runs that have not settled are kept too.+ * @type {{context: AsyncLocalStorage<Run>, ignored: {call: string, args: unknown[]}[], alive: Set<Run>, guarded?: boolean}}+ */+const runs = /** @type {any} */ (+ globalThis[Symbol.for('astryx.test-utils.run-cli')] ??= {+ context: new AsyncLocalStorage(),+ ignored: [],+ alive: new Set(),+ }+);++/** The console as this module found it, for the harness's own warnings. */+const warn = console.warn.bind(console);++/** Whether the calling code belongs to a released run. */+function inReleasedRun() {+ return runs.context.getStore()?.released === true;+}++/**+ * Record a call of a released run that the harness ignored, and warn. A+ * released run that wakes means that something hung, so CI logs show it.+ * @param {string} call+ * @param {unknown[]} args+ */+function noteIgnored(call, args) {+ runs.ignored.push({call, args});+ const shown = args.map(arg => JSON.stringify(arg)).join(', ');+ warn(+ `runCli: the harness ignored ${call}(${shown}) of a run released after its test ended.`,+ );+}++/**+ * Whether the calling code belongs to a released run. If so, the caller drops+ * the write. The write is recorded, and the first one of each run warns.+ * @param {string} text+ */+function isReleasedRunWrite(text) {+ const run = runs.context.getStore();+ if (!run?.released) return false;+ runs.ignored.push({call: 'write', args: [text]});+ if (!run.wroteLate) {+ run.wroteLate = true;+ warn(+ 'runCli: the harness drops the output of a run released after its test ended.',+ );+ }+ return true;+}++/**+ * Whether the calling code belongs to a released run. If so, the call is+ * recorded, and the caller ignores it.+ * @param {string} call+ * @param {unknown[]} args+ */+function isReleasedRunCall(call, args) {+ if (!inReleasedRun()) return false;+ noteIgnored(call, args);+ return true;+}++if (/** @type {any} */ (globalThis).__vitest_worker__ && !runs.guarded) {+ runs.guarded = true;+ // A released run can wake up after its test. Its exit must not end the test+ // worker, and its chdir must not move a later test.+ const exit = process.exit;+ const chdir = process.chdir;+ // @ts-expect-error - test-only monkeypatch+ process.exit = code => {+ if (!isReleasedRunCall('exit', [code])) exit.call(process, code);+ };+ process.chdir = directory => {+ if (!isReleasedRunCall('chdir', [directory])) {+ chdir.call(process, directory);+ }+ };+}++/**+ * The calls that released runs made, which the harness ignored.+ * @returns {{call: string, args: unknown[]}[]}+ */+export function ignoredCallsOfReleasedRuns() {+ return runs.ignored.slice();+}++/**+ * When the run's test ends, wait for the run, then let the next run start.+ * The wait is the test's own timeout, which is the node project's+ * `testTimeout` unless the test sets one. A run still going then is stuck:+ * the harness puts the process back and releases the run. The test's result+ * is set before this, so a release never turns a failure into a pass. Outside+ * a test (in a hook, or outside Vitest), the caller awaits the run.+ * @param {Run} run+ * @param {Promise<void>} turn settles when the run has given the process back+ * @param {() => void} giveBack lets the next run start+ */+function watchTest(run, turn, giveBack) {+ if (!(/** @type {any} */ (globalThis).__vitest_worker__)) return;+ try {+ onTestFinished(+ async ({task}) => {+ run.finished = true;+ // Node's own timers: a test's fake timers do not reach them.+ const settled = await new Promise(resolve => {+ const timer = setTimeout(() => resolve(false), task.timeout);+ void turn.then(() => {+ clearTimeout(timer);+ resolve(true);+ });+ });+ if (settled) return;+ run.released = true;+ runs.alive.add(run);+ run.restore?.();+ giveBack();+ },+ // The wait above bounds this hook, so the hook has no timeout of its own.+ Number.POSITIVE_INFINITY,+ );+ } catch {+ // Not in a test.+ }+}++/**+ * Return the process to `dir`, or to the repository root once `dir` is gone.+ * @param {string} dir+ */+function restoreCwd(dir) {+ try {+ process.chdir(dir);+ } catch {+ process.chdir(REPO_ROOT);+ }+}/** Thrown by the trapped process.exit to unwind parseAsync with the exit code. */class ExitSignal extends Error {@@ -50,7 +218,51 @@ export async function runCli(args, cwdOrOpts) {typeof cwdOrOpts === 'string' ? cwdOrOpts : cwdOrOpts && cwdOrOpts.cwd;const allCommands =typeof cwdOrOpts === 'object' && cwdOrOpts?.allCommands === true;+ const previous = lastTurn;+ /** @type {() => void} */+ let giveBack = () => {};+ /** @type {Promise<void>} */+ const ownTurn = new Promise(resolve => {+ giveBack = resolve;+ });+ const turn = previous.then(() => ownTurn);+ lastTurn = turn;+ /** @type {Run} */+ const run = {finished: false, released: false, restore: null};+ watchTest(run, turn, giveBack);+ await previous;+ try {+ return await runs.context.run(run, () =>+ runNow(args, cwd, allCommands, run),+ );+ } finally {+ runs.alive.delete(run);+ giveBack();+ }+}++/** What a run whose test has ended gives back, having touched nothing. */+const NOT_STARTED = {+ status: 1,+ code: 1,+ stdout: '',+ stderr: 'runCli: the test ended before this run could start.\n',+};++/**+ * Run the program once, holding the process until the run settles.+ * @param {string[]} args+ * @param {string | undefined} cwd+ * @param {boolean} allCommands+ * @param {Run} run+ * @returns {Promise<{status: number, code: number, stdout: string, stderr: string}>}+ */+async function runNow(args, cwd, allCommands, run) {+ if (run.finished) return NOT_STARTED;const program = await createProgram(allCommands ? undefined : {argv: args});+ // Building the program can outlast the test, whose cleanup may then have+ // removed `cwd`.+ if (run.finished) return NOT_STARTED;// Commander's own exits (parse errors, --help, --version, unknown option)// throw a CommanderError instead of calling process.exit.program.exitOverride();@@ -69,35 +281,58 @@ export async function runCli(args, cwdOrOpts) {let status = 0;+ run.restore = () => {+ run.restore = null;+ if (cwd) restoreCwd(origCwd);+ process.argv = origArgv;+ console.log = origLog;+ console.error = origError;+ process.stdout.write = origStdout;+ process.stderr.write = origStderr;+ process.exit = origExit;+ process.exitCode = 0;+ setJsonMode(false);+ };+// Capture at the console.* layer: Vitest replaces console.log/console.error// with its own collectors, so the CLI's output never reaches the raw streams —// patching process.stdout.write alone captures nothing. `format(...)` + "\n"// reproduces console.log's own formatting so parseJson(stdout) sees exactly// the envelope the binary would print. Direct stream writes (rare) are also// captured for fidelity.+ // A released run's writes go nowhere, so they never reach this run's output.console.log = (/** @type {unknown[]} */ ...a) => {- out.push(format(...a) + '\n');+ const text = format(...a) + '\n';+ if (!isReleasedRunWrite(text)) out.push(text);};console.error = (/** @type {unknown[]} */ ...a) => {- err.push(format(...a) + '\n');+ const text = format(...a) + '\n';+ if (!isReleasedRunWrite(text)) err.push(text);};// @ts-expect-error - test-only monkeypatchprocess.stdout.write = c => {- out.push(typeof c === 'string' ? c : c.toString());+ const text = typeof c === 'string' ? c : c.toString();+ if (!isReleasedRunWrite(text)) out.push(text);return true;};// @ts-expect-error - test-only monkeypatchprocess.stderr.write = c => {- err.push(typeof c === 'string' ? c : c.toString());+ const text = typeof c === 'string' ? c : c.toString();+ if (!isReleasedRunWrite(text)) err.push(text);return true;};// @ts-expect-error - test-only monkeypatchprocess.exit = code => {+ if (isReleasedRunCall('exit', [code])) return;throw new ExitSignal(Number(code) || 0);};// Reset the global CLI/JSON-contract state so runs never bleed into each other.setJsonMode(false);+ // An exit code here, while a released run is alive, is that run's late write.+ if (process.exitCode && runs.alive.size > 0) {+ noteIgnored('exitCode', [process.exitCode]);+ }process.exitCode = 0;process.__xdsJsonHandled = false;@@ -108,11 +343,21 @@ export async function runCli(args, cwdOrOpts) {// identically in-process.process.argv = ['node', 'astryx', ...args];- if (cwd) process.chdir(cwd);try {+ if (cwd) process.chdir(cwd);await program.parseAsync(['node', 'astryx', ...args]);- // Text-mode error paths set process.exitCode rather than calling exit.- if (status === 0 && process.exitCode) status = Number(process.exitCode) || 0;+ // Text-mode error paths set process.exitCode rather than calling exit. A+ // released run that wakes during this run can set it too. The harness+ // cannot tell the writes apart: exitCode is an accessor that the process+ // object does not let anyone replace. So it warns.+ if (status === 0 && process.exitCode) {+ status = Number(process.exitCode) || 0;+ if (runs.alive.size > 0) {+ warn(+ `runCli: this run's exit code ${status} may come from a run released after its test ended.`,+ );+ }+ }} catch (e) {if (e instanceof ExitSignal) {status = e.code;@@ -145,15 +390,8 @@ export async function runCli(args, cwdOrOpts) {throw e; // genuine unexpected error — surface it}} finally {- if (cwd) process.chdir(origCwd);- process.argv = origArgv;- console.log = origLog;- console.error = origError;- process.stdout.write = origStdout;- process.stderr.write = origStderr;- process.exit = origExit;- process.exitCode = 0;- setJsonMode(false);+ // A stuck run's test already put these back.+ run.restore?.();}return {status, code: status, stdout: out.join(''), stderr: err.join('')};diff --git a/packages/cli/test-utils/run-cli.stuck.test.mjs b/packages/cli/test-utils/run-cli.stuck.test.mjsnew file mode 100644index 0000000000..e801d88518--- /dev/null+++ b/packages/cli/test-utils/run-cli.stuck.test.mjs@@ -0,0 +1,138 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file A runCli run that outlives its test. The test still fails by its own+ * timeout, and the next test gets the process back. What the run does when it+ * wakes changes nothing: its exit, chdir and exit code are ignored, and its+ * writes reach no later run.+ */++import {afterAll, describe, expect, it, onTestFinished, vi} from 'vitest';+import * as fs from 'node:fs';+import * as path from 'node:path';++const late = vi.hoisted(() => {+ /** A promise and the function that settles it. */+ const signal = () => {+ /** @type {() => void} */+ let mark = () => {};+ const promise = new Promise(resolve => {+ mark = () => resolve(undefined);+ });+ return {promise, mark: () => mark()};+ };+ return {+ laterRunStarted: signal(),+ woken: signal(),+ laterRunDone: signal(),+ exitCodeSet: signal(),+ };+});++/**+ * A program that runCli can drive, which builds at once, so a short test+ * timeout measures the run alone.+ * @param {() => Promise<unknown>} parseAsync+ */+function fakeProgram(parseAsync) {+ return {exitOverride() {}, parseAsync};+}++vi.mock('../clients/cli/index.mjs', async importOriginal => {+ /** @type {typeof import('../clients/cli/index.mjs')} */+ const original = await importOriginal();+ return {+ ...original,+ /** @param {Parameters<typeof original.createProgram>[0]} options */+ createProgram: async options => {+ const command = options?.argv?.[0];+ if (command === 'stuck') {+ // Settles never. It wakes once a later run has started.+ return fakeProgram(async () => {+ const held = process.cwd();+ await late.laterRunStarted.promise;+ process.exit(7);+ process.chdir(held);+ console.log('from the released run');+ late.woken.mark();+ // Between runs, the released run sets an exit code too.+ await late.laterRunDone.promise;+ process.exitCode = 3;+ late.exitCodeSet.mark();+ return new Promise(() => {});+ });+ }+ if (command === 'later') {+ return fakeProgram(async () => {+ late.laterRunStarted.mark();+ await late.woken.promise;+ console.log('from the later run');+ });+ }+ return original.createProgram(options);+ },+ };+});++const {REPO_ROOT} = await import('./repo-root.mjs');+const {ignoredCallsOfReleasedRuns, runCli} = await import('./run-cli.mjs');++const dir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-run-cli-stuck-'));++/** The stuck run's test timeout, and so how long its release waits. */+const TEST_TIMEOUT_MS = 500;++afterAll(() => {+ fs.rmSync(dir, {recursive: true, force: true});+});++describe('runCli', () => {+ /** @type {{state?: string, error: string, cwd: string} | null} */+ let atTestEnd = null;++ it.fails(+ 'a test whose run never settles fails by its own timeout',+ async () => {+ const pending = runCli(['stuck'], dir);+ // Registered after runCli's own hook, so it runs before the release.+ onTestFinished(({task}) => {+ atTestEnd = {+ state: task.result?.state,+ error: String(task.result?.errors?.[0]?.message),+ cwd: process.cwd(),+ };+ });+ await pending;+ },+ TEST_TIMEOUT_MS,+ );++ it('the next test runs, and the released run changes nothing when it wakes', async () => {+ expect(atTestEnd).toMatchObject({+ state: 'fail',+ cwd: fs.realpathSync(dir),+ });+ expect(atTestEnd?.error).toMatch(`timed out in ${TEST_TIMEOUT_MS}ms`);+ expect(process.cwd()).toBe(REPO_ROOT);++ const later = await runCli(['later']);++ expect(later).toMatchObject({+ status: 0,+ stdout: 'from the later run\n',+ stderr: '',+ });+ late.laterRunDone.mark();+ await late.exitCodeSet.promise;+ const version = await runCli(['--version']);+ expect(version.status).toBe(0);+ expect(process.exitCode).toBe(0);+ expect(ignoredCallsOfReleasedRuns()).toEqual([+ {call: 'exit', args: [7]},+ {call: 'chdir', args: [fs.realpathSync(dir)]},+ {call: 'write', args: ['from the released run\n']},+ {call: 'exitCode', args: [3]},+ ]);+ expect(process.cwd()).toBe(REPO_ROOT);+ });+});diff --git a/packages/cli/test-utils/run-cli.turns.test.mjs b/packages/cli/test-utils/run-cli.turns.test.mjsnew file mode 100644index 0000000000..7ea7214dc9--- /dev/null+++ b/packages/cli/test-utils/run-cli.turns.test.mjs@@ -0,0 +1,88 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file runCli runs take turns, and a run that outlives its test gives the+ * process back before the next test starts.+ */++import {afterAll, describe, expect, it} from 'vitest';+import * as fs from 'node:fs';+import * as path from 'node:path';+import {REPO_ROOT} from './repo-root.mjs';+import {runCli} from './run-cli.mjs';++/** @type {string[]} */+const made = [];++afterAll(() => {+ for (const dir of made) fs.rmSync(dir, {recursive: true, force: true});+});++/**+ * A project in the repository that contributes one component.+ * @param {string} component+ * @returns {Promise<string>}+ */+async function projectWith(component) {+ const dir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-run-cli-turns-'));+ made.push(dir);+ fs.writeFileSync(+ path.join(dir, 'package.json'),+ `${JSON.stringify({+ name: `@acme/${component.toLowerCase()}`,+ version: '1.0.0',+ files: [],+ })}\n`,+ );+ const added = await runCli(+ ['integration', 'add', 'component', component, '--json'],+ dir,+ );+ expect(added.status).toBe(0);+ return dir;+}++/**+ * The component names that a `component --list --json` run printed.+ * @param {{stdout: string}} result+ * @returns {string[]}+ */+function listed(result) {+ const {data} = JSON.parse(result.stdout.trim());+ return Object.values(data.components)+ .flat()+ .map(component => component.name);+}++describe('runCli', () => {+ it('two runs at once each read their own folder', async () => {+ const alpha = await projectWith('AlphaWidget');+ const beta = await projectWith('BetaWidget');+ const [inAlpha, inBeta] = await Promise.all([+ runCli(['component', '--list', '--json'], alpha),+ runCli(['component', '--list', '--json'], beta),+ ]);+ expect(listed(inAlpha)).toContain('AlphaWidget');+ expect(listed(inAlpha)).not.toContain('BetaWidget');+ expect(listed(inBeta)).toContain('BetaWidget');+ expect(listed(inBeta)).not.toContain('AlphaWidget');+ });++ /** @type {Promise<unknown> | undefined} */+ let leftBehind;++ it('a test can end while its run still holds the process', async () => {+ const dir = await projectWith('GammaWidget');+ // The test ends without awaiting the run, as a test that timed out does.+ leftBehind = runCli(['component', '--list', '--json'], dir);+ });++ it('the next test starts with the process back in the repository', async () => {+ const seen = new Set([process.cwd()]);+ const sampler = setInterval(() => seen.add(process.cwd()), 1);+ await leftBehind;+ clearInterval(sampler);+ seen.add(process.cwd());+ expect([...seen]).toEqual([REPO_ROOT]);+ });+});diff --git a/packages/cli/test/integration-check-failures.test.mjs b/packages/cli/test/integration-check-failures.test.mjsindex cdd3159005..d2dc13e486 100644--- a/packages/cli/test/integration-check-failures.test.mjs+++ b/packages/cli/test/integration-check-failures.test.mjs@@ -26,6 +26,7 @@ import * as path from 'node:path';import {fileURLToPath} from 'node:url';import {afterAll, beforeAll, describe, expect, it} from 'vitest';import {requireNatively} from '../test-utils/native-require.mjs';+import {REPO_ROOT} from '../test-utils/repo-root.mjs';const require = requireNatively(import.meta.url);/** @type {typeof import('../api/integration/check/check.mjs')} */@@ -167,7 +168,7 @@ let result;beforeAll(async () => {// Under the repository, so the components check resolves Core. Every kind// of root, so every field a check's result can carry is present.- pkg = fs.mkdtempSync(path.join(process.cwd(), '.astryx-check-failures-'));+ pkg = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-check-failures-'));const write = (/** @type {string} */ rel, /** @type {string} */ text) => {fs.mkdirSync(path.dirname(path.join(pkg, rel)), {recursive: true});fs.writeFileSync(path.join(pkg, rel), text);diff --git a/packages/cli/test/inv28-package-provenance.test.mjs b/packages/cli/test/inv28-package-provenance.test.mjsindex d920bdd021..fe9d07a118 100644--- a/packages/cli/test/inv28-package-provenance.test.mjs+++ b/packages/cli/test/inv28-package-provenance.test.mjs@@ -20,6 +20,7 @@ import * as fs from 'node:fs';import * as os from 'node:os';import * as path from 'node:path';import {runCli} from '../test-utils/run-cli.mjs';+import {REPO_ROOT} from '../test-utils/repo-root.mjs';const CORE = '@astryxdesign/core';const CLI = '@astryxdesign/cli';@@ -229,7 +230,7 @@ describe('INV28: theme add names the package that owns the added theme', () => {*/function appWithThemePackage() {const dir = fs.mkdtempSync(- path.join(process.cwd(), '.astryx-inv28-theme-'),+ path.join(REPO_ROOT, '.astryx-inv28-theme-'),);dirs.push(dir);/** @param {string} rel @param {string} content */diff --git a/packages/cli/test/invalid-component-metadata.regression.test.mjs b/packages/cli/test/invalid-component-metadata.regression.test.mjsindex 63f38a0fdd..c958e3bbd9 100644--- a/packages/cli/test/invalid-component-metadata.regression.test.mjs+++ b/packages/cli/test/invalid-component-metadata.regression.test.mjs@@ -36,6 +36,7 @@ import {component} from '../api/component/component.mjs';import {search} from '../api/search/search.mjs';import {build} from '../api/build/build.mjs';import {doctor} from '../api/doctor/doctor.mjs';+import {REPO_ROOT} from '../test-utils/repo-root.mjs';// ── Fixture ────────────────────────────────────────────────────────@@ -149,7 +150,7 @@ function scaffoldInvalidDoc() {beforeEach(() => {originalCwd = process.cwd();- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-fr9-invalid-doc-'));+ tmpDir = fs.mkdtempSync(path.join(REPO_ROOT, '.astryx-fr9-invalid-doc-'));process.chdir(tmpDir);});diff --git a/vitest.config.ts b/vitest.config.tsindex 1bae5f51e0..91a66573f5 100644--- a/vitest.config.ts+++ b/vitest.config.ts@@ -200,9 +200,19 @@ export default defineConfig({// `.doc.mjs` documentation modules the docs catalog imports by the// hundred (doctor's first case: 0.7 s natively, 4.7 s inlined).// Both grow several times over on a loaded box. Mocks keep working- // from inlined callers.+ // from inlined callers. The CLI's doc importers import doc files+ // through `import-url.mjs`, which loads natively too, so its imports+ // make no request to Vitest's main process. Each request waits in+ // line behind every worker: `template --list` imports 771 doc files,+ // 0.6 s alone and up to 26 s on a loaded box.server: {- deps: {external: [/\/packages\/core\/dist\//, /\.doc\.mjs$/]},+ deps: {+ external: [+ /\/packages\/core\/dist\//,+ /\.doc\.mjs$/,+ /\/packages\/cli\/foundation\/fs\/import-url\.mjs$/,+ ],+ },},// Several CLI suites spawn a fresh `node bin/astryx.mjs` per assertion// (real process boundary). Under the forks pool these cold-starts can