Complete the core operation execution cutover

This commit is contained in:
2026-11-25 16:17:59 +00:00
parent b6a3638d70
commit 7d96c69a32
73 changed files with 891 additions and 1065 deletions

View File

@@ -41,8 +41,8 @@ func (store *producerCacheStore) Store(ctx context.Context, mode contracts.Cache
return store.inner.Store(ctx, mode, hash, content)
}
func numberCacheOperation(store contracts.ArtifactCache) contracts.ProducerOperation[int] {
return contracts.ProducerOperation[int]{
func numberCacheOperation(store contracts.ArtifactCache) ExecutionContext[int] {
return ExecutionContext[int]{
Controls: contracts.ProducerControls{Mode: contracts.ModeStrict, Cache: contracts.CacheAuto, MaxAdditionalTurns: 1},
ReuseEligible: true, Assess: acceptedProducerAssessment,
Cache: &contracts.ProducerCache[int]{
@@ -103,19 +103,19 @@ func TestProducerCachesAppliedCorrectionUnderInitialKeyAndReusesWithoutExecution
}
// The response is a proposal; the cache must contain the applied typed value,
// not the private response or an earlier candidate.
interpretApplied := func(ctx context.Context, response *promptkit.RunResult) (*int, []string, error) {
interpretApplied := func(ctx context.Context, response *promptkit.RunResult) (contracts.Evaluation[int], error) {
value, guidance, err := interpretProducerNumber(ctx, response)
if value != nil {
*value *= 10
}
return value, guidance, err
return numberEvaluation(value, guidance), err
}
store.beforeWrite = func(hash string, content []byte) {
if assessments != 2 || calls != 2 || string(content) != "20" || hash != keys[0] {
t.Fatalf("early or incorrect cache store: %s %q, calls=%d assessments=%d", hash, content, calls, assessments)
}
}
value, outcome, err := RunProducer(ctx, engine, operation, nativeProducerInitial(), interpretApplied, producerCorrection, nil)
value, outcome, err := runNativeOperation(ctx, engine, operation, contracts.NativeOperation[int]{Initial: nativeProducerInitial(), Interpret: interpretApplied, Correction: producerCorrection, Fallback: nil})
if err != nil || value != 20 || outcome.Disposition != contracts.ProducerAccepted || store.writes != 1 || nativePrepared != 2 || events == 0 {
t.Fatalf("accepted correction = %d %#v %v; writes %d, prepared %d, events %d", value, outcome, err, store.writes, nativePrepared, events)
}
@@ -132,11 +132,10 @@ func TestProducerCachesAppliedCorrectionUnderInitialKeyAndReusesWithoutExecution
t.Fatal("cache hit reassessed")
return contracts.CandidateAssessment{}, nil
}
value, outcome, err = RunProducer(ctx, engine, operation, initial,
func(context.Context, *promptkit.RunResult) (*int, []string, error) {
t.Fatal("cache hit interpreted a model result")
return nil, nil, nil
}, producerCorrection, nil)
value, outcome, err = runNativeOperation(ctx, engine, operation, contracts.NativeOperation[int]{Initial: initial, Interpret: func(context.Context, *promptkit.RunResult) (contracts.Evaluation[int], error) {
t.Fatal("cache hit interpreted a model result")
return numberEvaluation(nil, nil), nil
}, Correction: producerCorrection, Fallback: nil})
if err != nil || value != 20 || !outcome.ReuseEligible || calls != 2 || assessments != 2 || nativePrepared != 2 || events != priorEvents || store.writes != 1 || len(keys) != 2 || keys[0] != keys[1] {
t.Fatalf("settings/session reuse = %d %#v %v; calls=%d assessments=%d native-prepared=%d events=%d keys=%v", value, outcome, err, calls, assessments, nativePrepared, events, keys)
}
@@ -145,7 +144,7 @@ func TestProducerCachesAppliedCorrectionUnderInitialKeyAndReusesWithoutExecution
}
operation.Assess = acceptedProducerAssessment
initial.Inputs["source"] = promptkit.Inline("changed source content")
value, _, err = RunProducer(ctx, engine, operation, initial, interpretApplied, producerCorrection, nil)
value, _, err = runNativeOperation(ctx, engine, operation, contracts.NativeOperation[int]{Initial: initial, Interpret: interpretApplied, Correction: producerCorrection, Fallback: nil})
if err != nil || value != 20 || calls != 3 || len(keys) != 3 || keys[0] == keys[2] || store.writes != 2 {
t.Fatalf("content change did not miss: value %d error %v calls %d keys %v", value, err, calls, keys)
}
@@ -188,7 +187,7 @@ func TestProducerExecutesFrozenPreparedHandleAfterLookup(t *testing.T) {
t.Fatalf("mutable snapshot changed key: %s", key)
}
}
if value, _, err := RunProducer(ctx, engine, operation, initial, interpretProducerNumber, nil, nil); err != nil || value != 1 {
if value, _, err := runNativeOperation(ctx, engine, operation, contracts.NativeOperation[int]{Initial: initial, Interpret: interpretNumberEvaluation, Correction: nil, Fallback: nil}); err != nil || value != 1 {
t.Fatalf("prepared execution = %d, %v", value, err)
}
if started != 1 || finished != 1 {
@@ -241,8 +240,7 @@ func TestProducerCacheSkipsIneligibleBypassedAndNonacceptedWrites(t *testing.T)
}
return acceptedProducerAssessment(ctx, value)
}
_, outcome, err := RunProducer(ctx, engine, operation, nativeProducerInitial(), interpretProducerNumber, producerCorrection,
func(context.Context, *int) (int, error) { return -1, nil })
_, outcome, err := runNativeOperation(ctx, engine, operation, contracts.NativeOperation[int]{Initial: nativeProducerInitial(), Interpret: interpretNumberEvaluation, Correction: producerCorrection, Fallback: func(context.Context, contracts.Evaluation[int]) (int, error) { return -1, nil }})
switch {
case test.cancel:
if !errors.Is(err, context.Canceled) || outcome.Disposition != "" {
@@ -296,7 +294,7 @@ func TestProducerCacheMissesOnUnusableArtifactAndTreatsIOAsDiagnostic(t *testing
store.readErr = errors.New("unreadable cache")
store.writeErr = errors.New("unwritable cache")
}
value, outcome, err := RunProducer(context.Background(), engine, operation, nativeProducerInitial(), interpretProducerNumber, nil, nil)
value, outcome, err := runNativeOperation(context.Background(), engine, operation, contracts.NativeOperation[int]{Initial: nativeProducerInitial(), Interpret: interpretNumberEvaluation, Correction: nil, Fallback: nil})
if err != nil || value != 1 || outcome.Disposition != contracts.ProducerAccepted || calls != 1 || len(diagnostics) == 0 {
t.Fatalf("cache diagnostic changed successful work: %d %#v %v, calls %d, diagnostics %v", value, outcome, err, calls, diagnostics)
}
@@ -322,7 +320,7 @@ func TestProducerCacheDoesNotHideEncodingOrCaptureFailureWithFallback(t *testing
operation.Cache.Observe = func(context.Context, contracts.CacheObservation) error { return failure }
}
fallbacks := 0
_, outcome, err := RunProducer(context.Background(), engine, operation, nativeProducerInitial(), interpretProducerNumber, nil, func(context.Context, *int) (int, error) { fallbacks++; return -1, nil })
_, outcome, err := runNativeOperation(context.Background(), engine, operation, contracts.NativeOperation[int]{Initial: nativeProducerInitial(), Interpret: interpretNumberEvaluation, Correction: nil, Fallback: func(context.Context, contracts.Evaluation[int]) (int, error) { fallbacks++; return -1, nil }})
if !errors.Is(err, failure) || fallbacks != 0 || store.writes != 0 || outcome.Disposition != "" {
t.Fatalf("%s failure=%#v %v, fallback=%d", boundary, outcome, err, fallbacks)
}
@@ -349,7 +347,7 @@ func TestProducerCacheFailedRefreshPreservesPreviousArtifact(t *testing.T) {
}
operation := numberCacheOperation(store)
operation.Controls.Cache = contracts.CacheRefresh
if _, _, err := RunProducer(context.Background(), engine, operation, nativeProducerInitial(), interpretProducerNumber, nil, nil); err == nil {
if _, _, err := runNativeOperation(context.Background(), engine, operation, contracts.NativeOperation[int]{Initial: nativeProducerInitial(), Interpret: interpretNumberEvaluation, Correction: nil, Fallback: nil}); err == nil {
t.Fatal("refresh failure accepted")
}
content, err := os.ReadFile(filepath.Join(root, key+".json"))