Remove application credential substitution
This commit is contained in:
@@ -5,8 +5,6 @@ import (
|
||||
"html"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/core/redaction"
|
||||
)
|
||||
|
||||
// CompletionLine is the brief successful CLI summary. It uses the same counts
|
||||
@@ -24,12 +22,10 @@ func count(value *int) int {
|
||||
}
|
||||
|
||||
// Markdown renders a fixed-layout human report from one processing snapshot.
|
||||
func Markdown(snapshot Snapshot, secrets ...string) []byte {
|
||||
r := redaction.New(secrets)
|
||||
safe := func(value string) string { return escapeMarkdown(r.String(value)) }
|
||||
func Markdown(snapshot Snapshot) []byte {
|
||||
var b strings.Builder
|
||||
fmt.Fprintf(&b, "# Audita report: %s\n\n", safe(snapshot.RunID))
|
||||
fmt.Fprintf(&b, "Status: %s\n\n", safe(snapshot.Status))
|
||||
fmt.Fprintf(&b, "# Audita report: %s\n\n", escapeMarkdown(snapshot.RunID))
|
||||
fmt.Fprintf(&b, "Status: %s\n\n", escapeMarkdown(snapshot.Status))
|
||||
fmt.Fprintf(&b, "Corrections applied: %d \n", count(snapshot.Summary.CorrectionsApplied))
|
||||
fmt.Fprintf(&b, "Work units: %s total; %s completed; %s interrupted; %s not started \n",
|
||||
showCount(snapshot.Summary.WorkUnitsTotal), showCount(snapshot.Summary.WorkUnitsCompleted),
|
||||
@@ -38,20 +34,20 @@ func Markdown(snapshot Snapshot, secrets ...string) []byte {
|
||||
fmt.Fprintf(&b, "Recoveries: %s of %s model operations \n", showCount(snapshot.Summary.Recoveries), showCount(snapshot.Summary.LLMOperations))
|
||||
fmt.Fprintf(&b, "Proposal responses: %s; with filtering: %s\n\n",
|
||||
showCount(snapshot.Summary.ProposalResponses), showCount(snapshot.Summary.ProposalResponsesWithFiltering))
|
||||
fmt.Fprintf(&b, "Transcript input: %s \n", safe(snapshot.TranscriptPath))
|
||||
fmt.Fprintf(&b, "Transcript input: %s \n", escapeMarkdown(snapshot.TranscriptPath))
|
||||
output := snapshot.OutputPath
|
||||
if output == "" {
|
||||
output = "stdout"
|
||||
}
|
||||
fmt.Fprintf(&b, "Transcript output: %s\n\n", safe(output))
|
||||
fmt.Fprintf(&b, "Transcript output: %s\n\n", escapeMarkdown(output))
|
||||
|
||||
fmt.Fprintln(&b, "## Work-unit errors")
|
||||
fmt.Fprintln(&b)
|
||||
writeMatrix(&b, snapshot, r, false)
|
||||
writeMatrix(&b, snapshot, false)
|
||||
fmt.Fprintln(&b)
|
||||
fmt.Fprintln(&b, "## Recoveries")
|
||||
fmt.Fprintln(&b)
|
||||
writeMatrix(&b, snapshot, r, true)
|
||||
writeMatrix(&b, snapshot, true)
|
||||
fmt.Fprintln(&b)
|
||||
if len(snapshot.RepairOutcomes) > 0 {
|
||||
fmt.Fprintln(&b, "## Correction repair")
|
||||
@@ -59,14 +55,14 @@ func Markdown(snapshot Snapshot, secrets ...string) []byte {
|
||||
fmt.Fprintln(&b, "| Stage | Chunk | Proposal index | Attempts | Outcome |")
|
||||
fmt.Fprintln(&b, "| ---: | ---: | ---: | ---: | --- |")
|
||||
for _, row := range snapshot.RepairOutcomes {
|
||||
fmt.Fprintf(&b, "| %d | %d | %d | %d | %s |\n", row.StageIndex+1, row.ChunkIndex+1, row.ProposalIndex, row.Attempts, safe(row.Outcome))
|
||||
fmt.Fprintf(&b, "| %d | %d | %d | %d | %s |\n", row.StageIndex+1, row.ChunkIndex+1, row.ProposalIndex, row.Attempts, escapeMarkdown(row.Outcome))
|
||||
}
|
||||
fmt.Fprintln(&b)
|
||||
}
|
||||
fmt.Fprintln(&b, "Legend: `—` = not started; `n*` = interrupted with n recorded errors or recoveries. Completed error cells are 0 or 1.")
|
||||
fmt.Fprintln(&b)
|
||||
writeReasons(&b, "Error reasons", errorReasons(snapshot.Errors), safe)
|
||||
writeReasons(&b, "Recovery reasons", recoveryReasons(snapshot.Recoveries), safe)
|
||||
writeReasons(&b, "Error reasons", errorReasons(snapshot.Errors))
|
||||
writeReasons(&b, "Recovery reasons", recoveryReasons(snapshot.Recoveries))
|
||||
fmt.Fprintln(&b, "A recovery can have multiple reasons; reason counts need not sum to the recovery total.")
|
||||
fmt.Fprintln(&b)
|
||||
fmt.Fprintln(&b, "Details: `errors.yml` and `recoveries.yml`.")
|
||||
@@ -80,7 +76,7 @@ func showCount(value *int) string {
|
||||
return fmt.Sprint(*value)
|
||||
}
|
||||
|
||||
func writeMatrix(b *strings.Builder, snapshot Snapshot, redactor redaction.Redactor, recovery bool) {
|
||||
func writeMatrix(b *strings.Builder, snapshot Snapshot, recovery bool) {
|
||||
if len(snapshot.StageNames) == 0 || len(snapshot.WorkUnits) == 0 {
|
||||
fmt.Fprintln(b, "No work units.")
|
||||
return
|
||||
@@ -88,7 +84,7 @@ func writeMatrix(b *strings.Builder, snapshot Snapshot, redactor redaction.Redac
|
||||
columns := snapshot.StageNames
|
||||
fmt.Fprint(b, "| Chunk |")
|
||||
for _, name := range columns {
|
||||
fmt.Fprintf(b, " %s |", stageCellEscaper.Replace(html.EscapeString(redactor.String(name))))
|
||||
fmt.Fprintf(b, " %s |", stageCellEscaper.Replace(html.EscapeString(name)))
|
||||
}
|
||||
fmt.Fprint(b, "\n| --- |")
|
||||
for range columns {
|
||||
@@ -137,7 +133,7 @@ var stageCellEscaper = strings.NewReplacer(
|
||||
"://", "://", "www.", "www.", "@", "@",
|
||||
)
|
||||
|
||||
func writeReasons(b *strings.Builder, title string, counts map[string]int, safe func(string) string) {
|
||||
func writeReasons(b *strings.Builder, title string, counts map[string]int) {
|
||||
fmt.Fprintf(b, "### %s\n\n", title)
|
||||
if len(counts) == 0 {
|
||||
fmt.Fprintln(b, "None.")
|
||||
@@ -150,7 +146,7 @@ func writeReasons(b *strings.Builder, title string, counts map[string]int, safe
|
||||
}
|
||||
sort.Strings(keys)
|
||||
for _, key := range keys {
|
||||
fmt.Fprintf(b, "- `%s`: %d\n", safe(key), counts[key])
|
||||
fmt.Fprintf(b, "- `%s`: %d\n", escapeMarkdown(key), counts[key])
|
||||
}
|
||||
fmt.Fprintln(b)
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func TestMarkdownFixedLayoutAndCounts(t *testing.T) {
|
||||
Errors: []ErrorRecord{{Scope: "work_unit", Failures: []Failure{{Reason: "transport_failed"}, {Reason: "transport_failed"}}}},
|
||||
Recoveries: []RecoveryRecord{{Reasons: []string{"output_repaired", "proposals_filtered"}}, {Reasons: []string{"output_repaired"}}, {Reasons: []string{"service_recovered"}}},
|
||||
}
|
||||
got := Markdown(snapshot, "secret")
|
||||
got := Markdown(snapshot)
|
||||
text := string(got)
|
||||
// Compare only complete table rows, preserving order and states while leaving
|
||||
// prose and spacing outside the fixed matrices free to change.
|
||||
@@ -45,7 +45,7 @@ func TestMarkdownFixedLayoutAndCounts(t *testing.T) {
|
||||
if rows := markdownTableRows(text); !reflect.DeepEqual(rows, wantRows) {
|
||||
t.Fatalf("matrices: got %v; want %v", rows, wantRows)
|
||||
}
|
||||
for _, fragment := range []string{"in\\|put\\`[REDACTED]\\`.json", "out<br>file.json", "`transport_failed`: 1", "`output_repaired`: 2", "`proposals_filtered`: 1", "`service_recovered`: 1"} {
|
||||
for _, fragment := range []string{"in\\|put\\`secret\\`.json", "out<br>file.json", "`transport_failed`: 1", "`output_repaired`: 2", "`proposals_filtered`: 1", "`service_recovered`: 1"} {
|
||||
if !strings.Contains(text, fragment) {
|
||||
t.Fatalf("missing %q in:\n%s", fragment, text)
|
||||
}
|
||||
@@ -69,9 +69,6 @@ func TestMarkdownFixedLayoutAndCounts(t *testing.T) {
|
||||
t.Fatalf("%s summary: got %v; want %v", label, got, want)
|
||||
}
|
||||
}
|
||||
if strings.Contains(text, "secret") {
|
||||
t.Fatal("secret leaked")
|
||||
}
|
||||
var decoded struct {
|
||||
Summary Summary `yaml:"summary"`
|
||||
}
|
||||
@@ -88,12 +85,12 @@ func TestMarkdownFixedLayoutAndCounts(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMarkdownNoWorkAndEscapedStageLabel(t *testing.T) {
|
||||
text := string(Markdown(Snapshot{RunID: "r", StageNames: []string{"bad|label`\nsecret"}}, "secret"))
|
||||
text := string(Markdown(Snapshot{RunID: "r", StageNames: []string{"bad|label`\nsecret"}}))
|
||||
if len(markdownTableRows(text)) != 0 || strings.Contains(text, "secret") {
|
||||
t.Fatal(text)
|
||||
}
|
||||
text = string(Markdown(Snapshot{RunID: "r", StageNames: []string{"bad|label`\nsecret"}, WorkUnits: []WorkUnit{{StageIndex: 0, ChunkIndex: 0, State: "completed"}}}, "secret"))
|
||||
if !strings.Contains(text, "bad\\|label\\`<br>\\[REDACTED\\]") {
|
||||
text = string(Markdown(Snapshot{RunID: "r", StageNames: []string{"bad|label`\nsecret"}, WorkUnits: []WorkUnit{{StageIndex: 0, ChunkIndex: 0, State: "completed"}}}))
|
||||
if !strings.Contains(text, "bad\\|label\\`<br>secret") {
|
||||
t.Fatal(text)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/core/redaction"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
@@ -178,17 +177,13 @@ func completionTime(t *time.Time) *string {
|
||||
return &value
|
||||
}
|
||||
|
||||
// YAML redacts only string nodes after typed serialization.
|
||||
func YAML(document any, secrets ...string) ([]byte, error) {
|
||||
// YAML encodes the report document.
|
||||
func YAML(document any) ([]byte, error) {
|
||||
raw, err := yaml.Marshal(document)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("encode report YAML: %w", err)
|
||||
}
|
||||
safe, err := redaction.New(secrets).YAML(raw)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("redact report YAML: %w", err)
|
||||
}
|
||||
return safe, nil
|
||||
return raw, nil
|
||||
}
|
||||
|
||||
// StageLabel identifies a configured entry by position, module, and optional ID.
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func TestYAMLRedactsStringsWithoutChangingScalarTypes(t *testing.T) {
|
||||
func TestYAMLPreservesScalarTypes(t *testing.T) {
|
||||
zero, one := 0, 1
|
||||
falseValue := false
|
||||
snapshot := Snapshot{RunID: "secret\\\"key", Status: StatusCompleted, StartedAt: time.Date(2026, 9, 24, 0, 0, 0, 0, time.UTC),
|
||||
@@ -16,18 +16,15 @@ func TestYAMLRedactsStringsWithoutChangingScalarTypes(t *testing.T) {
|
||||
Errors: []ErrorRecord{{Scope: "run", Phase: "processing", Reason: "internal_failure", Message: "secret\\\"key 1"}},
|
||||
Recoveries: []RecoveryRecord{{StageIndex: 0, Reasons: []string{"service_recovered"}, ExecutionCounts: ExecutionCounts{RetriesExhausted: &falseValue}}}}
|
||||
for _, document := range []any{snapshot.ErrorsDocument(), snapshot.RecoveriesDocument()} {
|
||||
payload, err := YAML(document, `secret\"key`, "1")
|
||||
payload, err := YAML(document)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(string(payload), `secret\"key`) {
|
||||
t.Fatalf("secret leaked: %s", payload)
|
||||
}
|
||||
var decoded map[string]any
|
||||
if err := yaml.Unmarshal(payload, &decoded); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if decoded["version"] != 1 || decoded["started_at"] != "2026-09-24T00:00:00Z" {
|
||||
if decoded["run_id"] != snapshot.RunID || decoded["version"] != 1 || decoded["started_at"] != "2026-09-24T00:00:00Z" {
|
||||
t.Fatalf("wrong envelope types: %#v", decoded)
|
||||
}
|
||||
summary := decoded["summary"].(map[string]any)
|
||||
@@ -35,7 +32,7 @@ func TestYAMLRedactsStringsWithoutChangingScalarTypes(t *testing.T) {
|
||||
t.Fatalf("changed count types: %#v", summary)
|
||||
}
|
||||
}
|
||||
if payload, err := YAML(snapshot.RecoveriesDocument(), "1"); err != nil || !strings.Contains(string(payload), "retries_exhausted: false") {
|
||||
if payload, err := YAML(snapshot.RecoveriesDocument()); err != nil || !strings.Contains(string(payload), "retries_exhausted: false") {
|
||||
t.Fatalf("boolean changed: %s %v", payload, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user