|
| 1 | +/** Test E2E batch 14 — SecretRef config, jht setup/doctor/reset CLI, Badge, FloatingChat */ |
| 2 | +import { describe, it, expect } from "vitest"; |
| 3 | +import fs from "node:fs"; |
| 4 | +import path from "node:path"; |
| 5 | + |
| 6 | +const WEB = path.resolve(__dirname, "../../../web"); |
| 7 | +const CLI = path.resolve(__dirname, "../../../cli"); |
| 8 | +function readSrc(rel: string) { return fs.readFileSync(path.join(WEB, rel), "utf-8"); } |
| 9 | +function readCli(rel: string) { return fs.readFileSync(path.join(CLI, rel), "utf-8"); } |
| 10 | + |
| 11 | +/* ── SecretRef (shared/config) — test funzionali ── */ |
| 12 | +describe("SecretRef", () => { |
| 13 | + it("resolveSecret: plaintext + string legacy + env ref + undefined", async () => { |
| 14 | + const { resolveSecret } = await import("../../../shared/config/secret-ref"); |
| 15 | + expect(resolveSecret({ type: "plaintext", value: "sk-test" })).toBe("sk-test"); |
| 16 | + expect(resolveSecret("legacy-key")).toBe("legacy-key"); |
| 17 | + expect(resolveSecret(undefined)).toBe(""); |
| 18 | + process.env.__JHT_TEST_KEY = "from-env"; |
| 19 | + expect(resolveSecret({ type: "ref", source: "env", id: "__JHT_TEST_KEY" })).toBe("from-env"); |
| 20 | + delete process.env.__JHT_TEST_KEY; |
| 21 | + }); |
| 22 | + it("createSecretRef: 4 modi — plaintext/env/file/exec", async () => { |
| 23 | + const { createSecretRef } = await import("../../../shared/config/secret-ref"); |
| 24 | + expect(createSecretRef("plaintext", "sk")).toEqual({ type: "plaintext", value: "sk" }); |
| 25 | + expect(createSecretRef("env", "KEY")).toEqual({ type: "ref", source: "env", id: "KEY" }); |
| 26 | + expect(createSecretRef("file", "/tmp/k")).toEqual({ type: "ref", source: "file", path: "/tmp/k" }); |
| 27 | + expect(createSecretRef("exec", "op read")).toEqual({ type: "ref", source: "exec", command: "op read" }); |
| 28 | + }); |
| 29 | + it("describeSecret: non espone valori completi, mostra ref", async () => { |
| 30 | + const { describeSecret } = await import("../../../shared/config/secret-ref"); |
| 31 | + expect(describeSecret(undefined)).toBe("non configurato"); |
| 32 | + expect(describeSecret("sk-12345678rest")).toContain("****"); |
| 33 | + expect(describeSecret({ type: "ref", source: "env", id: "MY_KEY" })).toBe("env:MY_KEY"); |
| 34 | + expect(describeSecret({ type: "ref", source: "file", path: "/tmp/k" })).toBe("file:/tmp/k"); |
| 35 | + expect(describeSecret({ type: "ref", source: "exec", command: "op read secret" })).toContain("exec:"); |
| 36 | + }); |
| 37 | +}); |
| 38 | + |
| 39 | +/* ── jht setup CLI ── */ |
| 40 | +describe("jht setup CLI", () => { |
| 41 | + const src = readCli("src/commands/setup.js"); |
| 42 | + it("registerSetupCommand + options: provider, auth-method, api-key, secret-mode, model, workspace", () => { |
| 43 | + expect(src).toContain("export function registerSetupCommand"); |
| 44 | + expect(src).toContain("'setup'"); |
| 45 | + for (const o of ["--non-interactive", "--provider", "--auth-method", "--api-key", "--secret-mode", "--model", "--workspace", "--skip-health", "--reset"]) |
| 46 | + expect(src).toContain(o); |
| 47 | + }); |
| 48 | + it("printBanner + runSetupWizard + runNonInteractiveSetup + WizardCancelledError", () => { |
| 49 | + expect(src).toContain("function printBanner"); expect(src).toContain("runSetupWizard"); |
| 50 | + expect(src).toContain("runNonInteractiveSetup"); expect(src).toContain("WizardCancelledError"); |
| 51 | + }); |
| 52 | +}); |
| 53 | + |
| 54 | +/* ── jht doctor CLI ── */ |
| 55 | +describe("jht doctor CLI", () => { |
| 56 | + const src = readCli("src/commands/doctor.js"); |
| 57 | + it("registerDoctorCommand + 7 check functions", () => { |
| 58 | + expect(src).toContain("export function registerDoctorCommand"); |
| 59 | + expect(src).toContain("'doctor'"); |
| 60 | + for (const fn of ["checkNode", "checkConfig", "checkProvider", "checkApiKey", "checkDatabase", "checkDeps", "checkWorkers"]) |
| 61 | + expect(src).toContain(`function ${fn}`); |
| 62 | + }); |
| 63 | + it("5 sezioni diagnostica: Ambiente, Config, Provider LLM, Database, Workers", () => { |
| 64 | + for (const sec of ["Ambiente", "Config", "Provider LLM", "Database", "Workers"]) |
| 65 | + expect(src).toContain(sec); |
| 66 | + expect(src).toContain("printCheck"); expect(src).toContain("spinner"); |
| 67 | + }); |
| 68 | + it("deps required node/npm/tmux/git + optional claude/pandoc/typst/python3", () => { |
| 69 | + for (const d of ["node", "npm", "tmux", "git"]) expect(src).toContain(`'${d}'`); |
| 70 | + for (const d of ["claude", "pandoc", "typst", "python3"]) expect(src).toContain(`'${d}'`); |
| 71 | + }); |
| 72 | +}); |
| 73 | + |
| 74 | +/* ── jht reset CLI ── */ |
| 75 | +describe("jht reset CLI", () => { |
| 76 | + const src = readCli("src/commands/reset.js"); |
| 77 | + it("registerResetCommand + SCOPES 3: config/creds/full + options", () => { |
| 78 | + expect(src).toContain("export function registerResetCommand"); |
| 79 | + expect(src).toContain("'reset'"); expect(src).toContain("SCOPES"); |
| 80 | + for (const s of ["config", "creds", "full"]) expect(src).toContain(`${s}:`); |
| 81 | + expect(src).toContain("--scope"); expect(src).toContain("--non-interactive"); expect(src).toContain("--confirm-reset"); |
| 82 | + }); |
| 83 | + it("buildDeleteList + executeReset + pathExists + countFiles + confirm", () => { |
| 84 | + expect(src).toContain("function buildDeleteList"); expect(src).toContain("function executeReset"); |
| 85 | + expect(src).toContain("function pathExists"); expect(src).toContain("function countFiles"); |
| 86 | + expect(src).toContain("Confermi eliminazione"); |
| 87 | + }); |
| 88 | +}); |
| 89 | + |
| 90 | +/* ── Badge component ── */ |
| 91 | +describe("Badge", () => { |
| 92 | + const src = readSrc("app/components/Badge.tsx"); |
| 93 | + it("export Badge + BadgeGroup + StatusBadge + CountBadge + BadgeVariant 6 + BadgeSize 3", () => { |
| 94 | + expect(src).toMatch(/export function Badge\b/); expect(src).toMatch(/export function BadgeGroup\b/); |
| 95 | + expect(src).toMatch(/export function StatusBadge\b/); expect(src).toMatch(/export function CountBadge\b/); |
| 96 | + expect(src).toContain("export type BadgeVariant"); expect(src).toContain("export type BadgeSize"); |
| 97 | + for (const v of ["default", "success", "warning", "error", "info", "outline"]) expect(src).toContain(`${v}:`); |
| 98 | + }); |
| 99 | + it("VARIANT + DOT_COLOR + SIZE_CLS sm/md/lg + removable aria-label", () => { |
| 100 | + expect(src).toContain("VARIANT"); expect(src).toContain("DOT_COLOR"); expect(src).toContain("SIZE_CLS"); |
| 101 | + expect(src).toContain("removable"); expect(src).toContain('aria-label="Rimuovi"'); |
| 102 | + }); |
| 103 | + it("STATUS_MAP mappa stati → varianti + BadgeGroupProps gap/wrap", () => { |
| 104 | + expect(src).toContain("STATUS_MAP"); |
| 105 | + for (const s of ["attivo", "completato", "errore", "pending", "merged"]) |
| 106 | + expect(src).toContain(`${s}:`); |
| 107 | + expect(src).toContain("export interface BadgeGroupProps"); expect(src).toContain("wrap"); |
| 108 | + }); |
| 109 | +}); |
| 110 | + |
| 111 | +/* ── FloatingChat ── */ |
| 112 | +describe("FloatingChat", () => { |
| 113 | + const src = readSrc("app/components/FloatingChat.tsx"); |
| 114 | + it("export default FloatingChat + Message/Suggestion types + chat-slide-up", () => { |
| 115 | + expect(src).toMatch(/export default function FloatingChat/); |
| 116 | + expect(src).toContain("type Message"); expect(src).toContain("type Suggestion"); |
| 117 | + expect(src).toContain("chat-slide-up"); |
| 118 | + }); |
| 119 | + it("fetchHistory + send + suggestions + 'Sto pensando' + Enter + aria-label", () => { |
| 120 | + expect(src).toContain("fetchHistory"); expect(src).toContain("const send"); |
| 121 | + expect(src).toContain("suggestions"); expect(src).toContain("Sto pensando"); |
| 122 | + expect(src).toContain("'Enter'"); expect(src).toContain("Apri AI Assistant"); |
| 123 | + }); |
| 124 | +}); |
| 125 | + |
| 126 | +/* ── SecretRef JS wizard (cli) ── */ |
| 127 | +describe("SecretRef wizard (JS)", () => { |
| 128 | + const src = readCli("wizard/secret-ref.js"); |
| 129 | + it("export resolveSecret + formatSecretForConfig + describeSecret", () => { |
| 130 | + expect(src).toContain("export function resolveSecret"); |
| 131 | + expect(src).toContain("export function formatSecretForConfig"); |
| 132 | + expect(src).toContain("export function describeSecret"); |
| 133 | + }); |
| 134 | + it("supporta env/file/exec/plaintext + non espone valori ('****')", () => { |
| 135 | + expect(src).toContain("'env'"); expect(src).toContain("'file'"); expect(src).toContain("'exec'"); |
| 136 | + expect(src).toContain("'plaintext'"); expect(src).toContain("****"); |
| 137 | + }); |
| 138 | +}); |
0 commit comments