Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions libs/openant-core/context/application_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def gather_context_sources(repo_path: Path) -> dict[str, str]:
filepath = repo_path / filename
if filepath.exists():
try:
content = filepath.read_text(errors="ignore")
content = filepath.read_text(encoding="utf-8", errors="ignore")
# Limit size to avoid token overflow
if len(content) > 10000:
content = content[:10000] + "\n\n[... truncated ...]"
Expand Down Expand Up @@ -289,7 +289,7 @@ def detect_entry_points(repo_path: Path) -> str:
continue

try:
content = py_file.read_text(errors="ignore")
content = py_file.read_text(encoding="utf-8", errors="ignore")
rel_path = py_file.relative_to(repo_path)

for category, patterns in ENTRY_POINT_PATTERNS.items():
Expand All @@ -308,7 +308,7 @@ def detect_entry_points(repo_path: Path) -> str:
continue

try:
content = js_file.read_text(errors="ignore")
content = js_file.read_text(encoding="utf-8", errors="ignore")
rel_path = js_file.relative_to(repo_path)

if re.search(r"express\(\)|require\(['\"]express['\"]\)", content):
Expand Down Expand Up @@ -340,7 +340,7 @@ def check_manual_override(repo_path: Path) -> ApplicationContext | None:
continue

try:
content = filepath.read_text()
content = filepath.read_text(encoding="utf-8")

if filename.endswith('.json'):
# Direct JSON format
Expand Down Expand Up @@ -545,7 +545,7 @@ def save_context(context: ApplicationContext, output_path: Path) -> None:
output_path = Path(output_path)
output_path.parent.mkdir(parents=True, exist_ok=True)

with open(output_path, 'w') as f:
with open(output_path, 'w', encoding="utf-8") as f:
json.dump(asdict(context), f, indent=2)

