new features

This commit is contained in:
Mark Gregory
2026-11-16 13:41:54 +00:00
parent 87cdc990c3
commit 5338ae5751
16 changed files with 546 additions and 55 deletions
+71 -1
View File
@@ -120,7 +120,7 @@ final class LiveInferenceTests: XCTestCase {
let tag = environment["AISTUDIO_TEST_OLLAMA_MODEL"] else {
throw XCTSkip("Set the Ollama smoke-test endpoint and installed model.")
}
let ollama = try Ollama(endpoint: endpoint)
let ollama = try Ollama(endpoint: endpoint, token: environment["AISTUDIO_TEST_OLLAMA_TOKEN"] ?? "")
let models = try await ollama.models()
XCTAssertTrue(models.contains { $0.name == tag })
_ = try await ollama.details(for: tag)
@@ -222,6 +222,37 @@ final class ExpandedStudioTests: XCTestCase {
}
}
func testAuthenticatedOllamaGatewayAndRedirect() async throws {
guard let endpoint = ProcessInfo.processInfo.environment["AISTUDIO_TEST_OLLAMA_GATEWAY_URL"],
let base = URL(string: endpoint)?.deletingLastPathComponent() else {
throw XCTSkip("Set AISTUDIO_TEST_OLLAMA_GATEWAY_URL to the disposable gateway fixture.")
}
let client = try Ollama(endpoint: endpoint, token: "fixture-token")
let models = try await client.models()
XCTAssertEqual(models.map(\.name), ["fixture:latest"])
let request = InferenceRequest(model: "fixture:latest", messages: [
Message(role: .user, content: "Hello")
], thinking: .off)
let events = try await collect(client.generate(request))
XCTAssertTrue(events.contains(.answer("fixture answer")))
let unauthorized = try Ollama(endpoint: endpoint, token: "incorrect")
do {
_ = try await unauthorized.models()
XCTFail("Expected authentication failure")
} catch let error as StudioError {
XCTAssertEqual(error.message, "Ollama returned HTTP 401.")
}
let redirect = try Ollama(endpoint: base.appending(path: "redirect").absoluteString, token: "fixture-token")
do {
_ = try await redirect.models()
XCTFail("Expected redirect rejection")
} catch let error as StudioError {
XCTAssertEqual(error.message, "Ollama returned HTTP 302.")
}
}
func testOllamaModelManagementAgainstFixture() async throws {
guard let endpoint = ProcessInfo.processInfo.environment["AISTUDIO_TEST_OLLAMA_FIXTURE_URL"] else {
throw XCTSkip("Set AISTUDIO_TEST_OLLAMA_FIXTURE_URL to the disposable model-management fixture.")
@@ -252,3 +283,42 @@ final class ExpandedStudioTests: XCTestCase {
}
}
}
final class WorkspaceExperienceTests: XCTestCase {
func testPromptBuilderRendersOnlyPopulatedSectionsInOrder() {
var draft = PromptDraft()
draft.role = " Teacher "
draft.task = "Explain tides"
draft.audience = " "
draft.format = "One example"
XCTAssertEqual(draft.rendered, "## Role\nTeacher\n\n## Task\nExplain tides\n\n## Output format\nOne example")
XCTAssertEqual(PromptMode.standard.instructions(custom: "ignored"), "")
XCTAssertEqual(PromptMode.custom.instructions(custom: " Custom "), "Custom")
}
func testProviderThroughputUsesGenerationTime() {
XCTAssertEqual(ProviderMetrics(tokens: 60, seconds: 2).tokensPerSecond, 30)
XCTAssertNil(ProviderMetrics(tokens: 60, seconds: 0).tokensPerSecond)
}
func testMarkdownSeparatesCodeFromProse() {
let blocks = ChatMarkdown.blocks("Example\n```swift\nlet answer = 42\n```\nDone")
XCTAssertEqual(blocks.map(\.language), [nil, "swift", nil])
XCTAssertEqual(blocks[1].content, "let answer = 42")
XCTAssertEqual(ChatMarkdown.blocks("```swift\nunclosed").first?.language, nil)
}
func testConversationSearchAndRename() 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 store = try Store(url: folder.appending(path: "chat.sqlite"))
let first = try store.create(title: "Original")
_ = try store.create(title: "Unrelated")
try store.save(Message(role: .assistant, content: "A literal 100% match."), in: first.id)
try store.rename(first.id, title: "Renamed")
XCTAssertEqual(try store.searchConversations("renamed").map(\.id), [first.id])
XCTAssertEqual(try store.searchConversations("100% MATCH").map(\.id), [first.id])
XCTAssertTrue(try store.searchConversations("original").isEmpty)
}
}