@@ -6,6 +6,7 @@ import { test } from "node:test";
66import { createApp } from "../apps/server/src/app.ts" ;
77import { createStore } from "../apps/server/src/db.ts" ;
88import type { ActionProposal } from "../packages/domain/src/index.ts" ;
9+ import { browserFixture } from "./helpers/browser.ts" ;
910import { fixture as computerFixture } from "./helpers/computer.ts" ;
1011import { modelFixture } from "./helpers/model.ts" ;
1112
@@ -114,3 +115,68 @@ test("CopilotKit model worker executes server tools and persists the confirmed o
114115 await rm ( directory , { recursive : true , force : true } ) ;
115116 }
116117} ) ;
118+
119+
120+ test ( "browser reads keep observation identity distinct while reusing one session" , async ( t ) => {
121+ let currentUrl = "https://example.com/one" ;
122+ const sessionIds = new Set < string > ( ) ;
123+ const browser = await browserFixture ( t , ( path , body ) => {
124+ if ( path === "/sessions" ) {
125+ const id = String ( body . id ) ;
126+ currentUrl = String ( body . url ) ;
127+ sessionIds . add ( id ) ;
128+ return {
129+ data : {
130+ id,
131+ title : currentUrl ,
132+ url : currentUrl ,
133+ status : "active" ,
134+ updatedAt : new Date ( ) . toISOString ( ) ,
135+ } ,
136+ } ;
137+ }
138+ if ( path . endsWith ( "/read" ) ) {
139+ return {
140+ data : {
141+ url : currentUrl ,
142+ title : currentUrl . endsWith ( "/one" ) ? "Source one" : "Source two" ,
143+ text : `Evidence from ${ currentUrl } ` ,
144+ truncated : false ,
145+ } ,
146+ } ;
147+ }
148+ throw new Error ( `Unexpected browser path: ${ path } ` ) ;
149+ } ) ;
150+ const calls : { name : string ; arguments : object } [ ] = [
151+ { name : "read_web" , arguments : { url : "https://example.com/one" } } ,
152+ { name : "read_web" , arguments : { url : "https://example.com/two" } } ,
153+ { name : "finish_task" , arguments : { summary : "Compared both public sources." } } ,
154+ ] ;
155+ await modelFixture ( t , ( index ) => calls [ index ] ) ;
156+ const app = await createApp ( browser . db , {
157+ ...browser . config ,
158+ agentBackend : "model" ,
159+ model : "openai/fixture" ,
160+ } ) ;
161+ t . after ( ( ) => app . agent . stop ( ) ) ;
162+
163+ const task = await app . agent . createTask ( "owner" , {
164+ prompt : "Read both public sources and compare them." ,
165+ } ) ;
166+ await app . agent . worker . tick ( ) ;
167+
168+ const saved = await app . agent . getTask ( "owner" , task . id ) ;
169+ assert . equal ( saved . status , "succeeded" , saved . error ?? saved . question ) ;
170+ const webEvidence = saved . evidence . filter ( ( item ) => item . kind === "web" ) ;
171+ assert . equal ( webEvidence . length , 2 ) ;
172+ assert . deepEqual (
173+ webEvidence . map ( ( item ) => item . url ) ,
174+ [ "https://example.com/one" , "https://example.com/two" ] ,
175+ ) ;
176+ assert . equal ( sessionIds . size , 1 , "both reads should reuse the same browser session" ) ;
177+ assert . equal (
178+ new Set ( webEvidence . map ( ( item ) => item . id ) ) . size ,
179+ 2 ,
180+ "separate observations need separate evidence identities" ,
181+ ) ;
182+ } ) ;
0 commit comments