Skip to content

[coverage] Partial workspace support #2095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 22, 2025
Merged

[coverage] Partial workspace support #2095

merged 13 commits into from
May 22, 2025

Conversation

liamappelbe
Copy link
Contributor

@liamappelbe liamappelbe commented May 20, 2025

The eventual goal is that the user should be able to run dart run coverage:test_with_coverage from the workspace root, and it runs all the tests in the workspace and produces a single coverage report. There are 2 problems that need to be solved for this to happen:

  1. Find and run all the tests (with the correct working directory)
  2. Update the scoping logic to not exclude the subpackages from the report

I'm only tackling the scoping changes for now (see this comment). So this means that users can run test_with_coverage from the workspace root, but they have to manually specify the tests they want to run: dart run coverage:test_with_coverage -- pkgs/foo/test pkgs/bar/test.

The packages included in the final report are controlled by the --scope-output option. The problem is with the default behavior, where it defaults to the current package. This excludes all the subpackages. The fix is just to parse the pubspec.yaml file, and include all the subpackages in the default scopes. Workspaces can be nested, so we have to do this recursively.

#2083

Other changes

  • Deprecated the --package-name option. It's only used to set the --scope-output option, so it's a bit redundant. And it doesn't make sense in the context of workspaces anyway.
  • Changed the default --port option to 0. There's special logic in the Dart VM that will choose an arbitrary free port if you set --enable-vm-service=0.
  • Tag all the integration tests so that I can do dart test -x integration to run all the fast tests during development. Also, pull out the common bits of integration test config to dart_test.yaml.
  • Bump min SDK version so that we have access to workspaces
  • Unrelated changes to lib/src/collect.dart and lib/src/formatter.dart to fix some failing tests
  • Fail gracefully if the VM service fails to start. Fixes [coverage] Recover from dartdev socket already in use (instead of hanging) #2096

@github-actions github-actions bot added type-infra A repository infrastructure change or enhancement package:coverage labels May 20, 2025
Copy link

github-actions bot commented May 20, 2025

Package publishing

Package Version Status Publish tag (post-merge)
package:bazel_worker 1.1.3 already published at pub.dev
package:benchmark_harness 2.4.0-wip WIP (no publish necessary)
package:boolean_selector 2.1.2 already published at pub.dev
package:browser_launcher 1.1.3 already published at pub.dev
package:cli_config 0.2.1-wip WIP (no publish necessary)
package:cli_util 0.4.2 already published at pub.dev
package:clock 1.1.3-wip WIP (no publish necessary)
package:code_builder 4.10.2-wip WIP (no publish necessary)
package:coverage 1.14.0 ready to publish coverage-v1.14.0
package:csslib 1.0.2 already published at pub.dev
package:extension_discovery 2.1.0 already published at pub.dev
package:file 7.0.2-wip WIP (no publish necessary)
package:file_testing 3.1.0-wip WIP (no publish necessary)
package:glob 2.1.3 already published at pub.dev
package:graphs 2.3.3-wip WIP (no publish necessary)
package:html 0.15.6 already published at pub.dev
package:io 1.1.0-wip WIP (no publish necessary)
package:json_rpc_2 4.0.0 already published at pub.dev
package:markdown 7.3.1-wip WIP (no publish necessary)
package:mime 2.0.0 already published at pub.dev
package:oauth2 2.0.4-wip WIP (no publish necessary)
package:package_config 2.3.0-wip WIP (no publish necessary)
package:pool 1.5.2-wip WIP (no publish necessary)
package:process 5.0.4 already published at pub.dev
package:pub_semver 2.2.0 already published at pub.dev
package:pubspec_parse 1.5.0 already published at pub.dev
package:source_map_stack_trace 2.1.3-wip WIP (no publish necessary)
package:source_maps 0.10.14-wip WIP (no publish necessary)
package:source_span 1.10.1 already published at pub.dev
package:sse 4.1.8 already published at pub.dev
package:stack_trace 1.12.1 already published at pub.dev
package:stream_channel 2.1.4 already published at pub.dev
package:stream_transform 2.1.2-wip WIP (no publish necessary)
package:string_scanner 1.4.1 already published at pub.dev
package:term_glyph 1.2.3-wip WIP (no publish necessary)
package:test_reflective_loader 0.2.3 already published at pub.dev
package:timing 1.0.2 already published at pub.dev
package:unified_analytics 8.0.1 already published at pub.dev
package:watcher 1.1.1 already published at pub.dev
package:yaml 3.1.3 already published at pub.dev
package:yaml_edit 2.2.2 already published at pub.dev

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

