Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(cli): doctor validates the integrations it reports on (#6619)

Joey9e80db19089a
diff --git a/.changeset/cli-doctor-validates-integrations.md b/.changeset/cli-doctor-validates-integrations.md
new file mode 100644
index 0000000000..a9a60b49c4
--- /dev/null
+++ b/.changeset/cli-doctor-validates-integrations.md
@@ -0,0 +1,11 @@
+---
+'@astryxdesign/cli': patch
+---
+
+[fix] `astryx doctor` no longer reports an integration it could not check as absent or complete (#6619)
+
+- An installed dependency whose `astryx.integration.*` manifest cannot be loaded is still kept out of the loaded set, but `implicit-integrations` now names it and says it contributes nothing. Before, doctor said that no installed dependency ships a manifest. The check stays informational, and `astryx doctor integration validate <package>` gives the details.
+- `implicit-integrations` lists only the roots that exist on disk. A package whose declared roots are missing is reported as contributing nothing, with the missing roots named. Before, it listed every root the manifest declared.
+- `provider-identity` says how many loaded integrations it could not read, instead of counting only the readable ones.
+
+@josephfarina
diff --git a/packages/cli/api/doctor/doctor.mjs b/packages/cli/api/doctor/doctor.mjs
index 11d147993a..d396e82697 100644
--- a/packages/cli/api/doctor/doctor.mjs
+++ b/packages/cli/api/doctor/doctor.mjs
@@ -26,7 +26,11 @@ import * as path from 'node:path';
import {MIN_NODE_VERSION, isNodeVersionSupported} from '../../foundation/env/node-version.mjs';
import {CLI_ROOT, findCoreDir, findInstalledPackage} from '../../foundation/fs/paths.mjs';
import {explainPackageManager, getCliInvocation} from '../../foundation/env/package-manager.mjs';
-import {findConfigPath, Project} from '../../foundation/config/project.mjs';
+import {
+ findConfigPath,
+ Project,
+ providerLedgerOf,
+} from '../../foundation/config/project.mjs';
import {DocsCatalog} from '../../foundation/discovery/docs-discovery.mjs';
import {buildDocsIndexData} from '../../foundation/discovery/docs-section-key.mjs';
import {
@@ -76,6 +80,8 @@ import {semverCompare, isValidSemver, satisfiesRange} from '../../foundation/env
* @property {string|null} [docsCatalogError] - Why the project's docs catalog
* could not be built, when it could not.
* @property {Array<{package: string, code: string, severity: 'warning'|'error', message: string}>|null} [integrationIssues]
+ * @property {Array<{spec: string, error: string}>|null} [autolinkFailures]
+ * installed dependencies whose integration manifest could not be loaded
* Combined project-level integration issues, including cross-package template replacement warnings.
* @property {Error|null} [configError] - Error thrown while resolving the config
* path (e.g. multiple config files present), surfaced by checkConfig as a FAIL.
@@ -417,6 +423,9 @@ export function checkImplicitIntegrations(ctx) {
const implicit = ctx.integrations.filter(
integration => integration.__autolinked,
);
+ // A dependency whose manifest cannot be loaded leaves no loaded record, so
+ // without this line doctor would say no dependency ships a manifest at all.
+ const unreadable = describeUnreadableManifests(ctx.autolinkFailures ?? []);
if (implicit.length === 0) {
return {
@@ -424,9 +433,12 @@ export function checkImplicitIntegrations(ctx) {
label,
status: 'info',
message:
- ctx.integrations.length > 0
+ (ctx.integrations.length > 0
? 'None — every loaded integration is named in astryx.config.'
- : 'None — no installed dependency ships an astryx.integration.* manifest.',
+ : unreadable
+ ? 'None loaded.'
+ : 'None — no installed dependency ships an astryx.integration.* manifest.') +
+ unreadable,
};
}
@@ -439,11 +451,25 @@ export function checkImplicitIntegrations(ctx) {
integration.__spec && integration.__spec !== integration.name
? ` (declared as "${integration.__spec}")`
: '';
- const roots = ['components', 'templates', 'themes', 'docs', 'codemods'].filter(
+ // A declared root counts only when it exists: the manifest's keys are a
+ // claim, and `integration-issues` reports the ones that are not true.
+ const declared = ['components', 'templates', 'themes', 'docs', 'codemods'].filter(
root => integration[/** @type {'components'} */ (root)],
);
+ const missing = declared.filter(root => {
+ const dir = integration[/** @type {'components'} */ (root)];
+ if (typeof dir !== 'string') return false;
+ const base =
+ typeof integration.__packageDir === 'string'
+ ? integration.__packageDir
+ : (ctx.cwd ?? process.cwd());
+ return !fs.existsSync(path.isAbsolute(dir) ? dir : path.resolve(base, dir));
+ });
+ const roots = declared.filter(root => !missing.includes(root));
const contributes = roots.length > 0 ? roots.join(', ') : 'nothing';
- return `${integration.name}${version}${alias} from ${integration.__dependencyField}, contributing ${contributes}`;
+ const absent =
+ missing.length > 0 ? ` (declared ${missing.join(', ')} missing on disk)` : '';
+ return `${integration.name}${version}${alias} from ${integration.__dependencyField}, contributing ${contributes}${absent}`;
});
const plural = implicit.length === 1 ? '' : 's';
@@ -453,7 +479,8 @@ export function checkImplicitIntegrations(ctx) {
status: 'info',
message:
`${implicit.length} integration${plural} loaded from installed ` +
- `dependencies with no astryx.config entry: ${described.join('; ')}.`,
+ `dependencies with no astryx.config entry: ${described.join('; ')}.` +
+ unreadable,
fix:
'Nothing to fix. Keep these dependencies installed. The CLI links them ' +
'from package.json, so an unused-dependency check that looks only for ' +
@@ -462,6 +489,30 @@ export function checkImplicitIntegrations(ctx) {
};
}
+/**
+ * The sentence `implicit-integrations` adds for dependencies whose manifest
+ * could not be loaded, or '' when there are none. Still informational: the
+ * package is a dependency's own bug, which `doctor integration validate`
+ * diagnoses, but doctor must not report it as absent.
+ * @param {Array<{spec: string, error: string}>} failures
+ * @returns {string}
+ */
+function describeUnreadableManifests(failures) {
+ if (failures.length === 0) return '';
+ const one = failures.length === 1;
+ const listed = failures
+ .map(({spec, error}) => {
+ const reason = String(error).split('\n')[0].slice(0, 160);
+ return `${spec} (${reason})`;
+ })
+ .join('; ');
+ return (
+ ` ${failures.length} installed ${one ? 'dependency ships' : 'dependencies ship'} ` +
+ `an astryx.integration.* manifest that could not be loaded, so ${one ? 'it contributes' : 'they contribute'} ` +
+ `nothing: ${listed}. Run \`astryx doctor integration validate <package>\` for details.`
+ );
+}
+
/**
* Check 7 — agent docs exist and contain the Astryx section markers.
* @param {DoctorContext} ctx
@@ -738,12 +789,26 @@ export function checkProviderIdentity(ctx) {
integration =>
integration.providerId != null && integration.__loadError == null,
).length;
+ // An integration that could not be read has no provider ID to check, so the
+ // count above is not a complete survey. Say so instead of counting silently.
+ const unread = ctx.integrations.filter(
+ integration => integration.__loadError != null,
+ ).length;
+ const unreadNote =
+ unread === 0
+ ? ''
+ : unread === 1
+ ? ' 1 loaded integration could not be read, so its provider ID is unknown.'
+ : ` ${unread} loaded integrations could not be read, so their provider IDs are unknown.`;
if (count === 0) {
return {
id,
label,
status: 'info',
- message: 'None — no loaded integration has a provider identity.',
+ message:
+ (unread === 0
+ ? 'None — no loaded integration has a provider identity.'
+ : 'No readable integration has a provider identity.') + unreadNote,
};
}
return {
@@ -751,9 +816,10 @@ export function checkProviderIdentity(ctx) {
label,
status: 'pass',
message:
- count === 1
+ (count === 1
? '1 loaded integration has its own provider ID.'
- : `${count} loaded integrations each have their own provider ID.`,
+ : `${count} loaded integrations each have their own provider ID.`) +
+ unreadNote,
};
}
@@ -1198,11 +1264,25 @@ export async function runChecks(options = {}) {
let docsCatalogError = null;
/** @type {Array<{package: string, code: string, severity: 'warning'|'error', message: string}>|null} */
let integrationIssues = null;
+ /** @type {Array<{spec: string, error: string}>|null} */
+ let autolinkFailures = null;
try {
const project = await Project.load(cwd);
configTheme =
/** @type {{theme?: string}} */ (project.config ?? {}).theme ?? null;
integrations = project.loadedIntegrations;
+ // An installed dependency whose manifest cannot be loaded is kept out of
+ // loadedIntegrations on purpose. The provider ledger still records it.
+ autolinkFailures = [...providerLedgerOf(project).values()]
+ .filter(
+ entry =>
+ entry.outcome === 'load-failed' &&
+ entry.candidate.source === 'autolinked',
+ )
+ .map(entry => ({
+ spec: entry.candidate.spec ?? entry.label,
+ error: entry.error ?? 'its manifest could not be loaded',
+ }));
try {
docsCatalog = await project.docs();
docsCatalogIssues = (await project.issues()).filter(
@@ -1229,6 +1309,7 @@ export async function runChecks(options = {}) {
docsCatalogIssues,
docsCatalogError,
integrationIssues,
+ autolinkFailures,
configError,
};
diff --git a/packages/cli/api/doctor/doctor.test.mjs b/packages/cli/api/doctor/doctor.test.mjs
index 29a51a11e9..d02d1b8d2a 100644
--- a/packages/cli/api/doctor/doctor.test.mjs
+++ b/packages/cli/api/doctor/doctor.test.mjs
@@ -354,16 +354,31 @@ describe('checkImplicitIntegrations', () => {
});
it('names the package, the field, and what it contributes', () => {
- const c = checkImplicitIntegrations({
- integrations: [
- autolinked({templates: '/abs/templates', themes: '/abs/themes'}),
- ],
- });
- expect(c.message).toContain('@acme/[email protected]');
- expect(c.message).toContain('from dependencies');
- expect(c.message).toContain(
- 'contributing components, templates, themes',
- );
+ // Roots count only when they exist, so this one gives them real folders.
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-implicit-'));
+ try {
+ const dir = name => {
+ fs.mkdirSync(path.join(root, name));
+ return path.join(root, name);
+ };
+ const c = checkImplicitIntegrations({
+ integrations: [
+ autolinked({
+ components: dir('components'),
+ templates: dir('templates'),
+ themes: dir('themes'),
+ }),
+ ],
+ });
+ expect(c.message).toContain('@acme/[email protected]');
+ expect(c.message).toContain('from dependencies');
+ expect(c.message).toContain(
+ 'contributing components, templates, themes',
+ );
+ expect(c.message).not.toContain('missing on disk');
+ } finally {
+ fs.rmSync(root, {recursive: true, force: true});
+ }
});
it('names the declared key too when an npm alias makes them differ', () => {
@@ -906,3 +921,100 @@ describe('checkDocsProgressiveDisclosure languages', () => {
expect(c.message).not.toMatch(/deploying overview:/);
});
});
+
+describe('doctor says what it could not check', () => {
+ const CORE = {
+ 'node_modules/@astryxdesign/core/package.json': JSON.stringify({
+ name: '@astryxdesign/core',
+ version: '0.6.3',
+ }),
+ };
+
+ /** Installed dependency whose manifest declares roots that do not exist. */
+ const dangling = {
+ 'node_modules/@acme/dangling/package.json': JSON.stringify({
+ name: '@acme/dangling',
+ version: '2.0.0',
+ }),
+ 'node_modules/@acme/dangling/astryx.integration.mjs':
+ "export default {providerId: 'acme-dangling', components: './components', templates: './templates', docs: './docs'};\n",
+ };
+
+ /** Installed dependency whose manifest cannot be parsed at all. */
+ const broken = {
+ 'node_modules/@acme/broken/package.json': JSON.stringify({
+ name: '@acme/broken',
+ version: '1.0.0',
+ }),
+ 'node_modules/@acme/broken/astryx.integration.mjs':
+ 'export default { this is not valid javascript ((\n',
+ };
+
+ /** @param {Record<string, string>} extra @param {string[]} deps */
+ const project = (extra, deps) =>
+ mkProject({
+ 'package.json': JSON.stringify({
+ name: 'consumer',
+ version: '1.0.0',
+ dependencies: Object.fromEntries(
+ ['@astryxdesign/core', ...deps].map(d => [d, '1.0.0']),
+ ),
+ }),
+ ...CORE,
+ ...extra,
+ });
+
+ // An unparseable manifest is kept out of the loaded set on purpose, and
+ // doctor used to report that no installed dependency ships a manifest.
+ it('names an installed dependency whose manifest cannot be loaded', async () => {
+ const report = (await doctor({cwd: project(broken, ['@acme/broken'])})).data;
+ const check = report.checks.find(c => c.id === 'implicit-integrations');
+
+ expect(check.status).toBe('info');
+ expect(check.message).toContain('@acme/broken');
+ expect(check.message).toContain('could not be loaded');
+ expect(check.message).not.toContain('no installed dependency ships');
+ expect(report.summary.fail).toBe(0);
+ }, SLOW);
+
+ it('does not claim contributions from roots that are missing on disk', async () => {
+ const report = (await doctor({cwd: project(dangling, ['@acme/dangling'])}))
+ .data;
+ const implicit = report.checks.find(c => c.id === 'implicit-integrations');
+ const issues = report.checks.find(c => c.id === 'integration-issues');
+
+ expect(implicit.message).toContain('contributing nothing');
+ expect(implicit.message).toContain('missing on disk');
+ expect(implicit.message).not.toContain('contributing components');
+ expect(issues.status).toBe('warn');
+ expect(issues.message).toContain('@acme/dangling');
+ }, SLOW);
+
+ it('still says no dependency ships a manifest when none does', async () => {
+ const report = (await doctor({cwd: project({}, [])})).data;
+ const check = report.checks.find(c => c.id === 'implicit-integrations');
+
+ expect(check.message).toBe(
+ 'None — no installed dependency ships an astryx.integration.* manifest.',
+ );
+ }, SLOW);
+
+ it('says how many integrations could not be read, rather than counting silently', () => {
+ /** @type {any} */
+ const ctx = {
+ cwd: '/x',
+ nodeVersion: process.versions.node,
+ coreDir: null,
+ configPath: null,
+ configTheme: null,
+ integrations: [
+ {name: '@acme/ok', __spec: '@acme/ok', providerId: 'ok'},
+ {name: '@acme/bad', __spec: '@acme/bad', __loadError: 'boom'},
+ ],
+ };
+ const check = checkProviderIdentity(ctx);
+
+ expect(check.message).toContain('1 loaded integration has its own provider ID.');
+ expect(check.message).toContain('could not be read');
+ });
+});