Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions tests/golden/cli_output/workspace_serializer.json

This file was deleted.

70 changes: 0 additions & 70 deletions tests/unit/auth/test_error_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from __future__ import annotations

from datetime import UTC, datetime, timedelta
from pathlib import Path
from unittest.mock import patch

import pytest
Expand All @@ -17,7 +16,6 @@
from osmosis_ai.platform.auth.credentials import Credentials, UserInfo
from osmosis_ai.platform.auth.platform_client import (
AuthenticationExpiredError,
PlatformAPIError,
)
from osmosis_ai.platform.constants import MSG_ENV_TOKEN_INVALID

Expand All @@ -35,31 +33,6 @@ def _make_credentials(*, expired: bool = False) -> Credentials:
)


def test_reset_session_deletes_legacy_auth_local_config(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
from osmosis_ai.platform.auth.local_config import reset_session

legacy_config = tmp_path / ".config" / "osmosis" / "config.json"
legacy_config.parent.mkdir(parents=True)
legacy_config.write_text(
'{"active_workspace":{"id":"legacy","name":"legacy"}}',
encoding="utf-8",
)

monkeypatch.setattr(
"osmosis_ai.platform.auth.local_config.CONFIG_FILE",
legacy_config,
)
monkeypatch.setattr(
"osmosis_ai.platform.auth.credentials.delete_credentials", lambda: True
)

reset_session()

assert not legacy_config.exists()


class TestRequireCredentialsMessages:
"""Test require_credentials() raises the right exception for each state."""

Expand Down Expand Up @@ -93,30 +66,6 @@ def test_valid_credentials_returns_them(self, mock_load: object) -> None:
assert result is creds


def test_global_active_workspace_helpers_are_not_public_context_api() -> None:
"""Production modules must not expose global active workspace context APIs."""
import osmosis_ai.platform.auth as auth_module
import osmosis_ai.platform.auth.local_config as local_config
import osmosis_ai.platform.auth.platform_client as platform_client
import osmosis_ai.platform.cli.utils as cli_utils

removed_symbols = [
(auth_module, "ensure_active_workspace"),
(auth_module, "get_active_workspace"),
(auth_module, "get_active_workspace_id"),
(local_config, "get_active_workspace"),
(local_config, "get_active_workspace_id"),
(local_config, "get_active_workspace_name"),
(local_config, "set_active_workspace"),
(local_config, "clear_active_workspace"),
(platform_client, "ensure_active_workspace"),
(platform_client, "get_active_workspace_id"),
(cli_utils, "_get_active_workspace_name"),
]
for module, symbol in removed_symbols:
assert not hasattr(module, symbol), f"{module.__name__}.{symbol} remains"


class TestPlatformRequestMessages:
"""Test platform_request() error messages for each failure mode."""

Expand All @@ -129,25 +78,6 @@ def test_no_credentials_does_not_say_expired(self, _mock: object) -> None:
with pytest.raises(CLIError, match="Not logged in"):
platform_request("/api/test")

def test_git_scope_required_ignores_legacy_active_workspace_fallback(
self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
from osmosis_ai.platform.auth.platform_client import platform_request

legacy_config = tmp_path / "config.json"
legacy_config.write_text(
'{"active_workspace":{"id":"legacy-ws","name":"legacy-workspace"}}',
encoding="utf-8",
)
monkeypatch.setattr(
"osmosis_ai.platform.auth.local_config.CONFIG_FILE",
legacy_config,
)
creds = _make_credentials()

with pytest.raises(PlatformAPIError, match="explicit git_identity"):
platform_request("/api/test", credentials=creds)


class TestMainExceptionHandlerMessages:
"""Test that main() maps exceptions to the correct stderr output."""
Expand Down
6 changes: 0 additions & 6 deletions tests/unit/auth/test_local_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ def _isolate_config(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
monkeypatch.setattr(local_config, "CONFIG_FILE", config_file)


def test_local_config_does_not_expose_subscription_cache_helpers() -> None:
assert not hasattr(local_config, "clear_workspace_data")
assert not hasattr(local_config, "load_subscription_status")
assert not hasattr(local_config, "save_subscription_status")


# ── session reset ────────────────────────────────────────────────


Expand Down
65 changes: 2 additions & 63 deletions tests/unit/cli/output/test_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import typer.core

import osmosis_ai.cli.main as cli_main
from osmosis_ai.cli._click_compat import Context, UsageError
from osmosis_ai.cli._click_compat import Context
from osmosis_ai.cli.errors import CLIError
from osmosis_ai.cli.main import _handle_cli_error, main
from osmosis_ai.cli.main import main
from osmosis_ai.cli.output.error import (
classify_error,
command_path_for_error,
Expand All @@ -36,21 +36,6 @@ def _capture_envelope(err: CLIError) -> dict[str, Any]:
return json.loads(buf.getvalue())


def _capture_json_usage_error_for_argv(
argv: list[str],
capsys: pytest.CaptureFixture[str],
) -> dict[str, Any]:
rc = _handle_cli_error(
UsageError("No such command."),
argv=argv,
exit_code=2,
)
assert rc == 2
captured = capsys.readouterr()
assert captured.out == ""
return json.loads(captured.err)


def test_envelope_keys_match_golden() -> None:
envelope = _capture_envelope(CLIError("Bad input.", code="VALIDATION"))
expected = json.loads((GOLDEN / "error_envelope.json").read_text(encoding="utf-8"))
Expand Down Expand Up @@ -148,52 +133,6 @@ def test_command_path_root_when_argv_empty(monkeypatch) -> None:
assert command_path_for_error(None) == "<root>"


@pytest.mark.parametrize(
("argv", "expected_command"),
[
(["--json", "doctor"], "doctor"),
(["--json", "workspace"], "workspace"),
(["--json", "workspace", "list"], "workspace"),
(["--json", "workspace", "create", "team"], "workspace"),
(["--json", "workspace", "delete", "team"], "workspace"),
(["--json", "workspace", "switch", "team"], "workspace"),
(["--json", "login"], "login"),
(["--json", "logout"], "logout"),
(["--json", "whoami"], "whoami"),
(["--json", "init"], "init"),
(["--json", "link"], "link"),
(["--json", "unlink"], "unlink"),
(["--json", "project", "init"], "project"),
(["--json", "project", "info"], "project"),
(["--json", "project", "list"], "project"),
(["--json", "secret", "list"], "secret list"),
(["--json", "secret", "add", "NAME"], "secret add"),
(["--json", "dataset", "delete", "name"], "dataset delete"),
(["--json", "train", "delete", "run"], "train delete"),
(["--json", "train", "status", "run"], "train status"),
(["--json", "train", "metrics", "run"], "train metrics"),
(["--json", "train", "traces"], "train traces"),
(["--json", "model", "delete", "name"], "model delete"),
(["--json", "deployment", "list"], "deployment"),
(["--json", "deploy", "checkpoint"], "deploy"),
(["--json", "undeploy", "checkpoint"], "undeploy"),
(["--json", "rollout", "validate", "config.toml"], "rollout validate"),
],
)
def test_json_unknown_removed_command_uses_explicit_main_argv(
argv: list[str],
expected_command: str,
monkeypatch: pytest.MonkeyPatch,
capsys: pytest.CaptureFixture[str],
) -> None:
monkeypatch.setattr("sys.argv", ["osmosis", "--json", "dataset", "list"])

envelope = _capture_json_usage_error_for_argv(argv, capsys)

assert envelope["command"] == expected_command
assert envelope["error"]["code"] == "VALIDATION"


def test_json_unknown_command_from_main_uses_explicit_argv(
monkeypatch: pytest.MonkeyPatch,
capsys: pytest.CaptureFixture[str],
Expand Down
6 changes: 0 additions & 6 deletions tests/unit/cli/output/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,6 @@ def test_serialize_model_keys() -> None:
_assert_keys_match_golden(payload, "model_serializer.json")


def test_workspace_serializer_is_not_exported() -> None:
import osmosis_ai.cli.output as output

assert not hasattr(output, "serialize_workspace")


def test_serialize_rollout_keys() -> None:
rollout = RolloutInfo.from_dict(
{
Expand Down
Loading
Loading