Skip to content

chore(cmd): refactored main program#26

Merged
Ma11hewThomas merged 2 commits into
ctrf-io:mainfrom
fredbi:chore/improved-error-handling
Nov 29, 2025
Merged

chore(cmd): refactored main program#26
Ma11hewThomas merged 2 commits into
ctrf-io:mainfrom
fredbi:chore/improved-error-handling

Conversation

@fredbi
Copy link
Copy Markdown
Collaborator

@fredbi fredbi commented Nov 24, 2025

Another baby step forward:

  • refactored error and flags handling in main program
  • this improves testability, so we add a unit test for main

There is still some room for improvement (coverage, I/O injection for better control in a test environment). Essential options in main are covered by tests.

Another baby step forward:

* refactored error and flags handling in main program
* this improves testability, so we add a unit test for main

There is still some room for improvement (coverage, I/O injection for
better control in a test environment). Essential options in main
are covered by tests.

Signed-off-by: Frédéric BIDON <fredbi@yahoo.com>
@coveralls
Copy link
Copy Markdown

coveralls commented Nov 24, 2025

Pull Request Test Coverage Report for Build 19666678257

Details

  • 24 of 58 (41.38%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+10.3%) to 67.967%

Changes Missing Coverage Covered Lines Changed/Added Lines %
cmd/go-ctrf-json-reporter/main.go 24 58 41.38%
Files with Coverage Reduction New Missed Lines %
cmd/go-ctrf-json-reporter/main.go 1 40.96%
Totals Coverage Status
Change from base Build 19614637359: 10.3%
Covered Lines: 244
Relevant Lines: 359

💛 - Coveralls

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the main program to improve testability by extracting error handling and flag management into testable functions. The changes introduce a commandContext struct to hold CLI flags and I/O streams, an execute() function that can be independently tested, and comprehensive unit tests covering the main execution paths.

Key changes:

  • Extracted main logic into testable execute() function with dependency injection for I/O
  • Introduced commandContext and commandFlags structs for better organization
  • Added comprehensive unit tests for main program execution paths

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
cmd/go-ctrf-json-reporter/main.go Refactored main program with extracted execute(), registerFlags(), and ctrfEnvFromFlags() functions; introduced structs for better organization
cmd/go-ctrf-json-reporter/main_test.go Added comprehensive unit tests for main execution with various flag combinations
cmd/go-ctrf-json-reporter/testdata/test.json Added test fixture containing sample Go test JSON output for testing

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Comment thread cmd/go-ctrf-json-reporter/main.go Outdated
Comment thread cmd/go-ctrf-json-reporter/main.go Outdated
Comment thread cmd/go-ctrf-json-reporter/main_test.go
Comment thread cmd/go-ctrf-json-reporter/main_test.go
Comment thread cmd/go-ctrf-json-reporter/main_test.go
@fredbi
Copy link
Copy Markdown
Collaborator Author

fredbi commented Nov 24, 2025

Will correct the few little things reporter by copilot later this week.

@fredbi fredbi marked this pull request as draft November 24, 2025 23:52
@fredbi fredbi force-pushed the chore/improved-error-handling branch from 5aaebe1 to 542df34 Compare November 25, 2025 10:19
@fredbi fredbi requested a review from Copilot November 25, 2025 10:23
@fredbi fredbi marked this pull request as ready for review November 25, 2025 10:23
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Comment thread cmd/go-ctrf-json-reporter/main_test.go Outdated
Comment thread cmd/go-ctrf-json-reporter/main.go Outdated
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
@fredbi fredbi force-pushed the chore/improved-error-handling branch from 542df34 to 7ac356c Compare November 25, 2025 10:40
@Ma11hewThomas Ma11hewThomas merged commit e23d537 into ctrf-io:main Nov 29, 2025
5 checks passed
@Ma11hewThomas
Copy link
Copy Markdown
Contributor

Thanks!

@fredbi fredbi deleted the chore/improved-error-handling branch December 8, 2025 22:21
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.

4 participants