[Developer] #657 모델 파일명 .litertlm fix + 레거시 마이그레이션 + 에뮬레이터 dev 인프라
- ModelConfig.filename 기본값 gemma4_e2b_q4.bin → gemma-4-E2B-it.litertlm (#342 근본 원인) - _migrateLegacyPath: 기존 .bin 설치본 rename + meta 갱신 (재다운로드 2.4GB 방지, 멱등) - maxTokens 2048 유지 + 1024 회귀 방지 주석 (KV cache < prefill signature 시 추론 실패) - LLM_BACKEND dart-define: 에뮬레이터 CPU 강제 (SwiftShader GPU 네이티브 SIGABRT 회피) - GEMMA_MODEL_URL dart-define: 호스트 로컬 모델 서버 주입 (기본값 = HF URL 불변) - debug 전용 cleartext manifest (10.0.2.2 모델 서버용, release 불변) - 마이그레이션 테스트 4건 신규 (AC-2/3/4). 171 passed, analyze clean 2026-07-14 에뮬레이터 E2E 검증: 다운로드→로드→tool call 왕복 전 구간 성공. Refs #657, #342 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -250,4 +250,80 @@ void main() {
|
||||
await meta.put(AiMetaKeys.modelSha, 'expected_but_actual_will_differ');
|
||||
expect(await lc.checkAvailability(), ModelAvailability.corrupt);
|
||||
});
|
||||
|
||||
group('#657 legacy .bin filename migration', () {
|
||||
// Pre-.litertlm installs: file on disk + meta path both use the old
|
||||
// `gemma4_e2b_q4.bin` name that LiteRT-LM rejects.
|
||||
const legacyName = 'gemma4_e2b_q4.bin';
|
||||
const canonicalName = 'model.litertlm';
|
||||
|
||||
ModelLifecycle makeLc(String expectedSha) => ModelLifecycle(
|
||||
meta: meta,
|
||||
config: ModelConfig(
|
||||
url: Uri.parse(url),
|
||||
expectedSha256: expectedSha,
|
||||
filename: canonicalName,
|
||||
),
|
||||
storage: storage,
|
||||
);
|
||||
|
||||
Future<String> seedLegacy(List<int> payload) async {
|
||||
final legacyPath = '${tmp.path}/$legacyName';
|
||||
File(legacyPath).writeAsBytesSync(payload);
|
||||
await meta.put(AiMetaKeys.optIn, 'true');
|
||||
await meta.put(AiMetaKeys.modelPath, legacyPath);
|
||||
await meta.put(
|
||||
AiMetaKeys.modelSha, sha256.convert(payload).toString());
|
||||
await meta.put(AiMetaKeys.downloadState, 'completed');
|
||||
return legacyPath;
|
||||
}
|
||||
|
||||
test('quickCheck renames legacy file + updates meta path (AC-2)',
|
||||
() async {
|
||||
final payload = utf8.encode('legacy model bytes');
|
||||
final legacyPath = await seedLegacy(payload);
|
||||
final lc = makeLc(sha256.convert(payload).toString());
|
||||
|
||||
expect(await lc.quickCheck(), ModelAvailability.ready);
|
||||
expect(File(legacyPath).existsSync(), isFalse);
|
||||
final canonicalPath = '${tmp.path}/$canonicalName';
|
||||
expect(File(canonicalPath).existsSync(), isTrue);
|
||||
expect(await meta.find(AiMetaKeys.modelPath), canonicalPath);
|
||||
});
|
||||
|
||||
test('checkAvailability migrates and SHA meta stays valid (AC-2)',
|
||||
() async {
|
||||
final payload = utf8.encode('legacy model bytes');
|
||||
await seedLegacy(payload);
|
||||
final lc = makeLc(sha256.convert(payload).toString());
|
||||
|
||||
expect(await lc.checkAvailability(), ModelAvailability.ready);
|
||||
expect(File('${tmp.path}/$canonicalName').existsSync(), isTrue);
|
||||
});
|
||||
|
||||
test('migration is idempotent — second check is a no-op (AC-3)',
|
||||
() async {
|
||||
final payload = utf8.encode('legacy model bytes');
|
||||
await seedLegacy(payload);
|
||||
final lc = makeLc(sha256.convert(payload).toString());
|
||||
|
||||
expect(await lc.quickCheck(), ModelAvailability.ready);
|
||||
expect(await lc.quickCheck(), ModelAvailability.ready);
|
||||
expect(
|
||||
await meta.find(AiMetaKeys.modelPath),
|
||||
'${tmp.path}/$canonicalName',
|
||||
);
|
||||
});
|
||||
|
||||
test('meta path file gone → skip migration, stays missing (AC-4)',
|
||||
() async {
|
||||
await meta.put(AiMetaKeys.optIn, 'true');
|
||||
await meta.put(AiMetaKeys.modelPath, '${tmp.path}/$legacyName');
|
||||
await meta.put(AiMetaKeys.modelSha, 'irrelevant');
|
||||
|
||||
final lc = makeLc('irrelevant');
|
||||
expect(await lc.quickCheck(), ModelAvailability.missing);
|
||||
expect(File('${tmp.path}/$canonicalName').existsSync(), isFalse);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user