Share runtime glossaries with inspection commands
This commit is contained in:
@@ -88,3 +88,90 @@ func TestProcessRuntimeGlossaryFailures(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNativeCommandsUseRuntimeGlossary(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
for name, data := range map[string]string{
|
||||
"left.yml": "version: 3\ncontext: {description: left}\nglossary_collections: {party: {entries: [{id: a, name: Left, category: C}]}}\n",
|
||||
"right.yml": "version: 3\ncontext: {description: right}\nglossary_collections: {party: {entries: [{id: b, name: Right, category: C}]}}\n",
|
||||
"input.yml": "party: {entries: [{id: c, name: Runtime, category: C}]}\n",
|
||||
"bad.yml": "party: [\n",
|
||||
} {
|
||||
if err := os.WriteFile(filepath.Join(dir, name), []byte(data), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
app, err := buildApplication()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
run := func(args ...string) (int, string, string) {
|
||||
t.Helper()
|
||||
var out, stderr bytes.Buffer
|
||||
result := app.Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &stderr})
|
||||
return result.Status, out.String(), stderr.String()
|
||||
}
|
||||
main := filepath.Join(dir, "left.yml")
|
||||
file := filepath.Join(dir, "input.yml")
|
||||
code, out, stderr := run("config", "show", "--scope=app", "--config", main, "--glossary-file", file)
|
||||
if code != 0 || !strings.Contains(out, "Runtime") || strings.Contains(out, "name: Left") {
|
||||
t.Fatalf("show %d %s %s", code, out, stderr)
|
||||
}
|
||||
code, out, stderr = run("config", "explain", "--scope=app", "--config", main, "--glossary-file", file, "--path=/glossary_collections/party/entries")
|
||||
if code != 0 || !strings.Contains(out, "--glossary-file") {
|
||||
t.Fatalf("explain %d %s %s", code, out, stderr)
|
||||
}
|
||||
code, out, stderr = run("config", "diff", "--details", "--scope=app", "--config", main, "--against-config", filepath.Join(dir, "right.yml"), "--glossary-file", file)
|
||||
if code != 0 || !strings.Contains(out, "left") || !strings.Contains(out, "right") || strings.Contains(out, "glossary_collections") {
|
||||
t.Fatalf("diff %d %s %s", code, out, stderr)
|
||||
}
|
||||
for _, args := range [][]string{{"config", "show", "--scope=promptkit"}, {"promptkit", "list", "prompts"}} {
|
||||
valid := append(append([]string(nil), args...), "--config", main, "--glossary-file", file)
|
||||
code, _, stderr = run(valid...)
|
||||
if code != 0 {
|
||||
t.Fatalf("%v: %d %s", valid, code, stderr)
|
||||
}
|
||||
args = append(args, "--config", main, "--glossary-file", filepath.Join(dir, "bad.yml"))
|
||||
code, _, stderr = run(args...)
|
||||
if code == 0 || !strings.Contains(stderr, "bad.yml") {
|
||||
t.Fatalf("%v: %d %s", args, code, stderr)
|
||||
}
|
||||
}
|
||||
for _, args := range [][]string{{"--help"}, {"version"}, {"config", "scopes"}, {"promptkit", "--help"}} {
|
||||
code, _, stderr = run(args...)
|
||||
if code != 0 {
|
||||
t.Fatalf("%v: %d %s", args, code, stderr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRuntimeGlossaryUsesInvocationDirectory(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
project := filepath.Join(root, "project")
|
||||
invocation := filepath.Join(root, "invocation")
|
||||
for _, dir := range []string{project, invocation, filepath.Join(project, "overlays"), filepath.Join(project, "secrets")} {
|
||||
if err := os.MkdirAll(dir, 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
t.Setenv("AUDITA_GLOSSARY_CONTEXT_TEST", "")
|
||||
files := map[string]string{
|
||||
filepath.Join(project, "config.yml"): "version: 3\nconfig: {secrets_dir: secrets, secrets_overwrite: true}\ncontext: {description: main}\n",
|
||||
filepath.Join(project, "secrets", "AUDITA_GLOSSARY_CONTEXT_TEST"): "loaded",
|
||||
filepath.Join(project, "glossary.yml"): "reference: {entries: [{id: r, name: Companion, category: C}]}\n",
|
||||
filepath.Join(project, "overlays", "chosen.yml"): "context: {description: overlay}\n",
|
||||
filepath.Join(invocation, "input.yml"): "config: {imports: [{path: imported.yml}]}\nparty: {entries: [{id: a, name: Incoming, category: C}]}\n",
|
||||
filepath.Join(invocation, "imported.yml"): "lore: {entries: [{id: b, name: Imported, category: C}]}\n",
|
||||
}
|
||||
for path, data := range files {
|
||||
if err := os.WriteFile(path, []byte(data), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
t.Chdir(invocation)
|
||||
var out, stderr bytes.Buffer
|
||||
code := Run(context.Background(), []string{"config", "show", "--scope=app", "--config", filepath.Join(project, "config.yml"), "--overlay", "chosen", "--glossary-file", "input.yml"}, &out, &stderr)
|
||||
if code != 0 || !strings.Contains(out.String(), "Incoming") || !strings.Contains(out.String(), "Imported") || !strings.Contains(out.String(), "Companion") || !strings.Contains(out.String(), "overlay") || os.Getenv("AUDITA_GLOSSARY_CONTEXT_TEST") != "loaded" {
|
||||
t.Fatalf("status=%d out=%s err=%s", code, out.String(), stderr.String())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user