Skip to content

Commit f4beea9

Browse files
tretnedherges
authored andcommitted
fix: correct depth analysis of unordered dependencies for secondaries (#846)
1 parent 5e1d898 commit f4beea9

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/lib/brocc/depth.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,25 @@ describe(`DepthBuilder`, () => {
4848
expect(groups[3]).to.have.same.members(['b']);
4949
expect(groups[4]).to.have.same.members(['a']);
5050
});
51+
52+
/**
53+
* This scenario is visually documented:
54+
* https://mermaidjs.github.io/mermaid-live-editor/#/edit/eyJjb2RlIjoiZ3JhcGggVERcbmIgLS0-IGRcbmIgLS0-IGNcbmIgLS0-IGVcbmEgLS0-IGJcbmEgLS0-IGRcbmEgLS0-IGNcbmEgLS0-IGVcbmQgLS0-IGVcbmMgLS0-IGRcbmMgLS0-IGUiLCJtZXJtYWlkIjp7InRoZW1lIjoiZGVmYXVsdCJ9fQ
55+
*/
56+
it(`should group an unordered complex scenario`, () => {
57+
const builder = new DepthBuilder();
58+
builder.add('b', ['d','c','e']);
59+
builder.add('a', ['b', 'd', 'c', 'e']);
60+
builder.add('d','e');
61+
builder.add('c', ['d','e']);
62+
builder.add('e');
63+
64+
const groups = builder.build();
65+
expect(groups.length).to.equal(5);
66+
expect(groups[0]).to.have.same.members(['e']);
67+
expect(groups[1]).to.have.same.members(['d']);
68+
expect(groups[2]).to.have.same.members(['c']);
69+
expect(groups[3]).to.have.same.members(['b']);
70+
expect(groups[4]).to.have.same.members(['a']);
71+
});
5172
});

src/lib/brocc/depth.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ export class DepthBuilder {
8686

8787
const dependencyDepth = nodeDepths.get(parent.token);
8888
if (currentDepth > dependencyDepth) {
89+
// Push the dependency to the queue again and track its depth
90+
nodeQueue.push(parent);
8991
nodeDepths.set(parent.token, currentDepth);
9092
}
9193
});

0 commit comments

Comments
 (0)