Add test suite (63 tests) and CI workflow, fix Settings API bugs
Some checks failed
Release / Bump version and tag (push) Successful in 4s
Sidecar Release / Bump sidecar version and tag (push) Failing after 3s
Tests / Python Backend Tests (push) Failing after 3s
Tests / Frontend Tests (push) Successful in 8s
Tests / Rust Sidecar Tests (push) Successful in 3m10s
Some checks failed
Release / Bump version and tag (push) Successful in 4s
Sidecar Release / Bump sidecar version and tag (push) Failing after 3s
Tests / Python Backend Tests (push) Failing after 3s
Tests / Frontend Tests (push) Successful in 8s
Tests / Rust Sidecar Tests (push) Successful in 3m10s
Test suite covering all three layers: Python backend (25 tests): - AppController: state machine, start/stop, callbacks, settings reload - API server: REST endpoints, config CRUD, status, devices - Config: dot-notation get/set, persistence, nested paths - Main headless: ready event port format validation Svelte frontend (14 tests via Vitest): - Backend store: exported properties/methods, port derivation, URLs - Config store: method names (fetchConfig not loadConfig), defaults - Transcriptions store: add/clear/plaintext - File extension regression: ensures $state runes only in .svelte.ts Rust sidecar (24 tests via cargo test): - Platform/arch detection, asset name construction - Ready event deserialization (with extra fields tolerance) - Path construction, version read/write, old version cleanup - Zip extraction, SidecarManager lifecycle CI workflow (.gitea/workflows/test.yml): - Runs on push to main and PRs - Three parallel jobs: Python, Frontend, Rust Also fixes three bugs found during test planning: - Settings: /api/check-updates -> GET /api/check-update - Settings: /api/remote/login -> /api/login - Settings: /api/remote/register -> /api/register Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -214,7 +214,7 @@
|
||||
|
||||
async function handleCheckUpdates() {
|
||||
try {
|
||||
await backendStore.apiPost("/api/check-updates");
|
||||
await backendStore.apiGet("/api/check-update");
|
||||
} catch (err) {
|
||||
console.error("Failed to check for updates:", err);
|
||||
}
|
||||
@@ -222,7 +222,7 @@
|
||||
|
||||
async function handleManagedLogin() {
|
||||
try {
|
||||
await backendStore.apiPost("/api/remote/login", {
|
||||
await backendStore.apiPost("/api/login", {
|
||||
email: managedEmail,
|
||||
password: managedPassword,
|
||||
});
|
||||
@@ -233,7 +233,7 @@
|
||||
|
||||
async function handleManagedRegister() {
|
||||
try {
|
||||
await backendStore.apiPost("/api/remote/register", {
|
||||
await backendStore.apiPost("/api/register", {
|
||||
email: managedEmail,
|
||||
password: managedPassword,
|
||||
});
|
||||
|
||||
77
src/lib/stores/backend.test.ts
Normal file
77
src/lib/stores/backend.test.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { backendStore } from "./backend.svelte.ts";
|
||||
|
||||
// Mock WebSocket globally so the store module can reference it
|
||||
class MockWebSocket {
|
||||
onopen: ((ev: Event) => void) | null = null;
|
||||
onclose: ((ev: CloseEvent) => void) | null = null;
|
||||
onmessage: ((ev: MessageEvent) => void) | null = null;
|
||||
onerror: ((ev: Event) => void) | null = null;
|
||||
close = vi.fn();
|
||||
}
|
||||
vi.stubGlobal("WebSocket", MockWebSocket);
|
||||
|
||||
// Mock fetch to prevent real network calls
|
||||
vi.stubGlobal(
|
||||
"fetch",
|
||||
vi.fn(() =>
|
||||
Promise.resolve({
|
||||
ok: true,
|
||||
json: () => Promise.resolve({}),
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
describe("backend store", () => {
|
||||
beforeEach(() => {
|
||||
backendStore.disconnect();
|
||||
backendStore.setPort(8081);
|
||||
});
|
||||
|
||||
it("test_exports_expected_properties", () => {
|
||||
expect(backendStore).toHaveProperty("port");
|
||||
expect(backendStore).toHaveProperty("connectionState");
|
||||
expect(backendStore).toHaveProperty("connected");
|
||||
expect(backendStore).toHaveProperty("appState");
|
||||
expect(backendStore).toHaveProperty("stateMessage");
|
||||
expect(backendStore).toHaveProperty("deviceInfo");
|
||||
expect(backendStore).toHaveProperty("version");
|
||||
expect(backendStore).toHaveProperty("lastError");
|
||||
expect(backendStore).toHaveProperty("apiBaseUrl");
|
||||
expect(backendStore).toHaveProperty("wsUrl");
|
||||
expect(backendStore).toHaveProperty("obsUrl");
|
||||
expect(backendStore).toHaveProperty("syncUrl");
|
||||
});
|
||||
|
||||
it("test_exports_expected_methods", () => {
|
||||
expect(typeof backendStore.setPort).toBe("function");
|
||||
expect(typeof backendStore.connect).toBe("function");
|
||||
expect(typeof backendStore.disconnect).toBe("function");
|
||||
expect(typeof backendStore.apiUrl).toBe("function");
|
||||
expect(typeof backendStore.apiFetch).toBe("function");
|
||||
expect(typeof backendStore.apiGet).toBe("function");
|
||||
expect(typeof backendStore.apiPost).toBe("function");
|
||||
expect(typeof backendStore.apiPut).toBe("function");
|
||||
});
|
||||
|
||||
it("test_obsUrl_derives_from_port", () => {
|
||||
backendStore.setPort(8081);
|
||||
expect(backendStore.obsUrl).toBe("http://localhost:8080");
|
||||
});
|
||||
|
||||
it("test_apiBaseUrl_uses_port", () => {
|
||||
backendStore.setPort(8081);
|
||||
expect(backendStore.apiBaseUrl).toBe("http://localhost:8081");
|
||||
});
|
||||
|
||||
it("test_wsUrl_uses_port", () => {
|
||||
backendStore.setPort(8081);
|
||||
expect(backendStore.wsUrl).toBe("ws://localhost:8081/ws/control");
|
||||
});
|
||||
|
||||
it("test_initial_state", () => {
|
||||
// After disconnect() in beforeEach, state should be disconnected
|
||||
expect(backendStore.connectionState).toBe("disconnected");
|
||||
expect(backendStore.appState).toBe("initializing");
|
||||
});
|
||||
});
|
||||
48
src/lib/stores/config.test.ts
Normal file
48
src/lib/stores/config.test.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { describe, it, expect, vi } from "vitest";
|
||||
|
||||
// Mock fetch so the backend store module doesn't make real requests
|
||||
vi.stubGlobal(
|
||||
"fetch",
|
||||
vi.fn(() =>
|
||||
Promise.resolve({
|
||||
ok: true,
|
||||
json: () => Promise.resolve({}),
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
// Mock WebSocket for the backend store dependency
|
||||
class MockWebSocket {
|
||||
onopen: ((ev: Event) => void) | null = null;
|
||||
onclose: ((ev: CloseEvent) => void) | null = null;
|
||||
onmessage: ((ev: MessageEvent) => void) | null = null;
|
||||
onerror: ((ev: Event) => void) | null = null;
|
||||
close = vi.fn();
|
||||
}
|
||||
vi.stubGlobal("WebSocket", MockWebSocket);
|
||||
|
||||
import { configStore } from "./config.svelte.ts";
|
||||
|
||||
describe("config store", () => {
|
||||
it("test_has_fetchConfig_method", () => {
|
||||
expect(typeof configStore.fetchConfig).toBe("function");
|
||||
});
|
||||
|
||||
it("test_has_updateConfig_method", () => {
|
||||
expect(typeof configStore.updateConfig).toBe("function");
|
||||
});
|
||||
|
||||
it("test_config_defaults_have_expected_keys", () => {
|
||||
const cfg = configStore.config;
|
||||
expect(cfg).toHaveProperty("user");
|
||||
expect(cfg).toHaveProperty("audio");
|
||||
expect(cfg).toHaveProperty("transcription");
|
||||
expect(cfg).toHaveProperty("display");
|
||||
expect(cfg).toHaveProperty("remote");
|
||||
expect(cfg).toHaveProperty("updates");
|
||||
});
|
||||
|
||||
it("test_remote_config_has_byok_api_key", () => {
|
||||
expect(configStore.config.remote.byok_api_key).toBeDefined();
|
||||
});
|
||||
});
|
||||
34
src/lib/stores/file-extension.test.ts
Normal file
34
src/lib/stores/file-extension.test.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import * as fs from "node:fs";
|
||||
import * as path from "node:path";
|
||||
|
||||
describe("store file extensions", () => {
|
||||
it("test_store_files_use_svelte_ts_extension", () => {
|
||||
const storesDir = path.resolve(__dirname);
|
||||
const files = fs.readdirSync(storesDir);
|
||||
|
||||
// Find .ts files that are NOT .svelte.ts and NOT test files
|
||||
const plainTsFiles = files.filter(
|
||||
(f) =>
|
||||
f.endsWith(".ts") &&
|
||||
!f.endsWith(".svelte.ts") &&
|
||||
!f.endsWith(".test.ts")
|
||||
);
|
||||
|
||||
for (const file of plainTsFiles) {
|
||||
const content = fs.readFileSync(path.join(storesDir, file), "utf-8");
|
||||
expect(content).not.toMatch(
|
||||
/\$state\s*[<(]/,
|
||||
`${file} uses $state() but does not have .svelte.ts extension`
|
||||
);
|
||||
expect(content).not.toMatch(
|
||||
/\$derived\s*[<(]/,
|
||||
`${file} uses $derived() but does not have .svelte.ts extension`
|
||||
);
|
||||
expect(content).not.toMatch(
|
||||
/\$effect\s*[<(]/,
|
||||
`${file} uses $effect() but does not have .svelte.ts extension`
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
71
src/lib/stores/transcriptions.test.ts
Normal file
71
src/lib/stores/transcriptions.test.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
|
||||
// Mock WebSocket for the backend store dependency (loaded transitively)
|
||||
class MockWebSocket {
|
||||
onopen: ((ev: Event) => void) | null = null;
|
||||
onclose: ((ev: CloseEvent) => void) | null = null;
|
||||
onmessage: ((ev: MessageEvent) => void) | null = null;
|
||||
onerror: ((ev: Event) => void) | null = null;
|
||||
close = vi.fn();
|
||||
}
|
||||
vi.stubGlobal("WebSocket", MockWebSocket);
|
||||
|
||||
vi.stubGlobal(
|
||||
"fetch",
|
||||
vi.fn(() =>
|
||||
Promise.resolve({
|
||||
ok: true,
|
||||
json: () => Promise.resolve({}),
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
import { transcriptionStore } from "./transcriptions.svelte.ts";
|
||||
|
||||
describe("transcriptions store", () => {
|
||||
beforeEach(() => {
|
||||
transcriptionStore.clearAll();
|
||||
});
|
||||
|
||||
it("test_addTranscription", () => {
|
||||
transcriptionStore.addTranscription({
|
||||
text: "Hello world",
|
||||
user_name: "TestUser",
|
||||
timestamp: "12:00:00",
|
||||
});
|
||||
|
||||
expect(transcriptionStore.items.length).toBe(1);
|
||||
expect(transcriptionStore.items[0].text).toBe("Hello world");
|
||||
expect(transcriptionStore.items[0].userName).toBe("TestUser");
|
||||
expect(transcriptionStore.items[0].timestamp).toBe("12:00:00");
|
||||
expect(transcriptionStore.items[0].isPreview).toBe(false);
|
||||
});
|
||||
|
||||
it("test_clearAll", () => {
|
||||
transcriptionStore.addTranscription({ text: "One" });
|
||||
transcriptionStore.addTranscription({ text: "Two" });
|
||||
expect(transcriptionStore.items.length).toBe(2);
|
||||
|
||||
transcriptionStore.clearAll();
|
||||
expect(transcriptionStore.items.length).toBe(0);
|
||||
});
|
||||
|
||||
it("test_getPlainText", () => {
|
||||
transcriptionStore.addTranscription({
|
||||
text: "Hello",
|
||||
user_name: "Alice",
|
||||
timestamp: "10:00",
|
||||
});
|
||||
transcriptionStore.addTranscription({
|
||||
text: "World",
|
||||
user_name: "Bob",
|
||||
timestamp: "10:01",
|
||||
});
|
||||
|
||||
const text = transcriptionStore.getPlainText();
|
||||
expect(text).toContain("[10:00] Alice: Hello");
|
||||
expect(text).toContain("[10:01] Bob: World");
|
||||
// Lines separated by newline
|
||||
expect(text.split("\n").length).toBe(2);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user