Files
mev-beta/orig/tools/math-audit/internal/report/report.go
Administrator c54c569f30 refactor: move all remaining files to orig/ directory
Completed clean root directory structure:
- Root now contains only: .git, .env, docs/, orig/
- Moved all remaining files and directories to orig/:
  - Config files (.claude, .dockerignore, .drone.yml, etc.)
  - All .env variants (except active .env)
  - Git config (.gitconfig, .github, .gitignore, etc.)
  - Tool configs (.golangci.yml, .revive.toml, etc.)
  - Documentation (*.md files, @prompts)
  - Build files (Dockerfiles, Makefile, go.mod, go.sum)
  - Docker compose files
  - All source directories (scripts, tests, tools, etc.)
  - Runtime directories (logs, monitoring, reports)
  - Dependency files (node_modules, lib, cache)
  - Special files (--delete)

- Removed empty runtime directories (bin/, data/)

V2 structure is now clean:
- docs/planning/ - V2 planning documents
- orig/ - Complete V1 codebase preserved
- .env - Active environment config (not in git)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-10 10:53:05 +01:00

98 lines
2.9 KiB
Go

package report
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/fraktal/mev-beta/tools/math-audit/internal/audit"
)
// WriteJSON writes the audit result as pretty JSON to the specified directory.
func WriteJSON(dir string, res audit.Result) (string, error) {
if err := os.MkdirAll(dir, 0o755); err != nil {
return "", fmt.Errorf("create report dir: %w", err)
}
path := filepath.Join(dir, "report.json")
payload, err := json.MarshalIndent(res, "", " ")
if err != nil {
return "", fmt.Errorf("marshal report: %w", err)
}
if err := os.WriteFile(path, payload, 0o644); err != nil {
return "", fmt.Errorf("write report: %w", err)
}
return path, nil
}
// WriteMarkdown renders a human-readable summary and writes it next to the JSON.
func WriteMarkdown(dir string, res audit.Result) (string, error) {
if err := os.MkdirAll(dir, 0o755); err != nil {
return "", fmt.Errorf("create report dir: %w", err)
}
path := filepath.Join(dir, "report.md")
content := GenerateMarkdown(res)
if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
return "", fmt.Errorf("write markdown: %w", err)
}
return path, nil
}
// GenerateMarkdown returns a markdown representation of the audit result.
func GenerateMarkdown(res audit.Result) string {
var b strings.Builder
b.WriteString("# Math Audit Report\n\n")
b.WriteString(fmt.Sprintf("- Generated: %s UTC\n", res.Summary.GeneratedAt.Format("2006-01-02 15:04:05")))
b.WriteString(fmt.Sprintf("- Vectors: %d/%d passed\n", res.Summary.VectorsPassed, res.Summary.TotalVectors))
b.WriteString(fmt.Sprintf("- Assertions: %d/%d passed\n", res.Summary.AssertionsPassed, res.Summary.TotalAssertions))
b.WriteString(fmt.Sprintf("- Property checks: %d/%d passed\n\n", res.Summary.PropertySucceeded, res.Summary.PropertyChecks))
if len(res.Vectors) > 0 {
b.WriteString("## Vector Results\n\n")
b.WriteString("| Vector | Exchange | Status | Notes |\n")
b.WriteString("| --- | --- | --- | --- |\n")
for _, vec := range res.Vectors {
status := "✅ PASS"
if !vec.Passed {
status = "❌ FAIL"
}
var notes []string
for _, test := range vec.Tests {
if !test.Passed {
notes = append(notes, fmt.Sprintf("%s (%.4f bps)", test.Name, test.DeltaBPS))
}
}
if len(vec.Errors) > 0 {
notes = append(notes, vec.Errors...)
}
noteStr := ""
if len(notes) > 0 {
noteStr = strings.Join(notes, "; ")
}
b.WriteString(fmt.Sprintf("| %s | %s | %s | %s |\n", vec.Name, vec.Exchange, status, noteStr))
}
b.WriteString("\n")
}
if len(res.PropertyChecks) > 0 {
b.WriteString("## Property Checks\n\n")
for _, check := range res.PropertyChecks {
status := "✅"
if !check.Passed {
status = "❌"
}
if check.Details != "" {
b.WriteString(fmt.Sprintf("- %s %s — %s\n", status, check.Name, check.Details))
} else {
b.WriteString(fmt.Sprintf("- %s %s\n", status, check.Name))
}
}
b.WriteString("\n")
}
return b.String()
}