Copy link

github-actions bot commented May 20, 2025

PR Health

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
coverage Non-Breaking 1.13.1 1.14.0 1.14.0 ✔️
Changelog Entry ✔️
Package Changed Files

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

Coverage ⚠️
File Coverage
pkgs/coverage/bin/test_with_coverage.dart 💔 32 % ⬇️ 14 %
pkgs/coverage/lib/src/collect.dart 💔 87 % ⬇️ 0 %
pkgs/coverage/lib/src/coverage_options.dart 💚 100 %
pkgs/coverage/lib/src/formatter.dart 💚 97 %
pkgs/coverage/lib/src/hitmap.dart 💚 91 % ⬆️ 0 %
pkgs/coverage/lib/src/util.dart 💚 100 % ⬆️ 2 %

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.

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 symbols
License Headers ⚠️
// Copyright (c) 2025, 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
pkgs/coverage/lib/src/coverage_options.dart

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/bazel_worker/benchmark/benchmark.dart
pkgs/bazel_worker/example/client.dart
pkgs/bazel_worker/example/worker.dart
pkgs/benchmark_harness/integration_test/perf_benchmark_test.dart
pkgs/boolean_selector/example/example.dart
pkgs/clock/lib/clock.dart
pkgs/clock/lib/src/clock.dart
pkgs/clock/lib/src/default.dart
pkgs/clock/lib/src/stopwatch.dart
pkgs/clock/lib/src/utils.dart
pkgs/clock/test/clock_test.dart
pkgs/clock/test/default_test.dart
pkgs/clock/test/stopwatch_test.dart
pkgs/clock/test/utils.dart
pkgs/html/example/main.dart
pkgs/html/lib/dom.dart
pkgs/html/lib/dom_parsing.dart
pkgs/html/lib/html_escape.dart
pkgs/html/lib/parser.dart
pkgs/html/lib/src/constants.dart
pkgs/html/lib/src/encoding_parser.dart
pkgs/html/lib/src/html_input_stream.dart
pkgs/html/lib/src/list_proxy.dart
pkgs/html/lib/src/query_selector.dart
pkgs/html/lib/src/token.dart
pkgs/html/lib/src/tokenizer.dart
pkgs/html/lib/src/treebuilder.dart
pkgs/html/lib/src/utils.dart
pkgs/html/test/dom_test.dart
pkgs/html/test/parser_feature_test.dart
pkgs/html/test/parser_test.dart
pkgs/html/test/query_selector_test.dart
pkgs/html/test/selectors/level1_baseline_test.dart
pkgs/html/test/selectors/level1_lib.dart
pkgs/html/test/selectors/selectors.dart
pkgs/html/test/support.dart
pkgs/html/test/tokenizer_test.dart
pkgs/html/test/trie_test.dart
pkgs/html/tool/generate_trie.dart
pkgs/pubspec_parse/test/git_uri_test.dart
pkgs/stack_trace/example/example.dart
pkgs/watcher/test/custom_watcher_factory_test.dart
pkgs/yaml_edit/example/example.dart

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

@liamappelbe liamappelbe changed the title [coverage] Workspace support [coverage] Partial workspace support May 20, 2025
@coveralls
Copy link

