/**
* E2E: 검색 봇에게 전달되는 화면(SEO 렌더링)에 본문이 포함되는지
*
* 회귀 (#86): 위지윅 편집기 플러그인이 본문 영역을 확장으로 교체하는데, 봇용 화면을
* 만드는 서버 렌더러가 그 교체 규칙(호스트 props 전달)을 몰라 본문을 빈 요소로
* 내보냈다. 메타 태그에는 본문이 들어가지만 화면 본문 영역은 `
` 였다.
*
* 단위 테스트(ExtensionPointPropsRenderingTest)가 렌더러 계약을 잠그지만, 결함이
* "레이아웃 파일 + 확장 자산 + 실제 데이터" 가 만나는 실환경에서만 드러났으므로
* 실제 HTTP 응답으로도 잠근다.
*
* 브라우저 렌더링이 아니라 봇이 받는 원본 HTML 을 검사해야 하므로 `request` 픽스처로
* 직접 요청한다(React 가 실행되면 결함이 가려진다).
*
* @scenario ep_site=board_post, injection=extension_active, nesting=direct_child, host_gate=if_true, content_kind=html_mode
* @effects ep_props_resolved_into_context, subtree_inherits_ep_props
*/
import { test, expect, type APIRequestContext } from '@playwright/test';
/** 봇 렌더링을 강제하는 쿼리 파라미터 (검색엔진 escaped fragment 규약). */
const BOT_QUERY = '_escaped_fragment_=';
/**
* 봇 User-Agent (BotDetector 라이브러리 매칭 경로).
*
* 봇 판정은 escaped fragment 쿼리와 UA 두 경로로 진입한다. 한쪽만 검증하면 다른 경로에서
* 본문이 비어도 드러나지 않으므로 두 경로를 모두 잠근다.
*/
const BOT_USER_AGENT =
'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)';
/** 확장 주입 본문이 비어 있을 때 나오던 회귀 시그니처. */
const EMPTY_INJECTED_BODY = '';
/** 댓글 본문 영역을 식별하는 className (게시판 답글 확장 포인트). */
const REPLY_CONTENT_MARKER = 'prose-sm dark:prose-invert';
/**
* 봇 렌더링 응답(HTML + 캐시 헤더)을 가져옵니다.
*
* @param request Playwright 요청 컨텍스트
* @param path 대상 경로 (쿼리 포함 가능)
* @returns 응답 본문 HTML 과 X-SEO-Cache 헤더 값
*/
async function fetchBotResponse(
request: APIRequestContext,
path: string,
transport: 'escaped_fragment' | 'bot_user_agent' = 'escaped_fragment'
): Promise<{ html: string; cache: string | undefined }> {
const separator = path.includes('?') ? '&' : '?';
const url = transport === 'escaped_fragment' ? `${path}${separator}${BOT_QUERY}` : path;
const response = await request.get(
url,
transport === 'bot_user_agent' ? { headers: { 'User-Agent': BOT_USER_AGENT } } : undefined
);
expect(response.status(), `${path} 봇 렌더링 응답 코드 (${transport})`).toBe(200);
const headers = response.headers();
return {
html: await response.text(),
// 헤더명은 서버가 소문자로 정규화한다
cache: headers['x-seo-cache'],
};
}
/**
* 봇 렌더링 HTML 을 가져옵니다.
*
* 응답이 봇 렌더러를 실제로 거쳤는지(캐시 헤더 존재) 함께 확인합니다 — 헤더가 없으면
* 일반 SPA 응답을 받은 것이라 본문 검증이 무의미해집니다.
*
* @param request Playwright 요청 컨텍스트
* @param path 대상 경로 (쿼리 포함 가능)
* @returns 응답 본문 HTML
*/
async function fetchBotHtml(
request: APIRequestContext,
path: string,
transport: 'escaped_fragment' | 'bot_user_agent' = 'escaped_fragment'
): Promise {
const { html, cache } = await fetchBotResponse(request, path, transport);
expect(cache, `${path} 응답이 봇 렌더러를 거치지 않았습니다 (X-SEO-Cache 헤더 없음)`).toBeDefined();
expect(['HIT', 'MISS']).toContain(cache);
return html;
}
/**
* 봇 HTML 의 `` 부분만 잘라냅니다.
*
* 메타 태그에는 본문이 들어 있으므로, 화면 본문 영역 검증은 body 로 한정해야 한다.
*
* @param html 전체 HTML
* @returns body 이후 문자열
*/
function bodyOf(html: string): string {
const index = html.indexOf('');
return index === -1 ? html : html.slice(index);
}
test.describe('봇 렌더링 본문 노출', () => {
/**
* @scenario ep_site=board_post, injection=extension_active, nesting=direct_child, host_gate=if_true, content_kind=html_mode
* @effects ep_props_resolved_into_context, subtree_inherits_ep_props, escaped_fragment_request_renders_content
*/
test('게시글 본문이 메타뿐 아니라 봇 화면 본문 영역에도 출력된다 @smoke', async ({ request }) => {
// 목록에서 실제 게시글 경로를 얻는다 — 고정 ID 하드코딩 회피(환경별 데이터 상이).
const listHtml = await fetchBotHtml(request, '/board/notice');
const paths = [...bodyOf(listHtml).matchAll(/href="(\/board\/notice\/\d+)"/g)].map((m) => m[1]);
expect(paths.length, '공지 게시판 목록에서 게시글 링크를 찾지 못했습니다').toBeGreaterThan(0);
// 가려진 글/비밀글은 본문이 없는 것이 정상이므로, description 이 채워진 글을 고른다.
let checked = false;
for (const path of paths.slice(0, 5)) {
const postHtml = await fetchBotHtml(request, path);
const description = postHtml.match(/ {
// 답글이 달린 글을 목록에서 찾는다 — 고정 ID 하드코딩 회피.
const listHtml = await fetchBotHtml(request, '/board/qna');
const paths = [...bodyOf(listHtml).matchAll(/href="(\/board\/qna\/\d+)"/g)].map((m) => m[1]);
expect(paths.length, 'Q&A 게시판 목록에서 게시글 링크를 찾지 못했습니다').toBeGreaterThan(0);
let checked = false;
for (const path of paths.slice(0, 8)) {
const body = bodyOf(await fetchBotHtml(request, path));
// 댓글 본문 영역의 className (레이아웃의 답글 확장 포인트)
const replyIndex = body.indexOf(REPLY_CONTENT_MARKER);
if (replyIndex === -1) {
continue;
}
const replyBlock = body.slice(replyIndex, replyIndex + 600);
// 확장 주입 본문이 비어 있으면 여기가 로 나온다
expect(replyBlock, `${path} 의 댓글 본문이 비어 있습니다`).not.toContain(EMPTY_INJECTED_BODY);
// 댓글 영역 안에 실제 텍스트가 있어야 한다
expect(replyBlock, `${path} 의 댓글 영역에 텍스트가 없습니다`).toMatch(/>[^<>]{2,});
checked = true;
break;
}
test.skip(!checked, '답글이 달린 공개 게시글이 없어 건너뜁니다');
});
/**
* @scenario ep_site=page, injection=extension_active, nesting=direct_child, host_gate=if_true, content_kind=html_mode
* @effects ep_props_resolved_into_context
*/
test('페이지 본문이 봇 화면에 출력된다', async ({ request }) => {
const html = await fetchBotHtml(request, '/page/about');
const body = bodyOf(html);
expect(body).not.toContain(EMPTY_INJECTED_BODY);
// 페이지 제목이 h1 으로, 본문이 그 아래에 실제 텍스트로 나와야 한다
expect(body).toMatch(/