The old path carried the reachableceo org prefix while the repo lives at
git.knownelement.com/ukrrs/MOPAC; the drift was cited as doc rot. go.mod
and every internal import updated; build/vet/test clean in the builder.
💘 Generated with Crush
Assisted-by: Crush:glm-5.2
79 lines
2.1 KiB
Go
79 lines
2.1 KiB
Go
package writeback
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"ukrrs.com/mopac/harness/internal/task"
|
|
)
|
|
|
|
func TestWriteProducesReportAndLatest(t *testing.T) {
|
|
dir := t.TempDir()
|
|
r := Report{
|
|
Time: time.Date(2026, 8, 28, 19, 41, 2, 0, time.UTC),
|
|
Vertical: "demo-stack",
|
|
Task: task.Task{ID: "demo-1", Subject: "MVP demo", Prompt: "tell me about yourself", Class: "primary", Source: "demo"},
|
|
Class: "primary",
|
|
Tier: "mopac-primary",
|
|
Model: "glm-5.3",
|
|
PromptTokens: 12,
|
|
CompletionTokens: 340,
|
|
TotalTokens: 352,
|
|
Rounds: 1,
|
|
StopReason: "complete",
|
|
Duration: 2 * time.Second,
|
|
Content: "I am GLM, a large language model.",
|
|
}
|
|
path, err := Write(dir, r)
|
|
if err != nil {
|
|
t.Fatalf("Write: %v", err)
|
|
}
|
|
want := filepath.Join(dir, "REPORT-demo-stack-demo-1-20260828-194102.md")
|
|
if path != want {
|
|
t.Errorf("path = %s, want %s", path, want)
|
|
}
|
|
body, err := os.ReadFile(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
s := string(body)
|
|
for _, want := range []string{
|
|
"model: glm-5.3 (tier mopac-primary, class primary)",
|
|
"usage: prompt=12 completion=340 total=352 tokens",
|
|
"rounds=1",
|
|
"## Result",
|
|
"I am GLM, a large language model.",
|
|
} {
|
|
if !strings.Contains(s, want) {
|
|
t.Errorf("REPORT missing %q", want)
|
|
}
|
|
}
|
|
latest, err := os.ReadFile(filepath.Join(dir, "REPORT-latest.md"))
|
|
if err != nil || len(latest) != len(body) {
|
|
t.Errorf("REPORT-latest.md missing or stale (err=%v)", err)
|
|
}
|
|
// No .tmp litter.
|
|
entries, _ := os.ReadDir(dir)
|
|
for _, e := range entries {
|
|
if strings.HasSuffix(e.Name(), ".tmp") {
|
|
t.Errorf("tmp file left behind: %s", e.Name())
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSanitize(t *testing.T) {
|
|
if got := sanitize("a/b c"); got != "a-b-c" {
|
|
t.Errorf("sanitize = %q", got)
|
|
}
|
|
}
|
|
|
|
func TestEmptyContentPlaceholder(t *testing.T) {
|
|
r := Report{Time: time.Now(), Vertical: "v", Task: task.Task{ID: "x"}, Content: ""}
|
|
if !strings.Contains(r.Render(), "(no content produced)") {
|
|
t.Errorf("empty content should render a placeholder")
|
|
}
|
|
}
|