Skip to content

feat(update): verify release metadata by target#97

Merged
anandh8x merged 2 commits into
mainfrom
feat/update-check-target
Jun 6, 2026
Merged

feat(update): verify release metadata by target#97
anandh8x merged 2 commits into
mainfrom
feat/update-check-target

Conversation

@anandh8x

@anandh8x anandh8x commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add update target resolution for release asset names such as windows-x64 and macos-arm64
  • expose zero update --check --target so one machine can validate another platform's release metadata
  • keep default behavior as current-platform validation when --target is omitted
  • document supported targets and add CLI/backend tests

Validation

  • GOCACHE=/tmp/zero-go-cache go test ./internal/update ./internal/cli -run 'TestResolveTarget|TestCheck|TestRunUpdate'
  • GOCACHE=/tmp/zero-go-cache go test ./...
  • GOCACHE=/tmp/zero-go-cache go run ./cmd/zero-release build
  • ./zero update --check --target windows-x64 --endpoint 'data:application/json,%7B%22tag_name%22%3A%22v0.2.0%22%2C%22html_url%22%3A%22https%3A%2F%2Fexample.test%2Frelease%22%2C%22assets%22%3A%5B%7B%22name%22%3A%22zero-v0.2.0-windows-x64.zip%22%2C%22browser_download_url%22%3A%22https%3A%2F%2Fexample.test%2Fzero-v0.2.0-windows-x64.zip%22%7D%2C%7B%22name%22%3A%22zero-v0.2.0-windows-x64.zip.sha256%22%2C%22browser_download_url%22%3A%22https%3A%2F%2Fexample.test%2Fzero-v0.2.0-windows-x64.zip.sha256%22%7D%5D%7D' --json
  • git diff --check

Summary by CodeRabbit

  • New Features

    • Added a --target flag to zero update --check to allow checking releases for specific platforms (Linux, macOS, Windows; x64/arm64), instead of only the current system.
  • Documentation

    • Updated command docs and examples to describe --target <platform-arch>, supported targets, and platform-specific release checks.
  • Tests

    • Added tests covering target resolution, validation, and invalid-target behavior for the update check.

@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Zero automated PR review

Verdict: No blockers found

Blockers

  • None found.

Validation

  • [pass] Diff hygiene: git diff --check
  • [pass] Tests: go test ./...
  • [pass] Build: go run ./cmd/zero-release build
  • [pass] Smoke build: go run ./cmd/zero-release smoke

Scope

Head: da07c7300dac
Changed files (6): README.md, docs/UPDATE.md, internal/cli/app_test.go, internal/cli/update.go, internal/update/update.go, internal/update/update_test.go

This deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality.

@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown

Need the big picture first? Review this PR in Change Stack to see what changed before going file by file.

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6bf12933-348c-4fc2-afba-c8b1d6ea20ea

📥 Commits

Reviewing files that changed from the base of the PR and between e1791f3 and da07c73.

📒 Files selected for processing (3)
  • internal/cli/app_test.go
  • internal/cli/update.go
  • internal/update/update_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/update/update_test.go
  • internal/cli/app_test.go

Walkthrough

Adds an optional --target <platform-arch> flag to zero update --check, with a new Target type and ResolveTarget, CLI parsing/validation and wiring into update checks, unit tests for resolution and CLI behavior, and updated README/UPDATE.md documentation.

Changes

--target flag for platform-specific update checks

