Translate logical step counts when replaying native suffixes
This commit is contained in:
1 parent
9a6c162b46
commit
465a574124
8 files changed
+337
-86
No files matched your search
@@ -1761,6 +1761,102 @@ fn settled_suffix_carries_a_verified_prefix_into_later_edits() {
|
||||
fs::remove_dir_all(cwd).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn settled_suffix_translates_step_counts_and_enforces_the_limit() {
|
||||
let cwd = directory("settled-step-counts");
|
||||
let entry = cwd.join("main.tex");
|
||||
let body = |command| {
|
||||
format!(
|
||||
r"
|
||||
\tracingstats=2
|
||||
\def\unitA{{\relax}}\def\unitB{{\relax\relax}}
|
||||
\unitA\unitB
|
||||
\shipout\hbox{{Cover}}\relax
|
||||
{command}
|
||||
\shipout\hbox{{Second}}\relax
|
||||
\shipout\hbox{{Third}}\relax
|
||||
\shipout\hbox{{Fourth}}\relax
|
||||
\end
|
||||
"
|
||||
)
|
||||
};
|
||||
let original = ProjectSnapshot::new(atomic_definition(&cwd, 1, &body(r"\unitA"))).unwrap();
|
||||
let mut request = request(&cwd).observe_generated_initial();
|
||||
request.world = original.configuration();
|
||||
let edited = original
|
||||
.with_file_edits(
|
||||
2,
|
||||
[(
|
||||
entry.clone(),
|
||||
Arc::from(format!("{HEADER}{}", body(r"\unitB")).into_bytes()),
|
||||
)]
|
||||
.into(),
|
||||
)
|
||||
.unwrap();
|
||||
let shorter = edited
|
||||
.with_file_edits(
|
||||
3,
|
||||
[(
|
||||
entry.clone(),
|
||||
Arc::from(format!("{HEADER}{}", body(r"\unitA")).into_bytes()),
|
||||
)]
|
||||
.into(),
|
||||
)
|
||||
.unwrap();
|
||||
let mut old_steps = 0;
|
||||
for (seed, project, increased) in [
|
||||
(original.clone(), edited.clone(), true),
|
||||
(edited.clone(), shorter, false),
|
||||
] {
|
||||
// Each direction starts with a single donor so the decreasing
|
||||
// edit cannot pick an earlier completion with the same count.
|
||||
let session = NativeCompiler::default().with_automatic_entry_checkpoints();
|
||||
let donor = session.compile(request.clone().with_project(seed)).unwrap();
|
||||
let donor_steps = donor.execution.execution.steps;
|
||||
let input = request.clone().with_project(project);
|
||||
let updated = session.compile(input.clone()).unwrap();
|
||||
assert!(
|
||||
updated.entry_checkpoint_work.reused_suffix_steps > 0,
|
||||
"{:?}",
|
||||
updated.entry_checkpoint_work
|
||||
);
|
||||
if increased {
|
||||
old_steps = donor_steps;
|
||||
assert!(updated.execution.execution.steps > old_steps);
|
||||
} else {
|
||||
assert!(updated.execution.execution.steps < donor_steps);
|
||||
assert_eq!(updated.execution.execution.steps, old_steps);
|
||||
}
|
||||
let log = fs::read(cwd.join("job.log")).unwrap();
|
||||
let full = NativeCompiler::default().compile(input).unwrap();
|
||||
assert_eq!(updated.execution.execution, full.execution.execution);
|
||||
assert_eq!(updated.pdf, full.pdf);
|
||||
assert_eq!(updated.source_map.pages, full.source_map.pages);
|
||||
assert_eq!(log, fs::read(cwd.join("job.log")).unwrap());
|
||||
}
|
||||
|
||||
request.limits.steps = old_steps;
|
||||
let limited = NativeCompiler::default().with_automatic_entry_checkpoints();
|
||||
let first = limited
|
||||
.compile(request.clone().with_project(original))
|
||||
.unwrap();
|
||||
let input = request.with_project(edited);
|
||||
let failure = limited.compile(input.clone()).err().unwrap().to_string();
|
||||
assert!(failure.contains("step limit exceeded"), "{failure}");
|
||||
assert_eq!(limited.latest().unwrap().revision(), first.revision());
|
||||
assert_eq!(
|
||||
fs::read(cwd.join("job.pdf")).unwrap().as_slice(),
|
||||
first.pdf.as_deref().unwrap()
|
||||
);
|
||||
let full = NativeCompiler::default()
|
||||
.compile(input)
|
||||
.err()
|
||||
.unwrap()
|
||||
.to_string();
|
||||
assert_eq!(failure, full);
|
||||
fs::remove_dir_all(cwd).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn settled_suffix_replays_with_the_edited_prefix_and_discards_a_rejected_draft() {
|
||||
let cwd = directory("settled-suffix");
|
||||
|
||||
Reference in new issue
Block a user