Skip to content
Closed
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
14 changes: 10 additions & 4 deletions bounties/issue-2310/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
__version__ = '1.0.0'
__author__ = 'RustChain Bounty Program'

from crt_pattern_generator import CRTPatternGenerator
from crt_capture import CRTCapture, CaptureConfig, CaptureMethod
from crt_analyzer import CRTAnalyzer, CRTFingerprint
from crt_attestation_submitter import CRTAttestationSubmitter, CRTAttestation
if __package__:
from .crt_pattern_generator import CRTPatternGenerator
from .crt_capture import CRTCapture, CaptureConfig, CaptureMethod
from .crt_analyzer import CRTAnalyzer, CRTFingerprint
from .crt_attestation_submitter import CRTAttestationSubmitter, CRTAttestation
else:
from crt_pattern_generator import CRTPatternGenerator
from crt_capture import CRTCapture, CaptureConfig, CaptureMethod
from crt_analyzer import CRTAnalyzer, CRTFingerprint
from crt_attestation_submitter import CRTAttestationSubmitter, CRTAttestation

__all__ = [
'CRTPatternGenerator',
Expand Down
20 changes: 10 additions & 10 deletions bounties/issue-2310/validate_bounty_2310.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ def print_header(text):
print(f"{BLUE}{'=' * 60}{RESET}\n")

def print_success(text):
print(f"{GREEN} {text}{RESET}")
print(f"{GREEN}[OK] {text}{RESET}")

def print_error(text):
print(f"{RED} {text}{RESET}")
print(f"{RED}[FAIL] {text}{RESET}")

def print_info(text):
print(f"{YELLOW}ℹ️ {text}{RESET}")
print(f"{YELLOW}[INFO] {text}{RESET}")

def check_file_exists(filepath, description):
"""Check if a file exists"""
Expand All @@ -48,7 +48,7 @@ def check_file_content(filepath, patterns, description):
print_error(f"{description} missing: {filepath}")
return False

with open(filepath, 'r') as f:
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()

all_found = True
Expand All @@ -66,7 +66,7 @@ def count_lines(filepath):
"""Count lines in a file"""
if not os.path.exists(filepath):
return 0
with open(filepath, 'r') as f:
with open(filepath, 'r', encoding='utf-8') as f:
return sum(1 for _ in f)

def get_file_hash(filepath):
Expand Down Expand Up @@ -242,7 +242,7 @@ def validate_tests():
'pytest'
]

with open(test_file, 'r') as f:
with open(test_file, 'r', encoding='utf-8') as f:
content = f.read()

all_valid = True
Expand Down Expand Up @@ -271,7 +271,7 @@ def validate_evidence():
print_error("Evidence file missing: proof.json")
return False

with open(proof_file, 'r') as f:
with open(proof_file, 'r', encoding='utf-8') as f:
proof = json.load(f)

required_fields = [
Expand Down Expand Up @@ -306,7 +306,7 @@ def validate_requirements():
base_dir = Path(__file__).parent / 'evidence'
proof_file = base_dir / 'proof.json'

with open(proof_file, 'r') as f:
with open(proof_file, 'r', encoding='utf-8') as f:
proof = json.load(f)

req_verify = proof.get('requirements_verification', {})
Expand Down Expand Up @@ -404,10 +404,10 @@ def main():
print(f" Total source lines: {total_lines}")

if passed == total:
print(f"\n{GREEN} VALIDATION PASSED - Implementation is complete!{RESET}\n")
print(f"\n{GREEN}[OK] VALIDATION PASSED - Implementation is complete!{RESET}\n")
return 0
else:
print(f"\n{RED} VALIDATION FAILED - {total - passed} checks failed{RESET}\n")
print(f"\n{RED}[FAIL] VALIDATION FAILED - {total - passed} checks failed{RESET}\n")
return 1

if __name__ == '__main__':
Expand Down
43 changes: 43 additions & 0 deletions tests/test_issue2310_package_validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# SPDX-License-Identifier: Apache-2.0
import os
import subprocess
import sys
from pathlib import Path

import pytest


ROOT = Path(__file__).resolve().parents[1]
ISSUE_DIR = ROOT / "bounties" / "issue-2310"


def test_crt_attestation_package_imports_from_parent_path():
pytest.importorskip("numpy")

code = (
"import sys; "
f"sys.path.insert(0, {str(ISSUE_DIR)!r}); "
"import src; "
"assert src.CRTAttestationSubmitter; "
"assert src.CRTPatternGenerator"
)

subprocess.run([sys.executable, "-c", code], check=True, cwd=ROOT)


def test_issue2310_validator_does_not_crash_under_cp1252_stdout():
env = os.environ.copy()
env["PYTHONIOENCODING"] = "cp1252"

result = subprocess.run(
[sys.executable, "validate_bounty_2310.py"],
cwd=ISSUE_DIR,
env=env,
capture_output=True,
text=True,
timeout=30,
)

combined_output = result.stdout + result.stderr
assert "UnicodeEncodeError" not in combined_output
assert "Final Results" in combined_output
Loading