An open source design system that's fully customizable and agent ready
TypeScript
fix(cli): stop reading ASTRYX_LATEST_VERSION (#6554)
Joey59bb7fa1bdee
diff --git a/.changeset/cli-spec-drop-latest-version-env.md b/.changeset/cli-spec-drop-latest-version-env.mdnew file mode 100644index 0000000000..290acb12a9--- /dev/null+++ b/.changeset/cli-spec-drop-latest-version-env.md@@ -0,0 +1,7 @@+---+'@astryxdesign/cli': patch+---++[fix] The CLI no longer reads or sets the `ASTRYX_LATEST_VERSION` environment variable. Its only effect was an `FYI: A newer version of @astryxdesign/core ...` line on stderr after `astryx component` and `astryx docs`, and a CLI run cannot set a variable for later runs, so the line appeared only when the variable was set by hand. Commands now print the same output whether or not it is set.++@josephfarinadiff --git a/packages/cli/clients/cli/index.mjs b/packages/cli/clients/cli/index.mjsindex a763d1d455..d0e88680b0 100644--- a/packages/cli/clients/cli/index.mjs+++ b/packages/cli/clients/cli/index.mjs@@ -16,7 +16,6 @@ import {Command, Option} from 'commander';import {fileURLToPath} from 'node:url';import * as fs from 'node:fs';import * as path from 'node:path';-import {checkForUpdate} from './lib/update-check.mjs';import {getCliInvocation} from '../../foundation/env/package-manager.mjs';import {API_VERSION, setJsonMode} from '../../foundation/response/json.mjs';import {buildManifest} from './lib/manifest.mjs';@@ -275,7 +274,6 @@ const commands = [{name: 'doctor', path: './commands/doctor.mjs', register: 'registerDoctor'},];-const UPDATE_HINT_COMMANDS = new Set(['component', 'docs']);const SETUP_NUDGE_EXEMPT = new Set(['init', 'agent-docs']);/**@@ -499,25 +497,6 @@ export async function createProgram() {process.exit(1);});- /**- * Post-action hook: print update hint after any command output.- * Only fires for commands that produce output agents read (component, docs, etc.).- * Suppressed when --json is active to avoid contaminating stdout.- */- program.hook('postAction', (thisCommand, actionCommand) => {- if (program.opts().json) return;- try {- if (UPDATE_HINT_COMMANDS.has(actionCommand.name())) {- const hint = checkForUpdate();- if (hint) {- console.error(`\n${hint}`);- }- }- } catch {- // Never let update check break the CLI- }- });-/*** Enforcement layer 3 — setup nudge. If this project hasn't run `astryx init`* yet (no Astryx marker in any agent-doc file — see isAstryxInitialized), reminddiff --git a/packages/cli/clients/cli/latest-version-env.test.mjs b/packages/cli/clients/cli/latest-version-env.test.mjsnew file mode 100644index 0000000000..8752de3bd4--- /dev/null+++ b/packages/cli/clients/cli/latest-version-env.test.mjs@@ -0,0 +1,50 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file ASTRYX_LATEST_VERSION is not a CLI control: setting it changes nothing+ * a command prints. It used to append an update hint to `component` and+ * `docs`.+ */++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';++const VARIABLE = 'ASTRYX_LATEST_VERSION';++/** @type {string} */+let dir;+/** @type {string | undefined} */+let saved;++beforeEach(() => {+ saved = process.env[VARIABLE];+ dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-latest-version-'));+ // A project on an old core, so a "newer version" hint would have a reason to fire.+ fs.writeFileSync(+ path.join(dir, 'package.json'),+ JSON.stringify({name: 'app', private: true, dependencies: {'@astryxdesign/core': '^0.0.1'}}),+ );+});++afterEach(() => {+ if (saved === undefined) delete process.env[VARIABLE];+ else process.env[VARIABLE] = saved;+ fs.rmSync(dir, {recursive: true, force: true});+});++describe('ASTRYX_LATEST_VERSION', () => {+ it('does not change what astryx docs prints', async () => {+ delete process.env[VARIABLE];+ const without = await runCli(['docs'], {cwd: dir});+ process.env[VARIABLE] = '999.0.0';+ const withVariable = await runCli(['docs'], {cwd: dir});++ expect(withVariable.status).toBe(without.status);+ expect(withVariable.stdout).toBe(without.stdout);+ expect(withVariable.stderr).toBe(without.stderr);+ expect(withVariable.stderr).not.toMatch(/newer version/i);+ });+});diff --git a/packages/cli/clients/cli/lib/update-check.mjs b/packages/cli/clients/cli/lib/update-check.mjsdeleted file mode 100644index b703852586..0000000000--- a/packages/cli/clients/cli/lib/update-check.mjs+++ /dev/null@@ -1,83 +0,0 @@-// Copyright (c) Meta Platforms, Inc. and affiliates.--/**- * @file Check for newer @astryxdesign/core versions via local signals.- *- * Resolution order:- * 1. $ASTRYX_LATEST_VERSION env var- * 2. If unset: no hint (no network calls from this module)- *- * When a newer version is detected, returns a hint string for CLI output.- * Also sets $ASTRYX_LATEST_VERSION for subsequent commands in the same shell.- */--import * as fs from 'node:fs';-import * as path from 'node:path';-import {semverGt} from '../../../foundation/env/semver.mjs';-import {getCliInvocation} from '../../../foundation/env/package-manager.mjs';--/**- * Read the latest available version from local signals.- * No network calls — purely an env-var check ($ASTRYX_LATEST_VERSION),- * so it takes no arguments.- *- * @returns {string|null} Latest version string, or null if unknown- */-export function getLatestVersion() {- // 1. Check env var (fastest — set by previous CLI run)- const envVersion = process.env.ASTRYX_LATEST_VERSION;- if (envVersion && /^\d+\.\d+\.\d+/.test(envVersion)) {- return envVersion;- }-- return null;-}--/**- * Get the currently installed @astryxdesign/core version from the consumer's package.json.- *- * @param {string} [cwd] - Project directory- * @returns {string|null} Installed version, or null- */-export function getInstalledVersion(cwd = process.cwd()) {- try {- const pkgPath = path.resolve(cwd, 'package.json');- if (!fs.existsSync(pkgPath)) return null;-- const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));- const deps = {...pkg.dependencies, ...pkg.devDependencies};- const version = deps['@astryxdesign/core'];- if (!version) return null;-- // Strip semver range prefix- return version.replace(/^[^\d]*/, '');- } catch {- return null;- }-}--/**- * Check for available updates and return a hint string if one exists.- * Also sets $ASTRYX_LATEST_VERSION env var for subsequent commands.- *- * @param {string} [cwd] - Project directory- * @returns {string|null} FYI hint string, or null if up to date / unknown- */-export function checkForUpdate(cwd = process.cwd()) {- const latest = getLatestVersion();- if (!latest) return null;-- // Persist for subsequent commands in this shell session- process.env.ASTRYX_LATEST_VERSION = latest;-- const installed = getInstalledVersion(cwd);- if (!installed) return null;-- // Use semver-aware comparison so '0.0.20' is correctly treated as greater- // than '0.0.5' (lexicographic compare gets that backwards).- if (semverGt(latest, installed)) {- return `FYI: A newer version of @astryxdesign/core (${latest}) is available. Install the new package version, then run: ${getCliInvocation()} upgrade --from <old-version> --apply`;- }-- return null;-}diff --git a/packages/cli/clients/cli/lib/update-check.test.mjs b/packages/cli/clients/cli/lib/update-check.test.mjsdeleted file mode 100644index 714682bafd..0000000000--- a/packages/cli/clients/cli/lib/update-check.test.mjs+++ /dev/null@@ -1,137 +0,0 @@-// Copyright (c) Meta Platforms, Inc. and affiliates.--import {describe, it, expect, beforeEach, afterEach} from 'vitest';-import * as fs from 'node:fs';-import * as path from 'node:path';-import * as os from 'node:os';-import {- getLatestVersion,- getInstalledVersion,- checkForUpdate,-} from './update-check.mjs';--let tmpDir;-const originalEnv = {};--beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-update-check-'));- // Save and clear env- originalEnv.ASTRYX_LATEST_VERSION = process.env.ASTRYX_LATEST_VERSION;- delete process.env.ASTRYX_LATEST_VERSION;-});--afterEach(() => {- fs.rmSync(tmpDir, {recursive: true, force: true});- // Restore env- if (originalEnv.ASTRYX_LATEST_VERSION !== undefined) {- process.env.ASTRYX_LATEST_VERSION = originalEnv.ASTRYX_LATEST_VERSION;- } else {- delete process.env.ASTRYX_LATEST_VERSION;- }-});--describe('getLatestVersion', () => {- it('reads from ASTRYX_LATEST_VERSION env var', () => {- process.env.ASTRYX_LATEST_VERSION = '0.0.8';- expect(getLatestVersion()).toBe('0.0.8');- });-- it('ignores invalid env var values', () => {- process.env.ASTRYX_LATEST_VERSION = 'not-a-version';- expect(getLatestVersion()).toBeNull();- });-- it('returns null when no signals exist', () => {- fs.writeFileSync(- path.join(tmpDir, 'package.json'),- JSON.stringify({name: 'test'}),- );- expect(getLatestVersion()).toBeNull();- });-});--describe('getInstalledVersion', () => {- it('reads @astryxdesign/core version from dependencies', () => {- fs.writeFileSync(- path.join(tmpDir, 'package.json'),- JSON.stringify({dependencies: {'@astryxdesign/core': '^0.0.7'}}),- );- expect(getInstalledVersion(tmpDir)).toBe('0.0.7');- });-- it('strips semver range prefix', () => {- fs.writeFileSync(- path.join(tmpDir, 'package.json'),- JSON.stringify({dependencies: {'@astryxdesign/core': '~0.0.5'}}),- );- expect(getInstalledVersion(tmpDir)).toBe('0.0.5');- });-- it('returns null when @astryxdesign/core is not a dependency', () => {- fs.writeFileSync(- path.join(tmpDir, 'package.json'),- JSON.stringify({dependencies: {react: '^19.0.0'}}),- );- expect(getInstalledVersion(tmpDir)).toBeNull();- });-});--describe('checkForUpdate', () => {- it('returns hint when newer version is available', () => {- process.env.ASTRYX_LATEST_VERSION = '0.0.8';- fs.writeFileSync(- path.join(tmpDir, 'package.json'),- JSON.stringify({dependencies: {'@astryxdesign/core': '^0.0.7'}}),- );-- const hint = checkForUpdate(tmpDir);- expect(hint).toContain('0.0.8');- expect(hint).toContain('astryx upgrade --from <old-version> --apply');- expect(hint).toContain('FYI');- });-- it('returns null when up to date', () => {- process.env.ASTRYX_LATEST_VERSION = '0.0.7';- fs.writeFileSync(- path.join(tmpDir, 'package.json'),- JSON.stringify({dependencies: {'@astryxdesign/core': '^0.0.7'}}),- );-- expect(checkForUpdate(tmpDir)).toBeNull();- });-- it('returns null when no latest version is known', () => {- fs.writeFileSync(- path.join(tmpDir, 'package.json'),- JSON.stringify({dependencies: {'@astryxdesign/core': '^0.0.7'}}),- );-- expect(checkForUpdate(tmpDir)).toBeNull();- });-- it('uses semver (not lexicographic) comparison for double-digit patches', () => {- // Regression: with string compare, '0.0.20' > '0.0.5' is false because- // '2' < '5' lexicographically. Users on 0.0.5 would never be told that- // 0.0.20 is available.- process.env.ASTRYX_LATEST_VERSION = '0.0.20';- fs.writeFileSync(- path.join(tmpDir, 'package.json'),- JSON.stringify({dependencies: {'@astryxdesign/core': '^0.0.5'}}),- );-- const hint = checkForUpdate(tmpDir);- expect(hint).toContain('0.0.20');- });-- it('does not suggest an upgrade when latest < installed (semver)', () => {- // The mirror-image bug: '0.0.9' > '0.0.10' is true under string compare,- // so a stale env hint of 0.0.9 would falsely claim it's "newer" than 0.0.10.- process.env.ASTRYX_LATEST_VERSION = '0.0.9';- fs.writeFileSync(- path.join(tmpDir, 'package.json'),- JSON.stringify({dependencies: {'@astryxdesign/core': '^0.0.10'}}),- );-- expect(checkForUpdate(tmpDir)).toBeNull();- });-});diff --git a/packages/cli/clients/cli/update-hint-commands.test.mjs b/packages/cli/clients/cli/update-hint-commands.test.mjsdeleted file mode 100644index ba1474105e..0000000000--- a/packages/cli/clients/cli/update-hint-commands.test.mjs+++ /dev/null@@ -1,54 +0,0 @@-// Copyright (c) Meta Platforms, Inc. and affiliates.--/**- * @file Guards the update-hint command allowlist.- *- * The post-action update hint only fires for a small set of commands- * (see UPDATE_HINT_COMMANDS in index.mjs). Every name in that set must- * map to a real, registered command — otherwise the entry is dead and- * the hint can never fire for it. This test imports the assembled- * program and verifies the invariant so a stale reference can't creep in.- *- * Historically there was a dead 'doctor' entry in UPDATE_HINT_COMMANDS that- * referenced a command that didn't exist. `doctor` is now a real command- * (the health check), but it is intentionally NOT in the update-hint set —- * the hint is for content commands (component/docs) that agents read, not- * for the diagnostic command. This test pins both invariants.- */--import {describe, it, expect} from 'vitest';-import {program} from './index.mjs';--/** Commands the update hint is expected to fire for. */-const HINTED_COMMANDS = ['component', 'docs'];--/** Real commands that must NOT trigger the update hint. */-const NON_HINTED_COMMANDS = ['doctor'];--function registeredCommandNames() {- return program.commands.map((c) => c.name());-}--describe('update hint commands', () => {- it('fires only for real, registered commands', () => {- const registered = new Set(registeredCommandNames());- for (const name of HINTED_COMMANDS) {- expect(registered.has(name)).toBe(true);- }- });-- it('registers the real "doctor" command', () => {- const registered = new Set(registeredCommandNames());- expect(registered.has('doctor')).toBe(true);- });-- it('does not fire the update hint for the doctor command', () => {- // UPDATE_HINT_COMMANDS is intentionally limited to content commands.- // Doctor is a diagnostic; its output should not carry an update hint.- expect(NON_HINTED_COMMANDS).not.toContain('component');- expect(NON_HINTED_COMMANDS).not.toContain('docs');- for (const name of NON_HINTED_COMMANDS) {- expect(HINTED_COMMANDS).not.toContain(name);- }- });-});