Skip to content

feat(app_center): revert a snap to previous local revision#1972

Merged
ashuntu merged 2 commits intoubuntu:mainfrom
gajeshbhat:feature/snap-revert-1164
Feb 12, 2026
Merged

feat(app_center): revert a snap to previous local revision#1972
ashuntu merged 2 commits intoubuntu:mainfrom
gajeshbhat:feature/snap-revert-1164

Conversation

@gajeshbhat
Copy link
Copy Markdown
Contributor

@gajeshbhat gajeshbhat commented Aug 16, 2025

Summary

Adds "Revert update" functionality to allow users to revert snaps to their previous local version.

What's changed

  1. Added "Revert update" action in snap dropdown menu (only shown when previous revision exists)
  2. Confirmation dialog shows version/revision details when available
  3. UI displays actual installed version (not channel version) after revert
  4. Uses revertSnap() from snapd.dart 0.7.4 (feat: add SnapLocalRevision class and snap revert functionality canonical/snapd.dart#132)
  5. Added getLocalRevisions() and hasPreviousRevision() to SnapdService
  6. Comprehensive unit and widget tests

Screenshots

Snap Revert Workflow example

image image image

Cannot double revert and hide the revert entry altogether for snaps that cannot be reverted.

image

Cannot Revert a Snap without two versions or a Snap that has not been updated.

image

How to test

# Initial setup
melos bootstrap && melos generate

# Run Lint checks
melos run format:exclude

# Run static analysis
melos run analyze

# Run tests
melos tests

# Build the App Center Locally to test the feature manually
cd packages/app_center
fvm flutter run -d linux

Checklist

Related PR's

snapd.dart PR revert wrapper in 0.7.4: canonical/snapd.dart#132

@gajeshbhat gajeshbhat changed the title feat(app_center): revert a snap to previous local revision with confirmation and action gating feat(app_center): revert a snap to previous local revision Aug 16, 2025
@gajeshbhat
Copy link
Copy Markdown
Contributor Author

Hey folks, can someone kindly review this pull request? @matthew-hagemann @d-loose @Feichtmeier Please let me know if you have any questions. Cheers.

@Feichtmeier Feichtmeier requested a review from d-loose August 30, 2025 07:30
@gajeshbhat gajeshbhat force-pushed the feature/snap-revert-1164 branch 2 times, most recently from ec56ff1 to 23adfb1 Compare September 19, 2025 01:42
@gajeshbhat
Copy link
Copy Markdown
Contributor Author

Rebased PR and squashed commits fixing melos errors.

@Feichtmeier Feichtmeier requested a review from ashuntu September 19, 2025 07:11
Copy link
Copy Markdown
Collaborator

@ashuntu ashuntu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR. I've added some comments for things I noticed at first glance which will need to be addressed before going forward.

Comment thread packages/app_center/lib/snapd/snapd_service.dart Outdated
Comment thread packages/app_center/lib/snapd/snap_model.dart Outdated
Comment thread packages/app_center/lib/snapd/snap_model.dart Outdated
Comment thread packages/app_center/lib/snapd/snap_model.dart Outdated
@gajeshbhat
Copy link
Copy Markdown
Contributor Author

Thanks for this PR. I've added some comments for things I noticed at first glance, which will need to be addressed before going forward.

Thank you for taking a look at my submission @ashuntu . I have addressed your comments and put up another PR in snapd.dart and made the requested changes to this repo. Please let me know if you have any questions. Cheers.

@gajeshbhat gajeshbhat requested a review from ashuntu September 28, 2025 22:18
@gajeshbhat
Copy link
Copy Markdown
Contributor Author

I see there are some CI formatting checks. I will fix those errors and repush.

@gajeshbhat
Copy link
Copy Markdown
Contributor Author

@ashuntu Do you think the Integration error might have been created by some changes I did? https://github.com/ubuntu/app-center/actions/runs/18080314471/job/51504261035?pr=1972#step:4:488 I didn't modify any other dependencies except the pubspec.yml for testing the changes introduced on canonical/snapd.dart#132

@ashuntu
Copy link
Copy Markdown
Collaborator

ashuntu commented Sep 29, 2025

@ashuntu Do you think the Integration error might have been created by some changes I did? https://github.com/ubuntu/app-center/actions/runs/18080314471/job/51504261035?pr=1972#step:4:488 I didn't modify any other dependencies except the pubspec.yml for testing the changes introduced on canonical/snapd.dart#132

It's likely because you didn't also commit changes to pubspec.lock, since the version of snapd.dart will change in there.

@gajeshbhat
Copy link
Copy Markdown
Contributor Author

@ashuntu Do you think the Integration error might have been created by some changes I did? https://github.com/ubuntu/app-center/actions/runs/18080314471/job/51504261035?pr=1972#step:4:488 I didn't modify any other dependencies except the pubspec.yml for testing the changes introduced on canonical/snapd.dart#132

It's likely because you didn't also commit changes to pubspec.lock, since the version of snapd.dart will change in there.

Thank you. I will commit and push that.

@gajeshbhat
Copy link
Copy Markdown
Contributor Author

Looks like I have some formatting errors. Let me apply a fix and push the commit.

@gajeshbhat
Copy link
Copy Markdown
Contributor Author

@ashuntu I have fixed the formatting issues and pushed the changes. Can you kindly approve the workflow so that I can test the changes in the CI ? And Can you let me know if there are more changes required for this PR or the companion PR canonical/snapd.dart#132 that adds this functionality.

@gajeshbhat
Copy link
Copy Markdown
Contributor Author

Looks like a trailing comma is missing. https://github.com/ubuntu/app-center/actions/runs/19723085068/job/56841667566?pr=1972#step:6:72 I will update and repush.

@gajeshbhat
Copy link
Copy Markdown
Contributor Author

Looks like a trailing comma is missing. https://github.com/ubuntu/app-center/actions/runs/19723085068/job/56841667566?pr=1972#step:6:72 I will update and repush.

Done .

@gajeshbhat gajeshbhat force-pushed the feature/snap-revert-1164 branch from 13c1197 to fcdc96f Compare January 30, 2026 02:57
d-loose added a commit to canonical/snapd.dart that referenced this pull request Jan 30, 2026
## Summary

This PR adds support for retrieving local snap revisions and reverting
snaps to previous versions, addressing the need for snap revert
functionality in App Center. You can find that in the Pull Request on
App Center : ubuntu/app-center#1972

## Issue/Card
Fixes #1164 on ubuntu/app-center#1164

## Changes

### New Classes
- **`SnapLocalRevision`**: Represents a local revision of an installed
snap with `revision`, `version`, and `active` fields
- Handles revision typing robustly (int/num/string) using
`_parseRevision` method
  - Supports parsing negative revisions (e.g., "x123" → -123)
  - Includes proper JSON serialization via freezed

### New Methods
- **`SnapdClient.getLocalRevisions(name)`**: Retrieves all locally
installed revisions for a snap
  - Uses `GET /v2/snaps?select=all&snaps={name}` endpoint
  - Returns `List<SnapLocalRevision>` with revision details
  - Handles errors gracefully by returning empty list
  
- **`SnapdClient.revertSnap(name)`**: Reverts a snap to its previous
revision
  - Uses `POST /v2/snaps/{name}` with `{"action":"revert"}` payload
  - Returns change ID for monitoring operation status
  - Throws `SnapdException` on error responses

### Testing
- Extended `MockSnapdServer` to support new endpoints and actions
- Added comprehensive unit tests covering:
  - Basic functionality for both methods
  - Revision type handling (int/num/string)
  - Error cases and edge conditions
  - Proper request/response formatting

### Documentation
- Added detailed dartdoc comments with usage examples
- Documented parameters, return values, and exceptions

## Usage Example

```dart
// Get local revisions
final revisions = await client.getLocalRevisions('firefox');
for (final revision in revisions) {
  print('Revision ${revision.revision}: ${revision.version} ${revision.active ? '(active)' : ''}');
}

// Revert snap
try {
  final changeId = await client.revertSnap('firefox');
  final change = await client.getChange(changeId);
  print('Revert status: ${change.status}');
} catch (e) {
  print('Revert failed: $e');
}
```
## Testing
All existing tests continue to pass, and new tests for the feature
added.

## Files Changed

1.  `lib/src/snapd_client.dart` - Core implementation
2.  `lib/src/snapd_client.freezed.dart` - Generated freezed code
3.  `lib/src/snapd_client.g.dart` - Generated JSON serialization
4.  `test/snapd_test.dart` - mock server updates
@gajeshbhat
Copy link
Copy Markdown
Contributor Author

@d-loose I have fixed the lint errors and tested this locally and it works. The version wasn't properly being displayed on the App Center UI, commited and pushed fix for that as well. I am using main from snapd.dart on packages/app_center/pubspec.yaml and packages/app_center/pubspec.lock in this PR, when can we expect the latest update of snapd be published so that we can bump the snapd version and get this PR working ? I checked https://pub.dev/packages/snapd/versions and there are no new versions from the merge yesterday. I am happy ot make changes and get this more polished before snapd is published. Let me know if you feel this PR needs more changes. Cheers.

@ashuntu
Copy link
Copy Markdown
Collaborator

ashuntu commented Jan 31, 2026

We can get a version of snapd.dart published sometime next week most likely.

@gajeshbhat
Copy link
Copy Markdown
Contributor Author

We can get a version of snapd.dart published sometime next week most likely.

Thank you for the update @ashuntu !

@ashuntu
Copy link
Copy Markdown
Collaborator

ashuntu commented Feb 3, 2026

snapd.dart 0.7.4 was just released canonical/snapd.dart#138

@gajeshbhat
Copy link
Copy Markdown
Contributor Author

snapd.dart 0.7.4 was just released canonical/snapd.dart#138

Thank you for the update @ashuntu . I will update, test and repush in a couple of hours.

@gajeshbhat gajeshbhat force-pushed the feature/snap-revert-1164 branch from 788bfb1 to 1e55a9f Compare February 3, 2026 19:23
@gajeshbhat
Copy link
Copy Markdown
Contributor Author

@ashuntu I have updated the newly published snapd.dart in pubspec.yaml (https://pub.dev/packages/snapd/versions/0.7.4) and generated a new pubspec.lock, tested the revert functionality locally, squashed all the commits and resigned them and pushed them. Can you approve the workflow ?

@gajeshbhat
Copy link
Copy Markdown
Contributor Author

All CI checks pass!

Copy link
Copy Markdown
Collaborator

@ashuntu ashuntu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good now, just some minor comments on tests and localization.

Comment thread packages/app_center/test/snap_model_test.dart
Comment thread packages/app_center/test/snap_action_test.dart
Comment thread packages/app_center/lib/src/l10n/app_en.arb Outdated
- Add revert button to snap page for snaps with previous local revisions
- Implement getLocalRevisions() and hasPreviousRevision() in SnapdService
- Add revert confirmation dialog with version details
- Show local snap version instead of channel version in UI
- Add localization strings for revert feature
- Use snapd.dart 0.7.4 with revertSnap() support

Fixes ubuntu#1164

Signed-off-by: Gajesh Bhat <gajeshbht@gmail.com>
@gajeshbhat gajeshbhat force-pushed the feature/snap-revert-1164 branch from b020fbf to 0c45983 Compare February 3, 2026 21:29
@juanruitina
Copy link
Copy Markdown
Contributor

juanruitina commented Feb 4, 2026

Thank you @gajeshbhat for your contribution. Some feedback:

  • I wouldn't make the option red, I wouldn't consider this to be as destructive as "Uninstall" (and there is a confirmation modal)
  • "Revert update" would likely work better as a label. It would be more explicit about what this is about (vs revert some other kind of change). We can't expect users to be familiar with the command.

@juanruitina
Copy link
Copy Markdown
Contributor

juanruitina commented Feb 4, 2026

@ashuntu @d-loose Could it be problematic to show revert so prominently for some specific snap, perhaps for snapd? Could something go wrong?

Signed-off-by: Gajesh Bhat <gajeshbht@gmail.com>
@gajeshbhat
Copy link
Copy Markdown
Contributor Author

Updated PR description as it was severly out of date.

@ashuntu
Copy link
Copy Markdown
Collaborator

ashuntu commented Feb 5, 2026

It seems that reverting "essential" snaps like snapd is intended to be possible: https://snapcraft.io/docs/managing-updates#p-32248-revert-to-an-earlier-revision.

I would assume it just carries the same risk that reverting any other snap has, just that the conditions for reverting are a little more strict.

I'm not sure if there are issues with the App Center itself being a snap and reverting one it depends on while it is running, though. I think the revert would just fail with an error like it does if a snap is still open.

@gajeshbhat
Copy link
Copy Markdown
Contributor Author

gajeshbhat commented Feb 5, 2026

It seems that reverting "essential" snaps like snapd is intended to be possible: https://snapcraft.io/docs/managing-updates#p-32248-revert-to-an-earlier-revision.

I would assume it just carries the same risk that reverting any other snap has, just that the conditions for reverting are a little more strict.

I'm not sure if there are issues with the App Center itself being a snap and reverting one it depends on while it is running, though. I think the revert would just fail with an error like it does if a snap is still open.

I think there are enough safeguards in snapd to prevent reverts that can cause issue. But if that's something that has to be looked at closely for the app center, it would be out of scope for this PR. We might want to create a seperate issue ticket for that.

Copy link
Copy Markdown
Collaborator

@ashuntu ashuntu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks pretty good.

I'd like more in-depth error reporting on failures in the future if possible, but that can be a future change.

@gajeshbhat
Copy link
Copy Markdown
Contributor Author

I think this looks pretty good.

I'd like more in-depth error reporting on failures in the future if possible, but that can be a future change.

Thank you @ashuntu . I will create an issue to add it to the backlog.

@gajeshbhat
Copy link
Copy Markdown
Contributor Author

#2017

@ashuntu ashuntu merged commit b23c014 into ubuntu:main Feb 12, 2026
11 checks passed
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.

Add option for the user to revert a snap

3 participants