feat: print filename in inspect_file output

Add the resolved path at the top of every human report (File: line) and
include path in JSON output for all kinds, so batch inspection via find
can attribute hits to a file. Closes #31.
This commit is contained in:
Guillaume Meyer (The Opinionated Man)
2026-08-14 07:08:26 -07:00
parent 28eca2d91f
commit 33d430cf01
2 changed files with 46 additions and 6 deletions
+10 -6
View File
@@ -72,6 +72,7 @@ def main() -> int:
return 2
kind = args.force_type if args.force_type != "auto" else classify(args.path)
file_label = str(args.path.resolve())
if kind == "text":
text = read_text_input(
@@ -81,18 +82,20 @@ def main() -> int:
)
report = inspect_text(text, aggressive=args.aggressive)
if args.json:
emit_json({"kind": "text", **report.to_dict()})
emit_json({"kind": "text", "path": file_label, **report.to_dict()})
else:
print(f"Kind: text")
print(f"File: {file_label}")
print("Kind: text")
print(human_report(report))
return 0 if report.suspicious_total == 0 else 1
if kind == "image":
report = inspect_image(args.path)
if args.json:
emit_json({"kind": "image", **report.to_dict()})
emit_json({"kind": "image", "path": file_label, **report.to_dict()})
else:
print(f"Kind: image")
print(f"File: {file_label}")
print("Kind: image")
print(f"Path: {report.path}")
print(f"Format: {report.format}")
print(f"C2PA: {report.has_c2pa}")
@@ -103,9 +106,10 @@ def main() -> int:
report = inspect_container(args.path)
if args.json:
emit_json({"kind": "container", **report.to_dict()})
emit_json({"kind": "container", "path": file_label, **report.to_dict()})
else:
print(f"Kind: container")
print(f"File: {file_label}")
print("Kind: container")
print(f"Path: {report.path}")
print(f"Format: {report.format}")
print(f"C2PA: {report.has_c2pa}")
+36
View File
@@ -0,0 +1,36 @@
"""CLI inspect_file must name the file being inspected (issue #31)."""
from __future__ import annotations
import json
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SCRIPTS = ROOT / "skills" / "remove-ai-marks" / "scripts"
INSPECT = SCRIPTS / "inspect_file.py"
FIXTURE = ROOT / "tests" / "fixtures" / "sample_watermarked.txt"
def _run(*args: str) -> subprocess.CompletedProcess[str]:
return subprocess.run(
[sys.executable, str(INSPECT), *args],
check=False,
capture_output=True,
text=True,
)
def test_human_report_starts_with_file_line():
result = _run(str(FIXTURE))
first = result.stdout.splitlines()[0]
assert first == f"File: {FIXTURE.resolve()}"
assert "Kind: text" in result.stdout
def test_json_report_includes_path():
result = _run("--json", str(FIXTURE))
payload = json.loads(result.stdout)
assert payload["path"] == str(FIXTURE.resolve())
assert payload["kind"] == "text"