Commit graph

115 commits

Author SHA1 Message Date
William Martin
cb2b50576f Ensure huh prompter cleans up 2026-03-26 14:26:57 +01:00
Kynan Ware
84a3ba83e4 fix(huh prompter): remove unused fields and imports
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-26 14:26:57 +01:00
Kynan Ware
13e47d0078 feat(huh prompter): clear search input after submitting query
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-26 14:26:17 +01:00
Kynan Ware
cfb2224176 refactor(huh prompter): custom Field for MultiSelectWithSearch
Replace the OptionsFunc-based MultiSelectWithSearch with a custom huh
Field implementation. huh's OptionsFunc runs in a goroutine, causing
data races with selection state and stale cache issues that made
selections disappear on toggle or search changes.

The custom field (multiSelectSearchField) combines a text input and
multi-select list in a single field with full control over the update
loop. Search runs asynchronously via tea.Cmd when the user presses
Enter, with a themed spinner during loading. Selections are stored in
a simple map — no goroutine races, no Eval cache, no syncAccessor.

Also adds defensive validation for mismatched Keys/Labels slices from
searchFunc.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-26 14:26:17 +01:00
Kynan Ware
f38abbe1ca feat(huh prompter): add placeholder to search input
Add 'Type to search, Ctrl+U to clear' placeholder to the
MultiSelectWithSearch search input. Set WithWidth(80) in the test
harness to prevent textinput placeholder rendering panics when
there is no terminal.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-26 14:26:17 +01:00
Kynan Ware
38e10d5ebf fix(huh prompter): use synchronized accessors to eliminate data race
Replace Value() pointer bindings with syncAccessor in
MultiSelectWithSearch. huh's OptionsFunc runs in a goroutine while
the main event loop writes field values, causing a data race on
shared variables. syncAccessor implements huh's Accessor interface
with a shared mutex, ensuring all reads and writes are synchronized.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-26 14:26:17 +01:00
Kynan Ware
95a59f4431 fix(accessible prompter): update test expectations for huh v2
Fix accessible prompter tests that broke with the huh v2 upgrade:
- Replace 'Input a number' with 'Enter a number' (huh v2 changed text)
- Remove trailing CRLF from ExpectString calls that now fail due to
  ANSI color codes wrapping the title text
- Allow ANSI escape codes in password masking regex assertions

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-26 14:26:16 +01:00
Kynan Ware
4d74e057f2 refactor(huh prompter): pipe-based test harness with full coverage
Replace manual model updates with an io.Pipe-based test harness that
drives forms through bubbletea's real event loop. Interaction helpers
(tab(), toggle(), typeKeys(), enter(), etc.) send raw terminal bytes
through io.Pipe to form.Run() in a goroutine.

Add tests for AuthToken, ConfirmDeletion, and InputHostname including
validation rejection paths. Add MultiSelectWithSearch coverage for
persistent options and empty search results.

30 tests, ~1s, all build*Form methods at 94-100% coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-26 14:26:16 +01:00
Kynan Ware
86d876fd34 test(huh prompter): add table-driven tests for all prompt types
Extract build*Form() methods from each huhPrompter method, separating
form construction from form.Run(). This enables testing the real form
construction code by driving it with direct model updates, adapted
from huh's own test patterns.

Tests cover Input, Select, MultiSelect, Confirm, Password,
MarkdownEditor, and MultiSelectWithSearch including a persistence
test that verifies selections survive across search query changes.

Also fixes a search cache initialization bug where the first
buildOptions("") call would skip the searchFunc due to
cachedSearchQuery defaulting to "".

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-26 14:26:16 +01:00
Kynan Ware
f294831e7d Upgrade to huh/v2 and fix selection persistence in MultiSelectWithSearch
Migrate from github.com/charmbracelet/huh v1 to charm.land/huh/v2,
updating ThemeBase16 to the new ThemeFunc API.