print(f"Context saved to {output_path}", file=sys.stderr)
Expand All @@ -560,7 +560,7 @@ def load_context(input_path: Path) -> ApplicationContext:
Returns:
ApplicationContext loaded from file.
"""
with open(input_path) as f:
with open(input_path, encoding="utf-8") as f:
data = json.load(f)

# Mark as manual to skip validation (already validated when saved)
Expand Down
4 changes: 2 additions & 2 deletions libs/openant-core/core/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def run_analysis(

# Load dataset
print(f"[Analyze] Loading dataset: {dataset_path}", file=sys.stderr)
with open(dataset_path) as f:
with open(dataset_path, encoding="utf-8") as f:
dataset = json.load(f)

units = dataset.get("units", [])
Expand Down Expand Up @@ -513,7 +513,7 @@ def _summary_callback(finding, usage=None):
"code_by_route": code_by_route,
}

with open(results_path, "w") as f:
with open(results_path, "w", encoding="utf-8") as f:
json.dump(experiment_result, f, indent=2)

print(f"\n[Analyze] Results written to {results_path}", file=sys.stderr)
Expand Down
10 changes: 5 additions & 5 deletions libs/openant-core/core/checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def load(self) -> dict[str, dict]:
continue
filepath = os.path.join(self.dir, filename)
try:
with open(filepath, "r") as f:
with open(filepath, "r", encoding="utf-8") as f:
data = json.load(f)
unit_id = data.get("id")
if unit_id:
Expand Down Expand Up @@ -130,7 +130,7 @@ def save(self, unit_id: str, data: dict):
filename = self._safe_filename(unit_id) + ".json"
filepath = os.path.join(self.dir, filename)
data["id"] = unit_id # ensure id is always present
with open(filepath, "w") as f:
with open(filepath, "w", encoding="utf-8") as f:
json.dump(data, f, indent=2)

def write_summary(
Expand Down Expand Up @@ -168,7 +168,7 @@ def write_summary(
}
if usage is not None:
data["usage"] = usage
with open(filepath, "w") as f:
with open(filepath, "w", encoding="utf-8") as f:
json.dump(data, f, indent=2)

@staticmethod
Expand All @@ -182,7 +182,7 @@ def read_summary(checkpoint_dir: str) -> dict | None:
if not os.path.isfile(filepath):
return None
try:
with open(filepath, "r") as f:
with open(filepath, "r", encoding="utf-8") as f:
return json.load(f)
except (json.JSONDecodeError, OSError):
return None
Expand Down Expand Up @@ -241,7 +241,7 @@ def status(checkpoint_dir: str) -> dict:
continue
filepath = os.path.join(checkpoint_dir, filename)
try:
with open(filepath, "r") as f:
with open(filepath, "r", encoding="utf-8") as f:
data = json.load(f)
except (json.JSONDecodeError, OSError):
errors += 1
Expand Down
4 changes: 2 additions & 2 deletions libs/openant-core/core/dynamic_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def run_tests(
os.makedirs(output_dir, exist_ok=True)

# Check how many findings to test
with open(pipeline_output_path) as f:
with open(pipeline_output_path, encoding="utf-8") as f:
pipeline_data = json.load(f)

findings = pipeline_data.get("findings", [])
Expand All @@ -65,7 +65,7 @@ def run_tests(

if not testable:
results_path = os.path.join(output_dir, "dynamic_test_results.json")
with open(results_path, "w") as f:
with open(results_path, "w", encoding="utf-8") as f:
json.dump({"findings_tested": 0, "results": []}, f, indent=2)

return DynamicTestStepResult(
Expand Down
4 changes: 2 additions & 2 deletions libs/openant-core/core/enhancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def enhance_dataset(

# Load dataset
print(f"[Enhance] Loading dataset: {dataset_path}", file=sys.stderr)
with open(dataset_path) as f:
with open(dataset_path, encoding="utf-8") as f:
dataset = json.load(f)

units = dataset.get("units", [])
Expand Down Expand Up @@ -138,7 +138,7 @@ def _on_restored(count: int):

# Write enhanced dataset
os.makedirs(os.path.dirname(os.path.abspath(output_path)), exist_ok=True)
with open(output_path, "w") as f:
with open(output_path, "w", encoding="utf-8") as f:
json.dump(enhanced, f, indent=2)

print(f"[Enhance] Enhanced dataset: {output_path}", file=sys.stderr)
Expand Down
24 changes: 12 additions & 12 deletions libs/openant-core/core/parser_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def _maybe_apply_diff_filter(
)
return

with open(result.dataset_path, "r") as f:
with open(result.dataset_path, "r", encoding="utf-8") as f:
dataset = json.load(f)

# Dataset may be a dict with "units" or a raw list.
Expand All @@ -172,13 +172,13 @@ def _maybe_apply_diff_filter(

stats = apply_diff_filter(units, manifest)

with open(result.dataset_path, "w") as f:
with open(result.dataset_path, "w", encoding="utf-8") as f:
json.dump(dataset, f, indent=2)

# Expose stats on the ParseResult via a side-channel file; the parse
# step_context reads this when assembling parse.report.json.
diff_report_path = os.path.join(output_dir, "diff_filter.report.json")
with open(diff_report_path, "w") as f:
with open(diff_report_path, "w", encoding="utf-8") as f:
json.dump(stats.to_dict(), f, indent=2)

print(
Expand Down Expand Up @@ -245,7 +245,7 @@ def _load_module(name, filename):

print(f"\n[Reachability Filter] Filtering to {processing_level} units...", file=sys.stderr)

with open(call_graph_path, "r") as f:
with open(call_graph_path, "r", encoding="utf-8") as f:
call_graph_data = json.load(f)

functions = call_graph_data.get("functions", {})
Expand Down Expand Up @@ -352,10 +352,10 @@ def _parse_python(repo_path: str, output_dir: str, processing_level: str, skip_t
dataset = _apply_reachability_filter(dataset, output_dir, processing_level)

# Write outputs
with open(dataset_path, "w") as f:
with open(dataset_path, "w", encoding="utf-8") as f:
json.dump(dataset, f, indent=2)

with open(analyzer_output_path, "w") as f:
with open(analyzer_output_path, "w", encoding="utf-8") as f:
json.dump(analyzer_output, f, indent=2)

units_count = len(dataset.get("units", []))
Expand Down Expand Up @@ -413,7 +413,7 @@ def _parse_javascript(repo_path: str, output_dir: str, processing_level: str, sk
# Count units
units_count = 0
if os.path.exists(dataset_path):
with open(dataset_path) as f:
with open(dataset_path, encoding="utf-8") as f:
data = json.load(f)
units_count = len(data.get("units", []))

Expand Down Expand Up @@ -470,7 +470,7 @@ def _parse_go(repo_path: str, output_dir: str, processing_level: str, skip_tests
# Count units
units_count = 0
if os.path.exists(dataset_path):
with open(dataset_path) as f:
with open(dataset_path, encoding="utf-8") as f:
data = json.load(f)
units_count = len(data.get("units", []))

Expand Down Expand Up @@ -530,7 +530,7 @@ def _parse_c(repo_path: str, output_dir: str, processing_level: str, skip_tests:
# Count units
units_count = 0
if os.path.exists(dataset_path):
with open(dataset_path) as f:
with open(dataset_path, encoding="utf-8") as f:
data = json.load(f)
units_count = len(data.get("units", []))

Expand Down Expand Up @@ -590,7 +590,7 @@ def _parse_ruby(repo_path: str, output_dir: str, processing_level: str, skip_tes
# Count units
units_count = 0
if os.path.exists(dataset_path):
with open(dataset_path) as f:
with open(dataset_path, encoding="utf-8") as f:
data = json.load(f)
units_count = len(data.get("units", []))

Expand Down Expand Up @@ -650,7 +650,7 @@ def _parse_php(repo_path: str, output_dir: str, processing_level: str, skip_test
# Count units
units_count = 0
if os.path.exists(dataset_path):
with open(dataset_path) as f:
with open(dataset_path, encoding="utf-8") as f:
data = json.load(f)
units_count = len(data.get("units", []))

Expand Down Expand Up @@ -710,7 +710,7 @@ def _parse_zig(repo_path: str, output_dir: str, processing_level: str, skip_test
# Count units
units_count = 0
if os.path.exists(dataset_path):
with open(dataset_path) as f:
with open(dataset_path, encoding="utf-8") as f:
data = json.load(f)
units_count = len(data.get("units", []))

Expand Down
18 changes: 9 additions & 9 deletions libs/openant-core/core/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _load_diff_metadata(scan_dir: str) -> dict | None:
if not os.path.exists(manifest_path):
return None
try:
with open(manifest_path) as f:
with open(manifest_path, encoding="utf-8") as f:
manifest = json.load(f)
except (json.JSONDecodeError, OSError):
return None
Expand All @@ -50,7 +50,7 @@ def _load_diff_metadata(scan_dir: str) -> dict | None:
filter_report = os.path.join(scan_dir, "diff_filter.report.json")
if os.path.exists(filter_report):
try:
with open(filter_report) as f:
with open(filter_report, encoding="utf-8") as f:
stats = json.load(f)
out["units_in_diff"] = stats.get("selected")
out["units_total_parsed"] = stats.get("total")
Expand Down Expand Up @@ -129,7 +129,7 @@ def _dedup_caller_callee(
return confirmed

try:
with open(call_graph_path) as f:
with open(call_graph_path, encoding="utf-8") as f:
cg_data = json.load(f)
except (json.JSONDecodeError, OSError):
return confirmed
Expand Down Expand Up @@ -212,7 +212,7 @@ def build_pipeline_output(
"""
print(f"[Report] Building pipeline_output.json...", file=sys.stderr)

