Files
UHD_Media_Tool/apps/server/test/schedules/render-goal.test.ts
T
rootandClaude Opus 5.5 23bd8cfe45 fix(web): 巡检目标模板的占位符显示成名称(FIX-7)
执行时 renderGoal 已正确替换(补单测);界面显示的是模板本身,{{now}} 等改成「当前时间」标签。

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-09-30 00:00:03 +08:00

27 lines
1.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { BUILTIN_AGENT_CHECKS, renderGoal } from "../../src/modules/schedules/agent-checks.ts";
// FIX-7:界面上看到的 {{now}} / {{openDecisions}} 是模板本身;执行时必须全部替换成实际值。
describe("renderGoal(巡检目标模板)", () => {
const now = new Date("2026-09-28T18:53:50.468Z");
const facts = { openDecisions: 3, stalledDownloads: 1, activeSubscriptions: 5 };
it("内置巡检的模板执行时不留占位符", () => {
for (const c of BUILTIN_AGENT_CHECKS) {
const goal = renderGoal(c.config.goalTemplate, now, facts);
expect(goal).not.toMatch(/\{\{/);
}
const pending = BUILTIN_AGENT_CHECKS.find((c) => c.key === "check.pending");
expect(renderGoal(pending?.config.goalTemplate ?? "", now, facts)).toContain(
"巡检待处理(2026-09-28T18:53:50.468Z):有 3 条未关闭的待处理事项",
);
});
it("容许空格;不认识的占位符原样保留", () => {
expect(renderGoal("{{ date }} 待处理 {{openDecisions}} 条 {{other}}", now, facts)).toBe(
"2026-09-28 待处理 3 条 {{other}}",
);
});
});