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。

test: stabilize local gate fixtures

xuzini-xznf1fe98ca3296
diff --git a/apps/desktop/scripts/fixtures/subscription-fast/ui-page.mjs b/apps/desktop/scripts/fixtures/subscription-fast/ui-page.mjs
index 8867271fa9..e620c66d1b 100644
--- a/apps/desktop/scripts/fixtures/subscription-fast/ui-page.mjs
+++ b/apps/desktop/scripts/fixtures/subscription-fast/ui-page.mjs
@@ -53,7 +53,8 @@ export default {
{ name: await ui.t('subscriptionFastPolicy.label'), index, before },
);
const box = await control.boundingBox();
- assert.ok(box && box.x >= 0 && box.x + box.width <= page.viewportSize().width);
+ // Electron windows use the harness viewport; Playwright viewportSize() is null.
+ assert.ok(box && box.x >= 0 && box.x + box.width <= ui.viewport.width);
}
if (ui.case === 'pending' || ui.case === 'narrow')
await page.getByText(await ui.t('subscriptionFastPolicy.pending'), { exact: true }).waitFor();
diff --git a/apps/desktop/src/main/input-handoff/askpass/__tests__/askpass.native.test.ts b/apps/desktop/src/main/input-handoff/askpass/__tests__/askpass.native.test.ts
index 06b819a282..e585e86200 100644
--- a/apps/desktop/src/main/input-handoff/askpass/__tests__/askpass.native.test.ts
+++ b/apps/desktop/src/main/input-handoff/askpass/__tests__/askpass.native.test.ts
@@ -1,4 +1,7 @@
import { execFile } from 'node:child_process';
+import { constants } from 'node:fs';
+import { access, realpath } from 'node:fs/promises';
+import path from 'node:path';
import http from 'node:http';
import type { AddressInfo } from 'node:net';
import { afterEach, describe, expect, it } from 'vitest';
@@ -27,6 +30,22 @@ function run(file: string, args: string[], env: NodeJS.ProcessEnv): Promise<{ co
});
}
+// Apple Git resolves its transport helpers relative to argv[0]. A PATH symlink
+// outside the install tree otherwise fails before contacting the synthetic server.
+// Keep the same POSIX PATH selection, resolving only that executable's symlinks.
+async function nativeGitPath(): Promise<string> {
+ for (const directory of (process.env.PATH ?? '').split(path.delimiter)) {
+ const candidate = path.resolve(directory || '.', 'git');
+ try {
+ await access(candidate, constants.X_OK);
+ return await realpath(candidate);
+ } catch {
+ // Match executable lookup: an absent or inaccessible PATH entry is skipped.
+ }
+ }
+ throw new Error('git executable was not found on PATH');
+}
+
async function setup(answers: Record<string, string>) {
const prompts: TerminalPromptRequest[] = [];
const host = new AskpassHost({
@@ -58,7 +77,7 @@ describe.runIf(runnable)('代输入 askpass with real programs', () => {
const { port } = server.address() as AddressInfo;
const { prompts, env } = await setup({ Username: 'someone', Password: 'synthetic-pass' });
- const result = await run('git', ['-c', 'credential.helper=', 'ls-remote', `http://127.0.0.1:${port}/r.git`], {
+ const result = await run(await nativeGitPath(), ['-c', 'credential.helper=', 'ls-remote', `http://127.0.0.1:${port}/r.git`], {
PATH: process.env.PATH,
HOME: process.env.HOME,
GIT_CONFIG_NOSYSTEM: '1',
diff --git a/apps/desktop/src/main/voice-input/__tests__/MacModifierShortcutListenerStartRace.test.ts b/apps/desktop/src/main/voice-input/__tests__/MacModifierShortcutListenerStartRace.test.ts
index b876152c61..3b595aa93a 100644
--- a/apps/desktop/src/main/voice-input/__tests__/MacModifierShortcutListenerStartRace.test.ts
+++ b/apps/desktop/src/main/voice-input/__tests__/MacModifierShortcutListenerStartRace.test.ts
@@ -1,4 +1,5 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { MacModifierShortcutListener } from '../MacModifierShortcutListener.js';
/**
* 守住 helper 子进程不泄漏。
@@ -7,6 +8,11 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
* (swiftc,可能几秒)。那段时间 `child` 还是 null,所以 stop 光看 `child` 拦不住一个
* 正在飞的启动,重叠的启动之间也会互相覆盖 `child` 引用。漏掉的进程不是空转——它持有
* 全局 event tap,会一直监听键盘。
+ *
+ * Gate regression: the overlapping-start fixture left its winning start pending; its
+ * 1500 ms startup timeout could call the shared kill mock during a later test. Exercise
+ * the real start/ready/stop lifecycle and advance only the fake timeout clock (unit tier).
+ * State belongs to each listener instance, so the production module is loaded once.
*/
const mocks = vi.hoisted(() => {
@@ -78,7 +84,6 @@ function flush(): Promise<void> {
describe('MacModifierShortcutListener start race', () => {
beforeEach(() => {
- vi.resetModules();
mocks.pendingCompilations.length = 0;
mocks.execFile.mockClear();
mocks.spawn.mockClear();
@@ -92,7 +97,6 @@ describe('MacModifierShortcutListener start race', () => {
});
it('does not spawn a helper when the start is stopped while the dev helper is still compiling', async () => {
- const { MacModifierShortcutListener } = await import('../MacModifierShortcutListener.js');
const listener = new MacModifierShortcutListener({ onTrigger: vi.fn() });
const starting = listener.startKeyCapture();
@@ -112,25 +116,40 @@ describe('MacModifierShortcutListener start race', () => {
});
it('only spawns for the latest start when two starts overlap', async () => {
- const { MacModifierShortcutListener } = await import('../MacModifierShortcutListener.js');
const listener = new MacModifierShortcutListener({ onTrigger: vi.fn() });
-
- const first = listener.startKeyCapture();
- await flush();
- const second = listener.startKeyCapture();
- await flush();
- expect(mocks.pendingCompilations).toHaveLength(2);
-
- // 先让第一轮回来:它已被第二轮顶掉,不该 spawn。
- mocks.pendingCompilations[0]();
- await expect(first).resolves.toMatchObject({ ok: false });
- expect(mocks.spawn).not.toHaveBeenCalled();
-
- // 第二轮才是有效的那次。
- mocks.pendingCompilations[1]();
- await flush();
- expect(mocks.spawn).toHaveBeenCalledTimes(1);
- void second;
+ // Keep setImmediate real so flush() still drains compilation/spawn microtasks.
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
+ try {
+ const first = listener.startKeyCapture();
+ await flush();
+ const second = listener.startKeyCapture();
+ await flush();
+ expect(mocks.pendingCompilations).toHaveLength(2);
+
+ // 先让第一轮回来:它已被第二轮顶掉,不该 spawn。
+ mocks.pendingCompilations[0]();
+ await expect(first).resolves.toMatchObject({ ok: false });
+ expect(mocks.spawn).not.toHaveBeenCalled();
+
+ // 第二轮才是有效的那次。
+ mocks.pendingCompilations[1]();
+ await flush();
+ expect(mocks.spawn).toHaveBeenCalledTimes(1);
+ mocks.stdoutDataHandlers[0]?.('{"type":"ready"}\n');
+ await expect(second).resolves.toMatchObject({ ok: true });
+
+ // A leaked startup timer used to call the shared kill mock in a later case.
+ vi.advanceTimersByTime(1_500);
+ expect(mocks.kill).not.toHaveBeenCalled();
+ } finally {
+ try {
+ listener.stop();
+ mocks.spawnedChildren[0]?.get('exit')?.(null, 'SIGTERM');
+ expect(vi.getTimerCount()).toBe(0);
+ } finally {
+ vi.useRealTimers();
+ }
+ }
});
/**
@@ -140,7 +159,6 @@ describe('MacModifierShortcutListener start race', () => {
* 连续两轮共用一个 id)——新 helper 在跑,用户按 Fn 却没反应。
*/
it('reports a superseded start when the spawned helper is killed by stop before it reports ready', async () => {
- const { MacModifierShortcutListener } = await import('../MacModifierShortcutListener.js');
const listener = new MacModifierShortcutListener({ onTrigger: vi.fn() });
const starting = listener.startKeyCapture();
@@ -167,7 +185,6 @@ describe('MacModifierShortcutListener start race', () => {
* 而 helper 其实已经没了 —— 用户按 Fn 毫无反应,只能关掉录制框重开。
*/
it('reports a superseded start when a killed helper reports ready late', async () => {
- const { MacModifierShortcutListener } = await import('../MacModifierShortcutListener.js');
const listener = new MacModifierShortcutListener({ onTrigger: vi.fn() });
const starting = listener.startKeyCapture();
@@ -195,7 +212,6 @@ describe('MacModifierShortcutListener start race', () => {
* 不会 scheduleRestart)→ 快捷键写着「已注册」,实际没人监听,要等下次窗口聚焦才被救回来。
*/
it('does not accept a spawned-but-not-ready capture child as a working listener', async () => {
- const { MacModifierShortcutListener } = await import('../MacModifierShortcutListener.js');
const listener = new MacModifierShortcutListener({ onTrigger: vi.fn() });
// A 窗口的 capture:进程起来了,但还没报 ready。
@@ -227,7 +243,6 @@ describe('MacModifierShortcutListener start race', () => {
// 别把上面那条修成「有 child 就一律失败」:那次启动报了 ready 之后,复用方必须拿到成功。
it('accepts the preserved capture child once the in-flight start reports ready', async () => {
- const { MacModifierShortcutListener } = await import('../MacModifierShortcutListener.js');
const listener = new MacModifierShortcutListener({ onTrigger: vi.fn() });
const capture = listener.startKeyCapture();
@@ -249,12 +264,13 @@ describe('MacModifierShortcutListener start race', () => {
await expect(capture).resolves.toMatchObject({ ok: true });
// 复用没有再 spawn 一个 helper。
expect(mocks.spawn).toHaveBeenCalledTimes(1);
+ listener.stop();
+ mocks.spawnedChildren[0].get('exit')?.(null, 'SIGTERM');
});
// 同一个漏洞的另一半:解析 helper 抛异常(dev 下 swiftc 失败)时压根没查代次,
// 已被作废的启动会把编译错误当成这次操作的故障报出去。
it('reports a superseded start when the dev helper compilation fails after the start was stopped', async () => {
- const { MacModifierShortcutListener } = await import('../MacModifierShortcutListener.js');
const listener = new MacModifierShortcutListener({ onTrigger: vi.fn() });
const starting = listener.startKeyCapture();
@@ -268,7 +284,6 @@ describe('MacModifierShortcutListener start race', () => {
});
it('maps bare function-key snapshots to start/tap and releases an active press on helper exit', async () => {
- const { MacModifierShortcutListener } = await import('../MacModifierShortcutListener.js');
const onTrigger = vi.fn();
const listener = new MacModifierShortcutListener({ onTrigger });
const shortcut = {
@@ -311,7 +326,6 @@ describe('MacModifierShortcutListener start race', () => {
});
it('ends a held function key once and replaces the helper on a system release', async () => {
- const { MacModifierShortcutListener } = await import('../MacModifierShortcutListener.js');
const onTrigger = vi.fn();
const listener = new MacModifierShortcutListener({ onTrigger });
const shortcut = {
diff --git a/scripts/__tests__/check-test-hygiene.test.mjs b/scripts/__tests__/check-test-hygiene.test.mjs
index f764a80974..6c62244b6a 100644
--- a/scripts/__tests__/check-test-hygiene.test.mjs
+++ b/scripts/__tests__/check-test-hygiene.test.mjs
@@ -429,7 +429,10 @@ test("compareWithBaseline only lets counts stay or shrink", () => {
// Exercise the real CLI in its own Git repository. A same-PR JSON edit must
// not become trusted merely because it was committed or --update was used.
- const root = fs.mkdtempSync(path.join(os.tmpdir(), "cindy-hygiene-ratchet-"));
+ // Node resolves ESM entry points through symlinks; macOS os.tmpdir() may use
+ // /var while import.meta.url uses /private/var. Match the real CLI path so
+ // its main guard runs rather than silently exiting before creating a baseline.
+ const root = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), "cindy-hygiene-ratchet-")));
const baselinePath = path.join(root, "scripts", "test-hygiene-baseline.json");
const testPath = path.join(root, "apps", "sample", "sample.test.ts");
const relativeTestPath = "apps/sample/sample.test.ts";
@@ -457,6 +460,9 @@ test("compareWithBaseline only lets counts stay or shrink", () => {
git("update-ref", "refs/remotes/origin/main", firstIntroduction);
const bootstrap = cli(["--update"]);
assert.equal(bootstrap.status, 0, output(bootstrap));
+ assert.match(output(bootstrap), /baseline updated: 1 files/);
+ assert.deepEqual(JSON.parse(fs.readFileSync(baselinePath, "utf8")).files,
+ { [relativeTestPath]: { sourceReads: 1 } });
assert.equal(cli().status, 0);
const trusted = commit();
git("update-ref", "refs/remotes/origin/main", trusted);
diff --git a/scripts/__tests__/test-workspaces.test.mjs b/scripts/__tests__/test-workspaces.test.mjs
index 116bb17b1c..284acb2dae 100644
--- a/scripts/__tests__/test-workspaces.test.mjs
+++ b/scripts/__tests__/test-workspaces.test.mjs
@@ -1,5 +1,6 @@
import assert from "node:assert/strict";
import fs from "node:fs";
+import net from "node:net";
import os from "node:os";
import path from "node:path";
import { spawn } from "node:child_process";
@@ -1282,7 +1283,7 @@ function raceWithDeadline(candidates, deadlineMs, deadlineValue) {
});
}
-test("two real test gate lock holders serialize on the same identity", async () => {
+test("two real test gate lock holders serialize after a probe resets its connection", async () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "test-gate-real-lock-"));
let firstLock;
let secondLockPromise;
@@ -1299,6 +1300,16 @@ test("two real test gate lock holders serialize on the same identity", async ()
lockPortStride: REAL_LOCK_TEST_PORT_STRIDE,
output: () => {},
});
+ // Regression: an early-disconnecting probe emitted an unhandled ECONNRESET
+ // on the holder's accepted socket, terminating the gate before tests finished.
+ // Existing serialization coverage only exercised graceful probes. One real
+ // loopback RST now verifies the public lock entry stays available (runner tier).
+ await new Promise((resolve, reject) => {
+ const probe = net.createConnection({ host: "127.0.0.1", port: firstLock.port });
+ probe.once("error", reject);
+ probe.once("connect", () => probe.resetAndDestroy());
+ probe.once("close", resolve);
+ });
secondLockPromise = acquireTestGateLock({
repoRoot: root,
owner: { pid: 42, tier: "db", cwd: path.join(root, "second") },
diff --git a/scripts/test-gate-lock.mjs b/scripts/test-gate-lock.mjs
index 2300a92585..d288db133e 100644
--- a/scripts/test-gate-lock.mjs
+++ b/scripts/test-gate-lock.mjs
@@ -192,6 +192,9 @@ function close(server) {
async function listenForLock(port, banner) {
const server = net.createServer((socket) => {
+ // Probes can reset as soon as they recognize the banner. Their socket
+ // failure must not terminate the lock holder or release its test budget.
+ socket.on("error", () => socket.destroy());
socket.end(`${banner}\n`);
});
await listen(server, port);
diff --git a/scripts/test-hygiene-baseline.json b/scripts/test-hygiene-baseline.json
index da081002d5..27648e10fe 100644
--- a/scripts/test-hygiene-baseline.json
+++ b/scripts/test-hygiene-baseline.json
@@ -460,9 +460,6 @@
"apps/desktop/src/main/voice-input/__tests__/globalShortcut.test.ts": {
"resetModules": 1
},
- "apps/desktop/src/main/voice-input/__tests__/MacModifierShortcutListenerStartRace.test.ts": {
- "resetModules": 1
- },
"apps/desktop/src/main/voice-input/__tests__/RealtimeAsrWebSocketProvider.test.ts": {
"realWaits": 3
},