Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Grade Google connection health on granted scopes, not requested (SKY-15422) (#8424)
Andrew Neilson9276e5b4e16f
diff --git a/skyvern-frontend/src/hooks/useGoogleOAuthCredentials.test.ts b/skyvern-frontend/src/hooks/useGoogleOAuthCredentials.test.tsindex c30666700..4cbca73ed 100644--- a/skyvern-frontend/src/hooks/useGoogleOAuthCredentials.test.ts+++ b/skyvern-frontend/src/hooks/useGoogleOAuthCredentials.test.ts@@ -1,9 +1,10 @@import { describe, expect, it, vi } from "vitest";import type { GoogleOAuthCredential } from "@/api/types";import {+ attemptedGoogleOAuthIntegrationScopes,getGoogleOAuthCredentialScopesGranted,getGoogleOAuthCredentialScopesRequested,- matchesGoogleOAuthIntegrationScopes,+ hasGoogleOAuthCredentialScopes,normalizeGoogleOAuthScopes,safePostCredentialsInvalidate,} from "./useGoogleOAuthCredentials";@@ -57,31 +58,61 @@ describe("Google OAuth credential scope helpers", () => {).toEqual(["requested:a", "requested:b"]);});- it("matches integrations by requested scopes before cumulative granted scopes", () => {+ it("attributes an attempt by requested scopes before cumulative granted scopes", () => {const credential = {...baseCredential,scopes_requested: ["gmail"],scopes_granted: ["gmail", "sheets"],};- expect(matchesGoogleOAuthIntegrationScopes(credential, ["gmail"])).toBe(+ expect(attemptedGoogleOAuthIntegrationScopes(credential, ["gmail"])).toBe(true,);- expect(matchesGoogleOAuthIntegrationScopes(credential, ["sheets"])).toBe(+ expect(attemptedGoogleOAuthIntegrationScopes(credential, ["sheets"])).toBe(false,);});- it("falls back to granted scopes when requested scopes are absent", () => {+ it("falls back to capability scopes when requested scopes are absent", () => {+ const noHistory = { ...baseCredential, scopes_granted: ["sheets"] };++ expect(attemptedGoogleOAuthIntegrationScopes(noHistory, ["sheets"])).toBe(+ true,+ );expect(- matchesGoogleOAuthIntegrationScopes(- {- ...baseCredential,- scopes_granted: ["sheets"],- },+ attemptedGoogleOAuthIntegrationScopes(+ noHistory,+ ["sheets", "drive.metadata"],["sheets"],),).toBe(true);+ expect(+ attemptedGoogleOAuthIntegrationScopes(noHistory, [+ "sheets",+ "drive.metadata",+ ]),+ ).toBe(false);+ });++ it("separates a partial grant's attempt from its capability", () => {+ const partiallyGranted = {+ ...baseCredential,+ scopes_requested: ["sheets", "drive.metadata"],+ scopes_granted: ["drive.metadata"],+ };++ expect(+ attemptedGoogleOAuthIntegrationScopes(partiallyGranted, [+ "sheets",+ "drive.metadata",+ ]),+ ).toBe(true);+ expect(+ hasGoogleOAuthCredentialScopes(partiallyGranted, [+ "sheets",+ "drive.metadata",+ ]),+ ).toBe(false);});});diff --git a/skyvern-frontend/src/hooks/useGoogleOAuthCredentials.ts b/skyvern-frontend/src/hooks/useGoogleOAuthCredentials.tsindex 5b0da246e..a4e19e6fc 100644--- a/skyvern-frontend/src/hooks/useGoogleOAuthCredentials.ts+++ b/skyvern-frontend/src/hooks/useGoogleOAuthCredentials.ts@@ -10,7 +10,6 @@ import {GoogleOAuthCredentialResponse,} from "@/api/types";import { useToast } from "@/components/ui/use-toast";-export { GOOGLE_SHEETS_REQUIRED_SCOPES } from "@/util/googleScopes";const BROADCAST_CHANNEL_NAME = "skyvern:google-oauth-credentials";@@ -90,16 +89,17 @@ export function hasGoogleOAuthCredentialScopes(return requiredScopes.every((scope) => granted.has(scope));}-export function matchesGoogleOAuthIntegrationScopes(+export function attemptedGoogleOAuthIntegrationScopes(credential: GoogleOAuthCredential,requiredScopes: readonly string[],+ capabilityScopes: readonly string[] = requiredScopes,): boolean {const requested = getGoogleOAuthCredentialScopesRequested(credential);if (requested.length > 0) {const requestedSet = new Set(requested);return requiredScopes.every((scope) => requestedSet.has(scope));}- return hasGoogleOAuthCredentialScopes(credential, requiredScopes);+ return hasGoogleOAuthCredentialScopes(credential, capabilityScopes);}// Falls back to the first credential even when none are active, so a singlediff --git a/skyvern-frontend/src/routes/integrations/Integrations.tsx b/skyvern-frontend/src/routes/integrations/Integrations.tsxindex 787168273..d4b8cf539 100644--- a/skyvern-frontend/src/routes/integrations/Integrations.tsx+++ b/skyvern-frontend/src/routes/integrations/Integrations.tsx@@ -32,7 +32,7 @@ import {import {GOOGLE_DRIVE_REQUIRED_SCOPES,GOOGLE_GMAIL_REQUIRED_SCOPES,- GOOGLE_SHEETS_REQUIRED_SCOPES,+ GOOGLE_SHEETS_BLOCK_REQUIRED_SCOPES,} from "@/util/googleScopes";import {buildGoogleOAuthRedirectUri,@@ -46,21 +46,21 @@ const integrations = [title: "Google Sheets",description: "Read, append, and update spreadsheet data from workflows.",scopeProfile: "google_sheets",- requiredScopes: GOOGLE_SHEETS_REQUIRED_SCOPES,+ capabilityScopes: GOOGLE_SHEETS_BLOCK_REQUIRED_SCOPES,},{id: "gmail",title: "Gmail",description: "Read verification emails for OTP polling.",scopeProfile: "gmail",- requiredScopes: GOOGLE_GMAIL_REQUIRED_SCOPES,+ capabilityScopes: GOOGLE_GMAIL_REQUIRED_SCOPES,},{id: "google_drive",title: "Google Drive",description: "Upload generated files to connected Drive accounts.",scopeProfile: "google_drive",- requiredScopes: GOOGLE_DRIVE_REQUIRED_SCOPES,+ capabilityScopes: GOOGLE_DRIVE_REQUIRED_SCOPES,},] as const;@@ -128,7 +128,7 @@ function Integrations() {const matchingCredentials = credentials.filter((credential) =>hasGoogleOAuthCredentialScopes(credential,- Array.from(integration.requiredScopes),+ Array.from(integration.capabilityScopes),),);const activeCount = matchingCredentials.filter(diff --git a/skyvern-frontend/src/routes/workflows/editor/hooks/useResolveDefaultGoogleSheetsCredential.test.tsx b/skyvern-frontend/src/routes/workflows/editor/hooks/useResolveDefaultGoogleSheetsCredential.test.tsxindex b895b168e..d38061c45 100644--- a/skyvern-frontend/src/routes/workflows/editor/hooks/useResolveDefaultGoogleSheetsCredential.test.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/hooks/useResolveDefaultGoogleSheetsCredential.test.tsx@@ -227,15 +227,14 @@ describe("useResolveDefaultGoogleSheetsCredential (SKY-11219)", () => {});});- test("ignores partial Sheets grants that are missing Drive scopes", () => {+ test("fills a grant that carries only the Sheets data scope, as the copilot reads it", () => {mockCredentials = [credential("cred_spreadsheets_only", "active", [GOOGLE_SHEETS_SCOPE]),- credential("cred_sheets"),];render(<Harness nodes={[writeNode("g1", "")]} />);expect(updateNodeData).toHaveBeenCalledWith("g1", {- credentialId: "cred_sheets",+ credentialId: "cred_spreadsheets_only",});});diff --git a/skyvern-frontend/src/routes/workflows/editor/hooks/useResolveDefaultGoogleSheetsCredential.ts b/skyvern-frontend/src/routes/workflows/editor/hooks/useResolveDefaultGoogleSheetsCredential.tsindex 929794c7e..aac48ce1d 100644--- a/skyvern-frontend/src/routes/workflows/editor/hooks/useResolveDefaultGoogleSheetsCredential.ts+++ b/skyvern-frontend/src/routes/workflows/editor/hooks/useResolveDefaultGoogleSheetsCredential.ts@@ -2,11 +2,11 @@ import { useReactFlow } from "@xyflow/react";import { useEffect, useMemo } from "react";import {- GOOGLE_SHEETS_REQUIRED_SCOPES,getDefaultGoogleOAuthCredentialId,hasGoogleOAuthCredentialScopes,useGoogleOAuthCredentials,} from "@/hooks/useGoogleOAuthCredentials";+import { GOOGLE_SHEETS_BLOCK_REQUIRED_SCOPES } from "@/util/googleScopes";import { useWorkflowHasChangesStore } from "@/store/WorkflowHasChangesStore";import type { AppNode } from "../nodes";@@ -52,7 +52,7 @@ export function useResolveDefaultGoogleSheetsCredential(credentials.filter((credential) =>hasGoogleOAuthCredentialScopes(credential,- GOOGLE_SHEETS_REQUIRED_SCOPES,+ GOOGLE_SHEETS_BLOCK_REQUIRED_SCOPES,),),[credentials],diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/GoogleSheetsReadNode/GoogleSheetsReadEditor.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/GoogleSheetsReadNode/GoogleSheetsReadEditor.tsxindex e66e43b9c..d34fe9e27 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/GoogleSheetsReadNode/GoogleSheetsReadEditor.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/GoogleSheetsReadNode/GoogleSheetsReadEditor.tsx@@ -12,10 +12,8 @@ import {import { Label } from "@/components/ui/label";import { Separator } from "@/components/ui/separator";import { Switch } from "@/components/ui/switch";-import {- GOOGLE_SHEETS_REQUIRED_SCOPES,- useGoogleOAuthCredentials,-} from "@/hooks/useGoogleOAuthCredentials";+import { useGoogleOAuthCredentials } from "@/hooks/useGoogleOAuthCredentials";+import { GOOGLE_SHEETS_BLOCK_REQUIRED_SCOPES } from "@/util/googleScopes";import { useGoogleSpreadsheet } from "@/hooks/useGoogleSpreadsheet";import { GoogleOAuthCredentialSelector } from "@/routes/workflows/components/GoogleOAuthCredentialSelector";import { SheetTabCombobox } from "@/routes/workflows/components/SheetTabCombobox";@@ -138,7 +136,7 @@ function GoogleSheetsReadEditorBody({nodeId={blockId}value={data.credentialId}onChange={(next) => update({ credentialId: next })}- requiredScopes={GOOGLE_SHEETS_REQUIRED_SCOPES}+ requiredScopes={GOOGLE_SHEETS_BLOCK_REQUIRED_SCOPES}/></div>diff --git a/skyvern-frontend/src/routes/workflows/editor/nodes/GoogleSheetsWriteNode/GoogleSheetsWriteEditor.tsx b/skyvern-frontend/src/routes/workflows/editor/nodes/GoogleSheetsWriteNode/GoogleSheetsWriteEditor.tsxindex 41a43dc47..049b39a61 100644--- a/skyvern-frontend/src/routes/workflows/editor/nodes/GoogleSheetsWriteNode/GoogleSheetsWriteEditor.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/nodes/GoogleSheetsWriteNode/GoogleSheetsWriteEditor.tsx@@ -12,10 +12,8 @@ import {import { Checkbox } from "@/components/ui/checkbox";import { Label } from "@/components/ui/label";import { Separator } from "@/components/ui/separator";-import {- GOOGLE_SHEETS_REQUIRED_SCOPES,- useGoogleOAuthCredentials,-} from "@/hooks/useGoogleOAuthCredentials";+import { useGoogleOAuthCredentials } from "@/hooks/useGoogleOAuthCredentials";+import { GOOGLE_SHEETS_BLOCK_REQUIRED_SCOPES } from "@/util/googleScopes";import { useGoogleSheetDimensions } from "@/hooks/useGoogleSheetDimensions";import { useGoogleSheetHeaders } from "@/hooks/useGoogleSheetHeaders";import { useGoogleSpreadsheet } from "@/hooks/useGoogleSpreadsheet";@@ -178,7 +176,7 @@ function GoogleSheetsWriteEditorBody({nodeId={blockId}value={data.credentialId}onChange={(next) => update({ credentialId: next })}- requiredScopes={GOOGLE_SHEETS_REQUIRED_SCOPES}+ requiredScopes={GOOGLE_SHEETS_BLOCK_REQUIRED_SCOPES}/>{needsReconnect ? (<a