Skip to content

Fix unintended initial selection for value-type items and add form interaction tests#374

Merged
shibayan merged 11 commits into
masterfrom
fix/paginator-value-type-selection
Jul 5, 2026
Merged

Fix unintended initial selection for value-type items and add form interaction tests#374
shibayan merged 11 commits into
masterfrom
fix/paginator-value-type-selection

Conversation

@shibayan

@shibayan shibayan commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Summary

Two changes in Paginator<T>.UpdatePageSize:

  • It ignored the boolean result of TryGetSelectedItem and reused the out parameter, so for value-type items (e.g. enum Select) the item equal to default(T) was silently pre-selected on the first render — inconsistent with reference-type items, which start unselected.
  • It compared the requested page size against the clamped stored value, so whenever the item count was smaller than the requested size (the common PageSize = int.MaxValue default), the early return never hit and the paginator was fully reinitialized on every render.

This PR also adds a form interaction test harness: a scriptable FakeConsoleDriver that feeds queued key input through IConsoleDriver, plus tests driving SelectForm / MultiSelectForm / InputForm / ConfirmForm end to end (arrow-key selection, filtering, validation errors, default values, Escape cancellation, and the enum fallback). These tests are what surfaced the UpdatePageSize bug.

Notes

Stacked on #372 — the end-to-end enum test requires the reflection fallback. Merge #372 first; this PR targets its branch and should retarget to master once it lands.

Test plan

  • 2 new Paginator unit tests covering both regressions
  • 11 new form interaction tests
  • Full suite: 323 passed

🤖 Generated with Claude Code

shibayan and others added 5 commits July 5, 2026 15:51
…enerator

The v3.1 source generator only sees enum declarations in the consuming
compilation, so Prompt.Select/MultiSelect with a BCL enum or an enum from
an assembly built without the analyzer threw ArgumentNullException (Items).

Restore the v3.0 behavior by generating enum metadata at runtime via
reflection when no generated registration exists, honoring the same
Display(Name/Order) semantics as the generator. Generated registrations
still take precedence, keeping the AOT-friendly path intact.

Fixes #357

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…teraction tests

Paginator.UpdatePageSize ignored the TryGetSelectedItem result and reused
the out parameter, so for value-type items (e.g. enum Select) the item
equal to default(T) was silently pre-selected on the first render. It also
compared the requested page size against the clamped stored value, causing
a full reinitialization on every render whenever the item count was smaller
than the requested size.

Add a scriptable FakeConsoleDriver and interaction tests that drive the
Select/MultiSelect/Input/Confirm forms with queued key input, covering
arrow-key selection, filtering, validation errors, default values, Escape
cancellation, and the enum fallback end to end.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@shibayan shibayan requested a review from Copilot July 5, 2026 07:16
@shibayan shibayan self-assigned this Jul 5, 2026
@shibayan shibayan added the bug Something isn't working label Jul 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes two paginator regressions that affected selection behavior and render-time reinitialization, and adds end-to-end form interaction tests using a scriptable console driver to prevent similar issues going forward.

Changes:

  • Fix Paginator<T>.UpdatePageSize so value-type items don’t become implicitly “selected” via default(T) when no selection exists.
  • Fix UpdatePageSize early-return logic by comparing against the clamped/effective page size to avoid unnecessary reinitialization (e.g., PageSize = int.MaxValue cases).
  • Add a FakeConsoleDriver and new interaction tests covering selection, filtering, validation, defaults, cancellation, and enum fallback.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/Sharprompt/Internal/Paginator.cs Fixes selection preservation and page-size comparison logic in UpdatePageSize.
tests/Sharprompt.Tests/Internal/PaginatorTests.cs Adds unit tests covering both paginator regressions.
tests/Sharprompt.Tests/Forms/FakeConsoleDriver.cs Adds a scriptable console driver to enable deterministic end-to-end form interaction tests.
tests/Sharprompt.Tests/Forms/FormInteractionTests.cs Adds end-to-end tests for Select/MultiSelect/Input/Confirm flows and cancellation.

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

Comment thread tests/Sharprompt.Tests/Forms/FakeConsoleDriver.cs
Base automatically changed from fix/enum-metadata-fallback to master July 5, 2026 07:27
shibayan and others added 4 commits July 5, 2026 16:28
Write now advances CursorTop when text exceeds BufferWidth, using the same
East Asian width calculation as OffscreenBuffer and matching the deferred
wrap behavior its cursor math assumes. Add a test with a message longer
than the buffer width to exercise the wrapping path.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ution

EnumMetadataRegistry is a global static, so registering metadata for string
leaked an uppercase TextSelector into the form interaction tests that use
SelectOptions<string>, failing depending on test execution order. Register
a type unique to the test instead.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants