Skip to content

Commit b3eb92c

Browse files
Merge pull request #4 from pathbit/docs/revisao-profunda
docs: o /healthz respondia uma coisa e a wiki anunciava outra
2 parents 19f642c + bc4b5b9 commit b3eb92c

3 files changed

Lines changed: 78 additions & 2 deletions

File tree

‎docs/wiki/Dashboard.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Kept for automation; the dashboard itself does not use them.
113113

114114
| Endpoint | Method | Purpose |
115115
| :--- | :--- | :--- |
116-
| `/healthz` | GET | Unauthenticated liveness probe. `OK`, `DATABASE_NOT_READY` or `OMNIROUTE_SERVICE_UNREACHABLE`. |
116+
| `/healthz` | GET | Unauthenticated liveness probe. `OK`, `DATABASE_NOT_READY` or `GATEWAY_SERVICE_UNREACHABLE`. |
117117
| `/api/status` | GET | Full state as JSON. |
118118
| `/api/cron-status` | GET | Scheduler state and history. |
119119
| `/api/sync` | POST | Trigger a synchronization pass. |

‎docs/wiki/Troubleshooting.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ If the numbers still look wrong, the synchronizer may not be writing at all —
8080
| :--- | :--- |
8181
| `OK` | Database readable and gateway reachable. |
8282
| `DATABASE_NOT_READY` | `DB_PATH` points at a file that does not exist. |
83-
| `OMNIROUTE_SERVICE_UNREACHABLE` | `OMNIROUTE_URL` is wrong, or the gateway is down. |
83+
| `GATEWAY_SERVICE_UNREACHABLE` | `OMNIROUTE_URL` is wrong, or the gateway is down. |
8484

8585
---
8686

‎tests/test_healthz_documentado.py‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
"""A documentação do /healthz tem de citar as respostas que o código produz.
2+
3+
A wiki anunciava `OMNIROUTE_SERVICE_UNREACHABLE` e o servidor respondia
4+
`GATEWAY_SERVICE_UNREACHABLE`. Nada quebra: o painel funciona, o healthcheck
5+
funciona, os testes passam. Quem perde é quem monta um alerta sobre a string
6+
documentada — ele nunca dispara, e o silêncio parece saúde.
7+
8+
Este teste lê as respostas direto do fonte do servidor e exige que cada uma
9+
apareça na documentação.
10+
"""
11+
12+
import os
13+
import re
14+
import unittest
15+
16+
RAIZ = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17+
SERVIDOR = os.path.join(RAIZ, "src", "omini_rtksync", "web.py")
18+
19+
20+
def respostas_do_healthz() -> set:
21+
"""Os literais que o /healthz devolve, lidos do fonte."""
22+
with open(SERVIDOR, encoding="utf-8") as f:
23+
fonte = f.read()
24+
inicio = fonte.find("def serve_healthz")
25+
assert inicio > 0, "serve_healthz nao encontrada"
26+
trecho = fonte[inicio:inicio + 1500]
27+
return set(re.findall(r'b"([A-Z][A-Z0-9_]+)"', trecho))
28+
29+
30+
def paginas_de_documentacao():
31+
for pasta, dirs, arquivos in os.walk(RAIZ):
32+
dirs[:] = [d for d in dirs if d not in (".git", "tmp", "node_modules", "__pycache__")]
33+
for a in arquivos:
34+
if a.endswith(".md"):
35+
yield os.path.join(pasta, a)
36+
37+
38+
class TestHealthzDocumentado(unittest.TestCase):
39+
def test_every_answer_the_code_returns_is_documented(self):
40+
respostas = respostas_do_healthz()
41+
self.assertTrue(respostas, "nenhuma resposta encontrada no fonte")
42+
43+
documentado = ""
44+
for p in paginas_de_documentacao():
45+
with open(p, encoding="utf-8") as f:
46+
documentado += f.read()
47+
48+
faltando = sorted(r for r in respostas if r not in documentado)
49+
self.assertEqual(
50+
faltando,
51+
[],
52+
"o /healthz responde isto e a documentacao nao cita: " + ", ".join(faltando),
53+
)
54+
55+
def test_no_page_invents_an_answer_the_code_never_returns(self):
56+
respostas = respostas_do_healthz()
57+
inventadas = []
58+
# O sublinhado precisa ser aceito no meio: OMNIROUTE_SERVICE_UNREACHABLE
59+
# tem um segmento entre o prefixo e o sufixo, e um padrao que pare no
60+
# primeiro sublinhado deixa passar justamente o caso que motivou o teste.
61+
padrao = re.compile(r"`([A-Z][A-Z0-9_]*_(?:NOT_READY|UNREACHABLE|UNAVAILABLE))`")
62+
for p in paginas_de_documentacao():
63+
with open(p, encoding="utf-8") as f:
64+
for n, linha in enumerate(f, 1):
65+
for citado in padrao.findall(linha):
66+
if citado not in respostas:
67+
inventadas.append(os.path.relpath(p, RAIZ) + ":" + str(n) + " " + citado)
68+
self.assertEqual(
69+
inventadas,
70+
[],
71+
"documentacao cita resposta que o codigo nunca devolve: " + ", ".join(inventadas),
72+
)
73+
74+
75+
if __name__ == "__main__":
76+
unittest.main()

0 commit comments

Comments
 (0)