feat(assets): seven asset commands + Run dispatch/helpers
check-dupes, clean-dupes, check-mdl, fix-mdl, convert, upscale, compile behind a single runner indirection, mirroring internal/depot's Run shape. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package assets
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUpscalePNGUsesBackend(t *testing.T) {
|
||||
// A fake backend binary on PATH so look() resolves it.
|
||||
binDir := t.TempDir()
|
||||
fake := filepath.Join(binDir, "upscayl-bin")
|
||||
if err := os.WriteFile(fake, []byte("#!/bin/sh\n"), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv("PATH", binDir)
|
||||
|
||||
// Stub runner: emulate `-i in -o out -s scale` by copying in->out.
|
||||
orig := runner
|
||||
defer func() { runner = orig }()
|
||||
var gotScale string
|
||||
runner = func(dir string, env []string, name string, args ...string) ([]byte, error) {
|
||||
var in, out string
|
||||
for i := 0; i < len(args)-1; i++ {
|
||||
switch args[i] {
|
||||
case "-i":
|
||||
in = args[i+1]
|
||||
case "-o":
|
||||
out = args[i+1]
|
||||
case "-s":
|
||||
gotScale = args[i+1]
|
||||
}
|
||||
}
|
||||
data, err := os.ReadFile(in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, os.WriteFile(out, data, 0o644)
|
||||
}
|
||||
|
||||
dir := t.TempDir()
|
||||
src := filepath.Join(dir, "tex.png")
|
||||
if err := os.WriteFile(src, []byte("pngdata"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var stdout, stderr bytes.Buffer
|
||||
if code := runUpscale([]string{"--scale", "2", dir}, &stdout, &stderr); code != exitOK {
|
||||
t.Fatalf("upscale exit = %d\n%s", code, stderr.String())
|
||||
}
|
||||
if gotScale != "2" {
|
||||
t.Fatalf("scale passed to backend = %q, want 2", gotScale)
|
||||
}
|
||||
if data, _ := os.ReadFile(src); string(data) != "pngdata" {
|
||||
t.Fatalf("upscaled file content = %q, want the backend output", data)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpscaleNoBackendFailsClosed(t *testing.T) {
|
||||
t.Setenv("PATH", t.TempDir()) // empty PATH: no backend resolvable
|
||||
dir := t.TempDir()
|
||||
if err := os.WriteFile(filepath.Join(dir, "tex.png"), []byte("x"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var stdout, stderr bytes.Buffer
|
||||
if code := runUpscale([]string{dir}, &stdout, &stderr); code != exitTool {
|
||||
t.Fatalf("no-backend exit = %d, want %d", code, exitTool)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user