Skip to content

test: assert build-db PYTHONPATH uses package root#47

Merged
simongonzalezdc merged 5 commits into
mainfrom
fix/pythonpath-test-assertion
May 27, 2026
Merged

test: assert build-db PYTHONPATH uses package root#47
simongonzalezdc merged 5 commits into
mainfrom
fix/pythonpath-test-assertion

Conversation

@simongonzalezdc
Copy link
Copy Markdown
Member

@simongonzalezdc simongonzalezdc commented May 27, 2026

Problem

Follow-up from focused review: the previous PR fixed CI by making the PYTHONPATH assertion repo-name agnostic, but it only checked that the first PYTHONPATH entry was absolute. That would still allow regressions where build-db sets PYTHONPATH to an unrelated absolute path like /tmp.

Fix

Assert that the first PYTHONPATH entry exactly matches the package root derived from archaeology.cli.file, while still using os.pathsep for cross-platform path splitting.

Validation

  • python3 -m pytest tests/test_cli_coverage.py::test_build_db_propagates_pythonpath -q
  • python3 -m pytest tests/ -q

93 tests passed locally.


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag @codesmith with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes

    • CLI now constructs PYTHONPATH in a cross-platform-safe way, fixing incorrect module invocation on non-Unix systems.
  • Tests

    • Improved reliability of PYTHONPATH validation tests by implementing stricter, repository-independent verification.

Review Change Stack

The test was asserting that PYTHONPATH contains "archaeology" or
"DEV-ARCH" — hardcoded local directory names. In CI the repo is cloned
as "devarch-framework", so neither substring matched.

Replace with an assertion that PYTHONPATH is an absolute path (which is
the actual invariant the CLI code guarantees via Path(__file__).parent.parent).

Fixes #39
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 27, 2026

📝 Walkthrough

Walkthrough

CLI commands that spawn internal Python modules now build PYTHONPATH using os.pathsep for cross-platform correctness, and the test test_build_db_propagates_pythonpath imports archaeology.cli to derive and assert the expected PYTHONPATH root from cli.file.

Changes

CLI PYTHONPATH fixes and test update

Layer / File(s) Summary
CLI PYTHONPATH assembly uses os.pathsep
archaeology/cli.py
Replaces hard-coded ':' with os.pathsep when appending PYTHONPATH for subprocess invocations in the demo, build-db, cascade, and sync command flows.
Test derives expected PYTHONPATH root from cli
tests/test_cli_coverage.py
Adds import archaeology.cli as cli and tightens test_build_db_propagates_pythonpath to assert the first PYTHONPATH component equals Path(cli.__file__).parent.parent.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related issues

Possibly related PRs

  • KyaniteLabs/devarch-framework#44: Also updates the test to remove repo-name-specific PYTHONPATH substring checks and validate the computed absolute PYTHONPATH value.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description clearly explains the problem, fix, and validation but does not follow the required template with the Empower Orchestrator checklist. Add the Empower Orchestrator checklist section from the template to document task analysis and scope verification.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically summarizes the main change: adding a stricter assertion to verify that build-db sets PYTHONPATH to the package root.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/pythonpath-test-assertion

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/test_cli_coverage.py`:
- Around line 401-405: The CLI builds PYTHONPATH by concatenating _pkg_root with
a hardcoded ":" which breaks on Windows; in the places where _env["PYTHONPATH"]
is set (assignments referencing _pkg_root and _env.get("PYTHONPATH") in the CLI
logic—the lines that currently use ":"), replace the literal ":" with os.pathsep
and handle empty existing PYTHONPATH safely (e.g. set _env["PYTHONPATH"] =
_pkg_root + (os.pathsep + _env["PYTHONPATH"] if _env.get("PYTHONPATH") else "")
), ensuring you import os where needed and update all occurrences (the
assignments that construct PYTHONPATH using _pkg_root and _env).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ead38582-c56d-43ea-bb92-8b27256e1b6a

📥 Commits

Reviewing files that changed from the base of the PR and between f98035e and 0ae3d0c.

📒 Files selected for processing (1)
  • tests/test_cli_coverage.py

Comment thread tests/test_cli_coverage.py
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
archaeology/cli.py (1)

86-86: ⚡ Quick win

Extract PYTHONPATH assembly into a helper to avoid drift.

The same PYTHONPATH prepend logic is repeated in four places; a small helper would keep behavior consistent and reduce future mismatch risk.

Proposed refactor
+def _with_pkg_root_pythonpath(env: dict[str, str]) -> dict[str, str]:
+    out = env.copy()
+    pkg_root = str(Path(__file__).parent.parent)
+    existing = out.get("PYTHONPATH")
+    out["PYTHONPATH"] = pkg_root if not existing else f"{pkg_root}{os.pathsep}{existing}"
+    return out
+
@@
-        _env = os.environ.copy()
-        _pkg_root = str(Path(__file__).parent.parent)
-        _env["PYTHONPATH"] = _pkg_root + ((os.pathsep + _env["PYTHONPATH"]) if _env.get("PYTHONPATH") else "")
+        _env = _with_pkg_root_pythonpath(os.environ)

Also applies to: 146-146, 661-661, 996-996

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@archaeology/cli.py` at line 86, Extract the repeated PYTHONPATH assembly into
a single helper (e.g., prepend_pkg_root_to_pythonpath(env, pkg_root)) that takes
an env dict and a pkg_root string and sets env["PYTHONPATH"] = pkg_root +
(os.pathsep + env["PYTHONPATH"] if env.get("PYTHONPATH") else ""); replace the
four occurrences that currently inline this logic with calls to that helper so
behavior is identical and centralized (use the same helper name where functions
like the code around _env and _pkg_root currently run).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@archaeology/cli.py`:
- Line 86: Extract the repeated PYTHONPATH assembly into a single helper (e.g.,
prepend_pkg_root_to_pythonpath(env, pkg_root)) that takes an env dict and a
pkg_root string and sets env["PYTHONPATH"] = pkg_root + (os.pathsep +
env["PYTHONPATH"] if env.get("PYTHONPATH") else ""); replace the four
occurrences that currently inline this logic with calls to that helper so
behavior is identical and centralized (use the same helper name where functions
like the code around _env and _pkg_root currently run).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 96608072-21fd-4008-9635-233f25b81196

📥 Commits

Reviewing files that changed from the base of the PR and between 0ae3d0c and d211403.

📒 Files selected for processing (1)
  • archaeology/cli.py

@simongonzalezdc simongonzalezdc merged commit 48474ce into main May 27, 2026
12 checks passed
@simongonzalezdc simongonzalezdc deleted the fix/pythonpath-test-assertion branch May 27, 2026 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant