Migrate PromptKit reports to shared rendering
This commit is contained in:
@@ -15,7 +15,6 @@ type smokeCommandInput[I any] struct {
|
||||
selection ckconfig.Selection
|
||||
kind string
|
||||
request promptkit.SmokeTestRequest
|
||||
format string
|
||||
captured commandkit.FlagValues[I]
|
||||
selected I
|
||||
}
|
||||
@@ -36,8 +35,6 @@ func newSmokeTestCommand[I, S any](suite Suite[I, S]) commandkit.Command {
|
||||
func(input **smokeCommandInput[I], value commandkit.Supplied[string]) {
|
||||
(*input).selection.Overlay = value
|
||||
}),
|
||||
commandkit.ValueFlag(commandkit.FlagMeta{Name: "format", Usage: "Smoke report format: yaml.", Completion: completionChoices("yaml")}, stringDefault("yaml"), parseDefinitionString,
|
||||
func(input **smokeCommandInput[I], value commandkit.Supplied[string]) { (*input).format = value.Value }),
|
||||
commandkit.ValueFlag(commandkit.FlagMeta{Name: "backend", Usage: "PromptKit backend ID."}, (*string)(nil), parseDefinitionString,
|
||||
func(input **smokeCommandInput[I], value commandkit.Supplied[string]) {
|
||||
(*input).request.BackendID = value.Value
|
||||
@@ -134,7 +131,7 @@ func newSmokeTestCommand[I, S any](suite Suite[I, S]) commandkit.Command {
|
||||
Name: "test",
|
||||
Summary: "Run one PromptKit smoke test.",
|
||||
NewInput: func() *smokeCommandInput[I] {
|
||||
return &smokeCommandInput[I]{format: "yaml"}
|
||||
return &smokeCommandInput[I]{}
|
||||
},
|
||||
Flags: flags,
|
||||
Arguments: []commandkit.Argument[*smokeCommandInput[I]]{
|
||||
@@ -145,9 +142,6 @@ func newSmokeTestCommand[I, S any](suite Suite[I, S]) commandkit.Command {
|
||||
if input == nil {
|
||||
return errors.New("PromptKit smoke-test input must not be nil")
|
||||
}
|
||||
if err := checkSmokeFormat(input.format); err != nil {
|
||||
return err
|
||||
}
|
||||
if input.kind != "all" {
|
||||
input.request.Kind = promptkit.SmokeTestKind(input.kind)
|
||||
}
|
||||
@@ -175,13 +169,6 @@ func parseSmokeFloat(value string) (float64, error) {
|
||||
return strconv.ParseFloat(value, 64)
|
||||
}
|
||||
|
||||
func checkSmokeFormat(format string) error {
|
||||
if format != "yaml" {
|
||||
return fmt.Errorf("unsupported smoke report format %q; expected yaml", format)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func runSmokeTest[I, S any](invocation commandkit.Invocation, suite Suite[I, S], input *smokeCommandInput[I]) commandkit.Outcome {
|
||||
if err := promptKitContextError(invocation.Context); err != nil {
|
||||
return definitionFailure("PromptKit smoke testing was canceled.", commandkit.Explanation{}, err)
|
||||
@@ -214,14 +201,7 @@ func runSmokeTest[I, S any](invocation commandkit.Invocation, suite Suite[I, S],
|
||||
return definitionFailure(smokeFailureMessage(input.kind), acquired.Explanation, operationErr)
|
||||
}
|
||||
|
||||
_ = invocation.Reporter().RenderOutput(func(writer io.Writer) error {
|
||||
output, err := encodeSmokeReport(acquired.Value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = writer.Write(output)
|
||||
return err
|
||||
})
|
||||
_ = invocation.Reporter().Report(commandkit.Report{Value: smokeReportFromNative(acquired.Value)})
|
||||
if operationErr != nil {
|
||||
return definitionFailure(smokeFailureMessage(input.kind), acquired.Explanation, operationErr)
|
||||
}
|
||||
@@ -281,14 +261,7 @@ func runSmokeAggregate[I, S any](invocation commandkit.Invocation, suite Suite[I
|
||||
if len(results) == 0 {
|
||||
return definitionFailure("PromptKit aggregate smoke testing did not produce any results.", combineSmokeExplanations(explanations), errors.Join(operationErrors...))
|
||||
}
|
||||
_ = invocation.Reporter().RenderOutput(func(writer io.Writer) error {
|
||||
output, err := encodeSmokeResults(results)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = writer.Write(output)
|
||||
return err
|
||||
})
|
||||
_ = invocation.Reporter().Report(commandkit.Report{Value: smokeResultsReport(results)})
|
||||
if len(operationErrors) > 0 {
|
||||
return definitionFailure("One or more PromptKit smoke tests failed.", combineSmokeExplanations(explanations), errors.Join(operationErrors...))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user