Skip to content

fix(cli): fallback to latest undone session in undo show when all sessions are undone - #9

Open
Reyatsu99 wants to merge 1 commit into
edaywalid:mainfrom
Reyatsu99:fix/show-undone-fallback
Open

fix(cli): fallback to latest undone session in undo show when all sessions are undone#9
Reyatsu99 wants to merge 1 commit into
edaywalid:mainfrom
Reyatsu99:fix/show-undone-fallback

Conversation

@Reyatsu99

Copy link
Copy Markdown

Summary

When undo show is called without arguments and all recorded sessions have been undone, session.Latest() returns os.ErrNotExist. Previously, cmdShow would output an opaque error (undo: no such session), even though sessions clearly exist in undo list.

This PR updates cmdShow to fall back to the most recent undone session with entries when no active sessions remain, outputting a contextual notice to stderr:
(all sessions have been undone; showing the most recent)

Changes

  • Refactored session lookup logic in cmd/undo/main.go into getShowSession(args []string) to enable clean unit testing without calling fatal() / os.Exit().
  • Implemented fallback to the newest undone candidate when session.Latest() returns os.ErrNotExist and no explicit session ID was passed.
  • Added comprehensive unit tests in cmd/undo/show_test.go covering empty stores, 0-entry sessions, explicit ID lookups, mixed session states, and full output formatting.

Verification

  • make test: All Go unit tests and 25 E2E integration test cases pass cleanly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant