(reason: string, health?: HealthCheckResult)
| 3581 | // reconnect re-syncs tools anyway); at worst the skipped |
| 3582 | // `tools_synced_at` stamp makes the next read re-attempt the sync. |
| 3583 | const stampSyncedWithHealth = (reason: string, health?: HealthCheckResult) => |
| 3584 | findConnectionRow(ref).pipe( |
| 3585 | Effect.flatMap((fresh) => |
| 3586 | fresh === null |
| 3587 | ? Effect.void |
| 3588 | : core |
| 3589 | .updateMany("connection", { |
| 3590 | where: (b: AnyCb) => |
| 3591 | b.and( |
| 3592 | connectionWhere(b), |
| 3593 | b("updated_at", "=", fresh.updated_at), |
| 3594 | fresh.tools_synced_at == null |
| 3595 | ? b.isNull("tools_synced_at") |
| 3596 | : b("tools_synced_at", "=", fresh.tools_synced_at), |
| 3597 | ), |
| 3598 | set: |
| 3599 | oauthReauthRequiredFromProviderState(fresh.provider_state) !== null |
| 3600 | ? { tools_synced_at: Date.now() } |
| 3601 | : { |
| 3602 | tools_synced_at: Date.now(), |
| 3603 | // A plugin-supplied verdict (e.g. the MCP server |
| 3604 | // rejecting the token during discovery) is still |
| 3605 | // sync-stamped: mark it so credential-only health |
| 3606 | // checks cannot bury it under "healthy", and a |
| 3607 | // later successful sync clears it. |
| 3608 | last_health: |
| 3609 | health === undefined |
| 3610 | ? toolSyncHealth(reason) |
| 3611 | : { ...health, reason: health.reason ?? "tool_sync_failed" }, |
| 3612 | updated_at: new Date(), |
| 3613 | }, |
| 3614 | }) |
| 3615 | .pipe(Effect.asVoid), |
| 3616 | ), |
| 3617 | ); |
| 3618 | |
| 3619 | // Defense in depth (and cleanup for rows created before the create-time |
| 3620 | // guard, or emptied by an external edit): a credentialed non-OAuth |
no test coverage detected