Skip to content

Practical patterns, starters & CLI tools for loop engineering with AI coding agents. Design systems that prompt and orchestrate agents (inspired by Addy Osmani and Boris Cherny). Includes loop-audit, loop-init, loop-cost.

fix(loop-sync): honor json output flag (#138)

Zhang-9863499dcb037e8
diff --git a/tools/loop-sync/dist/cli.js b/tools/loop-sync/dist/cli.js
index c63e210..4525d89 100644
--- a/tools/loop-sync/dist/cli.js
+++ b/tools/loop-sync/dist/cli.js
@@ -27,7 +27,7 @@ function parseArgs(argv) {
else if (!a.startsWith('-'))
targetDir = a;
}
- return { targetDir, autoFix, dryRun, verbose, help };
+ return { targetDir, autoFix, dryRun, verbose, help, json };
}
async function main() {
const args = parseArgs(process.argv.slice(2));
diff --git a/tools/loop-sync/src/cli.ts b/tools/loop-sync/src/cli.ts
index ee19f77..da1e490 100644
--- a/tools/loop-sync/src/cli.ts
+++ b/tools/loop-sync/src/cli.ts
@@ -25,7 +25,7 @@ function parseArgs(argv: string[]): SyncOptions {
else if (!a.startsWith('-')) targetDir = a;
}
- return { targetDir, autoFix, dryRun, verbose, help };
+ return { targetDir, autoFix, dryRun, verbose, help, json };
}
async function main() {
@@ -86,4 +86,4 @@ Docs: https://github.com/cobusgreyling/loop-engineering/tree/main/tools/loop-syn
}
}
-main();
\ No newline at end of file
+main();
diff --git a/tools/loop-sync/test/sync.test.mjs b/tools/loop-sync/test/sync.test.mjs
index 0c27eaa..3ec4cfa 100644
--- a/tools/loop-sync/test/sync.test.mjs
+++ b/tools/loop-sync/test/sync.test.mjs
@@ -2,9 +2,13 @@ import { test, describe, beforeEach, afterEach } from 'node:test';
import assert from 'node:assert/strict';
import path from 'node:path';
import { mkdir, writeFile, rm } from 'node:fs/promises';
+import { execFile } from 'node:child_process';
+import { promisify } from 'node:util';
import { runSync, formatReport } from '../dist/sync.js';
const testDir = path.join(process.cwd(), '.test-tmp');
+const exec = promisify(execFile);
+const CLI = path.resolve('dist/cli.js');
async function setupTestDir() {
await mkdir(testDir, { recursive: true });
@@ -112,4 +116,25 @@ describe('formatReport', () => {
assert.match(formatted, /AGENTS\.md/);
assert.match(formatted, /missing/i);
});
-});
\ No newline at end of file
+});
+
+describe('cli', () => {
+ beforeEach(setupTestDir);
+ afterEach(cleanupTestDir);
+
+ test('emits JSON when --json is provided', async () => {
+ let stdout;
+ try {
+ ({ stdout } = await exec('node', [CLI, testDir, '--json']));
+ } catch (err) {
+ stdout = err.stdout;
+ assert.equal(err.code, 2);
+ }
+ const report = JSON.parse(stdout);
+
+ assert.equal(typeof report.score, 'number');
+ assert.ok(['healthy', 'warning', 'critical'].includes(report.level));
+ assert.ok(Array.isArray(report.issues));
+ assert.ok(Array.isArray(report.suggestions));
+ });
+});