Enhance unit tests for settings service and error handling

- Add comprehensive unit tests for SettingsService, covering global and project settings management, including creation, updates, and merging with defaults.
- Implement tests for handling credentials, ensuring proper masking and merging of API keys.
- Introduce tests for migration from localStorage, validating successful data transfer and error handling.
- Enhance error handling in subprocess management tests, ensuring robust timeout and output reading scenarios.
This commit is contained in:
Cody Seibert
2025-12-20 09:03:32 -05:00
parent ace736c7c2
commit c76ba691a4
8 changed files with 1019 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ import { describe, it, expect } from "vitest";
import {
isAbortError,
isAuthenticationError,
isCancellationError,
classifyError,
getUserFriendlyErrorMessage,
type ErrorType,
@@ -32,6 +33,34 @@ describe("error-handler.ts", () => {
});
});
describe("isCancellationError", () => {
it("should detect 'cancelled' message", () => {
expect(isCancellationError("Operation was cancelled")).toBe(true);
});
it("should detect 'canceled' message", () => {
expect(isCancellationError("Request was canceled")).toBe(true);
});
it("should detect 'stopped' message", () => {
expect(isCancellationError("Process was stopped")).toBe(true);
});
it("should detect 'aborted' message", () => {
expect(isCancellationError("Task was aborted")).toBe(true);
});
it("should be case insensitive", () => {
expect(isCancellationError("CANCELLED")).toBe(true);
expect(isCancellationError("Canceled")).toBe(true);
});
it("should return false for non-cancellation errors", () => {
expect(isCancellationError("File not found")).toBe(false);
expect(isCancellationError("Network error")).toBe(false);
});
});
describe("isAuthenticationError", () => {
it("should detect 'Authentication failed' message", () => {
expect(isAuthenticationError("Authentication failed")).toBe(true);
@@ -91,6 +120,42 @@ describe("error-handler.ts", () => {
expect(result.isAbort).toBe(true); // Still detected as abort too
});
it("should classify cancellation errors", () => {
const error = new Error("Operation was cancelled");
const result = classifyError(error);
expect(result.type).toBe("cancellation");
expect(result.isCancellation).toBe(true);
expect(result.isAbort).toBe(false);
expect(result.isAuth).toBe(false);
});
it("should prioritize abort over cancellation if both match", () => {
const error = new Error("Operation aborted");
error.name = "AbortError";
const result = classifyError(error);
expect(result.type).toBe("abort");
expect(result.isAbort).toBe(true);
expect(result.isCancellation).toBe(true); // Still detected as cancellation too
});
it("should classify cancellation errors with 'canceled' spelling", () => {
const error = new Error("Request was canceled");
const result = classifyError(error);
expect(result.type).toBe("cancellation");
expect(result.isCancellation).toBe(true);
});
it("should classify cancellation errors with 'stopped' message", () => {
const error = new Error("Process was stopped");
const result = classifyError(error);
expect(result.type).toBe("cancellation");
expect(result.isCancellation).toBe(true);
});
it("should classify generic Error as execution error", () => {
const error = new Error("Something went wrong");
const result = classifyError(error);