diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-07 09:15:08 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-07 09:15:08 +0300 |
| commit | 695b0b5c3572494c98c45fdacd74d777ab37d36e (patch) | |
| tree | aa8fafc57998d30d2d03e87aca216ac00896508d /internal/askcli/command_complete_uuids_test.go | |
| parent | 4185a422395bfe9d40c6f934fd56663d223bf782 (diff) | |
fix: recover gracefully from corrupted alias cache instead of hard-failingv0.29.1
When the task alias cache file contains invalid JSON (e.g. from a
concurrent write race producing two concatenated JSON objects), the
previous code returned a hard error that blocked all `ask` subcommands.
Now loadTaskAliasCache discards the corrupt file and starts fresh,
assigning new alias IDs on the next run. Validation errors (e.g.
next_id reuse) still surface as errors since those indicate a logic bug.
Also fix stale v1 reference in integration test aliasCachePath.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/askcli/command_complete_uuids_test.go')
| -rw-r--r-- | internal/askcli/command_complete_uuids_test.go | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/internal/askcli/command_complete_uuids_test.go b/internal/askcli/command_complete_uuids_test.go index 442e0a8..92bf244 100644 --- a/internal/askcli/command_complete_uuids_test.go +++ b/internal/askcli/command_complete_uuids_test.go @@ -80,7 +80,7 @@ func TestHandleCompleteUUIDs_ParseError(t *testing.T) { } } -func TestHandleCompleteUUIDs_WarnsOnInvalidAliasCache(t *testing.T) { +func TestHandleCompleteUUIDs_RecoverFromCorruptAliasCache(t *testing.T) { dir := t.TempDir() oldRoot := taskAliasCacheRoot taskAliasCacheRoot = func() (string, error) { return filepath.Join(dir, "hexai"), nil } @@ -93,6 +93,9 @@ func TestHandleCompleteUUIDs_WarnsOnInvalidAliasCache(t *testing.T) { if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { t.Fatalf("MkdirAll: %v", err) } + // Simulate a corrupted cache file (e.g. two JSON objects concatenated from a + // concurrent write race). The handler must recover by resetting the cache and + // assigning fresh aliases rather than erroring or degrading to UUID-only output. if err := os.WriteFile(path, []byte("{bad"), 0o600); err != nil { t.Fatalf("WriteFile: %v", err) } @@ -110,12 +113,18 @@ func TestHandleCompleteUUIDs_WarnsOnInvalidAliasCache(t *testing.T) { if code != 0 { t.Fatalf("handleCompleteUUIDs code = %d, want 0", code) } - // When alias cache is unavailable, output UUID with description (tab-separated). - if got := stdout.String(); got != "uuid-1\tFallback task\n" { - t.Fatalf("stdout = %q, want UUID-only fallback list with description", got) + // After recovery a fresh alias (e.g. "0") must be assigned, so the output + // includes both the short alias and the UUID (fish shows whichever the user + // types). No warning should appear on stderr. + got := stdout.String() + if !strings.Contains(got, "uuid-1\tFallback task") { + t.Fatalf("stdout = %q, want UUID with description", got) } - if !strings.Contains(stderr.String(), "failed to update task alias cache") { - t.Fatalf("stderr = %q, want cache warning", stderr.String()) + if !strings.Contains(got, "Fallback task") { + t.Fatalf("stdout = %q, want task description in output", got) + } + if stderr.Len() != 0 { + t.Fatalf("stderr = %q, want no warnings after graceful recovery", stderr.String()) } } |
