Skip to content

Commit ba12d57

Browse files
committed
fix PRのレビュー修正
1 parent 7dd8ec6 commit ba12d57

5 files changed

Lines changed: 46 additions & 48 deletions

File tree

backend/infrastructure/database/user_queries_test.go

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,38 @@ func TestTotalEmbeddingDiaryCount(t *testing.T) {
266266
ctx := context.Background()
267267
userID := testutil.CreateTestUser(t, db, "total-embedding-diary-count@example.com", "User")
268268

269-
t.Run("embeddingが存在しない場合は0を返す", func(t *testing.T) {
269+
t.Run("同一日記の複数チャンクは1件としてカウントされる", func(t *testing.T) {
270+
diaryID := uuid.New()
271+
now := time.Now().UnixMilli()
272+
if _, err := db.ExecContext(ctx,
273+
`INSERT INTO diaries (id, user_id, content, date, created_at, updated_at) VALUES ($1, $2, $3, $4, $5, $6)`,
274+
diaryID, userID, "日記内容", "2020-01-01", now, now,
275+
); err != nil {
276+
t.Fatalf("日記の挿入に失敗: %v", err)
277+
}
278+
279+
// 同じdiaryIDで複数のembeddingを挿入
280+
for i := 0; i < 3; i++ {
281+
if _, err := db.ExecContext(ctx,
282+
`INSERT INTO diary_embeddings (id, diary_id, user_id, content, embedding, model_version, created_at, updated_at)
283+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)`,
284+
uuid.New(), diaryID, userID, fmt.Sprintf("チャンク %d", i), "{0.1,0.2,0.3}", "v1", now, now,
285+
); err != nil {
286+
t.Fatalf("embeddingの挿入に失敗: %v", err)
287+
}
288+
}
289+
270290
count, err := database.TotalEmbeddingDiaryCount(ctx, db, userID)
271291
if err != nil {
272292
t.Fatalf("TotalEmbeddingDiaryCount失敗: %v", err)
273293
}
274-
if count != 0 {
275-
t.Errorf("期待 0, 実際 %d", count)
294+
if count != 1 {
295+
t.Errorf("期待 1, 実際 %d (DISTINCTが機能していない可能性があります)", count)
296+
}
297+
298+
totalChunks, _ := database.TotalEmbeddingCount(ctx, db, userID)
299+
if totalChunks != 3 {
300+
t.Errorf("TotalEmbeddingCount: 期待 3, 実際 %d", totalChunks)
276301
}
277302
})
278303
}

backend/service/diary/embedding_test.go

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,8 @@ func TestDiaryEntry_RegenerateAllEmbeddings_SemanticEnabled(t *testing.T) {
368368
userID := testutil.CreateTestUser(t, db, "regen-embedding@example.com", "Regen Test User")
369369
ctx := createAuthenticatedContext(userID)
370370

371-
// semantic_search_enabled=trueでuser_llmsを直接挿入
372-
now := time.Now().Unix()
373-
if _, err := db.ExecContext(ctx,
374-
`INSERT INTO user_llms (user_id, llm_provider, key, auto_summary_daily, auto_summary_monthly, auto_latest_trend_enabled, semantic_search_enabled, created_at, updated_at)
375-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`,
376-
userID, 1, "test-api-key", false, false, false, true, now, now,
377-
); err != nil {
378-
t.Fatalf("user_llmsの挿入に失敗: %v", err)
379-
}
371+
// semantic_search_enabled=trueでuser_llmsを挿入
372+
testutil.CreateTestUserLLMWithSettings(t, db, userID, "test-api-key", false, false, false, true)
380373

381374
redisClient := setupTestRedisForDiary(t)
382375
svc := &DiaryEntry{DB: db, Redis: redisClient}
@@ -401,14 +394,7 @@ func TestDiaryEntry_SearchDiaryEntriesSemantic_EnrichedQuery(t *testing.T) {
401394
ctx := createAuthenticatedContext(userID)
402395

403396
// semantic_search_enabled=trueでuser_llmsを挿入
404-
now := time.Now().Unix()
405-
if _, err := db.ExecContext(ctx,
406-
`INSERT INTO user_llms (user_id, llm_provider, key, auto_summary_daily, auto_summary_monthly, auto_latest_trend_enabled, semantic_search_enabled, created_at, updated_at)
407-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`,
408-
userID, 1, "test-api-key", false, false, false, true, now, now,
409-
); err != nil {
410-
t.Fatalf("user_llmsの挿入に失敗: %v", err)
411-
}
397+
testutil.CreateTestUserLLMWithSettings(t, db, userID, "test-api-key", false, false, false, true)
412398

413399
embedder := &mockGeminiEmbedder{}
414400
svc := &DiaryEntry{

backend/testutil/auth.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,19 @@ func GenerateTestTokens(t *testing.T, userID uuid.UUID) *model.TokenDetails {
102102
return tokens
103103
}
104104

105-
// CreateTestUserLLM creates a test LLM configuration for a user
105+
// CreateTestUserLLM creates a test LLM configuration for a user with default settings
106106
func CreateTestUserLLM(t *testing.T, db *sql.DB, userID uuid.UUID, apiKey string) {
107+
CreateTestUserLLMWithSettings(t, db, userID, apiKey, true, true, true, false)
108+
}
109+
110+
// CreateTestUserLLMWithSettings creates a test LLM configuration for a user with specific settings
111+
func CreateTestUserLLMWithSettings(t *testing.T, db *sql.DB, userID uuid.UUID, apiKey string, autoDaily, autoMonthly, autoTrend, semantic bool) {
107112
currentTime := time.Now().Unix()
108113

109114
// LLM provider: 1 = Gemini
110115
_, err := db.Exec(
111-
"INSERT INTO user_llms (user_id, llm_provider, key, auto_summary_daily, auto_summary_monthly, auto_latest_trend_enabled, created_at, updated_at) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
112-
userID, 1, apiKey, true, true, true, currentTime, currentTime,
116+
"INSERT INTO user_llms (user_id, llm_provider, key, auto_summary_daily, auto_summary_monthly, auto_latest_trend_enabled, semantic_search_enabled, created_at, updated_at) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
117+
userID, 1, apiKey, autoDaily, autoMonthly, autoTrend, semantic, currentTime, currentTime,
113118
)
114119
if err != nil {
115120
t.Fatalf("Failed to create test user LLM: %v", err)

frontend/src/lib/components/molecules/DiaryChunkTimeline.svelte

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
</div>
4646

4747
<!-- タイムライン本体: PC は常時表示、モバイルはトグル -->
48-
<div class="hidden sm:block px-4 pt-3 pb-1">
48+
<div class="{mobileOpen ? '' : 'hidden'} sm:block px-4 pt-3 pb-1">
4949
<!-- チャンク一覧 -->
5050
<div class="border-l-2 border-indigo-200 dark:border-indigo-700 pl-5 space-y-2 pb-2">
5151
{#each status.chunkSummaries as summary}
@@ -63,28 +63,6 @@
6363
<span>{$_("diary.embedding.updatedAt")}: {new Date(status.updatedAt * 1000).toLocaleString()}</span>
6464
</div>
6565
</div>
66-
67-
<!-- モバイル展開時 -->
68-
{#if mobileOpen}
69-
<div class="sm:hidden px-4 pt-3 pb-1">
70-
<!-- チャンク一覧 -->
71-
<div class="border-l-2 border-indigo-200 dark:border-indigo-700 pl-5 space-y-2 pb-2">
72-
{#each status.chunkSummaries as summary}
73-
<div class="relative">
74-
<div class="absolute -left-[1.6rem] top-1 w-2.5 h-2.5 rounded-full border-2 border-indigo-400 dark:border-indigo-500 bg-white dark:bg-gray-800"></div>
75-
<p class="text-sm text-gray-700 dark:text-gray-300 leading-snug">
76-
{summary || $_("diary.embedding.chunkSummaryEmpty")}
77-
</p>
78-
</div>
79-
{/each}
80-
</div>
81-
<!-- メタ情報フッター -->
82-
<div class="mt-1 pb-2 flex flex-wrap gap-x-4 gap-y-0.5 text-[11px] text-gray-400 dark:text-gray-500">
83-
<span>{$_("diary.embedding.modelVersion")}: <span class="font-mono">{status.modelVersion}</span></span>
84-
<span>{$_("diary.embedding.updatedAt")}: {new Date(status.updatedAt * 1000).toLocaleString()}</span>
85-
</div>
86-
</div>
87-
{/if}
8866
</div>
8967
{/if}
9068
{/await}

frontend/src/routes/llm/+page.svelte

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,12 @@
144144
];
145145
146146
// RAGカード用データ
147-
$: ragCards = [
147+
$: ragCards: {
148+
title: string;
149+
value: number;
150+
subLabel?: string;
151+
color: string;
152+
}[] = [
148153
{
149154
title: $_("llm.metrics.totalEmbeddings"),
150155
value: metrics.summary.totalEmbeddingDiaries,
@@ -154,7 +159,6 @@
154159
{
155160
title: $_("llm.metrics.pendingEmbeddings"),
156161
value: metrics.summary.pendingEmbeddings,
157-
subLabel: null,
158162
color: "text-pink-600 dark:text-pink-400",
159163
},
160164
];

0 commit comments

Comments
 (0)