Copilot commented on code in PR #7202:
URL: https://github.com/apache/incubator-kie/pull/7202#discussion_r4312336741


##########
drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/sequential/SequentialNodeSharingTest.java:
##########
@@ -0,0 +1,437 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.drools.mvel.integrationtests.sequential;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Stream;
+
+import org.drools.mvel.compiler.Address;
+import org.drools.mvel.compiler.Cheese;
+import org.drools.mvel.compiler.Person;
+import org.drools.testcoverage.common.util.KieBaseTestConfiguration;
+import org.drools.testcoverage.common.util.KieBaseUtil;
+import org.drools.testcoverage.common.util.KieUtil;
+import org.drools.testcoverage.common.util.TestParametersUtil2;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.kie.api.KieBase;
+import org.kie.api.builder.KieModule;
+import org.kie.api.conf.SequentialOption;
+import org.kie.api.runtime.StatelessKieSession;
+import org.kie.internal.command.CommandFactory;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests that sequential mode disables beta node sharing by default,
+ * producing correct results for all beta node types (FromNode, JoinNode,
+ * AccumulateNode, NotNode, ExistsNode) when rules use modify().
+ *
+ * @see <a 
href="https://github.com/apache/incubator-kie/issues/7201";>incubator-kie#7201</a>
+ */
+public class SequentialNodeSharingTest {
+
+    public static Stream<KieBaseTestConfiguration> parameters() {
+        return 
TestParametersUtil2.getKieBaseCloudConfigurations(true).stream();
+    }
+
+    // =====================================================================
+    // FromNode tests
+    // =====================================================================
+
+    /**
+     * FromNode - left update: R1 modifies $p (the from source), R2 shares the 
same from node.
+     * Previously caused NPE in PhreakFromNode.doLeftUpdates.
+     */
+    @ParameterizedTest(name = "KieBase type={0}")
+    @MethodSource("parameters")
+    public void testFromNodeLeftUpdate(KieBaseTestConfiguration 
kieBaseTestConfiguration) {
+        String str =
+                "package org.drools.mvel.compiler.test\n" +
+                "import " + Person.class.getCanonicalName() + "\n" +
+                "import " + Address.class.getCanonicalName() + "\n" +
+                "global " + List.class.getCanonicalName() + " list\n" +
+                "rule R1 salience 100 no-loop when\n" +
+                "    $p : Person( age >= 0 )\n" +
+                "    $a : Address() from $p.addresses\n" +
+                "then\n" +
+                "    modify( $p ) { setAge( $p.getAge() + 1 ) };\n" +
+                "    list.add( \"R1\" );\n" +
+                "end\n" +
+                "rule R2 when\n" +
+                "    $p : Person( age >= 0 )\n" +
+                "    $a : Address() from $p.addresses\n" +
+                "then\n" +
+                "    list.add( \"R2:\" + $a.getStreet() );\n" +
+                "end\n";

Review Comment:
   The test class repeats substantial DRL boilerplate (package/import/global) 
and near-identical rule scaffolding across many tests, which makes future edits 
error-prone (small DRL header changes would need to be replicated across all 
strings). Consider extracting a small helper to build the common DRL header 
and/or templating the repeated rule structure (e.g., helper methods for 
`header(...)`, `rule(...)` blocks, or a minimal string builder), so each test 
focuses only on the node-specific conditions/actions.



##########
drools-core/src/main/java/org/drools/core/RuleBaseConfiguration.java:
##########
@@ -642,6 +642,10 @@ public void setShareAlphaNodes(final boolean 
shareAlphaNodes) {
     }
 
     public boolean isShareBetaNodes() {
+        // Beta node sharing in sequential mode causes NPE and incorrect 
results (incubator-kie#7201)
+        if (this.sequential) {
+            return false;
+        }
         return this.shareBetaNodes;
     }

Review Comment:
   Returning a computed value from `isShareBetaNodes()` while leaving the 
underlying `shareBetaNodes` field unchanged can create an internally 
inconsistent configuration state (e.g., `toString()`, serialization, 
diagnostics, or any internal code paths that read the field might still 
report/assume sharing is enabled). A more maintainable approach is to enforce 
this constraint at the point sequential mode is enabled (e.g., in the 
sequential option setter/initialization) and optionally reject or warn when 
`shareBetaNodes` is set to `true` while sequential is enabled, so the stored 
configuration always matches the effective behavior.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to