Skip to content

Commit d0262bc

Browse files
Copilot0xkarmacoma
andcommitted
Address feedback: simplify tagging API and remove unnecessary tests
Co-authored-by: 0xkarmacoma <[email protected]>
1 parent b421f6e commit d0262bc

File tree

4 files changed

+86
-232
lines changed

4 files changed

+86
-232
lines changed

src/halmos/__main__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ def _compute_frontier(ctx: ContractContext, depth: int) -> Iterator[Exec]:
722722
ex=post_ex,
723723
panic_found=panic_found,
724724
description=msg,
725-
probe_tag=probe_tag,
725+
tag=probe_tag,
726726
)
727727
except ShutdownError:
728728
if args.debug:
@@ -821,7 +821,7 @@ def handle_assertion_violation(
821821
ex: Exec,
822822
panic_found: bool,
823823
description: str = None,
824-
probe_tag: str = None,
824+
tag: str | None = None,
825825
) -> None:
826826
"""
827827
Handles a potential assertion violation by solving it in a separate process.
@@ -876,7 +876,7 @@ def handle_assertion_violation(
876876
path_id=path_id,
877877
solving_ctx=ctx.solving_ctx,
878878
query=query,
879-
tag=probe_tag if probe_tag else ctx.info.sig,
879+
tag=tag if tag else ctx.info.sig,
880880
)
881881

882882
# ShutdownError may be raised here and will be handled by the caller
@@ -974,8 +974,8 @@ def _solve_end_to_end_callback(
974974

975975
# we have a valid counterexample, so we are eligible for early exit
976976
if args.early_exit:
977-
debug(f"Interrupting {ctx.info.name}'s solver queries")
978-
get_global_executor().interrupt(ctx.info.name)
977+
debug(f"Interrupting {ctx.info.sig}'s solver queries")
978+
get_global_executor().interrupt(ctx.info.sig)
979979
else:
980980
warn_str = f"Counterexample (potentially invalid): {model}"
981981
warn_code(COUNTEREXAMPLE_INVALID, warn_str)

tests/test_executor.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# SPDX-License-Identifier: AGPL-3.0
2+
3+
from unittest.mock import Mock
4+
5+
from halmos.processes import PopenFuture, get_global_executor
6+
7+
8+
def test_popen_future_with_tag():
9+
"""Test that PopenFuture accepts and stores tag parameter."""
10+
cmd = ["echo", "hello"]
11+
tag = "test-tag"
12+
13+
future = PopenFuture(cmd, tag)
14+
15+
assert future.cmd == cmd
16+
assert future.tag == tag
17+
18+
19+
def test_popen_future_with_minimal_args():
20+
"""Test that PopenFuture works with minimal required parameters."""
21+
cmd = ["echo", "hello"]
22+
tag = "test-minimal"
23+
24+
future = PopenFuture(cmd, tag)
25+
26+
assert future.cmd == cmd
27+
assert future.tag == tag
28+
29+
30+
def test_popen_future_empty_tag_assertion():
31+
"""Test that PopenFuture raises assertion error for empty tag."""
32+
cmd = ["echo", "hello"]
33+
34+
try:
35+
PopenFuture(cmd, "")
36+
raise AssertionError("Expected AssertionError for empty tag")
37+
except AssertionError:
38+
pass # Expected
39+
40+
41+
def test_interrupt_by_tag():
42+
"""Test that interrupt() cancels futures with matching tags."""
43+
executor = get_global_executor()
44+
45+
# Create mock futures with different tags
46+
future1 = Mock(spec=PopenFuture)
47+
future1.tag = "tag1"
48+
future2 = Mock(spec=PopenFuture)
49+
future2.tag = "tag2"
50+
future3 = Mock(spec=PopenFuture)
51+
future3.tag = "tag1"
52+
future4 = Mock(spec=PopenFuture)
53+
future4.tag = "tag3"
54+
55+
# Add to executor's futures list
56+
executor._futures = [future1, future2, future3, future4]
57+
58+
# Interrupt tag1
59+
executor.interrupt("tag1")
60+
61+
# Check that only futures with tag1 were cancelled
62+
future1.cancel.assert_called_once()
63+
future2.cancel.assert_not_called()
64+
future3.cancel.assert_called_once()
65+
future4.cancel.assert_not_called()
66+
67+
68+
def test_interrupt_nonexistent_tag():
69+
"""Test that interrupt() with non-existent tag does nothing."""
70+
executor = get_global_executor()
71+
72+
# Create mock future
73+
future = Mock(spec=PopenFuture)
74+
future.tag = "existing-tag"
75+
executor._futures = [future]
76+
77+
# Interrupt with non-existent tag
78+
executor.interrupt("nonexistent-tag")
79+
80+
# No futures should be cancelled
81+
future.cancel.assert_not_called()

tests/test_global_executor.py

Lines changed: 0 additions & 124 deletions
This file was deleted.

tests/test_solver_integration.py

Lines changed: 0 additions & 103 deletions
This file was deleted.

0 commit comments

Comments
 (0)