Open units whose contract predates the unit record get an age from the contract file's mtime, labelled inferred in status and record. done / next: repeat runs and report

This commit is contained in:
swaits committed 2026-11-23 13:06:27 -07:00
1 parent 8100295f98
commit f510cc08de
3 files changed
+67 -10

No files matched your search

+9 -3
View File
@@ -369,7 +369,9 @@ def open_units(cwd=None):
if not isinstance(c, dict) or not c.get("id") or c.get("status") == "closed" or C.is_unedited_skeleton(c): if not isinstance(c, dict) or not c.get("id") or c.get("status") == "closed" or C.is_unedited_skeleton(c):
return out return out
project = C.project_dir(p) project = C.project_dir(p)
row = {"id": c["id"], "status": c.get("status", "open"), "age": _age(c.get("started")), "goal": c.get("goal") or ""} started, basis = U.start_of(c, p)
row = {"id": c["id"], "status": c.get("status", "open"), "age": _age(started), "goal": c.get("goal") or "",
"age_basis": basis}
if row["status"] == "paused": if row["status"] == "paused":
pz = next((x for x in reversed(c.get("pauses") or []) if isinstance(x, dict) and not x.get("until")), {}) pz = next((x for x in reversed(c.get("pauses") or []) if isinstance(x, dict) and not x.get("until")), {})
row["waiting_for"], row["paused_for"] = pz.get("what"), _age(pz.get("since")) row["waiting_for"], row["paused_for"] = pz.get("what"), _age(pz.get("since"))
@@ -394,13 +396,17 @@ def _lowered_note(u):
(": " + str(rk["why"])) if rk.get("why") else "") (": " + str(rk["why"])) if rk.get("why") else "")
def _basis_note(r):
return " (inferred from the contract file)" if r.get("age_basis") == "inferred" else ""
def format_open(rows): def format_open(rows):
lines = [] lines = []
for r in rows: for r in rows:
if r["status"] == "paused": if r["status"] == "paused":
lines.append("paused %-24s age %s waiting for: %s (for %s)" % (r["id"], r["age"], r.get("waiting_for") or "?", r.get("paused_for"))) lines.append("paused %-24s age %s%s waiting for: %s (for %s)" % (r["id"], r["age"], _basis_note(r), r.get("waiting_for") or "?", r.get("paused_for")))
else: else:
lines.append("open %-24s age %s %s" % (r["id"], r["age"], r["goal"][:80])) lines.append("open %-24s age %s%s %s" % (r["id"], r["age"], _basis_note(r), r["goal"][:80]))
if r.get("lowered"): if r.get("lowered"):
lines.append(" lowered: " + r["lowered"]) lines.append(" lowered: " + r["lowered"])
if r.get("unverified"): if r.get("unverified"):
+24 -7
View File
@@ -219,11 +219,26 @@ def _transcript_stats(project, t0, t1):
return agg return agg
def build_telemetry(c, project, results, t0, t1): def start_of(c, contract_path=None):
"""(ISO UTC start, basis). A unit records `started` itself ("measured"). A contract written before the
unit record existed has none: the contract file's modification time stands in for it, and the basis
says "inferred" so nothing downstream reads it as measured. (None, None) when neither is known."""
if isinstance(c.get("started"), str) and c["started"]:
return c["started"], "measured"
try:
mt = os.stat(contract_path).st_mtime if contract_path else None
except OSError:
mt = None
if mt is None:
return None, None
return time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(mt)) + "Z", "inferred"
def build_telemetry(c, project, results, t0, t1, t0_basis="measured"):
"""Every value classed. Sources: deliveries, results, pauses on the contract, the """Every value classed. Sources: deliveries, results, pauses on the contract, the
host transcript where a session record names one, git, and the delegation ledger.""" host transcript where a session record names one, git, and the delegation ledger."""
tel = {} tel = {}
tel["time_to_validated_completion_s"] = val(round(t1 - t0, 1), "measured") if t0 is not None else unavailable() tel["time_to_validated_completion_s"] = val(round(t1 - t0, 1), t0_basis) if t0 is not None else unavailable()
if results: if results:
tel["time_in_checks_s"] = val(round(sum(float(r["duration_s"]) for r in results tel["time_in_checks_s"] = val(round(sum(float(r["duration_s"]) for r in results
if isinstance(r.get("duration_s"), (int, float))), 3), "measured") if isinstance(r.get("duration_s"), (int, float))), 3), "measured")
@@ -456,10 +471,11 @@ def decide_status(c, rows, abandon=None):
return "delivered", block, unrun return "delivered", block, unrun
def build_record(c, project, delivery_status, ended_epoch, abandon_reason=None, rows=None): def build_record(c, project, delivery_status, ended_epoch, abandon_reason=None, rows=None, contract_path=None):
t0 = harvest.epoch(c["started"]) if isinstance(c.get("started"), str) else None started, basis = start_of(c, contract_path)
t0 = harvest.epoch(started) if isinstance(started, str) else None
rows = _unit_results(c, project, c.get("started")) if rows is None else rows rows = _unit_results(c, project, c.get("started")) if rows is None else rows
tel = build_telemetry(c, project, rows, t0, ended_epoch) tel = build_telemetry(c, project, rows, t0, ended_epoch, basis or "measured")
models = tel.pop("_models") models = tel.pop("_models")
delegation_rows = tel.pop("_delegation_rows") delegation_rows = tel.pop("_delegation_rows")
changed = tel.pop("_changed") changed = tel.pop("_changed")
@@ -488,7 +504,7 @@ def build_record(c, project, delivery_status, ended_epoch, abandon_reason=None,
"plan": c.get("plan") or [], "plan": c.get("plan") or [],
"workers": delegation_rows, "workers": delegation_rows,
"models": models, "budgets": c.get("budgets"), "models": models, "budgets": c.get("budgets"),
"started": c.get("started"), "ended": ended, "closed_at": ended, "telemetry": tel, "started": started, "started_basis": basis, "ended": ended, "closed_at": ended, "telemetry": tel,
"start_commit": c.get("base_head"), "start_commit": c.get("base_head"),
"closing_commit": gitutil.head(project) if gitutil.root(project) else None, "closing_commit": gitutil.head(project) if gitutil.root(project) else None,
"summary": c.get("summary"), "summary": c.get("summary"),
@@ -603,7 +619,8 @@ def close_unit(c, contract_path, project, abandon=None, now=None):
return None, ("sisi: unit %s cannot close as delivered: %s. Fix and re-run `sisi verify`, " return None, ("sisi: unit %s cannot close as delivered: %s. Fix and re-run `sisi verify`, "
"record a deviation with `sisi contract waive \"<reason>\"`, or close it with " "record a deviation with `sisi contract waive \"<reason>\"`, or close it with "
"`sisi unit close --abandon \"<reason>\"`." % (c["id"], bad)), False "`sisi unit close --abandon \"<reason>\"`." % (c["id"], bad)), False
rec = build_record(c, project, status, ended_epoch, abandon_reason=abandon, rows=rows) rec = build_record(c, project, status, ended_epoch, abandon_reason=abandon, rows=rows,
contract_path=contract_path)
_, created = archive_record(rec, project) _, created = archive_record(rec, project)
if created: if created:
_capture_case(rec) _capture_case(rec)
+34
View File
@@ -41,6 +41,40 @@ class UnitCase(SisiCase):
subprocess.run(["git", "-c", "user.name=t", "-c", "user.email=t@t", "commit", "-qm", msg], cwd=self.proj, check=True) subprocess.run(["git", "-c", "user.name=t", "-c", "user.email=t@t", "commit", "-qm", msg], cwd=self.proj, check=True)
class OldContractAgeTests(UnitCase):
def old_contract(self, hours=3):
c = self.start()
c.pop("started", None)
C.save(self.contract_path, c)
t = time.time() - hours * 3600
os.utime(self.contract_path, (t, t))
def test_status_gives_an_age_to_a_contract_written_before_the_unit_record_existed(self):
"""The contract file's modification time stands in for the start, and says it is inferred."""
self.old_contract(3)
r = self.sisi("status")
line = next(l for l in r.stdout.splitlines() if l.strip().startswith("open"))
self.assertNotIn("age ?", line)
self.assertIn("age 3h", line)
self.assertIn("inferred", line)
def test_a_measured_start_is_not_labelled_inferred(self):
self.start()
line = next(l for l in self.sisi("status").stdout.splitlines() if l.strip().startswith("open"))
self.assertNotIn("inferred", line)
self.assertNotIn("age ?", line)
def test_the_record_of_such_a_unit_says_inferred_never_measured(self):
self.old_contract(2)
self.finish_green()
self.assertEqual(self.sisi("unit", "close").returncode, 0)
rec = self.archive("proj")
self.assertEqual(rec["started_basis"], "inferred")
t = rec["telemetry"]["time_to_validated_completion_s"]
self.assertEqual(t.get("class") or t.get("basis") or t.get("kind"), "inferred", t)
self.assertGreaterEqual(t["value"], 2 * 3600 - 120)
class RecordTests(UnitCase): class RecordTests(UnitCase):
def test_close_archives_all_fourteen_items(self): def test_close_archives_all_fourteen_items(self):
"""R-10.2-1, R-10.2-2, R-10.2-3, R-10.2-4, R-10.2-5, R-10.2-6, R-10.2-7, R-10.2-8, R-10.2-9, """R-10.2-1, R-10.2-2, R-10.2-3, R-10.2-4, R-10.2-5, R-10.2-6, R-10.2-7, R-10.2-8, R-10.2-9,