Compile editor buffers without waiting for a save

Project preview accepts ?buffer=1 and reads the editor text from the POST body.
The source is still expanded with project includes/packages/images, but the file
on disk is not touched, so typing can drive layout immediately while the normal
450 ms save timer runs independently.

Add a server test that previews buffer text, finds it in the SVG, and verifies
hello.tex on disk was not rewritten. Roadmap notes that warm buffer previews
are still ~430 ms (article) and ~2.1 s (arXiv), and that dirty-page streaming
is the next latency step.
This commit is contained in:
gloamxun committed 2026-10-27 21:01:24 +08:00
1 parent 30f1df03ca
commit e2e80e8728
7 files changed
+61 -10

No files matched your search

+34
View File
@@ -1258,6 +1258,40 @@ fn project_preview_resolves_bibtex() {
assert!(!text.contains("[?]"), "{text}");
}
#[test]
fn project_preview_compiles_the_editor_buffer_without_saving() {
let server = TestServer::start("route-d-buffer");
let buffer =
"\\documentclass{article}\n\\begin{document}\n\nBuffer preview.\n\n\\end{document}\n";
let preview = server.request(
"POST",
"/api/projects/hello/preview?engine=route-d&buffer=1",
buffer.as_bytes(),
"text/plain; charset=utf-8",
);
assert_eq!(preview.status, 200, "{}", preview.text());
let value: Value = serde_json::from_slice(&preview.body).expect("preview JSON");
assert_eq!(value["status"], "ok", "{}", value["message"]);
let mut text = String::new();
for page in value["pages"].as_array().expect("pages") {
if let Some(svg) = page["svg"].as_str() {
for piece in svg.split('>') {
if let Some(content) = piece.split('<').next() {
text.push_str(content);
}
}
}
}
let text: String = text.split_whitespace().collect();
assert!(text.contains("Bufferpreview"), "{text}");
let raw = server.get("/api/projects/hello/raw?path=hello.tex");
assert_eq!(raw.status, 200);
assert!(
!raw.text().contains("Buffer preview"),
"buffer preview must not write the file"
);
}
#[test]
fn project_preview_can_switch_to_route_d() {
let server = TestServer::start("route-d-toggle");