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(scripts): run DCO checks through linked directories

Zhao Dengfeng41faf2288c0d
diff --git a/scripts/__tests__/check-dco.test.mjs b/scripts/__tests__/check-dco.test.mjs
index 5eb3504c42..786ea7528d 100644
--- a/scripts/__tests__/check-dco.test.mjs
+++ b/scripts/__tests__/check-dco.test.mjs
@@ -449,6 +449,18 @@ test('resolvePosixShell never probes relative candidates from blank or invalid W
// --- 端到端:真 git 仓库 ---
const canRunGitFixture = process.platform !== 'win32';
+const canCreateFileSymlink = (() => {
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-dco-symlink-probe-'));
+ try {
+ fs.symlinkSync(CHECK_DCO, path.join(dir, 'check-dco.mjs'), 'file');
+ return true;
+ } catch (error) {
+ if (['EPERM', 'EACCES', 'ENOSYS', 'ENOTSUP'].includes(error?.code)) return false;
+ throw error;
+ } finally {
+ fs.rmSync(dir, { recursive: true, force: true });
+ }
+})();
function createRepo() {
const dir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-dco-')));
@@ -514,6 +526,30 @@ test('CLI fails on an unsigned commit and passes once it is signed off', { skip:
assert.match(passed.output, /DCO check passed/);
});
+test(
+ 'CLI runs when invoked through a symbolic link',
+ {
+ skip: !canRunGitFixture
+ ? 'Git fixture requires POSIX git configuration'
+ : !canCreateFileSymlink
+ ? 'File symbolic links are unavailable on this host'
+ : false,
+ },
+ (t) => {
+ const repo = createRepo();
+ t.after(() => fs.rmSync(repo.dir, { recursive: true, force: true }));
+
+ repo.commit('history.txt', 'chore: pre-DCO history');
+ repo.run(['git', 'checkout', '--quiet', '-b', 'feature']);
+ repo.commit('feature.txt', 'feat: signed work', ['-s']);
+ const linkedCheckDco = path.join(repo.dir, 'linked-check-dco.mjs');
+ fs.symlinkSync(CHECK_DCO, linkedCheckDco, 'file');
+
+ const output = repo.run(['node', linkedCheckDco, '--base', 'main']);
+ assert.match(output, /DCO check passed: 1 commit signed off/);
+ },
+);
+
test('installed hook signs off subsequent commits automatically', { skip: !canRunGitFixture }, (t) => {
const repo = createRepo();
t.after(() => fs.rmSync(repo.dir, { recursive: true, force: true }));
diff --git a/scripts/check-dco.mjs b/scripts/check-dco.mjs
index 176b75e863..e7a89a67ac 100644
--- a/scripts/check-dco.mjs
+++ b/scripts/check-dco.mjs
@@ -16,8 +16,8 @@
// base.sha 与 head.sha 作为范围。
import { execFileSync } from 'node:child_process';
-import { readFileSync } from 'node:fs';
-import { pathToFileURL } from 'node:url';
+import { existsSync, readFileSync, realpathSync } from 'node:fs';
+import { fileURLToPath } from 'node:url';
import { isSignOffHookInstalled } from './install-dco-hook.mjs';
@@ -336,7 +336,8 @@ function main() {
}
// 仅作为入口执行时运行;被 import 时只导出纯函数,便于单测。
-const isDirectRun = process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href;
+const isDirectRun =
+ process.argv[1] && existsSync(process.argv[1]) && realpathSync(process.argv[1]) === fileURLToPath(import.meta.url);
if (isDirectRun) {
try {
main();