An open source design system that's fully customizable and agent ready
TypeScript
fix(cli): state how integration debug handlers combine on the debug config entry (#6514)
Joey21c213756462
diff --git a/.changeset/cli-spec-config-debug-composition.md b/.changeset/cli-spec-config-debug-composition.mdnew file mode 100644index 0000000000..15f4b70506--- /dev/null+++ b/.changeset/cli-spec-config-debug-composition.md@@ -0,0 +1,7 @@+---+'@astryxdesign/cli': patch+---++[fix] The `debug` entry of the `AstryxConfig` type and of `astryx docs authoring config` now states how handlers from integrations combine with the app's own: the app's runs first, then each integration's in load order, a handler that throws is skipped without affecting the others or the command, and `{"astryx": {"inheritDebug": false}}` refuses inherited handlers. The type no longer claims that leaving `debug` out records nothing.++@josephfarinadiff --git a/packages/cli/authoring/config/config.doc.mjs b/packages/cli/authoring/config/config.doc.mjsindex a8b9742552..00080c9389 100644--- a/packages/cli/authoring/config/config.doc.mjs+++ b/packages/cli/authoring/config/config.doc.mjs@@ -48,7 +48,7 @@ export const doc = {name: 'debug',type: '(event: DebugEvent) => void',description:- 'Record every command run. The handler is synchronous; promises are not awaited and output goes to stderr. Declare `debug` directly in this file so early commands can discover it. An integration can supply one too, as a `debug` named export from its manifest — both run; set `{"astryx": {"inheritDebug": false}}` in package.json to take only your own.',+ 'Record every command run. The handler is synchronous; promises are not awaited and output goes to stderr. Declare `debug` directly in this file so early commands can discover it. An integration can supply one too, as a `debug` named export from its manifest. Every handler runs: yours first, then each integration\'s in load order (the `integrations` list, then autolinked ones). A handler that throws is skipped; the others still run and the command\'s result does not change. Set `{"astryx": {"inheritDebug": false}}` in package.json to take only your own.',example:"event => appendFileSync('runs.ndjson', JSON.stringify(event) + '\\n')",},diff --git a/packages/cli/authoring/config/debug-composition.test.mjs b/packages/cli/authoring/config/debug-composition.test.mjsnew file mode 100644index 0000000000..3ed4a8b3a4--- /dev/null+++ b/packages/cli/authoring/config/debug-composition.test.mjs@@ -0,0 +1,92 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file `debug` accepts handlers from integrations, so both public entries for+ * it — the exported `AstryxConfig` type and `astryx docs authoring config` —+ * must state how those handlers combine with the app's own: the contribution+ * form, the order, what a failing handler does, and the refusal control.+ */++import * as fs from 'node:fs';+import * as path from 'node:path';+import {fileURLToPath} from 'node:url';+import ts from 'typescript';+import {describe, expect, it} from 'vitest';+import {doc} from './config.doc.mjs';++const TYPE_FILE = path.join(+ path.dirname(fileURLToPath(import.meta.url)),+ 'type.ts',+);+const source = ts.createSourceFile(+ TYPE_FILE,+ fs.readFileSync(TYPE_FILE, 'utf8'),+ ts.ScriptTarget.Latest,+ true,+);++/** @param {ts.Node} node @returns {string} */+function jsdocText(node) {+ return ts+ .getJSDocCommentsAndTags(node)+ .map(jsdoc => ts.getTextOfJSDocComment(jsdoc.comment) ?? '')+ .join('\n');+}++/** @param {(node: ts.Node) => boolean} match @returns {ts.Node} */+function findTopLevel(match) {+ const node = source.statements.find(match);+ if (!node) throw new Error('declaration not found in config/type.ts');+ return node;+}++const configInterface = /** @type {ts.InterfaceDeclaration} */ (+ findTopLevel(+ node => ts.isInterfaceDeclaration(node) && node.name.text === 'AstryxConfig',+ )+);+const debugMember = configInterface.members.find(+ member =>+ ts.isPropertySignature(member) && member.name.getText(source) === 'debug',+);+if (!debugMember) throw new Error('AstryxConfig has no debug member');++const debugConfigAlias = findTopLevel(+ node => ts.isTypeAliasDeclaration(node) && node.name.text === 'DebugConfig',+);++const schemaField = doc.fields.find(field => field.name === 'debug');++const ENTRIES = {+ 'the AstryxConfig type': jsdocText(debugMember),+ 'astryx docs authoring config': schemaField?.description ?? '',+};++describe.each(Object.entries(ENTRIES))('debug entry in %s', (_, text) => {+ it('says integrations contribute, and in what form', () => {+ expect(text).toMatch(/integration/i);+ expect(text).toMatch(/`debug` named export/);+ });++ it('says every handler runs, the app first, then integrations in load order', () => {+ expect(text).toMatch(/\bfirst\b/i);+ expect(text).toMatch(/load order/i);+ });++ it('says a handler that throws is skipped without affecting the others', () => {+ expect(text).toMatch(/throws is skipped/i);+ expect(text).toMatch(/others still run/i);+ });++ it('names the one control that refuses inherited handlers', () => {+ expect(text).toContain('{"astryx": {"inheritDebug": false}}');+ });+});++describe('DebugConfig', () => {+ it('does not claim that leaving debug out records nothing', () => {+ const text = jsdocText(debugConfigAlias);+ expect(text).not.toMatch(/nothing is recorded/i);+ expect(text).toMatch(/integration/i);+ });+});diff --git a/packages/cli/authoring/config/type.ts b/packages/cli/authoring/config/type.tsindex 0df7d08683..7238e71bd3 100644--- a/packages/cli/authoring/config/type.ts+++ b/packages/cli/authoring/config/type.ts@@ -56,8 +56,9 @@ export interface XleComponent {/*** Record every astryx command run in this project.*- * A function that receives each run. Setting it is the whole opt-in; leave it- * out and nothing is recorded.+ * A function that receives each run. Leaving it out does not stop a handler an+ * integration contributes; see {@link AstryxConfig.debug} for how the two+ * combine and how to refuse inherited handlers.** ```* export default {@@ -80,7 +81,18 @@ export interface AstryxConfig {hooks?: {postCodemod?: PostCodemodHook[];};- /** Record every astryx command run in this project. See {@link DebugConfig}. */+ /**+ * Record every astryx command run in this project. See {@link DebugConfig}.+ *+ * An integration can contribute a handler too, as a `debug` named export+ * from its `astryx.integration.*` module. Every handler receives the run:+ * this one first, then each integration's in load order (the ones+ * `integrations` lists, in that order, then autolinked ones). A handler that+ * throws is skipped; the others still run and the command's result does not+ * change. To refuse inherited handlers, set+ * `{"astryx": {"inheritDebug": false}}` in the project's package.json; this+ * handler still runs.+ */debug?: DebugConfig;/** Route gap reports through a project-owned handler. See {@link GapReportHandler}. */gapReport?: GapReportHandler;