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。

fix(test-runner): skip git-ignored tmp/ and tolerate unreadable dirs (#3373)

Junshanfd03cf14a434
diff --git a/scripts/__tests__/test-workspaces.test.mjs b/scripts/__tests__/test-workspaces.test.mjs
index 679a602068..51675363ef 100644
--- a/scripts/__tests__/test-workspaces.test.mjs
+++ b/scripts/__tests__/test-workspaces.test.mjs
@@ -31,6 +31,7 @@ import {
discoverTestFiles,
expandWorkspacePatterns,
filterRunsByWorkspace,
+ isIgnoredFile,
mapWithConcurrency,
normalizeRelPath,
parseWorkspacePatterns,
@@ -291,6 +292,41 @@ test("discoverTestFiles ignores generated and nested non-workspace directories",
]);
});
+test("isIgnoredFile ignores the git-ignored tmp/ product directory", () => {
+ // .gitignore 忽略 tmp/(会话工具临时产物)。readAllFiles 若递归进去,
+ // 遇到沙箱/工具遗留的不可读子目录会 EPERM 让整个门禁失败(#3353)。
+ assert.equal(isIgnoredFile("tmp/blocked"), true);
+ assert.equal(isIgnoredFile("tmp/nested/deep/file.ts"), true);
+ assert.equal(isIgnoredFile("packages/orca-workflow/tmp/x.test.ts"), true);
+ // 含 "tmp" 的合法包名/文件名不应被误杀(按路径段精确匹配)。
+ assert.equal(isIgnoredFile("packages/tmp-adapter/src/index.ts"), false);
+});
+
+test("readAllFiles tolerates an unreadable directory instead of crashing the gate", () => {
+ // 平台不支持把目录 chmod 成不可读时(Windows)跳过:EPERM 容错分支在
+ // POSIX 上由 chmod 0o000 覆盖,逻辑本身是平台无关的 try/catch。
+ if (process.platform === "win32") return;
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), "read-all-files-"));
+ try {
+ fs.mkdirSync(path.join(root, "src"), { recursive: true });
+ fs.writeFileSync(path.join(root, "src", "a.test.ts"), "// ok\n");
+ // 一个当前进程无权 scandir 的目录(模拟沙箱遗留物)。
+ const locked = path.join(root, "tmp", "locked");
+ fs.mkdirSync(locked, { recursive: true });
+ fs.writeFileSync(path.join(locked, "secret.txt"), "x");
+ fs.chmodSync(path.join(root, "tmp", "locked"), 0o000);
+ try {
+ const files = readAllFiles(root);
+ assert.deepEqual(files.map(normalizeRelPath).sort(), ["src/a.test.ts"]);
+ } finally {
+ // 必须先恢复权限才能在 Windows/POSIX 清理临时目录。
+ fs.chmodSync(path.join(root, "tmp", "locked"), 0o700);
+ }
+ } finally {
+ fs.rmSync(root, { recursive: true, force: true });
+ }
+});
+
test("checkTestFiles fails runnable tiers with no selected tests", () => {
const workspace = { cwd: "packages/orca-workflow", status: "required" };
const tier = { status: "required", include: ["src/__tests__/**/*.test.ts"] };
diff --git a/scripts/test-workspaces.mjs b/scripts/test-workspaces.mjs
index 8005879c23..ac5f752b5a 100644
--- a/scripts/test-workspaces.mjs
+++ b/scripts/test-workspaces.mjs
@@ -20,6 +20,9 @@ const IGNORED_PARTS = new Set([
"coverage",
".git",
".cache",
+ // 会话工具临时产物(.gitignore 明确忽略 tmp/)。不忽略的话 readAllFiles
+ // 会递归进去,遇到沙箱/工具遗留的不可读子目录抛 EPERM 让整个门禁失败(#3353)。
+ "tmp",
]);
const NESTED_NON_WORKSPACES = ["apps/desktop/cindy-updater", "tools"];
const VALID_STATUSES = new Set([
@@ -757,7 +760,19 @@ export function createWorkspaceRunReporter({
export function readAllFiles(root) {
const files = [];
function visit(absDir) {
- for (const entry of fs.readdirSync(absDir, { withFileTypes: true })) {
+ let entries;
+ try {
+ entries = fs.readdirSync(absDir, { withFileTypes: true });
+ } catch (error) {
+ // 不可读目录(沙箱/本地工具遗留的受限临时目录在 Windows 上抛 EPERM,
+ // 见 #3353)不应让整个测试门禁在收集阶段失败:忽略该子树,继续扫描
+ // 其余可读目录。已跟踪文件与未被忽略的源码不会落在这种目录里。
+ if (error && (error.code === "EPERM" || error.code === "EACCES" || error.code === "ENOENT")) {
+ return;
+ }
+ throw error;
+ }
+ for (const entry of entries) {
const abs = path.join(absDir, entry.name);
const rel = normalizeRelPath(path.relative(root, abs));
if (isIgnoredFile(rel)) continue;