tftsr-devops_investigation/tests/unit/pii.test.ts
Shaun Arman 8839075805 feat: initial implementation of TFTSR IT Triage & RCA application
Implements Phases 1-8 of the TFTSR implementation plan.

Rust backend (Tauri 2.x, src-tauri/):
- Multi-provider AI: OpenAI-compatible, Anthropic, Gemini, Mistral, Ollama
- PII detection engine: 11 regex patterns with overlap resolution
- SQLCipher AES-256 encrypted database with 10 versioned migrations
- 28 Tauri IPC commands for triage, analysis, document, and system ops
- Ollama: hardware probe, model recommendations, pull/delete with events
- RCA and blameless post-mortem Markdown document generators
- PDF export via printpdf
- Audit log: SHA-256 hash of every external data send
- Integration stubs for Confluence, ServiceNow, Azure DevOps (v0.2)

Frontend (React 18 + TypeScript + Vite, src/):
- 9 pages: full triage workflow NewIssue→LogUpload→Triage→Resolution→RCA→Postmortem→History+Settings
- 7 components: ChatWindow, TriageProgress, PiiDiffViewer, DocEditor, HardwareReport, ModelSelector, UI primitives
- 3 Zustand stores: session, settings (persisted), history
- Type-safe tauriCommands.ts matching Rust backend types exactly
- 8 IT domain system prompts (Linux, Windows, Network, K8s, DB, Virt, HW, Obs)

DevOps:
- .woodpecker/test.yml: rustfmt, clippy, cargo test, tsc, vitest on every push
- .woodpecker/release.yml: linux/amd64 + linux/arm64 builds, Gogs release upload

Verified:
- cargo check: zero errors
- tsc --noEmit: zero errors
- vitest run: 13/13 unit tests passing

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 22:36:25 -05:00

98 lines
2.8 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from "vitest";
import { invoke } from "@tauri-apps/api/core";
import type { PiiDetectionResult } from "@/lib/tauriCommands";
describe("PII Detection Commands", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("detects IPv4 addresses in log text", async () => {
const mockResult: PiiDetectionResult = {
log_file_id: "log-001",
detections: [
{
id: "span-1",
pii_type: "IPv4",
start: 13,
end: 24,
original: "192.168.1.1",
replacement: "[IPv4]",
},
],
total_pii_found: 1,
};
vi.mocked(invoke).mockResolvedValueOnce(mockResult);
const { detectPiiCmd } = await import("@/lib/tauriCommands");
const result = await detectPiiCmd("log-001");
expect(invoke).toHaveBeenCalledWith("detect_pii", { logFileId: "log-001" });
expect(result.detections).toHaveLength(1);
expect(result.detections[0].pii_type).toBe("IPv4");
expect(result.detections[0].original).toBe("192.168.1.1");
expect(result.detections[0].replacement).toBe("[IPv4]");
});
it("detects email addresses", async () => {
const mockResult: PiiDetectionResult = {
log_file_id: "log-002",
detections: [
{
id: "span-2",
pii_type: "Email",
start: 5,
end: 22,
original: "admin@example.com",
replacement: "[EMAIL]",
},
],
total_pii_found: 1,
};
vi.mocked(invoke).mockResolvedValueOnce(mockResult);
const { detectPiiCmd } = await import("@/lib/tauriCommands");
const result = await detectPiiCmd("log-002");
expect(result.detections[0].pii_type).toBe("Email");
});
it("detects Bearer tokens", async () => {
const mockResult: PiiDetectionResult = {
log_file_id: "log-003",
detections: [
{
id: "span-3",
pii_type: "Bearer",
start: 15,
end: 60,
original: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9",
replacement: "[BEARER_TOKEN]",
},
],
total_pii_found: 1,
};
vi.mocked(invoke).mockResolvedValueOnce(mockResult);
const { detectPiiCmd } = await import("@/lib/tauriCommands");
const result = await detectPiiCmd("log-003");
expect(result.detections[0].pii_type).toBe("Bearer");
});
it("returns empty detections for clean logs", async () => {
const mockResult: PiiDetectionResult = {
log_file_id: "log-004",
detections: [],
total_pii_found: 0,
};
vi.mocked(invoke).mockResolvedValueOnce(mockResult);
const { detectPiiCmd } = await import("@/lib/tauriCommands");
const result = await detectPiiCmd("log-004");
expect(result.detections).toHaveLength(0);
expect(result.total_pii_found).toBe(0);
});
});