Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions apps/desktop/src/main/__tests__/assistant-stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,18 @@ import { describe, it } from 'node:test';
import {
ASSISTANT_MAX_DELTA_CHARS,
ASSISTANT_MAX_TOTAL_CHARS,
applyAssistantComplete,
applyAssistantDelta,
applyAssistantComplete as applyAssistantCompleteWithLocale,
applyAssistantDelta as applyAssistantDeltaWithLocale,
} from '@maka/ui/assistant-stream';
// Tests exercise stream mechanics, not copy; pin zh so markers stay verbatim.
const applyAssistantDelta = (prev: string, delta: string, options?: Partial<Parameters<typeof applyAssistantDeltaWithLocale>[2]>) =>
applyAssistantDeltaWithLocale(prev, delta, { locale: 'zh', ...options });
const applyAssistantComplete = (text: string, options?: Partial<Parameters<typeof applyAssistantCompleteWithLocale>[1]>) =>
applyAssistantCompleteWithLocale(text, { locale: 'zh', ...options });





function visibleDeltaResult(result: ReturnType<typeof applyAssistantDelta>) {
return {
Expand Down
73 changes: 73 additions & 0 deletions apps/desktop/src/main/__tests__/health-center-copy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import assert from 'node:assert/strict';
import { test } from 'node:test';
import { connectionLastTestMessageDisplay } from '../../renderer/features/connection-settings/index.js';
import { getHealthCenterCopy } from '../../renderer/locales/settings-health-copy.js';

test('labels blocker counts as global across filtered health views', () => {
Expand All @@ -31,3 +32,75 @@ test('labels blocker counts as global across filtered health views', () => {
'Across all health signals, 1 of 6 blocks sending',
);
});

const signal = (overrides: Partial<import('@maka/core/health').HealthSignal>): import('@maka/core/health').HealthSignal => ({
id: 'connection:demo',
label: 'Demo',
scope: 'llm_connection',
layer: 'configuration',
status: 'info',
source: 'settings',
checkedAt: 0,
message: 'not_default_source',
...overrides,
});

test('renders configuration message codes distinctly in both locales', () => {
const zh = getHealthCenterCopy('zh');
const en = getHealthCenterCopy('en');
assert.equal(zh.signalMessage(signal({ message: 'not_default_source' })), '不是工作区的默认模型来源。');
assert.equal(en.signalMessage(signal({ message: 'not_default_source' })), 'Not the workspace default model source.');
assert.equal(zh.signalMessage(signal({ message: 'no_models_enabled' })), '没有启用任何模型。');
assert.equal(en.signalMessage(signal({ message: 'no_models_enabled' })), 'No models are enabled on this connection.');
});

test('renders runtime probe details from structured params, not string parsing', () => {
const detail = { kind: 'runtime_probe_result', modelId: 'claude-sonnet-5', latencyMs: 812, errorClass: 'timeout' } as const;
assert.equal(
getHealthCenterCopy('zh').signalDetail(signal({ detail })),
'模型=claude-sonnet-5 · 延迟=812ms · 错误类型=timeout',
);
assert.equal(
getHealthCenterCopy('en').signalDetail(signal({ detail })),
'Model=claude-sonnet-5 · Latency=812ms · Error type=timeout',
);
});

test('degrades capability reasons safely in both locales', () => {
const unknown = { kind: 'capability_reason', reason: 'Discord rejected the Bot Token.' } as const;
assert.equal(
getHealthCenterCopy('zh').signalDetail(signal({ detail: unknown })),
'状态详情请见对应设置页。',
);
assert.equal(
getHealthCenterCopy('en').signalDetail(signal({ detail: unknown })),
'See the corresponding settings page for details.',
);
});

test('maps connection test error classes without exposing machine tokens', () => {
const auth = { kind: 'last_test_error_class', errorClass: 'auth' } as const;
assert.equal(getHealthCenterCopy('zh').signalDetail(signal({ detail: auth })), '鉴权失败');
assert.equal(getHealthCenterCopy('en').signalDetail(signal({ detail: auth })), 'Authentication failed');

const unknown = { kind: 'last_test_message', text: 'future_error_class' } as const;
assert.equal(
getHealthCenterCopy('zh').signalDetail(signal({ detail: unknown })),
'连接测试状态暂时无法显示,请重新测试。',
);
assert.equal(
getHealthCenterCopy('en').signalDetail(signal({ detail: unknown })),
'The connection test status is temporarily unavailable. Test again.',
);
});

test('maps connection test error classes in connection details', () => {
assert.equal(connectionLastTestMessageDisplay('auth', 'zh'), '鉴权失败');
assert.equal(connectionLastTestMessageDisplay('auth', 'en'), 'Authentication failed');
});

test('suffixes runtime signal labels per locale from the id, not the producer', () => {
const runtime = signal({ id: 'connection:demo:runtime', label: 'Demo' });
assert.equal(getHealthCenterCopy('zh').signalLabel(runtime), 'Demo 运行态');
assert.equal(getHealthCenterCopy('en').signalLabel(runtime), 'Demo runtime');
});
11 changes: 10 additions & 1 deletion apps/desktop/src/main/__tests__/thinking-stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@

import { strict as assert } from 'node:assert';
import { describe, it } from 'node:test';
import { applyThinkingComplete, applyThinkingDelta } from '@maka/ui';
import { applyThinkingComplete as applyThinkingCompleteWithLocale, applyThinkingDelta as applyThinkingDeltaWithLocale } from '@maka/ui';
// Tests exercise stream mechanics, not copy; pin zh so markers stay verbatim.
const applyThinkingDelta = (prev: string, delta: string, options?: Partial<Parameters<typeof applyThinkingDeltaWithLocale>[2]>) =>
applyThinkingDeltaWithLocale(prev, delta, { locale: 'zh', ...options });
const applyThinkingComplete = (text: string, options?: Partial<Parameters<typeof applyThinkingCompleteWithLocale>[1]>) =>
applyThinkingCompleteWithLocale(text, { locale: 'zh', ...options });





describe('applyThinkingDelta — secondary redaction', () => {
it('masks raw `Authorization: Bearer ...` text before storing', () => {
Expand Down
8 changes: 7 additions & 1 deletion apps/desktop/src/main/__tests__/tool-output-stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ import {
TOOL_STREAM_MAX_CHUNKS,
TOOL_STREAM_MAX_CHUNK_CHARS,
TOOL_STREAM_MAX_TOTAL_CHARS,
applyToolOutputChunk,
applyToolOutputChunk as applyToolOutputChunkWithLocale,
type ToolOutputChunk,
} from '@maka/ui';
// Tests exercise stream mechanics, not copy; pin zh so markers stay verbatim.
const applyToolOutputChunk = (prev: Parameters<typeof applyToolOutputChunkWithLocale>[0], chunk: Parameters<typeof applyToolOutputChunkWithLocale>[1], options?: Partial<Parameters<typeof applyToolOutputChunkWithLocale>[2]>) =>
applyToolOutputChunkWithLocale(prev, chunk, { locale: 'zh', ...options });




function chunk(seq: number, text: string, stream: 'stdout' | 'stderr' = 'stdout', redacted = false): ToolOutputChunk {
return { seq, text, stream, redacted, createdAt: 1_700_000_000_000 + seq };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ const zhCopy = {
categories: { oauth: 'OAuth', domestic: '国内', overseas: '海外', local: '本地', custom: 'Custom' },
connectionStatuses: { retired: '已停用 · 请删除', reauth: '需要重新登录', disabledFailed: '暂不可用 · 上次连接失败', disabled: '暂不可用', failed: '上次连接失败' },
lastTest: {
auth: '鉴权失败', timeout: '请求超时', provider_unavailable: '模型服务返回错误', network: '网络错误', invalid_response: '模型服务返回错误', unknown: '连接测试失败',
'连接已验证': '连接已验证', '鉴权失败': '鉴权失败', '请求超时': '请求超时', '网络错误': '网络错误', '模型服务返回错误': '模型服务返回错误', '连接测试失败': '连接测试失败',
'connection verified': '连接已验证', 'authentication failed': '鉴权失败', 'request timed out': '请求超时', 'network error': '网络错误', 'provider returned an error': '模型服务返回错误', 'connection test failed': '连接测试失败',
'claude oauth 未登录。': 'Claude OAuth 未登录。', 'claude oauth 本地凭据读取失败。': 'Claude OAuth 本地凭据读取失败。', 'claude oauth 需要重新登录。': 'Claude OAuth 需要重新登录。', 'claude oauth 已登录。': 'Claude OAuth 已登录。', 'claude oauth 已退出登录。': 'Claude OAuth 已退出登录。',
Expand Down Expand Up @@ -325,6 +326,7 @@ const enCopy: ProviderSettingsCopy = {
categories: { oauth: 'OAuth', domestic: 'China', overseas: 'Global', local: 'Local', custom: 'Custom' },
connectionStatuses: { retired: 'Retired · delete it', reauth: 'Sign-in required', disabledFailed: 'Unavailable · last connection failed', disabled: 'Unavailable', failed: 'Last connection failed' },
lastTest: {
auth: 'Authentication failed', timeout: 'Request timed out', provider_unavailable: 'Model service returned an error', network: 'Network error', invalid_response: 'Model service returned an error', unknown: 'Connection test failed',
'连接已验证': 'Connection verified', '鉴权失败': 'Authentication failed', '请求超时': 'Request timed out', '网络错误': 'Network error', '模型服务返回错误': 'Model service returned an error', '连接测试失败': 'Connection test failed',
'connection verified': 'Connection verified', 'authentication failed': 'Authentication failed', 'request timed out': 'Request timed out', 'network error': 'Network error', 'provider returned an error': 'Model service returned an error', 'connection test failed': 'Connection test failed',
'claude oauth 未登录。': 'Claude OAuth is signed out.', 'claude oauth 本地凭据读取失败。': 'Could not read local Claude OAuth credentials.', 'claude oauth 需要重新登录。': 'Claude OAuth requires sign-in.', 'claude oauth 已登录。': 'Claude OAuth is signed in.', 'claude oauth 已退出登录。': 'Claude OAuth signed out.',
Expand Down
Loading