1- import { projectionFor } from "./fixtures/shared.ts" ;
2- import type { ProviderReplayEntry } from "@t3tools/contracts" ;
3- import { assert , describe , it } from "@effect/vitest" ;
1+ import { describe } from "@effect/vitest" ;
42
53import {
64 materializeMuseReplayWorkspace ,
75 MuseOrchestratorReplayHarness ,
86} from "../Adapters/MuseAdapterV2.testkit.ts" ;
9- import {
10- findReplayFixture ,
11- itRunsReplayFixtures ,
12- runReplayFixture ,
13- } from "./ProviderReplayFixtures.ts" ;
7+ import { itRunsReplayFixtures , runReplayFixture } from "./ProviderReplayFixtures.ts" ;
148
159describe ( "Muse replay fixtures" , ( ) => {
1610 itRunsReplayFixtures ( "muse" , ( input ) =>
@@ -20,265 +14,4 @@ describe("Muse replay fixtures", () => {
2014 materializeWorkspace : materializeMuseReplayWorkspace ,
2115 } ) ,
2216 ) ;
23- it . effect (
24- "keeps Muse answers and decisions across native acknowledgement and turn cleanup" ,
25- ( ) => {
26- const fixture = findReplayFixture ( "simple" ) ;
27- const provider = fixture ?. providers . find ( ( candidate ) => candidate . driver === "muse" ) ;
28- assert . isDefined ( fixture ) ;
29- assert . isDefined ( provider ) ;
30- const answers = { approach : [ "Small" , "Keep tests focused" ] } ;
31- return runReplayFixture ( {
32- harness : MuseOrchestratorReplayHarness ,
33- materializeWorkspace : materializeMuseReplayWorkspace ,
34- fixtureName : fixture . name ,
35- buildInput : ( ) => ( {
36- ...fixture . buildInput ( ) ,
37- steps : [
38- ...fixture . buildInput ( ) . steps ,
39- { type : "answer_next_user_input_request" , answers } ,
40- { type : "answer_next_user_input_request" , answers } ,
41- { type : "approve_next_runtime_request" , decision : "acceptForSession" } ,
42- ] ,
43- } ) ,
44- driver : {
45- ...provider ,
46- assertOutput : ( result ) => {
47- const projection = projectionFor ( result , fixture . name ) ;
48- assert . equal ( projection . runs . at ( - 1 ) ?. status , "completed" ) ;
49- assert . lengthOf ( projection . runtimeRequests , 3 ) ;
50- const observed = [ ] ;
51- const expected = [ ] ;
52- for ( const nativeId of [ "question-ack" , "question-no-ack" , "approval-no-ack" ] ) {
53- const request = projection . runtimeRequests . find (
54- ( candidate ) => candidate . nativeRequestRef ?. nativeId === nativeId ,
55- ) ;
56- assert . isDefined ( request ) ;
57- const card = projection . turnItems . find ( ( item ) => item . nodeId === request . nodeId ) ;
58- const node = projection . nodes . find ( ( candidate ) => candidate . id === request . nodeId ) ;
59- const isQuestion = request . kind === "user_input" ;
60- const response = isQuestion ? { answers } : { decision : "acceptForSession" as const } ;
61- const submitted = result . domainEvents . find (
62- ( event ) =>
63- event . type === "runtime-request.updated" &&
64- event . payload . id === request . id &&
65- event . payload . status === "resolved" ,
66- ) ;
67- assert . isDefined ( submitted , `${ nativeId } was persisted before native delivery` ) ;
68- assert . deepInclude ( submitted . payload , response ) ;
69- if ( ! isQuestion ) {
70- const assistantItemIndex = result . domainEvents . findIndex (
71- ( event ) =>
72- event . type === "turn-item.updated" &&
73- event . payload . type === "assistant_message" ,
74- ) ;
75- const submittedIndex = result . domainEvents . indexOf ( submitted ) ;
76- assert . isAbove ( assistantItemIndex , submittedIndex ) ;
77- // The next assistant item is persisted after stageResolved, before turn cleanup.
78- const beforeAssistant = result . domainEvents . slice ( 0 , assistantItemIndex ) ;
79- const requestAtUpdate = beforeAssistant . findLast (
80- ( event ) =>
81- event . type === "runtime-request.updated" && event . payload . id === request . id ,
82- ) ;
83- const nodeAtUpdate = beforeAssistant . findLast (
84- ( event ) => event . type === "node.updated" && event . payload . id === request . nodeId ,
85- ) ;
86- const cardAtUpdate = beforeAssistant . findLast (
87- ( event ) =>
88- event . type === "turn-item.updated" && event . payload . nodeId === request . nodeId ,
89- ) ;
90- assert . deepInclude (
91- requestAtUpdate ?. payload ,
92- { status : "resolved" , decision : "acceptForSession" } ,
93- "stageResolved must preserve the persisted T3 decision before turn cleanup" ,
94- ) ;
95- assert . deepInclude ( nodeAtUpdate ?. payload , { status : "completed" } ) ;
96- assert . deepInclude ( cardAtUpdate ?. payload , { status : "completed" } ) ;
97- }
98- observed . push ( {
99- nativeId,
100- status : request . status ,
101- answers : request . answers ,
102- decision : request . decision ,
103- nodeStatus : node ?. status ,
104- cardStatus : card ?. status ,
105- questionAnswer :
106- card ?. type === "user_input_request" ? card . questionAnswer : undefined ,
107- } ) ;
108- expected . push ( {
109- nativeId,
110- status : "resolved" ,
111- answers : isQuestion ? answers : undefined ,
112- decision : isQuestion ? undefined : "acceptForSession" ,
113- nodeStatus : "completed" ,
114- cardStatus : "completed" ,
115- questionAnswer : isQuestion
116- ? {
117- requestId : request . id ,
118- answers,
119- attachmentsByQuestionId : { } ,
120- questionTextById : { approach : "Which approach?" } ,
121- }
122- : undefined ,
123- } as const ) ;
124- }
125- assert . deepEqual ( observed , expected ) ;
126- } ,
127- } ,
128- transformTranscript : ( transcript ) => {
129- const at = transcript . entries . findIndex (
130- ( entry ) => entry . type === "emit_inbound" && entry . label === "turn/started" ,
131- ) ;
132- const started = transcript . entries [ at ] ;
133- assert . isDefined ( started ) ;
134- if ( started . type !== "emit_inbound" ) assert . fail ( "Missing Muse turn/started" ) ;
135- const { sessionId, turnId } = (
136- started . frame as {
137- readonly params : { readonly sessionId : string ; readonly turnId : string } ;
138- }
139- ) . params ;
140- const metadata = transcript . metadata as {
141- readonly commandIds : ReadonlyArray < ReadonlyArray < string > > ;
142- } ;
143- return {
144- ...transcript ,
145- metadata : {
146- ...transcript . metadata ,
147- commandIds : [
148- [ ...metadata . commandIds [ 0 ] ! , "answer-ack" , "answer-no-ack" , "approve-no-ack" ] ,
149- ] ,
150- } ,
151- entries : [
152- ...transcript . entries . slice ( 0 , at + 1 ) ,
153- ...[ "question-ack" , "question-no-ack" ] . flatMap (
154- ( userInputId , index ) : ProviderReplayEntry [ ] => [
155- {
156- type : "emit_inbound" ,
157- frame : {
158- jsonrpc : "2.0" ,
159- method : "userInput/requested" ,
160- params : {
161- sessionId,
162- turnId,
163- userInputId,
164- questions : [
165- {
166- id : "approach" ,
167- header : "Approach" ,
168- question : "Which approach?" ,
169- options : [ { label : "Small" } , { label : "Large" } ] ,
170- selection : { mode : "single" } ,
171- } ,
172- ] ,
173- } ,
174- } ,
175- } ,
176- {
177- type : "expect_outbound" ,
178- frame : {
179- jsonrpc : "2.0" ,
180- id : 4 + index ,
181- method : "userInput/answer" ,
182- params : {
183- sessionId,
184- userInputId,
185- commandId : index === 0 ? "answer-ack" : "answer-no-ack" ,
186- answers : [
187- {
188- questionId : "approach" ,
189- selectedLabel : "Small" ,
190- note : "Keep tests focused" ,
191- } ,
192- ] ,
193- } ,
194- } ,
195- } ,
196- { type : "emit_inbound" , frame : { jsonrpc : "2.0" , id : 4 + index , result : { } } } ,
197- ...( index === 0
198- ? [
199- {
200- type : "emit_inbound" as const ,
201- frame : {
202- jsonrpc : "2.0" ,
203- method : "userInput/settled" ,
204- params : { sessionId, turnId, userInputId } ,
205- } ,
206- } ,
207- ]
208- : [ ] ) ,
209- ] ,
210- ) ,
211- {
212- type : "emit_inbound" ,
213- frame : {
214- jsonrpc : "2.0" ,
215- method : "approval/requested" ,
216- params : {
217- sessionId,
218- turnId,
219- approvalId : "approval-no-ack" ,
220- currentRequirementId : { approvalId : "approval-no-ack" , sourceIndex : 0 } ,
221- availableChoices : [
222- {
223- choiceId : "session" ,
224- label : "Allow for session" ,
225- decision : "approvedForSession" ,
226- scope : "session" ,
227- } ,
228- ] ,
229- subject : { kind : "shell" , command : "touch result.txt" } ,
230- } ,
231- } ,
232- } ,
233- {
234- type : "expect_outbound" ,
235- frame : {
236- jsonrpc : "2.0" ,
237- id : 6 ,
238- method : "approval/decide" ,
239- params : {
240- sessionId,
241- approvalId : "approval-no-ack" ,
242- commandId : "approve-no-ack" ,
243- requirementId : { approvalId : "approval-no-ack" , sourceIndex : 0 } ,
244- choiceId : "session" ,
245- } ,
246- } ,
247- } ,
248- { type : "emit_inbound" , frame : { jsonrpc : "2.0" , id : 6 , result : { } } } ,
249- {
250- type : "emit_inbound" ,
251- frame : {
252- jsonrpc : "2.0" ,
253- method : "approval/updated" ,
254- params : {
255- sessionId,
256- turnId,
257- approvalId : "approval-no-ack" ,
258- currentRequirementId : { approvalId : "approval-no-ack" , sourceIndex : 0 } ,
259- availableChoices : [
260- {
261- choiceId : "session" ,
262- label : "Allow for session" ,
263- decision : "approvedForSession" ,
264- scope : "session" ,
265- } ,
266- ] ,
267- subject : { kind : "shell" , command : "touch result.txt" } ,
268- change : {
269- kind : "stageResolved" ,
270- requirementId : { approvalId : "approval-no-ack" , sourceIndex : 0 } ,
271- choiceId : "session" ,
272- decision : "approvedForSession" ,
273- } ,
274- } ,
275- } ,
276- } ,
277- ...transcript . entries . slice ( at + 1 ) ,
278- ] ,
279- } ;
280- } ,
281- } ) ;
282- } ,
283- ) ;
28417} ) ;
0 commit comments