Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b5a24e31b5 |
@@ -0,0 +1,145 @@
|
||||
// @vitest-environment jsdom
|
||||
/**
|
||||
* Tests for cssVar — maps a ColorToken to a CSS custom-property string.
|
||||
*/
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { cssVar, type ColorToken } from "../theme";
|
||||
|
||||
const ALL_TOKENS: ColorToken[] = [
|
||||
// Warm-paper surface (light-flippable)
|
||||
"surface",
|
||||
"surface-elevated",
|
||||
"surface-sunken",
|
||||
"surface-card",
|
||||
"line",
|
||||
"line-soft",
|
||||
"ink",
|
||||
"ink-mid",
|
||||
"ink-soft",
|
||||
"accent",
|
||||
"accent-strong",
|
||||
"warm",
|
||||
"good",
|
||||
"bad",
|
||||
// Always-dark (terminal / console / log surfaces)
|
||||
"bg",
|
||||
"bg-elev",
|
||||
"bg-card",
|
||||
"line-strong",
|
||||
"ink-mute",
|
||||
"ink-dim",
|
||||
"accent-dim",
|
||||
"plasma",
|
||||
"warn",
|
||||
];
|
||||
|
||||
describe("cssVar", () => {
|
||||
it("returns var(--color-surface) for 'surface'", () => {
|
||||
expect(cssVar("surface")).toBe("var(--color-surface)");
|
||||
});
|
||||
|
||||
it("returns var(--color-surface-elevated) for 'surface-elevated'", () => {
|
||||
expect(cssVar("surface-elevated")).toBe("var(--color-surface-elevated)");
|
||||
});
|
||||
|
||||
it("returns var(--color-surface-sunken) for 'surface-sunken'", () => {
|
||||
expect(cssVar("surface-sunken")).toBe("var(--color-surface-sunken)");
|
||||
});
|
||||
|
||||
it("returns var(--color-surface-card) for 'surface-card'", () => {
|
||||
expect(cssVar("surface-card")).toBe("var(--color-surface-card)");
|
||||
});
|
||||
|
||||
it("returns var(--color-line) for 'line'", () => {
|
||||
expect(cssVar("line")).toBe("var(--color-line)");
|
||||
});
|
||||
|
||||
it("returns var(--color-line-soft) for 'line-soft'", () => {
|
||||
expect(cssVar("line-soft")).toBe("var(--color-line-soft)");
|
||||
});
|
||||
|
||||
it("returns var(--color-ink) for 'ink'", () => {
|
||||
expect(cssVar("ink")).toBe("var(--color-ink)");
|
||||
});
|
||||
|
||||
it("returns var(--color-ink-mid) for 'ink-mid'", () => {
|
||||
expect(cssVar("ink-mid")).toBe("var(--color-ink-mid)");
|
||||
});
|
||||
|
||||
it("returns var(--color-ink-soft) for 'ink-soft'", () => {
|
||||
expect(cssVar("ink-soft")).toBe("var(--color-ink-soft)");
|
||||
});
|
||||
|
||||
it("returns var(--color-accent) for 'accent'", () => {
|
||||
expect(cssVar("accent")).toBe("var(--color-accent)");
|
||||
});
|
||||
|
||||
it("returns var(--color-accent-strong) for 'accent-strong'", () => {
|
||||
expect(cssVar("accent-strong")).toBe("var(--color-accent-strong)");
|
||||
});
|
||||
|
||||
it("returns var(--color-warm) for 'warm'", () => {
|
||||
expect(cssVar("warm")).toBe("var(--color-warm)");
|
||||
});
|
||||
|
||||
it("returns var(--color-good) for 'good'", () => {
|
||||
expect(cssVar("good")).toBe("var(--color-good)");
|
||||
});
|
||||
|
||||
it("returns var(--color-bad) for 'bad'", () => {
|
||||
expect(cssVar("bad")).toBe("var(--color-bad)");
|
||||
});
|
||||
|
||||
it("returns var(--color-bg) for 'bg'", () => {
|
||||
expect(cssVar("bg")).toBe("var(--color-bg)");
|
||||
});
|
||||
|
||||
it("returns var(--color-bg-elev) for 'bg-elev'", () => {
|
||||
expect(cssVar("bg-elev")).toBe("var(--color-bg-elev)");
|
||||
});
|
||||
|
||||
it("returns var(--color-bg-card) for 'bg-card'", () => {
|
||||
expect(cssVar("bg-card")).toBe("var(--color-bg-card)");
|
||||
});
|
||||
|
||||
it("returns var(--color-line-strong) for 'line-strong'", () => {
|
||||
expect(cssVar("line-strong")).toBe("var(--color-line-strong)");
|
||||
});
|
||||
|
||||
it("returns var(--color-ink-mute) for 'ink-mute'", () => {
|
||||
expect(cssVar("ink-mute")).toBe("var(--color-ink-mute)");
|
||||
});
|
||||
|
||||
it("returns var(--color-ink-dim) for 'ink-dim'", () => {
|
||||
expect(cssVar("ink-dim")).toBe("var(--color-ink-dim)");
|
||||
});
|
||||
|
||||
it("returns var(--color-accent-dim) for 'accent-dim'", () => {
|
||||
expect(cssVar("accent-dim")).toBe("var(--color-accent-dim)");
|
||||
});
|
||||
|
||||
it("returns var(--color-plasma) for 'plasma'", () => {
|
||||
expect(cssVar("plasma")).toBe("var(--color-plasma)");
|
||||
});
|
||||
|
||||
it("returns var(--color-warn) for 'warn'", () => {
|
||||
expect(cssVar("warn")).toBe("var(--color-warn)");
|
||||
});
|
||||
|
||||
it("returns a var() string for every ColorToken", () => {
|
||||
for (const token of ALL_TOKENS) {
|
||||
const result = cssVar(token);
|
||||
expect(result).toBe(`var(--color-${token})`);
|
||||
expect(result.startsWith("var(--color-")).toBe(true);
|
||||
expect(result.endsWith(")")).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("is a pure function — same token always returns same output", () => {
|
||||
for (const token of ALL_TOKENS) {
|
||||
for (let i = 0; i < 3; i++) {
|
||||
expect(cssVar(token)).toBe(cssVar(token));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -5,9 +5,6 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -447,178 +444,3 @@ func TestAdminSchedulesHealth_ResponseFields(t *testing.T) {
|
||||
t.Fatalf("unmet expectations: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// ── classifyScheduleStatus — additional edge cases ─────────────────────────────────
|
||||
|
||||
func TestClassifyScheduleStatus_ZeroThreshold(t *testing.T) {
|
||||
now := time.Now()
|
||||
lastRun := now.Add(-365 * 24 * time.Hour) // very old
|
||||
result := classifyScheduleStatus(&lastRun, 0, now)
|
||||
if result != "ok" {
|
||||
t.Errorf("classifyScheduleStatus(threshold=0) = %q; want 'ok'", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClassifyScheduleStatus_NegativeThreshold(t *testing.T) {
|
||||
now := time.Now()
|
||||
lastRun := now.Add(-24 * time.Hour)
|
||||
result := classifyScheduleStatus(&lastRun, -1*time.Hour, now)
|
||||
if result != "ok" {
|
||||
t.Errorf("classifyScheduleStatus(threshold=-1h) = %q; want 'ok'", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClassifyScheduleStatus_ExactlyAtThreshold(t *testing.T) {
|
||||
// Strict >: if now.Sub(lastRun) == threshold, it is NOT stale
|
||||
now := time.Date(2026, 5, 18, 12, 0, 0, 0, time.UTC)
|
||||
lastRun := time.Date(2026, 5, 18, 10, 0, 0, 0, time.UTC) // exactly 2h ago
|
||||
result := classifyScheduleStatus(&lastRun, 2*time.Hour, now)
|
||||
if result != "ok" {
|
||||
t.Errorf("classifyScheduleStatus(exactly at threshold) = %q; want 'ok'", result)
|
||||
}
|
||||
}
|
||||
|
||||
// ── loadRuntimeProvisionTimeouts (runtime_provision_timeouts.go) ─────────────────
|
||||
|
||||
func writeRuntimeConfigYAML(t *testing.T, tmpDir, templateName, runtime string, timeoutSecs int) {
|
||||
t.Helper()
|
||||
dir := filepath.Join(tmpDir, templateName)
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
t.Fatalf("MkdirAll(%s): %v", dir, err)
|
||||
}
|
||||
yamlContent := "runtime: " + runtime + "\nruntime_config:\n provision_timeout_seconds: " + strconv.Itoa(timeoutSecs) + "\n"
|
||||
if err := os.WriteFile(filepath.Join(dir, "config.yaml"), []byte(yamlContent), 0644); err != nil {
|
||||
t.Fatalf("WriteFile: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRuntimeProvisionTimeouts_EmptyDir(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
result := loadRuntimeProvisionTimeouts(tmpDir)
|
||||
if len(result) != 0 {
|
||||
t.Errorf("loadRuntimeProvisionTimeouts(empty dir) len = %d; want 0", len(result))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRuntimeProvisionTimeouts_IgnoresNonDirEntries(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
if err := os.WriteFile(filepath.Join(tmpDir, "not-a-dir.yaml"), []byte("runtime: hermes\n"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result := loadRuntimeProvisionTimeouts(tmpDir)
|
||||
if len(result) != 0 {
|
||||
t.Errorf("loadRuntimeProvisionTimeouts(file-only dir) len = %d; want 0", len(result))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRuntimeProvisionTimeouts_SingleTemplate(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
writeRuntimeConfigYAML(t, tmpDir, "tmpl-hermes", "hermes", 300)
|
||||
result := loadRuntimeProvisionTimeouts(tmpDir)
|
||||
if v, ok := result["hermes"]; !ok || v != 300 {
|
||||
t.Errorf("loadRuntimeProvisionTimeouts → hermes = %d; want 300", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRuntimeProvisionTimeouts_MultipleTemplatesSameRuntime(t *testing.T) {
|
||||
// Two templates using the same runtime — takes the MAX timeout
|
||||
tmpDir := t.TempDir()
|
||||
writeRuntimeConfigYAML(t, tmpDir, "tmpl-hermes-slow", "hermes", 600)
|
||||
writeRuntimeConfigYAML(t, tmpDir, "tmpl-hermes-fast", "hermes", 120)
|
||||
result := loadRuntimeProvisionTimeouts(tmpDir)
|
||||
if v, ok := result["hermes"]; !ok || v != 600 {
|
||||
t.Errorf("loadRuntimeProvisionTimeouts → hermes = %d; want 600 (max of 600, 120)", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRuntimeProvisionTimeouts_MultipleRuntimes(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
writeRuntimeConfigYAML(t, tmpDir, "tmpl-hermes", "hermes", 300)
|
||||
writeRuntimeConfigYAML(t, tmpDir, "tmpl-claude-code", "claude-code", 420)
|
||||
writeRuntimeConfigYAML(t, tmpDir, "tmpl-deepagents", "deepagents", 180)
|
||||
result := loadRuntimeProvisionTimeouts(tmpDir)
|
||||
want := map[string]int{
|
||||
"hermes": 300,
|
||||
"claude-code": 420,
|
||||
"deepagents": 180,
|
||||
}
|
||||
for runtime, wantSecs := range want {
|
||||
if got, ok := result[runtime]; !ok || got != wantSecs {
|
||||
t.Errorf("loadRuntimeProvisionTimeouts → %s = %d; want %d", runtime, got, wantSecs)
|
||||
}
|
||||
}
|
||||
if len(result) != len(want) {
|
||||
t.Errorf("loadRuntimeProvisionTimeouts → len = %d; want %d", len(result), len(want))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRuntimeProvisionTimeouts_IgnoresZeroTimeout(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
writeRuntimeConfigYAML(t, tmpDir, "tmpl-zero", "zero-runtime", 0)
|
||||
result := loadRuntimeProvisionTimeouts(tmpDir)
|
||||
if _, ok := result["zero-runtime"]; ok {
|
||||
t.Errorf("loadRuntimeProvisionTimeouts → 'zero-runtime' present; want absent (timeout=0)")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRuntimeProvisionTimeouts_IgnoresNegativeTimeout(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
writeRuntimeConfigYAML(t, tmpDir, "tmpl-negative", "neg-runtime", -60)
|
||||
result := loadRuntimeProvisionTimeouts(tmpDir)
|
||||
if _, ok := result["neg-runtime"]; ok {
|
||||
t.Errorf("loadRuntimeProvisionTimeouts → 'neg-runtime' present; want absent (timeout<0)")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRuntimeProvisionTimeouts_IgnoresMissingRuntimeField(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
dir := filepath.Join(tmpDir, "tmpl-no-runtime")
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
yamlContent := "template_name: no-runtime-template\nruntime_config:\n provision_timeout_seconds: 300\n"
|
||||
if err := os.WriteFile(filepath.Join(dir, "config.yaml"), []byte(yamlContent), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result := loadRuntimeProvisionTimeouts(tmpDir)
|
||||
if len(result) != 0 {
|
||||
t.Errorf("loadRuntimeProvisionTimeouts → len = %d; want 0 (runtime field absent)", len(result))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRuntimeProvisionTimeouts_IgnoresMalformedYAML(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
dir := filepath.Join(tmpDir, "tmpl-bad-yaml")
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
badYAML := "runtime: bad\n provision_timeout_seconds: not a number\n"
|
||||
if err := os.WriteFile(filepath.Join(dir, "config.yaml"), []byte(badYAML), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result := loadRuntimeProvisionTimeouts(tmpDir)
|
||||
if len(result) != 0 {
|
||||
t.Errorf("loadRuntimeProvisionTimeouts → len = %d; want 0 (malformed YAML)", len(result))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRuntimeProvisionTimeouts_IgnoresMissingConfig(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
if err := os.MkdirAll(filepath.Join(tmpDir, "tmpl-no-config"), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeRuntimeConfigYAML(t, tmpDir, "tmpl-good", "good-runtime", 300)
|
||||
result := loadRuntimeProvisionTimeouts(tmpDir)
|
||||
if v, ok := result["good-runtime"]; !ok || v != 300 {
|
||||
t.Errorf("loadRuntimeProvisionTimeouts → good-runtime = %d; want 300", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRuntimeProvisionTimeouts_IgnoresEmptyRuntime(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
writeRuntimeConfigYAML(t, tmpDir, "tmpl-empty", "", 300)
|
||||
result := loadRuntimeProvisionTimeouts(tmpDir)
|
||||
if len(result) != 0 {
|
||||
t.Errorf("loadRuntimeProvisionTimeouts → len = %d; want 0 (empty runtime)", len(result))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user