fix: avoid hardcoded sandbox skill root in prompt fallback#6983
fix: avoid hardcoded sandbox skill root in prompt fallback#69831zzxy1 wants to merge 1 commit intoAstrBotDevs:masterfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves an issue where sandbox skill paths would incorrectly fall back to a hardcoded absolute path. It refactors the skill manager to use a relative path for sandbox skills, improving flexibility and correctness. Additionally, the user prompt for skill grounding has been updated to reflect this change, and comprehensive regression tests have been added to ensure the new behavior is robust. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider updating the docstring or adding a short comment for
_default_sandbox_skill_pathto make it explicit that it now returns a sandbox-relative path instead of an absolute path, so future callers don’t assume absolute semantics. - It may be worth scanning for any remaining references or assumptions about
/workspace/skills/...elsewhere in the codebase and consolidating them to use the new sandbox-relativeskills/<name>/SKILL.mdconvention to avoid mixed path styles.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider updating the docstring or adding a short comment for `_default_sandbox_skill_path` to make it explicit that it now returns a sandbox-relative path instead of an absolute path, so future callers don’t assume absolute semantics.
- It may be worth scanning for any remaining references or assumptions about `/workspace/skills/...` elsewhere in the codebase and consolidating them to use the new sandbox-relative `skills/<name>/SKILL.md` convention to avoid mixed path styles.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request refactors how sandbox skill paths are handled, transitioning from absolute paths (prefixed with /workspace) to relative paths. This change involves removing the SANDBOX_WORKSPACE_ROOT constant, updating the _default_sandbox_skill_path function, and modifying the build_skills_prompt to remove the 'absolute path' requirement. New tests have been added to validate these changes. A suggestion was made to refactor repeated test setup logic into a pytest fixture to improve maintainability and reduce code duplication.
| data_dir = tmp_path / "data" | ||
| temp_dir = tmp_path / "temp" | ||
| skills_root = tmp_path / "skills" | ||
| data_dir.mkdir(parents=True, exist_ok=True) | ||
| temp_dir.mkdir(parents=True, exist_ok=True) | ||
| skills_root.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| monkeypatch.setattr( | ||
| "astrbot.core.skills.skill_manager.get_astrbot_data_path", | ||
| lambda: str(data_dir), | ||
| ) | ||
| monkeypatch.setattr( | ||
| "astrbot.core.skills.skill_manager.get_astrbot_temp_path", | ||
| lambda: str(temp_dir), | ||
| ) | ||
|
|
||
| mgr = SkillManager(skills_root=str(skills_root)) |
There was a problem hiding this comment.
The setup logic for creating directories and monkeypatching path functions is repeated across multiple tests in this file. To improve maintainability and reduce code duplication, consider extracting this common setup into a pytest fixture.
This would make the tests cleaner and easier to manage. For example:
@pytest.fixture
def skill_manager(monkeypatch, tmp_path: Path) -> SkillManager:
data_dir = tmp_path / "data"
temp_dir = tmp_path / "temp"
skills_root = tmp_path / "skills"
data_dir.mkdir(parents=True, exist_ok=True)
temp_dir.mkdir(parents=True, exist_ok=True)
skills_root.mkdir(parents=True, exist_ok=True)
monkeypatch.setattr(
"astrbot.core.skills.skill_manager.get_astrbot_data_path",
lambda: str(data_dir),
)
monkeypatch.setattr(
"astrbot.core.skills.skill_manager.get_astrbot_temp_path",
lambda: str(temp_dir),
)
return SkillManager(skills_root=str(skills_root))Tests can then be simplified by using this fixture, for example:
def test_sandbox_path_fallback_uses_relative_skills_root(skill_manager: SkillManager):
skill_manager.set_sandbox_skills_cache(...)
skills = skill_manager.list_skills(runtime="sandbox")
# ... assertions|
Closing this PR until it has been properly tested. |
Summary
Fixes #5922
Testing
Summary by Sourcery
Adjust sandbox skill path handling and prompt instructions to avoid hardcoded workspace paths and support relative sandbox paths.
Bug Fixes:
Enhancements: