@oalacea/daemon 0.7.2 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/prompts/DEPS_EFFICIENCY.md +558 -0
  2. package/dist/prompts/E2E.md +491 -0
  3. package/dist/prompts/EXECUTE.md +1060 -0
  4. package/dist/prompts/INTEGRATION_API.md +484 -0
  5. package/dist/prompts/INTEGRATION_DB.md +425 -0
  6. package/dist/prompts/PERF_API.md +433 -0
  7. package/dist/prompts/PERF_DB.md +430 -0
  8. package/dist/prompts/PERF_FRONT.md +357 -0
  9. package/dist/prompts/REMEDIATION.md +482 -0
  10. package/dist/prompts/UNIT.md +260 -0
  11. package/dist/templates/README.md +221 -0
  12. package/dist/templates/k6/load-test.js +54 -0
  13. package/dist/templates/nestjs/controller.spec.ts +203 -0
  14. package/dist/templates/nestjs/e2e/api.e2e-spec.ts +451 -0
  15. package/dist/templates/nestjs/e2e/auth.e2e-spec.ts +533 -0
  16. package/dist/templates/nestjs/fixtures/test-module.ts +311 -0
  17. package/dist/templates/nestjs/guard.spec.ts +314 -0
  18. package/dist/templates/nestjs/interceptor.spec.ts +458 -0
  19. package/dist/templates/nestjs/module.spec.ts +173 -0
  20. package/dist/templates/nestjs/pipe.spec.ts +474 -0
  21. package/dist/templates/nestjs/service.spec.ts +296 -0
  22. package/dist/templates/playwright/e2e.spec.ts +61 -0
  23. package/dist/templates/rust/Cargo.toml +72 -0
  24. package/dist/templates/rust/actix-controller.test.rs +114 -0
  25. package/dist/templates/rust/axum-handler.test.rs +117 -0
  26. package/dist/templates/rust/integration.test.rs +63 -0
  27. package/dist/templates/rust/rocket-route.test.rs +106 -0
  28. package/dist/templates/rust/unit.test.rs +38 -0
  29. package/dist/templates/vitest/angular-component.test.ts +38 -0
  30. package/dist/templates/vitest/api.test.ts +51 -0
  31. package/dist/templates/vitest/component.test.ts +27 -0
  32. package/dist/templates/vitest/hook.test.ts +36 -0
  33. package/dist/templates/vitest/solid-component.test.ts +34 -0
  34. package/dist/templates/vitest/svelte-component.test.ts +33 -0
  35. package/dist/templates/vitest/vue-component.test.ts +39 -0
  36. package/package.json +2 -2
