Repository navigation
Expand file tree
/
Copy pathtracker_parse_diag_test.go
More file actions
67 lines (55 loc) · 2.43 KB
/
Copy pathtracker_parse_diag_test.go
File metadata and controls
67 lines (55 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// ABOUTME: Regression tests that root-package parse/preflight diagnostics route to the diag sink (#449).
package tracker
import (
"bytes"
"context"
"log/slog"
"strings"
"testing"
"github.com/2389-research/tracker/pipeline"
)
// TestParseDIPSourceDiagnosticsRouteToSink pins the #449 contract for the most
// common library entry path: lint/validation diagnostics emitted while parsing
// a .dip workflow must reach the injected sink, not the process-global logger.
func TestParseDIPSourceDiagnosticsRouteToSink(t *testing.T) {
var buf bytes.Buffer
SetDiagnosticLogger(slog.New(slog.NewTextHandler(&buf, nil)))
t.Cleanup(func() { SetDiagnosticLogger(nil) })
// A syntactically valid workflow that fails validation (no start/exit)
// deterministically yields diagnostics via pipeline.LoadDippinWorkflow.
src := "pipeline mini {\n node A [shape=box]\n node B [shape=box]\n A -> B\n}\n"
_, _ = parseDIPSource(src)
got := buf.String()
if !strings.Contains(got, "DIP001") && !strings.Contains(got, "no start node") {
t.Fatalf("injected sink did not receive the parse diagnostic; got %q", got)
}
}
// TestParseDOTSourceDeprecationRoutesToSink pins that the DOT-deprecation
// warning routes to the injected sink instead of the global logger.
func TestParseDOTSourceDeprecationRoutesToSink(t *testing.T) {
var buf bytes.Buffer
SetDiagnosticLogger(slog.New(slog.NewTextHandler(&buf, nil)))
t.Cleanup(func() { SetDiagnosticLogger(nil) })
_, _ = parseDOTSource("digraph { A -> B }")
got := buf.String()
if !strings.Contains(got, "DOT format is deprecated") {
t.Fatalf("injected sink did not receive the deprecation diagnostic; got %q", got)
}
}
// TestRunPreflightWarningRoutesToSink pins that library preflight warnings route
// to the injected sink instead of os.Stderr.
func TestRunPreflightWarningRoutesToSink(t *testing.T) {
var buf bytes.Buffer
SetDiagnosticLogger(slog.New(slog.NewTextHandler(&buf, nil)))
t.Cleanup(func() { SetDiagnosticLogger(nil) })
// requires:git + warn policy + a non-git workdir -> warns and returns nil.
graph := &pipeline.Graph{Attrs: map[string]string{"requires": "git"}}
cfg := Config{Git: &GitConfig{Preflight: GitPreflightWarn}}
workDir := t.TempDir()
if err := runPreflight(context.Background(), graph, cfg, workDir); err != nil {
t.Fatalf("expected warn policy to return nil, got %v", err)
}
if buf.Len() == 0 {
t.Fatalf("injected sink did not receive the preflight warning; got empty output")
}
}