DEV: Prevent removed keys from being resolved in the DAG (#26912)

This commit is contained in:
Sérgio Saquetim 2024-05-07 16:59:36 -03:00 committed by GitHub
parent 4edc011d10
commit e992cf1507
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 1 deletions

View File

@ -91,7 +91,14 @@ export default class DAG {
@bind
resolve() {
const result = [];
this.#dag.each((key, value) => result.push({ key, value }));
this.#dag.each((key, value) => {
// We need to filter keys that do not exist in the rawData because the DAGMap will insert a vertex for
// dependencies, for example if an item has a "before: search" dependency, the "search" vertex will be included
// even if it was explicitly excluded from the raw data.
if (this.has(key)) {
result.push({ key, value });
}
});
return result;
}

View File

@ -70,6 +70,20 @@ module("Unit | Lib | DAG", function (hooks) {
assert.deepEqual(keys, ["key1", "key2", "key4", "key3"]);
});
test("should resolve only existing keys", function (assert) {
dag = new DAG();
dag.add("key1", "value1");
dag.add("key2", "value2", { before: "key1" });
dag.add("key3", "value3");
dag.delete("key1");
const resolved = dag.resolve();
const keys = resolved.map((pair) => pair.key);
assert.deepEqual(keys, ["key2", "key3"]);
});
test("throws on bad positioning", function (assert) {
dag = new DAG();