feat(cafe24): 일괄수정 — 상세페이지 <style> 블록 통일

87개 상품의 상세설명 맨 위 <style> 을 정해진 내용으로 바꾸는 화면을 추가했다.

    <style>
    	div {
    		text-align: center;
    	}
    </style>

그냥 덮어쓰지 않고 검사 → 선택 → 적용 2단계로 만들었다. 상품 131번의 style 안에는
"비디오 태그 모바일 반응형 스타일" 같은 CSS 가 들어 있어서, 무엇이 지워지는지 보지
않고 87건을 일괄 실행하면 필요한 규칙이 조용히 사라진다. 검사 결과 표에 지금 들어
있는 CSS 를 그대로 보여주고, 변경이 필요한 상품만 자동 선택한다(이미 같은 내용이면
「이미 동일」로 제외).

맨 앞 <style> 블록 하나만 바꾼다. 아래쪽에 <style> 이 더 있으면 건드리지 않고
「블록 2개 · 주의」로 표시해 사람이 판단하게 한다 — 일괄 작업이 남의 CSS 를 조용히
지우는 것이 가장 위험하다. 블록이 없는 상품은 맨 앞에 넣는다.

상품 1건당 1요청으로 쪼갰다. 87건을 한 요청으로 묶으면 1분 가까이 걸려 프록시
타임아웃에 걸리고, 동시에 던지면 카페24 호출 제한(429)에 걸린다. 브라우저가 순차
호출하며 진행률을 보여주고, 한 건 실패가 나머지를 막지 않으며 어디까지 됐는지
화면에 남는다.

적용 순서는 단건 편집과 같은 원칙을 지킨다: 카페24 현재값 재조회 → BACKUP 버전 →
교체 → PUT → MANUAL 버전 + 감사로그(action=bulk_style). 검사 때 읽은 값을 재사용하지
않고 쓰기 직전에 다시 읽는다. PC/모바일 분리 상품은 모바일도 함께 바꾼다.

검증: 유닛테스트 51개 통과(신규 6개 — 앞 블록만 교체하고 뒤 블록 보존, 없을 때 삽입,
멱등, 포맷 후 탭 유지, 여러 줄 원문 정확히 절단). 실제 데이터로 미리보기 로직 확인:
비디오 CSS 가 "지워질 내용"에 잡히고, 이미 동일한 상품은 will_change=False,
style 없는 상품은 삽입 대상으로 판정. 라우트 13개 등록, 템플릿 렌더 확인.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-14 14:12:24 +09:00
parent 25ed369583
commit 3522fc2119
7 changed files with 502 additions and 4 deletions
+52
View File
@@ -539,6 +539,58 @@ def test_format_then_encode_roundtrip():
assert saved == raw
# ════════════════════════════════════════════════════════════
# <style> 블록 일괄 교체
# ════════════════════════════════════════════════════════════
_NEW_STYLE = "<style>\n\tdiv {\n\t\ttext-align: center;\n\t}\n</style>"
def test_find_style_blocks():
html = "<style>a{}</style><div>x</div><style type=\"text/css\">b{}</style>"
blocks = store.find_style_blocks(html)
assert len(blocks) == 2
assert blocks[0] == "<style>a{}</style>"
def test_replace_first_style_block_only():
"""두 번째 이후 <style> 은 건드리지 않는다(남의 CSS 를 조용히 지우지 않게)."""
html = "<style>OLD</style><div>x</div><style>KEEP</style>"
out = store.replace_first_style_block(html, _NEW_STYLE)
assert "OLD" not in out
assert "<style>KEEP</style>" in out
assert out.startswith(_NEW_STYLE)
assert "<div>x</div>" in out
def test_replace_style_inserts_when_missing():
out = store.replace_first_style_block("<div>x</div>", _NEW_STYLE)
assert out.startswith(_NEW_STYLE)
assert "<div>x</div>" in out
def test_replace_style_is_idempotent():
once = store.replace_first_style_block("<style>OLD</style><div>x</div>", _NEW_STYLE)
assert store.replace_first_style_block(once, _NEW_STYLE) == once
def test_replace_style_survives_formatting():
"""정리(포맷)를 거쳐도 <style> 안 탭·줄바꿈이 그대로 남는다."""
formatted = store.format_html(
store.replace_first_style_block("<style>OLD</style><div>x</div>", _NEW_STYLE)
)
assert "\tdiv {" in formatted
assert "\t\ttext-align: center;" in formatted
assert len(store.find_style_blocks(formatted)) == 1
def test_replace_style_keeps_multiline_original_shape():
"""원문이 여러 줄이어도 앞 블록만 정확히 잘라낸다."""
html = '<style>\n/* 비디오 반응형 */\n.video{max-width:100%}\n</style>\n<img src="a.gif">'
out = store.replace_first_style_block(html, _NEW_STYLE)
assert "비디오" not in out
assert '<img src="a.gif">' in out
def test_fingerprint_detects_change():
a = store.fingerprint("<p>A</p>")
assert a == store.fingerprint("<p>A</p>")