1- import { EnvironmentId , MessageId , ThreadId , type AssistantCitation } from "@t3tools/contracts" ;
1+ import {
2+ ASSISTANT_CITATION_MAX_COMMENT_LENGTH ,
3+ ASSISTANT_CITATION_MAX_TEXT_LENGTH ,
4+ EnvironmentId ,
5+ MessageId ,
6+ ThreadId ,
7+ type AssistantCitation ,
8+ } from "@t3tools/contracts" ;
9+ import {
10+ MAX_CITATION_HREF_LENGTH ,
11+ formatAssistantCitationHref ,
12+ parseAssistantCitationHref ,
13+ } from "@t3tools/shared/assistantCitations" ;
214import {
315 createMemoryHistory ,
416 createRootRoute ,
@@ -24,6 +36,21 @@ const citation: AssistantCitation = {
2436 suffix : "\nAfter." ,
2537} ;
2638
39+ const largeCitation = {
40+ ...citation ,
41+ text : "引" . repeat ( ASSISTANT_CITATION_MAX_TEXT_LENGTH ) ,
42+ comment : "注" . repeat ( ASSISTANT_CITATION_MAX_COMMENT_LENGTH ) ,
43+ start : 0 ,
44+ end : ASSISTANT_CITATION_MAX_TEXT_LENGTH ,
45+ } ;
46+ const maximumCitation = {
47+ ...largeCitation ,
48+ messageId : MessageId . make (
49+ largeCitation . messageId +
50+ "m" . repeat ( MAX_CITATION_HREF_LENGTH - formatAssistantCitationHref ( largeCitation ) . length ) ,
51+ ) ,
52+ } ;
53+
2754function createCitationRouter ( initialEntry = "/environment-one/thread-one" ) {
2855 const root = createRootRoute ( ) ;
2956 const thread = createRoute ( { getParentRoute : ( ) => root , path : "/$environmentId/$threadId" } ) ;
@@ -34,25 +61,29 @@ function createCitationRouter(initialEntry = "/environment-one/thread-one") {
3461}
3562
3663describe ( "assistant citation navigation" , ( ) => {
37- it ( "preserves encoded quote whitespace through router navigation and reload" , async ( ) => {
38- const router = createCitationRouter ( ) ;
39- await router . navigate ( assistantCitationNavigation ( citation ) ) ;
64+ it . each ( [ citation , maximumCitation ] ) (
65+ "preserves encoded quotes through router navigation and reload (%#)" ,
66+ async ( citation ) => {
67+ expect ( parseAssistantCitationHref ( formatAssistantCitationHref ( citation ) ) ) . toEqual ( citation ) ;
68+ const router = createCitationRouter ( ) ;
69+ await router . navigate ( assistantCitationNavigation ( citation ) ) ;
4070
41- expect ( assistantCitationFromLocation ( router . state . location . href ) ) . toEqual ( citation ) ;
42- let href = router . history . location . href ;
43- for ( let reload = 0 ; reload < 3 ; reload ++ ) {
44- const reloaded = createCitationRouter ( href ) ;
45- await reloaded . load ( ) ;
46- await reloaded . navigate ( {
47- to : "/$environmentId/$threadId" ,
48- params : { environmentId : citation . environmentId , threadId : citation . threadId } ,
49- hash : true ,
50- replace : true ,
51- } ) ;
52- href = reloaded . history . location . href ;
53- expect ( assistantCitationFromLocation ( href ) ) . toEqual ( citation ) ;
54- }
55- } ) ;
71+ expect ( assistantCitationFromLocation ( router . state . location . href ) ) . toEqual ( citation ) ;
72+ let href = router . history . location . href ;
73+ for ( let reload = 0 ; reload < 3 ; reload ++ ) {
74+ const reloaded = createCitationRouter ( href ) ;
75+ await reloaded . load ( ) ;
76+ await reloaded . navigate ( {
77+ to : "/$environmentId/$threadId" ,
78+ params : { environmentId : citation . environmentId , threadId : citation . threadId } ,
79+ hash : true ,
80+ replace : true ,
81+ } ) ;
82+ href = reloaded . history . location . href ;
83+ expect ( assistantCitationFromLocation ( href ) ) . toEqual ( citation ) ;
84+ }
85+ } ,
86+ ) ;
5687
5788 it ( "reactivates an identical citation instead of deduplicating its navigation" , async ( ) => {
5889 const router = createCitationRouter ( ) ;
0 commit comments