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 / linter-shell (push) Has been cancelled
Mark stable commit / linter-python (push) Has been cancelled
Mark stable commit / mark-stable (push) Has been cancelled
- Run publish automatically after successful release - Add --no-publish flag to disable auto-publish - Respect TTY for interactive/credential prompts - Harden repo directory resolution - Add integration and unit tests for release→publish hook https://chatgpt.com/share/693f335b-b820-800f-8666-68355f3c938f
67 lines
2.3 KiB
Python
67 lines
2.3 KiB
Python
from __future__ import annotations
|
|
|
|
import tempfile
|
|
import unittest
|
|
from types import SimpleNamespace
|
|
from unittest.mock import patch
|
|
|
|
|
|
class TestIntegrationReleasePublishHook(unittest.TestCase):
|
|
def _ctx(self) -> SimpleNamespace:
|
|
# Minimal CLIContext shape used by handle_release()
|
|
return SimpleNamespace(
|
|
repositories_base_dir="/tmp",
|
|
all_repositories=[],
|
|
)
|
|
|
|
def _parse(self, argv: list[str]):
|
|
from pkgmgr.cli.parser import create_parser
|
|
|
|
parser = create_parser("pkgmgr test")
|
|
return parser.parse_args(argv)
|
|
|
|
def test_release_runs_publish_by_default_and_respects_tty(self) -> None:
|
|
from pkgmgr.cli.commands.release import handle_release
|
|
|
|
with tempfile.TemporaryDirectory() as td:
|
|
selected = [{"directory": td}]
|
|
|
|
# Go through real parser to ensure CLI surface is wired correctly
|
|
args = self._parse(["release", "patch"])
|
|
|
|
with patch("pkgmgr.cli.commands.release.run_release") as m_release, patch(
|
|
"pkgmgr.cli.commands.release.run_publish"
|
|
) as m_publish, patch(
|
|
"pkgmgr.cli.commands.release.sys.stdin.isatty", return_value=False
|
|
):
|
|
handle_release(args=args, ctx=self._ctx(), selected=selected)
|
|
|
|
m_release.assert_called_once()
|
|
m_publish.assert_called_once()
|
|
|
|
_, kwargs = m_publish.call_args
|
|
self.assertEqual(kwargs["repo"], selected[0])
|
|
self.assertEqual(kwargs["repo_dir"], td)
|
|
self.assertFalse(kwargs["interactive"])
|
|
self.assertFalse(kwargs["allow_prompt"])
|
|
|
|
def test_release_skips_publish_when_no_publish_flag_set(self) -> None:
|
|
from pkgmgr.cli.commands.release import handle_release
|
|
|
|
with tempfile.TemporaryDirectory() as td:
|
|
selected = [{"directory": td}]
|
|
|
|
args = self._parse(["release", "patch", "--no-publish"])
|
|
|
|
with patch("pkgmgr.cli.commands.release.run_release") as m_release, patch(
|
|
"pkgmgr.cli.commands.release.run_publish"
|
|
) as m_publish:
|
|
handle_release(args=args, ctx=self._ctx(), selected=selected)
|
|
|
|
m_release.assert_called_once()
|
|
m_publish.assert_not_called()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|