dint-cli 0.1.0__tar.gz → 0.1.1__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.
- {dint_cli-0.1.0 → dint_cli-0.1.1}/PKG-INFO +2 -2
- {dint_cli-0.1.0 → dint_cli-0.1.1}/README.md +1 -1
- {dint_cli-0.1.0 → dint_cli-0.1.1}/pyproject.toml +1 -1
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint/__init__.py +1 -1
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint/logbook/__init__.py +1 -1
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint/runtime.py +132 -11
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint/status.py +5 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint_cli.egg-info/PKG-INFO +2 -2
- {dint_cli-0.1.0 → dint_cli-0.1.1}/tests/test_runtime.py +83 -5
- {dint_cli-0.1.0 → dint_cli-0.1.1}/LICENSE +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/setup.cfg +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint/__main__.py +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint/cli.py +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint/engines/__init__.py +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint/engines/base.py +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint/engines/claude.py +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint/engines/codex.py +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint/engines/copilot.py +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint/engines/grok.py +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint/envfile.py +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint/jobs.py +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint/logbook/mcp.py +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint/logbook/rest.py +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint/proc.py +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint/router.py +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint/types.py +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint_cli.egg-info/SOURCES.txt +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint_cli.egg-info/dependency_links.txt +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint_cli.egg-info/entry_points.txt +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint_cli.egg-info/requires.txt +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/src/dint_cli.egg-info/top_level.txt +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/tests/test_cli.py +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/tests/test_engines.py +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/tests/test_envfile.py +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/tests/test_jobs.py +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/tests/test_logbook.py +0 -0
- {dint_cli-0.1.0 → dint_cli-0.1.1}/tests/test_router.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dint-cli
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.1
|
|
4
4
|
Summary: One local chat API over Claude, Codex, Grok, and Copilot. Codicent Logbook is the ledger.
|
|
5
5
|
Author-email: Johan Isaksson <johan@izaxon.com>
|
|
6
6
|
License: MIT License
|
|
@@ -83,7 +83,7 @@ Then, in any folder:
|
|
|
83
83
|
dint
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
That starts logbook-server and a background `dint serve` if they are not running, then opens a chat in the current directory (same idea as running `grok` in a new folder). Config lives in `~/.dint`. `dint grok "Summarize this repo"` is a one-shot; `dint status` checks Logbook, serve, and engine CLIs.
|
|
86
|
+
That starts logbook-server and a background `dint serve` if they are not running, then opens a chat in the current directory (same idea as running `grok` in a new folder). One logbook covers every folder on the machine — chats store `cwd`; you do not get a server per repo. Config lives in `~/.dint`. If port 5100 already has someone else's logbook, dint picks the next free port and writes it to `~/.dint/.env`. `dint grok "Summarize this repo"` is a one-shot; `dint status` checks Logbook, serve, and engine CLIs.
|
|
87
87
|
|
|
88
88
|
## Chat
|
|
89
89
|
|
|
@@ -38,7 +38,7 @@ Then, in any folder:
|
|
|
38
38
|
dint
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
That starts logbook-server and a background `dint serve` if they are not running, then opens a chat in the current directory (same idea as running `grok` in a new folder). Config lives in `~/.dint`. `dint grok "Summarize this repo"` is a one-shot; `dint status` checks Logbook, serve, and engine CLIs.
|
|
41
|
+
That starts logbook-server and a background `dint serve` if they are not running, then opens a chat in the current directory (same idea as running `grok` in a new folder). One logbook covers every folder on the machine — chats store `cwd`; you do not get a server per repo. Config lives in `~/.dint`. If port 5100 already has someone else's logbook, dint picks the next free port and writes it to `~/.dint/.env`. `dint grok "Summarize this repo"` is a one-shot; `dint status` checks Logbook, serve, and engine CLIs.
|
|
42
42
|
|
|
43
43
|
## Chat
|
|
44
44
|
|
|
@@ -28,7 +28,7 @@ def _env(name: str, default: str) -> str:
|
|
|
28
28
|
|
|
29
29
|
def default_logbook() -> Logbook:
|
|
30
30
|
url = _env("LOGBOOK_URL", "http://127.0.0.1:5100")
|
|
31
|
-
key = _env("LOGBOOK_API_KEY", "
|
|
31
|
+
key = _env("LOGBOOK_API_KEY", "")
|
|
32
32
|
if _env("LOGBOOK_TRANSPORT", "rest") == "mcp":
|
|
33
33
|
return McpLogbook(url, key)
|
|
34
34
|
return RestLogbook(url, key)
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import json
|
|
5
6
|
import os
|
|
6
7
|
import secrets
|
|
7
8
|
import shutil
|
|
9
|
+
import socket
|
|
8
10
|
import subprocess
|
|
9
11
|
import sys
|
|
10
12
|
import time
|
|
@@ -14,6 +16,7 @@ from pathlib import Path
|
|
|
14
16
|
from urllib.parse import urlparse
|
|
15
17
|
|
|
16
18
|
from dint.envfile import home_dir, home_env_path, write_env
|
|
19
|
+
from dint.logbook.rest import LogbookError, RestLogbook
|
|
17
20
|
|
|
18
21
|
LOGBOOK_INSTALL = "https://logbook.codicent.ai"
|
|
19
22
|
|
|
@@ -29,24 +32,37 @@ def ensure_defaults() -> None:
|
|
|
29
32
|
home_dir().mkdir(parents=True, exist_ok=True)
|
|
30
33
|
os.environ.setdefault("LOGBOOK_URL", "http://127.0.0.1:5100")
|
|
31
34
|
os.environ.setdefault("LOGBOOK_PROJECT", "dint")
|
|
32
|
-
if not os.environ.get("LOGBOOK_API_KEY", "").strip():
|
|
33
|
-
os.environ["LOGBOOK_API_KEY"] = secrets.token_urlsafe(16)
|
|
34
35
|
path = home_env_path()
|
|
35
36
|
if not path.is_file():
|
|
36
|
-
|
|
37
|
-
path,
|
|
38
|
-
{
|
|
39
|
-
"LOGBOOK_URL": os.environ["LOGBOOK_URL"],
|
|
40
|
-
"LOGBOOK_API_KEY": os.environ["LOGBOOK_API_KEY"],
|
|
41
|
-
"LOGBOOK_PROJECT": os.environ["LOGBOOK_PROJECT"],
|
|
42
|
-
},
|
|
43
|
-
)
|
|
37
|
+
_write_home_env()
|
|
44
38
|
os.environ.setdefault("DINT_ENV_FILE", str(path))
|
|
45
39
|
|
|
46
40
|
|
|
47
41
|
def ensure_logbook() -> None:
|
|
48
|
-
|
|
42
|
+
"""Reuse a reachable logbook we can auth to; otherwise start one for this machine.
|
|
43
|
+
|
|
44
|
+
One logbook-server process is one project/database. dint does not start a
|
|
45
|
+
server per repo: chats already store cwd. If :5100 is someone else's
|
|
46
|
+
logbook (401), pick the next free port and persist it in ~/.dint/.env.
|
|
47
|
+
"""
|
|
48
|
+
health = logbook_health()
|
|
49
|
+
if health is not None and _auth_ok():
|
|
50
|
+
running = str(health.get("project") or "")
|
|
51
|
+
ours = os.environ.get("LOGBOOK_PROJECT", "dint")
|
|
52
|
+
if running and running != ours:
|
|
53
|
+
_note(f"using logbook project={running} at {logbook_url()}")
|
|
49
54
|
return
|
|
55
|
+
if health is not None:
|
|
56
|
+
_note(f"{logbook_url()} is another logbook; starting dint's own")
|
|
57
|
+
_relocate_logbook_port()
|
|
58
|
+
elif not can_bind(logbook_host(), logbook_port()):
|
|
59
|
+
_relocate_logbook_port()
|
|
60
|
+
_spawn_logbook()
|
|
61
|
+
ensure_logbook_auth(logbook_health())
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _spawn_logbook() -> None:
|
|
65
|
+
_ensure_own_api_key()
|
|
50
66
|
binary = shutil.which("logbook-server")
|
|
51
67
|
if not binary:
|
|
52
68
|
raise RuntimeError(
|
|
@@ -74,11 +90,90 @@ def ensure_logbook() -> None:
|
|
|
74
90
|
)
|
|
75
91
|
|
|
76
92
|
|
|
93
|
+
def _auth_ok() -> bool:
|
|
94
|
+
rest = RestLogbook(logbook_url(), os.environ.get("LOGBOOK_API_KEY", "").strip())
|
|
95
|
+
try:
|
|
96
|
+
rest.get_messages(length=1)
|
|
97
|
+
return True
|
|
98
|
+
except LogbookError as e:
|
|
99
|
+
if "401" in str(e) or "Unauthorized" in str(e):
|
|
100
|
+
return False
|
|
101
|
+
raise RuntimeError(str(e)) from e
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def ensure_logbook_auth(health: dict | None = None) -> None:
|
|
105
|
+
if _auth_ok():
|
|
106
|
+
return
|
|
107
|
+
env_file = os.environ.get("DINT_ENV_FILE") or str(home_env_path())
|
|
108
|
+
running = ""
|
|
109
|
+
if health and health.get("project"):
|
|
110
|
+
running = f" Server project is {health['project']}."
|
|
111
|
+
raise RuntimeError(
|
|
112
|
+
f"logbook at {logbook_url()} rejected dint's API key.{running}\n"
|
|
113
|
+
f"dint read LOGBOOK_API_KEY from {env_file}."
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def _relocate_logbook_port() -> None:
|
|
118
|
+
host = logbook_host()
|
|
119
|
+
start = logbook_port() + 1
|
|
120
|
+
port = find_free_port(host, start)
|
|
121
|
+
os.environ["LOGBOOK_URL"] = f"{logbook_scheme()}://{host}:{port}"
|
|
122
|
+
_write_home_env()
|
|
123
|
+
_note(f"logbook {os.environ['LOGBOOK_URL']}")
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def find_free_port(host: str, start: int, *, count: int = 30) -> int:
|
|
127
|
+
bind_host = "127.0.0.1" if host in {"localhost", "127.0.0.1", "::1"} else host
|
|
128
|
+
for port in range(start, start + count):
|
|
129
|
+
if probe(f"http://{bind_host}:{port}/health"):
|
|
130
|
+
continue
|
|
131
|
+
if can_bind(bind_host, port):
|
|
132
|
+
return port
|
|
133
|
+
raise RuntimeError(f"no free port in {start}-{start + count - 1} for logbook-server")
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def can_bind(host: str, port: int) -> bool:
|
|
137
|
+
bind_host = "127.0.0.1" if host in {"localhost", ""} else host
|
|
138
|
+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
139
|
+
try:
|
|
140
|
+
sock.bind((bind_host, port))
|
|
141
|
+
return True
|
|
142
|
+
except OSError:
|
|
143
|
+
return False
|
|
144
|
+
finally:
|
|
145
|
+
sock.close()
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _ensure_own_api_key() -> None:
|
|
149
|
+
if os.environ.get("LOGBOOK_API_KEY", "").strip():
|
|
150
|
+
return
|
|
151
|
+
os.environ["LOGBOOK_API_KEY"] = secrets.token_urlsafe(16)
|
|
152
|
+
_write_home_env()
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _write_home_env() -> None:
|
|
156
|
+
values = {
|
|
157
|
+
"LOGBOOK_URL": os.environ.get("LOGBOOK_URL", "http://127.0.0.1:5100"),
|
|
158
|
+
"LOGBOOK_PROJECT": os.environ.get("LOGBOOK_PROJECT", "dint"),
|
|
159
|
+
}
|
|
160
|
+
key = os.environ.get("LOGBOOK_API_KEY", "").strip()
|
|
161
|
+
if key:
|
|
162
|
+
values["LOGBOOK_API_KEY"] = key
|
|
163
|
+
values["DINT_JOBS_PORT"] = str(jobs_port())
|
|
164
|
+
write_env(home_env_path(), values)
|
|
165
|
+
|
|
166
|
+
|
|
77
167
|
def ensure_serve() -> None:
|
|
78
168
|
if os.environ.get("DINT_ROLE") == "serve":
|
|
79
169
|
return
|
|
80
170
|
if probe(jobs_url() + "/health"):
|
|
81
171
|
return
|
|
172
|
+
if not can_bind(jobs_host(), jobs_port()):
|
|
173
|
+
port = find_free_port(jobs_host(), jobs_port() + 1)
|
|
174
|
+
os.environ["DINT_JOBS_PORT"] = str(port)
|
|
175
|
+
_write_home_env()
|
|
176
|
+
_note(f"dint serve {jobs_url()}")
|
|
82
177
|
env = os.environ.copy()
|
|
83
178
|
env["DINT_ROLE"] = "serve"
|
|
84
179
|
pid = spawn_detached(
|
|
@@ -123,6 +218,18 @@ def logbook_url() -> str:
|
|
|
123
218
|
return os.environ.get("LOGBOOK_URL", "http://127.0.0.1:5100").rstrip("/")
|
|
124
219
|
|
|
125
220
|
|
|
221
|
+
def logbook_scheme() -> str:
|
|
222
|
+
return urlparse(logbook_url()).scheme or "http"
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def logbook_host() -> str:
|
|
226
|
+
return urlparse(logbook_url()).hostname or "127.0.0.1"
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def logbook_port() -> int:
|
|
230
|
+
return urlparse(logbook_url()).port or 5100
|
|
231
|
+
|
|
232
|
+
|
|
126
233
|
def jobs_host() -> str:
|
|
127
234
|
return os.environ.get("DINT_JOBS_HOST", "127.0.0.1")
|
|
128
235
|
|
|
@@ -141,6 +248,20 @@ def logbook_install_cmd() -> str:
|
|
|
141
248
|
return "curl -fsSL https://logbook.codicent.ai/install.sh | bash"
|
|
142
249
|
|
|
143
250
|
|
|
251
|
+
def logbook_health(*, timeout: float = 1.5) -> dict | None:
|
|
252
|
+
try:
|
|
253
|
+
req = urllib.request.Request(
|
|
254
|
+
logbook_url() + "/health",
|
|
255
|
+
method="GET",
|
|
256
|
+
headers={"Accept": "application/json"},
|
|
257
|
+
)
|
|
258
|
+
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
|
259
|
+
data = json.loads(resp.read().decode("utf-8") or "{}")
|
|
260
|
+
return data if isinstance(data, dict) else {"raw": data}
|
|
261
|
+
except (urllib.error.URLError, urllib.error.HTTPError, TimeoutError, OSError, json.JSONDecodeError):
|
|
262
|
+
return None
|
|
263
|
+
|
|
264
|
+
|
|
144
265
|
def probe(url: str, timeout: float = 1.5) -> bool:
|
|
145
266
|
try:
|
|
146
267
|
req = urllib.request.Request(url, method="GET", headers={"Accept": "application/json"})
|
|
@@ -36,6 +36,11 @@ def run_status() -> int:
|
|
|
36
36
|
print("auth: OK")
|
|
37
37
|
except LogbookError as e:
|
|
38
38
|
print(f"auth: FAIL {e}")
|
|
39
|
+
if "401" in str(e) or "Unauthorized" in str(e):
|
|
40
|
+
print(
|
|
41
|
+
"note: this URL is another logbook's key. Run `dint` and it will "
|
|
42
|
+
"start its own on the next free port, or put the server's key in ~/.dint/.env."
|
|
43
|
+
)
|
|
39
44
|
failed += 1
|
|
40
45
|
|
|
41
46
|
hook = jobs_url()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dint-cli
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.1
|
|
4
4
|
Summary: One local chat API over Claude, Codex, Grok, and Copilot. Codicent Logbook is the ledger.
|
|
5
5
|
Author-email: Johan Isaksson <johan@izaxon.com>
|
|
6
6
|
License: MIT License
|
|
@@ -83,7 +83,7 @@ Then, in any folder:
|
|
|
83
83
|
dint
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
That starts logbook-server and a background `dint serve` if they are not running, then opens a chat in the current directory (same idea as running `grok` in a new folder). Config lives in `~/.dint`. `dint grok "Summarize this repo"` is a one-shot; `dint status` checks Logbook, serve, and engine CLIs.
|
|
86
|
+
That starts logbook-server and a background `dint serve` if they are not running, then opens a chat in the current directory (same idea as running `grok` in a new folder). One logbook covers every folder on the machine — chats store `cwd`; you do not get a server per repo. Config lives in `~/.dint`. If port 5100 already has someone else's logbook, dint picks the next free port and writes it to `~/.dint/.env`. `dint grok "Summarize this repo"` is a one-shot; `dint status` checks Logbook, serve, and engine CLIs.
|
|
87
87
|
|
|
88
88
|
## Chat
|
|
89
89
|
|
|
@@ -5,14 +5,33 @@ from pathlib import Path
|
|
|
5
5
|
|
|
6
6
|
import pytest
|
|
7
7
|
|
|
8
|
+
from dint.logbook.rest import LogbookError
|
|
8
9
|
from dint.runtime import (
|
|
10
|
+
can_bind,
|
|
9
11
|
ensure_defaults,
|
|
10
12
|
ensure_logbook,
|
|
11
13
|
ensure_serve,
|
|
14
|
+
find_free_port,
|
|
12
15
|
pick_engine,
|
|
13
16
|
)
|
|
14
17
|
|
|
15
18
|
|
|
19
|
+
class _OkRest:
|
|
20
|
+
def __init__(self, *_a, **_k) -> None:
|
|
21
|
+
pass
|
|
22
|
+
|
|
23
|
+
def get_messages(self, length: int = 1) -> list:
|
|
24
|
+
return []
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class _UnauthorizedRest:
|
|
28
|
+
def __init__(self, *_a, **_k) -> None:
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
def get_messages(self, length: int = 1) -> list:
|
|
32
|
+
raise LogbookError('HTTP 401 GET /api/messages: {"error":"Unauthorized"}')
|
|
33
|
+
|
|
34
|
+
|
|
16
35
|
def test_ensure_defaults_writes_home_env(tmp_path, monkeypatch) -> None:
|
|
17
36
|
monkeypatch.setenv("DINT_HOME", str(tmp_path))
|
|
18
37
|
monkeypatch.delenv("LOGBOOK_API_KEY", raising=False)
|
|
@@ -22,12 +41,16 @@ def test_ensure_defaults_writes_home_env(tmp_path, monkeypatch) -> None:
|
|
|
22
41
|
text = (tmp_path / ".env").read_text(encoding="utf-8")
|
|
23
42
|
assert "LOGBOOK_PROJECT=dint" in text
|
|
24
43
|
assert "LOGBOOK_URL=http://127.0.0.1:5100" in text
|
|
25
|
-
assert
|
|
44
|
+
assert "LOGBOOK_API_KEY" not in text
|
|
26
45
|
assert os.environ["LOGBOOK_PROJECT"] == "dint"
|
|
27
46
|
|
|
28
47
|
|
|
29
48
|
def test_ensure_logbook_skips_when_healthy(monkeypatch) -> None:
|
|
30
|
-
monkeypatch.setattr(
|
|
49
|
+
monkeypatch.setattr(
|
|
50
|
+
"dint.runtime.logbook_health",
|
|
51
|
+
lambda **k: {"status": "healthy", "project": "test"},
|
|
52
|
+
)
|
|
53
|
+
monkeypatch.setattr("dint.runtime.RestLogbook", _OkRest)
|
|
31
54
|
|
|
32
55
|
def boom(*_a, **_k):
|
|
33
56
|
raise AssertionError("should not spawn")
|
|
@@ -36,9 +59,37 @@ def test_ensure_logbook_skips_when_healthy(monkeypatch) -> None:
|
|
|
36
59
|
ensure_logbook()
|
|
37
60
|
|
|
38
61
|
|
|
62
|
+
def test_ensure_logbook_foreign_starts_on_new_port(tmp_path, monkeypatch) -> None:
|
|
63
|
+
monkeypatch.setenv("DINT_HOME", str(tmp_path))
|
|
64
|
+
monkeypatch.setenv("LOGBOOK_URL", "http://127.0.0.1:5100")
|
|
65
|
+
monkeypatch.setenv("LOGBOOK_API_KEY", "dint-key")
|
|
66
|
+
monkeypatch.setenv("LOGBOOK_PROJECT", "dint")
|
|
67
|
+
|
|
68
|
+
def health(**_k):
|
|
69
|
+
if os.environ.get("LOGBOOK_URL", "").endswith(":5100"):
|
|
70
|
+
return {"status": "healthy", "project": "test"}
|
|
71
|
+
return None
|
|
72
|
+
|
|
73
|
+
monkeypatch.setattr("dint.runtime.logbook_health", health)
|
|
74
|
+
monkeypatch.setattr("dint.runtime.RestLogbook", _UnauthorizedRest)
|
|
75
|
+
monkeypatch.setattr("dint.runtime.find_free_port", lambda host, start, count=30: 5101)
|
|
76
|
+
monkeypatch.setattr("dint.runtime.ensure_logbook_auth", lambda health=None: None)
|
|
77
|
+
monkeypatch.setattr("dint.runtime.wait_for", lambda url, timeout=12: True)
|
|
78
|
+
monkeypatch.setattr(
|
|
79
|
+
"dint.runtime.shutil.which",
|
|
80
|
+
lambda name: "/bin/logbook-server" if name == "logbook-server" else None,
|
|
81
|
+
)
|
|
82
|
+
monkeypatch.setattr("dint.runtime.spawn_detached", lambda argv, **k: 9)
|
|
83
|
+
ensure_logbook()
|
|
84
|
+
assert os.environ["LOGBOOK_URL"] == "http://127.0.0.1:5101"
|
|
85
|
+
assert "5101" in (tmp_path / ".env").read_text(encoding="utf-8")
|
|
86
|
+
|
|
87
|
+
|
|
39
88
|
def test_ensure_logbook_spawns(monkeypatch, tmp_path) -> None:
|
|
40
89
|
monkeypatch.setenv("DINT_HOME", str(tmp_path))
|
|
41
|
-
monkeypatch.
|
|
90
|
+
monkeypatch.delenv("LOGBOOK_API_KEY", raising=False)
|
|
91
|
+
monkeypatch.setattr("dint.runtime.logbook_health", lambda **k: None)
|
|
92
|
+
monkeypatch.setattr("dint.runtime.ensure_logbook_auth", lambda health=None: None)
|
|
42
93
|
monkeypatch.setattr("dint.runtime.wait_for", lambda url, timeout=12: True)
|
|
43
94
|
monkeypatch.setattr(
|
|
44
95
|
"dint.runtime.shutil.which",
|
|
@@ -52,10 +103,13 @@ def test_ensure_logbook_spawns(monkeypatch, tmp_path) -> None:
|
|
|
52
103
|
ensure_defaults()
|
|
53
104
|
ensure_logbook()
|
|
54
105
|
assert calls[0] == ["/bin/logbook-server"]
|
|
106
|
+
assert os.environ["LOGBOOK_API_KEY"]
|
|
55
107
|
|
|
56
108
|
|
|
57
|
-
def test_ensure_logbook_missing_binary(monkeypatch) -> None:
|
|
58
|
-
monkeypatch.
|
|
109
|
+
def test_ensure_logbook_missing_binary(monkeypatch, tmp_path) -> None:
|
|
110
|
+
monkeypatch.setenv("DINT_HOME", str(tmp_path))
|
|
111
|
+
monkeypatch.delenv("LOGBOOK_API_KEY", raising=False)
|
|
112
|
+
monkeypatch.setattr("dint.runtime.logbook_health", lambda **k: None)
|
|
59
113
|
monkeypatch.setattr("dint.runtime.shutil.which", lambda name: None)
|
|
60
114
|
with pytest.raises(RuntimeError, match="logbook-server"):
|
|
61
115
|
ensure_logbook()
|
|
@@ -94,6 +148,30 @@ def test_pick_engine_prefers_grok(monkeypatch) -> None:
|
|
|
94
148
|
assert pick_engine() == "grok"
|
|
95
149
|
|
|
96
150
|
|
|
151
|
+
def test_find_free_port_skips_occupied(monkeypatch) -> None:
|
|
152
|
+
busy = {5101}
|
|
153
|
+
|
|
154
|
+
monkeypatch.setattr(
|
|
155
|
+
"dint.runtime.probe",
|
|
156
|
+
lambda url, timeout=1.5: ":5101" in url,
|
|
157
|
+
)
|
|
158
|
+
monkeypatch.setattr(
|
|
159
|
+
"dint.runtime.can_bind",
|
|
160
|
+
lambda host, port: port not in busy,
|
|
161
|
+
)
|
|
162
|
+
assert find_free_port("127.0.0.1", 5101) == 5102
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def test_can_bind_occupied() -> None:
|
|
166
|
+
sock = __import__("socket").socket()
|
|
167
|
+
sock.bind(("127.0.0.1", 0))
|
|
168
|
+
port = sock.getsockname()[1]
|
|
169
|
+
try:
|
|
170
|
+
assert can_bind("127.0.0.1", port) is False
|
|
171
|
+
finally:
|
|
172
|
+
sock.close()
|
|
173
|
+
|
|
174
|
+
|
|
97
175
|
def test_pick_engine_env_override(monkeypatch) -> None:
|
|
98
176
|
monkeypatch.setenv("DINT_ENGINE", "codex")
|
|
99
177
|
monkeypatch.setattr(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|