Repository navigation
fix(spawn): hide the remaining Windows console windows on git child launches - #687
Conversation
…aunches #679 hid the console window on the child launches it could reach, but a run-time audit of an installed 0.24.0 build (101 child processes observed, report at teamai-e2e/E2E-REPORT.md §4) found three more git spawns that still run without `windowsHide`: src/providers/git/index.ts - gitIdentity() spawnSync('git', ['config', '--get', 'user.name']) - ensureInstalled() spawnSync('git', ['--version']) src/wiki-engine/code-knowledge/code-collector.ts - gitCommit() execFileAsync('git', ['-C', root, 'rev-parse', 'HEAD']) (no options object was passed at all) Those three sat outside #679's scope. The first two are GenericGitProvider, which only runs for a repository whose host we do not recognise, so #679's `provider` / `gitHub` / `gitLab` paths never touched them; the third runs on every `teamai import --from-repo` scan. `gitCommit()`'s two neighbours in the same module — `isWorkingTreeClean()` (`git status --porcelain`) and `gitDiffNameStatus()` (`git diff --name-status`) — launch the same kind of child with the same missing option and are fixed alongside it. `cloneRepo()` in the same file is not in the audit table (the `git` provider never reached a clone in that run) but shares its second argument shape with `ensureInstalled()` and flashes once per clone, so it is fixed here too. When the parent has no console of its own — a GUI host or a hook host — Windows gives the child a new one, which flashes a visible window. Tests - `generic-git-provider.test.ts`: new `GenericGitProvider — windowsHide` block drives `ensureInstalled()` -> `authenticate()` -> `cloneRepo()` and asserts all three `spawnSync` calls carry `windowsHide: true`. - `code-collector-windowshide.test.ts` (new): mocks `node:child_process`, drives the three helpers and asserts the same on the options object passed to `execFile`. CI has no Windows runner (`os: [ubuntu-latest, macos-latest]`), so these assertions on the options object are the only guard available.
|
The review on #687 pointed out that the fix only covered `GenericGitProvider.cloneRepo()`. The identified-provider production paths launch `git clone` the same way, and `teamai init` reaches them whenever the remote host is known: - providers/github/gh-cli.ts ghRepoClone() - providers/gitlab/gitlab-api.ts gitlabRepoClone() - providers/gitcode/gitcode-api.ts gitcodeRepoClone() - providers/cnb/cnb-cli.ts cnbRepoClone() (clone + credential-helper write) - providers/tgit/gf-cli.ts gfRepoClone() All six spawn sites now pass `windowsHide: true`, matching the existing style in clone.ts / builtin-hooks.ts / hook-dispatch-cli.ts. provider-clone-windowshide.test.ts drives each clone function with a mocked `node:child_process` and asserts the option is present on every `git` launch (the CNB no-token path launches twice, so it covers the credential-helper write too). CI runs on ubuntu/macos only, so these assertions are the only guard against this regressing on Windows. Internal-path `spawnSync('bash', ...)` calls in tgit/gf-cli.ts are deliberately left alone: they are not git launders and are tracked separately in #686.
|
Both P1s addressed. 1. Incomplete fix — the identified-provider clone pathsYou are right, and my "listed in #686 for the maintainers to decide" framing was the wrong call for a PR that claims to fix the Windows flash. All six sites now pass
Style matches what is already in
Reverting the five provider files to Being straight about the coverage limit: these six paths cannot be reached by the real-CLI harness I have. They are only selected when the host resolves to
2. The build + real-CLI record
All six call sites of this PR were hit on the real path:
For contrast, the #679 run recorded 4 launches with 3. Two things I found while producing that record(a) The audit harness itself was producing a false failure mode. The original Fixed by re-attaching the custom promisify on the wrapper; the original is kept as (b) Full report, raw 4. Local checks
|
|
|
Addressed in the PR description — You were right that the 101-launch audit was not evidence about this build: it was measured on
All six call sites are listed in the description with the path that reaches each one and the observed The five provider clone functions added in One correction to the instrument itself, also written up in the description: the first version of the |
Fixes #686.
What
#679 hid the console window on the child launches it could reach. A run-time audit of the released
0.24.0 build — every
child_processlaunch instrumented, 101 launches acrossinit/import --from-repo/doctor/packages— found three moregitlaunches on a code path #679did not touch. This PR fixes those three plus the siblings that reading the same two files turns up.
src/providers/git/index.ts:28gitIdentity()spawnSync('git', ['config','--get','user.name'], …)— nowindowsHidesrc/providers/git/index.ts:72ensureInstalled()spawnSync('git', ['--version'], …)— nowindowsHidesrc/providers/git/index.ts:85cloneRepo()spawnSync('git', ['clone','--',…], …)— nowindowsHidesrc/wiki-engine/code-knowledge/code-collector.ts:146gitCommit()execFileAsync('git', ['-C', root, 'rev-parse','HEAD'])— no options object at allsrc/wiki-engine/code-knowledge/code-collector.ts:162isWorkingTreeClean()execFileAsync(…)— no options objectsrc/wiki-engine/code-knowledge/code-collector.ts:183gitDiffNameStatus()execFileAsync(…)— no options objectThe first two are
GenericGitProvider, which is selected only when the repository host is not onewe recognise — so #679's
provider/gitHub/gitLabbranches never reached them. Thecode-collector three run on every
teamai import --from-repo/ wiki scan.The code-collector change hoists one module-level constant so the three call sites stay in sync:
cloneRepo()is not in the audit table (thegitprovider never reached a clone in that run) butshares its second-argument shape with
ensureInstalled()and flashes once per clone, so it isfixed here too.
Why it matters
A parent with no console of its own — a GUI host or a hook host — makes Windows give the child a
new one, which flashes a visible window. Before this change a single
teamai init <git-url>plus asingle
teamai import --from-repostarts four such children: the audit recorded 4 launches withwindowsHide=Noneout of 101, three of them on these branches.Tests
src/__tests__/generic-git-provider.test.ts— newGenericGitProvider — windowsHideblock drivesensureInstalled()→authenticate()→cloneRepo()and asserts all threespawnSynccallscarry
windowsHide: true.src/__tests__/code-collector-windowshide.test.ts(new) — mocksnode:child_process, drives thethree helpers, asserts the same on the options object handed to
execFile.Both assert on the options object on purpose: CI has no Windows runner
(
os: [ubuntu-latest, macos-latest]), so nothing else can catch a missingwindowsHide.Verified locally on Windows 11 25H2 / Node 22.22.2:
tsc --noEmitTest Files 2 passed (2)/Tests 19 passed (19)Test Files 2 failed (2)/Tests 2 failed | 17 passedThe revert run fails on exactly the two new assertions, i.e. the tests do guard the change:
Real-CLI end-to-end verification on this build
The 101-launch audit above was measured against released 0.24.0. It documents what those branches
did before this PR; it is not evidence about this build. Here is the same instrument re-run on the
built output of the branch head.
Build.
npm run build→dist/index.js1,804,627 B (head3cb1b28, Windows 11 25H2,Node 22.22.2, tsup 8.5.1).
Harness. The
gitprovider channel from the #679 audit: a bare fixture repo exported bygit daemonon127.0.0.1:9418, reached ashttps://127.0.0.1:9418/group/fixture.gitso the hostis unknown and
resolveHostProviderselectsGenericGitProvider.USERPROFILE/HOMEandGIT_CONFIG_GLOBALare redirected into a scratch directory, and the credential guards are the same(
GIT_TERMINAL_PROMPT=0,GCM_INTERACTIVE=never,GCM_GUI_PROMPT=0,GIT_ASKPASS=,SSH_ASKPASS=). Everychild_processentry point is wrapped by a CJS--requireshim.Commands and results.
windowsHideinit <url> --scope user --agent codebuddy --forceimport --from-repo <url> --skip-enrich --all --output <out>import --from-repo <url> --incremental --skip-enrich --all --output <out>All six call sites this PR touches were reached on the real paths:
providers/git/index.tsensureInstalled()spawnSync('git', ['--version'], …)initproviders/git/index.tsgitIdentity()spawnSync('git', ['config','--get','user.name'], …)initproviders/git/index.tscloneRepo()spawnSync('git', ['clone','--',…], …)initcode-collector.tsgitCommit()execFile('git', ['-C',<cache>,'rev-parse','HEAD'], …)importcode-collector.tsisWorkingTreeClean()execFile('git', ['-C',<cache>,'status','--porcelain'], …)import --incrementalcode-collector.tsgitDiffNameStatus()execFile('git', ['-C',<cache>,'-c','core.quotePath=false','diff','--name-status','-M','-C',<old>,<new>], …)import --incrementalRaw records, showing the options object arrived at the three
execFileshapes:{"fn":"execFile","cmd":"git","args":["-C","…\\cache\\repos\\git\\group\\fixture","rev-parse","HEAD"],"hasOptions":true,"windowsHide":true,"stdio":null,"shell":null} {"fn":"execFile","cmd":"git","args":["-C","…\\cache\\repos\\git\\group\\fixture","status","--porcelain"],"hasOptions":true,"windowsHide":true,"stdio":null,"shell":null} {"fn":"execFile","cmd":"git","args":["-C","…\\cache\\repos\\git\\group\\fixture","-c","core.quotePath=false","diff","--name-status","-M","-C","0b3a193cde29fb05acc38eff2ce90103ae0e9986","0cfb450976422a9a03591a81eaf2003b875342ee"],"hasOptions":true,"windowsHide":true,"stdio":null,"shell":null}The incremental run fetched a real new fixture commit and acted on the diff, so the code-collector
paths were live rather than skipped:
For comparison, the #679 run recorded
windowsHide=Noneon 4 of 101 launches under these samecommands — three of them on the branches this PR fixes. On this build: 0 of 63.
The instrument had to be fixed before it could be trusted. The first shim replaced the six
child_processentries with a plainfunction (...args) { record(...); return original.apply(this, args); },which drops
util.promisify.custom.promisify(execFile)then degrades from{ stdout, stderr }toa bare string, so
code-collector'sconst { stdout } = …receivedundefined,stdout.trim()threw, and each function's own
catchswallowed it — the shim was manufacturing a silent failureand hiding the very incremental path it was meant to observe.
spawn-audit.cjsnow re-attaches thesymbol after wrapping, and the unfixed original is kept next to it so the #679 numbers stay
reproducible.
What this does not cover. The five clone functions added in
3cb1b28(ghRepoClone,gitlabRepoClone,gitcodeRepoClone,cnbRepoClone,gfRepoClone) run only when the host matchesgithub/gitlab/gitcode/cnb/tgit, which needs a live instance and a token perprovider, so the
gitchannel cannot reach them. They are covered bysrc/__tests__/provider-clone-windowshide.test.tsinstead: everygitlaunch is asserted to carrywindowsHide: true, and the CNB no-token path launches twice so the credential-helper write iscovered too. With the patch the three related files give
Test Files 3 passed (3)/Tests 24 passed (24); with the five provider files restored toHEADand only the test file kept,Tests 5 failed (5), each onexpected { encoding: 'utf-8', …(2) } to deeply equal ObjectContaining {"windowsHide": true}.Since CI runs only
ubuntu-latest/macos-latest, that assertion is the only guard this Windowsbehaviour has.
One incidental finding, out of scope here:
isWorkingTreeClean()is unreachable in practice. Theproduct writes its own cache artefacts (
LAST_SYNC,teamwiki/) into the same tree it then asksgit status --porcelainabout, so the tree is never clean andgitDiffNameStatus()only runs whenthose are excluded. The run above adds them to the cache clone's
.git/info/exclude, which touchesthe scratch clone and not the repo under test; worth a separate issue.
Not cited: the whole-suite run
I am not presenting a green whole-suite run, because on this Windows host the signal is
swamped. A full run reports
52 failed | 213 passedfiles and180 failed | 3415 passedtests,but the two files this PR touches are not in the failing set, and 149 of the 180 failures are
temp-directory artefacts:
Test timed out in 5000msEBUSY: resource busy or locked, rmdir 'C:\Users\…\AppData\Local\Temp\…'Hook timed out in 15000ms[vitest-worker]: Timeout calling "onTaskUpdate"0o600vs0o666,alpha\real.mdvsalpha/real.md, …)So: not a regression claim, and not a pass claim — the suite simply is not a usable gate here.
To put numbers behind that, I re-ran those 52 files serially with
--testTimeout=30000 --hookTimeout=60000. I stopped the sweep after 6 files (19 minutes; the full sweep would have runfor hours), and 4 of the 6 that had failed in the parallel run passed outright:
contribute-self-learnings.test.tslocal-agent-mcp.test.tsmigrate.test.tspull-submodule-skip-sync.test.tsgit-kind-reports.test.tslocal-agent.test.tsThe last two do not import either module this PR touches —
git-kind-reports.test.tsdrivessimple-gitandutils/reports-branch.js,local-agent.test.tsdriveshooks.js— and theirdetailed failure output is only printed at the end of a run, which I stopped before it got there,
so I am deliberately not characterising them. 4 of 6 flipping to green purely by removing
parallelism is the shape of the noise, not of a regression.