Skip to content

[api_summary] Add expectApiSummaryClean and --write/--check CLI flags - #2603

Merged
auto-submit[bot] merged 6 commits into
mainfrom
api-summary-expect-clean
Sep 29, 2026
Merged

auto-submit[bot] merged 6 commits into
mainfrom
api-summary-expect-clean

Conversation

@kevmoo

@kevmoo kevmoo commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

Adds a build_verify-style one-liner test helper (expectApiSummaryClean) and companion --write (-w), --check (-c), and --output (-o) CLI flags to package:api_summary (v1.1.0).

  • Programmatic Tear-Off (expectApiSummaryClean):
    • Verifies that a package's generated ApiSummary matches its checked-in golden file (api.txt, api.json, or api.yaml).
    • Because all parameters are optional and named (packagePath defaults to Directory.current), it can be passed directly as a tear-off to test():
      import 'package:api_summary/api_summary.dart';
      import 'package:test/scaffolding.dart';
      
      void main() {
        test('api_summary', expectApiSummaryClean);
      }
    • Throws ApiSummaryVerificationException with a compact line diff and copy-pasteable remediation command (dart run api_summary --write) without requiring package:test in api_summary's runtime dependencies.
  • CLI Enhancements (bin/api_summary.dart):
    • -w, --write: Writes the summary to the default golden file (api.txt, api.json, or api.yaml) in the package root.
    • -c, --check: Verifies that the existing golden file matches the current public API, exiting with code 1 on mismatch.
    • -o, --output <file>: Writes the summary to a custom file path instead of stdout (relative paths resolve relative to --package-path).
    • Enforces mutual exclusivity between --write, --check, and --output via an exhaustive record switch (exiting with code 64 on invalid combinations or unexpected positional arguments).
  • Self-Dogfooding & Tests (test/app_test.dart):
    • Dogfoods expectApiSummaryClean for api.txt, api.json, and api.yaml and pre-compiles bin/api_summary.dart to a kernel .dill in setUpAll (cutting test/app_test.dart execution time from ~105s to ~44s).

@github-actions

github-actions Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Package publishing

If you have publishing permissions, you can use the links below to publish the changes after merging this PR.

Package Version Status Publish tag (post-merge)
package:api_summary ⭐ 1.1.0 ready to publish api_summary-v1.1.0
package:pubspec_parse 1.6.1 ready to publish pubspec_parse-v1.6.1
package:test_reflective_loader 0.6.0 ready to publish test_reflective_loader-v0.6.0
  • 18 already published.
  • 21 WIP (no publish necessary).

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces golden file verification capabilities to the api_summary package, adding the expectApiSummaryClean function, ApiSummaryFormat enum, and ApiSummaryVerificationException class to support one-liner golden file verification in tests. It also extends the CLI executable with --write (-w), --check (-c), and --output (-o) flags. The review feedback highlights three key issues: a failure to correctly resolve the caller's package directory when api_summary is consumed as a pub dependency with a version suffix, a path resolution discrepancy in the CLI when combining a custom package path with a relative output path, and a regex parsing limitation in resolveCallerPackageDirectory when file paths contain parentheses.

Comment thread pkgs/api_summary/lib/src/verify.dart Outdated
Comment thread pkgs/api_summary/bin/api_summary.dart Outdated
Comment thread pkgs/api_summary/lib/src/verify.dart Outdated
@github-actions

github-actions Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

PR Health

Coverage ⚠️
File Coverage
pkgs/api_summary/bin/api_summary.dart 💔 Not covered
pkgs/api_summary/lib/api_summary.dart 💚 98 %
pkgs/api_summary/lib/src/verify.dart 💚 92 %

This check for test coverage is informational (issues shown here will not fail the PR).

This check can be disabled by tagging the PR with skip-coverage-check.

License Headers ✔️
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/html/test/differential_test.dart
pkgs/html/test/dom_parsing_test.dart
pkgs/html/test/mxss_test.dart
pkgs/html/test/noah_ark_clause_limit_test.dart

This check can be disabled by tagging the PR with skip-license-check.

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
api_summary Non-Breaking 1.0.0 1.1.0 1.1.0 ✔️

This check can be disabled by tagging the PR with skip-breaking-check.

Unused Dependencies ✔️
Package Status
api_summary ✔️ All dependencies utilized correctly.

For details on how to fix these, see dependency_validator.

This check can be disabled by tagging the PR with skip-unused-dependencies-check.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check.

@kevmoo
kevmoo requested a review from natebosch September 18, 2026 15:16
Comment thread pkgs/api_summary/lib/src/verify.dart Outdated
Comment thread pkgs/api_summary/lib/src/verify.dart Outdated
Comment thread pkgs/api_summary/lib/src/verify.dart
- Use enum dot shorthands in `ApiSummaryFormat.format` and `_buildRemediationCommand`.
- Use conditional collection elements and spreads in `_buildRemediationCommand`.
- Add doc comments to private helpers in `lib/src/verify.dart`.
@auto-submit
auto-submit Bot merged commit 7d859ed into main Sep 29, 2026
30 checks passed
@auto-submit
auto-submit Bot deleted the api-summary-expect-clean branch September 29, 2026 03:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants