mirror of
https://github.com/l0ng-ai/tty7.git
synced 2026-09-21 16:02:20 +00:00
fix(machine): format the three items and stop reading the tree per persist
`rustfmt` is a required check and was red on three hunks of this branch: `owner_of`'s signature, the `--cwd` argv in `tab_new`'s adopt test, and the two `tab_create` calls in `the_document_being_replaced_is_kept_beside_it`. `keep_a_generation` also read the whole document before asking whether it was going to keep anything. It runs on every persist — pane facts alone flush every couple of seconds — and answers "too soon" on almost all of them, so that was a full read of `machine.json` per write to produce one copy every five minutes. The spacing check moves ahead of the read; the `NotFound` arm still covers the machine that has never written a tree. And a line continuation was missing from an assertion message in `a_typed_name_waits_for_the_create_rather_than_racing_it`, so the failure would have printed eighteen spaces mid-sentence. Claude-Session: https://claude.ai/code/session_01JRqYZ9E153WpSHGS2AW3BM
This commit is contained in:
@@ -772,7 +772,10 @@ fn adopt_pane(
|
||||
}
|
||||
|
||||
/// The workspace a pane was spawned for, if it is still on this machine.
|
||||
fn owner_of(info: &tty7_core::daemon::protocol::PaneInfo, machine: &Machine) -> Option<WorkspaceId> {
|
||||
fn owner_of(
|
||||
info: &tty7_core::daemon::protocol::PaneInfo,
|
||||
machine: &Machine,
|
||||
) -> Option<WorkspaceId> {
|
||||
let owner = info.owner.as_deref()?;
|
||||
machine
|
||||
.workspaces
|
||||
@@ -2201,7 +2204,9 @@ mod tests {
|
||||
.push_back(ReplyOk::TabTree(Box::new(Tab::leaf(37))));
|
||||
|
||||
run_cli(
|
||||
&["tty7", "tab", "new", "web", "--pane", "%37", "--cwd", "C:\\else"],
|
||||
&[
|
||||
"tty7", "tab", "new", "web", "--pane", "%37", "--cwd", "C:\\else",
|
||||
],
|
||||
&Context::default(),
|
||||
&mut backend,
|
||||
);
|
||||
|
||||
@@ -1304,12 +1304,9 @@ fn backup_path(path: &Path, generation: usize) -> PathBuf {
|
||||
/// Returns `Ok(())` when there was nothing to do: no tree yet, or the newest
|
||||
/// generation is younger than `spacing`.
|
||||
fn keep_a_generation(path: &Path, spacing: Duration) -> io::Result<()> {
|
||||
let bytes = match std::fs::read(path) {
|
||||
Ok(bytes) => bytes,
|
||||
// Nothing has been written yet, so there is no previous generation.
|
||||
Err(e) if e.kind() == io::ErrorKind::NotFound => return Ok(()),
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
// Asked before the tree is read: this runs on every persist and answers
|
||||
// "nothing to do" on almost all of them, so reading the whole document
|
||||
// first would be a full read per write for one copy every five minutes.
|
||||
let newest = backup_path(path, 0);
|
||||
let too_soon = std::fs::metadata(&newest)
|
||||
.and_then(|meta| meta.modified())
|
||||
@@ -1318,6 +1315,12 @@ fn keep_a_generation(path: &Path, spacing: Duration) -> io::Result<()> {
|
||||
if too_soon {
|
||||
return Ok(());
|
||||
}
|
||||
let bytes = match std::fs::read(path) {
|
||||
Ok(bytes) => bytes,
|
||||
// Nothing has been written yet, so there is no previous generation.
|
||||
Err(e) if e.kind() == io::ErrorKind::NotFound => return Ok(()),
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
// Oldest first, so nothing is overwritten before it has been moved down.
|
||||
// A generation that is not there yet simply has nothing to move.
|
||||
for generation in (1..BACKUP_GENERATIONS).rev() {
|
||||
@@ -2701,8 +2704,12 @@ mod tests {
|
||||
let store = MachineStore::open(&path);
|
||||
|
||||
let ws = store.workspace_create(None, None, None).unwrap();
|
||||
store.tab_create(ws.id, None, seed(1, "/work"), None, None).unwrap();
|
||||
store.tab_create(ws.id, None, seed(2, "/work"), None, None).unwrap();
|
||||
store
|
||||
.tab_create(ws.id, None, seed(1, "/work"), None, None)
|
||||
.unwrap();
|
||||
store
|
||||
.tab_create(ws.id, None, seed(2, "/work"), None, None)
|
||||
.unwrap();
|
||||
|
||||
let kept = backup_path(&path, 0);
|
||||
assert!(
|
||||
|
||||
+2
-1
@@ -2909,7 +2909,8 @@ mod tests {
|
||||
assert_eq!(parked.name, "deploy");
|
||||
assert_eq!(
|
||||
parked.workspace, ws,
|
||||
"and it is parked against the workspace it was typed for, so a window that walks into a different one cannot spend it (#716)"
|
||||
"and it is parked against the workspace it was typed for, so a window \
|
||||
that walks into a different one cannot spend it (#716)"
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user