Extend native catalog adapters
This commit is contained in:
@@ -56,10 +56,10 @@ func TestCommandBuildsIndependentOptionalTrees(t *testing.T) {
|
||||
InspectRequirements: func(context.Context, RequirementsRequest, struct{}, struct{}) (commandkit.Acquired[*promptkit.RequirementInspection], error) {
|
||||
return commandkit.Acquired[*promptkit.RequirementInspection]{}, nil
|
||||
},
|
||||
ListPrompts: func(context.Context, ckconfig.Selection, struct{}, struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
ListPrompts: func(context.Context, CatalogRequest, struct{}, struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
return commandkit.Acquired[[]promptkit.PromptIdentity]{}, nil
|
||||
},
|
||||
ListProfiles: func(context.Context, ckconfig.Selection, struct{}, struct{}) (commandkit.Acquired[[]string], error) {
|
||||
ListProfiles: func(context.Context, CatalogRequest, struct{}, struct{}) (commandkit.Acquired[[]string], error) {
|
||||
return commandkit.Acquired[[]string]{}, nil
|
||||
},
|
||||
})
|
||||
@@ -232,12 +232,12 @@ func TestRequirementsCommandUsageFailuresPrecedeApplicationPreparation(t *testin
|
||||
|
||||
func TestCatalogCommandTreesAreIndependentAndOmitShow(t *testing.T) {
|
||||
prompts := Command(Suite[struct{}, struct{}]{
|
||||
ListPrompts: func(context.Context, ckconfig.Selection, struct{}, struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
ListPrompts: func(context.Context, CatalogRequest, struct{}, struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
return commandkit.Acquired[[]promptkit.PromptIdentity]{}, nil
|
||||
},
|
||||
})
|
||||
profiles := Command(Suite[struct{}, struct{}]{
|
||||
ListProfiles: func(context.Context, ckconfig.Selection, struct{}, struct{}) (commandkit.Acquired[[]string], error) {
|
||||
ListProfiles: func(context.Context, CatalogRequest, struct{}, struct{}) (commandkit.Acquired[[]string], error) {
|
||||
return commandkit.Acquired[[]string]{}, nil
|
||||
},
|
||||
})
|
||||
@@ -264,7 +264,7 @@ func TestCatalogCommandTreesAreIndependentAndOmitShow(t *testing.T) {
|
||||
InspectPrompt: func(context.Context, PromptRequest, struct{}, struct{}) (commandkit.Acquired[*promptkit.PromptInspection], error) {
|
||||
return commandkit.Acquired[*promptkit.PromptInspection]{}, nil
|
||||
},
|
||||
ListPrompts: func(context.Context, ckconfig.Selection, struct{}, struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
ListPrompts: func(context.Context, CatalogRequest, struct{}, struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
return commandkit.Acquired[[]promptkit.PromptIdentity]{}, nil
|
||||
},
|
||||
})
|
||||
@@ -298,9 +298,9 @@ func TestCatalogListUsesPreparedInputAndPreflightsFormat(t *testing.T) {
|
||||
}
|
||||
return nil
|
||||
},
|
||||
ListPrompts: func(_ context.Context, selection ckconfig.Selection, value input, gotState state) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
ListPrompts: func(_ context.Context, request CatalogRequest, value input, gotState state) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
providerCalls++
|
||||
received, receivedSelection, receivedState = value, selection, gotState
|
||||
received, receivedSelection, receivedState = value, request.Selection, gotState
|
||||
return commandkit.Acquired[[]promptkit.PromptIdentity]{Value: []promptkit.PromptIdentity{{ID: "briefing", Version: testStringPointer("1")}}}, nil
|
||||
},
|
||||
}
|
||||
@@ -372,13 +372,13 @@ func TestCatalogLifecycleCapturesSelectorsAndRefreshesInvocationValues(t *testin
|
||||
}
|
||||
return nil
|
||||
},
|
||||
ListPrompts: func(_ context.Context, selection ckconfig.Selection, got input, gotState *state) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
ListPrompts: func(_ context.Context, request CatalogRequest, got input, gotState *state) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
providers++
|
||||
if gotState == nil || gotState.run != providers {
|
||||
t.Errorf("provider state = %#v at invocation %d", gotState, providers)
|
||||
}
|
||||
if providers == 1 && (!selection.Config.Set || selection.Config.Value != "" || !selection.Overlay.Set || selection.Overlay.Value != "" || !got.campaign.Set || !got.enabled.Set || !got.limit.Set || !got.labels.Set) {
|
||||
t.Errorf("first provider values = selection %#v input %#v", selection, got)
|
||||
if providers == 1 && (!request.Selection.Config.Set || request.Selection.Config.Value != "" || !request.Selection.Overlay.Set || request.Selection.Overlay.Value != "" || !got.campaign.Set || !got.enabled.Set || !got.limit.Set || !got.labels.Set) {
|
||||
t.Errorf("first provider values = selection %#v input %#v", request.Selection, got)
|
||||
}
|
||||
return commandkit.Acquired[[]promptkit.PromptIdentity]{Value: []promptkit.PromptIdentity{}}, nil
|
||||
},
|
||||
@@ -424,9 +424,9 @@ func TestCatalogLifecycleCapturesSelectorsAndRefreshesInvocationValues(t *testin
|
||||
|
||||
func TestCatalogNilFactoriesSupplyZeroValues(t *testing.T) {
|
||||
app := newPromptTestApp(t, Command(Suite[*struct{}, *struct{}]{
|
||||
ListPrompts: func(_ context.Context, selection ckconfig.Selection, input, state *struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
if input != nil || state != nil || selection.Config.Set || selection.Overlay.Set {
|
||||
t.Errorf("nil-factory values = selection %#v input %#v state %#v", selection, input, state)
|
||||
ListPrompts: func(_ context.Context, request CatalogRequest, input, state *struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
if input != nil || state != nil || request.Selection.Config.Set || request.Selection.Overlay.Set {
|
||||
t.Errorf("nil-factory values = selection %#v input %#v state %#v", request.Selection, input, state)
|
||||
}
|
||||
return commandkit.Acquired[[]promptkit.PromptIdentity]{}, nil
|
||||
},
|
||||
@@ -446,10 +446,10 @@ func TestCatalogCommandsRenderNativeValuesAndEmptySequences(t *testing.T) {
|
||||
}
|
||||
profiles := []string{"later", "001", "a: true", "later"}
|
||||
suite := Suite[struct{}, struct{}]{
|
||||
ListPrompts: func(context.Context, ckconfig.Selection, struct{}, struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
ListPrompts: func(context.Context, CatalogRequest, struct{}, struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
return commandkit.Acquired[[]promptkit.PromptIdentity]{Value: prompts}, nil
|
||||
},
|
||||
ListProfiles: func(context.Context, ckconfig.Selection, struct{}, struct{}) (commandkit.Acquired[[]string], error) {
|
||||
ListProfiles: func(context.Context, CatalogRequest, struct{}, struct{}) (commandkit.Acquired[[]string], error) {
|
||||
return commandkit.Acquired[[]string]{Value: profiles}, nil
|
||||
},
|
||||
}
|
||||
@@ -502,14 +502,14 @@ func TestCatalogCommandsRenderNativeValuesAndEmptySequences(t *testing.T) {
|
||||
|
||||
promptEmptyCalls, profileEmptyCalls := 0, 0
|
||||
emptyApp := newPromptTestApp(t, Command(Suite[struct{}, struct{}]{
|
||||
ListPrompts: func(context.Context, ckconfig.Selection, struct{}, struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
ListPrompts: func(context.Context, CatalogRequest, struct{}, struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
promptEmptyCalls++
|
||||
if promptEmptyCalls%2 == 0 {
|
||||
return commandkit.Acquired[[]promptkit.PromptIdentity]{Value: []promptkit.PromptIdentity{}}, nil
|
||||
}
|
||||
return commandkit.Acquired[[]promptkit.PromptIdentity]{Value: nil}, nil
|
||||
},
|
||||
ListProfiles: func(context.Context, ckconfig.Selection, struct{}, struct{}) (commandkit.Acquired[[]string], error) {
|
||||
ListProfiles: func(context.Context, CatalogRequest, struct{}, struct{}) (commandkit.Acquired[[]string], error) {
|
||||
profileEmptyCalls++
|
||||
if profileEmptyCalls%2 == 0 {
|
||||
return commandkit.Acquired[[]string]{Value: []string{}}, nil
|
||||
@@ -530,7 +530,7 @@ func TestCatalogCommandsRenderNativeValuesAndEmptySequences(t *testing.T) {
|
||||
|
||||
func TestCatalogRejectsOperandsAndUnavailableSelectors(t *testing.T) {
|
||||
calls := 0
|
||||
app := newPromptTestApp(t, Command(Suite[struct{}, struct{}]{ListPrompts: func(context.Context, ckconfig.Selection, struct{}, struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
app := newPromptTestApp(t, Command(Suite[struct{}, struct{}]{ListPrompts: func(context.Context, CatalogRequest, struct{}, struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
calls++
|
||||
return commandkit.Acquired[[]promptkit.PromptIdentity]{}, nil
|
||||
}}))
|
||||
@@ -564,7 +564,7 @@ func TestCatalogFailuresRetainDiagnosticsAndDeliveryState(t *testing.T) {
|
||||
return false
|
||||
}
|
||||
providerErr := errors.New("catalog provider failed")
|
||||
app := newPromptTestApp(t, Command(Suite[struct{}, struct{}]{ListPrompts: func(context.Context, ckconfig.Selection, struct{}, struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
app := newPromptTestApp(t, Command(Suite[struct{}, struct{}]{ListPrompts: func(context.Context, CatalogRequest, struct{}, struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
return commandkit.Acquired[[]promptkit.PromptIdentity]{Diagnostics: []commandkit.Diagnostic{diagnostic}}, providerErr
|
||||
}}))
|
||||
outcome := app.Execute(context.Background(), []string{"promptkit", "list", "prompts"}, commandkit.Streams{Out: io.Discard, Err: io.Discard})
|
||||
@@ -573,7 +573,7 @@ func TestCatalogFailuresRetainDiagnosticsAndDeliveryState(t *testing.T) {
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
canceled := newPromptTestApp(t, Command(Suite[struct{}, struct{}]{ListPrompts: func(context.Context, ckconfig.Selection, struct{}, struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
canceled := newPromptTestApp(t, Command(Suite[struct{}, struct{}]{ListPrompts: func(context.Context, CatalogRequest, struct{}, struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
cancel()
|
||||
return commandkit.Acquired[[]promptkit.PromptIdentity]{Value: []promptkit.PromptIdentity{{ID: "briefing", Version: testStringPointer("1")}}, Diagnostics: []commandkit.Diagnostic{diagnostic}}, nil
|
||||
}}))
|
||||
@@ -593,7 +593,7 @@ func TestCatalogFailuresRetainDiagnosticsAndDeliveryState(t *testing.T) {
|
||||
{name: "short write", writer: partialReportWriter{}, want: io.ErrShortWrite},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
writerApp := newPromptTestApp(t, Command(Suite[struct{}, struct{}]{ListPrompts: func(context.Context, ckconfig.Selection, struct{}, struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
writerApp := newPromptTestApp(t, Command(Suite[struct{}, struct{}]{ListPrompts: func(context.Context, CatalogRequest, struct{}, struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
return commandkit.Acquired[[]promptkit.PromptIdentity]{Value: []promptkit.PromptIdentity{{ID: "briefing", Version: testStringPointer("1")}}, Diagnostics: []commandkit.Diagnostic{diagnostic}}, nil
|
||||
}}))
|
||||
outcome := writerApp.Execute(context.Background(), []string{"promptkit", "list", "prompts"}, commandkit.Streams{Out: test.writer, Err: io.Discard})
|
||||
|
||||
Reference in New Issue
Block a user