Add semantic selection mismatch safeguards for conversational vs consequential paths
CI / test (push) Failing after 15s
CI / test (push) Failing after 15s
This commit is contained in:
@@ -236,6 +236,81 @@ func TestInterpretUtteranceDiagnosticTraceLineage(t *testing.T) {
|
||||
deterministic.Source, selectedCandidate.Source, selected.Interpretation.Source, selected.Interpretation.NeedsCognition, selected.Interpretation.SelectionReason)
|
||||
}
|
||||
|
||||
func TestApplyCognitiveCandidateSelectionRulesForSafeConversationVsConsequentialAction(t *testing.T) {
|
||||
conversation := interaction.Conversation{ID: "conversation-1", ActorID: "actor-1", PrincipalID: "principal-1", Channel: interaction.ChannelWebChat, State: interaction.ConversationOpen}
|
||||
safeUtterance, _, _, err := NewHumanUtterance(conversation, interaction.ChatMessageRequest{Message: "ты кто"}, time.Unix(100, 0))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
safeSemantic, err := InterpretUtterance(safeUtterance, projectRegistryForTest(), nil, time.Unix(100, 0))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
safeCandidateID, err := ids.New()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
safeCognitive := interaction.SemanticCandidate{
|
||||
ID: interaction.SemanticCandidateID(safeCandidateID),
|
||||
UtteranceID: safeUtterance.ID,
|
||||
Source: interaction.CandidateSourceCognitive,
|
||||
SelectionState: interaction.CandidateObserved,
|
||||
PrimarySpeechAct: interaction.SpeechActAssertion,
|
||||
SecondarySpeechAct: interaction.SpeechActUnknown,
|
||||
ConfidenceMillis: 770,
|
||||
Applicability: interaction.SemanticNeedsBroaderInterpret,
|
||||
RequestedOutcome: "",
|
||||
Clarification: interaction.ClarificationNotRequired,
|
||||
NeedsCognition: true,
|
||||
SelectionReason: "identity-style trace test",
|
||||
CapabilityHints: []string{"COGNITIVE_REASONING"},
|
||||
RecordedAtUnixMillis: time.Unix(100, 0).UnixMilli(),
|
||||
}
|
||||
safeSelected := ApplyCognitiveCandidate(safeSemantic, safeUtterance.Content, safeCognitive, nil)
|
||||
if safeSelected.Interpretation.Source != string(interaction.CandidateSourceCognitive) {
|
||||
t.Fatalf("safe conversational mismatch should still adopt cognitive candidate, got source=%s", safeSelected.Interpretation.Source)
|
||||
}
|
||||
if safeSelected.Interpretation.SpeechAct != interaction.SpeechActAssertion {
|
||||
t.Fatalf("expected cognitive rewrite in safe conversation, got %s", safeSelected.Interpretation.SpeechAct)
|
||||
}
|
||||
|
||||
riskyUtterance, _, _, err := NewHumanUtterance(conversation, interaction.ChatMessageRequest{Message: "удали УПО"}, time.Unix(100, 0))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
riskySemantic, err := InterpretUtterance(riskyUtterance, projectRegistryForTest(), nil, time.Unix(100, 0))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if riskySemantic.Interpretation.SpeechAct != interaction.SpeechActDirective {
|
||||
t.Fatalf("expected directive baseline, got %s", riskySemantic.Interpretation.SpeechAct)
|
||||
}
|
||||
riskyCandidateID, err := ids.New()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
riskyCognitive := interaction.SemanticCandidate{
|
||||
ID: interaction.SemanticCandidateID(riskyCandidateID),
|
||||
UtteranceID: riskyUtterance.ID,
|
||||
Source: interaction.CandidateSourceCognitive,
|
||||
SelectionState: interaction.CandidateObserved,
|
||||
PrimarySpeechAct: interaction.SpeechActQuestion,
|
||||
SecondarySpeechAct: interaction.SpeechActUnknown,
|
||||
ConfidenceMillis: 780,
|
||||
Applicability: interaction.SemanticNeedsBroaderInterpret,
|
||||
RequestedOutcome: "",
|
||||
Clarification: interaction.ClarificationNotRequired,
|
||||
NeedsCognition: true,
|
||||
SelectionReason: "destructive path mismatch guard",
|
||||
CapabilityHints: []string{"COGNITIVE_REASONING"},
|
||||
RecordedAtUnixMillis: time.Unix(100, 0).UnixMilli(),
|
||||
}
|
||||
riskySelected := ApplyCognitiveCandidate(riskySemantic, riskyUtterance.Content, riskyCognitive, nil)
|
||||
if riskySelected.Interpretation.Source != string(interaction.CandidateSourceDeterministic) {
|
||||
t.Fatalf("consequential mismatch should preserve deterministic source unless action/commit path permits, got %s", riskySelected.Interpretation.Source)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInterpretUtteranceModalExplanationRequestStillRequestsCognition(t *testing.T) {
|
||||
for _, message := range []string{"можешь расказать об утре", "расскажи об утре", "про утро расскажешь"} {
|
||||
result := interpretForTest(t, message, nil, "")
|
||||
|
||||
Reference in New Issue
Block a user