Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/cli/src/commands/login.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { describe, expect, it } from 'vitest';
import { loginCmd } from './login.js';

// Regression guard for the `--no-browser` flag.
//
// Commander derives a boolean option named `browser` from `--no-browser` and defaults
// it to `true`. Passing an explicit default of `false` as the third argument overrides
// that, so `opts.browser` resolves to `false` even when the user never passed the flag.
// The action then evaluates `opts.browser !== false` as false and never opens the
// verification URL, which silently disables auto-open for everyone and makes
// `--no-browser` a no-op.
describe('login command --no-browser option', () => {
it('does not declare an explicit default value', () => {
const option = loginCmd.options.find((candidate) => candidate.long === '--no-browser');
expect(option).toBeDefined();
expect(option?.attributeName()).toBe('browser');
expect(option?.defaultValue).toBeUndefined();
});

it('defaults browser to true when the flag is absent', () => {
loginCmd.parseOptions([]);
expect(loginCmd.opts().browser).toBe(true);
});

it('sets browser to false when --no-browser is passed', () => {
loginCmd.parseOptions(['--no-browser']);
expect(loginCmd.opts().browser).toBe(false);
});
});
2 changes: 1 addition & 1 deletion packages/cli/src/commands/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
// the user approves on the page (or until the code expires).
export const loginCmd = new Command('login')
.description('Pair this CLI with your sh1pt.com account')
.option('--no-browser', 'do not auto-open the verification URL', false)
.option('--no-browser', 'do not auto-open the verification URL')
.action(async (opts: { browser: boolean }) => {
const existing = await readCredentials();
if (existing) {
Expand Down
Loading