Skip to content

Conversation

@yegor256
Copy link
Member

closes #138

Copilot AI review requested due to automatic review settings December 16, 2025 06:40
@yegor256
Copy link
Member Author

@volodya-lombrozo FYI

Copy link
Contributor

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 adds comprehensive test coverage across multiple packages in the refrax codebase to address issue #138. The tests cover server initialization, lifecycle management, agent behavior, and protocol data structures.

Key Changes

  • Added test files for the reviewer, fixer, and facilitator packages covering server and agent functionality
  • Added test files for the protocol package covering message parts and model structures
  • Implemented mock structures and helper functions to facilitate isolated unit testing

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
internal/reviewer/server_test.go Tests for reviewer server lifecycle, message handling, and agent card creation
internal/reviewer/agent_test.go Tests for suggestion parsing and review functionality
internal/protocol/part_test.go Tests for message part creation, metadata handling, and JSON marshaling
internal/protocol/model_test.go Tests for agent card builder pattern and data structures
internal/fixer/server_test.go Tests for fixer server lifecycle, code cleaning, and message handling
internal/facilitator/server_test.go Tests for facilitator server lifecycle and refactoring coordination
internal/facilitator/agent_test.go Tests for refactoring logic, class matching, and critique handling

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

Comment on lines +12 to +13
func secureRandomInt(limit int) int {
n, _ := rand.Int(rand.Reader, big.NewInt(int64(limit)))
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The error returned by rand.Int is being silently ignored. This could lead to undefined behavior if random number generation fails. Consider handling the error appropriately or documenting why it's safe to ignore.

Suggested change
func secureRandomInt(limit int) int {
n, _ := rand.Int(rand.Reader, big.NewInt(int64(limit)))
func secureRandomInt(t *testing.T, limit int) int {
n, err := rand.Int(rand.Reader, big.NewInt(int64(limit)))
if err != nil {
t.Fatalf("failed to generate secure random int: %v", err)
}

Copilot uses AI. Check for mistakes.
)

func randomPort() int {
n, _ := rand.Int(rand.Reader, big.NewInt(10000))
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The error returned by rand.Int is being silently ignored. This could lead to undefined behavior if random number generation fails. Consider handling the error appropriately or documenting why it's safe to ignore.

Suggested change
n, _ := rand.Int(rand.Reader, big.NewInt(10000))
n, err := rand.Int(rand.Reader, big.NewInt(10000))
if err != nil {
panic("failed to generate random port: " + err.Error())
}

Copilot uses AI. Check for mistakes.
Comment on lines +34 to +37
reeady := make(chan bool, 1)
reeady <- true
close(reeady)
m.ready = reeady
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

Misspelled variable name 'reeady' should be 'ready'.

Suggested change
reeady := make(chan bool, 1)
reeady <- true
close(reeady)
m.ready = reeady
ready := make(chan bool, 1)
ready <- true
close(ready)
m.ready = ready

Copilot uses AI. Check for mistakes.
Comment on lines +34 to +37
reeady := make(chan bool, 1)
reeady <- true
close(reeady)
m.ready = reeady
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

Misspelled variable name 'reeady' should be 'ready'.

Suggested change
reeady := make(chan bool, 1)
reeady <- true
close(reeady)
m.ready = reeady
ready := make(chan bool, 1)
ready <- true
close(ready)
m.ready = ready

Copilot uses AI. Check for mistakes.
Comment on lines +34 to +37
reeady := make(chan bool, 1)
reeady <- true
close(reeady)
m.ready = reeady
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

Misspelled variable name 'reeady' should be 'ready'.

Suggested change
reeady := make(chan bool, 1)
reeady <- true
close(reeady)
m.ready = reeady
ready := make(chan bool, 1)
ready <- true
close(ready)
m.ready = ready

Copilot uses AI. Check for mistakes.
Comment on lines +18 to +19
func randomPort() int {
n, _ := rand.Int(rand.Reader, big.NewInt(10000))
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The error returned by rand.Int is being silently ignored. This could lead to undefined behavior if random number generation fails. Consider handling the error appropriately or documenting why it's safe to ignore.

Suggested change
func randomPort() int {
n, _ := rand.Int(rand.Reader, big.NewInt(10000))
func randomPort(t *testing.T) int {
n, err := rand.Int(rand.Reader, big.NewInt(10000))
require.NoError(t, err)

Copilot uses AI. Check for mistakes.
Comment on lines +18 to +62
func randomPort() int {
n, _ := rand.Int(rand.Reader, big.NewInt(10000))
return int(n.Int64()) + 20000
}

type mock struct {
started bool
closed bool
handler protocol.MsgHandler
ready chan bool
}

func (m *mock) ListenAndServe() error {
if m.started {
return errors.New("server already started")
}
reeady := make(chan bool, 1)
reeady <- true
close(reeady)
m.ready = reeady
m.started = true
return nil
}

func (m *mock) Shutdown() error {
if !m.started {
return errors.New("server not started")
}
if m.closed {
return errors.New("server already closed")
}
m.closed = true
return nil
}

func (m *mock) Handler(_ protocol.Handler) {
}

func (m *mock) MsgHandler(handler protocol.MsgHandler) {
m.handler = handler
}

func (m *mock) Ready() <-chan bool {
return m.ready
}
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The randomPort function and mock struct are duplicated across internal/reviewer/server_test.go, internal/fixer/server_test.go, and internal/facilitator/server_test.go. Consider extracting these test utilities into a shared testing package to improve maintainability and reduce code duplication.

Copilot uses AI. Check for mistakes.
card := NewAgentCard().
WithName("Cömplëtë Ägënt").
WithDescription("Ä cömplëtë ägënt cärd").
WithURL("http://löcälhöst:" + string(rune(port))).
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

Incorrect type conversion: attempting to convert an int to a rune and then to a string will produce a single character (the rune representation of the number), not the string representation of the port number. Use strconv.Itoa(port) instead.

Copilot uses AI. Check for mistakes.
)

func randomPort() int {
n, _ := rand.Int(rand.Reader, big.NewInt(10000))
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The error returned by rand.Int is being silently ignored. This could lead to undefined behavior if random number generation fails. Consider handling the error appropriately or documenting why it's safe to ignore.

Suggested change
n, _ := rand.Int(rand.Reader, big.NewInt(10000))
n, err := rand.Int(rand.Reader, big.NewInt(10000))
if err != nil {
panic("failed to generate random port: " + err.Error())
}

Copilot uses AI. Check for mistakes.
)

func randomInt(limit int) int {
n, _ := rand.Int(rand.Reader, big.NewInt(int64(limit)))
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The error returned by rand.Int is being silently ignored. This could lead to undefined behavior if random number generation fails. Consider handling the error appropriately or documenting why it's safe to ignore.

Suggested change
n, _ := rand.Int(rand.Reader, big.NewInt(int64(limit)))
n, err := rand.Int(rand.Reader, big.NewInt(int64(limit)))
if err != nil {
panic("failed to generate random int: " + err.Error())
}

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@volodya-lombrozo volodya-lombrozo left a comment

Choose a reason for hiding this comment

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

@yegor256 This PR is too big. I will add the check for such a big PRs:

#145 (similar to EO check).

Could you split this PR on several small ones, please?

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.

code coverate is too low

3 participants