[agent/codex:gpt-5.4-mini] Read ~/spec/code/core/go/i18n/RFC.md fully. Find features de... #151
2 changed files with 73 additions and 2 deletions
40
loader.go
40
loader.go
|
|
@ -351,13 +351,49 @@ func loadSignalPriors(grammar *GrammarData, priors map[string]any) {
|
|||
grammar.Signals.Priors[key] = make(map[string]float64, len(bucket))
|
||||
}
|
||||
for role, value := range bucket {
|
||||
if score := toFloat64(value); score != 0 {
|
||||
grammar.Signals.Priors[key][core.Lower(role)] = score
|
||||
score, ok := float64Value(value)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
grammar.Signals.Priors[key][core.Lower(role)] = score
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func float64Value(v any) (float64, bool) {
|
||||
if v == nil {
|
||||
return 0, false
|
||||
}
|
||||
switch n := v.(type) {
|
||||
case float64:
|
||||
return n, true
|
||||
case float32:
|
||||
return float64(n), true
|
||||
case int:
|
||||
return float64(n), true
|
||||
case int64:
|
||||
return float64(n), true
|
||||
case int32:
|
||||
return float64(n), true
|
||||
case int16:
|
||||
return float64(n), true
|
||||
case int8:
|
||||
return float64(n), true
|
||||
case uint:
|
||||
return float64(n), true
|
||||
case uint64:
|
||||
return float64(n), true
|
||||
case uint32:
|
||||
return float64(n), true
|
||||
case uint16:
|
||||
return float64(n), true
|
||||
case uint8:
|
||||
return float64(n), true
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
||||
func shouldSkipDeprecatedEnglishGrammarEntry(fullKey string) bool {
|
||||
switch fullKey {
|
||||
case "gram.noun.passed", "gram.noun.failed", "gram.noun.skipped",
|
||||
|
|
|
|||
|
|
@ -624,3 +624,38 @@ func TestCustomFSLoader(t *testing.T) {
|
|||
t.Errorf("signal priors not loaded correctly: %+v", gd.Signals.Priors["draft"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestCustomFSLoaderPreservesZeroSignalPriors(t *testing.T) {
|
||||
fs := fstest.MapFS{
|
||||
"locales/test.json": &fstest.MapFile{
|
||||
Data: []byte(`{
|
||||
"gram": {
|
||||
"signal": {
|
||||
"prior": {
|
||||
"commit": { "verb": 0, "noun": 1 }
|
||||
}
|
||||
}
|
||||
}
|
||||
}`),
|
||||
},
|
||||
}
|
||||
|
||||
loader := NewFSLoader(fs, "locales")
|
||||
_, grammar, err := loader.Load("test")
|
||||
if err != nil {
|
||||
t.Fatalf("Load(test) failed: %v", err)
|
||||
}
|
||||
if grammar == nil {
|
||||
t.Fatal("expected grammar data")
|
||||
}
|
||||
bucket, ok := grammar.Signals.Priors["commit"]
|
||||
if !ok {
|
||||
t.Fatal("signal priors for commit were not loaded")
|
||||
}
|
||||
if got := bucket["verb"]; got != 0 {
|
||||
t.Fatalf("signal priors verb = %v, want 0", got)
|
||||
}
|
||||
if got := bucket["noun"]; got != 1 {
|
||||
t.Fatalf("signal priors noun = %v, want 1", got)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue