test: extract cli pure functions + CLI test suite (node:test) - #5
Closed
4222222 wants to merge 2 commits into
Closed
test: extract cli pure functions + CLI test suite (node:test)#54222222 wants to merge 2 commits into
4222222 wants to merge 2 commits into
Conversation
added 2 commits
August 14, 2026 17:50
Extract parseArgs (cli/args.js) and env loading/persistence (cli/env.js) from cli.js as pure functions — behavior identical, enabling unit tests for logic that was previously top-level-only. Export parseFrontmatter/discover from skill-scanner.js (1-line each). Add tests/ with node:test (zero deps): - args: --resume absence, provider defaults, model position (8) - env: KEY=VALUE parsing, no-override, idempotent persistence (7) - skill-scanner: frontmatter scalars, discovery (6) - CLI integration: --sessions boot smoke, EOF graceful exit; full-session cases (piped input, flush, bare /provider) auto-skip without an API key Verification: conformance gate still IDENTICAL on both Node and QuickJS (114 events); 23 pass / 3 skip / 0 fail locally. CI now runs the suite after building the CLI. Note: Node recursive mkdirSync hangs on procfs paths (not a fast failure) — tests use an ENOTDIR fixture instead.
…h, flush await) Add a scripted FakeAdapter (extends LlmAdapter, DSH_FAKE_LLM=1 + DSH_PROVIDER=fake) so the CLI integration tests exercise real sessions with no network and no API key — the three SKILL.md CLI pitfalls now run in CI instead of being skipped. Bug fixes found by the new tests: 1. EOF race: piped stdin closing before the REPL armed dropped queued lines (close handler exited while lineQueue still held input). Fix: defer exit until the queue drains; ask loop exits when EOF + drained. 2. /exit fall-through: the exit command matched but did not return, so "/exit" was sent to the model as a prompt during the 500ms exit grace (bare-command fall-through, SKILL.md L270 variant). 3. gracefulExit guessed 500ms for the JSONL flush; now awaits ctx.sessionPersistence.flush() before exiting (SKILL.md L304). Tests: 25/25 pass (0 skip) — piped multi-line consumption, flush writes session files, bare /provider never reaches the model. Conformance still IDENTICAL on Node + QuickJS (114 events).
4222222
force-pushed
the
feat/cli-tests
branch
from
August 14, 2026 18:27
d50ca89 to
6ca4e3c
Compare
LouisYang841
pushed a commit
that referenced
this pull request
Aug 16, 2026
Equivalent of PR #5, adapted to current main: - add scripted DSH_FAKE_LLM fake provider so CLI sessions run without keys - record stdin EOF during boot and exit only when idle and the line queue is drained, preserving queued piped input - add integration coverage for piped input, /provider interception, /exit fall-through, flush-before-exit, and --sessions
Owner
|
Implemented the equivalent change directly on
I intentionally did not extract |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改动
为可测性重构(零行为变化)
cli/args.js(新):parseArgs()纯函数——原 cli.js 顶层的 argv/provider/model 解析cli/env.js(新):loadEnvFiles()+persistCredential()纯函数cli/cli.js:改为调用上述模块,行为不变cli/skill-scanner.js:导出parseFrontmatter/discover测试套件(node:test,零新依赖)
测试驱动的 3 个真实 bug 修复
ctx.sessionPersistence.flush()完成再退出新功能:DSH_FAKE_LLM 测试模式
FakeAdapter extends LlmAdapter(脚本化回复,无网络无 key)——DSH_FAKE_LLM=1 DSH_PROVIDER=fake驱动完整 CLI 会话,让集成测试在 CI 里真实运行。验证
Run CLI tests步骤已加入 conformance workflow注
mkdirSync在 procfs 路径挂起(非快速失败)——不可写目标用例用 ENOTDIR fixture