Skip to content

refactor: fold duplicated _first_value into shared ssh_config - #787

Open
mrbobbytables wants to merge 2 commits into
projectbluefin:mainfrom
mrbobbytables:fix/dedup-first-value-763
Open

refactor: fold duplicated _first_value into shared ssh_config#787
mrbobbytables wants to merge 2 commits into
projectbluefin:mainfrom
mrbobbytables:fix/dedup-first-value-763

Conversation

@mrbobbytables

Copy link
Copy Markdown
Contributor

Refactor

Context: #763 flags that every behave suite hand-wires its own environment.py with copy-pasted cross-cutting concerns. One concretely named instance: _first_value(*values) is defined identically three times — tests/shared/ssh_config.py:32, tests/common/features/environment.py:23, and tests/kde-smoke/features/environment.py:35.

What this does:

  • Removes the two duplicate _first_value definitions from tests/common and tests/kde-smoke; both now import the existing implementation from tests.shared.ssh_config.
  • No behaviour change — all three implementations were byte-for-byte identical.
  • Extends tests/unit/test_suite_environment_contract.py (the ast-based contract test added by [architect] refactor: enforce behave suite environment quarantine-gate contract (new tests/unit/test_suite_environment_contract.py) #765 for the quarantine gate) with the same pattern for _first_value: a suite environment.py may not define its own copy, and if it calls the helper it must import it from tests.shared.ssh_config. This turns the fix into an enforced contract instead of a one-off cleanup that could silently regress.

Scope discipline (per #763's own recommendation-1 wording: "fold the duplicated _first_value into the existing tests/shared/ssh_config definition"): this PR does only that. It deliberately does not touch:

Verification:

  • pytest tests/unit -q — 1541 passed.
  • ruff check on the two edited environment.py files shows the same 4 pre-existing warnings as before the change (verified via git stash) — no new lint issues introduced.

Ref #763.

— hive: backend=copilot model=claude-sonnet-5

🐝 Hive Agent: contributor | SHA: 8f272f09

mrbobbytables and others added 2 commits September 6, 2026 18:34
tests/common/features/environment.py and tests/kde-smoke/features/environment.py
each carried a byte-for-byte copy of the _first_value(*values) helper that
already lives in tests/shared/ssh_config.py. Three copies of the same
four-line function is exactly the copy-paste-over-shared-abstraction shape
called out in projectbluefin#763: nothing enforced that a fix or behaviour change to one
copy would land in the other two.

Both suites now import _first_value from tests.shared.ssh_config instead of
redefining it. No behaviour change — the three implementations were
identical.

Extend tests/unit/test_suite_environment_contract.py, which already parses
every tests/*/features/environment.py with ast to enforce the quarantine-gate
contract, with the same treatment for _first_value: a suite may not define its
own copy, and any suite that calls it must import it from
tests.shared.ssh_config. This closes the gap before it can reopen.

Ref projectbluefin#763.

Signed-off-by: mrbobbytables <mrbobbytables@users.noreply.github.com>
Other unit tests can leave a minimal SSH module stub in sys.modules under xdist.
Allow the probe patch to install run_ssh on that stub before exercising it.

Assisted-by: Claude Sonnet 5 via GitHub Copilot CLI
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: sec-check[bot] <sec-check[bot]@users.noreply.github.com>
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 90.90909% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
tests/unit/test_suite_environment_contract.py 89.47% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@kubestellar-hive kubestellar-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved by @castrojo for Hive auto-merge on green CI.

@kubestellar-hive kubestellar-hive Bot added the lgtm This PR has been approved by a maintainer label Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants