Skip to content

Conversation

@Snider
Copy link
Owner

@Snider Snider commented Nov 4, 2025

No description provided.

Adds `go vet ./...` to the `test` task in Taskfile.yml to ensure static analysis is performed during testing.
Adds `go vet`, race detection, and fuzz testing to the GitHub Actions workflow. This will improve the quality and robustness of the codebase.
Adds `go vet` to the test procedures in both the local `Taskfile.yml` and the GitHub Actions workflow.

Also includes the following changes:
- Refactors the `trix` CLI to use the `cobra` library to improve testability.
- Adds comprehensive tests for the `trix` CLI, achieving 100% test coverage.
- Fixes a closure bug in the sigil command creation loop.
- Refactors the CLI to use Cobra's I/O writers, making the output testable.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 4, 2025

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • New Features

    • Restructured command-line interface with dedicated subcommands (encode, decode, hash, dynamic sigils).
    • Improved input/output handling now supports stdin, file paths, and direct string inputs.
  • Tests

    • Added comprehensive test suite covering all CLI commands and error scenarios.
    • Integrated static analysis checks into the testing pipeline for improved code quality.

Walkthrough

Migrates CLI from clir to Cobra with new subcommands (encode, decode, hash, dynamic sigils); adds IsHashAlgo validator; introduces go vet and a separate fuzz job in CI; alters Taskfile test task to run go vet before tests; adds comprehensive CLI tests and related helpers.

Changes

Cohort / File(s) Summary
CI / Task runner
.github/workflows/go.yml, Taskfile.yml
Reworked CI to run go vet as a separate Vet step, updated Test step to use -race and -covermode=atomic, added a Fuzz step (-run=Fuzz -fuzztime=10s); Taskfile test command now runs go vet ./... before go test.
CLI implementation
cmd/trix/main.go
Replaced clir with Cobra; introduced root command and subcommands (encode, decode, hash, dynamic sigils); unified stdin/file/string input handling, output routing, and RunE-based handlers.
Tests
cmd/trix/main_test.go
Added tests for root, encode/decode, and hash commands; added helpers executeCommand and executeCommandWithStdin; added subprocess main-function coverage test.
Dependencies
go.mod
Replaced github.com/leaanthony/clir with github.com/spf13/cobra; added indirect deps (mousetrap, pflag).
Validation
pkg/crypt/crypt.go
Added IsHashAlgo(algo string) bool method on Service to validate supported hash algorithm names (LTHN, SHA512, SHA256, SHA1, MD5).

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant CLI as trix (root)
    participant Sub as Subcommand
    participant H as RunE Handler
    participant Core as trix/crypt logic
    participant IO as Stdout/File

    U->>CLI: trix [command] [flags]
    CLI->>Sub: select subcommand
    Sub->>Sub: parse flags (input/output/magic)
    Sub->>H: invoke RunE
    H->>H: determine input source (stdin/file/string)
    H->>Core: process payload (encode/decode/hash/sigil)
    Core-->>H: result / error
    alt success
        H->>IO: write result
        IO-->>U: output
    else error
        H-->>CLI: return error
        CLI-->>U: exit non‑zero
    end
Loading

Possibly related PRs

Poem

🐰 I hopped through flags and cobra trails,

vet sniffed the code for tiny fails,
tests raced fast and coverage sang,
fuzz poked holes where edge-cases hang,
I nibble bugs and dance in glee. ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title 'Feature add go vet' is misleading as the primary changes involve migrating the CLI from 'clir' to 'Cobra' framework and restructuring commands; go vet is only a secondary improvement in the CI/build workflow. Consider a more accurate title such as 'Migrate CLI from clir to Cobra framework with subcommands' to better reflect the main architectural change.
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to assess whether it relates to the changeset. Add a pull request description explaining the motivation and scope of changes, particularly the CLI framework migration and go vet enhancements.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature-add-go-vet

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
cmd/trix/main.go (2)

5-5: Replace deprecated ioutil package.

The ioutil package has been deprecated since Go 1.16. Functions have been moved to io and os packages:

  • ioutil.ReadAllio.ReadAll
  • ioutil.ReadFileos.ReadFile
  • ioutil.WriteFileos.WriteFile

Apply this diff:

 import (
 	"fmt"
-	"io/ioutil"
+	"io"
 	"os"

162-197: Good validation and I/O handling; replace deprecated ioutil calls in encode.

The magic number validation and stdin/stdout support are well-implemented, but multiple deprecated ioutil functions are used.

Apply this diff:

 	var data []byte
 	var err error
 	if inputFile == "" || inputFile == "-" {
-		data, err = ioutil.ReadAll(cmd.InOrStdin())
+		data, err = io.ReadAll(cmd.InOrStdin())
 	} else {
-		data, err = ioutil.ReadFile(inputFile)
+		data, err = os.ReadFile(inputFile)
 	}
 	if err != nil {
 		return err
 	}
 
 	t := &trix.Trix{
 		Header:   make(map[string]interface{}),
 		Payload:  data,
 		InSigils: sigils,
 	}
 
 	if err := t.Pack(); err != nil {
 		return err
 	}
 
 	encoded, err := trix.Encode(t, magicNumber, nil)
 	if err != nil {
 		return err
 	}
 
 	if outputFile == "" || outputFile == "-" {
 		_, err = cmd.OutOrStdout().Write(encoded)
 		return err
 	}
-	return ioutil.WriteFile(outputFile, encoded, 0644)
+	return os.WriteFile(outputFile, encoded, 0644)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c5de118 and 695fe6d.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (6)
  • .github/workflows/go.yml (1 hunks)
  • Taskfile.yml (1 hunks)
  • cmd/trix/main.go (3 hunks)
  • cmd/trix/main_test.go (1 hunks)
  • go.mod (1 hunks)
  • pkg/crypt/crypt.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
pkg/crypt/crypt.go (3)
pkg/crypt/std/rsa/rsa.go (1)
  • Service (13-13)
examples/main.go (1)
  • demoHashing (129-148)
tdd/crypt/crypt_test.go (3)
  • TestHash_Good (15-22)
  • TestHash_Bad (24-29)
  • TestHash_Ugly (31-47)
cmd/trix/main.go (3)
pkg/enchantrix/sigils.go (3)
  • NewSigil (193-246)
  • s (79-89)
  • s (45-49)
pkg/crypt/crypt.go (2)
  • NewService (23-27)
  • HashType (30-30)
pkg/trix/trix.go (2)
  • Trix (30-36)
  • Decode (103-176)
cmd/trix/main_test.go (1)
tdd/trix/trix_test.go (5)
  • TestTrixEncodeDecode_Good (14-33)
  • TestChecksum_Good (178-190)
  • TestPackUnpack_Good (129-144)
  • interface{} (15-15)
  • interface{} (233-233)
🔇 Additional comments (12)
Taskfile.yml (1)

7-7: LGTM! Excellent addition of static analysis.

Adding go vet before tests ensures that static analysis issues are caught early in the development workflow, aligning perfectly with the CI/CD changes.

go.mod (1)

6-6: LGTM! Dependency migration to Cobra is correct.

The replacement of clir with Cobra v1.10.1 and its indirect dependencies (mousetrap, pflag) correctly supports the CLI refactoring implemented in cmd/trix/main.go.

Also applies to: 13-13, 15-15

pkg/crypt/crypt.go (1)

42-50: LGTM! Hash algorithm validation is correctly implemented.

The IsHashAlgo method properly validates against all defined HashType constants (LTHN, SHA512, SHA256, SHA1, MD5) and provides the necessary validation support for the CLI hash command.

.github/workflows/go.yml (1)

26-33: LGTM! Comprehensive CI/CD improvements.

The three-step approach (Vet → Test with race detection → Fuzz) significantly enhances code quality assurance. The combination of -race with -covermode=atomic is correct, and the 10-second fuzz testing provides good coverage without excessive runtime.

cmd/trix/main.go (3)

50-76: LGTM! Well-structured command initialization.

The flag definitions and dynamic sigil command generation are well-organized. The approach of creating commands for each sigil type in a loop is clean and maintainable.


78-89: LGTM! Clean command execution pattern.

The closure-based createSigilRunE helper and the testable main function (using the exit variable) demonstrate good design practices for CLI applications.


91-108: LGTM! Consistent command handler pattern.

The RunE handlers correctly delegate to their respective handle* functions. Ignoring errors from GetString is acceptable as these flags have defaults and Cobra ensures they exist.

cmd/trix/main_test.go (5)

13-35: LGTM! Well-designed test helper functions.

The test helpers properly configure Cobra commands for testing, with executeCommandWithStdin correctly resetting stdin after execution to prevent test pollution. This is essential for reliable test execution.


37-41: LGTM! Good baseline test for root command.

This test ensures the root command help text is displayed correctly, providing a simple smoke test for the CLI's basic functionality.


43-67: LGTM! Comprehensive encode/decode round-trip test.

The test effectively validates the complete encode/decode workflow with sigil transformation. The round-trip test with the "reverse" sigil ensures correctness of the transformation pipeline.


69-91: LGTM! Thorough hash command testing.

The test covers both file and stdin input methods, validates correct hash output, and tests error cases (missing arguments, invalid algorithm, non-existent file). This provides excellent coverage of the hash command functionality.


93-106: LGTM! Correct pattern for testing main function.

The subprocess pattern using GO_TEST_MAIN environment variable is the standard approach for testing main() functions that call os.Exit, ensuring coverage whilst avoiding premature test termination.

This commit fixes the fuzz test in the GitHub Actions workflow by correctly scoping it to the `pkg/trix` package. The `go test -fuzz` command can only be run on a single package at a time.

This also corrects the `-run` flag to ensure the fuzz test is executed correctly.
@codecov
Copy link

codecov bot commented Nov 4, 2025

Codecov Report

❌ Patch coverage is 56.62651% with 36 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/trix/main.go 61.03% 21 Missing and 9 partials ⚠️
pkg/crypt/crypt.go 0.00% 6 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 695fe6d and b17d329.

📒 Files selected for processing (1)
  • .github/workflows/go.yml (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (2)
.github/workflows/go.yml (2)

26-27: Static analysis step follows build and precedes tests—best practice.

The go vet ./... step is correctly positioned in the CI pipeline to catch static analysis issues before unit tests run, aligning with the PR objective to introduce go vet into the workflow.


29-30: Race detection with atomic coverage mode is correct.

Adding the -race flag and -covermode=atomic to the test step is appropriate. Atomic coverage mode prevents instrumentation conflicts that would otherwise occur when both race detection and coverage instrumentation are enabled simultaneously.

@Snider Snider merged commit 248de1e into main Nov 4, 2025
2 of 3 checks passed
@Snider Snider deleted the feature-add-go-vet branch November 4, 2025 13:22
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