Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 120 additions & 15 deletions astraweave-render/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12013,20 +12013,29 @@ fn install_device_error_handler(
/// Append one skip line for a test that found no adapter.
///
/// `new_headless` does not call this. The parent directory has to already
/// exist and canonicalize to the workspace `target/` directory. The file
/// itself is created. A symlink at the final path is refused, and the open
/// does not follow one. A failed write panics so the test does not pass
/// without a line.
#[allow(clippy::panic)]
/// exist and canonicalize to the workspace `target/` directory. That
/// directory is `CARGO_TARGET_DIR` when set, otherwise the parent of this
/// crate's compile-time manifest plus `target`. The calling test's runtime
/// manifest is not consulted, so a `<crate>/target` directory does not move
/// the log. The file itself is created. A symlink at the final path is
/// refused, and the open does not follow one. A failed write panics so the
/// test does not pass without a line.
pub fn record_gpu_skip_for_tests(reason: &str) {
record_gpu_skip_for_tests_at(reason, std::env::var_os("AW_GPU_SKIP_LOG"));
}

/// `log_override` is `AW_GPU_SKIP_LOG`. `None` uses `gpu-skip-reasons.txt`
/// inside the workspace target. The guard is the same either way.
#[allow(clippy::panic)]
fn record_gpu_skip_for_tests_at(reason: &str, log_override: Option<std::ffi::OsString>) {
let target = existing_workspace_target();
let target = target.canonicalize().unwrap_or_else(|err| {
panic!(
"GPU skip log stays in the workspace target directory, missing at {}: {err}",
target.display()
)
});
let path = match std::env::var_os("AW_GPU_SKIP_LOG") {
let path = match log_override {
Some(raw) => std::path::PathBuf::from(raw),
None => target.join("gpu-skip-reasons.txt"),
};
Expand Down Expand Up @@ -12116,20 +12125,24 @@ fn one_skip_line(reason: &str) -> String {
.collect()
}

/// Workspace `target/` for the GPU skip log.
///
/// `CARGO_TARGET_DIR` wins when the process has it. Otherwise the path is
/// the parent of this crate's compile-time manifest plus `target`.
/// `env!("CARGO_MANIFEST_DIR")` is baked into `astraweave-render`. The
/// runtime `CARGO_MANIFEST_DIR` is the package Cargo is testing, and an
/// ancestor walk stops at the first `target/` directory. Scene streaming
/// tests created `astraweave-scene/target`, so that walk returned the crate
/// directory and the guard rejected the workspace skip log.
fn existing_workspace_target() -> std::path::PathBuf {
if let Some(dir) = std::env::var_os("CARGO_TARGET_DIR") {
return std::path::PathBuf::from(dir);
}
let manifest = std::path::PathBuf::from(
std::env::var_os("CARGO_MANIFEST_DIR").unwrap_or_else(|| std::ffi::OsString::from(".")),
);
for ancestor in manifest.ancestors() {
let candidate = ancestor.join("target");
if candidate.is_dir() {
return candidate;
}
let manifest = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CARGO_TARGET_DIR is returned above this line, before the compile-time parent is considered. A relative value is canonicalized from the test process cwd. Cargo runs an integration test with cwd at the package directory, so CARGO_TARGET_DIR=./target becomes <crate>/target.

I checked that with a two-package workspace: from the member directory, ./target resolved to the member target/, and <workspace>/target was a different directory. .github/scripts/cache-config.sh exports CARGO_TARGET_DIR=./target on Linux and macOS. The Test full job does not source that file. scripts/ci/run-tests.sh and .github/actions/rust-ci-setup do not export it either. ci.yml sets AW_GPU_SKIP_LOG to the absolute ${GITHUB_WORKSPACE}/target/gpu-skip-reasons.txt. On that job this fallback runs.

A shell that sources cache-config.sh and then runs cargo test puts the guard back on a crate-local directory when that directory exists, and panics with missing at when it does not. The new trace text calls this value the workspace target. That holds for an absolute CARGO_TARGET_DIR.

match manifest.parent() {
Some(workspace) => workspace.join("target"),
None => manifest.join("target"),
}
manifest.join("target")
}

fn warp_requested() -> bool {
Expand Down Expand Up @@ -12207,6 +12220,98 @@ mod skip_log_tests {
let other: anyhow::Error = wgpu::RequestAdapterError::EnvNotSet.into();
assert!(!super::is_missing_adapter(&other));
}

/// A `<crate>/target` directory must not steal the workspace skip log.
///
/// The log path is what CI sets on `AW_GPU_SKIP_LOG`: a file whose parent
/// is the workspace `target/`. The override is passed in so a parallel
/// lib test does not observe a process-wide `set_var`.
#[test]
fn crate_local_target_keeps_the_workspace_skip_log() {
let decoy = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("target");
let created = !decoy.exists();
if created {
std::fs::create_dir_all(&decoy).expect("crate-local target");
}
struct Cleanup {
decoy: std::path::PathBuf,
created: bool,
log: Option<std::path::PathBuf>,
}
impl Drop for Cleanup {
fn drop(&mut self) {
if let Some(log) = &self.log {
let _ = std::fs::remove_file(log);
}
if self.created {
let _ = std::fs::remove_dir_all(&self.decoy);
}
}
}
let mut cleanup = Cleanup {
decoy: decoy.clone(),
created,
log: None,
};
let workspace = super::existing_workspace_target()
.canonicalize()
.expect("workspace target");
let decoy_canon = decoy.canonicalize().expect("decoy target");
assert_ne!(
workspace, decoy_canon,
"crate-local target must not become the workspace target"
);
let log_name = format!(
"gpu-skip-crate-decoy-{}-{}.txt",
std::process::id(),
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.expect("clock")
.as_nanos()
);
let log = workspace.join(log_name);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log is existing_workspace_target() joined with a unique name, and the guard then requires the file's parent to be that same directory. The assertion passes for any existing directory other than the decoy. macOS sets AW_GPU_SKIP_LOG to a fixed path, ${GITHUB_WORKSPACE}/target/gpu-skip-reasons.txt, and the guard compares that parent to the resolver.

assert_ne! against astraweave-render/target does catch the old walk when the runtime manifest is this crate: that walk returns the decoy. Pin the resolved path, when CARGO_TARGET_DIR is unset, to Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap().join("target").

Drop calls remove_dir_all on astraweave-render/target when this test created it. That is the directory the old walk would have selected. CI's artifacts live in the repo-root target/, so that delete does not remove the build tree on the Test full layout. The None override, which writes gpu-skip-reasons.txt, is not exercised.

cleanup.log = Some(log.clone());
super::record_gpu_skip_for_tests_at(
"crate-local target must not win",
Some(log.as_os_str().to_os_string()),
);
let written = std::fs::read_to_string(&log).expect("skip line");
assert!(
written.contains("SKIP(gpu):") && written.contains("crate-local target must not win"),
"{written}"
);
assert!(
!decoy.join("gpu-skip-reasons.txt").exists(),
"skip line was written under the crate-local target"
);
}

#[test]
fn skip_log_outside_the_workspace_target_still_panics() {
let dir = std::env::temp_dir().join(format!("aw-gpu-skip-outside-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).expect("outside dir");
let path = dir.join("gpu-skip-reasons.txt");
let caught = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
super::record_gpu_skip_for_tests_at("outside", Some(path.as_os_str().to_os_string()));
}));
let created = path.exists();
let _ = std::fs::remove_dir_all(&dir);
let payload = caught.expect_err("a skip log outside the workspace target must panic");
let text = panic_message(&payload);
assert!(text.contains("is outside"), "guard message was {text}");
assert!(!created, "the refused skip log must not be created");
}

fn panic_message(payload: &Box<dyn std::any::Any + Send>) -> String {
if let Some(msg) = payload.downcast_ref::<String>() {
return msg.clone();
}
if let Some(msg) = payload.downcast_ref::<&str>() {
return (*msg).to_string();
}
"non-string panic".to_string()
}
}

#[cfg(test)]
Expand Down
18 changes: 9 additions & 9 deletions astraweave-render/tests/support/gpu_capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,20 @@ fn skip_log_path() -> std::path::PathBuf {
path
}

/// Same rule as `renderer::existing_workspace_target`.
///
/// Compile-time manifest of this package, not the runtime
/// `CARGO_MANIFEST_DIR` of whichever test binary included this file. A
/// `<crate>/target` directory must not win the ancestor walk.
fn existing_target_dir() -> std::path::PathBuf {
if let Some(dir) = std::env::var_os("CARGO_TARGET_DIR") {
return std::path::PathBuf::from(dir);
}
let manifest = std::path::PathBuf::from(
std::env::var_os("CARGO_MANIFEST_DIR").unwrap_or_else(|| std::ffi::OsString::from(".")),
);
for ancestor in manifest.ancestors() {
let candidate = ancestor.join("target");
if candidate.is_dir() {
return candidate;
}
let manifest = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the resolver behind note_skip / skip_log_path. src/lib.rs compiles this file with #[path] under cfg(test), and the integration tests compile it again. The new tests call record_gpu_skip_for_tests_at only, so crate_local_target_keeps_the_workspace_skip_log never enters this function.

The two copies match in this commit. check-gpu-skip-log.sh reads the lines note_skip appends. A later edit to this copy alone puts the macOS census back on the runtime ancestor walk while the lib test stays green.

match manifest.parent() {
Some(workspace) => workspace.join("target"),
None => manifest.join("target"),
}
manifest.join("target")
}

fn skip_line(test: &str, reason: &str) -> String {
Expand Down
19 changes: 11 additions & 8 deletions astraweave-scene/tests/streaming_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ use std::sync::Arc;
use tokio::fs;
use tokio::sync::RwLock;

/// Helper to generate unique test directory per test to prevent parallel test race conditions
#[allow(dead_code)]
fn unique_test_dir(test_name: &str) -> PathBuf {
PathBuf::from(format!("target/test_assets/cells_{}", test_name))
/// Cell files this binary writes.
///
/// `CARGO_TARGET_TMPDIR` lives inside the workspace target. A relative
/// `target/` creates `astraweave-scene/target`, which used to win the GPU
/// skip log's ancestor walk and fail the workspace-path guard.
fn scratch_cells() -> PathBuf {
PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("test_assets/cells")
}

/// Helper to create a test cell file
Expand Down Expand Up @@ -99,8 +102,8 @@ async fn test_async_cell_loading() {
#[tokio::test]
async fn test_memory_budget_enforcement() {
// Create test directory
let test_dir = Path::new("target/test_assets/cells");
fs::create_dir_all(test_dir).await.ok();
let test_dir = scratch_cells();
fs::create_dir_all(&test_dir).await.ok();

// Create multiple cells
for x in 0..5 {
Expand Down Expand Up @@ -319,8 +322,8 @@ async fn test_lru_cache_functionality() {
#[tokio::test]
async fn test_performance_no_stalls() {
// Create test directory
let test_dir = Path::new("target/test_assets/cells");
fs::create_dir_all(test_dir).await.ok();
let test_dir = scratch_cells();
fs::create_dir_all(&test_dir).await.ok();

// Create cells
for x in 0..10 {
Expand Down
Loading
Loading