You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor(hack): make licenses tool unit-testable - #1541
Splits hack/licenses/main.go into main.go (flags, run, repo root), modules.go (go list pipeline and encoding), and detector.go (detector run, sync check, newline normalisation). Adds a commandRunner seam on generator, following hack/microsandbox, and unit tests that use a fake runner. No real go or git runs in tests.
Why
hack/licenses had no tests. Its only check was the CI --check run, which needs network and the Go toolchain.
Validation
mise run cli:format: exit 0, no changes.
mise run cli:lint:ci: 0 issues.
go test -count=1 ./hack/licenses/...: pass (7 test functions).
go vet on Linux and GOOS=windows: clean.
go run ./hack/licenses --check: exit 0. Stderr matches the pre-change baseline byte-for-byte after normalising temp paths.
go run ./hack/unit_test_packages: includes github.com/devsy-org/devsy/hack/licenses.
CodeRabbit CLI
coderabbit review --agent --committed against origin/main: 0 findings on 7 files.
CI coverage
licenses job (pr-ci.yml): runs on hack/licenses/** changes and executes go run ./hack/licenses --check.
Unit-test job: unit_test_packages picks up the new tests.
Auto-merge
Eligible under the ci-refactor policy: tooling-only under hack/, no workflow, go.mod, or product changes. Non-test diff is about 370 changed lines across 3 files.
Notes
Behaviour is unchanged. Flags, stderr text, and exit codes are the same.
checkInSync still returns nil when the file is out of date. It prints a diff and a warning. This is existing behaviour and is pinned by TestCheckInSync. Changing it would make the CI --check step fail, so it is a separate decision.
Baseline drift is pre-existing: on origin/main, THIRD_PARTY_LICENSES.md lags posthog-go (v1.25.1 to v1.25.2) and ginkgo/v2 (v2.32.1 to v2.32.2). This PR does not regenerate it.
Summary by CodeRabbit
Chores
License reports now include dependencies across release targets in a consistent, sorted format.
Check mode identifies when a report is out of date and displays the differences without treating them as a command error.
Missing reports and failures to collect dependency information are reported as errors.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 95a2fc6e-e441-4649-80fb-2bc516b3b771
📥 Commits
Reviewing files that changed from the base of the PR and between adbf08d and e21eadd.
📒 Files selected for processing: 7
hack/licenses/detector.go
hack/licenses/detector_test.go
hack/licenses/fake_runner_test.go
hack/licenses/main.go
hack/licenses/main_test.go
hack/licenses/modules.go
hack/licenses/modules_test.go
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.
📝 Walkthrough
The license generator now collects third-party modules across release targets and uses the combined list to generate or check the license report. Report generation and synchronization checks are implemented in detector.go, while main.go delegates to the generator.
Changes: License report generation
Layer / File(s)
Summary
Collect and encode modules hack/licenses/modules.go, hack/licenses/modules_test.go, hack/licenses/fake_runner_test.go
The module collector decodes package streams for each release target, excludes main modules and empty paths, merges modules by path, and encodes them in sorted order. Tests cover filtering, deterministic output, and target-specific failures.
Generate or check reports hack/licenses/detector.go, hack/licenses/detector_test.go
The detector writes report output with exactly one trailing newline. Check mode compares generated and existing reports, prints a diff and warning for outdated content, and returns errors for generation or file-read failures. Tests cover output normalization and synchronization cases.
Wire generator entry point hack/licenses/main.go, hack/licenses/main_test.go
run resolves the repository root and delegates to generator.generate, which collects modules and selects check or generation mode. Repository-root tests cover root, nested, and missing-module cases.
sequenceDiagram
participant run
participant generator.generate
participant moduleListJSON
participant buildModules
participant go_list as go list
participant checkInSync
participant runDetector
run->>generator.generate: delegate generation
generator.generate->>moduleListJSON: collect dependency modules
loop each release target
moduleListJSON->>buildModules: list target modules
buildModules->>go_list: run go list for target
go_list-->>buildModules: package JSON stream
buildModules-->>moduleListJSON: decoded modules
end
moduleListJSON-->>generator.generate: sorted module JSON
alt check mode
generator.generate->>checkInSync: compare generated report
else generation mode
generator.generate->>runDetector: generate report
end
Loading
Merge Risk:⚪ Minimal · up to e21ea
No issue requiring a fix before merge remains from this review.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 7 files.
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 4 passed
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title clearly and concisely describes the main change: refactoring the licenses tool to make it unit-testable.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Fix all pre-merge checks with AI
✨ Finishing Touches
✨ Simplify code
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Splits
hack/licenses/main.gointomain.go(flags, run, repo root),modules.go(go listpipeline and encoding), anddetector.go(detector run, sync check, newline normalisation). Adds acommandRunnerseam ongenerator, followinghack/microsandbox, and unit tests that use a fake runner. No realgoorgitruns in tests.Why
hack/licenseshad no tests. Its only check was the CI--checkrun, which needs network and the Go toolchain.Validation
mise run cli:format: exit 0, no changes.mise run cli:lint:ci: 0 issues.go test -count=1 ./hack/licenses/...: pass (7 test functions).go veton Linux andGOOS=windows: clean.go run ./hack/licenses --check: exit 0. Stderr matches the pre-change baseline byte-for-byte after normalising temp paths.go run ./hack/unit_test_packages: includesgithub.com/devsy-org/devsy/hack/licenses.CodeRabbit CLI
coderabbit review --agent --committedagainstorigin/main: 0 findings on 7 files.CI coverage
licensesjob (pr-ci.yml): runs onhack/licenses/**changes and executesgo run ./hack/licenses --check.unit_test_packagespicks up the new tests.Auto-merge
Eligible under the ci-refactor policy: tooling-only under
hack/, no workflow,go.mod, or product changes. Non-test diff is about 370 changed lines across 3 files.Notes
checkInSyncstill returns nil when the file is out of date. It prints a diff and a warning. This is existing behaviour and is pinned byTestCheckInSync. Changing it would make the CI--checkstep fail, so it is a separate decision.origin/main,THIRD_PARTY_LICENSES.mdlagsposthog-go(v1.25.1 to v1.25.2) andginkgo/v2(v2.32.1 to v2.32.2). This PR does not regenerate it.Summary by CodeRabbit