Skip to content

Commit cecd014

Browse files
committed
test(agents): tighten process label truncation coverage
1 parent cec3a49 commit cecd014

3 files changed

Lines changed: 9 additions & 33 deletions

File tree

src/agents/bash-process-references.test.ts

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,8 @@ import { addSession, deleteSession } from "./bash-process-registry.js";
44
import { createProcessSessionFixture } from "./bash-process-registry.test-helpers.js";
55

66
describe("bash-process-references truncation", () => {
7-
it("keeps surrogate pairs intact when truncating session names", () => {
8-
const command = `echo ${"😀".repeat(200)}`;
9-
addSession(
10-
createProcessSessionFixture({
11-
id: "emoji-proc",
12-
command,
13-
backgrounded: true,
14-
startedAt: 1,
15-
}),
16-
);
17-
18-
try {
19-
const [reference] = listActiveProcessSessionReferences({
20-
scopeKey: undefined,
21-
});
22-
expect(reference).toBeUndefined();
23-
const scoped = listActiveProcessSessionReferences({ scopeKey: "scope-a", now: 2 });
24-
expect(scoped).toEqual([]);
25-
} finally {
26-
deleteSession("emoji-proc");
27-
}
28-
});
29-
30-
it("keeps surrogate pairs intact for scoped background session labels", () => {
31-
const command = `python ${"😀".repeat(200)}`;
7+
it("keeps scoped session labels valid when the limit bisects an emoji", () => {
8+
const command = `${"a".repeat(136)}😀xyz`;
329
const session = createProcessSessionFixture({
3310
id: "emoji-proc-scoped",
3411
command,
@@ -40,8 +17,7 @@ describe("bash-process-references truncation", () => {
4017

4118
try {
4219
const [reference] = listActiveProcessSessionReferences({ scopeKey: "scope-a", now: 2 });
43-
expect(reference?.name).not.toContain("�");
44-
expect(reference?.name.length).toBeLessThanOrEqual(140);
20+
expect(reference?.name).toBe(`${"a".repeat(136)}...`);
4521
} finally {
4622
deleteSession("emoji-proc-scoped");
4723
}

src/agents/bash-process-references.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { truncateUtf16Safe } from "../utils.js";
21
/**
32
* Compact references for active background bash sessions.
43
* These references are surfaced in agent context so follow-up turns can
54
* reconnect to prior long-running work.
65
*/
6+
import { truncateUtf16Safe } from "../utils.js";
77
import { listRunningSessions } from "./bash-process-registry.js";
88
import { deriveSessionName } from "./bash-tools.shared.js";
99

src/agents/tools/web-fetch-utils.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ describe("web-fetch-utils htmlToMarkdown entity decoding", () => {
2222
});
2323

2424
it("decodes & last so an escaped entity is not double-decoded", () => {
25+
// "'" is the correct HTML encoding of the literal text "'" and must survive intact.
2526
expect(htmlToMarkdown(`<p>Tom &amp;#39;s pub</p>`).text).toBe("Tom &#39;s pub");
2627
});
2728

@@ -30,8 +31,12 @@ describe("web-fetch-utils htmlToMarkdown entity decoding", () => {
3031
});
3132

3233
it("preserves the prior contract: uppercase named entities decode, malformed numeric stays literal", () => {
34+
// web_fetch historically matched named entities case-insensitively, so
35+
// uppercase forms must keep decoding rather than leaking through as text.
3336
expect(htmlToMarkdown(`<p>a &AMP; b</p>`).text).toBe("a & b");
3437
expect(htmlToMarkdown(`<p>x &QUOT;y&QUOT;</p>`).text).toBe('x "y"');
38+
// A malformed numeric reference is not an entity and must survive as text,
39+
// not be consumed by a lenient parseInt (e.g. "&#39x;" must not become "'").
3540
expect(htmlToMarkdown(`<p>&#39x; end</p>`).text).toBe("&#39x; end");
3641
});
3742

@@ -43,9 +48,4 @@ describe("web-fetch-utils htmlToMarkdown entity decoding", () => {
4348
expect(result.text).toBe(prefix);
4449
expect(result.text).not.toContain(String.fromCharCode(0xd83d));
4550
});
46-
47-
it("truncates extracted text without splitting surrogate pairs", () => {
48-
expect(truncateText("😀abc", 1)).toEqual({ text: "", truncated: true });
49-
expect(truncateText("😀😀x", 3)).toEqual({ text: "😀", truncated: true });
50-
});
5151
});

0 commit comments

Comments
 (0)