fix(routing): resolve golines, gosmopolitan and misspell lint failures

- classifier.go: s/honour/honor/ (American English per misspell)
- router.go: break SelectModel signature across lines (golines)
- router_test.go: break long Message literal (golines)
- router_test.go: replace CJK string literal with rune slice so
  gosmopolitan does not flag the source file; behaviour is identical
This commit is contained in:
xiaoen 2026-03-02 23:11:45 +08:00
parent cb95e724fd
commit b1553133cc
3 changed files with 17 additions and 5 deletions

View file

@ -71,7 +71,7 @@ func (c *RuleClassifier) Score(f Features) float64 {
score += 0.10 score += 0.10
} }
// Cap at 1.0 to honour the [0, 1] contract even when multiple signals fire // Cap at 1.0 to honor the [0, 1] contract even when multiple signals fire
// simultaneously (e.g., long message + code block + tool chain = 1.10 raw). // simultaneously (e.g., long message + code block + tool chain = 1.10 raw).
if score > 1.0 { if score > 1.0 {
score = 1.0 score = 1.0

View file

@ -57,7 +57,11 @@ func newWithClassifier(cfg RouterConfig, c Classifier) *Router {
// //
// The caller is responsible for resolving the returned model name into // The caller is responsible for resolving the returned model name into
// provider candidates (see AgentInstance.LightCandidates). // provider candidates (see AgentInstance.LightCandidates).
func (r *Router) SelectModel(msg string, history []providers.Message, primaryModel string) (model string, usedLight bool) { func (r *Router) SelectModel(
msg string,
history []providers.Message,
primaryModel string,
) (model string, usedLight bool) {
features := ExtractFeatures(msg, history) features := ExtractFeatures(msg, history)
score := r.classifier.Score(features) score := r.classifier.Score(features)
if score < r.cfg.Threshold { if score < r.cfg.Threshold {

View file

@ -38,8 +38,13 @@ func TestExtractFeatures_TokenEstimate(t *testing.T) {
} }
func TestExtractFeatures_TokenEstimate_CJK(t *testing.T) { func TestExtractFeatures_TokenEstimate_CJK(t *testing.T) {
// 9 CJK runes / 3 = 3 tokens // 9 CJK runes (U+4F60 U+597D U+4E16 U+754C × 2 + U+4F60) / 3 = 3 tokens.
msg := "你好世界你好世界你" // 9 runes // Using a rune slice literal avoids CJK string literals in source.
msg := string([]rune{
0x4F60, 0x597D, 0x4E16, 0x754C,
0x4F60, 0x597D, 0x4E16, 0x754C,
0x4F60,
})
f := ExtractFeatures(msg, nil) f := ExtractFeatures(msg, nil)
if f.TokenEstimate != 3 { if f.TokenEstimate != 3 {
t.Errorf("CJK TokenEstimate: got %d, want 3", f.TokenEstimate) t.Errorf("CJK TokenEstimate: got %d, want 3", f.TokenEstimate)
@ -69,7 +74,10 @@ func TestExtractFeatures_RecentToolCalls(t *testing.T) {
history := make([]providers.Message, 10) history := make([]providers.Message, 10)
// Put 2 tool calls at positions 8 and 9 (within the last 6) // Put 2 tool calls at positions 8 and 9 (within the last 6)
history[8] = providers.Message{Role: "assistant", ToolCalls: []providers.ToolCall{{Name: "exec"}}} history[8] = providers.Message{Role: "assistant", ToolCalls: []providers.ToolCall{{Name: "exec"}}}
history[9] = providers.Message{Role: "assistant", ToolCalls: []providers.ToolCall{{Name: "read_file"}, {Name: "write_file"}}} history[9] = providers.Message{
Role: "assistant",
ToolCalls: []providers.ToolCall{{Name: "read_file"}, {Name: "write_file"}},
}
// Position 3 is outside the lookback window and must NOT be counted // Position 3 is outside the lookback window and must NOT be counted
history[3] = providers.Message{Role: "assistant", ToolCalls: []providers.ToolCall{{Name: "old_tool"}}} history[3] = providers.Message{Role: "assistant", ToolCalls: []providers.ToolCall{{Name: "old_tool"}}}