diff --git a/examples/category-schema.v0.json b/examples/category-schema.v0.json new file mode 100644 index 0000000..ab0d7d6 --- /dev/null +++ b/examples/category-schema.v0.json @@ -0,0 +1,13 @@ +{ + "schema_version": "memact.category_schema.v0", + "id": "cat-001", + "name": "Technology", + "version": "1.0.0", + "description": "Technology related categories", + "contextFields": ["field", "subfield", "topic"], + "exampleInputs": ["AI", "blockchain", "cloud computing"], + "normalizedOutputShape": { "id": "string", "label": "string" }, + "wikiTemplates": ["{{TechBox}}"], + "permissionSuggestions": ["read", "write"], + "safetyNotes": "Ensure accurate classification before submission" +} \ No newline at end of file diff --git a/src/contracts/category-schema.v0.mjs b/src/contracts/category-schema.v0.mjs new file mode 100644 index 0000000..8e378f8 --- /dev/null +++ b/src/contracts/category-schema.v0.mjs @@ -0,0 +1,17 @@ +import { validateObject } from "../validators.mjs" + +export function validateCategorySchema(value) { + return validateObject(value, [ + { key: "schema_version", const: "memact.category_schema.v0" }, + { key: "id", type: "string", required: true }, + { key: "name", type: "string", required: true }, + { key: "version", type: "string", required: true }, + { key: "description", type: "string" }, + { key: "contextFields", type: "array" }, + { key: "exampleInputs", type: "array" }, + { key: "normalizedOutputShape", type: "object" }, + { key: "wikiTemplates", type: "array" }, + { key: "permissionSuggestions", type: "array" }, + { key: "safetyNotes", type: "string" } + ]) +} \ No newline at end of file diff --git a/src/index.mjs b/src/index.mjs index fe4f810..0da5a88 100644 --- a/src/index.mjs +++ b/src/index.mjs @@ -6,3 +6,4 @@ export { validateFeatureManifest } from "./contracts/feature-manifest.v0.mjs" export { validateFeatureRunRequest, validateFeatureRunResult } from "./contracts/feature-run.v0.mjs" export { validateAccessPolicy } from "./contracts/access-policy.v0.mjs" export { validateApiError } from "./contracts/api-error.v0.mjs" +export { validateCategorySchema } from "./contracts/category-schema.v0.mjs" \ No newline at end of file diff --git a/test/contracts.test.mjs b/test/contracts.test.mjs index a2a4a58..9d9b2ff 100644 --- a/test/contracts.test.mjs +++ b/test/contracts.test.mjs @@ -77,3 +77,69 @@ test("invalid feature result status fails", () => { generated_at: new Date().toISOString() }).ok, false) }) +import { validateCategorySchema } from "../src/index.mjs" + +test("valid minimal category schema passes", () => { + const result = validateCategorySchema({ + schema_version: "memact.category_schema.v0", + id: "cat-001", + name: "Technology", + version: "1.0.0" + }) + assert.equal(result.ok, true) +}) + +test("valid full category schema passes", () => { + const result = validateCategorySchema({ + schema_version: "memact.category_schema.v0", + id: "cat-002", + name: "Science", + version: "2.0.0", + description: "All science related categories", + contextFields: ["field", "subfield"], + exampleInputs: ["biology", "chemistry"], + normalizedOutputShape: { id: "string", label: "string" }, + wikiTemplates: ["{{ScienceBox}}"], + permissionSuggestions: ["read", "write"], + safetyNotes: "Ensure accurate classification" + }) + assert.equal(result.ok, true) +}) + +test("missing id fails", () => { + const result = validateCategorySchema({ + schema_version: "memact.category_schema.v0", + name: "Technology", + version: "1.0.0" + }) + assert.equal(result.ok, false) +}) + +test("missing name fails", () => { + const result = validateCategorySchema({ + schema_version: "memact.category_schema.v0", + id: "cat-003", + version: "1.0.0" + }) + assert.equal(result.ok, false) +}) + +test("missing version fails", () => { + const result = validateCategorySchema({ + schema_version: "memact.category_schema.v0", + id: "cat-004", + name: "Health" + }) + assert.equal(result.ok, false) +}) + +test("wrong type for contextFields fails", () => { + const result = validateCategorySchema({ + schema_version: "memact.category_schema.v0", + id: "cat-005", + name: "Tech", + version: "1.0.0", + contextFields: "not-an-array" + }) + assert.equal(result.ok, false) +}) \ No newline at end of file