mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-15 20:10:42 +00:00
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
import {
|
|
clearInternalHooks,
|
|
registerInternalHook,
|
|
type AgentBootstrapHookContext,
|
|
} from "../hooks/internal-hooks.js";
|
|
import { applyBootstrapHookOverrides } from "./bootstrap-hooks.js";
|
|
import { DEFAULT_SOUL_FILENAME, type WorkspaceBootstrapFile } from "./workspace.js";
|
|
|
|
function makeFile(
|
|
name: WorkspaceBootstrapFile["name"] = DEFAULT_SOUL_FILENAME,
|
|
): WorkspaceBootstrapFile {
|
|
return {
|
|
name,
|
|
path: `/tmp/${name}`,
|
|
content: "base",
|
|
missing: false,
|
|
};
|
|
}
|
|
|
|
describe("applyBootstrapHookOverrides", () => {
|
|
beforeEach(() => clearInternalHooks());
|
|
afterEach(() => clearInternalHooks());
|
|
|
|
it("returns updated files when a hook mutates the context", async () => {
|
|
registerInternalHook("agent:bootstrap", (event) => {
|
|
const context = event.context as AgentBootstrapHookContext;
|
|
context.bootstrapFiles = [
|
|
...context.bootstrapFiles,
|
|
{
|
|
name: "EXTRA.md",
|
|
path: "/tmp/EXTRA.md",
|
|
content: "extra",
|
|
missing: false,
|
|
} as unknown as WorkspaceBootstrapFile,
|
|
];
|
|
});
|
|
|
|
const updated = await applyBootstrapHookOverrides({
|
|
files: [makeFile()],
|
|
workspaceDir: "/tmp",
|
|
});
|
|
|
|
expect(updated).toHaveLength(2);
|
|
expect(updated[1]?.path).toBe("/tmp/EXTRA.md");
|
|
});
|
|
});
|