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。

完善测试门禁锁跨平台覆盖

DavidShen65459227d7fc
diff --git a/packages/maker-core/src/agents/claude-code/__tests__/subagent-definitions.test.ts b/packages/maker-core/src/agents/claude-code/__tests__/subagent-definitions.test.ts
index 021410c580..0224098ef2 100644
--- a/packages/maker-core/src/agents/claude-code/__tests__/subagent-definitions.test.ts
+++ b/packages/maker-core/src/agents/claude-code/__tests__/subagent-definitions.test.ts
@@ -272,10 +272,26 @@ describe('discoverSubagentDefinitions', () => {
it('悬空软链跳过,不影响同目录其它定义', async () => {
const agents = path.join(root, 'repo', '.claude', 'agents');
await writeAgent(agents, 'ok.md', 'name: ok\nmodel: opus');
+ if (process.platform === 'win32') {
+ // 未开启 Developer Mode 时不能可靠创建文件软链,而 junction 对悬空目标的要求也因
+ // Windows / Node 版本而异。直接覆盖生产代码使用的 follow-stat 失败分支。
+ const link = path.join(agents, 'dead.md');
+ const kind = await classifySubagentEntry(symbolicLinkDirent, link, async () => {
+ throw Object.assign(new Error('missing target'), { code: 'ENOENT' });
+ });
+ expect(kind).toBeUndefined();
+
+ const found = await discoverSubagentDefinitions({
+ workingDir: path.join(root, 'repo'),
+ env: { CLAUDE_CONFIG_DIR: path.join(root, 'empty-home') },
+ });
+ expect(found.map((f) => f.name)).toEqual(['ok']);
+ return;
+ }
+
await fs.symlink(
path.join(root, 'gone', 'nothing.md'),
path.join(agents, 'dead.md'),
- directoryLinkType,
);
const found = await discoverSubagentDefinitions({
diff --git a/scripts/__tests__/test-workspaces.test.mjs b/scripts/__tests__/test-workspaces.test.mjs
index 15fce6c733..6506493c41 100644
--- a/scripts/__tests__/test-workspaces.test.mjs
+++ b/scripts/__tests__/test-workspaces.test.mjs
@@ -915,6 +915,76 @@ test("test gate lock reports the holder, waits, and acquires after release", asy
}
});
+test("two real test gate lock holders serialize on the same identity", async () => {
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), "test-gate-real-lock-"));
+ let firstLock;
+ let secondLock;
+ let reportWaiting;
+ const waiting = new Promise((resolve) => {
+ reportWaiting = resolve;
+ });
+ try {
+ firstLock = await acquireTestGateLock({
+ repoRoot: root,
+ owner: { pid: 41, tier: "unit", cwd: path.join(root, "first") },
+ output: () => {},
+ });
+ const secondLockPromise = acquireTestGateLock({
+ repoRoot: root,
+ owner: { pid: 42, tier: "db", cwd: path.join(root, "second") },
+ timeoutMs: 2_000,
+ retryDelayMs: 10,
+ output: reportWaiting,
+ }).then((lock) => {
+ secondLock = lock;
+ return lock;
+ });
+ const outcome = await Promise.race([
+ waiting.then(() => "waiting"),
+ secondLockPromise.then(() => "acquired"),
+ new Promise((resolve) => setTimeout(() => resolve("timed-out"), 1_000)),
+ ]);
+ assert.equal(outcome, "waiting");
+
+ await firstLock.release();
+ firstLock = undefined;
+ await secondLockPromise;
+ assert.ok(secondLock.port >= 49_152);
+ } finally {
+ await secondLock?.release();
+ await firstLock?.release();
+ fs.rmSync(root, { recursive: true, force: true });
+ }
+});
+
+test("test gate lock skips ports denied at bind time", async () => {
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), "test-gate-bind-denied-"));
+ const attemptedPorts = [];
+ try {
+ const lock = await acquireTestGateLock({
+ repoRoot: root,
+ owner: { pid: 99, tier: "unit", cwd: root },
+ probeCandidatesImpl: async (ports) =>
+ ports.map((port) => ({ port, result: "available" })),
+ listenImpl: async (port) => {
+ attemptedPorts.push(port);
+ if (attemptedPorts.length === 1) {
+ throw Object.assign(new Error("bind denied"), { code: "EACCES" });
+ }
+ return { port, release: async () => {} };
+ },
+ output: () => {},
+ });
+
+ assert.equal(attemptedPorts.length, 2);
+ assert.notEqual(attemptedPorts[0], attemptedPorts[1]);
+ assert.equal(lock.port, attemptedPorts[1]);
+ await lock.release();
+ } finally {
+ fs.rmSync(root, { recursive: true, force: true });
+ }
+});
+
test("test gate lock timeout uses a distinct temporary-failure exit code", async () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "test-gate-timeout-"));
let now = 0;
diff --git a/scripts/test-gate-lock.mjs b/scripts/test-gate-lock.mjs
index d83e8f85ac..b60b763d5d 100644
--- a/scripts/test-gate-lock.mjs
+++ b/scripts/test-gate-lock.mjs
@@ -12,6 +12,7 @@ const PROBE_TIMEOUT_MS = 1_000;
const RETRY_DELAY_MS = 500;
const WAIT_REPORT_INTERVAL_MS = 60_000;
const HEAVY_TEST_TIERS = new Set(["unit", "db", "git-integration"]);
+const BIND_DENIED_ERROR_CODES = new Set(["EACCES", "EPERM"]);
export const TEST_GATE_LOCK_TIMEOUT_EXIT_CODE = 75;
export const DEFAULT_TEST_GATE_LOCK_TIMEOUT_MS = 15 * 60_000;
@@ -245,9 +246,14 @@ export async function acquireTestGateLock({
});
const startedAt = now();
let lastReportAt = Number.NEGATIVE_INFINITY;
+ const bindDeniedPorts = new Set();
while (true) {
- const probes = await probeCandidatesImpl(ports, identity);
+ const probes = (await probeCandidatesImpl(ports, identity)).map((probe) =>
+ bindDeniedPorts.has(probe.port)
+ ? { port: probe.port, result: "collision" }
+ : probe,
+ );
const decision = decideTestGateLock(probes);
if (decision.type === "unavailable") {
throw new Error(
@@ -258,6 +264,10 @@ export async function acquireTestGateLock({
try {
return await listenImpl(decision.port, banner);
} catch (error) {
+ if (BIND_DENIED_ERROR_CODES.has(error?.code)) {
+ bindDeniedPorts.add(decision.port);
+ continue;
+ }
if (error?.code !== "EADDRINUSE") throw error;
const waitedMs = now() - startedAt;
if (waitedMs >= timeoutMs) throw createTimeoutError(waitedMs);