Skip to content

Smarter search#2901

Open
rumpl wants to merge 2 commits into
docker:mainfrom
rumpl:smarter-search
Open

Smarter search#2901
rumpl wants to merge 2 commits into
docker:mainfrom
rumpl:smarter-search

Conversation

@rumpl
Copy link
Copy Markdown
Member

@rumpl rumpl commented May 26, 2026

In the command palette typing "the" will now put "Theme" first on the list, and typing "ses" will put "Sessions" first on the list

In the command palette typing "the" will now put "Theme" first on the
list, and typing "ses" will put "Sessions" first on the list

Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
@rumpl rumpl requested a review from a team as a code owner May 26, 2026 21:01
Copy link
Copy Markdown

@docker-agent docker-agent left a comment

Choose a reason for hiding this comment

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

Assessment: 🔴 CRITICAL

The new test TestCommandPaletteFilteringRanksLabelPrefixFirst has a broken assertion — it expects session.attach to appear in filtered results for query "the", but none of that command's fields (label, slash command, or description) contain the substring "the". The test will fail as written.

for _, c := range d.filtered {
ids = append(ids, c.ID)
}
require.Equal(t, []string{"settings.theme", "session.attach"}, ids,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[HIGH] Test assertion incorrectly expects session.attach to appear for query "the"

The test TestCommandPaletteFilteringRanksLabelPrefixFirst queries for "the" and asserts []string{"settings.theme", "session.attach"}, but session.attach has:

  • Label: "Attach" → lowercase "attach" — does not contain "the"
  • SlashCommand: "/attach" — does not contain "the"
  • Description: "Attach a file to your message" — does not contain "the"

All four commandFieldQueryScore calls return commandQueryNoMatch, so session.attach is filtered out entirely. The actual filtered result would be ["settings.theme"] only, causing require.Equal to fail.

The intent of the test appears to be verifying that a label prefix match ranks ahead of a substring match. A suitable second command would be one whose description or label contains "the" as a mid-word substring (e.g., a command with description containing "the") to demonstrate that settings.theme (label prefix) ranks first.

Comment thread pkg/tui/dialog/command_palette.go Outdated
if index == 0 {
return true
}
previous := value[index-1]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LOW] isCommandQueryWordStart uses byte indexing; non-ASCII characters before the match position are not recognized as word boundaries

value[index-1] reads one byte before the match (where index is a byte offset from strings.Index). If the preceding character is a multi-byte UTF-8 sequence (e.g., é, ñ, or CJK), index-1 lands inside that sequence and reads a continuation byte (0x80–0xBF), which never equals any ASCII word-separator. This means a non-ASCII character immediately before the query match is never classified as a word boundary, slightly degrading ranking for non-ASCII content.

For the current use case (ASCII command names and descriptions) this has no practical impact. Consider using utf8.DecodeLastRuneInString(value[:index]) if internationalized command labels are ever needed.

- Remove unused matchesCommandQuery wrapper (lint: unused)
- Fix TestCommandPaletteFilteringRanksLabelPrefixFirst: session.attach
  description now contains "the" so it actually matches the query
- isCommandQueryWordStart: decode previous rune via utf8 so non-ASCII
  characters preceding the match are handled correctly
@aheritier aheritier added area/tui For features/issues/fixes related to the TUI kind/feat PR adds a new feature (maps to feat: commit prefix) labels May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/tui For features/issues/fixes related to the TUI kind/feat PR adds a new feature (maps to feat: commit prefix)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants