fix(proxy): strip client fetch metadata upstream

This commit is contained in:
2026-08-24 22:04:56 +08:00
parent f902edefd0
commit 34a4434cfb
3 changed files with 14 additions and 5 deletions

View File

@@ -22,6 +22,7 @@ const SKIPPED_REQUEST_HEADERS = new Set([
'keep-alive',
'proxy-authenticate',
'proxy-authorization',
'sec-fetch-mode',
'te',
'trailer',
'transfer-encoding',

View File

@@ -20,6 +20,7 @@ function parseArgs(argv, projectRoot = process.cwd()) {
};
for (let index = 0; index < argv.length; index += 1) {
const argument = argv[index];
if (argument === '--') continue;
const value = argv[index + 1];
if (!value || value.startsWith('--')) throw new Error(`${argument} requires a value`);
if (argument === '--runtime-root') options.runtimeRoot = resolve(value);
@@ -306,11 +307,15 @@ export async function runPackagedProductProof(options) {
|| beforeSubmitText.includes('正在重新连接本地 Agent')) {
throw new Error(`Packaged proxy first Conversation exposed a runtime banner: ${beforeSubmitText}`);
}
await page.getByTestId('coding-message-composer').evaluate(
(form) => form.requestSubmit(),
);
await page.getByRole('button', { name: '发送' }).click({ timeout: 30_000 });
const proxyStatus = await waitForActiveProxyProof(electronApplication);
let proxyStatus;
try {
proxyStatus = await waitForActiveProxyProof(electronApplication);
} catch (error) {
const bodyText = await page.locator('body').innerText().catch(() => '<unavailable>');
throw new Error(`${error instanceof Error ? error.message : String(error)}; UI=${bodyText}`);
}
assertPackagedMain(proxyStatus);
assertProxyStatus(proxyStatus.proxy);
await evaluateProof(electronApplication, 'proxy.release-child');

View File

@@ -134,7 +134,9 @@ describe('ai proxy routes', () => {
const response = createResponse();
const handled = await handleAiProxyRoutes(
createRequest('POST', { model: 'deepseek-chat', messages: [] }),
createRequest('POST', { model: 'deepseek-chat', messages: [] }, {
'sec-fetch-mode': 'cors',
}),
response.res,
new URL('http://127.0.0.1:13210/api/ai-proxy/v1/chat/completions?trace=1'),
{} as never,
@@ -155,6 +157,7 @@ describe('ai proxy routes', () => {
const forwardedHeaders = fetchMock.mock.calls[0][1].headers as Record<string, string>;
expect(forwardedHeaders.authorization).toBeUndefined();
expect(forwardedHeaders.host).toBeUndefined();
expect(forwardedHeaders['sec-fetch-mode']).toBeUndefined();
expect(response.statusCode).toBe(200);
expect(response.header('content-type')).toBe('application/json');
expect(response.body()).toBe(JSON.stringify({ id: 'chatcmpl_1' }));