-
-
Notifications
You must be signed in to change notification settings - Fork 288
fix(plugins): keep updated plugin marked Installed instead of reoffering Update #1626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // | ||
| // PluginBundleVersionTests.swift | ||
| // TableProTests | ||
| // | ||
|
|
||
| import Foundation | ||
| @testable import TablePro | ||
| import Testing | ||
|
|
||
| @Suite("Plugin bundle version reading", .serialized) | ||
| struct PluginBundleVersionTests { | ||
| private func makeTempDir() throws -> URL { | ||
| let dir = FileManager.default.temporaryDirectory | ||
| .appendingPathComponent("PluginBundleVersionTests-\(UUID().uuidString)", isDirectory: true) | ||
| try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true) | ||
| return dir | ||
| } | ||
|
|
||
| private func writeBundle(at directory: URL, name: String, version: String) throws -> URL { | ||
| let bundle = directory.appendingPathComponent("\(name).tableplugin", isDirectory: true) | ||
| let contents = bundle.appendingPathComponent("Contents", isDirectory: true) | ||
| try FileManager.default.createDirectory(at: contents, withIntermediateDirectories: true) | ||
| let payload = """ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>CFBundleIdentifier</key><string>com.example.\(name)</string> | ||
| <key>CFBundleShortVersionString</key><string>\(version)</string> | ||
| </dict> | ||
| </plist> | ||
| """ | ||
| try payload.write(to: contents.appendingPathComponent("Info.plist"), atomically: true, encoding: .utf8) | ||
| return bundle | ||
| } | ||
|
|
||
| @Test("bundleShortVersion reads CFBundleShortVersionString from disk") | ||
| func readsVersionFromDisk() throws { | ||
| let dir = try makeTempDir() | ||
| defer { try? FileManager.default.removeItem(at: dir) } | ||
|
|
||
| let bundle = try writeBundle(at: dir, name: "Driver", version: "1.2.3") | ||
| #expect(PluginManager.bundleShortVersion(at: bundle) == "1.2.3") | ||
| } | ||
|
|
||
| @Test("bundleShortVersion returns nil when the key is missing") | ||
| func returnsNilWhenMissing() throws { | ||
| let dir = try makeTempDir() | ||
| defer { try? FileManager.default.removeItem(at: dir) } | ||
|
|
||
| let bundle = dir.appendingPathComponent("Driver.tableplugin", isDirectory: true) | ||
| let contents = bundle.appendingPathComponent("Contents", isDirectory: true) | ||
| try FileManager.default.createDirectory(at: contents, withIntermediateDirectories: true) | ||
| let payload = """ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict><key>CFBundleIdentifier</key><string>com.example.Driver</string></dict> | ||
| </plist> | ||
| """ | ||
| try payload.write(to: contents.appendingPathComponent("Info.plist"), atomically: true, encoding: .utf8) | ||
|
|
||
| #expect(PluginManager.bundleShortVersion(at: bundle) == nil) | ||
| } | ||
|
|
||
| @Test("bundleShortVersion sees the new version after the bundle is replaced in place") | ||
| func seesNewVersionAfterInPlaceReplace() throws { | ||
| let dir = try makeTempDir() | ||
| defer { try? FileManager.default.removeItem(at: dir) } | ||
|
|
||
| let bundle = try writeBundle(at: dir, name: "Driver", version: "1.0.0") | ||
|
|
||
| let cached = Bundle(url: bundle) | ||
| #expect(cached?.infoDictionary?["CFBundleShortVersionString"] as? String == "1.0.0") | ||
|
|
||
| _ = try writeBundle(at: dir, name: "Driver", version: "2.0.0") | ||
|
|
||
| #expect(PluginManager.bundleShortVersion(at: bundle) == "2.0.0") | ||
| #expect(Bundle(url: bundle)?.infoDictionary?["CFBundleShortVersionString"] as? String == "1.0.0") | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When updating a plugin that has already been discovered or loaded at this same URL,
loadPluginAsyncstill obtains and loads theBundlebeforereplaceExistingPluginunloads the existing entry, so thebundlepassed here can be the cached CFBundle object from the previous install. Reading onlyCFBundleShortVersionStringfrom the replaced Info.plist then creates aPluginEntrythat advertises the registry version while its principal class/capabilities can still come from the cached old bundle, causingregistryUpdate(for:)to stop offering the update even though the running plugin code was not refreshed. Please avoid mixing the disk version with a cachedBundle(or unload/avoid the cached bundle before loading the replacement).Useful? React with 👍 / 👎.