feat(performance): 자동 업데이트가 끝나면 매출 실적·광고비 화면 새로 고침

- 화면이 20초마다 GET /api/update-status?kind=sales|ads 로 마지막으로 끝난 업데이트를 보고,
  그린 때(update_watch.seen)와 다르고 도는 중이 아니면 reload (jobs.last_finished — 메모리만, DB 안 읽음)
- 보는 사람이 직접 누른 업데이트는 제외(진행 창이 새로 그림), 매출·광고비 따로
- 칸 입력·창·메뉴·확인 창이 열려 있으면 닫힐 때까지 기다리고 "새 데이터 있음" 안내, 탭이 안 보이면 안 물음
- 테스트: last_finished·update-status API, 브라우저(새로 고침·기다림·종류별)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-26 18:37:39 +09:00
parent fba27772a4
commit 18d2835304
12 changed files with 272 additions and 8 deletions
+110
View File
@@ -0,0 +1,110 @@
// 실적 화면 자동 새로 고침(2026-10-26) — 실제 브라우저(Chromium).
// python tests/js/render_performance.py
// NODE_PATH=<playwright 경로> PJ_TEST_BROWSER=<Chrome 경로> node tests/js/perf_auto_refresh.browser.test.js
// 자동 업데이트(다른 사람 업데이트 포함)가 끝나면 매출 실적·광고비 화면이 20초 안에 알아채 새로 고친다(GET /api/update-status).
// 도는 중이면 끝날 때까지 기다림, 칸 입력·창이 열려 있으면 닫힐 때까지 기다림(안내 표시), 매출/광고비 종류 따로.
const fs = require("fs"), path = require("path");
const { chromium } = require("playwright");
const ROOT = path.join(__dirname, "..", "..");
const fails = [];
function check(name, cond, extra) {
if (cond) console.log("PASS " + name);
else { console.log("FAIL " + name + (extra !== undefined ? " → " + JSON.stringify(extra) : "")); fails.push(name); }
}
function page(file) {
const css = fs.readFileSync(path.join(ROOT, "app", "static", "performance.css"), "utf8");
const js = fs.readFileSync(path.join(ROOT, "app", "static", "performance.js"), "utf8");
return fs.readFileSync(path.join(__dirname, ".out", file), "utf8")
.replace(/<link rel="stylesheet" href="\/static\/performance\.css[^"]*" \/>/, function () { return "<style>" + css + "</style>"; })
.replace(/<script src="\/static\/performance\.js[^"]*" defer><\/script>/, function () { return "<script>" + js + "</script>"; });
}
(async function () {
const browser = await chromium.launch(process.env.PJ_TEST_BROWSER ? { executablePath: process.env.PJ_TEST_BROWSER } : {});
try {
async function open(file, url) {
const ctx = await browser.newContext({ viewport: { width: 1400, height: 900 } });
const p = await ctx.newPage();
const s = { loads: 0, asks: [], status: { running: false, done: "job-old" } };
await p.clock.install({ time: new Date("2026-10-07T10:17:25+09:00") });
await p.route("**/*", function (r) {
const u = r.request().url();
if (u.indexOf("/performance/api/update-status") >= 0) {
s.asks.push(u.split("?")[1]);
return r.fulfill({ status: 200, contentType: "application/json", body: JSON.stringify(Object.assign({ kind: "sales", user: "자동 업데이트" }, s.status)) });
}
if (u.indexOf("/static/") >= 0) return r.fulfill({ status: 200, body: "" });
if (r.request().resourceType() === "document") s.loads++;
r.fulfill({ status: 200, contentType: "text/html; charset=utf-8", body: page(file) });
});
await p.goto(url);
return { ctx: ctx, p: p, s: s };
}
const tick = async function (o, ms) { await o.p.clock.runFor(ms); await o.p.waitForTimeout(150); };
// ── 매출 실적 ──
let o = await open("perf_dash.html", "http://perf.test/performance/");
await tick(o, 21000);
check("20초마다 묻는다(매출)", o.s.asks.length === 1 && o.s.asks[0] === "kind=sales", o.s.asks);
check("그린 때와 같으면 그대로", o.s.loads === 1, o.s.loads);
o.s.status = { running: true, done: "job-new" };
await tick(o, 20000);
check("업데이트가 도는 중이면 기다림", o.s.loads === 1, o.s.loads);
o.s.status = { running: false, done: "job-new" };
await tick(o, 20000);
await o.p.waitForLoadState();
check("자동 업데이트 끝 → 새로 고침", o.s.loads === 2, o.s.loads);
// 새로 그린 화면(이 테스트는 같은 HTML — seen=job-old) — 창이 열려 있으면 닫을 때까지 기다림
o.s.status = { running: false, done: "job-old" };
await tick(o, 21000);
check("새로 고친 뒤 같은 값이면 그대로", o.s.loads === 2, o.s.loads);
await o.p.evaluate(function () {
const m = document.createElement("div"); m.className = "perf-modal"; m.id = "fake-modal"; document.body.appendChild(m);
});
o.s.status = { running: false, done: "job-2" };
await tick(o, 21000);
check("창이 열려 있으면 새로 고치지 않음", o.s.loads === 2, o.s.loads);
const note = await o.p.textContent("#perf-last-update");
check("안내: 창을 닫으면 새로 고침", /새 데이터 있음/.test(note), note);
await tick(o, 5000);
check("창이 열린 동안은 계속 기다림", o.s.loads === 2, o.s.loads);
await o.p.evaluate(function () { document.getElementById("fake-modal").remove(); });
await tick(o, 2000);
await o.p.waitForLoadState();
check("창을 닫으면 새로 고침", o.s.loads === 3, o.s.loads);
// 칸 입력 중(포커스)이면 기다림
o.s.status = { running: false, done: "job-3" };
await o.p.evaluate(function () {
const i = document.createElement("input"); i.id = "fake-input"; document.querySelector("#perf-dash").appendChild(i); i.focus();
});
await tick(o, 21000);
check("입력 중이면 새로 고치지 않음", o.s.loads === 3, o.s.loads);
await o.p.evaluate(function () { document.getElementById("fake-input").blur(); });
await tick(o, 2000);
await o.p.waitForLoadState();
check("입력을 마치면 새로 고침", o.s.loads === 4, o.s.loads);
await o.ctx.close();
// ── 광고비 — 광고비 업데이트를 따로 본다 ──
o = await open("perf_ads.html", "http://perf.test/performance/ads");
await tick(o, 21000);
check("광고비 화면은 kind=ads", o.s.asks[0] === "kind=ads", o.s.asks);
o.s.status = { running: false, done: "job-ads" };
await tick(o, 20000);
await o.p.waitForLoadState();
check("광고비 자동 업데이트 끝 → 새로 고침", o.s.loads === 2, o.s.loads);
await o.ctx.close();
// ── 자동 새로 고침 정보가 없는 화면(예전 서버 등) — 묻지 않음 ──
o = await open("perf_dash_groups.html", "http://perf.test/performance/");
await tick(o, 45000);
check("update_watch 없으면 묻지 않음", o.s.asks.length === 0, o.s.asks);
await o.ctx.close();
} finally {
await browser.close();
}
console.log(fails.length ? "\n" + fails.length + " FAILED" : "\nALL PASS");
process.exit(fails.length ? 1 : 0);
})();
+6
View File
@@ -95,6 +95,8 @@ def main() -> None:
ctx["auto_sync"] = {"next_at": "2026-10-07T10:30:00+09:00", "now": "2026-10-07T10:17:25.000+09:00",
"schedule": {"enabled": True, "interval": 30, "days": [0, 1, 2, 3, 4, 5, 6], "start": "09:00", "end": "19:00"},
"label": "매일 09:00~19:00 · 30분마다"}
# 화면 자동 새로 고침(2026-10-26, router._update_watch) — 그린 때 마지막으로 끝난 업데이트
ctx["update_watch"] = {"kind": "sales", "seen": "job-old"}
html = e.get_template("performance/index.html").render(**base, active_tab="dashboard", metric="net", **ctx)
with open(os.path.join(OUT_DIR, "perf_dash.html"), "w", encoding="utf-8") as f:
f.write(html)
@@ -104,12 +106,14 @@ def main() -> None:
sbase = {**base, "user": {"email": "me@test.local", "name": "Me", "picture": ""}}
mctx = build_dashboard(FakeStore(), kind="month", anchor=date(2026, 10, 7), today=date(2026, 10, 7))
mctx["auto_sync"] = ctx["auto_sync"]
mctx["update_watch"] = {"kind": "sales", "seen": "job-old"}
html = shell.get_template("performance/index.html").render(**sbase, active_tab="dashboard", metric="net", **mctx)
with open(os.path.join(OUT_DIR, "perf_dash_shell.html"), "w", encoding="utf-8") as f:
f.write(html)
sactx = build_ad_dashboard(FakeStore(), kind="month", anchor=date(2026, 10, 7), today=date(2026, 10, 7),
sales_codes=["cafe24", "coupang"])
sactx["auto_sync"] = ctx["auto_sync"]
sactx["update_watch"] = {"kind": "ads", "seen": "job-old"}
html = shell.get_template("performance/ads.html").render(**sbase, active_tab="ads", **sactx)
with open(os.path.join(OUT_DIR, "perf_ads_shell.html"), "w", encoding="utf-8") as f:
f.write(html)
@@ -117,6 +121,7 @@ def main() -> None:
sales_codes=["cafe24", "coupang"])
actx["ad_sync_sources"] = [{"code": "google", "name": "구글 광고"}] # [구글 광고 불러오기]
actx["auto_sync"] = ctx["auto_sync"] # 광고비 탭도 다음 업데이트 카운트다운(router._auto_sync_ctx)
actx["update_watch"] = {"kind": "ads", "seen": "job-old"}
html = e.get_template("performance/ads.html").render(**base, active_tab="ads", **actx)
with open(os.path.join(OUT_DIR, "perf_ads.html"), "w", encoding="utf-8") as f:
f.write(html)
@@ -136,6 +141,7 @@ def main() -> None:
# 직접 추가 쇼핑몰·그룹(2026-10-22) — perf_dash_groups.html · perf_settings_groups.html (perf_groups.browser.test.js)
gctx = build_dashboard(GroupStore(), kind="week", anchor=date(2026, 10, 7), today=date(2026, 10, 7))
gctx["auto_sync"] = None
gctx["update_watch"] = None
html = e.get_template("performance/index.html").render(**base, active_tab="dashboard", metric="gross", **gctx)
with open(os.path.join(OUT_DIR, "perf_dash_groups.html"), "w", encoding="utf-8") as f:
f.write(html)