Skip to content

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

TypeScript

fix(cli): honor inheritDebug in a project with no astryx.config (#6520)

Joeyb51fb1fe75e5
diff --git a/.changeset/cli-spec-inherit-debug-without-config.md b/.changeset/cli-spec-inherit-debug-without-config.md
new file mode 100644
index 0000000000..7433ca03da
--- /dev/null
+++ b/.changeset/cli-spec-inherit-debug-without-config.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/cli': patch
+---
+
+[fix] `"astryx": {"inheritDebug": false}` in package.json now also refuses the `debug` handler of an autolinked integration in a project that has no `astryx.config`. The setting used to be read only beside a config file, so without one those handlers still received every run.
+
+@josephfarina
diff --git a/packages/cli/foundation/config/integration-debug.test.mjs b/packages/cli/foundation/config/integration-debug.test.mjs
index 6a58c95a8f..7a8c04fe8b 100644
--- a/packages/cli/foundation/config/integration-debug.test.mjs
+++ b/packages/cli/foundation/config/integration-debug.test.mjs
@@ -63,11 +63,18 @@ function config(integrations, ownHandler = false) {
);
}
-/** @param {Record<string, unknown>} [astryx] */
-function packageJson(astryx) {
+/**
+ * @param {Record<string, unknown>} [astryx]
+ * @param {Record<string, string>} [dependencies]
+ */
+function packageJson(astryx, dependencies) {
fs.writeFileSync(
path.join(tmpDir, 'package.json'),
- JSON.stringify({name: 'consumer', ...(astryx ? {astryx} : {})}),
+ JSON.stringify({
+ name: 'consumer',
+ ...(dependencies ? {dependencies} : {}),
+ ...(astryx ? {astryx} : {}),
+ }),
);
}
@@ -172,6 +179,24 @@ describe('an app can refuse an inherited handler', () => {
expect(fired()).toEqual(['reporting-integration']);
});
+
+ it('keeps an autolinked handler in a project with no astryx.config', async () => {
+ packageJson(undefined, {'reporting-integration': '1.0.0'});
+ integration('reporting-integration');
+
+ await runOneCommand();
+
+ expect(fired()).toEqual(['reporting-integration']);
+ });
+
+ it('drops an autolinked handler under astryx.inheritDebug false with no astryx.config', async () => {
+ packageJson({inheritDebug: false}, {'reporting-integration': '1.0.0'});
+ integration('reporting-integration');
+
+ await runOneCommand();
+
+ expect(fired()).toEqual([]);
+ });
});
describe('loading the project twice delivers once', () => {
diff --git a/packages/cli/foundation/config/project.mjs b/packages/cli/foundation/config/project.mjs
index 2ca4d1234e..980d8771ca 100644
--- a/packages/cli/foundation/config/project.mjs
+++ b/packages/cli/foundation/config/project.mjs
@@ -260,13 +260,15 @@ function findPackageRoot(startDir) {
*
* This governs INHERITED handlers only. A project's own `debug` always runs.
*
- * @param {string|null} configPath
+ * Read from the project root whether or not an astryx.config exists: an
+ * autolinked integration contributes a handler with no config at all.
+ *
+ * @param {string} projectDir directory holding the project's package.json
* @returns {boolean}
*/
-function inheritsIntegrationDebug(configPath) {
- if (!configPath) return true;
+function inheritsIntegrationDebug(projectDir) {
try {
- const pkgPath = path.join(path.dirname(configPath), 'package.json');
+ const pkgPath = path.join(projectDir, 'package.json');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
return pkg?.astryx?.inheritDebug !== false;
} catch {
@@ -447,7 +449,7 @@ export class Project {
// because Project.load can run more than once in a process and appending
// would deliver twice.
setDebugIntegrationEventHandlers(
- inheritsIntegrationDebug(configPath)
+ inheritsIntegrationDebug(projectDir)
? loadedIntegrations.map(integration => integration.__debug)
: [],
);