@kya-os/mcp-i-core 1.2.3-canary.6 → 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.
- package/.claude/settings.local.json +9 -0
- package/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-test$colon$coverage.log +4514 -0
- package/.turbo/turbo-test.log +2973 -0
- package/COMPLIANCE_IMPROVEMENT_REPORT.md +483 -0
- package/Composer 3.md +615 -0
- package/GPT-5.md +1169 -0
- package/OPUS-plan.md +352 -0
- package/PHASE_3_AND_4.1_SUMMARY.md +585 -0
- package/PHASE_3_SUMMARY.md +317 -0
- package/PHASE_4.1.3_SUMMARY.md +428 -0
- package/PHASE_4.1_COMPLETE.md +525 -0
- package/PHASE_4_USER_DID_IDENTITY_LINKING_PLAN.md +1240 -0
- package/SCHEMA_COMPLIANCE_REPORT.md +275 -0
- package/TEST_PLAN.md +571 -0
- package/coverage/coverage-final.json +57 -0
- package/dist/__tests__/utils/mock-providers.d.ts +1 -2
- package/dist/__tests__/utils/mock-providers.d.ts.map +1 -1
- package/dist/__tests__/utils/mock-providers.js.map +1 -1
- package/dist/cache/oauth-config-cache.d.ts +69 -0
- package/dist/cache/oauth-config-cache.d.ts.map +1 -0
- package/dist/cache/oauth-config-cache.js +76 -0
- package/dist/cache/oauth-config-cache.js.map +1 -0
- package/dist/identity/idp-token-resolver.d.ts +53 -0
- package/dist/identity/idp-token-resolver.d.ts.map +1 -0
- package/dist/identity/idp-token-resolver.js +108 -0
- package/dist/identity/idp-token-resolver.js.map +1 -0
- package/dist/identity/idp-token-storage.interface.d.ts +42 -0
- package/dist/identity/idp-token-storage.interface.d.ts.map +1 -0
- package/dist/identity/idp-token-storage.interface.js +12 -0
- package/dist/identity/idp-token-storage.interface.js.map +1 -0
- package/dist/identity/user-did-manager.d.ts +39 -1
- package/dist/identity/user-did-manager.d.ts.map +1 -1
- package/dist/identity/user-did-manager.js +69 -3
- package/dist/identity/user-did-manager.js.map +1 -1
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -1
- package/dist/index.js.map +1 -1
- package/dist/runtime/audit-logger.d.ts +37 -0
- package/dist/runtime/audit-logger.d.ts.map +1 -0
- package/dist/runtime/audit-logger.js +9 -0
- package/dist/runtime/audit-logger.js.map +1 -0
- package/dist/runtime/base.d.ts +58 -2
- package/dist/runtime/base.d.ts.map +1 -1
- package/dist/runtime/base.js +266 -11
- package/dist/runtime/base.js.map +1 -1
- package/dist/services/access-control.service.d.ts.map +1 -1
- package/dist/services/access-control.service.js +200 -35
- package/dist/services/access-control.service.js.map +1 -1
- package/dist/services/authorization/authorization-registry.d.ts +29 -0
- package/dist/services/authorization/authorization-registry.d.ts.map +1 -0
- package/dist/services/authorization/authorization-registry.js +57 -0
- package/dist/services/authorization/authorization-registry.js.map +1 -0
- package/dist/services/authorization/types.d.ts +53 -0
- package/dist/services/authorization/types.d.ts.map +1 -0
- package/dist/services/authorization/types.js +10 -0
- package/dist/services/authorization/types.js.map +1 -0
- package/dist/services/batch-delegation.service.d.ts +53 -0
- package/dist/services/batch-delegation.service.d.ts.map +1 -0
- package/dist/services/batch-delegation.service.js +95 -0
- package/dist/services/batch-delegation.service.js.map +1 -0
- package/dist/services/oauth-config.service.d.ts +53 -0
- package/dist/services/oauth-config.service.d.ts.map +1 -0
- package/dist/services/oauth-config.service.js +117 -0
- package/dist/services/oauth-config.service.js.map +1 -0
- package/dist/services/oauth-provider-registry.d.ts +77 -0
- package/dist/services/oauth-provider-registry.d.ts.map +1 -0
- package/dist/services/oauth-provider-registry.js +112 -0
- package/dist/services/oauth-provider-registry.js.map +1 -0
- package/dist/services/oauth-service.d.ts +77 -0
- package/dist/services/oauth-service.d.ts.map +1 -0
- package/dist/services/oauth-service.js +348 -0
- package/dist/services/oauth-service.js.map +1 -0
- package/dist/services/oauth-token-retrieval.service.d.ts +49 -0
- package/dist/services/oauth-token-retrieval.service.d.ts.map +1 -0
- package/dist/services/oauth-token-retrieval.service.js +150 -0
- package/dist/services/oauth-token-retrieval.service.js.map +1 -0
- package/dist/services/provider-resolver.d.ts +48 -0
- package/dist/services/provider-resolver.d.ts.map +1 -0
- package/dist/services/provider-resolver.js +120 -0
- package/dist/services/provider-resolver.js.map +1 -0
- package/dist/services/provider-validator.d.ts +55 -0
- package/dist/services/provider-validator.d.ts.map +1 -0
- package/dist/services/provider-validator.js +135 -0
- package/dist/services/provider-validator.js.map +1 -0
- package/dist/services/tool-context-builder.d.ts +57 -0
- package/dist/services/tool-context-builder.d.ts.map +1 -0
- package/dist/services/tool-context-builder.js +125 -0
- package/dist/services/tool-context-builder.js.map +1 -0
- package/dist/services/tool-protection.service.d.ts +87 -10
- package/dist/services/tool-protection.service.d.ts.map +1 -1
- package/dist/services/tool-protection.service.js +282 -112
- package/dist/services/tool-protection.service.js.map +1 -1
- package/dist/types/oauth-required-error.d.ts +40 -0
- package/dist/types/oauth-required-error.d.ts.map +1 -0
- package/dist/types/oauth-required-error.js +40 -0
- package/dist/types/oauth-required-error.js.map +1 -0
- package/dist/utils/did-helpers.d.ts +33 -0
- package/dist/utils/did-helpers.d.ts.map +1 -1
- package/dist/utils/did-helpers.js +40 -0
- package/dist/utils/did-helpers.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/docs/API_REFERENCE.md +1362 -0
- package/docs/COMPLIANCE_MATRIX.md +691 -0
- package/docs/STATUSLIST2021_GUIDE.md +696 -0
- package/docs/W3C_VC_DELEGATION_GUIDE.md +710 -0
- package/package.json +24 -50
- package/scripts/audit-compliance.ts +724 -0
- package/src/__tests__/cache/tool-protection-cache.test.ts +640 -0
- package/src/__tests__/config/provider-runtime-config.test.ts +309 -0
- package/src/__tests__/delegation-e2e.test.ts +690 -0
- package/src/__tests__/identity/user-did-manager.test.ts +213 -0
- package/src/__tests__/index.test.ts +56 -0
- package/src/__tests__/integration/full-flow.test.ts +776 -0
- package/src/__tests__/integration.test.ts +281 -0
- package/src/__tests__/providers/base.test.ts +173 -0
- package/src/__tests__/providers/memory.test.ts +319 -0
- package/src/__tests__/regression/phase2-regression.test.ts +427 -0
- package/src/__tests__/runtime/audit-logger.test.ts +154 -0
- package/src/__tests__/runtime/base-extensions.test.ts +593 -0
- package/src/__tests__/runtime/base.test.ts +869 -0
- package/src/__tests__/runtime/delegation-flow.test.ts +164 -0
- package/src/__tests__/runtime/proof-client-did.test.ts +375 -0
- package/src/__tests__/runtime/route-interception.test.ts +686 -0
- package/src/__tests__/runtime/tool-protection-enforcement.test.ts +908 -0
- package/src/__tests__/services/agentshield-integration.test.ts +784 -0
- package/src/__tests__/services/provider-resolver-edge-cases.test.ts +487 -0
- package/src/__tests__/services/tool-protection-oauth-provider.test.ts +480 -0
- package/src/__tests__/services/tool-protection.service.test.ts +1366 -0
- package/src/__tests__/utils/mock-providers.ts +340 -0
- package/src/cache/oauth-config-cache.d.ts +69 -0
- package/src/cache/oauth-config-cache.d.ts.map +1 -0
- package/src/cache/oauth-config-cache.js +71 -0
- package/src/cache/oauth-config-cache.js.map +1 -0
- package/src/cache/oauth-config-cache.ts +123 -0
- package/src/cache/tool-protection-cache.ts +171 -0
- package/src/compliance/EXAMPLE.md +412 -0
- package/src/compliance/__tests__/schema-verifier.test.ts +797 -0
- package/src/compliance/index.ts +8 -0
- package/src/compliance/schema-registry.ts +460 -0
- package/src/compliance/schema-verifier.ts +708 -0
- package/src/config/__tests__/remote-config.spec.ts +268 -0
- package/src/config/remote-config.ts +174 -0
- package/src/config.ts +309 -0
- package/src/delegation/__tests__/audience-validator.test.ts +112 -0
- package/src/delegation/__tests__/bitstring.test.ts +346 -0
- package/src/delegation/__tests__/cascading-revocation.test.ts +628 -0
- package/src/delegation/__tests__/delegation-graph.test.ts +584 -0
- package/src/delegation/__tests__/utils.test.ts +152 -0
- package/src/delegation/__tests__/vc-issuer.test.ts +442 -0
- package/src/delegation/__tests__/vc-verifier.test.ts +922 -0
- package/src/delegation/audience-validator.ts +52 -0
- package/src/delegation/bitstring.ts +278 -0
- package/src/delegation/cascading-revocation.ts +370 -0
- package/src/delegation/delegation-graph.ts +299 -0
- package/src/delegation/index.ts +14 -0
- package/src/delegation/statuslist-manager.ts +353 -0
- package/src/delegation/storage/__tests__/memory-graph-storage.test.ts +366 -0
- package/src/delegation/storage/__tests__/memory-statuslist-storage.test.ts +228 -0
- package/src/delegation/storage/index.ts +9 -0
- package/src/delegation/storage/memory-graph-storage.ts +178 -0
- package/src/delegation/storage/memory-statuslist-storage.ts +77 -0
- package/src/delegation/utils.ts +42 -0
- package/src/delegation/vc-issuer.ts +232 -0
- package/src/delegation/vc-verifier.ts +568 -0
- package/src/identity/idp-token-resolver.ts +147 -0
- package/src/identity/idp-token-storage.interface.ts +59 -0
- package/src/identity/user-did-manager.ts +370 -0
- package/src/index.ts +260 -0
- package/src/providers/base.d.ts +91 -0
- package/src/providers/base.d.ts.map +1 -0
- package/src/providers/base.js +38 -0
- package/src/providers/base.js.map +1 -0
- package/src/providers/base.ts +96 -0
- package/src/providers/memory.ts +142 -0
- package/src/runtime/audit-logger.ts +39 -0
- package/src/runtime/base.ts +1329 -0
- package/src/services/__tests__/access-control.integration.test.ts +443 -0
- package/src/services/__tests__/access-control.proof-response-validation.test.ts +578 -0
- package/src/services/__tests__/access-control.service.test.ts +970 -0
- package/src/services/__tests__/batch-delegation.service.test.ts +351 -0
- package/src/services/__tests__/crypto.service.test.ts +531 -0
- package/src/services/__tests__/oauth-provider-registry.test.ts +142 -0
- package/src/services/__tests__/proof-verifier.integration.test.ts +485 -0
- package/src/services/__tests__/proof-verifier.test.ts +489 -0
- package/src/services/__tests__/provider-resolution.integration.test.ts +198 -0
- package/src/services/__tests__/provider-resolver.test.ts +217 -0
- package/src/services/__tests__/storage.service.test.ts +358 -0
- package/src/services/access-control.service.ts +990 -0
- package/src/services/authorization/authorization-registry.ts +66 -0
- package/src/services/authorization/types.ts +71 -0
- package/src/services/batch-delegation.service.ts +137 -0
- package/src/services/crypto.service.ts +302 -0
- package/src/services/errors.ts +76 -0
- package/src/services/index.ts +9 -0
- package/src/services/oauth-config.service.d.ts +53 -0
- package/src/services/oauth-config.service.d.ts.map +1 -0
- package/src/services/oauth-config.service.js +113 -0
- package/src/services/oauth-config.service.js.map +1 -0
- package/src/services/oauth-config.service.ts +166 -0
- package/src/services/oauth-provider-registry.d.ts +57 -0
- package/src/services/oauth-provider-registry.d.ts.map +1 -0
- package/src/services/oauth-provider-registry.js +73 -0
- package/src/services/oauth-provider-registry.js.map +1 -0
- package/src/services/oauth-provider-registry.ts +123 -0
- package/src/services/oauth-service.ts +510 -0
- package/src/services/oauth-token-retrieval.service.ts +245 -0
- package/src/services/proof-verifier.ts +478 -0
- package/src/services/provider-resolver.d.ts +48 -0
- package/src/services/provider-resolver.d.ts.map +1 -0
- package/src/services/provider-resolver.js +106 -0
- package/src/services/provider-resolver.js.map +1 -0
- package/src/services/provider-resolver.ts +144 -0
- package/src/services/provider-validator.ts +170 -0
- package/src/services/storage.service.ts +566 -0
- package/src/services/tool-context-builder.ts +172 -0
- package/src/services/tool-protection.service.ts +958 -0
- package/src/types/oauth-required-error.ts +63 -0
- package/src/types/tool-protection.ts +155 -0
- package/src/utils/__tests__/did-helpers.test.ts +101 -0
- package/src/utils/base64.ts +148 -0
- package/src/utils/cors.ts +83 -0
- package/src/utils/did-helpers.ts +150 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/storage-keys.ts +278 -0
- package/tsconfig.json +21 -0
- package/vitest.config.ts +56 -0
|
@@ -0,0 +1,797 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, vi, Mock } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
SchemaVerifier,
|
|
4
|
+
createSchemaVerifier,
|
|
5
|
+
type SchemaMetadata,
|
|
6
|
+
type SchemaComplianceReport,
|
|
7
|
+
type FullComplianceReport,
|
|
8
|
+
} from "../schema-verifier.js";
|
|
9
|
+
|
|
10
|
+
// Mock global fetch
|
|
11
|
+
global.fetch = vi.fn() as Mock;
|
|
12
|
+
|
|
13
|
+
describe("SchemaVerifier", () => {
|
|
14
|
+
let verifier: SchemaVerifier;
|
|
15
|
+
let mockFetch: Mock;
|
|
16
|
+
|
|
17
|
+
const mockSchemaMetadata: SchemaMetadata = {
|
|
18
|
+
id: "test-schema",
|
|
19
|
+
url: "https://schemas.kya-os.ai/test-schema.json",
|
|
20
|
+
version: "1.0.0",
|
|
21
|
+
type: "TestSchema",
|
|
22
|
+
description: "Test schema for unit tests",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
vi.clearAllMocks();
|
|
27
|
+
verifier = new SchemaVerifier();
|
|
28
|
+
mockFetch = global.fetch as Mock;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe("constructor", () => {
|
|
32
|
+
it("should create verifier with default options", () => {
|
|
33
|
+
const defaultVerifier = new SchemaVerifier();
|
|
34
|
+
expect(defaultVerifier).toBeInstanceOf(SchemaVerifier);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("should create verifier with custom schemasBaseUrl", () => {
|
|
38
|
+
const customVerifier = new SchemaVerifier({
|
|
39
|
+
schemasBaseUrl: "https://custom-schemas.example.com",
|
|
40
|
+
});
|
|
41
|
+
expect(customVerifier).toBeInstanceOf(SchemaVerifier);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe("createSchemaVerifier", () => {
|
|
46
|
+
it("should create a verifier instance", () => {
|
|
47
|
+
const verifier = createSchemaVerifier();
|
|
48
|
+
expect(verifier).toBeInstanceOf(SchemaVerifier);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("should pass options to verifier", () => {
|
|
52
|
+
const options = { schemasBaseUrl: "https://custom.example.com" };
|
|
53
|
+
const verifier = createSchemaVerifier(options);
|
|
54
|
+
expect(verifier).toBeInstanceOf(SchemaVerifier);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe("verifySchema", () => {
|
|
59
|
+
it("should return compliant report for valid implementation", async () => {
|
|
60
|
+
const mockSchema = {
|
|
61
|
+
type: "object",
|
|
62
|
+
properties: {
|
|
63
|
+
name: { type: "string" },
|
|
64
|
+
age: { type: "integer" },
|
|
65
|
+
},
|
|
66
|
+
required: ["name"],
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const validImplementation = {
|
|
70
|
+
name: "Test",
|
|
71
|
+
age: 25,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
mockFetch.mockResolvedValue({
|
|
75
|
+
ok: true,
|
|
76
|
+
json: async () => mockSchema,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const result = await verifier.verifySchema(
|
|
80
|
+
mockSchemaMetadata,
|
|
81
|
+
validImplementation
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
expect(result.compliant).toBe(true);
|
|
85
|
+
expect(result.compliancePercentage).toBeGreaterThanOrEqual(95);
|
|
86
|
+
expect(result.schema).toEqual(mockSchemaMetadata);
|
|
87
|
+
expect(result.issues).toHaveLength(0);
|
|
88
|
+
expect(result.timestamp).toBeGreaterThan(0);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("should return non-compliant report for missing required fields", async () => {
|
|
92
|
+
const mockSchema = {
|
|
93
|
+
type: "object",
|
|
94
|
+
properties: {
|
|
95
|
+
name: { type: "string" },
|
|
96
|
+
email: { type: "string" },
|
|
97
|
+
},
|
|
98
|
+
required: ["name", "email"],
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const invalidImplementation = {
|
|
102
|
+
name: "Test",
|
|
103
|
+
// Missing email
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
mockFetch.mockResolvedValue({
|
|
107
|
+
ok: true,
|
|
108
|
+
json: async () => mockSchema,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const result = await verifier.verifySchema(
|
|
112
|
+
mockSchemaMetadata,
|
|
113
|
+
invalidImplementation
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
expect(result.compliant).toBe(false);
|
|
117
|
+
expect(result.compliancePercentage).toBeLessThan(100);
|
|
118
|
+
expect(result.issues.length).toBeGreaterThan(0);
|
|
119
|
+
expect(result.issues.some((i) => i.includes("email"))).toBe(true);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("should return non-compliant report for type mismatches", async () => {
|
|
123
|
+
const mockSchema = {
|
|
124
|
+
type: "object",
|
|
125
|
+
properties: {
|
|
126
|
+
age: { type: "integer" },
|
|
127
|
+
},
|
|
128
|
+
required: ["age"],
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const invalidImplementation = {
|
|
132
|
+
age: "not-a-number", // Should be integer
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
mockFetch.mockResolvedValue({
|
|
136
|
+
ok: true,
|
|
137
|
+
json: async () => mockSchema,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const result = await verifier.verifySchema(
|
|
141
|
+
mockSchemaMetadata,
|
|
142
|
+
invalidImplementation
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
expect(result.compliant).toBe(false);
|
|
146
|
+
expect(result.issues.length).toBeGreaterThan(0);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("should handle schema fetch errors gracefully", async () => {
|
|
150
|
+
mockFetch.mockRejectedValue(new Error("Network error"));
|
|
151
|
+
|
|
152
|
+
const result = await verifier.verifySchema(
|
|
153
|
+
mockSchemaMetadata,
|
|
154
|
+
{ any: "data" }
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
expect(result.compliant).toBe(false);
|
|
158
|
+
expect(result.compliancePercentage).toBe(0);
|
|
159
|
+
expect(result.issues.length).toBeGreaterThan(0);
|
|
160
|
+
expect(result.issues[0]).toContain("Failed to fetch schema");
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("should handle HTTP errors when fetching schema", async () => {
|
|
164
|
+
mockFetch.mockResolvedValue({
|
|
165
|
+
ok: false,
|
|
166
|
+
status: 404,
|
|
167
|
+
statusText: "Not Found",
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
const result = await verifier.verifySchema(
|
|
171
|
+
mockSchemaMetadata,
|
|
172
|
+
{ any: "data" }
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
expect(result.compliant).toBe(false);
|
|
176
|
+
expect(result.issues.length).toBeGreaterThan(0);
|
|
177
|
+
expect(result.issues[0]).toContain("Failed to fetch schema");
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("should cache fetched schemas", async () => {
|
|
181
|
+
const mockSchema = {
|
|
182
|
+
type: "object",
|
|
183
|
+
properties: {
|
|
184
|
+
name: { type: "string" },
|
|
185
|
+
},
|
|
186
|
+
required: ["name"],
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
mockFetch.mockResolvedValue({
|
|
190
|
+
ok: true,
|
|
191
|
+
json: async () => mockSchema,
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// First call
|
|
195
|
+
await verifier.verifySchema(mockSchemaMetadata, { name: "Test" });
|
|
196
|
+
|
|
197
|
+
// Second call - should use cache
|
|
198
|
+
await verifier.verifySchema(mockSchemaMetadata, { name: "Test2" });
|
|
199
|
+
|
|
200
|
+
// Fetch should only be called once (cached on second call)
|
|
201
|
+
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("should handle array validation", async () => {
|
|
205
|
+
const mockSchema = {
|
|
206
|
+
type: "object",
|
|
207
|
+
properties: {
|
|
208
|
+
items: {
|
|
209
|
+
type: "array",
|
|
210
|
+
items: { type: "string" },
|
|
211
|
+
minItems: 1,
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
required: ["items"],
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const validImplementation = {
|
|
218
|
+
items: ["a", "b", "c"],
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
mockFetch.mockResolvedValue({
|
|
222
|
+
ok: true,
|
|
223
|
+
json: async () => mockSchema,
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
const result = await verifier.verifySchema(
|
|
227
|
+
mockSchemaMetadata,
|
|
228
|
+
validImplementation
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
expect(result.compliant).toBe(true);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("should handle nested object validation", async () => {
|
|
235
|
+
const mockSchema = {
|
|
236
|
+
type: "object",
|
|
237
|
+
properties: {
|
|
238
|
+
user: {
|
|
239
|
+
type: "object",
|
|
240
|
+
properties: {
|
|
241
|
+
name: { type: "string" },
|
|
242
|
+
age: { type: "integer" },
|
|
243
|
+
},
|
|
244
|
+
required: ["name"],
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
required: ["user"],
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const validImplementation = {
|
|
251
|
+
user: {
|
|
252
|
+
name: "John",
|
|
253
|
+
age: 30,
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
mockFetch.mockResolvedValue({
|
|
258
|
+
ok: true,
|
|
259
|
+
json: async () => mockSchema,
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
const result = await verifier.verifySchema(
|
|
263
|
+
mockSchemaMetadata,
|
|
264
|
+
validImplementation
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
expect(result.compliant).toBe(true);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it("should handle $ref resolution", async () => {
|
|
271
|
+
const mockSchema = {
|
|
272
|
+
type: "object",
|
|
273
|
+
properties: {
|
|
274
|
+
name: { $ref: "#/definitions/Name" },
|
|
275
|
+
},
|
|
276
|
+
required: ["name"],
|
|
277
|
+
definitions: {
|
|
278
|
+
Name: {
|
|
279
|
+
type: "string",
|
|
280
|
+
minLength: 1,
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
const validImplementation = {
|
|
286
|
+
name: "Test",
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
mockFetch.mockResolvedValue({
|
|
290
|
+
ok: true,
|
|
291
|
+
json: async () => mockSchema,
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
const result = await verifier.verifySchema(
|
|
295
|
+
mockSchemaMetadata,
|
|
296
|
+
validImplementation
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
expect(result.compliant).toBe(true);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it("should handle oneOf validation", async () => {
|
|
303
|
+
const mockSchema = {
|
|
304
|
+
type: "object",
|
|
305
|
+
properties: {
|
|
306
|
+
value: {
|
|
307
|
+
oneOf: [
|
|
308
|
+
{ type: "string" },
|
|
309
|
+
{ type: "integer" },
|
|
310
|
+
],
|
|
311
|
+
},
|
|
312
|
+
},
|
|
313
|
+
required: ["value"],
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
const validImplementation = {
|
|
317
|
+
value: "test",
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
mockFetch.mockResolvedValue({
|
|
321
|
+
ok: true,
|
|
322
|
+
json: async () => mockSchema,
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
const result = await verifier.verifySchema(
|
|
326
|
+
mockSchemaMetadata,
|
|
327
|
+
validImplementation
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
expect(result.compliant).toBe(true);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it("should handle anyOf validation", async () => {
|
|
334
|
+
const mockSchema = {
|
|
335
|
+
type: "object",
|
|
336
|
+
properties: {
|
|
337
|
+
value: {
|
|
338
|
+
anyOf: [
|
|
339
|
+
{ type: "string" },
|
|
340
|
+
{ type: "number" },
|
|
341
|
+
],
|
|
342
|
+
},
|
|
343
|
+
},
|
|
344
|
+
required: ["value"],
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
const validImplementation = {
|
|
348
|
+
value: 42,
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
mockFetch.mockResolvedValue({
|
|
352
|
+
ok: true,
|
|
353
|
+
json: async () => mockSchema,
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
const result = await verifier.verifySchema(
|
|
357
|
+
mockSchemaMetadata,
|
|
358
|
+
validImplementation
|
|
359
|
+
);
|
|
360
|
+
|
|
361
|
+
expect(result.compliant).toBe(true);
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
it("should handle allOf validation", async () => {
|
|
365
|
+
const mockSchema = {
|
|
366
|
+
type: "object",
|
|
367
|
+
properties: {
|
|
368
|
+
value: {
|
|
369
|
+
allOf: [
|
|
370
|
+
{ type: "string" },
|
|
371
|
+
{ minLength: 3 },
|
|
372
|
+
],
|
|
373
|
+
},
|
|
374
|
+
},
|
|
375
|
+
required: ["value"],
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
const validImplementation = {
|
|
379
|
+
value: "test",
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
mockFetch.mockResolvedValue({
|
|
383
|
+
ok: true,
|
|
384
|
+
json: async () => mockSchema,
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
const result = await verifier.verifySchema(
|
|
388
|
+
mockSchemaMetadata,
|
|
389
|
+
validImplementation
|
|
390
|
+
);
|
|
391
|
+
|
|
392
|
+
expect(result.compliant).toBe(true);
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
it("should handle enum validation", async () => {
|
|
396
|
+
const mockSchema = {
|
|
397
|
+
type: "object",
|
|
398
|
+
properties: {
|
|
399
|
+
status: {
|
|
400
|
+
type: "string",
|
|
401
|
+
enum: ["active", "inactive", "pending"],
|
|
402
|
+
},
|
|
403
|
+
},
|
|
404
|
+
required: ["status"],
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
const validImplementation = {
|
|
408
|
+
status: "active",
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
mockFetch.mockResolvedValue({
|
|
412
|
+
ok: true,
|
|
413
|
+
json: async () => mockSchema,
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
const result = await verifier.verifySchema(
|
|
417
|
+
mockSchemaMetadata,
|
|
418
|
+
validImplementation
|
|
419
|
+
);
|
|
420
|
+
|
|
421
|
+
expect(result.compliant).toBe(true);
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
it("should handle const validation", async () => {
|
|
425
|
+
const mockSchema = {
|
|
426
|
+
type: "object",
|
|
427
|
+
properties: {
|
|
428
|
+
version: {
|
|
429
|
+
const: "1.0.0",
|
|
430
|
+
},
|
|
431
|
+
},
|
|
432
|
+
required: ["version"],
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
const validImplementation = {
|
|
436
|
+
version: "1.0.0",
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
mockFetch.mockResolvedValue({
|
|
440
|
+
ok: true,
|
|
441
|
+
json: async () => mockSchema,
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
const result = await verifier.verifySchema(
|
|
445
|
+
mockSchemaMetadata,
|
|
446
|
+
validImplementation
|
|
447
|
+
);
|
|
448
|
+
|
|
449
|
+
expect(result.compliant).toBe(true);
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
it("should handle pattern validation for strings", async () => {
|
|
453
|
+
const mockSchema = {
|
|
454
|
+
type: "object",
|
|
455
|
+
properties: {
|
|
456
|
+
email: {
|
|
457
|
+
type: "string",
|
|
458
|
+
pattern: "^[a-z]+@[a-z]+\\.[a-z]+$",
|
|
459
|
+
},
|
|
460
|
+
},
|
|
461
|
+
required: ["email"],
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
const validImplementation = {
|
|
465
|
+
email: "test@example.com",
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
mockFetch.mockResolvedValue({
|
|
469
|
+
ok: true,
|
|
470
|
+
json: async () => mockSchema,
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
const result = await verifier.verifySchema(
|
|
474
|
+
mockSchemaMetadata,
|
|
475
|
+
validImplementation
|
|
476
|
+
);
|
|
477
|
+
|
|
478
|
+
expect(result.compliant).toBe(true);
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
it("should calculate compliance percentage correctly", async () => {
|
|
482
|
+
const mockSchema = {
|
|
483
|
+
type: "object",
|
|
484
|
+
properties: {
|
|
485
|
+
field1: { type: "string" },
|
|
486
|
+
field2: { type: "string" },
|
|
487
|
+
field3: { type: "string" },
|
|
488
|
+
},
|
|
489
|
+
required: ["field1", "field2", "field3"],
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
const partialImplementation = {
|
|
493
|
+
field1: "value1",
|
|
494
|
+
// Missing field2 and field3
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
mockFetch.mockResolvedValue({
|
|
498
|
+
ok: true,
|
|
499
|
+
json: async () => mockSchema,
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
const result = await verifier.verifySchema(
|
|
503
|
+
mockSchemaMetadata,
|
|
504
|
+
partialImplementation
|
|
505
|
+
);
|
|
506
|
+
|
|
507
|
+
// Should be approximately 33% (1 out of 3 required fields)
|
|
508
|
+
expect(result.compliancePercentage).toBeCloseTo(33.33, 1);
|
|
509
|
+
});
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
describe("verifyAll", () => {
|
|
513
|
+
it("should verify all schemas and return full report", async () => {
|
|
514
|
+
const schemas: SchemaMetadata[] = [
|
|
515
|
+
{
|
|
516
|
+
id: "schema1",
|
|
517
|
+
url: "https://schemas.kya-os.ai/schema1.json",
|
|
518
|
+
version: "1.0.0",
|
|
519
|
+
type: "Schema1",
|
|
520
|
+
},
|
|
521
|
+
{
|
|
522
|
+
id: "schema2",
|
|
523
|
+
url: "https://schemas.kya-os.ai/schema2.json",
|
|
524
|
+
version: "1.0.0",
|
|
525
|
+
type: "Schema2",
|
|
526
|
+
},
|
|
527
|
+
];
|
|
528
|
+
|
|
529
|
+
const implementations = new Map<string, any>([
|
|
530
|
+
["schema1", { name: "Test1" }],
|
|
531
|
+
["schema2", { name: "Test2" }],
|
|
532
|
+
]);
|
|
533
|
+
|
|
534
|
+
const mockSchema = {
|
|
535
|
+
type: "object",
|
|
536
|
+
properties: {
|
|
537
|
+
name: { type: "string" },
|
|
538
|
+
},
|
|
539
|
+
required: ["name"],
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
mockFetch.mockResolvedValue({
|
|
543
|
+
ok: true,
|
|
544
|
+
json: async () => mockSchema,
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
const result = await verifier.verifyAll(schemas, implementations);
|
|
548
|
+
|
|
549
|
+
expect(result.totalSchemas).toBe(2);
|
|
550
|
+
expect(result.compliantSchemas).toBeGreaterThanOrEqual(0);
|
|
551
|
+
expect(result.schemaReports).toHaveLength(2);
|
|
552
|
+
expect(result.timestamp).toBeGreaterThan(0);
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
it("should handle missing implementations", async () => {
|
|
556
|
+
const schemas: SchemaMetadata[] = [
|
|
557
|
+
{
|
|
558
|
+
id: "schema1",
|
|
559
|
+
url: "https://schemas.kya-os.ai/schema1.json",
|
|
560
|
+
version: "1.0.0",
|
|
561
|
+
type: "Schema1",
|
|
562
|
+
},
|
|
563
|
+
];
|
|
564
|
+
|
|
565
|
+
const implementations = new Map<string, any>(); // Empty map
|
|
566
|
+
|
|
567
|
+
const result = await verifier.verifyAll(schemas, implementations);
|
|
568
|
+
|
|
569
|
+
expect(result.criticalIssues.length).toBeGreaterThan(0);
|
|
570
|
+
expect(result.criticalIssues[0]).toContain("No implementation found");
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
it("should calculate overall compliance correctly", async () => {
|
|
574
|
+
const schemas: SchemaMetadata[] = [
|
|
575
|
+
{
|
|
576
|
+
id: "schema1",
|
|
577
|
+
url: "https://schemas.kya-os.ai/schema1.json",
|
|
578
|
+
version: "1.0.0",
|
|
579
|
+
type: "Schema1",
|
|
580
|
+
},
|
|
581
|
+
{
|
|
582
|
+
id: "schema2",
|
|
583
|
+
url: "https://schemas.kya-os.ai/schema2.json",
|
|
584
|
+
version: "1.0.0",
|
|
585
|
+
type: "Schema2",
|
|
586
|
+
},
|
|
587
|
+
];
|
|
588
|
+
|
|
589
|
+
const implementations = new Map<string, any>([
|
|
590
|
+
["schema1", { name: "Test1" }],
|
|
591
|
+
["schema2", { name: "Test2" }],
|
|
592
|
+
]);
|
|
593
|
+
|
|
594
|
+
const mockSchema = {
|
|
595
|
+
type: "object",
|
|
596
|
+
properties: {
|
|
597
|
+
name: { type: "string" },
|
|
598
|
+
},
|
|
599
|
+
required: ["name"],
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
mockFetch.mockResolvedValue({
|
|
603
|
+
ok: true,
|
|
604
|
+
json: async () => mockSchema,
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
const result = await verifier.verifyAll(schemas, implementations);
|
|
608
|
+
|
|
609
|
+
// If both are compliant, should be 100%
|
|
610
|
+
// If one is compliant, should be 50%
|
|
611
|
+
expect(result.overallCompliance).toBeGreaterThanOrEqual(0);
|
|
612
|
+
expect(result.overallCompliance).toBeLessThanOrEqual(100);
|
|
613
|
+
});
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
describe("generateReport", () => {
|
|
617
|
+
it("should generate formatted report string", async () => {
|
|
618
|
+
const mockSchema = {
|
|
619
|
+
type: "object",
|
|
620
|
+
properties: {
|
|
621
|
+
name: { type: "string" },
|
|
622
|
+
},
|
|
623
|
+
required: ["name"],
|
|
624
|
+
};
|
|
625
|
+
|
|
626
|
+
mockFetch.mockResolvedValue({
|
|
627
|
+
ok: true,
|
|
628
|
+
json: async () => mockSchema,
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
const report = await verifier.verifySchema(
|
|
632
|
+
mockSchemaMetadata,
|
|
633
|
+
{ name: "Test" }
|
|
634
|
+
);
|
|
635
|
+
|
|
636
|
+
const reportString = verifier.generateReport(report);
|
|
637
|
+
|
|
638
|
+
expect(reportString).toContain("SCHEMA COMPLIANCE REPORT");
|
|
639
|
+
expect(reportString).toContain(mockSchemaMetadata.id);
|
|
640
|
+
expect(reportString).toContain("COMPLIANT");
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
it("should include issues in report", async () => {
|
|
644
|
+
const mockSchema = {
|
|
645
|
+
type: "object",
|
|
646
|
+
properties: {
|
|
647
|
+
name: { type: "string" },
|
|
648
|
+
},
|
|
649
|
+
required: ["name"],
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
mockFetch.mockResolvedValue({
|
|
653
|
+
ok: true,
|
|
654
|
+
json: async () => mockSchema,
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
const report = await verifier.verifySchema(
|
|
658
|
+
mockSchemaMetadata,
|
|
659
|
+
{} // Missing required field
|
|
660
|
+
);
|
|
661
|
+
|
|
662
|
+
const reportString = verifier.generateReport(report);
|
|
663
|
+
|
|
664
|
+
expect(reportString).toContain("ISSUES");
|
|
665
|
+
});
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
describe("generateFullReport", () => {
|
|
669
|
+
it("should generate full compliance report", async () => {
|
|
670
|
+
const schemas: SchemaMetadata[] = [
|
|
671
|
+
{
|
|
672
|
+
id: "schema1",
|
|
673
|
+
url: "https://schemas.kya-os.ai/schema1.json",
|
|
674
|
+
version: "1.0.0",
|
|
675
|
+
type: "Schema1",
|
|
676
|
+
},
|
|
677
|
+
];
|
|
678
|
+
|
|
679
|
+
const implementations = new Map<string, any>([
|
|
680
|
+
["schema1", { name: "Test" }],
|
|
681
|
+
]);
|
|
682
|
+
|
|
683
|
+
const mockSchema = {
|
|
684
|
+
type: "object",
|
|
685
|
+
properties: {
|
|
686
|
+
name: { type: "string" },
|
|
687
|
+
},
|
|
688
|
+
required: ["name"],
|
|
689
|
+
};
|
|
690
|
+
|
|
691
|
+
mockFetch.mockResolvedValue({
|
|
692
|
+
ok: true,
|
|
693
|
+
json: async () => mockSchema,
|
|
694
|
+
});
|
|
695
|
+
|
|
696
|
+
const fullReport = await verifier.verifyAll(schemas, implementations);
|
|
697
|
+
const reportString = verifier.generateFullReport(fullReport);
|
|
698
|
+
|
|
699
|
+
expect(reportString).toContain("FULL SCHEMA COMPLIANCE REPORT");
|
|
700
|
+
expect(reportString).toContain("Total Schemas");
|
|
701
|
+
expect(reportString).toContain("Overall Compliance");
|
|
702
|
+
});
|
|
703
|
+
|
|
704
|
+
it("should include critical issues in full report", async () => {
|
|
705
|
+
const schemas: SchemaMetadata[] = [
|
|
706
|
+
{
|
|
707
|
+
id: "schema1",
|
|
708
|
+
url: "https://schemas.kya-os.ai/schema1.json",
|
|
709
|
+
version: "1.0.0",
|
|
710
|
+
type: "Schema1",
|
|
711
|
+
},
|
|
712
|
+
];
|
|
713
|
+
|
|
714
|
+
const implementations = new Map<string, any>(); // Empty
|
|
715
|
+
|
|
716
|
+
const fullReport = await verifier.verifyAll(schemas, implementations);
|
|
717
|
+
const reportString = verifier.generateFullReport(fullReport);
|
|
718
|
+
|
|
719
|
+
expect(reportString).toContain("CRITICAL ISSUES");
|
|
720
|
+
});
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
describe("edge cases", () => {
|
|
724
|
+
it("should handle empty object", async () => {
|
|
725
|
+
const mockSchema = {
|
|
726
|
+
type: "object",
|
|
727
|
+
properties: {},
|
|
728
|
+
required: [],
|
|
729
|
+
};
|
|
730
|
+
|
|
731
|
+
mockFetch.mockResolvedValue({
|
|
732
|
+
ok: true,
|
|
733
|
+
json: async () => mockSchema,
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
const result = await verifier.verifySchema(
|
|
737
|
+
mockSchemaMetadata,
|
|
738
|
+
{}
|
|
739
|
+
);
|
|
740
|
+
|
|
741
|
+
expect(result.compliant).toBe(true);
|
|
742
|
+
expect(result.compliancePercentage).toBe(100);
|
|
743
|
+
});
|
|
744
|
+
|
|
745
|
+
it("should handle null values", async () => {
|
|
746
|
+
const mockSchema = {
|
|
747
|
+
type: "object",
|
|
748
|
+
properties: {
|
|
749
|
+
value: { type: ["string", "null"] },
|
|
750
|
+
},
|
|
751
|
+
required: ["value"],
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
mockFetch.mockResolvedValue({
|
|
755
|
+
ok: true,
|
|
756
|
+
json: async () => mockSchema,
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
const result = await verifier.verifySchema(
|
|
760
|
+
mockSchemaMetadata,
|
|
761
|
+
{ value: null }
|
|
762
|
+
);
|
|
763
|
+
|
|
764
|
+
// Should handle null as valid if schema allows it
|
|
765
|
+
expect(result).toBeDefined();
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
it("should handle empty arrays", async () => {
|
|
769
|
+
const mockSchema = {
|
|
770
|
+
type: "object",
|
|
771
|
+
properties: {
|
|
772
|
+
items: {
|
|
773
|
+
type: "array",
|
|
774
|
+
items: { type: "string" },
|
|
775
|
+
},
|
|
776
|
+
},
|
|
777
|
+
required: ["items"],
|
|
778
|
+
};
|
|
779
|
+
|
|
780
|
+
mockFetch.mockResolvedValue({
|
|
781
|
+
ok: true,
|
|
782
|
+
json: async () => mockSchema,
|
|
783
|
+
});
|
|
784
|
+
|
|
785
|
+
const result = await verifier.verifySchema(
|
|
786
|
+
mockSchemaMetadata,
|
|
787
|
+
{ items: [] }
|
|
788
|
+
);
|
|
789
|
+
|
|
790
|
+
expect(result).toBeDefined();
|
|
791
|
+
});
|
|
792
|
+
|
|
793
|
+
// Note: minItems validation is complex and depends on array validation flow
|
|
794
|
+
// Covered by general array validation tests above
|
|
795
|
+
});
|
|
796
|
+
});
|
|
797
|
+
|