Skip to content
Closed
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
8 changes: 6 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ jobs:
- name: Choose the lanes this change needs
id: plan
# The crate graph comes from `cargo metadata`, which needs no build.
run: python3 scripts/ci-plan.py plan --event "$GITHUB_EVENT_NAME" --draft "${{ github.event.pull_request.draft || false }}"
# TEMP evidence run (do not merge): only the Windows web e2e lane.
run: |
echo 'lanes=["windows-e2e"]' >> "$GITHUB_OUTPUT"
echo 'full=false' >> "$GITHUB_OUTPUT"
echo 'rust-packages=[]' >> "$GITHUB_OUTPUT"

policy:
name: policy checks
Expand Down Expand Up @@ -383,7 +387,7 @@ jobs:
runner: windows-latest
herdr-platform: windows-x86_64
shards: 1
grep: "@platform"
grep: "Delete worktree closes the agents its checkout spawned|is deleted once both boxes are ticked"

# The web shell is the same code on every operating system, so the whole
# suite runs once, on Linux, where runners are plentiful. What differs by
Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/web-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ jobs:
# stops the shards, and the lane reports the failure.
if: ${{ !cancelled() && contains(fromJSON('["success","skipped"]'), needs.build.result) }}
runs-on: ${{ inputs.runner }}
timeout-minutes: 40
timeout-minutes: 150
defaults:
run:
shell: bash
Expand Down Expand Up @@ -237,7 +237,7 @@ jobs:
fi
echo "bin=$bin" >> "$GITHUB_OUTPUT"
- name: End-to-end
timeout-minutes: 20
timeout-minutes: 120
env:
HIDE_E2E_HERDR_BIN: ${{ steps.herdr.outputs.bin }}
HIDE_E2E_SCREENSHOT_DIR: ${{ runner.temp }}/hide-e2e
Expand Down Expand Up @@ -267,13 +267,15 @@ jobs:
python3 scripts/web-e2e-shard.py check --shard "$SHARD" "$list" "$RUNNER_TEMP/web-e2e-shard-list.txt"
args+=(--test-list "$shard_file")
fi
bash scripts/verify-web.sh web e2e "${args[@]}"
# TEMP evidence run (do not merge): every CPU busy, the delete tests repeated.
for i in $(seq "$(nproc)"); do (while :; do :; done) & done
bash scripts/verify-web.sh web e2e "${args[@]}" --repeat-each 30 --retries 0
- name: Report flaky tests
# A test that failed and passed its retry becomes an issue with a
# seven-day deadline, or a comment on the issue that tracks it. A
# report that fails to file is a warning, not a failed lane.
id: flaky
if: ${{ !cancelled() }}
if: ${{ false }}
continue-on-error: true
timeout-minutes: 5
env:
Expand All @@ -287,7 +289,7 @@ jobs:
# is on the step's stdout. A screen assertion alone cannot say which
# side moved. A flaky run keeps them too: its first attempt failed,
# and its issue has no other evidence of why.
if: ${{ failure() || steps.flaky.outputs.flaky == 'true' }}
if: always()
uses: actions/upload-artifact@v7
with:
name: hide-web-e2e-logs-${{ inputs.lane }}-${{ matrix.shard }}
Expand Down
70 changes: 70 additions & 0 deletions hide-host/src/worktrees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,15 @@ pub fn describe(
base_override: Option<&str>,
) -> WorktreeFacts {
let path = listed.path.to_string_lossy().into_owned();
eprintln!("{}", serde_json::json!({"kind": "temp.describe", "phase": "start", "path": path, "at_ms": temp_now_ms()}));
let temp_path = path.clone();
struct TempEnd(String);
impl Drop for TempEnd {
fn drop(&mut self) {
eprintln!("{}", serde_json::json!({"kind": "temp.describe", "phase": "end", "path": self.0, "at_ms": temp_now_ms()}));
}
}
let _temp_end = TempEnd(temp_path);
if !listed.path.exists() {
// Nothing can be counted against a path that is not there, and
// reporting zeros would read as a clean checkout rather than a gone
Expand Down Expand Up @@ -1337,7 +1346,10 @@ fn set_aside(root: &Path, common: &Path, checkout: &Path, force: bool) -> Option
.ok()?
.as_nanos();
let entry = trash.join(format!("{nanos}-{}-{id}", std::process::id()));
eprintln!("{}", serde_json::json!({"kind": "temp.set_aside_attempt", "checkout": checkout, "at_ms": temp_now_ms()}));
if let Err(error) = std::fs::rename(checkout, &entry) {
#[cfg(windows)]
temp_record_cwds(checkout);
// Git removes the folder in place from here; record why the cheap
// path was not taken, since the removal's own result will not.
let attempt = entry
Expand All @@ -1361,6 +1373,64 @@ fn set_aside(root: &Path, common: &Path, checkout: &Path, force: bool) -> Option
Some(SetAside { entry, admin })
}

/// TEMP evidence for issue 707 (do not merge).
fn temp_now_ms() -> u128 {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map(|elapsed| elapsed.as_millis())
.unwrap_or(0)
}

/// TEMP evidence for issue 707 (do not merge): at the refusal, the processes
/// working inside the folder and every child of this process.
#[cfg(windows)]
fn temp_record_cwds(checkout: &Path) {
let started = std::time::Instant::now();
let spell = |path: &Path| {
path.to_string_lossy()
.to_lowercase()
.replace('/', "\\")
.trim_end_matches('\\')
.to_owned()
};
let folder = spell(checkout);
let me = std::process::id();
let table = hide_platform::process::temp_process_cwds();
let describe = |(pid, parent, name, cwd): &(u32, u32, String, Option<PathBuf>)| {
serde_json::json!({"pid": pid, "parent": parent, "name": name, "cwd": cwd})
};
let inside: Vec<_> = table
.iter()
.filter(|(_, _, _, cwd)| {
cwd.as_deref().is_some_and(|cwd| {
let cwd = spell(cwd);
cwd == folder || cwd.starts_with(&format!("{folder}\\"))
})
})
.map(describe)
.collect();
let children: Vec<_> = table.iter().filter(|(_, parent, _, _)| *parent == me).map(describe).collect();
let git: Vec<_> = table
.iter()
.filter(|(_, _, name, _)| name.eq_ignore_ascii_case("git.exe"))
.map(describe)
.collect();
eprintln!(
"{}",
serde_json::json!({
"kind": "temp.set_aside_cwds",
"checkout": checkout,
"at_ms": temp_now_ms(),
"self_pid": me,
"scan_ms": started.elapsed().as_millis() as u64,
"processes": table.len(),
"inside": inside,
"self_children": children,
"git": git,
})
);
}

/// The one scan for holders that may run at a time (see [`record_holders`]).
#[cfg(windows)]
static HOLDER_SCAN: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
Expand Down
85 changes: 85 additions & 0 deletions hide-platform/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2429,3 +2429,88 @@ mod run_cleanup_tests {
child.wait().unwrap();
}
}

/// TEMP evidence for issue 707 (do not merge): every process with its parent,
/// executable name and working directory where the system lets it be read.
#[cfg(windows)]
pub fn temp_process_cwds() -> Vec<(u32, u32, String, Option<PathBuf>)> {
use windows_sys::Win32::Foundation::{CloseHandle, INVALID_HANDLE_VALUE};
use windows_sys::Win32::System::Diagnostics::Debug::ReadProcessMemory;
use windows_sys::Win32::System::Diagnostics::ToolHelp::{
CreateToolhelp32Snapshot, PROCESSENTRY32W, Process32FirstW, Process32NextW,
TH32CS_SNAPPROCESS,
};
use windows_sys::Win32::System::Threading::{
OpenProcess, PROCESS_QUERY_LIMITED_INFORMATION, PROCESS_VM_READ,
};
#[link(name = "ntdll")]
unsafe extern "system" {
fn NtQueryInformationProcess(
process: *mut core::ffi::c_void,
class: u32,
info: *mut core::ffi::c_void,
length: u32,
returned: *mut u32,
) -> i32;
}
unsafe fn read<T: Copy>(process: *mut core::ffi::c_void, at: usize) -> Option<T> {
let mut value = std::mem::MaybeUninit::<T>::uninit();
let mut got = 0usize;
let ok = unsafe {
ReadProcessMemory(
process,
at as *const _,
value.as_mut_ptr().cast(),
std::mem::size_of::<T>(),
&mut got,
)
};
(ok != 0 && got == std::mem::size_of::<T>()).then(|| unsafe { value.assume_init() })
}
fn cwd(pid: u32) -> Option<PathBuf> {
let process = unsafe { OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_VM_READ, 0, pid) };
if process.is_null() {
return None;
}
let answer = (|| {
let mut basic = [0usize; 6];
let status = unsafe {
NtQueryInformationProcess(process, 0, basic.as_mut_ptr().cast(), 48, std::ptr::null_mut())
};
if status < 0 {
return None;
}
let peb = basic[1];
let parameters: usize = unsafe { read(process, peb + 0x20) }?;
let length: u16 = unsafe { read(process, parameters + 0x38) }?;
let buffer: usize = unsafe { read(process, parameters + 0x40) }?;
let mut text = vec![0u16; length as usize / 2];
let mut got = 0usize;
let ok = unsafe {
ReadProcessMemory(process, buffer as *const _, text.as_mut_ptr().cast(), length as usize, &mut got)
};
(ok != 0).then(|| PathBuf::from(String::from_utf16_lossy(&text)))
})();
unsafe { CloseHandle(process) };
answer
}
let mut table: Vec<(u32, u32, String)> = Vec::new();
let snapshot = unsafe { CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) };
if snapshot == INVALID_HANDLE_VALUE {
return Vec::new();
}
let mut entry: PROCESSENTRY32W = unsafe { std::mem::zeroed() };
entry.dwSize = std::mem::size_of::<PROCESSENTRY32W>() as u32;
let mut more = unsafe { Process32FirstW(snapshot, &mut entry) } != 0;
while more {
let end = entry.szExeFile.iter().position(|unit| *unit == 0).unwrap_or(entry.szExeFile.len());
let name = String::from_utf16_lossy(&entry.szExeFile[..end]);
table.push((entry.th32ProcessID, entry.th32ParentProcessID, name));
more = unsafe { Process32NextW(snapshot, &mut entry) } != 0;
}
unsafe { CloseHandle(snapshot) };
table
.into_iter()
.map(|(pid, parent, name)| (pid, parent, name, cwd(pid)))
.collect()
}
40 changes: 40 additions & 0 deletions hided/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ impl Drop for RunningDaemon {
}

