feat: 接入拍摄任务实时订阅并完善日志与封面

This commit is contained in:
2026-11-03 09:06:38 +08:00
parent 687088326c
commit 980d16da9b
27 changed files with 1790 additions and 64 deletions
@@ -5,6 +5,25 @@ import XCTest
/// 验证统一控制台日志覆盖普通、裸 JSON 和文件上传入口,全部使用内存响应。
@MainActor
final class APIClientConsoleLoggingTests: XCTestCase {
/// 普通网络出口根据实际请求模块生成成对标签,兼容系统日志二次分段。
func testKnownBusinessRequestUsesModuleRequestAndResponseLabels() async throws {
var logs: [String] = []
let payload = try TestJSON.errorEnvelope(code: 100099, msg: "测试订单不存在")
let client = APIClient(environment: .testing, session: MockURLSession(responses: [payload]),
debugLogSink: { logs.append($0) })
do {
let _: EmptyPayload = try await client.send(APIRequest(method: .get, path: "/api/app/store/order/detail"))
XCTFail("应保留业务拒绝")
} catch {}
XCTAssertTrue(logs[0].hasPrefix("【订单-Request】 GET"))
XCTAssertTrue(logs[1].hasPrefix("【订单-Response】 GET"))
XCTAssertTrue(logs[2].hasPrefix("【订单-Failure】 GET"))
for text in logs {
let lines = APIConsoleFormat.lines(text, sessionID: "S", entryID: "E", fallbackModule: "通用接口")
XCTAssertTrue(lines.allSatisfy { $0.hasPrefix("【订单-") })
}
}
/// 请求与大响应完整保留;multipart 记录大小,不把文件字节打印到控制台。
func testEveryRequestEntryLogsRequestAndCompleteResponse() async throws {
let detail = String(repeating: "完整中文字段😀", count: 1_000) + "END-OF-RESPONSE"
@@ -17,7 +36,7 @@ final class APIClientConsoleLoggingTests: XCTestCase {
try await send(kind, client: client)
XCTAssertEqual(logs.count, 2, kind.rawValue)
let request = try XCTUnwrap(logs.first)
XCTAssertTrue(request.contains("[API][Request] POST"))
XCTAssertTrue(request.contains("【通用接口-Request】 POST"))
XCTAssertTrue(request.contains("/api/mock/release-logging"))
XCTAssertTrue(request.contains("test-auth-token"))
if kind == .multipart {
@@ -28,7 +47,7 @@ final class APIClientConsoleLoggingTests: XCTestCase {
if kind == .typed { XCTAssertTrue(request.contains("page=2")) }
}
let received = try XCTUnwrap(logs.last)
XCTAssertTrue(received.contains("[API][Response] POST"))
XCTAssertTrue(received.contains("【通用接口-Response】 POST"))
XCTAssertTrue(received.contains("status=200"))
XCTAssertTrue(received.contains(detail), "完整响应不能因为长度被截断")
XCTAssertEqual(session.requests.count, 1)
@@ -46,8 +65,8 @@ final class APIClientConsoleLoggingTests: XCTestCase {
do { try await send(kind, client: client); XCTFail("失败必须保留") } catch {}
XCTAssertEqual(logs.count, 2, kind.rawValue)
let cancelled = error is CancellationError || (error as? URLError)?.code == .cancelled
XCTAssertTrue(logs.last?.contains(cancelled ? "[API][Cancelled]" : "[API][Failure]") == true)
XCTAssertFalse(logs.joined().contains("[API][Response]"))
XCTAssertTrue(logs.last?.contains(cancelled ? "【通用接口-Cancelled】" : "【通用接口-Failure】") == true)
XCTAssertFalse(logs.joined().contains("【通用接口-Response】"))
}
}
}
@@ -65,9 +84,9 @@ final class APIClientConsoleLoggingTests: XCTestCase {
debugLogSink: { logs.append($0) })
do { try await send(kind, client: client); XCTFail("失败必须抛出") } catch {}
XCTAssertEqual(logs.count, 3, kind.rawValue)
XCTAssertTrue(logs[1].contains("[API][Response]"))
XCTAssertTrue(logs[1].contains("【通用接口-Response】"))
XCTAssertTrue(logs[1].contains("status=\(status)"))
XCTAssertTrue(logs[2].contains("[API][Failure]"))
XCTAssertTrue(logs[2].contains("【通用接口-Failure】"))
}
}
}