aura-protocol
Version:
Core TypeScript definitions and JSON Schema for the AURA protocol - making websites machine-readable for AI agents
82 lines (81 loc) • 4.15 kB
JavaScript
;
// packages/aura-protocol/src/schema-sync.test.ts
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
// Load the generated JSON schema, which is the artifact we are testing.
const schemaPath = path.join(__dirname, '../dist/aura-v1.0.schema.json');
if (!fs.existsSync(schemaPath)) {
throw new Error(`Schema file not found at ${schemaPath}. Run 'npm run build' in the protocol package first.`);
}
const schema = JSON.parse(fs.readFileSync(schemaPath, 'utf-8'));
/**
* Helper function to compare required properties cleanly.
* @param definition The schema definition to check.
* @param expected The expected array of required properties.
*/
function assertRequiredProperties(definition, expected) {
// Sort both arrays to ensure comparison is not order-dependent.
const actualRequired = ((definition === null || definition === void 0 ? void 0 : definition.required) || []).sort();
const expectedRequired = [...expected].sort();
(0, vitest_1.expect)(actualRequired).toEqual(expectedRequired);
}
(0, vitest_1.describe)('JSON Schema and TypeScript Interface Synchronization', () => {
(0, vitest_1.it)('should have correct required fields for AuraManifest', () => {
const expected = ['protocol', 'version', 'site', 'resources', 'capabilities', '$schema'];
assertRequiredProperties(schema, expected);
});
(0, vitest_1.it)('should have correct required fields for Resource', () => {
var _a;
const expected = ['uriPattern', 'description', 'operations'];
const definition = (_a = schema.definitions) === null || _a === void 0 ? void 0 : _a.Resource;
(0, vitest_1.expect)(definition).toBeDefined();
assertRequiredProperties(definition, expected);
});
(0, vitest_1.it)('should have correct required fields for Capability', () => {
var _a;
const expected = ['id', 'v', 'description', 'action'];
const definition = (_a = schema.definitions) === null || _a === void 0 ? void 0 : _a.Capability;
(0, vitest_1.expect)(definition).toBeDefined();
assertRequiredProperties(definition, expected);
});
(0, vitest_1.it)('should have correct required fields for HttpAction', () => {
var _a;
const expected = ['type', 'method', 'urlTemplate', 'parameterMapping'];
const definition = (_a = schema.definitions) === null || _a === void 0 ? void 0 : _a.HttpAction;
(0, vitest_1.expect)(definition).toBeDefined();
assertRequiredProperties(definition, expected);
});
(0, vitest_1.it)('should have correct required fields for Policy', () => {
var _a;
const definition = (_a = schema.definitions) === null || _a === void 0 ? void 0 : _a.Policy;
// Policy itself is optional, but if present, it has no required fields at its top level.
const expected = [];
(0, vitest_1.expect)(definition).toBeDefined();
assertRequiredProperties(definition, expected);
});
});