Skip to content

Commit 7d757e3

Browse files
committed
Fix upgrade command. Closes #293
Closes #293
1 parent b5b3a28 commit 7d757e3

File tree

3 files changed

+72
-3
lines changed

3 files changed

+72
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
> **Note**: odd version numbers, for example, `0.13.0`, are not included in this changelog. They are used to test the new features and fixes before the final release.
9+
910
## [0.26.3] - 2025-06-27
1011

12+
### Fixed:
13+
14+
- Commands: Fixed issue where brew update output would be shown in a notification when upgrading Dev Proxy via homebrew
15+
1116
## [0.26.2] - 2025-06-27
1217

1318
### Changed:

src/helpers.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,11 @@ export const executeCommand = async (cmd: string, options: ExecOptions = {}): Pr
122122
return new Promise((resolve, reject) => {
123123
exec(cmd, options, (error, stdout, stderr) => {
124124
if (error) {
125-
reject(`exec error: ${error}`);
126-
} else if (stderr) {
127-
reject(`stderr: ${stderr}`);
125+
// Command failed with non-zero exit code
126+
reject(`exec error: ${error}${stderr ? `\nstderr: ${stderr}` : ''}`);
128127
} else {
128+
// Command succeeded (exit code 0), return stdout
129+
// Note: Many tools like brew send informational messages to stderr even on success
129130
resolve(stdout);
130131
}
131132
});

src/test/extension.test.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as vscode from 'vscode';
33
import {
44
isConfigFile,
55
sleep,
6+
executeCommand,
67
} from '../helpers';
78
import * as path from 'path';
89
import { createCodeLensForPluginNodes } from '../codelens';
@@ -686,3 +687,65 @@ info v0.30.0-beta.2`;
686687
assert.strictEqual(result, '0.30.0-beta.2');
687688
});
688689
});
690+
691+
suite('executeCommand', () => {
692+
test('should resolve when command succeeds with stdout only', async () => {
693+
// Test with a simple command that only outputs to stdout
694+
const result = await executeCommand('echo "hello world"');
695+
assert.strictEqual(result.trim(), 'hello world');
696+
});
697+
698+
test('should resolve when command succeeds with stderr output (informational)', async () => {
699+
// Test with a command that outputs to stderr but exits with code 0
700+
// This simulates brew update behavior where informational messages go to stderr
701+
const result = await executeCommand('echo "output" && echo "info message" >&2');
702+
assert.strictEqual(result.trim(), 'output');
703+
});
704+
705+
test('should reject when command fails with non-zero exit code', async () => {
706+
// Test with a command that fails (exit code 1)
707+
try {
708+
await executeCommand('exit 1');
709+
assert.fail('Expected executeCommand to reject but it resolved');
710+
} catch (error) {
711+
assert.ok(typeof error === 'string');
712+
assert.ok(error.includes('exec error'));
713+
}
714+
});
715+
716+
test('should reject when command fails and include stderr in error message', async () => {
717+
// Test with a command that fails and outputs to stderr
718+
try {
719+
await executeCommand('echo "error details" >&2 && exit 1');
720+
assert.fail('Expected executeCommand to reject but it resolved');
721+
} catch (error) {
722+
assert.ok(typeof error === 'string');
723+
assert.ok(error.includes('exec error'));
724+
assert.ok(error.includes('error details'));
725+
}
726+
});
727+
728+
test('should handle command not found errors', async () => {
729+
try {
730+
await executeCommand('nonexistentcommand12345');
731+
assert.fail('Expected executeCommand to reject but it resolved');
732+
} catch (error) {
733+
assert.ok(typeof error === 'string');
734+
assert.ok(error.includes('exec error'));
735+
}
736+
});
737+
738+
test('should resolve with empty string when command succeeds with no output', async () => {
739+
const result = await executeCommand('true'); // true command succeeds and outputs nothing
740+
assert.strictEqual(result, '');
741+
});
742+
743+
test('should simulate brew update behavior (GitHub issue #292)', async () => {
744+
// Simulate the specific case from GitHub issue #292 where brew sends
745+
// informational messages to stderr but the command succeeds
746+
const result = await executeCommand('echo "Already up-to-date." && echo "==> Updating Homebrew..." >&2');
747+
748+
// Should resolve (not reject) and return stdout content
749+
assert.strictEqual(result.trim(), 'Already up-to-date.');
750+
});
751+
});

0 commit comments

Comments
 (0)