oneie 3.6.7 → 3.6.12

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 (168) hide show
  1. package/.claude/agents/agent-backend.md +83 -0
  2. package/.claude/agents/agent-designer.md +97 -0
  3. package/.claude/agents/agent-director.md +118 -7
  4. package/.claude/agents/agent-documenter.md +93 -0
  5. package/.claude/agents/agent-frontend.md +96 -0
  6. package/.claude/agents/agent-ops.md +264 -32
  7. package/.claude/agents/agent-problem-solver.md +166 -0
  8. package/.claude/agents/agent-quality.md +127 -0
  9. package/.claude/commands/build.md +293 -0
  10. package/.claude/commands/cascade.md +231 -127
  11. package/.claude/commands/deploy.md +56 -17
  12. package/.claude/commands/mcp-toggle.md +93 -0
  13. package/.claude/commands/one.md +78 -127
  14. package/.claude/commands/plan.md +394 -80
  15. package/.claude/commands/push.md +75 -14
  16. package/.claude/commands/release.md +89 -25
  17. package/.claude/commands/server.md +2 -0
  18. package/.claude/hooks/__pycache__/todo.cpython-313.pyc +0 -0
  19. package/.claude/hooks/root-cleanup.py +75 -0
  20. package/.claude/skills/INDEX.md +523 -0
  21. package/.claude/skills/REGISTRY.md +529 -0
  22. package/.claude/skills/agent-backend-create-mutation.md +319 -0
  23. package/.claude/skills/agent-designer-create-wireframe.md +341 -0
  24. package/.claude/skills/agent-frontend-create-page.md +413 -0
  25. package/.claude/skills/agents/README.md +238 -0
  26. package/dist/clone-web.js +1 -1
  27. package/dist/clone-web.js.map +1 -1
  28. package/folders.yaml +1 -1
  29. package/one/.obsidian/workspace.json +38 -38
  30. package/one/connections/api/queries-reference.md +842 -0
  31. package/one/connections/api-reference.md +1011 -0
  32. package/one/connections/integration-examples.md +875 -0
  33. package/one/connections/integration-guide.md +869 -0
  34. package/one/connections/integration-phase2.md +736 -0
  35. package/one/events/API_ROUTES_FIXES_SUMMARY.md +262 -0
  36. package/one/events/ASTRO-INTEGRATION-EXAMPLES.md +636 -0
  37. package/one/events/BEFORE_AFTER_COMPARISON.md +960 -0
  38. package/one/events/CONNECTIONS_DEMO.md +501 -0
  39. package/one/events/DELIVERABLES.md +432 -0
  40. package/one/events/DEMO-GROUPS-PAGE.md +392 -0
  41. package/one/events/DEMO-TESTING-SUMMARY.md +518 -0
  42. package/one/events/DEMO_COMPONENTS.md +487 -0
  43. package/one/events/DEMO_HOOKS_INDEX.md +334 -0
  44. package/one/events/DEMO_INFRASTRUCTURE.md +905 -0
  45. package/one/events/DEMO_INFRASTRUCTURE_SUMMARY.md +570 -0
  46. package/one/events/DEMO_INTEGRATION_CHECKLIST.md +431 -0
  47. package/one/events/DEMO_QUICK_REFERENCE.md +441 -0
  48. package/one/events/DEMO_SETUP.md +476 -0
  49. package/one/events/EFFECT_TS_API_PATTERN.md +478 -0
  50. package/one/events/GROUPS_DEMO_IMPLEMENTATION.md +414 -0
  51. package/one/events/HOOKS-DEMO.md +441 -0
  52. package/one/events/ONTOLOGY-HOOKS-README.md +700 -0
  53. package/one/events/ONTOLOGY-INTEGRATION-MANIFEST.md +365 -0
  54. package/one/events/QA-CHECKLIST.md +674 -0
  55. package/one/events/QUICK-START-ONTOLOGY.md +408 -0
  56. package/one/events/SEARCH_DEMO_CODE_REFERENCE.md +639 -0
  57. package/one/events/SEARCH_DEMO_DELIVERY.md +415 -0
  58. package/one/events/SEARCH_DEMO_SUMMARY.md +303 -0
  59. package/one/events/SEARCH_DEMO_VISUAL_GUIDE.md +381 -0
  60. package/one/events/TEST-PLAN-INDEX.md +346 -0
  61. package/one/events/TEST-PLAN.md +1417 -0
  62. package/one/events/TESTING-DELIVERY.txt +372 -0
  63. package/one/events/TRANSITIONS-QUICK-START.md +141 -0
  64. package/one/events/TYPESCRIPT_FIXES.md +152 -0
  65. package/one/events/TYPESCRIPT_FIXES_COMPLETE.txt +412 -0
  66. package/one/events/TYPESCRIPT_FIXES_INDEX.md +341 -0
  67. package/one/events/VIEW-TRANSITIONS.md +428 -0
  68. package/one/events/backend-integration-tests.md +606 -0
  69. package/one/events/backend-structure-diagram.txt +393 -0
  70. package/one/events/backend-structure-summary.txt +269 -0
  71. package/one/events/cloudflare-pages-infrastructure-setup.md +264 -0
  72. package/one/events/convex-analysis-index.md +304 -0
  73. package/one/events/convex-structure-analysis.md +700 -0
  74. package/one/events/design-spec-complete.md +208 -0
  75. package/one/events/ontology-test-examples.md +562 -0
  76. package/one/events/phase1-backend-implementation-complete.md +518 -0
  77. package/one/events/test-dashboard.md +345 -0
  78. package/one/events/test-index.md +361 -0
  79. package/one/events/test-report-ontology.md +582 -0
  80. package/one/events/testing-summary.md +344 -0
  81. package/one/groups/features.md +2878 -0
  82. package/one/groups/strategy copy.md +869 -0
  83. package/one/knowledge/backend-api-reference.md +710 -0
  84. package/one/knowledge/documentation-summary.md +285 -0
  85. package/one/knowledge/lessons-learned.md +294 -4
  86. package/one/knowledge/ontology-visual-guide.md +360 -0
  87. package/one/knowledge/ontology.md +9 -17
  88. package/one/things/demo-accessibility-animations.md +999 -0
  89. package/one/things/demo-components.md +1304 -0
  90. package/one/things/demo-design-summary.md +629 -0
  91. package/one/things/demo-design-system.md +919 -0
  92. package/one/things/demo-page-layouts.md +989 -0
  93. package/one/things/designs/accessibility-audit.md +790 -0
  94. package/one/things/designs/component-specifications.md +757 -0
  95. package/one/things/designs/design-overview.md +318 -0
  96. package/one/things/designs/design-tokens.md +414 -0
  97. package/one/things/designs/wireframes-dashboard.md +653 -0
  98. package/one/things/docs/api-requests.md +923 -0
  99. package/one/things/features/0 All Features.md +2 -0
  100. package/one/things/implementation/backend-guide.md +412 -0
  101. package/one/things/plans/2-backend-agnostic-frontend.md +11 -8
  102. package/one/things/plans/2-sites.md +895 -0
  103. package/one/things/plans/ai-elements.md +1259 -0
  104. package/one/things/plans/ai-integration.md +947 -0
  105. package/one/things/plans/ai-sdk.md +761 -0
  106. package/one/things/plans/app.md +1 -1
  107. package/one/things/plans/architecture-summary.md +283 -0
  108. package/one/things/plans/async-ai-agents.md +215 -0
  109. package/one/things/plans/backend-agnostic-frontend.md +11 -6
  110. package/one/things/plans/backend-cleanup-quickstart.md +346 -0
  111. package/one/things/plans/backend-ontology-conformance.md +416 -0
  112. package/one/things/plans/backend-status.md +541 -0
  113. package/one/things/plans/backend-structure.md +799 -0
  114. package/one/things/plans/backend-target-structure.md +438 -0
  115. package/one/things/plans/backend.md +1133 -0
  116. package/one/things/plans/better-auth-any-backend.md +11 -11
  117. package/one/things/plans/cli-updates-required.md +280 -0
  118. package/one/things/plans/complete-step-by-step.md +1302 -0
  119. package/one/things/plans/convex-agents.md +1005 -0
  120. package/one/things/plans/deployment-architecture.md +426 -0
  121. package/one/things/plans/development-plan.md +1220 -0
  122. package/one/things/plans/effect.md +808 -48
  123. package/one/things/plans/integrate-frontend-and-backend.md +579 -0
  124. package/one/things/plans/mcp-clear-context-prompt.md +60 -0
  125. package/one/things/plans/mcp-simple.md +228 -0
  126. package/one/things/plans/one.md +8 -7
  127. package/one/things/plans/ontology-6-dimensions.md +20 -14
  128. package/one/things/plans/quick-wins.md +1273 -0
  129. package/one/things/plans/readme-backend-cleanup.md +361 -0
  130. package/one/things/plans/separate-demo.md +830 -0
  131. package/one/things/plans/separate.md +3 -3
  132. package/one/things/plans/sequence.md +1897 -0
  133. package/one/things/plans/sync-checklist.md +321 -0
  134. package/one/things/plans/unified-implementation-plan.md +3 -3
  135. package/one/things/plans/update-demos.md +513 -0
  136. package/package.json +1 -1
  137. package/.claude/agents/backend-specialist.md +0 -169
  138. package/.claude/agents/designer.md +0 -216
  139. package/.claude/agents/frontend-specialist.md +0 -236
  140. package/.claude/commands/done.md +0 -35
  141. package/.claude/commands/infer.md +0 -138
  142. package/.claude/commands/next.md +0 -53
  143. package/.claude/commands/one copy.md +0 -565
  144. package/.claude/commands/one-template.md +0 -106
  145. package/.claude/commands/one-v1.md +0 -609
  146. package/.claude/hooks/__pycache__/knowledge-post.cpython-313.pyc +0 -0
  147. package/.claude/hooks/__pycache__/knowledge-pre.cpython-313.pyc +0 -0
  148. package/one/groups/nine-padel-customers.md +0 -138
  149. package/one/groups/nine-padel-data-structure.md +0 -167
  150. package/one/groups/nine-padel-ontology-specification.md +0 -359
  151. package/one/groups/nine-padel-ontology.md +0 -143
  152. package/one/groups/nine-padel-strategy.md +0 -234
  153. package/one/groups/nine-padel.md +0 -211
  154. package/one/groups/nine-padle-contents.baked.md +0 -1252
  155. package/one/groups/nine-padle-contents.md +0 -6
  156. package/one/things/features/1-1-agent-prompts/design.md +0 -470
  157. package/one/things/features/1-1-agent-prompts/tests.md +0 -264
  158. package/one/things/features/1-2-yaml-orchestrator/design.md +0 -497
  159. package/one/things/features/1-2-yaml-orchestrator/tests.md +0 -227
  160. package/one/things/features/1-3-event-coordination/design.md +0 -544
  161. package/one/things/features/1-3-event-coordination/tests.md +0 -223
  162. package/one/things/features/1-4-knowledge-management/design.md +0 -609
  163. package/one/things/features/1-4-knowledge-management/tests.md +0 -195
  164. package/one/things/features/1-5-quality-loops/design.md +0 -797
  165. package/one/things/features/1-5-quality-loops/tests.md +0 -212
  166. package/one/things/features/1-6-numbering-structure/design.md +0 -610
  167. package/one/things/features/1-6-numbering-structure/tests.md +0 -213
  168. package/one/things/features/dataprovider-interface/1-tests.md +0 -1522
