Verify native bundle and configuration reports

This commit is contained in:
2026-11-06 00:59:56 +00:00
parent 33cc36ff3b
commit 1e3879e880
2 changed files with 58 additions and 2 deletions

View File

@@ -15,6 +15,7 @@ import (
commandkit "go.maximumdirect.net/commandkit"
configkit "go.maximumdirect.net/configkit"
promptkit "go.maximumdirect.net/promptkit"
"go.yaml.in/yaml/v4"
)
const adapterPrompt = `prompts:
@@ -288,7 +289,7 @@ func TestConfigScopeUsesNativeInspectionFacetsAndInvocationValues(t *testing.T)
t.Fatalf("scope acquisition = (%#v, %v), calls=%d", acquired, err, loaderCalls)
}
var effective bytes.Buffer
if err := acquired.Value.Effective.WriteEffective(&effective); err != nil || !strings.Contains(effective.String(), "briefing:") {
if err := acquired.Value.Effective.WriteEffective(&effective); err != nil || !strings.Contains(effective.String(), "id: briefing") {
t.Fatalf("native effective report = %q, %v", effective.String(), err)
}
if sources := acquired.Value.Sources.Sources(); len(sources) == 0 || sources[0].ID == "" {
@@ -299,6 +300,59 @@ func TestConfigScopeUsesNativeInspectionFacetsAndInvocationValues(t *testing.T)
}
}
func TestBundledRecordsAndSourcesReachCommandOutput(t *testing.T) {
engine := bundledEngine(t)
ctx := context.Background()
profiles, err := engine.ListProfiles(ctx)
if err != nil || len(profiles) == 0 {
t.Fatalf("native bundled profiles = %v, %v", profiles, err)
}
inspection, err := engine.InspectConfiguration()
if err != nil {
t.Fatal(err)
}
sources := inspection.Sources()
if len(sources) == 0 || sources[0].ID == "" {
t.Fatalf("native bundled sources = %#v", sources)
}
load := func(context.Context, ckconfig.Selection, struct{}, struct{}) (*promptkit.Engine, error) {
return engine, nil
}
app, err := commandkit.New(commandkit.Identity{Name: "bundle"}, Command(FromEngine(load)), ckconfig.Command(ckconfig.Suite[struct{}, struct{}]{Scopes: []ckconfig.Scope[struct{}, struct{}]{ConfigScope(load)}}))
if err != nil {
t.Fatal(err)
}
var out bytes.Buffer
result := app.Execute(ctx, []string{"promptkit", "list", "profiles", "--format", "yaml"}, commandkit.Streams{Out: &out, Err: io.Discard})
var gotProfiles []string
if result.Kind != commandkit.OutcomeSuccess {
t.Fatalf("profile catalog = %#v: %s", result, out.String())
}
if err := yaml.Unmarshal(out.Bytes(), &gotProfiles); err != nil || !slices.Contains(gotProfiles, profiles[0]) {
t.Fatalf("bundled profile %q missing from catalog %q: %v", profiles[0], out.String(), err)
}
out.Reset()
result = app.Execute(ctx, []string{"config", "sources", "--scope", "promptkit", "--format", "yaml"}, commandkit.Streams{Out: &out, Err: io.Discard})
var report struct {
Sources []struct {
ID string `yaml:"id"`
Label string `yaml:"label"`
} `yaml:"sources"`
}
if result.Kind != commandkit.OutcomeSuccess {
t.Fatalf("source report = %#v: %s", result, out.String())
}
if err := yaml.Unmarshal(out.Bytes(), &report); err != nil {
t.Fatal(err)
}
for _, source := range report.Sources {
if source.ID == sources[0].ID && source.Label == sources[0].Label {
return
}
}
t.Fatalf("bundled source %#v missing from report %q", sources[0], out.String())
}
func TestConfigScopeRetainsNilLoaderIssueAfterCapabilitiesAreCleared(t *testing.T) {
scope := ConfigScope[int, int](nil)
if scope.Acquire != nil {