Layer / File(s) Summary
Target type and resolution
internal/update/update.go, internal/update/update_test.go
New exported Target struct and ResolveTarget(target string) that normalize inputs and map supported names (linux-x64, linux-arm64, macos-x64, macos-arm64, windows-x64, windows-arm64) to GOOS/GOARCH, Platform, Arch, or return a descriptive error. Table-driven tests validate mappings and error cases.
CLI parsing, validation, and execution
internal/cli/update.go
updateOptions gains a target field; parseUpdateArgs accepts --target and --target=<...>; parseUpdateTarget trims/validates input; resolved targets set GOOS/GOARCH on local checkOptions before calling deps.checkUpdate; help text updated.
CLI tests and help text
internal/cli/app_test.go
TestRunUpdatePassesCheckOptions extended to pass --target and assert derived GOOS/GOARCH; adds TestRunUpdateRejectsInvalidTarget to assert usage exit and that checkUpdate is not called for invalid/empty targets; help text test updated to include --target.
User documentation
README.md, docs/UPDATE.md
README example updated to zero update --check --target windows-x64; UPDATE.md adds same example and documents --target <platform-arch>, platform-specific release validation (archive + .sha256), supported OS/arch values, and default behavior when omitted.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Gitlawb/zero#84: Related work around GOOS/GOARCH-driven release asset verification that this change integrates with via the new --target flag.

Suggested reviewers

  • gnanam1990
  • Vasanthdev2004
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 accurately reflects the main feature added: support for verifying release metadata against a specific target platform via the --target flag.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/update-check-target

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/update/update_test.go (1)

78-109: ⚡ Quick win

Add normalization and canonical-name assertions in TestResolveTarget.

This test only validates already-normalized inputs. Add cases with whitespace/casing variants and assert target.Name so resolver normalization behavior is locked down.