pub async fn run_daemon(env: Env) -> Result<(), String> {
#[cfg(windows)]
temp_start_cwd_sampler();
let state_dir = env.state_dir.clone();
let running = start_daemon(env).await?;
wait_shutdown_or_signal(&running).await;
Expand Down Expand Up @@ -830,3 +832,41 @@ mod tests {
assert!(roots_from_snapshot(b"not json").is_empty());
}
}

/// TEMP evidence for issue 707 (do not merge): every 25 ms, the processes
/// whose working directory is inside an e2e fixture folder, logged when each
/// first appears there and when it leaves.
#[cfg(windows)]
fn temp_start_cwd_sampler() {
let _ = std::thread::Builder::new().name("temp-cwd-sampler".into()).spawn(|| {
let now_ms = || {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map(|elapsed| elapsed.as_millis())
.unwrap_or(0)
};
let mut seen: std::collections::BTreeMap<(u32, String), (u32, String)> = Default::default();
loop {
let mut current = std::collections::BTreeMap::new();
for (pid, parent, name, cwd) in hide_platform::process::temp_process_cwds() {
let Some(cwd) = cwd else { continue };
let cwd = cwd.to_string_lossy().into_owned();
if cwd.to_lowercase().contains("hide-e2e-herdr-") {
current.insert((pid, cwd), (parent, name));
}
}
for (key, (parent, name)) in &current {
if !seen.contains_key(key) {
eprintln!("{}", serde_json::json!({"kind": "temp.cwd_seen", "pid": key.0, "parent": parent, "name": name, "cwd": key.1, "at_ms": now_ms(), "self_pid": std::process::id()}));
}
}
for (key, (_, name)) in &seen {
if !current.contains_key(key) {
eprintln!("{}", serde_json::json!({"kind": "temp.cwd_gone", "pid": key.0, "name": name, "cwd": key.1, "at_ms": now_ms()}));
}
}
seen = current;
std::thread::sleep(std::time::Duration::from_millis(25));
}
});
}
Loading