o2o-site-AEO/solution/frontend/tests/generation.mjs
Mina Choi 079c93a62a [feat] solution,postgres-init,docs: 생성 진행 상태 · 새로 만들기 존중 · 발행본 색인·파비콘
작업트리에 커밋되지 않은 채 쌓여 있던 것과, 오늘 찾은 문제 셋을 함께 담는다.

## 1. 콘텐츠 생성 진행 상태 (작업트리에 있던 것)

COPY 잡의 실제 단계를 DB에 기록하고 응답으로 내보낸다. 폴링 횟수로 진행률을 흉내 내던
것을 걷어냈다. 새로고침·재접속해도 jobId 로 이어서 본다.

- services/copy_steps.py · services/job_progress.py · common/job_errors.py (신규)
- postgres-init/migrations/0013_job_progress.sql + init.sql
- 프론트: useGenerationJob · generationLabels (신규), Step5Generating·pollJob 배선,
  orval 모델 갱신(jobProgress · jobStep · jobStepStatus · jobStepReason)
- docs/GENERATION_FLOW.md (신규)

## 2. 발행된 사이트만 색인한다

실측(2026-09-15): 디스크의 발행본 33곳 중 **15곳이 draft 인데 `index, follow`** 였고
사이트맵에도 올라가 있었다. 사장님이 발행 버튼을 누른 적 없는 사이트가 짓다 만 상태로
구글에 실려 있었다는 뜻이다.

head.ts 가 robots 를 하드코딩하고 payload 의 `site.status` 를 보지 않았다.
"색인을 막을 이유가 없다"는 주석은 굽는 것이 곧 발행이던 시절의 말인데, 지금은 빌더
미리보기만 눌러도 draft 로 구워진다.

- seo/head.ts: PUBLISHED 일 때만 index, 아니면 `noindex, follow`
- 사이트맵·`/s` 목록·llms.txt 에서도 함께 빠진다 — 그쪽은 구운 HTML 의 robots 를 읽어
  거른다(seo/directory.ts readBakedNoindex). 규칙을 두 자리에 두지 않으려고 한 곳에 뒀다

## 3. [새로 크롤링하고 사이트 생성하기] 를 뒤집지 않는다

ba90a19 의 중복 합치기가 **일부러 다시 만들려는 경우까지** 기존 사업장으로 끌고 갔다 —
새로 만들기를 눌렀는데 기존 에디터가 열린다(사장님 보고 2026-09-15).

- Req_VerifyPlaceByUrl.reuse_existing (기본 True — 다른 호출자의 동작은 그대로)
- place_service.verify_place_by_url: 끄면 이어붙이지 않는다. 다만 **비어 있는 중복 행은
  계속 치운다** — 원래 막으려던 누적이 그것이고 빈 행은 잃을 것이 없다
- ensureServerPlace: 위저드는 새로 만들기 경로에서만 오므로 False 로 보낸다

## 4. 발행본 파비콘

발행본에 파비콘 링크가 아예 없어 브라우저 탭에 기본 아이콘이 떴다. 파일은 오리진 루트의
공용 자산이라 사이트마다 복사하지 않고 루트 절대경로로 가리킨다.

검증: site vitest 84건 통과 · tsc(site·frontend) · eslint 통과.
백엔드 pytest 는 로컬 DB 비밀번호가 맞지 않아 돌리지 못했다(a5b8701 과 같은 자리).
발행본 반영에는 전체 재굽기가 필요하다.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-15 17:29:27 +09:00

126 lines
5.8 KiB
JavaScript

