Skip to content
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

Expanded test coverage for pnpm lockfile processing #2004

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Silic0nS0ldier
Copy link

Split from #1924

This PR primarily serves to add test cases to cover the malformed package label generation that #1924 aims to fix, such that the changes in that other PR are more obvious.

Additionally;

  • Adds .git to .bazelignore (editors see .git when inspecting test logs otherwise)
  • Fixed typo file -> find in npm/private/npm_translate_lock_generate.bzl
  • Documented params for _new_package_info in npm/private/pnpm.bzl
  • Documented and tested _convert_pnpm_v6_v9_version_peer_dep in npm/private/pnpm.bzl
  • Added tests for v6 and v9 lockfiles covering current behaviour around injected deps (unsupported feature that is non-fatal when used in v6 and now v9)
  • Remove inlined JSON in favour of Starlark + json.encode in npm/private/test/parse_pnpm_lock_tests.bzl
  • Added test suite target for //npm/private/test:test_parse_pnpm_lock

Changes are visible to end-users: yes(-ish)

  • Searched for relevant documentation and updated as needed: yes
  • Breaking change (forces users to change their own code or config): no
  • Suggested release notes appear below: no

Test plan

NA, PR is adding new tests with little/no behaviour changes.

Copy link

aspect-workflows bot commented Oct 29, 2024

Test

2 test targets passed

Targets
//npm/private:_test_gendocs_0_0 [k8-fastbuild]                 52ms
//npm/private:_test_gendocs_0_1 [k8-fastbuild]                 39ms

Total test execution time was 91ms. 204 tests (99.0%) were fully cached saving 39s.


Test

e2e/bzlmod

All tests were cache hits

5 tests (100.0%) were fully cached saving 789ms.


Test

e2e/gyp_no_install_script

All tests were cache hits

2 tests (100.0%) were fully cached saving 169ms.


Test

e2e/js_image_oci

All tests were cache hits

1 test (100.0%) was fully cached saving 8s.


Test

e2e/npm_link_package

All tests were cache hits

3 tests (100.0%) were fully cached saving 920ms.


Test

e2e/npm_link_package-esm

All tests were cache hits

3 tests (100.0%) were fully cached saving 924ms.


Test

e2e/npm_translate_lock

All tests were cache hits

1 test (100.0%) was fully cached saving 27ms.


Test

e2e/npm_translate_lock_empty

All tests were cache hits

1 test (100.0%) was fully cached saving 27ms.


Test

e2e/npm_translate_lock_multi

All tests were cache hits

2 tests (100.0%) were fully cached saving 296ms.


Test

e2e/npm_translate_lock_partial_clone

All tests were cache hits

1 test (100.0%) was fully cached saving 112ms.


Test

e2e/npm_translate_lock_replace_packages

All tests were cache hits

3 tests (100.0%) were fully cached saving 233ms.


Test

e2e/npm_translate_lock_subdir_patch

All tests were cache hits

1 test (100.0%) was fully cached saving 236ms.


Test

e2e/npm_translate_package_lock

All tests were cache hits

1 test (100.0%) was fully cached saving 81ms.


Test

e2e/npm_translate_yarn_lock

All tests were cache hits

1 test (100.0%) was fully cached saving 81ms.


Test

e2e/package_json_module

All tests were cache hits

1 test (100.0%) was fully cached saving 504ms.


Test

e2e/pnpm_lockfiles

All tests were cache hits

40 tests (100.0%) were fully cached saving 3s.


Test

e2e/pnpm_workspace

All tests were cache hits

10 tests (100.0%) were fully cached saving 2s.


Test

e2e/pnpm_workspace_rerooted

All tests were cache hits

12 tests (100.0%) were fully cached saving 3s.


Test

e2e/repo_mapping

All tests were cache hits

2 tests (100.0%) were fully cached saving 493ms.


Test

e2e/rules_foo

All tests were cache hits

2 tests (100.0%) were fully cached saving 153ms.


Test

e2e/runfiles

All tests were cache hits

1 test (100.0%) was fully cached saving 443ms.


Test

e2e/vendored_node

All tests were cache hits

1 test (100.0%) was fully cached saving 171ms.


Buildifier      Format

@@ -23,3 +23,4 @@ node_modules/
npm/private/test/node_modules/
npm/private/test/npm_package/node_modules/
npm/private/test/npm_package_publish/node_modules
.git
Copy link
Member

Choose a reason for hiding this comment

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

I don't think I've ever seen this in any bazel repo, do you have any more info on this?

Copy link
Author

Choose a reason for hiding this comment

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

Bazel does not ignore .git by default, meaning commands like bazel build //... also search in .git for BUILD files.

This is bad for performance (especially in a large repository with a long history).

Additionally while rare, a .git directory could have a file Bazel will attempt to process. For example a branch called BUILD would create a file .git/refs/remotes/origin/BUILD containing the hash of the commit it current points to. Utter nonsense to Bazel that will fail the build/query/etc.

}
}
""")
parsed_json = pnpm.parse_pnpm_lock_json(json.encode({
Copy link
Member

@jbedard jbedard Oct 29, 2024

Choose a reason for hiding this comment

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

Why switch to objects instead of JSON strings? When I'm writing these tests I always generate a pnpm-lock and then paste it into here, converting to json sounds like extra work when writing tests?

Copy link
Author

Choose a reason for hiding this comment

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

Happy to switch this back.

I've forgotten the exact reason I did this, my guess is the syntax highlighting just made it easier to scan when comparing inputs to outputs. Could also just be habit, in a few internal Rust projects we use a json! macro so the data is expressed in the "host" language, meaning it'll be processed by existing tooling (e.g. formatters).

I do remember being annoyed that repr has no way of returning indented output.

Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer just switching it back. If you really want to debate it I'd rather debate it in a different PR so we can merge the rest of your changes sooner rather then later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants