Let resumed SVG drafts precede a new final-state fingerprint
This commit is contained in:
1 parent
1a2379a6c2
commit
58b0f16998
9 files changed
+519
-84
No files matched your search
@@ -2824,6 +2824,127 @@ fn checkpoint_keeps_late_special_tokens_until_the_updated_page_is_shipped() {
|
||||
fs::remove_dir_all(p).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preview_before_state_fingerprint_keeps_exact_execution_evidence() {
|
||||
#[derive(Clone, Copy)]
|
||||
enum Action {
|
||||
Supersede,
|
||||
Reject,
|
||||
Publish,
|
||||
}
|
||||
|
||||
struct ObserveDraft {
|
||||
compiler: NativeCompiler,
|
||||
initial: Arc<CompiledDocument>,
|
||||
action: Action,
|
||||
update: Mutex<Option<PreviewUpdate>>,
|
||||
}
|
||||
|
||||
impl CompileObserver for ObserveDraft {
|
||||
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> {
|
||||
assert!(draft.state_fingerprint_pending());
|
||||
assert!(draft.entry_checkpoint_work().reused_steps > 0);
|
||||
assert!(Arc::ptr_eq(&self.initial, &self.compiler.latest().unwrap()));
|
||||
let update = draft.preview_since(Some(self.initial.revision()))?;
|
||||
assert_eq!(update.pages.iter().map(|p| p.index).collect::<Vec<_>>(), [1]);
|
||||
assert!(self.update.lock().unwrap().replace(update).is_none());
|
||||
match self.action {
|
||||
Action::Supersede => {
|
||||
self.compiler.start();
|
||||
Ok(())
|
||||
}
|
||||
Action::Reject => Err("reject resumed SVG draft".into()),
|
||||
Action::Publish => Ok(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let root = directory("preview-before-state-fingerprint");
|
||||
let entry = root.join("main.tex");
|
||||
let padding = "\\relax\n".repeat(64);
|
||||
let body = format!(
|
||||
r"
|
||||
\shipout\hbox{{Stable first page}}
|
||||
{padding}
|
||||
\global\count73=17
|
||||
\immediate\openout1=state.dat
|
||||
\immediate\write1{{\the\count73}}
|
||||
\immediate\closeout1
|
||||
\shipout\hbox{{Final value \the\count73}}
|
||||
\end
|
||||
"
|
||||
);
|
||||
let mut definition = atomic_definition(&root, 1, &body);
|
||||
definition.generated.insert(root.join("state.dat"));
|
||||
let project = ProjectSnapshot::new(definition).unwrap();
|
||||
let job = request(&root).observe_generated_initial();
|
||||
let compiler = NativeCompiler::default().with_automatic_entry_checkpoints();
|
||||
let initial = compiler.compile(job.clone().with_project(project.clone())).unwrap();
|
||||
let names = ["job.pdf", "job.log", "state.dat"];
|
||||
let initial_files = names.map(|name| fs::read(root.join(name)).unwrap());
|
||||
|
||||
for (value, action) in [(23, Action::Supersede), (29, Action::Reject), (31, Action::Publish)] {
|
||||
let edited = format!("{HEADER}{}", body.replace("count73=17", &format!("count73={value}")));
|
||||
let project = project.with_file_edits(
|
||||
u64::try_from(value).unwrap(),
|
||||
[(entry.clone(), Arc::from(edited.into_bytes()))].into(),
|
||||
).unwrap();
|
||||
let compile = job.clone().with_project(project);
|
||||
let observer = Arc::new(ObserveDraft {
|
||||
compiler: compiler.clone(),
|
||||
initial: initial.clone(),
|
||||
action,
|
||||
update: Mutex::new(None),
|
||||
});
|
||||
let mut observed = compile.clone();
|
||||
observed.observer = Some(observer.clone());
|
||||
let result = compiler.compile_detailed(observed);
|
||||
let draft = observer.update.lock().unwrap().take().unwrap();
|
||||
match action {
|
||||
Action::Supersede | Action::Reject => {
|
||||
let failure = result.err().unwrap();
|
||||
assert_eq!(failure.phase, AttemptPhase::Export);
|
||||
match action {
|
||||
Action::Supersede => assert!(matches!(failure.error, CompileError::Cancelled)),
|
||||
Action::Reject => assert!(failure.error.to_string().contains("reject resumed SVG draft")),
|
||||
Action::Publish => unreachable!(),
|
||||
}
|
||||
let completed = failure.completed_execution.unwrap();
|
||||
assert_eq!(completed.execution.outgoing_state, completed.execution.state.fingerprint());
|
||||
assert_eq!(completed.execution.state.count(73), value);
|
||||
assert!(Arc::ptr_eq(&initial, &compiler.latest().unwrap()));
|
||||
assert_eq!(names.map(|name| fs::read(root.join(name)).unwrap()), initial_files);
|
||||
}
|
||||
Action::Publish => {
|
||||
let published = result.unwrap();
|
||||
let full = NativeCompiler::default().compile(compile).unwrap();
|
||||
assert!(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.pdf, full.pdf);
|
||||
assert_eq!(published.source_map.sources, full.source_map.sources);
|
||||
assert_eq!(published.source_map.pages, full.source_map.pages);
|
||||
let preview = published.preview_since(Some(initial.revision())).unwrap();
|
||||
assert_eq!(draft.pages, preview.pages);
|
||||
assert_eq!(fs::read(root.join("state.dat")).unwrap(), b"31\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn provisional_preview_matches_published_pages_and_cancellation_keeps_artifacts() {
|
||||
#[derive(Clone, Copy)]
|
||||
|
||||
Reference in new issue
Block a user