@codelitdev/platform-conformance 0.1.0-alpha.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CodeLit
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,61 @@
1
+ export type PlatformConformanceAdapter<Principal, Tenant, SessionCredential, OAuthCredential, ApiKeyCredential, HttpInput, McpInput, McpOutput, AuditEvent> = {
2
+ reset(): Promise<void>;
3
+ /** Optional cleanup for fixtures that allocate an HTTP listener. */
4
+ close?(): Promise<void>;
5
+ fixtures: {
6
+ owner: Principal;
7
+ member: Principal;
8
+ outsider: Principal;
9
+ tenantA: Tenant;
10
+ tenantB: Tenant;
11
+ };
12
+ credentials: {
13
+ session(principal: Principal): Promise<SessionCredential>;
14
+ oauth(principal: Principal): Promise<OAuthCredential>;
15
+ apiKey(tenant: Tenant, permissions: readonly string[]): Promise<ApiKeyCredential>;
16
+ system?(principal: Principal): Promise<{
17
+ kind: "system";
18
+ }>;
19
+ };
20
+ http(input: HttpInput): Promise<{
21
+ status: number;
22
+ body: unknown;
23
+ headers?: Record<string, string>;
24
+ }>;
25
+ mcp?(input: McpInput): Promise<McpOutput>;
26
+ readAuditEvents(): Promise<readonly AuditEvent[]>;
27
+ openapiDocument?(): Promise<{
28
+ paths: Record<string, unknown>;
29
+ contractOperationIds: readonly string[];
30
+ }>;
31
+ observability?: {
32
+ redact(secret: string): Promise<string>;
33
+ disabledDoesNotThrow(): Promise<{
34
+ threw: boolean;
35
+ }>;
36
+ failingSinkDoesNotFailRequest(): Promise<{
37
+ requestStatus: number;
38
+ }>;
39
+ };
40
+ billingComposition?: {
41
+ generatedSchemaCurrent(): Promise<boolean>;
42
+ actionGrantRejected(): Promise<boolean>;
43
+ fakeProviderWorks(): Promise<boolean>;
44
+ maintenanceInvoked(): Promise<boolean>;
45
+ auditRecorded(): Promise<boolean>;
46
+ };
47
+ shutdown?(): Promise<{
48
+ mcpStatus: number;
49
+ }>;
50
+ };
51
+ export type ConformanceCapabilities = {
52
+ mcp?: boolean;
53
+ billing?: boolean;
54
+ observability?: boolean;
55
+ openapi?: boolean;
56
+ shutdown?: boolean;
57
+ };
58
+ export type ConformanceFailure = {
59
+ suite: string;
60
+ message: string;
61
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export type { ConformanceCapabilities, ConformanceFailure, PlatformConformanceAdapter, } from "./adapter.js";
2
+ export { type ReferenceHttpInput, type ReferenceMcpInput, runPlatformConformance, } from "./run.js";
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { runPlatformConformance, } from "./run.js";
package/dist/run.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ import type { ConformanceCapabilities, ConformanceFailure, PlatformConformanceAdapter } from "./adapter.js";
2
+ export type ReferenceHttpInput = {
3
+ method: string;
4
+ path: string;
5
+ headers: Record<string, string | undefined>;
6
+ body?: unknown;
7
+ };
8
+ export type ReferenceMcpInput = {
9
+ headers: Record<string, string | undefined>;
10
+ tool: string;
11
+ args?: unknown;
12
+ };
13
+ type HttpAdapter = PlatformConformanceAdapter<{
14
+ id: string;
15
+ sessionCookie?: string;
16
+ oauthToken?: string;
17
+ }, {
18
+ id: string;
19
+ publicId: string;
20
+ }, {
21
+ cookie: string;
22
+ }, {
23
+ authorization: string;
24
+ }, {
25
+ apiKey: string;
26
+ }, ReferenceHttpInput, ReferenceMcpInput, {
27
+ status: number;
28
+ body: unknown;
29
+ }, {
30
+ action: string;
31
+ resourceId: string;
32
+ actorId: string;
33
+ }>;
34
+ export declare function runPlatformConformance(adapter: HttpAdapter, capabilities?: ConformanceCapabilities): Promise<{
35
+ failures: ConformanceFailure[];
36
+ }>;
37
+ export {};
package/dist/run.js ADDED
@@ -0,0 +1,266 @@
1
+ function errorCode(body) {
2
+ if (!body || typeof body !== "object")
3
+ return undefined;
4
+ if ("code" in body && typeof body.code === "string")
5
+ return body.code;
6
+ if ("error" in body &&
7
+ body.error &&
8
+ typeof body.error === "object" &&
9
+ "code" in body.error &&
10
+ typeof body.error.code === "string") {
11
+ return body.error.code;
12
+ }
13
+ return undefined;
14
+ }
15
+ export async function runPlatformConformance(adapter, capabilities = {}) {
16
+ const failures = [];
17
+ const fail = (suite, message) => {
18
+ failures.push({ suite, message });
19
+ };
20
+ if (capabilities.mcp && typeof adapter.mcp !== "function") {
21
+ fail("capabilities", "declared mcp capability has no mcp fixture");
22
+ return { failures };
23
+ }
24
+ if (capabilities.observability && !adapter.observability) {
25
+ fail("capabilities", "declared observability capability has no observability fixture");
26
+ return { failures };
27
+ }
28
+ if (capabilities.billing && !adapter.billingComposition) {
29
+ fail("capabilities", "declared billing capability has no billingComposition fixture");
30
+ return { failures };
31
+ }
32
+ if (capabilities.openapi && typeof adapter.openapiDocument !== "function") {
33
+ fail("capabilities", "declared openapi capability has no openapi fixture");
34
+ return { failures };
35
+ }
36
+ if (capabilities.shutdown && typeof adapter.shutdown !== "function") {
37
+ fail("capabilities", "declared shutdown capability has no shutdown fixture");
38
+ return { failures };
39
+ }
40
+ await adapter.reset();
41
+ const { owner, member, tenantA, tenantB } = adapter.fixtures;
42
+ const session = await adapter.credentials.session(owner);
43
+ const oauth = await adapter.credentials.oauth(owner);
44
+ const apiKey = await adapter.credentials.apiKey(tenantA, [
45
+ "notes:read",
46
+ "notes:write",
47
+ "notes:delete",
48
+ "billing:read",
49
+ ]);
50
+ const health = await adapter.http({
51
+ method: "GET",
52
+ path: "/health",
53
+ headers: {},
54
+ });
55
+ if (health.status !== 200 || health.body.status !== "ok") {
56
+ fail("lifecycle", "health body is not ok");
57
+ }
58
+ const ready = await adapter.http({
59
+ method: "GET",
60
+ path: "/ready",
61
+ headers: {},
62
+ });
63
+ if (ready.body.status !== "ready") {
64
+ fail("lifecycle", "readiness body is not ready");
65
+ }
66
+ const ambiguous = await adapter.http({
67
+ method: "GET",
68
+ path: "/v1/notes",
69
+ headers: {
70
+ cookie: session.cookie,
71
+ authorization: oauth.authorization,
72
+ },
73
+ });
74
+ if (errorCode(ambiguous.body) !== "credential_ambiguous") {
75
+ fail("auth", "multiple credentials did not return credential_ambiguous");
76
+ }
77
+ const invalid = await adapter.http({
78
+ method: "GET",
79
+ path: "/v1/notes",
80
+ headers: { authorization: "Bearer totally-invalid" },
81
+ });
82
+ if (errorCode(invalid.body) !== "unauthenticated") {
83
+ fail("auth", "invalid bearer did not return unauthenticated");
84
+ }
85
+ const keyCross = await adapter.http({
86
+ method: "GET",
87
+ path: "/v1/notes",
88
+ headers: {
89
+ "x-api-key": apiKey.apiKey,
90
+ "x-tenant-id": tenantB.publicId,
91
+ },
92
+ });
93
+ const keyBody = keyCross.body;
94
+ if (keyCross.status !== 200 ||
95
+ !keyBody.items?.every((item) => item.tenantId === tenantA.publicId)) {
96
+ fail("tenancy", "API key selected another tenant");
97
+ }
98
+ const memberSession = await adapter.credentials.session(member);
99
+ const cross = await adapter.http({
100
+ method: "PATCH",
101
+ path: "/v1/notes/missing-from-b",
102
+ headers: {
103
+ cookie: memberSession.cookie,
104
+ "x-tenant-id": tenantB.publicId,
105
+ },
106
+ body: { title: "x" },
107
+ });
108
+ if (errorCode(cross.body) !== "tenant_forbidden") {
109
+ fail("tenancy", "member of A was not denied tenant B");
110
+ }
111
+ const outsider = await adapter.credentials.session(adapter.fixtures.outsider);
112
+ const outsiderResponse = await adapter.http({
113
+ method: "GET",
114
+ path: "/v1/notes",
115
+ headers: {
116
+ cookie: outsider.cookie,
117
+ "x-tenant-id": tenantA.publicId,
118
+ },
119
+ });
120
+ if (errorCode(outsiderResponse.body) !== "tenant_forbidden") {
121
+ fail("tenancy", "outsider was allowed to read a tenant");
122
+ }
123
+ const created = await adapter.http({
124
+ method: "POST",
125
+ path: "/v1/notes",
126
+ headers: { cookie: session.cookie, "x-tenant-id": tenantA.publicId },
127
+ body: { title: "conformance note", body: "created by the suite" },
128
+ });
129
+ if (created.status !== 201) {
130
+ fail("rest", "authorized mutation did not succeed");
131
+ }
132
+ else if (adapter.readAuditEvents) {
133
+ const events = await adapter.readAuditEvents();
134
+ if (!events.some((event) => event.action === "note.created")) {
135
+ fail("rest", "authorized mutation did not emit an audit event");
136
+ }
137
+ }
138
+ if (capabilities.mcp) {
139
+ const mcpList = await adapter.mcp({
140
+ headers: {
141
+ authorization: oauth.authorization,
142
+ "x-tenant-id": tenantA.publicId,
143
+ },
144
+ tool: "notes.list",
145
+ args: {},
146
+ });
147
+ const mcpBody = mcpList.body;
148
+ if (mcpList.status !== 200 || !mcpBody.result) {
149
+ fail("mcp", "notes.list MCP call failed");
150
+ }
151
+ const cookieMcp = await adapter.mcp({
152
+ headers: { cookie: session.cookie },
153
+ tool: "notes.list",
154
+ args: {},
155
+ });
156
+ if (errorCode(cookieMcp.body) !== "unauthenticated") {
157
+ fail("mcp", "browser session was accepted on MCP");
158
+ }
159
+ const unconfirmed = await adapter.mcp({
160
+ headers: {
161
+ authorization: oauth.authorization,
162
+ "x-tenant-id": tenantA.publicId,
163
+ },
164
+ tool: "notes.delete",
165
+ args: { noteId: "conformance-missing" },
166
+ });
167
+ if (errorCode(unconfirmed.body) !== "forbidden") {
168
+ fail("mcp", "destructive MCP call did not require confirmation");
169
+ }
170
+ const confirmed = await adapter.mcp({
171
+ headers: {
172
+ authorization: oauth.authorization,
173
+ "x-tenant-id": tenantA.publicId,
174
+ },
175
+ tool: "notes.delete",
176
+ args: { noteId: "conformance-missing", confirm: true },
177
+ });
178
+ if (errorCode(confirmed.body) !== "not_found") {
179
+ fail("mcp", "confirmed destructive MCP call did not map not_found");
180
+ }
181
+ }
182
+ const invalidRest = await adapter.http({
183
+ method: "POST",
184
+ path: "/v1/notes",
185
+ headers: {
186
+ cookie: session.cookie,
187
+ "x-tenant-id": tenantA.publicId,
188
+ },
189
+ body: { title: "" },
190
+ });
191
+ if (errorCode(invalidRest.body) !== "validation_failed") {
192
+ fail("rest", "invalid create body did not return validation_failed");
193
+ }
194
+ if (capabilities.openapi) {
195
+ const document = await adapter.openapiDocument();
196
+ if (!document.paths["/v1/notes"]) {
197
+ fail("openapi", "ts-rest contract is missing /v1/notes");
198
+ }
199
+ if (!document.contractOperationIds.includes("listNotes")) {
200
+ fail("openapi", "ts-rest contract is missing listNotes");
201
+ }
202
+ for (const operationId of ["createNote", "updateNote", "deleteNote"]) {
203
+ if (!document.contractOperationIds.includes(operationId)) {
204
+ fail("openapi", `ts-rest contract is missing ${operationId}`);
205
+ }
206
+ }
207
+ }
208
+ if (capabilities.observability) {
209
+ const obs = adapter.observability;
210
+ const redacted = await obs.redact("secret-token-abcdefghijklmnopqrstuvwxyz");
211
+ if (redacted.includes("secret-token-abcdefghijklmnopqrstuvwxyz")) {
212
+ fail("observability", "secret was not redacted");
213
+ }
214
+ const disabled = await obs.disabledDoesNotThrow();
215
+ if (disabled.threw) {
216
+ fail("observability", "disabled observability threw");
217
+ }
218
+ const isolated = await obs.failingSinkDoesNotFailRequest();
219
+ if (isolated.requestStatus >= 500) {
220
+ fail("observability", "failing sink failed the request");
221
+ }
222
+ }
223
+ if (capabilities.billing) {
224
+ const entitlement = await adapter.http({
225
+ method: "GET",
226
+ path: "/v1/billing/entitlement",
227
+ headers: {
228
+ cookie: session.cookie,
229
+ "x-tenant-id": tenantA.publicId,
230
+ },
231
+ });
232
+ const body = entitlement.body;
233
+ if (entitlement.status !== 200 || typeof body.entitled !== "boolean") {
234
+ fail("billing", "entitlement was not returned");
235
+ }
236
+ const composition = adapter.billingComposition;
237
+ if (!(await composition.generatedSchemaCurrent())) {
238
+ fail("billing", "generated billing schema drifted");
239
+ }
240
+ if (!(await composition.actionGrantRejected())) {
241
+ fail("billing", "action grant did not reject an invalid grant");
242
+ }
243
+ if (!(await composition.fakeProviderWorks())) {
244
+ fail("billing", "fake provider did not serve catalog/checkout");
245
+ }
246
+ if (!(await composition.maintenanceInvoked())) {
247
+ fail("billing", "maintenance invocation failed");
248
+ }
249
+ if (!(await composition.auditRecorded())) {
250
+ fail("billing", "billing audit hook did not record");
251
+ }
252
+ }
253
+ if (capabilities.shutdown) {
254
+ const after = await adapter.shutdown();
255
+ if (after.mcpStatus !== 503) {
256
+ fail("lifecycle", "shutdown did not reject MCP with 503");
257
+ }
258
+ }
259
+ if (adapter.credentials.system) {
260
+ const system = await adapter.credentials.system(owner);
261
+ if (system.kind !== "system") {
262
+ fail("auth", "system credential helper did not return system");
263
+ }
264
+ }
265
+ return { failures };
266
+ }
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@codelitdev/platform-conformance",
3
+ "version": "0.1.0-alpha.0",
4
+ "description": "Shared Platform composition suites for product adapters",
5
+ "author": "CodeLit",
6
+ "type": "module",
7
+ "license": "MIT",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsc -p tsconfig.json",
20
+ "test": "bun test --timeout 60000 src",
21
+ "test:packed": "bun scripts/packed-consumer.mjs",
22
+ "typecheck": "tsc -p tsconfig.test.json --noEmit",
23
+ "lint": "biome lint ."
24
+ },
25
+ "publishConfig": {
26
+ "access": "public",
27
+ "tag": "latest"
28
+ },
29
+ "peerDependencies": {
30
+ "@codelitdev/platform": ">=0.1.0-alpha.0"
31
+ },
32
+ "devDependencies": {
33
+ "@codelitdev/platform": "0.1.0-alpha.0",
34
+ "@types/bun": "^1.4.1",
35
+ "@types/node": "^22.14.1",
36
+ "typescript": "^5.9.3"
37
+ }
38
+ }