Skip to content

feat: add pubspec audit & audit-all commands for dependency validation #19

@tsavo-at-pieces

Description

@tsavo-at-pieces

Overview

Add audit and audit-all CLI commands to runtime_ci_tooling that validate pubspec.yaml dependency declarations across consumer packages. This fills a critical gap — we have consumer discovery (consumers command) and template sync (update/update-all), but no automated way to detect or repair misconfigured pubspec dependencies.

Problem

Manual pubspec dependency management across 20+ repos leads to recurring issues:

  1. Bare constraints where git SSH deps are required — e.g. encrypt: ^6.0.0 instead of the full git block with tag_pattern
  2. Wrong GitHub org — e.g. pieces-app/encrypt.git instead of open-runtime/encrypt.git
  3. Stale version constraints — e.g. encrypt: ^5.1.10 when source is at ^6.0.0
  4. Missing tag_pattern: v{{version}} on git deps
  5. HTTPS URLs instead of SSH URLs (https://github.com/... vs git@github.com:...)

Real examples found today:

  • runtime_aot_tooling/pubspec.yaml had encrypt: ^5.1.10 (stale)
  • runtime_mindfck/pubspec.yaml had pieces-app/encrypt.git (wrong org)
  • runtime_aot_client_examples/pubspec.yaml had 5 bare deps missing git SSH blocks

Proposed Commands

audit — Single package pubspec validation

manage_cicd audit [--path <dir>] [--fix] [--verbose]

Behavior:

  1. Read pubspec.yaml in the target directory (default: cwd)
  2. For each dependency in dependencies and dev_dependencies:
    • If it's a known git-sourced package (from a registry — see below), validate:
      • Has git: block with SSH URL (git@github.com:org/repo.git)
      • Has tag_pattern: v{{version}} (or package-specific pattern)
      • Has version: constraint
      • URL points to correct GitHub org
      • Version constraint is compatible with latest known version
    • If it's a pub.dev package or workspace-internal dep, skip
  3. Report all issues found (structured output)
  4. With --fix: rewrite the pubspec to correct format

audit-all — Recursive batch validation

manage_cicd audit-all [--path <dir>] [--fix] [--verbose] [--exclude <glob>]

Behavior:

  1. Recursively find all pubspec.yaml files under the target directory (default: cwd)
  2. Skip .dart_tool/, .consumers/, .claude/, build/ directories
  3. Run audit logic on each
  4. Aggregate and report results
  5. With --fix: batch-fix all

Package Registry

The "known git-sourced packages" registry should be derived from configs/external_workspace_packages.yaml in the monorepo (or a local equivalent). Each entry defines:

  • github_org + github_repo → SSH URL
  • tag_pattern (usually v{{version}}, but some packages like custom_lint have different patterns)
  • version → latest known version constraint

The audit commands should accept a --registry <path> flag to point at this YAML file, with a sensible default.

Cross-referencing with .consumers/

When .consumers/ data is available (from a prior consumers run), the audit can additionally:

  • Compare consumer pubspec snapshots against current source versions
  • Flag consumers whose dependency constraints are incompatible with the source's current version
  • Generate a compatibility matrix

Existing Infrastructure to Build On

  • consumers command already discovers all downstream repos and stores pubspec snapshots in .consumers/
  • external_workspace_packages.yaml already defines all git-sourced packages with org, repo, version, tag_pattern
  • hook_installer.dart already handles resolution: workspace stripping (pre-commit hook)
  • YAML parsing already used in consumers_command.dart via loadYaml()

Audit of Existing Commands (No Issues Found)

All existing commands were audited for incorrect pubspec modifications:

Command Pubspec interaction Status
create-release Bumps version: field via regex ✅ Safe — only touches version line
consumers Fetches + stores pubspec snapshots (read-only) ✅ Safe
update / update-all Updates workflows/configs, not pubspecs ✅ Safe
validate YAML syntax check (read-only) ✅ Safe
determine-version Reads version via awk (read-only) ✅ Safe
release Reads version via awk (read-only) ✅ Safe
Pre-commit hook Strips resolution: workspace via sed ✅ Correct

No existing commands incorrectly modify pubspec dependency structures.

Acceptance Criteria

  • audit command validates a single pubspec against the package registry
  • audit-all command recursively validates all pubspecs in a directory tree
  • Reports bare deps, wrong orgs, stale versions, missing tag_patterns, HTTPS URLs
  • --fix flag rewrites pubspecs with correct git SSH + tag_pattern format
  • --registry <path> flag to specify package registry YAML
  • Structured output (JSON) option for CI integration
  • Skips pub.dev packages and workspace-internal deps automatically
  • Cross-references .consumers/ data when available

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions