@@ -111,3 +111,45 @@ func TestFileTokenStore_Save_MergesPartialMetadataWithExistingAuthFile(t *testin
111111 t .Fatalf ("name=%#v, want codex.json (raw=%s)" , got , string (raw ))
112112 }
113113}
114+
115+ func TestFileTokenStore_Save_PreservesExistingPriorityWhenAbsentFromUpdate (t * testing.T ) {
116+ ctx := context .Background ()
117+ baseDir := t .TempDir ()
118+ path := filepath .Join (baseDir , "codex.json" )
119+
120+ // The on-disk file carries a priority the update payload does not include;
121+ // saving partial metadata must not drop it.
122+ seed := `{"type":"codex","access_token":"access","priority":7}`
123+ if err := os .WriteFile (path , []byte (seed ), 0o600 ); err != nil {
124+ t .Fatalf ("seed auth file: %v" , err )
125+ }
126+
127+ store := NewFileTokenStore ()
128+ store .SetBaseDir (baseDir )
129+ auth := & cliproxyauth.Auth {
130+ ID : "codex.json" ,
131+ Provider : "codex" ,
132+ FileName : "codex.json" ,
133+ Metadata : map [string ]any {"name" : "codex.json" },
134+ }
135+
136+ if _ , err := store .Save (ctx , auth ); err != nil {
137+ t .Fatalf ("Save() error: %v" , err )
138+ }
139+
140+ raw , err := os .ReadFile (path )
141+ if err != nil {
142+ t .Fatalf ("read auth file: %v" , err )
143+ }
144+ var meta map [string ]any
145+ if err := json .Unmarshal (raw , & meta ); err != nil {
146+ t .Fatalf ("unmarshal auth file: %v" , err )
147+ }
148+ // JSON numbers decode to float64.
149+ if got , _ := meta ["priority" ].(float64 ); got != 7 {
150+ t .Fatalf ("priority=%#v, want preserved 7 (raw=%s)" , meta ["priority" ], string (raw ))
151+ }
152+ if got := meta ["access_token" ]; got != "access" {
153+ t .Fatalf ("access_token=%#v, want preserved access (raw=%s)" , got , string (raw ))
154+ }
155+ }
0 commit comments