Agents: simplify inferred commitment config (#74189)

This commit is contained in:
Vignesh Natarajan
2026-04-29 14:13:11 -07:00
committed by Vignesh
parent 11771ec172
commit aecde2b3ac
18 changed files with 234 additions and 534 deletions

View File

@@ -18,6 +18,7 @@ describe("commitment extraction runtime", () => {
afterEach(async () => {
resetCommitmentExtractionRuntimeForTests();
vi.unstubAllEnvs();
await Promise.all(tmpDirs.map((dir) => fs.rm(dir, { recursive: true, force: true })));
tmpDirs.length = 0;
});
@@ -25,13 +26,10 @@ describe("commitment extraction runtime", () => {
async function createConfig(): Promise<OpenClawConfig> {
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-commitment-runtime-"));
tmpDirs.push(tmpDir);
vi.stubEnv("OPENCLAW_STATE_DIR", tmpDir);
return {
commitments: {
store: path.join(tmpDir, "commitments.json"),
extraction: {
debounceMs: 1_000,
batchMaxItems: 8,
},
enabled: true,
},
};
}
@@ -52,6 +50,29 @@ describe("commitment extraction runtime", () => {
).toBe(false);
});
it("keeps hidden extraction opt-in by default", () => {
const cfg: OpenClawConfig = {
commitments: {},
};
configureCommitmentExtractionRuntime({
forceInTests: true,
setTimer: () => ({ unref() {} }) as ReturnType<typeof setTimeout>,
clearTimer: () => undefined,
});
expect(
enqueueCommitmentExtraction({
cfg,
nowMs,
agentId: "main",
sessionKey: "agent:main:telegram:user-1",
channel: "telegram",
userText: "Interview tomorrow.",
assistantText: "Good luck.",
}),
).toBe(false);
});
it("micro-batches queued turns into one extractor call", async () => {
const cfg = await createConfig();
const extractBatch = vi.fn(async ({ items }: { items: CommitmentExtractionItem[] }) => ({
@@ -106,7 +127,7 @@ describe("commitment extraction runtime", () => {
).toBe(true);
await expect(drainCommitmentExtractionQueue()).resolves.toBe(2);
const store = await loadCommitmentStore(cfg.commitments?.store);
const store = await loadCommitmentStore();
expect(extractBatch).toHaveBeenCalledTimes(1);
const batchItems = extractBatch.mock.calls[0]?.[0].items;