test(license): 退出授权降级语义测试同步——远端失败清本机+标记而非报错保留
CI / Backend (go vet + test) (push) Waiting to run
CI / Frontend (lint + build + test) (push) Waiting to run

This commit is contained in:
opsx committed 2026-11-01 04:08:12 +08:00
1 parent daa531f4ed
commit 8423192719
1 file changed
+9 -8
+9 -8
View File
@@ -79,6 +79,8 @@ func TestDeactivateLicenseOfflineLocalOnly(t *testing.T) {
}
}
// 远端解绑失败时不再报错卡死(用户无法自愈),降级为清本机 + offlineLocalOnly 标记;
// 授权服务不返回 activation_token 的现实下,"保留本地等重试"等于永远解不了绑。
func TestDeactivateLicenseOnlineKeepsStateOnRemoteFailure(t *testing.T) {
withTempDB(t)
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -101,16 +103,15 @@ func TestDeactivateLicenseOnlineKeepsStateOnRemoteFailure(t *testing.T) {
db.RequestSave()
db.Unlock()
_, err := DeactivateLicense()
if err == nil {
t.Fatal("expected remote failure")
res, err := DeactivateLicense()
if err != nil {
t.Fatalf("远端失败应降级成功而非报错: %v", err)
}
if !strings.Contains(err.Error(), "远端解绑失败") {
t.Fatalf("unexpected err: %v", err)
if !res.OfflineLocalOnly {
t.Fatal("远端失败降级时应标记 OfflineLocalOnly")
}
stored := StoredLicense()
if stored == nil || stored.LicenseKey != "LIC-KEEP-ON-FAIL" || stored.Plan != "pro" {
t.Fatalf("must keep local state on failure: %+v", stored)
if StoredLicense() != nil {
t.Fatal("降级后本机授权应已清除")
}
}