@@ -0,0 +1,260 @@
1
+ # Unit Test Generation Guide
2
+
3
+ This prompt is included by EXECUTE.md. It provides detailed guidance for generating unit tests.
4
+
5
+ ---
6
+
7
+ ## Component Test Patterns
8
+
9
+ ### Presentational Components
10
+
11
+ ```typescript
12
+ // Button component test
13
+ describe('Button', () => {
14
+ it('should render with default props', () => {
15
+ render(<Button>Click me</Button>);
16
+ expect(screen.getByRole('button')).toHaveTextContent('Click me');
17
+ });
18
+
19
+ it('should apply variant classes', () => {
20
+ render(<Button variant="danger">Delete</Button>);
21
+ expect(screen.getByRole('button')).toHaveClass('btn-danger');
22
+ });
23
+
24
+ it('should be disabled when loading', () => {
25
+ render(<Button loading>Submit</Button>);
26
+ expect(screen.getByRole('button')).toBeDisabled();
27
+ expect(screen.getByTestId('spinner')).toBeInTheDocument();
28
+ });
29
+ });
30
+ ```
31
+
32
+ ### Container Components
33
+
34
+ ```typescript
35
+ // UserList component test
36
+ describe('UserList', () => {
37
+ it('should show loading state', () => {
38
+ vi.mocked(useUsers).mockReturnValue({ data: null, loading: true });
39
+ render(<UserList />);
40
+ expect(screen.getByTestId('skeleton')).toBeInTheDocument();
41
+ });
42
+
43
+ it('should show error state', () => {
44
+ vi.mocked(useUsers).mockReturnValue({
45
+ data: null,
46
+ loading: false,
47
+ error: new Error('Failed to fetch')
48
+ });
49
+ render(<UserList />);
50
+ expect(screen.getByText('Failed to fetch')).toBeInTheDocument();
51
+ });
52
+
53
+ it('should render users', () => {
54
+ vi.mocked(useUsers).mockReturnValue({
55
+ data: [{ id: '1', name: 'John' }],
56
+ loading: false,
57
+ error: null
58
+ });
59
+ render(<UserList />);
60
+ expect(screen.getByText('John')).toBeInTheDocument();
61
+ });
62
+ });
63
+ ```
64
+
65
+ ---
66
+
67
+ ## Hook Test Patterns
68
+
69
+ ```typescript
70
+ import { renderHook, act, waitFor } from '@testing-library/react';
71
+
72
+ describe('useDebounce', () => {
73
+ vi.useFakeTimers();
74
+
75
+ it('should debounce value changes', async () => {
76
+ const { result } = renderHook(() => useDebounce('test', 500));
77
+
78
+ // Immediate value
79
+ expect(result.current).toBe('test');
80
+
81
+ // Change value immediately
82
+ act(() => {
83
+ result.current.setValue('test2');
84
+ });
85
+ expect(result.current.value).toBe('test'); // Not debounced yet
86
+
87
+ // Fast-forward
88
+ act(() => {
89
+ vi.advanceTimersByTime(500);
90
+ });
91
+ expect(result.current.value).toBe('test2');
92
+ });
93
+ });
94
+ ```
95
+
96
+ ---
97
+
98
+ ## Utility Function Patterns
99
+
100
+ ```typescript
101
+ describe('formatCurrency', () => {
102
+ it('should format positive numbers', () => {
103
+ expect(formatCurrency(1234.56)).toBe('$1,234.56');
104
+ });
105
+
106
+ it('should format zero', () => {
107
+ expect(formatCurrency(0)).toBe('$0.00');
108
+ });
109
+
110
+ it('should handle negative numbers', () => {
111
+ expect(formatCurrency(-100)).toBe('-$100.00');
112
+ });
113
+
114
+ it('should round to 2 decimal places', () => {
115
+ expect(formatCurrency(1.999)).toBe('$2.00');
116
+ });
117
+ });
118
+ ```
119
+
120
+ ---
121
+
122
+ ## Validator Test Patterns (Zod)
123
+
124
+ ```typescript
125
+ import { z } from 'zod';
126
+ import { userSchema } from './schema';
127
+
128
+ describe('userSchema', () => {
129
+ const validData = {
130
+ email: 'test@example.com',
131
+ age: 25,
132
+ name: 'John Doe'
133
+ };
134
+
135
+ it('should accept valid data', () => {
136
+ expect(() => userSchema.parse(validData)).not.toThrow();
137
+ });
138
+
139
+ it('should reject invalid email', () => {
140
+ expect(() =>
141
+ userSchema.parse({ ...validData, email: 'invalid' })
142
+ ).toThrow(z.ZodError);
143
+ });
144
+
145
+ it('should reject negative age', () => {
146
+ expect(() =>
147
+ userSchema.parse({ ...validData, age: -1 })
148
+ ).toThrow(z.ZodError);
149
+ });
150
+
151
+ it('should reject missing required fields', () => {
152
+ expect(() => userSchema.parse({})).toThrow(z.ZodError);
153
+ });
154
+ });
155
+ ```
156
+
157
+ ---
158
+
159
+ ## Store Test Patterns (Zustand)
160
+
161
+ ```typescript
162
+ import { create } from 'zustand';
163
+ import { useAuthStore } from './authStore';
164
+
165
+ describe('useAuthStore', () => {
166
+ beforeEach(() => {
167
+ useAuthStore.getState().reset();
168
+ });
169
+
170
+ it('should set user on login', () => {
171
+ const user = { id: '1', name: 'John' };
172
+ useAuthStore.getState().login(user);
173
+ expect(useAuthStore.getState().user).toEqual(user);
174
+ expect(useAuthStore.getState().isAuthenticated).toBe(true);
175
+ });
176
+
177
+ it('should clear user on logout', () => {
178
+ useAuthStore.getState().login({ id: '1', name: 'John' });
179
+ useAuthStore.getState().logout();
180
+ expect(useAuthStore.getState().user).toBeNull();
181
+ expect(useAuthStore.getState().isAuthenticated).toBe(false);
182
+ });
183
+ });
184
+ ```
185
+
186
+ ---
187
+
188
+ ## Mock Patterns
189
+
190
+ ### Mocking React Query
191
+
192
+ ```typescript
193
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
194
+
195
+ function createTestQueryClient() {
196
+ return new QueryClient({
197
+ defaultOptions: {
198
+ queries: { retry: false },
199
+ mutations: { retry: false }
200
+ }
201
+ });
202
+ }
203
+
204
+ function Wrapper({ children }) {
205
+ return (
206
+ <QueryClientProvider client={createTestQueryClient()}>
207
+ {children}
208
+ </QueryClientProvider>
209
+ );
210
+ }
211
+
212
+ describe('MyComponent', () => {
213
+ it('should work with React Query', () => {
214
+ render(<MyComponent />, { wrapper: Wrapper });
215
+ });
216
+ });
217
+ ```
218
+
219
+ ### Mocking Next.js Router
220
+
221
+ ```typescript
222
+ import { useRouter } from 'next/navigation';
223
+
224
+ vi.mock('next/navigation', () => ({
225
+ useRouter: () => ({
226
+ push: vi.fn(),
227
+ replace: vi.fn(),
228
+ prefetch: vi.fn(),
229
+ back: vi.fn(),
230
+ pathname: '/test'
231
+ }),
232
+ useSearchParams: () => new URLSearchParams('foo=bar'),
233
+ usePathname: () => '/test'
234
+ }));
235
+ ```
236
+
237
+ ### Mocking Fetch
238
+
239
+ ```typescript
240
+ global.fetch = vi.fn(() =>
241
+ Promise.resolve({
242
+ ok: true,
243
+ json: () => Promise.resolve({ data: 'test' })
244
+ })
245
+ ) as ReturnType<typeof vi.fn>;
246
+
247
+ // Or use MSW for more complex scenarios
248
+ import { http, HttpResponse } from 'msw';
249
+ import { setupServer } from 'msw/node';
250
+
251
+ const server = setupServer(
252
+ http.get('/api/users', () => {
253
+ return HttpResponse.json({ users: [] });
254
+ })
255
+ );
256
+
257
+ beforeAll(() => server.listen());
258
+ afterEach(() => server.resetHandlers());
259
+ afterAll(() => server.close());
260
+ ```
@@ -0,0 +1,221 @@
1
+ # Daemon Templates
2
+
3
+ This directory contains test templates for different frameworks and tools.
4
+
5
+ ## Structure
6
+
7
+ ```
8
+ templates/
9
+ ├── vitest/ # Vitest test templates
10
+ │ ├── component.test.ts # React component template
11
+ │ ├── vue-component.test.ts # Vue component template
12
+ │ ├── solid-component.test.ts # Solid component template
13
+ │ ├── svelte-component.test.ts # Svelte component template
14
+ │ ├── angular-component.test.ts # Angular component template
15
+ │ ├── hook.test.ts # React hooks template
16
+ │ └── api.test.ts # API route template
17
+ ├── rust/ # Rust test templates
18
+ │ ├── unit.test.rs # Basic unit test template
19
+ │ ├── integration.test.rs # Integration test template
20
+ │ ├── axum-handler.test.rs # Axum framework handler tests
21
+ │ ├── actix-controller.test.rs # Actix-web controller tests
22
+ │ ├── rocket-route.test.rs # Rocket framework route tests
23
+ │ └── Cargo.toml # Test dependencies configuration
24
+ ├── nestjs/ # NestJS test templates
25
+ │ ├── controller.spec.ts # Controller unit tests
26
+ │ ├── service.spec.ts # Service unit tests
27
+ │ ├── module.spec.ts # Module tests
28
+ │ ├── guard.spec.ts # Guard tests
29
+ │ ├── interceptor.spec.ts # Interceptor tests
30
+ │ ├── pipe.spec.ts # Pipe tests
31
+ │ ├── e2e/ # E2E tests
32
+ │ │ ├── api.e2e-spec.ts # API E2E tests
33
+ │ │ └── auth.e2e-spec.ts # Auth E2E tests
34
+ │ └── fixtures/ # Test utilities
35
+ │ └── test-module.ts # Module fixture
36
+ ├── playwright/ # Playwright E2E templates
37
+ │ ├── auth.spec.ts
38
+ │ └── crud.spec.ts
39
+ ├── k6/ # k6 backend performance templates
40
+ │ └── load-test.js
41
+ └── lighthouse/ # Lighthouse frontend performance (via CLI)
42
+ └── (run directly with npx lighthouse)
43
+ ```
44
+
45
+ ## Framework Support
46
+
47
+ ### Frontend Frameworks
48
+
49
+ | Framework | Template | Testing Library |
50
+ |-----------|----------|-----------------|
51
+ | React | `component.test.ts` | `@testing-library/react` |
52
+ | Vue | `vue-component.test.ts` | `@vue/test-utils` |
53
+ | Solid | `solid-component.test.ts` | `@solidjs/testing-library` |
54
+ | Svelte | `svelte-component.test.ts` | `@testing-library/svelte` |
55
+ | Angular | `angular-component.test.ts` | `@angular/core/testing` |
56
+
57
+ ### Backend Frameworks
58
+
59
+ | Framework | Templates | Testing Library |
60
+ |-----------|----------|-----------------|
61
+ | NestJS | `*.spec.ts` | `@nestjs/testing` |
62
+ | Rust - Axum | `axum-handler.test.rs` | `axum-test` |
63
+ | Rust - Actix | `actix-controller.test.rs` | `actix-rt` |
64
+ | Rust - Rocket | `rocket-route.test.rs` | Built-in |
65
+ | Rust - Generic | `unit.test.rs`, `integration.test.rs` | Built-in |
66
+ | Express | `api.test.ts` | `supertest` |
67
+ | Fastify | `api.test.ts` | `supertest` |
68
+
69
+ ## Rust Templates
70
+
71
+ The Rust templates provide test coverage for common Rust web frameworks and general testing patterns:
72
+
73
+ ### Unit Tests
74
+
75
+ - **unit.test.rs**: Basic unit test template including:
76
+ - Test function examples
77
+ - Error handling tests
78
+ - Test fixtures
79
+ - Assertion patterns
80
+
81
+ ### Integration Tests
82
+
83
+ - **integration.test.rs**: Integration test template including:
84
+ - API endpoint testing
85
+ - Database operations
86
+ - Test app setup helpers
87
+ - Test database pool creation
88
+
89
+ ### Framework-Specific Tests
90
+
91
+ - **axum-handler.test.rs**: Axum framework tests including:
92
+ - Health check endpoint
93
+ - GET/POST handler tests
94
+ - Request/response validation
95
+ - Error status code verification
96
+
97
+ - **actix-controller.test.rs**: Actix-web framework tests including:
98
+ - Controller initialization
99
+ - Route handler testing
100
+ - Query parameter handling
101
+ - JSON payload validation
102
+
103
+ - **rocket-route.test.rs**: Rocket framework tests including:
104
+ - Route testing with blocking client
105
+ - Authentication header handling
106
+ - Form data testing
107
+ - Status code assertions
108
+
109
+ ### Configuration
110
+
111
+ - **Cargo.toml**: Test dependencies including:
112
+ - `tokio-test` for async testing
113
+ - `criterion` for benchmarks
114
+ - Framework-specific test utilities
115
+
116
+ ## NestJS Templates
117
+
118
+ The NestJS templates provide comprehensive test coverage for all NestJS components:
119
+
120
+ ### Unit Tests
121
+
122
+ - **controller.spec.ts**: Tests for controllers including:
123
+ - Route handlers
124
+ - Request/response handling
125
+ - Query parameters
126
+ - DTO validation
127
+ - Error handling
128
+
129
+ - **service.spec.ts**: Tests for services including:
130
+ - Business logic
131
+ - Repository mocking
132
+ - CRUD operations
133
+ - Transaction handling
134
+ - Database errors
135
+
136
+ - **module.spec.ts**: Tests for modules including:
137
+ - Provider availability
138
+ - Dependency injection
139
+ - Module configuration
140
+ - Dynamic modules
141
+
142
+ - **guard.spec.ts**: Tests for guards including:
143
+ - Authentication logic
144
+ - Authorization checks
145
+ - Role validation
146
+ - Public route handling
147
+
148
+ - **interceptor.spec.ts**: Tests for interceptors including:
149
+ - Request/response transformation
150
+ - Logging behavior
151
+ - Caching
152
+ - Timeout handling
153
+
154
+ - **pipe.spec.ts**: Tests for pipes including:
155
+ - Data transformation
156
+ - Validation logic
157
+ - Error handling
158
+ - Custom business rules
159
+
160
+ ### E2E Tests
161
+
162
+ - **api.e2e-spec.ts**: Full API testing including:
163
+ - CRUD operations
164
+ - Pagination/filtering/sorting
165
+ - Error handling
166
+ - Performance tests
167
+ - CORS and rate limiting
168
+
169
+ - **auth.e2e-spec.ts**: Authentication testing including:
170
+ - Registration flow
171
+ - Login/logout
172
+ - Token refresh
173
+ - Password reset
174
+ - Role-based access
175
+
176
+ ### Fixtures
177
+
178
+ - **test-module.ts**: Common test utilities including:
179
+ - Mock repository factory
180
+ - Mock JWT service
181
+ - Test module builder
182
+ - Mock execution context
183
+ - Test data generators
184
+
185
+ ## Patterns Checked
186
+
187
+ The NestJS analyzer verifies:
188
+
189
+ ### Dependency Injection
190
+ - Circular dependencies between services
191
+ - Proper provider exports
192
+ - Missing @Injectable decorators
193
+ - Constructor injection patterns
194
+
195
+ ### Decorators
196
+ - @Controller with routes
197
+ - @Injectable on services/guards/pipes
198
+ - @UseGuards on protected routes
199
+ - @UsePipes for validation
200
+ - @UseInterceptors for cross-cutting concerns
201
+
202
+ ### Single Responsibility
203
+ - Services with too many dependencies (>5)
204
+ - Controllers without route handlers
205
+ - Large service classes (potential refactoring)
206
+
207
+ ### Error Handling
208
+ - Proper exception usage
209
+ - HTTP exception decorators
210
+ - Exception filters
211
+ - Error response format
212
+
213
+ ### DTOs
214
+ - class-validator decorators
215
+ - class-transformer usage
216
+ - Partial types for updates
217
+ - Nested DTO validation
218
+
219
+ ## Usage
220
+
221
+ Templates are used by the test generator agent to create new test files based on the detected framework and patterns.
@@ -0,0 +1,54 @@
1
+ import http from 'k6/http';
2
+ import { check, sleep } from 'k6';
3
+
4
+ // Configuration
5
+ export const options = {
6
+ stages: [
7
+ { duration: '30s', target: 20 }, // Ramp up to 20 users
8
+ { duration: '1m', target: 20 }, // Stay at 20 users
9
+ { duration: '30s', target: 50 }, // Ramp up to 50 users
10
+ { duration: '1m', target: 50 }, // Stay at 50 users
11
+ { duration: '30s', target: 0 }, // Ramp down
12
+ ],
13
+ thresholds: {
14
+ http_req_duration: ['p(95)<200', 'p(99)<500'],
15
+ http_req_failed: ['rate<0.01'],
16
+ },
17
+ };
18
+
19
+ const BASE_URL = __ENV.BASE_URL || 'http://host.docker.internal:3000';
20
+
21
+ export default function () {
22
+ // Test homepage
23
+ let res = http.get(`${BASE_URL}/`);
24
+ check(res, {
25
+ 'homepage status 200': (r) => r.status === 200,
26
+ 'homepage response time < 200ms': (r) => r.timings.duration < 200,
27
+ });
28
+
29
+ sleep(1);
30
+
31
+ // Test API endpoint
32
+ res = http.get(`${BASE_URL}/api/users`);
33
+ check(res, {
34
+ 'users API status 200': (r) => r.status === 200,
35
+ 'users response time < 200ms': (r) => r.timings.duration < 200,
36
+ });
37
+
38
+ sleep(1);
39
+
40
+ // Test POST endpoint
41
+ res = http.post(`${BASE_URL}/api/contact`, JSON.stringify({
42
+ name: 'Test User',
43
+ email: 'test@example.com',
44
+ message: 'Test message',
45
+ }), {
46
+ headers: { 'Content-Type': 'application/json' },
47
+ });
48
+
49
+ check(res, {
50
+ 'contact API status 200': (r) => r.status === 200,
51
+ });
52
+
53
+ sleep(1);
54
+ }