Stage verified suffix previews before new state hashing
This commit is contained in:
1 parent
5927196149
commit
f684872941
9 files changed
+350
-80
No files matched your search
+113
-8
@@ -2081,11 +2081,8 @@ fn resized_entry_prefix_invalidates_an_executed_file_size_query() {
|
||||
fs::remove_dir_all(cwd).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn settled_suffix_relocates_source_spans_after_insertions_and_deletions() {
|
||||
let cwd = directory("settled-resized-suffix");
|
||||
let entry = cwd.join("main.tex");
|
||||
let body = |letter, note, tail_query| format!(r"
|
||||
fn resized_suffix_body(letter: char, note: &str, tail_query: &str) -> String {
|
||||
format!(r"
|
||||
\tracingstats=2
|
||||
\shipout\hbox{{Cover ABC}}
|
||||
\setbox3=\hbox{{{letter}}}\relax%{note}
|
||||
@@ -2099,10 +2096,16 @@ fn settled_suffix_relocates_source_spans_after_insertions_and_deletions() {
|
||||
\relax
|
||||
\shipout\hbox{{Final}}
|
||||
\end
|
||||
");
|
||||
")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn settled_suffix_relocates_source_spans_after_insertions_and_deletions() {
|
||||
let cwd = directory("settled-resized-suffix");
|
||||
let entry = cwd.join("main.tex");
|
||||
for tail_query in ["", r"\count42=\pdffilesize{main.tex}\relax"] {
|
||||
let mut project = ProjectSnapshot::new(
|
||||
atomic_definition(&cwd, 1, &body('A', "medium", tail_query)),
|
||||
atomic_definition(&cwd, 1, &resized_suffix_body('A', "medium", tail_query)),
|
||||
).unwrap();
|
||||
let mut request = request(&cwd).observe_generated_initial();
|
||||
request.world = project.configuration();
|
||||
@@ -2110,7 +2113,7 @@ fn settled_suffix_relocates_source_spans_after_insertions_and_deletions() {
|
||||
// Only the current document can donate the suffix in either direction.
|
||||
let session = NativeCompiler::default().with_automatic_entry_checkpoints();
|
||||
let previous = session.compile(request.clone().with_project(project.clone())).unwrap();
|
||||
let source = format!("{HEADER}{}", body(letter, note, tail_query));
|
||||
let source = format!("{HEADER}{}", resized_suffix_body(letter, note, tail_query));
|
||||
let tail_offset = source.find("Suffix glyphs").unwrap();
|
||||
let bytes = i32::try_from(source.len()).unwrap();
|
||||
project = project.with_file_edits(
|
||||
@@ -2151,6 +2154,108 @@ fn settled_suffix_relocates_source_spans_after_insertions_and_deletions() {
|
||||
fs::remove_dir_all(cwd).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preview_before_relocated_suffix_fingerprint_preserves_exact_publication() {
|
||||
struct WatchDraft {
|
||||
compiler: NativeCompiler,
|
||||
previous: Arc<CompiledDocument>,
|
||||
cancel: bool,
|
||||
preview: Mutex<Option<PreviewUpdate>>,
|
||||
}
|
||||
|
||||
impl CompileObserver for WatchDraft {
|
||||
fn stage(&self, _: u64, _: CompileStage) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn preview_before_export(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn preview_before_fingerprint(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn draft_ready(&self, draft: DraftPreview<'_>) -> Result<(), String> {
|
||||
let work = draft.entry_checkpoint_work();
|
||||
assert!(work.reused_suffix_steps > 0 && !work.reused_completion, "{work:?}");
|
||||
assert!(draft.state_fingerprint_pending(), "{work:?}");
|
||||
assert!(Arc::ptr_eq(&self.previous, &self.compiler.latest().unwrap()));
|
||||
let update = draft.preview_since(Some(self.previous.revision()))?;
|
||||
assert_eq!(update.pages.iter().map(|page| page.index).collect::<Vec<_>>(), [1]);
|
||||
assert!(self.preview.lock().unwrap().replace(update).is_none());
|
||||
if self.cancel {
|
||||
self.compiler.start();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
let cwd = directory("preview-before-relocated-suffix-fingerprint");
|
||||
let original = resized_suffix_body('A', "medium", "");
|
||||
let edited = resized_suffix_body('B', "expanded comment", "");
|
||||
assert_ne!(original.find("Suffix glyphs"), edited.find("Suffix glyphs"));
|
||||
let project = ProjectSnapshot::new(atomic_definition(&cwd, 1, &original)).unwrap();
|
||||
let mut request = request(&cwd).observe_generated_initial();
|
||||
request.world = project.configuration();
|
||||
let compiler = NativeCompiler::default().with_automatic_entry_checkpoints();
|
||||
let previous = compiler.compile(request.clone().with_project(project.clone())).unwrap();
|
||||
let paths = ["job.pdf", "job.log"].map(|name| cwd.join(name));
|
||||
let original_artifacts = paths.each_ref().map(|path| fs::read(path).unwrap());
|
||||
|
||||
let source = format!("{HEADER}{edited}");
|
||||
let project = project.with_file_edits(
|
||||
2,
|
||||
[(cwd.join("main.tex"), Arc::from(source.into_bytes()))].into(),
|
||||
).unwrap();
|
||||
let request = request.with_project(project);
|
||||
let mut cancelled = None;
|
||||
for cancel in [true, false] {
|
||||
let observer = Arc::new(WatchDraft {
|
||||
compiler: compiler.clone(),
|
||||
previous: previous.clone(),
|
||||
cancel,
|
||||
preview: Mutex::new(None),
|
||||
});
|
||||
let mut observed = request.clone();
|
||||
observed.observer = Some(observer.clone());
|
||||
let result = compiler.compile_detailed(observed);
|
||||
let draft = observer.preview.lock().unwrap().take().unwrap();
|
||||
if cancel {
|
||||
let failure = result.err().unwrap();
|
||||
assert!(matches!(failure.error, CompileError::Cancelled));
|
||||
assert_eq!(failure.phase, AttemptPhase::Export);
|
||||
assert!(Arc::ptr_eq(&previous, &compiler.latest().unwrap()));
|
||||
assert_eq!(paths.each_ref().map(|path| fs::read(path).unwrap()), original_artifacts);
|
||||
cancelled = Some((failure.completed_execution.unwrap(), draft));
|
||||
continue;
|
||||
}
|
||||
|
||||
let published = result.unwrap();
|
||||
assert!(Arc::ptr_eq(&published, &compiler.latest().unwrap()));
|
||||
assert_eq!(draft, published.preview_since(Some(previous.revision())).unwrap());
|
||||
let (cancelled_execution, cancelled_draft) = cancelled.as_ref().unwrap();
|
||||
assert_eq!(draft.pages, cancelled_draft.pages);
|
||||
let artifacts = paths.each_ref().map(|path| fs::read(path).unwrap());
|
||||
assert_eq!(published.output, file_version(&paths[0]).unwrap());
|
||||
|
||||
let full = NativeCompiler::default().compile(request.clone()).unwrap();
|
||||
assert!(full.execution.execution.state != previous.execution.execution.state);
|
||||
assert_eq!(cancelled_execution.execution, full.execution.execution);
|
||||
assert_eq!(published.execution.execution, full.execution.execution);
|
||||
assert_eq!(published.execution.source_versions, full.execution.source_versions);
|
||||
assert_eq!(published.execution.execution_resources, full.execution.execution_resources);
|
||||
assert_eq!(published.output, full.output);
|
||||
assert_eq!(published.pdf, full.pdf);
|
||||
assert_eq!(published.pages, full.pages);
|
||||
assert_eq!(published.source_map.sources, full.source_map.sources);
|
||||
assert_eq!(published.source_map.pages, full.source_map.pages);
|
||||
assert_eq!(published.preview_since(None).unwrap().pages, full.preview_since(None).unwrap().pages);
|
||||
assert_eq!(paths.each_ref().map(|path| fs::read(path).unwrap()), artifacts);
|
||||
}
|
||||
fs::remove_dir_all(cwd).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn whole_line_edits_reuse_the_settled_suffix_and_relocate_provenance() {
|
||||
check_whole_line_suffix_edits("whole-line-safe-suffix", InputProfile::TeX8Bit, false);
|
||||
|
||||
Reference in new issue
Block a user