Log in

Commit 3cd2661f

3cd2661fdbe9

Merged on mrmrs-d5ae98
mrmrs · 1 month ago · 3 files ~3 modified
M suites/scale/scalesuite/ops.py
@@ -332,7 +332,51 @@
332332 ctx.oracle(not paths, "clean_status_reports_no_paths", "subject_output", reported_paths=paths[:10])
333333
334334
335+def _dirty_branch_enter(ctx: Ctx) -> None:
336+ """The dirty cycle runs on a throwaway branch (untimed switch), so the base
337+ branch never accumulates harness commits: every run's switch/log/merge ops
338+ see the same repository state (no run-over-run drift)."""
339+ name = f"dirty-{ctx.tag}"
340+ if _is_git(ctx):
341+ ctx.git(["switch", "-q", "-c", name, "main"], ctx.work)
342+ else:
343+ ctx.untimed(["switch", "-c", name], ctx.work)
344+ ctx.state["dirty_branch"] = name
345+
346+
347+def _dirty_branch_leave(ctx: Ctx) -> None:
348+ name = ctx.state.pop("dirty_branch", None)
349+ if name is None:
350+ return
351+ if _is_git(ctx):
352+ ctx.git(["switch", "-q", "-f", "main"], ctx.work)
353+ ctx.git(["branch", "-q", "-D", name], ctx.work, check=False)
354+ else:
355+ ctx.untimed(["switch", _base_branch(ctx)], ctx.work)
356+
357+
358+def recover(ctx: Ctx) -> Optional[str]:
359+ """Untimed repair after a failed unit: discard worktree changes, return to base."""
360+ try:
361+ ctx.state.pop("dirty", None)
362+ ctx.state.pop("dirty_branch", None)
363+ if _is_git(ctx):
364+ ctx.git(["merge", "--abort"], ctx.work, check=False)
365+ ctx.git(["reset", "-q", "--hard"], ctx.work, check=False)
366+ ctx.git(["clean", "-fdq", "-e", "build/"], ctx.work, check=False)
367+ ctx.git(["switch", "-q", "-f", "main"], ctx.work)
368+ else:
369+ ctx.untimed(["reset", "-f"], ctx.work, check=False)
370+ for extra in ("added", "renamed"):
371+ shutil.rmtree(ctx.work / extra, ignore_errors=True)
372+ ctx.untimed(["switch", _base_branch(ctx)], ctx.work)
373+ return None
374+ except Exception as exc: # noqa: BLE001 - reported on the row, never hidden
375+ return f"{type(exc).__name__}: {str(exc)[-300:]}"
376+
377+
335378 def op_status_dirty(ctx: Ctx) -> None:
379+ _dirty_branch_enter(ctx)
336380 dirty = apply_dirty(ctx)
337381 ctx.outcome.extra["dirty_applied"] = dirty["applied"]
338382 args = ["status", "--porcelain=v1"] if _is_git(ctx) else ["status", "--porcelain"]
@@ -377,9 +421,6 @@
377421 ctx.timed(["commit", "-q", "--no-verify", "-m", f"dirty {ctx.tag}"], ctx.work, label="commit")
378422 else:
379423 ctx.timed(["commit", "--json"], ctx.work)
380- ctx.state["harness_commits"] += 1
381- ctx.state["deleted"].update(dirty["deleted"])
382- ctx.state["deleted"].update(old for old, _ in dirty["renamed"])
383424 probe = dirty["modified"][0] if dirty["modified"] else None
384425 status_args = ["status", "--porcelain=v1"] if _is_git(ctx) else ["status", "--porcelain"]
385426 left = porcelain_paths(ctx.untimed(status_args, ctx.work).stdout.decode(errors="replace"))
@@ -398,6 +439,7 @@
398439 committed_ok = got == want
399440 ctx.oracle(not left and committed_ok, "tree_clean_and_modified_bytes_committed", reader,
400441 left_after_commit=left[:10], committed_bytes_match=committed_ok)
442+ _dirty_branch_leave(ctx)
401443
402444
403445 def _log_count(text: str) -> int: