여러 줄 주석이 설명보다 경위(예전·실측·지적)를 적고 있어 읽는 사람이 결론을 찾기 어려웠다. - ts·tsx·js·mjs·css·py 478개: 여러 줄 주석은 첫 문장 한 줄로, 과거형·날짜 문장은 삭제 - 주석 위치는 TypeScript 파서·파이썬 tokenize/ast 로 찾는다 — 문자열 안의 # · /* 는 건드리지 않는다 - eslint·ts·noqa·type: ignore 같은 지시 주석은 그대로 둔다 파이썬 275개 정리 전후 AST 동일, TS 298개 주석 뺀 토큰 동일(빈 JSX 주석 10곳만 차이). site·frontend·admin tsc, site vitest 105 passed Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
86 lines
3.3 KiB
Python
86 lines
3.3 KiB
Python
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
|
|
from services import azure_static
|
|
|
|
|
|
class FakeContainer:
|
|
def __init__(self):
|
|
self.uploads = {}
|
|
self.existing = []
|
|
self.deleted = []
|
|
|
|
def upload_blob(self, name, data, **options):
|
|
self.uploads[name] = {"body": data.read(), **options}
|
|
|
|
def list_blobs(self, name_starts_with):
|
|
return [SimpleNamespace(name=name) for name in self.existing if name.startswith(name_starts_with)]
|
|
|
|
def delete_blob(self, name):
|
|
self.deleted.append(name)
|
|
|
|
|
|
def test_설정없으면_로컬발행만_유지(monkeypatch):
|
|
monkeypatch.delenv("AZURE_STORAGE_CONNECTION_STRING", raising=False)
|
|
assert azure_static.is_configured() is False
|
|
|
|
|
|
def test_ai_for_web_아래에_사이트와_공용산출물을_업로드(tmp_path, monkeypatch):
|
|
(tmp_path / "assets").mkdir()
|
|
(tmp_path / "assets" / "index-abc.js").write_text("console.log(1)")
|
|
(tmp_path / "fonts").mkdir()
|
|
(tmp_path / "fonts" / "Pretendard.woff2").write_bytes(b"font")
|
|
# 오리진 루트 파일 — 크롤러가 robots.txt 를 읽는 유일한 자리다(RFC 9309).
|
|
(tmp_path / "robots.txt").write_text("User-agent: *\nAllow: /\n")
|
|
(tmp_path / "sitemap.xml").write_text("<sitemapindex/>")
|
|
site_dir = tmp_path / "s" / "butter"
|
|
(site_dir / "about").mkdir(parents=True)
|
|
(site_dir / "index.html").write_text("<h1>Butter</h1>")
|
|
(site_dir / "about" / "index.html").write_text("<h1>About</h1>")
|
|
# 다른 사업장의 발행본.
|
|
(tmp_path / "s" / "joy").mkdir(parents=True)
|
|
(tmp_path / "s" / "joy" / "index.html").write_text("<h1>Joy</h1>")
|
|
|
|
container = FakeContainer()
|
|
container.existing = [
|
|
"ai-for-web/s/butter/index.html",
|
|
"ai-for-web/s/butter/old/index.html",
|
|
]
|
|
service = SimpleNamespace(get_container_client=lambda name: container)
|
|
monkeypatch.setattr(
|
|
azure_static.BlobServiceClient,
|
|
"from_connection_string",
|
|
lambda value: service,
|
|
)
|
|
monkeypatch.setattr(azure_static, "output_dir", lambda: Path(tmp_path))
|
|
monkeypatch.setenv("AZURE_STORAGE_CONNECTION_STRING", "UseDevelopmentStorage=true")
|
|
monkeypatch.delenv("AZURE_STORAGE_PREFIX", raising=False)
|
|
|
|
result = azure_static._publish_sync("butter")
|
|
|
|
assert set(container.uploads) == {
|
|
"ai-for-web/assets/index-abc.js",
|
|
"ai-for-web/fonts/Pretendard.woff2",
|
|
"ai-for-web/robots.txt",
|
|
"ai-for-web/sitemap.xml",
|
|
"ai-for-web/s/butter/index.html",
|
|
"ai-for-web/s/butter/about/index.html",
|
|
}
|
|
assert container.deleted == ["ai-for-web/s/butter/old/index.html"]
|
|
assert result == {
|
|
"container": "$web",
|
|
"prefix": "ai-for-web",
|
|
"shared_files": 4,
|
|
"site_files": 2,
|
|
"removed_stale": 1,
|
|
}
|
|
|
|
|
|
def test_루트_robots_와_사이트맵은_짧게_캐시된다():
|
|
# 해시가 박힌 번들만 영구 캐시다.
|
|
assert "immutable" in azure_static._cache_control(Path("assets/index-abc.js"))
|
|
assert azure_static._cache_control(Path("robots.txt")) == "public, max-age=60, must-revalidate"
|
|
assert azure_static._cache_control(Path("sitemap.xml")) == "public, max-age=60, must-revalidate"
|
|
assert azure_static._cache_control(Path("s/butter/index.html")) == "public, max-age=60, must-revalidate"
|
|
assert azure_static._cache_control(Path("fonts/Pretendard.woff2")) == "public, max-age=604800"
|