"""Checks that keep the published repository honest: the README names only real commands, and no file carries a home path or a personal email address.""" import os, re, subprocess, sys, unittest from support import REPO, SisiCase def _tracked_or_untracked_files(): """Every file that would be published: tracked files plus untracked ones that .gitignore does not hide. Falls back to a directory walk when git is unavailable.""" try: r = subprocess.run(["git", "ls-files", "--cached", "--others", "--exclude-standard"], cwd=REPO, capture_output=True, text=True, timeout=30) if r.returncode == 0 and r.stdout.strip(): return [f for f in r.stdout.splitlines() if os.path.isfile(os.path.join(REPO, f))] except (OSError, subprocess.SubprocessError): pass out = [] for dp, dns, fns in os.walk(REPO): dns[:] = [d for d in dns if d not in (".git", "__pycache__")] out += [os.path.relpath(os.path.join(dp, n), REPO) for n in fns if not n.endswith(".pyc")] return out def _text(rel): try: with open(os.path.join(REPO, rel), "rb") as f: data = f.read() except OSError: return None if b"\0" in data: return None return data.decode("utf-8", "replace") # Paths under /home/ or /Users/ that are placeholders in tests and examples, not real people. _ALLOWED_HOME_USERS = {"alice", "bob", "user", "you", "name", "username", "example", "me"} HOME_RE = re.compile(r"(? %s" % (doc, target)) class NoStaleValues(unittest.TestCase): def test_readme_has_no_stale_values(self): text = open(os.path.join(REPO, "README.md"), encoding="utf-8").read() self.assertEqual(_stale_value_findings(text, "README.md"), [], "hardcoded values that will go stale in the README") def test_docs_have_no_stale_values(self): rels = ["CONTRIBUTING.md", "SECURITY.md"] # docs/target.md is the reconciliation build reference: its start date and "as today" # describe that project, not the product, so they do not go stale with the product. rels += [os.path.join("docs", n) for n in sorted(os.listdir(os.path.join(REPO, "docs"))) if n.endswith(".md") and n != "target.md"] findings = [] for rel in rels: findings += _stale_value_findings(_text(rel), rel, allow_version_evidence=True) self.assertEqual(findings, [], "hardcoded values that will go stale in the docs") def test_readme_word_count_stays_under_ceiling(self): words = len(open(os.path.join(REPO, "README.md"), encoding="utf-8").read().split()) self.assertLessEqual(words, README_WORD_CEILING, "README has %d words, ceiling %d; cut or raise it deliberately" % (words, README_WORD_CEILING)) def test_the_stale_scan_can_fail(self): bad = _stale_value_findings( "Version 0.1.0 had 140 verification techniques and 20 recipes in 2026; today it grows.", "sample") self.assertGreaterEqual(len(bad), 5, bad) self.assertTrue(_stale_value_findings("checked on Foo v1.2.3", "sample")) allowed = "Python 3.9 or newer; rung 1, rung 2, rung 3, rung 4, rung 5, rung 6." self.assertEqual(_stale_value_findings(allowed, "sample"), []) evidence = "no delivery could be confirmed on Foo v1.2.3 in headless runs" self.assertEqual(_stale_value_findings(evidence, "sample", allow_version_evidence=True), []) if __name__ == "__main__": unittest.main() class BrandIsWrittenCorrectly(unittest.TestCase): """The brand is 'sisi is still improving', always lower case; the old expansion is retired.""" def tracked(self): out = subprocess.run(["git", "ls-files"], cwd=REPO, capture_output=True, text=True).stdout for name in out.split("\n"): path = os.path.join(REPO, name) if not name or not os.path.isfile(path): continue try: yield name, open(path, encoding="utf-8").read() except UnicodeDecodeError: continue def test_old_expansion_is_gone_outside_the_changelog(self): old = re.compile("self[- ]improving\\s+super" + "intelligence", re.I) bad = [n for n, text in self.tracked() if n != "CHANGELOG.md" and old.search(text)] self.assertEqual(bad, []) def test_brand_line_is_always_lower_case(self): brand = re.compile(r"\*{0,2}sisi\*{0,2}\s+is\s+still\s+improving", re.I) bad = [] for name, text in self.tracked(): for m in brand.finditer(text): if m.group(0) != m.group(0).lower(): bad.append((name, m.group(0))) self.assertEqual(bad, []) def test_readme_title_is_the_brand(self): first = open(os.path.join(REPO, "README.md"), encoding="utf-8").readline().rstrip("\n") self.assertEqual(first, "# **sisi** is still improving")