[Developer] #215 AC2/AC4/AC6 fixes after QA reject

QA 1차 (커밋 6ab4c0d 검증) 에서 3건 AC 미충족 → 03-Developer 반려.
본 커밋은 그 3건을 해결한다.

AC6 — _AiSuggestButton 가시성 분기 분리:
- optIn=false → 숨김 유지
- optIn=true && !ready → 노출 + disabled + Tooltip("AI 도움을 먼저 켜주세요")
- optIn=true && ready → enabled
AC5 보완: 후보의 c.level 직접 전달 (이전 "나는" 휴리스틱 제거).
FrameSuggestionDialog.show 반환 타입 String? → FrameCandidate?.

AC4 — L2:2 + L3:1 분포 강제:
- few_shot prompt 에 "정확히 L2 2개 + L3 1개" 명시
- suggestFrame 결과를 _shapeDistribution(l2Quota=2, l3Quota=1) 로 후처리
- 부족분은 패딩 X (graceful: UI 가 더 적은 카드만 표시)

AC2 — 다운로드 진행률 + 일시정지/재개 UI:
- ModelDownloadController (StateNotifier<DownloadProgress?>)
  · start() / pause() / resume() / cancel()
  · pause() 는 subscription 만 cancel, .tmp + meta_kv 유지 → resume 시 Range header 로 이어받음
- AiSettingsController.setOptIn(true) → controller.start() 자동 호출
- SettingsScreen 에 _DownloadProgressTile 추가
  · LinearProgressIndicator + bytes/total + 일시정지/재개/다시 시도 토글

회귀 테스트 9건 신규:
- test/ui/ai_suggest_button_visibility_test.dart (4): AC6 4상태 (hidden / disabled+tooltip × missing/downloading / enabled)
- test/state/model_download_controller_test.dart (3): opt-in→start, pause→paused, cancel→idle
- test/domain/ai/suggest_frame_test.dart (+3): AC4 분포 케이스 3개 (기존 take(3) 테스트 대체)

검증:
- flutter analyze → No issues found
- flutter test → 71 tests pass (62 → 71, +9 신규)
- flutter build apk --debug → 성공 (8.8s)

OQ-1 (모델 URL+SHA) 미해결 유지. MockLlmService 기본 주입 + placeholder URL 다운로드는 여전히 실패하지만, UI/스트림 wiring 은 모두 검증됨.

Refs #215

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-12 12:30:16 +09:00
parent 6ab4c0da7d
commit 1e019c6dc7
9 changed files with 603 additions and 47 deletions

View File

@@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../data/ai/llm_service.dart';
@@ -33,6 +35,8 @@ final aiSettingsProvider = FutureProvider<bool>((ref) async {
});
/// Toggles opt-in. On opt-out, purges model file via [ModelLifecycle.purge].
/// On opt-in, kicks off `ModelDownloadController.start()` so AC2 (progress UI)
/// has a stream to subscribe to.
class AiSettingsController {
AiSettingsController(this.ref);
final Ref ref;
@@ -43,8 +47,13 @@ class AiSettingsController {
await meta.put(AiMetaKeys.optIn, 'true');
ref.invalidate(aiSettingsProvider);
ref.invalidate(modelAvailabilityProvider);
// AC2: opt-in triggers download stream so Settings UI can render
// progress + pause/resume. Fire-and-forget; controller emits states.
ref.read(modelDownloadControllerProvider.notifier).start();
return 0;
}
// opt-out: cancel any in-flight download, then purge.
ref.read(modelDownloadControllerProvider.notifier).cancel();
final freed = await ref.read(modelLifecycleProvider).purge();
await meta.put(AiMetaKeys.optIn, 'false');
ref.invalidate(aiSettingsProvider);
@@ -57,6 +66,72 @@ final aiSettingsControllerProvider = Provider<AiSettingsController>((ref) {
return AiSettingsController(ref);
});
/// AC2: streams DownloadProgress + supports pause/resume/cancel.
/// State `null` means idle (no active subscription).
class ModelDownloadController extends StateNotifier<DownloadProgress?> {
ModelDownloadController(this.ref) : super(null);
final Ref ref;
StreamSubscription<DownloadProgress>? _sub;
void start() {
cancel();
final lc = ref.read(modelLifecycleProvider);
_sub = lc.download().listen(
(p) {
state = p;
if (p.state == DownloadState.completed) {
ref.invalidate(modelAvailabilityProvider);
}
},
onError: (Object e) {
state = DownloadProgress(
bytesReceived: state?.bytesReceived ?? 0,
totalBytes: state?.totalBytes ?? -1,
state: DownloadState.failed,
errorMessage: e.toString(),
);
},
onDone: () {
_sub = null;
},
);
}
/// Pauses by cancelling the subscription. .tmp file + meta_kv preserved so
/// `start()` resumes via HTTP Range header.
void pause() {
_sub?.cancel();
_sub = null;
final cur = state;
if (cur != null && cur.state != DownloadState.completed) {
state = DownloadProgress(
bytesReceived: cur.bytesReceived,
totalBytes: cur.totalBytes,
state: DownloadState.paused,
);
}
}
void resume() => start();
void cancel() {
_sub?.cancel();
_sub = null;
state = null;
}
@override
void dispose() {
_sub?.cancel();
super.dispose();
}
}
final modelDownloadControllerProvider =
StateNotifierProvider<ModelDownloadController, DownloadProgress?>(
(ref) => ModelDownloadController(ref),
);
final modelAvailabilityProvider =
FutureProvider<ModelAvailability>((ref) async {
final lc = ref.watch(modelLifecycleProvider);