mirror of https://github.com/openclaw/openclaw.git
test: dedupe post compaction legacy fallback checks
This commit is contained in:
parent
91c94c8b95
commit
07b3f5233e
|
|
@ -15,6 +15,28 @@ describe("readPostCompactionContext", () => {
|
|||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
async function expectLegacySectionFallback(
|
||||
postCompactionSections: string[],
|
||||
expectDefaultProse = false,
|
||||
) {
|
||||
const content = `## Every Session\n\nDo startup things.\n\n## Safety\n\nBe safe.\n`;
|
||||
fs.writeFileSync(path.join(tmpDir, "AGENTS.md"), content);
|
||||
const cfg = {
|
||||
agents: {
|
||||
defaults: {
|
||||
compaction: { postCompactionSections },
|
||||
},
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const result = await readPostCompactionContext(tmpDir, cfg);
|
||||
expect(result).not.toBeNull();
|
||||
expect(result).toContain("Do startup things");
|
||||
expect(result).toContain("Be safe");
|
||||
if (expectDefaultProse) {
|
||||
expect(result).toContain("Run your Session Startup sequence");
|
||||
}
|
||||
}
|
||||
|
||||
it("returns null when no AGENTS.md exists", async () => {
|
||||
const result = await readPostCompactionContext(tmpDir);
|
||||
expect(result).toBeNull();
|
||||
|
|
@ -339,36 +361,11 @@ Read WORKFLOW.md on startup.
|
|||
// Older AGENTS.md templates use "Every Session" / "Safety" instead of
|
||||
// "Session Startup" / "Red Lines". Explicitly setting the defaults should
|
||||
// still trigger the legacy fallback — same behavior as leaving the field unset.
|
||||
const content = `## Every Session\n\nDo startup things.\n\n## Safety\n\nBe safe.\n`;
|
||||
fs.writeFileSync(path.join(tmpDir, "AGENTS.md"), content);
|
||||
const cfg = {
|
||||
agents: {
|
||||
defaults: {
|
||||
compaction: { postCompactionSections: ["Session Startup", "Red Lines"] },
|
||||
},
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const result = await readPostCompactionContext(tmpDir, cfg);
|
||||
expect(result).not.toBeNull();
|
||||
expect(result).toContain("Do startup things");
|
||||
expect(result).toContain("Be safe");
|
||||
await expectLegacySectionFallback(["Session Startup", "Red Lines"]);
|
||||
});
|
||||
|
||||
it("falls back to legacy sections when default sections are configured in a different order", async () => {
|
||||
const content = `## Every Session\n\nDo startup things.\n\n## Safety\n\nBe safe.\n`;
|
||||
fs.writeFileSync(path.join(tmpDir, "AGENTS.md"), content);
|
||||
const cfg = {
|
||||
agents: {
|
||||
defaults: {
|
||||
compaction: { postCompactionSections: ["Red Lines", "Session Startup"] },
|
||||
},
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const result = await readPostCompactionContext(tmpDir, cfg);
|
||||
expect(result).not.toBeNull();
|
||||
expect(result).toContain("Do startup things");
|
||||
expect(result).toContain("Be safe");
|
||||
expect(result).toContain("Run your Session Startup sequence");
|
||||
await expectLegacySectionFallback(["Red Lines", "Session Startup"], true);
|
||||
});
|
||||
|
||||
it("custom section names are matched case-insensitively", async () => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue