Skip to content

fix: normalize shipyard shell exec response#8850

Open
nhirsama wants to merge 2 commits into
AstrBotDevs:masterfrom
nhirsama:master
Open

fix: normalize shipyard shell exec response#8850
nhirsama wants to merge 2 commits into
AstrBotDevs:masterfrom
nhirsama:master

Conversation

@nhirsama

@nhirsama nhirsama commented Jun 18, 2026

Copy link
Copy Markdown

修复旧版 Shipyard Bay shell 命令实际执行成功,但 AstrBot 返回空 stdout、空 stderrexit_code: null 的问题。

旧版 Shipyard /ship/{ship_id}/exec API 会把 shell 执行结果包在 data 字段中,例如 data.stdoutdata.stderrdata.return_code。此前 AstrBot 只读取外层字段,导致命令输出和退出码被丢弃。

Modifications / 改动点

  • 更新 astrbot/core/computer/booters/shipyard.py,兼容 Shipyard Bay success/data/error 包装结构。

  • data.stdout / data.stderr 正确映射为 AstrBot shell 工具输出。

  • data.return_code 正确映射为 AstrBot exit_code

  • tests/unit/test_computer.py 中增加基于真实 Shipyard Bay 响应结构的回归测试。

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

Ling code/AstrBot ‹master› » uv run pytest tests/unit/test_computer.py::TestShipyardBooter::test_shipyard_shell_unwraps_bay_exec_response
=================================================================================================================== test session starts ====================================================================================================================
platform linux -- Python 3.12.13, pytest-9.1.0, pluggy-1.6.0
rootdir: /home/ling/Documents/code/AstrBot
configfile: pyproject.toml
plugins: anyio-4.14.0, asyncio-1.4.0, cov-7.1.0
asyncio: mode=Mode.STRICT, debug=False, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function
collected 1 item                                                                                                                                                                                                                                           

tests/unit/test_computer.py .                                                                                                                                                                                                                        [100%]

==================================================================================================================== 1 passed in 3.66s =====================================================================================================================

Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Normalize handling of Shipyard Bay shell exec responses so shell command output and exit codes are correctly surfaced by AstrBot.

Bug Fixes:

  • Fix missing stdout, stderr, and exit_code when processing nested Shipyard Bay /ship/{ship_id}/exec responses wrapped under a data field.

Tests:

  • Add a regression test ensuring ShipyardShellWrapper correctly unwraps Bay exec response payloads and maps them to the standardized shell result format.

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. area:core The bug / feature is about astrbot's core, backend labels Jun 18, 2026

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request updates the ShipyardShellWrapper execution logic to correctly unwrap nested execution responses where shell output is stored under the data field. It also adds a unit test to verify this behavior. The review feedback suggests simplifying the fallback logic for extracting stdout and stderr to make it more concise and idiomatic.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread astrbot/core/computer/booters/shipyard.py Outdated

@sourcery-ai sourcery-ai 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.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/unit/test_computer.py" line_range="401-405" />
<code_context>
+            }
+        )
+
+        result = await ShipyardShellWrapper(raw_shell).exec(
+            "echo hello_from_shipyard_bay && pwd"
+        )
+
+        assert result == {
+            "stdout": "hello_from_shipyard_bay\n/workspace\n",
+            "stderr": "",
</code_context>
<issue_to_address>
**suggestion (testing):** Consider adding a complementary test for non-wrapped (legacy) exec responses to guard backward compatibility

Since this test only covers the nested `data` response from Shipyard Bay, please also add a sibling test where `raw_shell.exec` returns a flat payload (top-level `stdout`, `stderr`, `exit_code` and no `data` key). That will explicitly cover the legacy shape and reduce the risk of regressions in future changes to the unwrapping logic.

Suggested implementation:

```python
        result = await ShipyardShellWrapper(raw_shell).exec(
            "echo hello_from_shipyard_bay && pwd"
        )

    async def test_shipyard_shell_wrapper_exec_legacy_flat_response(self, raw_shell):
        raw_shell.exec.return_value = {
            "stdout": "hello_from_legacy_shell\n/workspace\n",
            "stderr": "",
            "exit_code": 0,
            "pid": 16,
            "process_id": None,
            "error": None,
        }

        result = await ShipyardShellWrapper(raw_shell).exec(
            "echo hello_from_legacy_shell && pwd"
        )

        assert result == {
            "stdout": "hello_from_legacy_shell\n/workspace\n",
            "stderr": "",
            "exit_code": 0,
            "pid": 16,
            "process_id": None,
            "error": None,
        }

```

I assumed this code is inside a test class that already has access to a `raw_shell` fixture and `ShipyardShellWrapper` import, mirroring the existing Shipyard Bay response test. If the tests are function-based rather than class-based, drop the `self` parameter and remove the `self` qualifier from the new test definition:

```python
async def test_shipyard_shell_wrapper_exec_legacy_flat_response(raw_shell):
    ...
```

Also, if your project uses a specific async test framework marker (e.g. `pytest.mark.anyio` or `pytest.mark.asyncio`) applied at the class or module level, ensure the new test is covered by that same marker so it runs correctly.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread tests/unit/test_computer.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant