Skip to content
Merged
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
36 changes: 21 additions & 15 deletions apps/desktop/forge.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ function signPackagedExes(buildPath: string): void {

/**
* macOS 打包显示名(与 win32metadata 同构):packaged 后把
* .app 的 Info.plist 里 CFBundleDisplayName 改成 Cindy——Dock 名、Cmd+Tab、
* .app 的 Info.plist 里 CFBundleDisplayName 写成 BRAND_IDENTITY.displayName——Dock 名、Cmd+Tab、
* Finder、系统通知读的都是它(显示优先级 CFBundleDisplayName > CFBundleName)。
*
* ⚠️ 绝不能改 CFBundleName:Electron 启动时用主 app 的 CFBundleName 拼
Expand All @@ -704,7 +704,7 @@ function signPackagedExes(buildPath: string): void {
* cn 构建的 packager 本身就会把 CFBundleName/CFBundleDisplayName 写成 Cindy,
* 对 cn 是冗余兜底;2026-07-26 global exe 名与 cn 统一为 'Cindy' 后 global
* 同样只是冗余兜底;dev 构建的 packager name 仍是 'CindyDev',本步骤把
* Dock 名、Cmd+Tab、系统通知的**显示层**拉回 Cindy(BRAND_NAME 各区共用),
* Dock 名、Cmd+Tab、系统通知的**显示层**统一为各区共用的品牌显示名,
* 对 dev 是显示名的唯一来源。正式签名/公证(外部发布流程)发生在
* postPackage 之后,本改动会被签名一起封印,不存在破坏签名问题。
*/
Expand All @@ -719,19 +719,25 @@ function applyMacPackagedDisplayName(buildPath: string, platform: string): void
// 只改 CFBundleDisplayName;CFBundleName 必须保持 packager name 原值,
// 否则 Electron 找不到 Helper app(见函数头 ⚠️)。
const key = 'CFBundleDisplayName';
// packager 必写该键,Set 即可;Add 兜底防未来 packager 行为变化。
const set = spawnSync('/usr/libexec/PlistBuddy', ['-c', `Set :${key} Cindy`, plistPath]);
if (set.status !== 0) {
const add = spawnSync('/usr/libexec/PlistBuddy', [
'-c',
`Add :${key} string Cindy`,
plistPath,
]);
if (add.status !== 0) {
throw new Error(`[forge:postPackage] PlistBuddy failed to set ${key} in ${plistPath}`);
}
const displayName = BRAND_IDENTITY.displayName;
const plutil = '/usr/bin/plutil';
const keyType = spawnSync(plutil, ['-type', key, '--', plistPath], { encoding: 'utf8' });
if (keyType.status !== 0 && keyType.status !== 1) {
const detail = keyType.error?.message || keyType.signal || `exit ${keyType.status}`;
throw new Error(`[forge:postPackage] plutil could not check ${key} in ${plistPath}: ${detail}`);
}
// 缺键时显式插入。损坏或不可读的 plist 会在写入时报错。
const operation = keyType.status === 0 ? '-replace' : '-insert';
const result = spawnSync(plutil, [operation, key, '-string', displayName, '--', plistPath], {
encoding: 'utf8',
});
if (result.status !== 0) {
const detail =
result.error?.message || result.stderr?.trim() || result.stdout?.trim() ||
result.signal || `exit ${result.status}`;
throw new Error(`[forge:postPackage] plutil ${operation} failed for ${key} in ${plistPath}: ${detail}`);
}
console.log(`[forge:postPackage] mac display name → Cindy (${appDir}/Contents/Info.plist)`);
console.log(`[forge:postPackage] mac display name → ${displayName} (${appDir}/Contents/Info.plist)`);
}
}

