@@ -114,6 +114,7 @@ type interactiveHTTPModel struct {
114114 args map [string ]any
115115 called bool
116116 principal execution.Principal
117+ validatePrincipal func (context.Context , * model.LLMRequest , execution.Principal )
117118 t * testing.T
118119}
119120
@@ -127,7 +128,9 @@ func (m *interactiveHTTPModel) GenerateContent(ctx context.Context, req *model.L
127128 return originalYield (scriptedHTTPProgressiveResponse (req , response ), err )
128129 }
129130 p , _ := execution .PrincipalFromContext (ctx )
130- if p .Subject != m .principal .Subject || p .Authentication != m .principal .Authentication || p .Surface != m .principal .Surface {
131+ if m .validatePrincipal != nil {
132+ m .validatePrincipal (ctx , req , p )
133+ } else if p .Subject != m .principal .Subject || p .Authentication != m .principal .Authentication || p .Surface != m .principal .Surface {
131134 m .t .Errorf ("provider lost original principal: %+v" , p )
132135 }
133136 if response , ok := scriptedEmployeeReview (req ); ok {
@@ -416,8 +419,9 @@ func newInteractiveHTTPFixture(t *testing.T, toolName string, args map[string]an
416419 files := newComposedHTTPFiles (t , dir , repo , b , func (name string , args map [string ]interface {}) (json.RawMessage , error ) {
417420 return pool .Call ("" , name , args )
418421 })
419- workerConfig := daemon.BotWorkerConfig {Backend : db , Sandbox : synthesisHTTPBackend {files : files .disk }, Pool : pool , TurnRegistry : registry , WorkerID : uuid .NewString (), ContextWindow : 8192 , ModelOptions : provider.BudgetLLMOptions {MaxOutputTokens : 100 , SupportsOutputLimit : true }, ResolveModel : func (context.Context , execution.Principal , store.BotScope , string , string ) (model.LLM , error ) {
420- return mdl , nil
422+ mediatedModel := mediateHTTPModel (mdl )
423+ workerConfig := daemon.BotWorkerConfig {Backend : db , Sandbox : synthesisHTTPBackend {files : files .disk }, Pool : pool , TurnRegistry : registry , WorkerID : uuid .NewString (), ContextWindow : 8192 , LeaseTTL : 4 * time .Second , ModelOptions : provider.BudgetLLMOptions {MaxOutputTokens : 100 , SupportsOutputLimit : true }, ResolveModel : func (context.Context , execution.Principal , store.BotScope , string , string ) (model.LLM , error ) {
424+ return mediatedModel , nil
421425 }, Prepare : func (c context.Context , q bot.RunRequest , s * launcher.BotChatScope ) (* launcher.BotChatSafeResources , error ) {
422426 // Title-start fixtures may create another Bot in this same tenant.
423427 runFiles := * files
@@ -439,6 +443,7 @@ func newInteractiveHTTPFixture(t *testing.T, toolName string, args map[string]an
439443 return work
440444 }
441445 resources := & launcher.BotChatSafeResources {WorkspaceDir : "/isolated" , ChatConfig : & config.AppConfig {}, Catalog : & launcher.ChatCatalogResources {Pool : pool }, VerifyIsolation : func (c context.Context ) error { return c .Err () }, Cleanup : func () {}}
446+ resources .PolicyRuntime = agent.BotPolicyRuntime {Classifier : composedWeatherClassifier {}, Guard : interactiveFixtureGuard {repo : repo , req : q }}
442447 if ! q .Run .IsInteractiveChat () {
443448 resources .Tools , err = launcher .BotCatalogueTools (pool , q .Run .SessionID .String ())
444449 if err != nil {
@@ -662,9 +667,9 @@ func TestBotAgentCheckHTTPAcceptance(t *testing.T) {
662667 return & model.LLMResponse {Content : & genai.Content {Role : "model" , Parts : []* genai.Part {part }}, UsageMetadata : & genai.GenerateContentResponseUsageMetadata {PromptTokenCount : 5 , CandidatesTokenCount : 3 , TotalTokenCount : 8 }}, true
663668 }
664669 run := f .capabilityTurn (mode , []string {"read_file" , "bot_evidence_read" , "bot_check_work" })
665- // Four producer turns plus the explicitly requested optional check;
666- // no mandatory end-of-run content review is charged .
667- if run .Usage .InputTokens != 31 || run .Usage .OutputTokens != 19 || run .Usage .ToolCalls != 3 {
670+ // Four producer turns, one private Chat action/result pair and the
671+ // explicitly requested optional check share the run ledger .
672+ if run .Usage .InputTokens != 41 || run .Usage .OutputTokens != 25 || run .Usage .ToolCalls != 3 {
668673 t .Fatalf ("optional check did not share producer budget: %+v" , run .Usage )
669674 }
670675 if run .Status != store .RunSucceeded || step != 4 || checks != 1 || f .pool .calls != 1 || run .Report .Work == nil || len (run .Report .Work .Checks ) != 1 {
@@ -807,7 +812,7 @@ func TestBotAgentSourceFallbackHTTPAcceptance(t *testing.T) {
807812 if run .Status != store .RunSucceeded || step != 6 || checks != 1 || f .pool .calls != 2 || requests ["/primary" ] != 1 || requests ["/alternative" ] != 1 {
808813 t .Fatalf ("fallback blocked/replayed: run=%+v step=%d checks=%d requests=%v" , run , step , checks , requests )
809814 }
810- if run .Usage .InputTokens != 46 || run .Usage .OutputTokens != 28 || run .Usage .ToolCalls != 5 {
815+ if run .Usage .InputTokens != 66 || run .Usage .OutputTokens != 40 || run .Usage .ToolCalls != 5 {
811816 t .Fatalf ("fallback/check budget not shared: %+v" , run .Usage )
812817 }
813818 if run .Report .Work == nil || len (run .Report .Work .Checks ) != 1 || run .Report .Work .Checks [0 ].Status != store .BotWorkCheckFailed || run .Report .Work .Checks [0 ].Judgment != store .BotWorkCheckUnverified {
@@ -901,13 +906,18 @@ func TestBotInteractiveChatHTTPAcceptance(t *testing.T) {
901906 if err := json .Unmarshal (f .request ("POST" , f .path + "/pause" , fmt .Sprintf (`{"expected_revision":%d,"reason":"pause before chat"}` , f .b .Revision ), 200 ), & f .b ); err != nil {
902907 t .Fatal (err )
903908 }
909+ f .model .called = true // Paused conversations must not dispatch private Chat work.
904910 }
905911 f .model .chatOnly = true
906912 run := f .turn ()
907913 if ! f .model .deliverySet || run .Report .Summary != "Observed scoped result." || len (run .Report .Artifacts ) != 0 {
908914 t .Fatalf ("short conversation changed: %+v" , run )
909915 }
910- if f .pool .calls != 1 || run .Status != store .RunSucceeded || len (run .Report .Unverified ) != 0 || len (run .Report .Unchanged ) != 2 || run .Usage .ToolCalls != 2 {
916+ wantCalls , wantEvidence := 1 , 3
917+ if paused {
918+ wantCalls , wantEvidence = 0 , 1
919+ }
920+ if f .pool .calls != wantCalls || run .Status != store .RunSucceeded || len (run .Report .Unverified ) != 0 || len (run .Report .Unchanged ) != wantEvidence || run .Usage .ToolCalls != int64 (wantCalls + 1 ) {
911921 t .Fatalf ("tool runtime calls=%d run=%+v" , f .pool .calls , run )
912922 }
913923 })
@@ -920,7 +930,7 @@ func TestBotInteractivePersonalHTTPAcceptance(t *testing.T) {
920930 if ! f .model .deliverySet || run .Report .Summary != "Observed scoped result." || len (run .Report .Artifacts ) != 0 {
921931 t .Fatalf ("short conversation changed: %+v" , run )
922932 }
923- if f .pool .calls != 1 || run .Status != store .RunSucceeded || len (run .Report .Unverified ) != 0 || len (run .Report .Unchanged ) != 2 || run .Usage .ToolCalls != 2 {
933+ if f .pool .calls != 1 || run .Status != store .RunSucceeded || len (run .Report .Unverified ) != 0 || len (run .Report .Unchanged ) != 3 || run .Usage .ToolCalls != 2 {
924934 t .Fatalf ("personal runtime calls=%d run=%+v" , f .pool .calls , run )
925935 }
926936}
0 commit comments