From 4bc8542ddd81ca50c8229185b6baca8987a6ec92 Mon Sep 17 00:00:00 2001 From: Ruifeng Xue <2463436064@qq.com> Date: Wed, 16 Sep 2026 15:23:09 +0800 Subject: [PATCH] fix(import): expose JSON output for cache commands (#580) --- CHANGELOG.md | 1 + src/__tests__/index-import-help.test.ts | 32 +++++++++++++++++++++++++ src/index.ts | 1 + 3 files changed, 34 insertions(+) create mode 100644 src/__tests__/index-import-help.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 67045d99..ff6a88f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file. See [standa ### 🐛 Bug Fixes +- `teamai import --cache-status` and `--cache-gc` now expose their existing JSON output through the CLI `--json` option. - Course-correction matching normalizes prompts and keywords to Unicode NFC, so composed and decomposed accents match. Stored prompt summaries and the 60-second correction window are unchanged. Fixes [#573](https://github.com/Tencent/teamai-cli/issues/573). - Course-correction detection matches keywords in space-separated scripts as whole words, so Spanish "segundo" no longer counts as `undo` (for [#564](https://github.com/Tencent/teamai-cli/issues/564)). - MCP `requires` is resolved from `PATH` (including Windows `PATHEXT`), so `teamai mcp inject` no longer skips servers such as `uvx` on Windows ([#540](https://github.com/Tencent/teamai-cli/pull/540), for [#539](https://github.com/Tencent/teamai-cli/issues/539)). diff --git a/src/__tests__/index-import-help.test.ts b/src/__tests__/index-import-help.test.ts new file mode 100644 index 00000000..0cc8936e --- /dev/null +++ b/src/__tests__/index-import-help.test.ts @@ -0,0 +1,32 @@ +import { afterEach, describe, expect, it, vi } from 'vitest'; + +const originalArgv = process.argv; + +afterEach(() => { + process.argv = originalArgv; + vi.restoreAllMocks(); + vi.resetModules(); +}); + +async function readImportHelp(): Promise { + let output = ''; + process.argv = ['node', 'teamai', 'import', '--help']; + vi.spyOn(process.stdout, 'write').mockImplementation((chunk) => { + output += String(chunk); + return true; + }); + vi.spyOn(process, 'exit').mockImplementation(((code?: string | number | null) => { + throw new Error(`process.exit(${code})`); + }) as never); + + await expect(import('../index.js')).rejects.toThrow('process.exit(0)'); + return output; +} + +describe('import command registration', () => { + it('lists JSON output for cache status and GC', async () => { + const output = await readImportHelp(); + expect(output).toContain('--json'); + expect(output).toContain('Output cache status or GC result as JSON'); + }); +}); diff --git a/src/index.ts b/src/index.ts index 48160da0..7fa70798 100644 --- a/src/index.ts +++ b/src/index.ts @@ -878,6 +878,7 @@ program .addOption(new Option('--require-review', 'Defer codebase section writes to .teamai/pending-review.jsonl for human review').hideHelp()) .option('--cache-status', 'Show import cache status (repos cached, disk usage)') .option('--cache-gc', 'Garbage-collect stale import cache entries') + .option('--json', 'Output cache status or GC result as JSON') .addOption(new Option('--max-bytes ', 'Override capacity cap for --cache-gc').hideHelp()) .addOption(new Option('--stale-days ', 'Threshold for stale-eviction in days (default 30)').default('30').hideHelp()) .action(async (cmdOpts) => {