

























@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
22import {
33rewriteCopilotConnectionBoundResponseIds,
44rewriteCopilotResponsePayloadConnectionBoundIds,
5+sanitizeCopilotReplayResponseIds,
56} from "./connection-bound-ids.js";
6778describe("github-copilot connection-bound response IDs", () => {
@@ -35,7 +36,7 @@ describe("github-copilot connection-bound response IDs", () => {
3536expect(input[4]?.id).toMatch(/^msg_[a-f0-9]{16}$/);
3637});
373838-it("preserves reasoning IDs regardless of encrypted_content", () => {
39+it("preserves valid reasoning IDs regardless of encrypted_content", () => {
3940const withEncrypted = Buffer.from(`reasoning-${"e".repeat(24)}`).toString("base64");
4041const withNull = Buffer.from(`reasoning-${"n".repeat(24)}`).toString("base64");
4142const withoutField = Buffer.from(`reasoning-${"a".repeat(24)}`).toString("base64");
@@ -51,6 +52,38 @@ describe("github-copilot connection-bound response IDs", () => {
5152expect(input[2]?.id).toBe(withoutField);
5253});
535455+it("preserves valid base64-ish reasoning IDs with and without encrypted content", () => {
56+const withEncrypted = "abcDEF0123+/=";
57+const withoutEncrypted = "reasoning/abc+123=";
58+const input = [
59+{ id: withEncrypted, type: "reasoning", encrypted_content: "opaque-encrypted-payload" },
60+{ id: withoutEncrypted, type: "reasoning" },
61+];
62+63+expect(sanitizeCopilotReplayResponseIds(input)).toBe(false);
64+expect(input.map((item) => item.id)).toEqual([withEncrypted, withoutEncrypted]);
65+});
66+67+it("drops unsafe reasoning replay items instead of stripping their IDs", () => {
68+const overlongId = `5PX6gLHXT5wE+Y2tPmUV4gn+${"B".repeat(384)}`;
69+const input = [
70+{
71+id: overlongId,
72+type: "reasoning",
73+encrypted_content: "encrypted-replay-payload",
74+summary: [],
75+},
76+{ type: "reasoning", encrypted_content: "missing-id", summary: [] },
77+{ id: 123, type: "reasoning", encrypted_content: "non-string-id", summary: [] },
78+{ id: "rs_valid", type: "reasoning", encrypted_content: "valid", summary: [] },
79+];
80+81+expect(sanitizeCopilotReplayResponseIds(input)).toBe(true);
82+expect(input).toEqual([
83+{ id: "rs_valid", type: "reasoning", encrypted_content: "valid", summary: [] },
84+]);
85+});
86+5487it("patches response payload input arrays only", () => {
5588const messageId = Buffer.from(`message-${"m".repeat(24)}`).toString("base64");
5689const payload = { input: [{ id: messageId, type: "message" }] };
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。