test(desktop): cover deepseek account name extraction for wechat + phone logins
Desktop Client Build / Resolve Build Metadata (push) Successful in 28s
Frontend CI / Frontend (push) Successful in 4m5s
Backend CI / Backend (push) Successful in 17m7s
Desktop Client Build / Publish Client Artifacts to NAS (push) Has been cancelled
Desktop Client Build / Build Desktop Client (push) Has been cancelled
Desktop Client Build / Resolve Build Metadata (push) Successful in 28s
Frontend CI / Frontend (push) Successful in 4m5s
Backend CI / Backend (push) Successful in 17m7s
Desktop Client Build / Publish Client Artifacts to NAS (push) Has been cancelled
Desktop Client Build / Build Desktop Client (push) Has been cancelled
Refactor readDeepseekAccountIdentity so the JSON payload parser is a pure
ts function (extractDeepseekIdentityFromPayload). The webContents IIFE now
just polls for userToken and returns the raw API JSON; payload picking lives
in ts and is unit-tested.
Tests lock the contract for both login types we observed in the wild:
- WeChat-bound account: id_profile.name = '阿白', picture present.
- Phone-only login: id_profile = null, mobile_number = '177******08',
email = '' (empty string, not null) — the case that originally regressed.
Plus regressions for the priority order (profile.name > mobile_number > email),
the all-empty fallback, and non-record payloads.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -39,6 +39,7 @@ type monitorDesktopTaskSpec struct {
|
||||
Priority int
|
||||
Lane string
|
||||
InterruptGeneration int
|
||||
RequestedByUserID int64
|
||||
}
|
||||
|
||||
type monitorDesktopAccountCandidate struct {
|
||||
@@ -46,6 +47,7 @@ type monitorDesktopAccountCandidate struct {
|
||||
AccountID uuid.UUID
|
||||
DBClientID *uuid.UUID
|
||||
HealthRank int
|
||||
OnlineRank int
|
||||
RecordOrder int
|
||||
}
|
||||
|
||||
@@ -107,6 +109,7 @@ func (s *MonitoringService) loadMonitorDesktopTaskSpecs(
|
||||
questionIDs []int64,
|
||||
platformIDs []string,
|
||||
targetClientID uuid.UUID,
|
||||
requestedByUserID int64,
|
||||
) ([]monitorDesktopTaskSpec, error) {
|
||||
if q == nil || len(questionIDs) == 0 || len(platformIDs) == 0 {
|
||||
return nil, nil
|
||||
@@ -142,11 +145,10 @@ func (s *MonitoringService) loadMonitorDesktopTaskSpecs(
|
||||
AND t.business_date = $3::date
|
||||
AND t.status = 'pending'
|
||||
AND COALESCE(t.execution_owner, 'legacy') = 'desktop_tasks'
|
||||
AND t.target_client_id = $4
|
||||
AND t.question_id = ANY($5)
|
||||
AND t.ai_platform_id = ANY($6)
|
||||
AND t.question_id = ANY($4)
|
||||
AND t.ai_platform_id = ANY($5)
|
||||
ORDER BY t.dispatch_priority DESC, t.id ASC
|
||||
`, tenantID, monitoringCollectorType, businessDate.Format("2006-01-02"), targetClientID, questionIDs, platformIDs)
|
||||
`, tenantID, monitoringCollectorType, businessDate.Format("2006-01-02"), questionIDs, platformIDs)
|
||||
if err != nil {
|
||||
return nil, response.ErrInternal(50041, "query_failed", "failed to load phase2 monitor desktop task specs")
|
||||
}
|
||||
@@ -177,6 +179,7 @@ func (s *MonitoringService) loadMonitorDesktopTaskSpecs(
|
||||
}
|
||||
spec.WorkspaceID = workspaceID
|
||||
spec.TargetClientID = targetClientID
|
||||
spec.RequestedByUserID = requestedByUserID
|
||||
spec.BusinessDate = businessDay.Format("2006-01-02")
|
||||
spec.QuestionHash = encodeQuestionHash(questionHash)
|
||||
spec.SchedulerGroupKey = monitoringSchedulerGroupKey(spec.QuestionHash, spec.QuestionID, spec.QuestionText)
|
||||
@@ -196,7 +199,7 @@ func (s *MonitoringService) dispatchMonitorDesktopTasks(
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
targets, err := s.loadMonitorDesktopTaskTargets(ctx, specs[0].TenantID, specs[0].WorkspaceID, specs)
|
||||
targets, err := s.loadMonitorDesktopTaskTargets(ctx, specs[0].TenantID, specs[0].WorkspaceID, specs[0].RequestedByUserID, specs)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -240,7 +243,7 @@ func (s *MonitoringService) dispatchMonitorDesktopTasks(
|
||||
|
||||
func (s *MonitoringService) loadMonitorDesktopTaskTargets(
|
||||
ctx context.Context,
|
||||
tenantID, workspaceID int64,
|
||||
tenantID, workspaceID, userID int64,
|
||||
specs []monitorDesktopTaskSpec,
|
||||
) (map[string]monitorDesktopTaskTarget, error) {
|
||||
platformIDs := uniqueMonitorDesktopTaskPlatformIDs(specs)
|
||||
@@ -253,6 +256,20 @@ func (s *MonitoringService) loadMonitorDesktopTaskTargets(
|
||||
platform_id,
|
||||
desktop_id,
|
||||
COALESCE(client_id::text, '') AS client_id,
|
||||
CASE
|
||||
WHEN client_id IS NOT NULL
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM desktop_clients dc
|
||||
WHERE dc.id = platform_accounts.client_id
|
||||
AND dc.workspace_id = platform_accounts.workspace_id
|
||||
AND dc.revoked_at IS NULL
|
||||
AND dc.last_seen_at IS NOT NULL
|
||||
AND dc.last_seen_at >= NOW() - $5::interval
|
||||
)
|
||||
THEN 0
|
||||
ELSE 1
|
||||
END AS online_rank,
|
||||
CASE health
|
||||
WHEN 'live' THEN 0
|
||||
WHEN 'risk' THEN 1
|
||||
@@ -264,7 +281,22 @@ func (s *MonitoringService) loadMonitorDesktopTaskTargets(
|
||||
AND workspace_id = $2
|
||||
AND deleted_at IS NULL
|
||||
AND platform_id = ANY($3::text[])
|
||||
AND ($4::bigint = 0 OR user_id = $4)
|
||||
ORDER BY platform_id ASC,
|
||||
CASE
|
||||
WHEN client_id IS NOT NULL
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM desktop_clients dc
|
||||
WHERE dc.id = platform_accounts.client_id
|
||||
AND dc.workspace_id = platform_accounts.workspace_id
|
||||
AND dc.revoked_at IS NULL
|
||||
AND dc.last_seen_at IS NOT NULL
|
||||
AND dc.last_seen_at >= NOW() - $5::interval
|
||||
)
|
||||
THEN 0
|
||||
ELSE 1
|
||||
END ASC,
|
||||
CASE health
|
||||
WHEN 'live' THEN 0
|
||||
WHEN 'risk' THEN 1
|
||||
@@ -274,7 +306,7 @@ func (s *MonitoringService) loadMonitorDesktopTaskTargets(
|
||||
verified_at DESC NULLS LAST,
|
||||
updated_at DESC,
|
||||
created_at DESC
|
||||
`, tenantID, workspaceID, platformIDs)
|
||||
`, tenantID, workspaceID, platformIDs, userID, formatPgInterval(desktopClientPresenceTTL))
|
||||
if err != nil {
|
||||
return nil, response.ErrInternal(50117, "desktop_account_lookup_failed", "failed to resolve monitor desktop accounts")
|
||||
}
|
||||
@@ -286,7 +318,7 @@ func (s *MonitoringService) loadMonitorDesktopTaskTargets(
|
||||
item monitorDesktopAccountCandidate
|
||||
clientIDText string
|
||||
)
|
||||
if scanErr := rows.Scan(&item.PlatformID, &item.AccountID, &clientIDText, &item.HealthRank); scanErr != nil {
|
||||
if scanErr := rows.Scan(&item.PlatformID, &item.AccountID, &clientIDText, &item.OnlineRank, &item.HealthRank); scanErr != nil {
|
||||
return nil, response.ErrInternal(50117, "desktop_account_lookup_failed", "failed to parse monitor desktop accounts")
|
||||
}
|
||||
if parsedClientID, parseErr := uuid.Parse(strings.TrimSpace(clientIDText)); parseErr == nil {
|
||||
@@ -401,23 +433,28 @@ func selectMonitorDesktopTaskTargets(
|
||||
onlineClients map[uuid.UUID]bool,
|
||||
) map[string]monitorDesktopTaskTarget {
|
||||
result := make(map[string]monitorDesktopTaskTarget)
|
||||
targetsByPlatform := make(map[string][]monitorDesktopTaskTarget)
|
||||
for _, candidate := range candidates {
|
||||
platformID := normalizeMonitoringPlatformID(candidate.PlatformID)
|
||||
if platformID == "" || candidate.AccountID == uuid.Nil {
|
||||
continue
|
||||
}
|
||||
if _, exists := result[platformID]; exists {
|
||||
continue
|
||||
}
|
||||
|
||||
if clientID, ok := accountPresence[candidate.AccountID]; ok && clientID != uuid.Nil && onlineClients[clientID] {
|
||||
result[platformID] = monitorDesktopTaskTarget{AccountID: candidate.AccountID, ClientID: clientID}
|
||||
targetsByPlatform[platformID] = append(targetsByPlatform[platformID], monitorDesktopTaskTarget{AccountID: candidate.AccountID, ClientID: clientID})
|
||||
continue
|
||||
}
|
||||
if candidate.DBClientID != nil && *candidate.DBClientID != uuid.Nil && onlineClients[*candidate.DBClientID] {
|
||||
result[platformID] = monitorDesktopTaskTarget{AccountID: candidate.AccountID, ClientID: *candidate.DBClientID}
|
||||
targetsByPlatform[platformID] = append(targetsByPlatform[platformID], monitorDesktopTaskTarget{AccountID: candidate.AccountID, ClientID: *candidate.DBClientID})
|
||||
}
|
||||
}
|
||||
for platformID, targets := range targetsByPlatform {
|
||||
if len(targets) == 0 {
|
||||
continue
|
||||
}
|
||||
index := randomIndex(len(targets))
|
||||
result[platformID] = targets[index]
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user