Skip to content

Commit 83fb835

Browse files
Fix false upgrade notifications when latest Dev Proxy version is already installed (#288)
Co-authored-by: garrytrinder <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
1 parent 40f095d commit 83fb835

File tree

3 files changed

+102
-24
lines changed

3 files changed

+102
-24
lines changed

package-lock.json

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/detect.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,29 @@ export const extractVersionFromOutput = (output: string): string => {
4141
return '';
4242
}
4343

44-
// Extract version number using semver pattern
45-
// Matches: major.minor.patch[-prerelease][+build] but only captures up to prerelease
46-
const semverRegex = /v?(\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?)(?:\+[a-zA-Z0-9.-]+)?/;
47-
const match = output.match(semverRegex);
48-
return match ? match[1] : '';
44+
// Split into lines and look for version information on dedicated lines
45+
// This avoids extracting versions from file paths like /opt/homebrew/Cellar/dev-proxy/v0.29.1/devproxy-errors.json
46+
const lines = output.split('\n');
47+
48+
// Look for lines that contain version information (not file paths)
49+
for (const line of lines) {
50+
const trimmedLine = line.trim();
51+
52+
// Skip lines that contain file paths (indicated by slashes and common path patterns)
53+
if (trimmedLine.includes('/') || trimmedLine.includes('\\') || trimmedLine.includes('loaded from')) {
54+
continue;
55+
}
56+
57+
// Look for version pattern on non-filepath lines
58+
// Matches: major.minor.patch[-prerelease][+build] but only captures up to prerelease
59+
const semverRegex = /v?(\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?)(?:\+[a-zA-Z0-9.-]+)?/;
60+
const match = trimmedLine.match(semverRegex);
61+
if (match) {
62+
return match[1];
63+
}
64+
}
65+
66+
return '';
4967
};
5068

5169
export const getOutdatedVersion = async (devProxyExe: string): Promise<string> => {

src/test/extension.test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,4 +625,64 @@ suite('extractVersionFromOutput', () => {
625625
const result = detect.extractVersionFromOutput(output);
626626
assert.strictEqual(result, '1.0.0-beta.1');
627627
});
628+
629+
test('should not extract version from file paths in error responses (issue #286)', () => {
630+
const output = `info 1 error responses loaded from /opt/homebrew/Cellar/dev-proxy/v0.29.1/devproxy-errors.json`;
631+
632+
const result = detect.extractVersionFromOutput(output);
633+
assert.strictEqual(result, '');
634+
});
635+
636+
test('should extract version from update notification line, ignoring file paths (issue #286)', () => {
637+
const output = `info 1 error responses loaded from /opt/homebrew/Cellar/dev-proxy/v0.29.0/devproxy-errors.json
638+
info v0.29.1`;
639+
640+
const result = detect.extractVersionFromOutput(output);
641+
assert.strictEqual(result, '0.29.1');
642+
});
643+
644+
test('should not extract version from Windows file paths', () => {
645+
const output = `info 1 error responses loaded from C:\\Program Files\\dev-proxy\\v0.29.1\\devproxy-errors.json`;
646+
647+
const result = detect.extractVersionFromOutput(output);
648+
assert.strictEqual(result, '');
649+
});
650+
651+
test('should extract version from actual update notification with Windows paths in earlier lines', () => {
652+
const output = `info 1 error responses loaded from C:\\Program Files\\dev-proxy\\v0.29.0\\devproxy-errors.json
653+
info v0.29.1`;
654+
655+
const result = detect.extractVersionFromOutput(output);
656+
assert.strictEqual(result, '0.29.1');
657+
});
658+
659+
test('should not extract beta version from Unix file paths (issue #286)', () => {
660+
const output = `info 1 error responses loaded from /opt/homebrew/Cellar/dev-proxy/v0.30.0-beta.2/devproxy-errors.json`;
661+
662+
const result = detect.extractVersionFromOutput(output);
663+
assert.strictEqual(result, '');
664+
});
665+
666+
test('should not extract beta version from Windows file paths (issue #286)', () => {
667+
const output = `info 1 error responses loaded from C:\\Program Files\\dev-proxy\\v0.30.0-beta.2\\devproxy-errors.json`;
668+
669+
const result = detect.extractVersionFromOutput(output);
670+
assert.strictEqual(result, '');
671+
});
672+
673+
test('should extract beta version from update notification, ignoring file paths (issue #286)', () => {
674+
const output = `info 1 error responses loaded from /opt/homebrew/Cellar/dev-proxy/v0.30.0-beta.1/devproxy-errors.json
675+
info v0.30.0-beta.2`;
676+
677+
const result = detect.extractVersionFromOutput(output);
678+
assert.strictEqual(result, '0.30.0-beta.2');
679+
});
680+
681+
test('should extract beta version from update notification with Windows paths in earlier lines (issue #286)', () => {
682+
const output = `info 1 error responses loaded from C:\\Program Files\\dev-proxy\\v0.30.0-beta.1\\devproxy-errors.json
683+
info v0.30.0-beta.2`;
684+
685+
const result = detect.extractVersionFromOutput(output);
686+
assert.strictEqual(result, '0.30.0-beta.2');
687+
});
628688
});

0 commit comments

Comments
 (0)