Consolidate test harness helpers and replace global stdout/stderr patching
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 重构
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- nodejs, typescript
- 领域
- testing
调研方向
Start with the duplicated helpers the issue lists: test/es/helpers/bulk-ingest.test.ts, watch.test.ts, scroll-search.test.ts and msearch.test.ts, plus test/factory.test.ts and test/config/text-output.test.ts. Run rg -n 'process\.(stdout|stderr)\.write = ' test to confirm the baseline. Done means one shared capture and transport helper under test/helpers/ that uses t.mock.method, with the grep returning 0 and npm test passing. The helper signatures differ between files, so decide on a shared signature with the maintainers before migrating.
由索引模型根据 Issue 内容生成。
描述
Problem
Tests patch global streams by hand and copy the same harness helpers between files.
- Global stream patching.
rg -n 'process\.(stdout|stderr)\.write = ' testfinds 82 assignments in 19 files (rg -l ... | wc -l). Examples:test/config/text-output.test.ts,test/config/loader.test.ts,test/docs/chat.test.ts:138-158. If a test skips its restore, runner output is lost and later tests see the stub. - Duplicated helpers (
rg -n 'function <name>\b|const <name>\b' test):mockTransport: 4 files (test/es/helpers/{bulk-ingest,scroll-search,watch,msearch}.test.ts)makeDeps: 5 files (the four above plustest/es/handler.test.ts:40)runCommand: 4;captureOutput: 4 in 3 files;captureStdout: 2 (test/factory.test.ts:2059,2364,4188,test/es/search-schema.test.ts:33,test/es/helpers/watch.test.ts:49)makeClient: 4 in 2 files (test/lib/es-client.test.ts,test/lib/kibana-client.test.ts)mkdtemp: 24 files.ELASTIC_CLI_CONFIG_FILEused: 9 files.
The copies have different signatures:
bulk-ingest.test.ts:18mockTransport(responses: Array<{ errors: boolean, items: ... }>)vswatch.test.ts:32mockTransport(responses: MockResponse[])factory.test.ts:2059captureOutput(fn: () => Promise<void>)vswatch.test.ts:49captureOutput()(takes no arguments and returns a sink)
Note: test/docs/chat.test.ts patches process.stderr.write on purpose. The test checks that the chat loop never writes to the real stderr (assert.deepEqual(realWrites, [])). It does not show a bypass in src/docs/*.
Proposal
Add test/helpers/{capture,transport,tmp-config}.ts. capture(t) uses t.mock.method(process.stdout, 'write', ...), which node:test restores automatically. Migrate in small PRs: the four test/es/helpers tests first, then factory.test.ts. Keep the chat.test.ts guard, but switch it to t.mock.method.
Acceptance criteria
-
rg 'process\.(stdout|stderr)\.write = ' testreturns 0 matches - Only one
mockTransport/captureOutputdefinition exists, intest/helpers/ - Temporary config setup (
mkdtemp+ELASTIC_CLI_CONFIG_FILE) goes through one helper with automatic cleanup -
npm testpasses on all supported Node versions
Related: #733 (DI for _test* seams).
authored by Pi Coding Agent (Claude Opus 5.5)
- 主要语言
- TypeScript
- 星标
- 47
- 派生
- 27
- 平均合并
- 2 天 6 小时
- 30 天内合并 PR
- 52
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
elastic/cli 的其他 Issue
-
feat: ship skills/elastic/SKILL.md for agent invocation可能已有人在做 @onatozmenn 于 15 天前认领。 未关闭enhancement
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 3/5 半天 新手友好度 62/100
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 20/100
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 70/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
NaturalIntelligence/fast-xml-parser#890 · 1 条评论 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
zsviczian/obsidian-excalidraw-plugin#3000 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
pnpm/get.pnpm.io#68 ·
-
[BUG] Cloudflare KV binding 模式下 kvDriver.list() 沿用 EdgeOne 语义,字段名不匹配导致 key 格式下初始化 500 并耗尽 list 配额可能已有人在做 @wumingzhinu 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 64/100
OpenListTeam/OpenList-Worker#125 ·
维护者通常 2 天内回复
-
Android (vision-camera-location): HybridLocationManager never quits its HandlerThread on dispose未关闭
难度 2/5 1-3 小时 新手友好度 74/100
margelo/react-native-vision-camera#4217 ·
维护者通常 4 天内回复