@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
22import {
33 rewriteCopilotConnectionBoundResponseIds ,
44 rewriteCopilotResponsePayloadConnectionBoundIds ,
5+ sanitizeCopilotReplayResponseIds ,
56} from "./connection-bound-ids.js" ;
67
78describe ( "github-copilot connection-bound response IDs" , ( ) => {
@@ -35,7 +36,7 @@ describe("github-copilot connection-bound response IDs", () => {
3536 expect ( input [ 4 ] ?. id ) . toMatch ( / ^ m s g _ [ a - f 0 - 9 ] { 16 } $ / ) ;
3637 } ) ;
3738
38- it ( "preserves reasoning IDs regardless of encrypted_content" , ( ) => {
39+ it ( "preserves valid reasoning IDs regardless of encrypted_content" , ( ) => {
3940 const withEncrypted = Buffer . from ( `reasoning-${ "e" . repeat ( 24 ) } ` ) . toString ( "base64" ) ;
4041 const withNull = Buffer . from ( `reasoning-${ "n" . repeat ( 24 ) } ` ) . toString ( "base64" ) ;
4142 const withoutField = Buffer . from ( `reasoning-${ "a" . repeat ( 24 ) } ` ) . toString ( "base64" ) ;
@@ -51,6 +52,38 @@ describe("github-copilot connection-bound response IDs", () => {
5152 expect ( input [ 2 ] ?. id ) . toBe ( withoutField ) ;
5253 } ) ;
5354
55+ 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+
5487 it ( "patches response payload input arrays only" , ( ) => {
5588 const messageId = Buffer . from ( `message-${ "m" . repeat ( 24 ) } ` ) . toString ( "base64" ) ;
5689 const payload = { input : [ { id : messageId , type : "message" } ] } ;
0 commit comments