Replace lexical Rust fragments with real modules

This commit is contained in:
ms2k 2026-07-19 05:12:57 +09:00
commit 247819250b
7 changed files with 3302 additions and 2671 deletions

View file

@ -1,3 +1,14 @@
use super::{
ActiveTerminal, Arc, DRAIN_DEADLINE, GenerationId, GuestReleaseAuthority, GuestWaitOutcome,
HashMap, HostCoordinatorDomainStore, HostCoordinatorTerminalRecorder, Instant, MAX_DRAIN_BYTES,
MAX_EVENT_BYTES, MAX_INPUT_QUEUE_BYTES, MAX_OUTPUT_BYTES, POLL_INTERVAL,
PersistedHostProcessOwnership, ProcessExit, PromptRouteCancellation, SIGNAL_GRACE, SessionExit,
SessionId, SessionTerminalEngine, SessionTerminalEvent, SessionTerminalFactory,
SessionTerminalMessage, SessionTerminalProcess, SessionTerminalState, TerminalAcquisition,
TerminalError, TerminalLoss, TerminalOutput, TerminalRoute, TerminalSignalKind, VecDeque,
clean_terminal, copy_terminal_state, io, terminal_snapshot,
};
impl SessionTerminalEngine {
#[must_use]
pub fn new(
@ -356,7 +367,7 @@ impl SessionTerminalEngine {
}
}
fn release_physical(
pub(super) fn release_physical(
process: &mut dyn SessionTerminalProcess,
session_id: SessionId,
connected: bool,
@ -536,4 +547,3 @@ fn exit_message(
_ => Err(TerminalError::InvalidExit),
}
}

View file

@ -1,18 +1,29 @@
struct ActiveTerminal {
generation_id: GenerationId,
request: TerminalAcquisition,
route: TerminalRoute,
record: SessionTerminal,
process: Box<dyn SessionTerminalProcess>,
releasing: bool,
pending_input: VecDeque<u8>,
use super::{
Arc, ContainerId, ControlError, CoordinatorId, DomainId, GenerationId, HashMap,
HostCoordinatorDomainStore, HostCoordinatorTerminalRecorder, InteractiveControlSession,
InteractiveSessionBatch, InteractiveSessionEvent, InteractiveSessionExecutor,
InteractiveSessionMessage, InteractiveSessionRequest, Mutex, OsString, PathBuf,
PidfsProcessIdentityV1, PromptRouteCancellation, ProtocolVersion, RunscSessionTerminalFactory,
SessionId, SessionPromptTransport, SessionTerminal, SessionTerminalEvent,
SessionTerminalFactory, SessionTerminalMessage, SessionTerminalProcess, TerminalAcquisition,
TerminalError, TerminalLoss, TerminalRoute, VecDeque,
};
pub(super) struct ActiveTerminal {
pub(super) generation_id: GenerationId,
pub(super) request: TerminalAcquisition,
pub(super) route: TerminalRoute,
pub(super) record: SessionTerminal,
pub(super) process: Box<dyn SessionTerminalProcess>,
pub(super) releasing: bool,
pub(super) pending_input: VecDeque<u8>,
}
pub struct SessionTerminalEngine {
recorder: HostCoordinatorTerminalRecorder,
factory: Arc<dyn SessionTerminalFactory>,
cancellation: Arc<dyn PromptRouteCancellation>,
active: HashMap<SessionId, ActiveTerminal>,
pub(super) recorder: HostCoordinatorTerminalRecorder,
pub(super) factory: Arc<dyn SessionTerminalFactory>,
pub(super) cancellation: Arc<dyn PromptRouteCancellation>,
pub(super) active: HashMap<SessionId, ActiveTerminal>,
}
pub struct RunscInteractiveSessionExecutor {
@ -124,11 +135,11 @@ impl InteractiveSessionExecutor for RunscInteractiveSessionExecutor {
}
}
struct RunscInteractiveControlSession {
engine: Arc<Mutex<SessionTerminalEngine>>,
prompt_transport: Arc<SessionPromptTransport>,
generation_id: GenerationId,
session_id: SessionId,
pub(super) struct RunscInteractiveControlSession {
pub(super) engine: Arc<Mutex<SessionTerminalEngine>>,
pub(super) prompt_transport: Arc<SessionPromptTransport>,
pub(super) generation_id: GenerationId,
pub(super) session_id: SessionId,
}
impl InteractiveControlSession for RunscInteractiveControlSession {
@ -246,4 +257,3 @@ fn hex_session(bytes: &[u8]) -> String {
output
})
}

View file

@ -1,3 +1,20 @@
use super::{
Arc, ChildStandardIo, DeviceId, File, FileDescriptor, GenerationId, GuestProcessGroupId,
GuestProcessId, GuestProcessIdentity, GuestProcessStartTimeTicks,
HostCoordinatorTerminalRecorder, IDENTITY_DEADLINE, InodeId, Instant, Mutex, OFlags,
OpenptFlags, OsString, POLL_INTERVAL, PRIVATE_SESSION_EXEC_ROLE, PRIVATE_SESSION_IDENTITY_ROLE,
PersistedHostProcessOwnership, PidfsProcessIdentityV1, ProcessExit, ProcessOwnershipCommitAck,
ProcessOwnershipContext, PtyIdentity, RetainedProcess, SANDBOX_INIT_PATH, SessionId,
SessionTerminal, SessionTerminalFactory, SessionTerminalFields, SessionTerminalProcess,
SessionTerminalState, StagedProcessOwnership, TargetCommand, TerminalAcquisition,
TerminalError, TerminalResize, Winsize, child_broker, current_process_identity, fcntl_getfl,
fcntl_setfl, fstat, grantpt, io, ioctl_tiocgptpeer, openpt, release_physical, tcsetwinsize,
unlockpt,
};
use std::io::{Read, Write};
use std::os::fd::AsRawFd;
use std::os::unix::ffi::OsStringExt;
pub struct RunscSessionTerminalFactory;
impl SessionTerminalFactory for RunscSessionTerminalFactory {
@ -156,7 +173,7 @@ impl SessionTerminalFactory for RunscSessionTerminalFactory {
}
}
fn commit_running_or_cleanup(
pub(super) fn commit_running_or_cleanup(
recorder: &HostCoordinatorTerminalRecorder,
request: &TerminalAcquisition,
running: SessionTerminal,
@ -364,7 +381,7 @@ fn allocate_pty() -> io::Result<(File, File, PtyIdentity)> {
Ok((File::from(master), File::from(slave), pty))
}
fn staged_terminal(
pub(super) fn staged_terminal(
request: &TerminalAcquisition,
pty: PtyIdentity,
staged: StagedProcessOwnership,
@ -379,7 +396,7 @@ fn staged_terminal(
)
}
fn terminal_snapshot(
pub(super) fn terminal_snapshot(
request: &TerminalAcquisition,
state: SessionTerminalState,
host_coordinator: PersistedHostProcessOwnership,
@ -401,7 +418,7 @@ fn terminal_snapshot(
.map_err(|_| io::Error::other("Session Terminal snapshot is invalid").into())
}
fn copy_terminal_state(
pub(super) fn copy_terminal_state(
record: &SessionTerminal,
state: SessionTerminalState,
) -> Result<SessionTerminal, TerminalError> {
@ -418,7 +435,7 @@ fn copy_terminal_state(
.map_err(|_| io::Error::other("Session Terminal release snapshot is invalid").into())
}
fn clean_terminal(
pub(super) fn clean_terminal(
generation_id: GenerationId,
session_id: SessionId,
) -> Result<SessionTerminal, TerminalError> {
@ -590,6 +607,3 @@ fn hex_lower(bytes: &[u8]) -> String {
output
})
}
#[cfg(test)]
mod tests;

View file

@ -1,3 +1,5 @@
use super::*;
use std::collections::VecDeque;
use std::fs::{File, OpenOptions};
use std::io;
@ -20,8 +22,6 @@ use tempfile::TempDir;
use crate::control::TrustAnchor;
use super::*;
fn bytes(value: u8) -> [u8; 32] {
[value; 32]
}
@ -542,6 +542,8 @@ fn engine_for(fixture: &Fixture) -> (Arc<MockFactory>, SessionTerminalEngine) {
engine_for_store(store)
}
include!("tests/prompt.rs");
include!("tests/acquisition.rs");
include!("tests/output.rs");
mod acquisition;
mod output;
mod prompt;
use prompt::{assert_no_group_signal, engine_for_store, id};

View file

@ -1,3 +1,5 @@
use super::*;
fn assert_no_guest_action_after(factory: &MockFactory, marker: &str) {
let log = factory.log.lock().unwrap();
let marker = log.iter().position(|action| action == marker).unwrap();

View file

@ -1,3 +1,5 @@
use super::*;
#[test]
fn merged_output_is_ordered_and_prompt_route_isolated_by_session() {
let first = id(6);

View file

@ -1,3 +1,5 @@
use super::*;
#[test]
#[allow(clippy::too_many_lines)]
fn prompt_adapter_retains_resume_resize_before_authenticated_denial() {
@ -175,7 +177,7 @@ fn prompt_adapter_retains_resume_resize_before_authenticated_denial() {
.unwrap();
}
fn engine_for_store(
pub(super) fn engine_for_store(
store: Arc<dyn TerminalDomainStore>,
) -> (Arc<MockFactory>, SessionTerminalEngine) {
let factory = Arc::new(MockFactory::default());
@ -188,11 +190,11 @@ fn engine_for_store(
(factory, engine)
}
fn id(value: u8) -> SessionId {
pub(super) fn id(value: u8) -> SessionId {
SessionId::new(bytes(value))
}
fn assert_no_group_signal(factory: &MockFactory) {
pub(super) fn assert_no_group_signal(factory: &MockFactory) {
assert!(
factory
.log