Skip to content

Commit aa5264c

Browse files
committed
refactor: migrate to new ensemble model and improve test coverage
- Replaced usage of entity.SuggestModel with ensemble.Ensemble to streamline prediction logic - Renamed Ensemble.NextPredict to ProgressivePredict for clarity and consistency - Refactored and consolidated alias store logic into a single file with test coverage - Switched logging from custom log levels to slog for structured logging and cleaner API - Added unit tests for freq, prefix, ensemble, alias, llm, meta, and migration modules - Removed unused eval.go_ and legacy alias store files
1 parent f7a7607 commit aa5264c

File tree

19 files changed

+797
-372
lines changed

19 files changed

+797
-372
lines changed

cmd/benchmark/profile.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/trknhr/ghosttype/cmd/eval"
1616
"github.com/trknhr/ghosttype/internal/history"
1717
"github.com/trknhr/ghosttype/internal/model"
18+
"github.com/trknhr/ghosttype/internal/model/ensemble"
1819
"github.com/trknhr/ghosttype/internal/model/entity"
1920
"github.com/trknhr/ghosttype/internal/ollama"
2021
"github.com/trknhr/ghosttype/internal/store"
@@ -705,7 +706,7 @@ func runAllProfileTypes(db *sql.DB) error {
705706
// NOTE: For accurate measurement, this requires instrumenting the actual
706707
// DB and network clients, for example by wrapping sql.DB and http.Client.
707708
type InstrumentedEnsemble struct {
708-
model entity.SuggestModel
709+
model *ensemble.Ensemble
709710
dbTime time.Duration
710711
networkTime time.Duration
711712
mu sync.Mutex
@@ -716,7 +717,7 @@ type ModelTimings struct {
716717
NetworkTime time.Duration
717718
}
718719

719-
func createInstrumentedEnsemble(originalModel entity.SuggestModel) *InstrumentedEnsemble {
720+
func createInstrumentedEnsemble(originalModel *ensemble.Ensemble) *InstrumentedEnsemble {
720721
return &InstrumentedEnsemble{
721722
model: originalModel,
722723
}

cmd/eval/batch-eval.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/spf13/cobra"
1010
"github.com/trknhr/ghosttype/internal/history"
1111
"github.com/trknhr/ghosttype/internal/model"
12-
"github.com/trknhr/ghosttype/internal/model/entity"
12+
"github.com/trknhr/ghosttype/internal/model/ensemble"
1313
"github.com/trknhr/ghosttype/internal/ollama"
1414
"github.com/trknhr/ghosttype/internal/store"
1515
)
@@ -103,7 +103,7 @@ func RunBatchEvaluation(db *sql.DB, filePath string, modelNames []string) error
103103
return nil
104104
}
105105

106-
func runSingleModelEvaluation(model entity.SuggestModel, cases []EvaluationCase) (EvaluationResult, error) {
106+
func runSingleModelEvaluation(model *ensemble.Ensemble, cases []EvaluationCase) (EvaluationResult, error) {
107107
result := EvaluationResult{
108108
ByCategory: make(map[string]CategoryResult),
109109
}

cmd/eval/eval.go_

Lines changed: 0 additions & 277 deletions
This file was deleted.

internal/history/shell_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package history_test
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/trknhr/ghosttype/internal/history"
8+
)
9+
10+
func TestDetectShell(t *testing.T) {
11+
tests := []struct {
12+
name string
13+
shellEnv string
14+
want string
15+
}{
16+
{"Zsh", "/bin/zsh", "zsh"},
17+
{"Bash", "/usr/bin/bash", "bash"},
18+
{"Fish", "/usr/local/bin/fish", "fish"},
19+
{"PowerShell", "/usr/bin/pwsh", "powershell"},
20+
{"PowerShell full", "/usr/bin/powershell", "powershell"},
21+
{"Unknown", "/bin/foobar", "unknown"},
22+
{"Empty", "", "unknown"},
23+
}
24+
25+
original := os.Getenv("SHELL") // 元の値を保存
26+
defer os.Setenv("SHELL", original)
27+
28+
for _, tt := range tests {
29+
t.Run(tt.name, func(t *testing.T) {
30+
os.Setenv("SHELL", tt.shellEnv)
31+
if got := history.DetectShell(); got != tt.want {
32+
t.Errorf("DetectShell() = %v, want %v", got, tt.want)
33+
}
34+
})
35+
}
36+
}

0 commit comments

Comments
 (0)