Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(desktop): canonicalize main hash graph paths (#19484)

Innei92c2452d5348
diff --git a/apps/desktop/scripts/__tests__/mainHash.test.mjs b/apps/desktop/scripts/__tests__/mainHash.test.mjs
index c8bb7349074..0c98955fc87 100644
--- a/apps/desktop/scripts/__tests__/mainHash.test.mjs
+++ b/apps/desktop/scripts/__tests__/mainHash.test.mjs
@@ -141,6 +141,32 @@ describe('source main hash', () => {
}
});
+ it('canonicalizes graph paths before walking package boundaries', async () => {
+ await put('package.json', '{"private":true}');
+ const node = (id) => ({
+ configFiles: [],
+ defines: {},
+ nodes: new Map([
+ [
+ id,
+ {
+ ast: undefined,
+ dynamicImports: [],
+ entry: false,
+ external: false,
+ id,
+ imports: [],
+ retained: false,
+ },
+ ],
+ ]),
+ });
+ const canonical = await hash({ graph: [node(path.join(root, 'package.json'))] });
+ const relative = `${root}/apps/desktop/src/main/../../../../package.json`;
+
+ expect((await hash({ graph: [node(relative)] })).mainHash).toBe(canonical.mainHash);
+ });
+
it('tracks Cloud runtime sources and dependency declarations without the whole Cloud revision', async () => {
const cloud = `${root}-cloud`;
try {
diff --git a/apps/desktop/scripts/mainHash.mjs b/apps/desktop/scripts/mainHash.mjs
index 8197f96f186..28dc27398d6 100644
--- a/apps/desktop/scripts/mainHash.mjs
+++ b/apps/desktop/scripts/mainHash.mjs
@@ -292,7 +292,7 @@ export async function collectSourceInputs({
const file = sourceFile(id);
if (slash(id).includes('/node_modules/') || node.external) continue;
if (path.isAbsolute(file)) {
- let dir = path.dirname(file);
+ let dir = path.dirname(await realpath(file));
const owner = roots.find(([, root]) => inside(root, dir));
if (!owner) throw new Error(`Main hash input is outside the source roots: ${file}`);
while (dir !== owner[1]) {