Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

perf(test): trim ambient types from direct send guard

MagicLizi49daa510b0dd
diff --git a/apps/desktop/src/main/__tests__/directSessionSendGuard.test.ts b/apps/desktop/src/main/__tests__/directSessionSendGuard.test.ts
index 2d06d6c350..e71d1a2d09 100644
--- a/apps/desktop/src/main/__tests__/directSessionSendGuard.test.ts
+++ b/apps/desktop/src/main/__tests__/directSessionSendGuard.test.ts
@@ -38,8 +38,10 @@ describe('direct Session.send guard', () => {
import { assertSendDispatched, toSessionDispatchOutcome } from '@cindy/maker-core';
declare const session: Session;
+ type SessionAlias = Session;
+ const alias: SessionAlias = session;
declare const webContents: { send(channel: string, payload?: unknown): void };
- declare const socket: { send(data: string): void };
+ declare const socket: { send(data: string): void; sendHostTurnContinuation(data: string): void };
declare function observeFireAndForgetSendOutcome(
promise: ReturnType<Session['send']>,
meta: { owner: string; entrypoint: string; action: string; context: string },
@@ -49,6 +51,14 @@ describe('direct Session.send guard', () => {
await session.send({ type: 'user', content: 'hello' });
}
+ async function aliasedSessionSend() {
+ await alias.send({ type: 'user', content: 'hello' });
+ }
+
+ async function ignoredHostContinuation() {
+ await alias.sendHostTurnContinuation({ type: 'user', content: 'continue' });
+ }
+
async function awaitedNotConsumed() {
const result = await session.send({ type: 'user', content: 'hello' });
return result;
@@ -75,6 +85,11 @@ describe('direct Session.send guard', () => {
assertSendDispatched(result, 'fixture/assert');
}
+ async function allowedHostContinuation() {
+ const result = await alias.sendHostTurnContinuation({ type: 'user', content: 'continue' });
+ assertSendDispatched(result, 'fixture/continuation');
+ }
+
async function allowedConvert() {
const result = await session.send({ type: 'user', content: 'hello' });
return toSessionDispatchOutcome(result, 'fixture/convert');
@@ -92,6 +107,7 @@ describe('direct Session.send guard', () => {
function ignoredNonMakerSends() {
webContents.send('maker:event', {});
socket.send('hello');
+ socket.sendHostTurnContinuation('hello');
}
`;
@@ -101,7 +117,9 @@ describe('direct Session.send guard', () => {
const violations = findDirectSendViolations(program);
expect(violations.map((violation) => violation.functionName).sort()).toEqual([
+ 'aliasedSessionSend',
'awaitedNotConsumed',
+ 'ignoredHostContinuation',
'nakedAwait',
'promiseAllIgnored',
'returnedDirectly',
@@ -357,6 +375,7 @@ function createProgramWithSources(
id: string;
agentKind: AgentKind;
send(message: unknown, options?: unknown): Promise<SessionSendResult>;
+ sendHostTurnContinuation(message: unknown, options?: unknown): Promise<SessionSendResult>;
}
export interface Maker {
@@ -388,6 +407,11 @@ function createProgramWithSources(
const options: ts.CompilerOptions = {
noEmit: true,
skipLibCheck: true,
+ // Only ES globals (not auto-discovered @types or DOM) participate in the
+ // fixture-backed receiver types. Keep Promise/Map inference without loading
+ // unrelated ambient packages for every runtime file in this guard.
+ types: [],
+ lib: ['lib.es2022.d.ts'],
// 这个 guard 只扫描直接忽略 Session.send outcome 的语法形态。
// strict=false + noResolve=true 是为了把全量并发下的 TS Program 限在
// 最小虚拟文件图;如果后续扩展到依赖严格空值传播的判断,必须先补
diff --git a/docs/dev-rules/desktop-unit-test-performance.md b/docs/dev-rules/desktop-unit-test-performance.md
index 2e07d79f91..e4456f4358 100644
--- a/docs/dev-rules/desktop-unit-test-performance.md
+++ b/docs/dev-rules/desktop-unit-test-performance.md
@@ -59,6 +59,12 @@ Linux 及 package script 的启动方式不变。回归测试通过真实 runner
无关的执行不能豁免它。device-link client 的四处 ≥100ms 等待改用假时钟,288 条原有
用例整份通过,约 17.2 秒;未通过新增基线或删除结果断言来放行。
+最终复跑曾在 `directSessionSendGuard` 的全运行时 TypeScript Program 检查超过原有
+15 秒限制。该 guard 现只装入 ES2022 标准库与显式 Session fixture,避免自动装入约
+80 份无关 `@types` 和 DOM 声明;2,238 个运行时根文件、类型检查器和失败关闭行为
+不变。同机 4 项测试从 7.14 秒降到 4.95 秒,原有超时未提高;别名与 continuation
+方法正反例验证仍能区分 maker Session 与其它同名 send。最终 CI 另行复验。
+
### 2026-10-16 实验与落地
本机 Windows、32 CPU、Desktop 8 worker。隔离方式三组用同一分片(869 个文件)连续对照: