fix(desktop): 修正 #329 后过时的 3 条单测断言,恢复单测门禁全绿

- deviceLinkInteractionScenarios:Maker Memory 守卫断言先折叠空白再匹配
  token 序列(#329 中 prettier 把该三元折成三行,语义未变);
  RESOLVE_INTERACTION 接线断言的截取窗口从固定字符数改为语法边界
  (下一个 ipcMain.handle / helper 列首闭括号),handler 随入参校验
  增重时不再误报。
- makerChatStoreTextDeltaBatching:setup 步数断言对齐实际契约——
  GHOST_SETUP_MAX_STEPS(64,manifest 上限)接受、
  GHOST_SETUP_MAX_INTERACTION_STEPS(72,含 Host 保留的传输上限)接受、
  73 拒。原「65 拒」与同一提交实现的 72 传输上限自相矛盾;manifest 64
  上限由 manifest 校验层(8 组 × 8 条)结构性保证,renderer 只守传输上限。

实现侧零改动:resolvePendingInteraction / dismissRendererInteraction 在
#329 前后逐字节相同,makerMemoryEnabled 守卫仅被格式化折行,均经独立
对抗性 review 核实(无 P0/P1)。

验证(win32):根 pnpm test:unit 全绿(0 失败 workspace);desktop
typecheck 通过。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Lizi
2026-07-25 16:23:49 +08:00
parent 9916cbf3a7
commit 5c1a81cdcd
2 changed files with 42 additions and 15 deletions

View File

@@ -660,7 +660,8 @@ describe('远程交互接线不变式', () => {
const src = read('lib/makerChatStore.ts');
expect(src).toContain('const deviceLinkRemote = isRemoteSession(sessionId);');
expect(src).toContain('const sshRemote = Boolean(current.remoteHostId);');
expect(src).toContain(
// 该三元可能被 prettier 折成多行:先把空白折叠成单空格,只锁 token 序列。
expect(src.replace(/\s+/g, ' ')).toContain(
'...(deviceLinkRemote ? {} : { makerMemoryEnabled: sshRemote ? false : getMakerMemoryEnabled() })',
);
});
@@ -1006,13 +1007,19 @@ describe('远程交互接线不变式', () => {
it('main RESOLVE_INTERACTION handler 解决后广播 dismissed(dismissRendererInteraction)', () => {
const src = readFileSync(resolve(__dirname, '../../main/maker-ipc/register.ts'), 'utf8');
// handler 可以只委托 helper,但 helper 必须负责 resolved 广播和权威落库。
// 截取窗口用下一个语法边界而非固定字符数:handler/helper 体量会随入参校验、
// 注释增长,固定窗口会在无行为回归时误报(#329 曾把调用挤出 1000 字符窗口)。
const handlerStart = src.indexOf('ipcMain.handle(MAKER_INVOKE.RESOLVE_INTERACTION');
expect(handlerStart).toBeGreaterThan(-1);
const handlerBody = src.slice(handlerStart, handlerStart + 1000);
const handlerEnd = src.indexOf('ipcMain.handle(', handlerStart + 1);
const handlerBody = src.slice(handlerStart, handlerEnd === -1 ? undefined : handlerEnd);
expect(handlerBody).toContain('resolvePendingInteraction(');
const helperStart = src.indexOf('function resolvePendingInteraction');
expect(helperStart).toBeGreaterThan(-1);
const body = src.slice(helperStart, helperStart + 1800);
// 顶层函数体内嵌套块都有缩进,列首 '\n}' 即 helper 自己的闭括号。
const helperEnd = src.indexOf('\n}', helperStart);
expect(helperEnd).toBeGreaterThan(-1);
const body = src.slice(helperStart, helperEnd);
expect(body).toContain('resolver.resolve(');
expect(body).toContain('dismissRendererInteraction(');
// F1:resolve 后被控端权威落库 ask/plan answered 状态。

View File

@@ -6,6 +6,10 @@
*/
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import {
GHOST_SETUP_MAX_INTERACTION_STEPS,
GHOST_SETUP_MAX_STEPS,
} from '../../shared/ghost';
import type { AgentInputProjection, AgentInputQueuedMessage } from '../../shared/agentInputQueue';
import type { Message } from '@/lib/ccAgent.types';
import type { AttachedFile, MentionedResource } from '@/lib/fileTypes';
@@ -827,27 +831,43 @@ describe('makerChatStore text delta batching', () => {
expect(makerChatStore.getSnapshot(SESSION_ID).pendingPluginSetup).toBeNull();
});
it('accepts all 64 manifest-valid setup steps and rejects a 65th', () => {
it('accepts manifest-max and host-reserve step counts, rejects past the transport cap', () => {
const step = pluginSetupRequest(1).steps[0];
emitInteractionRequest({
...pluginSetupRequest(1),
steps: Array.from({ length: 64 }, (_, index) => ({
const buildSteps = (count: number) =>
Array.from({ length: count }, (_, index) => ({
...step,
id: `setup-${index}`,
action: { ...step.action, id: `oauth:${index}` },
})),
});
expect(makerChatStore.getSnapshot(SESSION_ID).pendingPluginSetup?.steps).toHaveLength(64);
}));
// manifest 合法声明的步数上限(8 组 × 8 条)。
emitInteractionRequest({
...pluginSetupRequest(1),
steps: buildSteps(GHOST_SETUP_MAX_STEPS),
});
expect(makerChatStore.getSnapshot(SESSION_ID).pendingPluginSetup?.steps).toHaveLength(
GHOST_SETUP_MAX_STEPS,
);
// Host-owned setup provider 可在 manifest 步骤之外追加 Core 步骤,
// Main → Renderer 的传输上限是 GHOST_SETUP_MAX_INTERACTION_STEPS
// (= manifest 上限 + Host 保留),打满仍须完整过界。
makerChatStore.purgeSession(SESSION_ID);
emitInteractionRequest({
...pluginSetupRequest(1),
requestId: 'plugin-setup-transport-cap',
steps: buildSteps(GHOST_SETUP_MAX_INTERACTION_STEPS),
});
expect(makerChatStore.getSnapshot(SESSION_ID).pendingPluginSetup?.steps).toHaveLength(
GHOST_SETUP_MAX_INTERACTION_STEPS,
);
// 超过传输上限:整卡拒收。
makerChatStore.purgeSession(SESSION_ID);
emitInteractionRequest({
...pluginSetupRequest(1),
requestId: 'plugin-setup-oversized',
steps: Array.from({ length: 65 }, (_, index) => ({
...step,
id: `setup-${index}`,
action: { ...step.action, id: `oauth:${index}` },
})),
steps: buildSteps(GHOST_SETUP_MAX_INTERACTION_STEPS + 1),
});
expect(makerChatStore.getSnapshot(SESSION_ID).pendingPluginSetup).toBeNull();
});