Suggested test expansion
 func TestResolveTarget(t *testing.T) {
 	tests := []struct {
-		target   string
+		input    string
+		name     string
 		goos     string
 		goarch   string
 		platform string
 		arch     string
 	}{
-		{target: "linux-x64", goos: "linux", goarch: "amd64", platform: "linux", arch: "x64"},
+		{input: "linux-x64", name: "linux-x64", goos: "linux", goarch: "amd64", platform: "linux", arch: "x64"},
+		{input: " WINDOWS-X64 ", name: "windows-x64", goos: "windows", goarch: "amd64", platform: "windows", arch: "x64"},
 		...
 	}
 
 	for _, tt := range tests {
-		t.Run(tt.target, func(t *testing.T) {
-			target, err := ResolveTarget(tt.target)
+		t.Run(tt.input, func(t *testing.T) {
+			target, err := ResolveTarget(tt.input)
 			if err != nil {
 				t.Fatalf("ResolveTarget returned error: %v", err)
 			}
-			if target.GOOS != tt.goos || target.GOARCH != tt.goarch || target.Platform != tt.platform || target.Arch != tt.arch {
-				t.Fatalf("ResolveTarget(%q) = %#v", tt.target, target)
+			if target.Name != tt.name || target.GOOS != tt.goos || target.GOARCH != tt.goarch || target.Platform != tt.platform || target.Arch != tt.arch {
+				t.Fatalf("ResolveTarget(%q) = %#v", tt.input, target)
 			}
 		})
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/update/update_test.go` around lines 78 - 109, Add test cases to
TestResolveTarget that exercise normalization by including inputs with extra
whitespace and mixed-case (e.g., " Linux-X64 ", "MacOS-Arm64") and assert the
returned ResolveTarget structure fields including target.Name equal the
canonical name (e.g., "linux-x64", "macos-arm64") in addition to existing checks
for GOOS, GOARCH, Platform and Arch; update the subtests to call ResolveTarget
on these variant strings and fail the test if err != nil or if target.Name does
not match the expected canonical name so the resolver’s normalization and
canonical-name behavior is locked down.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/cli/update.go`:
- Around line 112-121: The parser currently accepts empty or whitespace-only
--target values and silently sets options.target to "", causing runUpdate to use
the current machine instead of the requested target; update the handling in the
case for "--target" (the branch that calls nextFlagValue) and the
strings.HasPrefix("--target=") branch to validate after trimming: if the
resulting options.target is empty, return an error (from the flag-parsing
function) indicating that --target requires a non-empty value so the caller
(runUpdate) never receives an empty target.

---

Nitpick comments:
In `@internal/update/update_test.go`:
- Around line 78-109: Add test cases to TestResolveTarget that exercise
normalization by including inputs with extra whitespace and mixed-case (e.g., "
Linux-X64 ", "MacOS-Arm64") and assert the returned ResolveTarget structure
fields including target.Name equal the canonical name (e.g., "linux-x64",
"macos-arm64") in addition to existing checks for GOOS, GOARCH, Platform and
Arch; update the subtests to call ResolveTarget on these variant strings and
fail the test if err != nil or if target.Name does not match the expected
canonical name so the resolver’s normalization and canonical-name behavior is
locked down.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 371c82fe-f5a2-4ac9-a3d9-3f1d3dfc9fe5

📥 Commits

Reviewing files that changed from the base of the PR and between 3e4add9 and e1791f3.

📒 Files selected for processing (6)
  • README.md
  • docs/UPDATE.md
  • internal/cli/app_test.go
  • internal/cli/update.go
  • internal/update/update.go
  • internal/update/update_test.go

Comment thread internal/cli/update.go

@Vasanthdev2004 Vasanthdev2004 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Blockers

  • internal/cli/update.go: --target= is accepted as if no target was supplied, so the command silently validates the current machine's release asset instead of failing the malformed target flag. I reproduced this on the PR build with a Windows data endpoint: ./zero update --check --target= --endpoint <windows data: endpoint> --json exited 0 and reported zero-v0.2.0-windows-x64.zip. For release metadata validation this can give false confidence in CI or scripts when an empty target variable is passed; the inline --target= form should return a usage error just like the separated empty/flag-shaped value path.

Non-Blocking

  • The target mapping itself looks aligned with the release archive naming contract (linux/macos/windows + x64/arm64), and invalid explicit targets such as solaris-sparc fail closed with exit 2.

Looks Good

  • CLI option passthrough correctly maps --target windows-x64 to GOOS=windows / GOARCH=amd64 before calling update.Check.
  • Documentation covers the supported target names and preserves the default current-platform behavior when no target is supplied.
  • Validation run locally:
    • go test -count=1 ./internal/update ./internal/cli -run 'TestResolveTarget|TestCheck|TestRunUpdate'
    • go test -count=1 -p 1 ./...
    • go run ./cmd/zero-release build
    • ./zero update --check --target windows-x64 --endpoint <windows data: endpoint> --json
    • ./zero update --check --target solaris-sparc --json returned exit 2
    • git diff --check

@anandh8x
anandh8x requested a review from Vasanthdev2004 June 6, 2026 10:19

@Vasanthdev2004 Vasanthdev2004 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Blockers

  • None. The previous blocker on --target= has been fixed at da07c7300dac2f8f805a098b8c57db47abe92ae3: inline empty target values now return a usage error instead of silently falling back to the current platform, and the CLI regression test covers that path.

Non-Blocking

  • None.

Looks Good

  • Verified the incremental fix from the blocked head e1791f3ef446161fcfd4594e94f381ce9f7a45e9 to da07c7300dac2f8f805a098b8c57db47abe92ae3.
  • --target windows-x64 still maps to the expected Windows x64 release asset and verifies the data-endpoint payload.
  • Invalid targets still fail closed with exit 2.
  • Validation run locally:
    • go test -count=1 ./internal/update ./internal/cli -run 'TestResolveTarget|TestCheck|TestRunUpdate'
    • go test -count=1 -p 1 ./...
    • go run ./cmd/zero-release build
    • ./zero update --check --target= --json returned exit 2 with --target requires a non-empty value
    • ./zero update --check --target windows-x64 --endpoint <windows data: endpoint> --json
    • ./zero update --check --target solaris-sparc --endpoint <windows data: endpoint> --json returned exit 2
    • git diff --check

@anandh8x
anandh8x merged commit 699df01 into main Jun 6, 2026
6 checks passed
@Vasanthdev2004
Vasanthdev2004 deleted the feat/update-check-target branch June 28, 2026 08:27
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