


























@@ -47,25 +47,50 @@ describe("heartbeat event prompts", () => {
4747it.each([
4848{
4949name: "builds user-relay exec prompt by default",
50+events: ["Exec finished (node=abc id=123, code 0)\nUploaded file"],
5051opts: undefined,
51-expected: ["Please relay the command output to the user", "If it failed"],
52-unexpected: ["Handle the result internally"],
52+expected: [
53+"Exec finished",
54+"Uploaded file",
55+"Please relay the command output to the user",
56+"If it failed",
57+],
58+unexpected: ["system messages above", "Handle the result internally"],
5359},
5460{
5561name: "builds internal-only exec prompt when delivery is disabled",
62+events: ["Exec failed (node=abc id=123, code 1)\nUpload failed"],
5663opts: { deliverToUser: false },
57-expected: ["Handle the result internally"],
58-unexpected: ["Please relay the command output to the user"],
64+expected: ["user delivery is disabled", "Handle the result internally", "HEARTBEAT_OK only"],
65+unexpected: [
66+"Upload failed",
67+"system messages above",
68+"Please relay the command output to the user",
69+],
5970},
60-])("$name", ({ opts, expected, unexpected }) => {
61-const prompt = buildExecEventPrompt(opts);
71+{
72+name: "suppresses empty exec completion prompts",
73+events: ["", " "],
74+opts: undefined,
75+expected: ["no command output was found", "Reply HEARTBEAT_OK only"],
76+unexpected: ["Please relay the command output to the user", "system messages above"],
77+},
78+])("$name", ({ events, opts, expected, unexpected }) => {
79+const prompt = buildExecEventPrompt(events, opts);
6280for (const part of expected) {
6381expect(prompt).toContain(part);
6482}
6583for (const part of unexpected) {
6684expect(prompt).not.toContain(part);
6785}
6886});
87+88+it("truncates oversized user-relay exec prompt output", () => {
89+const prompt = buildExecEventPrompt([`Exec finished: ${"x".repeat(8_100)}`]);
90+91+expect(prompt).toContain("[truncated]");
92+expect(prompt.length).toBeLessThan(8_500);
93+});
6994});
70957196describe("heartbeat event classification", () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。