package reflector_test import ( "context" "encoding/json" "fmt" "git.flytoex.net/yuanwei/flyto-agent/pkg/evolve" "git.flytoex.net/yuanwei/flyto-agent/pkg/reflector" "git.flytoex.net/yuanwei/flyto-agent/pkg/validator" ) // Example_evaluatorAsValidator wraps an evolve.Evaluator as a // validator.Validator so a GA-style scorer can plug into the // commit-gate pipeline without rewriting the scorer against the // Validator interface. // // Example_evaluatorAsValidator 把 evolve.Evaluator 包为 // validator.Validator, 让 GA 式打分器直接接入 commit-gate 流水线, 无需 // 针对 Validator 接口重写打分器. func Example_evaluatorAsValidator() { scorer, _ := evolve.NewFuncEvaluator(func(_ context.Context, c evolve.Candidate) (float64, map[string]float64, error) { payload, _ := c.Payload.(map[string]any) if payload["risky"] == true { return 0.2, map[string]float64{"risk": 0.8}, nil } return 0.9, map[string]float64{"risk": 0.1}, nil }) extract := func(d validator.DiffInput) (evolve.Candidate, error) { var payload map[string]any if err := json.Unmarshal(d.Raw, &payload); err != nil { return evolve.Candidate{}, err } return evolve.Candidate{ID: d.SourceTool, Payload: payload}, nil } v := reflector.EvaluatorAsValidator(scorer, extract, 0.5, reflector.WithName("ga-gate"), reflector.WithPolicyVersion("2026-04"), ) vd, _ := v.Validate(context.Background(), validator.DiffInput{ SourceTool: "SQLCAS", Raw: []byte(`{"risky": true}`), }) fmt.Println(v.Name(), vd.Approved, vd.Severity) // Output: ga-gate false block }