





























@@ -278,6 +278,58 @@ describe("pruneStaleModelRunEntries", () => {
278278),
279279).toBe(false);
280280});
281+282+it("rejects non-canonical session keys that do not parse as agent-scoped", () => {
283+// Unscoped: missing `agent:<id>:` prefix — parseAgentSessionKey returns null.
284+expect(
285+isGatewayModelRunSessionKey("explicit:model-run-123e4567-e89b-12d3-a456-426614174000"),
286+).toBe(false);
287+// Empty agent id segment: not a canonical `agent:<id>:` scoped key.
288+expect(
289+isGatewayModelRunSessionKey("agent::explicit:model-run-123e4567-e89b-12d3-a456-426614174000"),
290+).toBe(false);
291+// Extra colon segment between agent id and `explicit:` — rest starts
292+// with `extra:` and fails the predicate's regex.
293+expect(
294+isGatewayModelRunSessionKey(
295+"agent:main:extra:explicit:model-run-123e4567-e89b-12d3-a456-426614174000",
296+),
297+).toBe(false);
298+// Whitespace-padded keys are non-canonical even though parseAgentSessionKey
299+// trims before normalizing; the predicate intentionally checks the original
300+// key shape before accepting a model-run key.
301+expect(
302+isGatewayModelRunSessionKey(
303+" agent:main:explicit:model-run-123e4567-e89b-12d3-a456-426614174000",
304+),
305+).toBe(false);
306+expect(
307+isGatewayModelRunSessionKey(
308+"agent:main:explicit:model-run-123e4567-e89b-12d3-a456-426614174000 ",
309+),
310+).toBe(false);
311+});
312+313+it("matches canonical keys whose agent id begins with model-run-", () => {
314+// Guards against an over-tight fix that confuses the agent id segment
315+// with the `explicit:model-run-<uuid>` rest segment.
316+expect(
317+isGatewayModelRunSessionKey(
318+"agent:model-run-foo:explicit:model-run-123e4567-e89b-12d3-a456-426614174000",
319+),
320+).toBe(true);
321+});
322+323+it("preserves case-insensitive matching for canonical keys", () => {
324+// normalizeLowercaseStringOrEmpty + parseAgentSessionKey's normalization
325+// lower-case everything outside opaque peer IDs, so a mixed-case
326+// canonical key still matches.
327+expect(
328+isGatewayModelRunSessionKey(
329+"agent:Main:Explicit:Model-Run-123E4567-E89B-12D3-A456-426614174000",
330+),
331+).toBe(true);
332+});
281333});
282334283335describe("capEntryCount", () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。