Remove application credential substitution

This commit is contained in:
2026-11-16 03:37:29 +00:00
parent e34672f7fe
commit ffe0e3491e
37 changed files with 217 additions and 729 deletions

View File

@@ -2,13 +2,17 @@ package diagnostics
import (
"bytes"
"encoding/json"
"errors"
"io"
"math"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"gitea.maximumdirect.net/eric/audita/v3/internal/core/schema"
)
func TestPrepareOutputAllowsInPlaceTranscriptButRejectsReportCollisions(t *testing.T) {
@@ -242,7 +246,7 @@ func TestDebugRunDirectoryUsesSuppliedIDAndIsRetained(t *testing.T) {
if _, err := os.Stat(parent); !errors.Is(err, os.ErrNotExist) {
t.Fatalf("unexpected parent: %v", err)
}
run, err := NewRunDirectory(parent, "run-123", "secret")
run, err := NewRunDirectory(parent, "run-123")
if err != nil {
t.Fatal(err)
}
@@ -252,11 +256,11 @@ func TestDebugRunDirectoryUsesSuppliedIDAndIsRetained(t *testing.T) {
if _, err := NewRunDirectory(parent, "run-123"); err == nil {
t.Fatal("duplicate run ID accepted")
}
if err := run.WriteJSONArtifact(ArtifactCorrectionLedger, map[string]string{"proposal": "secret"}); err != nil {
if err := run.WriteJSONArtifact(ArtifactCorrectionLedger, map[string]string{"proposal": "edit"}); err != nil {
t.Fatal(err)
}
contents, err := os.ReadFile(filepath.Join(run.Path(), ArtifactCorrectionLedger))
if err != nil || strings.Contains(string(contents), "secret") {
if err != nil || string(contents) != "{\"proposal\":\"edit\"}\n" {
t.Fatalf("debug artifact: %s %v", contents, err)
}
if _, err := os.Stat(run.Path()); err != nil {
@@ -264,6 +268,48 @@ func TestDebugRunDirectoryUsesSuppliedIDAndIsRetained(t *testing.T) {
}
}
func TestDebugTranscriptSnapshotsPreserveSourceAndTypedViews(t *testing.T) {
run, err := NewRunDirectory(t.TempDir(), "run-transcripts")
if err != nil {
t.Fatal(err)
}
raw := []byte(" [\n {\"id\": 2, \"text\": \"literal\", \"speaker\": \"A\", \"start\": 0, \"end\": 1}\n ] ")
source, err := schema.ParseSourceTranscriptJSON(raw)
if err != nil {
t.Fatal(err)
}
if err := run.WriteSourceTranscript(source, raw); err != nil {
t.Fatal(err)
}
normalized := &schema.Transcript{Segments: []schema.Segment{{ID: 2, Text: "normalized"}}}
if err := run.WriteNormalizedTranscript(normalized); err != nil {
t.Fatal(err)
}
acquired, err := os.ReadFile(filepath.Join(run.Path(), ArtifactSourceTranscript))
if err != nil || !bytes.Equal(acquired, raw) {
t.Fatalf("acquired source = %q, error = %v", acquired, err)
}
for name, want := range map[string]string{ArtifactParsedSourceTranscript: "literal", ArtifactNormalizedTranscript: "normalized"} {
payload, err := os.ReadFile(filepath.Join(run.Path(), name))
if err != nil {
t.Fatal(err)
}
var transcript schema.Transcript
if err := json.Unmarshal(payload, &transcript); err != nil {
t.Fatal(err)
}
if len(transcript.Segments) != 1 || transcript.Segments[0].ID != 2 || transcript.Segments[0].Text != want {
t.Fatalf("%s: %s", name, payload)
}
}
if err := run.WriteJSONArtifact("invalid.json", math.NaN()); err == nil {
t.Fatal("expected serialization failure")
}
if _, err := os.Stat(filepath.Join(run.Path(), "invalid.json")); !errors.Is(err, os.ErrNotExist) {
t.Fatalf("failed artifact persisted: %v", err)
}
}
func TestSelectionAndAbortPreserveTranscript(t *testing.T) {
dir := t.TempDir()
output := filepath.Join(dir, "output.json")
@@ -363,7 +409,7 @@ func TestOptionalDebugPreparationReportsProblems(t *testing.T) {
if run, problems := session.PrepareDebug(file, "run", InvocationMetadata{}, nil); run != nil || len(problems) == 0 {
t.Fatalf("run=%v problems=%v", run, problems)
}
run, problems := session.PrepareDebug(filepath.Join(dir, "debug"), "run", InvocationMetadata{Operation: "process"}, []byte("secret: sensitive\n"), "sensitive")
run, problems := session.PrepareDebug(filepath.Join(dir, "debug"), "run", InvocationMetadata{Operation: "process"}, []byte("version: 3\n"))
if len(problems) != 0 {
t.Fatal(problems)
}
@@ -371,8 +417,8 @@ func TestOptionalDebugPreparationReportsProblems(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if strings.Contains(string(contents), "sensitive") {
t.Fatal("debug artifact contains secret")
if string(contents) != "version: 3\n" {
t.Fatalf("changed effective configuration: %q", contents)
}
}