Skip to content

refactor(hack): make licenses tool unit-testable - #1541

Merged
skevetter merged 1 commit into
mainfrom
refactor/hack-licenses-testable
Oct 18, 2026
Merged

skevetter merged 1 commit into
mainfrom
refactor/hack-licenses-testable

Conversation

@skevetter

@skevetter skevetter commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

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.

@skevetter skevetter added the ci-refactor CI/e2e refactor label Oct 18, 2026
@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

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.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Sequence Diagram(s)

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: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning 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 Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: refactoring the licenses tool to make it unit-testable.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@netlify

netlify Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for devsydev canceled.

Name Link
🔨 Latest commit e21eadd
🔍 Latest deploy log https://app.netlify.com/projects/devsydev/deploys/6ad468b0d488cb754081e500

@netlify

netlify Bot commented Oct 18, 2026

Copy link
Copy Markdown

👷 Deploy Preview for images-devsy-sh processing.

Name Link
🔨 Latest commit e21eadd
🔍 Latest deploy log https://app.netlify.com/projects/images-devsy-sh/deploys/6ad468b043409751d649978d

@netlify

netlify Bot commented Oct 18, 2026

Copy link
Copy Markdown

✅ Deploy Preview for images-devsy-sh canceled.

Name Link
🔨 Latest commit e21eadd
🔍 Latest deploy log https://app.netlify.com/projects/images-devsy-sh/deploys/6ad468b043409751d649978d

@skevetter
skevetter marked this pull request as ready for review October 18, 2026 07:22
@mergify

mergify Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@skevetter
skevetter merged commit 62820b0 into main Oct 18, 2026
111 checks passed
@skevetter
skevetter deleted the refactor/hack-licenses-testable branch October 18, 2026 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-refactor CI/e2e refactor size/xl

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant