tftsr-devops_investigation/tests/unit/setup.ts
Shaun Arman 093495a653
Some checks failed
Test / rust-fmt-check (pull_request) Failing after 0s
Test / rust-clippy (pull_request) Failing after 1s
Test / rust-tests (pull_request) Failing after 0s
Test / frontend-typecheck (pull_request) Failing after 16s
Test / frontend-tests (pull_request) Failing after 18s
PR Review Automation / review (pull_request) Failing after 4m13s
feat: full copy from apollo_nxt-trcaa with complete sanitization
Complete backport of all features from apollo_nxt-trcaa repository:
- Three-tier shell execution safety system (Tier 1: auto, Tier 2: approve, Tier 3: deny)
- Ollama function calling with tool use support
- AI provider tool calling auto-detection
- kubectl binary bundling and management
- kubeconfig upload and context management
- Shell approval modal with real-time UI
- MCP protocol HTTP transport with custom headers
- Enhanced security audit logging
- Comprehensive test coverage (275+ tests)
- Updated CI/CD workflows for Gitea Actions
- Complete documentation (ADRs, wiki, release notes)

Sanitization applied to all files:
- Removed all MSI, Motorola, VNXT, Vesta references
- Replaced internal infrastructure references with TFTSR equivalents
- Updated all URLs and API endpoints
- Sanitized commit history references in documentation

Technical changes:
- New modules: shell/classifier, shell/executor, shell/kubectl, shell/kubeconfig
- Enhanced AI providers: ollama.rs, openai.rs with function calling
- New Tauri commands: shell execution, kubeconfig management, tool calling detection
- Database migrations: shell_execution_audit table
- Frontend: ShellApprovalModal, ShellExecution, KubeconfigManager pages
- CI/CD: kubectl bundling, multi-platform builds, Gitea Actions integration

Version: 1.0.8

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-06-05 14:12:43 -05:00

62 lines
2.1 KiB
TypeScript

import { vi, beforeAll, afterAll } from "vitest";
import "@testing-library/jest-dom/vitest";
// Node 25 ships a native localStorage stub that lacks .clear() unless --localstorage-file is set.
// Replace it with a real in-memory implementation so tests relying on localStorage work correctly.
function makeStorage() {
let store: Record<string, string> = {};
return {
get length() { return Object.keys(store).length; },
key(i: number) { return Object.keys(store)[i] ?? null; },
getItem(k: string) { return store[k] ?? null; },
setItem(k: string, v: string) { store[k] = String(v); },
removeItem(k: string) { delete store[k]; },
clear() { store = {}; },
};
}
Object.defineProperty(globalThis, "localStorage", { value: makeStorage(), writable: true });
Object.defineProperty(globalThis, "sessionStorage", { value: makeStorage(), writable: true });
// Mock Tauri core API
vi.mock("@tauri-apps/api/core", () => ({
invoke: vi.fn(),
}));
// Mock Tauri event API
vi.mock("@tauri-apps/api/event", () => ({
listen: vi.fn(() => Promise.resolve(() => {})),
emit: vi.fn(() => Promise.resolve()),
once: vi.fn(() => Promise.resolve(() => {})),
}));
// Mock Tauri dialog plugin
vi.mock("@tauri-apps/plugin-dialog", () => ({
open: vi.fn(() => Promise.resolve(null)),
save: vi.fn(() => Promise.resolve(null)),
message: vi.fn(() => Promise.resolve()),
ask: vi.fn(() => Promise.resolve(false)),
confirm: vi.fn(() => Promise.resolve(false)),
}));
// Mock Tauri fs plugin
vi.mock("@tauri-apps/plugin-fs", () => ({
readTextFile: vi.fn(() => Promise.resolve("")),
writeTextFile: vi.fn(() => Promise.resolve()),
readFile: vi.fn(() => Promise.resolve(new Uint8Array())),
writeFile: vi.fn(() => Promise.resolve()),
mkdir: vi.fn(() => Promise.resolve()),
exists: vi.fn(() => Promise.resolve(false)),
}));
// Mock console.error to suppress React warnings
const originalError = console.error;
beforeAll(() => {
console.error = (...args: unknown[]) => {
if (typeof args[0] === "string" && args[0].includes("Warning:")) return;
originalError(...args);
};
});
afterAll(() => {
console.error = originalError;
});