Files
chopratejas--headroom/tests/test_provider_openclaw_wrap.py
wehub-resource-sync 0ef5fcb1c5
Security / Dependency audit (pip-audit) (push) Has been cancelled
Security / CodeQL (javascript-typescript) (push) Has been cancelled
Security / CodeQL (python) (push) Has been cancelled
Security / Secret scan (gitleaks) (push) Has been cancelled
rust / test (ubuntu) (push) Has been cancelled
rust / simulator e2e (macos-latest) (push) Has been cancelled
rust / simulator e2e (ubuntu-latest) (push) Has been cancelled
rust / simulator e2e (windows-latest) (push) Has been cancelled
rust / wheels (aarch64-apple-darwin) (push) Has been cancelled
rust / wheels (x86_64-unknown-linux-gnu) (push) Has been cancelled
rust / wheels (x86_64-apple-darwin) (push) Has been cancelled
rust / audit (push) Has been cancelled
rust / parity (nightly, allowed to fail during Phase 0) (push) Has been cancelled
CI / commitlint (push) Has been skipped
Dev Containers / validate (.devcontainer/devcontainer.json, default) (push) Failing after 0s
Dev Containers / validate (.devcontainer/memory-stack/devcontainer.json, memory-stack) (push) Failing after 0s
Dev Containers / validate-worktree (push) Failing after 0s
CI / changes (push) Failing after 4s
Deploy Documentation / validate (push) Has been skipped
Deploy Documentation / deploy (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, claude) (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, codex) (push) Failing after 1s
Install Native E2E / install-native (ubuntu-latest) (push) Failing after 1s
OpenCode Plugin / typecheck + build + test (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, copilot) (push) Failing after 1s
Release Please / release-please (push) Failing after 1s
Wrap E2E / docker-wrap-e2e (push) Failing after 1s
Wrap Native E2E / wrap-native (ubuntu-latest) (push) Failing after 1s
Init E2E / docker-init-e2e (push) Failing after 4s
Merge Conflicts / merge-conflicts (push) Failing after 4s
CI / lint (push) Has been cancelled
CI / build-wheel (push) Has been cancelled
CI / build-wheel-windows (push) Has been cancelled
CI / prefetch-model (push) Has been cancelled
CI / test-dashboard-ui (push) Has been cancelled
CI / test (1) (push) Has been cancelled
CI / test (2) (push) Has been cancelled
CI / test (3) (push) Has been cancelled
CI / test (4) (push) Has been cancelled
CI / test-extras (push) Has been cancelled
CI / test-agno (push) Has been cancelled
CI / build (push) Has been cancelled
CI / workflow-validation (push) Has been cancelled
CI / docker-native-e2e (push) Has been cancelled
CI / windows-native-wrapper (push) Has been cancelled
CI / macos-native-wrapper (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / promote-latest (push) Has been cancelled
Init Native E2E / init-native (macos-latest, claude) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, codex) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, copilot) (push) Has been cancelled
Install Native E2E / install-native (macos-latest) (push) Has been cancelled
Wrap Native E2E / wrap-native (macos-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:03:20 +08:00

151 lines
4.3 KiB
Python

from __future__ import annotations
from headroom.providers.openclaw.wrap import (
DEFAULT_GATEWAY_PROVIDER_IDS,
build_plugin_entry,
build_unwrap_entry,
decode_entry_json,
normalize_gateway_provider_ids,
)
def test_normalize_gateway_provider_ids_trims_deduplicates_and_defaults() -> None:
# Arrange / Act / Assert
assert normalize_gateway_provider_ids((" openai-codex ", "anthropic", "anthropic", "")) == [
"openai-codex",
"anthropic",
]
assert normalize_gateway_provider_ids(None) == DEFAULT_GATEWAY_PROVIDER_IDS
def test_decode_entry_json_handles_empty_valid_and_invalid_payloads() -> None:
# Arrange / Act / Assert
assert decode_entry_json(None) is None
assert decode_entry_json("") is None
assert decode_entry_json('{"enabled": true}') == {"enabled": True}
assert decode_entry_json("{not-json}") == "{not-json}"
def test_build_plugin_entry_preserves_unmanaged_values_and_removes_empty_python_path() -> None:
# Arrange
existing_entry = {
"enabled": False,
"name": "headroom",
"config": {
"keep": "value",
"proxyUrl": "https://user.example",
"pythonPath": "/old/python",
},
}
# Act
entry = build_plugin_entry(
existing_entry=existing_entry,
proxy_port=8787,
startup_timeout_ms=1500,
python_path=None,
no_auto_start=True,
gateway_provider_ids=(" openai-codex ", "anthropic", "anthropic"),
enabled=True,
)
# Assert
assert entry["enabled"] is True
assert entry["name"] == "headroom"
assert entry["config"] == {
"keep": "value",
"proxyUrl": "https://user.example",
"proxyPort": 8787,
"autoStart": False,
"startupTimeoutMs": 1500,
"gatewayProviderIds": ["openai-codex", "anthropic"],
}
def test_build_plugin_entry_creates_managed_defaults_for_non_mapping_input() -> None:
# Arrange / Act
entry = build_plugin_entry(
existing_entry="not-a-dict",
proxy_port=9000,
startup_timeout_ms=2500,
python_path="/usr/bin/python",
no_auto_start=False,
gateway_provider_ids=None,
enabled=False,
)
# Assert
assert entry == {
"enabled": False,
"config": {
"proxyPort": 9000,
"autoStart": True,
"startupTimeoutMs": 2500,
"gatewayProviderIds": ["openai-codex"],
"pythonPath": "/usr/bin/python",
},
}
def test_build_unwrap_entry_disables_plugin_and_removes_managed_keys_only() -> None:
# Arrange
existing_entry = {
"enabled": True,
"name": "headroom",
"config": {
"keep": "value",
"gatewayProviderIds": ["openai-codex"],
"proxyUrl": "https://managed.example",
"proxyPort": 8787,
"autoStart": True,
"startupTimeoutMs": 1000,
"pythonPath": "/usr/bin/python",
},
}
# Act
entry = build_unwrap_entry(existing_entry)
# Assert
assert entry == {
"enabled": False,
"name": "headroom",
"config": {"keep": "value"},
}
def test_build_unwrap_entry_handles_non_mapping_input() -> None:
# Arrange / Act / Assert
assert build_unwrap_entry("not-a-dict") == {"enabled": False, "config": {}}
def test_build_plugin_entry_strips_mcpServers_from_existing_entry() -> None:
"""Newer OpenClaw schemas reject `mcpServers` at the plugin-entry root.
`headroom init -g` was failing with `Config invalid: Unrecognized
key: "mcpServers"` because the prior plugin entry in the user's
config still had that legacy field, and we were spreading it back in
via `**existing_entry`. Pin the strip so we don't regress.
"""
existing_entry = {
"enabled": True,
"name": "headroom",
"mcpServers": {"some": "stale-block"}, # legacy, must be removed
"config": {"keep": "value"},
}
entry = build_plugin_entry(
existing_entry=existing_entry,
proxy_port=8787,
startup_timeout_ms=1500,
python_path=None,
no_auto_start=False,
gateway_provider_ids=None,
enabled=True,
)
assert "mcpServers" not in entry
assert entry["enabled"] is True
assert entry["name"] == "headroom"
assert entry["config"]["keep"] == "value"