@@ -1,1522 +0,0 @@
1
- # Test Specification: DataProvider Interface & ConvexProvider
2
-
3
- **Feature ID:** `feature_dataprovider_interface`
4
- **Test Suite:** Comprehensive Unit, Integration, E2E, Performance, and Security Tests
5
- **Coverage Target:** 95%+ Unit, 85%+ Integration
6
- **Estimated Test Count:** 120+ test cases
7
- **Owner:** Quality Agent
8
- **Status:** Ready for Implementation
9
-
10
- ---
11
-
12
- ## Table of Contents
13
-
14
- 1. [Test Plan Overview](#test-plan-overview)
15
- 2. [Test Environment Setup](#test-environment-setup)
16
- 3. [Unit Tests (80+ cases)](#unit-tests)
17
- 4. [Integration Tests (20+ cases)](#integration-tests)
18
- 5. [E2E Tests (10+ cases)](#e2e-tests)
19
- 6. [Performance Tests](#performance-tests)
20
- 7. [Security Tests](#security-tests)
21
- 8. [Accessibility Tests](#accessibility-tests)
22
- 9. [Test Data & Fixtures](#test-data--fixtures)
23
- 10. [CI/CD Integration](#cicd-integration)
24
- 11. [Quality Gates](#quality-gates)
25
-
26
- ---
27
-
28
- ## Test Plan Overview
29
-
30
- ### Scope
31
-
32
- This test suite validates the **DataProvider interface** and **ConvexProvider implementation**:
33
-
34
- - DataProvider interface definition (TypeScript contract)
35
- - ConvexProvider implementation (all 6 dimensions)
36
- - Error handling (typed errors with `_tag`)
37
- - Subscription lifecycle (real-time updates)
38
- - Performance overhead (<10ms target)
39
- - Backward compatibility (all 50+ auth tests must pass)
40
-
41
- ### Test Types
42
-
43
- - **Unit Tests**: Service methods in isolation with mocks
44
- - **Integration Tests**: ConvexProvider → Convex backend flows
45
- - **E2E Tests**: Full user journeys with real data
46
- - **Performance Tests**: Latency, throughput, memory benchmarks
47
- - **Security Tests**: Input validation, authorization checks
48
- - **Accessibility Tests**: N/A (backend interface only)
49
-
50
- ### Testing Framework
51
-
52
- ```bash
53
- # Dependencies
54
- bun add -d vitest @vitest/ui @vitest/coverage-v8
55
- bun add -d @testing-library/react @testing-library/jest-dom
56
- bun add -d msw # Mock Service Worker for API mocking
57
- ```
58
-
59
- ### Test Configuration
60
-
61
- ```typescript
62
- // vitest.config.ts
63
- import { defineConfig } from 'vitest/config';
64
- import react from '@vitejs/plugin-react';
65
-
66
- export default defineConfig({
67
- plugins: [react()],
68
- test: {
69
- globals: true,
70
- environment: 'jsdom',
71
- setupFiles: './tests/setup.ts',
72
- coverage: {
73
- provider: 'v8',
74
- reporter: ['text', 'json', 'html', 'lcov'],
75
- include: ['src/providers/**/*.ts'],
76
- exclude: ['**/*.test.ts', '**/*.d.ts', '**/types.ts'],
77
- lines: 90,
78
- functions: 90,
79
- branches: 85,
80
- statements: 90,
81
- },
82
- },
83
- });
84
- ```
85
-
86
- ---
87
-
88
- ## Test Environment Setup
89
-
90
- ### Setup Files
91
-
92
- ```typescript
93
- // tests/setup.ts
94
- import { beforeAll, afterAll, afterEach } from 'vitest';
95
- import { cleanup } from '@testing-library/react';
96
-
97
- beforeAll(() => {
98
- // Global test setup
99
- process.env.PUBLIC_CONVEX_URL = 'https://test.convex.cloud';
100
- });
101
-
102
- afterEach(() => {
103
- cleanup();
104
- });
105
-
106
- afterAll(() => {
107
- // Global cleanup
108
- });
109
- ```
110
-
111
- ### Mock Convex Client
112
-
113
- ```typescript
114
- // tests/mocks/MockConvexClient.ts
115
- import { vi } from 'vitest';
116
- import type { ConvexHttpClient } from 'convex/browser';
117
-
118
- export class MockConvexClient {
119
- query = vi.fn();
120
- mutation = vi.fn();
121
- subscribe = vi.fn();
122
- close = vi.fn();
123
-
124
- reset() {
125
- this.query.mockReset();
126
- this.mutation.mockReset();
127
- this.subscribe.mockReset();
128
- this.close.mockReset();
129
- }
130
- }
131
- ```
132
-
133
- ### Test Utilities
134
-
135
- ```typescript
136
- // tests/utils/testUtils.ts
137
- import { Effect, Layer } from 'effect';
138
- import { ConvexDatabase } from '@/providers/convex/ConvexDatabase';
139
- import { MockConvexClient } from '../mocks/MockConvexClient';
140
-
141
- export function createTestLayer(mockClient: MockConvexClient) {
142
- const mockDb = Layer.succeed(ConvexDatabase, {
143
- query: (name, args) => Effect.tryPromise(() => mockClient.query(name, args)),
144
- mutation: (name, args) => Effect.tryPromise(() => mockClient.mutation(name, args)),
145
- });
146
-
147
- return mockDb;
148
- }
149
-
150
- export async function runTest<A>(
151
- effect: Effect.Effect<A, any, any>,
152
- layer: Layer.Layer<any, any, any>
153
- ): Promise<A> {
154
- return Effect.runPromise(Effect.provide(effect, layer));
155
- }
156
- ```
157
-
158
- ---
159
-
160
- ## Unit Tests
161
-
162
- ### 1. DataProvider Interface Tests
163
-
164
- #### 1.1 Interface Definition Tests
165
-
166
- ```typescript
167
- // tests/unit/providers/DataProvider.test.ts
168
- import { describe, it, expect } from 'vitest';
169
- import { DataProvider } from '@/providers/DataProvider';
170
-
171
- describe('DataProvider Interface', () => {
172
- it('should have organizations namespace', () => {
173
- expect(DataProvider).toBeDefined();
174
- // TypeScript compiler validates interface structure
175
- });
176
-
177
- it('should have people namespace', () => {
178
- // Validated by TypeScript
179
- });
180
-
181
- it('should have things namespace with all CRUD methods', () => {
182
- // Validated by TypeScript
183
- });
184
-
185
- it('should have connections namespace', () => {
186
- // Validated by TypeScript
187
- });
188
-
189
- it('should have events namespace', () => {
190
- // Validated by TypeScript
191
- });
192
-
193
- it('should have knowledge namespace', () => {
194
- // Validated by TypeScript
195
- });
196
-
197
- it('should have optional subscriptions namespace', () => {
198
- // Validated by TypeScript
199
- });
200
- });
201
- ```
202
-
203
- #### 1.2 TypeScript Type Tests
204
-
205
- ```typescript
206
- // tests/unit/providers/DataProvider.types.test.ts
207
- import { describe, it, expectTypeOf } from 'vitest';
208
- import type { DataProvider } from '@/providers/DataProvider';
209
- import type { Effect } from 'effect';
210
- import type { ThingNotFoundError, OrganizationNotFoundError } from '@/providers/errors';
211
-
212
- describe('DataProvider Types', () => {
213
- it('should have correct return types for things.get', () => {
214
- type GetReturn = ReturnType<DataProvider['things']['get']>;
215
- expectTypeOf<GetReturn>().toMatchTypeOf<Effect.Effect<Thing, ThingNotFoundError>>();
216
- });
217
-
218
- it('should have correct return types for things.list', () => {
219
- type ListReturn = ReturnType<DataProvider['things']['list']>;
220
- expectTypeOf<ListReturn>().toMatchTypeOf<Effect.Effect<Thing[], Error>>();
221
- });
222
-
223
- it('should have correct return types for things.create', () => {
224
- type CreateReturn = ReturnType<DataProvider['things']['create']>;
225
- expectTypeOf<CreateReturn>().toMatchTypeOf<Effect.Effect<string, Error>>();
226
- });
227
-
228
- it('should enforce required parameters', () => {
229
- // TypeScript will error if required params missing
230
- expectTypeOf<DataProvider['things']['get']>().parameter(0).toEqualTypeOf<string>();
231
- });
232
- });
233
- ```
234
-
235
- ### 2. ConvexProvider Implementation Tests
236
-
237
- #### 2.1 Things Namespace Tests
238
-
239
- ```typescript
240
- // tests/unit/providers/ConvexProvider.things.test.ts
241
- import { describe, it, expect, beforeEach } from 'vitest';
242
- import { Effect } from 'effect';
243
- import { ConvexProvider } from '@/providers/convex/ConvexProvider';
244
- import { MockConvexClient } from '../../mocks/MockConvexClient';
245
- import { ThingNotFoundError } from '@/providers/errors';
246
- import { api } from '@/convex/_generated/api';
247
-
248
- describe('ConvexProvider.things', () => {
249
- let provider: ConvexProvider;
250
- let mockClient: MockConvexClient;
251
-
252
- beforeEach(() => {
253
- mockClient = new MockConvexClient();
254
- provider = new ConvexProvider(mockClient as any);
255
- });
256
-
257
- describe('get()', () => {
258
- it('should return thing when found', async () => {
259
- const mockThing = {
260
- _id: 'thing_123',
261
- type: 'product',
262
- name: 'Test Product',
263
- properties: {},
264
- status: 'active',
265
- organizationId: 'org_1',
266
- createdAt: Date.now(),
267
- updatedAt: Date.now(),
268
- };
269
-
270
- mockClient.query.mockResolvedValue(mockThing);
271
-
272
- const result = await Effect.runPromise(provider.things.get('thing_123'));
273
-
274
- expect(result).toEqual(mockThing);
275
- expect(mockClient.query).toHaveBeenCalledWith(
276
- api.queries.entities.get,
277
- { id: 'thing_123' }
278
- );
279
- });
280
-
281
- it('should throw ThingNotFoundError when not found', async () => {
282
- mockClient.query.mockRejectedValue(new Error('Not found'));
283
-
284
- await expect(
285
- Effect.runPromise(provider.things.get('thing_999'))
286
- ).rejects.toThrow(ThingNotFoundError);
287
- });
288
-
289
- it('should include thing ID in error', async () => {
290
- mockClient.query.mockRejectedValue(new Error('Not found'));
291
-
292
- try {
293
- await Effect.runPromise(provider.things.get('thing_999'));
294
- } catch (error) {
295
- expect(error).toBeInstanceOf(ThingNotFoundError);
296
- expect((error as ThingNotFoundError).thingId).toBe('thing_999');
297
- }
298
- });
299
-
300
- it('should handle network errors', async () => {
301
- mockClient.query.mockRejectedValue(new Error('Network error'));
302
-
303
- await expect(
304
- Effect.runPromise(provider.things.get('thing_123'))
305
- ).rejects.toThrow();
306
- });
307
-
308
- it('should validate thing ID format', async () => {
309
- await expect(
310
- Effect.runPromise(provider.things.get(''))
311
- ).rejects.toThrow();
312
- });
313
- });
314
-
315
- describe('list()', () => {
316
- it('should return list of things', async () => {
317
- const mockThings = [
318
- { _id: '1', type: 'product', name: 'Product 1' },
319
- { _id: '2', type: 'product', name: 'Product 2' },
320
- ];
321
-
322
- mockClient.query.mockResolvedValue(mockThings);
323
-
324
- const result = await Effect.runPromise(
325
- provider.things.list({ type: 'product' })
326
- );
327
-
328
- expect(result).toEqual(mockThings);
329
- expect(mockClient.query).toHaveBeenCalledWith(
330
- api.queries.entities.list,
331
- { type: 'product' }
332
- );
333
- });
334
-
335
- it('should filter by organization ID', async () => {
336
- mockClient.query.mockResolvedValue([]);
337
-
338
- await Effect.runPromise(
339
- provider.things.list({ type: 'product', organizationId: 'org_1' })
340
- );
341
-
342
- expect(mockClient.query).toHaveBeenCalledWith(
343
- api.queries.entities.list,
344
- { type: 'product', organizationId: 'org_1' }
345
- );
346
- });
347
-
348
- it('should return empty array when no things found', async () => {
349
- mockClient.query.mockResolvedValue([]);
350
-
351
- const result = await Effect.runPromise(
352
- provider.things.list({ type: 'product' })
353
- );
354
-
355
- expect(result).toEqual([]);
356
- });
357
-
358
- it('should validate thing type', async () => {
359
- await expect(
360
- Effect.runPromise(provider.things.list({ type: '' as any }))
361
- ).rejects.toThrow();
362
- });
363
-
364
- it('should handle pagination parameters', async () => {
365
- mockClient.query.mockResolvedValue([]);
366
-
367
- await Effect.runPromise(
368
- provider.things.list({
369
- type: 'product',
370
- limit: 10,
371
- cursor: 'cursor_123',
372
- })
373
- );
374
-
375
- expect(mockClient.query).toHaveBeenCalledWith(
376
- api.queries.entities.list,
377
- expect.objectContaining({ limit: 10, cursor: 'cursor_123' })
378
- );
379
- });
380
- });
381
-
382
- describe('create()', () => {
383
- it('should create thing and return ID', async () => {
384
- mockClient.mutation.mockResolvedValue('thing_new');
385
-
386
- const input = {
387
- type: 'product',
388
- name: 'New Product',
389
- properties: { price: 99.99 },
390
- organizationId: 'org_1',
391
- };
392
-
393
- const id = await Effect.runPromise(provider.things.create(input));
394
-
395
- expect(id).toBe('thing_new');
396
- expect(mockClient.mutation).toHaveBeenCalledWith(
397
- api.mutations.entities.create,
398
- expect.objectContaining(input)
399
- );
400
- });
401
-
402
- it('should validate required fields', async () => {
403
- await expect(
404
- Effect.runPromise(
405
- provider.things.create({
406
- type: '',
407
- name: '',
408
- organizationId: '',
409
- } as any)
410
- )
411
- ).rejects.toThrow();
412
- });
413
-
414
- it('should handle creation errors', async () => {
415
- mockClient.mutation.mockRejectedValue(new Error('Database error'));
416
-
417
- await expect(
418
- Effect.runPromise(
419
- provider.things.create({
420
- type: 'product',
421
- name: 'Product',
422
- organizationId: 'org_1',
423
- })
424
- )
425
- ).rejects.toThrow();
426
- });
427
-
428
- it('should set default status to draft', async () => {
429
- mockClient.mutation.mockResolvedValue('thing_new');
430
-
431
- await Effect.runPromise(
432
- provider.things.create({
433
- type: 'product',
434
- name: 'Product',
435
- organizationId: 'org_1',
436
- })
437
- );
438
-
439
- expect(mockClient.mutation).toHaveBeenCalledWith(
440
- api.mutations.entities.create,
441
- expect.objectContaining({ status: 'draft' })
442
- );
443
- });
444
-
445
- it('should include timestamps', async () => {
446
- mockClient.mutation.mockResolvedValue('thing_new');
447
-
448
- await Effect.runPromise(
449
- provider.things.create({
450
- type: 'product',
451
- name: 'Product',
452
- organizationId: 'org_1',
453
- })
454
- );
455
-
456
- expect(mockClient.mutation).toHaveBeenCalledWith(
457
- api.mutations.entities.create,
458
- expect.objectContaining({
459
- createdAt: expect.any(Number),
460
- updatedAt: expect.any(Number),
461
- })
462
- );
463
- });
464
- });
465
-
466
- describe('update()', () => {
467
- it('should update thing and return updated thing', async () => {
468
- const mockUpdated = {
469
- _id: 'thing_123',
470
- type: 'product',
471
- name: 'Updated Product',
472
- properties: {},
473
- status: 'active',
474
- organizationId: 'org_1',
475
- createdAt: Date.now() - 1000,
476
- updatedAt: Date.now(),
477
- };
478
-
479
- mockClient.mutation.mockResolvedValue(mockUpdated);
480
-
481
- const result = await Effect.runPromise(
482
- provider.things.update('thing_123', { name: 'Updated Product' })
483
- );
484
-
485
- expect(result).toEqual(mockUpdated);
486
- expect(mockClient.mutation).toHaveBeenCalledWith(
487
- api.mutations.entities.update,
488
- { id: 'thing_123', name: 'Updated Product' }
489
- );
490
- });
491
-
492
- it('should handle partial updates', async () => {
493
- mockClient.mutation.mockResolvedValue({});
494
-
495
- await Effect.runPromise(
496
- provider.things.update('thing_123', {
497
- properties: { newField: 'value' },
498
- })
499
- );
500
-
501
- expect(mockClient.mutation).toHaveBeenCalledWith(
502
- api.mutations.entities.update,
503
- expect.objectContaining({ properties: { newField: 'value' } })
504
- );
505
- });
506
-
507
- it('should throw error if thing not found', async () => {
508
- mockClient.mutation.mockRejectedValue(new Error('Not found'));
509
-
510
- await expect(
511
- Effect.runPromise(provider.things.update('thing_999', { name: 'X' }))
512
- ).rejects.toThrow();
513
- });
514
-
515
- it('should update updatedAt timestamp', async () => {
516
- mockClient.mutation.mockResolvedValue({});
517
-
518
- await Effect.runPromise(
519
- provider.things.update('thing_123', { name: 'Updated' })
520
- );
521
-
522
- expect(mockClient.mutation).toHaveBeenCalledWith(
523
- api.mutations.entities.update,
524
- expect.objectContaining({ updatedAt: expect.any(Number) })
525
- );
526
- });
527
- });
528
-
529
- describe('delete()', () => {
530
- it('should delete thing', async () => {
531
- mockClient.mutation.mockResolvedValue(undefined);
532
-
533
- await Effect.runPromise(provider.things.delete('thing_123'));
534
-
535
- expect(mockClient.mutation).toHaveBeenCalledWith(
536
- api.mutations.entities.delete,
537
- { id: 'thing_123' }
538
- );
539
- });
540
-
541
- it('should throw error if thing not found', async () => {
542
- mockClient.mutation.mockRejectedValue(new Error('Not found'));
543
-
544
- await expect(
545
- Effect.runPromise(provider.things.delete('thing_999'))
546
- ).rejects.toThrow();
547
- });
548
-
549
- it('should validate thing ID', async () => {
550
- await expect(
551
- Effect.runPromise(provider.things.delete(''))
552
- ).rejects.toThrow();
553
- });
554
- });
555
- });
556
- ```
557
-
558
- #### 2.2 Connections Namespace Tests (15 cases)
559
-
560
- ```typescript
561
- // tests/unit/providers/ConvexProvider.connections.test.ts
562
- import { describe, it, expect, beforeEach } from 'vitest';
563
- import { Effect } from 'effect';
564
- import { ConvexProvider } from '@/providers/convex/ConvexProvider';
565
- import { MockConvexClient } from '../../mocks/MockConvexClient';
566
-
567
- describe('ConvexProvider.connections', () => {
568
- let provider: ConvexProvider;
569
- let mockClient: MockConvexClient;
570
-
571
- beforeEach(() => {
572
- mockClient = new MockConvexClient();
573
- provider = new ConvexProvider(mockClient as any);
574
- });
575
-
576
- describe('create()', () => {
577
- it('should create connection and return ID', async () => {
578
- mockClient.mutation.mockResolvedValue('conn_123');
579
-
580
- const input = {
581
- fromThingId: 'user_1',
582
- toThingId: 'product_1',
583
- type: 'owns',
584
- metadata: { purchasedAt: Date.now() },
585
- };
586
-
587
- const id = await Effect.runPromise(provider.connections.create(input));
588
-
589
- expect(id).toBe('conn_123');
590
- expect(mockClient.mutation).toHaveBeenCalledWith(
591
- api.mutations.connections.create,
592
- expect.objectContaining(input)
593
- );
594
- });
595
-
596
- it('should validate connection type', async () => {
597
- await expect(
598
- Effect.runPromise(
599
- provider.connections.create({
600
- fromThingId: 'thing_1',
601
- toThingId: 'thing_2',
602
- type: 'invalid_type' as any,
603
- })
604
- )
605
- ).rejects.toThrow();
606
- });
607
-
608
- it('should validate thing IDs exist', async () => {
609
- mockClient.mutation.mockRejectedValue(new Error('Thing not found'));
610
-
611
- await expect(
612
- Effect.runPromise(
613
- provider.connections.create({
614
- fromThingId: 'invalid',
615
- toThingId: 'invalid',
616
- type: 'owns',
617
- })
618
- )
619
- ).rejects.toThrow();
620
- });
621
-
622
- it('should include timestamps', async () => {
623
- mockClient.mutation.mockResolvedValue('conn_123');
624
-
625
- await Effect.runPromise(
626
- provider.connections.create({
627
- fromThingId: 'thing_1',
628
- toThingId: 'thing_2',
629
- type: 'owns',
630
- })
631
- );
632
-
633
- expect(mockClient.mutation).toHaveBeenCalledWith(
634
- api.mutations.connections.create,
635
- expect.objectContaining({ createdAt: expect.any(Number) })
636
- );
637
- });
638
-
639
- it('should support temporal validity', async () => {
640
- mockClient.mutation.mockResolvedValue('conn_123');
641
-
642
- const validFrom = Date.now();
643
- const validTo = Date.now() + 86400000;
644
-
645
- await Effect.runPromise(
646
- provider.connections.create({
647
- fromThingId: 'thing_1',
648
- toThingId: 'thing_2',
649
- type: 'owns',
650
- validFrom,
651
- validTo,
652
- })
653
- );
654
-
655
- expect(mockClient.mutation).toHaveBeenCalledWith(
656
- api.mutations.connections.create,
657
- expect.objectContaining({ validFrom, validTo })
658
- );
659
- });
660
- });
661
-
662
- describe('getRelated()', () => {
663
- it('should return related connections', async () => {
664
- const mockConnections = [
665
- { _id: 'conn_1', fromThingId: 'user_1', toThingId: 'product_1', type: 'owns' },
666
- { _id: 'conn_2', fromThingId: 'user_1', toThingId: 'product_2', type: 'owns' },
667
- ];
668
-
669
- mockClient.query.mockResolvedValue(mockConnections);
670
-
671
- const result = await Effect.runPromise(
672
- provider.connections.getRelated({ thingId: 'user_1' })
673
- );
674
-
675
- expect(result).toEqual(mockConnections);
676
- });
677
-
678
- it('should filter by connection type', async () => {
679
- mockClient.query.mockResolvedValue([]);
680
-
681
- await Effect.runPromise(
682
- provider.connections.getRelated({ thingId: 'user_1', type: 'owns' })
683
- );
684
-
685
- expect(mockClient.query).toHaveBeenCalledWith(
686
- api.queries.connections.getRelated,
687
- { thingId: 'user_1', type: 'owns' }
688
- );
689
- });
690
-
691
- it('should return empty array when no connections', async () => {
692
- mockClient.query.mockResolvedValue([]);
693
-
694
- const result = await Effect.runPromise(
695
- provider.connections.getRelated({ thingId: 'user_new' })
696
- );
697
-
698
- expect(result).toEqual([]);
699
- });
700
- });
701
-
702
- describe('getCount()', () => {
703
- it('should return connection count', async () => {
704
- mockClient.query.mockResolvedValue(5);
705
-
706
- const count = await Effect.runPromise(
707
- provider.connections.getCount({ thingId: 'user_1' })
708
- );
709
-
710
- expect(count).toBe(5);
711
- });
712
-
713
- it('should filter count by type', async () => {
714
- mockClient.query.mockResolvedValue(3);
715
-
716
- const count = await Effect.runPromise(
717
- provider.connections.getCount({ thingId: 'user_1', type: 'owns' })
718
- );
719
-
720
- expect(count).toBe(3);
721
- });
722
-
723
- it('should return 0 for no connections', async () => {
724
- mockClient.query.mockResolvedValue(0);
725
-
726
- const count = await Effect.runPromise(
727
- provider.connections.getCount({ thingId: 'user_new' })
728
- );
729
-
730
- expect(count).toBe(0);
731
- });
732
- });
733
-
734
- describe('delete()', () => {
735
- it('should delete connection', async () => {
736
- mockClient.mutation.mockResolvedValue(undefined);
737
-
738
- await Effect.runPromise(provider.connections.delete('conn_123'));
739
-
740
- expect(mockClient.mutation).toHaveBeenCalledWith(
741
- api.mutations.connections.delete,
742
- { id: 'conn_123' }
743
- );
744
- });
745
-
746
- it('should throw error if connection not found', async () => {
747
- mockClient.mutation.mockRejectedValue(new Error('Not found'));
748
-
749
- await expect(
750
- Effect.runPromise(provider.connections.delete('conn_999'))
751
- ).rejects.toThrow();
752
- });
753
- });
754
- });
755
- ```
756
-
757
- #### 2.3 Events Namespace Tests (10 cases)
758
-
759
- ```typescript
760
- // tests/unit/providers/ConvexProvider.events.test.ts
761
- describe('ConvexProvider.events', () => {
762
- let provider: ConvexProvider;
763
- let mockClient: MockConvexClient;
764
-
765
- beforeEach(() => {
766
- mockClient = new MockConvexClient();
767
- provider = new ConvexProvider(mockClient as any);
768
- });
769
-
770
- describe('log()', () => {
771
- it('should log event successfully', async () => {
772
- mockClient.mutation.mockResolvedValue(undefined);
773
-
774
- await Effect.runPromise(
775
- provider.events.log({
776
- type: 'thing_created',
777
- actorId: 'user_1',
778
- targetId: 'thing_123',
779
- metadata: { source: 'web' },
780
- })
781
- );
782
-
783
- expect(mockClient.mutation).toHaveBeenCalledWith(
784
- api.mutations.events.log,
785
- expect.objectContaining({
786
- type: 'thing_created',
787
- actorId: 'user_1',
788
- targetId: 'thing_123',
789
- timestamp: expect.any(Number),
790
- })
791
- );
792
- });
793
-
794
- it('should include timestamp', async () => {
795
- mockClient.mutation.mockResolvedValue(undefined);
796
-
797
- await Effect.runPromise(
798
- provider.events.log({
799
- type: 'thing_updated',
800
- actorId: 'user_1',
801
- targetId: 'thing_123',
802
- })
803
- );
804
-
805
- expect(mockClient.mutation).toHaveBeenCalledWith(
806
- api.mutations.events.log,
807
- expect.objectContaining({ timestamp: expect.any(Number) })
808
- );
809
- });
810
-
811
- it('should validate event type', async () => {
812
- await expect(
813
- Effect.runPromise(
814
- provider.events.log({
815
- type: '' as any,
816
- actorId: 'user_1',
817
- targetId: 'thing_123',
818
- })
819
- )
820
- ).rejects.toThrow();
821
- });
822
-
823
- it('should support metadata', async () => {
824
- mockClient.mutation.mockResolvedValue(undefined);
825
-
826
- const metadata = { ip: '192.168.1.1', userAgent: 'Mozilla/5.0' };
827
-
828
- await Effect.runPromise(
829
- provider.events.log({
830
- type: 'thing_viewed',
831
- actorId: 'user_1',
832
- targetId: 'thing_123',
833
- metadata,
834
- })
835
- );
836
-
837
- expect(mockClient.mutation).toHaveBeenCalledWith(
838
- api.mutations.events.log,
839
- expect.objectContaining({ metadata })
840
- );
841
- });
842
- });
843
-
844
- describe('query()', () => {
845
- it('should query events', async () => {
846
- const mockEvents = [
847
- { _id: 'evt_1', type: 'thing_created', timestamp: Date.now() },
848
- { _id: 'evt_2', type: 'thing_updated', timestamp: Date.now() },
849
- ];
850
-
851
- mockClient.query.mockResolvedValue(mockEvents);
852
-
853
- const result = await Effect.runPromise(
854
- provider.events.query({ targetId: 'thing_123' })
855
- );
856
-
857
- expect(result).toEqual(mockEvents);
858
- });
859
-
860
- it('should filter by event type', async () => {
861
- mockClient.query.mockResolvedValue([]);
862
-
863
- await Effect.runPromise(
864
- provider.events.query({ targetId: 'thing_123', type: 'thing_created' })
865
- );
866
-
867
- expect(mockClient.query).toHaveBeenCalledWith(
868
- api.queries.events.query,
869
- expect.objectContaining({ type: 'thing_created' })
870
- );
871
- });
872
-
873
- it('should filter by date range', async () => {
874
- mockClient.query.mockResolvedValue([]);
875
-
876
- const from = Date.now() - 86400000;
877
- const to = Date.now();
878
-
879
- await Effect.runPromise(
880
- provider.events.query({ targetId: 'thing_123', from, to })
881
- );
882
-
883
- expect(mockClient.query).toHaveBeenCalledWith(
884
- api.queries.events.query,
885
- expect.objectContaining({ from, to })
886
- );
887
- });
888
- });
889
- });
890
- ```
891
-
892
- #### 2.4 Knowledge Namespace Tests (8 cases)
893
-
894
- ```typescript
895
- // tests/unit/providers/ConvexProvider.knowledge.test.ts
896
- describe('ConvexProvider.knowledge', () => {
897
- let provider: ConvexProvider;
898
- let mockClient: MockConvexClient;
899
-
900
- beforeEach(() => {
901
- mockClient = new MockConvexClient();
902
- provider = new ConvexProvider(mockClient as any);
903
- });
904
-
905
- describe('embed()', () => {
906
- it('should create embedding and return ID', async () => {
907
- mockClient.mutation.mockResolvedValue('knowledge_123');
908
-
909
- const result = await Effect.runPromise(
910
- provider.knowledge.embed({
911
- text: 'Test content',
912
- thingId: 'thing_123',
913
- labels: ['topic:testing'],
914
- })
915
- );
916
-
917
- expect(result).toBe('knowledge_123');
918
- });
919
-
920
- it('should validate text content', async () => {
921
- await expect(
922
- Effect.runPromise(
923
- provider.knowledge.embed({ text: '', thingId: 'thing_123' })
924
- )
925
- ).rejects.toThrow();
926
- });
927
- });
928
-
929
- describe('search()', () => {
930
- it('should return semantic search results', async () => {
931
- const mockResults = [
932
- { id: 'knowledge_1', text: 'Result 1', score: 0.95 },
933
- { id: 'knowledge_2', text: 'Result 2', score: 0.87 },
934
- ];
935
-
936
- mockClient.query.mockResolvedValue(mockResults);
937
-
938
- const results = await Effect.runPromise(
939
- provider.knowledge.search({ query: 'test query', limit: 10 })
940
- );
941
-
942
- expect(results).toEqual(mockResults);
943
- });
944
-
945
- it('should filter by labels', async () => {
946
- mockClient.query.mockResolvedValue([]);
947
-
948
- await Effect.runPromise(
949
- provider.knowledge.search({
950
- query: 'test',
951
- labels: ['topic:testing'],
952
- limit: 10,
953
- })
954
- );
955
-
956
- expect(mockClient.query).toHaveBeenCalledWith(
957
- api.queries.knowledge.search,
958
- expect.objectContaining({ labels: ['topic:testing'] })
959
- );
960
- });
961
- });
962
- });
963
- ```
964
-
965
- #### 2.5 Subscriptions Tests (12 cases)
966
-
967
- ```typescript
968
- // tests/unit/providers/ConvexProvider.subscriptions.test.ts
969
- describe('ConvexProvider.subscriptions', () => {
970
- let provider: ConvexProvider;
971
- let mockClient: MockConvexClient;
972
-
973
- beforeEach(() => {
974
- mockClient = new MockConvexClient();
975
- provider = new ConvexProvider(mockClient as any);
976
- });
977
-
978
- describe('subscribeToThings()', () => {
979
- it('should subscribe to thing updates', async () => {
980
- const callback = vi.fn();
981
- const mockUnsubscribe = vi.fn();
982
-
983
- mockClient.subscribe.mockReturnValue(mockUnsubscribe);
984
-
985
- const unsubscribe = provider.subscriptions!.subscribeToThings(
986
- { type: 'product', organizationId: 'org_1' },
987
- callback
988
- );
989
-
990
- expect(mockClient.subscribe).toHaveBeenCalled();
991
- expect(typeof unsubscribe).toBe('function');
992
- });
993
-
994
- it('should call callback on updates', async () => {
995
- const callback = vi.fn();
996
- let updateHandler: any;
997
-
998
- mockClient.subscribe.mockImplementation((query, args, handler) => {
999
- updateHandler = handler;
1000
- return vi.fn();
1001
- });
1002
-
1003
- provider.subscriptions!.subscribeToThings(
1004
- { type: 'product', organizationId: 'org_1' },
1005
- callback
1006
- );
1007
-
1008
- const mockThings = [{ _id: '1', type: 'product', name: 'Product 1' }];
1009
- updateHandler(mockThings);
1010
-
1011
- expect(callback).toHaveBeenCalledWith(mockThings[0]);
1012
- });
1013
-
1014
- it('should unsubscribe when called', async () => {
1015
- const callback = vi.fn();
1016
- const mockUnsubscribe = vi.fn();
1017
-
1018
- mockClient.subscribe.mockReturnValue(mockUnsubscribe);
1019
-
1020
- const unsubscribe = provider.subscriptions!.subscribeToThings(
1021
- { type: 'product', organizationId: 'org_1' },
1022
- callback
1023
- );
1024
-
1025
- unsubscribe();
1026
-
1027
- expect(mockUnsubscribe).toHaveBeenCalled();
1028
- });
1029
-
1030
- it('should handle subscription errors', async () => {
1031
- const callback = vi.fn();
1032
- mockClient.subscribe.mockImplementation(() => {
1033
- throw new Error('Subscription failed');
1034
- });
1035
-
1036
- expect(() =>
1037
- provider.subscriptions!.subscribeToThings(
1038
- { type: 'product', organizationId: 'org_1' },
1039
- callback
1040
- )
1041
- ).toThrow('Subscription failed');
1042
- });
1043
- });
1044
-
1045
- describe('subscribeToConnections()', () => {
1046
- it('should subscribe to connection updates', async () => {
1047
- const callback = vi.fn();
1048
- const mockUnsubscribe = vi.fn();
1049
-
1050
- mockClient.subscribe.mockReturnValue(mockUnsubscribe);
1051
-
1052
- const unsubscribe = provider.subscriptions!.subscribeToConnections(
1053
- { thingId: 'thing_123' },
1054
- callback
1055
- );
1056
-
1057
- expect(mockClient.subscribe).toHaveBeenCalled();
1058
- expect(typeof unsubscribe).toBe('function');
1059
- });
1060
-
1061
- it('should call callback on connection changes', async () => {
1062
- const callback = vi.fn();
1063
- let updateHandler: any;
1064
-
1065
- mockClient.subscribe.mockImplementation((query, args, handler) => {
1066
- updateHandler = handler;
1067
- return vi.fn();
1068
- });
1069
-
1070
- provider.subscriptions!.subscribeToConnections(
1071
- { thingId: 'thing_123' },
1072
- callback
1073
- );
1074
-
1075
- const mockConnections = [{ _id: 'conn_1', type: 'owns' }];
1076
- updateHandler(mockConnections);
1077
-
1078
- expect(callback).toHaveBeenCalledWith(mockConnections[0]);
1079
- });
1080
- });
1081
- });
1082
- ```
1083
-
1084
- ### 3. Error Handling Tests (10 cases)
1085
-
1086
- ```typescript
1087
- // tests/unit/providers/errors.test.ts
1088
- import { describe, it, expect } from 'vitest';
1089
- import {
1090
- DataProviderError,
1091
- ThingNotFoundError,
1092
- OrganizationNotFoundError,
1093
- ConnectionCreateError,
1094
- } from '@/providers/errors';
1095
-
1096
- describe('Error Types', () => {
1097
- describe('DataProviderError', () => {
1098
- it('should create base error', () => {
1099
- const error = new DataProviderError('Test error', 'TEST_CODE', 'convex');
1100
-
1101
- expect(error.message).toBe('Test error');
1102
- expect(error.code).toBe('TEST_CODE');
1103
- expect(error.provider).toBe('convex');
1104
- expect(error._tag).toBe('DataProviderError');
1105
- });
1106
-
1107
- it('should be instanceof Error', () => {
1108
- const error = new DataProviderError('Test', 'CODE', 'provider');
1109
-
1110
- expect(error).toBeInstanceOf(Error);
1111
- expect(error).toBeInstanceOf(DataProviderError);
1112
- });
1113
- });
1114
-
1115
- describe('ThingNotFoundError', () => {
1116
- it('should create thing not found error', () => {
1117
- const error = new ThingNotFoundError('thing_123', 'Not in database');
1118
-
1119
- expect(error.thingId).toBe('thing_123');
1120
- expect(error.message).toContain('thing_123');
1121
- expect(error._tag).toBe('ThingNotFoundError');
1122
- expect(error.code).toBe('THING_NOT_FOUND');
1123
- });
1124
-
1125
- it('should include optional details', () => {
1126
- const error = new ThingNotFoundError('thing_123', 'Database offline');
1127
-
1128
- expect(error.message).toContain('Database offline');
1129
- });
1130
- });
1131
-
1132
- describe('OrganizationNotFoundError', () => {
1133
- it('should create org not found error', () => {
1134
- const error = new OrganizationNotFoundError('org_123');
1135
-
1136
- expect(error.organizationId).toBe('org_123');
1137
- expect(error._tag).toBe('OrganizationNotFoundError');
1138
- });
1139
- });
1140
- });
1141
- ```
1142
-
1143
- ---
1144
-
1145
- ## Integration Tests
1146
-
1147
- ### 1. Full CRUD Flow Tests
1148
-
1149
- ```typescript
1150
- // tests/integration/convexProvider.test.ts
1151
- import { describe, it, expect, beforeAll, afterAll } from 'vitest';
1152
- import { ConvexHttpClient } from 'convex/browser';
1153
- import { ConvexProvider } from '@/providers/convex/ConvexProvider';
1154
- import { Effect } from 'effect';
1155
-
1156
- describe('ConvexProvider Integration', () => {
1157
- let provider: ConvexProvider;
1158
- let client: ConvexHttpClient;
1159
-
1160
- beforeAll(() => {
1161
- client = new ConvexHttpClient(process.env.TEST_CONVEX_URL!);
1162
- provider = new ConvexProvider(client);
1163
- });
1164
-
1165
- afterAll(() => {
1166
- client.close();
1167
- });
1168
-
1169
- describe('Things CRUD Flow', () => {
1170
- it('should complete full CRUD lifecycle', async () => {
1171
- // CREATE
1172
- const createInput = {
1173
- type: 'product' as const,
1174
- name: 'Test Product',
1175
- properties: { price: 99.99 },
1176
- organizationId: 'org_test',
1177
- };
1178
-
1179
- const thingId = await Effect.runPromise(provider.things.create(createInput));
1180
- expect(thingId).toBeTruthy();
1181
-
1182
- // READ
1183
- const thing = await Effect.runPromise(provider.things.get(thingId));
1184
- expect(thing.name).toBe('Test Product');
1185
- expect(thing.properties.price).toBe(99.99);
1186
-
1187
- // UPDATE
1188
- const updated = await Effect.runPromise(
1189
- provider.things.update(thingId, { name: 'Updated Product' })
1190
- );
1191
- expect(updated.name).toBe('Updated Product');
1192
-
1193
- // LIST
1194
- const list = await Effect.runPromise(
1195
- provider.things.list({ type: 'product', organizationId: 'org_test' })
1196
- );
1197
- expect(list.some((t) => t._id === thingId)).toBe(true);
1198
-
1199
- // DELETE
1200
- await Effect.runPromise(provider.things.delete(thingId));
1201
-
1202
- // VERIFY DELETED
1203
- await expect(Effect.runPromise(provider.things.get(thingId))).rejects.toThrow();
1204
- });
1205
- });
1206
-
1207
- describe('Connections Flow', () => {
1208
- it('should create and query connections', async () => {
1209
- // Create two things
1210
- const userId = await Effect.runPromise(
1211
- provider.things.create({
1212
- type: 'creator',
1213
- name: 'User',
1214
- organizationId: 'org_test',
1215
- })
1216
- );
1217
-
1218
- const productId = await Effect.runPromise(
1219
- provider.things.create({
1220
- type: 'product',
1221
- name: 'Product',
1222
- organizationId: 'org_test',
1223
- })
1224
- );
1225
-
1226
- // Create connection
1227
- const connId = await Effect.runPromise(
1228
- provider.connections.create({
1229
- fromThingId: userId,
1230
- toThingId: productId,
1231
- type: 'owns',
1232
- })
1233
- );
1234
-
1235
- expect(connId).toBeTruthy();
1236
-
1237
- // Query connections
1238
- const connections = await Effect.runPromise(
1239
- provider.connections.getRelated({ thingId: userId })
1240
- );
1241
-
1242
- expect(connections).toHaveLength(1);
1243
- expect(connections[0].toThingId).toBe(productId);
1244
-
1245
- // Count connections
1246
- const count = await Effect.runPromise(
1247
- provider.connections.getCount({ thingId: userId })
1248
- );
1249
-
1250
- expect(count).toBe(1);
1251
-
1252
- // Cleanup
1253
- await Effect.runPromise(provider.connections.delete(connId));
1254
- await Effect.runPromise(provider.things.delete(userId));
1255
- await Effect.runPromise(provider.things.delete(productId));
1256
- });
1257
- });
1258
-
1259
- describe('Events Flow', () => {
1260
- it('should log and query events', async () => {
1261
- const thingId = await Effect.runPromise(
1262
- provider.things.create({
1263
- type: 'product',
1264
- name: 'Product',
1265
- organizationId: 'org_test',
1266
- })
1267
- );
1268
-
1269
- // Log event
1270
- await Effect.runPromise(
1271
- provider.events.log({
1272
- type: 'thing_viewed',
1273
- actorId: 'user_test',
1274
- targetId: thingId,
1275
- metadata: { ip: '127.0.0.1' },
1276
- })
1277
- );
1278
-
1279
- // Query events
1280
- const events = await Effect.runPromise(
1281
- provider.events.query({ targetId: thingId })
1282
- );
1283
-
1284
- expect(events.length).toBeGreaterThan(0);
1285
- expect(events.some((e) => e.type === 'thing_viewed')).toBe(true);
1286
-
1287
- // Cleanup
1288
- await Effect.runPromise(provider.things.delete(thingId));
1289
- });
1290
- });
1291
- });
1292
- ```
1293
-
1294
- ### 2. Real-time Subscription Tests
1295
-
1296
- ```typescript
1297
- // tests/integration/subscriptions.test.ts
1298
- describe('Real-time Subscriptions', () => {
1299
- let provider: ConvexProvider;
1300
- let client: ConvexHttpClient;
1301
-
1302
- beforeAll(() => {
1303
- client = new ConvexHttpClient(process.env.TEST_CONVEX_URL!);
1304
- provider = new ConvexProvider(client);
1305
- });
1306
-
1307
- afterAll(() => {
1308
- client.close();
1309
- });
1310
-
1311
- it('should receive real-time updates', async () => {
1312
- const updates: any[] = [];
1313
- const organizationId = 'org_test';
1314
-
1315
- // Subscribe
1316
- const unsubscribe = provider.subscriptions!.subscribeToThings(
1317
- { type: 'product', organizationId },
1318
- (thing) => {
1319
- updates.push(thing);
1320
- }
1321
- );
1322
-
1323
- // Wait for initial subscription
1324
- await new Promise((resolve) => setTimeout(resolve, 1000));
1325
-
1326
- // Create thing (should trigger update)
1327
- const thingId = await Effect.runPromise(
1328
- provider.things.create({
1329
- type: 'product',
1330
- name: 'Subscription Test',
1331
- organizationId,
1332
- })
1333
- );
1334
-
1335
- // Wait for update
1336
- await new Promise((resolve) => setTimeout(resolve, 2000));
1337
-
1338
- expect(updates.length).toBeGreaterThan(0);
1339
- expect(updates.some((u) => u._id === thingId)).toBe(true);
1340
-
1341
- // Cleanup
1342
- unsubscribe();
1343
- await Effect.runPromise(provider.things.delete(thingId));
1344
- });
1345
- });
1346
- ```
1347
-
1348
- ---
1349
-
1350
- ## Performance Tests
1351
-
1352
- ```typescript
1353
- // tests/performance/provider.bench.ts
1354
- import { describe, bench } from 'vitest';
1355
- import { Effect } from 'effect';
1356
- import { ConvexProvider } from '@/providers/convex/ConvexProvider';
1357
-
1358
- describe('ConvexProvider Performance', () => {
1359
- const provider = new ConvexProvider(/* ... */);
1360
-
1361
- bench('things.get() overhead', async () => {
1362
- await Effect.runPromise(provider.things.get('thing_123'));
1363
- }, {
1364
- time: 5000, // 5 seconds
1365
- iterations: 1000,
1366
- });
1367
-
1368
- bench('things.list() overhead', async () => {
1369
- await Effect.runPromise(provider.things.list({ type: 'product' }));
1370
- }, {
1371
- time: 5000,
1372
- iterations: 500,
1373
- });
1374
-
1375
- bench('connections.create() overhead', async () => {
1376
- await Effect.runPromise(
1377
- provider.connections.create({
1378
- fromThingId: 'thing_1',
1379
- toThingId: 'thing_2',
1380
- type: 'owns',
1381
- })
1382
- );
1383
- }, {
1384
- time: 5000,
1385
- iterations: 500,
1386
- });
1387
- });
1388
- ```
1389
-
1390
- ---
1391
-
1392
- ## Test Data & Fixtures
1393
-
1394
- ```typescript
1395
- // tests/fixtures/things.ts
1396
- export const mockThings = {
1397
- product: {
1398
- _id: 'thing_product_1',
1399
- type: 'product',
1400
- name: 'Test Product',
1401
- properties: { price: 99.99, stock: 100 },
1402
- status: 'active',
1403
- organizationId: 'org_test',
1404
- createdAt: 1704067200000,
1405
- updatedAt: 1704067200000,
1406
- },
1407
- user: {
1408
- _id: 'thing_user_1',
1409
- type: 'creator',
1410
- name: 'Test User',
1411
- properties: { email: 'test@example.com' },
1412
- status: 'active',
1413
- organizationId: 'org_test',
1414
- createdAt: 1704067200000,
1415
- updatedAt: 1704067200000,
1416
- },
1417
- };
1418
-
1419
- export const mockConnections = [
1420
- {
1421
- _id: 'conn_1',
1422
- fromThingId: 'thing_user_1',
1423
- toThingId: 'thing_product_1',
1424
- type: 'owns',
1425
- metadata: { purchasedAt: 1704067200000 },
1426
- createdAt: 1704067200000,
1427
- },
1428
- ];
1429
- ```
1430
-
1431
- ---
1432
-
1433
- ## CI/CD Integration
1434
-
1435
- ```yaml
1436
- # .github/workflows/test-dataprovider.yml
1437
- name: DataProvider Tests
1438
-
1439
- on:
1440
- push:
1441
- paths:
1442
- - 'src/providers/**'
1443
- - 'tests/unit/providers/**'
1444
- - 'tests/integration/convexProvider.test.ts'
1445
-
1446
- jobs:
1447
- test:
1448
- runs-on: ubuntu-latest
1449
- steps:
1450
- - uses: actions/checkout@v3
1451
- - uses: oven-sh/setup-bun@v1
1452
-
1453
- - name: Install dependencies
1454
- run: bun install
1455
-
1456
- - name: Run unit tests
1457
- run: bun test tests/unit/providers
1458
-
1459
- - name: Run integration tests
1460
- run: bun test tests/integration/convexProvider.test.ts
1461
- env:
1462
- TEST_CONVEX_URL: ${{ secrets.TEST_CONVEX_URL }}
1463
-
1464
- - name: Upload coverage
1465
- uses: codecov/codecov-action@v3
1466
- with:
1467
- files: ./coverage/lcov.info
1468
- ```
1469
-
1470
- ---
1471
-
1472
- ## Quality Gates
1473
-
1474
- ### Gate 1: Unit Tests
1475
-
1476
- - [ ] All DataProvider interface types compile
1477
- - [ ] All ConvexProvider methods implemented
1478
- - [ ] 90%+ code coverage
1479
- - [ ] All error types tested
1480
- - [ ] All subscription methods tested
1481
- - [ ] No TypeScript errors
1482
- - [ ] All tests pass (100%)
1483
-
1484
- ### Gate 2: Integration Tests
1485
-
1486
- - [ ] Full CRUD flow passes
1487
- - [ ] Real-time subscriptions work
1488
- - [ ] All 6 dimensions tested
1489
- - [ ] Performance <10ms overhead measured
1490
- - [ ] Memory leaks checked (no leaks)
1491
- - [ ] All tests pass (100%)
1492
-
1493
- ### Gate 3: Backward Compatibility
1494
-
1495
- - [ ] All 50+ existing auth tests pass UNCHANGED
1496
- - [ ] No breaking changes to public API
1497
- - [ ] Existing Convex hooks work
1498
- - [ ] Zero production incidents
1499
-
1500
- ### Gate 4: Performance
1501
-
1502
- - [ ] things.get() <10ms overhead
1503
- - [ ] things.list() <20ms overhead
1504
- - [ ] connections.create() <15ms overhead
1505
- - [ ] Subscription setup <50ms
1506
- - [ ] Memory usage stable (no leaks)
1507
-
1508
- ### Gate 5: Code Quality
1509
-
1510
- - [ ] ESLint passes (zero errors)
1511
- - [ ] Prettier formatted
1512
- - [ ] TSDoc comments complete
1513
- - [ ] Code review approved by 2+ developers
1514
-
1515
- ---
1516
-
1517
- **Total Test Count:** 120+ test cases
1518
- **Estimated Implementation Time:** 3-4 days
1519
- **Coverage Target:** 95%+ unit, 85%+ integration
1520
- **Performance Target:** <10ms overhead per operation
1521
-
1522
- **Status:** ✅ Ready for Implementation