🤯 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🔨 chore(check): route symlinked file args by their real path (#22983)
YuTengjingaf268c520a9b
diff --git a/.agents/scripts/check/collect.test.ts b/.agents/scripts/check/collect.test.tsnew file mode 100644index 00000000000..2acd56c479d--- /dev/null+++ b/.agents/scripts/check/collect.test.ts@@ -0,0 +1,67 @@+import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import path from 'node:path';++import { afterEach, beforeEach, describe, expect, it } from 'vitest';++import { normalizeArgs } from './collect';+import { setConfig } from './paths';++let root: string;++beforeEach(() => {+ root = mkdtempSync(path.join(tmpdir(), 'check-collect-'));+ mkdirSync(path.join(root, 'lobehub/.agents/skills/design/scripts'), { recursive: true });+ writeFileSync(path.join(root, 'lobehub/.agents/skills/design/scripts/run.mjs'), '');+ mkdirSync(path.join(root, '.agents/skills'), { recursive: true });+ symlinkSync('../../lobehub/.agents/skills/design', path.join(root, '.agents/skills/design'));+ mkdirSync(path.join(root, 'src'));+ writeFileSync(path.join(root, 'src/app.ts'), '');+ // A link that leaves the repo, like a skill installed from the user's home.+ const outside = mkdtempSync(path.join(tmpdir(), 'check-outside-'));+ symlinkSync(outside, path.join(root, '.agents/skills/external'));++ setConfig({+ repos: [+ { dir: '', pipelines: [] },+ { dir: 'lobehub', pipelines: [] },+ ],+ rootDir: root,+ });+});++afterEach(() => {+ rmSync(root, { force: true, recursive: true });+});++describe('normalizeArgs', () => {+ it('routes a host path that links into a sub-repo to its real sub-repo path', () => {+ expect(normalizeArgs([path.join(root, '.agents/skills/design/scripts/run.mjs')])).toEqual([+ 'lobehub/.agents/skills/design/scripts/run.mjs',+ ]);+ });++ it('checks a file once when both its link path and its real path are passed', () => {+ expect(+ normalizeArgs([+ path.join(root, '.agents/skills/design/scripts/run.mjs'),+ path.join(root, 'lobehub/.agents/skills/design/scripts/run.mjs'),+ ]),+ ).toEqual(['lobehub/.agents/skills/design/scripts/run.mjs']);+ });++ it('resolves the linked directory of a deleted file', () => {+ expect(normalizeArgs([path.join(root, '.agents/skills/design/scripts/gone.mjs')])).toEqual([+ 'lobehub/.agents/skills/design/scripts/gone.mjs',+ ]);+ });++ it('keeps plain host paths and links that leave the repo as written', () => {+ expect(+ normalizeArgs([+ path.join(root, 'src/app.ts'),+ path.join(root, '.agents/skills/external/SKILL.md'),+ ]),+ ).toEqual(['src/app.ts', '.agents/skills/external/SKILL.md']);+ });+});diff --git a/.agents/scripts/check/collect.ts b/.agents/scripts/check/collect.tsindex a238e23dfd0..d29fbbed904 100644--- a/.agents/scripts/check/collect.ts+++ b/.agents/scripts/check/collect.ts@@ -1,3 +1,4 @@+import { realpathSync } from 'node:fs';import path from 'node:path';import { git } from './exec';@@ -37,14 +38,43 @@ export const collectFromGit = async (stagedOnly = false): Promise<string[]> => {return perRepo.flat().filter((file) => !gitlinks.has(file));};-/** Resolve CLI file args to root-relative paths; exits on paths outside the repo. */-export const normalizeArgs = (args: string[]): string[] =>- args.map((arg) => {+/**+ * Resolve a path through symlinks. A missing tail (e.g. a deleted file) is kept+ * as written below its nearest existing ancestor, so the ancestor's links still+ * resolve.+ */+const realpathOrSelf = (abs: string): string => {+ try {+ return realpathSync(abs);+ } catch {+ const parent = path.dirname(abs);+ return parent === abs ? abs : path.join(realpathOrSelf(parent), path.basename(abs));+ }+};++/**+ * Resolve CLI file args to root-relative paths; exits on paths outside the repo.+ *+ * Paths are routed by where they really live: a host path that links into a+ * mounted sub-repo (Cloud's `.agents/skills/<name>` -> `lobehub/.agents/skills/<name>`)+ * becomes the sub-repo path, so it gets that repo's pipeline and ignore files+ * instead of the host's fixers rewriting vendored sub-repo files. A link that+ * leaves the repo keeps its written path.+ */+export const normalizeArgs = (args: string[]): string[] => {+ const { rootDir } = getConfig();+ const realRoot = realpathOrSelf(rootDir);++ // A link and its target may both be passed; they normalize to one entry.+ const resolved = args.map((arg) => {const abs = path.resolve(process.cwd(), arg);- const rel = path.relative(getConfig().rootDir, abs);+ const rel = path.relative(rootDir, abs);if (rel.startsWith('..')) {console.error(`✗ file outside repo: ${arg}`);process.exit(2);}- return rel;+ const realRel = path.relative(realRoot, realpathOrSelf(abs));+ return realRel.startsWith('..') || path.isAbsolute(realRel) ? rel : realRel;});+ return [...new Set(resolved)];+};