mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 20:00:22 +00:00
refactor: dedupe gateway config and infra flows
This commit is contained in:
@@ -21,6 +21,34 @@ function writeHookPackageManifest(pkgDir: string, hooks: string[]): void {
|
||||
);
|
||||
}
|
||||
|
||||
function setupHardlinkHookWorkspace(hookName: string): {
|
||||
hooksRoot: string;
|
||||
hookDir: string;
|
||||
outsideDir: string;
|
||||
} {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-hooks-workspace-hardlink-"));
|
||||
const hooksRoot = path.join(root, "hooks");
|
||||
fs.mkdirSync(hooksRoot, { recursive: true });
|
||||
|
||||
const hookDir = path.join(hooksRoot, hookName);
|
||||
const outsideDir = path.join(root, "outside");
|
||||
fs.mkdirSync(hookDir, { recursive: true });
|
||||
fs.mkdirSync(outsideDir, { recursive: true });
|
||||
return { hooksRoot, hookDir, outsideDir };
|
||||
}
|
||||
|
||||
function tryCreateHardlinkOrSkip(createLink: () => void): boolean {
|
||||
try {
|
||||
createLink();
|
||||
return true;
|
||||
} catch (err) {
|
||||
if ((err as NodeJS.ErrnoException).code === "EXDEV") {
|
||||
return false;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
describe("hooks workspace", () => {
|
||||
it("ignores package.json hook paths that traverse outside package directory", () => {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-hooks-workspace-"));
|
||||
@@ -88,27 +116,15 @@ describe("hooks workspace", () => {
|
||||
return;
|
||||
}
|
||||
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-hooks-workspace-hardlink-"));
|
||||
const hooksRoot = path.join(root, "hooks");
|
||||
fs.mkdirSync(hooksRoot, { recursive: true });
|
||||
|
||||
const hookDir = path.join(hooksRoot, "hardlink-hook");
|
||||
const outsideDir = path.join(root, "outside");
|
||||
fs.mkdirSync(hookDir, { recursive: true });
|
||||
fs.mkdirSync(outsideDir, { recursive: true });
|
||||
const { hooksRoot, hookDir, outsideDir } = setupHardlinkHookWorkspace("hardlink-hook");
|
||||
fs.writeFileSync(path.join(hookDir, "handler.js"), "export default async () => {};\n");
|
||||
const outsideHookMd = path.join(outsideDir, "HOOK.md");
|
||||
const linkedHookMd = path.join(hookDir, "HOOK.md");
|
||||
fs.writeFileSync(linkedHookMd, "---\nname: hardlink-hook\n---\n");
|
||||
fs.rmSync(linkedHookMd);
|
||||
fs.writeFileSync(outsideHookMd, "---\nname: outside\n---\n");
|
||||
try {
|
||||
fs.linkSync(outsideHookMd, linkedHookMd);
|
||||
} catch (err) {
|
||||
if ((err as NodeJS.ErrnoException).code === "EXDEV") {
|
||||
return;
|
||||
}
|
||||
throw err;
|
||||
if (!tryCreateHardlinkOrSkip(() => fs.linkSync(outsideHookMd, linkedHookMd))) {
|
||||
return;
|
||||
}
|
||||
|
||||
const entries = loadHookEntriesFromDir({ dir: hooksRoot, source: "openclaw-workspace" });
|
||||
@@ -121,25 +137,13 @@ describe("hooks workspace", () => {
|
||||
return;
|
||||
}
|
||||
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-hooks-workspace-hardlink-"));
|
||||
const hooksRoot = path.join(root, "hooks");
|
||||
fs.mkdirSync(hooksRoot, { recursive: true });
|
||||
|
||||
const hookDir = path.join(hooksRoot, "hardlink-handler-hook");
|
||||
const outsideDir = path.join(root, "outside");
|
||||
fs.mkdirSync(hookDir, { recursive: true });
|
||||
fs.mkdirSync(outsideDir, { recursive: true });
|
||||
const { hooksRoot, hookDir, outsideDir } = setupHardlinkHookWorkspace("hardlink-handler-hook");
|
||||
fs.writeFileSync(path.join(hookDir, "HOOK.md"), "---\nname: hardlink-handler-hook\n---\n");
|
||||
const outsideHandler = path.join(outsideDir, "handler.js");
|
||||
const linkedHandler = path.join(hookDir, "handler.js");
|
||||
fs.writeFileSync(outsideHandler, "export default async () => {};\n");
|
||||
try {
|
||||
fs.linkSync(outsideHandler, linkedHandler);
|
||||
} catch (err) {
|
||||
if ((err as NodeJS.ErrnoException).code === "EXDEV") {
|
||||
return;
|
||||
}
|
||||
throw err;
|
||||
if (!tryCreateHardlinkOrSkip(() => fs.linkSync(outsideHandler, linkedHandler))) {
|
||||
return;
|
||||
}
|
||||
|
||||
const entries = loadHookEntriesFromDir({ dir: hooksRoot, source: "openclaw-workspace" });
|
||||
|
||||
Reference in New Issue
Block a user