Fix PoA validator direct-run imports#6785
Conversation
c2fc34a to
0114092
Compare
|
CI note for reviewers:
Local validation also passed for the actual bug path: printf '{}\n' >/tmp/poa-genesis.json
python3 rustchain-poa/cli/run_validator.py /tmp/poa-genesis.json
# returned validation JSON containing "validated" |
zqleslie
left a comment
There was a problem hiding this comment.
Code Review Bounty Claim — RustChain PR #6785
Bounty: #73 Code Review Bounty Program
Reviewer: zqleslie
RTC wallet: XKO212dF8324b9b61F294D26A6Dc68e3f81e4BE451D
Reviewed PR
- PR: #6785
- Review state:
APPROVED
Review performed
Reviewed the PoA validator direct-run import fix:
-
rustchain-poa/api/poa_api.py—POA_ROOT = Path(__file__).resolve().parents[1]correctly resolves to therustchain-poapackage root.sys.path.insert(0, str(POA_ROOT))ensuresfrom validator.validate_genesis import validate_genesisworks when runningpython rustchain-poa/api/poa_api.pydirectly. Theinsert(0, ...)is better thanappend()because it takes precedence over any conflicting package on the path. -
rustchain-poa/cli/run_validator.py— Samesys.pathfix applied before thevalidate_genesisimport. Clean, same pattern. -
New test
tests/test_poa_validator_entrypoints.py— Usessubprocess.run()to invoke the CLI directly from the repo root, confirming it works withoutPYTHONPATH. Asserts return code 0 and JSON withvalidatedkey. This is exactly the regression test needed. -
Diff size — +40/-4 across 3 files. All changes are import-path fixes and one test. No runtime logic changed.
-
Scope — The fix only affects direct-running (
python file.py); imports from package context (e.g.,pytest, Flask app) are unchanged since the path is already correct when Python knows the package root.
No blocking issues found. Safe to merge.
This is a claim only. No payout asserted here.
MolhamHamwi
left a comment
There was a problem hiding this comment.
Reviewed current head 01140927d7a4728917e9b665f94b6bdee8849b03 for the PoA validator direct-run import fix.
Specific observations:
- The
Path(__file__).resolve().parents[1]insertion targets therustchain-poapackage root in both entrypoints, so direct execution ofrustchain-poa/cli/run_validator.pyand import ofvalidator.validate_genesisnow work without requiring callers to set an externalPYTHONPATH. - The guard avoids duplicate
sys.pathentries and preserves normal import behavior once the package root is present; the API entrypoint keeps the Flask imports separate from the local validator import, which makes the dependency boundary clearer. - The regression test exercises the real CLI in a subprocess from the repository root, which is the right failure mode for this bug because an in-process import test would not catch missing direct-run path setup.
Validation performed locally:
python3 rustchain-poa/cli/run_validator.py /tmp/poa-genesis-empty.json-> returned JSON with"validated": truepython3 -m py_compile rustchain-poa/cli/run_validator.py rustchain-poa/api/poa_api.py tests/test_poa_validator_entrypoints.py
No blocking issues found. I received RTC compensation for this review.
jaxint
left a comment
There was a problem hiding this comment.
Great contribution! 🔍 Reviewed and looks solid.
jaxint
left a comment
There was a problem hiding this comment.
LGTM! Thanks for contributing to RustChain. Approved.
Code Review for PR #6785Files reviewed: 3 files (+40/-4) Files examined:
General observations:
Assessment:
Recommendation: Looks good to merge. Wallet for bounty: jesusmp Claiming code review bounty. Review completed on all 3 changed files. |
jaxint
left a comment
There was a problem hiding this comment.
Well done! This contribution adds real value to the project.
✅ Reviewed → merging — direct-run import fix with a real testThis is a clean one: |
Fixes a PoA validator entrypoint import bug where running the CLI/API files directly cannot resolve
validator.validate_genesisunless callers manually setPYTHONPATH=rustchain-poa.Before:
python3 rustchain-poa/cli/run_validator.py /tmp/genesis.json # ModuleNotFoundError: No module named 'validator'What changed:
rustchain-poapackage root tosys.pathat the CLI/API entrypoints before importingvalidator.validate_genesistests/suite that runs the CLI without externalPYTHONPATHValidation:
python3 rustchain-poa/cli/run_validator.py /tmp/poa-genesis.json # returns JSON containing "validated"Local note:
python3 -m pytest tests/test_poa_validator_entrypoints.py -qrequires the repo's CI dependencies (for example Flask viatests/conftest.py); direct CLI validation above passed locally.Bug bounty context: this is a small direct-runner reliability bug for the RustChain PoA validator tooling.