fix: unblock local news page generation

This commit is contained in:
john
2026-07-25 21:55:00 +08:00
parent 793e64bfbc
commit 6b6f9ed01c
16 changed files with 1075 additions and 47 deletions
+131
View File
@@ -3,6 +3,7 @@ import test from 'node:test';
import {
createLlmProviderService,
CUSTOM_PROVIDER_ID,
MEMIND_DEEPSEEK_NO_THINK_PROVIDER_ID,
buildExecutorLaunchPlan,
decryptSecret,
encryptSecret,
@@ -753,6 +754,136 @@ test('syncProfileToGoosed writes provider, model and secret keys for builtin', a
);
});
test('syncProfileToGoosed routes local DeepSeek through the no-thinking proxy', async () => {
const previousProfile = process.env.MEMIND_RUNTIME_PROFILE;
const previousDisableThinking = process.env.MEMIND_DEEPSEEK_DISABLE_THINKING;
const previousProxyBase = process.env.MEMIND_DEEPSEEK_NO_THINK_BASE_URL;
const previousGateway = process.env.MEMIND_GOOSED_HOST_GATEWAY;
process.env.MEMIND_RUNTIME_PROFILE = 'local';
delete process.env.MEMIND_DEEPSEEK_DISABLE_THINKING;
delete process.env.MEMIND_DEEPSEEK_NO_THINK_BASE_URL;
process.env.MEMIND_GOOSED_HOST_GATEWAY = 'host.lima.internal';
try {
const calls = [];
const mockFetch = async (url, init = {}) => {
const href = String(url);
const body = init.body ? JSON.parse(init.body) : null;
calls.push({ href, method: init.method ?? 'GET', body });
if (
init.method === 'PUT'
&& href.includes(`/config/custom-providers/${MEMIND_DEEPSEEK_NO_THINK_PROVIDER_ID}`)
) {
return { ok: false, status: 404, text: async () => '' };
}
if (init.method === 'POST' && href.endsWith('/config/custom-providers')) {
return {
ok: true,
json: async () => ({ provider_name: MEMIND_DEEPSEEK_NO_THINK_PROVIDER_ID }),
text: async () => '',
};
}
return { ok: true, status: 200, text: async () => '' };
};
const providerId = await syncProfileToGoosed(
'https://127.0.0.1:18006',
'secret',
{
providerKind: 'builtin',
providerId: 'custom_deepseek',
defaultModel: 'deepseek-v4-pro',
apiKey: 'sk-test',
},
mockFetch,
);
assert.equal(providerId, MEMIND_DEEPSEEK_NO_THINK_PROVIDER_ID);
const createCall = calls.find(
(call) => call.method === 'POST' && call.href.endsWith('/config/custom-providers'),
);
assert.equal(createCall?.body?.api_url, 'http://host.lima.internal:18036/v1');
assert.equal(createCall?.body?.preserves_thinking, false);
const providerWrite = calls.find(
(call) => call.href.includes('/config/upsert') && call.body?.key === 'GOOSE_PROVIDER',
);
assert.equal(providerWrite?.body?.value, MEMIND_DEEPSEEK_NO_THINK_PROVIDER_ID);
} finally {
if (previousProfile == null) delete process.env.MEMIND_RUNTIME_PROFILE;
else process.env.MEMIND_RUNTIME_PROFILE = previousProfile;
if (previousDisableThinking == null) delete process.env.MEMIND_DEEPSEEK_DISABLE_THINKING;
else process.env.MEMIND_DEEPSEEK_DISABLE_THINKING = previousDisableThinking;
if (previousProxyBase == null) delete process.env.MEMIND_DEEPSEEK_NO_THINK_BASE_URL;
else process.env.MEMIND_DEEPSEEK_NO_THINK_BASE_URL = previousProxyBase;
if (previousGateway == null) delete process.env.MEMIND_GOOSED_HOST_GATEWAY;
else process.env.MEMIND_GOOSED_HOST_GATEWAY = previousGateway;
}
});
test('syncProfileToGoosed routes local Moonshot profiles through schema compat proxy', async () => {
const previousProfile = process.env.MEMIND_RUNTIME_PROFILE;
const previousCompat = process.env.MEMIND_MOONSHOT_TOOL_SCHEMA_COMPAT;
const previousBase = process.env.MEMIND_MOONSHOT_COMPAT_BASE_URL;
const previousGateway = process.env.MEMIND_GOOSED_HOST_GATEWAY;
process.env.MEMIND_RUNTIME_PROFILE = 'split-service';
delete process.env.MEMIND_MOONSHOT_TOOL_SCHEMA_COMPAT;
delete process.env.MEMIND_MOONSHOT_COMPAT_BASE_URL;
process.env.MEMIND_GOOSED_HOST_GATEWAY = 'host.lima.internal';
try {
const calls = [];
const mockFetch = async (url, init = {}) => {
const href = String(url);
const body = init.body ? JSON.parse(init.body) : null;
calls.push({ href, method: init.method ?? 'GET', body });
if (
init.method === 'PUT'
&& href.includes('/config/custom-providers/custom_kimi')
) {
return { ok: true, status: 200, text: async () => '' };
}
return { ok: true, status: 200, text: async () => '' };
};
const providerId = await syncProfileToGoosed(
'https://127.0.0.1:18006',
'secret',
{
providerKind: 'custom',
providerId: 'custom_kimi',
goosedProviderId: 'custom_kimi',
name: 'kimi',
apiUrl: 'https://api.moonshot.cn/v1',
apiKey: 'sk-test',
models: ['kimi-k2.6', 'kimi-k3'],
defaultModel: 'kimi-k2.6',
engine: 'openai',
},
mockFetch,
);
assert.equal(providerId, 'custom_kimi');
const updateCall = calls.find(
(call) => call.method === 'PUT'
&& call.href.includes('/config/custom-providers/custom_kimi'),
);
assert.equal(
updateCall?.body?.api_url,
'http://host.lima.internal:18036/moonshot/v1',
);
assert.equal(updateCall?.body?.preserves_thinking, false);
} finally {
if (previousProfile == null) delete process.env.MEMIND_RUNTIME_PROFILE;
else process.env.MEMIND_RUNTIME_PROFILE = previousProfile;
if (previousCompat == null) delete process.env.MEMIND_MOONSHOT_TOOL_SCHEMA_COMPAT;
else process.env.MEMIND_MOONSHOT_TOOL_SCHEMA_COMPAT = previousCompat;
if (previousBase == null) delete process.env.MEMIND_MOONSHOT_COMPAT_BASE_URL;
else process.env.MEMIND_MOONSHOT_COMPAT_BASE_URL = previousBase;
if (previousGateway == null) delete process.env.MEMIND_GOOSED_HOST_GATEWAY;
else process.env.MEMIND_GOOSED_HOST_GATEWAY = previousGateway;
}
});
test('syncSelectedToGoosed writes selected provider to every configured target', async () => {
const encrypted = encryptSecret('sk-test', 'unit-test-secret');
const row = {