optforge 0.3.7__tar.gz → 0.3.9__tar.gz
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.
- {optforge-0.3.7 → optforge-0.3.9}/Makefile +2 -2
- {optforge-0.3.7 → optforge-0.3.9}/PKG-INFO +7 -4
- {optforge-0.3.7 → optforge-0.3.9}/README.md +2 -2
- {optforge-0.3.7 → optforge-0.3.9}/pyproject.toml +8 -4
- optforge-0.3.9/src/optforge/_version.py +1 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/core/processes.py +1 -1
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/portcheck/binder.py +23 -7
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/portcheck/connector.py +22 -1
- {optforge-0.3.7/src/optforge/pycacheClean → optforge-0.3.9/src/optforge/pycacheclean}/cleaner.py +6 -3
- optforge-0.3.9/tests/test_cli.py +190 -0
- optforge-0.3.9/tests/test_portcheck.py +332 -0
- optforge-0.3.9/tests/test_processes.py +57 -0
- optforge-0.3.9/tests/test_pycacheclean.py +232 -0
- optforge-0.3.9/tests/test_version.py +15 -0
- optforge-0.3.7/src/optforge/_version.py +0 -1
- optforge-0.3.7/tests/test_cli.py +0 -35
- optforge-0.3.7/tests/test_portcheck.py +0 -76
- optforge-0.3.7/tests/test_pycacheclean.py +0 -105
- optforge-0.3.7/tests/test_version.py +0 -12
- {optforge-0.3.7 → optforge-0.3.9}/.gitignore +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/LICENSE +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/__init__.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/__main__.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/cli.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/core/__init__.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/core/cli.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/core/console.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/core/errors.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/core/formatting.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/core/net.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/core/redaction.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/core/version.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/diskcheck/__init__.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/diskcheck/cli.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/diskcheck/models.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/diskcheck/service.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/envcheck/__init__.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/envcheck/cli.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/envcheck/models.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/envcheck/service.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/killNotif/__init__.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/killNotif/cli.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/killNotif/core.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/killNotif/job.ps1 +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/portcheck/__init__.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/portcheck/cli.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/portcheck/models.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/portcheck/scanner.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/portcheck/service.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/portcheck/waiter.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/py.typed +0 -0
- {optforge-0.3.7/src/optforge/pycacheClean → optforge-0.3.9/src/optforge/pycacheclean}/__init__.py +0 -0
- {optforge-0.3.7/src/optforge/pycacheClean → optforge-0.3.9/src/optforge/pycacheclean}/cli.py +0 -0
- {optforge-0.3.7/src/optforge/pycacheClean → optforge-0.3.9/src/optforge/pycacheclean}/models.py +0 -0
- {optforge-0.3.7/src/optforge/pycacheClean → optforge-0.3.9/src/optforge/pycacheclean}/scanner.py +0 -0
- {optforge-0.3.7/src/optforge/pycacheClean → optforge-0.3.9/src/optforge/pycacheclean}/service.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/volume/__init__.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/volume/cli.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/src/optforge/volume/core.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/tests/test_console.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/tests/test_diskcheck.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/tests/test_envcheck.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/tests/test_formatting.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/tests/test_killnotif.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/tests/test_net.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/tests/test_redaction.py +0 -0
- {optforge-0.3.7 → optforge-0.3.9}/tests/test_volume.py +0 -0
|
@@ -9,7 +9,7 @@ help:
|
|
|
9
9
|
@echo " format Format with ruff"
|
|
10
10
|
@echo " format-check Verify formatting without changing files"
|
|
11
11
|
@echo " typecheck Run mypy"
|
|
12
|
-
@echo " test Run pytest"
|
|
12
|
+
@echo " test Run pytest with the coverage gate"
|
|
13
13
|
@echo " check lint + format-check + typecheck + test"
|
|
14
14
|
@echo " build Build sdist and wheel"
|
|
15
15
|
@echo " clean Remove caches and build artifacts"
|
|
@@ -30,7 +30,7 @@ typecheck:
|
|
|
30
30
|
$(UV) run mypy src
|
|
31
31
|
|
|
32
32
|
test:
|
|
33
|
-
$(UV) run pytest
|
|
33
|
+
$(UV) run pytest --cov=optforge --cov-report=term-missing
|
|
34
34
|
|
|
35
35
|
check: lint format-check typecheck test
|
|
36
36
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: optforge
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.9
|
|
4
4
|
Summary: Cross-platform developer CLI tools for ports, environment variables, disk usage, and Python cache cleanup.
|
|
5
5
|
Project-URL: Homepage, https://github.com/cmd-3324/OptForge
|
|
6
6
|
Project-URL: Repository, https://github.com/cmd-3324/OptForge
|
|
@@ -14,11 +14,14 @@ Classifier: Environment :: Console
|
|
|
14
14
|
Classifier: Intended Audience :: Developers
|
|
15
15
|
Classifier: Operating System :: OS Independent
|
|
16
16
|
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
20
|
Classifier: Programming Language :: Python :: 3.14
|
|
18
21
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
22
|
Classifier: Topic :: System :: Systems Administration
|
|
20
23
|
Classifier: Typing :: Typed
|
|
21
|
-
Requires-Python: >=3.
|
|
24
|
+
Requires-Python: >=3.11
|
|
22
25
|
Requires-Dist: psutil>=6.0.0
|
|
23
26
|
Requires-Dist: pycaw>=20240210; sys_platform == 'win32'
|
|
24
27
|
Requires-Dist: rich>=13.7.0
|
|
@@ -105,7 +108,7 @@ Most tools are designed to be simple, fast, and cross-platform; `killNotif` is W
|
|
|
105
108
|
|
|
106
109
|
## Installation
|
|
107
110
|
|
|
108
|
-
Python 3.
|
|
111
|
+
Python 3.11 or newer is required.
|
|
109
112
|
|
|
110
113
|
### Install from PyPI with pipx
|
|
111
114
|
|
|
@@ -265,7 +268,7 @@ make test
|
|
|
265
268
|
|
|
266
269
|
## Requirements
|
|
267
270
|
|
|
268
|
-
- Python 3.
|
|
271
|
+
- Python 3.11+
|
|
269
272
|
- Typer
|
|
270
273
|
- Rich
|
|
271
274
|
- psutil
|
|
@@ -72,7 +72,7 @@ Most tools are designed to be simple, fast, and cross-platform; `killNotif` is W
|
|
|
72
72
|
|
|
73
73
|
## Installation
|
|
74
74
|
|
|
75
|
-
Python 3.
|
|
75
|
+
Python 3.11 or newer is required.
|
|
76
76
|
|
|
77
77
|
### Install from PyPI with pipx
|
|
78
78
|
|
|
@@ -232,7 +232,7 @@ make test
|
|
|
232
232
|
|
|
233
233
|
## Requirements
|
|
234
234
|
|
|
235
|
-
- Python 3.
|
|
235
|
+
- Python 3.11+
|
|
236
236
|
- Typer
|
|
237
237
|
- Rich
|
|
238
238
|
- psutil
|
|
@@ -8,8 +8,8 @@ license-files = ["LICENSE"]
|
|
|
8
8
|
authors = [
|
|
9
9
|
{ name = "Max Miller", email = "ali.alipour4576@gmail.com" },
|
|
10
10
|
]
|
|
11
|
-
|
|
12
|
-
requires-python = ">=3.
|
|
11
|
+
|
|
12
|
+
requires-python = ">=3.11"
|
|
13
13
|
keywords = ["cli", "developer-tools", "ports", "environment", "disk", "pycache"]
|
|
14
14
|
classifiers = [
|
|
15
15
|
"Development Status :: 4 - Beta",
|
|
@@ -17,6 +17,9 @@ classifiers = [
|
|
|
17
17
|
"Intended Audience :: Developers",
|
|
18
18
|
"Operating System :: OS Independent",
|
|
19
19
|
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
20
23
|
"Programming Language :: Python :: 3.14",
|
|
21
24
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
22
25
|
"Topic :: System :: Systems Administration",
|
|
@@ -75,14 +78,14 @@ include = [
|
|
|
75
78
|
|
|
76
79
|
[tool.ruff]
|
|
77
80
|
line-length = 120
|
|
78
|
-
target-version = "
|
|
81
|
+
target-version = "py311"
|
|
79
82
|
src = ["src", "tests"]
|
|
80
83
|
|
|
81
84
|
[tool.ruff.lint]
|
|
82
85
|
select = ["E", "F", "I", "UP", "B", "SIM", "C4", "PIE", "RUF"]
|
|
83
86
|
|
|
84
87
|
[tool.mypy]
|
|
85
|
-
python_version = "3.
|
|
88
|
+
python_version = "3.11"
|
|
86
89
|
files = ["src"]
|
|
87
90
|
check_untyped_defs = true
|
|
88
91
|
disallow_untyped_defs = true
|
|
@@ -102,3 +105,4 @@ branch = true
|
|
|
102
105
|
|
|
103
106
|
[tool.coverage.report]
|
|
104
107
|
show_missing = true
|
|
108
|
+
fail_under = 75
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.3.9"
|
|
@@ -29,7 +29,7 @@ class ProcessNameResolver:
|
|
|
29
29
|
return cached
|
|
30
30
|
try:
|
|
31
31
|
resolved = self._factory(pid).name()
|
|
32
|
-
except psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess:
|
|
32
|
+
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
|
|
33
33
|
resolved = _UNKNOWN
|
|
34
34
|
self._cache[pid] = resolved
|
|
35
35
|
return resolved
|
|
@@ -9,6 +9,7 @@ from optforge.core.errors import OperationFailed
|
|
|
9
9
|
from optforge.core.net import Endpoint, resolve_endpoints
|
|
10
10
|
|
|
11
11
|
_WILDCARD_HOSTS = frozenset({"", "*", "any", "all"})
|
|
12
|
+
_WILDCARD_ADDRESSES = frozenset({"0.0.0.0", "::"})
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
class PortBinder:
|
|
@@ -23,16 +24,22 @@ class PortBinder:
|
|
|
23
24
|
* A successful probe is inherently racy: another process may take the
|
|
24
25
|
port after the probe closes. Callers must treat the answer as a
|
|
25
26
|
snapshot.
|
|
27
|
+
|
|
28
|
+
A host the caller named explicitly is never silently assumed free: an
|
|
29
|
+
unresolvable name is an error, because answering "free" for a typo is worse
|
|
30
|
+
than refusing to answer.
|
|
26
31
|
"""
|
|
27
32
|
|
|
28
33
|
def __init__(self, default_host: str = "0.0.0.0") -> None:
|
|
29
34
|
self._default_host = default_host
|
|
30
35
|
|
|
31
36
|
def is_free(self, port: int, host: str | None = None) -> bool:
|
|
32
|
-
"""Return ``True`` only if every resolved address for the host binds.
|
|
37
|
+
"""Return ``True`` only if every resolved address for the host binds.
|
|
38
|
+
|
|
39
|
+
Raises:
|
|
40
|
+
OperationFailed: if an explicit ``host`` cannot be resolved.
|
|
41
|
+
"""
|
|
33
42
|
endpoints = self._endpoints(port, host or self._default_host)
|
|
34
|
-
if not endpoints:
|
|
35
|
-
return True
|
|
36
43
|
return all(self._can_bind(endpoint) for endpoint in endpoints)
|
|
37
44
|
|
|
38
45
|
def is_free_on_all_interfaces(self, port: int) -> bool:
|
|
@@ -40,13 +47,22 @@ class PortBinder:
|
|
|
40
47
|
return self.is_free(port, "0.0.0.0") and self.is_free(port, "::")
|
|
41
48
|
|
|
42
49
|
def _endpoints(self, port: int, host: str) -> list[Endpoint]:
|
|
43
|
-
|
|
50
|
+
"""Return the addresses that should be probed for ``host``.
|
|
51
|
+
|
|
52
|
+
A wildcard request that resolves to nothing means the machine has no
|
|
53
|
+
address of that family (IPv6 disabled, for example). There is nothing
|
|
54
|
+
to bind, so the port cannot be occupied there. An explicit host is a
|
|
55
|
+
different question: its failure to resolve is information the caller
|
|
56
|
+
needs, not a free port.
|
|
57
|
+
"""
|
|
58
|
+
lowered = host.lower()
|
|
59
|
+
target = None if lowered in _WILDCARD_HOSTS else host
|
|
44
60
|
try:
|
|
45
61
|
return resolve_endpoints(target or "", port, passive=True)
|
|
46
62
|
except OperationFailed:
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
63
|
+
if lowered in _WILDCARD_HOSTS or lowered in _WILDCARD_ADDRESSES:
|
|
64
|
+
return []
|
|
65
|
+
raise
|
|
50
66
|
|
|
51
67
|
def _can_bind(self, endpoint: Endpoint) -> bool:
|
|
52
68
|
try:
|
|
@@ -32,14 +32,17 @@ class Connector:
|
|
|
32
32
|
return ConnectResult(ok=False, error=str(exc))
|
|
33
33
|
|
|
34
34
|
last_error = "no endpoint accepted the connection"
|
|
35
|
+
remaining_endpoints = len(endpoints)
|
|
35
36
|
for endpoint in endpoints:
|
|
36
37
|
remaining = timeout - (self._clock() - start)
|
|
37
38
|
if remaining <= 0:
|
|
38
39
|
last_error = f"timed out after {timeout:g}s"
|
|
39
40
|
break
|
|
41
|
+
attempt = _attempt_budget(remaining, remaining_endpoints)
|
|
42
|
+
remaining_endpoints -= 1
|
|
40
43
|
try:
|
|
41
44
|
with socket.socket(endpoint.family, socket.SOCK_STREAM) as sock:
|
|
42
|
-
sock.settimeout(
|
|
45
|
+
sock.settimeout(attempt)
|
|
43
46
|
sock.connect(endpoint.sockaddr)
|
|
44
47
|
return ConnectResult(
|
|
45
48
|
ok=True,
|
|
@@ -52,6 +55,24 @@ class Connector:
|
|
|
52
55
|
return ConnectResult(ok=False, error=last_error)
|
|
53
56
|
|
|
54
57
|
|
|
58
|
+
_MIN_ATTEMPT_SECONDS = 0.05
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _attempt_budget(remaining: float, endpoints_left: int) -> float:
|
|
62
|
+
"""Share the remaining deadline between the endpoints still to be tried.
|
|
63
|
+
|
|
64
|
+
Handing the whole remaining budget to one attempt lets a single blackholed
|
|
65
|
+
address (a dropped SYN, or a host that resets silently) consume the deadline,
|
|
66
|
+
so later endpoints are never contacted. Each attempt instead gets its fair
|
|
67
|
+
share, with a small floor so a long endpoint list cannot shrink every attempt
|
|
68
|
+
to nothing.
|
|
69
|
+
"""
|
|
70
|
+
if endpoints_left <= 1:
|
|
71
|
+
return remaining
|
|
72
|
+
share = remaining / endpoints_left
|
|
73
|
+
return max(share, min(remaining, _MIN_ATTEMPT_SECONDS))
|
|
74
|
+
|
|
75
|
+
|
|
55
76
|
def _reason(exc: OSError) -> str:
|
|
56
77
|
if isinstance(exc, ConnectionRefusedError):
|
|
57
78
|
return "connection refused"
|
{optforge-0.3.7/src/optforge/pycacheClean → optforge-0.3.9/src/optforge/pycacheclean}/cleaner.py
RENAMED
|
@@ -30,13 +30,16 @@ class CacheCleaner:
|
|
|
30
30
|
def on_error(
|
|
31
31
|
_func: Any,
|
|
32
32
|
path: str,
|
|
33
|
-
|
|
33
|
+
exc_info: tuple[type[BaseException], BaseException, Any],
|
|
34
34
|
errors: list[str] = errors,
|
|
35
35
|
) -> None:
|
|
36
|
-
errors.append(f"{path}: {
|
|
36
|
+
errors.append(f"{path}: {exc_info[1]}")
|
|
37
37
|
|
|
38
38
|
try:
|
|
39
|
-
|
|
39
|
+
# ``onerror`` is deprecated in favour of ``onexc`` from 3.12 on,
|
|
40
|
+
# but it is the only spelling that exists on 3.11. Switch when
|
|
41
|
+
# the floor moves to 3.12.
|
|
42
|
+
self._remover(target.path, onerror=on_error)
|
|
40
43
|
except OSError as exc:
|
|
41
44
|
failed.append(CleanFailure(path=target.path, error=str(exc)))
|
|
42
45
|
continue
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import socket
|
|
5
|
+
import sys
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
import pytest
|
|
9
|
+
from typer.testing import CliRunner
|
|
10
|
+
|
|
11
|
+
from optforge.cli import app as dispatcher
|
|
12
|
+
from optforge.core.version import get_version
|
|
13
|
+
from optforge.diskcheck.cli import app as diskcheck_app
|
|
14
|
+
from optforge.envcheck.cli import app as envcheck_app
|
|
15
|
+
from optforge.killNotif import cli as killnotif_cli
|
|
16
|
+
from optforge.portcheck.cli import app as portcheck_app
|
|
17
|
+
from optforge.pycacheclean.cli import app as pycache_app
|
|
18
|
+
|
|
19
|
+
runner = CliRunner()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_dispatcher_version() -> None:
|
|
23
|
+
result = runner.invoke(dispatcher, ["--version"])
|
|
24
|
+
assert result.exit_code == 0
|
|
25
|
+
assert get_version() in result.stdout
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_dispatcher_exposes_killnotif() -> None:
|
|
29
|
+
result = runner.invoke(dispatcher, ["killNotif", "--help"])
|
|
30
|
+
assert result.exit_code == 0
|
|
31
|
+
assert "notifications" in result.stdout.lower()
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_pycache_options_after_positional(tmp_path: Path) -> None:
|
|
35
|
+
(tmp_path / "__pycache__").mkdir()
|
|
36
|
+
result = runner.invoke(pycache_app, [str(tmp_path), "--dry-run", "--json"])
|
|
37
|
+
assert result.exit_code == 0
|
|
38
|
+
assert (tmp_path / "__pycache__").exists()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _free_port() -> int:
|
|
42
|
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as probe:
|
|
43
|
+
probe.bind(("127.0.0.1", 0))
|
|
44
|
+
return int(probe.getsockname()[1])
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_portcheck_help() -> None:
|
|
48
|
+
result = runner.invoke(portcheck_app, ["--help"])
|
|
49
|
+
assert result.exit_code == 0
|
|
50
|
+
assert "portcheck" in result.output.lower()
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_portcheck_version() -> None:
|
|
54
|
+
result = runner.invoke(portcheck_app, ["--version"])
|
|
55
|
+
assert result.exit_code == 0
|
|
56
|
+
assert get_version() in result.output
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_portcheck_check_answers_yes_for_a_free_port() -> None:
|
|
60
|
+
result = runner.invoke(portcheck_app, ["check", str(_free_port()), "-H", "127.0.0.1"])
|
|
61
|
+
assert result.exit_code == 0
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_portcheck_check_answers_no_for_a_busy_port() -> None:
|
|
65
|
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server:
|
|
66
|
+
server.bind(("127.0.0.1", 0))
|
|
67
|
+
server.listen(1)
|
|
68
|
+
port = str(server.getsockname()[1])
|
|
69
|
+
assert runner.invoke(portcheck_app, ["check", port, "--expect", "used", "-H", "127.0.0.1"]).exit_code == 0
|
|
70
|
+
assert runner.invoke(portcheck_app, ["check", port, "--expect", "free", "-H", "127.0.0.1"]).exit_code == 1
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def test_portcheck_find_answers_no_for_a_free_port() -> None:
|
|
74
|
+
assert runner.invoke(portcheck_app, ["find", str(_free_port())]).exit_code == 1
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def test_portcheck_rejects_an_out_of_range_port() -> None:
|
|
78
|
+
assert runner.invoke(portcheck_app, ["check", "70000"]).exit_code == 2
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_portcheck_requires_a_port() -> None:
|
|
82
|
+
assert runner.invoke(portcheck_app, ["check"]).exit_code == 2
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_killnotif_help() -> None:
|
|
86
|
+
result = runner.invoke(killnotif_cli.app, ["--help"])
|
|
87
|
+
assert result.exit_code == 0
|
|
88
|
+
assert "notifications" in result.output.lower()
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def test_killnotif_clears_and_reports(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
92
|
+
monkeypatch.setattr(sys, "platform", "win32")
|
|
93
|
+
monkeypatch.setattr(killnotif_cli, "_clear", lambda _aumid: 2)
|
|
94
|
+
|
|
95
|
+
result = runner.invoke(killnotif_cli.app, [])
|
|
96
|
+
assert result.exit_code == 0
|
|
97
|
+
assert "Cleared 2 sender(s)" in result.output
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def test_killnotif_reports_json(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
101
|
+
monkeypatch.setattr(sys, "platform", "win32")
|
|
102
|
+
monkeypatch.setattr(killnotif_cli, "_clear", lambda _aumid: 2)
|
|
103
|
+
|
|
104
|
+
result = runner.invoke(killnotif_cli.app, ["--json"])
|
|
105
|
+
assert result.exit_code == 0
|
|
106
|
+
assert json.loads(result.output)["cleared"] == 2
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def test_killnotif_is_quiet_when_asked(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
110
|
+
monkeypatch.setattr(sys, "platform", "win32")
|
|
111
|
+
monkeypatch.setattr(killnotif_cli, "_clear", lambda _aumid: 0)
|
|
112
|
+
|
|
113
|
+
result = runner.invoke(killnotif_cli.app, ["--quiet"])
|
|
114
|
+
assert result.exit_code == 0
|
|
115
|
+
assert result.output.strip() == ""
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def test_killnotif_refuses_on_other_platforms(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
119
|
+
monkeypatch.setattr(sys, "platform", "linux")
|
|
120
|
+
assert runner.invoke(killnotif_cli.app, []).exit_code == 3
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def test_killnotif_rejects_unknown_options() -> None:
|
|
124
|
+
assert runner.invoke(killnotif_cli.app, ["--nope"]).exit_code == 2
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def test_envcheck_help() -> None:
|
|
128
|
+
result = runner.invoke(envcheck_app, ["--help"])
|
|
129
|
+
assert result.exit_code == 0
|
|
130
|
+
assert "environment" in result.output.lower()
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def test_envcheck_redacts_secrets_in_json(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
134
|
+
monkeypatch.setenv("OPTFORGE_SMOKE_VISIBLE", "hello")
|
|
135
|
+
monkeypatch.setenv("OPTFORGE_SMOKE_TOKEN", "s3cret")
|
|
136
|
+
|
|
137
|
+
result = runner.invoke(envcheck_app, ["--prefix", "OPTFORGE_SMOKE", "--json"])
|
|
138
|
+
assert result.exit_code == 0
|
|
139
|
+
entries = {entry["key"]: entry for entry in json.loads(result.output)}
|
|
140
|
+
assert entries["OPTFORGE_SMOKE_VISIBLE"]["value"] == "hello"
|
|
141
|
+
assert entries["OPTFORGE_SMOKE_TOKEN"]["value"] == "<redacted>"
|
|
142
|
+
assert entries["OPTFORGE_SMOKE_TOKEN"]["redacted"] is True
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def test_envcheck_dotenv_format(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
146
|
+
monkeypatch.setenv("OPTFORGE_SMOKE_VISIBLE", "hello")
|
|
147
|
+
|
|
148
|
+
result = runner.invoke(envcheck_app, ["--prefix", "OPTFORGE_SMOKE_VISIBLE", "--format", "dotenv"])
|
|
149
|
+
assert result.exit_code == 0
|
|
150
|
+
assert "OPTFORGE_SMOKE_VISIBLE=hello" in result.output
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def test_envcheck_rejects_an_unknown_format() -> None:
|
|
154
|
+
assert runner.invoke(envcheck_app, ["--format", "yaml"]).exit_code == 2
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def test_pycache_help() -> None:
|
|
158
|
+
assert runner.invoke(pycache_app, ["--help"]).exit_code == 0
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def test_pycache_deletes_with_yes(tmp_path: Path) -> None:
|
|
162
|
+
(tmp_path / "pkg" / "__pycache__").mkdir(parents=True)
|
|
163
|
+
|
|
164
|
+
result = runner.invoke(pycache_app, [str(tmp_path), "--yes", "--json"])
|
|
165
|
+
assert result.exit_code == 0
|
|
166
|
+
assert len(json.loads(result.output)["removed"]) == 1
|
|
167
|
+
assert not (tmp_path / "pkg" / "__pycache__").exists()
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def test_pycache_refuses_to_delete_without_a_terminal(tmp_path: Path) -> None:
|
|
171
|
+
(tmp_path / "pkg" / "__pycache__").mkdir(parents=True)
|
|
172
|
+
|
|
173
|
+
result = runner.invoke(pycache_app, [str(tmp_path)])
|
|
174
|
+
assert result.exit_code == 2
|
|
175
|
+
assert (tmp_path / "pkg" / "__pycache__").exists()
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def test_pycache_reports_nothing_found_as_json(tmp_path: Path) -> None:
|
|
179
|
+
result = runner.invoke(pycache_app, [str(tmp_path), "--json"])
|
|
180
|
+
assert result.exit_code == 0
|
|
181
|
+
assert json.loads(result.output)["removed"] == []
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def test_pycache_rejects_a_bad_depth(tmp_path: Path) -> None:
|
|
185
|
+
assert runner.invoke(pycache_app, [str(tmp_path), "--max-depth", "0"]).exit_code == 2
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def test_diskcheck_options_after_positional(tmp_path: Path) -> None:
|
|
189
|
+
result = runner.invoke(diskcheck_app, [str(tmp_path), "--json"])
|
|
190
|
+
assert result.exit_code == 0
|