Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions packages/cli/src/commands/doctor-config-env-overlay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,15 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import { doctorConfig } from '../utils/__tests__/doctor-config.js';
import Doctor, {
readDotenvFiles,
withDotenvOverlay,
withDotenvOverlayAsync,
environmentSourcesCheck,
} from './doctor.js';

const HERE = path.dirname(fileURLToPath(import.meta.url));
/** `packages/cli` — the oclif root the real command is loaded against below. */
const CLI_ROOT = path.resolve(HERE, '..', '..');

/**
* The escape is written as `\x1b`, never as the byte itself: one raw control
* character makes `grep` treat the whole file as binary, and a test file no
Expand Down Expand Up @@ -257,7 +253,7 @@ describe('os doctor, end to end, against a config that reads .env at top level',
}) as never);

try {
await Doctor.run([], { root: CLI_ROOT });
await Doctor.run([], await doctorConfig());
} catch (err) {
if (!(err instanceof Error) || !err.message.startsWith('__PROCESS_EXIT__')) throw err;
} finally {
Expand Down
8 changes: 2 additions & 6 deletions packages/cli/src/commands/doctor-config-load-cause.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,10 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import { doctorConfig } from '../utils/__tests__/doctor-config.js';
import Doctor, { configLoadFailureCheck } from './doctor.js';

const HERE = path.dirname(fileURLToPath(import.meta.url));
/** `packages/cli` — the oclif root the real command is loaded against below. */
const CLI_ROOT = path.resolve(HERE, '..', '..');

/**
* The escape is written as `\x1b`, never as the byte itself: one raw control
* character makes `grep` treat the whole file as binary, and a test file no
Expand Down Expand Up @@ -199,7 +195,7 @@ describe('os doctor, end to end, against a config that cannot be loaded', () =>
}) as never);

try {
await Doctor.run(argv, { root: CLI_ROOT });
await Doctor.run(argv, await doctorConfig());
} catch (err) {
if (!(err instanceof Error) || !err.message.startsWith('__PROCESS_EXIT__')) throw err;
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,12 @@ import os from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import { doctorConfig } from '../utils/__tests__/doctor-config.js';
import Doctor from './doctor.js';

const HERE = path.dirname(fileURLToPath(import.meta.url));
/** `packages/cli/src/commands` — where oclif's pattern strategy finds commands. */
const COMMANDS_DIR = HERE;
/** `packages/cli` — the oclif root the real command is loaded against below. */
const CLI_ROOT = path.resolve(HERE, '..', '..');
const DOCTOR_SRC = path.join(COMMANDS_DIR, 'doctor.ts');

/**
Expand Down Expand Up @@ -251,7 +250,7 @@ describe('os doctor --scan-deprecations, end to end', () => {
}) as never);

try {
await Doctor.run(argv, { root: CLI_ROOT });
await Doctor.run(argv, await doctorConfig());
} catch (err) {
if (!(err instanceof Error) || !err.message.startsWith('__PROCESS_EXIT__')) throw err;
} finally {
Expand Down
10 changes: 3 additions & 7 deletions packages/cli/src/commands/doctor-ledger-dir-authority.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ import { describe, it, expect, beforeAll, afterEach, vi } from 'vitest';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import { doctorConfig } from '../utils/__tests__/doctor-config.js';
import Doctor, {
installedPackageLedgerDirAuthorityMissingCheck,
installedPackageLedgerSkippedEntriesCheck,
Expand All @@ -62,10 +62,6 @@ import Doctor, {
// where the same shape cost 30 ejected merge-queue builds in one night.
import '@objectstack/cloud-connection';

const HERE = path.dirname(fileURLToPath(import.meta.url));
/** `packages/cli` — the oclif root the real command is loaded against below. */
const CLI_ROOT = path.resolve(HERE, '..', '..');

