Complete workspace recovery, migration, and compatibility checks
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import XCTest
|
||||
import AppKit
|
||||
import SQLite3
|
||||
@testable import AIStudio
|
||||
|
||||
final class StudioTests: XCTestCase {
|
||||
@@ -335,6 +336,36 @@ final class ExpandedStudioTests: XCTestCase {
|
||||
}
|
||||
|
||||
final class WorkspaceExperienceTests: XCTestCase {
|
||||
func testMstyImportAndPromptHistory() throws {
|
||||
let folder = FileManager.default.temporaryDirectory.appending(path: UUID().uuidString)
|
||||
try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true)
|
||||
defer { try? FileManager.default.removeItem(at: folder) }
|
||||
let source = folder.appending(path: "msty.db")
|
||||
var db: OpaquePointer?
|
||||
XCTAssertEqual(sqlite3_open(source.path, &db), SQLITE_OK)
|
||||
let sql = """
|
||||
CREATE TABLE conversationTexts(id,title,createdAt);
|
||||
CREATE TABLE conversationTextChatSplits(id,conversationId,createdAt);
|
||||
CREATE TABLE conversationTextMessages(chatSplitId,role,content,createdAt);
|
||||
INSERT INTO conversationTexts VALUES('chat','Imported','1');
|
||||
INSERT INTO conversationTextChatSplits VALUES('split','chat','1');
|
||||
INSERT INTO conversationTextMessages VALUES('split','user','Question','1'),('split','assistant','Answer','2');
|
||||
"""
|
||||
let result = sqlite3_exec(db, sql, nil, nil, nil)
|
||||
sqlite3_close(db)
|
||||
XCTAssertEqual(result, SQLITE_OK)
|
||||
let store = try Store(url: folder.appending(path: "studio.sqlite"))
|
||||
XCTAssertEqual(try store.importMstyChats(from: source), 1)
|
||||
XCTAssertEqual(try store.importMstyChats(from: source), 0)
|
||||
let chat = try XCTUnwrap(store.conversations().first)
|
||||
XCTAssertEqual(try store.messages(in: chat.id).map(\.content), ["Question", "Answer"])
|
||||
let prompt = UUID()
|
||||
try store.savePrompt(id: prompt, title: "Prompt", content: "First", notes: "", tags: "")
|
||||
try store.savePrompt(id: prompt, title: "Prompt", content: "Second", notes: "Edited", tags: "swift")
|
||||
XCTAssertEqual(try store.snippets().first?.tags, "swift")
|
||||
XCTAssertEqual(try store.promptVersions(prompt).map(\.content), ["Second", "First"])
|
||||
}
|
||||
|
||||
func testPromptBuilderRendersOnlyPopulatedSectionsInOrder() {
|
||||
var draft = PromptDraft()
|
||||
draft.role = " Teacher "
|
||||
@@ -421,6 +452,21 @@ final class CompatibleEndpointTests: XCTestCase {
|
||||
XCTAssertNoThrow(try CompatibleEndpoint(endpoint: "http://127.0.0.1:1234/v1"))
|
||||
}
|
||||
|
||||
func testLiveLMStudioDiscoveryAndStreaming() async throws {
|
||||
let env = ProcessInfo.processInfo.environment
|
||||
guard let endpoint = env["AISTUDIO_TEST_LM_STUDIO_URL"],
|
||||
let model = env["AISTUDIO_TEST_LM_STUDIO_MODEL"] else {
|
||||
throw XCTSkip("Configure a running LM Studio server and loaded model.")
|
||||
}
|
||||
let client = try CompatibleEndpoint(endpoint: endpoint, token: "")
|
||||
let models = try await client.models()
|
||||
XCTAssertTrue(models.contains(model))
|
||||
let output = try await collect(client.generate(InferenceRequest(model: model, messages: [
|
||||
Message(role: .user, content: "Reply with only OK. /no_think")
|
||||
], thinking: .off, parameters: GenerationParameters(temperature: 0, maxTokens: 64))))
|
||||
XCTAssertTrue(output.contains { if case .answer(let answer) = $0 { return !answer.isEmpty }; return false })
|
||||
}
|
||||
|
||||
func testAuthenticatedDiscoveryAndStreaming() async throws {
|
||||
guard let endpoint = ProcessInfo.processInfo.environment["AISTUDIO_TEST_COMPATIBLE_URL"] else {
|
||||
throw XCTSkip("Set AISTUDIO_TEST_COMPATIBLE_URL to the compatible endpoint fixture.")
|
||||
@@ -850,6 +896,30 @@ final class ConnectedChatTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func testWorkspaceRelocationPreservesDatabase() throws {
|
||||
let root = FileManager.default.temporaryDirectory.appending(path: UUID().uuidString)
|
||||
let defaults = try XCTUnwrap(UserDefaults(suiteName: root.lastPathComponent))
|
||||
defer {
|
||||
defaults.removePersistentDomain(forName: root.lastPathComponent)
|
||||
try? FileManager.default.removeItem(at: root)
|
||||
}
|
||||
let studio = StudioModel()
|
||||
let original = root.appending(path: "original.sqlite")
|
||||
studio.open(databaseURL: original)
|
||||
studio.newChat()
|
||||
let first = try XCTUnwrap(studio.selected)
|
||||
let target = root.appending(path: "Relocated")
|
||||
try FileManager.default.createDirectory(at: target, withIntermediateDirectories: true)
|
||||
try studio.relocateWorkspace(to: target, defaults: defaults)
|
||||
XCTAssertEqual(defaults.string(forKey: "workspaceLocation"), target.path)
|
||||
let copy = target.appending(path: "studio.sqlite")
|
||||
XCTAssertTrue(Store.isWorkspaceBackup(copy))
|
||||
XCTAssertEqual(try Store(url: copy).conversations().map(\.id), [first])
|
||||
XCTAssertEqual(try Store(url: original).conversations().map(\.id), [first])
|
||||
XCTAssertThrowsError(try studio.relocateWorkspace(to: target, defaults: defaults))
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func testDeleteChatTargetsRequestedConversation() throws {
|
||||
let folder = FileManager.default.temporaryDirectory.appending(path: UUID().uuidString)
|
||||
|
||||
Reference in New Issue
Block a user