intelligent_test_auth.go 1.1 KB

1234567891011121314151617181920212223242526
  1. package service
  2. import (
  3. "errors"
  4. "strings"
  5. "time"
  6. )
  7. var errIntelligentCredentialRefreshRequired = errors.New("账号认证缺失、过期或需要更新;请先在账号管理中单独刷新认证,再运行测试。智能测试不会自动刷新 access_token 或注册认证任务")
  8. // Capability observations use the authoritative account snapshot. Reading a
  9. // shared provider cache or calling RefreshIfNeeded may otherwise auto-detect a
  10. // project, change route metadata, quarantine the account or rotate a refresh
  11. // token through a repository that is outside the runner's read-only wrapper.
  12. // Block before the exchange: discarding an already rotated token is unsafe.
  13. func intelligentExistingAccessToken(account *Account) (string, error) {
  14. if account == nil {
  15. return "", errIntelligentCredentialRefreshRequired
  16. }
  17. token := strings.TrimSpace(account.GetCredential("access_token"))
  18. expires := account.GetCredentialAsTime("expires_at")
  19. if token == "" || expires == nil || !time.Now().Before(*expires) {
  20. return "", errIntelligentCredentialRefreshRequired
  21. }
  22. return token, nil
  23. }