diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-27 06:30:16 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-27 06:30:16 +0200 |
| commit | 7a38213ce33d11690c32645456fd3814f33731da (patch) | |
| tree | f796e0e1e156da179e0f1dc2000a9785fa12b206 /internal | |
| parent | 2edeaa610553b667776010bf2e9f5596aaa8ddbd (diff) | |
Add alias coverage for task b777fcc2-8f64-4250-b0ac-6038a8aa26b4
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/askcli/task_alias_cache_test.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/internal/askcli/task_alias_cache_test.go b/internal/askcli/task_alias_cache_test.go index c9fffd6..f792585 100644 --- a/internal/askcli/task_alias_cache_test.go +++ b/internal/askcli/task_alias_cache_test.go @@ -179,6 +179,53 @@ func TestEnsureTaskAliases_PrunesExpiredEntriesWithoutReusingIDs(t *testing.T) { } } +func TestEnsureTaskAliases_DoesNotPruneEntriesAt120DayBoundary(t *testing.T) { + dir := t.TempDir() + + oldNow := nowTaskAliasCache + oldRoot := taskAliasCacheRoot + nowTaskAliasCache = func() time.Time { return time.Date(2026, 3, 26, 12, 0, 0, 0, time.UTC) } + taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil } + defer func() { + nowTaskAliasCache = oldNow + taskAliasCacheRoot = oldRoot + }() + + path, err := taskAliasCachePath() + if err != nil { + t.Fatalf("taskAliasCachePath: %v", err) + } + + boundary := nowTaskAliasCache().Add(-taskAliasCacheTTL) + cache := taskAliasCache{ + NextID: 37, + Entries: []taskAliasCacheEntry{ + { + UUID: "boundary", + Alias: "z", + CreatedAt: boundary, + LastAccessedAt: boundary, + }, + }, + } + if err := cache.save(path); err != nil { + t.Fatalf("save seed cache: %v", err) + } + + aliases, err := ensureTaskAliases([]TaskExport{{UUID: "boundary"}}) + if err != nil { + t.Fatalf("ensureTaskAliases returned error: %v", err) + } + if aliases["boundary"] != "z" { + t.Fatalf("boundary alias = %q, want z", aliases["boundary"]) + } + + cache = readTaskAliasCacheForTest(t, path) + if !hasTaskAliasEntry(cache, "boundary") { + t.Fatal("boundary entry should not have been pruned") + } +} + func TestEnsureTaskAliases_InvalidCacheReturnsError(t *testing.T) { dir := t.TempDir() |
