Align illegal-tier fallback with PlanTier's conservative policy so unrecognized values never silently enable V2 query routing. Co-authored-by: Cursor <cursoragent@cursor.com>
52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package intent
|
|
|
|
import "testing"
|
|
|
|
func TestTierAllowsRisk(t *testing.T) {
|
|
tests := []struct {
|
|
tier V2DecisionTier
|
|
risk RiskLevel
|
|
want bool
|
|
}{
|
|
{V2TierNone, RiskLow, false},
|
|
{V2TierQuery, RiskLow, true},
|
|
{V2TierQuery, RiskMedium, false},
|
|
{V2TierGenerate, RiskMedium, true},
|
|
{V2TierGenerate, RiskHigh, false},
|
|
{V2TierWriteLow, RiskHigh, false},
|
|
{V2TierWriteHigh, RiskHigh, true},
|
|
}
|
|
for _, tc := range tests {
|
|
if got := tierAllowsRisk(tc.tier, tc.risk); got != tc.want {
|
|
t.Errorf("tierAllowsRisk(%s, %s) = %v, want %v", tc.tier, tc.risk, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestUnknownV2DecisionTierFailsClosedToNone(t *testing.T) {
|
|
if parseV2DecisionTier("definitely-not-a-tier") != V2TierNone {
|
|
t.Fatal("unknown INTENT_V2_DECISION_TIER must fail closed to none, not query")
|
|
}
|
|
}
|
|
|
|
func TestBuildV2ShadowReport_MismatchDetection(t *testing.T) {
|
|
SetFeatureFlagsForTest(FeatureFlags{IntentV2Shadow: true})
|
|
defer ResetFeatureFlagsForTest()
|
|
|
|
res := &IntentRecognitionResult{
|
|
TopIntent: &CandidateIntent{Intent: IntentQueryProgress, Confidence: 0.9},
|
|
IntentFrameV2: &IntentFrameV2{
|
|
LegacyIntent: IntentQueryRegulations,
|
|
ActionKey: "regulation.query",
|
|
Goal: GoalQuery,
|
|
},
|
|
}
|
|
ApplyV2ShadowObservability(res)
|
|
if res.V2Shadow == nil {
|
|
t.Fatal("expected v2_shadow report")
|
|
}
|
|
if !res.V2Shadow.Mismatch {
|
|
t.Error("expected mismatch=true")
|
|
}
|
|
}
|