Skip to content
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

Improved configuration validation #278

Merged
merged 11 commits into from
Jan 20, 2025
Merged

Conversation

enzowritescode
Copy link
Contributor

@enzowritescode enzowritescode commented Jan 16, 2025

Description

  • Improve configuration validation based on aider feedback
  • Add additional validation
  • Added some tests for configuration validation
  • Typo fixes
  • Replaced hard-code strings with constants for the different service types

@enzowritescode enzowritescode requested review from crspeller and a team January 17, 2025 01:51
@enzowritescode enzowritescode marked this pull request as ready for review January 17, 2025 01:58
@enzowritescode enzowritescode requested review from a team and removed request for a team January 17, 2025 02:06
Copy link
Member

@crspeller crspeller left a comment

Choose a reason for hiding this comment

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

I like the improvements! Just a couple fixes.

"github.com/stretchr/testify/assert"
)

func TestBotConfig_IsValid(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

There isn't a success case. So a function that always fails will pass. (Which is the current case)

}

// Validate access levels are within bounds
if c.ChannelAccessLevel < ChannelAccessLevelAll || c.ChannelAccessLevel > ChannelAccessLevelNone {
Copy link
Member

Choose a reason for hiding this comment

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

This is backwards. UserAccessLevelAll = 0 and ChannelAccessLevelNone = 3

Copy link
Contributor Author

@enzowritescode enzowritescode Jan 17, 2025

Choose a reason for hiding this comment

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

I'm not sure I understand your comment.

ChannelAccessLevelAll = 0 and ChannelAccessLevelNone = 3. The code checks that the value passed to it is not less than 0 and not greater than 3. Is that not correct?

if c.ChannelAccessLevel < ChannelAccessLevelAll || c.ChannelAccessLevel > ChannelAccessLevelNone {
return false
}
if c.UserAccessLevel < UserAccessLevelAll || c.UserAccessLevel > UserAccessLevelNone {
Copy link
Member

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor Author

@enzowritescode enzowritescode Jan 17, 2025

Choose a reason for hiding this comment

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

UserAccessLevelAll = 0 and UserAccessLevelNone = 3. The code checks that the value passed to it is not less than 0 and not greater than 3. Is that not correct?

Copy link
Member

Choose a reason for hiding this comment

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

Yes I read those wrong. Don't do code reviews while jet-legged kids 🛫

@@ -49,10 +57,30 @@ type BotConfig struct {
}

func (c *BotConfig) IsValid() bool {
Copy link
Member

Choose a reason for hiding this comment

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

It might be nice to have this return an error with a specific failure. (I bet Aider could make this change pretty quick)

// Service-specific validation
switch c.Service.Type {
case ServiceTypeOpenAI:
return c.Service.APIKey != "" && c.Service.OrgID != ""
Copy link
Member

Choose a reason for hiding this comment

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

The OrgID is optional.

@crspeller crspeller merged commit 06c7e57 into master Jan 20, 2025
8 checks passed
@crspeller crspeller deleted the improve-config-validation branch January 20, 2025 15:15
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