fix: 파이프라인 3대 핵심 버그 수정
- generate-report: Harness 4 groundTruth 주입 레이어 추가 (IG/YT/FB/NaverBlog/NaverPlace/GangnamUnni 필드 강제 주입, diagnosis 폴백, qualityReport DB 저장)
- discover-channels: CLINIC_NOT_REGISTERED 조기 종료 제거 + clinics 캐시 fast-path 추가 (14일 TTL, Firecrawl fallback 재활성화)
- collect-channel-data: silent skip → {status, reason, attemptedAt} 구조적 기록 (naverBlog/naverPlace/googleMaps/gangnamUnni)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
aabba1534b
commit
c753d8593f
3 files changed
+398
-36
No files matched your search
@@ -195,6 +195,157 @@ ${JSON.stringify(scrapeData.branding || {}, null, 2).slice(0, 1000)}
|
||||
report.visionAnalysis = vision;
|
||||
}
|
||||
|
||||
// ─── Harness 4: GroundTruth channel injection ───
|
||||
// Perplexity occasionally drops channel metrics even though they exist in channelData.
|
||||
// For each channel we force-inject the numeric fields from the actually-collected data.
|
||||
// Same pattern as the Vision injection above (foundingYear / gangnamUnni), extended
|
||||
// to instagram / youtube / facebook / naverBlog / naverPlace.
|
||||
report.channelAnalysis = report.channelAnalysis || {};
|
||||
const injectedChannels: string[] = [];
|
||||
|
||||
// Instagram — prefer instagramAccounts[0], fall back to channelData.instagram
|
||||
const igAccountsList = (channelData.instagramAccounts as Record<string, unknown>[] | undefined) || [];
|
||||
const igPrimary = (igAccountsList[0] || channelData.instagram) as Record<string, unknown> | undefined;
|
||||
const igPostsSummary = channelData.instagramPosts as Record<string, unknown> | undefined;
|
||||
if (igPrimary) {
|
||||
const target = (report.channelAnalysis.instagram ||= {} as Record<string, unknown>);
|
||||
if (isMissingValue(target.followers) && igPrimary.followers) {
|
||||
target.followers = igPrimary.followers;
|
||||
}
|
||||
// Prefer profile-level post count; fall back to scraped posts summary
|
||||
if (isMissingValue(target.posts)) {
|
||||
if (igPrimary.posts) target.posts = igPrimary.posts;
|
||||
else if (igPostsSummary?.totalPosts) target.posts = igPostsSummary.totalPosts;
|
||||
}
|
||||
if (isMissingValue(target.status)) target.status = "active";
|
||||
injectedChannels.push(`instagram(f=${target.followers},p=${target.posts})`);
|
||||
}
|
||||
|
||||
// YouTube
|
||||
const ytGT = channelData.youtube as Record<string, unknown> | undefined;
|
||||
if (ytGT) {
|
||||
const target = (report.channelAnalysis.youtube ||= {} as Record<string, unknown>);
|
||||
if (isMissingValue(target.subscribers) && ytGT.subscribers) {
|
||||
target.subscribers = ytGT.subscribers;
|
||||
}
|
||||
if (isMissingValue((target as Record<string, unknown>).videos) && ytGT.totalVideos) {
|
||||
(target as Record<string, unknown>).videos = ytGT.totalVideos;
|
||||
}
|
||||
if (isMissingValue(target.status)) target.status = "active";
|
||||
injectedChannels.push(`youtube(s=${target.subscribers})`);
|
||||
}
|
||||
|
||||
// Facebook
|
||||
const fbGT = channelData.facebook as Record<string, unknown> | undefined;
|
||||
if (fbGT) {
|
||||
const target = (report.channelAnalysis.facebook ||= {} as Record<string, unknown>);
|
||||
if (isMissingValue(target.followers) && fbGT.followers) {
|
||||
target.followers = fbGT.followers;
|
||||
}
|
||||
if (isMissingValue((target as Record<string, unknown>).likes) && fbGT.likes) {
|
||||
(target as Record<string, unknown>).likes = fbGT.likes;
|
||||
}
|
||||
if (isMissingValue(target.status)) target.status = "active";
|
||||
injectedChannels.push(`facebook(f=${target.followers})`);
|
||||
}
|
||||
|
||||
// Naver Blog — RSS provides totalResults + posts
|
||||
const nbGT = channelData.naverBlog as Record<string, unknown> | undefined;
|
||||
if (nbGT && !nbGT.skipped) {
|
||||
const target = (report.channelAnalysis.naverBlog ||= {} as Record<string, unknown>);
|
||||
if (isMissingValue(target.posts) && nbGT.totalResults) {
|
||||
target.posts = nbGT.totalResults;
|
||||
}
|
||||
if (isMissingValue(target.status)) {
|
||||
target.status = (nbGT.totalResults as number) > 0 ? "active" : "inactive";
|
||||
}
|
||||
injectedChannels.push(`naverBlog(p=${target.posts})`);
|
||||
}
|
||||
|
||||
// Naver Place — Naver Local Search doesn't include rating/reviews, but stores the place metadata.
|
||||
// If the place was found we at least set status=active; rating/reviews often come via Vision.
|
||||
const npGT = channelData.naverPlace as Record<string, unknown> | undefined;
|
||||
if (npGT && !npGT.skipped && npGT.name) {
|
||||
const target = (report.channelAnalysis.naverPlace ||= {} as Record<string, unknown>);
|
||||
if (isMissingValue(target.status)) target.status = "active";
|
||||
if (isMissingValue((target as Record<string, unknown>).name) && npGT.name) {
|
||||
(target as Record<string, unknown>).name = npGT.name;
|
||||
}
|
||||
// Rating/reviews may be injected by Vision block above; don't overwrite
|
||||
injectedChannels.push(`naverPlace(${npGT.name})`);
|
||||
}
|
||||
|
||||
// GangnamUnni — Vision block handled the rating/reviews path already.
|
||||
// Here we only fill status/rating when they come directly from the scraper (D).
|
||||
const guGT = channelData.gangnamUnni as Record<string, unknown> | undefined;
|
||||
if (guGT && !guGT.skipped) {
|
||||
const target = (report.channelAnalysis.gangnamUnni ||= {} as Record<string, unknown>);
|
||||
if (isMissingValue(target.rating) && guGT.rating) {
|
||||
target.rating = guGT.rating;
|
||||
(target as Record<string, unknown>).ratingScale = 10;
|
||||
}
|
||||
if (isMissingValue(target.reviews) && (guGT.totalReviews || guGT.reviews)) {
|
||||
target.reviews = guGT.totalReviews || guGT.reviews;
|
||||
}
|
||||
if (isMissingValue(target.status)) target.status = "active";
|
||||
injectedChannels.push(`gangnamUnni(r=${target.rating})`);
|
||||
}
|
||||
|
||||
if (injectedChannels.length > 0) {
|
||||
console.log(`[report] GroundTruth injected: ${injectedChannels.join(", ")}`);
|
||||
}
|
||||
|
||||
// ─── Harness 4b: Diagnosis fallback ───
|
||||
// ProblemDiagnosis.tsx returns null when `problemDiagnosis` is empty, hiding the whole
|
||||
// section. Make sure each weak channel contributes at least one diagnosis item so the
|
||||
// frontend renders. Only runs when AI didn't fill diagnosis itself.
|
||||
const DEFAULT_DIAGNOSIS: Record<string, { issue: string; recommendation: string }> = {
|
||||
instagram: {
|
||||
issue: "Instagram 업로드 빈도가 부족하거나 게시물 참여율이 낮습니다",
|
||||
recommendation: "주 3회 이상 주제별 콘텐츠 발행 + 릴스 비중 40% 이상 확보",
|
||||
},
|
||||
youtube: {
|
||||
issue: "YouTube 채널 활동이 저조하여 브랜드 신뢰도 확보가 어렵습니다",
|
||||
recommendation: "시술 Before/After Shorts 주 2회, 롱폼 월 2회 업로드 루틴 수립",
|
||||
},
|
||||
facebook: {
|
||||
issue: "Facebook 페이지 활동이 낮아 유입 기여가 제한적입니다",
|
||||
recommendation: "광고 랜딩 채널로 재정의하고 월 4회 프로모션 포스트 자동화",
|
||||
},
|
||||
naverBlog: {
|
||||
issue: "네이버 블로그 최신 포스팅 양이 부족하여 로컬 SEO 기회를 놓치고 있습니다",
|
||||
recommendation: "주요 시술 키워드별 주 2건, 월 8건 이상 SEO 최적화 포스팅",
|
||||
},
|
||||
naverPlace: {
|
||||
issue: "네이버 플레이스 리뷰/콘텐츠 관리가 체계화되어 있지 않습니다",
|
||||
recommendation: "방문 리뷰 유도 프로세스 구축 + 키워드·사진 리뷰 월 20건 확보",
|
||||
},
|
||||
gangnamUnni: {
|
||||
issue: "강남언니 프로필 정보와 답변률이 미흡합니다",
|
||||
recommendation: "의사별 프로필 완성도 100% + 문의 24시간 내 응답 체계",
|
||||
},
|
||||
};
|
||||
const weakStatuses = new Set(["inactive", "weak", "not_found", undefined]);
|
||||
for (const ch of Object.keys(DEFAULT_DIAGNOSIS)) {
|
||||
const node = (report.channelAnalysis as Record<string, unknown>)[ch] as
|
||||
| Record<string, unknown>
|
||||
| undefined;
|
||||
if (!node) continue;
|
||||
const existing = node.diagnosis as unknown[] | undefined;
|
||||
if (Array.isArray(existing) && existing.length > 0) continue;
|
||||
const score = typeof node.score === "number" ? node.score : null;
|
||||
const status = node.status as string | undefined;
|
||||
const needsFallback = (score !== null && score < 60) || weakStatuses.has(status);
|
||||
if (!needsFallback) continue;
|
||||
const def = DEFAULT_DIAGNOSIS[ch];
|
||||
node.diagnosis = [{
|
||||
issue: def.issue,
|
||||
severity: score !== null && score < 40 ? "critical" : "warning",
|
||||
recommendation: def.recommendation,
|
||||
}];
|
||||
console.log(`[report] Diagnosis fallback injected for ${ch} (score=${score}, status=${status})`);
|
||||
}
|
||||
|
||||
// Embed channel enrichment data for frontend mergeEnrichment()
|
||||
report.channelEnrichment = channelData;
|
||||
report.enrichedAt = new Date().toISOString();
|
||||
@@ -320,10 +471,31 @@ ${JSON.stringify(scrapeData.branding || {}, null, 2).slice(0, 1000)}
|
||||
console.warn(`[harness] Low report quality (${qualityReport.score}/100):`, qualityReport.warnings);
|
||||
}
|
||||
|
||||
// Persist quality report into analysis_data.qualityReport so the frontend (and
|
||||
// future debugging queries) can inspect why specific sections rendered empty.
|
||||
// Downgrade status to 'partial' when too many important/critical fields are missing.
|
||||
const totalMissing = qualityReport.missingCritical.length + qualityReport.missingImportant.length;
|
||||
const reportStatus = (qualityReport.missingCritical.length > 0 || totalMissing >= 5)
|
||||
? "partial"
|
||||
: "complete";
|
||||
const enrichedAnalysisData = {
|
||||
...analysisData,
|
||||
qualityReport: {
|
||||
score: qualityReport.score,
|
||||
missingCritical: qualityReport.missingCritical,
|
||||
missingImportant: qualityReport.missingImportant,
|
||||
missingOptional: qualityReport.missingOptional,
|
||||
warnings: qualityReport.warnings,
|
||||
injectedChannels,
|
||||
generatedAt: new Date().toISOString(),
|
||||
},
|
||||
};
|
||||
|
||||
// Legacy: marketing_reports
|
||||
await supabase.from("marketing_reports").update({
|
||||
report,
|
||||
status: "complete",
|
||||
analysis_data: enrichedAnalysisData,
|
||||
status: reportStatus,
|
||||
data_quality_score: qualityReport.score,
|
||||
pipeline_completed_at: new Date().toISOString(),
|
||||
updated_at: new Date().toISOString(),
|
||||
|
||||
Reference in new issue
Block a user