File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -145,6 +145,20 @@ describe('createConfigStore', () => {
145145 expect ( reloaded . getOrigin ( ) ) . toBe ( 'https://self-hosted.example' )
146146 } )
147147
148+ it ( 'canonicalizes the apex production origin on setOrigin, not just on load' , ( ) => {
149+ // Entering https://sim.ai mid-session must not persist the apex: the
150+ // running session would use the wrong cookie partition and misclassify
151+ // social login until the next launch's load-time rewrite repaired it.
152+ const filePath = tempSettingsPath ( )
153+ const store = createConfigStore ( filePath , { } )
154+ const result = store . setOrigin ( 'https://sim.ai' )
155+ expect ( result ) . toEqual ( { ok : true , origin : 'https://www.sim.ai' } )
156+ expect ( store . getOrigin ( ) ) . toBe ( 'https://www.sim.ai' )
157+
158+ const reloaded = createConfigStore ( filePath , { } )
159+ expect ( reloaded . getOrigin ( ) ) . toBe ( 'https://www.sim.ai' )
160+ } )
161+
148162 it ( 'recovers from a corrupted settings file' , ( ) => {
149163 const filePath = tempSettingsPath ( )
150164 writeFileSync ( filePath , '{not json' )
Original file line number Diff line number Diff line change @@ -328,14 +328,22 @@ export function createConfigStore(
328328 } ,
329329 setOrigin ( raw : string ) {
330330 const validated = validateOriginInput ( raw )
331- if ( validated . ok ) {
332- settings . origin = validated . origin
333- // Not debounced: changing the origin tears the session down and
334- // reloads, so a pending write could be lost on the way out — and this
335- // is the one setting whose loss strands the app on the wrong server.
336- writeNow ( )
331+ if ( ! validated . ok ) {
332+ return validated
337333 }
338- return validated
334+ // Same canonicalization the load path applies (ORIGIN_REWRITES).
335+ // Without it, entering the apex origin mid-session persists it and
336+ // immediately drives the wrong cookie partition and social-login
337+ // classification for the rest of the session — the load-time rewrite
338+ // only repairs it on the next launch. The canonical origin is also
339+ // returned so the caller sees what was actually stored.
340+ const origin = canonicalOrigin ( validated . origin )
341+ settings . origin = origin
342+ // Not debounced: changing the origin tears the session down and
343+ // reloads, so a pending write could be lost on the way out — and this
344+ // is the one setting whose loss strands the app on the wrong server.
345+ writeNow ( )
346+ return { ok : true , origin }
339347 } ,
340348 get ( key ) {
341349 return settings [ key ]
You can’t perform that action at this time.
0 commit comments