diff --git a/graph/planner/planner.py b/graph/planner/planner.py index 96c4639..771c0ac 100644 --- a/graph/planner/planner.py +++ b/graph/planner/planner.py @@ -36,7 +36,9 @@ def __init__( self._unhealthy = unhealthy or [] self._selected = selected - def apply(self) -> tuple[dict[str, NodeState], list[str]]: + def apply( + self, + ) -> tuple[dict[str, NodeState]]: # tuple[dict[str, NodeState], list[str]] nodes_state = self._state.nodes() nodes_target = self._target.nodes() @@ -90,102 +92,131 @@ def apply(self) -> tuple[dict[str, NodeState], list[str]]: # add required nodes by parent dependency for node in nodes_add: - parent_transitive = self._target.parents_transitive(node) - for node_add_transitive in parent_transitive: - if node_add_transitive not in nodes_state: - nodes[node_add_transitive].transitive_action = nodes[ - node_add_transitive + for parent in self._target.parents_transitive(node): + nodes[parent].active = nodes[parent].active.union({"transitive"}) + if parent not in nodes_state: + nodes[parent].transitive_action = nodes[ + parent ].transitive_action.union({"add"}) - # delete child nodes + # delete child nodes, consider 'Tools' (parent) for node in nodes_delete: - childs_transitive = self._state.childs_transitive( + for tool in self._state.parents( + node, accept=lambda adjacent: adjacent[1] == EdgeType.TOOL + ): + nodes[tool].active = nodes[tool].active.union({"transitive"}) + for parent in self._state.parents_transitive(tool): + nodes[parent].active = nodes[parent].active.union({"transitive"}) + + for child in self._state.childs_transitive( node, accept=lambda adjacent: adjacent[1] != EdgeType.TOOL, - ) - for node_transitive_delete in childs_transitive: + ): + nodes[child].active = nodes[child].active.union({"transitive"}) # if nodes[node_transitive_delete].primary_action != "delete": - nodes[node_transitive_delete].transitive_action = nodes[ - node_transitive_delete - ].transitive_action.union({"delete"}) + nodes[child].transitive_action = nodes[child].transitive_action.union( + {"delete"} + ) - # propagate 'modified'/'unhealthy' state - unhealthy_adjacent_tool_edge_nodes = set() for key, value in nodes.items(): node = key - state = value.state - # TODO test if reachable/required from user selected nodes - if "unhealthy" in state: - # propagate 'unhealthy' state to children != EdgeType.TOOL - childs_transitive = self._state.childs_transitive( + if "unhealthy" in value.state: + for child in self._state.childs_transitive( node, accept=lambda adjacent: adjacent[1] != EdgeType.TOOL, - ) - for node_transitive_state in childs_transitive: - nodes[node_transitive_state].transitive_state = nodes[ - node_transitive_state - ].transitive_state.union({"unhealthy"}) - - # collect nodes ('unhealthy')' w/ EdgeType.TOOL in reverse graph ~> incoming edge(s) - if EdgeType.TOOL in value.dependent_edge_types: - unhealthy_adjacent_tool_edge_nodes.add(node) - - if "modified" in state and value.active: - # propagate 'modified' state to children != EdgeType.TOOL - childs_transitive = self._state.childs_transitive( + ): + nodes[child].active = nodes[child].active.union({"transitive"}) + nodes[child].transitive_state = nodes[child].transitive_state.union( + {"unhealthy"} + ) + + if "modified" in value.state and "user" in value.active: + for child in self._state.childs_transitive( node, accept=lambda adjacent: adjacent[1] != EdgeType.TOOL, - ) - for node_transitive_state in childs_transitive: - nodes[node_transitive_state].transitive_state = nodes[ - node_transitive_state - ].transitive_state.union({"modified"}) - - operations = [] - # recover unhealthy nodes (required by dependent 'active' nodes) - if len(unhealthy_adjacent_tool_edge_nodes) > 0: - for node in reversed(self._state.topological_order()): - if node in unhealthy_adjacent_tool_edge_nodes: - operations.append(f"-{node}") - for node in self._state.topological_order(): - if node in unhealthy_adjacent_tool_edge_nodes: - operations.append(f"+{node}") - - # TODO re-run w/ updated unhealthy list - - nodes_re_add_modified_or_unhealthy = ( - [] - ) # optimization, not evaluate modified/unhealthy again - # 'delete' run - # TODO postpone nodes wich are required as tool - for node in self._state.topological_order(): - value = nodes[node] - - modified = ( - "modified" in value.state - and value.active - or "modified" in value.transitive_state - ) - unhealthy = ( - "unhealthy" in value.state and value.active - ) or "unhealthy" in value.transitive_state - delete = "delete" == value.action or "delete" in value.transitive_action - - if not delete and (modified or unhealthy): - operations.append(f"-{node}") - nodes_re_add_modified_or_unhealthy.append(node) - - if delete: - operations.append(f"-{node}") - - # 'add' run - for node in reversed(self._target.topological_order()): - value = nodes[node] - - add = "add" == value.action or "add" in value.transitive_action - if add or node in nodes_re_add_modified_or_unhealthy: - operations.append(f"+{node}") - - # TODO delete postponed nodes required as tool but selected for 'delete' - - return nodes, operations + ): + nodes[child].active = nodes[child].active.union({"transitive"}) + nodes[child].transitive_state = nodes[child].transitive_state.union( + {"modified"} + ) + + # # propagate 'modified'/'unhealthy' state + # unhealthy_adjacent_tool_edge_nodes = set() + # for key, value in nodes.items(): + # node = key + # state = value.state + # # TODO test if reachable/required from user selected nodes + # if "unhealthy" in state: + # # propagate 'unhealthy' state to children != EdgeType.TOOL + # childs_transitive = self._state.childs_transitive( + # node, + # accept=lambda adjacent: adjacent[1] != EdgeType.TOOL, + # ) + # for node_transitive_state in childs_transitive: + # nodes[node_transitive_state].transitive_state = nodes[ + # node_transitive_state + # ].transitive_state.union({"unhealthy"}) + # + # # collect nodes ('unhealthy')' w/ EdgeType.TOOL in reverse graph ~> incoming edge(s) + # if EdgeType.TOOL in value.dependent_edge_types: + # unhealthy_adjacent_tool_edge_nodes.add(node) + # + # if "modified" in state and value.active: + # # propagate 'modified' state to children != EdgeType.TOOL + # childs_transitive = self._state.childs_transitive( + # node, + # accept=lambda adjacent: adjacent[1] != EdgeType.TOOL, + # ) + # for node_transitive_state in childs_transitive: + # nodes[node_transitive_state].transitive_state = nodes[ + # node_transitive_state + # ].transitive_state.union({"modified"}) + # + # operations = [] + # # recover unhealthy nodes (required by dependent 'active' nodes) + # if len(unhealthy_adjacent_tool_edge_nodes) > 0: + # for node in reversed(self._state.topological_order()): + # if node in unhealthy_adjacent_tool_edge_nodes: + # operations.append(f"-{node}") + # for node in self._state.topological_order(): + # if node in unhealthy_adjacent_tool_edge_nodes: + # operations.append(f"+{node}") + # + # # TODO re-run w/ updated unhealthy list + # + # nodes_re_add_modified_or_unhealthy = ( + # [] + # ) # optimization, not evaluate modified/unhealthy again + # # 'delete' run + # # TODO postpone nodes wich are required as tool + # for node in self._state.topological_order(): + # value = nodes[node] + # + # modified = ( + # "modified" in value.state + # and value.active + # or "modified" in value.transitive_state + # ) + # unhealthy = ( + # "unhealthy" in value.state and value.active + # ) or "unhealthy" in value.transitive_state + # delete = "delete" == value.action or "delete" in value.transitive_action + # + # if not delete and (modified or unhealthy): + # operations.append(f"-{node}") + # nodes_re_add_modified_or_unhealthy.append(node) + # + # if delete: + # operations.append(f"-{node}") + # + # # 'add' run + # for node in reversed(self._target.topological_order()): + # value = nodes[node] + # + # add = "add" == value.action or "add" in value.transitive_action + # if add or node in nodes_re_add_modified_or_unhealthy: + # operations.append(f"+{node}") + # + # # TODO delete postponed nodes required as tool but selected for 'delete' + + return (nodes,) # , operations diff --git a/graph/planner/planner_test.py b/graph/planner/planner_test.py index 1708c89..49a2499 100644 --- a/graph/planner/planner_test.py +++ b/graph/planner/planner_test.py @@ -71,7 +71,7 @@ def test_no_action(self): dependent_edge_types={EdgeType.DEPENDENCY}, ), }, - [], + # [], ), planner.apply(), ) @@ -84,19 +84,19 @@ def test_apply_DAG1_modified_multiple(self): { "a": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, transitive_state={"modified"}, ), "b": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, state={"modified"}, dependent_edge_types={EdgeType.DEPENDENCY}, transitive_state={"modified"}, ), "c": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, state=set(), dependent_edge_types={EdgeType.DEPENDENCY}, transitive_state={"modified"}, @@ -114,7 +114,7 @@ def test_apply_DAG1_modified_multiple(self): dependent_edge_types={EdgeType.DEPENDENCY}, ), }, - ["-a", "-b", "-c", "-d", "+d", "+c", "+b", "+a"], + # ["-a", "-b", "-c", "-d", "+d", "+c", "+b", "+a"], ), planner.apply(), ) @@ -127,19 +127,19 @@ def test_apply_DAG1_unhealthy_multiple(self): { "a": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, transitive_state={"unhealthy"}, ), "b": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, state={"unhealthy"}, transitive_state={"unhealthy"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "c": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, transitive_state={"unhealthy"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), @@ -155,7 +155,7 @@ def test_apply_DAG1_unhealthy_multiple(self): dependent_edge_types={EdgeType.DEPENDENCY}, ), }, - ["-a", "-b", "-c", "-d", "+d", "+c", "+b", "+a"], + # ["-a", "-b", "-c", "-d", "+d", "+c", "+b", "+a"], ), planner.apply(), ) @@ -170,19 +170,19 @@ def test_apply_DAG1_unhealthy_and_modified(self): { "a": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, transitive_state={"modified", "unhealthy"}, ), "b": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, state={"modified", "unhealthy"}, transitive_state={"modified", "unhealthy"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "c": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, transitive_state={"modified", "unhealthy"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), @@ -198,7 +198,7 @@ def test_apply_DAG1_unhealthy_and_modified(self): dependent_edge_types={EdgeType.DEPENDENCY}, ), }, - ["-a", "-b", "-c", "-d", "+d", "+c", "+b", "+a"], + # ["-a", "-b", "-c", "-d", "+d", "+c", "+b", "+a"], ), planner.apply(), ) @@ -211,19 +211,19 @@ def test_apply_DAG1_unhealthy_or_modified(self): { "a": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, transitive_state={"modified", "unhealthy"}, ), "b": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, state={"modified"}, transitive_state={"unhealthy"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "c": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, transitive_state={"unhealthy"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), @@ -239,7 +239,7 @@ def test_apply_DAG1_unhealthy_or_modified(self): dependent_edge_types={EdgeType.DEPENDENCY}, ), }, - ["-a", "-b", "-c", "-d", "+d", "+c", "+b", "+a"], + # ["-a", "-b", "-c", "-d", "+d", "+c", "+b", "+a"], ), planner.apply(), ) @@ -252,24 +252,24 @@ def test_apply_DAG1_modified_root(self): { "a": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, transitive_state={"modified"}, ), "b": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, transitive_state={"modified"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "c": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, transitive_state={"modified"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "d": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, transitive_state={"modified"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), @@ -280,7 +280,7 @@ def test_apply_DAG1_modified_root(self): dependent_edge_types={EdgeType.DEPENDENCY}, ), }, - ["-a", "-b", "-c", "-d", "-e", "+e", "+d", "+c", "+b", "+a"], + # ["-a", "-b", "-c", "-d", "-e", "+e", "+d", "+c", "+b", "+a"], ), planner.apply(), ) @@ -293,24 +293,24 @@ def test_apply_DAG1_unhealthy_root(self): { "a": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, transitive_state={"unhealthy"}, ), "b": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, transitive_state={"unhealthy"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "c": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, transitive_state={"unhealthy"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "d": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, transitive_state={"unhealthy"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), @@ -321,7 +321,7 @@ def test_apply_DAG1_unhealthy_root(self): dependent_edge_types={EdgeType.DEPENDENCY}, ), }, - ["-a", "-b", "-c", "-d", "-e", "+e", "+d", "+c", "+b", "+a"], + # ["-a", "-b", "-c", "-d", "-e", "+e", "+d", "+c", "+b", "+a"], ), planner.apply(), ) @@ -351,7 +351,7 @@ def test_apply_DAG3_modified_single(self): present={"state", "target"}, active={"user"}, state={"modified"} ), }, - ["-d", "+d"], + # ["-d", "+d"], ), planner.apply(), ) @@ -370,7 +370,7 @@ def test_apply_DAG3_modified_root(self): ), "b": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, transitive_state={"modified"}, dependent_edge_types={EdgeType.DEPENDENCY, EdgeType.TOOL}, ), @@ -381,11 +381,11 @@ def test_apply_DAG3_modified_root(self): ), "d": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, transitive_state={"modified"}, ), }, - ["-d", "-b", "-a", "+a", "+b", "+d"], + # ["-d", "-b", "-a", "+a", "+b", "+d"], ), planner.apply(), ) @@ -402,13 +402,13 @@ def test_apply_add_to_empty(self): "a": NodeState(present={"target"}, active={"user"}, action="add"), "b": NodeState( present={"target"}, - active={"user"}, + active={"user", "transitive"}, transitive_action={"add"}, action="add", dependent_edge_types={EdgeType.DEPENDENCY}, ), }, - ["+b", "+a"], + # ["+b", "+a"], ), planner.apply(), ) @@ -427,7 +427,7 @@ def test_apply_add_to_existing(self): "a": NodeState(present={"state", "target"}, active={"user"}), "b": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "c": NodeState( @@ -437,7 +437,7 @@ def test_apply_add_to_existing(self): dependent_edge_types={EdgeType.DEPENDENCY}, ), }, - ["+c"], + # ["+c"], ), planner.apply(), ) @@ -453,7 +453,7 @@ def test_apply_remove_all(self): { "a": NodeState( present={"state"}, - active={"user"}, + active={"user", "transitive"}, action="delete", transitive_action={"delete"}, ), @@ -464,7 +464,7 @@ def test_apply_remove_all(self): dependent_edge_types={EdgeType.DEPENDENCY}, ), }, - ["-a", "-b"], + # ["-a", "-b"], ), planner.apply(), ) @@ -477,13 +477,13 @@ def test_apply_DAG3_remove_all(self): { "a": NodeState( present={"state"}, - active={"user"}, + active={"user", "transitive"}, action="delete", dependent_edge_types={EdgeType.DEPENDENCY}, ), "b": NodeState( present={"state"}, - active={"user"}, + active={"user", "transitive"}, action="delete", transitive_action={"delete"}, dependent_edge_types={EdgeType.DEPENDENCY, EdgeType.TOOL}, @@ -496,12 +496,12 @@ def test_apply_DAG3_remove_all(self): ), "d": NodeState( present={"state"}, - active={"user"}, + active={"user", "transitive"}, action="delete", transitive_action={"delete"}, ), }, - ["-d", "-c", "-b", "-a"], + # ["-d", "-c", "-b", "-a"], ), planner.apply(), ) @@ -517,13 +517,13 @@ def test_add_and_delete(self): { "a": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "b": NodeState(present={"state"}, active={"user"}, action="delete"), "c": NodeState(present={"target"}, active={"user"}, action="add"), }, - ["-b", "+c"], + # ["-b", "+c"], ), planner.apply(), ) @@ -556,7 +556,7 @@ def test_modified_but_delete(self): state={"modified"}, ), }, - ["-c"], + # ["-c"], ), planner.apply(), ) @@ -569,20 +569,24 @@ def test_apply_delete_DAG2_temporarily(self): { "a": NodeState( present={"state", "target"}, + active={"transitive"}, transitive_action={"delete"}, ), "b": NodeState( present={"state", "target"}, + active={"transitive"}, transitive_action={"delete"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "c": NodeState( present={"state", "target"}, + active={"transitive"}, transitive_action={"delete"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "c1": NodeState( present={"state", "target"}, + active={"transitive"}, transitive_action={"delete"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), @@ -602,11 +606,13 @@ def test_apply_delete_DAG2_temporarily(self): ), "d": NodeState( present={"state", "target"}, + active={"transitive"}, transitive_action={"delete"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "d1": NodeState( present={"state", "target"}, + active={"transitive"}, transitive_action={"delete"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), @@ -619,7 +625,7 @@ def test_apply_delete_DAG2_temporarily(self): dependent_edge_types={EdgeType.DEPENDENCY}, ), }, - ["-a", "-b", "-d", "-d1", "-c", "-c1", "-c1d1"], + # ["-a", "-b", "-d", "-d1", "-c", "-c1", "-c1d1"], ), planner.apply(), ) @@ -647,20 +653,24 @@ def test_apply_delete_DAG2_temporarily_with_target_changes(self): { "a": NodeState( present={"state"}, + active={"transitive"}, transitive_action={"delete"}, ), "b": NodeState( present={"state"}, + active={"transitive"}, transitive_action={"delete"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "c": NodeState( present={"state", "target"}, + active={"transitive"}, transitive_action={"delete"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "c1": NodeState( present={"state", "target"}, + active={"transitive"}, transitive_action={"delete"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), @@ -680,11 +690,13 @@ def test_apply_delete_DAG2_temporarily_with_target_changes(self): ), "d": NodeState( present={"state", "target"}, + active={"transitive"}, transitive_action={"delete"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "d1": NodeState( present={"state", "target"}, + active={"transitive"}, transitive_action={"delete"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), @@ -697,7 +709,7 @@ def test_apply_delete_DAG2_temporarily_with_target_changes(self): dependent_edge_types={EdgeType.DEPENDENCY}, ), }, - ["-a", "-b", "-d", "-d1", "-c", "-c1", "-c1d1"], + # ["-a", "-b", "-d", "-d1", "-c", "-c1", "-c1d1"], ), planner.apply(), ) @@ -710,20 +722,24 @@ def test_apply_delete_roots_DAG2_temporarily(self): { "a": NodeState( present={"state", "target"}, + active={"transitive"}, transitive_action={"delete"}, ), "b": NodeState( present={"state", "target"}, + active={"transitive"}, transitive_action={"delete"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "c": NodeState( present={"state", "target"}, + active={"transitive"}, transitive_action={"delete"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "c1": NodeState( present={"state", "target"}, + active={"transitive"}, transitive_action={"delete"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), @@ -735,6 +751,7 @@ def test_apply_delete_roots_DAG2_temporarily(self): ), "c2": NodeState( present={"state", "target"}, + active={"transitive"}, transitive_action={"delete"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), @@ -746,16 +763,19 @@ def test_apply_delete_roots_DAG2_temporarily(self): ), "d": NodeState( present={"state", "target"}, + active={"transitive"}, transitive_action={"delete"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "d1": NodeState( present={"state", "target"}, + active={"transitive"}, transitive_action={"delete"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "d2": NodeState( present={"state", "target"}, + active={"transitive"}, transitive_action={"delete"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), @@ -764,7 +784,7 @@ def test_apply_delete_roots_DAG2_temporarily(self): dependent_edge_types={EdgeType.DEPENDENCY}, ), }, - ["-a", "-b", "-d", "-d2", "-d1", "-c", "-c2", "-c2d2", "-c1", "-c1d1"], + # ["-a", "-b", "-d", "-d2", "-d1", "-c", "-c2", "-c2d2", "-c1", "-c1d1"], ), planner.apply(), ) @@ -782,11 +802,13 @@ def test_apply_delete_with_modified_one_TOOL_edge(self): ( { "a": NodeState( + active={"transitive"}, present={"state", "target"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "b": NodeState( present={"state", "target"}, + active={"transitive"}, state={"modified"}, dependent_edge_types={EdgeType.TOOL}, ), @@ -796,7 +818,7 @@ def test_apply_delete_with_modified_one_TOOL_edge(self): action="delete", ), }, - ["-c"], + # ["-c"], ), planner.apply(), ) @@ -815,10 +837,12 @@ def test_apply_delete_with_unhealthy_one_TOOL_edge(self): { "a": NodeState( present={"state", "target"}, + active={"transitive"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "b": NodeState( present={"state", "target"}, + active={"transitive"}, state={"unhealthy"}, dependent_edge_types={EdgeType.TOOL}, ), @@ -828,7 +852,7 @@ def test_apply_delete_with_unhealthy_one_TOOL_edge(self): action="delete", ), }, - ["-b", "+b", "-c"], + # ["-b", "+b", "-c"], ), planner.apply(), ) @@ -849,14 +873,17 @@ def test_apply_delete_with_one_modified_two_TOOL_edge_in_chain(self): { "a": NodeState( present={"state", "target"}, + active={"transitive"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "b1": NodeState( present={"state", "target"}, + active={"transitive"}, dependent_edge_types={EdgeType.TOOL}, ), "b2": NodeState( present={"state", "target"}, + active={"transitive"}, state={"modified"}, dependent_edge_types={EdgeType.TOOL}, ), @@ -866,7 +893,7 @@ def test_apply_delete_with_one_modified_two_TOOL_edge_in_chain(self): action="delete", ), }, - ["-c"], + # ["-c"], ), planner.apply(), ) @@ -887,14 +914,17 @@ def test_apply_delete_with_one_unhealthy_two_TOOL_edge_in_chain(self): { "a": NodeState( present={"state", "target"}, + active={"transitive"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "b1": NodeState( present={"state", "target"}, + active={"transitive"}, dependent_edge_types={EdgeType.TOOL}, ), "b2": NodeState( present={"state", "target"}, + active={"transitive"}, state={"unhealthy"}, dependent_edge_types={EdgeType.TOOL}, ), @@ -904,7 +934,7 @@ def test_apply_delete_with_one_unhealthy_two_TOOL_edge_in_chain(self): action="delete", ), }, - ["-b2", "+b2", "-c"], + # ["-b2", "+b2", "-c"], ), planner.apply(), ) @@ -925,15 +955,18 @@ def test_apply_delete_with_two_modified_two_TOOL_edge_in_chain(self): { "a": NodeState( present={"state", "target"}, + active={"transitive"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "b1": NodeState( present={"state", "target"}, state={"modified"}, + active={"transitive"}, dependent_edge_types={EdgeType.TOOL}, ), "b2": NodeState( present={"state", "target"}, + active={"transitive"}, state={"modified"}, dependent_edge_types={EdgeType.TOOL}, ), @@ -943,7 +976,7 @@ def test_apply_delete_with_two_modified_two_TOOL_edge_in_chain(self): action="delete", ), }, - ["-c"], + # ["-c"], ), planner.apply(), ) @@ -964,15 +997,18 @@ def test_apply_delete_with_two_unhealthy_two_TOOL_edge_in_chain(self): { "a": NodeState( present={"state", "target"}, + active={"transitive"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "b1": NodeState( present={"state", "target"}, + active={"transitive"}, state={"unhealthy"}, dependent_edge_types={EdgeType.TOOL}, ), "b2": NodeState( present={"state", "target"}, + active={"transitive"}, state={"unhealthy"}, dependent_edge_types={EdgeType.TOOL}, ), @@ -982,7 +1018,7 @@ def test_apply_delete_with_two_unhealthy_two_TOOL_edge_in_chain(self): action="delete", ), }, - ["-b1", "-b2", "+b2", "+b1", "-c"], + # ["-b1", "-b2", "+b2", "+b1", "-c"], ), planner.apply(), ) @@ -1003,15 +1039,18 @@ def test_apply_delete_with_one_modified_two_TOOL_edge_in_chain_skip(self): { "a": NodeState( present={"state", "target"}, + active={"transitive"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "b1": NodeState( present={"state", "target"}, + active={"transitive"}, state={"modified"}, dependent_edge_types={EdgeType.TOOL}, ), "b2": NodeState( present={"state", "target"}, + active={"transitive"}, dependent_edge_types={EdgeType.TOOL}, ), "c": NodeState( @@ -1020,7 +1059,7 @@ def test_apply_delete_with_one_modified_two_TOOL_edge_in_chain_skip(self): action="delete", ), }, - ["-c"], + # ["-c"], ), planner.apply(), ) @@ -1050,7 +1089,7 @@ def test_no_action_apply_selected(self): dependent_edge_types={EdgeType.DEPENDENCY}, ), }, - [], + # [], ), planner.apply(), ) @@ -1063,6 +1102,7 @@ def test_apply_DAG1_modified_multiple_single_selected(self): { "a": NodeState( present={"state", "target"}, + active={"transitive"}, transitive_state={"modified"}, ), "b": NodeState( @@ -1085,7 +1125,7 @@ def test_apply_DAG1_modified_multiple_single_selected(self): dependent_edge_types={EdgeType.DEPENDENCY}, ), }, - ["-a", "-b", "+b", "+a"], + # ["-a", "-b", "+b", "+a"], ), planner.apply(), ) @@ -1100,10 +1140,12 @@ def test_apply_DAG3_selected_target(self): { "a": NodeState( present={"state", "target"}, + active={"transitive"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "b": NodeState( present={"target"}, + active={"transitive"}, transitive_action={"add"}, dependent_edge_types={EdgeType.DEPENDENCY, EdgeType.TOOL}, ), @@ -1115,7 +1157,7 @@ def test_apply_DAG3_selected_target(self): ), "d": NodeState(present={"target"}), }, - ["+b", "+c"], + # ["+b", "+c"], ), planner.apply(), ) @@ -1133,11 +1175,13 @@ def test_apply_DAG3_selected_target_modified(self): { "a": NodeState( present={"state", "target"}, + active={"transitive"}, state={"modified"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "b": NodeState( present={"target"}, + active={"transitive"}, transitive_action={"add"}, dependent_edge_types={EdgeType.DEPENDENCY, EdgeType.TOOL}, ), @@ -1149,7 +1193,7 @@ def test_apply_DAG3_selected_target_modified(self): ), "d": NodeState(present={"target"}), }, - ["+b", "+c"], + # ["+b", "+c"], ), planner.apply(), ) @@ -1167,11 +1211,13 @@ def test_apply_DAG3_selected_target_unhealthy(self): { "a": NodeState( present={"state", "target"}, + active={"transitive"}, state={"unhealthy"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "b": NodeState( present={"target"}, + active={"transitive"}, transitive_action={"add"}, dependent_edge_types={EdgeType.DEPENDENCY, EdgeType.TOOL}, ), @@ -1183,8 +1229,7 @@ def test_apply_DAG3_selected_target_unhealthy(self): ), "d": NodeState(present={"target"}), }, - # TODO? ["-a", "+a", "+b", "+c"], - ["+b", "+c"], + # ["-a", "+a", "+b", "+c"], ), planner.apply(), ) @@ -1204,16 +1249,18 @@ def test_apply_DAG3_selected_target_modified_one_TOOL_edge(self): { "a": NodeState( present={"state", "target"}, + active={"transitive"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "b": NodeState( present={"state", "target"}, + active={"transitive"}, state={"modified"}, dependent_edge_types={EdgeType.TOOL}, ), "c": NodeState(present={"target"}, active={"user"}, action="add"), }, - ["+c"], + # ["+c"], ), planner.apply(), ) @@ -1233,16 +1280,18 @@ def test_apply_DAG3_selected_target_unhealthy_one_TOOL_edge(self): { "a": NodeState( present={"state", "target"}, + active={"transitive"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "b": NodeState( present={"state", "target"}, + active={"transitive"}, state={"unhealthy"}, dependent_edge_types={EdgeType.TOOL}, ), "c": NodeState(present={"target"}, active={"user"}, action="add"), }, - ["-b", "+b", "+c"], + # ["-b", "+b", "+c"], ), planner.apply(), ) @@ -1268,25 +1317,29 @@ def test_apply_DAG3_selected_target_modified_one_TOOL_edge_chain_skip(self): { "a": NodeState( present={"state", "target"}, + active={"transitive"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), "b": NodeState( present={"state", "target"}, + active={"transitive"}, state={"modified"}, dependent_edge_types={EdgeType.TOOL}, ), "c": NodeState( present={"state", "target"}, + active={"transitive"}, dependent_edge_types={EdgeType.TOOL}, ), "d": NodeState( present={"target"}, + active={"transitive"}, dependent_edge_types={EdgeType.DEPENDENCY}, transitive_action={"add"}, ), "e": NodeState(present={"target"}, active={"user"}, action="add"), }, - ["+d", "+e"], + # ["+d", "+e"], ), planner.apply(), ) @@ -1309,11 +1362,12 @@ def test_apply_selected_TOOL_edge_modified(self): ), "b": NodeState( present={"state", "target"}, + active={"transitive"}, state={"modified"}, dependent_edge_types={EdgeType.TOOL}, ), }, - ["-a"], + # ["-a"], ), planner.apply(), ) @@ -1336,11 +1390,12 @@ def test_apply_selected_TOOL_edge_unhealthy(self): ), "b": NodeState( present={"state", "target"}, + active={"transitive"}, state={"unhealthy"}, dependent_edge_types={EdgeType.TOOL}, ), }, - ["-b", "+b", "-a"], + # ["-b", "+b", "-a"], ), planner.apply(), ) @@ -1362,13 +1417,13 @@ def test_apply_unhealthy_tool(self): { "a": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, action="delete", transitive_action={"delete"}, ), "b": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, action="delete", transitive_action={"delete"}, state={"unhealthy"}, @@ -1376,12 +1431,12 @@ def test_apply_unhealthy_tool(self): ), "c": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, action="delete", dependent_edge_types={EdgeType.DEPENDENCY}, ), }, - ["-b", "+b", "-a", "-b", "-c"], + # ["-b", "+b", "-a", "-b", "-c"], ), planner.apply(), ) @@ -1401,16 +1456,17 @@ def test_apply_delete_tool(self): "a": NodeState(present={"target"}, active={"user"}, action="add"), "b": NodeState( present={"state", "target"}, - active={"user"}, + active={"user", "transitive"}, action="delete", dependent_edge_types={EdgeType.TOOL}, ), "c": NodeState( present={"state", "target"}, + active={"transitive"}, dependent_edge_types={EdgeType.DEPENDENCY}, ), }, - ["+a", "-b"], + # ["+a", "-b"], ), planner.apply(), )