@@ -3,6 +3,7 @@ import { onTestFinished } from "vite-plus/test";
33import { page } from "vite-plus/test/browser" ;
44import { stubGlobal } from "../../../test/render" ;
55import {
6+ ComposerContextId ,
67 EnvironmentId ,
78 MessageId ,
89 RunAttemptId ,
@@ -32,6 +33,11 @@ import { toastManager } from "../ui/toast";
3233import type { CitedHistory } from "./citationProcedure" ;
3334import type { TimelineNavigation } from "./timelineViewport" ;
3435import { rememberTimelinePosition } from "./timelineScrollAnchoring" ;
36+ import {
37+ COMPOSER_CONTEXT_CLIPBOARD_MIME ,
38+ decodeComposerContextFragment ,
39+ } from "@t3tools/shared/composerContextClipboard" ;
40+ import { collectComposerContextReferences } from "@t3tools/shared/composerContextReferences" ;
3541
3642const environmentQuery = vi . hoisted ( ( ) => ( {
3743 error : "Pull request not found" ,
@@ -642,6 +648,75 @@ describe("MessagesTimeline agent messages", () => {
642648} ) ;
643649
644650describe ( "MessagesTimeline attachments" , ( ) => {
651+ it . each ( [ "image" , "file" ] as const ) (
652+ "copies only matching context records for a wordless %s attachment" ,
653+ async ( kind ) => {
654+ const attachment = {
655+ type : kind ,
656+ id : "media" ,
657+ name : kind === "image" ? "photo.png" : "clip.mp4" ,
658+ mimeType : kind === "image" ? "image/png" : "video/mp4" ,
659+ sizeBytes : 100 ,
660+ downloadable : false ,
661+ } ;
662+ const record = {
663+ version : 1 as const ,
664+ ...( kind === "image" ? { kind : "image" as const } : { kind : "file" as const } ) ,
665+ contextId : ComposerContextId . make ( "media-context" ) ,
666+ label : attachment . name ,
667+ attachmentId : attachment . id ,
668+ name : attachment . name ,
669+ mimeType : attachment . mimeType ,
670+ sizeBytes : attachment . sizeBytes ,
671+ } ;
672+ await using screen = await renderTimeline ( [ message ( "" , { attachments : [ attachment ] } ) ] ) ;
673+ expect ( screen . buttons ( "Copy message" ) ) . toHaveLength ( 0 ) ;
674+ await screen . rerender (
675+ < MessagesTimeline
676+ { ...baseProps ( ) }
677+ timelineEntries = { [
678+ message ( "" , {
679+ attachments : [ attachment ] ,
680+ context : { version : 1 , records : [ { ...record , attachmentId : "other" } ] } ,
681+ } ) ,
682+ ] }
683+ /> ,
684+ ) ;
685+ expect ( screen . buttons ( "Copy message" ) ) . toHaveLength ( 0 ) ;
686+ await screen . rerender (
687+ < MessagesTimeline
688+ { ...baseProps ( ) }
689+ timelineEntries = { [
690+ message ( "" , {
691+ attachments : [ attachment ] ,
692+ context : {
693+ version : 1 ,
694+ records : [
695+ record ,
696+ {
697+ ...record ,
698+ contextId : ComposerContextId . make ( "other-context" ) ,
699+ attachmentId : "other" ,
700+ } ,
701+ ] ,
702+ } ,
703+ } ) ,
704+ ] }
705+ /> ,
706+ ) ;
707+ using write = vi . spyOn ( navigator . clipboard , "write" ) . mockResolvedValue ( ) ;
708+ await click ( screen . button ( "Copy message" ) ) ;
709+ await vi . waitFor ( ( ) => expect ( write ) . toHaveBeenCalledOnce ( ) ) ;
710+ const [ item ] = write . mock . calls [ 0 ] ! [ 0 ] ;
711+ const text = await ( await item ! . getType ( "text/plain" ) ) . text ( ) ;
712+ const fragment = await ( await item ! . getType ( COMPOSER_CONTEXT_CLIPBOARD_MIME ) ) . text ( ) ;
713+ expect (
714+ collectComposerContextReferences ( text ) . map ( ( reference ) => reference . contextId ) ,
715+ ) . toEqual ( [ record . contextId ] ) ;
716+ expect ( decodeComposerContextFragment ( fragment ) ?. records ) . toEqual ( [ record ] ) ;
717+ } ,
718+ ) ;
719+
645720 it . each ( [ "loadedmetadata" , "loadeddata" , "canplay" ] ) (
646721 "plays audio with unknown duration after %s and updates the total later" ,
647722 async ( readyEvent ) => {
0 commit comments