-
-
Notifications
You must be signed in to change notification settings - Fork 10
fix(init): fix InkUI on native Windows terminals (CLI-1NT) #978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0bda41d
fix(init): fix InkUI on native Windows terminals (CLI-1NT)
betegon 9404632
fix(init): destroy ReadStream on setRawMode probe failure to prevent …
betegon e8593e0
test(init): update LoggingUIPromptError message assertion for isTTY path
betegon b6270ac
test(init): add coverage for InkUI catch fallback and LoggingUIPrompt…
betegon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| /** | ||
| * Tests for getUIAsync() — InkUI creation failure path. | ||
| * | ||
| * Uses mock.module() to simulate createInkUI() failing so we can verify | ||
| * getUIAsync() falls back to LoggingUI on any throw. This covers the | ||
| * catch block added for CLI-1NT (Windows InkUI regression). | ||
| * | ||
| * addBreadcrumb() is called in the catch block but cannot be spied on here: | ||
| * @sentry/node-core exports via CJS, so the binding in factory.ts is | ||
| * captured at module load time and is not reachable through mock.module(). | ||
| * Coverage of that line is provided by the tests below (the catch block | ||
| * executes; the breadcrumb call runs against the real SDK). | ||
| * | ||
| * Kept separate from factory.test.ts: mock.module() state is file-scoped, | ||
| * bun test --isolate gives each file a fresh module graph. | ||
| */ | ||
|
|
||
| import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test"; | ||
|
|
||
| // ── Mock setup — must precede all imports of the modules under test ──────── | ||
| // Bun processes mock.module() before resolving static imports in this file, | ||
| // so factory.ts picks up the mocked ink-ui.js at load time. | ||
|
|
||
| /** Swappable per-test — lets us exercise different failure modes. */ | ||
| let createInkUIImpl: () => Promise<never> = async () => { | ||
| throw new Error("mountApp failed: SetConsoleMode error"); | ||
| }; | ||
|
|
||
| mock.module("../../../../src/lib/init/ui/ink-ui.js", () => ({ | ||
| createInkUI: () => createInkUIImpl(), | ||
| })); | ||
|
|
||
| // ── Imports after mock setup ─────────────────────────────────────────────── | ||
|
|
||
| import { getUIAsync } from "../../../../src/lib/init/ui/factory.js"; | ||
| import { LoggingUI } from "../../../../src/lib/init/ui/logging-ui.js"; | ||
|
|
||
| // ── TTY helpers — mirrors factory.test.ts ───────────────────────────────── | ||
|
|
||
| type TerminalSnapshot = { | ||
| stdinTTY: boolean | undefined; | ||
| stdoutTTY: boolean | undefined; | ||
| }; | ||
|
|
||
| function snapshot(): TerminalSnapshot { | ||
| return { stdinTTY: process.stdin.isTTY, stdoutTTY: process.stdout.isTTY }; | ||
| } | ||
|
|
||
| function restore(snap: TerminalSnapshot): void { | ||
| (process.stdin as { isTTY: boolean | undefined }).isTTY = snap.stdinTTY; | ||
| (process.stdout as { isTTY: boolean | undefined }).isTTY = snap.stdoutTTY; | ||
| } | ||
|
|
||
| let saved: TerminalSnapshot; | ||
|
|
||
| beforeEach(() => { | ||
| saved = snapshot(); | ||
| // Both TTYs must be true so shouldUseLogging() returns false and | ||
| // getUIAsync() reaches the createInkUI() call. | ||
| (process.stdin as { isTTY: boolean }).isTTY = true; | ||
| (process.stdout as { isTTY: boolean }).isTTY = true; | ||
| // Reset to the default Error-throwing impl. | ||
| createInkUIImpl = async () => { | ||
| throw new Error("mountApp failed: SetConsoleMode error"); | ||
| }; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| restore(saved); | ||
| }); | ||
|
|
||
| // ── Tests ────────────────────────────────────────────────────────────────── | ||
|
|
||
| describe("getUIAsync — InkUI creation failure", () => { | ||
| test("falls back to LoggingUI when createInkUI throws an Error", async () => { | ||
| const ui = await getUIAsync({ yes: false }); | ||
| expect(ui).toBeInstanceOf(LoggingUI); | ||
| }); | ||
|
|
||
| test("falls back to LoggingUI when createInkUI rejects with a non-Error", async () => { | ||
| // Exercises the `err instanceof Error ? err.stack : undefined` branch | ||
| // in the breadcrumb — err.stack is undefined for non-Error rejects. | ||
| createInkUIImpl = async () => { | ||
| // biome-ignore lint/style/useThrowOnlyError: deliberately testing non-Error rejection | ||
| throw "WASM init failed"; | ||
| }; | ||
| const ui = await getUIAsync({ yes: false }); | ||
| expect(ui).toBeInstanceOf(LoggingUI); | ||
| }); | ||
|
|
||
| test("falls back to LoggingUI when the ink-ui import itself throws", async () => { | ||
| // Simulates a corrupted sidecar or missing $bunfs embed — the dynamic | ||
| // import throws before createInkUI is ever called. | ||
| createInkUIImpl = mock(() => | ||
| Promise.reject(new Error("Cannot find module")) | ||
| ); | ||
| const ui = await getUIAsync({ yes: false }); | ||
| expect(ui).toBeInstanceOf(LoggingUI); | ||
| }); | ||
|
|
||
| test("fallback is stateless — consecutive failures each return a fresh LoggingUI", async () => { | ||
| const first = await getUIAsync({ yes: false }); | ||
| const second = await getUIAsync({ yes: false }); | ||
| expect(first).toBeInstanceOf(LoggingUI); | ||
| expect(second).toBeInstanceOf(LoggingUI); | ||
| expect(first).not.toBe(second); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.