按 W2 plan Task 4 落地模型路径管理: - ModelKind enum: llm (Qwen3-1.7B-MLX-4bit) / vl (Qwen2.5-VL-3B-MLX-4bit) - 用 config.json 作为 sentinel 判定模型是否就绪 - isReady / localURL / totalBytes 三个查询接口 - seedFromBundle(_:) 占位:Demo 现场预装模型旁路(W6 启用) - shared 单例用 Application Support/Models/ 测试 3 条:fresh / mark-ready / totalBytes,均用临时目录隔离 + defer cleanup。 注:.swift 文件需用户在 Xcode 拖入 target,⌘U 确认绿后 amend build commit。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
47 lines
1.7 KiB
Swift
47 lines
1.7 KiB
Swift
import Testing
|
|
import Foundation
|
|
@testable import 体己
|
|
|
|
struct ModelStoreTests {
|
|
|
|
private func isolatedStore() throws -> ModelStore {
|
|
let temp = FileManager.default.temporaryDirectory
|
|
.appendingPathComponent(UUID().uuidString, isDirectory: true)
|
|
return try ModelStore(rootURL: temp)
|
|
}
|
|
|
|
@Test func freshStoreReportsBothModelsMissing() throws {
|
|
let store = try isolatedStore()
|
|
defer { try? FileManager.default.removeItem(at: store.rootURL) }
|
|
|
|
#expect(store.isReady(.llm) == false)
|
|
#expect(store.isReady(.vl) == false)
|
|
}
|
|
|
|
@Test func markReadyAfterFolderCreated() throws {
|
|
let store = try isolatedStore()
|
|
defer { try? FileManager.default.removeItem(at: store.rootURL) }
|
|
|
|
let llmFolder = store.localURL(for: .llm)
|
|
try FileManager.default.createDirectory(at: llmFolder, withIntermediateDirectories: true)
|
|
let configURL = llmFolder.appendingPathComponent("config.json")
|
|
try "{}".write(to: configURL, atomically: true, encoding: .utf8)
|
|
|
|
#expect(store.isReady(.llm) == true)
|
|
#expect(store.isReady(.vl) == false)
|
|
}
|
|
|
|
@Test func totalBytesSumsExistingFiles() throws {
|
|
let store = try isolatedStore()
|
|
defer { try? FileManager.default.removeItem(at: store.rootURL) }
|
|
|
|
let folder = store.localURL(for: .llm)
|
|
try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true)
|
|
let data = Data(repeating: 0, count: 1024)
|
|
try data.write(to: folder.appendingPathComponent("a.bin"))
|
|
try data.write(to: folder.appendingPathComponent("b.bin"))
|
|
|
|
#expect(store.totalBytes(for: .llm) == 2048)
|
|
}
|
|
}
|