From eea1239346e048e667a0a4c0893a93cbf2b4cae6 Mon Sep 17 00:00:00 2001 From: $zhangzhaokang <$zhangzhaokang@bytedance.com> Date: Sat, 4 Jul 2026 10:32:23 +0800 Subject: [PATCH] fix(loop-sync): honor json output flag --- tools/loop-sync/dist/cli.js | 2 +- tools/loop-sync/src/cli.ts | 4 ++-- tools/loop-sync/test/sync.test.mjs | 27 ++++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) 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)); + }); +});