feat(runtime): add HostPath for jail-aware host path translation#9
Merged
Conversation
Promote the previously private OsFS jail-translation to a public API on the FileSystem interface and forward it from Runtime.HostPath, so callers that need a real on-disk path (subprocess argv, file handles handed to external libraries, logging) have a single stable entry point instead of re-implementing TrimPrefix + filepath.Join(jail, ...) at each call site. - FileSystem.HostPath(virtual) (string, error) added to the interface - (*OsFS).HostPath canonicalizes via EvalSymlinks on the jail root with a raw fallback so darwin /var -> /private/var resolves correctly at the API boundary instead of leaking into every caller - Runtime.HostPath forwarder applies the standard validate -> ExpandEnv -> ExpandPath -> wd-prefix chain before delegating to the FS - toolkit.Edit migrated from inline TrimPrefix + filepath.Join(jail, ...) to the canonical ResolvePath + HostPath two-call form, with godoc noting the rationale; pinned by the existing TestEdit_UsesRuntimeAndResolvesSymlinkPath regression - ErrSubprocessNotSupported sentinel exported for backends that cannot host a subprocess (TestFS, jailed FSes without a real host mapping) - Tests: 5 TestOsFS_HostPath_* (including a darwin /var regression and a lexical-contract case for parent-symlink chasing) plus 4 TestRuntime_HostPath_* covering the forwarder chain
098ac55 to
b721858
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Promotes the previously private
OsFSjail-translation helper to a public API on theFileSysteminterface and forwards it fromRuntime.HostPath. Callers that need a real on-disk path — subprocess argv, file handles handed to external libraries, log output — now have a single stable entry point instead of re-implementingTrimPrefix+filepath.Join(jail, ...)at each call site.Changes
FileSystem.HostPath(virtual) (string, error)added to the interface with godoc covering the canonicalization contract (jail prefix isEvalSymlinks'd before joining; intermediate symlinks invirtualare not canonicalized).(*OsFS).HostPathcanonicalizes viaEvalSymlinkson the jail root with a raw fallback, so darwin/var→/private/varresolves correctly at the API boundary instead of leaking into every caller. Same precedent as theresolveVirtualfix in PR feat(runtime): add Chmod, Chown, Lchown, Chtimes to FileSystem and Runtime #6.Runtime.HostPathforwarder applies the standard validate →ExpandEnv→ExpandPath→ wd-prefix chain before delegating to the FS.toolkit.Editmigrated from inlineTrimPrefix+filepath.Join(jail, ...)to the canonicalResolvePath+HostPathtwo-call form, with godoc noting the rationale. Pinned by the existingTestEdit_UsesRuntimeAndResolvesSymlinkPathregression.ErrSubprocessNotSupportedsentinel exported for backends that cannot host a subprocess (TestFS, jailed FSes without a real host mapping). Forward-looking — no consumer in this PR.Symlink semantics
HostPathis the lexical contract — it canonicalizes only the jail prefix, not the virtual path's intermediate components. Callers that need parent-traversal-symlink defense must resolve throughResolvePath(_, true)first. The darwin canonicalization at the prefix is non-negotiable: without it, a caller that later runsEvalSymlinkson the returned path would see the path move under/private/var/...and fail every subsequentIsInJailcheck.TestOsFS_HostPath_LexicalContract_ParentSymlinkNotChasedpins this contract explicitly so a future change that conflatesHostPathwithResolvePathgets caught.Tests
9 new tests, all pass with
-race:TestOsFS_HostPath_*(5): in-jail virtual path, lexical contract (parent-symlink not chased), no-jail passthrough, relative-uses-wd, darwin/varregression anchor.TestRuntime_HostPath_*(4): forwarder chain coverage including the validate → expand → wd-prefix steps.Test plan
go vet ./...cleangofmt -l toolkit/cleango test -race -count=1 ./...— all 7 packages passTestEdit_UsesRuntimeAndResolvesSymlinkPathstill green after theEditmigration/var→/private/varcanonicalization happens at the API boundary, not in callersOut of scope
ErrSubprocessNotSupportedconsumer. Sentinel only — wired by a future change..github/workflows/release.yml); thefeat:prefix on this commit triggers the next minor bump.