mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-13 14:30:35 +00:00
refactor(agents): dedupe plugin hooks and test helpers
This commit is contained in:
@@ -13,33 +13,42 @@ function makeBootstrapFile(overrides: Partial<WorkspaceBootstrapFile>): Workspac
|
||||
}
|
||||
|
||||
describe("buildSystemPromptReport", () => {
|
||||
it("counts injected chars when injected file paths are absolute", () => {
|
||||
const file = makeBootstrapFile({ path: "/tmp/workspace/policies/AGENTS.md" });
|
||||
const report = buildSystemPromptReport({
|
||||
const makeReport = (params: {
|
||||
file: WorkspaceBootstrapFile;
|
||||
injectedPath: string;
|
||||
injectedContent: string;
|
||||
bootstrapMaxChars?: number;
|
||||
bootstrapTotalMaxChars?: number;
|
||||
}) =>
|
||||
buildSystemPromptReport({
|
||||
source: "run",
|
||||
generatedAt: 0,
|
||||
bootstrapMaxChars: 20_000,
|
||||
bootstrapMaxChars: params.bootstrapMaxChars ?? 20_000,
|
||||
bootstrapTotalMaxChars: params.bootstrapTotalMaxChars,
|
||||
systemPrompt: "system",
|
||||
bootstrapFiles: [file],
|
||||
injectedFiles: [{ path: "/tmp/workspace/policies/AGENTS.md", content: "trimmed" }],
|
||||
bootstrapFiles: [params.file],
|
||||
injectedFiles: [{ path: params.injectedPath, content: params.injectedContent }],
|
||||
skillsPrompt: "",
|
||||
tools: [],
|
||||
});
|
||||
|
||||
it("counts injected chars when injected file paths are absolute", () => {
|
||||
const file = makeBootstrapFile({ path: "/tmp/workspace/policies/AGENTS.md" });
|
||||
const report = makeReport({
|
||||
file,
|
||||
injectedPath: "/tmp/workspace/policies/AGENTS.md",
|
||||
injectedContent: "trimmed",
|
||||
});
|
||||
|
||||
expect(report.injectedWorkspaceFiles[0]?.injectedChars).toBe("trimmed".length);
|
||||
});
|
||||
|
||||
it("keeps legacy basename matching for injected files", () => {
|
||||
const file = makeBootstrapFile({ path: "/tmp/workspace/policies/AGENTS.md" });
|
||||
const report = buildSystemPromptReport({
|
||||
source: "run",
|
||||
generatedAt: 0,
|
||||
bootstrapMaxChars: 20_000,
|
||||
systemPrompt: "system",
|
||||
bootstrapFiles: [file],
|
||||
injectedFiles: [{ path: "AGENTS.md", content: "trimmed" }],
|
||||
skillsPrompt: "",
|
||||
tools: [],
|
||||
const report = makeReport({
|
||||
file,
|
||||
injectedPath: "AGENTS.md",
|
||||
injectedContent: "trimmed",
|
||||
});
|
||||
|
||||
expect(report.injectedWorkspaceFiles[0]?.injectedChars).toBe("trimmed".length);
|
||||
@@ -50,15 +59,10 @@ describe("buildSystemPromptReport", () => {
|
||||
path: "/tmp/workspace/policies/AGENTS.md",
|
||||
content: "abcdefghijklmnopqrstuvwxyz",
|
||||
});
|
||||
const report = buildSystemPromptReport({
|
||||
source: "run",
|
||||
generatedAt: 0,
|
||||
bootstrapMaxChars: 20_000,
|
||||
systemPrompt: "system",
|
||||
bootstrapFiles: [file],
|
||||
injectedFiles: [{ path: "/tmp/workspace/policies/AGENTS.md", content: "trimmed" }],
|
||||
skillsPrompt: "",
|
||||
tools: [],
|
||||
const report = makeReport({
|
||||
file,
|
||||
injectedPath: "/tmp/workspace/policies/AGENTS.md",
|
||||
injectedContent: "trimmed",
|
||||
});
|
||||
|
||||
expect(report.injectedWorkspaceFiles[0]?.truncated).toBe(true);
|
||||
@@ -66,19 +70,27 @@ describe("buildSystemPromptReport", () => {
|
||||
|
||||
it("includes both bootstrap caps in the report payload", () => {
|
||||
const file = makeBootstrapFile({ path: "/tmp/workspace/policies/AGENTS.md" });
|
||||
const report = buildSystemPromptReport({
|
||||
source: "run",
|
||||
generatedAt: 0,
|
||||
const report = makeReport({
|
||||
file,
|
||||
injectedPath: "AGENTS.md",
|
||||
injectedContent: "trimmed",
|
||||
bootstrapMaxChars: 11_111,
|
||||
bootstrapTotalMaxChars: 22_222,
|
||||
systemPrompt: "system",
|
||||
bootstrapFiles: [file],
|
||||
injectedFiles: [{ path: "AGENTS.md", content: "trimmed" }],
|
||||
skillsPrompt: "",
|
||||
tools: [],
|
||||
});
|
||||
|
||||
expect(report.bootstrapMaxChars).toBe(11_111);
|
||||
expect(report.bootstrapTotalMaxChars).toBe(22_222);
|
||||
});
|
||||
|
||||
it("reports injectedChars=0 when injected file does not match by path or basename", () => {
|
||||
const file = makeBootstrapFile({ path: "/tmp/workspace/policies/AGENTS.md" });
|
||||
const report = makeReport({
|
||||
file,
|
||||
injectedPath: "/tmp/workspace/policies/OTHER.md",
|
||||
injectedContent: "trimmed",
|
||||
});
|
||||
|
||||
expect(report.injectedWorkspaceFiles[0]?.injectedChars).toBe(0);
|
||||
expect(report.injectedWorkspaceFiles[0]?.truncated).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user