release: Mantoz — population-scale evaluation with simulated personas
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
FROM mcr.microsoft.com/playwright/python:v1.49.1-noble
|
||||
# Образ на Ubuntu - bash уже есть (Harbor оборачивает команды в bash).
|
||||
# В образе браузеры (/ms-playwright), но нет pip-пакета - ставим ровно ту
|
||||
# версию, под которую собраны браузеры образа.
|
||||
RUN pip install --no-cache-dir playwright==1.49.1
|
||||
WORKDIR /app
|
||||
COPY stand.html run_scenario.py /app/
|
||||
@@ -0,0 +1,58 @@
|
||||
"""Проходит сценарий выбора тарифа в настоящем браузере (Playwright/Chromium).
|
||||
|
||||
Читает план из /app/plan.json (запечён хостом из признаков персоны), исполняет
|
||||
его кликами по странице-стенду и пишет /app/result.json: след действий и
|
||||
итоговое решение, ПРОЧИТАННОЕ ИЗ DOM страницы, а не из плана.
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
OPTIONS = ("base", "standart", "premium")
|
||||
|
||||
|
||||
def main() -> int:
|
||||
plan = json.loads(Path("/app/plan.json").read_text("utf-8"))
|
||||
inspect = plan.get("inspect") or []
|
||||
choose = plan.get("choose")
|
||||
unknown = [o for o in [*inspect, choose] if o is not None and o not in OPTIONS]
|
||||
if unknown:
|
||||
print(f"неизвестные тарифы в плане: {unknown}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
actions = []
|
||||
with sync_playwright() as playwright:
|
||||
browser = playwright.chromium.launch()
|
||||
try:
|
||||
page = browser.new_page()
|
||||
page.goto("file:///app/stand.html")
|
||||
page.wait_for_selector("h1")
|
||||
actions.append({"type": "open", "target": "stand"})
|
||||
for option_id in inspect:
|
||||
page.click(f"[data-details='{option_id}']")
|
||||
page.wait_for_selector(f"[data-panel='{option_id}'].open")
|
||||
actions.append({"type": "inspect", "target": option_id})
|
||||
decision = None
|
||||
if choose is not None:
|
||||
page.click(f"[data-choose='{choose}']")
|
||||
page.wait_for_selector("#confirmation[data-decision]")
|
||||
# Решение - из DOM страницы, не из плана: это итог браузерного
|
||||
# прогона, а не пересказ входных данных.
|
||||
decision = page.get_attribute("#confirmation", "data-decision")
|
||||
actions.append({"type": "choose", "target": decision})
|
||||
finally:
|
||||
browser.close()
|
||||
|
||||
Path("/app/result.json").write_text(
|
||||
json.dumps({"actions": actions, "decision": decision}, ensure_ascii=False)
|
||||
+ "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,61 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Выбор тарифа</title>
|
||||
<style>
|
||||
body { font-family: sans-serif; max-width: 720px; margin: 2rem auto; }
|
||||
.card { border: 1px solid #999; border-radius: 8px; padding: 1rem; margin-bottom: 1rem; }
|
||||
.panel { display: none; margin: 0.5rem 0; color: #333; }
|
||||
.panel.open { display: block; }
|
||||
#confirmation { display: none; margin-top: 1rem; font-weight: bold; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Выберите тариф сервиса</h1>
|
||||
|
||||
<section class="card" data-card="base">
|
||||
<h2>Базовый</h2>
|
||||
<p>0 ₽ в месяц</p>
|
||||
<button type="button" data-details="base">Подробнее</button>
|
||||
<div class="panel" data-panel="base">Один проект, без поддержки, данные только на устройстве.</div>
|
||||
<button type="button" data-choose="base">Выбрать</button>
|
||||
</section>
|
||||
|
||||
<section class="card" data-card="standart">
|
||||
<h2>Стандарт</h2>
|
||||
<p>490 ₽ в месяц</p>
|
||||
<button type="button" data-details="standart">Подробнее</button>
|
||||
<div class="panel" data-panel="standart">Десять проектов, поддержка по почте, резервные копии.</div>
|
||||
<button type="button" data-choose="standart">Выбрать</button>
|
||||
</section>
|
||||
|
||||
<section class="card" data-card="premium">
|
||||
<h2>Премиум</h2>
|
||||
<p>1490 ₽ в месяц</p>
|
||||
<button type="button" data-details="premium">Подробнее</button>
|
||||
<div class="panel" data-panel="premium">Без ограничений, личный менеджер, приоритетная поддержка.</div>
|
||||
<button type="button" data-choose="premium">Выбрать</button>
|
||||
</section>
|
||||
|
||||
<div id="confirmation" role="status"></div>
|
||||
|
||||
<script>
|
||||
document.querySelectorAll("[data-details]").forEach(function (button) {
|
||||
button.addEventListener("click", function () {
|
||||
var id = button.getAttribute("data-details");
|
||||
document.querySelector('[data-panel="' + id + '"]').classList.toggle("open");
|
||||
});
|
||||
});
|
||||
document.querySelectorAll("[data-choose]").forEach(function (button) {
|
||||
button.addEventListener("click", function () {
|
||||
var id = button.getAttribute("data-choose");
|
||||
var confirmation = document.getElementById("confirmation");
|
||||
confirmation.setAttribute("data-decision", id);
|
||||
confirmation.textContent = "Выбран тариф: " + id;
|
||||
confirmation.style.display = "block";
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,22 @@
|
||||
На странице-стенде `/app/stand.html` размещены три тарифа: `base`, `standart`,
|
||||
`premium`. Прочитай план прохождения из `/app/plan.json` формата:
|
||||
|
||||
```json
|
||||
{"inspect": ["base", "standart"], "choose": "standart"}
|
||||
```
|
||||
|
||||
Пройди сценарий в браузере скриптом `/app/run_scenario.py`: открой страницу,
|
||||
раскрой детали каждого тарифа из `inspect`, затем нажми «Выбрать» на тарифе из
|
||||
`choose` (если `choose` не `null`). Скрипт запишет `/app/result.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"actions": [{"type": "open", "target": "stand"}, ...],
|
||||
"decision": "standart"
|
||||
}
|
||||
```
|
||||
|
||||
Решение (`decision`) обязано совпадать с тарифом последнего действия `choose`
|
||||
и быть одним из `base`, `standart`, `premium`. Действий должно быть не меньше
|
||||
двух. Если тариф не выбран (`choose: null`), поле `decision` остаётся `null` —
|
||||
это честный исход «персона ушла без выбора», верификатор его не засчитывает.
|
||||
@@ -0,0 +1,14 @@
|
||||
schema_version = "1.4"
|
||||
|
||||
[metadata]
|
||||
title = "web-choice"
|
||||
environment = "web"
|
||||
|
||||
[verifier]
|
||||
timeout_sec = 300.0
|
||||
|
||||
[agent]
|
||||
timeout_sec = 600.0
|
||||
|
||||
[environment]
|
||||
build_timeout_sec = 1800.0
|
||||
@@ -0,0 +1,35 @@
|
||||
#!/bin/sh
|
||||
# Верификатор web-choice: судит итоговое решение по /app/result.json.
|
||||
# Нет решения, мало действий или решение не из списка тарифов стенда -
|
||||
# провал (reward 0), не крах.
|
||||
mkdir -p /logs/verifier
|
||||
# След и решение из браузерного прогона - на хост, их читает mantoz.web.
|
||||
cp /app/result.json /logs/verifier/result.json 2>/dev/null || true
|
||||
python3 - <<'PY'
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
OPTIONS = ("base", "standart", "premium")
|
||||
|
||||
reward = 0
|
||||
try:
|
||||
result = json.loads(Path("/app/result.json").read_text("utf-8"))
|
||||
actions = result["actions"]
|
||||
decision = result["decision"]
|
||||
choose_actions = [a for a in actions if a.get("type") == "choose"]
|
||||
valid = (
|
||||
decision in OPTIONS
|
||||
and isinstance(actions, list)
|
||||
and len(actions) >= 2
|
||||
and actions[0].get("type") == "open"
|
||||
and choose_actions
|
||||
and choose_actions[-1].get("target") == decision
|
||||
and all(
|
||||
a.get("target") in OPTIONS or a.get("type") == "open" for a in actions
|
||||
)
|
||||
)
|
||||
reward = int(valid)
|
||||
except Exception:
|
||||
reward = 0
|
||||
Path("/logs/verifier/reward.txt").write_text(str(reward))
|
||||
PY
|
||||
Reference in New Issue
Block a user