with open(results_path) as f:
with open(results_path, encoding="utf-8") as f:
experiment = json.load(f)

all_results = experiment.get("results", [])
Expand Down Expand Up @@ -371,7 +371,7 @@ def build_pipeline_output(
print(_banner, file=sys.stderr)

os.makedirs(os.path.dirname(os.path.abspath(output_path)), exist_ok=True)
with open(output_path, "w") as f:
with open(output_path, "w", encoding="utf-8") as f:
json.dump(pipeline_output, f, indent=2, ensure_ascii=False)

print(f" pipeline_output.json: {len(findings_data)} findings", file=sys.stderr)
Expand Down Expand Up @@ -469,7 +469,7 @@ def generate_summary_report(

print("[Report] Generating summary report (LLM)...", file=sys.stderr)

with open(results_path) as f:
with open(results_path, encoding="utf-8") as f:
pipeline_data = json.load(f)

# Merge dynamic test results if available
Expand All @@ -483,7 +483,7 @@ def generate_summary_report(
report_text, usage = _generate_summary(pipeline_data)

os.makedirs(os.path.dirname(os.path.abspath(output_path)), exist_ok=True)
with open(output_path, "w") as f:
with open(output_path, "w", encoding="utf-8") as f:
f.write(report_text)

print(f" Summary report: {output_path}", file=sys.stderr)
Expand Down Expand Up @@ -517,7 +517,7 @@ def generate_disclosure_docs(

print("[Report] Generating disclosure documents (LLM)...", file=sys.stderr)

with open(results_path) as f:
with open(results_path, encoding="utf-8") as f:
pipeline_data = json.load(f)

# Merge dynamic test results if available
Expand Down Expand Up @@ -552,7 +552,7 @@ def _one(args):
safe_name = finding["short_name"].replace(" ", "_").upper()
filename = f"DISCLOSURE_{i:02d}_{safe_name}.md"
filepath = os.path.join(output_dir, filename)
with open(filepath, "w") as f:
with open(filepath, "w", encoding="utf-8") as f:
f.write(disclosure_text)
return finding["short_name"], filepath, usage

Expand Down
6 changes: 3 additions & 3 deletions libs/openant-core/core/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def _step_label(name: str) -> str:
_diff_report = os.path.join(output_dir, "diff_filter.report.json")
if os.path.exists(_diff_report):
try:
with open(_diff_report) as _f:
with open(_diff_report, encoding="utf-8") as _f:
ctx.summary["diff_stats"] = json.load(_f)
except (json.JSONDecodeError, OSError):
pass
Expand Down Expand Up @@ -542,7 +542,7 @@ def _load_step_report(output_dir: str, step: str) -> dict:
"""Load a step report JSON from disk. Returns empty dict on failure."""
path = os.path.join(output_dir, f"{step}.report.json")
try:
with open(path) as f:
with open(path, encoding="utf-8") as f:
return json.load(f)
except Exception:
return {"step": step, "status": "unknown"}
Expand All @@ -551,7 +551,7 @@ def _load_step_report(output_dir: str, step: str) -> dict:
def _read_app_type(app_context_path: str) -> str | None:
"""Read application_type from an app context JSON file."""
try:
with open(app_context_path) as f:
with open(app_context_path, encoding="utf-8") as f:
data = json.load(f)
return data.get("application_type")
except Exception:
Expand Down
2 changes: 1 addition & 1 deletion libs/openant-core/core/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,6 @@ def write(self, output_dir: str) -> str:
"""Write ``{step}.report.json`` to *output_dir*. Returns the path."""
os.makedirs(output_dir, exist_ok=True)
path = os.path.join(output_dir, f"{self.step}.report.json")
with open(path, "w") as f:
with open(path, "w", encoding="utf-8") as f:
json.dump(self.to_dict(), f, indent=2)
return path
4 changes: 2 additions & 2 deletions libs/openant-core/core/verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def run_verification(

# Load Stage 1 results
print(f"[Verify] Loading results: {results_path}", file=sys.stderr)
with open(results_path) as f:
with open(results_path, encoding="utf-8") as f:
experiment = json.load(f)

all_results = experiment.get("results", [])
Expand Down Expand Up @@ -268,7 +268,7 @@ def _write_verified_results(

output["metrics"] = {"total": len(merged_results), **counts}

with open(path, "w") as f:
with open(path, "w", encoding="utf-8") as f:
json.dump(output, f, indent=2, ensure_ascii=False)


Expand Down
Loading
Loading