Initial commit: NetworkCity — network traffic as a neon city

A native macOS network monitor that renders live traffic as a top-down
neon city: your Mac is downtown, remote orgs are glowing districts, and
traffic is cars of light driving the roads.

Architecture:
- NetworkCityCore: swappable data layer behind a ConnectionSource protocol
  (nettop-backed today), plus pure/tested logic — traffic diffing, org
  classification (reverse-DNS + CIDR), traffic classes, hub-and-spoke
  expansion policy, label anti-overlap, and latency→distance layout.
- NetworkCityApp: SwiftUI + SpriteKit city — auto-expanding districts,
  protocol-coloured cars, click-to-inspect panel, and latency-as-distance
  (districts glide to their measured RTT).
- nettop-probe: CLI proof of the data layer.

44 tests passing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-13 08:43:32 -07:00
commit c08fc277a9
33 changed files with 2499 additions and 0 deletions
@@ -0,0 +1,35 @@
import XCTest
import CoreGraphics
@testable import NetworkCityCore
final class LatencyLayoutTests: XCTestCase {
func testZeroRTTSitsAtInnerRadius() {
XCTAssertEqual(LatencyLayout.radius(forRTT: 0), LatencyLayout.minRadius, accuracy: 0.001)
}
func testCeilingSitsAtOuterEdge() {
XCTAssertEqual(LatencyLayout.radius(forRTT: 250), LatencyLayout.maxRadius, accuracy: 0.001)
}
func testClampsBeyondCeiling() {
XCTAssertEqual(LatencyLayout.radius(forRTT: 5000), LatencyLayout.maxRadius, accuracy: 0.001)
}
func testMonotonicAndWithinBounds() {
var last = LatencyLayout.radius(forRTT: 0)
for rtt in stride(from: 5.0, through: 250.0, by: 5) {
let r = LatencyLayout.radius(forRTT: rtt)
XCTAssertGreaterThan(r, last) // farther RTT -> farther out
XCTAssertLessThanOrEqual(r, LatencyLayout.maxRadius)
last = r
}
}
func testNearRangeSpreadsOut() {
// The log curve should give the 150ms band real separation, not a clump.
let r10 = LatencyLayout.radius(forRTT: 10)
let r50 = LatencyLayout.radius(forRTT: 50)
XCTAssertGreaterThan(r50 - r10, 40) // meaningfully far apart on screen
}
}