-
Notifications
You must be signed in to change notification settings - Fork 95
Add --dump-smt-directory flag to specify custom SMT dump location #533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: 0xkarmacoma <[email protected]>
src/halmos/config.py
Outdated
| group=debugging, | ||
| ) | ||
|
|
||
| dump_smt_directory: Union[str, None] = arg( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use str | None and avoid importing Union
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use str | None and removed the Union import. Changes in bd91173.
Co-authored-by: 0xkarmacoma <[email protected]>
src/halmos/solve.py
Outdated
| @dataclass | ||
| class DumpDirectory: | ||
| """Wrapper for directory used for dumping SMT files. | ||
| Can wrap either a TemporaryDirectory or a regular directory path. | ||
| Provides a consistent .name property for both cases. | ||
| """ | ||
| _temp_dir: TemporaryDirectory | None = None | ||
| _path: str | None = None | ||
|
|
||
| @classmethod | ||
| def from_temp_dir(cls, temp_dir: TemporaryDirectory) -> "DumpDirectory": | ||
| return cls(_temp_dir=temp_dir) | ||
|
|
||
| @classmethod | ||
| def from_path(cls, path: str | Path) -> "DumpDirectory": | ||
| return cls(_path=str(path)) | ||
|
|
||
| @property | ||
| def name(self) -> str: | ||
| if self._temp_dir is not None: | ||
| return self._temp_dir.name | ||
| elif self._path is not None: | ||
| return self._path | ||
| else: | ||
| raise ValueError("DumpDirectory not properly initialized") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need to introduce a whole new dataclass for this, instead introduce a simple DumpDirectory type alias for TemporaryDirectory | Path
then we can just have a helper function dirname(dump_dir: DumpDirectory) that does a match on the actual type of dump_dir. Basically like a lightweight algebraic data type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified the implementation using a type alias DumpDirectory = TemporaryDirectory | Path and helper function dirname(dump_dir: DumpDirectory) with pattern matching as suggested. This is much cleaner than the dataclass approach. Changes in fa5ad32.
tests/test_dump_directory.py
Outdated
| def test_dump_directory_from_temp_dir(): | ||
| """Test DumpDirectory.from_temp_dir creates correct wrapper""" | ||
| with TemporaryDirectory() as temp_dir_path: | ||
| temp_dir = TemporaryDirectory() | ||
| temp_dir.name = temp_dir_path # set a known path for testing | ||
|
|
||
| dump_dir = DumpDirectory.from_temp_dir(temp_dir) | ||
|
|
||
| assert dump_dir.name == temp_dir_path | ||
| assert dump_dir._temp_dir == temp_dir | ||
| assert dump_dir._path is None | ||
|
|
||
|
|
||
| def test_dump_directory_from_path_string(): | ||
| """Test DumpDirectory.from_path with string path""" | ||
| with tempfile.TemporaryDirectory() as temp_dir: | ||
| dump_dir = DumpDirectory.from_path(temp_dir) | ||
|
|
||
| assert dump_dir.name == temp_dir | ||
| assert dump_dir._temp_dir is None | ||
| assert dump_dir._path == temp_dir | ||
|
|
||
|
|
||
| def test_dump_directory_from_path_pathlib(): | ||
| """Test DumpDirectory.from_path with Path object""" | ||
| with tempfile.TemporaryDirectory() as temp_dir: | ||
| path_obj = Path(temp_dir) | ||
| dump_dir = DumpDirectory.from_path(path_obj) | ||
|
|
||
| assert dump_dir.name == str(path_obj) | ||
| assert dump_dir._temp_dir is None | ||
| assert dump_dir._path == str(path_obj) | ||
|
|
||
|
|
||
| def test_dump_directory_uninitialized(): | ||
| """Test that uninitialized DumpDirectory raises error""" | ||
| dump_dir = DumpDirectory() | ||
|
|
||
| with pytest.raises(ValueError, match="DumpDirectory not properly initialized"): | ||
| _ = dump_dir.name | ||
|
|
||
|
|
||
| def test_config_has_dump_smt_directory_field(): | ||
| """Test that Config has the new dump_smt_directory field""" | ||
| config = Config(_parent=None, _source=ConfigSource.void) | ||
|
|
||
| # Check that the field exists and defaults to None | ||
| assert hasattr(config, 'dump_smt_directory') | ||
| assert config.dump_smt_directory is None | ||
|
|
||
|
|
||
| def test_config_dump_smt_directory_accepts_string(): | ||
| """Test that dump_smt_directory accepts string values""" | ||
| with tempfile.TemporaryDirectory() as temp_dir: | ||
| config = Config( | ||
| _parent=None, | ||
| _source=ConfigSource.void, | ||
| dump_smt_directory=temp_dir | ||
| ) | ||
|
|
||
| assert config.dump_smt_directory == temp_dir No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are too complex, add at most a couple simple tests for dirname in the existing tests/test_utils.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified the tests by removing the complex test_dump_directory.py file and adding just 2 simple tests for the dirname function in test_utils.py. This reduces test complexity from 62 lines with 6 tests to 18 lines with 2 focused tests. Changes in 9ede713.
…of dataclass Co-authored-by: 0xkarmacoma <[email protected]>
…x test file Co-authored-by: 0xkarmacoma <[email protected]>
| group=debugging, | ||
| ) | ||
|
|
||
| dump_smt_directory: str = arg( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bring back the str | None annotation since the default is None. Or make the default "", your choice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use str type annotation with global_default="" instead of None to maintain consistency and resolve argparse compatibility issues. Changes in 9e13542.
tests/test_utils.py
Outdated
|
|
||
|
|
||
| def test_dirname_with_temporary_directory(): | ||
| """Test dirname function with TemporaryDirectory""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove low-information comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the low-information docstring. Changes in a10b253.
tests/test_utils.py
Outdated
|
|
||
|
|
||
| def test_dirname_with_path(): | ||
| """Test dirname function with Path""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove low-information comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the low-information docstring. Changes in a10b253.
Co-authored-by: 0xkarmacoma <[email protected]>
Co-authored-by: 0xkarmacoma <[email protected]>
This PR adds a new
--dump-smt-directoryflag that allows users to specify a custom directory for dumping SMT files, addressing the limitation where SMT files were always saved to/tmp/with no user control.Changes
New CLI Flag
Key Features
./my-smt-files/testFunction/,./my-smt-files/MyContract-constructor/)--dump-smt-directoryis not specified, behavior remains unchanged (files go to temporary directories)Implementation Details
dump_smt_directory: Union[str, None]field to theConfigclassExample Usage
Benefits
/tmpFixes #490.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
http://168.63.129.16:80/machine//usr/bin/python3 -u bin/WALinuxAgent-2.13.1.1-py3.9.egg -collect-logs(http block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.