Skip to content

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

TypeScript

fix(cli): validate commands fail when there is nothing to validate (#7150)

Joey39be4b193949
diff --git a/.changeset/cli-validate-nothing-exits-nonzero.md b/.changeset/cli-validate-nothing-exits-nonzero.md
new file mode 100644
index 0000000000..9d78df8c02
--- /dev/null
+++ b/.changeset/cli-validate-nothing-exits-nonzero.md
@@ -0,0 +1,13 @@
+---
+'@astryxdesign/cli': minor
+---
+
+[breaking] `doctor integration validate` exits 1 when there is no package.json.
+
+- incompatible-fix `IFIX-0008` / cleanup `CLN-0014`
+
+The no-package.json case now carries a `no_package` error-severity issue, so the existing exit rule (exit 1 on error-severity issues) covers it. A directory with package.json but no integration manifest stays exit 0 as published.
+
+Migration: run the command in a directory that has a `package.json`, or handle exit 1 for that case.
+
+@josephfarina
diff --git a/packages/cli/README.md b/packages/cli/README.md
index f1ca0a095b..5c7a7f0f97 100644
--- a/packages/cli/README.md
+++ b/packages/cli/README.md
@@ -476,7 +476,7 @@ Every response has a `type` discriminant. The full set is below (generated from
| `doctor` | The health-check report: `checks` (each with id, label, status: pass \| warn \| fail \| info, a message, and an optional fix, always present on warn and fail) plus a `summary` of counts per status. |
| `integration.add` | A contribution-writer receipt: kind, name, optional root {path, created}, integration-manifest path, every affected project-relative path, written, and dryRun. |
| `integration.pack-check` | The packed-package check: name, version, packable, tarball {filename, fileCount, size, unpackedSize} or null, inventory {manifest, roots [{kind, path, expectedFiles, missingFiles, complete}], expectedFiles, packedFiles}, contributions {local, packed}, each null or {themes [{slug, exportName}], components, templates [{id, type, name}], codemods [{version, id}], docs, agentDocsAppend}, and issues [{code, severity, message}]. |
-| `integration.validate` | The validation result: validated (false when no integration manifest was found, so nothing was checked and the empty issues list proves nothing), the package name and version (both null when validated is false) plus issues, an AstryxIntegrationIssue[] of {code, severity: warning \| error, message}. |
+| `integration.validate` | The validation result: validated (false when nothing was validated: with no package.json the issues list carries one no_package error so the command exits 1, and with a package.json but no integration manifest the issues list is empty and proves nothing), the package name and version (both null when validated is false) plus issues, an AstryxIntegrationIssue[] of {code, severity: warning \| error, message}. |
| `integration.template-conflicts` | validated (false when no integration manifest was found, so nothing was inspected), the integration identity, structural issues, and non-blocking Core template-id conflicts as {id, severity: warning, integrationPackage, integrationType, integrationName, coreMatches, message, command}. |
| `integration.component-conflicts` | validated (false when no integration manifest was found, so nothing was inspected), the integration identity, structural issues, and non-blocking conflicts where an integration component name is also owned by Core; each conflict includes the exact package-qualified command. |
| `integration.doc-conflicts` | validated (false when no integration manifest was found, so nothing was inspected), the integration identity, structural issues, and Core doc overlaps. Each finding includes `severity` (`info` \| `error`) and `relationship` (`replaces` \| `extends` \| `accidental`). |
diff --git a/packages/cli/api/integration/validate-integration.mjs b/packages/cli/api/integration/validate-integration.mjs
index c6d0157a64..9de89f1d50 100644
--- a/packages/cli/api/integration/validate-integration.mjs
+++ b/packages/cli/api/integration/validate-integration.mjs
@@ -72,6 +72,7 @@ export {validateLoadedIntegration};
* @property {string} [name] Integration package name (from package.json).
* @property {string} [version] Integration package version.
* @property {string} [manifestFile] Absolute path to the loaded manifest.
+ * @property {'no_package_json'} [reason] Why nothing was validated (internal).
* @property {Issue[]} issues
* @property {import('../../foundation/integrations/integrations.mjs').LoadedIntegration} [integration]
*/
@@ -349,7 +350,7 @@ async function validateAtPackageDir(
export async function validateLocalIntegration(cwd = process.cwd()) {
const pkgJsonPath = findNearestPackageJson(cwd);
if (!pkgJsonPath) {
- return {found: false, issues: []};
+ return {found: false, reason: 'no_package_json', issues: []};
}
const packageDir = path.dirname(pkgJsonPath);
@@ -468,7 +469,9 @@ export async function validateIntegration(pkg, options = {}) {
validated: result.found,
name: result.found ? (result.name ?? null) : null,
version: result.found ? (result.version ?? null) : null,
- issues: result.issues,
+ issues: result.reason === 'no_package_json'
+ ? [{code: 'no_package', severity: 'error', message: 'No package.json found. Run this command inside a package directory.'}]
+ : result.issues,
},
};
}
diff --git a/packages/cli/api/integration/validateIntegration.doc.mjs b/packages/cli/api/integration/validateIntegration.doc.mjs
index abbf94d50d..1b6aff5941 100644
--- a/packages/cli/api/integration/validateIntegration.doc.mjs
+++ b/packages/cli/api/integration/validateIntegration.doc.mjs
@@ -46,7 +46,7 @@ export const doc = {
{
type: 'integration.validate',
description:
- 'The result envelope: `data.validated`, false only when no integration manifest was found — nothing was checked, so the empty `data.issues` means "not looked at", not "healthy"; `data.name` and `data.version` of the validated package (both null when `data.validated` is false; `data.name` is `(local package)` when the local package.json has no readable name), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message}.',
+ 'The result envelope: `data.validated`, false when nothing was validated — with no `package.json` at all, `data.issues` carries one `no_package` error-severity issue so the command exits 1; with a `package.json` but no integration manifest, `data.issues` is empty, which means "not looked at", not "healthy"; `data.name` and `data.version` of the validated package (both null when `data.validated` is false; `data.name` is `(local package)` when the local package.json has no readable name), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message}.',
},
],
examples: [
diff --git a/packages/cli/clients/cli/commands/doctor.mjs b/packages/cli/clients/cli/commands/doctor.mjs
index dadb0cea1f..46db659ad6 100644
--- a/packages/cli/clients/cli/commands/doctor.mjs
+++ b/packages/cli/clients/cli/commands/doctor.mjs
@@ -259,10 +259,13 @@ async function runIntegrationValidation(program, pkg) {
const result = await validateIntegration(pkg);
if (program.opts().json) jsonOut(result);
else if (!result.data.validated) {
+ const noPackage = result.data.issues.some(i => i.code === 'no_package');
emit(
text(
- 'Nothing was validated: no astryx.integration.* found next to package.json. ' +
- 'To validate an installed integration: astryx doctor integration validate <package>',
+ noPackage
+ ? 'Nothing was validated: no package.json found. Run this command inside a package directory.'
+ : 'Nothing was validated: no astryx.integration.* found next to package.json. ' +
+ 'To validate an installed integration: astryx doctor integration validate <package>',
),
);
} else printIntegrationValidation(result.data);
diff --git a/packages/cli/clients/cli/commands/validate-nothing-exits-nonzero.test.mjs b/packages/cli/clients/cli/commands/validate-nothing-exits-nonzero.test.mjs
new file mode 100644
index 0000000000..7664b4b2c8
--- /dev/null
+++ b/packages/cli/clients/cli/commands/validate-nothing-exits-nonzero.test.mjs
@@ -0,0 +1,67 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+import {describe, it, expect, beforeEach, afterEach} from 'vitest';
+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 {validateIntegration} from '../../../api/integration/validate-integration.mjs';
+import {integrationTemplateConflicts, integrationComponentConflicts, integrationDocConflicts} from '../../../api/integration/authoring-checks.mjs';
+let dir;
+beforeEach(() => { dir = fs.mkdtempSync(path.join(os.tmpdir(),'astryx-val-')); });
+afterEach(() => fs.rmSync(dir, {recursive:true,force:true}));
+const json = async a => { const {status,stdout}=await runCli(['--json',...a],{cwd:dir}); return {status,body:JSON.parse(stdout)}; };
+const text = async a => runCli(a, {cwd: dir});
+
+describe('doctor integration validate exit codes (IFIX-0008)', () => {
+ it('exits 1 with no package.json (JSON has no_package issue)', async () => {
+ const {status, body} = await json(['doctor','integration','validate']);
+ expect(status).toBe(1);
+ expect(body.data.validated).toBe(false);
+ expect(body.data.issues).toEqual([
+ expect.objectContaining({code: 'no_package', severity: 'error'}),
+ ]);
+ });
+
+ it('text mode says no package.json when there is none', async () => {
+ const {status, stdout} = await text(['doctor','integration','validate']);
+ expect(status).toBe(1);
+ expect(stdout).toContain('no package.json found');
+ });
+
+ it('exits 0 with package.json but no manifest (byte-identical to published)', async () => {
+ fs.writeFileSync(path.join(dir,'package.json'), JSON.stringify({name:'myapp',version:'1.0.0'}));
+ const {status, body} = await json(['doctor','integration','validate']);
+ expect(status).toBe(0);
+ expect(body.data).toEqual({validated: false, name: null, version: null, issues: []});
+ });
+
+ it('text mode says no manifest when package.json exists', async () => {
+ fs.writeFileSync(path.join(dir,'package.json'), JSON.stringify({name:'myapp',version:'1.0.0'}));
+ const {status, stdout} = await text(['doctor','integration','validate']);
+ expect(status).toBe(0);
+ expect(stdout).toContain('no astryx.integration');
+ });
+
+ it('exported API returns the no_package issue', async () => {
+ const result = await validateIntegration(undefined, {cwd: dir});
+ expect(result.type).toBe('integration.validate');
+ expect(result.data.validated).toBe(false);
+ expect(result.data.issues).toEqual([
+ expect.objectContaining({code: 'no_package', severity: 'error'}),
+ ]);
+ });
+
+ it('integration verify exits 1 with a data envelope', async () => {
+ const {status, body} = await json(['integration','verify']);
+ expect(status).toBe(1);
+ expect(body.type).toBe('integration.pack-check');
+ expect(body.data.issues.some(i => i.code === 'no_package')).toBe(true);
+ });
+
+ it('sibling commands stay unchanged with no package.json', async () => {
+ for (const sub of ['templates', 'components', 'docs']) {
+ const {status, body} = await json(['doctor','integration', sub]);
+ expect(status, `doctor integration ${sub}`).toBe(0);
+ expect(body.data.validated).toBe(false);
+ expect(body.data.issues).toEqual([]);
+ }
+ });
+});
diff --git a/packages/cli/foundation/response/response-types.doc.mjs b/packages/cli/foundation/response/response-types.doc.mjs
index deb95eb533..a2f400be5d 100644
--- a/packages/cli/foundation/response/response-types.doc.mjs
+++ b/packages/cli/foundation/response/response-types.doc.mjs
@@ -332,7 +332,7 @@ export const doc = {
{
value: 'integration.validate',
description:
- 'The validation result: validated (false when no integration manifest was found, so nothing was checked and the empty issues list proves nothing), the package name and version (both null when validated is false) plus issues, an AstryxIntegrationIssue[] of {code, severity: warning | error, message}.',
+ 'The validation result: validated (false when nothing was validated: with no package.json the issues list carries one no_package error so the command exits 1, and with a package.json but no integration manifest the issues list is empty and proves nothing), the package name and version (both null when validated is false) plus issues, an AstryxIntegrationIssue[] of {code, severity: warning | error, message}.',
},
{
value: 'integration.template-conflicts',