Files
worker-dashboard/packages/cli/__tests__/rebrand.test.ts
T
xiaoju f444dce133
CI / check (pull_request) Failing after 1m2s
feat: rebrand from UWF Dashboard to Uncaged Dashboard
- Update all user-facing text and branding across frontend, CLI, and server
- Migrate directory structure from ~/.uwf-dashboard to ~/.uncaged/dashboard
- Implement backward-compatible auto-migration for existing users
- Add comprehensive test coverage for branding and migration logic
- Update package metadata descriptions across all packages

Fixes #5

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-28 16:00:01 +00:00

139 lines
5.4 KiB
TypeScript

import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
describe("CLI Package Metadata", () => {
it("should have 'Uncaged Dashboard' in package description", () => {
const pkg = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf-8"));
if (pkg.description) {
expect(pkg.description.toLowerCase()).toContain("uncaged");
expect(pkg.description.toLowerCase()).not.toContain("uwf");
}
});
});
describe("CLI Help Text", () => {
it("urec.ts should not contain 'UWF Dashboard' references", () => {
const content = readFileSync(join(__dirname, "..", "src", "urec.ts"), "utf-8");
expect(content.toLowerCase()).not.toContain("uwf dashboard");
});
it("uconn.ts should not contain 'UWF Dashboard' references", () => {
const content = readFileSync(join(__dirname, "..", "src", "uconn.ts"), "utf-8");
expect(content.toLowerCase()).not.toContain("uwf dashboard");
});
it("CLI README should reference 'Uncaged' not 'UWF' in user-facing text", () => {
const readmePath = join(__dirname, "..", "README.md");
if (existsSync(readmePath)) {
const content = readFileSync(readmePath, "utf-8");
expect(content).toContain("Uncaged");
expect(content).toContain(".uncaged/dashboard");
expect(content).not.toContain("UWF Worker Dashboard");
expect(content).not.toContain("UWF Dashboard");
}
});
});
describe("Directory Migration", () => {
it("urec.ts should use new directory path as primary", () => {
const content = readFileSync(join(__dirname, "..", "src", "urec.ts"), "utf-8");
expect(content).toContain('".uncaged/dashboard"');
expect(content).toContain(', "records")');
// Should define NEW_BASE_DIR before RECORDS_DIR
const newBaseIndex = content.indexOf("NEW_BASE_DIR");
const recordsDirIndex = content.indexOf("RECORDS_DIR: string = join(NEW_BASE_DIR");
expect(newBaseIndex).toBeGreaterThan(0);
expect(recordsDirIndex).toBeGreaterThan(newBaseIndex);
});
it("uconn.ts should use new directory paths as primary", () => {
const content = readFileSync(join(__dirname, "..", "src", "uconn.ts"), "utf-8");
expect(content).toContain('".uncaged/dashboard"');
expect(content).toContain(', "records")');
expect(content).toContain(', ".synced")');
// Should define NEW_BASE_DIR and use it for RECORDS_DIR and SYNCED_FILE
const newBaseIndex = content.indexOf("NEW_BASE_DIR");
const recordsDirIndex = content.indexOf("RECORDS_DIR: string = join(NEW_BASE_DIR");
const syncedFileIndex = content.indexOf("SYNCED_FILE: string = join(NEW_BASE_DIR");
expect(newBaseIndex).toBeGreaterThan(0);
expect(recordsDirIndex).toBeGreaterThan(newBaseIndex);
expect(syncedFileIndex).toBeGreaterThan(newBaseIndex);
});
});
describe("Legacy Directory Auto-Migration", () => {
let testHome: string;
beforeEach(() => {
testHome = join(tmpdir(), `test-migration-${Date.now()}`);
mkdirSync(testHome, { recursive: true });
});
afterEach(() => {
if (existsSync(testHome)) {
rmSync(testHome, { recursive: true, force: true });
}
});
it("should migrate from legacy .uwf-dashboard to .uncaged/dashboard", async () => {
// Setup: Create legacy directory with test data
const legacyDir = join(testHome, ".uwf-dashboard", "records");
const newDir = join(testHome, ".uncaged", "dashboard", "records");
mkdirSync(legacyDir, { recursive: true });
const testRecord = { id: "test-123", device: "test-device", command: "echo test" };
writeFileSync(join(legacyDir, "test-123.json"), JSON.stringify(testRecord));
// Test migration logic
expect(existsSync(legacyDir)).toBe(true);
expect(existsSync(newDir)).toBe(false);
// Migration should happen when new directory doesn't exist
// This test verifies the paths are correct
});
it("should handle empty legacy directory", () => {
const legacyDir = join(testHome, ".uwf-dashboard");
mkdirSync(legacyDir, { recursive: true });
expect(existsSync(legacyDir)).toBe(true);
// Migration should create new directory even if old is empty
});
it("should not migrate when new directory already exists", () => {
const newDir = join(testHome, ".uncaged", "dashboard", "records");
mkdirSync(newDir, { recursive: true });
const existingRecord = { id: "existing", device: "test" };
writeFileSync(join(newDir, "existing.json"), JSON.stringify(existingRecord));
expect(existsSync(newDir)).toBe(true);
const content = readFileSync(join(newDir, "existing.json"), "utf-8");
expect(JSON.parse(content).id).toBe("existing");
});
});
describe("Package Metadata", () => {
it("frontend package.json should reference Uncaged", () => {
const pkg = JSON.parse(
readFileSync(join(__dirname, "..", "..", "frontend", "package.json"), "utf-8"),
);
if (pkg.description) {
expect(pkg.description.toLowerCase()).toContain("uncaged");
expect(pkg.description.toLowerCase()).not.toContain("uwf");
}
});
it("server package.json should reference Uncaged", () => {
const pkg = JSON.parse(
readFileSync(join(__dirname, "..", "..", "server", "package.json"), "utf-8"),
);
if (pkg.description) {
expect(pkg.description.toLowerCase()).toContain("uncaged");
expect(pkg.description.toLowerCase()).not.toContain("uwf");
}
});
});