harden(ai): ModelStore seedFromBundle 在 DEBUG 报错,加空目录测试

按 code quality review 反馈:
- seedFromBundle 找不到 bundle 资源时,DEBUG 下 assertionFailure 提示
  target membership(release 仍静默 return),避免 W6 启用时排查困难
- 补 totalBytesReturnsZeroWhenFolderMissing 测试,覆盖 folder 不存在时
  enumerator 为 nil 的 guard 路径

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
link2026
2026-05-25 15:12:26 +08:00
parent ad6fb660f0
commit d40cb7d1e0
2 changed files with 11 additions and 0 deletions

View File

@@ -65,6 +65,9 @@ final class ModelStore {
/// Demo : Bundle (W6 使,)
func seedFromBundle(_ kind: ModelKind) throws {
guard let bundleURL = Bundle.main.url(forResource: kind.rawValue, withExtension: nil) else {
#if DEBUG
assertionFailure("Bundle 缺少 \(kind.rawValue),检查资源是否加入 target")
#endif
return
}
let target = localURL(for: kind)

View File

@@ -43,4 +43,12 @@ struct ModelStoreTests {
#expect(store.totalBytes(for: .llm) == 2048)
}
@Test func totalBytesReturnsZeroWhenFolderMissing() throws {
let store = try isolatedStore()
defer { try? FileManager.default.removeItem(at: store.rootURL) }
// vl
#expect(store.totalBytes(for: .vl) == 0)
}
}