From 6fa60dca2295fa67413efe188c1aec8b9f3c6b59 Mon Sep 17 00:00:00 2001 From: Ioannis Rosuochatzakis Date: Wed, 25 Mar 2026 21:41:47 +0100 Subject: [PATCH] TEDEFO-5002 Exclude @POST rules, add global/stage variable dependency test --- .../EfxValidationDependencyExtractor.java | 19 ++++++++--- .../EfxValidationDependencyExtractorTest.java | 5 +++ .../testComprehensive/input.efx | 6 ++++ .../testGlobalAndStageVariables/expected.json | 34 +++++++++++++++++++ .../testGlobalAndStageVariables/input.efx | 12 +++++++ 5 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 src/test/resources/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractorTest/testGlobalAndStageVariables/expected.json create mode 100644 src/test/resources/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractorTest/testGlobalAndStageVariables/input.efx diff --git a/src/main/java/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractor.java b/src/main/java/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractor.java index 9f009c5..b51ab4a 100644 --- a/src/main/java/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractor.java +++ b/src/main/java/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractor.java @@ -128,7 +128,7 @@ public void enterSimpleRule(final SimpleRuleContext ctx) { @Override public void exitSimpleRule(final SimpleRuleContext ctx) { - this.commitRule(ctx.asClause(), ctx.forClause()); + this.commitRule(ctx.asClause(), ctx.forClause(), ctx.scopeClause()); } @Override @@ -138,7 +138,7 @@ public void enterConditionalRule(final ConditionalRuleContext ctx) { @Override public void exitConditionalRule(final ConditionalRuleContext ctx) { - this.commitRule(ctx.asClause(), ctx.forClause()); + this.commitRule(ctx.asClause(), ctx.forClause(), ctx.scopeClause()); } @Override @@ -148,7 +148,7 @@ public void enterFallbackRule(final FallbackRuleContext ctx) { @Override public void exitFallbackRule(final FallbackRuleContext ctx) { - this.commitRule(ctx.asClause(), ctx.forClause()); + this.commitRule(ctx.asClause(), ctx.forClause(), ctx.scopeClause()); } private void pushRuleFrame() { @@ -157,8 +157,19 @@ private void pushRuleFrame() { this.stack.push(ruleFrame); } - private void commitRule(final AsClauseContext asClause, final ForClauseContext forClause) { + private boolean isPostOnly(final ScopeClauseContext scopeClause) { + return scopeClause != null + && scopeClause.scopeAnnotation() != null + && scopeClause.scopeAnnotation().Post() != null; + } + + private void commitRule(final AsClauseContext asClause, final ForClauseContext forClause, + final ScopeClauseContext scopeClause) { final DependencySet ruleDeps = this.stack.pop(); + + if (this.isPostOnly(scopeClause)) { + return; + } final String ruleId = asClause.ruleId().getText().replaceAll("^\"|\"$", ""); final String targetId; diff --git a/src/test/java/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractorTest.java b/src/test/java/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractorTest.java index 31152a0..d2afac6 100644 --- a/src/test/java/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractorTest.java +++ b/src/test/java/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractorTest.java @@ -120,6 +120,11 @@ void testMultipleStages() throws IOException { assertDependencyGraph("testMultipleStages"); } + @Test + void testGlobalAndStageVariables() throws IOException { + assertDependencyGraph("testGlobalAndStageVariables"); + } + // #endregion: Structure // #region: Comprehensive ---------------------------------------------------- diff --git a/src/test/resources/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractorTest/testComprehensive/input.efx b/src/test/resources/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractorTest/testComprehensive/input.efx index 6d72fd7..af4d4f7 100644 --- a/src/test/resources/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractorTest/testComprehensive/input.efx +++ b/src/test/resources/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractorTest/testComprehensive/input.efx @@ -56,3 +56,9 @@ WITH ND-Root ASSERT BT-00-Code in [...accessibility] AS ERROR R-C02-003 FOR BT-00-Code IN * + +// Rule 9: @POST rule — should be excluded from the dependency graph +WITH ND-Root + ASSERT BT-00-Number > 0 and BT-00-Text is present + AS ERROR R-C02-004 + FOR BT-00-Indicator IN * SCOPE @POST diff --git a/src/test/resources/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractorTest/testGlobalAndStageVariables/expected.json b/src/test/resources/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractorTest/testGlobalAndStageVariables/expected.json new file mode 100644 index 0000000..f355db4 --- /dev/null +++ b/src/test/resources/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractorTest/testGlobalAndStageVariables/expected.json @@ -0,0 +1,34 @@ +{ + "fields" : [ { + "id" : "BT-00-Code", + "dependsOn" : { + "assert" : [ { + "ruleId" : "R-GS0-001", + "fields" : [ "BT-00-Text", "BT-00-Number" ], + "nodes" : [ "ND-Root" ] + } ] + } + }, { + "id" : "BT-00-Text", + "requiredBy" : { + "assert" : { + "fields" : [ "BT-00-Code" ] + } + } + }, { + "id" : "BT-00-Number", + "requiredBy" : { + "assert" : { + "fields" : [ "BT-00-Code" ] + } + } + } ], + "nodes" : [ { + "id" : "ND-Root", + "requiredBy" : { + "assert" : { + "fields" : [ "BT-00-Code" ] + } + } + } ] +} \ No newline at end of file diff --git a/src/test/resources/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractorTest/testGlobalAndStageVariables/input.efx b/src/test/resources/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractorTest/testGlobalAndStageVariables/input.efx new file mode 100644 index 0000000..fd2efb6 --- /dev/null +++ b/src/test/resources/eu/europa/ted/efx/sdk2/EfxValidationDependencyExtractorTest/testGlobalAndStageVariables/input.efx @@ -0,0 +1,12 @@ +// Test: Dependencies inherited through global and stage variables + +LET text:$globalLabel = BT-00-Text; + +---- STAGE test ---- + +LET number:$stageThreshold = BT-00-Number; + +WITH ND-Root + ASSERT $globalLabel == 'expected' and $stageThreshold > 0 + AS ERROR R-GS0-001 + FOR BT-00-Code IN *