mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 06:10:45 +00:00
test: tighten post compaction context assertions
This commit is contained in:
@@ -29,7 +29,6 @@ describe("readPostCompactionContext", () => {
|
||||
},
|
||||
} 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) {
|
||||
@@ -63,7 +62,6 @@ Not relevant.
|
||||
`;
|
||||
fs.writeFileSync(path.join(tmpDir, "AGENTS.md"), content);
|
||||
const result = await readPostCompactionContext(tmpDir);
|
||||
expect(result).not.toBeNull();
|
||||
expect(result).toContain("Session Startup");
|
||||
expect(result).toContain("WORKFLOW_AUTO.md");
|
||||
expect(result).toContain("Post-compaction context refresh");
|
||||
@@ -84,7 +82,6 @@ Stuff.
|
||||
`;
|
||||
fs.writeFileSync(path.join(tmpDir, "AGENTS.md"), content);
|
||||
const result = await readPostCompactionContext(tmpDir);
|
||||
expect(result).not.toBeNull();
|
||||
expect(result).toContain("Red Lines");
|
||||
expect(result).toContain("Never do X");
|
||||
});
|
||||
@@ -106,7 +103,6 @@ Ignore this.
|
||||
`;
|
||||
fs.writeFileSync(path.join(tmpDir, "AGENTS.md"), content);
|
||||
const result = await readPostCompactionContext(tmpDir);
|
||||
expect(result).not.toBeNull();
|
||||
expect(result).toContain("Session Startup");
|
||||
expect(result).toContain("Red Lines");
|
||||
expect(result).not.toContain("Other");
|
||||
@@ -116,9 +112,8 @@ Ignore this.
|
||||
const longContent = "## Session Startup\n\n" + "A".repeat(4000) + "\n\n## Other\n\nStuff.";
|
||||
fs.writeFileSync(path.join(tmpDir, "AGENTS.md"), longContent);
|
||||
const result = await readPostCompactionContext(tmpDir);
|
||||
expect(result).not.toBeNull();
|
||||
expect(result).toContain("[truncated]");
|
||||
expect(result!.length).toBeLessThan(2600);
|
||||
expect(result?.length).toBeLessThan(2600);
|
||||
});
|
||||
|
||||
it("honors per-agent post-compaction context limit overrides", async () => {
|
||||
@@ -144,9 +139,8 @@ Ignore this.
|
||||
} as OpenClawConfig;
|
||||
|
||||
const result = await readPostCompactionContext(tmpDir, { cfg, agentId: "writer" });
|
||||
expect(result).not.toBeNull();
|
||||
expect(result).toContain("[truncated]");
|
||||
expect(result!.length).toBeLessThan(1_200);
|
||||
expect(result?.length).toBeLessThan(1_200);
|
||||
});
|
||||
|
||||
it("matches section names case-insensitively", async () => {
|
||||
@@ -160,7 +154,6 @@ Read WORKFLOW_AUTO.md
|
||||
`;
|
||||
fs.writeFileSync(path.join(tmpDir, "AGENTS.md"), content);
|
||||
const result = await readPostCompactionContext(tmpDir);
|
||||
expect(result).not.toBeNull();
|
||||
expect(result).toContain("WORKFLOW_AUTO.md");
|
||||
});
|
||||
|
||||
@@ -175,7 +168,6 @@ Read these files.
|
||||
`;
|
||||
fs.writeFileSync(path.join(tmpDir, "AGENTS.md"), content);
|
||||
const result = await readPostCompactionContext(tmpDir);
|
||||
expect(result).not.toBeNull();
|
||||
expect(result).toContain("Read these files");
|
||||
});
|
||||
|
||||
@@ -195,7 +187,6 @@ Real red lines here.
|
||||
`;
|
||||
fs.writeFileSync(path.join(tmpDir, "AGENTS.md"), content);
|
||||
const result = await readPostCompactionContext(tmpDir);
|
||||
expect(result).not.toBeNull();
|
||||
expect(result).toContain("Real red lines here");
|
||||
expect(result).not.toContain("inside a code block");
|
||||
});
|
||||
@@ -213,7 +204,6 @@ Never do Y.
|
||||
`;
|
||||
fs.writeFileSync(path.join(tmpDir, "AGENTS.md"), content);
|
||||
const result = await readPostCompactionContext(tmpDir);
|
||||
expect(result).not.toBeNull();
|
||||
expect(result).toContain("Rule 1");
|
||||
expect(result).toContain("Rule 2");
|
||||
expect(result).not.toContain("Other Section");
|
||||
@@ -259,7 +249,6 @@ Never modify memory/YYYY-MM-DD.md destructively.
|
||||
// 2026-03-03 14:00 UTC = 2026-03-03 09:00 EST
|
||||
const nowMs = Date.UTC(2026, 2, 3, 14, 0, 0);
|
||||
const result = await readPostCompactionContext(tmpDir, { cfg, nowMs });
|
||||
expect(result).not.toBeNull();
|
||||
expect(result).toContain("memory/2026-03-03.md");
|
||||
expect(result).not.toContain("memory/YYYY-MM-DD.md");
|
||||
expect(result).toContain("Current time: Tuesday, March 3rd, 2026 - 9:00 AM (America/New_York)");
|
||||
@@ -274,7 +263,6 @@ Read WORKFLOW.md on startup.
|
||||
fs.writeFileSync(path.join(tmpDir, "AGENTS.md"), content);
|
||||
const nowMs = Date.UTC(2026, 2, 3, 14, 0, 0);
|
||||
const result = await readPostCompactionContext(tmpDir, { nowMs });
|
||||
expect(result).not.toBeNull();
|
||||
expect(result).toContain("Current time:");
|
||||
});
|
||||
|
||||
@@ -302,7 +290,6 @@ Read WORKFLOW.md on startup.
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const result = await readPostCompactionContext(tmpDir, { cfg });
|
||||
expect(result).not.toBeNull();
|
||||
expect(result).toContain("Critical Rules");
|
||||
expect(result).toContain("My custom rules");
|
||||
// Default sections must not be included when overridden
|
||||
@@ -321,7 +308,6 @@ Read WORKFLOW.md on startup.
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const result = await readPostCompactionContext(tmpDir, { cfg });
|
||||
expect(result).not.toBeNull();
|
||||
expect(result).toContain("Onboard things");
|
||||
expect(result).toContain("Safe things");
|
||||
expect(result).not.toContain("Ignore");
|
||||
@@ -370,7 +356,6 @@ Read WORKFLOW.md on startup.
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const result = await readPostCompactionContext(tmpDir, { cfg });
|
||||
expect(result).not.toBeNull();
|
||||
// Must not reference the hardcoded default section name
|
||||
expect(result).not.toContain("Session Startup");
|
||||
// Must reference the actual configured section names
|
||||
@@ -381,7 +366,6 @@ Read WORKFLOW.md on startup.
|
||||
const content = `## Session Startup\n\nDo startup.\n`;
|
||||
fs.writeFileSync(path.join(tmpDir, "AGENTS.md"), content);
|
||||
const result = await readPostCompactionContext(tmpDir);
|
||||
expect(result).not.toBeNull();
|
||||
expect(result).toContain("Run your Session Startup sequence");
|
||||
});
|
||||
|
||||
@@ -407,7 +391,6 @@ Read WORKFLOW.md on startup.
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const result = await readPostCompactionContext(tmpDir, { cfg });
|
||||
expect(result).not.toBeNull();
|
||||
expect(result).toContain("Init things");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user