mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-19 00:52:10 -06:00
edecdbd05e
* refactor(config): consolidate media model lists * refactor(config): unify memory configuration * refactor(config): consolidate TTS ownership * refactor(config): move typing policy to agents * refactor(config): retire product-level config surfaces * refactor(config): share scoped tool policy type * chore(config): refresh generated baselines * fix(config): honor agent typing overrides * fix(config): migrate sibling config consumers * refactor(infra): keep base64url decoder private * fix(config): strip invalid legacy TTS values * chore(config): refresh rebased baseline hash * fix(doctor): route legacy messages.tts.realtime voice to talk during tts move * refactor(config): polish final layout names * refactor(config): freeze retired tuning defaults * feat(config): add fast mode default symmetry * refactor(config): key agent entries by id * docs(config): update final layout reference * test(config): cover final layout migrations * chore(config): refresh final layout baselines * fix(config): align final layout runtime readers * fix(config): align remaining readers * fix(config): stabilize final layout migrations * fix(config): finalize config projection proof * fix(config): address final layout review * docs(release): preserve historical config names * fix(config): complete keyed agent migration * fix(config): close final migration gaps * fix(config): finish full-branch review * fix(config): complete runtime secret detection * fix(config): close final review findings * fix(config): finish canonical docs and heartbeat migration * fix(config): integrate latest main after rebase * refactor(env): isolate test-only controls * refactor(env): isolate build and development controls * refactor(env): collapse process identity indirection * refactor(env): remove duplicate config and temp aliases * docs(env): define the operator-facing allowlist * ci(env): ratchet production variable count * fix(env): remove stale provider helper import * fix(env): make ratchet sorting explicit * test(env): keep test seam in dead-code audit * test(env): cover ratchet growth and boundary; document surface budgets * docs(config): document tier-eval consolidations * docs(config): clarify speech preference ownership * test(memory): align retired tuning fixtures * refactor(memory): freeze engine heuristics * refactor(config): apply tier-eval tranche * refactor(tts): move persona shaping to providers * refactor(compaction): move prompt policy to providers * test(config): align hookified prompt fixtures * chore(deadcode): classify test-only exports * chore(github): remove unused spawn helper * chore(deadcode): classify queue diagnostics * chore(deadcode): remove unused lane snapshot export * chore(plugin-sdk): ratchet consolidated surface * fix(config): integrate latest main after rebase
139 lines
4.7 KiB
TypeScript
139 lines
4.7 KiB
TypeScript
// Exercises commitment heartbeat policy through end-to-end runtime flows.
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import type { OpenClawConfig } from "../config/config.js";
|
|
import { runHeartbeatOnce } from "../infra/heartbeat-runner.js";
|
|
import { installHeartbeatRunnerTestRuntime } from "../infra/heartbeat-runner.test-harness.js";
|
|
import {
|
|
seedSessionStore,
|
|
withTempHeartbeatSandbox,
|
|
} from "../infra/heartbeat-runner.test-utils.js";
|
|
import { closeOpenClawStateDatabaseForTest } from "../state/openclaw-state-db.js";
|
|
import { withEnvAsync } from "../test-utils/env.js";
|
|
import { readCommitmentsForTest, seedCommitmentsForTest } from "./store.test-utils.js";
|
|
import type { CommitmentRecord } from "./types.js";
|
|
|
|
vi.mock("./config.js", async (importOriginal) => ({
|
|
...(await importOriginal<typeof import("./config.js")>()),
|
|
resolveCommitmentsConfig: () => ({
|
|
enabled: true,
|
|
maxPerDay: 3,
|
|
extraction: {
|
|
debounceMs: 15_000,
|
|
batchMaxItems: 8,
|
|
queueMaxItems: 64,
|
|
confidenceThreshold: 0.72,
|
|
careConfidenceThreshold: 0.86,
|
|
timeoutSeconds: 45,
|
|
},
|
|
}),
|
|
}));
|
|
|
|
installHeartbeatRunnerTestRuntime();
|
|
|
|
describe("commitments heartbeat delivery policy e2e", () => {
|
|
const nowMs = Date.parse("2026-04-29T17:00:00.000Z");
|
|
const sessionKey = "agent:main:telegram:user-155462274";
|
|
|
|
afterEach(() => {
|
|
closeOpenClawStateDatabaseForTest();
|
|
vi.unstubAllEnvs();
|
|
});
|
|
|
|
function commitment(overrides?: Partial<CommitmentRecord>): CommitmentRecord {
|
|
return {
|
|
id: "cm_target_none",
|
|
agentId: "main",
|
|
sessionKey,
|
|
channel: "telegram",
|
|
accountId: "primary",
|
|
to: "155462274",
|
|
kind: "care_check_in",
|
|
sensitivity: "care",
|
|
source: "inferred_user_context",
|
|
status: "pending",
|
|
reason: "The user said they were exhausted yesterday.",
|
|
suggestedText: "Did you get some rest?",
|
|
dedupeKey: "sleep:2026-04-28",
|
|
confidence: 0.94,
|
|
dueWindow: {
|
|
earliestMs: nowMs - 60_000,
|
|
latestMs: nowMs + 60 * 60_000,
|
|
timezone: "America/Los_Angeles",
|
|
},
|
|
createdAtMs: nowMs - 24 * 60 * 60_000,
|
|
updatedAtMs: nowMs - 24 * 60 * 60_000,
|
|
attempts: 0,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
it("does not send externally when heartbeat target is none", async () => {
|
|
await withTempHeartbeatSandbox(async ({ tmpDir, storePath, replySpy }) => {
|
|
await withEnvAsync({ OPENCLAW_STATE_DIR: tmpDir }, async () => {
|
|
const cfg: OpenClawConfig = {
|
|
agents: {
|
|
defaults: {
|
|
workspace: tmpDir,
|
|
heartbeat: {
|
|
every: "5m",
|
|
target: "none",
|
|
},
|
|
},
|
|
},
|
|
channels: { telegram: { allowFrom: ["*"] } },
|
|
session: { store: storePath },
|
|
};
|
|
await seedSessionStore(storePath, sessionKey, {
|
|
lastChannel: "telegram",
|
|
lastProvider: "telegram",
|
|
lastTo: "155462274",
|
|
});
|
|
seedCommitmentsForTest([commitment()]);
|
|
|
|
const sendTelegram = vi.fn().mockResolvedValue({
|
|
messageId: "m1",
|
|
chatId: "155462274",
|
|
});
|
|
replySpy.mockImplementation(
|
|
async (
|
|
ctx: { Body?: string; OriginatingChannel?: string; OriginatingTo?: string },
|
|
opts?: { disableTools?: boolean },
|
|
) => {
|
|
expect(ctx.Body).not.toContain("Due inferred follow-up commitments");
|
|
expect(ctx.Body).not.toContain("Did you get some rest?");
|
|
expect(ctx.Body).not.toContain("CALL_TOOL");
|
|
expect(ctx.OriginatingChannel).toBeUndefined();
|
|
expect(ctx.OriginatingTo).toBeUndefined();
|
|
expect(opts?.disableTools).toBeUndefined();
|
|
return { text: "internal heartbeat only" };
|
|
},
|
|
);
|
|
|
|
const result = await runHeartbeatOnce({
|
|
cfg,
|
|
agentId: "main",
|
|
sessionKey,
|
|
deps: {
|
|
getReplyFromConfig: replySpy,
|
|
telegram: sendTelegram,
|
|
getQueueSize: () => 0,
|
|
nowMs: () => nowMs,
|
|
},
|
|
});
|
|
|
|
expect(result.status).toBe("ran");
|
|
expect(sendTelegram).not.toHaveBeenCalled();
|
|
const [persistedCommitment] = readCommitmentsForTest();
|
|
if (!persistedCommitment) {
|
|
throw new Error("missing persisted commitment");
|
|
}
|
|
expect(persistedCommitment.id).toBe("cm_target_none");
|
|
expect(persistedCommitment.status).toBe("pending");
|
|
expect(persistedCommitment.attempts).toBe(0);
|
|
expect(persistedCommitment).not.toHaveProperty("sourceUserText");
|
|
expect(persistedCommitment).not.toHaveProperty("sourceAssistantText");
|
|
});
|
|
});
|
|
});
|
|
});
|