-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples_test.go
More file actions
57 lines (53 loc) · 2.02 KB
/
Copy pathexamples_test.go
File metadata and controls
57 lines (53 loc) · 2.02 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
package cli_test
import (
"os"
"path/filepath"
"testing"
cli "github.com/civitai/cli"
"github.com/civitai/cli/internal/manifest"
"github.com/civitai/cli/internal/validate"
)
// TestExampleManifestsValidateClean asserts that the real example manifests
// shipped under examples/ (copied from the live civitai-block-* apps) pass the
// CLI's `validate` — making the README/PR claim "the example manifests validate
// clean" TRUE rather than aspirational. If a future server-validator change
// makes one of these stricter, this test fails and forces a reconciliation
// (fix the example, or fix the ported check, and document it).
//
// SCOPE — this checks schema/structural conformance ONLY. It says nothing about
// whether any VALUE in an example is well-chosen: page.buzzBudgetPerGen: 10
// satisfies `exclusiveMinimum: 0` no matter how it was sized. Sizing guidance is
// prose (README + the canonical schema's field description), deliberately not a
// test — any threshold here would have to guess at correct sizing per app and
// would fire on legitimately cheap ones.
func TestExampleManifestsValidateClean(t *testing.T) {
entries, err := cli.ExamplesFS.ReadDir("examples")
if err != nil {
t.Fatalf("read embedded examples: %v", err)
}
if len(entries) == 0 {
t.Fatal("no example manifests embedded — examples/*.block.manifest.json missing")
}
for _, e := range entries {
e := e
t.Run(e.Name(), func(t *testing.T) {
data, err := cli.ExamplesFS.ReadFile(filepath.Join("examples", e.Name()))
if err != nil {
t.Fatalf("read %s: %v", e.Name(), err)
}
dir := t.TempDir()
// validate.Dir expects the manifest at the project root under the
// canonical filename.
if err := os.WriteFile(filepath.Join(dir, manifest.Filename), data, 0o600); err != nil {
t.Fatalf("write manifest: %v", err)
}
res, err := validate.Dir(dir)
if err != nil {
t.Fatalf("validate.Dir: %v", err)
}
if !res.OK() {
t.Fatalf("example %s should validate clean, got errors: %v", e.Name(), res.Errors)
}
})
}
}