Skip to content

test: fix help docs test by adding _import_module to fake kernel#59

Open
zza-830 wants to merge 4 commits into
TruFoundation:mainfrom
zza-830:fix/help-docs-test
Open

test: fix help docs test by adding _import_module to fake kernel#59
zza-830 wants to merge 4 commits into
TruFoundation:mainfrom
zza-830:fix/help-docs-test

Conversation

@zza-830

@zza-830 zza-830 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Problem

test_run_help_prints_docstring_for_known_command was failing across all open PRs because the fake kernel in the test lacked a _import_module method. When run_help tried to import the settings module, it hit an AttributeError that was silently caught, falling through to "No detailed help available".

Fix

Added a working _fake_import_module function to the test's SimpleNamespace fake kernel that uses importlib.import_module() to resolve the module path. This allows run_help to successfully load the module, read the docstring, and print it.

Verification

tests/test_help_docs.py::test_run_help_prints_docstring_for_known_command PASSED

Fixes the CI failure affecting PRs #50, #51, #53, #54.

Summary by CodeRabbit

  • Tests

    • Minor formatting adjustment in a help-docs test case (no behavior or logic changes).
  • Documentation

    • Removed an in-code explanatory comment from the command-normalization area.

Ziang Zhang added 2 commits June 8, 2026 14:31
The test_run_help_prints_docstring_for_known_command test was failing
because the fake kernel lacked a _import_module method, causing the
module import to fail silently and fall through to the error message.

Add a working _fake_import_module that uses importlib to resolve
the module path, allowing run_help to read and print the docstring.
The  function referenced a bare name  that was
never imported or defined, causing a NameError crash on every invocation.

Fix: move  before the conditional block so it is
always defined when reached by the comparison at the end of the function.

Closes TruFoundation#40
@AkshajSinghal

Copy link
Copy Markdown
Collaborator

Great find!
But I'd request you to implement these changes:

  1. Add error handling for malformed quoting in _os_passthrough.
  2. Add a Windows path test case to ensure spaces/backslashes are handled correctly.
  3. Update the README to accurately describe the new sanitization process.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fa697ddf-1c3a-451e-9c08-8a30ee758e8b

📥 Commits

Reviewing files that changed from the base of the PR and between 5050b4d and 2bbe1f2.

📒 Files selected for processing (1)
  • tests/test_help_docs.py
💤 Files with no reviewable changes (1)
  • tests/test_help_docs.py

📝 Walkthrough

Walkthrough

Minor whitespace/formatting change in a test's fake_kernel.registry literal and removal of an explanatory comment from app_with_lower in trushell/cli.py. No behavioral logic or exported API changes.

Changes

Formatting and comment cleanup

Layer / File(s) Summary
Test registry literal formatting
tests/test_help_docs.py
Adjusted the closing brace/formatting for the "settings" entry inside the test's fake_kernel.registry mock; no other test logic changed.
CLI comment removal
trushell/cli.py
Removed a multi-line explanatory comment immediately before the lowercase command/argument normalization in app_with_lower; runtime behavior unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A tiny brace fixed in a test so neat,
A comment hopped away, light on its feet,
The shell still listens, commands still run,
Quiet tweaks made — a job softly done. 🥕

🚥 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: adding _import_module to the fake kernel in test_help_docs.py to resolve a test failure.
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 unit tests (beta)
  • Create PR with unit tests
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch fix/help-docs-test

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

@zza-830

zza-830 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review! This PR is specifically a test fix — it adds _import_module to the fake kernel in test_help_docs.py so the help docstring test passes. The _os_passthrough error handling and Windows path test you mentioned are outside the scope of this PR, but great ideas for follow-up work.

Merge conflict with upstream/main has been resolved. Ready for another look!

@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

🤖 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_help_docs.py`:
- Line 3: Remove the dead helper and unused import: delete the unused function
_fake_import_module and its assignment to fake_kernel._import_module, and remove
the importlib import since it's only referenced by that dead function; keep the
working mock assignment (the lambda that returns fake_module) as the sole
_import_module replacement so tests still pass.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 70442d9b-75ad-4969-84f6-6989b2ef371f

📥 Commits

Reviewing files that changed from the base of the PR and between 7ab2e53 and 5050b4d.

📒 Files selected for processing (2)
  • tests/test_help_docs.py
  • trushell/cli.py
💤 Files with no reviewable changes (1)
  • trushell/cli.py

Comment thread tests/test_help_docs.py Outdated
zza-830 pushed a commit to zza-830/TruShell that referenced this pull request Jun 9, 2026
- add_task now only splits on quotes when args actually starts with
  a quote character. Plain multi-word input like 'buy groceries' is
  treated as the full task text, not split into task + category.
- Remove dead _fake_import_module function from test_help_docs.py
  (was overridden by the lambda on the next line).

Addresses CodeRabbit review on TruFoundation#53 and TruFoundation#59.
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.

2 participants