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,45 @@
import XCTest
import CoreGraphics
@testable import NetworkCityCore
final class LayoutSolverTests: XCTestCase {
// A label box centered under the node: ~160 wide, sitting below the dot.
private let label = CGRect(x: -80, y: -34, width: 160, height: 30)
private func worldBox(at c: CGPoint) -> CGRect { label.offsetBy(dx: c.x, dy: c.y) }
func testEmptyMapReturnsSeed() {
let p = LayoutSolver.placeNonOverlapping(baseAngle: 0, baseRadius: 200, localRect: label, existing: [])
XCTAssertEqual(p.x, 200, accuracy: 0.001) // attempt 0 == seed
XCTAssertEqual(p.y, 0, accuracy: 0.001)
}
func testAvoidsOverlapWithExisting() {
// Pre-place a box exactly where the seed would land.
let seed = CGPoint(x: cos(0.0) * 200, y: sin(0.0) * 200)
let existing = [worldBox(at: seed).insetBy(dx: -16, dy: -16)]
let p = LayoutSolver.placeNonOverlapping(baseAngle: 0, baseRadius: 200, localRect: label, existing: existing)
XCTAssertNotEqual(p, seed) // had to move
// The chosen spot's padded box must clear the existing one.
let placed = worldBox(at: p).insetBy(dx: -16, dy: -16)
XCTAssertFalse(placed.intersects(existing[0]))
}
func testResultClearsAllOfManyNeighbours() {
// Seed eight districts and confirm none of their boxes overlap.
var placed: [CGRect] = []
for i in 0..<8 {
let angle = Double(i) / 8 * 2 * .pi
let c = LayoutSolver.placeNonOverlapping(baseAngle: angle, baseRadius: 180, localRect: label, existing: placed)
placed.append(worldBox(at: c))
}
for a in 0..<placed.count {
for b in (a + 1)..<placed.count {
XCTAssertFalse(placed[a].intersects(placed[b]), "districts \(a) and \(b) overlap")
}
}
}
}