tenseleyflow/loader / 56f1959

Browse files

Add HTML starter cues

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
56f1959d2bc7868fd07044ce7a0e9d1e59a3f209
Parents
624edfe
Tree
a5d38fd

2 changed files

StatusFile+-
M src/loader/runtime/repair.py 54 0
M tests/test_repair.py 6 0
src/loader/runtime/repair.pymodified
@@ -442,6 +442,13 @@ class ResponseRepairer:
442442
         )
443443
         if reference_cues_line:
444444
             lines.append(reference_cues_line)
445
+        html_starter_line = self._known_html_starter_shape_line(
446
+            concrete_target,
447
+            require_first_substantive_output=True,
448
+            retry_number=retry_number,
449
+        )
450
+        if html_starter_line:
451
+            lines.append(html_starter_line)
445452
         if _should_encourage_initial_version(
446453
             target=concrete_target,
447454
             has_confirmed_output_file_progress=True,
@@ -924,6 +931,16 @@ class ResponseRepairer:
924931
             )
925932
             if reference_cues_line:
926933
                 lines.append(reference_cues_line)
934
+            html_starter_line = self._known_html_starter_shape_line(
935
+                concrete_target,
936
+                require_first_substantive_output=(
937
+                    has_confirmed_output_file_progress
938
+                    and not has_confirmed_substantive_output_file_progress
939
+                ),
940
+                retry_number=retry_number,
941
+            )
942
+            if html_starter_line:
943
+                lines.append(html_starter_line)
927944
             if _should_encourage_initial_version(
928945
                 target=concrete_target,
929946
                 has_confirmed_output_file_progress=has_confirmed_output_file_progress,
@@ -1008,6 +1025,16 @@ class ResponseRepairer:
10081025
             )
10091026
             if reference_cues_line:
10101027
                 lines.append(reference_cues_line)
1028
+            html_starter_line = self._known_html_starter_shape_line(
1029
+                inferred_pending_target,
1030
+                require_first_substantive_output=(
1031
+                    has_confirmed_output_file_progress
1032
+                    and not has_confirmed_substantive_output_file_progress
1033
+                ),
1034
+                retry_number=retry_number,
1035
+            )
1036
+            if html_starter_line:
1037
+                lines.append(html_starter_line)
10111038
             if todo_describes_aggregate_mutation(next_pending):
10121039
                 lines.insert(
10131040
                     1,
@@ -1127,6 +1154,16 @@ class ResponseRepairer:
11271154
                     )
11281155
                     if reference_cues_line:
11291156
                         lines.append(reference_cues_line)
1157
+                    html_starter_line = self._known_html_starter_shape_line(
1158
+                        next_output_file,
1159
+                        require_first_substantive_output=(
1160
+                            has_confirmed_output_file_progress
1161
+                            and not has_confirmed_substantive_output_file_progress
1162
+                        ),
1163
+                        retry_number=retry_number,
1164
+                    )
1165
+                    if html_starter_line:
1166
+                        lines.append(html_starter_line)
11301167
                     if _should_encourage_initial_version(
11311168
                         target=next_output_file,
11321169
                         has_confirmed_output_file_progress=has_confirmed_output_file_progress,
@@ -1442,6 +1479,23 @@ class ResponseRepairer:
14421479
             return None
14431480
         return f"Reference cues from `{display_runtime_path(reference)}`: {cues}"
14441481
 
1482
+    def _known_html_starter_shape_line(
1483
+        self,
1484
+        target: Path,
1485
+        *,
1486
+        require_first_substantive_output: bool,
1487
+        retry_number: int,
1488
+    ) -> str | None:
1489
+        if not require_first_substantive_output or retry_number < 2:
1490
+            return None
1491
+        if target.suffix.lower() not in {".html", ".htm"}:
1492
+            return None
1493
+        return (
1494
+            "For this first HTML content file, a minimal acceptable starter is: "
1495
+            "matching `<title>` and `<h1>`, one introductory paragraph, a few section "
1496
+            "blocks, and a back link to `../index.html`."
1497
+        )
1498
+
14451499
     def _best_known_reference_path(self, target: Path) -> Path | None:
14461500
         normalized_target = target.expanduser().resolve(strict=False)
14471501
         target_tokens = {
tests/test_repair.pymodified
@@ -1336,6 +1336,12 @@ def test_compact_first_substantive_retry_reuses_known_reference_structure(
13361336
         "<h1>Chapter 1: Introduction to Fortran</h1>"
13371337
         in decision.retry_message
13381338
     )
1339
+    assert (
1340
+        "For this first HTML content file, a minimal acceptable starter is: "
1341
+        "matching `<title>` and `<h1>`, one introductory paragraph, a few section "
1342
+        "blocks, and a back link to `../index.html`."
1343
+        in decision.retry_message
1344
+    )
13391345
 
13401346
 
13411347
 def test_empty_response_retry_prefers_output_index_over_reference_index_with_same_name(