Pull Request Test Coverage Report for Build 15153463985

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 22 of 22 (100.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 93.775%

Totals Coverage Status
Change from base Build 15090578894: 0.2%
Covered Lines: 693
Relevant Lines: 739

💛 - Coveralls

@liamappelbe liamappelbe marked this pull request as ready for review May 21, 2025 05:34
@liamappelbe liamappelbe requested review from a team as code owners May 21, 2025 05:34
@liamappelbe liamappelbe requested a review from bkonyi May 21, 2025 05:39
Copy link
Member

@mosuem mosuem left a comment

Choose a reason for hiding this comment

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

(LGTM for ecosystem-team)

@@ -93,13 +86,13 @@ ArgParser _createArgParser(CoverageOptions defaultOptions) => ArgParser()
defaultsTo: defaultOptions.scopeOutput,
help: 'restrict coverage results so that only scripts that start with '
'the provided package path are considered. Defaults to the name of '
'the package under test.')
'the current package (including all subpackages, if this is a '
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm assuming one can still specify which subpackages one want coverage for with --scope-output manually?

E.g.

  • pkgs/
    • my_package/
      • lib/ <-- I want coverage for this.
      • test_data/
        • my_test_package/
          • lib/ <-- I don't want coverage for this

If I use dart pub global run coverage:test_with_coverage --scope-output my_package -- pkgs/my_package/test will that do what I want?

The test projects are usually part of the workspace w.r.t. analysis. However, they are not part of the packages we want code coverage stats for.

(I know it's not what this PR is doing, because it's automating the --scope-output if not provided. But maybe we can add a test for this use case. Fine to do that in a separate PR.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The scoping is based on the package URI:

package:my_package/my_package.dart
        \________/
          scope

my_test_package is a separate package with a different URI, so dart pub global run coverage:test_with_coverage -- pkgs/my_package/test should work. But yeah, you can also provide the scopes manually if you want.

@@ -218,8 +208,9 @@ Future<void> main(List<String> arguments) async {
);
final serviceUri = await serviceUriCompleter.future;

final scopes =
flags.scopeOutput.isEmpty ? [flags.packageName] : flags.scopeOutput;
final scopes = flags.scopeOutput.isEmpty
Copy link
Contributor

Choose a reason for hiding this comment

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

This completely removes the packageName rather than deprecating it right? Better to fully remove it then if it's not supported anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would be a breaking change.

- Partial support for workspace packages in `test_wth_coverage`.
- Deprecate `test_wth_coverage`'s `--package-name` flag, because it doesn't make
sense for workspaces.
- Change the default `--port` to 0, allowing the VM to choose a free port.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any possibility that a user will be assuming that 8181 is being used by default? If the VM service from the spawned process is something we expect users to want to connect to, this is a breaking change in behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I considered that, but it seems pretty unlikely. I'd expect people to be manually specifying the port if they need that sort of thing.

@liamappelbe liamappelbe merged commit 89997b0 into main May 22, 2025
19 checks passed
@liamappelbe liamappelbe deleted the cov_workspaces branch May 22, 2025 23:21
@@ -15,6 +15,7 @@ dependencies:
meta: ^1.0.2
package_config: ^2.0.0
path: ^1.8.0
pubspec_parse: ^1.5.0
Copy link
Member

Choose a reason for hiding this comment

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

Can you switch to using package:yaml? This package has a dep on checked_yaml, which is not available in the sdk repo.

Copy link
Contributor Author

@liamappelbe liamappelbe May 27, 2025

Choose a reason for hiding this comment

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

When I switch to package:yaml, I'm still pulling in pubpsec_parse as an indirect dep:
build_runner -> build_config -> pubpsec_parse
This indirect dep has been around for a long time, but I guess that hasn't been an issue before because build_runner is a dev dependency?

Copy link
Member

Choose a reason for hiding this comment

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

That's likely it - I think we're just being affected by the non-dev dependencies when trying to resolve in the sdk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:coverage type-infra A repository infrastructure change or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[coverage] Recover from dartdev socket already in use (instead of hanging)
6 participants