oneie 2.0.3 → 2.0.5

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 (75) hide show
  1. package/CLAUDE.md +220 -29
  2. package/LICENSE.md +84 -0
  3. package/README.md +489 -931
  4. package/folders.yaml +78 -17
  5. package/one/.obsidian/workspace.json +6 -6
  6. package/one/events/CASCADE-2-BACKEND-AGNOSTIC.md +412 -0
  7. package/one/events/FEATURE-2-4-COMPLETE.md +302 -0
  8. package/one/events/FEATURE_2_3_COMPLETE.md +575 -0
  9. package/one/events/GROUPS-MIGRATION.md +625 -0
  10. package/one/events/INSTALL-TESTS.md +293 -0
  11. package/one/events/INTEGRATION-ARCHITECTURE.md +561 -0
  12. package/one/events/INTEGRATION-CHECKLIST.md +1234 -0
  13. package/one/events/INTEGRATION-ORCHESTRATION.md +2623 -0
  14. package/one/events/INTEGRATION-SUMMARY.md +653 -0
  15. package/one/events/MIGRATION-REPORT.md +435 -0
  16. package/one/events/MIGRATION.md +69 -0
  17. package/one/events/README-archived.md +519 -0
  18. package/one/events/TEST-SUMMARY.md +393 -0
  19. package/one/events/TESTS-QUICK-REF.md +262 -0
  20. package/one/groups/groups.md +543 -0
  21. package/one/knowledge/CLOUDFLARE_ENV_SETUP.md +49 -0
  22. package/one/knowledge/architecture-any-backend.md +1366 -0
  23. package/one/knowledge/docs/flow.md +0 -0
  24. package/one/knowledge/ontology-documentation.md +18 -18
  25. package/one/knowledge/ontology.md +154 -143
  26. package/one/knowledge/ontology.md.backup +2822 -0
  27. package/one/knowledge/ontology.yaml +87 -87
  28. package/one/knowledge/provider-creation-guide.md +1064 -0
  29. package/one/knowledge/todo.md +251 -0
  30. package/one/license.md +84 -0
  31. package/one/things/CHECKLIST.md +356 -0
  32. package/one/things/ONE.md +510 -0
  33. package/one/things/{cli.md → cli/cli.md} +27 -4
  34. package/one/things/features/2-1-dataprovider-interface.md +2358 -0
  35. package/one/things/features/2-2-config-system.md +3075 -0
  36. package/one/things/features/2-3-effectts-services.md +1498 -0
  37. package/one/things/features/2-4-react-hooks.md +2120 -0
  38. package/one/things/features/2-5-auth-migration.md +2046 -0
  39. package/one/things/features/2-6-dashboard-migration.md +1985 -0
  40. package/one/things/features/2-7-alternative-providers.md +2505 -0
  41. package/one/things/features/2-7-implementation-report.md +680 -0
  42. package/one/things/features/2-cli.md +39 -39
  43. package/one/things/features/2-design.md +1738 -0
  44. package/one/things/features/2-tests.md +520 -0
  45. package/one/things/features/AUTH_HOOKS_IMPLEMENTATION.md +521 -0
  46. package/one/things/features/DECOUPLING.md +272 -0
  47. package/one/things/features/DEPLOYMENT.md +452 -0
  48. package/one/things/features/IMPLEMENTATION_SUMMARY.md +316 -0
  49. package/one/things/features/dataprovider-interface/1-tests.md +1522 -0
  50. package/one/things/features/improve.md +843 -0
  51. package/one/things/features/remove-convex-deps.md +45 -0
  52. package/one/things/features/top-features.md +79 -0
  53. package/one/things/ideas/2-backend-agnostic-frontend.md +384 -0
  54. package/one/things/plans/2-backend-agnostic-frontend.md +543 -0
  55. package/one/things/plans/3-groups.md +502 -0
  56. package/one/things/plans/backend-agnostic-frontend.md +323 -0
  57. package/one/things/plans/deploy-to-cloudflare.md +581 -0
  58. package/one/things/plans/organizations-to-groups.md +705 -0
  59. package/one/things/plans/release.md +432 -0
  60. package/one/things/products/ontology.md +1 -1
  61. package/one/things/system.md +600 -0
  62. package/one/things/tests/2-1-dataprovider-interface.md +1144 -0
  63. package/one/things/tests/2-1-test-analysis.md +496 -0
  64. package/one/things/vision/elegant-interface.md +214 -0
  65. package/package.json +1 -1
  66. package/one/organisation/organisation.md +0 -438
  67. package/one/repomix-output.md +0 -92634
  68. /package/one/{things → connections}/agentkit.md +0 -0
  69. /package/one/{things → connections}/copilotkit.md +0 -0
  70. /package/one/{organisation → groups}/one.md +0 -0
  71. /package/one/{organisation → groups}/revenue.md +0 -0
  72. /package/one/{organisation → groups}/strategy.md +0 -0
  73. /package/one/{organisation → groups}/vision.md +0 -0
  74. /package/one/things/{cli-code.md → cli/cli-code.md} +0 -0
  75. /package/one/things/{cli-compiler-code.md → cli/cli-compiler-code.md} +0 -0
