Files
CleanMM/Packages/AtlasProtocol/Tests/AtlasProtocolTests/AtlasProtocolTests.swift
zhukang 1d4dbeb370 feat(smart-clean): add structured targetPaths to ActionItem for execution
ActionItem now carries optional targetPaths so plan.execute can use
plan-carried targets instead of reconstructing execution intent from
findings. This improves execution reliability and enables proper restore
mappings for recovery items.

- Add targetPaths field to ActionItem domain model
- Update plan execution to prefer plan-carried targets with finding fallback
- Expand safe cache path fragments for direct-trash execution
- Add gate review documentation for ATL-211/212/215
- Bump protocol version to 0.3.0
2026-03-13 00:49:32 +08:00

60 lines
2.3 KiB
Swift

import XCTest
@testable import AtlasProtocol
import AtlasDomain
final class AtlasProtocolTests: XCTestCase {
func testRequestEnvelopeRoundTripsJSON() throws {
let taskID = UUID(uuidString: "10000000-0000-0000-0000-000000000001") ?? UUID()
let envelope = AtlasRequestEnvelope(command: .startScan(taskID: taskID))
let data = try JSONEncoder().encode(envelope)
let decoded = try JSONDecoder().decode(AtlasRequestEnvelope.self, from: data)
XCTAssertEqual(decoded.id, envelope.id)
XCTAssertEqual(decoded.command, envelope.command)
}
func testSettingsRequestRoundTripsJSON() throws {
let envelope = AtlasRequestEnvelope(command: .settingsSet(AtlasScaffoldFixtures.settings))
let data = try JSONEncoder().encode(envelope)
let decoded = try JSONDecoder().decode(AtlasRequestEnvelope.self, from: data)
XCTAssertEqual(decoded.command, envelope.command)
}
func testAppsResponseRoundTripsJSON() throws {
let envelope = AtlasResponseEnvelope(
requestID: UUID(),
response: .apps(AtlasScaffoldFixtures.apps)
)
let data = try JSONEncoder().encode(envelope)
let decoded = try JSONDecoder().decode(AtlasResponseEnvelope.self, from: data)
XCTAssertEqual(decoded.response, envelope.response)
}
func testPreviewResponseRoundTripsStructuredPlanTargets() throws {
let plan = ActionPlan(
title: "Review 1 selected finding",
items: [
ActionItem(
id: UUID(uuidString: "10000000-0000-0000-0000-000000000099") ?? UUID(),
title: "Move container cache to Trash",
detail: "Sandboxed cache path",
kind: .removeCache,
recoverable: true,
targetPaths: ["/Users/test/Library/Containers/com.example.sample/Data/Library/Caches/cache.db"]
)
],
estimatedBytes: 1_024
)
let envelope = AtlasResponseEnvelope(
requestID: UUID(),
response: .preview(plan)
)
let data = try JSONEncoder().encode(envelope)
let decoded = try JSONDecoder().decode(AtlasResponseEnvelope.self, from: data)
XCTAssertEqual(decoded.response, envelope.response)
}
}