Files
Octop/tests/unit/agents/test_reasoning_middleware.py
jubaoliangandjubaoliang 18ab9f6ba9 feat: workspace backend sandboxing, execute-env injection, and ephemeral image refs (#376)
* feat: workspace backend sandboxing, execute-env injection, and ephemeral image refs

Workspace file-I/O hardening across backend and dashboard:
- Host directory sandboxing via root_dir allow-list and denied prefixes
- Execute-environment defaults injected into harness backend specs
- Ephemeral workspace image rematerialization for model calls
- Attachment hint expansion and inbound store improvements
- Portable memory backend and skill workspace catalog updates
- Dashboard UI for agent backend fields and root-dir selection
- Bump harness-agent 0.9.23 / harness-memory 0.9.7; docs + install notes

* feat: add user invitation codes with admin management and redeem flow

- Add user_invites table (migration 009) plus SQLite/Postgres reconcile paths
- Add InviteRepo and InviteService for create/revoke/list/redeem
- Expose public validate/redeem endpoints and admin create/revoke/list routers
- Extract default-agent bootstrap into octop.infra.agents.default_agent
- Add invite error codes and en/zh i18n strings
- Dashboard: invite drawer, login redeem UI, users list, and locales

* fix: add Windows cross-platform guards for pre-existing sandbox/rootfs tests

- Guard POSIX/container-only tests (rootfs-absolute /.octop/... workspace
  paths) with posix_only in test_thread_artifacts.py and test_agent_manager.py
- Normalize the rendered workspace path assertion in test_octop_builtin_skills.py
  (forward slashes on Windows, not str(tmp_path) backslashes)
- Canonicalize ws_dir before the prefix check in attachment hint/path tests
  (tempfile may yield an 8.3 short path on Windows while the resolved
  attachment path uses the long form)

These failures predate the user-invites commit and are unrelated to it; the
product path logic is correct.

---------

Co-authored-by: jubaoliang <jubaoliang@tencent.com>
2026-08-21 22:32:48 +08:00

53 lines
1.7 KiB
Python

from langchain.agents.middleware import ModelRequest
from langchain_anthropic import ChatAnthropic
from langchain_openai import ChatOpenAI
from octop.infra.agents.middleware import reasoning
def test_reasoning_middleware_updates_openai_field_and_extra_body(monkeypatch) -> None:
monkeypatch.setattr(
reasoning,
"get_config",
lambda: {
"configurable": {
reasoning.CONFIG_KEY: {
"model_fields": {"reasoning_effort": "high"},
"extra_body": {"thinking": {"type": "enabled"}},
}
}
},
)
model = ChatOpenAI(model="gpt-5.4", api_key="test")
request = ModelRequest(model=model, messages=[])
configured = reasoning._configured_request(request)
assert configured.model is not model
assert configured.model.reasoning_effort == "high"
assert configured.model.extra_body == {"thinking": {"type": "enabled"}}
def test_reasoning_middleware_updates_native_anthropic_fields(monkeypatch) -> None:
monkeypatch.setattr(
reasoning,
"get_config",
lambda: {
"configurable": {
reasoning.CONFIG_KEY: {
"model_fields": {
"thinking": {"type": "adaptive"},
"reasoning_effort": "high",
}
}
}
},
)
model = ChatAnthropic(model="claude-opus-4-6", api_key="test", max_tokens=1024)
request = ModelRequest(model=model, messages=[])
configured = reasoning._configured_request(request)
assert configured.model.thinking == {"type": "adaptive"}
assert configured.model.reasoning_effort == "high"