Keep progress writes outside model deadlines
This commit is contained in:
@@ -1561,3 +1561,45 @@ func TestProgressDeliveryFailureKeepsCompletedProcessing(t *testing.T) {
|
||||
t.Fatalf("presentation changed report status: %+v", doc)
|
||||
}
|
||||
}
|
||||
|
||||
type delayedProposalProgress struct {
|
||||
delay time.Duration
|
||||
delayed bool
|
||||
}
|
||||
|
||||
func (w *delayedProposalProgress) Write(p []byte) (int, error) {
|
||||
if !w.delayed && bytes.Contains(p, []byte("proposal started")) {
|
||||
w.delayed = true
|
||||
time.Sleep(w.delay)
|
||||
}
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
func TestProgressDeliveryDoesNotSpendModelDeadline(t *testing.T) {
|
||||
const timeout = 500 * time.Millisecond
|
||||
for _, showProgress := range []bool{false, true} {
|
||||
f := newProcessFixture(t, "normal", "[grammar]")
|
||||
t.Setenv("AUDITA_TEST_PROVIDER_KEY", f.provider.secret)
|
||||
config, err := os.ReadFile(f.config)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
config = bytes.Replace(config, []byte("llm:\n"), []byte("llm:\n operation_timeout: "+timeout.String()+"\n"), 1)
|
||||
if err := os.WriteFile(f.config, config, 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
args := []string{"process", f.transcript, "--config", f.config, "--output", f.output}
|
||||
diagnostics := &delayedProposalProgress{delay: timeout + 250*time.Millisecond}
|
||||
if showProgress {
|
||||
args = append(args, "--progress")
|
||||
}
|
||||
code := cli.Run(context.Background(), args, io.Discard, diagnostics)
|
||||
output, err := os.ReadFile(f.output)
|
||||
if code != 0 || err != nil || !bytes.Contains(output, []byte("Hello world")) || f.provider.callCount() != 3 {
|
||||
t.Fatalf("progress=%v, exit=%d, requests=%d, output=%q, read error=%v", showProgress, code, f.provider.callCount(), output, err)
|
||||
}
|
||||
if diagnostics.delayed != showProgress {
|
||||
t.Fatalf("progress=%v, delayed=%v", showProgress, diagnostics.delayed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user