play-console-cli icon indicating copy to clipboard operation
play-console-cli copied to clipboard

Feature: Checks API integration for app compliance (checks/v1alpha)

Open tamtom opened this issue 8 months ago • 2 comments

Summary

Integrate the Google Checks API (checks/v1alpha) into the gplay CLI to provide automated app compliance analysis, privacy report generation, and AI safety content classification directly from the command line.

Why this is applicable to Google Play

Google Checks is Google's own compliance platform that analyzes Android (APK/AAB) and iOS app binaries for privacy violations, policy non-compliance, undisclosed data collection, SDK risks, and regulatory issues (GDPR, CCPA, COPPA). It is purpose-built for developers publishing to the Play Store and directly complements the existing gplay data-safety commands by providing automated verification of what an app actually does versus what is declared. Integrating Checks into gplay enables pre-submission compliance gating in CI/CD pipelines, catching policy violations before they reach Play Store review.

Problem

Currently, gplay data-safety update lets developers declare what data their app collects, but there is no way to verify those declarations against actual app behavior through the CLI. Developers must manually use the Checks web console or a separate CLI tool to:

  • Upload app binaries for compliance analysis
  • Review privacy reports for undisclosed endpoints, permissions, SDKs, and data types
  • Monitor data collection behavior changes across releases
  • Classify AI-generated content against safety policies

This creates a gap in the CLI's coverage: developers can manage their entire Play Store presence through gplay, but must leave the tool for the critical compliance verification step. The existing gplay-submission-checks skill validates metadata and screenshots, but cannot perform deep binary analysis for privacy and policy compliance.

Goals

  • Add a gplay checks command group for interacting with the Google Checks API
  • Support uploading app binaries (APK/AAB) for automated compliance analysis
  • Enable retrieving and filtering privacy/compliance reports
  • Support listing and managing Checks-connected apps
  • Provide AI safety content classification for app content moderation
  • Support long-running operation polling (upload analysis is async)
  • Integrate with existing --output json/table/markdown formatting
  • Enable CI/CD pipeline integration with exit codes based on check severity
  • Complement the existing gplay data-safety and gplay-submission-checks workflows

Proposed Commands

gplay checks (command group)

gplay checks <subcommand> [flags]

Parent command group for all Google Checks API interactions.


gplay checks apps list

List apps connected to the Checks account.

gplay checks apps list --account <account-id> [--page-size 10] [--paginate] [--output json]
Flag Required Description
--account Yes Checks account ID
--page-size No Results per page (default: 10, max: 50)
--paginate No Fetch all pages automatically
--output No Output format: json (default), table, markdown
--pretty No Pretty-print JSON output

gplay checks apps get

Get details for a specific Checks app.

gplay checks apps get --account <account-id> --app <app-id> [--output json]
Flag Required Description
--account Yes Checks account ID
--app Yes Checks app ID
--output No Output format: json (default), table, markdown
--pretty No Pretty-print JSON output

gplay checks analyze

Upload an app binary for compliance analysis. Returns a report when analysis completes.

gplay checks analyze --account <account-id> --app <app-id> --binary <path> [--binary-type APK] [--code-ref <git-sha>] [--wait] [--wait-timeout 10m] [--severity-threshold PRIORITY] [--output json]
Flag Required Description
--account Yes Checks account ID
--app Yes Checks app ID
--binary Yes Path to APK or AAB file
--binary-type No File type: ANDROID_APK (default), ANDROID_AAB
--code-ref No Git commit SHA or changelist number to associate
--wait No Wait for analysis to complete and print report (default: true)
--wait-timeout No Max time to wait for analysis (default: 10m)
--severity-threshold No Fail (exit 1) if any check at or above this severity: PRIORITY, POTENTIAL, OPPORTUNITY
--checks-filter No AIP-160 filter for checks (e.g., state = FAILED)
--output No Output format: json (default), table, markdown
--pretty No Pretty-print JSON output

When --wait is set (default), the command polls the long-running operation until the report is ready, then prints the full report. When --severity-threshold is set, the command exits with code 1 if any check meets or exceeds the threshold -- enabling CI/CD gating.


gplay checks reports list

List compliance reports for an app.

gplay checks reports list --account <account-id> --app <app-id> [--filter <aip-160>] [--checks-filter <aip-160>] [--page-size 10] [--paginate] [--output json]
Flag Required Description
--account Yes Checks account ID
--app Yes Checks app ID
--filter No AIP-160 filter for reports (e.g., appBundle.releaseType = PRE_RELEASE)
--checks-filter No AIP-160 filter for checks within reports (e.g., state = FAILED)
--page-size No Results per page (default: 10, max: 50)
--paginate No Fetch all pages automatically
--output No Output format: json (default), table, markdown
--pretty No Pretty-print JSON output

