diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-07 09:01:46 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-07 09:01:46 +0300 |
| commit | 627485ecf12991c08340c69c999a117dfb24eebb (patch) | |
| tree | 36c374ac0781261f9417f581b81668a43a97bed5 /internal/askcli/task_alias_cache_test.go | |
| parent | 51d278935b8c0b07faf075d1d4e45bb2a48249a2 (diff) | |
feat: reverse alias IDs for better shell tab-completion
Alias IDs are now stored in reversed form (e.g. id=37 → "10" instead
of "01") so that the first character varies quickly across consecutive
IDs, making shell auto-completion more effective. The counter logic is
unchanged; only the string representation is reversed via a new
reverseString helper in encodeTaskAliasID/decodeTaskAliasID.
The cache file is bumped to task-aliases-v2.json so existing mappings
are abandoned and all aliases are regenerated with the new format.
Also fix TestDispatcher_CompleteUUIDsSubcommand to use an isolated temp
dir for the alias cache, preventing flakiness from cross-test pollution.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/askcli/task_alias_cache_test.go')
| -rw-r--r-- | internal/askcli/task_alias_cache_test.go | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/internal/askcli/task_alias_cache_test.go b/internal/askcli/task_alias_cache_test.go index f792585..92d528b 100644 --- a/internal/askcli/task_alias_cache_test.go +++ b/internal/askcli/task_alias_cache_test.go @@ -11,6 +11,8 @@ import ( func TestEncodeTaskAliasID(t *testing.T) { t.Parallel() + // Aliases are stored in reversed form so that the first character varies + // quickly across consecutive IDs, improving shell tab-completion. tests := []struct { id uint64 want string @@ -20,12 +22,12 @@ func TestEncodeTaskAliasID(t *testing.T) { {id: 10, want: "a"}, {id: 35, want: "z"}, {id: 36, want: "00"}, - {id: 37, want: "01"}, - {id: 71, want: "0z"}, - {id: 72, want: "10"}, + {id: 37, want: "10"}, + {id: 71, want: "z0"}, + {id: 72, want: "01"}, {id: 1331, want: "zz"}, {id: 1332, want: "000"}, - {id: 1333, want: "001"}, + {id: 1333, want: "100"}, } for _, tc := range tests { @@ -38,6 +40,8 @@ func TestEncodeTaskAliasID(t *testing.T) { func TestDecodeTaskAliasID(t *testing.T) { t.Parallel() + // Aliases are in reversed form (matching encodeTaskAliasID output), so + // decodeTaskAliasID must reverse them back before decoding. tests := []struct { alias string want uint64 @@ -46,7 +50,7 @@ func TestDecodeTaskAliasID(t *testing.T) { {alias: "0", want: 0, ok: true}, {alias: "z", want: 35, ok: true}, {alias: "00", want: 36, ok: true}, - {alias: "01", want: 37, ok: true}, + {alias: "10", want: 37, ok: true}, {alias: "zz", want: 1331, ok: true}, {alias: "000", want: 1332, ok: true}, {alias: "", ok: false}, @@ -163,8 +167,8 @@ func TestEnsureTaskAliases_PrunesExpiredEntriesWithoutReusingIDs(t *testing.T) { if aliases["fresh"] != "00" { t.Fatalf("fresh alias = %q, want 00", aliases["fresh"]) } - if aliases["new-task"] != "01" { - t.Fatalf("new-task alias = %q, want 01", aliases["new-task"]) + if aliases["new-task"] != "10" { + t.Fatalf("new-task alias = %q, want 10", aliases["new-task"]) } cache = readTaskAliasCacheForTest(t, path) |
