feat: simplify SOP to immediate-effect configuration
This commit is contained in:
@@ -11,25 +11,33 @@ import (
|
||||
|
||||
func TestPetDoctorSOPPassesPublishValidation(t *testing.T) {
|
||||
fields := petFieldModels()
|
||||
knowledgeIDs := map[string]uint64{
|
||||
"线上问诊边界": 1,
|
||||
"急症红旗征象": 2,
|
||||
"问诊用药安全原则": 3,
|
||||
"观察与复诊提示": 4,
|
||||
}
|
||||
nodes := petNodeModels(petNodes(knowledgeIDs))
|
||||
nodes := petNodeModels(petNodes())
|
||||
edges := petEdgeModels(petEdges())
|
||||
if len(fields) != 47 || len(nodes) != 21 || len(edges) != 21 {
|
||||
if len(fields) != 13 || len(nodes) != 5 || len(edges) != 4 {
|
||||
t.Fatalf("unexpected definition size: fields=%d nodes=%d edges=%d", len(fields), len(nodes), len(edges))
|
||||
}
|
||||
|
||||
problems := sop.ValidateForPublish("start", nodes, edges, sop.ValidationContext{
|
||||
Fields: fields,
|
||||
PublishedKnowledgeCardIDs: map[uint64]bool{
|
||||
1: true,
|
||||
2: true,
|
||||
3: true,
|
||||
4: true,
|
||||
KnowledgeItems: []model.KnowledgeItem{
|
||||
{Base: model.Base{ID: 1}, ItemKey: "consultation_boundary", Type: "guidance", Status: "active"},
|
||||
{Base: model.Base{ID: 2}, ItemKey: "emergency_guidance", Type: "guidance", Status: "active"},
|
||||
{Base: model.Base{ID: 3}, ItemKey: "medication_safety", Type: "guidance", Status: "active"},
|
||||
{Base: model.Base{ID: 4}, ItemKey: "safety_net", Type: "guidance", Status: "active"},
|
||||
{Base: model.Base{ID: 5}, ItemKey: "soft_stool", Type: "symptom", Status: "active"},
|
||||
{Base: model.Base{ID: 6}, ItemKey: "poor_appetite", Type: "symptom", Status: "active"},
|
||||
{Base: model.Base{ID: 7}, ItemKey: "ask_stool", Type: "copy", Status: "active"},
|
||||
{Base: model.Base{ID: 8}, ItemKey: "gi_discomfort", Type: "disease", Status: "active"},
|
||||
{Base: model.Base{ID: 9}, ItemKey: "gut_plan", Type: "plan", Status: "active"},
|
||||
{Base: model.Base{ID: 10}, ItemKey: "gut_product", Type: "product", Status: "active"},
|
||||
},
|
||||
KnowledgeRelations: []model.KnowledgeRelation{
|
||||
{FromKnowledgeID: 5, ToKnowledgeID: 7, RelationType: "recommended_copy"},
|
||||
{FromKnowledgeID: 5, ToKnowledgeID: 8, RelationType: "possible_disease"},
|
||||
{FromKnowledgeID: 5, ToKnowledgeID: 9, RelationType: "recommended_plan"},
|
||||
{FromKnowledgeID: 8, ToKnowledgeID: 7, RelationType: "recommended_copy"},
|
||||
{FromKnowledgeID: 8, ToKnowledgeID: 9, RelationType: "recommended_plan"},
|
||||
{FromKnowledgeID: 8, ToKnowledgeID: 10, RelationType: "recommended_product"},
|
||||
},
|
||||
})
|
||||
if len(problems) > 0 {
|
||||
@@ -37,31 +45,27 @@ func TestPetDoctorSOPPassesPublishValidation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPetDoctorSOPHasBothRiskEscalations(t *testing.T) {
|
||||
nodes := petNodes(map[string]uint64{
|
||||
"线上问诊边界": 1,
|
||||
"急症红旗征象": 2,
|
||||
"问诊用药安全原则": 3,
|
||||
"观察与复诊提示": 4,
|
||||
})
|
||||
escalations := map[string]bool{}
|
||||
for _, node := range nodes {
|
||||
if node.Type == "escalate" {
|
||||
escalations[node.Key] = true
|
||||
func TestPetDoctorSOPIsFiveStepLinearFlow(t *testing.T) {
|
||||
wantNodes := []string{"start", "pet_info", "symptom", "recommend_product", "finish"}
|
||||
for index, node := range petNodes() {
|
||||
if node.Key != wantNodes[index] {
|
||||
t.Fatalf("node %d = %s, want %s", index, node.Key, wantNodes[index])
|
||||
}
|
||||
}
|
||||
for _, key := range []string{"emergency_escalate", "medication_escalate"} {
|
||||
if !escalations[key] {
|
||||
t.Fatalf("missing risk escalation node %s", key)
|
||||
wantEdges := [][2]string{{"start", "pet_info"}, {"pet_info", "symptom"}, {"symptom", "recommend_product"}, {"recommend_product", "finish"}}
|
||||
for index, edge := range petEdges() {
|
||||
if edge.Source != wantEdges[index][0] || edge.Target != wantEdges[index][1] {
|
||||
t.Fatalf("edge %d = %s -> %s", index, edge.Source, edge.Target)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSameJSONIgnoresObjectOrderAndWhitespace(t *testing.T) {
|
||||
left := []byte(`{"standard_copy":"安全提示","risk_note":"立即就医"}`)
|
||||
right := []byte(`{ "risk_note": "立即就医", "standard_copy": "安全提示" }`)
|
||||
if !sameJSON(left, right) {
|
||||
t.Fatal("equivalent JSON objects should match")
|
||||
func TestPetKnowledgeKeyIsStableAndTypeScoped(t *testing.T) {
|
||||
if petKnowledgeKey("symptom", "腹泻") != petKnowledgeKey("symptom", " 腹泻 ") {
|
||||
t.Fatal("key should ignore surrounding whitespace")
|
||||
}
|
||||
if petKnowledgeKey("symptom", "腹泻") == petKnowledgeKey("disease", "腹泻") {
|
||||
t.Fatal("key should include knowledge type")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +78,7 @@ func petFieldModels() []model.ScenarioField {
|
||||
fields = append(fields, model.ScenarioField{
|
||||
FieldKey: definition.Key,
|
||||
FieldName: definition.Name,
|
||||
SourcePath: definition.SourcePath,
|
||||
FieldType: definition.Type,
|
||||
Required: definition.Required,
|
||||
Options: datatypes.JSON(options),
|
||||
|
||||
Reference in New Issue
Block a user