Skip to content

Commit

Permalink
Fixed stateful modification of ctx
Browse files Browse the repository at this point in the history
Signed-off-by: JonahSussman <sussmanjonah@gmail.com>
  • Loading branch information
JonahSussman committed Aug 20, 2024
1 parent dfd675b commit 9a28c61
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
14 changes: 8 additions & 6 deletions kai/service/solution_handling/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,14 @@ def solution_detection_line_match(
4. Check if the mapping contains the node. If it does, the incident is
unsolved. If not, it's solved
"""
result = SolutionDetectorResult([], [], [])

# TODO: Support multiple languages
ts_language = ts.Language(tree_sitter_java.language())
parser = ts.Parser(ts_language)

result = SolutionDetectorResult([], [], [])
# new_incidents = ctx.new_incidents.copy()
new_incidents = [x for x in ctx.new_incidents]

# Map the old incidents to their hashes for quick equality lookup.

naive_old_incidents: dict[int, SQLIncident] = {
Expand All @@ -161,13 +163,13 @@ def solution_detection_line_match(
# Filter the exact matches

i = 0
while i < len(ctx.new_incidents):
incident = ctx.new_incidents[i]
while i < len(new_incidents):
incident = new_incidents[i]
incident_hash = naive_hash(incident)

if incident_hash in naive_old_incidents:
result.unsolved.append(naive_old_incidents.pop(incident_hash))
ctx.new_incidents.pop(i)
new_incidents.pop(i)
else:
i += 1

Expand All @@ -187,7 +189,7 @@ def solution_detection_line_match(

# Check each remaining incident in new_incidents

for incident in ctx.new_incidents:
for incident in new_incidents:
incident_line_match_hash = line_match_hash(incident)

# Check if the incident is in the remaining old incidents. If not, then
Expand Down
3 changes: 1 addition & 2 deletions kai/service/solution_handling/test_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ def local_yaml(file_path: str) -> dict | list:
)
)

# Detection algorithms statefully modify inputs
self.assertEqual(result.new, [new_incidents[0]], "Failed added incidents")
self.assertEqual(result.new, [new_incidents[1]], "Failed added incidents")
self.assertEqual(result.unsolved, [old_incidents[0]], "Failed added incidents")
self.assertEqual(result.solved, [], "Failed added incidents")

Expand Down

0 comments on commit 9a28c61

Please sign in to comment.