/**
* The escape is written as `\x1b`, never as the byte itself: one raw control
* character makes `grep` treat the whole file as binary, and a test file no
Expand Down Expand Up @@ -258,7 +254,7 @@ describe('os doctor, end to end, against a reader that declares no ledger direct
}) as never);

try {
await FreshDoctor.run(argv, { root: CLI_ROOT });
await FreshDoctor.run(argv, await doctorConfig());
} catch (err) {
if (!(err instanceof Error) || !err.message.startsWith('__PROCESS_EXIT__')) throw err;
} finally {
Expand Down Expand Up @@ -410,7 +406,7 @@ describe('os doctor, end to end, skipped-entries fix quotes the resolved directo
}) as never);

try {
await Doctor.run(['--verbose'], { root: CLI_ROOT });
await Doctor.run(['--verbose'], await doctorConfig());
} catch (err) {
if (!(err instanceof Error) || !err.message.startsWith('__PROCESS_EXIT__')) throw err;
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ import { describe, it, expect, beforeAll, beforeEach, afterEach, vi } from 'vite
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import { doctorConfig } from '../utils/__tests__/doctor-config.js';
import Doctor from './doctor.js';

// [#10126] Pay the first transform of these dist-resolved workspace deps at MODULE
Expand All @@ -76,10 +76,6 @@ import Doctor from './doctor.js';
// where the same shape cost 30 ejected merge-queue builds in one night.
import '@objectstack/cloud-connection';

const HERE = path.dirname(fileURLToPath(import.meta.url));
/** `packages/cli` — the oclif root the real command is loaded against below. */
const CLI_ROOT = path.resolve(HERE, '..', '..');

/**
* The escape is written as `\x1b`, never as the byte itself: one raw control
* character makes `grep` treat the whole file as binary, and a test file no
Expand Down Expand Up @@ -224,7 +220,7 @@ describe('os doctor reports ledger readability under every posture (#5429)', ()
}) as never);

try {
await Doctor.run(argv, { root: CLI_ROOT });
await Doctor.run(argv, await doctorConfig());
} catch (err) {
if (!(err instanceof Error) || !err.message.startsWith('__PROCESS_EXIT__')) throw err;
} finally {
Expand Down
14 changes: 5 additions & 9 deletions packages/cli/src/commands/doctor-ledger-read-failure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ import { describe, it, expect, beforeAll, beforeEach, afterEach, vi } from 'vite
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import { doctorConfig } from '../utils/__tests__/doctor-config.js';
import Doctor, {
installedPackageLedgerFailureCheck,
installedPackageLedgerReaderFailureCheck,
Expand All @@ -100,10 +100,6 @@ import Doctor, {
// where the same shape cost 30 ejected merge-queue builds in one night.
import '@objectstack/cloud-connection';

const HERE = path.dirname(fileURLToPath(import.meta.url));
/** `packages/cli` — the oclif root the real command is loaded against below. */
const CLI_ROOT = path.resolve(HERE, '..', '..');

/**
* The escape is written as `\x1b`, never as the byte itself: one raw control
* character makes `grep` treat the whole file as binary, and a test file no
Expand Down Expand Up @@ -439,7 +435,7 @@ describe('os doctor, end to end, against an unreadable installed-package ledger'
}) as never);

try {
await Doctor.run(argv, { root: CLI_ROOT });
await Doctor.run(argv, await doctorConfig());
} catch (err) {
if (!(err instanceof Error) || !err.message.startsWith('__PROCESS_EXIT__')) throw err;
} finally {
Expand Down Expand Up @@ -765,7 +761,7 @@ describe('the optional package INSTALLED BUT UNLOADABLE is reported (#5644)', ()
}) as never);

try {
await FreshDoctor.run(['--verbose'], { root: CLI_ROOT });
await FreshDoctor.run(['--verbose'], await doctorConfig());
} catch (err) {
if (!(err instanceof Error) || !err.message.startsWith('__PROCESS_EXIT__')) throw err;
} finally {
Expand Down Expand Up @@ -837,7 +833,7 @@ describe('the optional package INSTALLED BUT UNLOADABLE is reported (#5644)', ()

let exitCode: number | undefined;
try {
await FreshDoctor.run(['--verbose'], { root: CLI_ROOT });
await FreshDoctor.run(['--verbose'], await doctorConfig());
} catch (err) {
if (!(err instanceof Error) || !err.message.startsWith('__PROCESS_EXIT__')) throw err;
exitCode = Number(err.message.split(':')[1]);
Expand Down Expand Up @@ -931,7 +927,7 @@ describe('the optional package being genuinely ABSENT stays completely silent (#
}) as never);

try {
await FreshDoctor.run(['--verbose'], { root: CLI_ROOT });
await FreshDoctor.run(['--verbose'], await doctorConfig());
} catch (err) {
if (!(err instanceof Error) || !err.message.startsWith('__PROCESS_EXIT__')) throw err;
} finally {
Expand Down
7 changes: 2 additions & 5 deletions packages/cli/src/commands/doctor-node-env-default.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import { doctorConfig } from '../utils/__tests__/doctor-config.js';
import Doctor, {
nodeEnvCheck,
nodeEnvSourcePosture,
Expand All @@ -73,9 +73,6 @@ import Doctor, {
readDotenvFiles,
} from './doctor.js';

/** `packages/cli` — the oclif root the real command is loaded against below. */
const CLI_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..');

