Skip to content

Commit 5f7dba1

Browse files
authored
fix(auth): honor request timeout during configure (#52)
1 parent 7928b5c commit 5f7dba1

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

src/commands/auth.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,50 @@ describe('runConfigure', () => {
110110
);
111111
});
112112

113+
it('uses requestTimeoutMs for the pre-write key validation ping', async () => {
114+
const { deps } = makeCapture();
115+
let sawAbort = false;
116+
const fetchImpl = vi.fn(
117+
async (_input: string | URL | Request, init?: RequestInit) =>
118+
new Promise<Response>((_resolve, reject) => {
119+
const signal = init?.signal;
120+
const timeout = setTimeout(() => {
121+
reject(new Error('requestTimeoutMs was not applied to the validation ping'));
122+
}, 50);
123+
signal?.addEventListener(
124+
'abort',
125+
() => {
126+
sawAbort = true;
127+
clearTimeout(timeout);
128+
reject(new DOMException('The operation timed out.', 'TimeoutError'));
129+
},
130+
{ once: true },
131+
);
132+
}),
133+
) as unknown as typeof fetch;
134+
135+
await expect(
136+
runConfigure(
137+
{
138+
profile: 'default',
139+
output: 'text',
140+
debug: false,
141+
fromEnv: true,
142+
requestTimeoutMs: 1,
143+
},
144+
{
145+
...deps,
146+
env: { TESTSPRITE_API_KEY: 'sk' },
147+
credentialsPath,
148+
fetchImpl,
149+
},
150+
),
151+
).rejects.toBeInstanceOf(CLIError);
152+
153+
expect(sawAbort).toBe(true);
154+
expect(readProfile('default', { path: credentialsPath })).toBeUndefined();
155+
});
156+
113157
it('throws VALIDATION_ERROR when --from-env is set but key is missing', async () => {
114158
const { deps } = makeCapture();
115159
await expect(

src/commands/auth.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export async function runConfigure(opts: ConfigureOptions, deps: AuthDeps = {}):
145145
baseUrl: facadeBaseUrl(apiUrl),
146146
apiKey,
147147
fetchImpl: deps.fetchImpl,
148+
requestTimeoutMs: opts.requestTimeoutMs,
148149
});
149150
try {
150151
// Tag the validation call with the originating command (when provided) so

0 commit comments

Comments
 (0)