Skip to content

Commit e410730

Browse files
committed
fix(session): strip trailing punct from extracted user-text URLs
`new URL` keeps a trailing period in the hostname, so a summary that names api.com misses Call HTTP://API.COM. as an exactName.
1 parent 8076151 commit e410730

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎src/session/compaction-verify.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,27 @@ describe("extractContinuationFacts", () => {
126126
]);
127127
expect(facts.exactNames).toContain("HTTP://API.COM");
128128
});
129+
130+
test("sentence-final period is not part of a user-text URL", () => {
131+
const facts = extractContinuationFacts([
132+
textTurn("user", "Call HTTP://API.COM."),
133+
]);
134+
expect(facts.exactNames).toContain("HTTP://API.COM");
135+
expect(facts.exactNames).not.toContain("HTTP://API.COM.");
136+
expect(
137+
verifyCompactionSummary("Call api.com", facts).misses.some(
138+
(m) => m.kind === "exactName",
139+
),
140+
).toBe(false);
141+
});
142+
143+
test("comma glue is not part of a user-text URL", () => {
144+
const facts = extractContinuationFacts([
145+
textTurn("user", "Call HTTP://API.COM, then retry"),
146+
]);
147+
expect(facts.exactNames).toContain("HTTP://API.COM");
148+
expect(facts.exactNames).not.toContain("HTTP://API.COM,");
149+
});
129150
});
130151

131152
describe("verifyCompactionSummary", () => {

‎src/session/compaction-verify.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,13 @@ function hostnameOf(url: string): string | undefined {
256256
}
257257
}
258258

259+
// User-text URLs sit next to sentence punct (`Call HTTP://API.COM.`).
260+
// `new URL` keeps a trailing `.` in the hostname, so a summary that
261+
// names `api.com` would miss the exactName.
262+
function stripUrlGlue(match: string): string {
263+
return match.replace(/[.,;:!]+$/, "");
264+
}
265+
259266
/**
260267
* Pull the continuation facts out of the turns a fold is about to drop.
261268
* Deterministic and total: no fact means nothing to verify, never an abort.
@@ -297,7 +304,8 @@ export function extractContinuationFacts(
297304
}
298305
for (const text of [...users, ...assistants]) {
299306
for (const match of text.match(/https?:\/\/[^\s)]+/gi) ?? []) {
300-
if (!exactNames.includes(match)) exactNames.push(match);
307+
const url = stripUrlGlue(match);
308+
if (url.length > 0 && !exactNames.includes(url)) exactNames.push(url);
301309
}
302310
}
303311

0 commit comments

Comments
 (0)