Share runtime glossaries with inspection commands
This commit is contained in:
@@ -98,15 +98,15 @@ func TestPromptConfigurationComparisonAcquiresEqualSelectionsIndependently(t *te
|
||||
}
|
||||
}
|
||||
writeProfile("before")
|
||||
scope := ckprompt.ConfigScope(func(ctx context.Context, selection ckconfig.Selection, input struct{}, state *invocationState) (*pk.Engine, error) {
|
||||
scope := ckprompt.ConfigScope(func(ctx context.Context, selection ckconfig.Selection, input acquisitionInput, state *invocationState) (*pk.Engine, error) {
|
||||
engine, err := loadPromptEngine(ctx, selection, input, state)
|
||||
writeProfile("after")
|
||||
return engine, err
|
||||
})
|
||||
side := ckconfig.ComparisonSide[struct{}]{Selection: ckconfig.Selection{
|
||||
side := ckconfig.ComparisonSide[acquisitionInput]{Selection: ckconfig.Selection{
|
||||
Config: commandkit.Supplied[string]{Value: main, Set: true},
|
||||
}}
|
||||
result, err := scope.Compare(context.Background(), ckconfig.ComparisonRequest[struct{}]{Left: side, Right: side}, &invocationState{})
|
||||
result, err := scope.Compare(context.Background(), ckconfig.ComparisonRequest[acquisitionInput]{Left: side, Right: side}, &invocationState{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -118,6 +118,32 @@ func TestPromptConfigurationComparisonAcquiresEqualSelectionsIndependently(t *te
|
||||
t.Fatal("comparison did not capture the model before and after the resource changed")
|
||||
}
|
||||
|
||||
func TestPromptEngineCacheIncludesRuntimeGlossaryInput(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
main := filepath.Join(dir, "main.yml")
|
||||
first := filepath.Join(dir, "first.yml")
|
||||
second := filepath.Join(dir, "second.yml")
|
||||
for path, contents := range map[string]string{main: "version: 3\n", first: "one: {entries: []}\n", second: "two: {entries: []}\n"} {
|
||||
if err := os.WriteFile(path, []byte(contents), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
selection := ckconfig.Selection{Config: commandkit.Supplied[string]{Value: main, Set: true}}
|
||||
state := &invocationState{}
|
||||
left, err := capturePromptEngine(context.Background(), selection, acquisitionInput{GlossaryFiles: []string{first}}, state)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
right, err := capturePromptEngine(context.Background(), selection, acquisitionInput{GlossaryFiles: []string{second}}, state)
|
||||
if err != nil || left == right {
|
||||
t.Fatalf("different inputs reused engine: %v", err)
|
||||
}
|
||||
matched, err := capturePromptEngine(context.Background(), selection, acquisitionInput{GlossaryFiles: []string{first}}, state)
|
||||
if err != nil || matched != left {
|
||||
t.Fatalf("matching input did not reuse engine: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequestInspectionAndExplicitSmokeUseSameSources(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
file := filepath.Join(dir, "config.yml")
|
||||
|
||||
Reference in New Issue
Block a user