/**
* `chalk` may or may not emit SGR codes depending on TTY detection.
*
Expand Down Expand Up @@ -337,7 +334,7 @@ describe('[#5673] os doctor, end to end — the row reaches the report', () => {
}) as never);

try {
await Doctor.run(argv, { root: CLI_ROOT });
await Doctor.run(argv, await doctorConfig());
} catch (err) {
if (!(err instanceof Error) || !err.message.startsWith('__PROCESS_EXIT__')) throw err;
} finally {
Expand Down
9 changes: 3 additions & 6 deletions packages/cli/src/commands/doctor-unexamined-spec-tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,10 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import { doctorConfig } from '../utils/__tests__/doctor-config.js';
import Doctor, { monorepoTreeSkipNotice } from './doctor.js';

/** `packages/cli` — the oclif root the real command is loaded against below. */
const CLI_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..');

/**
* `chalk` may or may not emit SGR codes depending on TTY detection.
*
Expand Down Expand Up @@ -175,7 +172,7 @@ describe('os doctor, end to end, in a user-app cwd with no packages/spec', () =>
}) as never);

try {
await Doctor.run(argv, { root: CLI_ROOT });
await Doctor.run(argv, await doctorConfig());
} catch (err) {
if (!(err instanceof Error) || !err.message.startsWith('__PROCESS_EXIT__')) throw err;
} finally {
Expand Down Expand Up @@ -289,7 +286,7 @@ describe('os doctor, end to end, in a monorepo-shaped cwd — the no-regression
}) as never);

try {
await Doctor.run(argv, { root: CLI_ROOT });
await Doctor.run(argv, await doctorConfig());
} catch (err) {
if (!(err instanceof Error) || !err.message.startsWith('__PROCESS_EXIT__')) throw err;
} finally {
Expand Down
36 changes: 36 additions & 0 deletions packages/cli/src/utils/__tests__/doctor-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* The oclif `Config` the in-process `os doctor` suites hand `Doctor.run()`.
*
* `Doctor.run(argv, { root })` makes oclif load a Config from the package root,
* and this package ships no `oclif.manifest.json`, so that load builds the
* command manifest by importing every compiled command under `dist/commands`:
* 6.6 s of each file's first test, measured locally (#23181). `os doctor`
* reads none of it — `doctor.ts` never touches `this.config` — so this Config
* is the package's own `package.json` with only `oclif.commands` dropped. The
* hooks (the `preparse` separator strip) and everything else still load from
* the same manifest, and it loads in tens of milliseconds.
*
* ⛔ Not for a suite that asks the Config for a command (`findCommand`,
* `config.commands`, `runCommand`): this one has none.
*/

import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { Config } from '@oclif/core';

/** `packages/cli` — the root a `Doctor.run()` loads its Config from. */
const CLI_ROOT = resolve(fileURLToPath(import.meta.url), '../../../..');

let loaded: Promise<Config> | undefined;

/** One Config per test file, loaded on first use. */
export function doctorConfig(): Promise<Config> {
loaded ??= (async () => {
const pjson = JSON.parse(readFileSync(resolve(CLI_ROOT, 'package.json'), 'utf8'));
return Config.load({ root: CLI_ROOT, pjson: { ...pjson, oclif: { ...pjson.oclif, commands: undefined } } });
})();
return loaded;
}
Loading