Skip to content

[quality] add BATS tests for ublue-motd double-execution guard (PR #795 coverage) - #846

Open
clubanderson wants to merge 1 commit into
projectbluefin:mainfrom
clubanderson:quality/test-ublue-motd-guard
Open

[quality] add BATS tests for ublue-motd double-execution guard (PR #795 coverage)#846
clubanderson wants to merge 1 commit into
projectbluefin:mainfrom
clubanderson:quality/test-ublue-motd-guard

Conversation

@clubanderson

@clubanderson clubanderson commented Jul 21, 2026

Copy link
Copy Markdown

Test Improvement

Adds tests/test_ublue_motd_guard.bats (14 tests) covering the double-execution
guard and env.sh existence guard introduced by PR #795.

New test coverage

ublue-motd.sh (profile.d entry)

  • First invocation runs ublue-motd and exports UBLUE_MOTD_SHOWN=1
  • Second invocation (with UBLUE_MOTD_SHOWN=1 set) does NOT run ublue-motd again
  • Invocation skipped when ~/.config/no-show-user-motd exists
  • Guard variables present via grep assertions

usr/bin/ublue-motd binary

fish_greeting.fish

  • Contains UBLUE_MOTD_SHOWN guard (static assertions)
  • Sets UBLUE_MOTD_SHOWN=1 before returning
  • Still checks no-show-user-motd opt-out file

Related Issue

Closes #845


Filed by quality agent (hold-gated mode). Human review required.

Summary by CodeRabbit

  • Tests
    • Added automated coverage for MOTD display guards across shell and Fish environments.
    • Verified MOTD displays only once per session and respects the user opt-out setting.
    • Confirmed MOTD operates successfully when optional environment configuration is unavailable.
    • Added checks ensuring environment configuration is loaded when present.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a Bats test suite with an isolated sandbox and mocked ublue-motd command. Tests cover profile-script guards, missing and present env.sh behavior, and static assertions for Fish greeting guards.

Changes

MOTD guard test coverage

Layer / File(s) Summary
Profile guard coverage
tests/test_ublue_motd_guard.bats
Sets up isolated test state and verifies first invocation, repeated sourcing, and the no-show-user-motd opt-out behavior.
Environment-file handling
tests/test_ublue_motd_guard.bats
Checks successful execution without env.sh, sourcing when present, and the file-existence guard.
Fish greeting guard coverage
tests/test_ublue_motd_guard.bats
Checks the Fish guard, exported UBLUE_MOTD_SHOWN assignment, and opt-out condition.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: size:M

Poem

I’m a rabbit with tests in my burrow so bright,
MOTD guards now hop through the night.
First shell call leaves a flag in the air,
Second call finds it and stays unaware.
Missing env files cause no fright—
Fish greetings guard the startup right.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: adding BATS tests for the ublue-motd double-execution guard.
Description check ✅ Passed The description includes the change summary and issue reference, though it omits some template sections like the pipeline and checklist.
Linked Issues check ✅ Passed The added tests cover the linked issue's requested guards for first run, repeat run, opt-out file, and missing env.sh behavior.
Out of Scope Changes check ✅ Passed The changes stay in scope by adding only a dedicated test suite for the ublue-motd guard behavior.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@clubanderson

Copy link
Copy Markdown
Author

HOLD — do not merge

This PR was filed by the quality agent (hold-gated mode). It requires human review before merging.

Note: system_files/shared/etc/profile.d/ublue-motd.sh is absent on current main. This test file is designed to land alongside PR #795 (fix(motd): prevent double-execution and missing env.sh errors). The tests will fail until #795 is merged — that is intentional and expected.

Please apply the following labels manually if not already set:

  • hold
  • quality
  • testing

This PR adds 14 BATS tests for the double-execution guard logic introduced by #795, closing issue #845.

@coderabbitai coderabbitai Bot added the size:M label Jul 21, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/test_ublue_motd_guard.bats (1)

48-48: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Prevent path quoting issues in bash -c.

Injecting path variables directly into a bash -c command string using single quotes works for spaces, but can cause a syntax error if the repository clone path happens to contain a single quote character (e.g., /home/user/my'repos/...). Passing file paths as positional arguments to the sub-shell is a safer convention.

  • tests/test_ublue_motd_guard.bats#L48-L48: Refactor to run bash -c 'source "$1"; echo "${UBLUE_MOTD_SHOWN:-unset}"' _ "${MOTD_PROFILE}"
  • tests/test_ublue_motd_guard.bats#L55-L58: Refactor to run bash -c 'export UBLUE_MOTD_SHOWN=1; source "$1"' _ "${MOTD_PROFILE}"
🤖 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 `@tests/test_ublue_motd_guard.bats` at line 48, Update both bash -c invocations
in tests/test_ublue_motd_guard.bats: at lines 48-48, pass MOTD_PROFILE as a
positional argument and source it via "$1"; at lines 55-58, use the same
positional-argument pattern while preserving the UBLUE_MOTD_SHOWN export. Avoid
interpolating MOTD_PROFILE directly into the shell command string.
🤖 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_ublue_motd_guard.bats`:
- Around line 1-11: Wire tests/test_ublue_motd_guard.bats into the repository’s
standard test execution by adding it to the appropriate test target in Justfile
and the unit-test workflow in .github/workflows/unit-tests.yml. Ensure both
local just test runs and CI execute this Bats test.

---

Nitpick comments:
In `@tests/test_ublue_motd_guard.bats`:
- Line 48: Update both bash -c invocations in tests/test_ublue_motd_guard.bats:
at lines 48-48, pass MOTD_PROFILE as a positional argument and source it via
"$1"; at lines 55-58, use the same positional-argument pattern while preserving
the UBLUE_MOTD_SHOWN export. Avoid interpolating MOTD_PROFILE directly into the
shell command string.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b65b4b68-ad04-41c4-a5f7-59366be17685

📥 Commits

Reviewing files that changed from the base of the PR and between c330ec7 and 707147b.

📒 Files selected for processing (1)
  • tests/test_ublue_motd_guard.bats

Comment on lines +1 to +11
#!/usr/bin/env bats
# Tests for the double-execution guard in system_files/shared/etc/profile.d/ublue-motd.sh
# and the env.sh existence guard in system_files/shared/usr/bin/ublue-motd.
#
# These tests validate the changes introduced by PR #795 (fix(motd): prevent
# double-execution and missing env.sh errors).
#
# Run: bats tests/test_ublue_motd_guard.bats

bats_require_minimum_version 1.5.0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Execute all tests using `just test` as instructed by coding guidelines.
just test

Repository: projectbluefin/common

Length of output: 201


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== files ==\n'
git ls-files 'tests/test_ublue_motd_guard.bats' 'Justfile' 'AGENTS.md' | cat

printf '\n== test file ==\n'
cat -n tests/test_ublue_motd_guard.bats

printf '\n== just-related targets ==\n'
rg -n '^\s*(test|tests|bats|pytest)\b|just test|bats ' Justfile tests -S || true

Repository: projectbluefin/common

Length of output: 7765


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== just test references ==\n'
rg -n '\bjust test\b|\btests/test_ublue_motd_guard\.bats\b|\btest_ublue_motd_guard\b' .github/workflows docs Justfile tests -S || true

printf '\n== workflow files ==\n'
git ls-files '.github/workflows/*' | cat

Repository: projectbluefin/common

Length of output: 1196


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== unit-tests workflow ==\n'
sed -n '1,220p' .github/workflows/unit-tests.yml

printf '\n== run-testsuite workflow ==\n'
sed -n '1,220p' .github/workflows/run-testsuite.yml

printf '\n== testing docs ==\n'
sed -n '1,120p' docs/TESTING.md

Repository: projectbluefin/common

Length of output: 9694


Add this Bats test to the main test target
tests/test_ublue_motd_guard.bats isn’t wired into Justfile or .github/workflows/unit-tests.yml, so it won’t run through the repo’s standard just test/CI path yet.

🤖 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 `@tests/test_ublue_motd_guard.bats` around lines 1 - 11, Wire
tests/test_ublue_motd_guard.bats into the repository’s standard test execution
by adding it to the appropriate test target in Justfile and the unit-test
workflow in .github/workflows/unit-tests.yml. Ensure both local just test runs
and CI execute this Bats test.

Source: Coding guidelines

@hanthor hanthor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for adding coverage, but this test file can't pass on its current base. It targets the guards from PR #795, which is still open (unmerged), so the source files these tests exercise don't exist on main:

  • system_files/shared/etc/profile.d/ublue-motd.sh — not present on main. @test "ublue-motd.sh: first invocation runs ublue-motd" does run bash "${MOTD_PROFILE}" on a nonexistent path, which returns 127, so [ "${status}" -eq 0 ] fails.
  • system_files/shared/usr/bin/ublue-motd — not present on main; the env.sh guard tests can't run.
  • fish_greeting.fish on main is just function fish_greeting; umotd; end — it contains no UBLUE_MOTD_SHOWN and no set -gx UBLUE_MOTD_SHOWN 1, so @test "fish_greeting: contains UBLUE_MOTD_SHOWN guard" and the sibling static assertions fail.

To land this, either rebase it onto PR #795's branch (or wait until #795 merges and re-target main), so the code under test actually ships alongside the tests. As written against main the suite is red. Happy to re-review once the base includes the guard implementation.

@castrojo castrojo added 4-review A pull request is awaiting review. and removed area/bling labels Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4-review A pull request is awaiting review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[quality] common#795 adds double-execution guard to ublue-motd.sh without test coverage

3 participants