feat(sdk-python): add network timeouts to release version helper (#3833)

This commit is contained in:
jinye 2026-05-05 19:25:00 +08:00 committed by GitHub
parent ec51fd3138
commit 07441cc1e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 105 additions and 3 deletions

View file

@ -50,6 +50,16 @@ function makeExecError(message, { stderr = '', stdout = '', status } = {}) {
return error;
}
function makeTimeoutError(command) {
const error = new Error(`Command failed: ${command}\nSIGTERM`);
// Real Node.js execSync timeout shape (verified on Node 20+):
// killed=undefined, signal='SIGTERM', code='ETIMEDOUT'
error.code = 'ETIMEDOUT';
error.signal = 'SIGTERM';
error.status = null;
return error;
}
function makeExecSyncMock({
tags = {},
tagError = null,
@ -927,4 +937,51 @@ describe('python sdk get-release-version', () => {
resumeExistingRelease: true,
});
});
it('throws a timeout error when gh release view times out', async () => {
execSyncMock.mockImplementation(
makeExecSyncMock({
releases: {
'sdk-python-v0.1.0-preview.0': makeTimeoutError(
'gh release view "sdk-python-v0.1.0-preview.0"',
),
},
}),
);
const getVersion = await loadGetVersion();
await expect(getVersion({ type: 'preview' })).rejects.toThrow(
'gh release view timed out after 30s checking "sdk-python-v0.1.0-preview.0" — GitHub API may be unavailable',
);
});
it('throws a timeout error when git tag -l times out', async () => {
execSyncMock.mockImplementation(
makeExecSyncMock({
tagError: makeTimeoutError('git tag -l'),
}),
);
const getVersion = await loadGetVersion();
await expect(getVersion({ type: 'preview' })).rejects.toThrow(
'git tag -l timed out after 10s — local git may be unresponsive',
);
});
it('throws a timeout error when git rev-parse times out', async () => {
execSyncMock.mockImplementation((command) => {
if (command === 'git rev-parse --short HEAD') {
throw makeTimeoutError('git rev-parse --short HEAD');
}
return makeExecSyncMock()(command);
});
const getVersion = await loadGetVersion();
await expect(getVersion({ type: 'nightly' })).rejects.toThrow(
'git rev-parse timed out after 10s — local git may be unresponsive',
);
});
});