Complete the core operation execution cutover
This commit is contained in:
@@ -8,12 +8,6 @@ import (
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
)
|
||||
|
||||
// PrepareChunkExtraction validates common D&D extraction prerequisites and
|
||||
// prepares owned chunk-scoped source material for prompt inputs.
|
||||
func PrepareChunkExtraction[T any](ctx context.Context, req contracts.TypedExtractionRequest[T]) (contracts.LLMInputMaterial, error) {
|
||||
return PrepareChunkInput(ctx, contracts.ExtractionInput{Source: req.Source, Chunk: req.Chunk, SourceInput: req.SourceInput})
|
||||
}
|
||||
|
||||
// PrepareChunkInput validates the chunk-scoped inputs used during preparation.
|
||||
func PrepareChunkInput(ctx context.Context, req contracts.ExtractionInput) (contracts.LLMInputMaterial, error) {
|
||||
if ctx == nil {
|
||||
|
||||
@@ -10,13 +10,13 @@ import (
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
)
|
||||
|
||||
func TestPrepareChunkExtraction(t *testing.T) {
|
||||
func TestPrepareChunkInput(t *testing.T) {
|
||||
canceled, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
tests := []struct {
|
||||
name string
|
||||
ctx context.Context
|
||||
configure func(*contracts.TypedExtractionRequest[any])
|
||||
configure func(*contracts.ExtractionInput)
|
||||
sourceInput contracts.LLMInputMaterial
|
||||
want contracts.LLMInputMaterial
|
||||
wantErr string
|
||||
@@ -33,21 +33,21 @@ func TestPrepareChunkExtraction(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "nil source",
|
||||
configure: func(req *contracts.TypedExtractionRequest[any]) {
|
||||
configure: func(req *contracts.ExtractionInput) {
|
||||
req.Source = nil
|
||||
},
|
||||
wantErr: "source must not be nil",
|
||||
},
|
||||
{
|
||||
name: "nil chunk",
|
||||
configure: func(req *contracts.TypedExtractionRequest[any]) {
|
||||
configure: func(req *contracts.ExtractionInput) {
|
||||
req.Chunk = nil
|
||||
},
|
||||
wantErr: "chunk must not be nil",
|
||||
},
|
||||
{
|
||||
name: "empty chunk units",
|
||||
configure: func(req *contracts.TypedExtractionRequest[any]) {
|
||||
configure: func(req *contracts.ExtractionInput) {
|
||||
req.Chunk = &source.Chunk{ID: req.Chunk.ID}
|
||||
},
|
||||
wantErr: "units must not be empty",
|
||||
@@ -116,30 +116,30 @@ func TestPrepareChunkExtraction(t *testing.T) {
|
||||
if ctx == nil && test.wantErr != "context must not be nil" {
|
||||
ctx = context.Background()
|
||||
}
|
||||
got, err := PrepareChunkExtraction(ctx, req)
|
||||
got, err := PrepareChunkInput(ctx, req)
|
||||
if test.wantErr != "" {
|
||||
if err == nil || !strings.Contains(err.Error(), test.wantErr) {
|
||||
t.Fatalf("PrepareChunkExtraction() error = %v, want %q", err, test.wantErr)
|
||||
t.Fatalf("PrepareChunkInput() error = %v, want %q", err, test.wantErr)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("PrepareChunkExtraction() error = %v, want nil", err)
|
||||
t.Fatalf("PrepareChunkInput() error = %v, want nil", err)
|
||||
}
|
||||
if !reflect.DeepEqual(got, test.want) {
|
||||
t.Fatalf("PrepareChunkExtraction() = %#v, want %#v", got, test.want)
|
||||
t.Fatalf("PrepareChunkInput() = %#v, want %#v", got, test.want)
|
||||
}
|
||||
if test.mutateOutput {
|
||||
got.Content[0] = 'x'
|
||||
if string(req.SourceInput.Content) != string(test.sourceInput.Content) || string(req.Chunk.Content) != `{"units":[1,2]}` {
|
||||
t.Fatal("PrepareChunkExtraction() output shares request content")
|
||||
t.Fatal("PrepareChunkInput() output shares request content")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func extractionRequest() contracts.TypedExtractionRequest[any] {
|
||||
func extractionRequest() contracts.ExtractionInput {
|
||||
doc := &source.SourceDocument{ID: "session-alpha"}
|
||||
chunk := &source.Chunk{
|
||||
ID: "session-alpha:chunk:0",
|
||||
@@ -148,5 +148,5 @@ func extractionRequest() contracts.TypedExtractionRequest[any] {
|
||||
MediaType: "application/json",
|
||||
Units: []source.SourceUnit{{ID: 1}},
|
||||
}
|
||||
return contracts.TypedExtractionRequest[any]{Source: doc, Chunk: chunk}
|
||||
return contracts.ExtractionInput{Source: doc, Chunk: chunk}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user