Share a lazy source index across cache hits
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"errors"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
||||
@@ -13,6 +14,47 @@ import (
|
||||
"go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
func TestRunnerChecksCurrentSourceOnConcurrentCacheHits(t *testing.T) {
|
||||
_, cache := filesystemProducerCache(t)
|
||||
var calls atomic.Int32
|
||||
engine := nativeProducerEngine(t, producerClientFunc(func(context.Context, promptkit.GenerateRequest) (*promptkit.GenerateResponse, error) {
|
||||
calls.Add(1)
|
||||
return &promptkit.GenerateResponse{Content: `{"value":1}`}, nil
|
||||
}))
|
||||
const chunkCount = 4
|
||||
prepared := preparedConcurrentPipeline(t, chunkCount)
|
||||
for i := range prepared.Steps[0].lanes {
|
||||
lane := &prepared.Steps[0].lanes[i]
|
||||
if lane.resolved.ArtifactKind != "test/notes" {
|
||||
continue
|
||||
}
|
||||
lane.resolved.ExtractExecutionClass = contracts.ExecutionClassLLMBacked
|
||||
lane.typed.cacheEvidence = func(any) ([]source.SourceRef, error) {
|
||||
return []source.SourceRef{{SourceID: "source", StartUnitID: 1, EndUnitID: 1}}, nil
|
||||
}
|
||||
lane.typed.extract = func(ctx context.Context, _ any, request contracts.TypedExtractionRequest[any]) (erasedTypedResult, error) {
|
||||
initial := nativeProducerInitial()
|
||||
initial.Inputs["source"] = promptkit.Inline(string(request.Chunk.Content))
|
||||
value, outcome, err := RunProducer(ctx, engine, request.Operation, initial,
|
||||
func(context.Context, *promptkit.RunResult) (*any, []string, error) {
|
||||
var value any = codecNotes{Items: []string{"accepted"}}
|
||||
return &value, nil, nil
|
||||
}, nil, nil)
|
||||
return erasedTypedResult{Value: value, Outcome: outcome}, err
|
||||
}
|
||||
}
|
||||
for run := 0; run < 2; run++ {
|
||||
// The filesystem store is concurrency-safe; its counting test wrapper is not.
|
||||
output, err := New().Run(context.Background(), RunInput{Prepared: prepared, Cache: cache.inner, RawInput: []byte("input"), Workers: chunkCount})
|
||||
if err != nil || len(output.normalizeOutputs) != 2 {
|
||||
t.Fatalf("run %d: outputs=%d error=%v", run, len(output.normalizeOutputs), err)
|
||||
}
|
||||
}
|
||||
if calls.Load() != chunkCount {
|
||||
t.Fatalf("cache hits executed model work: calls=%d", calls.Load())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunnerReusesAcceptedPredecessorAfterDownstreamFailure(t *testing.T) {
|
||||
_, store := filesystemProducerCache(t)
|
||||
probe := newRunnerProbe()
|
||||
|
||||
Reference in New Issue
Block a user