style: fix formatting with Prettier

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
SuperComboGamer
2025-12-21 20:31:57 -05:00
parent 584f5a3426
commit 8d578558ff
295 changed files with 9088 additions and 10546 deletions

View File

@@ -1,143 +1,137 @@
import { describe, it, expect } from "vitest";
import { describe, it, expect } from 'vitest';
import {
specToXml,
getStructuredSpecPromptInstruction,
getAppSpecFormatInstruction,
APP_SPEC_XML_FORMAT,
type SpecOutput,
} from "@/lib/app-spec-format.js";
} from '@/lib/app-spec-format.js';
describe("app-spec-format.ts", () => {
describe("specToXml", () => {
it("should convert minimal spec to XML", () => {
describe('app-spec-format.ts', () => {
describe('specToXml', () => {
it('should convert minimal spec to XML', () => {
const spec: SpecOutput = {
project_name: "Test Project",
overview: "A test project",
technology_stack: ["TypeScript", "Node.js"],
core_capabilities: ["Testing", "Development"],
implemented_features: [
{ name: "Feature 1", description: "First feature" },
],
project_name: 'Test Project',
overview: 'A test project',
technology_stack: ['TypeScript', 'Node.js'],
core_capabilities: ['Testing', 'Development'],
implemented_features: [{ name: 'Feature 1', description: 'First feature' }],
};
const xml = specToXml(spec);
expect(xml).toContain('<?xml version="1.0" encoding="UTF-8"?>');
expect(xml).toContain("<project_specification>");
expect(xml).toContain("</project_specification>");
expect(xml).toContain("<project_name>Test Project</project_name>");
expect(xml).toContain("<technology>TypeScript</technology>");
expect(xml).toContain("<capability>Testing</capability>");
expect(xml).toContain('<project_specification>');
expect(xml).toContain('</project_specification>');
expect(xml).toContain('<project_name>Test Project</project_name>');
expect(xml).toContain('<technology>TypeScript</technology>');
expect(xml).toContain('<capability>Testing</capability>');
});
it("should escape XML special characters", () => {
it('should escape XML special characters', () => {
const spec: SpecOutput = {
project_name: "Test & Project",
overview: "Description with <tags>",
technology_stack: ["TypeScript"],
core_capabilities: ["Cap"],
project_name: 'Test & Project',
overview: 'Description with <tags>',
technology_stack: ['TypeScript'],
core_capabilities: ['Cap'],
implemented_features: [],
};
const xml = specToXml(spec);
expect(xml).toContain("Test &amp; Project");
expect(xml).toContain("&lt;tags&gt;");
expect(xml).toContain('Test &amp; Project');
expect(xml).toContain('&lt;tags&gt;');
});
it("should include file_locations when provided", () => {
it('should include file_locations when provided', () => {
const spec: SpecOutput = {
project_name: "Test",
overview: "Test",
technology_stack: ["TS"],
core_capabilities: ["Cap"],
project_name: 'Test',
overview: 'Test',
technology_stack: ['TS'],
core_capabilities: ['Cap'],
implemented_features: [
{
name: "Feature",
description: "Desc",
file_locations: ["src/index.ts"],
name: 'Feature',
description: 'Desc',
file_locations: ['src/index.ts'],
},
],
};
const xml = specToXml(spec);
expect(xml).toContain("<file_locations>");
expect(xml).toContain("<location>src/index.ts</location>");
expect(xml).toContain('<file_locations>');
expect(xml).toContain('<location>src/index.ts</location>');
});
it("should not include file_locations when empty", () => {
it('should not include file_locations when empty', () => {
const spec: SpecOutput = {
project_name: "Test",
overview: "Test",
technology_stack: ["TS"],
core_capabilities: ["Cap"],
implemented_features: [
{ name: "Feature", description: "Desc", file_locations: [] },
],
project_name: 'Test',
overview: 'Test',
technology_stack: ['TS'],
core_capabilities: ['Cap'],
implemented_features: [{ name: 'Feature', description: 'Desc', file_locations: [] }],
};
const xml = specToXml(spec);
expect(xml).not.toContain("<file_locations>");
expect(xml).not.toContain('<file_locations>');
});
it("should include additional_requirements when provided", () => {
it('should include additional_requirements when provided', () => {
const spec: SpecOutput = {
project_name: "Test",
overview: "Test",
technology_stack: ["TS"],
core_capabilities: ["Cap"],
project_name: 'Test',
overview: 'Test',
technology_stack: ['TS'],
core_capabilities: ['Cap'],
implemented_features: [],
additional_requirements: ["Node.js 18+"],
additional_requirements: ['Node.js 18+'],
};
const xml = specToXml(spec);
expect(xml).toContain("<additional_requirements>");
expect(xml).toContain("<requirement>Node.js 18+</requirement>");
expect(xml).toContain('<additional_requirements>');
expect(xml).toContain('<requirement>Node.js 18+</requirement>');
});
it("should include development_guidelines when provided", () => {
it('should include development_guidelines when provided', () => {
const spec: SpecOutput = {
project_name: "Test",
overview: "Test",
technology_stack: ["TS"],
core_capabilities: ["Cap"],
project_name: 'Test',
overview: 'Test',
technology_stack: ['TS'],
core_capabilities: ['Cap'],
implemented_features: [],
development_guidelines: ["Use ESLint"],
development_guidelines: ['Use ESLint'],
};
const xml = specToXml(spec);
expect(xml).toContain("<development_guidelines>");
expect(xml).toContain("<guideline>Use ESLint</guideline>");
expect(xml).toContain('<development_guidelines>');
expect(xml).toContain('<guideline>Use ESLint</guideline>');
});
it("should include implementation_roadmap when provided", () => {
it('should include implementation_roadmap when provided', () => {
const spec: SpecOutput = {
project_name: "Test",
overview: "Test",
technology_stack: ["TS"],
core_capabilities: ["Cap"],
project_name: 'Test',
overview: 'Test',
technology_stack: ['TS'],
core_capabilities: ['Cap'],
implemented_features: [],
implementation_roadmap: [
{ phase: "Phase 1", status: "completed", description: "Setup" },
],
implementation_roadmap: [{ phase: 'Phase 1', status: 'completed', description: 'Setup' }],
};
const xml = specToXml(spec);
expect(xml).toContain("<implementation_roadmap>");
expect(xml).toContain("<status>completed</status>");
expect(xml).toContain('<implementation_roadmap>');
expect(xml).toContain('<status>completed</status>');
});
it("should not include optional sections when empty", () => {
it('should not include optional sections when empty', () => {
const spec: SpecOutput = {
project_name: "Test",
overview: "Test",
technology_stack: ["TS"],
core_capabilities: ["Cap"],
project_name: 'Test',
overview: 'Test',
technology_stack: ['TS'],
core_capabilities: ['Cap'],
implemented_features: [],
additional_requirements: [],
development_guidelines: [],
@@ -146,44 +140,44 @@ describe("app-spec-format.ts", () => {
const xml = specToXml(spec);
expect(xml).not.toContain("<additional_requirements>");
expect(xml).not.toContain("<development_guidelines>");
expect(xml).not.toContain("<implementation_roadmap>");
expect(xml).not.toContain('<additional_requirements>');
expect(xml).not.toContain('<development_guidelines>');
expect(xml).not.toContain('<implementation_roadmap>');
});
});
describe("getStructuredSpecPromptInstruction", () => {
it("should return non-empty prompt instruction", () => {
describe('getStructuredSpecPromptInstruction', () => {
it('should return non-empty prompt instruction', () => {
const instruction = getStructuredSpecPromptInstruction();
expect(instruction).toBeTruthy();
expect(instruction.length).toBeGreaterThan(100);
});
it("should mention required fields", () => {
it('should mention required fields', () => {
const instruction = getStructuredSpecPromptInstruction();
expect(instruction).toContain("project_name");
expect(instruction).toContain("overview");
expect(instruction).toContain("technology_stack");
expect(instruction).toContain('project_name');
expect(instruction).toContain('overview');
expect(instruction).toContain('technology_stack');
});
});
describe("getAppSpecFormatInstruction", () => {
it("should return non-empty format instruction", () => {
describe('getAppSpecFormatInstruction', () => {
it('should return non-empty format instruction', () => {
const instruction = getAppSpecFormatInstruction();
expect(instruction).toBeTruthy();
expect(instruction.length).toBeGreaterThan(100);
});
it("should include critical formatting requirements", () => {
it('should include critical formatting requirements', () => {
const instruction = getAppSpecFormatInstruction();
expect(instruction).toContain("CRITICAL FORMATTING REQUIREMENTS");
expect(instruction).toContain('CRITICAL FORMATTING REQUIREMENTS');
});
});
describe("APP_SPEC_XML_FORMAT", () => {
it("should contain valid XML template structure", () => {
expect(APP_SPEC_XML_FORMAT).toContain("<project_specification>");
expect(APP_SPEC_XML_FORMAT).toContain("</project_specification>");
describe('APP_SPEC_XML_FORMAT', () => {
it('should contain valid XML template structure', () => {
expect(APP_SPEC_XML_FORMAT).toContain('<project_specification>');
expect(APP_SPEC_XML_FORMAT).toContain('</project_specification>');
});
});
});

View File

@@ -1,20 +1,20 @@
import { describe, it, expect, beforeEach, vi } from "vitest";
import { createMockExpressContext } from "../../utils/mocks.js";
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { createMockExpressContext } from '../../utils/mocks.js';
/**
* Note: auth.ts reads AUTOMAKER_API_KEY at module load time.
* We need to reset modules and reimport for each test to get fresh state.
*/
describe("auth.ts", () => {
describe('auth.ts', () => {
beforeEach(() => {
vi.resetModules();
});
describe("authMiddleware - no API key", () => {
it("should call next() when no API key is set", async () => {
describe('authMiddleware - no API key', () => {
it('should call next() when no API key is set', async () => {
delete process.env.AUTOMAKER_API_KEY;
const { authMiddleware } = await import("@/lib/auth.js");
const { authMiddleware } = await import('@/lib/auth.js');
const { req, res, next } = createMockExpressContext();
authMiddleware(req, res, next);
@@ -24,11 +24,11 @@ describe("auth.ts", () => {
});
});
describe("authMiddleware - with API key", () => {
it("should reject request without API key header", async () => {
process.env.AUTOMAKER_API_KEY = "test-secret-key";
describe('authMiddleware - with API key', () => {
it('should reject request without API key header', async () => {
process.env.AUTOMAKER_API_KEY = 'test-secret-key';
const { authMiddleware } = await import("@/lib/auth.js");
const { authMiddleware } = await import('@/lib/auth.js');
const { req, res, next } = createMockExpressContext();
authMiddleware(req, res, next);
@@ -36,34 +36,34 @@ describe("auth.ts", () => {
expect(res.status).toHaveBeenCalledWith(401);
expect(res.json).toHaveBeenCalledWith({
success: false,
error: "Authentication required. Provide X-API-Key header.",
error: 'Authentication required. Provide X-API-Key header.',
});
expect(next).not.toHaveBeenCalled();
});
it("should reject request with invalid API key", async () => {
process.env.AUTOMAKER_API_KEY = "test-secret-key";
it('should reject request with invalid API key', async () => {
process.env.AUTOMAKER_API_KEY = 'test-secret-key';
const { authMiddleware } = await import("@/lib/auth.js");
const { authMiddleware } = await import('@/lib/auth.js');
const { req, res, next } = createMockExpressContext();
req.headers["x-api-key"] = "wrong-key";
req.headers['x-api-key'] = 'wrong-key';
authMiddleware(req, res, next);
expect(res.status).toHaveBeenCalledWith(403);
expect(res.json).toHaveBeenCalledWith({
success: false,
error: "Invalid API key.",
error: 'Invalid API key.',
});
expect(next).not.toHaveBeenCalled();
});
it("should call next() with valid API key", async () => {
process.env.AUTOMAKER_API_KEY = "test-secret-key";
it('should call next() with valid API key', async () => {
process.env.AUTOMAKER_API_KEY = 'test-secret-key';
const { authMiddleware } = await import("@/lib/auth.js");
const { req, res, next} = createMockExpressContext();
req.headers["x-api-key"] = "test-secret-key";
const { authMiddleware } = await import('@/lib/auth.js');
const { req, res, next } = createMockExpressContext();
req.headers['x-api-key'] = 'test-secret-key';
authMiddleware(req, res, next);
@@ -72,44 +72,44 @@ describe("auth.ts", () => {
});
});
describe("isAuthEnabled", () => {
it("should return false when no API key is set", async () => {
describe('isAuthEnabled', () => {
it('should return false when no API key is set', async () => {
delete process.env.AUTOMAKER_API_KEY;
const { isAuthEnabled } = await import("@/lib/auth.js");
const { isAuthEnabled } = await import('@/lib/auth.js');
expect(isAuthEnabled()).toBe(false);
});
it("should return true when API key is set", async () => {
process.env.AUTOMAKER_API_KEY = "test-key";
it('should return true when API key is set', async () => {
process.env.AUTOMAKER_API_KEY = 'test-key';
const { isAuthEnabled } = await import("@/lib/auth.js");
const { isAuthEnabled } = await import('@/lib/auth.js');
expect(isAuthEnabled()).toBe(true);
});
});
describe("getAuthStatus", () => {
it("should return disabled status when no API key", async () => {
describe('getAuthStatus', () => {
it('should return disabled status when no API key', async () => {
delete process.env.AUTOMAKER_API_KEY;
const { getAuthStatus } = await import("@/lib/auth.js");
const { getAuthStatus } = await import('@/lib/auth.js');
const status = getAuthStatus();
expect(status).toEqual({
enabled: false,
method: "none",
method: 'none',
});
});
it("should return enabled status when API key is set", async () => {
process.env.AUTOMAKER_API_KEY = "test-key";
it('should return enabled status when API key is set', async () => {
process.env.AUTOMAKER_API_KEY = 'test-key';
const { getAuthStatus } = await import("@/lib/auth.js");
const { getAuthStatus } = await import('@/lib/auth.js');
const status = getAuthStatus();
expect(status).toEqual({
enabled: true,
method: "api_key",
method: 'api_key',
});
});
});

View File

@@ -1,4 +1,4 @@
import { describe, it, expect } from "vitest";
import { describe, it, expect } from 'vitest';
import {
getEnhancementPrompt,
getSystemPrompt,
@@ -15,38 +15,38 @@ import {
SIMPLIFY_EXAMPLES,
ACCEPTANCE_EXAMPLES,
type EnhancementMode,
} from "@/lib/enhancement-prompts.js";
} from '@/lib/enhancement-prompts.js';
describe("enhancement-prompts.ts", () => {
describe("System Prompt Constants", () => {
it("should have non-empty improve system prompt", () => {
describe('enhancement-prompts.ts', () => {
describe('System Prompt Constants', () => {
it('should have non-empty improve system prompt', () => {
expect(IMPROVE_SYSTEM_PROMPT).toBeDefined();
expect(IMPROVE_SYSTEM_PROMPT.length).toBeGreaterThan(100);
expect(IMPROVE_SYSTEM_PROMPT).toContain("ANALYZE");
expect(IMPROVE_SYSTEM_PROMPT).toContain("CLARIFY");
expect(IMPROVE_SYSTEM_PROMPT).toContain('ANALYZE');
expect(IMPROVE_SYSTEM_PROMPT).toContain('CLARIFY');
});
it("should have non-empty technical system prompt", () => {
it('should have non-empty technical system prompt', () => {
expect(TECHNICAL_SYSTEM_PROMPT).toBeDefined();
expect(TECHNICAL_SYSTEM_PROMPT.length).toBeGreaterThan(100);
expect(TECHNICAL_SYSTEM_PROMPT).toContain("technical");
expect(TECHNICAL_SYSTEM_PROMPT).toContain('technical');
});
it("should have non-empty simplify system prompt", () => {
it('should have non-empty simplify system prompt', () => {
expect(SIMPLIFY_SYSTEM_PROMPT).toBeDefined();
expect(SIMPLIFY_SYSTEM_PROMPT.length).toBeGreaterThan(100);
expect(SIMPLIFY_SYSTEM_PROMPT).toContain("simplify");
expect(SIMPLIFY_SYSTEM_PROMPT).toContain('simplify');
});
it("should have non-empty acceptance system prompt", () => {
it('should have non-empty acceptance system prompt', () => {
expect(ACCEPTANCE_SYSTEM_PROMPT).toBeDefined();
expect(ACCEPTANCE_SYSTEM_PROMPT.length).toBeGreaterThan(100);
expect(ACCEPTANCE_SYSTEM_PROMPT).toContain("acceptance criteria");
expect(ACCEPTANCE_SYSTEM_PROMPT).toContain('acceptance criteria');
});
});
describe("Example Constants", () => {
it("should have improve examples with input and output", () => {
describe('Example Constants', () => {
it('should have improve examples with input and output', () => {
expect(IMPROVE_EXAMPLES).toBeDefined();
expect(IMPROVE_EXAMPLES.length).toBeGreaterThan(0);
IMPROVE_EXAMPLES.forEach((example) => {
@@ -57,7 +57,7 @@ describe("enhancement-prompts.ts", () => {
});
});
it("should have technical examples with input and output", () => {
it('should have technical examples with input and output', () => {
expect(TECHNICAL_EXAMPLES).toBeDefined();
expect(TECHNICAL_EXAMPLES.length).toBeGreaterThan(0);
TECHNICAL_EXAMPLES.forEach((example) => {
@@ -66,7 +66,7 @@ describe("enhancement-prompts.ts", () => {
});
});
it("should have simplify examples with input and output", () => {
it('should have simplify examples with input and output', () => {
expect(SIMPLIFY_EXAMPLES).toBeDefined();
expect(SIMPLIFY_EXAMPLES.length).toBeGreaterThan(0);
SIMPLIFY_EXAMPLES.forEach((example) => {
@@ -75,7 +75,7 @@ describe("enhancement-prompts.ts", () => {
});
});
it("should have acceptance examples with input and output", () => {
it('should have acceptance examples with input and output', () => {
expect(ACCEPTANCE_EXAMPLES).toBeDefined();
expect(ACCEPTANCE_EXAMPLES.length).toBeGreaterThan(0);
ACCEPTANCE_EXAMPLES.forEach((example) => {
@@ -85,66 +85,66 @@ describe("enhancement-prompts.ts", () => {
});
});
describe("getEnhancementPrompt", () => {
it("should return config for improve mode", () => {
const config = getEnhancementPrompt("improve");
describe('getEnhancementPrompt', () => {
it('should return config for improve mode', () => {
const config = getEnhancementPrompt('improve');
expect(config.systemPrompt).toBe(IMPROVE_SYSTEM_PROMPT);
expect(config.description).toContain("clear");
expect(config.description).toContain('clear');
});
it("should return config for technical mode", () => {
const config = getEnhancementPrompt("technical");
it('should return config for technical mode', () => {
const config = getEnhancementPrompt('technical');
expect(config.systemPrompt).toBe(TECHNICAL_SYSTEM_PROMPT);
expect(config.description).toContain("technical");
expect(config.description).toContain('technical');
});
it("should return config for simplify mode", () => {
const config = getEnhancementPrompt("simplify");
it('should return config for simplify mode', () => {
const config = getEnhancementPrompt('simplify');
expect(config.systemPrompt).toBe(SIMPLIFY_SYSTEM_PROMPT);
expect(config.description).toContain("concise");
expect(config.description).toContain('concise');
});
it("should return config for acceptance mode", () => {
const config = getEnhancementPrompt("acceptance");
it('should return config for acceptance mode', () => {
const config = getEnhancementPrompt('acceptance');
expect(config.systemPrompt).toBe(ACCEPTANCE_SYSTEM_PROMPT);
expect(config.description).toContain("acceptance");
expect(config.description).toContain('acceptance');
});
it("should handle case-insensitive mode", () => {
const config = getEnhancementPrompt("IMPROVE");
it('should handle case-insensitive mode', () => {
const config = getEnhancementPrompt('IMPROVE');
expect(config.systemPrompt).toBe(IMPROVE_SYSTEM_PROMPT);
});
it("should fall back to improve for invalid mode", () => {
const config = getEnhancementPrompt("invalid-mode");
it('should fall back to improve for invalid mode', () => {
const config = getEnhancementPrompt('invalid-mode');
expect(config.systemPrompt).toBe(IMPROVE_SYSTEM_PROMPT);
});
it("should fall back to improve for empty string", () => {
const config = getEnhancementPrompt("");
it('should fall back to improve for empty string', () => {
const config = getEnhancementPrompt('');
expect(config.systemPrompt).toBe(IMPROVE_SYSTEM_PROMPT);
});
});
describe("getSystemPrompt", () => {
it("should return correct system prompt for each mode", () => {
expect(getSystemPrompt("improve")).toBe(IMPROVE_SYSTEM_PROMPT);
expect(getSystemPrompt("technical")).toBe(TECHNICAL_SYSTEM_PROMPT);
expect(getSystemPrompt("simplify")).toBe(SIMPLIFY_SYSTEM_PROMPT);
expect(getSystemPrompt("acceptance")).toBe(ACCEPTANCE_SYSTEM_PROMPT);
describe('getSystemPrompt', () => {
it('should return correct system prompt for each mode', () => {
expect(getSystemPrompt('improve')).toBe(IMPROVE_SYSTEM_PROMPT);
expect(getSystemPrompt('technical')).toBe(TECHNICAL_SYSTEM_PROMPT);
expect(getSystemPrompt('simplify')).toBe(SIMPLIFY_SYSTEM_PROMPT);
expect(getSystemPrompt('acceptance')).toBe(ACCEPTANCE_SYSTEM_PROMPT);
});
});
describe("getExamples", () => {
it("should return correct examples for each mode", () => {
expect(getExamples("improve")).toBe(IMPROVE_EXAMPLES);
expect(getExamples("technical")).toBe(TECHNICAL_EXAMPLES);
expect(getExamples("simplify")).toBe(SIMPLIFY_EXAMPLES);
expect(getExamples("acceptance")).toBe(ACCEPTANCE_EXAMPLES);
describe('getExamples', () => {
it('should return correct examples for each mode', () => {
expect(getExamples('improve')).toBe(IMPROVE_EXAMPLES);
expect(getExamples('technical')).toBe(TECHNICAL_EXAMPLES);
expect(getExamples('simplify')).toBe(SIMPLIFY_EXAMPLES);
expect(getExamples('acceptance')).toBe(ACCEPTANCE_EXAMPLES);
});
it("should return arrays with example objects", () => {
const modes: EnhancementMode[] = ["improve", "technical", "simplify", "acceptance"];
it('should return arrays with example objects', () => {
const modes: EnhancementMode[] = ['improve', 'technical', 'simplify', 'acceptance'];
modes.forEach((mode) => {
const examples = getExamples(mode);
expect(Array.isArray(examples)).toBe(true);
@@ -153,38 +153,38 @@ describe("enhancement-prompts.ts", () => {
});
});
describe("buildUserPrompt", () => {
const testText = "Add a logout button";
describe('buildUserPrompt', () => {
const testText = 'Add a logout button';
it("should build prompt with examples by default", () => {
const prompt = buildUserPrompt("improve", testText);
expect(prompt).toContain("Example 1:");
it('should build prompt with examples by default', () => {
const prompt = buildUserPrompt('improve', testText);
expect(prompt).toContain('Example 1:');
expect(prompt).toContain(testText);
expect(prompt).toContain("Now, please enhance the following task description:");
expect(prompt).toContain('Now, please enhance the following task description:');
});
it("should build prompt without examples when includeExamples is false", () => {
const prompt = buildUserPrompt("improve", testText, false);
expect(prompt).not.toContain("Example 1:");
it('should build prompt without examples when includeExamples is false', () => {
const prompt = buildUserPrompt('improve', testText, false);
expect(prompt).not.toContain('Example 1:');
expect(prompt).toContain(testText);
expect(prompt).toContain("Please enhance the following task description:");
expect(prompt).toContain('Please enhance the following task description:');
});
it("should include all examples for improve mode", () => {
const prompt = buildUserPrompt("improve", testText);
it('should include all examples for improve mode', () => {
const prompt = buildUserPrompt('improve', testText);
IMPROVE_EXAMPLES.forEach((example, index) => {
expect(prompt).toContain(`Example ${index + 1}:`);
expect(prompt).toContain(example.input);
});
});
it("should include separator between examples", () => {
const prompt = buildUserPrompt("improve", testText);
expect(prompt).toContain("---");
it('should include separator between examples', () => {
const prompt = buildUserPrompt('improve', testText);
expect(prompt).toContain('---');
});
it("should work with all enhancement modes", () => {
const modes: EnhancementMode[] = ["improve", "technical", "simplify", "acceptance"];
it('should work with all enhancement modes', () => {
const modes: EnhancementMode[] = ['improve', 'technical', 'simplify', 'acceptance'];
modes.forEach((mode) => {
const prompt = buildUserPrompt(mode, testText);
expect(prompt).toContain(testText);
@@ -192,40 +192,40 @@ describe("enhancement-prompts.ts", () => {
});
});
it("should preserve the original text exactly", () => {
const specialText = "Add feature with special chars: <>&\"'";
const prompt = buildUserPrompt("improve", specialText);
it('should preserve the original text exactly', () => {
const specialText = 'Add feature with special chars: <>&"\'';
const prompt = buildUserPrompt('improve', specialText);
expect(prompt).toContain(specialText);
});
});
describe("isValidEnhancementMode", () => {
it("should return true for valid modes", () => {
expect(isValidEnhancementMode("improve")).toBe(true);
expect(isValidEnhancementMode("technical")).toBe(true);
expect(isValidEnhancementMode("simplify")).toBe(true);
expect(isValidEnhancementMode("acceptance")).toBe(true);
describe('isValidEnhancementMode', () => {
it('should return true for valid modes', () => {
expect(isValidEnhancementMode('improve')).toBe(true);
expect(isValidEnhancementMode('technical')).toBe(true);
expect(isValidEnhancementMode('simplify')).toBe(true);
expect(isValidEnhancementMode('acceptance')).toBe(true);
});
it("should return false for invalid modes", () => {
expect(isValidEnhancementMode("invalid")).toBe(false);
expect(isValidEnhancementMode("IMPROVE")).toBe(false); // case-sensitive
expect(isValidEnhancementMode("")).toBe(false);
expect(isValidEnhancementMode("random")).toBe(false);
it('should return false for invalid modes', () => {
expect(isValidEnhancementMode('invalid')).toBe(false);
expect(isValidEnhancementMode('IMPROVE')).toBe(false); // case-sensitive
expect(isValidEnhancementMode('')).toBe(false);
expect(isValidEnhancementMode('random')).toBe(false);
});
});
describe("getAvailableEnhancementModes", () => {
it("should return all four enhancement modes", () => {
describe('getAvailableEnhancementModes', () => {
it('should return all four enhancement modes', () => {
const modes = getAvailableEnhancementModes();
expect(modes).toHaveLength(4);
expect(modes).toContain("improve");
expect(modes).toContain("technical");
expect(modes).toContain("simplify");
expect(modes).toContain("acceptance");
expect(modes).toContain('improve');
expect(modes).toContain('technical');
expect(modes).toContain('simplify');
expect(modes).toContain('acceptance');
});
it("should return an array", () => {
it('should return an array', () => {
const modes = getAvailableEnhancementModes();
expect(Array.isArray(modes)).toBe(true);
});

View File

@@ -1,20 +1,20 @@
import { describe, it, expect, vi } from "vitest";
import { createEventEmitter, type EventType } from "@/lib/events.js";
import { describe, it, expect, vi } from 'vitest';
import { createEventEmitter, type EventType } from '@/lib/events.js';
describe("events.ts", () => {
describe("createEventEmitter", () => {
it("should emit events to single subscriber", () => {
describe('events.ts', () => {
describe('createEventEmitter', () => {
it('should emit events to single subscriber', () => {
const emitter = createEventEmitter();
const callback = vi.fn();
emitter.subscribe(callback);
emitter.emit("agent:stream", { message: "test" });
emitter.emit('agent:stream', { message: 'test' });
expect(callback).toHaveBeenCalledOnce();
expect(callback).toHaveBeenCalledWith("agent:stream", { message: "test" });
expect(callback).toHaveBeenCalledWith('agent:stream', { message: 'test' });
});
it("should emit events to multiple subscribers", () => {
it('should emit events to multiple subscribers', () => {
const emitter = createEventEmitter();
const callback1 = vi.fn();
const callback2 = vi.fn();
@@ -23,42 +23,42 @@ describe("events.ts", () => {
emitter.subscribe(callback1);
emitter.subscribe(callback2);
emitter.subscribe(callback3);
emitter.emit("feature:started", { id: "123" });
emitter.emit('feature:started', { id: '123' });
expect(callback1).toHaveBeenCalledOnce();
expect(callback2).toHaveBeenCalledOnce();
expect(callback3).toHaveBeenCalledOnce();
expect(callback1).toHaveBeenCalledWith("feature:started", { id: "123" });
expect(callback1).toHaveBeenCalledWith('feature:started', { id: '123' });
});
it("should support unsubscribe functionality", () => {
it('should support unsubscribe functionality', () => {
const emitter = createEventEmitter();
const callback = vi.fn();
const unsubscribe = emitter.subscribe(callback);
emitter.emit("agent:stream", { test: 1 });
emitter.emit('agent:stream', { test: 1 });
expect(callback).toHaveBeenCalledOnce();
unsubscribe();
emitter.emit("agent:stream", { test: 2 });
emitter.emit('agent:stream', { test: 2 });
expect(callback).toHaveBeenCalledOnce(); // Still called only once
});
it("should handle errors in subscribers without crashing", () => {
it('should handle errors in subscribers without crashing', () => {
const emitter = createEventEmitter();
const errorCallback = vi.fn(() => {
throw new Error("Subscriber error");
throw new Error('Subscriber error');
});
const normalCallback = vi.fn();
const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => {});
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
emitter.subscribe(errorCallback);
emitter.subscribe(normalCallback);
expect(() => {
emitter.emit("feature:error", { error: "test" });
emitter.emit('feature:error', { error: 'test' });
}).not.toThrow();
expect(errorCallback).toHaveBeenCalledOnce();
@@ -68,17 +68,17 @@ describe("events.ts", () => {
consoleSpy.mockRestore();
});
it("should emit different event types", () => {
it('should emit different event types', () => {
const emitter = createEventEmitter();
const callback = vi.fn();
emitter.subscribe(callback);
const eventTypes: EventType[] = [
"agent:stream",
"auto-mode:started",
"feature:completed",
"project:analysis-progress",
'agent:stream',
'auto-mode:started',
'feature:completed',
'project:analysis-progress',
];
eventTypes.forEach((type) => {
@@ -88,15 +88,15 @@ describe("events.ts", () => {
expect(callback).toHaveBeenCalledTimes(4);
});
it("should handle emitting without subscribers", () => {
it('should handle emitting without subscribers', () => {
const emitter = createEventEmitter();
expect(() => {
emitter.emit("agent:stream", { test: true });
emitter.emit('agent:stream', { test: true });
}).not.toThrow();
});
it("should allow multiple subscriptions and unsubscriptions", () => {
it('should allow multiple subscriptions and unsubscriptions', () => {
const emitter = createEventEmitter();
const callback1 = vi.fn();
const callback2 = vi.fn();
@@ -106,14 +106,14 @@ describe("events.ts", () => {
const unsub2 = emitter.subscribe(callback2);
const unsub3 = emitter.subscribe(callback3);
emitter.emit("feature:started", { test: 1 });
emitter.emit('feature:started', { test: 1 });
expect(callback1).toHaveBeenCalledOnce();
expect(callback2).toHaveBeenCalledOnce();
expect(callback3).toHaveBeenCalledOnce();
unsub2();
emitter.emit("feature:started", { test: 2 });
emitter.emit('feature:started', { test: 2 });
expect(callback1).toHaveBeenCalledTimes(2);
expect(callback2).toHaveBeenCalledOnce(); // Still just once
expect(callback3).toHaveBeenCalledTimes(2);
@@ -121,7 +121,7 @@ describe("events.ts", () => {
unsub1();
unsub3();
emitter.emit("feature:started", { test: 3 });
emitter.emit('feature:started', { test: 3 });
expect(callback1).toHaveBeenCalledTimes(2);
expect(callback2).toHaveBeenCalledOnce();
expect(callback3).toHaveBeenCalledTimes(2);