|
1 | | -"""Selftests for the Workbench git-ops clone command construction. |
| 1 | +"""Selftests for the Workbench git-ops clone command construction and skip gates. |
2 | 2 |
|
3 | 3 | Covers ``_do_clone`` in ``vip_tests.workbench.test_git_ops``: verifies the |
4 | 4 | shell command it builds removes any pre-existing clone directory before |
5 | 5 | running ``git clone``, so repeat runs against long-lived QA VMs don't fail |
6 | 6 | with "destination path already exists". No live Workbench deployment or |
7 | 7 | Playwright browser required -- ``terminal_run`` is monkeypatched to capture |
8 | 8 | the command string instead of executing it. |
| 9 | +
|
| 10 | +Also covers the config/auth skip-gate wording (#483) and the Gherkin step |
| 11 | +order guard (#479): every scenario in test_git_ops.feature must resolve the |
| 12 | +Git config gate before attempting the (possibly flaky) login step, so a |
| 13 | +read-only/config situation is reported deterministically instead of being |
| 14 | +masked by a login bounce. |
9 | 15 | """ |
10 | 16 |
|
11 | 17 | from __future__ import annotations |
12 | 18 |
|
| 19 | +from importlib.util import find_spec |
| 20 | +from pathlib import Path |
| 21 | + |
| 22 | +import pytest |
| 23 | + |
| 24 | +from vip.config import GitTestConfig, VIPConfig, WorkbenchConfig |
| 25 | +from vip.gherkin import parse_feature_file |
13 | 26 | from vip_tests.workbench import test_git_ops as git_ops |
14 | 27 |
|
15 | 28 |
|
@@ -57,3 +70,115 @@ def fake_terminal_run(page, cmd, timeout=30_000, *, readback_lang="r"): |
57 | 70 |
|
58 | 71 | assert clone_dir == "/home/vip/other-repo" |
59 | 72 | assert "rm -rf /home/vip/other-repo" in captured["cmd"] |
| 73 | + |
| 74 | + |
| 75 | +# --------------------------------------------------------------------------- |
| 76 | +# #479 -- Gherkin step order guard |
| 77 | +# --------------------------------------------------------------------------- |
| 78 | + |
| 79 | + |
| 80 | +def _git_ops_feature_path() -> Path: |
| 81 | + spec = find_spec("vip_tests") |
| 82 | + assert spec and spec.submodule_search_locations |
| 83 | + return Path(spec.submodule_search_locations[0]) / "workbench" / "test_git_ops.feature" |
| 84 | + |
| 85 | + |
| 86 | +class TestFeatureStepOrder: |
| 87 | + """The Git config gate must resolve before the (possibly flaky) login step. |
| 88 | +
|
| 89 | + Otherwise a read-only/config situation is masked by a non-deterministic |
| 90 | + login bounce, surfacing a misleading auth error instead of the real |
| 91 | + config/read-only reason (#479). |
| 92 | + """ |
| 93 | + |
| 94 | + def test_config_gate_precedes_login_in_every_scenario(self): |
| 95 | + parsed = parse_feature_file(_git_ops_feature_path()) |
| 96 | + assert parsed["scenarios"], "expected scenarios in test_git_ops.feature" |
| 97 | + for scenario in parsed["scenarios"]: |
| 98 | + steps = scenario["steps"] |
| 99 | + config_idx = next( |
| 100 | + i for i, s in enumerate(steps) if "the Git test config is available" in s |
| 101 | + ) |
| 102 | + login_idx = next( |
| 103 | + i for i, s in enumerate(steps) if "Workbench is accessible and I am logged in" in s |
| 104 | + ) |
| 105 | + assert config_idx < login_idx, ( |
| 106 | + f"scenario {scenario['title']!r}: 'the Git test config is available' " |
| 107 | + f"must precede 'Workbench is accessible and I am logged in', " |
| 108 | + f"got steps: {steps}" |
| 109 | + ) |
| 110 | + |
| 111 | + def test_push_scenarios_check_pushing_before_login(self): |
| 112 | + parsed = parse_feature_file(_git_ops_feature_path()) |
| 113 | + push_scenarios = [s for s in parsed["scenarios"] if "push" in s["title"].lower()] |
| 114 | + assert push_scenarios, "expected at least one push scenario" |
| 115 | + for scenario in push_scenarios: |
| 116 | + steps = scenario["steps"] |
| 117 | + pushing_idx = next( |
| 118 | + i for i, s in enumerate(steps) if "the Git test config supports pushing" in s |
| 119 | + ) |
| 120 | + login_idx = next( |
| 121 | + i for i, s in enumerate(steps) if "Workbench is accessible and I am logged in" in s |
| 122 | + ) |
| 123 | + assert pushing_idx < login_idx, ( |
| 124 | + f"scenario {scenario['title']!r}: 'the Git test config supports pushing' " |
| 125 | + f"must precede 'Workbench is accessible and I am logged in', " |
| 126 | + f"got steps: {steps}" |
| 127 | + ) |
| 128 | + |
| 129 | + |
| 130 | +# --------------------------------------------------------------------------- |
| 131 | +# #483 -- skip-message wording |
| 132 | +# --------------------------------------------------------------------------- |
| 133 | + |
| 134 | + |
| 135 | +def _make_vip_config(git_test: GitTestConfig | None) -> VIPConfig: |
| 136 | + wc = WorkbenchConfig(url="https://workbench.example.com", git_test=git_test) |
| 137 | + return VIPConfig(workbench=wc) |
| 138 | + |
| 139 | + |
| 140 | +class TestGitConfigAvailableSkipMessages: |
| 141 | + def test_none_config_message_explains_public_vs_token(self): |
| 142 | + """Defensive fallback: git_test is None only via direct construction.""" |
| 143 | + cfg = _make_vip_config(None) |
| 144 | + with pytest.raises(pytest.skip.Exception) as exc_info: |
| 145 | + git_ops.git_config_available(cfg) |
| 146 | + msg = exc_info.value.msg |
| 147 | + assert "auth_method='none'" in msg |
| 148 | + assert "no token required" in msg |
| 149 | + assert "VIP_GIT_TOKEN" in msg |
| 150 | + |
| 151 | + def test_empty_clone_url_message_explains_public_vs_token(self): |
| 152 | + cfg = _make_vip_config(GitTestConfig(clone_url="", auth_method="none")) |
| 153 | + with pytest.raises(pytest.skip.Exception) as exc_info: |
| 154 | + git_ops.git_config_available(cfg) |
| 155 | + msg = exc_info.value.msg |
| 156 | + assert "auth_method='none'" in msg |
| 157 | + assert "no token" in msg |
| 158 | + |
| 159 | + def test_valid_none_config_does_not_skip(self): |
| 160 | + cfg = _make_vip_config( |
| 161 | + GitTestConfig( |
| 162 | + clone_url="https://github.com/posit-dev/posit-cli.git", auth_method="none" |
| 163 | + ) |
| 164 | + ) |
| 165 | + result = git_ops.git_config_available(cfg) |
| 166 | + assert result is cfg.workbench.git_test |
| 167 | + |
| 168 | + |
| 169 | +class TestGitConfigSupportsPushingSkipMessage: |
| 170 | + def test_anonymous_auth_skip_message(self): |
| 171 | + git_cfg = GitTestConfig(clone_url="https://github.com/org/repo.git", auth_method="none") |
| 172 | + with pytest.raises(pytest.skip.Exception) as exc_info: |
| 173 | + git_ops.git_config_supports_pushing(git_cfg) |
| 174 | + msg = exc_info.value.msg |
| 175 | + assert "auth_method='none' is anonymous (read-only)" in msg |
| 176 | + assert "auth_method='https-token'" in msg |
| 177 | + assert "VIP_GIT_TOKEN" in msg |
| 178 | + |
| 179 | + def test_https_token_auth_does_not_skip(self): |
| 180 | + git_cfg = GitTestConfig( |
| 181 | + clone_url="https://github.com/org/repo.git", auth_method="https-token", token="tok" |
| 182 | + ) |
| 183 | + # Should not raise/skip. |
| 184 | + git_ops.git_config_supports_pushing(git_cfg) |
0 commit comments