fix(daemon): exclude hidden commands from palette codes
- commit
- 9e796e191705c6c8ffe4f56430e27ed81e709293
- author
- brice · · 2026-07-23 21:43 UTC
- parent
- 4165239
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +32 -2
M internal/usecase/daemon/config.go +2 -2
| @@ -113,7 +113,7 @@ func configWarningsError(warnings []domain.Warning) error { | |||
| 113 | 113 | } | |
| 114 | 114 | ||
| 115 | 115 | func (d *Daemon) buildCodeOverrides(configured map[string]string) (map[string]string, []domain.Warning) { | |
| 116 | - | commands := command.Registry() | |
| 116 | + | commands := command.PaletteRegistry() | |
| 117 | 117 | bySlug := make(map[string]command.Command, len(commands)) | |
| 118 | 118 | for _, cmd := range commands { | |
| 119 | 119 | bySlug[cmd.Slug] = cmd | |
| @@ -294,7 +294,7 @@ func commandWithOverrides(cmd command.Command, overrides map[string]string) comm | |||
| 294 | 294 | func (d *Daemon) commandByEffectiveCode(code string) (command.Command, bool) { | |
| 295 | 295 | code = strings.ToUpper(strings.TrimSpace(code)) | |
| 296 | 296 | overrides := d.codeOverrideSnapshot() | |
| 297 | - | for _, cmd := range command.Registry() { | |
| 297 | + | for _, cmd := range command.PaletteRegistry() { | |
| 298 | 298 | cmd = commandWithOverrides(cmd, overrides) | |
| 299 | 299 | if cmd.Code == code { | |
| 300 | 300 | return cmd, true | |
| @@ -113,7 +113,7 @@ func configWarningsError(warnings []domain.Warning) error { | |||||
| 113 | } | 113 | } | ||
| 114 | 114 | ||||
| 115 | func (d *Daemon) buildCodeOverrides(configured map[string]string) (map[string]string, []domain.Warning) { | 115 | func (d *Daemon) buildCodeOverrides(configured map[string]string) (map[string]string, []domain.Warning) { | ||
| 116 | - | commands := command.Registry() | 116 | + | commands := command.PaletteRegistry() |
| 117 | bySlug := make(map[string]command.Command, len(commands)) | 117 | bySlug := make(map[string]command.Command, len(commands)) | ||
| 118 | for _, cmd := range commands { | 118 | for _, cmd := range commands { | ||
| 119 | bySlug[cmd.Slug] = cmd | 119 | bySlug[cmd.Slug] = cmd | ||
| @@ -294,7 +294,7 @@ func commandWithOverrides(cmd command.Command, overrides map[string]string) comm | |||||
| 294 | func (d *Daemon) commandByEffectiveCode(code string) (command.Command, bool) { | 294 | func (d *Daemon) commandByEffectiveCode(code string) (command.Command, bool) { | ||
| 295 | code = strings.ToUpper(strings.TrimSpace(code)) | 295 | code = strings.ToUpper(strings.TrimSpace(code)) | ||
| 296 | overrides := d.codeOverrideSnapshot() | 296 | overrides := d.codeOverrideSnapshot() | ||
| 297 | - | for _, cmd := range command.Registry() { | 297 | + | for _, cmd := range command.PaletteRegistry() { |
| 298 | cmd = commandWithOverrides(cmd, overrides) | 298 | cmd = commandWithOverrides(cmd, overrides) | ||
| 299 | if cmd.Code == code { | 299 | if cmd.Code == code { | ||
| 300 | return cmd, true | 300 | return cmd, true | ||
M internal/usecase/daemon/palette_test.go +30 -0
| @@ -574,6 +574,36 @@ func TestPaletteReopensWithSuccessfulCommandFirst(t *testing.T) { | |||
| 574 | 574 | require.Equal(t, "NXT", cmd.Code) | |
| 575 | 575 | } | |
| 576 | 576 | ||
| 577 | + | func TestPaletteCodeOverridesRejectAPIOnlyCommands(t *testing.T) { | |
| 578 | + | d := newTestDaemon(t, nil, stubClock{}) | |
| 579 | + | ||
| 580 | + | overrides, warnings := d.buildCodeOverrides(map[string]string{ | |
| 581 | + | "new-tab": "TAB", | |
| 582 | + | "toast": "API", | |
| 583 | + | }) | |
| 584 | + | ||
| 585 | + | require.Equal(t, map[string]string{"new-tab": "TAB"}, overrides) | |
| 586 | + | require.Len(t, warnings, 1) | |
| 587 | + | require.Contains(t, warnings[0].Msg, `unknown command code slug "toast"`) | |
| 588 | + | } | |
| 589 | + | ||
| 590 | + | func TestCommandByEffectiveCodeExcludesAPIOnlyCommands(t *testing.T) { | |
| 591 | + | d := newTestDaemon(t, nil, stubClock{}) | |
| 592 | + | overrides := map[string]string{ | |
| 593 | + | "new-tab": "TAB", | |
| 594 | + | "toast": "API", | |
| 595 | + | } | |
| 596 | + | d.codeOverrides.Store(&overrides) | |
| 597 | + | ||
| 598 | + | cmd, ok := d.commandByEffectiveCode("tab") | |
| 599 | + | require.True(t, ok) | |
| 600 | + | require.Equal(t, "new-tab", cmd.Slug) | |
| 601 | + | require.Equal(t, "TAB", cmd.Code) | |
| 602 | + | ||
| 603 | + | _, ok = d.commandByEffectiveCode("API") | |
| 604 | + | require.False(t, ok) | |
| 605 | + | } | |
| 606 | + | ||
| 577 | 607 | func TestPaletteRecentCommandsNewestFirstThenRegistryOrder(t *testing.T) { | |
| 578 | 608 | d := &Daemon{} | |
| 579 | 609 | d.recordPaletteUse("SSP") | |
| @@ -574,6 +574,36 @@ func TestPaletteReopensWithSuccessfulCommandFirst(t *testing.T) { | |||||
| 574 | require.Equal(t, "NXT", cmd.Code) | 574 | require.Equal(t, "NXT", cmd.Code) | ||
| 575 | } | 575 | } | ||
| 576 | 576 | ||||
| 577 | + | func TestPaletteCodeOverridesRejectAPIOnlyCommands(t *testing.T) { | |||
| 578 | + | d := newTestDaemon(t, nil, stubClock{}) | |||
| 579 | + | ||||
| 580 | + | overrides, warnings := d.buildCodeOverrides(map[string]string{ | |||
| 581 | + | "new-tab": "TAB", | |||
| 582 | + | "toast": "API", | |||
| 583 | + | }) | |||
| 584 | + | ||||
| 585 | + | require.Equal(t, map[string]string{"new-tab": "TAB"}, overrides) | |||
| 586 | + | require.Len(t, warnings, 1) | |||
| 587 | + | require.Contains(t, warnings[0].Msg, `unknown command code slug "toast"`) | |||
| 588 | + | } | |||
| 589 | + | ||||
| 590 | + | func TestCommandByEffectiveCodeExcludesAPIOnlyCommands(t *testing.T) { | |||
| 591 | + | d := newTestDaemon(t, nil, stubClock{}) | |||
| 592 | + | overrides := map[string]string{ | |||
| 593 | + | "new-tab": "TAB", | |||
| 594 | + | "toast": "API", | |||
| 595 | + | } | |||
| 596 | + | d.codeOverrides.Store(&overrides) | |||
| 597 | + | ||||
| 598 | + | cmd, ok := d.commandByEffectiveCode("tab") | |||
| 599 | + | require.True(t, ok) | |||
| 600 | + | require.Equal(t, "new-tab", cmd.Slug) | |||
| 601 | + | require.Equal(t, "TAB", cmd.Code) | |||
| 602 | + | ||||
| 603 | + | _, ok = d.commandByEffectiveCode("API") | |||
| 604 | + | require.False(t, ok) | |||
| 605 | + | } | |||
| 606 | + | ||||
| 577 | func TestPaletteRecentCommandsNewestFirstThenRegistryOrder(t *testing.T) { | 607 | func TestPaletteRecentCommandsNewestFirstThenRegistryOrder(t *testing.T) { | ||
| 578 | d := &Daemon{} | 608 | d := &Daemon{} | ||
| 579 | d.recordPaletteUse("SSP") | 609 | d.recordPaletteUse("SSP") | ||