Skip to content

Commit 437ffa3

Browse files
fix(cli): exit after interactive secret input (#7118)
1 parent db88eca commit 437ffa3

4 files changed

Lines changed: 12 additions & 10 deletions

File tree

bun.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sim-cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sim",
3-
"version": "2.1.1",
3+
"version": "2.1.2",
44
"description": "Sim CLI - talk to the Sim API from your terminal",
55
"type": "module",
66
"bin": {

packages/sim-cli/src/terminal/secret-input.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ const ESCAPE = '\u001b'
88
class FakeInput extends EventEmitter {
99
isTTY = true
1010
isRaw = false
11-
paused = true
11+
readableFlowing: boolean | null = null
1212
readonly rawStates: boolean[] = []
1313

1414
isPaused(): boolean {
15-
return this.paused
15+
return this.readableFlowing === false
1616
}
1717

1818
setRawMode(value: boolean): this {
@@ -22,12 +22,12 @@ class FakeInput extends EventEmitter {
2222
}
2323

2424
resume(): this {
25-
this.paused = false
25+
this.readableFlowing = true
2626
return this
2727
}
2828

2929
pause(): this {
30-
this.paused = true
30+
this.readableFlowing = false
3131
return this
3232
}
3333
}
@@ -42,9 +42,11 @@ class FakeOutput {
4242
}
4343

4444
describe('promptSecret', () => {
45-
it('masks input and restores the terminal before returning it', async () => {
45+
it('masks input and pauses an initially idle terminal before returning', async () => {
4646
const input = new FakeInput()
4747
const output = new FakeOutput()
48+
expect(input.isPaused()).toBe(false)
49+
4850
const result = promptSecret(input as unknown as ReadStream, output)
4951

5052
input.emit('keypress', 'hunter2', { name: 'h' })
@@ -53,7 +55,7 @@ describe('promptSecret', () => {
5355
await expect(result).resolves.toBe('hunter2')
5456
expect(output.value).toBe('Secret value: *******\n')
5557
expect(input.rawStates).toEqual([true, false])
56-
expect(input.paused).toBe(true)
58+
expect(input.isPaused()).toBe(true)
5759
})
5860

5961
it('handles backspace without revealing the value', async () => {
@@ -88,6 +90,7 @@ describe('promptSecret', () => {
8890
await expect(result).rejects.toThrow('Secret input cancelled.')
8991
await expect(result).rejects.toBeInstanceOf(SecretInputCancelledError)
9092
expect(input.rawStates).toEqual([true, false])
93+
expect(input.isPaused()).toBe(true)
9194
})
9295

9396
it('keeps the character following a pasted escape byte', async () => {

packages/sim-cli/src/terminal/secret-input.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export function promptSecret(
4545
throw new SimApiError('Interactive secret input requires a terminal. Pass --value instead.', 0)
4646
}
4747

48-
const wasPaused = input.isPaused()
4948
const wasRaw = input.isRaw
5049
let value = ''
5150
let settled = false
@@ -59,7 +58,7 @@ export function promptSecret(
5958
const cleanup = () => {
6059
input.removeListener('keypress', onKeypress)
6160
input.setRawMode(wasRaw)
62-
if (wasPaused) input.pause()
61+
input.pause()
6362
}
6463

6564
const finish = (complete: () => void) => {

0 commit comments

Comments
 (0)