@@ -50,6 +50,60 @@ describe("fetch-router", () => {
5050 expect ( result ) . toBeNull ( ) ;
5151 } ) ;
5252
53+ it ( "matches GET /threads" , ( ) => {
54+ const result = matchRoute ( "/api/copilotkit/threads" , basePath ) ;
55+ expect ( result ) . toEqual ( { method : "threads/list" } ) ;
56+ } ) ;
57+
58+ it ( "matches POST /threads/subscribe" , ( ) => {
59+ const result = matchRoute ( "/api/copilotkit/threads/subscribe" , basePath ) ;
60+ expect ( result ) . toEqual ( { method : "threads/subscribe" } ) ;
61+ } ) ;
62+
63+ it ( "matches PATCH /threads/:threadId" , ( ) => {
64+ const result = matchRoute (
65+ "/api/copilotkit/threads/thread-abc" ,
66+ basePath ,
67+ ) ;
68+ expect ( result ) . toEqual ( {
69+ method : "threads/update" ,
70+ threadId : "thread-abc" ,
71+ } ) ;
72+ } ) ;
73+
74+ it ( "matches POST /threads/:threadId/archive" , ( ) => {
75+ const result = matchRoute (
76+ "/api/copilotkit/threads/thread-abc/archive" ,
77+ basePath ,
78+ ) ;
79+ expect ( result ) . toEqual ( {
80+ method : "threads/archive" ,
81+ threadId : "thread-abc" ,
82+ } ) ;
83+ } ) ;
84+
85+ it ( "matches GET /threads/:threadId/messages" , ( ) => {
86+ const result = matchRoute (
87+ "/api/copilotkit/threads/thread-abc/messages" ,
88+ basePath ,
89+ ) ;
90+ expect ( result ) . toEqual ( {
91+ method : "threads/messages" ,
92+ threadId : "thread-abc" ,
93+ } ) ;
94+ } ) ;
95+
96+ it ( "handles URL-encoded threadId in thread routes" , ( ) => {
97+ const result = matchRoute (
98+ "/api/copilotkit/threads/thread%2F123" ,
99+ basePath ,
100+ ) ;
101+ expect ( result ) . toEqual ( {
102+ method : "threads/update" ,
103+ threadId : "thread/123" ,
104+ } ) ;
105+ } ) ;
106+
53107 it ( "returns null when basePath is a prefix but not a segment boundary" , ( ) => {
54108 const result = matchRoute ( "/api/copilotkitextra/info" , basePath ) ;
55109 expect ( result ) . toBeNull ( ) ;
@@ -124,6 +178,31 @@ describe("fetch-router", () => {
124178 expect ( result ) . toBeNull ( ) ;
125179 } ) ;
126180
181+ it ( "matches /threads suffix" , ( ) => {
182+ const result = matchRoute ( "/anything/threads" ) ;
183+ expect ( result ) . toEqual ( { method : "threads/list" } ) ;
184+ } ) ;
185+
186+ it ( "matches /threads/subscribe suffix" , ( ) => {
187+ const result = matchRoute ( "/anything/threads/subscribe" ) ;
188+ expect ( result ) . toEqual ( { method : "threads/subscribe" } ) ;
189+ } ) ;
190+
191+ it ( "matches /threads/:threadId suffix" , ( ) => {
192+ const result = matchRoute ( "/anything/threads/t1" ) ;
193+ expect ( result ) . toEqual ( { method : "threads/update" , threadId : "t1" } ) ;
194+ } ) ;
195+
196+ it ( "matches /threads/:threadId/archive suffix" , ( ) => {
197+ const result = matchRoute ( "/anything/threads/t1/archive" ) ;
198+ expect ( result ) . toEqual ( { method : "threads/archive" , threadId : "t1" } ) ;
199+ } ) ;
200+
201+ it ( "matches /threads/:threadId/messages suffix" , ( ) => {
202+ const result = matchRoute ( "/anything/threads/t1/messages" ) ;
203+ expect ( result ) . toEqual ( { method : "threads/messages" , threadId : "t1" } ) ;
204+ } ) ;
205+
127206 it ( "works with deeply nested mount prefix" , ( ) => {
128207 const result = matchRoute ( "/api/v2/copilotkit/agent/a1/run" ) ;
129208 expect ( result ) . toEqual ( { method : "agent/run" , agentId : "a1" } ) ;
0 commit comments