Some checks failed
Mark stable commit / test-unit (push) Has been cancelled
Mark stable commit / test-integration (push) Has been cancelled
Mark stable commit / test-env-virtual (push) Has been cancelled
Mark stable commit / test-env-nix (push) Has been cancelled
Mark stable commit / test-e2e (push) Has been cancelled
Mark stable commit / test-virgin-user (push) Has been cancelled
Mark stable commit / test-virgin-root (push) Has been cancelled
Mark stable commit / lint-shell (push) Has been cancelled
Mark stable commit / lint-python (push) Has been cancelled
Mark stable commit / mark-stable (push) Has been cancelled
* Move VS Code workspace logic (incl. guards) from cli.commands.tools into cli.tools.vscode * Extract shared repo path resolution into cli.tools.paths and reuse for explore/terminal * Simplify cli.commands.tools to pure orchestration via open_vscode_workspace * Update existing tools command unit test to assert delegation instead of patching removed internals * Add new unit tests for cli.tools.paths and cli.tools.vscode (workspace creation, reuse, guard errors) https://chatgpt.com/share/69419a6a-c9e4-800f-9538-b6652b2da6b3
39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
import unittest
|
|
from types import SimpleNamespace
|
|
from unittest.mock import patch
|
|
|
|
|
|
class TestResolveRepositoryPath(unittest.TestCase):
|
|
def test_explicit_directory_key_wins(self) -> None:
|
|
from pkgmgr.cli.tools.paths import resolve_repository_path
|
|
|
|
ctx = SimpleNamespace(repositories_base_dir="/base", repositories_dir="/base2")
|
|
repo = {"directory": "/explicit/repo"}
|
|
|
|
self.assertEqual(resolve_repository_path(repo, ctx), "/explicit/repo")
|
|
|
|
def test_fallback_uses_get_repo_dir_with_repositories_base_dir(self) -> None:
|
|
from pkgmgr.cli.tools.paths import resolve_repository_path
|
|
|
|
ctx = SimpleNamespace(repositories_base_dir="/base", repositories_dir="/base2")
|
|
repo = {"provider": "github.com", "account": "acme", "repository": "demo"}
|
|
|
|
with patch("pkgmgr.cli.tools.paths.get_repo_dir", return_value="/computed/repo") as m:
|
|
out = resolve_repository_path(repo, ctx)
|
|
|
|
self.assertEqual(out, "/computed/repo")
|
|
m.assert_called_once_with("/base", repo)
|
|
|
|
def test_raises_if_no_base_dir_in_context(self) -> None:
|
|
from pkgmgr.cli.tools.paths import resolve_repository_path
|
|
|
|
ctx = SimpleNamespace(repositories_base_dir=None, repositories_dir=None)
|
|
repo = {"provider": "github.com", "account": "acme", "repository": "demo"}
|
|
|
|
with self.assertRaises(RuntimeError) as cm:
|
|
resolve_repository_path(repo, ctx)
|
|
|
|
self.assertIn("Cannot resolve repositories base directory", str(cm.exception))
|