fix(coding): reject mismatched Data Service errors

This commit is contained in:
2026-08-26 19:26:05 +08:00
parent e15d8b7f51
commit 6b36753b37
2 changed files with 35 additions and 0 deletions

View File

@@ -202,6 +202,24 @@ describe('DataServiceCloudClient', () => {
});
});
it('rejects a known error code paired with the wrong HTTP status', async () => {
const client = new DataServiceCloudClient({
fetchImpl: vi.fn<typeof fetch>().mockResolvedValue(
jsonResponse({ detail: { code: 'quota_exceeded' } }, { status: 400 }),
),
getAccessToken: vi.fn().mockResolvedValue('access-token'),
});
const result = await client.inspect(projectId);
expect(result).toMatchObject({
success: false,
status: 502,
code: 'upstream_invalid_response',
data: null,
});
});
it('normalizes malformed client errors and all upstream 5xx responses safely', async () => {
const fetchImpl = vi.fn<typeof fetch>()
.mockResolvedValueOnce(new Response(null, { status: 404 }))