Skip to content

Commit d99d699

Browse files
committed
.interaction file is based on output_validator
1 parent 1f528b7 commit d99d699

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

bin/generate.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def run(self, bar, cwd):
217217
bar.log("stderr", result.err)
218218
return result
219219

220-
def run_interaction(self, bar, cwd, t):
220+
def generate_interaction(self, bar, cwd, t):
221221
in_path = cwd / "testcase.in"
222222
interaction_path = cwd / "testcase.interaction"
223223
interaction_path.unlink(missing_ok=True)
@@ -787,6 +787,7 @@ def init_meta():
787787
"generated_extensions": [],
788788
"input_validator_hashes": dict(),
789789
"solution_hash": dict(),
790+
"interactor_hash": dict(),
790791
"ans_out_validator_hashes": dict(),
791792
"visualizer_hash": dict(),
792793
}
@@ -924,7 +925,7 @@ def generate_from_rule():
924925
assert t._has_required_in(infile), f"Failed to generate in file: {infile.name}"
925926
return True
926927

927-
def generate_from_solution(testcase: Testcase):
928+
def generate_from_solution(testcase: Testcase, bar: ProgressBar):
928929
nonlocal meta_yaml
929930

930931
if testcase.root in [*config.INVALID_CASE_DIRECTORIES, "valid_output"]:
@@ -943,11 +944,16 @@ def generate_from_solution(testcase: Testcase):
943944
"solution": None,
944945
}
945946

946-
def needed(ext):
947+
def needed(ext, interactor_hash=None):
947948
if ext in meta_yaml["generated_extensions"]:
948949
return False
949950
if not infile.with_suffix(ext).is_file():
950951
return True
952+
if (
953+
interactor_hash is not None
954+
and meta_yaml.get("interactor_hash") != interactor_hash
955+
):
956+
return True
951957
return meta_yaml.get("solution_hash") != solution_hash
952958

953959
used_solution = False
@@ -959,19 +965,21 @@ def needed(ext):
959965
ansfile.write_text("")
960966
changed_ans = True
961967
# For interactive/multi-pass problems, run the solution and generate a .interaction if necessary.
962-
if (
963-
(problem.interactive or problem.multi_pass)
964-
and t.config.solution
965-
and (testcase.root == "sample" or config.args.interaction)
966-
and needed(".interaction")
967-
and not any(
968-
infile.with_suffix(ext).is_file()
969-
for ext in [".out", ".in.statement", ".ans.statement"]
970-
)
971-
):
972-
if not t.config.solution.run_interaction(bar, cwd, t):
973-
return False
974-
used_solution = True
968+
if problem.interactive or problem.multi_pass:
969+
interactor_hash = testcase.validator_hashes(validate.OutputValidator, bar)
970+
if (
971+
t.config.solution
972+
and (testcase.root == "sample" or config.args.interaction)
973+
and needed(".interaction", interactor_hash)
974+
and not any(
975+
infile.with_suffix(ext).is_file()
976+
for ext in [".out", ".in.statement", ".ans.statement"]
977+
)
978+
):
979+
if not t.config.solution.generate_interaction(bar, cwd, t):
980+
return False
981+
used_solution = True
982+
meta_yaml["interactor_hash"] = interactor_hash
975983
else:
976984
# Generate a .ans if not already generated by earlier steps.
977985
if needed(".ans"):
@@ -1212,7 +1220,7 @@ def add_testdata_to_cache():
12121220
return
12131221

12141222
# Step 4: generate .ans and .interaction if needed
1215-
if not generate_from_solution(testcase):
1223+
if not generate_from_solution(testcase, bar):
12161224
return
12171225

12181226
# Step 5: validate .ans (and .out if it exists)

0 commit comments

Comments
 (0)