Enforce runtime report contracts and recoverable session exports
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSessionExportCompleteness(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
evidence protocol.SessionExport
|
||||
want string
|
||||
}{
|
||||
{protocol.SessionExport{Source: "native_export", HTML: "session.html", HTMLBytes: 100}, "empty"},
|
||||
{protocol.SessionExport{Source: "native_export", Diagnostic: "export failed"}, "failed"},
|
||||
{protocol.SessionExport{Source: "native_export", Messages: 2, HTML: "session.html", HTMLBytes: 100, Truncated: true}, "partial"},
|
||||
{protocol.SessionExport{Source: "native_export", Messages: 2, HTML: "session.html", HTMLBytes: 100}, "complete"},
|
||||
{protocol.SessionExport{Source: "unavailable"}, "unavailable"},
|
||||
} {
|
||||
classifySessionExport(&tc.evidence)
|
||||
if tc.evidence.Status != tc.want {
|
||||
t.Fatalf("%+v want %s", tc.evidence, tc.want)
|
||||
}
|
||||
if tc.want == "empty" && tc.evidence.Diagnostic == "" {
|
||||
t.Fatal("empty export has no warning")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRuntimeSessionExportFileVerificationDoesNotClaimMissingEvidence(t *testing.T) {
|
||||
for _, kind := range []string{"missing", "empty", "symlink", "normal"} {
|
||||
t.Run(kind, func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
path := filepath.Join(dir, "session.html")
|
||||
switch kind {
|
||||
case "empty":
|
||||
if err := os.WriteFile(path, nil, 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
case "normal":
|
||||
if err := os.WriteFile(path, []byte("html"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
case "symlink":
|
||||
if err := os.Symlink(filepath.Join(t.TempDir(), "outside"), path); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
evidence := &protocol.SessionExport{Source: "native_export", Messages: 2, HTML: "session.html", HTMLBytes: 4}
|
||||
verifySessionExportFile(evidence, dir)
|
||||
classifySessionExport(evidence)
|
||||
if (evidence.Status == "complete") != (kind == "normal") {
|
||||
t.Fatalf("%s: %+v", kind, evidence)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user