@@ -290,8 +290,18 @@ describe("applyServerUiPrefs", () => {
290290
291291 it ( "ignores a server custom theme until this browser imported one" , ( ) => {
292292 const onApplied = vi . fn ( ) ;
293- expect ( applyServerUiPrefs ( configWithPrefs ( { theme : "custom" } ) , { onApplied } ) ) . toBe ( false ) ;
293+ const onThemeChanged = vi . fn ( ) ;
294+ expect (
295+ applyServerUiPrefs ( configWithPrefs ( { theme : "custom" } ) , { onApplied, onThemeChanged } ) ,
296+ ) . toBe ( false ) ;
294297 expect ( loadSettings ( ) . theme ) . toBe ( "claw" ) ;
298+ expect ( onThemeChanged ) . toHaveBeenLastCalledWith ( "custom" ) ;
299+
300+ expect (
301+ applyServerUiPrefs ( configWithPrefs ( { theme : "claw" } ) , { onApplied, onThemeChanged } ) ,
302+ ) . toBe ( false ) ;
303+ expect ( onThemeChanged ) . toHaveBeenLastCalledWith ( "claw" ) ;
304+ expect ( onApplied ) . not . toHaveBeenCalled ( ) ;
295305 } ) ;
296306} ) ;
297307
@@ -457,6 +467,37 @@ describe("pushServerUiPrefs", () => {
457467 JSON . parse ( localStorage . getItem ( pendingKey ( scope ) ) ?? "{}" ) as Record < string , unknown > ;
458468 const createClient = createServerPrefsWriter ;
459469
470+ it ( "does not publish a server theme change shadowed by pending local intent" , async ( ) => {
471+ const scope = "ws://gw" ;
472+ const requestGate = deferred ( ) ;
473+ const request = vi . fn < ( method : string , params ?: unknown ) => Promise < unknown > > (
474+ ( ) => requestGate . promise ,
475+ ) ;
476+ const client = createClient ( request , scope ) ;
477+ const onApplied = vi . fn ( ) ;
478+ const onThemeChanged = vi . fn ( ) ;
479+ applyServerUiPrefs ( configWithPrefs ( { theme : "claw" } ) , {
480+ scope,
481+ onApplied,
482+ onThemeChanged,
483+ } ) ;
484+ onThemeChanged . mockClear ( ) ;
485+
486+ pushServerUiPrefs ( client , { theme : "knot" } ) ;
487+ await vi . waitFor ( ( ) => expect ( request ) . toHaveBeenCalledOnce ( ) ) ;
488+ expect (
489+ applyServerUiPrefs ( configWithPrefs ( { theme : "knot" } ) , {
490+ scope,
491+ onApplied,
492+ onThemeChanged,
493+ } ) ,
494+ ) . toBe ( false ) ;
495+ expect ( onThemeChanged ) . not . toHaveBeenCalled ( ) ;
496+
497+ requestGate . resolve ( { } ) ;
498+ await vi . waitFor ( ( ) => expect ( localStorage . getItem ( pendingKey ( scope ) ) ) . toBeNull ( ) ) ;
499+ } ) ;
500+
460501 it ( "keeps a synced default reset as a pending offline null intent" , ( ) => {
461502 const scope = "ws://gw" ;
462503 const previous = loadSettings ( ) ;
0 commit comments