Skip to content

Commit accfa5a

Browse files
Copilotmrlubos
andcommitted
Fix GitHub issue report enabled by default and --interactive option not working
Co-authored-by: mrlubos <[email protected]>
1 parent f134df3 commit accfa5a

File tree

2 files changed

+121
-7
lines changed

2 files changed

+121
-7
lines changed

packages/openapi-ts/bin/index.cjs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ const params = program
4949
'--useOptions [value]',
5050
'DEPRECATED. Use options instead of arguments?',
5151
)
52+
.option(
53+
'--interactive [value]',
54+
'Show an interactive error reporting tool when the program crashes? (default: false)',
55+
)
5256
.parse(process.argv)
5357
.opts();
5458

@@ -91,15 +95,14 @@ async function start() {
9195
'experimentalParser',
9296
'exportCore',
9397
'useOptions',
98+
'interactive',
9499
]);
95100

96-
const isInteractive =
97-
process.stdin.isTTY &&
98-
process.stdout.isTTY &&
99-
!process.env.CI &&
100-
!process.env.NO_INTERACTIVE &&
101-
!process.env.NO_INTERACTION;
102-
userConfig.interactive = isInteractive;
101+
// Only set interactive automatically if not explicitly configured by user
102+
// Default should be false according to documentation
103+
if (userConfig.interactive === undefined) {
104+
userConfig.interactive = false; // Default to false as per documentation
105+
}
103106

104107
if (params.plugins === true) {
105108
userConfig.plugins = [];
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import { describe, expect, it, vi } from 'vitest';
2+
3+
import { shouldReportCrash } from '../error';
4+
5+
describe('shouldReportCrash', () => {
6+
it('should return false when isInteractive is false', async () => {
7+
const result = await shouldReportCrash({
8+
error: new Error('test error'),
9+
isInteractive: false,
10+
});
11+
expect(result).toBe(false);
12+
});
13+
14+
it('should return false when isInteractive is undefined', async () => {
15+
const result = await shouldReportCrash({
16+
error: new Error('test error'),
17+
isInteractive: undefined,
18+
});
19+
expect(result).toBe(false);
20+
});
21+
22+
it('should not prompt when isInteractive is explicitly false', async () => {
23+
// Mock stdin/stdout to ensure we don't wait for user input
24+
const writeSpy = vi
25+
.spyOn(process.stdout, 'write')
26+
.mockImplementation(() => true);
27+
const setEncodingSpy = vi
28+
.spyOn(process.stdin, 'setEncoding')
29+
.mockImplementation(() => {});
30+
const onceSpy = vi
31+
.spyOn(process.stdin, 'once')
32+
.mockImplementation(() => process.stdin);
33+
34+
const result = await shouldReportCrash({
35+
error: new Error('test error'),
36+
isInteractive: false,
37+
});
38+
39+
expect(result).toBe(false);
40+
expect(writeSpy).not.toHaveBeenCalled();
41+
expect(setEncodingSpy).not.toHaveBeenCalled();
42+
expect(onceSpy).not.toHaveBeenCalled();
43+
44+
writeSpy.mockRestore();
45+
setEncodingSpy.mockRestore();
46+
onceSpy.mockRestore();
47+
});
48+
49+
it('should prompt when isInteractive is true', async () => {
50+
// Mock stdin/stdout for interactive session
51+
const writeSpy = vi
52+
.spyOn(process.stdout, 'write')
53+
.mockImplementation(() => true);
54+
const setEncodingSpy = vi
55+
.spyOn(process.stdin, 'setEncoding')
56+
.mockImplementation(() => {});
57+
const onceSpy = vi
58+
.spyOn(process.stdin, 'once')
59+
.mockImplementation((event, callback) => {
60+
// Simulate user typing 'n'
61+
setTimeout(() => {
62+
(callback as any)('n');
63+
}, 0);
64+
return process.stdin;
65+
});
66+
67+
const result = await shouldReportCrash({
68+
error: new Error('test error'),
69+
isInteractive: true,
70+
});
71+
72+
expect(result).toBe(false); // User said 'n'
73+
expect(writeSpy).toHaveBeenCalledWith(
74+
expect.stringContaining('📢 Open a GitHub issue with crash details?'),
75+
);
76+
77+
writeSpy.mockRestore();
78+
setEncodingSpy.mockRestore();
79+
onceSpy.mockRestore();
80+
});
81+
82+
it('should handle user saying yes to crash report', async () => {
83+
// Mock stdin/stdout for interactive session
84+
const writeSpy = vi
85+
.spyOn(process.stdout, 'write')
86+
.mockImplementation(() => true);
87+
const setEncodingSpy = vi
88+
.spyOn(process.stdin, 'setEncoding')
89+
.mockImplementation(() => {});
90+
const onceSpy = vi
91+
.spyOn(process.stdin, 'once')
92+
.mockImplementation((event, callback) => {
93+
// Simulate user typing 'y'
94+
setTimeout(() => {
95+
(callback as any)('y');
96+
}, 0);
97+
return process.stdin;
98+
});
99+
100+
const result = await shouldReportCrash({
101+
error: new Error('test error'),
102+
isInteractive: true,
103+
});
104+
105+
expect(result).toBe(true); // User said 'y'
106+
107+
writeSpy.mockRestore();
108+
setEncodingSpy.mockRestore();
109+
onceSpy.mockRestore();
110+
});
111+
});

0 commit comments

Comments
 (0)