Add patch to prevent updates to unsupported versions#408
Add patch to prevent updates to unsupported versions#408
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the
📝 WalkthroughWalkthroughAdds a new misc setting Changes
Sequence DiagramsequenceDiagram
participant User as User
participant UI as tweakcc UI
participant Patch as Patch Pipeline
participant Updater as Auto-updater (patched)
participant GitHub as GitHub
User->>UI: Toggle "Prevent unsupported updates" (on)
UI->>Patch: Persist settings (preventUpdateToUnsupportedVersions = true)
Note over Patch: Patch pipeline runs during packaging/patch step and injects check into Updater
Note over Updater: At runtime when checking for updates...
Updater->>GitHub: HEAD /prompts/VERSION_X
GitHub-->>Updater: 200 / 404
alt 200 OK
Updater->>Updater: Proceed with update to VERSION_X
else 404 Not Found
Updater->>Updater: Block update (unsupported)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/patches/preventUnsupportedUpdates.ts`:
- Around line 106-112: The injected test code in tweakccVersionCheck is spoofing
the fetched version to "99.0.0" and writing debug logs to /tmp/tweakcc-test.log,
which will always block updates and leaks logs; remove the test artifacts so the
check uses the real fetched version variable (versionVar/v) and eliminate all
require("fs").appendFileSync calls and the hardcoded v="99.0.0" assignment;
retain the HEAD request using fetchFunc/channelVar and return currentVersionVar
only when the HEAD check fails or throws, preserving the original control flow
in the async IIFE.
🧹 Nitpick comments (1)
src/patches/preventUnsupportedUpdates.ts (1)
100-104: Consider adding length validation foridentifiersarray.While
getAutoUpdaterLocationguarantees 6 elements inidentifierswhen returning non-null, the non-null assertions (!) here rely on that implicit contract. If the regex or return structure changes, this could silently break.💡 Optional: Add explicit validation
+ if (!location.identifiers || location.identifiers.length < 6) { + console.error('patch: preventUnsupportedUpdates: invalid identifiers array'); + return null; + } + - const channelVar = location.identifiers![1]; - const versionVar = location.identifiers![2]; - const fetchFunc = location.identifiers![3]; - const nextVar = location.identifiers![4]; - const nextFunc = location.identifiers![5]; + const channelVar = location.identifiers[1]; + const versionVar = location.identifiers[2]; + const fetchFunc = location.identifiers[3]; + const nextVar = location.identifiers[4]; + const nextFunc = location.identifiers[5];
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/patches/preventUnsupportedUpdates.ts`:
- Around line 106-110: The injected tweakccVersionCheck currently swallows HEAD
fetch errors and allows updates; change the inline IIFE so its catch returns the
current version variable (currentVersionVar) to fail-closed: inside the
try/catch in the async IIFE used to compute versionVar (the template string
assigned to tweakccVersionCheck that references versionVar, fetchFunc,
channelVar, and currentVersionVar), ensure the catch block returns
${currentVersionVar} (and not nothing) so any fetch exception causes the code to
fallback to the current version and block the update.
🧹 Nitpick comments (1)
src/patches/preventUnsupportedUpdates.ts (1)
60-75: Broaden current-version lookup to reduce patch brittleness.The 500‑char window and
let‑only pattern make this easy to miss if minification shifts or usesconst/var, causing the patch to no-op. Scanning up to the updater block and allowingconst|varmakes the match more resilient.♻️ Suggested change
- const searchStart = Math.max(0, autoUpdaterLocation.startIndex - 500); - const searchChunk = oldFile.slice( - searchStart, - autoUpdaterLocation.startIndex - ); + const searchChunk = oldFile.slice(0, autoUpdaterLocation.startIndex); - const pattern = /let ([$\w]+)=\{[^}]*ISSUES_EXPLAINER:/g; + const pattern = /\b(?:let|const|var)\s+([$\w]+)=\{[^}]*ISSUES_EXPLAINER:/g;
|
@mike1858 Not working for me: Once you've fixed that (and added the 2.1.20 prompts to the tweakcc repo), to test if the patch is working properly, you can modify the |
|
@georpar Can you please try it now and mark it as ready for review if it works? It should work. |
|
The code looks good, and it works with npm installations, but it doesn't work with native installations. Needs to be investigated by @mike1858 or me. |
Closes #170.
Note: I can't test this until a new version of Claude Code (2.1.20) comes out.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.