sandbox-agent/foundry/packages/cli/test/theme.test.ts
Nathan Flurry 70d31f819c
chore(foundry): improve sandbox impl + status pill (#252)
* Improve Daytona sandbox provisioning and frontend UI

Refactor git clone script in Daytona provider to use cleaner shell logic for GitHub token authentication and branch checkout. Add support for private repository clones with token-based auth. Improve Daytona provider error handling and git configuration setup.

Frontend improvements include enhanced dev panel, workspace dashboard, sidebar navigation, and UI components for better task/session management. Update interest manager and backend client to support improved session state handling.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>

* Add header status pill showing task/session/sandbox state

Surface aggregate status (error, provisioning, running, ready, no sandbox)
as a colored pill in the transcript panel header. Integrates task runtime
status, session status, and sandbox availability via the sandboxProcesses
interest topic so the pill accurately reflects unreachable sandboxes.

Includes mock tasks demonstrating error, provisioning, and running states,
unit tests for deriveHeaderStatus, and workspace-dashboard integration.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
2026-03-14 12:14:06 -07:00

105 lines
3.8 KiB
TypeScript

import { afterEach, describe, expect, it } from "vitest";
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { tmpdir } from "node:os";
import { ConfigSchema, type AppConfig } from "@sandbox-agent/foundry-shared";
import { resolveTuiTheme } from "../src/theme.js";
function withEnv(key: string, value: string | undefined): void {
if (value === undefined) {
delete process.env[key];
return;
}
process.env[key] = value;
}
describe("resolveTuiTheme", () => {
let tempDir: string | null = null;
const originalState = process.env.XDG_STATE_HOME;
const originalConfig = process.env.XDG_CONFIG_HOME;
const baseConfig: AppConfig = ConfigSchema.parse({
auto_submit: true,
notify: ["terminal"],
workspace: { default: "default" },
backend: {
host: "127.0.0.1",
port: 7741,
dbPath: "~/.local/share/foundry/task.db",
opencode_poll_interval: 2,
github_poll_interval: 30,
backup_interval_secs: 3600,
backup_retention_days: 7,
},
providers: {
local: {},
e2b: {},
},
});
afterEach(() => {
withEnv("XDG_STATE_HOME", originalState);
withEnv("XDG_CONFIG_HOME", originalConfig);
if (tempDir) {
rmSync(tempDir, { recursive: true, force: true });
tempDir = null;
}
});
it("falls back to default theme when no theme sources are present", () => {
tempDir = mkdtempSync(join(tmpdir(), "hf-theme-test-"));
withEnv("XDG_STATE_HOME", join(tempDir, "state"));
withEnv("XDG_CONFIG_HOME", join(tempDir, "config"));
const resolution = resolveTuiTheme(baseConfig, tempDir);
expect(resolution.name).toBe("opencode-default");
expect(resolution.source).toBe("default");
expect(resolution.theme.text).toBe("#ffffff");
});
it("loads theme from opencode state when configured", () => {
tempDir = mkdtempSync(join(tmpdir(), "hf-theme-test-"));
const stateHome = join(tempDir, "state");
const configHome = join(tempDir, "config");
withEnv("XDG_STATE_HOME", stateHome);
withEnv("XDG_CONFIG_HOME", configHome);
mkdirSync(join(stateHome, "opencode"), { recursive: true });
writeFileSync(join(stateHome, "opencode", "kv.json"), JSON.stringify({ theme: "gruvbox", theme_mode: "dark" }), "utf8");
const resolution = resolveTuiTheme(baseConfig, tempDir);
expect(resolution.name).toBe("gruvbox");
expect(resolution.source).toContain("opencode state");
expect(resolution.mode).toBe("dark");
expect(resolution.theme.selectionBorder.toLowerCase()).not.toContain("dark");
});
it("resolves OpenCode token references in theme defs", () => {
tempDir = mkdtempSync(join(tmpdir(), "hf-theme-test-"));
const stateHome = join(tempDir, "state");
const configHome = join(tempDir, "config");
withEnv("XDG_STATE_HOME", stateHome);
withEnv("XDG_CONFIG_HOME", configHome);
mkdirSync(join(stateHome, "opencode"), { recursive: true });
writeFileSync(join(stateHome, "opencode", "kv.json"), JSON.stringify({ theme: "orng", theme_mode: "dark" }), "utf8");
const resolution = resolveTuiTheme(baseConfig, tempDir);
expect(resolution.name).toBe("orng");
expect(resolution.theme.selectionBorder).toBe("#EE7948");
expect(resolution.theme.background).toBe("#0a0a0a");
});
it("prefers explicit foundry theme override from config", () => {
tempDir = mkdtempSync(join(tmpdir(), "hf-theme-test-"));
withEnv("XDG_STATE_HOME", join(tempDir, "state"));
withEnv("XDG_CONFIG_HOME", join(tempDir, "config"));
const config = { ...baseConfig, theme: "default" } as AppConfig & { theme: string };
const resolution = resolveTuiTheme(config, tempDir);
expect(resolution.name).toBe("opencode-default");
expect(resolution.source).toBe("foundry config");
});
});