Preserve Session Terminal TTY through causal launch
This commit is contained in:
parent
2af8a4f09f
commit
39307f4281
1 changed files with 87 additions and 8 deletions
|
|
@ -305,7 +305,7 @@ fn run_session_terminal_matrix() -> Result<(), MatrixError> {
|
|||
session.session_phase = SessionPhase::Attached;
|
||||
fixture
|
||||
.store
|
||||
.apply(&[DomainStoreMutation::PutSession(session)])
|
||||
.apply(&[DomainStoreMutation::PutSession(session.clone())])
|
||||
.map_err(failure)?;
|
||||
let command = fixture.bundle.command();
|
||||
let run = command
|
||||
|
|
@ -383,7 +383,35 @@ fn run_session_terminal_matrix() -> Result<(), MatrixError> {
|
|||
)
|
||||
.map_err(failure)?;
|
||||
}
|
||||
wait_for_signal_lines(&signals, 4)?;
|
||||
wait_for_signal_lines(&mut engine, session_id, &signals, 4)?;
|
||||
let mut forwarded_before_prompt = 0_usize;
|
||||
for _ in 0..2_000 {
|
||||
let messages = engine
|
||||
.poll(session_id, GenerationId::new(7))
|
||||
.map_err(failure)?;
|
||||
if messages.is_empty() {
|
||||
if forwarded_before_prompt > 0 {
|
||||
break;
|
||||
}
|
||||
thread::sleep(Duration::from_millis(5));
|
||||
continue;
|
||||
}
|
||||
for message in messages {
|
||||
if let SessionTerminalMessage::Output(chunk) = message {
|
||||
forwarded_before_prompt += chunk.bytes.len();
|
||||
}
|
||||
}
|
||||
}
|
||||
if forwarded_before_prompt == 0 {
|
||||
return Err(failure(
|
||||
"sandbox route did not forward buffered output before Prompt",
|
||||
));
|
||||
}
|
||||
session.session_phase = SessionPhase::Prompting;
|
||||
fixture
|
||||
.store
|
||||
.apply(&[DomainStoreMutation::PutSession(session.clone())])
|
||||
.map_err(failure)?;
|
||||
engine
|
||||
.set_route(session_id, GenerationId::new(7), TerminalRoute::Prompt)
|
||||
.map_err(failure)?;
|
||||
|
|
@ -394,6 +422,11 @@ fn run_session_terminal_matrix() -> Result<(), MatrixError> {
|
|||
if before != after {
|
||||
return Err(failure("prompt route did not apply PTY backpressure"));
|
||||
}
|
||||
session.session_phase = SessionPhase::Attached;
|
||||
fixture
|
||||
.store
|
||||
.apply(&[DomainStoreMutation::PutSession(session)])
|
||||
.map_err(failure)?;
|
||||
engine
|
||||
.set_route(session_id, GenerationId::new(7), TerminalRoute::Sandbox)
|
||||
.map_err(failure)?;
|
||||
|
|
@ -470,8 +503,16 @@ fn wait_for_path(path: &Path) -> Result<(), MatrixError> {
|
|||
Err(failure("Session Terminal guest did not become ready"))
|
||||
}
|
||||
|
||||
fn wait_for_signal_lines(path: &Path, expected: usize) -> Result<(), MatrixError> {
|
||||
fn wait_for_signal_lines(
|
||||
engine: &mut SessionTerminalEngine,
|
||||
session_id: SessionId,
|
||||
path: &Path,
|
||||
expected: usize,
|
||||
) -> Result<(), MatrixError> {
|
||||
for _ in 0..2_000 {
|
||||
engine
|
||||
.poll(session_id, GenerationId::new(7))
|
||||
.map_err(failure)?;
|
||||
if fs::read_to_string(path)
|
||||
.ok()
|
||||
.is_some_and(|value| value.lines().count() >= expected)
|
||||
|
|
|
|||
Loading…
Reference in a new issue