Files
magpie/internal/cli/groups_intentsure_cli_test.go
T
yetoneandggbdpq 7e5a54147f gateway: a routing group's intent sureness is its own, intent-sure= (#5101)
Jev's sure of an intent had to reach jevSure, a fixed 0.4, for every
group. zminds measured 39 of 237 turns in one day (16.5%) refused at sure
0.153 to 0.395, and those turns went by the group's routing as if it had
no intent rules. A group can now set its own threshold: intentSure, from
0 (take Jev's likeliest intent however unsure) to 1. Missing keeps 0.4.

readJev keeps Jev's likeliest intent, its sure and Topic (an answer of
intents rather than levels). ruleFor applies the group's own sure through
intentOf, so two groups sharing one classifier and its cached answer each
judge it at their own. "none of these" is never an intent, at 0 too.
Levels and effort are as before.

Set from a terminal: magpie group set <group> intent-sure=0.25, empty to
unset. SaveGroup and the CLI refuse a value outside 0 to 1, NaN too: the
patch's `v < 0 || v > 1` let intent-sure=NaN through the CLI, which
SaveGroup then failed on as "json: unsupported value". cloneGroups copies
the new pointer, since TestCloneGroupsSharesNothing went red on it.

Changed from ggbdpq's patch on #5101:
- The group editor's "Intent sure" row is left out. Its hints were long
  secondary text, it showed for every classifier when only Jev answers
  with a sure, and it had no GUI test. The Routing page instead carries
  intentSure through each save it makes of a group (the editor's Save,
  the routing menu, the manual pick), so a value set from the CLI isn't
  wiped by the next GUI save.
- Its i18n strings and site/public/docs/intent.html are left out. A
  site/ change waits for the maintainer (docs/contributors.md). The site
  diff was documentation text only: a paragraph id="sure", a sentence
  in "Match the rules" and one table row. It had no links or scripts.
- docs/subsystems/gateway-routing.md has a bullet for IntentSure.

Run on mote (mote-run):
- gofmt -l internal/: clean.
- go vet -tags nogui, also with GOOS=linux and GOOS=windows, on
  internal/gateway, internal/cli and internal/provider: clean.
- go test -tags nogui -run 'TestGroupIntentSure|TestJev|Rule|Classif|Decide'
  ./internal/gateway: ok.
- -run 'Group|Apply' ./internal/cli: ok.
- -run 'Group|Save|Clone' ./internal/provider: ok.
- go test -run Budget ./internal/gui: ok.
- node --test group-intent-sure (new), routing-group-strategy and
  group-first-token, in Chromium and WebKit: 42 pass, 0 fail.
- i18n-keys has one red, "a plugin's words are its own". It fails the
  same on origin/main b712adb84 and is filed as #5327, #5332 and #5426.
  i18n-en-no-cjk: ok.

Broken by hand, each red, then restored:
- sureNeeded always returns 0.4: TestGroupIntentSureThreshold,
  ZeroTakesTheArgmax and IsPerGroup FAIL.
- The patch's `< 0 || > 1` checks put back: TestGroupIntentSurePairs
  FAILs on "NaN" and "nan"; TestGroupIntentSureRange FAILs on NaN.
- The cloneGroups copy removed: TestCloneGroupsSharesNothing FAILs.
- The editor's Save sending intentSure null: group-intent-sure FAILs 4/4
  ("the editor's Save keeps it").
- The routing menu's pick sending null: it FAILs 4/4 ("a routing pick
  keeps it").

Not tried: a real Jev account with a group at 0.25; the full suite.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-06 10:44:24 +08:00

37 lines
1.3 KiB
Go

package cli
import (
"strings"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// intent-sure= sets how sure the classifier must be of a group's intent
// (#5101): from 0 to 1, empty back to the 0.4 every group asked before, and
// anything else, NaN among it, refused with the group unchanged.
func TestGroupIntentSurePairs(t *testing.T) {
none := func(string) (string, error) { return "", nil }
g := provider.Group{}
for _, c := range []struct {
v string
want float64
}{{"0.25", 0.25}, {"0", 0}, {"1", 1}, {" 0.6 ", 0.6}} {
if err := applyGroupPairs(&g, []string{"intent-sure=" + c.v}, none, false); err != nil || g.IntentSure == nil || *g.IntentSure != c.want {
t.Fatalf("intent-sure=%q: %v %v, want %g", c.v, err, g.IntentSure, c.want)
}
}
for _, v := range []string{"-0.1", "1.5", "NaN", "nan", "high"} {
err := applyGroupPairs(&g, []string{"intent-sure=" + v}, none, false)
if err == nil || !strings.Contains(err.Error(), "from 0 to 1") {
t.Errorf("intent-sure=%q: %v, want refused", v, err)
}
if g.IntentSure == nil || *g.IntentSure != 0.6 {
t.Errorf("intent-sure=%q changed the group: %v", v, g.IntentSure)
}
}
if err := applyGroupPairs(&g, []string{"intentsure="}, none, false); err != nil || g.IntentSure != nil {
t.Fatalf("empty: %v %v, want nil", err, g.IntentSure)
}
}