Propagate temporary directories into sandbox policy contexts (#40660)

## Why

Filesystem policies containing `:tmpdir` need executor-local directory bindings,
including when execution occurs in a remote environment.

## What changed

- Cache temporary directories reported by remote executors and discover the
  equivalent directories for local environments.
- Preserve the cached directories across inherited environment selection and
  include them in `FileSystemSandboxContext`.
- Add `FileSystemSandboxPolicyContext` and a context accessor so filesystem
  policy entries can be resolved with the executor-owned current directory,
  workspace roots, and temporary directories.

## Testing

Extend environment-selection tests to cover local, remote, and inherited
temporary-directory policy context.

GitOrigin-RevId: 36335af3465c529f024bf69293af288803dd582d
This commit is contained in:
iceweasel-oai
2026-08-25 18:04:01 +00:00
committed by copyberry
parent 2f4b105514
commit ba9567daf3
10 changed files with 126 additions and 12 deletions
+25 -2
View File
@@ -153,9 +153,16 @@ pub enum EnvironmentStatusKind {
}
impl EnvironmentInfo {
/// Returns information about the current local exec-server process.
pub fn local() -> Self {
/// Returns executor-local default directories used to resolve `:tmpdir`.
///
/// This is separate from `local` so orchestrator startup can cache the
/// directories without repeating local shell detection.
pub fn local_temporary_directories() -> Vec<PathUri> {
let cwd = std::env::current_dir().ok();
Self::local_temporary_directories_with_cwd(cwd.as_deref())
}
fn local_temporary_directories_with_cwd(cwd: Option<&std::path::Path>) -> Vec<PathUri> {
let temporary_directory_env_vars: &[&str] = if cfg!(windows) {
&["TEMP", "TMP"]
} else {
@@ -181,6 +188,22 @@ impl EnvironmentInfo {
temporary_directories.push(path);
}
}
temporary_directories
}
/// Returns information about the current local exec-server process.
pub fn local() -> Self {
let cwd = std::env::current_dir().ok();
let temporary_directories = Self::local_temporary_directories_with_cwd(cwd.as_deref());
let normalize_temp_path = |path: std::ffi::OsString| {
PathUri::from_host_native_path(&path).ok().or_else(|| {
if cfg!(unix) {
PathUri::from_host_native_path(cwd.as_ref()?.join(path)).ok()
} else {
None
}
})
};
let temp_dir = normalize_temp_path(std::env::temp_dir().into_os_string());
Self {