Update plugin validation script
Some checks failed
Deploy to GitHub Pages / deploy (push) Failing after 10s
Validate Plugins / validate (push) Successful in 9m24s

This commit is contained in:
Sean O'Connor
2026-03-21 20:21:31 -04:00
parent 14137ba631
commit d772aecc54

View File

@@ -1,35 +1,35 @@
#!/usr/bin/env node #!/usr/bin/env node
const fs = require('fs'); const fs = require("fs");
const path = require('path'); const path = require("path");
// Color output helpers // Color output helpers
const colors = { const colors = {
red: '\x1b[31m', red: "\x1b[31m",
green: '\x1b[32m', green: "\x1b[32m",
yellow: '\x1b[33m', yellow: "\x1b[33m",
blue: '\x1b[34m', blue: "\x1b[34m",
reset: '\x1b[0m' reset: "\x1b[0m",
}; };
function log(message, color = 'reset') { function log(message, color = "reset") {
console.log(`${colors[color]}${message}${colors.reset}`); console.log(`${colors[color]}${message}${colors.reset}`);
} }
function error(message) { function error(message) {
log(`${message}`, 'red'); log(`${message}`, "red");
} }
function success(message) { function success(message) {
log(`${message}`, 'green'); log(`${message}`, "green");
} }
function warn(message) { function warn(message) {
log(`⚠️ ${message}`, 'yellow'); log(`⚠️ ${message}`, "yellow");
} }
function info(message) { function info(message) {
log(` ${message}`, 'blue'); log(` ${message}`, "blue");
} }
// Plugin schema validation // Plugin schema validation
@@ -40,7 +40,7 @@ function validatePlugin(pluginPath) {
let plugin; let plugin;
try { try {
plugin = JSON.parse(fs.readFileSync(pluginPath, 'utf8')); plugin = JSON.parse(fs.readFileSync(pluginPath, "utf8"));
} catch (e) { } catch (e) {
throw new Error(`Invalid JSON syntax: ${e.message}`); throw new Error(`Invalid JSON syntax: ${e.message}`);
} }
@@ -50,17 +50,17 @@ function validatePlugin(pluginPath) {
// Required fields validation // Required fields validation
const requiredFields = [ const requiredFields = [
'robotId', "robotId",
'name', "name",
'platform', "platform",
'version', "version",
'pluginApiVersion', "pluginApiVersion",
'hriStudioVersion', "hriStudioVersion",
'trustLevel', "trustLevel",
'category' "category",
]; ];
requiredFields.forEach(field => { requiredFields.forEach((field) => {
if (!plugin[field]) { if (!plugin[field]) {
errors.push(`Missing required field: ${field}`); errors.push(`Missing required field: ${field}`);
} }
@@ -68,36 +68,43 @@ function validatePlugin(pluginPath) {
// Field format validation // Field format validation
if (plugin.robotId && !/^[a-z0-9-]+$/.test(plugin.robotId)) { if (plugin.robotId && !/^[a-z0-9-]+$/.test(plugin.robotId)) {
errors.push('robotId must be lowercase with hyphens only'); errors.push("robotId must be lowercase with hyphens only");
} }
if (plugin.version && !/^\d+\.\d+\.\d+/.test(plugin.version)) { if (plugin.version && !/^\d+\.\d+\.\d+/.test(plugin.version)) {
errors.push('version must follow semantic versioning (e.g., 1.0.0)'); errors.push("version must follow semantic versioning (e.g., 1.0.0)");
} }
if (plugin.trustLevel && !['official', 'verified', 'community'].includes(plugin.trustLevel)) { if (
errors.push(`Invalid trustLevel: ${plugin.trustLevel}. Must be: official, verified, or community`); plugin.trustLevel &&
!["official", "verified", "community"].includes(plugin.trustLevel)
) {
errors.push(
`Invalid trustLevel: ${plugin.trustLevel}. Must be: official, verified, or community`,
);
} }
// Category validation // Category validation
const validCategories = [ const validCategories = [
'mobile-robot', "mobile-robot",
'humanoid-robot', "humanoid-robot",
'manipulator', "manipulator",
'drone', "drone",
'sensor-platform', "sensor-platform",
'simulation' "simulation",
]; ];
if (plugin.category && !validCategories.includes(plugin.category)) { if (plugin.category && !validCategories.includes(plugin.category)) {
errors.push(`Invalid category: ${plugin.category}. Valid categories: ${validCategories.join(', ')}`); errors.push(
`Invalid category: ${plugin.category}. Valid categories: ${validCategories.join(", ")}`,
);
} }
// Actions validation // Actions validation
if (!plugin.actions || !Array.isArray(plugin.actions)) { if (!plugin.actions || !Array.isArray(plugin.actions)) {
errors.push('Plugin must have an actions array'); errors.push("Plugin must have an actions array");
} else if (plugin.actions.length === 0) { } else if (plugin.actions.length === 0) {
warnings.push('Plugin has no actions defined'); warnings.push("Plugin has no actions defined");
} else { } else {
plugin.actions.forEach((action, index) => { plugin.actions.forEach((action, index) => {
const actionErrors = validateAction(action, index); const actionErrors = validateAction(action, index);
@@ -108,37 +115,43 @@ function validatePlugin(pluginPath) {
// Assets validation // Assets validation
if (plugin.assets) { if (plugin.assets) {
if (!plugin.assets.thumbnailUrl) { if (!plugin.assets.thumbnailUrl) {
errors.push('assets.thumbnailUrl is required'); errors.push("assets.thumbnailUrl is required");
} }
// Check if asset paths exist // Check if asset paths exist
const assetChecks = [ const assetChecks = [
['thumbnailUrl', plugin.assets.thumbnailUrl], ["thumbnailUrl", plugin.assets.thumbnailUrl],
['main image', plugin.assets.images?.main], ["main image", plugin.assets.images?.main],
['logo', plugin.assets.images?.logo] ["logo", plugin.assets.images?.logo],
]; ];
if (plugin.assets.images?.angles) { if (plugin.assets.images?.angles) {
Object.entries(plugin.assets.images.angles).forEach(([angle, assetPath]) => { Object.entries(plugin.assets.images.angles).forEach(
([angle, assetPath]) => {
assetChecks.push([`${angle} angle`, assetPath]); assetChecks.push([`${angle} angle`, assetPath]);
}); },
);
} }
assetChecks.forEach(([description, assetPath]) => { assetChecks.forEach(([description, assetPath]) => {
if (assetPath && assetPath.startsWith('assets/')) { if (assetPath && assetPath.startsWith("assets/")) {
const fullPath = path.resolve(path.dirname(pluginPath), '..', assetPath); const fullPath = path.resolve(
path.dirname(pluginPath),
"..",
assetPath,
);
if (!fs.existsSync(fullPath)) { if (!fs.existsSync(fullPath)) {
warnings.push(`Asset not found: ${description} (${assetPath})`); warnings.push(`Asset not found: ${description} (${assetPath})`);
} }
} }
}); });
} else { } else {
errors.push('Plugin must have assets definition'); errors.push("Plugin must have assets definition");
} }
// Manufacturer validation // Manufacturer validation
if (!plugin.manufacturer?.name) { if (!plugin.manufacturer?.name) {
warnings.push('manufacturer.name is recommended'); warnings.push("manufacturer.name is recommended");
} }
return { errors, warnings, plugin }; return { errors, warnings, plugin };
@@ -148,8 +161,8 @@ function validateAction(action, index) {
const errors = []; const errors = [];
// Required action fields // Required action fields
const requiredFields = ['id', 'name', 'category', 'parameterSchema']; const requiredFields = ["id", "name", "category", "parameterSchema"];
requiredFields.forEach(field => { requiredFields.forEach((field) => {
if (!action[field]) { if (!action[field]) {
errors.push(`Action ${index}: missing required field '${field}'`); errors.push(`Action ${index}: missing required field '${field}'`);
} }
@@ -157,18 +170,22 @@ function validateAction(action, index) {
// Action ID format // Action ID format
if (action.id && !/^[a-z_]+$/.test(action.id)) { if (action.id && !/^[a-z_]+$/.test(action.id)) {
errors.push(`Action ${index}: id must be snake_case (lowercase with underscores)`); errors.push(
`Action ${index}: id must be snake_case (lowercase with underscores)`,
);
} }
// Action category validation // Action category validation
const validActionCategories = ['movement', 'interaction', 'sensors', 'logic']; const validActionCategories = ["movement", "interaction", "sensors", "logic"];
if (action.category && !validActionCategories.includes(action.category)) { if (action.category && !validActionCategories.includes(action.category)) {
errors.push(`Action ${index}: invalid category '${action.category}'. Valid: ${validActionCategories.join(', ')}`); errors.push(
`Action ${index}: invalid category '${action.category}'. Valid: ${validActionCategories.join(", ")}`,
);
} }
// Parameter schema validation // Parameter schema validation
if (action.parameterSchema) { if (action.parameterSchema) {
if (action.parameterSchema.type !== 'object') { if (action.parameterSchema.type !== "object") {
errors.push(`Action ${index}: parameterSchema.type must be 'object'`); errors.push(`Action ${index}: parameterSchema.type must be 'object'`);
} }
@@ -187,7 +204,9 @@ function validateAction(action, index) {
const hasRestApi = action.restApi; const hasRestApi = action.restApi;
if (!hasRos2 && !hasNaoqi && !hasRestApi) { if (!hasRos2 && !hasNaoqi && !hasRestApi) {
errors.push(`Action ${index}: must have at least one communication protocol (ros2, naoqi, or restApi)`); errors.push(
`Action ${index}: must have at least one communication protocol (ros2, naoqi, or restApi)`,
);
} }
return errors; return errors;
@@ -195,15 +214,15 @@ function validateAction(action, index) {
// Repository validation // Repository validation
function validateRepository() { function validateRepository() {
const repoPath = path.resolve('repository.json'); const repoPath = path.resolve("repository.json");
if (!fs.existsSync(repoPath)) { if (!fs.existsSync(repoPath)) {
throw new Error('repository.json not found'); throw new Error("repository.json not found");
} }
let repo; let repo;
try { try {
repo = JSON.parse(fs.readFileSync(repoPath, 'utf8')); repo = JSON.parse(fs.readFileSync(repoPath, "utf8"));
} catch (e) { } catch (e) {
throw new Error(`Invalid repository.json: ${e.message}`); throw new Error(`Invalid repository.json: ${e.message}`);
} }
@@ -212,22 +231,30 @@ function validateRepository() {
const warnings = []; const warnings = [];
// Required repository fields // Required repository fields
const requiredFields = ['id', 'name', 'apiVersion', 'pluginApiVersion', 'trust']; const requiredFields = [
requiredFields.forEach(field => { "id",
"name",
"apiVersion",
"pluginApiVersion",
"trust",
];
requiredFields.forEach((field) => {
if (!repo[field]) { if (!repo[field]) {
errors.push(`Missing required repository field: ${field}`); errors.push(`Missing required repository field: ${field}`);
} }
}); });
// Validate plugin count // Validate plugin count
const indexPath = path.resolve('plugins/index.json'); const indexPath = path.resolve("plugins/index.json");
if (fs.existsSync(indexPath)) { if (fs.existsSync(indexPath)) {
const index = JSON.parse(fs.readFileSync(indexPath, 'utf8')); const index = JSON.parse(fs.readFileSync(indexPath, "utf8"));
const actualCount = index.length; const actualCount = index.length;
const reportedCount = repo.stats?.plugins || 0; const reportedCount = repo.stats?.plugins || 0;
if (actualCount !== reportedCount) { if (actualCount !== reportedCount) {
errors.push(`Plugin count mismatch: reported ${reportedCount}, actual ${actualCount}`); errors.push(
`Plugin count mismatch: reported ${reportedCount}, actual ${actualCount}`,
);
} }
} }
@@ -236,24 +263,25 @@ function validateRepository() {
// Update plugin index // Update plugin index
function updateIndex() { function updateIndex() {
const pluginsDir = path.resolve('plugins'); const pluginsDir = path.resolve("plugins");
const indexPath = path.join(pluginsDir, 'index.json'); const indexPath = path.join(pluginsDir, "index.json");
if (!fs.existsSync(pluginsDir)) { if (!fs.existsSync(pluginsDir)) {
throw new Error('plugins directory not found'); throw new Error("plugins directory not found");
} }
const pluginFiles = fs.readdirSync(pluginsDir) const pluginFiles = fs
.filter(file => file.endsWith('.json') && file !== 'index.json') .readdirSync(pluginsDir)
.filter((file) => file.endsWith(".json") && file !== "index.json")
.sort(); .sort();
fs.writeFileSync(indexPath, JSON.stringify(pluginFiles, null, 2)); fs.writeFileSync(indexPath, JSON.stringify(pluginFiles, null, 2));
success(`Updated index.json with ${pluginFiles.length} plugins`); success(`Updated index.json with ${pluginFiles.length} plugins`);
// Update repository stats // Update repository stats
const repoPath = path.resolve('repository.json'); const repoPath = path.resolve("repository.json");
if (fs.existsSync(repoPath)) { if (fs.existsSync(repoPath)) {
const repo = JSON.parse(fs.readFileSync(repoPath, 'utf8')); const repo = JSON.parse(fs.readFileSync(repoPath, "utf8"));
repo.stats = repo.stats || {}; repo.stats = repo.stats || {};
repo.stats.plugins = pluginFiles.length; repo.stats.plugins = pluginFiles.length;
fs.writeFileSync(repoPath, JSON.stringify(repo, null, 2)); fs.writeFileSync(repoPath, JSON.stringify(repo, null, 2));
@@ -268,10 +296,10 @@ function main() {
try { try {
switch (command) { switch (command) {
case 'validate': case "validate":
const pluginPath = args[1]; const pluginPath = args[1];
if (!pluginPath) { if (!pluginPath) {
error('Usage: validate <plugin-file>'); error("Usage: validate <plugin-file>");
process.exit(1); process.exit(1);
} }
@@ -279,53 +307,53 @@ function main() {
const { errors, warnings } = validatePlugin(pluginPath); const { errors, warnings } = validatePlugin(pluginPath);
if (errors.length > 0) { if (errors.length > 0) {
error('Validation failed:'); error("Validation failed:");
errors.forEach(err => console.log(` - ${err}`)); errors.forEach((err) => console.log(` - ${err}`));
} }
if (warnings.length > 0) { if (warnings.length > 0) {
warn('Warnings:'); warn("Warnings:");
warnings.forEach(warn => console.log(` - ${warn}`)); warnings.forEach((warn) => console.log(` - ${warn}`));
} }
if (errors.length === 0) { if (errors.length === 0) {
success('Plugin validation passed!'); success("Plugin validation passed!");
if (warnings.length === 0) { if (warnings.length === 0) {
success('No warnings found'); success("No warnings found");
} }
} else { } else {
process.exit(1); process.exit(1);
} }
break; break;
case 'validate-all': case "validate-all":
info('Validating all plugins...'); info("Validating all plugins...");
// Validate repository // Validate repository
const repoResult = validateRepository(); const repoResult = validateRepository();
if (repoResult.errors.length > 0) { if (repoResult.errors.length > 0) {
error('Repository validation failed:'); error("Repository validation failed:");
repoResult.errors.forEach(err => console.log(` - ${err}`)); repoResult.errors.forEach((err) => console.log(` - ${err}`));
process.exit(1); process.exit(1);
} }
// Validate all plugins // Validate all plugins
const indexPath = path.resolve('plugins/index.json'); const indexPath = path.resolve("plugins/index.json");
if (!fs.existsSync(indexPath)) { if (!fs.existsSync(indexPath)) {
error('plugins/index.json not found'); error("plugins/index.json not found");
process.exit(1); process.exit(1);
} }
const index = JSON.parse(fs.readFileSync(indexPath, 'utf8')); const index = JSON.parse(fs.readFileSync(indexPath, "utf8"));
let allValid = true; let allValid = true;
for (const pluginFile of index) { for (const pluginFile of index) {
const pluginPath = path.resolve('plugins', pluginFile); const pluginPath = path.resolve("plugins", pluginFile);
try { try {
const { errors } = validatePlugin(pluginPath); const { errors } = validatePlugin(pluginPath);
if (errors.length > 0) { if (errors.length > 0) {
error(`${pluginFile}: ${errors.length} errors`); error(`${pluginFile}: ${errors.length} errors`);
errors.forEach(err => console.log(` - ${err}`)); errors.forEach((err) => console.log(` - ${err}`));
allValid = false; allValid = false;
} else { } else {
success(`${pluginFile}: valid`); success(`${pluginFile}: valid`);
@@ -337,18 +365,18 @@ function main() {
} }
if (allValid) { if (allValid) {
success('All plugins are valid!'); success("All plugins are valid!");
} else { } else {
process.exit(1); process.exit(1);
} }
break; break;
case 'update-index': case "update-index":
info('Updating plugin index...'); info("Updating plugin index...");
updateIndex(); updateIndex();
break; break;
case 'help': case "help":
default: default:
console.log(` console.log(`
HRIStudio Plugin Validator HRIStudio Plugin Validator
@@ -379,5 +407,5 @@ if (require.main === module) {
module.exports = { module.exports = {
validatePlugin, validatePlugin,
validateRepository, validateRepository,
updateIndex updateIndex,
}; };