@@ -0,0 +1,1144 @@
1
+ # Test Specification: Feature 2-1 - DataProvider Interface & ConvexProvider
2
+
3
+ **Feature ID:** `2-1-dataprovider-interface`
4
+ **Plan:** Backend-Agnostic Frontend Architecture
5
+ **Status:** Ready for Implementation
6
+ **Created:** 2025-10-13
7
+ **Quality Agent:** Claude (Intelligence Agent)
8
+
9
+ ---
10
+
11
+ ## Executive Summary
12
+
13
+ This document defines comprehensive tests for the DataProvider interface and ConvexProvider implementation BEFORE implementation begins. The tests validate that the backend abstraction layer correctly implements all 6 ontology dimensions while maintaining zero functionality regression from current Convex SDK usage.
14
+
15
+ **Success Criteria:**
16
+ - [ ] 90%+ unit test coverage
17
+ - [ ] 80%+ integration test coverage
18
+ - [ ] All 6-dimension operations fully tested
19
+ - [ ] Performance overhead <10ms per operation
20
+ - [ ] Zero TypeScript errors
21
+ - [ ] ConvexProvider passes all existing auth tests (50+)
22
+
23
+ ---
24
+
25
+ ## Test Categories
26
+
27
+ ### Category 1: Interface Contract Tests (Unit)
28
+ Tests the DataProvider interface definition and type contracts.
29
+
30
+ ### Category 2: ConvexProvider Tests (Unit)
31
+ Tests the ConvexProvider implementation wrapping Convex SDK.
32
+
33
+ ### Category 3: Integration Tests
34
+ Tests full data flow through provider with real backend.
35
+
36
+ ### Category 4: Performance Tests
37
+ Tests performance overhead of abstraction layer.
38
+
39
+ ### Category 5: Error Handling Tests
40
+ Tests typed error patterns and edge cases.
41
+
42
+ ### Category 6: Real-time Subscription Tests
43
+ Tests reactive data subscriptions through provider.
44
+
45
+ ---
46
+
47
+ ## Ontology Coverage Matrix
48
+
49
+ | Dimension | CRUD Operations | Real-time | Auth | Multi-tenant |
50
+ |-----------|----------------|-----------|------|--------------|
51
+ | Organizations | ✅ | ✅ | ✅ | ✅ |
52
+ | People | ✅ | ✅ | ✅ | ✅ |
53
+ | Things | ✅ | ✅ | ✅ | ✅ |
54
+ | Connections | ✅ | ✅ | ✅ | ✅ |
55
+ | Events | ✅ | ✅ | ✅ | ✅ |
56
+ | Knowledge | ✅ | ✅ | ✅ | ✅ |
57
+
58
+ **Total Operations to Test:** 6 dimensions × 5 operations = 30+ test cases
59
+
60
+ ---
61
+
62
+ ## Category 1: Interface Contract Tests (Unit)
63
+
64
+ ### 1.1 Type Safety Tests
65
+
66
+ **Test:** DataProvider interface type definitions
67
+ ```typescript
68
+ describe("DataProvider Interface Types", () => {
69
+ it("should define all 6-dimension operations", () => {
70
+ // Verify interface has: organizations, people, things, connections, events, knowledge
71
+ });
72
+
73
+ it("should type all CRUD operations correctly", () => {
74
+ // Verify get, list, create, update, delete signatures
75
+ });
76
+
77
+ it("should use Effect.ts for all operations", () => {
78
+ // Verify return types are Effect<Success, Error, Never>
79
+ });
80
+
81
+ it("should define typed errors with _tag pattern", () => {
82
+ // Verify ThingNotFoundError, CreateError, QueryError, etc.
83
+ });
84
+ });
85
+ ```
86
+
87
+ **Expected Behavior:**
88
+ - All operations return `Effect<T, E, never>`
89
+ - All errors extend base `DataProviderError` with `_tag` field
90
+ - Type inference works correctly (no `any` types)
91
+ - Autocomplete works in IDE
92
+
93
+ **Performance:** N/A (type-only)
94
+ **Coverage Target:** 100%
95
+
96
+ ---
97
+
98
+ ### 1.2 Organizations Dimension Tests
99
+
100
+ **Test Suite:** Organizations CRUD
101
+ ```typescript
102
+ describe("DataProvider.organizations", () => {
103
+ it("should get organization by id", async () => {
104
+ // Test: provider.organizations.get(orgId)
105
+ // Expected: Returns organization or ThingNotFoundError
106
+ });
107
+
108
+ it("should list organizations with filters", async () => {
109
+ // Test: provider.organizations.list({ plan: "pro" })
110
+ // Expected: Returns filtered array
111
+ });
112
+
113
+ it("should create organization", async () => {
114
+ // Test: provider.organizations.create({ name, plan })
115
+ // Expected: Returns organization id
116
+ });
117
+
118
+ it("should update organization", async () => {
119
+ // Test: provider.organizations.update(id, { plan: "enterprise" })
120
+ // Expected: Updates successfully
121
+ });
122
+
123
+ it("should enforce multi-tenant isolation", async () => {
124
+ // Test: Org A cannot access Org B's data
125
+ // Expected: Returns empty or error
126
+ });
127
+ });
128
+ ```
129
+
130
+ **Expected Behavior:**
131
+ - Organizations table correctly mapped to `things` with `type: "organization"`
132
+ - Multi-tenant filtering automatic
133
+ - Plan validation (starter/pro/enterprise)
134
+ - Usage tracking accurate
135
+
136
+ **Performance:** <10ms per operation
137
+ **Coverage Target:** 95%
138
+
139
+ ---
140
+
141
+ ### 1.3 People Dimension Tests
142
+
143
+ **Test Suite:** People CRUD & Roles
144
+ ```typescript
145
+ describe("DataProvider.people", () => {
146
+ it("should get person by id", async () => {
147
+ // Test: provider.people.get(personId)
148
+ // Expected: Returns person with role
149
+ });
150
+
151
+ it("should list people by role", async () => {
152
+ // Test: provider.people.list({ role: "org_owner" })
153
+ // Expected: Returns filtered by role
154
+ });
155
+
156
+ it("should list people by organization", async () => {
157
+ // Test: provider.people.list({ organizationId })
158
+ // Expected: Returns org members only
159
+ });
160
+
161
+ it("should enforce 4 roles: platform_owner, org_owner, org_user, customer", () => {
162
+ // Test: Role validation
163
+ // Expected: Rejects invalid roles
164
+ });
165
+
166
+ it("should link people to organizations via connections", async () => {
167
+ // Test: provider.connections.create({ person → org, type: "member_of" })
168
+ // Expected: Creates membership connection
169
+ });
170
+ });
171
+ ```
172
+
173
+ **Expected Behavior:**
174
+ - People represented as `things` with `type: "creator"` and `properties.role`
175
+ - Role validation strict (4 roles only)
176
+ - Organization membership via `connections`
177
+ - Authorization checks included
178
+
179
+ **Performance:** <10ms per operation
180
+ **Coverage Target:** 95%
181
+
182
+ ---
183
+
184
+ ### 1.4 Things Dimension Tests
185
+
186
+ **Test Suite:** Things CRUD for all 66 types
187
+ ```typescript
188
+ describe("DataProvider.things", () => {
189
+ it("should create thing with correct type", async () => {
190
+ // Test: provider.things.create({ type: "blog_post", name, properties })
191
+ // Expected: Returns thing id
192
+ });
193
+
194
+ it("should get thing by id", async () => {
195
+ // Test: provider.things.get(thingId)
196
+ // Expected: Returns thing or ThingNotFoundError
197
+ });
198
+
199
+ it("should list things by type", async () => {
200
+ // Test: provider.things.list({ type: "course" })
201
+ // Expected: Returns all courses
202
+ });
203
+
204
+ it("should list things by status", async () => {
205
+ // Test: provider.things.list({ status: "published" })
206
+ // Expected: Returns published things only
207
+ });
208
+
209
+ it("should update thing properties", async () => {
210
+ // Test: provider.things.update(id, { properties: {...} })
211
+ // Expected: Merges properties correctly
212
+ });
213
+
214
+ it("should soft delete thing (set deletedAt)", async () => {
215
+ // Test: provider.things.delete(id)
216
+ // Expected: Sets deletedAt timestamp
217
+ });
218
+
219
+ it("should support all 66 thing types", async () => {
220
+ // Test: Create one of each type
221
+ // Expected: All types validate correctly
222
+ });
223
+
224
+ it("should validate thing type enum", () => {
225
+ // Test: Invalid type rejected
226
+ // Expected: ThingTypeError
227
+ });
228
+ });
229
+ ```
230
+
231
+ **Expected Behavior:**
232
+ - All 66 thing types supported
233
+ - Type validation strict
234
+ - Properties flexible (any JSON)
235
+ - Status lifecycle: draft → active → published → archived
236
+ - Soft delete (deletedAt)
237
+
238
+ **Performance:** <10ms per operation
239
+ **Coverage Target:** 90%
240
+
241
+ ---
242
+
243
+ ### 1.5 Connections Dimension Tests
244
+
245
+ **Test Suite:** Connections CRUD for all 25 types
246
+ ```typescript
247
+ describe("DataProvider.connections", () => {
248
+ it("should create connection between things", async () => {
249
+ // Test: provider.connections.create({ fromThingId, toThingId, relationshipType: "owns" })
250
+ // Expected: Returns connection id
251
+ });
252
+
253
+ it("should get connection by id", async () => {
254
+ // Test: provider.connections.get(connectionId)
255
+ // Expected: Returns connection or NotFoundError
256
+ });
257
+
258
+ it("should list connections from a thing", async () => {
259
+ // Test: provider.connections.list({ fromThingId })
260
+ // Expected: Returns all outgoing connections
261
+ });
262
+
263
+ it("should list connections to a thing", async () => {
264
+ // Test: provider.connections.list({ toThingId })
265
+ // Expected: Returns all incoming connections
266
+ });
267
+
268
+ it("should list connections by type", async () => {
269
+ // Test: provider.connections.list({ relationshipType: "authored" })
270
+ // Expected: Returns filtered connections
271
+ });
272
+
273
+ it("should delete connection", async () => {
274
+ // Test: provider.connections.delete(connectionId)
275
+ // Expected: Removes connection
276
+ });
277
+
278
+ it("should support metadata on connections", async () => {
279
+ // Test: Create connection with metadata: { balance: 100 }
280
+ // Expected: Metadata stored correctly
281
+ });
282
+
283
+ it("should support temporal validity (validFrom/validTo)", async () => {
284
+ // Test: Create connection with validFrom, validTo
285
+ // Expected: Timestamps stored
286
+ });
287
+
288
+ it("should support all 25 relationship types", async () => {
289
+ // Test: Create one of each type
290
+ // Expected: All types validate correctly
291
+ });
292
+
293
+ it("should prevent self-connections (unless justified)", () => {
294
+ // Test: fromThingId === toThingId
295
+ // Expected: SelfConnectionError (or allow with justification)
296
+ });
297
+ });
298
+ ```
299
+
300
+ **Expected Behavior:**
301
+ - All 25 connection types supported
302
+ - Bidirectional queries efficient (indexes)
303
+ - Metadata flexible (JSON)
304
+ - Temporal validity optional
305
+ - Self-connections validated
306
+
307
+ **Performance:** <10ms per operation
308
+ **Coverage Target:** 90%
309
+
310
+ ---
311
+
312
+ ### 1.6 Events Dimension Tests
313
+
314
+ **Test Suite:** Events CRUD for all 67 types
315
+ ```typescript
316
+ describe("DataProvider.events", () => {
317
+ it("should create event with actor and target", async () => {
318
+ // Test: provider.events.create({ type: "entity_created", actorId, targetId })
319
+ // Expected: Returns event id
320
+ });
321
+
322
+ it("should get event by id", async () => {
323
+ // Test: provider.events.get(eventId)
324
+ // Expected: Returns event or NotFoundError
325
+ });
326
+
327
+ it("should list events by type", async () => {
328
+ // Test: provider.events.list({ type: "payment_event" })
329
+ // Expected: Returns filtered events
330
+ });
331
+
332
+ it("should list events by actor", async () => {
333
+ // Test: provider.events.list({ actorId })
334
+ // Expected: Returns user's actions
335
+ });
336
+
337
+ it("should list events by target", async () => {
338
+ // Test: provider.events.list({ targetId })
339
+ // Expected: Returns events affecting target
340
+ });
341
+
342
+ it("should list events with time range", async () => {
343
+ // Test: provider.events.list({ startTime, endTime })
344
+ // Expected: Returns events in range
345
+ });
346
+
347
+ it("should store metadata with events", async () => {
348
+ // Test: Create event with metadata: { amount: 100, currency: "USD" }
349
+ // Expected: Metadata stored correctly
350
+ });
351
+
352
+ it("should support all 67 event types", async () => {
353
+ // Test: Create one of each type
354
+ // Expected: All types validate correctly
355
+ });
356
+
357
+ it("should auto-set timestamp if not provided", () => {
358
+ // Test: Create event without timestamp
359
+ // Expected: Timestamp = Date.now()
360
+ });
361
+ });
362
+ ```
363
+
364
+ **Expected Behavior:**
365
+ - All 67 event types supported
366
+ - Timestamps immutable
367
+ - Metadata flexible (JSON)
368
+ - Complete audit trail
369
+ - Efficient queries by actor/target/type/time
370
+
371
+ **Performance:** <10ms per operation
372
+ **Coverage Target:** 90%
373
+
374
+ ---
375
+
376
+ ### 1.7 Knowledge Dimension Tests
377
+
378
+ **Test Suite:** Knowledge CRUD & RAG
379
+ ```typescript
380
+ describe("DataProvider.knowledge", () => {
381
+ it("should create knowledge item (label)", async () => {
382
+ // Test: provider.knowledge.create({ knowledgeType: "label", text: "industry:fitness" })
383
+ // Expected: Returns knowledge id
384
+ });
385
+
386
+ it("should create knowledge item (chunk with embedding)", async () => {
387
+ // Test: provider.knowledge.create({ knowledgeType: "chunk", text, embedding })
388
+ // Expected: Returns knowledge id
389
+ });
390
+
391
+ it("should get knowledge by id", async () => {
392
+ // Test: provider.knowledge.get(knowledgeId)
393
+ // Expected: Returns knowledge or NotFoundError
394
+ });
395
+
396
+ it("should list knowledge by type", async () => {
397
+ // Test: provider.knowledge.list({ knowledgeType: "label" })
398
+ // Expected: Returns labels only
399
+ });
400
+
401
+ it("should link knowledge to thing", async () => {
402
+ // Test: provider.knowledge.link(thingId, knowledgeId, "label")
403
+ // Expected: Creates thingKnowledge junction
404
+ });
405
+
406
+ it("should search by embedding (vector search)", async () => {
407
+ // Test: provider.knowledge.search(embedding, { limit: 10 })
408
+ // Expected: Returns similar chunks
409
+ });
410
+
411
+ it("should filter search by source thing", async () => {
412
+ // Test: provider.knowledge.search(embedding, { sourceThingId })
413
+ // Expected: Returns chunks from source only
414
+ });
415
+
416
+ it("should support 4 knowledge types: label, document, chunk, vector_only", () => {
417
+ // Test: Create each type
418
+ // Expected: All types validate
419
+ });
420
+ });
421
+ ```
422
+
423
+ **Expected Behavior:**
424
+ - All 4 knowledge types supported
425
+ - Vector search efficient (ANN)
426
+ - Junction table (thingKnowledge) managed
427
+ - Embeddings stored correctly
428
+ - Labels searchable
429
+
430
+ **Performance:** <50ms for vector search, <10ms for others
431
+ **Coverage Target:** 85%
432
+
433
+ ---
434
+
435
+ ## Category 2: ConvexProvider Tests (Unit)
436
+
437
+ ### 2.1 ConvexProvider Implementation Tests
438
+
439
+ **Test Suite:** ConvexProvider wraps Convex SDK correctly
440
+ ```typescript
441
+ describe("ConvexProvider", () => {
442
+ it("should implement DataProvider interface", () => {
443
+ // Test: ConvexProvider satisfies DataProvider type
444
+ // Expected: TypeScript compiles
445
+ });
446
+
447
+ it("should wrap Convex queries correctly", async () => {
448
+ // Test: provider.things.get() calls convex.query(api.queries.things.get)
449
+ // Expected: Correct API call
450
+ });
451
+
452
+ it("should wrap Convex mutations correctly", async () => {
453
+ // Test: provider.things.create() calls convex.mutation(api.mutations.things.create)
454
+ // Expected: Correct API call
455
+ });
456
+
457
+ it("should convert Convex errors to DataProvider errors", async () => {
458
+ // Test: Convex error → typed DataProviderError
459
+ // Expected: Error has _tag field
460
+ });
461
+
462
+ it("should pass auth context to Convex", async () => {
463
+ // Test: Auth token passed to Convex client
464
+ // Expected: Authenticated requests
465
+ });
466
+
467
+ it("should support real-time subscriptions", async () => {
468
+ // Test: useQuery hook through provider
469
+ // Expected: Reactive updates
470
+ });
471
+ });
472
+ ```
473
+
474
+ **Expected Behavior:**
475
+ - Zero functionality regression
476
+ - All existing Convex queries work
477
+ - All existing Convex mutations work
478
+ - Error mapping correct
479
+ - Auth works identically
480
+
481
+ **Performance:** <10ms overhead per operation
482
+ **Coverage Target:** 95%
483
+
484
+ ---
485
+
486
+ ### 2.2 ConvexProvider Auth Integration Tests
487
+
488
+ **Test Suite:** Auth flows through ConvexProvider
489
+ ```typescript
490
+ describe("ConvexProvider Auth", () => {
491
+ it("should pass all 50+ existing auth tests", async () => {
492
+ // Test: Run entire auth test suite with ConvexProvider
493
+ // Expected: All tests pass
494
+ });
495
+
496
+ it("should support email/password auth", async () => {
497
+ // Test: Sign up, sign in through provider
498
+ // Expected: Works identically to direct Convex
499
+ });
500
+
501
+ it("should support OAuth (GitHub, Google)", async () => {
502
+ // Test: OAuth flow through provider
503
+ // Expected: Works identically to direct Convex
504
+ });
505
+
506
+ it("should support magic links", async () => {
507
+ // Test: Magic link flow through provider
508
+ // Expected: Works identically to direct Convex
509
+ });
510
+
511
+ it("should support password reset", async () => {
512
+ // Test: Password reset flow through provider
513
+ // Expected: Works identically to direct Convex
514
+ });
515
+
516
+ it("should support email verification", async () => {
517
+ // Test: Email verification flow through provider
518
+ // Expected: Works identically to direct Convex
519
+ });
520
+
521
+ it("should support 2FA (TOTP)", async () => {
522
+ // Test: 2FA flow through provider
523
+ // Expected: Works identically to direct Convex
524
+ });
525
+ });
526
+ ```
527
+
528
+ **Expected Behavior:**
529
+ - All 50+ auth tests pass
530
+ - Zero regression in auth functionality
531
+ - Better Auth integration unchanged
532
+ - Session management identical
533
+
534
+ **Performance:** Same as baseline
535
+ **Coverage Target:** 100% (all existing tests)
536
+
537
+ ---
538
+
539
+ ## Category 3: Integration Tests
540
+
541
+ ### 3.1 Full Data Flow Tests
542
+
543
+ **Test Suite:** Complete user journeys through provider
544
+ ```typescript
545
+ describe("DataProvider Integration - Full Flows", () => {
546
+ it("should complete user signup → create content → publish flow", async () => {
547
+ // 1. Create user (people dimension)
548
+ // 2. Create organization (organizations dimension)
549
+ // 3. Create membership connection
550
+ // 4. Create blog post (things dimension)
551
+ // 5. Create ownership connection
552
+ // 6. Log creation event
553
+ // 7. Publish blog post
554
+ // 8. Log publish event
555
+ // Expected: Full flow works end-to-end
556
+ });
557
+
558
+ it("should complete token purchase flow", async () => {
559
+ // 1. Get user
560
+ // 2. Get token
561
+ // 3. Create payment (things dimension)
562
+ // 4. Create holds_tokens connection
563
+ // 5. Log payment_event
564
+ // 6. Update token balance
565
+ // Expected: Full flow works end-to-end
566
+ });
567
+
568
+ it("should complete course enrollment flow", async () => {
569
+ // 1. Get user
570
+ // 2. Get course
571
+ // 3. Create enrolled_in connection
572
+ // 4. Log enrollment event
573
+ // 5. Track progress
574
+ // Expected: Full flow works end-to-end
575
+ });
576
+ });
577
+ ```
578
+
579
+ **Expected Behavior:**
580
+ - Multi-step flows work correctly
581
+ - Transactions atomic (if supported)
582
+ - Events logged completely
583
+ - Connections created correctly
584
+
585
+ **Performance:** <100ms for full flow
586
+ **Coverage Target:** 80%
587
+
588
+ ---
589
+
590
+ ### 3.2 Multi-Tenant Isolation Tests
591
+
592
+ **Test Suite:** Organization data isolation
593
+ ```typescript
594
+ describe("DataProvider Integration - Multi-Tenant", () => {
595
+ it("should isolate organization data", async () => {
596
+ // 1. Create Org A with user A
597
+ // 2. Create Org B with user B
598
+ // 3. User A creates thing in Org A
599
+ // 4. User B tries to access Org A's thing
600
+ // Expected: User B cannot access Org A's data
601
+ });
602
+
603
+ it("should isolate organization events", async () => {
604
+ // Test: Org A events not visible to Org B
605
+ // Expected: Events filtered by organization
606
+ });
607
+
608
+ it("should isolate organization connections", async () => {
609
+ // Test: Org A connections not visible to Org B
610
+ // Expected: Connections filtered by organization
611
+ });
612
+
613
+ it("should allow platform_owner to access all orgs", async () => {
614
+ // Test: Platform owner can query across orgs
615
+ // Expected: No isolation for platform_owner role
616
+ });
617
+ });
618
+ ```
619
+
620
+ **Expected Behavior:**
621
+ - Perfect data isolation between orgs
622
+ - Platform owner has full access
623
+ - Org owners have org-level access
624
+ - Org users have limited access
625
+
626
+ **Performance:** <10ms per query (with proper indexes)
627
+ **Coverage Target:** 100% (critical security)
628
+
629
+ ---
630
+
631
+ ### 3.3 Real-time Subscription Tests
632
+
633
+ **Test Suite:** Reactive data updates
634
+ ```typescript
635
+ describe("DataProvider Integration - Real-time", () => {
636
+ it("should update when thing changes", async () => {
637
+ // 1. Subscribe to thing via useQuery
638
+ // 2. Update thing via mutation
639
+ // 3. Verify subscription receives update
640
+ // Expected: Reactive update received
641
+ });
642
+
643
+ it("should update when connection added", async () => {
644
+ // 1. Subscribe to connections list
645
+ // 2. Add new connection
646
+ // 3. Verify subscription receives update
647
+ // Expected: List updates automatically
648
+ });
649
+
650
+ it("should update when event logged", async () => {
651
+ // 1. Subscribe to events list
652
+ // 2. Log new event
653
+ // 3. Verify subscription receives update
654
+ // Expected: List updates automatically
655
+ });
656
+
657
+ it("should unsubscribe correctly", async () => {
658
+ // Test: Component unmounts, subscription closes
659
+ // Expected: No memory leaks
660
+ });
661
+ });
662
+ ```
663
+
664
+ **Expected Behavior:**
665
+ - Real-time updates work correctly
666
+ - Subscriptions clean up properly
667
+ - No memory leaks
668
+ - Performance maintained
669
+
670
+ **Performance:** <50ms latency for updates
671
+ **Coverage Target:** 85%
672
+
673
+ ---
674
+
675
+ ## Category 4: Performance Tests
676
+
677
+ ### 4.1 Operation Performance Tests
678
+
679
+ **Test Suite:** Measure provider overhead
680
+ ```typescript
681
+ describe("DataProvider Performance", () => {
682
+ it("should add <10ms overhead for get operations", async () => {
683
+ // Measure: Direct Convex vs. ConvexProvider
684
+ // Expected: <10ms difference
685
+ });
686
+
687
+ it("should add <10ms overhead for list operations", async () => {
688
+ // Measure: Direct Convex vs. ConvexProvider
689
+ // Expected: <10ms difference
690
+ });
691
+
692
+ it("should add <10ms overhead for create operations", async () => {
693
+ // Measure: Direct Convex vs. ConvexProvider
694
+ // Expected: <10ms difference
695
+ });
696
+
697
+ it("should add <10ms overhead for update operations", async () => {
698
+ // Measure: Direct Convex vs. ConvexProvider
699
+ // Expected: <10ms difference
700
+ });
701
+
702
+ it("should add <10ms overhead for delete operations", async () => {
703
+ // Measure: Direct Convex vs. ConvexProvider
704
+ // Expected: <10ms difference
705
+ });
706
+ });
707
+ ```
708
+
709
+ **Performance Baseline (Direct Convex):**
710
+ - Get: ~5ms
711
+ - List: ~10ms
712
+ - Create: ~15ms
713
+ - Update: ~10ms
714
+ - Delete: ~8ms
715
+
716
+ **Performance Target (ConvexProvider):**
717
+ - Get: <15ms (<10ms overhead)
718
+ - List: <20ms (<10ms overhead)
719
+ - Create: <25ms (<10ms overhead)
720
+ - Update: <20ms (<10ms overhead)
721
+ - Delete: <18ms (<10ms overhead)
722
+
723
+ **Coverage Target:** 100% (all operations measured)
724
+
725
+ ---
726
+
727
+ ### 4.2 Large Dataset Performance Tests
728
+
729
+ **Test Suite:** Performance with scale
730
+ ```typescript
731
+ describe("DataProvider Performance - Scale", () => {
732
+ it("should list 1000 things efficiently", async () => {
733
+ // Test: List 1000 things
734
+ // Expected: <100ms
735
+ });
736
+
737
+ it("should list 1000 connections efficiently", async () => {
738
+ // Test: List 1000 connections from a thing
739
+ // Expected: <100ms
740
+ });
741
+
742
+ it("should list 1000 events efficiently", async () => {
743
+ // Test: List 1000 events for a thing
744
+ // Expected: <100ms
745
+ });
746
+
747
+ it("should handle 100 concurrent requests", async () => {
748
+ // Test: 100 parallel operations
749
+ // Expected: All complete, no errors
750
+ });
751
+ });
752
+ ```
753
+
754
+ **Performance Targets:**
755
+ - 1000 items: <100ms
756
+ - 10,000 items: <500ms
757
+ - 100 concurrent requests: <1000ms total
758
+
759
+ **Coverage Target:** 80%
760
+
761
+ ---
762
+
763
+ ## Category 5: Error Handling Tests
764
+
765
+ ### 5.1 Typed Error Tests
766
+
767
+ **Test Suite:** Error handling patterns
768
+ ```typescript
769
+ describe("DataProvider Error Handling", () => {
770
+ it("should throw ThingNotFoundError for missing thing", async () => {
771
+ // Test: Get non-existent thing
772
+ // Expected: ThingNotFoundError with _tag
773
+ });
774
+
775
+ it("should throw CreateError on creation failure", async () => {
776
+ // Test: Create thing with invalid data
777
+ // Expected: CreateError with _tag and details
778
+ });
779
+
780
+ it("should throw QueryError on query failure", async () => {
781
+ // Test: Query with invalid parameters
782
+ // Expected: QueryError with _tag and details
783
+ });
784
+
785
+ it("should throw AuthError on auth failure", async () => {
786
+ // Test: Unauthorized access
787
+ // Expected: AuthError with _tag
788
+ });
789
+
790
+ it("should throw ValidationError on validation failure", async () => {
791
+ // Test: Invalid input
792
+ // Expected: ValidationError with _tag and field details
793
+ });
794
+
795
+ it("should provide error recovery via Effect.ts", async () => {
796
+ // Test: Effect.catchTag for error handling
797
+ // Expected: Graceful recovery
798
+ });
799
+ });
800
+ ```
801
+
802
+ **Expected Behavior:**
803
+ - All errors have `_tag` field
804
+ - Error messages descriptive
805
+ - Error types exported
806
+ - Effect.ts error handling works
807
+
808
+ **Coverage Target:** 95%
809
+
810
+ ---
811
+
812
+ ### 5.2 Edge Case Tests
813
+
814
+ **Test Suite:** Edge cases and failure modes
815
+ ```typescript
816
+ describe("DataProvider Edge Cases", () => {
817
+ it("should handle network failures gracefully", async () => {
818
+ // Test: Simulate network failure
819
+ // Expected: NetworkError thrown
820
+ });
821
+
822
+ it("should handle timeout errors", async () => {
823
+ // Test: Operation exceeds timeout
824
+ // Expected: TimeoutError thrown
825
+ });
826
+
827
+ it("should handle concurrent updates", async () => {
828
+ // Test: Two updates to same thing
829
+ // Expected: Last write wins or conflict error
830
+ });
831
+
832
+ it("should handle large payloads", async () => {
833
+ // Test: Create thing with 1MB properties
834
+ // Expected: Success or PayloadTooLargeError
835
+ });
836
+
837
+ it("should handle invalid types", async () => {
838
+ // Test: Create thing with invalid type
839
+ // Expected: ValidationError
840
+ });
841
+
842
+ it("should handle circular connections", async () => {
843
+ // Test: A → B → A
844
+ // Expected: Allowed (circular references valid)
845
+ });
846
+ });
847
+ ```
848
+
849
+ **Expected Behavior:**
850
+ - Graceful degradation
851
+ - Clear error messages
852
+ - No silent failures
853
+ - Proper cleanup
854
+
855
+ **Coverage Target:** 85%
856
+
857
+ ---
858
+
859
+ ## Category 6: Real-time Subscription Tests
860
+
861
+ ### 6.1 React Hooks Tests
862
+
863
+ **Test Suite:** useQuery and useMutation hooks
864
+ ```typescript
865
+ describe("DataProvider React Hooks", () => {
866
+ it("should work with useQuery hook", async () => {
867
+ // Test: const things = useQuery(provider.things.list, { type: "blog_post" })
868
+ // Expected: Returns loading, data, error states
869
+ });
870
+
871
+ it("should work with useMutation hook", async () => {
872
+ // Test: const create = useMutation(provider.things.create)
873
+ // Expected: Returns loading, success, error states
874
+ });
875
+
876
+ it("should handle loading state correctly", async () => {
877
+ // Test: useQuery returns undefined while loading
878
+ // Expected: UI shows loading indicator
879
+ });
880
+
881
+ it("should handle error state correctly", async () => {
882
+ // Test: useQuery returns error when query fails
883
+ // Expected: UI shows error message
884
+ });
885
+
886
+ it("should refetch on parameter change", async () => {
887
+ // Test: Change query parameters
888
+ // Expected: New query triggered
889
+ });
890
+ });
891
+ ```
892
+
893
+ **Expected Behavior:**
894
+ - Hook API matches Convex hooks
895
+ - Loading states accurate
896
+ - Error states accurate
897
+ - Refetch works correctly
898
+
899
+ **Coverage Target:** 90%
900
+
901
+ ---
902
+
903
+ ## Test Infrastructure Requirements
904
+
905
+ ### Required Test Utilities
906
+
907
+ 1. **Mock DataProvider** (in-memory)
908
+ - For unit tests
909
+ - Fast execution
910
+ - Predictable behavior
911
+
912
+ 2. **Test Convex Deployment**
913
+ - For integration tests
914
+ - Real backend
915
+ - Isolated test data
916
+
917
+ 3. **Performance Benchmarking**
918
+ - Measure operation times
919
+ - Compare with baseline
920
+ - Track over time
921
+
922
+ 4. **Test Data Generators**
923
+ - Create test organizations
924
+ - Create test users
925
+ - Create test things/connections/events
926
+
927
+ 5. **Auth Test Helpers**
928
+ - Sign up test users
929
+ - Generate auth tokens
930
+ - Clean up test data
931
+
932
+ ### Test Environment Setup
933
+
934
+ ```bash
935
+ # Backend test deployment
936
+ CONVEX_URL=https://test-deployment.convex.cloud
937
+ CONVEX_DEPLOYMENT=test:shocking-falcon-870
938
+
939
+ # Test database (separate from prod)
940
+ TEST_ORG_ID=test-org-123
941
+
942
+ # Performance monitoring
943
+ PERFORMANCE_BASELINE_FILE=./tests/performance/baseline.json
944
+ ```
945
+
946
+ ---
947
+
948
+ ## Coverage Targets by Category
949
+
950
+ | Category | Unit Coverage | Integration Coverage | Total Tests |
951
+ |----------|---------------|---------------------|-------------|
952
+ | Interface Contract | 95% | N/A | 30+ |
953
+ | Organizations | 95% | 85% | 10+ |
954
+ | People | 95% | 85% | 12+ |
955
+ | Things | 90% | 80% | 20+ |
956
+ | Connections | 90% | 80% | 18+ |
957
+ | Events | 90% | 80% | 15+ |
958
+ | Knowledge | 85% | 75% | 12+ |
959
+ | ConvexProvider | 95% | 90% | 15+ |
960
+ | Integration Flows | N/A | 80% | 8+ |
961
+ | Performance | 100% | 80% | 15+ |
962
+ | Error Handling | 95% | 85% | 12+ |
963
+ | Real-time | 90% | 85% | 10+ |
964
+ | **TOTAL** | **90%+** | **80%+** | **177+** |
965
+
966
+ ---
967
+
968
+ ## Test Execution Plan
969
+
970
+ ### Phase 1: Unit Tests (Day 1-2)
971
+ 1. Interface contract tests (type-only)
972
+ 2. Mock provider tests
973
+ 3. Error handling tests
974
+ 4. ConvexProvider implementation tests
975
+
976
+ **Goal:** 90%+ unit coverage
977
+
978
+ ### Phase 2: Integration Tests (Day 3-4)
979
+ 1. Full flow tests with real backend
980
+ 2. Multi-tenant isolation tests
981
+ 3. Auth integration tests (50+ existing)
982
+ 4. Real-time subscription tests
983
+
984
+ **Goal:** 80%+ integration coverage
985
+
986
+ ### Phase 3: Performance Tests (Day 5)
987
+ 1. Operation overhead tests
988
+ 2. Large dataset tests
989
+ 3. Concurrent request tests
990
+ 4. Establish baseline
991
+
992
+ **Goal:** <10ms overhead validated
993
+
994
+ ### Phase 4: Edge Cases (Day 6-7)
995
+ 1. Error scenarios
996
+ 2. Network failures
997
+ 3. Concurrent updates
998
+ 4. Large payloads
999
+
1000
+ **Goal:** All edge cases covered
1001
+
1002
+ ---
1003
+
1004
+ ## Acceptance Criteria
1005
+
1006
+ ### Must Pass Before Approval
1007
+
1008
+ - [ ] All 177+ tests pass
1009
+ - [ ] 90%+ unit test coverage achieved
1010
+ - [ ] 80%+ integration test coverage achieved
1011
+ - [ ] All 50+ existing auth tests pass (zero regression)
1012
+ - [ ] Performance overhead <10ms per operation
1013
+ - [ ] All 6 dimensions fully tested (organizations, people, things, connections, events, knowledge)
1014
+ - [ ] All 66 thing types validated
1015
+ - [ ] All 25 connection types validated
1016
+ - [ ] All 67 event types validated
1017
+ - [ ] Multi-tenant isolation verified
1018
+ - [ ] Real-time subscriptions working
1019
+ - [ ] Error handling comprehensive
1020
+ - [ ] TypeScript compiles with zero errors
1021
+ - [ ] Documentation complete
1022
+
1023
+ ### Performance Benchmarks
1024
+
1025
+ | Operation | Baseline (Convex) | Target (Provider) | Max Acceptable |
1026
+ |-----------|------------------|-------------------|----------------|
1027
+ | Get | 5ms | 10ms | 15ms |
1028
+ | List | 10ms | 15ms | 20ms |
1029
+ | Create | 15ms | 20ms | 25ms |
1030
+ | Update | 10ms | 15ms | 20ms |
1031
+ | Delete | 8ms | 13ms | 18ms |
1032
+ | Vector Search | 40ms | 50ms | 90ms |
1033
+
1034
+ **If ANY operation exceeds max acceptable, feature is REJECTED.**
1035
+
1036
+ ---
1037
+
1038
+ ## Quality Gates
1039
+
1040
+ ### Gate 1: Unit Tests (End of Day 2)
1041
+ - [ ] All interface tests pass
1042
+ - [ ] All mock provider tests pass
1043
+ - [ ] 90%+ unit coverage
1044
+ - [ ] Zero TypeScript errors
1045
+
1046
+ ### Gate 2: Integration Tests (End of Day 4)
1047
+ - [ ] All integration flows pass
1048
+ - [ ] All 50+ auth tests pass
1049
+ - [ ] 80%+ integration coverage
1050
+ - [ ] Multi-tenant isolation verified
1051
+
1052
+ ### Gate 3: Performance Tests (End of Day 5)
1053
+ - [ ] All operations within acceptable range
1054
+ - [ ] Baseline established
1055
+ - [ ] Performance report generated
1056
+
1057
+ ### Gate 4: Final Validation (End of Day 7)
1058
+ - [ ] All 177+ tests pass
1059
+ - [ ] All acceptance criteria met
1060
+ - [ ] Documentation complete
1061
+ - [ ] Ready for code review
1062
+
1063
+ ---
1064
+
1065
+ ## Test Failure Protocol
1066
+
1067
+ ### If Tests Fail During Implementation
1068
+
1069
+ 1. **STOP** - Do not proceed with implementation
1070
+ 2. **ANALYZE** - Identify root cause of failure
1071
+ 3. **EMIT EVENT** - Log `test_failed` event with details
1072
+ 4. **TRIGGER PROBLEM SOLVER** - Problem solver agent monitors test failures
1073
+ 5. **FIX** - Backend specialist fixes issue
1074
+ 6. **RETEST** - Run failed tests again
1075
+ 7. **VALIDATE** - Ensure fix doesn't break other tests
1076
+
1077
+ ### Common Failure Modes
1078
+
1079
+ 1. **Type Errors** - Interface contract violated
1080
+ 2. **Auth Regression** - Existing auth tests fail
1081
+ 3. **Performance Degradation** - Overhead exceeds 10ms
1082
+ 4. **Multi-tenant Leak** - Data isolation broken
1083
+ 5. **Connection Type Mismatch** - Wrong relationship types used
1084
+
1085
+ ---
1086
+
1087
+ ## Success Metrics
1088
+
1089
+ ### Technical Quality
1090
+ - **Test Coverage:** 90%+ unit, 80%+ integration
1091
+ - **Performance:** <10ms overhead per operation
1092
+ - **Type Safety:** 100% typed (no `any`)
1093
+ - **Error Handling:** All errors have `_tag`
1094
+ - **Regression:** Zero functionality loss
1095
+
1096
+ ### Ontology Alignment
1097
+ - **6 Dimensions:** All fully tested
1098
+ - **66 Thing Types:** All validated
1099
+ - **25 Connection Types:** All validated
1100
+ - **67 Event Types:** All validated
1101
+ - **Multi-tenant:** Perfect isolation
1102
+
1103
+ ### Developer Experience
1104
+ - **Hook API:** Matches Convex ergonomics
1105
+ - **Error Messages:** Clear and actionable
1106
+ - **Type Inference:** Full autocomplete
1107
+ - **Documentation:** Complete examples
1108
+ - **Migration Path:** Straightforward
1109
+
1110
+ ---
1111
+
1112
+ ## Related Documents
1113
+
1114
+ - **Plan:** `/Users/toc/Server/ONE/one/things/plans/2-backend-agnostic-frontend.md`
1115
+ - **Feature Spec:** `/Users/toc/Server/ONE/one/things/features/2-1-dataprovider-interface.md` (to be created)
1116
+ - **Implementation:** `/Users/toc/Server/ONE/frontend/src/providers/`
1117
+ - **Existing Tests:** `/Users/toc/Server/ONE/frontend/tests/auth/` (50+ auth tests)
1118
+ - **Mock Provider:** `/Users/toc/Server/ONE/frontend/src/providers/__tests__/DataProvider.test.ts` (existing)
1119
+
1120
+ ---
1121
+
1122
+ ## Notes for Backend Specialist
1123
+
1124
+ **Context Budget:** This test spec is designed to fit within 2,000 token context when implementing.
1125
+
1126
+ **Key Points:**
1127
+ 1. Read this spec BEFORE writing any code
1128
+ 2. Implement tests BEFORE implementation (TDD)
1129
+ 3. Use existing test patterns from `/frontend/tests/auth/`
1130
+ 4. Use existing mock provider pattern from `/__tests__/DataProvider.test.ts`
1131
+ 5. Run tests continuously during implementation
1132
+ 6. Target: 90%+ unit, 80%+ integration coverage
1133
+ 7. Zero regression on auth tests (50+)
1134
+
1135
+ **Critical Success Factor:**
1136
+ The DataProvider interface is the foundation for the entire backend-agnostic architecture. These tests MUST pass before proceeding to Features 2-2 through 2-7. Quality cannot be compromised.
1137
+
1138
+ ---
1139
+
1140
+ **Test Specification Status:** ✅ Complete and Ready for Implementation
1141
+ **Created:** 2025-10-13
1142
+ **Validated By:** Quality Agent (Intelligence Agent)
1143
+ **Approval Required From:** Engineering Director Agent
1144
+ **Next Step:** Backend Specialist begins implementation with tests first (TDD)