@@ -8,7 +8,10 @@ import {
88} from '../src/runState' ;
99import { RunContext } from '../src/runContext' ;
1010import { Agent } from '../src/agent' ;
11- import { RunToolApprovalItem as ToolApprovalItem } from '../src/items' ;
11+ import {
12+ RunToolApprovalItem as ToolApprovalItem ,
13+ RunMessageOutputItem ,
14+ } from '../src/items' ;
1215import { computerTool } from '../src/tool' ;
1316import * as protocol from '../src/types/protocol' ;
1417import { TEST_MODEL_MESSAGE , FakeComputer } from './stubs' ;
@@ -31,6 +34,32 @@ describe('RunState', () => {
3134 expect ( state . _context . context ) . toEqual ( { foo : 'bar' } ) ;
3235 } ) ;
3336
37+ it ( 'returns history including original input and generated items' , ( ) => {
38+ const context = new RunContext ( ) ;
39+ const agent = new Agent ( { name : 'HistAgent' } ) ;
40+ const state = new RunState ( context , 'input' , agent , 1 ) ;
41+ state . _generatedItems . push (
42+ new RunMessageOutputItem ( TEST_MODEL_MESSAGE , agent ) ,
43+ ) ;
44+
45+ expect ( state . history ) . toEqual ( [
46+ { type : 'message' , role : 'user' , content : 'input' } ,
47+ TEST_MODEL_MESSAGE ,
48+ ] ) ;
49+ } ) ;
50+
51+ it ( 'preserves history after serialization' , async ( ) => {
52+ const context = new RunContext ( ) ;
53+ const agent = new Agent ( { name : 'HistAgent2' } ) ;
54+ const state = new RunState ( context , 'input' , agent , 1 ) ;
55+ state . _generatedItems . push (
56+ new RunMessageOutputItem ( TEST_MODEL_MESSAGE , agent ) ,
57+ ) ;
58+
59+ const restored = await RunState . fromString ( agent , state . toString ( ) ) ;
60+ expect ( restored . history ) . toEqual ( state . history ) ;
61+ } ) ;
62+
3463 it ( 'toJSON and toString produce valid JSON' , ( ) => {
3564 const context = new RunContext ( ) ;
3665 const agent = new Agent ( { name : 'Agent1' } ) ;
0 commit comments