An open source design system that's fully customizable and agent ready
TypeScript
fix(cli): make blog text output mirror its JSON (#6526)
Joey05c764198098
diff --git a/.changeset/cli-spec-blog-text-projection.md b/.changeset/cli-spec-blog-text-projection.mdnew file mode 100644index 0000000000..bbd9e5d8dc--- /dev/null+++ b/.changeset/cli-spec-blog-text-projection.md@@ -0,0 +1,7 @@+---+'@astryxdesign/cli': patch+---++[fix] `astryx blog` text output now labels the feed URL `feedUrl`, matching its `--json` key, and prints every post field the JSON carries: the list adds each post's description, date, authors and link, and a post read adds its metadata above the body.++@josephfarinadiff --git a/packages/cli/clients/cli/commands/blog.mjs b/packages/cli/clients/cli/commands/blog.mjsindex ee953e2365..6a0adf3ea5 100644--- a/packages/cli/clients/cli/commands/blog.mjs+++ b/packages/cli/clients/cli/commands/blog.mjs@@ -24,6 +24,18 @@ import {resultSet} from '../../../foundation/debug/index.mjs';import {doc as blogCommand} from './blog.doc.mjs';import {doc as blogFn} from '../../../api/blog/blog.doc.mjs';+/** Every field of a post in the JSON, in order; record() skips empty ones. */+const POST_FIELDS = [+ 'slug',+ 'title',+ 'description',+ 'date',+ 'type',+ 'authors',+ 'link',+ 'textUrl',+];+/*** @param {import('commander').Command} program*/@@ -62,22 +74,25 @@ export function registerBlog(program) {const {feedUrl, posts} = result.data;if (posts.length === 0) {emit(- section('Astryx blog', `feed: ${feedUrl}`),+ section('Astryx blog'),+ record({feedUrl}),text('No posts found in the feed.'),);return answered;}- // One record per post — fields mirror the JSON post shape; empty- // fields (type/textUrl) are skipped by record().emit(- section('Astryx blog', `feed: ${feedUrl}`),- records(posts, {fields: ['slug', 'title', 'type', 'textUrl']}),+ section('Astryx blog'),+ record({feedUrl}),+ records(posts, {fields: POST_FIELDS}),text(`Read one: ${run} astryx blog <slug>`),);} else {- // blog.detail — the feed URL, then the post body emitted verbatim- // (code() so article typography/spacing isn't ASCII-normalized).- emit(record({feed: result.data.feedUrl}), code(result.data.text));+ // blog.detail — the post's fields and the feed URL, then the body+ // verbatim (code() so article typography/spacing isn't ASCII-normalized).+ emit(+ record(result.data, {fields: [...POST_FIELDS, 'feedUrl']}),+ code(result.data.text),+ );}return answered;},diff --git a/packages/cli/clients/cli/commands/blog.test.mjs b/packages/cli/clients/cli/commands/blog.test.mjsindex c9fec4fb30..4da500c58b 100644--- a/packages/cli/clients/cli/commands/blog.test.mjs+++ b/packages/cli/clients/cli/commands/blog.test.mjs@@ -19,7 +19,10 @@ const FEED = `<?xml version="1.0" encoding="UTF-8"?><item><title>How Astryx works</title><link>${SITE_URL}/blog/how-astryx-works</link>+ <description>Under the hood & more</description><category>engineering</category>+ <author>Ada</author>+ <author>Grace</author><pubDate>Mon, 29 Jun 2026 00:00:00 GMT</pubDate><atom:link rel="alternate" type="text/plain" href="${SITE_URL}/blog/how-astryx-works.txt" /></item>@@ -39,6 +42,23 @@ function stubFetch(routes) {});}+/**+ * Every non-empty field prints as a `key: value` line under its JSON key.+ * @param {string} stdout+ * @param {Record<string, unknown>} fields+ */+function expectFields(stdout, fields) {+ const lines = stdout.split('\n');+ for (const [key, value] of Object.entries(fields)) {+ if (value == null || value === '' || (Array.isArray(value) && !value.length)) continue;+ const shown = Array.isArray(value) ? value.join(', ') : String(value);+ expect(+ lines.some(line => line.startsWith(`${key}:`) && line.trimEnd().endsWith(shown)),+ `${key}: ${shown}`,+ ).toBe(true);+ }+}+beforeEach(() => {vi.stubGlobal('fetch',@@ -83,10 +103,31 @@ describe('blog CLI — json-enabled', () => {const {status, stdout} = await runCli(['blog']);expect(status).toBe(0);expect(stdout).toMatch(/Astryx blog/);- expect(stdout).toMatch(/feed:/);+ expect(stdout).toMatch(/^feedUrl:/m);expect(stdout).toMatch(/how-astryx-works/);});+ it('the text list projects every JSON field under its JSON key', async () => {+ const env = JSON.parse((await runCli(['blog', '--json'])).stdout);+ const {status, stdout} = await runCli(['blog']);+ expect(status).toBe(0);+ expectFields(stdout, {feedUrl: env.data.feedUrl});+ for (const post of env.data.posts) expectFields(stdout, post);+ expect(stdout).not.toMatch(/^feed:/m);+ });++ it('the text detail projects every JSON field, then the post body', async () => {+ const env = JSON.parse(+ (await runCli(['blog', 'how-astryx-works', '--json'])).stdout,+ );+ const {status, stdout} = await runCli(['blog', 'how-astryx-works']);+ expect(status).toBe(0);+ const {text, ...fields} = env.data;+ expectFields(stdout, fields);+ expect(stdout).toContain(text);+ expect(stdout).not.toMatch(/^feed:/m);+ });+it('surfaces the API error code and exits non-zero for an unknown slug (--json)', async () => {const {status, stdout} = await runCli(['blog', 'no-such-post', '--json']);expect(status).not.toBe(0);