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: restore cross-platform unit test invariants

Davide579fba399f0
diff --git a/apps/desktop/src/main/cindy-brain/builtinGhostProvisioner.ts b/apps/desktop/src/main/cindy-brain/builtinGhostProvisioner.ts
index ea8eea99bb..f151c13428 100644
--- a/apps/desktop/src/main/cindy-brain/builtinGhostProvisioner.ts
+++ b/apps/desktop/src/main/cindy-brain/builtinGhostProvisioner.ts
@@ -1,6 +1,7 @@
import fs from 'node:fs';
import path from 'node:path';
import crypto from 'node:crypto';
+import os from 'node:os';
import {
GHOST_MANIFEST_FILE,
@@ -178,11 +179,39 @@ function isRealDirectoryPath(absPath: string, allowMissingLeaf = false): boolean
}
return false;
}
- if (!stat.isDirectory() || stat.isSymbolicLink()) return false;
+ if (stat.isSymbolicLink()) {
+ if (!isExternalTempAncestor(current, resolved)) return false;
+ try {
+ if (!fs.statSync(current).isDirectory()) return false;
+ } catch {
+ return false;
+ }
+ continue;
+ }
+ if (!stat.isDirectory()) return false;
}
return true;
}
+/**
+ * macOS exposes the temporary directory through a system alias (`/var` →
+ * `/private/var`). That alias is outside the caller-controlled directory and
+ * is safe to traverse; links at or below the temporary root remain rejected.
+ */
+function isExternalTempAncestor(segment: string, target: string): boolean {
+ const tempRoot = path.resolve(os.tmpdir());
+ const targetRel = path.relative(tempRoot, target);
+ if (targetRel.startsWith(`..${path.sep}`) || path.isAbsolute(targetRel)) return false;
+ try {
+ const realSegment = fs.realpathSync.native(segment);
+ const realTempRoot = fs.realpathSync.native(tempRoot);
+ const tempRel = path.relative(realSegment, realTempRoot);
+ return tempRel !== '' && !tempRel.startsWith(`..${path.sep}`) && !path.isAbsolute(tempRel);
+ } catch {
+ return false;
+ }
+}
+
/** Verify that an approval source is the exact, link-free bundled seed directory for an id. */
export function isTrustedBuiltinSeedSource(
seedRootDirs: string[],
diff --git a/apps/desktop/src/main/cindy-brain/forge.ts b/apps/desktop/src/main/cindy-brain/forge.ts
index 6c6612c0e5..9aece04ba2 100644
--- a/apps/desktop/src/main/cindy-brain/forge.ts
+++ b/apps/desktop/src/main/cindy-brain/forge.ts
@@ -15,6 +15,7 @@
import fs from 'node:fs';
import path from 'node:path';
+import os from 'node:os';
import { promisify } from 'node:util';
import JSZip from 'jszip';
@@ -84,7 +85,29 @@ async function pathHasLinkSegment(inputPath: string): Promise<boolean> {
const relative = path.relative(root, resolved);
for (const segment of relative.split(path.sep).filter(Boolean)) {
current = path.join(current, segment);
- if ((await fs.promises.lstat(current)).isSymbolicLink()) return true;
+ const stat = await fs.promises.lstat(current);
+ if (!stat.isSymbolicLink()) continue;
+ // macOS exposes os.tmpdir() under `/var` while realpath resolves it to
+ // `/private/var`. This system alias is safe; links created below the temp
+ // root remain rejected by the ordinary segment check.
+ const tempRoot = path.resolve(os.tmpdir());
+ const targetRel = path.relative(tempRoot, resolved);
+ if (targetRel.startsWith(`..${path.sep}`) || path.isAbsolute(targetRel)) return true;
+ try {
+ const realSegment = await realpathNative(current);
+ const realTempRoot = await realpathNative(tempRoot);
+ const tempRel = path.relative(realSegment, realTempRoot);
+ if (
+ tempRel === '' ||
+ tempRel.startsWith(`..${path.sep}`) ||
+ path.isAbsolute(tempRel) ||
+ !(await fs.promises.stat(current)).isDirectory()
+ ) {
+ return true;
+ }
+ } catch {
+ return true;
+ }
}
return false;
}
diff --git a/packages/maker-core/src/agents/pi/__tests__/pi-rpc-resource-discovery.integration.test.ts b/packages/maker-core/src/agents/pi/__tests__/pi-rpc-resource-discovery.integration.test.ts
index 1e25e8224c..5993b648d4 100644
--- a/packages/maker-core/src/agents/pi/__tests__/pi-rpc-resource-discovery.integration.test.ts
+++ b/packages/maker-core/src/agents/pi/__tests__/pi-rpc-resource-discovery.integration.test.ts
@@ -868,7 +868,7 @@ describe.skipIf(!existsSync(PI_BINARY))('Pi v0.83.0 RPC resource discovery facts
sourceInfo: expect.objectContaining({
path: path.join(explicitSkill, 'SKILL.md'),
source: 'local',
- scope: 'project',
+ scope: 'temporary',
}),
}),
]));
@@ -932,7 +932,7 @@ describe.skipIf(!existsSync(PI_BINARY))('Pi v0.83.0 RPC resource discovery facts
baseDir: path.dirname(explicitSkill),
path: explicitSkill,
source: 'local',
- scope: 'project',
+ scope: 'temporary',
}),
}),
]));
@@ -962,7 +962,7 @@ describe.skipIf(!existsSync(PI_BINARY))('Pi v0.83.0 RPC resource discovery facts
expect(duplicates).toHaveLength(1);
expect(duplicates[0]).toMatchObject({
source: 'skill',
- sourceInfo: { baseDir: first, source: 'local', scope: 'project' },
+ sourceInfo: { baseDir: first, source: 'local', scope: 'temporary' },
});
});