From 8b1f5435a47e85c4cf397e06300bcaf60e113bfe Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Fri, 21 Jun 2024 12:58:01 +0200 Subject: [PATCH 1/2] Add validation tests for format2 primitive types --- .../tests/integration/validation.test.ts | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/server/gx-workflow-ls-format2/tests/integration/validation.test.ts b/server/gx-workflow-ls-format2/tests/integration/validation.test.ts index 5a843dd..a1f234b 100644 --- a/server/gx-workflow-ls-format2/tests/integration/validation.test.ts +++ b/server/gx-workflow-ls-format2/tests/integration/validation.test.ts @@ -80,6 +80,37 @@ steps: ); }); + it("should not report error for compatible primitive types", async () => { + const content = ` +class: GalaxyWorkflow +inputs: +outputs: +steps: + step: + position: + top: 0 + left: 0 + `; + const diagnostics = await validateDocument(content); + expect(diagnostics).toHaveLength(0); + }); + + it("should report error for incompatible primitive types", async () => { + const content = ` +class: GalaxyWorkflow +inputs: +outputs: +steps: + step: + position: + top: "not a number" + left: 0 + `; + const diagnostics = await validateDocument(content); + expect(diagnostics).toHaveLength(1); + expect(diagnostics[0].message).toContain("Type mismatch for field 'top'. Expected 'float' but found 'string'."); + }); + describe("Custom Rules", () => { let rule: ValidationRule; From 334b0b42fe8ce09e8a1991f5e0a47365e134d0fc Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Fri, 21 Jun 2024 12:58:53 +0200 Subject: [PATCH 2/2] Fix primitive type compatibility check in FieldSchemaNode --- server/gx-workflow-ls-format2/src/schema/definitions.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/gx-workflow-ls-format2/src/schema/definitions.ts b/server/gx-workflow-ls-format2/src/schema/definitions.ts index 14b87df..0568f86 100644 --- a/server/gx-workflow-ls-format2/src/schema/definitions.ts +++ b/server/gx-workflow-ls-format2/src/schema/definitions.ts @@ -1,3 +1,5 @@ +import { isCompatibleType, isWorkflowDataType } from "@gxwf/server-common/src/utils"; + export interface SchemaDocument { $base: string; $namespaces?: object; @@ -266,7 +268,10 @@ export class FieldSchemaNode implements SchemaNode, IdMapper { if (this.canBeAny) return true; if (typeName === "null" && this.isOptional) return true; for (const allowedType of this._allowedTypes) { - if (allowedType.typeName === typeName) { + if ( + allowedType.typeName === typeName || + (isWorkflowDataType(allowedType.typeName) && isCompatibleType(allowedType.typeName, typeName)) + ) { return true; } if (isArrayFieldType(allowedType)) {