Skip to content

fix(plugins): native version-based discovery, restart UX, registry hardening - #1208

Merged
datlechin merged 3 commits into
mainfrom
fix/plugin-system-audit
May 11, 2026
Merged

datlechin merged 3 commits into
mainfrom
fix/plugin-system-audit

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

End-to-end audit and rewrite of the plugin system. Closes #1192 and addresses 14 other issues found in the audit (P0–P3).

Plugin discovery (#1192)

Rewrote discovery to follow the native NSBundle pattern: scan both Contents/PlugIns (built-in) and ~/Library/Application Support/TablePro/Plugins (user-installed), group by bundle ID, pick the newest version by CFBundleShortVersionString. The "skip user-installed if built-in exists" branches in registerBundle and registerLazyManifest are gone — discovery dedupes by construction. pruneOutdatedUserCopies only deletes user copies that are older than or equal to the built-in version, so upgraded built-in plugins survive restart.

Plugin version is now read from Info.plist (CFBundleShortVersionString) instead of the hardcoded principalClass.pluginVersion static. The .metadata.json sidecar no longer stores version — only the registry plugin ID for update lookups.

Concurrency hardening

  • installFromRegistry and updateFromRegistry set isInstalling at their own entry points. The internal performInstall helper bypasses the guard so registry methods do not double-set.
  • waitForInitialLoad wraps the 10-second timeout in withTaskCancellationHandler and a UUID-keyed waiter, so the continuation is always resumed and removed from initialLoadWaiters on cancel.
  • installFromZip rejects multi-bundle archives. installBundle and installFromZip now run bundle.load() on DispatchQueue.global(qos: .userInitiated) via validateAndLoadBundleAsync, off the main actor.

Storage & security

  • Registry manifest cache moved from UserDefaults binary blob to ~/Library/Caches/<bundle-id>/registry-manifest.json. Legacy registryManifestCache, registryETag, registryLastFetch keys are removed on first launch.
  • registryETag namespaced to com.TablePro.registryETag.
  • Signing requirement reads team identifier from Bundle.main at runtime via SecCodeCopySigningInformation. Falls back to the previous hardcoded value if no signature is available (DEBUG / ad-hoc).
  • removeRegistryMetadata logs errors instead of swallowing them silently.

HIG & UX

  • Restart banner gets a native Quit & Reopen button (NSWorkspace.openApplication + NSApp.terminate).
  • needsRestart is in-memory only; the banner no longer persists across launches.
  • Completed install badges auto-clear after 3 seconds. Failed installs still persist until the user retries.

Plugin SDK

  • Default escapeStringLiteral follows SQL standard — no longer escapes backslashes by default. Drivers opt in via requiresBackslashEscapingInLiterals. MySQLPluginDriver sets the flag.
  • Eager-loading fallback warns when user-installed plugins lack TableProProvides* Info.plist keys.

Test plan

  • EscapedParameterValueTests (8 tests, MySQL-style) pass
  • SqlStandardEscapeTests (4 new tests, SQL-standard mode) pass
  • IsNumericLiteralTests (4 tests) pass
  • PluginLazyLoadingTests (3 tests) pass
  • RegistryClientURLTests (4 tests) pass
  • Full project build passes
  • Install an outdated MSSQL plugin (or any built-in), upgrade via Settings → Plugins, restart, verify the upgraded version persists and the upgrade prompt does not reappear
  • Click "Quit & Reopen" in the restart banner and verify the app relaunches with the new plugin loaded
  • Try to install a ZIP archive containing two .tableplugin bundles; verify it is rejected with a clear error

datlechin added 3 commits May 11, 2026 12:50
…y hardening (#1192)

Discovery: scan built-in and user dirs, pick newest CFBundleShortVersionString
per bundle ID. Prune user copies only when older than or equal to built-in.
Read version from Info.plist instead of hardcoded principalClass.pluginVersion.

isInstalling guard now wraps installFromRegistry and updateFromRegistry at
their entry points; concurrent registry installs cannot race past it.

waitForInitialLoad wraps the timeout in withTaskCancellationHandler so the
continuation is always resumed and removed from the waiter list.

installFromZip rejects multi-bundle archives instead of silently installing
only the last one. Bundle load runs on a userInitiated DispatchQueue so the
main actor is not blocked during dyld symbol resolution.

Registry cache moved from UserDefaults binary blob to
~/Library/Caches/<bundle-id>/registry-manifest.json; legacy keys are removed
on first launch. registryETag namespaced to com.TablePro.registryETag.

Code signing requirement reads team identifier from Bundle.main signature at
runtime via SecCodeCopySigningInformation, with a documented fallback.

InstalledPluginsView restart banner gets a Quit & Reopen button that calls
NSWorkspace.openApplication followed by NSApp.terminate. needsRestart is
in-memory only so the banner does not persist across launches.

Completed install badges auto-clear after 3 seconds. Lazy-load fallback
emits a warning for user-installed plugins missing TableProProvides* keys.

Default escapeStringLiteral no longer escapes backslashes; drivers that
need MySQL-style escaping opt in via requiresBackslashEscapingInLiterals.
MySQLPluginDriver sets the flag. Tests cover both modes.
Migrating the legacy registry ETag while deleting the manifest cache blob
left the client in an inconsistent state: the server returned 304 against
the carried-over ETag, but the in-memory manifest stayed nil so the Browse
list rendered empty.

Two defenses: drop the legacy ETag during migration (force a fresh body
on first launch after upgrade), and if a 304 ever arrives with no cached
manifest, retry once with forceRefresh.
Drop unreleased doc comment from the new requiresBackslashEscapingInLiterals
property; collapse RegistryMetadata to a single pluginId field and remove
the dead version-with-custom-Codable scaffolding.

Rename performInstall to performInstallAssumingLock so the contract that
the caller already holds isInstalling is encoded in the name, since the
function must remain at least internal for the registry extension to call
it across files.

Quit & Reopen now checks the openApplication completion result and only
calls NSApp.terminate when a new instance launched successfully; on
failure the user sees an alert and the running app stays alive.

pruneOutdatedUserCopies log differentiates equal-version pruning from
truly older copies so support diagnostics do not report "outdated" for
identical versions.

Reorder Unreleased CHANGELOG sections to Keep a Changelog 1.1.0 order
(Added, Changed, Fixed) and fold the plugin entries into the existing
Changed and Fixed sections rather than appending fresh ones.
@datlechin
datlechin merged commit 7edf694 into main May 11, 2026
2 checks passed
@datlechin
datlechin deleted the fix/plugin-system-audit branch May 11, 2026 06:07
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