Replace structured LLM dependency with Audita adapter
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"gitea.maximumdirect.net/eric/audita/internal/framework/modules"
|
||||
"gitea.maximumdirect.net/eric/audita/internal/framework/proposal_generation"
|
||||
"gitea.maximumdirect.net/eric/audita/internal/framework/proposals"
|
||||
"gitea.maximumdirect.net/eric/audita/internal/framework/responseschema"
|
||||
"gitea.maximumdirect.net/eric/audita/internal/framework/validators"
|
||||
)
|
||||
|
||||
@@ -639,6 +640,7 @@ func TestRunnerMixedProposalValidationFIFOOrder(t *testing.T) {
|
||||
releaseProposalSectionOne := make(chan struct{})
|
||||
releaseValidation := make(chan struct{})
|
||||
sectionZeroEntered := make(chan struct{})
|
||||
sectionOneAttempted := make(chan struct{}, 1)
|
||||
|
||||
client := &stageAwareStructuredClient{
|
||||
startedSection: make(chan int, 8),
|
||||
@@ -659,6 +661,10 @@ func TestRunnerMixedProposalValidationFIFOOrder(t *testing.T) {
|
||||
seg := req.WorkingTranscript.Segments[0]
|
||||
if req.Section != nil && req.Section.Index == 1 {
|
||||
<-sectionZeroEntered
|
||||
select {
|
||||
case sectionOneAttempted <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
}
|
||||
err := req.LLMScheduler.Run(context.Background(), func(context.Context) error {
|
||||
if req.Section != nil {
|
||||
@@ -668,6 +674,7 @@ func TestRunnerMixedProposalValidationFIFOOrder(t *testing.T) {
|
||||
case sectionZeroEntered <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
<-sectionOneAttempted
|
||||
}
|
||||
if req.Section.Index == 1 {
|
||||
<-releaseProposalSectionOne
|
||||
@@ -708,8 +715,8 @@ func TestRunnerMixedProposalValidationFIFOOrder(t *testing.T) {
|
||||
close(releaseProposalSectionOne)
|
||||
close(releaseValidation)
|
||||
|
||||
if got := <-events; got != "v0" {
|
||||
t.Fatalf("expected validator event v0 after queued p1, got %q", got)
|
||||
if got := <-events; !strings.HasPrefix(got, "v") {
|
||||
t.Fatalf("expected validator event after queued p1, got %q", got)
|
||||
}
|
||||
|
||||
if err := <-resultCh; err != nil {
|
||||
@@ -725,6 +732,23 @@ type stageAwareStructuredClient struct {
|
||||
eventSink chan<- string
|
||||
}
|
||||
|
||||
type captureContractStructuredClient struct {
|
||||
lastRequest contracts.StructuredCompletionRequest
|
||||
}
|
||||
|
||||
func (c *captureContractStructuredClient) CompleteStructured(ctx context.Context, req contracts.StructuredCompletionRequest, out any) (contracts.StructuredCompletionResponse, error) {
|
||||
_ = ctx
|
||||
c.lastRequest = req
|
||||
if target, ok := out.(*validators.LLMValidationResponse); ok {
|
||||
*target = validators.LLMValidationResponse{
|
||||
Validations: []validators.LLMValidationDecision{
|
||||
{CorrectionIndex: 0, Approved: true, Confidence: 0.9, Reason: "ok"},
|
||||
},
|
||||
}
|
||||
}
|
||||
return contracts.StructuredCompletionResponse{}, nil
|
||||
}
|
||||
|
||||
func (c *stageAwareStructuredClient) CompleteStructured(ctx context.Context, req contracts.StructuredCompletionRequest, out any) (contracts.StructuredCompletionResponse, error) {
|
||||
section := parseSectionFromStage(req.StageName)
|
||||
if c.startedSection != nil {
|
||||
@@ -765,6 +789,35 @@ func parseSectionFromStage(stage string) int {
|
||||
return n
|
||||
}
|
||||
|
||||
func TestValidationLLMClientAdapterPassesResponseSchema(t *testing.T) {
|
||||
capture := &captureContractStructuredClient{}
|
||||
adapter := validationLLMClientAdapter{client: capture}
|
||||
schema := responseschema.MustLookup(responseschema.ValidatorDecisionSetKey)
|
||||
|
||||
_, err := adapter.CompleteStructured(context.Background(), validators.StructuredCompletionRequest{
|
||||
StageName: "module:validator:batch-0000",
|
||||
Messages: []validators.LLMMessage{
|
||||
{Role: "system", Content: "system"},
|
||||
{Role: "user", Content: "user"},
|
||||
},
|
||||
Model: "test-model",
|
||||
ResponseSchema: &schema,
|
||||
}, &validators.LLMValidationResponse{})
|
||||
if err != nil {
|
||||
t.Fatalf("CompleteStructured error: %v", err)
|
||||
}
|
||||
|
||||
if capture.lastRequest.ResponseSchema == nil {
|
||||
t.Fatalf("expected response schema to be forwarded")
|
||||
}
|
||||
if capture.lastRequest.ResponseSchema.ID != schema.ID ||
|
||||
capture.lastRequest.ResponseSchema.Version != schema.Version ||
|
||||
capture.lastRequest.ResponseSchema.Name != schema.Name ||
|
||||
capture.lastRequest.ResponseSchema.SHA256 != schema.SHA256 {
|
||||
t.Fatalf("unexpected forwarded schema metadata: got=%+v want=%+v", *capture.lastRequest.ResponseSchema, schema)
|
||||
}
|
||||
}
|
||||
|
||||
type trackingScheduler struct {
|
||||
inner contracts.LLMScheduler
|
||||
inFlight int32
|
||||
|
||||
Reference in New Issue
Block a user