mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 00:41:25 +00:00
85 lines
2.7 KiB
TypeScript
85 lines
2.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { buildSystemPromptReport } from "./system-prompt-report.js";
|
|
import type { WorkspaceBootstrapFile } from "./workspace.js";
|
|
|
|
function makeBootstrapFile(overrides: Partial<WorkspaceBootstrapFile>): WorkspaceBootstrapFile {
|
|
return {
|
|
name: "AGENTS.md",
|
|
path: "/tmp/workspace/AGENTS.md",
|
|
content: "alpha",
|
|
missing: false,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("buildSystemPromptReport", () => {
|
|
it("counts injected chars when injected file paths are absolute", () => {
|
|
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: "/tmp/workspace/policies/AGENTS.md", content: "trimmed" }],
|
|
skillsPrompt: "",
|
|
tools: [],
|
|
});
|
|
|
|
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: [],
|
|
});
|
|
|
|
expect(report.injectedWorkspaceFiles[0]?.injectedChars).toBe("trimmed".length);
|
|
});
|
|
|
|
it("marks workspace files truncated when injected chars are smaller than raw chars", () => {
|
|
const file = makeBootstrapFile({
|
|
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: [],
|
|
});
|
|
|
|
expect(report.injectedWorkspaceFiles[0]?.truncated).toBe(true);
|
|
});
|
|
|
|
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,
|
|
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);
|
|
});
|
|
});
|