feat: migrate account usage to CLIProxyAPI
Frontend / quality (push) Canceled after 0s

This commit is contained in:
2026-09-08 09:56:08 +08:00
parent 0b2f969c6d
commit 8997886eef
35 changed files with 2778 additions and 1651 deletions
+19 -7
View File
@@ -3,6 +3,7 @@ package store
import (
"context"
"database/sql"
"fmt"
"path/filepath"
"testing"
@@ -33,18 +34,26 @@ func TestAccountsAndPerAccountUsage(t *testing.T) {
}
defer s.DB.Close()
accounts, err := s.Accounts()
if err != nil || len(accounts) != 1 || accounts[0].ID != 1 || accounts[0].PublicVisible {
t.Fatalf("default accounts = %#v, %v", accounts, err)
if err != nil || len(accounts) != 0 {
t.Fatalf("fresh accounts = %#v, %v; want no automatic default account", accounts, err)
}
second, err := s.CreateAccount("Team workspace")
first, err := s.CreateAccount("Personal workspace", "auth-personal")
if err != nil {
t.Fatal(err)
}
for _, id := range []int64{1, second.ID} {
second, err := s.CreateAccount("Team workspace", "auth-team")
if err != nil {
t.Fatal(err)
}
for _, id := range []int64{first.ID, second.ID} {
if _, err = s.DB.Exec("INSERT INTO daily_usage(account_id,date,total_tokens,fetched_at) VALUES(?,?,?,?)", id, "2026-08-13", id*100, 1); err != nil {
t.Fatal(err)
}
}
if _, err = s.DB.Exec(`INSERT INTO notifications
(dedupe_key,channel,kind,status,scheduled_at,body) VALUES(?, 'configured', 'after', 'pending', 1, '{}')`, fmt.Sprintf("%d:codex:primary:1:after", second.ID)); err != nil {
t.Fatal(err)
}
if err = s.DeleteAccount(second.ID); err != nil {
t.Fatal(err)
}
@@ -52,6 +61,9 @@ func TestAccountsAndPerAccountUsage(t *testing.T) {
if err = s.DB.QueryRow("SELECT COUNT(*) FROM daily_usage WHERE account_id=?", second.ID).Scan(&count); err != nil || count != 0 {
t.Fatalf("usage was not cascaded: %d, %v", count, err)
}
if err = s.DB.QueryRow("SELECT COUNT(*) FROM notifications WHERE dedupe_key GLOB ?", fmt.Sprintf("%d:*", second.ID)).Scan(&count); err != nil || count != 0 {
t.Fatalf("notifications were not deleted: %d, %v", count, err)
}
}
func TestAccountKindAndValidation(t *testing.T) {
@@ -97,7 +109,7 @@ func TestExistingAccountsGainExpectedKind(t *testing.T) {
if err != nil || len(accounts) != 1 {
t.Fatalf("accounts = %#v, %v", accounts, err)
}
if accounts[0].ExpectedKind != "any" || accounts[0].PublicVisible || accounts[0].ActualKind != "team" || accounts[0].ValidationStatus != "matched" {
if accounts[0].AuthIndex != "" || accounts[0].ExpectedKind != "any" || accounts[0].PublicVisible || accounts[0].Connected || accounts[0].ActualKind != "team" || accounts[0].ValidationStatus != "pending" {
t.Fatalf("migrated account = %#v", accounts[0])
}
}
@@ -109,11 +121,11 @@ func TestAccountVisibilitySettings(t *testing.T) {
}
defer s.DB.Close()
private, err := s.CreateAccount("私有账号")
private, err := s.CreateAccount("私有账号", "private-auth")
if err != nil {
t.Fatal(err)
}
public, err := s.CreateAccountWithVisibility("公开账号", "team", true)
public, err := s.CreateAccountWithVisibility("公开账号", "public-auth", "team", true)
if err != nil {
t.Fatal(err)
}