@kya-os/mcp-i-core 1.2.3-canary.7 → 1.3.0

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 (231) hide show
  1. package/.claude/settings.local.json +9 -0
  2. package/.turbo/turbo-build.log +4 -0
  3. package/.turbo/turbo-test$colon$coverage.log +4514 -0
  4. package/.turbo/turbo-test.log +2973 -0
  5. package/COMPLIANCE_IMPROVEMENT_REPORT.md +483 -0
  6. package/Composer 3.md +615 -0
  7. package/GPT-5.md +1169 -0
  8. package/OPUS-plan.md +352 -0
  9. package/PHASE_3_AND_4.1_SUMMARY.md +585 -0
  10. package/PHASE_3_SUMMARY.md +317 -0
  11. package/PHASE_4.1.3_SUMMARY.md +428 -0
  12. package/PHASE_4.1_COMPLETE.md +525 -0
  13. package/PHASE_4_USER_DID_IDENTITY_LINKING_PLAN.md +1240 -0
  14. package/SCHEMA_COMPLIANCE_REPORT.md +275 -0
  15. package/TEST_PLAN.md +571 -0
  16. package/coverage/coverage-final.json +57 -0
  17. package/dist/__tests__/utils/mock-providers.d.ts +1 -2
  18. package/dist/__tests__/utils/mock-providers.d.ts.map +1 -1
  19. package/dist/__tests__/utils/mock-providers.js.map +1 -1
  20. package/dist/cache/oauth-config-cache.d.ts +69 -0
  21. package/dist/cache/oauth-config-cache.d.ts.map +1 -0
  22. package/dist/cache/oauth-config-cache.js +76 -0
  23. package/dist/cache/oauth-config-cache.js.map +1 -0
  24. package/dist/identity/idp-token-resolver.d.ts +53 -0
  25. package/dist/identity/idp-token-resolver.d.ts.map +1 -0
  26. package/dist/identity/idp-token-resolver.js +108 -0
  27. package/dist/identity/idp-token-resolver.js.map +1 -0
  28. package/dist/identity/idp-token-storage.interface.d.ts +42 -0
  29. package/dist/identity/idp-token-storage.interface.d.ts.map +1 -0
  30. package/dist/identity/idp-token-storage.interface.js +12 -0
  31. package/dist/identity/idp-token-storage.interface.js.map +1 -0
  32. package/dist/identity/user-did-manager.d.ts +39 -1
  33. package/dist/identity/user-did-manager.d.ts.map +1 -1
  34. package/dist/identity/user-did-manager.js +69 -3
  35. package/dist/identity/user-did-manager.js.map +1 -1
  36. package/dist/index.d.ts +22 -0
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +39 -1
  39. package/dist/index.js.map +1 -1
  40. package/dist/runtime/audit-logger.d.ts +37 -0
  41. package/dist/runtime/audit-logger.d.ts.map +1 -0
  42. package/dist/runtime/audit-logger.js +9 -0
  43. package/dist/runtime/audit-logger.js.map +1 -0
  44. package/dist/runtime/base.d.ts +58 -2
  45. package/dist/runtime/base.d.ts.map +1 -1
  46. package/dist/runtime/base.js +266 -11
  47. package/dist/runtime/base.js.map +1 -1
  48. package/dist/services/access-control.service.d.ts.map +1 -1
  49. package/dist/services/access-control.service.js +200 -35
  50. package/dist/services/access-control.service.js.map +1 -1
  51. package/dist/services/authorization/authorization-registry.d.ts +29 -0
  52. package/dist/services/authorization/authorization-registry.d.ts.map +1 -0
  53. package/dist/services/authorization/authorization-registry.js +57 -0
  54. package/dist/services/authorization/authorization-registry.js.map +1 -0
  55. package/dist/services/authorization/types.d.ts +53 -0
  56. package/dist/services/authorization/types.d.ts.map +1 -0
  57. package/dist/services/authorization/types.js +10 -0
  58. package/dist/services/authorization/types.js.map +1 -0
  59. package/dist/services/batch-delegation.service.d.ts +53 -0
  60. package/dist/services/batch-delegation.service.d.ts.map +1 -0
  61. package/dist/services/batch-delegation.service.js +95 -0
  62. package/dist/services/batch-delegation.service.js.map +1 -0
  63. package/dist/services/oauth-config.service.d.ts +53 -0
  64. package/dist/services/oauth-config.service.d.ts.map +1 -0
  65. package/dist/services/oauth-config.service.js +117 -0
  66. package/dist/services/oauth-config.service.js.map +1 -0
  67. package/dist/services/oauth-provider-registry.d.ts +77 -0
  68. package/dist/services/oauth-provider-registry.d.ts.map +1 -0
  69. package/dist/services/oauth-provider-registry.js +112 -0
  70. package/dist/services/oauth-provider-registry.js.map +1 -0
  71. package/dist/services/oauth-service.d.ts +77 -0
  72. package/dist/services/oauth-service.d.ts.map +1 -0
  73. package/dist/services/oauth-service.js +348 -0
  74. package/dist/services/oauth-service.js.map +1 -0
  75. package/dist/services/oauth-token-retrieval.service.d.ts +49 -0
  76. package/dist/services/oauth-token-retrieval.service.d.ts.map +1 -0
  77. package/dist/services/oauth-token-retrieval.service.js +150 -0
  78. package/dist/services/oauth-token-retrieval.service.js.map +1 -0
  79. package/dist/services/provider-resolver.d.ts +48 -0
  80. package/dist/services/provider-resolver.d.ts.map +1 -0
  81. package/dist/services/provider-resolver.js +120 -0
  82. package/dist/services/provider-resolver.js.map +1 -0
  83. package/dist/services/provider-validator.d.ts +55 -0
  84. package/dist/services/provider-validator.d.ts.map +1 -0
  85. package/dist/services/provider-validator.js +135 -0
  86. package/dist/services/provider-validator.js.map +1 -0
  87. package/dist/services/tool-context-builder.d.ts +57 -0
  88. package/dist/services/tool-context-builder.d.ts.map +1 -0
  89. package/dist/services/tool-context-builder.js +125 -0
  90. package/dist/services/tool-context-builder.js.map +1 -0
  91. package/dist/services/tool-protection.service.d.ts +87 -10
  92. package/dist/services/tool-protection.service.d.ts.map +1 -1
  93. package/dist/services/tool-protection.service.js +282 -112
  94. package/dist/services/tool-protection.service.js.map +1 -1
  95. package/dist/types/oauth-required-error.d.ts +40 -0
  96. package/dist/types/oauth-required-error.d.ts.map +1 -0
  97. package/dist/types/oauth-required-error.js +40 -0
  98. package/dist/types/oauth-required-error.js.map +1 -0
  99. package/dist/utils/did-helpers.d.ts +33 -0
  100. package/dist/utils/did-helpers.d.ts.map +1 -1
  101. package/dist/utils/did-helpers.js +40 -0
  102. package/dist/utils/did-helpers.js.map +1 -1
  103. package/dist/utils/index.d.ts +1 -0
  104. package/dist/utils/index.d.ts.map +1 -1
  105. package/dist/utils/index.js +1 -0
  106. package/dist/utils/index.js.map +1 -1
  107. package/docs/API_REFERENCE.md +1362 -0
  108. package/docs/COMPLIANCE_MATRIX.md +691 -0
  109. package/docs/STATUSLIST2021_GUIDE.md +696 -0
  110. package/docs/W3C_VC_DELEGATION_GUIDE.md +710 -0
  111. package/package.json +24 -50
  112. package/scripts/audit-compliance.ts +724 -0
  113. package/src/__tests__/cache/tool-protection-cache.test.ts +640 -0
  114. package/src/__tests__/config/provider-runtime-config.test.ts +309 -0
  115. package/src/__tests__/delegation-e2e.test.ts +690 -0
  116. package/src/__tests__/identity/user-did-manager.test.ts +213 -0
  117. package/src/__tests__/index.test.ts +56 -0
  118. package/src/__tests__/integration/full-flow.test.ts +776 -0
  119. package/src/__tests__/integration.test.ts +281 -0
  120. package/src/__tests__/providers/base.test.ts +173 -0
  121. package/src/__tests__/providers/memory.test.ts +319 -0
  122. package/src/__tests__/regression/phase2-regression.test.ts +427 -0
  123. package/src/__tests__/runtime/audit-logger.test.ts +154 -0
  124. package/src/__tests__/runtime/base-extensions.test.ts +593 -0
  125. package/src/__tests__/runtime/base.test.ts +869 -0
  126. package/src/__tests__/runtime/delegation-flow.test.ts +164 -0
  127. package/src/__tests__/runtime/proof-client-did.test.ts +375 -0
  128. package/src/__tests__/runtime/route-interception.test.ts +686 -0
  129. package/src/__tests__/runtime/tool-protection-enforcement.test.ts +908 -0
  130. package/src/__tests__/services/agentshield-integration.test.ts +784 -0
  131. package/src/__tests__/services/provider-resolver-edge-cases.test.ts +487 -0
  132. package/src/__tests__/services/tool-protection-oauth-provider.test.ts +480 -0
  133. package/src/__tests__/services/tool-protection.service.test.ts +1366 -0
  134. package/src/__tests__/utils/mock-providers.ts +340 -0
  135. package/src/cache/oauth-config-cache.d.ts +69 -0
  136. package/src/cache/oauth-config-cache.d.ts.map +1 -0
  137. package/src/cache/oauth-config-cache.js +71 -0
  138. package/src/cache/oauth-config-cache.js.map +1 -0
  139. package/src/cache/oauth-config-cache.ts +123 -0
  140. package/src/cache/tool-protection-cache.ts +171 -0
  141. package/src/compliance/EXAMPLE.md +412 -0
  142. package/src/compliance/__tests__/schema-verifier.test.ts +797 -0
  143. package/src/compliance/index.ts +8 -0
  144. package/src/compliance/schema-registry.ts +460 -0
  145. package/src/compliance/schema-verifier.ts +708 -0
  146. package/src/config/__tests__/remote-config.spec.ts +268 -0
  147. package/src/config/remote-config.ts +174 -0
  148. package/src/config.ts +309 -0
  149. package/src/delegation/__tests__/audience-validator.test.ts +112 -0
  150. package/src/delegation/__tests__/bitstring.test.ts +346 -0
  151. package/src/delegation/__tests__/cascading-revocation.test.ts +628 -0
  152. package/src/delegation/__tests__/delegation-graph.test.ts +584 -0
  153. package/src/delegation/__tests__/utils.test.ts +152 -0
  154. package/src/delegation/__tests__/vc-issuer.test.ts +442 -0
  155. package/src/delegation/__tests__/vc-verifier.test.ts +922 -0
  156. package/src/delegation/audience-validator.ts +52 -0
  157. package/src/delegation/bitstring.ts +278 -0
  158. package/src/delegation/cascading-revocation.ts +370 -0
  159. package/src/delegation/delegation-graph.ts +299 -0
  160. package/src/delegation/index.ts +14 -0
  161. package/src/delegation/statuslist-manager.ts +353 -0
  162. package/src/delegation/storage/__tests__/memory-graph-storage.test.ts +366 -0
  163. package/src/delegation/storage/__tests__/memory-statuslist-storage.test.ts +228 -0
  164. package/src/delegation/storage/index.ts +9 -0
  165. package/src/delegation/storage/memory-graph-storage.ts +178 -0
  166. package/src/delegation/storage/memory-statuslist-storage.ts +77 -0
  167. package/src/delegation/utils.ts +42 -0
  168. package/src/delegation/vc-issuer.ts +232 -0
  169. package/src/delegation/vc-verifier.ts +568 -0
  170. package/src/identity/idp-token-resolver.ts +147 -0
  171. package/src/identity/idp-token-storage.interface.ts +59 -0
  172. package/src/identity/user-did-manager.ts +370 -0
  173. package/src/index.ts +260 -0
  174. package/src/providers/base.d.ts +91 -0
  175. package/src/providers/base.d.ts.map +1 -0
  176. package/src/providers/base.js +38 -0
  177. package/src/providers/base.js.map +1 -0
  178. package/src/providers/base.ts +96 -0
  179. package/src/providers/memory.ts +142 -0
  180. package/src/runtime/audit-logger.ts +39 -0
  181. package/src/runtime/base.ts +1329 -0
  182. package/src/services/__tests__/access-control.integration.test.ts +443 -0
  183. package/src/services/__tests__/access-control.proof-response-validation.test.ts +578 -0
  184. package/src/services/__tests__/access-control.service.test.ts +970 -0
  185. package/src/services/__tests__/batch-delegation.service.test.ts +351 -0
  186. package/src/services/__tests__/crypto.service.test.ts +531 -0
  187. package/src/services/__tests__/oauth-provider-registry.test.ts +142 -0
  188. package/src/services/__tests__/proof-verifier.integration.test.ts +485 -0
  189. package/src/services/__tests__/proof-verifier.test.ts +489 -0
  190. package/src/services/__tests__/provider-resolution.integration.test.ts +198 -0
  191. package/src/services/__tests__/provider-resolver.test.ts +217 -0
  192. package/src/services/__tests__/storage.service.test.ts +358 -0
  193. package/src/services/access-control.service.ts +990 -0
  194. package/src/services/authorization/authorization-registry.ts +66 -0
  195. package/src/services/authorization/types.ts +71 -0
  196. package/src/services/batch-delegation.service.ts +137 -0
  197. package/src/services/crypto.service.ts +302 -0
  198. package/src/services/errors.ts +76 -0
  199. package/src/services/index.ts +9 -0
  200. package/src/services/oauth-config.service.d.ts +53 -0
  201. package/src/services/oauth-config.service.d.ts.map +1 -0
  202. package/src/services/oauth-config.service.js +113 -0
  203. package/src/services/oauth-config.service.js.map +1 -0
  204. package/src/services/oauth-config.service.ts +166 -0
  205. package/src/services/oauth-provider-registry.d.ts +57 -0
  206. package/src/services/oauth-provider-registry.d.ts.map +1 -0
  207. package/src/services/oauth-provider-registry.js +73 -0
  208. package/src/services/oauth-provider-registry.js.map +1 -0
  209. package/src/services/oauth-provider-registry.ts +123 -0
  210. package/src/services/oauth-service.ts +510 -0
  211. package/src/services/oauth-token-retrieval.service.ts +245 -0
  212. package/src/services/proof-verifier.ts +478 -0
  213. package/src/services/provider-resolver.d.ts +48 -0
  214. package/src/services/provider-resolver.d.ts.map +1 -0
  215. package/src/services/provider-resolver.js +106 -0
  216. package/src/services/provider-resolver.js.map +1 -0
  217. package/src/services/provider-resolver.ts +144 -0
  218. package/src/services/provider-validator.ts +170 -0
  219. package/src/services/storage.service.ts +566 -0
  220. package/src/services/tool-context-builder.ts +172 -0
  221. package/src/services/tool-protection.service.ts +958 -0
  222. package/src/types/oauth-required-error.ts +63 -0
  223. package/src/types/tool-protection.ts +155 -0
  224. package/src/utils/__tests__/did-helpers.test.ts +101 -0
  225. package/src/utils/base64.ts +148 -0
  226. package/src/utils/cors.ts +83 -0
  227. package/src/utils/did-helpers.ts +150 -0
  228. package/src/utils/index.ts +8 -0
  229. package/src/utils/storage-keys.ts +278 -0
  230. package/tsconfig.json +21 -0
  231. package/vitest.config.ts +56 -0
