forked from alibaba/open-code-review
-
Notifications
You must be signed in to change notification settings - Fork 0
fix(update): suppress update nudge when installed version equals latest (#697) #30
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
Open
chethanuk
wants to merge
1
commit into
main
Choose a base branch
from
fix/issue-697-ocr-shows-update-nudge-despite-being
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| #!/usr/bin/env node | ||
| "use strict"; | ||
|
|
||
| // Inline the two pure functions under test so we don't need a test framework. | ||
| const SEMVER_RE = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/; | ||
|
|
||
| function semverGt(a, b) { | ||
| const pa = a.replace(/-.*$/, "").split(".").map(Number); | ||
| const pb = b.replace(/-.*$/, "").split(".").map(Number); | ||
| for (let i = 0; i < 3; i++) { | ||
| if ((pa[i] || 0) > (pb[i] || 0)) return true; | ||
| if ((pa[i] || 0) < (pb[i] || 0)) return false; | ||
| } | ||
| const aPre = a.includes("-"); | ||
| const bPre = b.includes("-"); | ||
| if (bPre && !aPre) return true; | ||
| return false; | ||
| } | ||
|
|
||
| function normalizeVersion(v) { | ||
| return v && v.startsWith("v") ? v.slice(1) : v; | ||
| } | ||
|
|
||
| let passed = 0, failed = 0; | ||
| function assert(cond, msg) { | ||
| if (cond) { console.log(` ok: ${msg}`); passed++; } | ||
| else { console.error(`FAIL: ${msg}`); failed++; } | ||
| } | ||
|
|
||
| // --- semverGt --- | ||
| assert(!semverGt("1.8.6", "1.8.6"), "equal versions: not gt"); | ||
| assert( semverGt("1.8.7", "1.8.6"), "patch bump: gt"); | ||
| assert(!semverGt("1.8.5", "1.8.6"), "older: not gt"); | ||
| assert( semverGt("2.0.0", "1.9.9"), "major bump: gt"); | ||
| assert( semverGt("1.8.6", "1.8.6-beta"), "stable > pre-release: gt"); | ||
| assert( semverGt("1.8.6", "1.8.6-rc1"), "stable > rc: gt"); | ||
|
|
||
| // --- normalizeVersion (the v-prefix fix) --- | ||
| assert(normalizeVersion("v1.8.6") === "1.8.6", "strips leading v"); | ||
| assert(normalizeVersion("1.8.6") === "1.8.6", "leaves bare version alone"); | ||
| assert(normalizeVersion("") === "", "empty string unchanged"); | ||
|
|
||
| // --- equal after normalize => no nudge --- | ||
| const latestRaw = "1.8.6"; // npm registry style | ||
| const installed = "1.8.6"; // from binary | ||
| const latest = normalizeVersion(latestRaw); | ||
| assert(SEMVER_RE.test(latest), "normalized version passes SEMVER_RE"); | ||
| assert(!semverGt(latest, installed), "equal versions: no nudge"); | ||
|
|
||
| // --- v-prefixed registry response handled correctly --- | ||
| const latestRawV = "v1.8.6"; | ||
| const latestNorm = normalizeVersion(latestRawV); | ||
| assert(SEMVER_RE.test(latestNorm), "v-prefixed from registry normalizes and passes SEMVER_RE"); | ||
| assert(!semverGt(latestNorm, "1.8.6"), "v-prefixed equal: no nudge"); | ||
| assert( semverGt(latestNorm, "1.8.5"), "v-prefixed newer: nudge shown"); | ||
|
|
||
| // --- hint display guard (ocr.js logic) --- | ||
| function shouldShowNudge(hintVersion, pkgVersion) { | ||
| const hintNorm = normalizeVersion(hintVersion); | ||
| const pkgNorm = normalizeVersion(pkgVersion); | ||
| return !pkgNorm || hintNorm !== pkgNorm; | ||
| } | ||
| assert(!shouldShowNudge("1.8.6", "1.8.6"), "same bare: no nudge"); | ||
| assert(!shouldShowNudge("v1.8.6", "1.8.6"), "v-hint vs bare: no nudge"); | ||
| assert(!shouldShowNudge("1.8.6", "v1.8.6"), "bare hint vs v-pkg: no nudge"); | ||
| assert( shouldShowNudge("1.8.7", "1.8.6"), "newer hint: show nudge"); | ||
| assert( shouldShowNudge("1.8.6", ""), "unknown pkg version: show nudge (safe default)"); | ||
|
|
||
| console.log(`\n${passed} passed, ${failed} failed`); | ||
| if (failed > 0) process.exit(1); |
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.
Suggestion: The wrapper package version is not necessarily the installed native binary version:
OCR_VERSIONcan pin the binary to an older release whilepackage.jsonretains the newer wrapper version. In that case this comparison suppresses the hint even though the binary is outdated. Compare against the resolved binary's actual version, or persist and use the version selected during installation. [api mismatch]Severity Level: Major⚠️
- ⚠️ Pinned native binaries can be mistaken for current versions.Prompt for AI Agent 🤖