-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from davelopez/add_output_labels_rule
Custom Validation Rule: `workflow_outputs` must have a label
- Loading branch information
Showing
15 changed files
with
353 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
server/src/providers/validation/WorkflowOutputLabelValidation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Diagnostic, DiagnosticSeverity } from "vscode-languageserver-types"; | ||
import { ValidationRule, WorkflowDocument } from "../../languageTypes"; | ||
|
||
export class WorkflowOutputLabelValidation implements ValidationRule { | ||
constructor(readonly severity: DiagnosticSeverity = DiagnosticSeverity.Error) {} | ||
|
||
validate(workflowDocument: WorkflowDocument): Promise<Diagnostic[]> { | ||
const result: Diagnostic[] = []; | ||
const stepNodes = workflowDocument.getStepNodes(); | ||
stepNodes.forEach((step) => { | ||
const workflowOutputs = step.properties.find((property) => property.keyNode.value === "workflow_outputs"); | ||
if (workflowOutputs && workflowOutputs.valueNode && workflowOutputs.valueNode.type === "array") { | ||
workflowOutputs.valueNode.items.forEach((outputNode) => { | ||
if (outputNode.type === "object") { | ||
const labelNode = outputNode.properties.find((property) => property.keyNode.value === "label"); | ||
if (!labelNode?.valueNode?.value) { | ||
result.push({ | ||
message: `Missing label in workflow output.`, | ||
range: workflowDocument.getNodeRange(outputNode), | ||
severity: this.severity, | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
return Promise.resolve(result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import * as fs from "fs"; | ||
import * as path from "path"; | ||
|
||
const TEST_DATA_PATH = path.join(__dirname, "..", "..", "test-data"); | ||
|
||
interface TestJsonWorkflows { | ||
/** Workflows for testing validation issues. */ | ||
validation: { | ||
/** Invalid workflow without steps. */ | ||
withoutSteps: string; | ||
/** Valid workflow with 1 step. */ | ||
withOneStep: string; | ||
/** Invalid workflow with 3 steps. The steps are missing UUID and workflow_outputs. */ | ||
withThreeSteps: string; | ||
/** Workflow with 1 step. The step has 2 workflow_outputs without labels. */ | ||
withoutWorkflowOutputLabels: string; | ||
/** Workflow with 1 step. The step has 2 workflow_outputs with labels. */ | ||
withWorkflowOutputLabels: string; | ||
}; | ||
} | ||
|
||
export class TestWorkflowProvider { | ||
private static _jsonWorkflows: TestJsonWorkflows = { | ||
validation: { | ||
withoutSteps: fs.readFileSync(path.join(TEST_DATA_PATH, "json", "validation", "test_wf_00.ga"), "utf-8"), | ||
withOneStep: fs.readFileSync(path.join(TEST_DATA_PATH, "json", "validation", "test_wf_01.ga"), "utf-8"), | ||
withThreeSteps: fs.readFileSync(path.join(TEST_DATA_PATH, "json", "validation", "test_wf_02.ga"), "utf-8"), | ||
withoutWorkflowOutputLabels: fs.readFileSync( | ||
path.join(TEST_DATA_PATH, "json", "validation", "test_wf_03.ga"), | ||
"utf-8" | ||
), | ||
withWorkflowOutputLabels: fs.readFileSync( | ||
path.join(TEST_DATA_PATH, "json", "validation", "test_wf_04.ga"), | ||
"utf-8" | ||
), | ||
}, | ||
}; | ||
|
||
/** Workflows in native JSON format. */ | ||
public static get nativeJson(): TestJsonWorkflows { | ||
return this._jsonWorkflows; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { createNativeWorkflowDocument } from "../testHelpers"; | ||
import { WorkflowOutputLabelValidation } from "../../src/providers/validation/WorkflowOutputLabelValidation"; | ||
import { TestWorkflowProvider } from "../testWorkflowProvider"; | ||
|
||
describe("Custom Validation Rules", () => { | ||
describe("WorkflowOutputLabelValidation Rule", () => { | ||
let rule: WorkflowOutputLabelValidation; | ||
|
||
beforeEach(() => { | ||
rule = new WorkflowOutputLabelValidation(); | ||
}); | ||
|
||
it("should not provide diagnostics when there are no steps", async () => { | ||
const wfDocument = createNativeWorkflowDocument(TestWorkflowProvider.nativeJson.validation.withoutSteps); | ||
const diagnostics = await rule.validate(wfDocument); | ||
expect(diagnostics).toHaveLength(0); | ||
}); | ||
|
||
it("should not provide diagnostics when there are no workflow_outputs in the steps", async () => { | ||
const wfDocument = createNativeWorkflowDocument(TestWorkflowProvider.nativeJson.validation.withThreeSteps); | ||
const diagnostics = await rule.validate(wfDocument); | ||
expect(diagnostics).toHaveLength(0); | ||
}); | ||
|
||
it("should not provide diagnostics when the steps contains workflow_outputs with label", async () => { | ||
const wfDocument = createNativeWorkflowDocument( | ||
TestWorkflowProvider.nativeJson.validation.withWorkflowOutputLabels | ||
); | ||
const diagnostics = await rule.validate(wfDocument); | ||
expect(diagnostics).toHaveLength(0); | ||
}); | ||
|
||
it("should provide diagnostics when the steps contains workflow_outputs without label", async () => { | ||
const wfDocument = createNativeWorkflowDocument( | ||
TestWorkflowProvider.nativeJson.validation.withoutWorkflowOutputLabels | ||
); | ||
const diagnostics = await rule.validate(wfDocument); | ||
expect(diagnostics).toHaveLength(2); | ||
diagnostics.forEach((diagnostic) => { | ||
expect(diagnostic.message).toBe("Missing label in workflow output."); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { createNativeWorkflowDocument } from "../testHelpers"; | ||
import { TestWorkflowProvider } from "../testWorkflowProvider"; | ||
|
||
describe("NativeWorkflowDocument", () => { | ||
describe("getStepNodes", () => { | ||
it.each([ | ||
["", 0], | ||
[TestWorkflowProvider.nativeJson.validation.withoutSteps, 0], | ||
[TestWorkflowProvider.nativeJson.validation.withOneStep, 1], | ||
[TestWorkflowProvider.nativeJson.validation.withThreeSteps, 3], | ||
])("returns the expected number of steps", (wf_content: string, expectedNumSteps: number) => { | ||
const wfDocument = createNativeWorkflowDocument(wf_content); | ||
const stepNodes = wfDocument.getStepNodes(); | ||
expect(stepNodes).toHaveLength(expectedNumSteps); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"a_galaxy_workflow": "true", | ||
"format-version": "0.1", | ||
"name": "Test Workflow Without Steps", | ||
"steps": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,18 @@ | ||
{ | ||
"a_galaxy_workflow": "true", | ||
"annotation": "simple workflow", | ||
"format-version": "0.1", | ||
"name": "TestWorkflow1", | ||
"name": "Test Workflow Minimum Valid", | ||
"steps": { | ||
"0": { | ||
"annotation": "input1 description", | ||
"id": 0, | ||
"input_connections": {}, | ||
"inputs": [ | ||
{ | ||
"description": "input1 description", | ||
"name": "WorkflowInput1" | ||
} | ||
], | ||
"name": "Input dataset", | ||
"outputs": [], | ||
"position": { | ||
"left": 199.55555772781372, | ||
"top": 200.66666460037231 | ||
}, | ||
"tool_errors": null, | ||
"tool_id": null, | ||
"tool_state": "{\"name\": \"WorkflowInput1\"}", | ||
"tool_version": null, | ||
"name": "Test Step", | ||
"type": "data_input", | ||
"user_outputs": [] | ||
}, | ||
"1": { | ||
"annotation": "", | ||
"id": 1, | ||
"annotation": "Step description", | ||
"uuid": "692d2674-5e70-4e01-ad12-4ce5572c39e5", | ||
"input_connections": {}, | ||
"inputs": [ | ||
{ | ||
"description": "", | ||
"name": "WorkflowInput2" | ||
} | ||
], | ||
"name": "Input dataset", | ||
"outputs": [], | ||
"position": { | ||
"left": 206.22221422195435, | ||
"top": 327.33335161209106 | ||
}, | ||
"tool_errors": null, | ||
"tool_id": null, | ||
"tool_state": "{\"name\": \"WorkflowInput2\"}", | ||
"tool_version": null, | ||
"type": "data_input", | ||
"user_outputs": [] | ||
}, | ||
"2": { | ||
"annotation": "", | ||
"id": 2, | ||
"input_connections": { | ||
"input1": { | ||
"id": 0, | ||
"output_name": "output" | ||
}, | ||
"queries_0|input2": { | ||
"id": 1, | ||
"output_name": "output" | ||
} | ||
}, | ||
"inputs": [], | ||
"name": "Concatenate datasets", | ||
"outputs": [ | ||
{ | ||
"name": "out_file1", | ||
"type": "input" | ||
} | ||
], | ||
"position": { | ||
"left": 419.33335876464844, | ||
"top": 200.44446563720703 | ||
}, | ||
"post_job_actions": {}, | ||
"tool_errors": null, | ||
"tool_id": "cat1", | ||
"tool_state": "{\"__page__\": 0, \"__rerun_remap_job_id__\": null, \"input1\": \"null\", \"queries\": \"[{\\\"input2\\\": null, \\\"__index__\\\": 0}]\"}", | ||
"tool_version": "1.0.0", | ||
"type": "tool", | ||
"user_outputs": [] | ||
"outputs": [], | ||
"workflow_outputs": [] | ||
} | ||
} | ||
} |
Oops, something went wrong.