Skip to content

Use SystemPath for SandboxRuntimeConfiguration#22

Open
chrisgeo wants to merge 2 commits into
mainfrom
feat/chaos-1456-sandbox-runtime-config
Open

Use SystemPath for SandboxRuntimeConfiguration#22
chrisgeo wants to merge 2 commits into
mainfrom
feat/chaos-1456-sandbox-runtime-config

Conversation

@chrisgeo

@chrisgeo chrisgeo commented May 8, 2026

Copy link
Copy Markdown

Summary

Converts SandboxRuntimeConfiguration from URL to SystemPackage.FilePath for filesystem path handling, mirroring the established migration pattern (apple#1480, apple#1518, just-merged forks #20-21).

Two-commit PR — second commit addresses review feedback on Codable/wire-format.

Changes

Commit 1 — Use SystemPath for SandboxRuntimeConfiguration

  • RuntimeConfiguration.path: URLFilePath (public API)
  • runtimeConfigurationPath: URLFilePath (computed)
  • readRuntimeConfiguration(from: URL)from: FilePath
  • 2 server-side caller bridges in ContainersService.swift and SandboxService.swift: FilePath(url.path(percentEncoded: false)) at producer, URL(fileURLWithPath: fp.string) at Bundle.create consumer (still requires URL — Foundation API)

Commit 2 — Codable backward compatibility + restore Data(contentsOf:)

  • FilePath's default Codable encoding exposes its internal _storage as a keyed container, while URL's default encoding produced a plain absoluteString. Without explicit CodingKeys + encode/init(from:), runtime-configuration.json files written by daemons before this migration would fail to decode after upgrade.
  • Added explicit Codable that serializes path as a plain string and accepts either form (file:// URL or bare path) on decode for backward compatibility.
  • Added regression test testRuntimeConfigurationDecodesLegacyURLPathFormat.
  • Restored Data(contentsOf: URL(fileURLWithPath:)) (was FileManager.default.contents(atPath:)) to match codebase precedent (Bundle.swift, ConfigurationLoader.swift, EntityStore.swift).

Out of scope

  • Bundle+Log.swift (sibling file in the same module): all 3 callers use FileHandle(forReadingFrom:), FileHandle(forWritingTo:), Darwin.open(... .path, ...) — Foundation APIs requiring URL. Converting just this file would create cross-file compile breaks. Should be bundled with the broader SandboxService/ContainersService migration (CHAOS-1467).

Context

Test plan

  • swift test --filter RuntimeConfigurationTests — 3 tests pass (including new legacy-format test)
  • swift test --filter ContainerAPIServiceTests — full module passes
  • swift-format strict lint clean

@linear

linear Bot commented May 8, 2026

Copy link
Copy Markdown

CHAOS-1456

@chrisgeo chrisgeo force-pushed the feat/chaos-1456-sandbox-runtime-config branch 3 times, most recently from d9b7ed9 to 863733b Compare May 13, 2026 01:10
chrisgeo added 2 commits May 24, 2026 06:22
Converts RuntimeConfiguration.path, runtimeConfigurationPath, and the
readRuntimeConfiguration(from:) parameter from URL to FilePath. Following
the migration pattern from apple#1480 (HostDNSResolver), apple#1518 (PacketFilter),
and discussion apple#1481.

The two server-side callers (ContainersService, SandboxService) get
minimal URL <-> FilePath bridge calls. Bundle.create still requires URL
(Foundation API) so the bridge stays at that boundary.

Bundle+Log.swift in the same module is intentionally NOT converted in
this PR: all three of its callers use Foundation FileHandle APIs that
require URL, and converting bundle.containerLog without simultaneously
updating those callers (in ContainersService and SandboxService) would
expand the PR scope significantly. Bundle+Log can be converted later as
part of a SandboxService/ContainersService cluster conversion.
…sOf:).

Address review feedback on the URL → FilePath conversion of
RuntimeConfiguration.path:

1. FilePath's default Codable encoding exposes its internal _storage
   as a keyed container, while URL's default encoding produced a plain
   absoluteString. Without this fix, runtime-configuration.json files
   written by daemons before the migration would fail to decode after
   upgrade. Add explicit CodingKeys + encode(to:) / init(from:) that
   serialize path as a plain string and accept either form (file:// or
   bare path) on decode for backward compatibility. Add a regression
   test for the legacy URL format.

2. Restore Data(contentsOf: URL(fileURLWithPath:)) for reading the
   config file, matching the codebase precedent (Bundle.swift,
   ConfigurationLoader.swift, EntityStore.swift). FileManager.contents
   would have lost typed CocoaError diagnostics on I/O failure.
@chrisgeo chrisgeo force-pushed the feat/chaos-1456-sandbox-runtime-config branch from 3eed0a2 to cc4be53 Compare May 24, 2026 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant