Skip to content

Commit 84ba5b9

Browse files
zhangguiping-xydtsteipete
authored andcommitted
test(pr): isolate wrapper command inventory
1 parent 408111f commit 84ba5b9

2 files changed

Lines changed: 17 additions & 29 deletions

File tree

‎src/gateway/server-methods/board.test.ts‎

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,19 +1008,27 @@ describe("board gateway methods", () => {
10081008
expect(triggerCronJob).toHaveBeenCalledWith("job-1", expect.any(Object));
10091009
});
10101010

1011-
it("caps board.event payloads at 8KB and notices at 500 characters", async () => {
1011+
it("caps board.event payloads and preserves Unicode at the notice boundary", async () => {
10121012
const { invoke } = createHarness();
10131013
await invoke("board.widget.put", {
10141014
sessionKey: "session",
10151015
name: "counter",
10161016
content: { kind: "html", html: "ok" },
10171017
});
1018+
const clippedCodeUnits = 500 - "[dashboard] ".length - " on widget counter".length - 1;
1019+
// JSON's opening quote places the emoji across the legacy slice boundary.
1020+
const payload = `${"x".repeat(clippedCodeUnits - 2)}😀tail`;
1021+
await invoke("board.event", { sessionKey: "session", widget: "counter", payload });
1022+
const unicodeNotice = peekSystemEvents("session")[0] ?? "";
1023+
expect(unicodeNotice.length).toBeLessThanOrEqual(500);
1024+
expect(unicodeNotice).not.toContain(String.fromCharCode(0xd83d));
1025+
expect(unicodeNotice).toMatch(/… on widget counter$/u);
10181026
await invoke("board.event", {
10191027
sessionKey: "session",
10201028
widget: "counter",
10211029
payload: "x".repeat(1_000),
10221030
});
1023-
expect(peekSystemEvents("session")[0]).toHaveLength(500);
1031+
expect(peekSystemEvents("session")[1]).toHaveLength(500);
10241032
const oversized = await invoke("board.event", {
10251033
sessionKey: "session",
10261034
widget: "counter",
@@ -1029,31 +1037,6 @@ describe("board gateway methods", () => {
10291037
expect(oversized.mock.calls[0]?.[0]).toBe(false);
10301038
});
10311039

1032-
it("does not split surrogate pairs when truncating board.event notices", async () => {
1033-
const { invoke } = createHarness();
1034-
await invoke("board.widget.put", {
1035-
sessionKey: "session",
1036-
name: "counter",
1037-
content: { kind: "html", html: "ok" },
1038-
});
1039-
const prefix = "[dashboard] ";
1040-
const suffix = " on widget counter";
1041-
const clippedCodeUnits = 500 - prefix.length - suffix.length - 1;
1042-
1043-
// JSON serialization adds a leading quote, placing the emoji's high surrogate
1044-
// at the old slice boundary when the payload contains clippedCodeUnits - 2 ASCII units.
1045-
await invoke("board.event", {
1046-
sessionKey: "session",
1047-
widget: "counter",
1048-
payload: `${"x".repeat(clippedCodeUnits - 2)}😀tail`,
1049-
});
1050-
1051-
const notice = peekSystemEvents("session")[0] ?? "";
1052-
expect(notice.length).toBeLessThanOrEqual(500);
1053-
expect(notice).not.toContain(String.fromCharCode(0xd83d));
1054-
expect(notice).toMatch(/… on widget counter$/u);
1055-
});
1056-
10571040
it("keeps board state across the real sessions.reset handler", async () => {
10581041
const sessionKey = "agent:main:board-reset-proof";
10591042
const stateDir = tempDirs.make("openclaw-board-reset-");

‎test/scripts/pr-wrappers.test.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ function makeMismatchedWrapperRepo() {
3939
const originPath = join(root, "origin.git");
4040
mkdirSync(bin, { recursive: true });
4141
mkdirSync(home, { recursive: true });
42-
writeFileSync(join(bin, "rg"), "#!/usr/bin/env sh\nexit 0\n");
43-
chmodSync(join(bin, "rg"), 0o755);
42+
// This fixture exercises wrapper trust routing, not the host command inventory.
43+
for (const command of ["jq", "pnpm", "rg"]) {
44+
const commandPath = join(bin, command);
45+
writeFileSync(commandPath, "#!/bin/sh\nexit 0\n");
46+
chmodSync(commandPath, 0o755);
47+
}
4448

4549
const fixtureEnv = {
4650
...process.env,
@@ -186,6 +190,7 @@ describe("scripts/pr wrappers", () => {
186190
try {
187191
rmSync(join(fixture.bin, "rg"));
188192
for (const command of ["bash", "basename", "dirname", "git", "jq", "pnpm", "node"]) {
193+
rmSync(join(fixture.bin, command), { force: true });
189194
symlinkSync(resolveCommand(command), join(fixture.bin, command));
190195
}
191196

0 commit comments

Comments
 (0)