Skip to content

Commit b46edcb

Browse files
author
hacky1997
committed
feat: v0.3.1 — audit command, verify command, pre-commit hook support
1 parent 88b86d1 commit b46edcb

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

src/snapfix/audit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ class Finding:
126126
match: str
127127

128128
def __str__(self) -> str:
129-
# Redact the match in output — don't print real PII to terminal
130129
redacted = self.match[:4] + "***" if len(self.match) > 4 else "***"
130+
safe_line = self.line.replace(self.match, redacted) # ← scrub match from line
131131
return (
132132
f" {self.file.name}:{self.line_number} "
133133
f"[{self.pattern}] {redacted} "
134-
f"— {self.line.strip()[:80]}"
134+
f"— {safe_line.strip()[:80]}"
135135
)
136136

137137

src/snapfix/capture.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ def _record(
7474
serializer = SnapfixSerializer(max_depth=effective_depth, max_size_bytes=effective_size)
7575
scrubber = SnapfixScrubber(scrub_fields)
7676
codegen = SnapfixCodegen()
77-
store = SnapfixStore(cfg.output_dir)
7877

7978
try:
79+
store = SnapfixStore(cfg.output_dir) # ← now inside try, error is caught
8080
serialized = serializer.serialize(obj)
8181
scrubbed, scrubbed_keys = scrubber.scrub(serialized)
8282
source = codegen.generate(

tests/test_integration.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,26 @@
2121
# Stub pytest.fixture so the generated file can be imported in tests
2222
_fake_pytest = types.ModuleType("pytest")
2323
_fake_pytest.fixture = lambda f: f # type: ignore
24-
sys.modules.setdefault("pytest", _fake_pytest)
24+
# sys.modules.setdefault("pytest", _fake_pytest)
2525

2626

2727
def _reload_snapfix():
2828
for m in list(sys.modules):
2929
if "snapfix" in m:
3030
del sys.modules[m]
3131

32-
3332
def _import_fixture_file(path: pathlib.Path):
34-
spec = importlib.util.spec_from_file_location("_fx_tmp", path)
35-
mod = importlib.util.module_from_spec(spec) # type: ignore
36-
sys.modules["_fx_tmp"] = mod
37-
spec.loader.exec_module(mod) # type: ignore
38-
return mod
33+
real_pytest = sys.modules.get("pytest")
34+
sys.modules["pytest"] = _fake_pytest # ← force replace
35+
try:
36+
spec = importlib.util.spec_from_file_location("_fx_tmp", path)
37+
mod = importlib.util.module_from_spec(spec)
38+
sys.modules["_fx_tmp"] = mod
39+
spec.loader.exec_module(mod)
40+
return mod
41+
finally:
42+
if real_pytest is not None:
43+
sys.modules["pytest"] = real_pytest
3944

4045

4146
def test_full_pipeline_simple_dict(tmp_path):

0 commit comments

Comments
 (0)