Buckets:
localhost1978/localhost / LOCALHOST1978 /Modules /SSK_Abstractions /Tests /SSK_AbstractionsTests /DocGenHostCommandTests.swift
| import Foundation | |
| import XCTest | |
| @testable import SSK_Abstractions | |
| final class DocGenHostCommandTests: XCTestCase { | |
| func testReadResourceRoundTripUsesStableWireFields() throws { | |
| let requestID = UUID(uuidString: "18D09B17-A701-44B4-A5EC-489085D7038B")! | |
| let command = DocGenHostCommand.readResource( | |
| requestID: requestID, | |
| resource: .doccIndex | |
| ) | |
| let data = try JSONEncoder().encode(command) | |
| let object = try XCTUnwrap( | |
| JSONSerialization.jsonObject(with: data) as? [String: Any] | |
| ) | |
| XCTAssertEqual(object["version"] as? Int, 1) | |
| XCTAssertEqual(object["command"] as? String, "readResource") | |
| XCTAssertEqual(object["requestID"] as? String, requestID.uuidString) | |
| XCTAssertEqual(object["resource"] as? String, "doccIndex") | |
| XCTAssertEqual(try JSONDecoder().decode(DocGenHostCommand.self, from: data), command) | |
| } | |
| func testCommandDoesNotContainAPathOrPrompt() throws { | |
| let data = try JSONEncoder().encode( | |
| DocGenHostCommand.readResource( | |
| requestID: UUID(), | |
| resource: .masterMarkdownIndex | |
| ) | |
| ) | |
| let text = String(decoding: data, as: UTF8.self) | |
| XCTAssertFalse(text.contains("file://")) | |
| XCTAssertFalse(text.contains("workspace")) | |
| XCTAssertFalse(text.contains("vault")) | |
| XCTAssertFalse(text.contains("prompt")) | |
| } | |
| func testResourceResponseRoundTrip() throws { | |
| let requestID = UUID() | |
| let value = DocGenWorkerResponse( | |
| resource: .codebaseGraph, | |
| uri: DocGenResource.codebaseGraph.uri, | |
| mimeType: DocGenResource.codebaseGraph.mimeType, | |
| text: "{}" | |
| ) | |
| let response = DocGenHostResponse.resource(requestID: requestID, value: value) | |
| let data = try JSONEncoder().encode(response) | |
| XCTAssertEqual(try JSONDecoder().decode(DocGenHostResponse.self, from: data), response) | |
| } | |
| func testEveryFailureRoundTrips() throws { | |
| let errors: [DocGenHostError] = [ | |
| .malformedData, | |
| .unsupportedVersion, | |
| .unknownCommand, | |
| .unknownResource, | |
| .duplicateRequest, | |
| .vaultUnavailable, | |
| .workerUnavailable, | |
| .timedOut, | |
| .cancelled, | |
| .responseTooLarge, | |
| .workerFailure, | |
| ] | |
| for error in errors { | |
| let response = DocGenHostResponse.failure(requestID: UUID(), error: error) | |
| let data = try JSONEncoder().encode(response) | |
| XCTAssertEqual(try JSONDecoder().decode(DocGenHostResponse.self, from: data), response) | |
| } | |
| } | |
| func testRefreshCommandRoundTrip() throws { | |
| let requestID = UUID() | |
| let command = DocGenHostCommand.refreshDocumentation(requestID: requestID, clean: true) | |
| let data = try JSONEncoder().encode(command) | |
| let decoded = try JSONDecoder().decode(DocGenHostCommand.self, from: data) | |
| XCTAssertEqual(decoded, command) | |
| let statusCommand = DocGenHostCommand.getRefreshStatus(requestID: requestID) | |
| let statusData = try JSONEncoder().encode(statusCommand) | |
| let statusDecoded = try JSONDecoder().decode(DocGenHostCommand.self, from: statusData) | |
| XCTAssertEqual(statusDecoded, statusCommand) | |
| } | |
| func testStatusResponseRoundTrip() throws { | |
| let requestID = UUID() | |
| let status = DocGenRefreshStatus( | |
| state: .running, | |
| requestID: requestID, | |
| startedAt: Date(timeIntervalSince1970: 1000), | |
| completedAt: nil, | |
| filesDiscovered: 42, | |
| filesProcessed: 40, | |
| filesFailed: 0, | |
| entitiesWritten: 120, | |
| artifactsWritten: 3, | |
| errorMessage: nil | |
| ) | |
| let response = DocGenHostResponse.status(requestID: requestID, status: status) | |
| let data = try JSONEncoder().encode(response) | |
| let decoded = try JSONDecoder().decode(DocGenHostResponse.self, from: data) | |
| XCTAssertEqual(decoded, response) | |
| } | |
| func testRefreshStatesAndErrors() throws { | |
| let allStates = DocGenRefreshState.allCases | |
| XCTAssertEqual(allStates, [.queued, .running, .ready, .failed]) | |
| let error = DocGenHostError.refreshInProgress | |
| let response = DocGenHostResponse.failure(requestID: UUID(), error: error) | |
| let data = try JSONEncoder().encode(response) | |
| XCTAssertEqual(try JSONDecoder().decode(DocGenHostResponse.self, from: data), response) | |
| } | |
| } | |
Xet Storage Details
- Size:
- 4.58 kB
- Xet hash:
- d12d0019efa007fbecb294453da0441452b9c4072a01bafa7f6f08cda80ca16e
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.