"""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"] rels += [os.path.join("docs", n) for n in sorted(os.listdir(os.path.join(REPO, "docs"))) if n.endswith(".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()