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:
@@ -65,6 +65,9 @@ final class ModelStore {
|
|||||||
/// Demo 现场旁路:从 Bundle 拷贝预装模型(W6 才真正使用,本周占位)
|
/// Demo 现场旁路:从 Bundle 拷贝预装模型(W6 才真正使用,本周占位)
|
||||||
func seedFromBundle(_ kind: ModelKind) throws {
|
func seedFromBundle(_ kind: ModelKind) throws {
|
||||||
guard let bundleURL = Bundle.main.url(forResource: kind.rawValue, withExtension: nil) else {
|
guard let bundleURL = Bundle.main.url(forResource: kind.rawValue, withExtension: nil) else {
|
||||||
|
#if DEBUG
|
||||||
|
assertionFailure("Bundle 缺少 \(kind.rawValue),检查资源是否加入 target")
|
||||||
|
#endif
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let target = localURL(for: kind)
|
let target = localURL(for: kind)
|
||||||
|
|||||||
@@ -43,4 +43,12 @@ struct ModelStoreTests {
|
|||||||
|
|
||||||
#expect(store.totalBytes(for: .llm) == 2048)
|
#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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user