gplay checks reports get

Get a specific compliance report with full details.

gplay checks reports get --account <account-id> --app <app-id> --report <report-id> [--checks-filter <aip-160>] [--output json]
Flag Required Description
--account Yes Checks account ID
--app Yes Checks app ID
--report Yes Report ID
--checks-filter No AIP-160 filter for checks (e.g., state = FAILED)
--output No Output format: json (default), table, markdown
--pretty No Pretty-print JSON output

gplay checks operations get

Check the status of a long-running analysis operation.

gplay checks operations get --account <account-id> --app <app-id> --operation <operation-id> [--output json]

gplay checks operations wait

Wait for a long-running operation to complete.

gplay checks operations wait --account <account-id> --app <app-id> --operation <operation-id> [--timeout 10m] [--output json]

gplay checks operations cancel

Cancel a running analysis operation.

gplay checks operations cancel --account <account-id> --app <app-id> --operation <operation-id>

gplay checks classify

Classify text content against AI safety policies. Useful for validating user-generated content, AI outputs, or app content before release.

gplay checks classify --text <content> [--language <code>] [--policies DANGEROUS_CONTENT,HARASSMENT,...] [--context <prompt>] [--output json]
Flag Required Description
--text Yes Text content to classify (or @file to read from file)
--language No BCP-47 language code of the content
--policies No Comma-separated policy types (default: all). Options: DANGEROUS_CONTENT, PII_SOLICITING_RECITING, HARASSMENT, SEXUALLY_EXPLICIT, HATE_SPEECH, MEDICAL_INFO, VIOLENCE_AND_GORE, OBSCENITY_AND_PROFANITY
--context No Additional context prompt for classification
--severity-threshold No Fail (exit 1) if any policy result is VIOLATIVE
--output No Output format: json (default), table, markdown
--pretty No Pretty-print JSON output

Implementation Details

API Endpoints

All endpoints use base URL https://checks.googleapis.com/v1alpha:

Command Method Endpoint
checks apps list GET /accounts/{id}/apps
checks apps get GET /accounts/{id}/apps/{appId}
checks analyze POST /upload/accounts/{id}/apps/{appId}/reports:analyzeUpload
checks reports list GET /accounts/{id}/apps/{appId}/reports
checks reports get GET /accounts/{id}/apps/{appId}/reports/{reportId}
checks operations get GET /accounts/{id}/apps/{appId}/operations/{opId}
checks operations wait POST /accounts/{id}/apps/{appId}/operations/{opId}:wait
checks operations cancel POST /accounts/{id}/apps/{appId}/operations/{opId}:cancel
checks classify POST /aisafety:classifyContent

Authentication

  • The Checks API requires OAuth scope https://www.googleapis.com/auth/checks
  • This is a separate scope from the Android Publisher API scope used by the rest of gplay
  • The existing service account can be used, but it must be granted the Checks API scope
  • A new checksclient package should create its own checks.Service using google.golang.org/api/checks/v1alpha with the existing credential resolution from config.Config
  • Consider adding a GPLAY_CHECKS_ACCOUNT env var and checks_account config field to avoid passing --account on every command

Go Client Library

  • Package: google.golang.org/api/checks/v1alpha (already available via google.golang.org/api v0.272.0 in go.mod)
  • No new dependency required -- the checks/v1alpha sub-package is part of the existing google.golang.org/api module
  • Key service types: AccountsAppsService, AccountsAppsReportsService, AccountsAppsOperationsService, AisafetyService, MediaService
  • Key struct types: GoogleChecksReportV1alphaReport, GoogleChecksReportV1alphaCheck, GoogleChecksReportV1alphaAppBundle, GoogleChecksReportV1alphaDataMonitoring

New Packages/Files

internal/
├── checksclient/              # New: Checks API client wrapper
│   ├── client.go              # Service initialization, auth with checks scope
│   └── client_test.go
├── cli/
│   └── checks/                # New: Command implementations
│       ├── checks.go          # Parent command group
│       ├── apps.go            # apps list, apps get
│       ├── analyze.go         # Binary upload + operation polling
│       ├── reports.go         # reports list, reports get
│       ├── operations.go      # operations get, wait, cancel
│       ├── classify.go        # AI safety classification
│       └── checks_test.go     # CLI tests

Integration with Existing Features

  • gplay data-safety: The checks analyze command validates what the app actually does, while data-safety update declares what it claims to do. Document this workflow: run checks analyze first, review the report, then update data safety declarations accordingly.
  • gplay-submission-checks skill: Extend the skill to optionally invoke checks analyze as part of pre-submission validation when a binary path is available, adding Checks report results to the submission readiness assessment.
  • gplay release: Document how to chain checks analyze --severity-threshold PRIORITY before gplay release in CI/CD pipelines to gate releases on compliance.

