Add Notarius credential configuration

This commit is contained in:
2026-09-16 14:22:45 +00:00
parent 2d346733d6
commit 9d68cfcf2f
6 changed files with 183 additions and 3 deletions

View File

@@ -50,6 +50,72 @@ notarius:
}
}
func TestNotariusCredentialReferenceLoading(t *testing.T) {
const envName = "NARRATIO_TEST_NOTARIUS_KEY"
const canary = "notarius-credential-canary"
t.Setenv(envName, canary)
tests := []struct {
name string
credential string
wantNil bool
}{
{name: "omitted", wantNil: true},
{name: "null", credential: " llm_api_key: null\n", wantNil: true},
{name: "custom reference", credential: " llm_api_key: " + envName + "\n"},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
path := filepath.Join(t.TempDir(), "pipeline.yml")
pipelineYAML := testPipelineBaseYAML + "\nnotarius:\n enabled: false\n" + test.credential
if err := os.WriteFile(path, []byte(pipelineYAML), 0o644); err != nil {
t.Fatal(err)
}
cfg, err := LoadPipeline(path)
if err != nil {
t.Fatal(err)
}
if test.wantNil {
if cfg.Notarius.LLMAPIKey != nil {
t.Fatal("credential reference should be nil")
}
return
}
if cfg.Notarius.LLMAPIKey == nil || cfg.Notarius.LLMAPIKey.EnvName() != envName ||
!cfg.Notarius.LLMAPIKey.IsResolved() || cfg.Notarius.LLMAPIKey.Value() != canary {
t.Fatal("credential reference was not loaded and resolved")
}
})
}
}
func TestNotariusCredentialReferenceFailures(t *testing.T) {
const missing = "NARRATIO_TEST_NOTARIUS_MISSING"
if err := os.Unsetenv(missing); err != nil {
t.Fatal(err)
}
tests := []struct {
name, reference, want string
}{
{name: "missing", reference: missing, want: "secret.unset"},
{name: "empty", reference: `""`, want: "secret.invalid_name"},
{name: "invalid", reference: "123-NOT-AN-ENV-NAME", want: "secret.invalid_name"},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
path := filepath.Join(t.TempDir(), "pipeline.yml")
pipelineYAML := testPipelineBaseYAML + "\nnotarius:\n enabled: false\n llm_api_key: " + test.reference + "\n"
if err := os.WriteFile(path, []byte(pipelineYAML), 0o644); err != nil {
t.Fatal(err)
}
_, err := LoadPipeline(path)
if err == nil || !strings.Contains(err.Error(), test.want) {
t.Fatalf("LoadPipeline() error = %v, want classification %q", err, test.want)
}
})
}
}
func TestNotariusEnabledDefaultsAndPathResolution(t *testing.T) {
dir := t.TempDir()
pipelinePath := filepath.Join(dir, "deployment", "pipeline.yml")