package/TEST_PLAN.md ADDED
@@ -0,0 +1,571 @@
1
+ # MCP-I Core Delegation Test Suite Plan
2
+
3
+ ## Overview
4
+
5
+ Comprehensive test coverage for W3C VC-based delegation system with cascading revocation.
6
+
7
+ ## Test Categories
8
+
9
+ ### 1. Unit Tests (per module)
10
+
11
+ #### 1.1 Bitstring Manager (`bitstring.test.ts`)
12
+
13
+ **Critical Tests:**
14
+ ```typescript
15
+ describe('BitstringManager', () => {
16
+ // Basic Operations
17
+ test('should set and get bits correctly')
18
+ test('should handle edge cases (index 0, max index)')
19
+ test('should throw on out-of-range indices')
20
+ test('should return all set bits')
21
+
22
+ // Encoding/Decoding
23
+ test('should encode to base64url format')
24
+ test('should decode from base64url format')
25
+ test('should handle empty bitstring')
26
+ test('should handle fully set bitstring')
27
+ test('should round-trip encode/decode without data loss')
28
+
29
+ // Compression
30
+ test('should compress efficiently (large sparse bitstring)')
31
+ test('should compress efficiently (large dense bitstring)')
32
+ test('should handle platform-specific compression (mock)')
33
+
34
+ // Edge Cases
35
+ test('should handle bitstring size not multiple of 8')
36
+ test('should handle maximum bitstring size (1M entries)')
37
+ test('should handle concurrent bit operations')
38
+ })
39
+
40
+ describe('isIndexSet', () => {
41
+ test('should check index without full decode')
42
+ test('should return false for out-of-range index')
43
+ test('should work with various compressed formats')
44
+ })
45
+ ```
46
+
47
+ **Estimated: 15 tests**
48
+
49
+ ---
50
+
51
+ #### 1.2 VC Issuer (`vc-issuer.test.ts`)
52
+
53
+ **Critical Tests:**
54
+ ```typescript
55
+ describe('DelegationCredentialIssuer', () => {
56
+ // Basic Issuance
57
+ test('should issue a valid delegation VC')
58
+ test('should include all required VC fields')
59
+ test('should sign with Ed25519')
60
+ test('should use correct verification method')
61
+
62
+ // DelegationRecord → VC Conversion
63
+ test('should wrap delegation record correctly')
64
+ test('should preserve delegation constraints')
65
+ test('should handle optional fields')
66
+ test('should set proper expiration dates')
67
+
68
+ // Credential Status
69
+ test('should include credentialStatus if provided')
70
+ test('should omit credentialStatus if not provided')
71
+
72
+ // Proof Generation
73
+ test('should generate valid Ed25519Signature2020 proof')
74
+ test('should canonicalize VC before signing')
75
+ test('should include verificationMethod in proof')
76
+
77
+ // Error Handling
78
+ test('should throw on missing identity')
79
+ test('should throw on invalid delegation record')
80
+ test('should throw on signing failure')
81
+ })
82
+
83
+ describe('createAndIssueDelegation', () => {
84
+ test('should create and issue in one step')
85
+ test('should generate proper vcId')
86
+ test('should handle parent delegations')
87
+ })
88
+ ```
89
+
90
+ **Estimated: 18 tests**
91
+
92
+ ---
93
+
94
+ #### 1.3 VC Verifier (`vc-verifier.test.ts`)
95
+
96
+ **Critical Tests:**
97
+ ```typescript
98
+ describe('DelegationCredentialVerifier', () => {
99
+ // Progressive Enhancement - Stage 1
100
+ describe('Stage 1: Basic Checks', () => {
101
+ test('should reject expired credentials')
102
+ test('should reject not-yet-valid credentials')
103
+ test('should reject missing proof')
104
+ test('should reject revoked status')
105
+ test('should reject invalid schema')
106
+ test('should accept valid basic properties')
107
+ test('should complete in <5ms')
108
+ })
109
+
110
+ // Progressive Enhancement - Stage 2
111
+ describe('Stage 2: Signature Verification', () => {
112
+ test('should verify valid Ed25519 signature')
113
+ test('should reject invalid signature')
114
+ test('should skip if no DID resolver')
115
+ test('should reject unresolvable DID')
116
+ test('should reject wrong verification method')
117
+ test('should complete in <100ms with resolver')
118
+ })
119
+
120
+ describe('Stage 2: Status Checking', () => {
121
+ test('should check StatusList2021')
122
+ test('should reject revoked credentials')
123
+ test('should accept non-revoked credentials')
124
+ test('should skip if no status list resolver')
125
+ test('should handle missing status list')
126
+ })
127
+
128
+ // Combined Results
129
+ describe('Stage 3: Combined Results', () => {
130
+ test('should run stages in parallel')
131
+ test('should return combined result')
132
+ test('should include performance metrics')
133
+ test('should cache successful verifications')
134
+ })
135
+
136
+ // Caching
137
+ describe('Caching', () => {
138
+ test('should cache valid verifications')
139
+ test('should respect TTL')
140
+ test('should skip cache when requested')
141
+ test('should clear cache entries')
142
+ })
143
+ })
144
+ ```
145
+
146
+ **Estimated: 24 tests**
147
+
148
+ ---
149
+
150
+ #### 1.4 StatusList2021 Manager (`statuslist-manager.test.ts`)
151
+
152
+ **Critical Tests:**
153
+ ```typescript
154
+ describe('StatusList2021Manager', () => {
155
+ // Index Allocation
156
+ describe('allocateStatusEntry', () => {
157
+ test('should allocate unique indices')
158
+ test('should create status list on first allocation')
159
+ test('should handle concurrent allocations')
160
+ test('should generate proper credentialStatus entry')
161
+ test('should support revocation purpose')
162
+ test('should support suspension purpose')
163
+ })
164
+
165
+ // Status Updates
166
+ describe('updateStatus', () => {
167
+ test('should revoke a credential')
168
+ test('should restore a credential')
169
+ test('should re-sign after update')
170
+ test('should handle non-existent status list')
171
+ test('should handle invalid index')
172
+ })
173
+
174
+ // Status Checking
175
+ describe('checkStatus', () => {
176
+ test('should return false for non-revoked')
177
+ test('should return true for revoked')
178
+ test('should return false for missing status list')
179
+ test('should handle invalid status entry')
180
+ })
181
+
182
+ // Status List Creation
183
+ describe('Status List Creation', () => {
184
+ test('should create proper StatusList2021Credential')
185
+ test('should include all required fields')
186
+ test('should sign with issuer key')
187
+ test('should use correct context URLs')
188
+ })
189
+
190
+ // Storage Integration
191
+ describe('Storage Integration', () => {
192
+ test('should store status lists correctly')
193
+ test('should retrieve status lists correctly')
194
+ test('should handle storage failures')
195
+ })
196
+
197
+ // Performance
198
+ describe('Performance', () => {
199
+ test('should handle 100K+ entries efficiently')
200
+ test('should compress bitstring properly')
201
+ test('should update in <50ms')
202
+ })
203
+ })
204
+ ```
205
+
206
+ **Estimated: 21 tests**
207
+
208
+ ---
209
+
210
+ #### 1.5 Delegation Graph (`delegation-graph.test.ts`)
211
+
212
+ **Critical Tests:**
213
+ ```typescript
214
+ describe('DelegationGraphManager', () => {
215
+ // Node Registration
216
+ describe('registerDelegation', () => {
217
+ test('should register root delegation')
218
+ test('should register child delegation')
219
+ test('should update parent children list')
220
+ test('should handle duplicate registration')
221
+ test('should throw on missing parent')
222
+ })
223
+
224
+ // Graph Queries
225
+ describe('getChildren', () => {
226
+ test('should return direct children only')
227
+ test('should return empty array for leaf nodes')
228
+ test('should handle deleted children')
229
+ })
230
+
231
+ describe('getDescendants', () => {
232
+ test('should return all descendants')
233
+ test('should handle multi-level trees')
234
+ test('should return empty for leaf nodes')
235
+ test('should handle large trees (1000+ nodes)')
236
+ })
237
+
238
+ describe('getChain', () => {
239
+ test('should return path from root to node')
240
+ test('should include the node itself')
241
+ test('should order correctly (root first)')
242
+ test('should handle root nodes')
243
+ })
244
+
245
+ // Relationship Queries
246
+ describe('isAncestor', () => {
247
+ test('should identify direct parent')
248
+ test('should identify distant ancestor')
249
+ test('should return false for siblings')
250
+ test('should return false for descendants')
251
+ })
252
+
253
+ describe('getDepth', () => {
254
+ test('should return 0 for root')
255
+ test('should return correct depth for nested nodes')
256
+ })
257
+
258
+ // Chain Validation
259
+ describe('validateChain', () => {
260
+ test('should validate proper chain')
261
+ test('should reject broken issuer-subject link')
262
+ test('should reject broken parent pointer')
263
+ test('should handle missing nodes')
264
+ })
265
+
266
+ // Node Removal
267
+ describe('removeDelegation', () => {
268
+ test('should remove node from graph')
269
+ test('should update parent children list')
270
+ test('should handle missing node')
271
+ })
272
+ })
273
+ ```
274
+
275
+ **Estimated: 23 tests**
276
+
277
+ ---
278
+
279
+ #### 1.6 Cascading Revocation (`cascading-revocation.test.ts`)
280
+
281
+ **Critical Tests:**
282
+ ```typescript
283
+ describe('CascadingRevocationManager', () => {
284
+ // Basic Revocation
285
+ describe('revokeDelegation', () => {
286
+ test('should revoke single delegation')
287
+ test('should revoke all children')
288
+ test('should revoke all grandchildren')
289
+ test('should trigger revocation hooks')
290
+ test('should return all revocation events')
291
+ test('should handle root delegation')
292
+ test('should handle leaf delegation')
293
+ })
294
+
295
+ // Cascade Depth
296
+ describe('Cascade Depth', () => {
297
+ test('should cascade to level 10')
298
+ test('should enforce maxDepth limit')
299
+ test('should throw on depth exceeded')
300
+ })
301
+
302
+ // Dry Run
303
+ describe('Dry Run', () => {
304
+ test('should not actually revoke in dry run')
305
+ test('should return what would be revoked')
306
+ test('should include all descendants')
307
+ })
308
+
309
+ // Restoration
310
+ describe('restoreDelegation', () => {
311
+ test('should restore single delegation')
312
+ test('should NOT cascade to children')
313
+ test('should update status list')
314
+ })
315
+
316
+ // Revocation Checking
317
+ describe('isRevoked', () => {
318
+ test('should detect direct revocation')
319
+ test('should detect ancestor revocation')
320
+ test('should return false for valid delegation')
321
+ test('should identify which ancestor is revoked')
322
+ test('should check entire chain')
323
+ })
324
+
325
+ describe('getRevokedInSubtree', () => {
326
+ test('should find all revoked in subtree')
327
+ test('should handle partial revocation')
328
+ test('should handle fully revoked subtree')
329
+ })
330
+
331
+ // Validation
332
+ describe('validateDelegation', () => {
333
+ test('should validate non-revoked delegation')
334
+ test('should reject revoked delegation')
335
+ test('should reject if ancestor revoked')
336
+ test('should validate chain structure')
337
+ test('should combine all checks')
338
+ })
339
+
340
+ // Hooks & Events
341
+ describe('Revocation Hooks', () => {
342
+ test('should call hook for each revocation')
343
+ test('should pass correct event data')
344
+ test('should handle async hooks')
345
+ test('should handle hook errors gracefully')
346
+ })
347
+
348
+ // Performance
349
+ describe('Performance', () => {
350
+ test('should cascade 1000 delegations in <1s')
351
+ test('should handle large trees efficiently')
352
+ })
353
+ })
354
+ ```
355
+
356
+ **Estimated: 28 tests**
357
+
358
+ ---
359
+
360
+ ### 2. Integration Tests
361
+
362
+ #### 2.1 Full Lifecycle Test (`delegation-lifecycle.integration.test.ts`)
363
+
364
+ ```typescript
365
+ describe('Complete Delegation Lifecycle', () => {
366
+ test('Issue → Verify → Use → Revoke → Verify Again', async () => {
367
+ // 1. Issue delegation VC
368
+ // 2. Verify signature
369
+ // 3. Use delegation for action
370
+ // 4. Revoke delegation
371
+ // 5. Verify revocation
372
+ // 6. Attempt use (should fail)
373
+ })
374
+
375
+ test('Multi-level delegation chain', async () => {
376
+ // Root → Child1 → Child2 → Child3
377
+ // Verify chain
378
+ // Revoke Child1
379
+ // Verify Child2 and Child3 are revoked
380
+ })
381
+
382
+ test('Parallel delegation branches', async () => {
383
+ // Root → Child1 → Grandchild1
384
+ // → Child2 → Grandchild2
385
+ // Revoke Child1
386
+ // Verify Child2 still valid
387
+ })
388
+ })
389
+ ```
390
+
391
+ **Estimated: 10 tests**
392
+
393
+ ---
394
+
395
+ #### 2.2 Cross-Module Integration (`cross-module.integration.test.ts`)
396
+
397
+ ```typescript
398
+ describe('Cross-Module Integration', () => {
399
+ test('VC Issuer → StatusList Manager', async () => {
400
+ // Issue VC with status
401
+ // Allocate status entry
402
+ // Verify status entry in VC
403
+ })
404
+
405
+ test('VC Issuer → Graph → Cascading Revocation', async () => {
406
+ // Issue parent + children VCs
407
+ // Register in graph
408
+ // Revoke parent
409
+ // Verify all revoked
410
+ })
411
+
412
+ test('Verifier → StatusList → Graph', async () => {
413
+ // Create complex chain
414
+ // Revoke middle node
415
+ // Verify with full validation
416
+ })
417
+ })
418
+ ```
419
+
420
+ **Estimated: 8 tests**
421
+
422
+ ---
423
+
424
+ ### 3. Performance Tests
425
+
426
+ ```typescript
427
+ describe('Performance Benchmarks', () => {
428
+ test('Issue 1000 VCs in <10s')
429
+ test('Verify 1000 VCs in <20s')
430
+ test('Allocate 100K status entries in <30s')
431
+ test('Cascade revoke 10K delegations in <5s')
432
+ test('Bitstring compress 1M entries in <100ms')
433
+ test('Graph query 10K nodes in <50ms')
434
+ })
435
+ ```
436
+
437
+ **Estimated: 6 tests**
438
+
439
+ ---
440
+
441
+ ### 4. Platform Compatibility Tests
442
+
443
+ ```typescript
444
+ describe('Platform Compatibility', () => {
445
+ // Node.js specific
446
+ test('Node.js crypto (zlib compression)')
447
+ test('Node.js jose library')
448
+
449
+ // Cloudflare Workers specific
450
+ test('Cloudflare CompressionStream')
451
+ test('Cloudflare Web Crypto API')
452
+
453
+ // Browser specific
454
+ test('Browser Web Crypto API')
455
+ test('Browser CompressionStream')
456
+ })
457
+ ```
458
+
459
+ **Estimated: 6 tests**
460
+
461
+ ---
462
+
463
+ ### 5. Error & Edge Case Tests
464
+
465
+ ```typescript
466
+ describe('Error Handling', () => {
467
+ test('Handle missing storage')
468
+ test('Handle corrupted status list')
469
+ test('Handle invalid bitstring encoding')
470
+ test('Handle circular delegation references')
471
+ test('Handle orphaned delegations')
472
+ test('Handle extremely deep chains (> 100 levels)')
473
+ test('Handle concurrent revocations')
474
+ test('Handle network failures')
475
+ test('Handle malformed VCs')
476
+ test('Handle expired signing keys')
477
+ })
478
+ ```
479
+
480
+ **Estimated: 10 tests**
481
+
482
+ ---
483
+
484
+ ## Test Summary
485
+
486
+ | Category | Module | Tests | Priority |
487
+ |----------|--------|-------|----------|
488
+ | Unit | Bitstring | 15 | HIGH |
489
+ | Unit | VC Issuer | 18 | HIGH |
490
+ | Unit | VC Verifier | 24 | HIGH |
491
+ | Unit | StatusList Manager | 21 | HIGH |
492
+ | Unit | Delegation Graph | 23 | HIGH |
493
+ | Unit | Cascading Revocation | 28 | HIGH |
494
+ | Integration | Full Lifecycle | 10 | CRITICAL |
495
+ | Integration | Cross-Module | 8 | HIGH |
496
+ | Performance | Benchmarks | 6 | MEDIUM |
497
+ | Platform | Compatibility | 6 | MEDIUM |
498
+ | Error | Edge Cases | 10 | HIGH |
499
+ | **TOTAL** | | **169** | |
500
+
501
+ ---
502
+
503
+ ## Test Implementation Strategy
504
+
505
+ ### Phase 1: Core Unit Tests (Priority: CRITICAL)
506
+ 1. Bitstring Manager (foundation for everything)
507
+ 2. VC Issuer (delegation creation)
508
+ 3. VC Verifier (delegation validation)
509
+
510
+ **Target: 57 tests, 2 days**
511
+
512
+ ---
513
+
514
+ ### Phase 2: Advanced Unit Tests (Priority: HIGH)
515
+ 1. StatusList Manager (revocation infrastructure)
516
+ 2. Delegation Graph (chain tracking)
517
+ 3. Cascading Revocation (Python POC parity)
518
+
519
+ **Target: 72 tests, 3 days**
520
+
521
+ ---
522
+
523
+ ### Phase 3: Integration Tests (Priority: CRITICAL)
524
+ 1. Full lifecycle tests
525
+ 2. Cross-module integration
526
+
527
+ **Target: 18 tests, 1 day**
528
+
529
+ ---
530
+
531
+ ### Phase 4: Performance & Platform Tests (Priority: MEDIUM)
532
+ 1. Performance benchmarks
533
+ 2. Platform compatibility
534
+ 3. Error handling
535
+
536
+ **Target: 22 tests, 1 day**
537
+
538
+ ---
539
+
540
+ ## Testing Tools
541
+
542
+ - **Framework**: Vitest (already configured)
543
+ - **Mocking**: Vitest mocks for storage providers
544
+ - **Assertions**: Vitest assertions + custom matchers
545
+ - **Coverage Target**: 90%+ for core modules
546
+
547
+ ---
548
+
549
+ ## Success Criteria
550
+
551
+ ✅ All unit tests pass
552
+ ✅ All integration tests pass
553
+ ✅ Performance benchmarks meet targets
554
+ ✅ Platform compatibility verified
555
+ ✅ 90%+ code coverage
556
+ ✅ No memory leaks in long-running tests
557
+ ✅ Thread-safe operations verified
558
+
559
+ ---
560
+
561
+ ## Next Steps
562
+
563
+ 1. Create test utilities (mock storage, identity providers)
564
+ 2. Implement Phase 1 tests
565
+ 3. Run coverage reports
566
+ 4. Iterate on failing tests
567
+ 5. Document test patterns
568
+
569
+ ---
570
+
571
+ **Total Estimated Effort**: 7 days for complete test suite