mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-04 18:01:40 +00:00
* 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
108 lines
4.5 KiB
TypeScript
108 lines
4.5 KiB
TypeScript
// Covers cron-style current-time formatting and invalid Date fallbacks.
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { appendCronStyleCurrentTimeLine, resolveCronStyleNow } from "./current-time.js";
|
|
|
|
describe("resolveCronStyleNow", () => {
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it("falls back when nowMs is outside Date range", () => {
|
|
// Invalid scheduler timestamps should fall back to wall-clock time so cron
|
|
// prompts still get a usable reference date.
|
|
vi.spyOn(Date, "now").mockReturnValue(Date.parse("2026-05-30T12:00:00.000Z"));
|
|
|
|
const result = resolveCronStyleNow(
|
|
{ agents: { defaults: { userTimezone: "UTC", timeFormat: "24" } } },
|
|
8_640_000_000_000_001,
|
|
);
|
|
|
|
expect(result.formattedTime).toBe("Saturday, May 30th, 2026 - 12:00 PM");
|
|
expect(result.timeLine).toContain("Reference UTC: 2026-05-30 12:00 UTC");
|
|
});
|
|
|
|
it("falls back to epoch when both nowMs and Date.now are outside Date range", () => {
|
|
// If both inputs are invalid, epoch is the deterministic last resort.
|
|
vi.spyOn(Date, "now").mockReturnValue(8_640_000_000_000_001);
|
|
|
|
const result = resolveCronStyleNow(
|
|
{ agents: { defaults: { userTimezone: "UTC", timeFormat: "24" } } },
|
|
8_640_000_000_000_001,
|
|
);
|
|
|
|
expect(result.timeLine).toContain("Reference UTC: 1970-01-01 00:00 UTC");
|
|
});
|
|
});
|
|
|
|
const CFG = {
|
|
agents: {
|
|
defaults: {
|
|
userTimezone: "UTC",
|
|
},
|
|
},
|
|
};
|
|
|
|
describe("appendCronStyleCurrentTimeLine", () => {
|
|
it("returns the empty input unchanged", () => {
|
|
expect(appendCronStyleCurrentTimeLine("", CFG, Date.now())).toBe("");
|
|
});
|
|
|
|
it("appends a Current time line when none is present", () => {
|
|
const out = appendCronStyleCurrentTimeLine(
|
|
"Heartbeat tick",
|
|
CFG,
|
|
Date.parse("2026-04-30T10:00:00Z"),
|
|
);
|
|
expect(out).toContain("Heartbeat tick");
|
|
expect(out).toMatch(/Reference UTC: 2026-04-30 10:00 UTC/);
|
|
});
|
|
|
|
it("refreshes an existing Current time line on subsequent calls (#44993)", () => {
|
|
const oldNow = Date.parse("2026-04-30T08:00:00Z");
|
|
const newNow = Date.parse("2026-04-30T10:00:00Z");
|
|
const firstPass = appendCronStyleCurrentTimeLine("Heartbeat tick", CFG, oldNow);
|
|
expect(firstPass).toMatch(/Reference UTC: 2026-04-30 08:00 UTC/);
|
|
|
|
const secondPass = appendCronStyleCurrentTimeLine(firstPass, CFG, newNow);
|
|
expect(secondPass).toContain("Heartbeat tick");
|
|
expect(secondPass).toMatch(/Reference UTC: 2026-04-30 10:00 UTC/);
|
|
expect(secondPass).not.toMatch(/Reference UTC: 2026-04-30 08:00 UTC/);
|
|
expect(secondPass.match(/Current time:/g)?.length).toBe(1);
|
|
});
|
|
|
|
it("collapses multiple Current time blocks into a single fresh entry", () => {
|
|
const stale = [
|
|
"Heartbeat tick",
|
|
"Current time: Wednesday, January 1st, 2025 - 12:00 AM (UTC)\nReference UTC: 2025-01-01 00:00 UTC",
|
|
"Current time: Thursday, January 2nd, 2025 - 12:00 AM (UTC)\nReference UTC: 2025-01-02 00:00 UTC",
|
|
].join("\n");
|
|
const newNow = Date.parse("2026-04-30T10:00:00Z");
|
|
const out = appendCronStyleCurrentTimeLine(stale, CFG, newNow);
|
|
expect(out).toContain("Heartbeat tick");
|
|
expect(out).toMatch(/Reference UTC: 2026-04-30 10:00 UTC/);
|
|
expect(out).not.toMatch(/Reference UTC: 2025-01-01 00:00 UTC/);
|
|
expect(out).not.toMatch(/Reference UTC: 2025-01-02 00:00 UTC/);
|
|
expect(out.match(/Current time:/g)?.length).toBe(1);
|
|
});
|
|
|
|
it("matches helper blocks with natural-language formattedTime (#44993 codex P1)", () => {
|
|
const helperShape =
|
|
"Heartbeat tick\nCurrent time: Thursday, April 30th, 2026 - 10:00 AM (Asia/Seoul)\nReference UTC: 2026-04-30 01:00 UTC";
|
|
const newNow = Date.parse("2026-04-30T10:00:00Z");
|
|
const out = appendCronStyleCurrentTimeLine(helperShape, CFG, newNow);
|
|
expect(out).not.toMatch(/Asia\/Seoul/);
|
|
expect(out.match(/Current time:/g)?.length).toBe(1);
|
|
expect(out).toMatch(/Reference UTC: 2026-04-30 10:00 UTC/);
|
|
});
|
|
|
|
it("preserves user-authored content that starts with 'Current time:'", () => {
|
|
const userContent = "Reminder from cron:\nCurrent time: please check the dashboard before EOD";
|
|
const newNow = Date.parse("2026-04-30T10:00:00Z");
|
|
const out = appendCronStyleCurrentTimeLine(userContent, CFG, newNow);
|
|
expect(out).toContain("Reminder from cron:");
|
|
expect(out).toContain("Current time: please check the dashboard before EOD");
|
|
expect(out).toMatch(/Current time: .+? \(UTC\)\nReference UTC: 2026-04-30 10:00 UTC/);
|
|
expect(out.match(/Current time:/g)?.length).toBe(2);
|
|
});
|
|
});
|