Retry earlier checkpoints after host replay changes

This commit is contained in:
gloamxun committed 2026-11-28 13:17:46 +08:00
1 parent d4e78bc29a
commit 09cd19594c
3 files changed
+247 -61

No files matched your search

+139
View File
@@ -2226,6 +2226,145 @@ fn relocated_format_checks_current_sources_and_consumed_stream_ranges() {
fs::remove_dir_all(root).unwrap();
}
#[test]
fn replay_rejection_resumes_earlier_without_publishing_rejected_effects() {
struct PublishedBeforeExecution(Vec<(PathBuf, Vec<u8>)>);
impl CompileObserver for PublishedBeforeExecution {
fn stage(&self, _: u64, stage: CompileStage) -> Result<(), String> {
if stage == CompileStage::Prepared {
for (path, previous) in &self.0 {
assert_eq!(&fs::read(path).unwrap(), previous, "{}", path.display());
}
}
Ok(())
}
}
let cwd = directory("retry-entry-replay").canonicalize().unwrap();
let vendor = cwd.join("vendor");
let aux = cwd.join("main.aux");
let log = cwd.join("job.log");
let pdf = cwd.join("job.pdf");
let aux_bytes = b"BEGIN\nEND\n";
fs::write(&aux, aux_bytes).unwrap();
let padding = "\\advance\\count0 by 1\\relax\n".repeat(32);
let source = format!(
r"\catcode123=1 \catcode125=2
\def\widthfrominput{{10}}
{padding}\immediate\openout1=main.aux
\immediate\write1{{BEGIN}}
{padding}\openin3=settings.tex
\ifeof3\else\input settings.tex \fi\closein3
\edef\sizeoftag{{\pdffilesize{{tag.tex}}}}
{padding}{padding}\shipout\hbox{{\vrule width\widthfrominput pt height1pt}}
\immediate\write1{{END}}
\immediate\closeout1
\end"
);
let optional_lookup = source.find("\\openin3=").unwrap();
let size_lookup = source.find("\\edef\\sizeoftag").unwrap();
let mut world = WorldConfig::new(&cwd);
world.input_policy = texrra_tex_core::resources::InputPolicy::Tex;
world.paths.insert(
ResourceKind::Tex,
vec![
SearchPath::directory(&cwd, false),
SearchPath::directory(&vendor, false),
],
);
let mut project = ProjectSnapshot::new(ProjectDefinition {
configuration: world.clone(),
revision: 1,
roots: [cwd.clone()].into(),
files: [
(cwd.join("main.tex"), source.into_bytes().into()),
(vendor.clone().join("tag.tex"), Arc::from(b"42".as_slice())),
]
.into(),
directories: [vendor].into(),
aliases: Default::default(),
generated_roots: [cwd.clone()].into(),
generated: [aux.clone()].into(),
})
.unwrap();
let job_time = JobTime::new(2026, 11, 28, 0)
.unwrap()
.with_pdf_clock(0, 0)
.unwrap();
let mut job = CompileRequest::new(world, "main.tex", "job.pdf", job_time);
job.entry = Entry::Initex;
let session = NativeCompiler::default().with_automatic_entry_checkpoints();
let mut previous = session
.compile(job.clone().with_project(project.clone()))
.unwrap();
for (revision, name, bytes, lookup_offset) in [
(
2,
"settings.tex",
br"\def\widthfrominput{20}".as_slice(),
optional_lookup,
),
(3, "tag.tex", b"59".as_slice(), size_lookup),
] {
assert!(previous.entry_checkpoint_work.captured_frontier.unwrap() > size_lookup);
let new_path = cwd.join(name);
project = project
.with_file_changes(revision, [(new_path.clone(), Some(bytes.into()))].into())
.unwrap();
let next = job.clone().with_project(project.clone());
let mut observed = next.clone();
observed.observer = Some(Arc::new(PublishedBeforeExecution(
[&aux, &log, &pdf]
.into_iter()
.map(|path| (path.clone(), fs::read(path).unwrap()))
.collect(),
)));
let result = session.compile(observed).unwrap();
let work = &result.entry_checkpoint_work;
assert!(work.reused_steps > 0, "{work:?}");
assert!(work.reused_frontier.unwrap() <= lookup_offset, "{work:?}");
assert_eq!(fs::read(&aux).unwrap(), aux_bytes);
let replayed_log = fs::read(&log).unwrap();
let full = NativeCompiler::default().compile(next).unwrap();
assert_eq!(result.pdf, full.pdf);
assert_eq!(result.pages, full.pages);
assert_eq!(result.source_map.pages, full.source_map.pages);
assert_eq!(result.source_map.sources, full.source_map.sources);
assert_eq!(
result.preview_since(None).unwrap().pages,
full.preview_since(None).unwrap().pages
);
assert_eq!(result.resources.trace.lookups, full.resources.trace.lookups);
assert!(
result
.resources
.trace
.lookups
.iter()
.any(|lookup| lookup.resolved.as_deref() == Some(new_path.as_path()))
);
let journal = result.resources.stream_io.events();
assert_eq!(
journal
.iter()
.filter(|event| matches!(&event.effect, StreamEffect::Write { stream: 1, .. }))
.count(),
2
);
assert_eq!(fs::read(&aux).unwrap(), aux_bytes);
assert_eq!(fs::read(&log).unwrap(), replayed_log);
if revision == 2 {
assert_ne!(result.pdf, previous.pdf);
} else {
assert_eq!(result.pdf, previous.pdf);
}
eprintln!("{name}: {work:?}");
previous = result;
}
fs::remove_dir_all(cwd).unwrap();
}
#[test]
fn relocated_format_binds_packed_and_new_glyphs_to_the_current_tfm() {
use texrra_tex_core::render::DisplayItem;