Replace module-level _test* seams with dependency injection
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Refactorización
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- bun, node.js, typescript
Línea de trabajo
Start with the _testSetPlatform and _testSetExecSync seams: packages/config-resolver/src/index.ts, src/config/writer.ts, src/config/secret-store.ts and src/extension/store.ts, where process.platform is copied into a module-level let _platform. Find how each module is called and replace the seam with an injected deps parameter. Done when those two setters are gone, the tests pass under both Node and Bun, and the rg -n 'export function _test' count drops. The issue also asks for a policy line in AGENTS.md.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
Production modules expose module-level _test* setters that tests use to swap out globals (stdin reader, TTY, execSync, process.platform, fetch, spawn, client singletons). Each one is a mutable module global plus a setter, and tests must restore it in finally. They also ship in the published package, because package.json files includes dist.
Counts (taken at the current main working copy):
rg -n 'export function _test' src packages/*/src→ 23 exported seams in 12 files:src/factory.ts:64,82,101(_testSetStdinReader,_testSetIsTTY,_testSetConfirmReader)_testSetExecSync×3:packages/config-resolver/src/index.ts:341,src/config/writer.ts:46,src/config/secret-store.ts:130_testSetPlatform×4: the same three files (:347,:53,:144) plussrc/extension/store.ts:34_testReset*×7: Es/Kibana/Cloud clients, config store, detection, resolvers, loose inline secret warning- extension:
runner.ts:32,installer.ts:52,60,store.ts:34,78
- Module-level
_testSetFetchexists only once (src/status/register.ts:43). The ES/Kibana/Cloud clients have_testSetFetchas an instance method (es-client.ts:151,kibana-client.ts:226,cloud-client.ts:92), not as an export. rg -l '_test[A-Z]' --glob '*.test.*' .→ 28 test files use them.rg -l '_testSet' distlists built.jsand.d.tsfiles, e.g.dist/factory.js,dist/config/secret-store.d.ts,dist/lib/cloud-client.d.ts. Your counts depend on how fresh your localdistis.rg -l 'mock\.(method|module|fn)' --glob '*.test.*' .→ 1 hit, and that hit is a comment.test/es/handler.test.ts:50explains that a hand-rolledspy()exists because "t.mock.fn()… is not implemented in Bun".
The four _testSetPlatform seams are needed because each module copies process.platform into a let _platform at module scope (e.g. packages/config-resolver/src/index.ts:133, src/extension/store.ts:31). Stubbing process.platform after import would not reach that copy.
Motivation
Every seam adds global mutable state. If a test forgets to restore one, the stub leaks into later tests in the same file. The _test* names also become de facto public API of the published package. Because package.json declares "bun": ">=1.2.0" in engines, swapping these seams for t.mock.method / mock.module from node:test is not a safe default. The repo already avoids t.mock.fn for Bun compatibility.
Proposal
- Policy: add no new
_test*exports. Use dependency injection (adepsparameter or constructor option), assrc/docs/*(deps.stdout) andsrc/es/handler(EsHandlerDeps) already do. - Migrate the highest-churn seams first:
_testSetExecSync: this goes away with the execFile migration._testSetPlatform: passplatformas a dep instead of a module-scope copy.fetch: one injection point in the shared client core (see the sibling client-core consolidation issue, #728).
- Once the remaining seams are migrated, strip leftover
_test*symbols from published types, e.g. with@internal+stripInternal.
Only use node:test mocking APIs where they are confirmed to work under both Node ≥22.1 and Bun ≥1.2.
Acceptance criteria
-
AGENTS.md(orCONTRIBUTING.md) states the "no new_test*exports" rule. -
_testSetExecSyncand_testSetPlatformare removed. Callers take injected deps, and tests pass on Node and Bun. -
rg -n 'export function _test' src packages/*/srccount goes down. Track it in the PR description. - No
_testSet*symbol appears indist/**/*.d.tsfor the migrated modules.
Related
- #728 (shared HTTP client core): the natural single
fetchinjection point - A sibling issue on shared test helpers (e.g. promoting
spy()fromtest/es/handler.test.ts)
authored by Pi Coding Agent (Claude Opus 5.5)
- Lenguaje dominante
- TypeScript
- Estrellas
- 53
- Forks
- 28
- Merge medio
- 4 d 12 h
- PR fusionados (30 d)
- 61
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de elastic/cli
-
tracking
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
Los mantenedores suelen responder en 1 día
-
feat: ship skills/elastic/SKILL.md for agent invocationPosiblemente ocupada @onatozmenn la tomó hace 32 días. Abiertoenhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
elastic/cli#628 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
elastic/cli#617 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
tracking
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
Los mantenedores suelen responder en 1 día
Todos los issues de elastic/cli
Issues similares
-
area:desktop area:ui bug platform:macos
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
anthropics/claude-code#106183 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
feature:App-Tour feature:Chat ready Web
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
digitalfabrik/integreat-app#4523 · 2 reacciones ·
Los mantenedores suelen responder en 3 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Required Lexical field accepts two empty paragraphsPosiblemente ocupada @lazerg la tomó hoy. AbiertoBug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
payloadcms/payload#19222 ·
Los mantenedores suelen responder en 1 día