Skip to content

Commit 2d5897b

Browse files
committed
fix(log-view): handle consola prompt cancel Symbol on Ctrl+C
consola's prompt() returns Symbol(clack:cancel) on Ctrl+C, which is truthy in JavaScript. Use strict `confirmed !== true` check instead of `!confirmed` to prevent opening browser tabs on cancel. Adds isolated test for cancel-symbol behavior.
1 parent ab88827 commit 2d5897b

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/commands/log/view.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ async function handleWebOpen(
212212
type: "confirm",
213213
initial: false,
214214
});
215-
if (!confirmed) {
215+
// consola prompt returns Symbol(clack:cancel) on Ctrl+C — a truthy value.
216+
// Strictly check for `true` to avoid opening tabs on cancel.
217+
if (confirmed !== true) {
216218
return;
217219
}
218220
}

test/isolated/log-view-prompt.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,25 @@ describe("log view --web interactive prompt", () => {
156156
expect(mockPrompt).toHaveBeenCalled();
157157
expect(openInBrowserSpy).not.toHaveBeenCalled();
158158
});
159+
160+
test("aborts when user cancels prompt with Ctrl+C (truthy Symbol)", async () => {
161+
// consola returns Symbol(clack:cancel) on Ctrl+C — truthy but not `true`.
162+
// Cast needed because the mock is typed as boolean but consola actually
163+
// returns a Symbol on cancel.
164+
mockPrompt.mockResolvedValue(Symbol("clack:cancel") as unknown as boolean);
165+
openInBrowserSpy.mockResolvedValue(undefined);
166+
167+
const { context } = createMockContext();
168+
const func = await viewCommand.loader();
169+
await func.call(
170+
context,
171+
{ json: false, web: true },
172+
"my-org/proj",
173+
ID1,
174+
ID2
175+
);
176+
177+
expect(mockPrompt).toHaveBeenCalled();
178+
expect(openInBrowserSpy).not.toHaveBeenCalled();
179+
});
159180
});

0 commit comments

Comments
 (0)