Fix selected options being lost across searches in the huhPrompter's
MultiSelectWithSearch. The root cause was huh's internal Eval cache:
when the user returned to a previously-seen search query, cached
options with stale .selected state overwrote the current selections
via updateValue(). The fix includes selectedValues in the OptionsFunc
binding hash (via searchOptionsBinding) so the cache key changes
whenever selections change, preventing stale cache hits. A local
searchFunc result cache avoids redundant API calls when only the
selection state (not the query) has changed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-26 14:26:15 +01:00
Kynan Ware
726714d1a7 Use LayoutStack for huhPrompter MultiSelectWithSearch
Implement a huh-native MultiSelectWithSearch that renders the search
input and multi-select list simultaneously using LayoutStack. The
search input is in Group 0 and the multi-select in Group 1, with
OptionsFunc bound to the search query so results update when the
user presses Enter to advance focus. Users can Shift+Tab back to
refine their search, and selections persist across queries.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-26 14:24:56 +01:00
Kynan Ware
87426ee236 Add experimental huh-only prompter gated by GH_EXPERIMENTAL_PROMPTER
Introduce a new Prompter implementation (huhPrompter) that uses the
charmbracelet/huh library in its standard interactive mode, as an
alternative to the survey-based default prompter. The new implementation
is gated behind the GH_EXPERIMENTAL_PROMPTER environment variable,
following the same truthy/falsey pattern as GH_ACCESSIBLE_PROMPTER.

Key differences from the accessible prompter:
- No WithAccessible(true) flag (full interactive TUI)
- Uses EchoModePassword (masked with *) instead of EchoModeNone
- No default value annotations appended to prompt text

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-26 14:24:56 +01:00
Kynan Ware
a33d809c88
Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-01-26 15:09:16 -07:00
Kynan Ware
af124cd5d2 Add test for MultiSelectWithSearch error propagation
Introduces a test case to verify that errors returned from the MultiSelectWithSearch search function are properly propagated to the caller.
2026-01-26 13:56:47 -07:00
Kynan Ware
38f9d7891b Fix linter and mock prompter signature 2026-01-26 13:29:22 -07:00
Kynan Ware
07dfdf97ae Update edit tests
Updated test mocks and logic to consistently use lowercase 'monalisa' for login names and display names for user assignees. Improved handling of dynamic assignee fetching in interactive flows by relying on searchFunc and metadata population, and clarified logic in FetchOptions to fetch assignees only when necessary. These changes ensure more accurate simulation of interactive assignment and better test coverage for actor assignee features.
2026-01-26 13:29:22 -07:00
Kynan Ware
d46f42a752 Refactor MultiSelectWithSearch to use result struct
Refactored the MultiSelectWithSearch function and related interfaces to use a MultiSelectSearchResult struct instead of multiple return values. This change improves clarity and extensibility of the search function signature, and updates all usages, mocks, and tests accordingly.
2026-01-26 13:29:22 -07:00
Kynan Ware
38578f7991 Add comment describing logger
Added a comment explaining how to enable logging in expect-based tests by using expect.WithLogger. This helps developers debug by printing characters read to stdout.
2026-01-26 13:29:22 -07:00
Kynan Ware
0beb74bf72 MultiSelectWithSearch initial implementation
Initial implementation of MultiSelectWithSearch:

