Merged via /review-pr -> /prepare-pr -> /merge-pr. Prepared head SHA: 385dcbd8a9d3fd1bd67b5cb439b699a98728a679 Co-authored-by: Swader <1430603+Swader@users.noreply.github.com> Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com> Reviewed-by: @gumadeiras
63 lines
2.0 KiB
TypeScript
63 lines
2.0 KiB
TypeScript
import path from "node:path";
|
|
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
import {
|
|
clearInternalHooks,
|
|
registerInternalHook,
|
|
type AgentBootstrapHookContext,
|
|
} from "../hooks/internal-hooks.js";
|
|
import { makeTempWorkspace } from "../test-helpers/workspace.js";
|
|
import { resolveBootstrapContextForRun, resolveBootstrapFilesForRun } from "./bootstrap-files.js";
|
|
|
|
describe("resolveBootstrapFilesForRun", () => {
|
|
beforeEach(() => clearInternalHooks());
|
|
afterEach(() => clearInternalHooks());
|
|
|
|
it("applies bootstrap hook overrides", async () => {
|
|
registerInternalHook("agent:bootstrap", (event) => {
|
|
const context = event.context as AgentBootstrapHookContext;
|
|
context.bootstrapFiles = [
|
|
...context.bootstrapFiles,
|
|
{
|
|
name: "EXTRA.md",
|
|
path: path.join(context.workspaceDir, "EXTRA.md"),
|
|
content: "extra",
|
|
missing: false,
|
|
},
|
|
];
|
|
});
|
|
|
|
const workspaceDir = await makeTempWorkspace("openclaw-bootstrap-");
|
|
const files = await resolveBootstrapFilesForRun({ workspaceDir });
|
|
|
|
expect(files.some((file) => file.name === "EXTRA.md")).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("resolveBootstrapContextForRun", () => {
|
|
beforeEach(() => clearInternalHooks());
|
|
afterEach(() => clearInternalHooks());
|
|
|
|
it("returns context files for hook-adjusted bootstrap files", async () => {
|
|
registerInternalHook("agent:bootstrap", (event) => {
|
|
const context = event.context as AgentBootstrapHookContext;
|
|
context.bootstrapFiles = [
|
|
...context.bootstrapFiles,
|
|
{
|
|
name: "EXTRA.md",
|
|
path: path.join(context.workspaceDir, "EXTRA.md"),
|
|
content: "extra",
|
|
missing: false,
|
|
},
|
|
];
|
|
});
|
|
|
|
const workspaceDir = await makeTempWorkspace("openclaw-bootstrap-");
|
|
const result = await resolveBootstrapContextForRun({ workspaceDir });
|
|
const extra = result.contextFiles.find(
|
|
(file) => file.path === path.join(workspaceDir, "EXTRA.md"),
|
|
);
|
|
|
|
expect(extra?.content).toBe("extra");
|
|
});
|
|
});
|