✨ bypass + correctif
This commit is contained in:
1 parent
1cbbf7aa3c
commit
902529a4ea
9 files changed
+59
-7
No files matched your search
+6
-1
@@ -12,7 +12,11 @@ COPY src ./src
|
||||
RUN pip install --no-cache-dir ".[ocr]"
|
||||
|
||||
RUN useradd -m scalper && mkdir -p /app/data /app/out && chown -R scalper:scalper /app
|
||||
USER scalper
|
||||
|
||||
# Le conteneur démarre en root : l'entrypoint chown les répertoires montés
|
||||
# (bind mounts root côté hôte, ex. Coolify) puis droppe les privilèges (setpriv).
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
EXPOSE 8000
|
||||
@@ -20,4 +24,5 @@ EXPOSE 8000
|
||||
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
|
||||
CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/healthz')" || exit 1
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
CMD ["scalper", "serve", "--host", "0.0.0.0", "--port", "8000"]
|
||||
@@ -34,7 +34,7 @@ scalper run --source demo --series demo-1 --lang fr --mock-llm --out out
|
||||
| `scalper translate <chapter.json> --lang fr [--mock-llm]` | traduction LLM + glossaire |
|
||||
| `scalper qa <source.json> <traduit.json> --lang fr` | score 0-100, pass si ≥ 80 |
|
||||
| `scalper export <traduit.json> --format md\|json\|html` | export Markdown / JSON / HTML |
|
||||
| `scalper run --source ... --series ... --lang fr` | pipeline complet end-to-end |
|
||||
| `scalper run --source ... --series ... --lang fr [--force]` | pipeline complet end-to-end (`--force` = exporte même si la QA échoue) |
|
||||
|
||||
## OCR & remplacement du texte dans les images (V2)
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ Les résultats sont écrits dans le volume `./out` (monté dans le compose).
|
||||
|---|---|---|
|
||||
| GET | `/` | **interface web** (formulaire run) |
|
||||
| GET | `/healthz` | sonde de santé |
|
||||
| POST | `/run` | pipeline complet (scrape → clean → translate → QA → export) |
|
||||
| POST | `/run` | pipeline complet (scrape → clean → translate → QA → export). Champ optionnel `"force": true` : exporte même si la QA échoue (les chapitres concernés sont marqués `"forced": true`) |
|
||||
|
||||
## Sécurité
|
||||
- Rate limiting ≥ 1 s entre requêtes vers les sources.
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
# Les répertoires montés (bind mounts compose/Coolify) appartiennent souvent à root
|
||||
# côté hôte : on les rend à l'utilisateur applicatif, puis on droppe les privilèges.
|
||||
chown -R scalper:scalper /app/data /app/out 2>/dev/null || true
|
||||
exec setpriv --reuid scalper --regid scalper --init-groups "$@"
|
||||
@@ -96,6 +96,7 @@ def main(argv: list[str] | None = None) -> int:
|
||||
c.add_argument("--max-chapters", type=int, default=None)
|
||||
c.add_argument("--mock-llm", action="store_true", help="démo hors ligne (LLM factice)")
|
||||
c.add_argument("--with-ocr", action="store_true", help="OCR + remplacement du texte dans les images")
|
||||
c.add_argument("--force", action="store_true", help="exporte même si la QA échoue (bypass vérification)")
|
||||
|
||||
args = p.parse_args(argv)
|
||||
|
||||
@@ -203,6 +204,7 @@ def main(argv: list[str] | None = None) -> int:
|
||||
args.source, args.series, args.lang,
|
||||
out_root=Path(args.out), mock_llm=args.mock_llm,
|
||||
max_chapters=args.max_chapters, group=args.group, with_ocr=args.with_ocr,
|
||||
force=args.force,
|
||||
)
|
||||
_print(summary)
|
||||
return 0 if summary.get("status") == "done" else 3
|
||||
|
||||
@@ -26,6 +26,7 @@ def run_pipeline(
|
||||
max_chapters: int | None = None,
|
||||
group: str | None = None,
|
||||
with_ocr: bool = False,
|
||||
force: bool = False,
|
||||
) -> dict[str, Any]:
|
||||
out_root = Path(out_root)
|
||||
fetcher = fetcher or RespectfulFetcher(min_delay=1.0)
|
||||
@@ -66,13 +67,15 @@ def run_pipeline(
|
||||
report = qa_chapter(chapter, translated, glossary, lang)
|
||||
(dest / f"qa.{lang}.json").write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||
entry["qa"] = {"score": report["score"], "pass": report["pass"], "issues": len(report["issues"])}
|
||||
if report["pass"]:
|
||||
if report["pass"] or force:
|
||||
for fmt in ("md", "json", "html"):
|
||||
export_chapter(translated, fmt, dest / "export")
|
||||
if with_ocr:
|
||||
entry["ocr"] = _run_ocr_typeset(dest, meta, lang)
|
||||
state.mark_done(ref.id)
|
||||
entry["status"] = "ok"
|
||||
if not report["pass"]:
|
||||
entry["forced"] = True
|
||||
else:
|
||||
entry["status"] = "qa_failed"
|
||||
results.append(entry)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
Endpoints :
|
||||
- GET /healthz
|
||||
- POST /run {"source","series","lang","group"?,"max_chapters"?,"mock_llm"?,"with_ocr"?,"out"?}
|
||||
- POST /run {"source","series","lang","group"?,"max_chapters"?,"mock_llm"?,"with_ocr"?,"force"?,"out"?}
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -26,12 +26,13 @@ INDEX_HTML = """<!doctype html>
|
||||
<input id="r-lang" placeholder="langue cible (fr, en, ...)" value="fr">
|
||||
<input id="r-group" placeholder="groupe optionnel (ex. Keiyoushi, mangadex uniquement)">
|
||||
<input id="r-max" placeholder="max chapitres (optionnel)">
|
||||
<label><input type="checkbox" id="r-mock" style="width:auto"> mock-llm (démo hors ligne)</label><br>
|
||||
<label><input type="checkbox" id="r-mock" style="width:auto"> mock-llm (démo hors ligne)</label>
|
||||
<label><input type="checkbox" id="r-force" style="width:auto"> forcer l'export même si la QA échoue</label><br>
|
||||
<button onclick="runPipeline()">Lancer le pipeline</button>
|
||||
</fieldset>
|
||||
<pre id="out">résultats ici…</pre>
|
||||
<script>
|
||||
async function runPipeline(){const g=document.getElementById('r-group').value;const m=document.getElementById('r-max').value;const body={source:document.getElementById('r-source').value,series:document.getElementById('r-series').value,lang:document.getElementById('r-lang').value,mock_llm:document.getElementById('r-mock').checked};if(g)body.group=g;if(m)body.max_chapters=Number(m);document.getElementById('out').textContent='en cours…';const r=await fetch('/run',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(body)});document.getElementById('out').textContent=r.status+'\\n'+JSON.stringify(await r.json(),null,2);}
|
||||
async function runPipeline(){const g=document.getElementById('r-group').value;const m=document.getElementById('r-max').value;const body={source:document.getElementById('r-source').value,series:document.getElementById('r-series').value,lang:document.getElementById('r-lang').value,mock_llm:document.getElementById('r-mock').checked,force:document.getElementById('r-force').checked};if(g)body.group=g;if(m)body.max_chapters=Number(m);document.getElementById('out').textContent='en cours…';const r=await fetch('/run',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(body)});document.getElementById('out').textContent=r.status+'\\n'+JSON.stringify(await r.json(),null,2);}
|
||||
</script>
|
||||
</body></html>
|
||||
"""
|
||||
@@ -81,6 +82,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
max_chapters=body.get("max_chapters"),
|
||||
group=body.get("group"),
|
||||
with_ocr=bool(body.get("with_ocr", False)),
|
||||
force=bool(body.get("force", False)),
|
||||
)
|
||||
except KeyError as e:
|
||||
return self._json(400, {"error": f"champ requis manquant: {e}"})
|
||||
|
||||
@@ -2,6 +2,7 @@ import json
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
from scalper import pipeline
|
||||
from scalper.exporter import export_chapter, slugify
|
||||
@@ -30,6 +31,28 @@ class TestPipeline(unittest.TestCase):
|
||||
res = pipeline.run_pipeline("demo", "demo-1", "fr", out_root=tmp, mock_llm=True)
|
||||
self.assertTrue(any(c.get("skipped") for c in res["chapters"]))
|
||||
|
||||
def test_qa_failure_blocks_export_without_force(self):
|
||||
fake = {"score": 10, "pass": False, "issues": [{"type": "x", "critical": True}]}
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
with mock.patch("scalper.pipeline.qa_chapter", return_value=fake):
|
||||
res = pipeline.run_pipeline("demo", "demo-1", "fr", out_root=tmp, mock_llm=True, max_chapters=1)
|
||||
self.assertEqual(res["chapters"][0]["status"], "qa_failed")
|
||||
raw1 = Path(tmp) / "raw" / "demo" / "demo-1" / "demo-1-ch1"
|
||||
self.assertFalse((raw1 / "export").exists())
|
||||
|
||||
def test_force_exports_despite_qa_failure(self):
|
||||
fake = {"score": 10, "pass": False, "issues": [{"type": "x", "critical": True}]}
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
with mock.patch("scalper.pipeline.qa_chapter", return_value=fake):
|
||||
res = pipeline.run_pipeline("demo", "demo-1", "fr", out_root=tmp, mock_llm=True, max_chapters=1, force=True)
|
||||
self.assertEqual(res["status"], "done")
|
||||
ch = res["chapters"][0]
|
||||
self.assertEqual(ch["status"], "ok")
|
||||
self.assertTrue(ch.get("forced"))
|
||||
self.assertFalse(ch["qa"]["pass"])
|
||||
raw1 = Path(tmp) / "raw" / "demo" / "demo-1" / "demo-1-ch1"
|
||||
self.assertTrue(list((raw1 / "export").glob("*.md")))
|
||||
|
||||
|
||||
class TestExporter(unittest.TestCase):
|
||||
def test_exports(self):
|
||||
|
||||
@@ -5,6 +5,7 @@ import unittest
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
from http.server import ThreadingHTTPServer
|
||||
from unittest import mock
|
||||
|
||||
from scalper.server import Handler
|
||||
|
||||
@@ -63,6 +64,16 @@ class TestServer(unittest.TestCase):
|
||||
status, body = self._post("/run", {"source": "demo"})
|
||||
self.assertEqual(status, 400)
|
||||
|
||||
def test_run_force_bypasses_qa_gate(self):
|
||||
fake = {"score": 10, "pass": False, "issues": [{"type": "x", "critical": True}]}
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
with mock.patch("scalper.pipeline.qa_chapter", return_value=fake):
|
||||
status, body = self._post("/run", {"source": "demo", "series": "demo-1", "lang": "fr", "mock_llm": True, "out": tmp, "max_chapters": 1, "force": True})
|
||||
self.assertEqual(status, 200)
|
||||
self.assertEqual(body["status"], "done")
|
||||
self.assertEqual(body["chapters"][0]["status"], "ok")
|
||||
self.assertTrue(body["chapters"][0].get("forced"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user