Output Format Considerations

  • Default minified JSON output for agent/CI consumption (consistent with all other gplay commands)
  • Table output for reports list should show: report name, app bundle version, check pass/fail counts, results URL
  • Table output for reports get should show: per-check type, state (PASSED/FAILED/UNCHECKED), severity, citations, affected regions
  • Table output for classify should show: policy type, violation result, score
  • Markdown output useful for posting compliance summaries to PRs or Slack via gplay notify send

Long-Running Operation Handling

The checks analyze command triggers an async analysis via media.upload, which returns a google.longrunning.Operation. The implementation should:

  1. Upload the binary and receive the operation resource name
  2. Poll operations.get with exponential backoff (start 5s, max 30s)
  3. When operation.done == true, deserialize the result as a Report
  4. Apply --severity-threshold filtering and set exit code accordingly
  5. Respect --wait-timeout and exit with a clear error if exceeded
  6. Print progress to stderr (e.g., "Analyzing... (elapsed: 45s)")

Acceptance Criteria

  • [ ] gplay checks --help displays all subcommands with descriptions
  • [ ] gplay checks apps list lists apps connected to the Checks account
  • [ ] gplay checks apps get retrieves details for a specific app
  • [ ] gplay checks analyze uploads an APK/AAB and returns a compliance report
  • [ ] gplay checks analyze --wait polls until analysis completes (with progress on stderr)
  • [ ] gplay checks analyze --severity-threshold PRIORITY exits with code 1 when critical checks fail
  • [ ] gplay checks reports list lists reports with pagination support (--paginate)
  • [ ] gplay checks reports get retrieves a full report with checks, evidence, and data monitoring
  • [ ] gplay checks reports list --filter and --checks-filter correctly apply AIP-160 filters
  • [ ] gplay checks operations get/wait/cancel manage long-running operations
  • [ ] gplay checks classify classifies text content against specified AI safety policies
  • [ ] gplay checks classify --severity-threshold exits with code 1 on violative content
  • [ ] All commands support --output json/table/markdown and --pretty flags
  • [ ] All commands use shared.ContextWithTimeout (or shared.ContextWithUploadTimeout for analyze)
  • [ ] All commands use shared.DefaultUsageFunc
  • [ ] New checksclient package authenticates with https://www.googleapis.com/auth/checks scope
  • [ ] --account is resolved from flag > GPLAY_CHECKS_ACCOUNT env var > checks_account config field
  • [ ] --dry-run works for write operations (analyze, operations cancel)
  • [ ] CLI-level tests cover flag validation, error messages, and output formatting
  • [ ] Command is registered in internal/cli/registry/registry.go
  • [ ] gplay checks analyze documentation explains CI/CD gating workflow
  • [ ] No new dependencies required (uses existing google.golang.org/api module)

References

tamtom avatar Apr 04 '26 18:04 tamtom

Implementation Checklist

Command & Registration

  • [ ] Command group gplay checks in internal/cli/checks/
  • [ ] Subcommands: apps list, apps get, upload, reports list, reports get, content classify
  • [ ] Registered in internal/cli/registry/registry.go
  • [ ] UsageFunc: shared.DefaultUsageFunc set on all commands
  • [ ] Dedicated client wrapper for checks/v1alpha API
  • [ ] Long-running operation polling for async upload analysis
  • [ ] Exit codes based on check severity (for CI/CD gating)
  • [ ] Required flags validated with stderr error messages

Tests

  • [ ] CLI black-box tests in internal/cmdtest/checks_test.go
  • [ ] Unit tests for severity-to-exit-code mapping
  • [ ] Unit tests for operation polling logic
  • [ ] Error paths: missing --account, invalid binary path, timeout during polling

Docs & Help

  • [ ] --help output follows existing conventions
  • [ ] Command docs regenerated: gplay docs generate

Validation (before opening PR)

make format
make lint
make test
make build
/tmp/gplay checks --help
/tmp/gplay checks apps list --help
/tmp/gplay checks upload --help
/tmp/gplay checks upload                  # missing required flags → stderr error
/tmp/gplay checks upload --binary /bad    # invalid path

tamtom avatar Apr 05 '26 04:04 tamtom

Addendum to checklist above — docs CI gate:

The PR CI now runs make check-docs on every PR. This means:

  1. After implementing the command, run make docs to regenerate GPLAY.md
  2. Commit the updated GPLAY.md alongside your code changes
  3. If you forget, the PR check will fail with: "GPLAY.md is out of date"

This ensures every user-facing command, flag, and help text is always reflected in the reference docs.

tamtom avatar Apr 05 '26 04:04 tamtom