// 실행: 개발 서버를 켠 뒤 node solution/frontend/tests/generation.mjs [URL]
// 모든 API는 가짜 응답으로 막는다. 외부 생성 API·실제 사업장에는 쓰지 않는다.
import assert from 'node:assert/strict';
import {chromium} from 'playwright';
const origin = process.argv[2] ?? 'http://127.0.0.1:3015';
const placeId = '10000000-0000-4000-8000-000000000001';
const jobId = '20000000-0000-4000-8000-000000000001';
const result = {success: true, code: 0};
const browser = await chromium.launch({channel: 'chrome'});
let passed = 0;
async function scenario(name, run) {
const page = await browser.newPage();
page.on('pageerror', (error) => console.error(error.message));
const state = {
posts: [], gets: 0, unavailable: false,
job: {job_id: jobId, place_id: placeId, job_type: 3, status: 2, attempts: 1,
progress: {attempt: 1, steps: [
{id: 'prepare', status: 'done'}, {id: 'generate', status: 'running'},
{id: 'save', status: 'pending'}, {id: 'faq_fill', status: 'pending'},
]}},
};
await page.addInitScript(() => localStorage.setItem('o2o-web4ai.accessToken', 'test-token'));
await page.route('**/*', async (route) => {
const url = new URL(route.request().url());
if (!url.pathname.startsWith('/v1/')) {
return url.origin === origin ? route.continue() : route.abort();
}
let body = {result};
if (url.pathname === `/v1/job/${jobId}`) {
state.gets += 1;
if (state.unavailable) return route.fulfill({status: 503, json: {}});
body.job = state.job;
} else if (url.pathname.endsWith('/copy')) {
state.posts.push(route.request().postDataJSON());
body = {...body, job_id: jobId, created: true, status: state.job.status};
} else if (url.pathname === `/v1/place/${placeId}`) {
body.place = {place_id: placeId, name: '진행 복구 테스트', category: 1, status: 3,
verified_at: '2026-09-15T00:00:00Z', road_address: '서울 강남구'};
} else if (url.pathname.endsWith('/schema')) body.fields = [];
else if (url.pathname.endsWith('/fact/list')) body.facts = [];
else if (url.pathname.endsWith('/media')) body.media = [];
else if (url.pathname.endsWith('/site')) body.site = {site_id: 'test-site', status: 1, template_id: 'stay.oasi'};
else if (url.pathname.endsWith('/auth/me')) body = {...body, user_id: 'test-owner', id: 'test', role: 1};
await route.fulfill({json: body});
});
const open = (suffix = `&jobId=${jobId}`) => page.goto(`${origin}/builder?step=generating&flow=onboarding&placeId=${placeId}${suffix}`);
try {
await run(page, state, open);
console.log(`PASS ${name}`);
passed += 1;
} catch (error) {
console.error(await page.locator('body').innerText());
console.error(JSON.stringify({gets: state.gets, posts: state.posts}));
throw error;
} finally {
await page.close();
}
}
try {
await scenario('새로고침은 같은 잡 조회만, 서버가 멈추면 표시도 그대로', async (page, state, open) => {
await open();
await page.getByText('소개문·FAQ 생성 및 근거 검증', {exact: true}).waitFor();
await page.reload();
await page.getByText('소개문·FAQ 생성 및 근거 검증', {exact: true}).waitFor();
await page.waitForFunction(() => document.querySelectorAll('ol li').length === 4);
await page.waitForTimeout(2300);
assert.equal(state.posts.length, 0);
assert.ok(state.gets >= 3);
assert.match(await page.locator('ol li').nth(1).innerText(), /진행 중/);
assert.match(await page.locator('ol li').nth(2).innerText(), /대기/);
assert.equal(await page.getByText(/\d+%/).count(), 0);
});
await scenario('구 URL은 resume으로 복구하고 잡 ID를 주소에 보존', async (page, state, open) => {
await open('');
await page.waitForURL(`**jobId=${jobId}`);
assert.ok(state.posts.length > 0);
assert.ok(state.posts.every((body) => body.resume === true));
const count = state.posts.length;
await page.reload();
await page.getByText('소개문·FAQ 생성 및 근거 검증', {exact: true}).waitFor();
assert.equal(state.posts.length, count);
});
await scenario('완료된 잡 재접속은 재생성 없이 편집기로', async (page, state, open) => {
state.job.status = 3;
await open();
await page.waitForURL('**step=editor**');
assert.equal(new URL(page.url()).searchParams.has('jobId'), false);
assert.equal(state.posts.length, 0);
});
await scenario('실패는 완료로 표시하거나 자동으로 편집기로 보내지 않음', async (page, state, open) => {
state.job.status = 4;
await open();
await page.getByRole('heading', {name: '콘텐츠 생성을 완료하지 못했습니다'}).waitFor();
assert.equal(new URL(page.url()).searchParams.get('step'), 'generating');
assert.match(await page.locator('ol li').nth(1).innerText(), /중단/);
assert.equal(state.posts.length, 0);
});
await scenario('통신 오류 뒤에는 같은 잡 조회만 재시도', async (page, state, open) => {
state.unavailable = true;
await open();
await page.getByRole('button', {name: '상태 다시 확인'}).waitFor();
state.unavailable = false;
await page.getByRole('button', {name: '상태 다시 확인'}).click();
await page.getByText('소개문·FAQ 생성 및 근거 검증', {exact: true}).waitFor();
assert.equal(state.posts.length, 0);
});
await scenario('다른 사업장의 잡 ID는 완료여도 이동 금지', async (page, state, open) => {
state.job.place_id = 'other-place';
state.job.status = 3;
await open();
await page.getByText('이 화면의 생성 작업이 아닙니다. 이전 단계에서 다시 시작해 주세요.').waitFor();
assert.equal(new URL(page.url()).searchParams.get('step'), 'generating');
});
console.log(`${passed} scenarios passed`);
} finally {
await browser.close();
}