git 저장소가 없어 히스토리·협업 기반이 아예 없던 상태를 연다.
함께 문서를 재편했다. 그동안 문서가 있어도 "이 제품이 뭘 푸는가"와
"어떻게 도는가"를 담은 문서가 없어서, 목표 문장이 backend/frontend
README 두 곳에 복붙돼 있었다 — 상위 문서가 없어 아래로 샌 것이다.
신설
README.md 레포 진입점 + 문서 지도 + 문서 규칙 4가지
AGENTS.md 에이전트·신규 합류자용 함정 목록과 규약
(CLAUDE.md 는 여기로 걸린 심볼릭 링크)
docs/PRODUCT.md 제품 정의 — 문제·사용자·원칙·**non-goals**·성공 기준
docs/ARCHITECTURE.md payload 경계·발행 파이프라인·서빙 결정·앱 분리 설계
이동
backend/docs/DECISIONS.md → docs/DECISIONS.md
백엔드만의 결정이 아니다. 게다가 코드 주석 ~25곳이 이미
`docs/DECISIONS.md` 로 적고 있어 레포 루트 기준으로는 그게 맞다.
갱신
docs/DEPLOY.md 서빙 결정 반영 — nginx 정적 서빙이 지금 경로(3절),
Azure 는 나중에 켤 때(4절)로 분리
docs/ARCHITECTURE.md 사이트 = 한 장(2026-08-31) 구조 반영
docs/COLLECTION_SEO_AEO_FLOW.md
robots.txt·sitemap.xml 은 오리진 루트에만 굽는다는 점 명시
frontend/site/scripts/prerender.ts
헤더 주석의 렌더 보고서 경로가 실제(422줄)와 달라 수정
.gitignore
★ CLAUDE.md 를 더 이상 무시하지 않는다. 에이전트 지침은 팀과 모든
에이전트가 공유하는 규약이라 커밋해야 한다 — 무시하면 클론한 사람이
"배포 후 republish_all.py 필수" 같은 함정을 전달받지 못한다.
개인용 오버라이드는 ~/.claude/CLAUDE.md 에 둔다.
106 lines
3.8 KiB
Python
106 lines
3.8 KiB
Python
"""발행 URL 의 색인 통보(IndexNow).
|
|
|
|
이 경로가 절대 하면 안 되는 것:
|
|
- 통보 실패로 발행을 되돌리는 것 — 정적 파일은 이미 올라갔다. 다음 발행에서 다시 보내면 된다.
|
|
- 사이트맵에 없는 URL 을 통보하는 것 — 404 통보는 신뢰만 깎는다.
|
|
"""
|
|
from pathlib import Path
|
|
|
|
import httpx
|
|
import pytest
|
|
|
|
from services import indexnow
|
|
|
|
SITEMAP = """<?xml version="1.0" encoding="UTF-8"?>
|
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
<url><loc>https://w4ai.o2o.kr/s/butter/</loc></url>
|
|
<url><loc>https://w4ai.o2o.kr/s/butter/faq</loc></url>
|
|
</urlset>
|
|
"""
|
|
|
|
|
|
def _out(tmp_path: Path, slug: str, body: str = SITEMAP) -> Path:
|
|
site = tmp_path / "s" / slug
|
|
site.mkdir(parents=True)
|
|
(site / "sitemap.xml").write_text(body)
|
|
return tmp_path
|
|
|
|
|
|
def test_키가_없으면_통보하지_않는다(monkeypatch):
|
|
monkeypatch.delenv("INDEXNOW_KEY", raising=False)
|
|
assert indexnow.is_configured() is False
|
|
|
|
|
|
def test_보낼_URL_은_사이트맵에서_읽는다(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("SITE_OUTPUT_DIR", str(_out(tmp_path, "butter")))
|
|
assert indexnow.site_urls("butter") == [
|
|
"https://w4ai.o2o.kr/s/butter/",
|
|
"https://w4ai.o2o.kr/s/butter/faq",
|
|
]
|
|
|
|
|
|
def test_사이트맵이_없으면_빈_목록(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("SITE_OUTPUT_DIR", str(tmp_path))
|
|
assert indexnow.site_urls("없는사이트") == []
|
|
|
|
|
|
def test_깨진_사이트맵은_예외를_올리지_않는다(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("SITE_OUTPUT_DIR", str(_out(tmp_path, "butter", "<urlset>깨짐")))
|
|
assert indexnow.site_urls("butter") == []
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_키파일_위치와_호스트를_URL에서_뽑는다(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("SITE_OUTPUT_DIR", str(_out(tmp_path, "butter")))
|
|
monkeypatch.setenv("INDEXNOW_KEY", "abc12345")
|
|
sent = {}
|
|
|
|
async def fake_post(self, url, json=None, **kwargs):
|
|
sent["url"] = url
|
|
sent["body"] = json
|
|
return httpx.Response(200, request=httpx.Request("POST", url))
|
|
|
|
monkeypatch.setattr(httpx.AsyncClient, "post", fake_post)
|
|
|
|
result = await indexnow.submit("butter")
|
|
|
|
assert sent["url"] == indexnow.ENDPOINT
|
|
assert sent["body"]["host"] == "w4ai.o2o.kr"
|
|
assert sent["body"]["key"] == "abc12345"
|
|
# 키 파일은 오리진 루트에 있다 — 사이트 경로(/s/butter) 아래가 아니다.
|
|
assert sent["body"]["keyLocation"] == "https://w4ai.o2o.kr/abc12345.txt"
|
|
assert sent["body"]["urlList"] == [
|
|
"https://w4ai.o2o.kr/s/butter/",
|
|
"https://w4ai.o2o.kr/s/butter/faq",
|
|
]
|
|
assert result == {"ok": True, "status": 200, "urls": 2}
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_거절되어도_예외를_올리지_않는다(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("SITE_OUTPUT_DIR", str(_out(tmp_path, "butter")))
|
|
monkeypatch.setenv("INDEXNOW_KEY", "abc12345")
|
|
|
|
async def fake_post(self, url, json=None, **kwargs):
|
|
# 403 = 키 파일 대조 실패. 발행은 이미 끝났으므로 되돌리지 않는다.
|
|
return httpx.Response(403, text="key not found", request=httpx.Request("POST", url))
|
|
|
|
monkeypatch.setattr(httpx.AsyncClient, "post", fake_post)
|
|
|
|
assert await indexnow.submit("butter") == {"ok": False, "status": 403, "urls": 2}
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_네트워크_실패도_삼킨다(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("SITE_OUTPUT_DIR", str(_out(tmp_path, "butter")))
|
|
monkeypatch.setenv("INDEXNOW_KEY", "abc12345")
|
|
|
|
async def fake_post(self, url, json=None, **kwargs):
|
|
raise httpx.ConnectTimeout("timed out")
|
|
|
|
monkeypatch.setattr(httpx.AsyncClient, "post", fake_post)
|
|
|
|
result = await indexnow.submit("butter")
|
|
assert result["ok"] is False
|
|
assert "ConnectTimeout" in result["error"]
|