D2: engine commands for the remote browser, compare and sync; save before upload

deploy.browse, readRemote, writeRemote, renameRemote, mkdirRemote,
deleteRemote (confirm: true required), compare, sync (confirmDelete
required for deletions). deploy.upload saves dirty buffers under its
paths first (saveFirst, default true) without queueing uploads on save.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-11-06 19:41:31 +01:00
parent a8ad74755c
commit 7601ce12f6
5 changed files with 673 additions and 11 deletions

View file

@ -384,3 +384,122 @@ fn bad_params_and_no_project() {
Err(EngineError::Disabled(_))
));
}
#[test]
fn remote_browser_compare_sync_and_save_first() {
let tmp = tempfile::tempdir().unwrap();
let remote = tmp.path().join("remote");
std::fs::create_dir_all(remote.join("www/public")).unwrap();
std::fs::write(remote.join("www/public/old.php"), "<?php // old").unwrap();
let ftp = FtpServer::start(&remote, "deploy", PASSWORD).unwrap();
let host = Host::new(tmp.path());
let proj = project(tmp.path());
host.run("project.open", json!({"path": proj})).unwrap();
host.run(
"deploy.saveServer",
json!({"server": {
"name": "Shared", "kind": "ftp", "host": "127.0.0.1", "port": ftp.addr.port(),
"user": "deploy", "root": "/www", "excluded": ["composer.json"],
}, "secret": PASSWORD}),
)
.unwrap();
let listed = host
.run("deploy.browse", json!({"path": "public"}))
.unwrap();
assert_eq!(listed["entries"][0]["name"], "old.php");
assert_eq!(listed["entries"][0]["isDir"], false);
let bad = host
.run("deploy.browse", json!({"path": "../.."}))
.unwrap_err();
assert_eq!(bad.code(), "invalid_params", "{bad}");
host.run(
"deploy.writeRemote",
json!({"remotePath": "notes/n.txt", "text": "hi"}),
)
.unwrap();
assert_eq!(
std::fs::read_to_string(remote.join("www/notes/n.txt")).unwrap(),
"hi"
);
let read = host
.run("deploy.readRemote", json!({"remotePath": "notes/n.txt"}))
.unwrap();
assert_eq!(read["text"], "hi");
let missing = host
.run("deploy.readRemote", json!({"path": "public/index.php"}))
.unwrap();
assert_eq!(missing["text"], Value::Null);
host.run(
"deploy.renameRemote",
json!({"from": "notes/n.txt", "to": "notes/m.txt"}),
)
.unwrap();
host.run("deploy.mkdirRemote", json!({"path": "empty/dir"}))
.unwrap();
assert!(remote.join("www/empty/dir").is_dir());
let refused = host
.run("deploy.deleteRemote", json!({"path": "notes"}))
.unwrap_err();
assert_eq!(refused.code(), "invalid_params");
assert!(
remote.join("www/notes/m.txt").exists(),
"nothing is deleted without confirm"
);
let deleted = host
.run(
"deploy.deleteRemote",
json!({"path": "notes", "confirm": true}),
)
.unwrap();
assert_eq!(deleted["deleted"], 2);
let diffs = host
.run("deploy.compare", json!({"paths": ["public"]}))
.unwrap();
assert_eq!(
diffs["differences"],
json!([
{"path": "public/index.php", "status": "localOnly", "localSize": 13},
{"path": "public/old.php", "status": "remoteOnly", "remoteSize": 12},
])
);
let unconfirmed = host
.run(
"deploy.sync",
json!({"upload": ["public/index.php"], "delete": ["public/old.php"]}),
)
.unwrap_err();
assert_eq!(unconfirmed.code(), "invalid_params");
assert!(remote.join("www/public/old.php").exists());
let synced = host
.run(
"deploy.sync",
json!({"upload": ["public/index.php"], "delete": ["public/old.php"], "confirmDelete": true}),
)
.unwrap();
assert_eq!(
(synced["files"].clone(), synced["deleted"].clone()),
(json!(1), json!(1))
);
assert!(!remote.join("www/public/old.php").exists());
let opened = host
.run("file.open", json!({"path": "public/index.php"}))
.unwrap();
let id = opened["id"].as_u64().unwrap();
host.run(
"buffer.edit",
json!({"id": id, "baseVersion": 1, "edits": [{"from": 0, "to": 0, "insert": "// unsaved\n"}]}),
)
.unwrap();
host.run("deploy.upload", json!({"paths": ["public"]}))
.unwrap();
assert_eq!(
std::fs::read_to_string(remote.join("www/public/index.php")).unwrap(),
"// unsaved\n<?php echo 1;",
"the upload saved the buffer first"
);
assert!(!host.transcript().contains(PASSWORD));
}