Expand Down Expand Up @@ -2131,7 +2137,7 @@ const config: ForgeConfig = {
// 互覆已被 owner 接受)/ dev 'CindyDev'(显式设值防 packager 回落
// package.json productName 让 dev 与正式包撞名)。mac 的 Dock/Cmd+Tab/
// 通知**显示名**由 postPackage 的 applyMacPackagedDisplayName 经
// CFBundleDisplayName 统一拉回 Cindy(对 dev 是唯一显示名来源;
// CFBundleDisplayName 使用 BRAND_IDENTITY.displayName(对 dev 是唯一显示名来源;
// CFBundleName 不可动,Electron 靠它找 Helper,见该函数注释)。
name: CINDY_EXE,
executableName: CINDY_EXE,
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/scripts/dev-local-env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ if (!command) {

const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..', '..');
const env = withDesktopDevNodeOptions({ ...process.env, XDT_DESKTOP_DEV_MODE: 'local' });
delete env.CINDY_DEV_TERMINAL_SPAWNED;
const startupConfig = applyDesktopDevStartupConfig({ argv: rawArgs, env, mode: 'local' });
const args = stripDesktopDevRegionArgs(rawArgs);
if (!env.XDT_ENDPOINT_MANIFEST_FILE?.trim()) {
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/scripts/dev-remote-env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const env = withDesktopDevNodeOptions({
XDT_DESKTOP_DEV_MODE: 'remote',
VITE_CINDY_AUTH_REGION: startupConfig.region,
});
delete env.CINDY_DEV_TERMINAL_SPAWNED;
const isWindows = process.platform === 'win32';

// Windows 下 electron-forge 等 .cmd shim 需要经 shell 解析;shell 模式下 Node 不转义
Expand Down
15 changes: 15 additions & 0 deletions apps/desktop/scripts/fixtures/unified-model-rail/ui-page.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default {
cases: {
'uploaded-icon': { about: 'Uploaded SVG palette follows the selected source background and the idle theme', data: { customIcon } },
default: { about: '「全部」视图:联合列表 + 侧栏 rail 全格' },
'bailian-personal': { about: 'Bailian Personal monthly quota and countdown in the picker source details and rail' },
'custom-ids': { about: '#10253: custom models with near-identical names and long IDs differing only at the end' },
'custom-ids-legacy': { about: '#10253: the same custom IDs in the single-engine provider list' },
recent: { about: '「最近」视图:三态 Fast 载体(`ultrafast`/`true`)的条目后缀原样保留' },
Expand All @@ -21,6 +22,20 @@ export default {
},
async check(page, ui) {
await page.getByRole('listbox', { name: await ui.t('newChat.modelSelector.modelListAria') }).waitFor();
if (ui.case === 'bailian-personal') {
const rail = page.locator('[data-rail-item="provider:fixture-bailian"]');
await rail.locator('[data-weekly-remaining="77"]').waitFor();
await page.locator('[data-rail-item="all"]').click();
const details = page.locator('[data-model-source-details]').filter({ hasText: '77%' });
await details.waitFor();
const duration = `12${await ui.t('todaySpend.unit.day')} 3${await ui.t('todaySpend.unit.hour')}`;
assert.ok((await details.textContent()).includes(duration));
assert.ok((await rail.getAttribute('aria-description')).includes(await ui.t('quotaCard.monthlyLabel')));
await rail.hover();
await page.getByRole('tooltip').getByText(await ui.t('quotaCard.resetIn', { duration }), { exact: true }).waitFor({ state: 'attached' });
await ui.capture('monthly-quota');
return;
}
if (ui.case === 'cindy-brands') {
// 2026-11-30 user decision: a source holding models of many makers gets a second-level menu on top of its list —
// pills, icons only, the chosen one spelled out. Maker pills appear only inside that source's cell;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,28 @@ function SharedFavoritesFixture() {
/></main>;
}

const bailianProvider: ProviderView = {
id: 'fixture-bailian', name: '阿里云百炼 Token Plan', source: 'user',
agents: ['codex'], auth: { method: 'apiKey' }, access: { kind: 'api' }, connected: true,
routing: { codex: {
upstream: 'https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1',
authStrategy: 'api-key-header',
catalogPresetId: 'aliyun-bailian-token-plan-cn', usagePresetId: 'aliyun-bailian-token-plan-cn',
} },
models: { codex: [{ id: 'qwen4-max', name: 'Qwen4 Max', contextWindow: 200000, efforts: [] }] },
};

function BailianQuotaFixture() {
return <main className="p-4"><UnifiedModelPanel
providers={[bailianProvider]} scope="draft" providerUsage={{ deviceId: null }}
query="" sourceVersion="fixture" isVisible={() => true}
selected={{ providerId: bailianProvider.id, modelId: 'qwen4-max' }}
liveAgentKind="codex" agentFastModeCapable={() => false} priceOf={() => null}
providerLabel={() => bailianProvider.name} effortLabelOf={(_agent, effort) => effort}
onSelect={() => {}}
/></main>;
}

function Fixture({ scenario }: { scenario: string }) {
const { t } = useTranslation();
const gateway = scenario.startsWith('cindy-');
Expand Down Expand Up @@ -251,6 +273,15 @@ void mountPage({
return { maker: {
getModelContextLimit: async () => ({ limit: 272000, isCustomized: false }),
onProvidersChanged: subscription('providersChanged'),
...(ctx.case === 'bailian-personal' ? {
fetchProviderAccountUsage: async () => ({
status: 'ready', stale: false,
snapshot: {
kind: 'bailian-personal-quota', usedPercent: 23,
resetsAt: Date.now() + (12 * 24 + 3) * 3_600_000, fetchedAt: Date.now(),
},
}),
} : {}),
// agent 级 Fast 能力:useAgentCapabilities → electronAPI.maker.getCapabilities;
// 缺了它 unifiedAgentFastCapable 恒 false,行速度同样会被折掉。
getCapabilities: async () => ({
Expand All @@ -274,5 +305,6 @@ void mountPage({
},
} } : {}) };
},
render: ctx => ctx.case === 'share-favorite-recovery' ? <SharedFavoritesFixture /> : <Fixture scenario={ctx.case} />,
render: ctx => ctx.case === 'share-favorite-recovery' ? <SharedFavoritesFixture />
: ctx.case === 'bailian-personal' ? <BailianQuotaFixture /> : <Fixture scenario={ctx.case} />,
});
81 changes: 80 additions & 1 deletion apps/desktop/src/main/__tests__/hostDelegation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
installUnsupportedMakerFallbacks,
registerHostDelegatedIpc,
registerHostDelegatedSync,
forwardScheduleEvent,
pushBelongsToOwner,
resolveHostDelegation,
startHostEventBridge,
} from '../host-delegation';
Expand Down Expand Up @@ -421,6 +423,7 @@ describe('claimProxiedChannels and unsupported fallbacks', () => {
let projectAliasesNotified = false;
const errors: unknown[] = [];
const pluginPushes: unknown[] = [];
const scheduleEvents: Array<{ event: unknown; ownerStamp: unknown }> = [];

const server = http.createServer((req, res) => {
try {
Expand All @@ -443,6 +446,7 @@ describe('claimProxiedChannels and unsupported fallbacks', () => {
res.write('data: {"seq":10,"type":"subagent_runs_changed","sessionId":"s1"}\n\n');
res.write('data: {"seq":11,"type":"right_sidebar_tabs_changed","sessionId":"s1"}\n\n');
res.write('data: {"seq":12,"type":"plugin_push","channel":"ghosts:changed","payload":{"ghosts":[]}}\n\n');
res.write('data: {"seq":13,"type":"schedule_event","event":{"type":"fired","scheduleId":"s1","runId":"r1"},"ownerStamp":{"dataOwnerId":"o1","ownerGeneration":3}}\n\n');
} else {
res.writeHead(404);
res.end();
Expand All @@ -464,6 +468,7 @@ describe('claimProxiedChannels and unsupported fallbacks', () => {
onInputProjection: (payload) => projections.push(payload),
onInteractionRequest: (payload) => interactions.push(payload),
onPluginPush: (channel, payload) => pluginPushes.push({ channel, payload }),
onScheduleEvent: (event, ownerStamp) => scheduleEvents.push({ event, ownerStamp }),
onSettingsChanged: (domain, value) => settingsChanged.push({ domain, value }),
onSessionChanged: (event) => sessionEvents.push(event),
onMessageCreated: (event) => messageEvents.push(event),
Expand All @@ -482,7 +487,7 @@ describe('claimProxiedChannels and unsupported fallbacks', () => {

// Wait for the stream events to process
for (let i = 0; i < 20; i++) {
if (historyChanges.length >= 3 && sidebarChanges.length) break;
if (historyChanges.length >= 3 && sidebarChanges.length && scheduleEvents.length) break;
await new Promise((resolve) => setTimeout(resolve, 50));
}

Expand All @@ -494,6 +499,10 @@ describe('claimProxiedChannels and unsupported fallbacks', () => {
expect(projections).toEqual([{ sessionId: 's1', turnInProgress: true }]);
expect(interactions).toEqual([{ sessionId: 's1', request: { requestId: 'r1' } }]);
expect(pluginPushes).toEqual([{ channel: 'ghosts:changed', payload: { ghosts: [] } }]);
expect(scheduleEvents).toEqual([{
event: { type: 'fired', scheduleId: 's1', runId: 'r1' },
ownerStamp: { dataOwnerId: 'o1', ownerGeneration: 3 },
}]);
expect(settingsChanged).toEqual([{ domain: 'appearance', value: { theme: 'dark' } }]);
expect(sessionEvents).toEqual([{ seq: 2, type: 'session_changed', action: 'create', sessionId: 's1' }]);
expect(messageEvents).toEqual([{ seq: 3, type: 'message_created', sessionId: 's1', messageId: 'm1' }]);
Expand All @@ -507,6 +516,76 @@ describe('claimProxiedChannels and unsupported fallbacks', () => {
});
});

describe('forwardScheduleEvent', () => {
const send = () => {
const sent: unknown[] = [];
return { sent, send: (event: unknown) => { sent.push(event); } };
};

it('uses the Host authoritative stamp, not the local process generation', () => {
const hostAuthoritative = { dataOwnerId: 'owner-a', ownerGeneration: 7 };
const localGeneration = { dataOwnerId: 'owner-a', ownerGeneration: 42 };
const out = send();
const event = { type: 'fired', scheduleId: 's1', runId: 'r1' };
expect(forwardScheduleEvent({
event,
ownerStamp: { dataOwnerId: 'owner-a', ownerGeneration: 7 },
boundaryPending: false,
currentOwner: hostAuthoritative,
send: out.send,
})).toBe(true);
expect(out.sent).toEqual([event]);
// The old local-generation comparison would have dropped this valid event.
expect(pushBelongsToOwner({ dataOwnerId: 'owner-a', ownerGeneration: 7 }, localGeneration)).toBe(false);
});

it('drops a stale Host generation', () => {
const out = send();
expect(forwardScheduleEvent({
event: { type: 'completed' },
ownerStamp: { dataOwnerId: 'owner-a', ownerGeneration: 6 },
boundaryPending: false,
currentOwner: { dataOwnerId: 'owner-a', ownerGeneration: 7 },
send: out.send,
})).toBe(false);
expect(out.sent).toEqual([]);
});

it('after a reconnect only the new Host generation passes', () => {
const out = send();
const next = { dataOwnerId: 'owner-a', ownerGeneration: 8 };
expect(forwardScheduleEvent({ event: {}, ownerStamp: { dataOwnerId: 'owner-a', ownerGeneration: 7 },
boundaryPending: false, currentOwner: next, send: out.send })).toBe(false);
expect(forwardScheduleEvent({ event: { type: 'read' }, ownerStamp: { dataOwnerId: 'owner-a', ownerGeneration: 8 },
boundaryPending: false, currentOwner: next, send: out.send })).toBe(true);
});

it('drops everything while an account switch is pending', () => {
const out = send();
expect(forwardScheduleEvent({ event: {}, ownerStamp: { dataOwnerId: 'owner-a', ownerGeneration: 7 },
boundaryPending: true, currentOwner: { dataOwnerId: 'owner-a', ownerGeneration: 7 }, send: out.send })).toBe(false);
expect(out.sent).toEqual([]);
});
});

describe('pushBelongsToOwner', () => {
const current = { dataOwnerId: 'owner-a', ownerGeneration: 4 };

it('accepts only a well-formed stamp for the account the window shows', () => {
expect(pushBelongsToOwner({ dataOwnerId: 'owner-a', ownerGeneration: 4 }, current)).toBe(true);
expect(pushBelongsToOwner({ dataOwnerId: 'owner-b', ownerGeneration: 4 }, current)).toBe(false);
expect(pushBelongsToOwner({ dataOwnerId: 'owner-a', ownerGeneration: 3 }, current)).toBe(false);
});

it('rejects a missing or malformed stamp instead of guessing an owner', () => {
expect(pushBelongsToOwner(undefined, current)).toBe(false);
expect(pushBelongsToOwner(null, current)).toBe(false);
expect(pushBelongsToOwner({ dataOwnerId: 'owner-a' }, current)).toBe(false);
expect(pushBelongsToOwner({ dataOwnerId: 'owner-a', ownerGeneration: '4' }, current)).toBe(false);
expect(pushBelongsToOwner('owner-a', current)).toBe(false);
});
});

// Preserve the desktop settings sender gate even when the authoritative browser
// runtime lives in Host. A later local registration must not shadow the proxy.
it('delegates browser settings only from the trusted renderer and keeps Host authoritative', async () => {
Expand Down
Loading