mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-14 14:17:08 +00:00
fix: docsgpt up review follow-ups
- wait_healthy starts no request once the deadline is reached, and neither its pauses nor the requests after the first run past it; the first attempt still always runs (status uses a zero timeout). - envfile writes $ as $$ inside double quotes, which Compose interpolates, and reads $$ back as $, so a value such as pa$w'rd reaches the container unchanged. - Upgrading no longer describes the working directory as the data home.
This commit is contained in:
1 parent
5e699b0168
commit
f6bf4fefd1
5 files changed
+64
-10
No files matched your search
@@ -120,6 +120,38 @@ class TestWaitHealthy:
|
||||
sleep=lambda s: None, clock=lambda: next(clock))
|
||||
assert attempts["n"] == 3
|
||||
|
||||
def test_no_request_starts_at_or_after_the_deadline(self):
|
||||
"""A short timeout must not be overrun by a sleep and one more five-second request."""
|
||||
now = {"t": 0.0}
|
||||
starts = []
|
||||
|
||||
def opener(url, timeout):
|
||||
starts.append((now["t"], timeout))
|
||||
now["t"] += 1
|
||||
raise OSError("connection refused")
|
||||
|
||||
def sleep(seconds):
|
||||
now["t"] += seconds
|
||||
|
||||
assert not docker_module.wait_healthy("http://127.0.0.1:7091/api/health", 3, opener=opener,
|
||||
sleep=sleep, clock=lambda: now["t"])
|
||||
assert starts, "the first attempt always runs"
|
||||
for started, timeout in starts[1:]:
|
||||
assert started < 3
|
||||
assert started + timeout <= 3
|
||||
assert now["t"] <= 3
|
||||
|
||||
def test_a_zero_timeout_still_tries_once(self):
|
||||
calls = []
|
||||
|
||||
def opener(url, timeout):
|
||||
calls.append(timeout)
|
||||
return _Response(200)
|
||||
|
||||
assert docker_module.wait_healthy("http://127.0.0.1:7091/api/health", 0, opener=opener,
|
||||
sleep=lambda s: None, clock=lambda: 0.0)
|
||||
assert len(calls) == 1 and calls[0] > 0
|
||||
|
||||
def test_gives_up_after_the_timeout(self):
|
||||
def opener(url, timeout):
|
||||
raise OSError("connection refused")
|
||||
|
||||
@@ -55,12 +55,21 @@ class TestUpdate:
|
||||
envfile.update(path, {"A": "3"})
|
||||
assert path.read_text() == "A=3\nX=y\n"
|
||||
|
||||
@pytest.mark.parametrize("value", ["plain", "with space", "hash # inside", "it's", 'say "hi"', "back\\slash", ""])
|
||||
@pytest.mark.parametrize(
|
||||
"value",
|
||||
["plain", "with space", "hash # inside", "it's", 'say "hi"', "back\\slash", "", "pa$w'rd", "a$$b'c", "$HOME"],
|
||||
)
|
||||
def test_values_round_trip(self, tmp_path, value):
|
||||
path = tmp_path / ".env"
|
||||
envfile.update(path, {"VALUE": value})
|
||||
assert envfile.read(path)["VALUE"] == value
|
||||
|
||||
def test_a_dollar_in_double_quotes_is_escaped_for_compose(self, tmp_path):
|
||||
"""Compose interpolates double-quoted .env values; $$ is its literal dollar."""
|
||||
path = tmp_path / ".env"
|
||||
envfile.update(path, {"API_KEY": "pa$w'rd"})
|
||||
assert path.read_text() == "API_KEY=\"pa$$w'rd\"\n"
|
||||
|
||||
@pytest.mark.skipif(sys.platform == "win32", reason="POSIX permissions")
|
||||
def test_a_new_file_is_private(self, tmp_path):
|
||||
path = tmp_path / "stack" / ".env"
|
||||
|
||||
Reference in new issue
Block a user