Skip to content

Fix package ownership for nested packages and for package.yml with package.json - #156

Merged
dduugg merged 3 commits into
mainfrom
nearest-package-owners
Nov 17, 2026
Merged

dduugg merged 3 commits into
mainfrom
nearest-package-owners

Conversation

@dduugg

@dduugg dduugg commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Found while scoping #69. Both are bugs in today's behavior, independent of the precedence discussion there.

What

  • In validate, a file in a nested package now belongs to the nearest package of its type, as it already does in CODEOWNERS and for-file.
  • for-file now reports both packages when one directory has a package.yml and a package.json, as validate already does.
  • The version goes to 0.7.2, so merging this cuts a patch release.

Why

Nested packages. The package mappers built a matcher only for the outermost of a set of nested packages, so validate gave a file in a nested package the outer package's team. CODEOWNERS and for-file give it the nested package's team. A full validate didn't notice. But validate <files> compares each file's owner with CODEOWNERS, so it failed with "CODEOWNERS out of date", which regenerating can't fix. A package at the project root encloses every other package, so with one, every file in another package failed this way.

A package.yml and a package.json in one directory. for-file stopped at the first package it found, checking package.yml first. When the two named different teams, it answered with the package.yml's team, while validate reported two owners.

How

  • PackageMapper::owner_matchers gives each package's matcher the directories of the packages of its type nested directly in it as subtracted globs. Sorting the packages by root puts a package's descendants right after it, so this is one pass. remove_nested_packages is gone.
  • A package naming a team that doesn't exist still gets no matcher and isn't subtracted, so its files fall through to the enclosing package, as in CODEOWNERS and for-file.
  • nearest_package_owners returns every package in the nearest directory that has one naming a known team.

Behavior change

  • A file in a nested package that another source gives the outer package's team, such as an annotation, a team glob or a .codeowner, now has two owners in validate. for-file already reported it that way, so validate can newly fail on such a file.
  • For a directory with both package files naming different teams, for-file now fails with "file is owned by multiple teams". code_ownership's for_file takes the first owner, which is now the first by team name, as for any other tie, rather than the package.yml's team.
  • The CODEOWNERS file doesn't change.

Out of scope

A package of one type nested in a package of the other, such as a package.json inside a package.yml directory, still gives validate two owners, while for-file picks the nearer one and CODEOWNERS always picks the package.json. Choosing one answer for that is part of the precedence proposal in #69.

Tests

  • tests/package_ownership_test.rs. Each test fails on main:
    • Nested Ruby and JavaScript packages: validate <files> passes, and for-file with and without --from-codeowners gives each file the nearer package.
    • A package inside a root package: validate <files> passes.
    • An annotation naming the outer package's team on a nested package's file: validate reports two owners, as for-file does.
    • A package.yml and a package.json naming different teams: for-file reports both, as validate does.
  • Unit tests: the package matchers leave out nested packages (directly nested only, skipping unknown teams and a sibling whose name starts the same), the mapper resolver gives each file its nearest package, and nearest_package_owners returns both package files in one directory. The two remove_nested_packages tests are removed, and the root package test now expects the nested package to be left out.
  • Checks: cargo test (341 passed, 3 ignored), cargo clippy --all-targets --all-features -- -D warnings and cargo fmt --all -- --check.

`validate` built a matcher for only the outermost of a set of nested
packages of one type, so a file in a nested package got the outer
package's team. CODEOWNERS and `for-file` give it the nested package's
team. A full `validate` didn't notice, but `validate <files>` compares
each file's owner with CODEOWNERS, so it failed with "CODEOWNERS out of
date", which regenerating can't fix. A package at the project root
encloses every other package, so with one, every file in another
package failed this way.

Each package's matcher now leaves out the packages of its type nested
in it, so a file matches only its nearest package. A package naming a
team that doesn't exist still gets no matcher, so its files still fall
through to the enclosing package, as in CODEOWNERS and `for-file`.

A file in a nested package that another source gives the outer
package's team, such as an annotation, now has two owners in
`validate`, as it already did in `for-file`.
…json

`for-file` stopped at the first package it found in the nearest
directory with one, checking `package.yml` before `package.json`. In a
directory with both, naming different teams, it gave the
`package.yml`'s team, while `validate` matches both and reports the
file as having two owners.

It now returns both, so `for-file` reports the conflict that `validate`
does, and lists both files when they name one team. code_ownership's
`for_file` takes the first owner, which is now the first by team name,
as for any other tie.
@dduugg
dduugg requested a review from a team as a code owner November 17, 2026 19:26
@github-project-automation github-project-automation Bot moved this to Triage in Modularity Nov 17, 2026
@dduugg
dduugg merged commit 90dd3c5 into main Nov 17, 2026
15 checks passed
@dduugg
dduugg deleted the nearest-package-owners branch November 17, 2026 22:44
@github-project-automation github-project-automation Bot moved this from Triage to Done in Modularity Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant