refactor: dedupe cli config cron and install flows
This commit is contained in:
@@ -65,6 +65,20 @@ describe("loader", () => {
|
||||
});
|
||||
|
||||
describe("loadInternalHooks", () => {
|
||||
const createLegacyHandlerConfig = () =>
|
||||
createEnabledHooksConfig([
|
||||
{
|
||||
event: "command:new",
|
||||
module: "legacy-handler.js",
|
||||
},
|
||||
]);
|
||||
|
||||
const expectNoCommandHookRegistration = async (cfg: OpenClawConfig) => {
|
||||
const count = await loadInternalHooks(cfg, tmpDir);
|
||||
expect(count).toBe(0);
|
||||
expect(getRegisteredEventKeys()).not.toContain("command:new");
|
||||
};
|
||||
|
||||
it("should return 0 when hooks are not enabled", async () => {
|
||||
const cfg: OpenClawConfig = {
|
||||
hooks: {
|
||||
@@ -252,11 +266,7 @@ describe("loader", () => {
|
||||
return;
|
||||
}
|
||||
|
||||
const cfg = createEnabledHooksConfig();
|
||||
|
||||
const count = await loadInternalHooks(cfg, tmpDir);
|
||||
expect(count).toBe(0);
|
||||
expect(getRegisteredEventKeys()).not.toContain("command:new");
|
||||
await expectNoCommandHookRegistration(createEnabledHooksConfig());
|
||||
});
|
||||
|
||||
it("rejects legacy handler modules that escape workspace via symlink", async () => {
|
||||
@@ -270,16 +280,7 @@ describe("loader", () => {
|
||||
return;
|
||||
}
|
||||
|
||||
const cfg = createEnabledHooksConfig([
|
||||
{
|
||||
event: "command:new",
|
||||
module: "legacy-handler.js",
|
||||
},
|
||||
]);
|
||||
|
||||
const count = await loadInternalHooks(cfg, tmpDir);
|
||||
expect(count).toBe(0);
|
||||
expect(getRegisteredEventKeys()).not.toContain("command:new");
|
||||
await expectNoCommandHookRegistration(createLegacyHandlerConfig());
|
||||
});
|
||||
|
||||
it("rejects directory hook handlers that escape hook dir via hardlink", async () => {
|
||||
@@ -313,10 +314,7 @@ describe("loader", () => {
|
||||
throw err;
|
||||
}
|
||||
|
||||
const cfg = createEnabledHooksConfig();
|
||||
const count = await loadInternalHooks(cfg, tmpDir);
|
||||
expect(count).toBe(0);
|
||||
expect(getRegisteredEventKeys()).not.toContain("command:new");
|
||||
await expectNoCommandHookRegistration(createEnabledHooksConfig());
|
||||
});
|
||||
|
||||
it("rejects legacy handler modules that escape workspace via hardlink", async () => {
|
||||
@@ -336,16 +334,7 @@ describe("loader", () => {
|
||||
throw err;
|
||||
}
|
||||
|
||||
const cfg = createEnabledHooksConfig([
|
||||
{
|
||||
event: "command:new",
|
||||
module: "legacy-handler.js",
|
||||
},
|
||||
]);
|
||||
|
||||
const count = await loadInternalHooks(cfg, tmpDir);
|
||||
expect(count).toBe(0);
|
||||
expect(getRegisteredEventKeys()).not.toContain("command:new");
|
||||
await expectNoCommandHookRegistration(createLegacyHandlerConfig());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -339,6 +339,23 @@ function readBoundaryFileUtf8(params: {
|
||||
rootPath: string;
|
||||
boundaryLabel: string;
|
||||
}): string | null {
|
||||
return withOpenedBoundaryFileSync(params, (opened) => {
|
||||
try {
|
||||
return fs.readFileSync(opened.fd, "utf-8");
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function withOpenedBoundaryFileSync<T>(
|
||||
params: {
|
||||
absolutePath: string;
|
||||
rootPath: string;
|
||||
boundaryLabel: string;
|
||||
},
|
||||
read: (opened: { fd: number; path: string }) => T,
|
||||
): T | null {
|
||||
const opened = openBoundaryFileSync({
|
||||
absolutePath: params.absolutePath,
|
||||
rootPath: params.rootPath,
|
||||
@@ -348,9 +365,7 @@ function readBoundaryFileUtf8(params: {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return fs.readFileSync(opened.fd, "utf-8");
|
||||
} catch {
|
||||
return null;
|
||||
return read({ fd: opened.fd, path: opened.path });
|
||||
} finally {
|
||||
fs.closeSync(opened.fd);
|
||||
}
|
||||
@@ -361,15 +376,5 @@ function resolveBoundaryFilePath(params: {
|
||||
rootPath: string;
|
||||
boundaryLabel: string;
|
||||
}): string | null {
|
||||
const opened = openBoundaryFileSync({
|
||||
absolutePath: params.absolutePath,
|
||||
rootPath: params.rootPath,
|
||||
boundaryLabel: params.boundaryLabel,
|
||||
});
|
||||
if (!opened.ok) {
|
||||
return null;
|
||||
}
|
||||
const safePath = opened.path;
|
||||
fs.closeSync(opened.fd);
|
||||
return safePath;
|
||||
return withOpenedBoundaryFileSync(params, (opened) => opened.path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user