- Implement by survey and accessible prompters. They use the same internal func under the hood.
- Implement in `gh preview prompter` for initial testing and demonstration
- Implement interface changes across the codebase and mocks to satisfy compiler.
- Implement tests for new MultiSelectWithSearch prompter
2026-01-26 13:29:22 -07:00
William Martin
d88b4cb8ec Fix accessible prompter tests with huh 0.8.0 upgrade 2025-12-02 14:36:43 +01:00
Babak K. Shandiz
5db8cf7c1d
Increase beforePasswordSendTimeout to 100 us (#10977)
Signed-off-by: Babak K. Shandiz <babakks@github.com>
2025-05-13 12:38:45 +01:00
Andy Feller
7ceca4534d
Merge pull request #10937 from cli/kw/accessible-prompter-prints-readable-defaults-in-prompt
Accessible prompter always displays defaults in speech synthesis readable format
2025-05-09 08:48:10 -04:00
Babak K. Shandiz
90532e8377
Improve assertion for disabled echo mode (#10927)
* Improve assertion for disabled echo

Signed-off-by: Babak K. Shandiz <babakks@github.com>

* Use `expect.RegExpPattern`

Signed-off-by: Babak K. Shandiz <babakks@github.com>

---------

Signed-off-by: Babak K. Shandiz <babakks@github.com>
2025-05-08 21:26:02 +01:00
Kynan Ware
9b89a0ac0e fix(a11y prompter): remove invalid defaults 2025-05-08 07:41:36 -06:00
Kynan Ware
3594f6357b fix(a11y prompter): confirm prompt default is readable 2025-05-06 15:50:57 -06:00
Kynan Ware
04aaaea142 fix(a11y prompter): multi select defaults are readable 2025-05-06 15:43:26 -06:00
Kynan Ware
957667efe6 doc(prompter): remove TODO about default value panic 2025-05-06 15:33:51 -06:00
Kynan Ware
cab906151f fix(a11y prompter): select prompt default value is readable 2025-05-06 15:33:15 -06:00
Kynan Ware
ab4cfb84d2 refactor(a11yprompter): shared method for prompt defaults 2025-05-06 15:33:15 -06:00
Kynan Ware
2ee68411a7 fix(a11y prompter): Select prompt respects defaults 2025-05-06 15:33:15 -06:00
Kynan Ware
9bc2c388da fix(a11y prompter): input prompt default value is readable 2025-05-06 14:34:05 -06:00
William Martin
a2fcb9b2df
Merge pull request #10915 from cli/wm/projectsv1-deprecation-pr-create-rest
Feature detect v1 projects on interactive `pr create`
2025-05-06 15:24:04 +02:00
Kynan Ware
cc673cfaba test(prompter): add timeout before password input 2025-05-02 14:48:07 -06:00
William Martin
5a3aee056a Feature detect v1 projects on interactive pr create 2025-05-02 17:42:23 +02:00
Kynan Ware
00c930d509
doc(prompter): small typo 2025-04-30 08:04:16 -06:00
Andy Feller
8130126ce5
Merge pull request #10901 from cli/kw/fix-accessible-multi-select-prompter-respects-defaults
Fix: Accessible multiselect prompt respects default selections
2025-04-30 09:46:56 -04:00
Kynan Ware
d8512a9066 fix(prompter): respect default MultiSelect a11y prompter 2025-04-29 16:35:04 -06:00
Andy Feller
88d52ebf97 Fix other disabled echo mode comments 2025-04-28 11:20:17 -04:00
Andy Feller
df0aedbe3c
Update internal/prompter/prompter.go 2025-04-28 11:16:35 -04:00
Andy Feller
2d66877d6c
Update internal/prompter/accessible_prompter_test.go 2025-04-28 11:15:28 -04:00
Andy Feller
9fa00c350b Update accessible tests based on huh@0.7.0 changes 2025-04-28 10:17:23 -04:00
Andy Feller
a53b6c074c Assert password and auth token not displayed
This commit expands existing tests (thanks to @babakks) to assert whether the echo mode is actually disabled for password and auth token prompts.
2025-04-28 08:55:47 -04:00
Andy Feller
97a3b70599 Update to huh@0.7.0, echo mode changes
This commit is the initial change around updating to huh@0.7.0; pre-testing changes.
2025-04-26 12:57:10 -04:00
Kynan Ware
9463b0ee61 test(prompter): correct typo in accessible prompter name 2025-04-22 17:12:07 -06:00
Kynan Ware
138bccd437 feat(config): add accessible prompter and spinner 2025-04-22 16:50:58 -06:00
Andy Feller
f61961907e Update configuration support for accessible colors
- added support for `accessible_colors` configuration setting in `gh config` commandset
- updated default configuration file to contain `accessible_colors: disabled`
- add `GH_ACCESSIBLE_COLORS` env var to `gh environment`
- generated mocks via `go generate ./...` including previously missed prompter changes
2025-04-17 15:57:49 -04:00
Kynan Ware
70537de132
test(prompter): fix invalid comment 2025-04-10 17:18:56 -06:00
Kynan Ware
8cd39923fe test(prompter): fix race condition
This test was trying to block on `expect`’ing a string at the same
time the prompt was completed.

This doesn't need to happen for this test. It should just check for
the output from the Input prompt invocation.
2025-04-10 17:09:22 -06:00
Andy Feller
b8cd094ca8 Ensure markdown confirm prompt shows editor name
Apparently, `gh` might not actually have an editor at the time we're prompting
the user if they want to use it for markdown editing.  In the survey package,
there is a function that will handle fallback to the default editor based on
environment variables and parse it in the case the editor contains flags and
arguments for cases like Visual Studio Code.

Additionally, there are no tests for the EditorName function and the fact it
is loaded via `init` makes this difficult to test.

Co-authored-by: Kynan Ware <47394200+BagToad@users.noreply.github.com>
2025-04-10 16:28:58 -06:00
Kynan Ware
20ff409bfc fix(prompter): remove needless default value assignment 2025-04-10 16:28:57 -06:00