-
Notifications
You must be signed in to change notification settings - Fork 3
more tests #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
more tests #144
Conversation
There was a problem hiding this 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.
| func secureRandomInt(limit int) int { | ||
| n, _ := rand.Int(rand.Reader, big.NewInt(int64(limit))) |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
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.
| 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) | |
| } |
| ) | ||
|
|
||
| func randomPort() int { | ||
| n, _ := rand.Int(rand.Reader, big.NewInt(10000)) |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
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.
| 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()) | |
| } |
| reeady := make(chan bool, 1) | ||
| reeady <- true | ||
| close(reeady) | ||
| m.ready = reeady |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
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'.
| reeady := make(chan bool, 1) | |
| reeady <- true | |
| close(reeady) | |
| m.ready = reeady | |
| ready := make(chan bool, 1) | |
| ready <- true | |
| close(ready) | |
| m.ready = ready |
| reeady := make(chan bool, 1) | ||
| reeady <- true | ||
| close(reeady) | ||
| m.ready = reeady |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
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'.
| reeady := make(chan bool, 1) | |
| reeady <- true | |
| close(reeady) | |
| m.ready = reeady | |
| ready := make(chan bool, 1) | |
| ready <- true | |
| close(ready) | |
| m.ready = ready |
| reeady := make(chan bool, 1) | ||
| reeady <- true | ||
| close(reeady) | ||
| m.ready = reeady |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
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'.
| reeady := make(chan bool, 1) | |
| reeady <- true | |
| close(reeady) | |
| m.ready = reeady | |
| ready := make(chan bool, 1) | |
| ready <- true | |
| close(ready) | |
| m.ready = ready |
| func randomPort() int { | ||
| n, _ := rand.Int(rand.Reader, big.NewInt(10000)) |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
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.
| 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) |
| 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 | ||
| } |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
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.
| 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))). |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
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.
| ) | ||
|
|
||
| func randomPort() int { | ||
| n, _ := rand.Int(rand.Reader, big.NewInt(10000)) |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
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.
| 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()) | |
| } |
| ) | ||
|
|
||
| func randomInt(limit int) int { | ||
| n, _ := rand.Int(rand.Reader, big.NewInt(int64(limit))) |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
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.
| 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()) | |
| } |
volodya-lombrozo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
closes #138