-
Notifications
You must be signed in to change notification settings - Fork 12
🤖 refactor: make command palette a workspace switcher by default #477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4f92a8e
🤖 refactor: make command palette a workspace switcher by default
ammar-agent a3162c2
refine: only show workspace switching by default, not mutations
ammar-agent aa1228e
fix: enable cmdk filtering for > queries
ammar-agent 5ca6ba5
fix: exclude switching commands when using > prefix
ammar-agent deab377
refactor: extract filtering logic to utility function
ammar-agent 113bf09
refactor: make tests property-based, not data-dependent
ammar-agent 1b04505
🤖 refactor: centralize command ID construction
ammar-agent 98df4b2
🤖 refactor: eliminate prefix duplication in commandIds
ammar-agent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { filterCommandsByPrefix } from "@/utils/commandPaletteFiltering"; | ||
| import { CommandIds, CommandIdMatchers } from "@/utils/commandIds"; | ||
|
|
||
| /** | ||
| * Tests for command palette filtering logic | ||
| * Property-based tests that verify behavior regardless of specific command data | ||
| */ | ||
|
|
||
| describe("CommandPalette filtering", () => { | ||
| describe("property: default mode shows only ws:switch:* commands", () => { | ||
| test("all results start with ws:switch:", () => { | ||
| const actions = [ | ||
| { id: CommandIds.workspaceSwitch("1") }, | ||
| { id: CommandIds.workspaceSwitch("2") }, | ||
| { id: CommandIds.workspaceNew() }, | ||
| { id: CommandIds.navToggleSidebar() }, | ||
| ]; | ||
|
|
||
| const result = filterCommandsByPrefix("", actions); | ||
|
|
||
| expect(result.every((a) => CommandIdMatchers.isWorkspaceSwitch(a.id))).toBe(true); | ||
| }); | ||
|
|
||
| test("excludes all non-switching commands", () => { | ||
| const actions = [ | ||
| { id: CommandIds.workspaceSwitch("1") }, | ||
| { id: CommandIds.workspaceNew() }, | ||
| { id: CommandIds.workspaceRemove() }, | ||
| { id: CommandIds.navToggleSidebar() }, | ||
| ]; | ||
|
|
||
| const result = filterCommandsByPrefix("", actions); | ||
|
|
||
| expect(result.some((a) => !CommandIdMatchers.isWorkspaceSwitch(a.id))).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("property: > mode shows all EXCEPT ws:switch:* commands", () => { | ||
| test("no results start with ws:switch:", () => { | ||
| const actions = [ | ||
| { id: CommandIds.workspaceSwitch("1") }, | ||
| { id: CommandIds.workspaceNew() }, | ||
| { id: CommandIds.navToggleSidebar() }, | ||
| { id: CommandIds.chatClear() }, | ||
| ]; | ||
|
|
||
| const result = filterCommandsByPrefix(">", actions); | ||
|
|
||
| expect(result.every((a) => !CommandIdMatchers.isWorkspaceSwitch(a.id))).toBe(true); | ||
| }); | ||
|
|
||
| test("includes all non-switching commands", () => { | ||
| const actions = [ | ||
| { id: CommandIds.workspaceSwitch("1") }, | ||
| { id: CommandIds.workspaceNew() }, | ||
| { id: CommandIds.workspaceRemove() }, | ||
| { id: CommandIds.navToggleSidebar() }, | ||
| ]; | ||
|
|
||
| const result = filterCommandsByPrefix(">", actions); | ||
|
|
||
| // Should include workspace mutations | ||
| expect(result.some((a) => a.id === CommandIds.workspaceNew())).toBe(true); | ||
| expect(result.some((a) => a.id === CommandIds.workspaceRemove())).toBe(true); | ||
| // Should include navigation | ||
| expect(result.some((a) => a.id === CommandIds.navToggleSidebar())).toBe(true); | ||
| // Should NOT include switching | ||
| expect(result.some((a) => a.id === CommandIds.workspaceSwitch("1"))).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("property: modes partition the command space", () => { | ||
| test("default + > modes cover all commands (no overlap, no gaps)", () => { | ||
| const actions = [ | ||
| { id: CommandIds.workspaceSwitch("1") }, | ||
| { id: CommandIds.workspaceSwitch("2") }, | ||
| { id: CommandIds.workspaceNew() }, | ||
| { id: CommandIds.workspaceRemove() }, | ||
| { id: CommandIds.navToggleSidebar() }, | ||
| { id: CommandIds.chatClear() }, | ||
| ]; | ||
|
|
||
| const defaultResult = filterCommandsByPrefix("", actions); | ||
| const commandResult = filterCommandsByPrefix(">", actions); | ||
|
|
||
| // No overlap - disjoint sets | ||
| const defaultIds = new Set(defaultResult.map((a) => a.id)); | ||
| const commandIds = new Set(commandResult.map((a) => a.id)); | ||
| const intersection = [...defaultIds].filter((id) => commandIds.has(id)); | ||
| expect(intersection).toHaveLength(0); | ||
|
|
||
| // No gaps - covers everything | ||
| expect(defaultResult.length + commandResult.length).toBe(actions.length); | ||
| }); | ||
| }); | ||
|
|
||
| describe("property: / prefix always returns empty", () => { | ||
| test("returns empty array regardless of actions", () => { | ||
| const actions = [ | ||
| { id: CommandIds.workspaceSwitch("1") }, | ||
| { id: CommandIds.workspaceNew() }, | ||
| { id: CommandIds.navToggleSidebar() }, | ||
| ]; | ||
|
|
||
| expect(filterCommandsByPrefix("/", actions)).toHaveLength(0); | ||
| expect(filterCommandsByPrefix("/help", actions)).toHaveLength(0); | ||
| expect(filterCommandsByPrefix("/ ", actions)).toHaveLength(0); | ||
| }); | ||
| }); | ||
|
|
||
| describe("property: query with > prefix applies to all non-switching", () => { | ||
| test(">text shows same set as > (cmdk filters further)", () => { | ||
| const actions = [ | ||
| { id: CommandIds.workspaceSwitch("1") }, | ||
| { id: CommandIds.workspaceNew() }, | ||
| { id: CommandIds.navToggleSidebar() }, | ||
| ]; | ||
|
|
||
| // Our filter doesn't care about text after >, just the prefix | ||
| const resultEmpty = filterCommandsByPrefix(">", actions); | ||
| const resultWithText = filterCommandsByPrefix(">abc", actions); | ||
|
|
||
| expect(resultEmpty).toEqual(resultWithText); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.