Skip to content

perf: cache completion scripts in shell completion tests#166

Open
toiroakr wants to merge 1 commit intomainfrom
perf/cache-completion-scripts-in-tests
Open

perf: cache completion scripts in shell completion tests#166
toiroakr wants to merge 1 commit intomainfrom
perf/cache-completion-scripts-in-tests

Conversation

@toiroakr
Copy link
Owner

@toiroakr toiroakr commented Mar 6, 2026

Summary

  • Pre-generate completion scripts once per shell in setupTestContext() / setupNestedTestContext() instead of spawning tsx/Node.js on every test invocation
  • Each *Complete() helper now accepts an optional scriptPath to source from file instead of running eval "$(app completion shell)"
  • Interactive test functions (zpty, expect, complete --do-complete) also use cached scripts

This eliminates ~500-1500ms tsx/Node.js startup overhead per test call, reducing fish tests from ~44s to ~6s, zsh from ~94s to ~37s, and bash from ~121s to ~64s. Fixes intermittent CI timeouts in shell completion tests.

Code Metrics Report

main (3bebf51) #166 (3953751) +/-
Coverage 88.6% 88.6% 0.0%
Test Execution Time 50s 42s -8s
Details
  |                     | main (3bebf51) | #166 (3953751) | +/-  |
  |---------------------|----------------|----------------|------|
  | Coverage            |          88.6% |          88.6% | 0.0% |
  |   Files             |             41 |             41 |    0 |
  |   Lines             |           3164 |           3164 |    0 |
  |   Covered           |           2804 |           2804 |    0 |
+ | Test Execution Time |            50s |            42s |  -8s |

Reported by octocov

Pre-generate completion scripts once per shell in setupTestContext()
instead of spawning tsx/Node.js on every test invocation. This
eliminates ~500-1500ms overhead per test call and significantly
reduces total test duration and CI timeout risk.
Copilot AI review requested due to automatic review settings March 6, 2026 13:49
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves shell completion test performance by generating each shell’s completion script once per test context and reusing it across all completion helper calls and interactive completion tests, avoiding repeated Node/tsx startup.

Changes:

  • Add completionScripts (bash/zsh/fish) to the shell test context and generate scripts during setupTestContext() / setupNestedTestContext().
  • Update bash/zsh/fish completion helpers to optionally source a cached script file via scriptPath instead of running eval "$(app completion ...)" each time.
  • Update interactive completion tests (bash/expect, zsh/zpty, fish/complete --do-complete) to source cached scripts.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
tests/shell-completion/helpers.ts Generates and stores cached completion scripts; adds scriptPath support to completion helpers.
tests/shell-completion/bash.test.ts Uses cached bash completion script for raw and interactive completion tests.
tests/shell-completion/zsh.test.ts Uses cached zsh completion script for raw and zpty-based interactive completion tests.
tests/shell-completion/fish.test.ts Uses cached fish completion script for raw and complete --do-complete interactive tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants