collab-runtime 0.2.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- collab/__init__.py +77 -0
- collab/__main__.py +11 -0
- collab_runtime-0.2.9.dist-info/METADATA +218 -0
- collab_runtime-0.2.9.dist-info/RECORD +82 -0
- collab_runtime-0.2.9.dist-info/WHEEL +5 -0
- collab_runtime-0.2.9.dist-info/entry_points.txt +3 -0
- collab_runtime-0.2.9.dist-info/licenses/LICENSE +21 -0
- collab_runtime-0.2.9.dist-info/top_level.txt +10 -0
- scripts/cleanup.py +395 -0
- scripts/collab_git_hook.py +190 -0
- scripts/format_code.py +594 -0
- scripts/generate_tests.py +560 -0
- scripts/validate_code.py +1397 -0
- src/__init__.py +4 -0
- src/dashboard/index.html +1131 -0
- src/live_locks_watcher.py +1982 -0
- src/lock_client.py +4268 -0
- src/logging_config.py +259 -0
- src/main.py +436 -0
- tests/backend/__init__.py +0 -0
- tests/backend/functional/__init__.py +0 -0
- tests/backend/functional/test_package_imports.py +43 -0
- tests/backend/integration/__init__.py +0 -0
- tests/backend/integration/test_cli_contract_parity.py +220 -0
- tests/backend/performance/__init__.py +0 -0
- tests/backend/reliability/__init__.py +0 -0
- tests/backend/security/__init__.py +0 -0
- tests/backend/unit/live_locks_watcher/__init__.py +5 -0
- tests/backend/unit/live_locks_watcher/_helpers.py +123 -0
- tests/backend/unit/live_locks_watcher/conftest.py +18 -0
- tests/backend/unit/live_locks_watcher/test_live_locks_watcher_dashboard.py +188 -0
- tests/backend/unit/live_locks_watcher/test_live_locks_watcher_developer.py +56 -0
- tests/backend/unit/live_locks_watcher/test_live_locks_watcher_graceful_shutdown.py +459 -0
- tests/backend/unit/live_locks_watcher/test_live_locks_watcher_main.py +1925 -0
- tests/backend/unit/live_locks_watcher/test_live_locks_watcher_module.py +187 -0
- tests/backend/unit/live_locks_watcher/test_live_locks_watcher_multi_session.py +320 -0
- tests/backend/unit/live_locks_watcher/test_live_locks_watcher_notify.py +67 -0
- tests/backend/unit/live_locks_watcher/test_live_locks_watcher_parsing.py +155 -0
- tests/backend/unit/live_locks_watcher/test_live_locks_watcher_process_helpers.py +684 -0
- tests/backend/unit/live_locks_watcher/test_live_locks_watcher_processing.py +173 -0
- tests/backend/unit/live_locks_watcher/test_live_locks_watcher_prompt_abort.py +71 -0
- tests/backend/unit/live_locks_watcher/test_live_locks_watcher_reconcile.py +516 -0
- tests/backend/unit/live_locks_watcher/test_live_locks_watcher_scan.py +296 -0
- tests/backend/unit/lock_client/__init__.py +1 -0
- tests/backend/unit/lock_client/_helpers.py +132 -0
- tests/backend/unit/lock_client/test_lock_client_acquire.py +214 -0
- tests/backend/unit/lock_client/test_lock_client_active.py +104 -0
- tests/backend/unit/lock_client/test_lock_client_api.py +63 -0
- tests/backend/unit/lock_client/test_lock_client_cli.py +682 -0
- tests/backend/unit/lock_client/test_lock_client_daemon.py +3730 -0
- tests/backend/unit/lock_client/test_lock_client_dashboard.py +438 -0
- tests/backend/unit/lock_client/test_lock_client_discover.py +241 -0
- tests/backend/unit/lock_client/test_lock_client_force_release.py +354 -0
- tests/backend/unit/lock_client/test_lock_client_helper_branches.py +1890 -0
- tests/backend/unit/lock_client/test_lock_client_history.py +301 -0
- tests/backend/unit/lock_client/test_lock_client_isolation.py +316 -0
- tests/backend/unit/lock_client/test_lock_client_pid.py +75 -0
- tests/backend/unit/lock_client/test_lock_client_reconcile.py +464 -0
- tests/backend/unit/lock_client/test_lock_client_release.py +77 -0
- tests/backend/unit/lock_client/test_lock_client_shutdown.py +1110 -0
- tests/backend/unit/lock_client/test_lock_client_utils.py +474 -0
- tests/backend/unit/lock_client/test_lock_client_watch.py +866 -0
- tests/backend/unit/scripts/__init__.py +1 -0
- tests/backend/unit/scripts/_helpers.py +42 -0
- tests/backend/unit/scripts/test_cleanup.py +285 -0
- tests/backend/unit/scripts/test_collab_git_hook.py +280 -0
- tests/backend/unit/scripts/test_collab_git_hook_ported.py +50 -0
- tests/backend/unit/scripts/test_format_code.py +368 -0
- tests/backend/unit/scripts/test_format_code_ported.py +177 -0
- tests/backend/unit/scripts/test_generate_tests.py +305 -0
- tests/backend/unit/scripts/test_hook_templates.py +357 -0
- tests/backend/unit/scripts/test_setup_hook_overlay.py +95 -0
- tests/backend/unit/scripts/test_validate_code.py +867 -0
- tests/backend/unit/scripts/test_validate_code_ported.py +237 -0
- tests/backend/unit/test_entrypoints_main_run.py +83 -0
- tests/backend/unit/test_logging_config.py +529 -0
- tests/backend/unit/test_main_watch_pid_file.py +278 -0
- tests/conftest.py +167 -0
- tests/frontend/__init__.py +0 -0
- tests/frontend/jest/__init__.py +0 -0
- tests/frontend/playwright/__init__.py +0 -0
- tests/packaging/test_smoke_install.py +76 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"""Additional ported coverage tests for scripts/validate_code.py."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import shutil
|
|
6
|
+
from unittest.mock import MagicMock
|
|
7
|
+
|
|
8
|
+
from tests.backend.unit.scripts._helpers import load_script_module
|
|
9
|
+
|
|
10
|
+
validate_code = load_script_module(
|
|
11
|
+
"validate_code.py", "validate_code_ported_under_test"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class TestValidatePythonBackendPaths:
|
|
16
|
+
def test_full_mode_no_files(self, monkeypatch):
|
|
17
|
+
monkeypatch.setattr(
|
|
18
|
+
validate_code,
|
|
19
|
+
"run_command",
|
|
20
|
+
lambda cmd, desc, **kwargs: (True, ""),
|
|
21
|
+
)
|
|
22
|
+
monkeypatch.setattr(
|
|
23
|
+
validate_code.os.path,
|
|
24
|
+
"exists",
|
|
25
|
+
lambda p: p == "coverage.xml",
|
|
26
|
+
)
|
|
27
|
+
assert validate_code.validate_python_backend(quick=False, files=None) is True
|
|
28
|
+
|
|
29
|
+
def test_quick_with_test_files(self, monkeypatch):
|
|
30
|
+
monkeypatch.setattr(
|
|
31
|
+
validate_code,
|
|
32
|
+
"run_command",
|
|
33
|
+
lambda cmd, desc, **kwargs: (True, ""),
|
|
34
|
+
)
|
|
35
|
+
monkeypatch.setattr(
|
|
36
|
+
validate_code.os.path,
|
|
37
|
+
"exists",
|
|
38
|
+
lambda p: p == "coverage.xml",
|
|
39
|
+
)
|
|
40
|
+
assert (
|
|
41
|
+
validate_code.validate_python_backend(
|
|
42
|
+
quick=True,
|
|
43
|
+
files=["tests/backend/unit/test_foo.py", "src/main.py"],
|
|
44
|
+
)
|
|
45
|
+
is True
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
def test_quick_source_only_full_suite(self, monkeypatch):
|
|
49
|
+
monkeypatch.setattr(
|
|
50
|
+
validate_code,
|
|
51
|
+
"run_command",
|
|
52
|
+
lambda cmd, desc, **kwargs: (True, ""),
|
|
53
|
+
)
|
|
54
|
+
monkeypatch.setattr(
|
|
55
|
+
validate_code.os.path,
|
|
56
|
+
"exists",
|
|
57
|
+
lambda p: p == "coverage.xml",
|
|
58
|
+
)
|
|
59
|
+
monkeypatch.setattr(
|
|
60
|
+
validate_code,
|
|
61
|
+
"detect_changed_scopes",
|
|
62
|
+
lambda *args, **kwargs: {
|
|
63
|
+
"full_suite": True,
|
|
64
|
+
"backend": [],
|
|
65
|
+
"frontend": [],
|
|
66
|
+
"reason": "x",
|
|
67
|
+
"changed_files": [],
|
|
68
|
+
},
|
|
69
|
+
)
|
|
70
|
+
assert (
|
|
71
|
+
validate_code.validate_python_backend(
|
|
72
|
+
quick=True,
|
|
73
|
+
files=["src/main.py"],
|
|
74
|
+
)
|
|
75
|
+
is True
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
def test_quick_no_files_backend_scope(self, monkeypatch):
|
|
79
|
+
monkeypatch.setattr(
|
|
80
|
+
validate_code,
|
|
81
|
+
"run_command",
|
|
82
|
+
lambda cmd, desc, **kwargs: (True, ""),
|
|
83
|
+
)
|
|
84
|
+
monkeypatch.setattr(
|
|
85
|
+
validate_code.os.path,
|
|
86
|
+
"exists",
|
|
87
|
+
lambda p: p == "coverage.xml",
|
|
88
|
+
)
|
|
89
|
+
monkeypatch.setattr(
|
|
90
|
+
validate_code,
|
|
91
|
+
"detect_changed_scopes",
|
|
92
|
+
lambda *args, **kwargs: {
|
|
93
|
+
"full_suite": False,
|
|
94
|
+
"backend": ["tests/backend/unit/"],
|
|
95
|
+
"frontend": [],
|
|
96
|
+
"reason": None,
|
|
97
|
+
"changed_files": ["src/main.py"],
|
|
98
|
+
},
|
|
99
|
+
)
|
|
100
|
+
assert validate_code.validate_python_backend(quick=True, files=None) is True
|
|
101
|
+
|
|
102
|
+
def test_quick_no_relevant_scopes_skips_tests(self, monkeypatch):
|
|
103
|
+
monkeypatch.setattr(
|
|
104
|
+
validate_code,
|
|
105
|
+
"run_command",
|
|
106
|
+
lambda cmd, desc, **kwargs: (True, ""),
|
|
107
|
+
)
|
|
108
|
+
monkeypatch.setattr(
|
|
109
|
+
validate_code.os.path,
|
|
110
|
+
"exists",
|
|
111
|
+
lambda p: p == "coverage.xml",
|
|
112
|
+
)
|
|
113
|
+
monkeypatch.setattr(
|
|
114
|
+
validate_code,
|
|
115
|
+
"detect_changed_scopes",
|
|
116
|
+
lambda *args, **kwargs: {
|
|
117
|
+
"full_suite": False,
|
|
118
|
+
"backend": [],
|
|
119
|
+
"frontend": [],
|
|
120
|
+
"reason": None,
|
|
121
|
+
"changed_files": [],
|
|
122
|
+
},
|
|
123
|
+
)
|
|
124
|
+
assert (
|
|
125
|
+
validate_code.validate_python_backend(
|
|
126
|
+
quick=True,
|
|
127
|
+
files=["src/main.py"],
|
|
128
|
+
)
|
|
129
|
+
is True
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def test_validate_python_backend_expands_directory_targets(tmp_path, monkeypatch):
|
|
134
|
+
pkg = tmp_path / "pkg"
|
|
135
|
+
pkg.mkdir(parents=True, exist_ok=True)
|
|
136
|
+
(pkg / "mod.py").write_text("x = 1\n", encoding="utf-8")
|
|
137
|
+
|
|
138
|
+
commands = []
|
|
139
|
+
|
|
140
|
+
def _fake_run_command(cmd, desc, **kwargs):
|
|
141
|
+
commands.append(cmd)
|
|
142
|
+
return True, ""
|
|
143
|
+
|
|
144
|
+
monkeypatch.setattr(validate_code, "run_command", _fake_run_command)
|
|
145
|
+
monkeypatch.setattr(validate_code.os.path, "exists", lambda p: p == "coverage.xml")
|
|
146
|
+
|
|
147
|
+
result = validate_code.validate_python_backend(quick=False, files=[str(pkg)])
|
|
148
|
+
assert result is True
|
|
149
|
+
assert any(cmd and cmd[0] == "isort" for cmd in commands)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def test_diff_cover_not_installed_soft_passes(monkeypatch):
|
|
153
|
+
monkeypatch.setattr(validate_code.os.path, "exists", lambda p: p == "coverage.xml")
|
|
154
|
+
|
|
155
|
+
def mock_run(cmd, desc, **kwargs):
|
|
156
|
+
if "diff-cover" in cmd and "--version" in cmd:
|
|
157
|
+
return False, "not found"
|
|
158
|
+
return True, ""
|
|
159
|
+
|
|
160
|
+
monkeypatch.setattr(validate_code, "run_command", mock_run)
|
|
161
|
+
result = validate_code.validate_python_backend(quick=False, files=None)
|
|
162
|
+
assert result is True
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def test_diff_cover_fails_reports_failure(monkeypatch):
|
|
166
|
+
monkeypatch.setattr(validate_code.os.path, "exists", lambda p: p == "coverage.xml")
|
|
167
|
+
|
|
168
|
+
def mock_run(cmd, desc, **kwargs):
|
|
169
|
+
if "diff-cover" in cmd and "--version" in cmd:
|
|
170
|
+
return True, "diff-cover 1.0"
|
|
171
|
+
if "diff-cover" in cmd and "coverage.xml" in cmd:
|
|
172
|
+
return False, "Coverage below 92%"
|
|
173
|
+
return True, ""
|
|
174
|
+
|
|
175
|
+
monkeypatch.setattr(validate_code, "run_command", mock_run)
|
|
176
|
+
result = validate_code.validate_python_backend(quick=False, files=None)
|
|
177
|
+
assert result is False
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def test_validate_others_prettier_not_installed(monkeypatch):
|
|
181
|
+
monkeypatch.setattr(
|
|
182
|
+
validate_code.subprocess,
|
|
183
|
+
"run",
|
|
184
|
+
lambda *a, **kw: MagicMock(returncode=1),
|
|
185
|
+
)
|
|
186
|
+
assert validate_code.validate_others(files=["docs/readme.md"]) is True
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def test_validate_others_prettier_installed(monkeypatch):
|
|
190
|
+
monkeypatch.setattr(
|
|
191
|
+
validate_code.subprocess,
|
|
192
|
+
"run",
|
|
193
|
+
lambda *a, **kw: MagicMock(returncode=0, stdout="ok", stderr=""),
|
|
194
|
+
)
|
|
195
|
+
monkeypatch.setattr(
|
|
196
|
+
validate_code,
|
|
197
|
+
"run_command",
|
|
198
|
+
lambda cmd, desc, **kw: (True, ""),
|
|
199
|
+
)
|
|
200
|
+
assert validate_code.validate_others(files=["docs/readme.md"]) is True
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def test_validate_frontend_branches(monkeypatch):
|
|
204
|
+
monkeypatch.setattr(shutil, "which", lambda name: None)
|
|
205
|
+
assert validate_code.validate_javascript_frontend(quick=False, files=None) is True
|
|
206
|
+
|
|
207
|
+
monkeypatch.setattr(shutil, "which", lambda name: "/usr/bin/npm")
|
|
208
|
+
monkeypatch.setattr(validate_code, "run_command", lambda *a, **kw: (True, ""))
|
|
209
|
+
monkeypatch.setattr(
|
|
210
|
+
validate_code,
|
|
211
|
+
"detect_changed_scopes",
|
|
212
|
+
lambda *args, **kwargs: {
|
|
213
|
+
"full_suite": False,
|
|
214
|
+
"backend": [],
|
|
215
|
+
"frontend": ["src/dashboard/app.js"],
|
|
216
|
+
"reason": None,
|
|
217
|
+
"changed_files": ["src/dashboard/app.js"],
|
|
218
|
+
},
|
|
219
|
+
)
|
|
220
|
+
assert (
|
|
221
|
+
validate_code.validate_javascript_frontend(
|
|
222
|
+
quick=True,
|
|
223
|
+
files=["src/dashboard/app.js"],
|
|
224
|
+
)
|
|
225
|
+
is True
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def test_detect_changed_scopes_reason_paths(monkeypatch):
|
|
230
|
+
monkeypatch.setattr(validate_code, "_get_changed_files", lambda: ["scripts/x.py"])
|
|
231
|
+
scopes = validate_code.detect_changed_scopes()
|
|
232
|
+
assert scopes["full_suite"] is True
|
|
233
|
+
assert "Infrastructure file changed" in (scopes["reason"] or "")
|
|
234
|
+
|
|
235
|
+
monkeypatch.setattr(validate_code, "_get_changed_files", lambda: ["src\\app.py"])
|
|
236
|
+
scopes = validate_code.detect_changed_scopes()
|
|
237
|
+
assert "src\\app.py" in scopes["changed_files"]
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""Tests for entrypoint modules run.py and src/main.py (implementation module)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import runpy
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def test_run_py_imports_main_function(monkeypatch):
|
|
11
|
+
called = {"n": 0}
|
|
12
|
+
|
|
13
|
+
def _fake_main():
|
|
14
|
+
called["n"] += 1
|
|
15
|
+
|
|
16
|
+
# run.py delegates to collab.__main__.main
|
|
17
|
+
monkeypatch.setattr("collab.__main__.main", _fake_main)
|
|
18
|
+
|
|
19
|
+
module_globals = runpy.run_path("run.py")
|
|
20
|
+
assert "main" in module_globals
|
|
21
|
+
|
|
22
|
+
module_globals["main"]()
|
|
23
|
+
assert called["n"] == 1
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_run_py_dunder_main_executes(monkeypatch):
|
|
27
|
+
called = {"n": 0}
|
|
28
|
+
|
|
29
|
+
def _fake_main():
|
|
30
|
+
called["n"] += 1
|
|
31
|
+
|
|
32
|
+
# run.py delegates to collab.__main__.main
|
|
33
|
+
monkeypatch.setattr("collab.__main__.main", _fake_main)
|
|
34
|
+
runpy.run_path("run.py", run_name="__main__")
|
|
35
|
+
assert called["n"] == 1
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_src_main_module_executes_as_script(monkeypatch):
|
|
39
|
+
monkeypatch.setattr("sys.argv", ["python", "daemon-status"])
|
|
40
|
+
# Ensure package 'src' is not present in sys.modules to avoid
|
|
41
|
+
# runpy runtime-warning about pre-imported package state.
|
|
42
|
+
import sys as _sys
|
|
43
|
+
|
|
44
|
+
saved = _sys.modules.pop("src", None)
|
|
45
|
+
try:
|
|
46
|
+
with pytest.raises(SystemExit) as exc:
|
|
47
|
+
runpy.run_module("src.main", run_name="__main__")
|
|
48
|
+
finally:
|
|
49
|
+
if saved is not None:
|
|
50
|
+
_sys.modules["src"] = saved
|
|
51
|
+
|
|
52
|
+
assert exc.value.code in (0, 1)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_src_main_success_path(monkeypatch):
|
|
56
|
+
import src.main as main_mod
|
|
57
|
+
|
|
58
|
+
monkeypatch.setattr(main_mod, "_run_cli", lambda: None)
|
|
59
|
+
main_mod.main()
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def test_src_main_exception_path(monkeypatch, capsys):
|
|
63
|
+
import src.main as main_mod
|
|
64
|
+
|
|
65
|
+
monkeypatch.setattr(
|
|
66
|
+
main_mod,
|
|
67
|
+
"_run_cli",
|
|
68
|
+
lambda: (_ for _ in ()).throw(RuntimeError("boom")),
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
exits = []
|
|
72
|
+
monkeypatch.setattr(
|
|
73
|
+
main_mod.sys,
|
|
74
|
+
"exit",
|
|
75
|
+
lambda code: exits.append(code) or (_ for _ in ()).throw(SystemExit(code)),
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
with pytest.raises(SystemExit) as exc:
|
|
79
|
+
main_mod.main()
|
|
80
|
+
|
|
81
|
+
assert exc.value.code == 1
|
|
82
|
+
assert exits == [1]
|
|
83
|
+
assert "FATAL: lock_client crashed" in capsys.readouterr().err
|