From 1ef43dbabd1bbbb206bea867b98e843229ff747b Mon Sep 17 00:00:00 2001 From: Gerard Louis Recinto Date: Sat, 19 Sep 2026 17:53:00 -0700 Subject: [PATCH] add real coverage for IngestAgent's config and dependency resolution ingest.go had zero tests. covered the validation gates that fire before any real infra spins up: missing config file, invalid JSON, an unknown target agent ID, and an embedder pointing at a dependency agent that doesn't exist inline or on disk. left the actual DB/vector ingestion path alone since exercising it needs real infra setup, noted as a follow-up. etl coverage 24.9% -> 35.0%. Claude-Session: https://claude.ai/code/session_01ABxAejDCQZhXXLwCjTEtoc --- ai/etl/ingest_test.go | 70 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 ai/etl/ingest_test.go diff --git a/ai/etl/ingest_test.go b/ai/etl/ingest_test.go new file mode 100644 index 000000000..1c6731922 --- /dev/null +++ b/ai/etl/ingest_test.go @@ -0,0 +1,70 @@ +package etl + +import ( + "context" + "os" + "path/filepath" + "strings" + "testing" +) + +func writeIngestConfig(t *testing.T, contents string) string { + t.Helper() + path := filepath.Join(t.TempDir(), "config.json") + if err := os.WriteFile(path, []byte(contents), 0o600); err != nil { + t.Fatalf("failed to write config fixture: %v", err) + } + return path +} + +func TestIngestAgent_MissingConfigFileReturnsError(t *testing.T) { + path := filepath.Join(t.TempDir(), "does-not-exist.json") + + err := IngestAgent(context.Background(), path, "", "") + if err == nil { + t.Fatal("expected an error for a missing config file") + } + if !strings.Contains(err.Error(), "failed to load config") { + t.Errorf("expected a 'failed to load config' error, got: %v", err) + } +} + +func TestIngestAgent_InvalidJSONReturnsError(t *testing.T) { + path := writeIngestConfig(t, `{not valid json`) + + err := IngestAgent(context.Background(), path, "", "") + if err == nil { + t.Fatal("expected an error for invalid config JSON") + } + if !strings.Contains(err.Error(), "failed to load config") { + t.Errorf("expected a 'failed to load config' error, got: %v", err) + } +} + +func TestIngestAgent_UnknownTargetAgentIDReturnsError(t *testing.T) { + path := writeIngestConfig(t, `{"id":"root-agent","name":"Root"}`) + + err := IngestAgent(context.Background(), path, "", "no-such-agent") + if err == nil { + t.Fatal("expected an error for a target agent ID absent from both the inline agents list and the root config") + } + if !strings.Contains(err.Error(), "agent 'no-such-agent' not found in configuration file") { + t.Errorf("expected an 'agent not found' error, got: %v", err) + } +} + +func TestIngestAgent_UnknownEmbedderDependencyReturnsError(t *testing.T) { + path := writeIngestConfig(t, `{ + "id": "root-agent", + "name": "Root", + "embedder": {"type": "agent", "agent_id": "missing-dep"} + }`) + + err := IngestAgent(context.Background(), path, "", "") + if err == nil { + t.Fatal("expected an error when the embedder's agent dependency can't be resolved") + } + if !strings.Contains(err.Error(), "dependency agent 'missing-dep' not found in inline agents or as a file") { + t.Errorf("expected a 'dependency agent not found' error, got: %v", err) + } +}