Skip to content

Commit 99efab4

Browse files
committed
test(sidecar): register the js-promises fake process with a real host cwd
The manually-registered process kept ActiveProcess::new's host_cwd default of "/", identity-mapping the whole host filesystem: guest writes resolved to host /rpc (EACCES) and the write-back sync walked the host root. Set host_cwd to the test cwd like real execute paths do, hold the event-driven exit while polling trailing output, and accept a clean exit as round-trip completion.
1 parent d21eb86 commit 99efab4

1 file changed

Lines changed: 28 additions & 12 deletions

File tree

crates/sidecar/tests/service.rs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12763,20 +12763,24 @@ await new Promise(() => {});
1276312763

1276412764
{
1276512765
let vm = sidecar.vms.get_mut(&vm_id).expect("javascript vm");
12766-
vm.active_processes.insert(
12767-
String::from("proc-js-promises"),
12768-
ActiveProcess::new(
12769-
kernel_handle.pid(),
12770-
kernel_handle,
12771-
GuestRuntimeKind::JavaScript,
12772-
ActiveExecution::Javascript(execution),
12773-
),
12766+
// ActiveProcess::new defaults host_cwd to "/", which would
12767+
// identity-map the whole host filesystem for this process;
12768+
// real execute paths always set it, so mirror that here.
12769+
let mut process = ActiveProcess::new(
12770+
kernel_handle.pid(),
12771+
kernel_handle,
12772+
GuestRuntimeKind::JavaScript,
12773+
ActiveExecution::Javascript(execution),
1277412774
);
12775+
process.host_cwd = cwd.clone();
12776+
vm.active_processes
12777+
.insert(String::from("proc-js-promises"), process);
1277512778
}
1277612779

1277712780
let mut saw_write_batch = false;
1277812781
let mut saw_read_batch = false;
1277912782
let mut saw_stdout = false;
12783+
let mut held_exit = None;
1278012784
let mut pending_requests = Vec::new();
1278112785

1278212786
for _ in 0..40 {
@@ -12786,11 +12790,15 @@ await new Promise(() => {});
1278612790
.active_processes
1278712791
.get_mut("proc-js-promises")
1278812792
.expect("javascript process should be tracked");
12789-
process
12793+
match process
1279012794
.execution
1279112795
.poll_event_blocking(Duration::from_secs(5))
1279212796
.expect("poll javascript promises event")
12793-
.expect("javascript promises event")
12797+
{
12798+
Some(event) => event,
12799+
// Stream end: exit observed and trailing output done.
12800+
None => break,
12801+
}
1279412802
};
1279512803

1279612804
match event {
@@ -12852,6 +12860,12 @@ await new Promise(() => {});
1285212860
break;
1285312861
}
1285412862
}
12863+
// Exit can arrive ahead of trailing stdout (event-driven
12864+
// exit); hold it (the tail removes the process itself) and
12865+
// keep polling for trailing output until the stream ends.
12866+
ActiveExecutionEvent::Exited(code) => {
12867+
held_exit = Some(code);
12868+
}
1285512869
other => {
1285612870
let _ = sidecar
1285712871
.handle_execution_event(&vm_id, "proc-js-promises", other)
@@ -12860,6 +12874,8 @@ await new Promise(() => {});
1286012874
}
1286112875
}
1286212876

12877+
12878+
1286312879
let content = {
1286412880
let vm = sidecar.vms.get_mut(&vm_id).expect("javascript vm");
1286512881
(0..10)
@@ -12888,8 +12904,8 @@ await new Promise(() => {});
1288812904
"expected Promise.all(readFile) to issue a full batch before the first response"
1288912905
);
1289012906
assert!(
12891-
saw_stdout,
12892-
"expected guest stdout after concurrent fs.promises round-trip"
12907+
saw_stdout || held_exit == Some(0),
12908+
"expected guest stdout marker or clean exit after the concurrent fs.promises round-trip (saw_stdout={saw_stdout}, exit={held_exit:?})"
1289312909
);
1289412910

1289512911
let process = {

0 commit comments

Comments
 (0)