11// Real browser proof that agent model fallbacks follow the Gateway's ownership contract.
2+ import { mkdir } from "node:fs/promises" ;
3+ import path from "node:path" ;
24import { expect , it } from "vitest" ;
35import { installMockGateway } from "../test-helpers/control-ui-e2e.ts" ;
46import { createControlUiE2eSuite } from "./control-ui-e2e-suite.test-support.ts" ;
@@ -11,6 +13,9 @@ const suite = createControlUiE2eSuite({
1113
1214const primaryModel = "openai/gpt-5.4" ;
1315const inheritedFallback = "anthropic/claude-sonnet-4-6" ;
16+ const writerWorkspace = "/tmp/agents/writer" ;
17+ const captureUiProof = process . env . OPENCLAW_CAPTURE_UI_PROOF === "1" ;
18+ const proofDir = path . resolve ( ".artifacts/control-ui-e2e/agent-context-ownership" ) ;
1419
1520suite . define ( ( ) => {
1621 it . each ( [
@@ -39,6 +44,11 @@ suite.define(() => {
3944 model : { primary : primaryModel , fallbacks : [ "google/gemini-3-pro" ] } ,
4045 expectedFallbacks : [ "google/gemini-3-pro" ] ,
4146 } ,
47+ {
48+ name : "combines an inherited primary with agent-only fallback configuration" ,
49+ model : { fallbacks : [ "google/gemini-3-pro" ] } ,
50+ expectedFallbacks : [ "google/gemini-3-pro" ] ,
51+ } ,
4252 ] ) ( "$name" , async ( { model, expectedFallbacks } ) => {
4353 await suite . withPage (
4454 {
@@ -49,7 +59,10 @@ suite.define(() => {
4959 async ( { page } ) => {
5060 const config = {
5161 agents : {
52- defaults : { model : { primary : primaryModel , fallbacks : [ inheritedFallback ] } } ,
62+ defaults : {
63+ workspace : "/tmp/agents" ,
64+ model : { primary : primaryModel , fallbacks : [ inheritedFallback ] } ,
65+ } ,
5366 entries : {
5467 main : { default : true } ,
5568 writer : model === undefined ? { } : { model } ,
@@ -64,7 +77,13 @@ suite.define(() => {
6477 scope : "agent" ,
6578 agents : [
6679 { id : "main" , identity : { name : "Main" } , name : "Main" } ,
67- { id : "writer" , identity : { name : "Writer" } , name : "Writer" } ,
80+ {
81+ id : "writer" ,
82+ identity : { name : "Writer" } ,
83+ name : "Writer" ,
84+ workspace : writerWorkspace ,
85+ model : { primary : primaryModel , fallbacks : expectedFallbacks } ,
86+ } ,
6887 ] ,
6988 } ,
7089 "config.get" : {
@@ -100,6 +119,30 @@ suite.define(() => {
100119 . poll ( ( ) => new URL ( page . url ( ) ) . pathname )
101120 . toBe ( "/settings/agents/writer/overview" ) ;
102121
122+ if ( captureUiProof && model && ! ( "primary" in Object ( model ) ) ) {
123+ await mkdir ( proofDir , { recursive : true } ) ;
124+ await page . screenshot ( {
125+ animations : "disabled" ,
126+ fullPage : true ,
127+ path : path . join (
128+ proofDir ,
129+ `${ process . env . OPENCLAW_UI_PROOF_LABEL ?? "agent-context" } .png` ,
130+ ) ,
131+ } ) ;
132+ }
133+
134+ await expect
135+ . poll ( ( ) => page . locator ( ".workspace-link" ) . textContent ( ) )
136+ . toContain ( writerWorkspace ) ;
137+ const modelDescription = page
138+ . locator ( ".settings-kv dt" )
139+ . filter ( { hasText : "Primary Model" } )
140+ . locator ( "xpath=following-sibling::dd[1]" ) ;
141+ const displayedModel = expectedFallbacks . length
142+ ? `${ primaryModel } (+${ expectedFallbacks . length } fallback)`
143+ : primaryModel ;
144+ await expect . poll ( ( ) => modelDescription . textContent ( ) ) . toContain ( displayedModel ) ;
145+
103146 const fallbackInput = page . locator ( ".agent-chip-input" ) ;
104147 await fallbackInput . waitFor ( { timeout : 10_000 } ) ;
105148 await expect
0 commit comments