merge: integrate complete MapKit runtime refresh

# Conflicts:
#	App/MapHomeView.swift
#	Shared/CoordinateConverter.swift
#	Tests/PaopaoLocationSpooferTests/FavoriteLocationStoreTests.swift
#	Tests/map_refactor_contract_test.sh
This commit is contained in:
xweiba
2026-08-07 14:51:30 +08:00
7 changed files with 363 additions and 201 deletions
@@ -36,6 +36,25 @@ final class FavoriteLocationStoreTests: XCTestCase {
XCTAssertNotEqual(favorite.coordinatePair.gcj02.longitude, wgs.longitude)
}
func testSavingPrecomputedPairDoesNotReinterpretItAfterMapTypeRefresh() {
let suite = "FavoriteLocationStoreTests.\(UUID().uuidString)"
let defaults = UserDefaults(suiteName: suite)!
defer { defaults.removePersistentDomain(forName: suite) }
let pair = CoordinateConverter.coordinatePair(
lat: 22.296_642,
lon: 114.172_175,
mapCoordinateSystem: .wgs84
)
let favorite = FavoriteLocationStore(defaults: defaults).save(
name: "香港天文台",
coordinatePair: pair,
accuracy: 25
)
XCTAssertEqual(favorite.coordinatePair, pair)
}
func testLegacyFavoriteIsUpgradedAsDomesticGCJAndRewritten() throws {
let suite = "FavoriteLocationStoreTests.\(UUID().uuidString)"
let defaults = UserDefaults(suiteName: suite)!
@@ -122,41 +141,15 @@ final class FavoriteLocationStoreTests: XCTestCase {
XCTAssertNil(CoordinateConverter.diagnoseRepresentation(sample: unrelated, pair: pair).inferredSystem)
}
@MainActor
func testDetectedMapCoordinateSystemChangePreventsHongKongWGS84DoubleConversion() {
let original = CoordinateConverter.currentMapCoordinateSystem
defer { _ = CoordinateConverter.applyDetectedMapCoordinateSystem(original) }
_ = CoordinateConverter.applyDetectedMapCoordinateSystem(.gcj02)
let hongKongObservatory = CLLocationCoordinate2D(
latitude: 22.302_344,
longitude: 114.174_566
func testFixedAnchorResultNameUsesOneSharedMapTypeRule() {
XCTAssertEqual(
CoordinateConverter.mapCoordinateSystem(forFixedAnchorFirstResultName: "林士街"),
.gcj02
)
let stalePair = CoordinatePair(
mapCoordinate: hongKongObservatory,
mapCoordinateSystem: CoordinateConverter.currentMapCoordinateSystem
XCTAssertEqual(
CoordinateConverter.mapCoordinateSystem(forFixedAnchorFirstResultName: "Connaught Road West"),
.wgs84
)
let change = CoordinateConverter.applyDetectedMapCoordinateSystem(.wgs84)
let pair = CoordinatePair(
mapCoordinate: hongKongObservatory,
mapCoordinateSystem: CoordinateConverter.currentMapCoordinateSystem
)
XCTAssertEqual(change?.previous, .gcj02)
XCTAssertEqual(change?.current, .wgs84)
XCTAssertNotEqual(stalePair.wgs84.longitude, hongKongObservatory.longitude)
XCTAssertEqual(pair.wgs84.latitude, hongKongObservatory.latitude, accuracy: 0.000_000_1)
XCTAssertEqual(pair.wgs84.longitude, hongKongObservatory.longitude, accuracy: 0.000_000_1)
}
@MainActor
func testApplyingSameDetectedMapCoordinateSystemDoesNotReportAChange() {
let original = CoordinateConverter.currentMapCoordinateSystem
defer { _ = CoordinateConverter.applyDetectedMapCoordinateSystem(original) }
_ = CoordinateConverter.applyDetectedMapCoordinateSystem(.gcj02)
XCTAssertNil(CoordinateConverter.applyDetectedMapCoordinateSystem(.gcj02))
}
func testMapConfigurationNeverRequestsRealUserLocation() {
@@ -173,6 +173,19 @@ final class MapLocationStateTests: XCTestCase {
XCTAssertEqual(state.selection.source, .search)
}
func testMapCoordinateSystemChangeClearsSupersededRealtimeSampleWithoutMovingSelection() {
let state = MapLocationState(initialCoordinate: initial)
state.selectSearchResult(.init(latitude: 31.23, longitude: 121.47), name: "外滩")
let selection = state.selection
state.updateRealtimeLocation(CLLocation(latitude: 30.42, longitude: 114.25))
state.clearRealtimeLocationForMapCoordinateSystemChange()
XCTAssertNil(state.realtimeLocation)
XCTAssertNil(state.realtimeCoordinate)
XCTAssertEqual(state.selection, selection)
}
func testRealtimeIntentCanImmediatelyAcceptNativeLocation() {
let state = MapLocationState(initialCoordinate: initial)
let nativeLocation = CLLocation(latitude: 30.42, longitude: 114.25)
+13 -6
View File
@@ -65,12 +65,19 @@ if grep -q 'logEvent("CONNECT " + host + " -> passthrough")' "$ROOT/Core/proxy.g
fi
grep -q 'enum SystemSettingsNavigator' "$SETTINGS_NAVIGATOR" || fail "shared settings navigator is missing"
grep -q 'await CoordinateConverter.resolveInitialMapCoordinateSystem()' "$CONTENT" || fail "map type must resolve before MapHomeView construction"
grep -q 'static func refreshMapCoordinateSystem() async' "$CONVERTER" || fail "runtime MapKit coordinate-system changes must reuse the fixed-anchor probe"
grep -q 'fixedAnchorCoordinateSystemProbe()' "$CONVERTER" || fail "runtime coordinate-system refresh must use the location-independent fixed anchor"
test "$(grep -c 'initialMapCoordinateSystemUsedFallback = false' "$CONVERTER")" -ge 2 || fail "a successful runtime anchor probe must disable location-region fallback correction"
grep -q 'refreshMapCoordinateSystemAfterLocationEnvironmentChange' "$MAP_HOME" || fail "MapHomeView must refresh the coordinate system after spoofing changes the location environment"
grep -q 'nearestTargetDistance' "$MAP_HOME" || fail "spoof refresh must wait until the MapKit blue point reaches the active target"
grep -q 'reprojectMapSelection(for: change)' "$MAP_HOME" || fail "coordinate-system refresh must replay the persisted coordinate pair"
grep -q 'refreshRuntimeMapCoordinateSystem(reason:' "$CONVERTER" || fail "fixed-anchor map type must support runtime refresh"
grep -q 'scheduleBluePointMapCoordinateSystemRefresh()' "$MAP_HOME" || fail "native blue-point samples must trigger runtime map-type refresh while spoofing"
! grep -A3 'private func scheduleBluePointMapCoordinateSystemRefresh' "$MAP_HOME" | grep -q 'spoofState == .active' || fail "blue-point map-type refresh must also detect the return to physical location"
grep -q 'awaitCoordinatedMapCoordinateSystemRefresh(reason: "点击实时定位")' "$MAP_HOME" || fail "realtime button must await the coordinated map-type refresh"
grep -q 'awaitCoordinatedMapCoordinateSystemRefresh(reason: "保存收藏")' "$MAP_HOME" || fail "favorite save must await the coordinated map-type refresh"
grep -q 'awaitCoordinatedMapCoordinateSystemRefresh(reason: "App回到前台")' "$MAP_HOME" || fail "foreground recovery must reuse the coordinated map-type refresh"
grep -q '地图坐标标准运行期检测结果已过期,取消写入' "$CONVERTER" || fail "cancelled runtime probes must not mutate the global map type"
! grep -q 'source == .coreLocation.*correctMapCoordinateSystemUsingRealtime' "$MAP_HOME" || fail "runtime Core Location samples must not infer MapKit type"
grep -q 'clearRealtimeLocationForMapCoordinateSystemChange' "$MAP_HOME" || fail "map-type changes must discard superseded blue-point samples"
grep -q '地图坐标类型已变化' "$MAP_HOME" || fail "map-type changes must emit an explicit searchable business log"
grep -q '图钉已按新类型重设' "$MAP_HOME" || fail "map-type change log must report pin reprojection"
grep -q '国内标准 GCJ-02' "$MAP_HOME" || fail "current selection panel must show GCJ-02"
grep -q '国际标准 WGS-84' "$MAP_HOME" || fail "current selection panel must show WGS-84"
grep -q 'phase = .map' "$CONTENT" || fail "ContentView must explicitly gate MapHomeView construction"
! grep -q 'startTileProbe' "$MAP_HOME" || fail "MapHomeView must not start a second fixed-anchor coordinate-system probe"
! grep -q 'initializeMap()' "$MAP_HOME" || fail "MapHomeView must not replay a second map initialization from onAppear"