Verify the complete native CLI cutover and record roadmap completion
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
@@ -129,6 +130,41 @@ type failedDeliveryWriter struct{ cause error }
|
||||
|
||||
func (writer failedDeliveryWriter) Write([]byte) (int, error) { return 0, writer.cause }
|
||||
|
||||
type partialDeliveryWriter struct {
|
||||
bytes.Buffer
|
||||
cause error
|
||||
}
|
||||
|
||||
func (writer *partialDeliveryWriter) Write(value []byte) (int, error) {
|
||||
count := min(2, len(value))
|
||||
_, _ = writer.Buffer.Write(value[:count])
|
||||
return count, writer.cause
|
||||
}
|
||||
|
||||
func TestPartialOutputAndDiagnosticFailureUseNativeFinalization(t *testing.T) {
|
||||
t.Chdir(t.TempDir())
|
||||
failure := errors.New("presentation failure")
|
||||
app, err := commandkit.New(commandkit.Identity{Name: "delivery"}, commandkit.NewCommand(commandkit.CommandSpec[struct{}]{Name: "run", Run: func(inv commandkit.Invocation, _ struct{}) commandkit.Outcome {
|
||||
return deliverRunResult(inv, runInput{ReportPath: commandkit.Supplied[string]{Set: true, Value: "report"}}, &promptkit.RunResult{Artifact: promptkit.Artifact{Body: []byte("artifact")}})
|
||||
}}))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
output := &partialDeliveryWriter{cause: failure}
|
||||
var diagnostics bytes.Buffer
|
||||
outcome := app.Execute(context.Background(), []string{"run"}, commandkit.Streams{Out: output, Err: &diagnostics})
|
||||
if outcome.Status != 1 || output.String() != "ar" || !errors.Is(outcome.Presentation.Output.WriteError, failure) {
|
||||
t.Fatalf("partial output was lost: %+v %q", outcome, output.String())
|
||||
}
|
||||
if _, err := os.Stat("report"); err != nil {
|
||||
t.Fatal("report was not attempted", err)
|
||||
}
|
||||
outcome = Execute(context.Background(), commandkit.Identity{Name: "scriptorium"}, []string{"run"}, io.Discard, failedDeliveryWriter{failure})
|
||||
if outcome.Status != 1 || outcome.Kind != commandkit.OutcomeOperational || !errors.Is(outcome.Presentation.Diagnostics.WriteError, failure) {
|
||||
t.Fatalf("usage diagnostic failure not finalized: %+v", outcome)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNativeDeliveryAttemptsReportAfterStdoutFailure(t *testing.T) {
|
||||
t.Chdir(t.TempDir())
|
||||
result := &promptkit.RunResult{RunID: "known-result", Artifact: promptkit.Artifact{Body: []byte("body")}}
|
||||
|
||||
Reference in New Issue
Block a user