Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(VariableResolver): correctly filter out already existing properties #30

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/base/VariableResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ function merge(property, target, source) {
target[property] = [];
}

const originToAdd = source[property].filter(o => !target.origin.includes(o));
const propertiesToAdd = source[property].filter(o => !target[property].includes(o));

target[property].push(...originToAdd);
target[property].push(...propertiesToAdd);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If spread can cause problems, why do we keep using it?

Suggested change
target[property].push(...propertiesToAdd);
target[property] = target[property].concat(propertiesToAdd);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a (desired) side effect of using .push, we modify the original array, which is referenced from nested variables as well. So you will get the correct list of origins for a (sub-)variable even when it was added through mappings.

The Stack index was only a symptom of another problem, so it should be safe to use it

}

export function mergeEntries(target, source, visited = []) {
Expand Down
75 changes: 0 additions & 75 deletions test/fixtures/zeebe/mappings/mappings.bpmn

This file was deleted.

38 changes: 37 additions & 1 deletion test/fixtures/zeebe/mappings/merging.bpmn
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1noegy9" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.10.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.1.0">
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1noegy9" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.21.0-rc.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.1.0">
<bpmn:collaboration id="Collaboration_0val525">
<bpmn:participant id="Participant_1" processRef="Process_1" />
<bpmn:participant id="Participant_2" processRef="Process_2" />
<bpmn:participant id="Participant_3" processRef="Process_3" />
</bpmn:collaboration>
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:serviceTask id="mergeContext" name="Merging Contexts">
Expand Down Expand Up @@ -36,6 +37,34 @@
</bpmn:extensionElements>
</bpmn:serviceTask>
</bpmn:process>
<bpmn:process id="Process_3" isExecutable="false">
<bpmn:serviceTask id="Activity_1d3l9mi" name="20 Mappings">
<bpmn:extensionElements>
<zeebe:ioMapping>
<zeebe:output source="=a" target="foo" />
<zeebe:output target="foo" />
<zeebe:output target="foo" />
<zeebe:output target="foo" />
<zeebe:output target="foo" />
<zeebe:output target="foo" />
<zeebe:output target="foo" />
<zeebe:output target="foo" />
<zeebe:output target="foo" />
<zeebe:output target="foo" />
<zeebe:output target="foo" />
<zeebe:output target="foo" />
<zeebe:output target="foo" />
<zeebe:output target="foo" />
<zeebe:output target="foo" />
<zeebe:output target="foo" />
<zeebe:output target="foo" />
<zeebe:output target="foo" />
<zeebe:output target="foo" />
<zeebe:output target="foo" />
</zeebe:ioMapping>
</bpmn:extensionElements>
</bpmn:serviceTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_0val525">
<bpmndi:BPMNShape id="Participant_0o063cf_di" bpmnElement="Participant_1" isHorizontal="true">
Expand All @@ -59,6 +88,13 @@
<dc:Bounds x="510" y="460" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Participant_10nlgk8_di" bpmnElement="Participant_3" isHorizontal="true">
<dc:Bounds x="160" y="680" width="600" height="250" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1lvesqk_di" bpmnElement="Activity_1d3l9mi">
<dc:Bounds x="210" y="760" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
23 changes: 23 additions & 0 deletions test/spec/zeebe/Mappings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,29 @@ describe('ZeebeVariableResolver - Variable Mappings', function() {
]);
}));


it('should handle many merge operations', inject(async function(variableResolver, elementRegistry) {

// given
const root = elementRegistry.get('Participant_3');

createProvider({
variables: [],
variableResolver
});

// when
// this failed previously in an infinite loop, cf. https://github.com/camunda/camunda-modeler/issues/4139
const variables = await variableResolver.getVariablesForElement(root.businessObject.processRef);

// then
expect(variables).to.variableEqual([
{
name: 'foo'
}
]);
}));

});


Expand Down