Files
OpenSpec/test/cli-e2e
76d49a1d81 perf(completion): keep Tab completion off telemetry and heavy imports (#2064)
* perf(completion): keep Tab completion off telemetry and heavy imports

Shell completion scripts run `openspec __complete <type>` on every Tab
press. Each press loaded 344 modules (zod, yaml, fast-glob, ora) and, with
telemetry on, waited for the usage request before exiting.

- Skip the telemetry and completion-tip hooks for `__complete`. The
  scripts send stderr to /dev/null, so the first-run notice would also be
  marked seen there without anyone reading it.
- Load `ora` only in install and uninstall, which use the spinner.
- Load `listSchemas` from the resolver inside `getSchemaNames` instead of
  through the artifact-graph barrel, which also pulls in fast-glob.

Completing changes or specs now loads 48 modules (commander only), and
schemas loads 219. Part of #2026, items 1 and 2.

* test(completion): pin the privacy fix, the skip's narrowness, and zsh's redirect

The change is sound - completion output is byte-identical on all four
types, the hook skip matches the command path exactly, and all four
generated scripts discard `__complete` stderr. What was thin was the
coverage around it.

The startup assertions pin that `telemetry/index.js` is not loaded. They do
not pin the consequence that makes this worth doing. The disclosure goes to
stderr, every completion script sends `__complete` stderr to /dev/null, and
`maybeShowTelemetryNotice` marks `noticeSeen` before `trackCommand` re-reads
it - so a user whose first-ever interaction was a Tab press had the notice
burned where nobody could read it and collection started on that same
press. A new e2e test runs `__complete` with telemetry left enabled and an
isolated HOME, and asserts stderr is empty and no config file is written.

Two traps in that test, both of which made it pass vacuously before they
were fixed. `HOME` has to be isolated as well as `XDG_CONFIG_HOME`, or
`migrateLegacyTelemetryConfig` imports the developer's real config. And the
opt-out variables must be deleted rather than set to `''`: both read as
"set to anything that is not an explicit on-value", so blanking them
switches telemetry off and the assertions then hold on any build. Verified
against main, where the test now fails on the notice appearing in stderr.

Added a negative control, because nothing asserted that normal commands
still reach the hooks. `isTabCompletionRun` matches exactly, while the
adjacent `isCompletionRun` prefix-matches `completion:*`; widening one into
the other would silently stop tracking that whole group with every existing
assertion still green.

The zsh generator was the one shell whose test did not pin the stderr
redirect, though it has the most call sites and is the macOS default. It
now checks every real invocation, skipping the comment lines that name the
command without running it.

Also made the schemas test say what its name promises: it now pins that the
resolver loads and the artifact-graph barrel does not, since the barrel
re-exports the same function but pulls in fast-glob.

6414 tests pass; lint clean.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Clay Good <hi@claygood.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-10-14 19:13:00 +00:00
..