From 90023614ccdd381ebba27865a91254f419a29bbc Mon Sep 17 00:00:00 2001 From: Victor Felder Date: Wed, 3 Feb 2021 11:17:38 +0100 Subject: [PATCH] fix: report right dependency type close #31 --- packages/validation/lib/parser.js | 20 +++++++++---------- .../validation/lib/validators/dependency.js | 18 ++++++++++++----- .../validation/lib/validators/operation.js | 2 +- packages/validation/test/parser.test.js | 2 +- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/packages/validation/lib/parser.js b/packages/validation/lib/parser.js index 968178a3..198ea04e 100644 --- a/packages/validation/lib/parser.js +++ b/packages/validation/lib/parser.js @@ -185,28 +185,28 @@ function getPipelineProperties (graph, pipelines) { async function getAllOperationProperties (dependencies, checks) { const results = {} - for (const env in dependencies) { - for (const module in dependencies[env]) { + for (const protocol in dependencies) { + for (const module in dependencies[protocol]) { let issue - const currOperations = Array.from(dependencies[env][module]).join('"\n * "') - issue = validators.dependency.validate(module, currOperations) + const operations = Array.from(dependencies[protocol][module]).join('"\n * "') + issue = validators.dependency.validate(module, { operations, protocol }) checks.addGenericCheck(issue) if (!utils.isModuleInstalled(module)) { continue } - const operationsPath = utils.getManifestPath(module) + const manifestPath = utils.getManifestPath(module) - issue = validators.operation.validate(operationsPath, module, currOperations) + issue = validators.operation.validate(manifestPath, module, operations) checks.addGenericCheck(issue) - if (operationsPath) { - const graph = await readGraph(operationsPath, checks) - const tempResults = getModuleOperationProperties(graph, dependencies[env][module].values()) + if (manifestPath) { + const manifestGraph = await readGraph(manifestPath, checks) + const tempResults = getModuleOperationProperties(manifestGraph, dependencies[protocol][module].values()) Object.assign(results, tempResults) } else { - for (const codelink of dependencies[env][module]) { + for (const codelink of dependencies[protocol][module]) { results[codelink] = null } } diff --git a/packages/validation/lib/validators/dependency.js b/packages/validation/lib/validators/dependency.js index c45a4b84..9d4d79a0 100644 --- a/packages/validation/lib/validators/dependency.js +++ b/packages/validation/lib/validators/dependency.js @@ -2,20 +2,28 @@ const Issue = require('../issue') const utils = require('../utils') const { template } = require('../utils') +// corresponds to rdf-code-loader resolvers: +// https://github.com/zazuko/rdf-loader-code/blob/c5137d45f13c6788f9f6f161653b7cd800401a0f/lib/iriResolve.js#L4-L17 +const dependencyTypes = { + 'node:': 'package', + 'file:': 'file' +} + const dependency = { ruleDescription: 'Each dependency must be installed', ruleId: 2668, - messageSuccessTemplate: template`Package ${'library'} found successfully`, - messageFailureTemplate: template`Missing package ${'library'}\n The following operations cannot be validated:\n * "${'operations'}"`, - validate (library, codelinksWithMissingMetadata) { + messageSuccessTemplate: template`Found ${'dependencyType'} ${'library'} successfully`, + messageFailureTemplate: template`Missing ${'dependencyType'} ${'library'}\n The following operations cannot be validated:\n * "${'operations'}"`, + validate (library, { operations, protocol }) { + const dependencyType = dependencyTypes[protocol] let issue if (utils.isModuleInstalled(library)) { - issue = Issue.info({ id: this.ruleId, templateData: { library } }) + issue = Issue.info({ id: this.ruleId, templateData: { library, dependencyType } }) } else { issue = Issue.error({ id: this.ruleId, - templateData: { library, operations: codelinksWithMissingMetadata } + templateData: { library, dependencyType, operations } }) } return issue diff --git a/packages/validation/lib/validators/operation.js b/packages/validation/lib/validators/operation.js index a55a4431..3e6a5601 100644 --- a/packages/validation/lib/validators/operation.js +++ b/packages/validation/lib/validators/operation.js @@ -5,7 +5,7 @@ const operation = { ruleId: 3, ruleDescription: 'manifest.ttl file exists and can be parsed', messageSuccessTemplate: template`Metadata file for ${'library'} loaded successfully`, - messageFailureTemplate: template`Missing metadata file for ${'library'}.\n The following operations cannot be validated:\n * "${'operations'}"`, + messageFailureTemplate: template`Missing metadata file for ${'library'}\n The following operations cannot be validated:\n * "${'operations'}"`, validate (operationPathExists, library, codelinksWithMissingMetadata) { let issue if (operationPathExists) { diff --git a/packages/validation/test/parser.test.js b/packages/validation/test/parser.test.js index e1b1529b..e7f9313b 100644 --- a/packages/validation/test/parser.test.js +++ b/packages/validation/test/parser.test.js @@ -350,7 +350,7 @@ describe('parser.getAllOperationProperties', () => { const actual = await mockedParser.getAllOperationProperties(input, checks) assert.deepStrictEqual(actual, expected) - const expectedMssg = validators.dependency.messageFailureTemplate({ library: 'foo-bar', operations: 'node:foo-bar#fn' }) + const expectedMssg = validators.dependency.messageFailureTemplate({ library: 'foo-bar', operations: 'node:foo-bar#fn', dependencyType: 'package' }) assert(genericContainsMessage(checks, expectedMssg)) }) })