Skip to content

Commit fef2886

Browse files
Tie watcher recovery regression to the source edit
Log the source event path and its requested compile type once, then wait for the edited source to request full initialization and for an error after that event. Delayed config failures can no longer satisfy the recovery assertion before the edit is processed. Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
1 parent ff35b9a commit fef2886

2 files changed

Lines changed: 21 additions & 15 deletions

File tree

‎rewatch/src/watcher.rs‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -462,22 +462,20 @@ async fn async_watch(
462462
.filter(|path| matches_filter(path, filter));
463463
for path in paths {
464464
let path_buf = path.to_path_buf();
465+
let source_compile_type = compile_type_for_source_event(event.kind, initialization_failed);
466+
log::debug!(
467+
"received {:?} for {path:?} -> {source_compile_type:?} (pending: {needs_compile_type:?})",
468+
event.kind
469+
);
465470

466-
match (
467-
needs_compile_type,
468-
compile_type_for_source_event(event.kind, initialization_failed),
469-
) {
471+
match (needs_compile_type, source_compile_type) {
470472
(
471473
CompileType::Incremental | CompileType::None,
472474
// Structural changes and edits after failed initialization need a full scan.
473475
CompileType::Full,
474476
) => {
475477
// if we are going to do a full compile, we don't need to bother marking
476478
// files dirty because we do a full scan anyway
477-
log::debug!(
478-
"received {:?} while needs_compile_type was {needs_compile_type:?} -> full compile",
479-
event.kind
480-
);
481479
needs_compile_type = CompileType::Full;
482480
}
483481

@@ -488,10 +486,6 @@ async fn async_watch(
488486
) => {
489487
// if we are going to compile incrementally, we need to mark the exact files
490488
// dirty
491-
log::debug!(
492-
"received {:?} while needs_compile_type was {needs_compile_type:?} -> incremental compile",
493-
event.kind
494-
);
495489
if let Ok(canonicalized_path_buf) = path_buf
496490
.canonicalize()
497491
.map(StrippedVerbatimPath::to_stripped_verbatim_path)

‎rewatch/tests/watch/08-watch-recovers-from-invalid-config.sh‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,25 @@ stop_watcher() {
1111
fi
1212
}
1313

14+
wait_for_source_retry() {
15+
local marker='received Modify.*Test[.]res.* -> Full'
16+
wait_for_pattern rewatch.log "$marker" 30 || return 1
17+
# Require an initialization failure after the source event, not another config event before it.
18+
local preceding_errors
19+
preceding_errors=$(awk -v marker="$marker" '
20+
$0 ~ marker {exit}
21+
/Could not initialize build/ {count++}
22+
END {print count + 0}
23+
' rewatch.log)
24+
wait_for_pattern_count rewatch.log "Could not initialize build" "$((preceding_errors + 1))" 30
25+
}
26+
1427
if ! rewatch clean > /dev/null 2>&1; then
1528
error "Could not clean before watcher recovery test"
1629
exit 1
1730
fi
1831
cp rescript.json rescript.json.watch-recovery.bak
19-
rewatch_bg watch > rewatch.log 2>&1 &
32+
rewatch_bg -vv watch > rewatch.log 2>&1 &
2033

2134
if ! wait_for_file "./src/Test.mjs" 20 || ! wait_for_file "lib/watch.lock" 20; then
2235
error "Initial watch build did not complete"
@@ -47,9 +60,8 @@ if ! wait_for_pattern rewatch.log "Could not initialize build" 30; then
4760
fi
4861

4962
# A content-only edit must retry initialization instead of compiling with the old config.
50-
initial_errors=$(grep -c "Could not initialize build" rewatch.log 2> /dev/null || true)
5163
echo 'let watchRecoveryMarker = "watch-recovery-marker"' >> src/Test.res
52-
if ! wait_for_pattern_count rewatch.log "Could not initialize build" "$((initial_errors + 1))" 30; then
64+
if ! wait_for_source_retry; then
5365
error "Source edit did not retry failed initialization"
5466
cat rewatch.log
5567
stop_watcher

0 commit comments

Comments
 (0)