Run integrity checks and return a list of (severity, message) tuples.
(db_path: str)
| 18 | |
| 19 | |
| 20 | def check(db_path: str) -> list[tuple[str, str]]: |
| 21 | """Run integrity checks and return a list of (severity, message) tuples.""" |
| 22 | conn = sqlite3.connect(db_path) |
| 23 | conn.row_factory = sqlite3.Row |
| 24 | |
| 25 | issues: list[tuple[str, str]] = [] |
| 26 | |
| 27 | # 1. Malformed source paths. |
| 28 | for row in conn.execute("SELECT source, name FROM parsed_manpages"): |
| 29 | try: |
| 30 | validate_source_path(row["source"]) |
| 31 | except errors.InvalidSourcePath: |
| 32 | issues.append( |
| 33 | ( |
| 34 | "error", |
| 35 | f"malformed source path: {row['source']!r} " |
| 36 | f"(manpage {row['name']!r})", |
| 37 | ) |
| 38 | ) |
| 39 | |
| 40 | # 2. Shadowed duplicates: same name+section+distro from different sources. |
| 41 | rows = conn.execute("SELECT source, name FROM parsed_manpages").fetchall() |
| 42 | seen: dict[tuple[str, str, str, str], str] = {} |
| 43 | for row in rows: |
| 44 | source = row["source"] |
| 45 | name = row["name"] |
| 46 | try: |
| 47 | distro, release = config.parse_distro_release(source) |
| 48 | except (IndexError, ValueError): |
| 49 | continue # already caught by malformed-source check |
| 50 | _, section = util.name_section(os.path.basename(source)[:-3]) |
| 51 | key = (name, section, distro, release) |
| 52 | if key in seen: |
| 53 | issues.append( |
| 54 | ( |
| 55 | "error", |
| 56 | f"shadowed duplicate: {name}({section}) in {distro}/{release} " |
| 57 | f"from both {seen[key]!r} and {source!r}", |
| 58 | ) |
| 59 | ) |
| 60 | else: |
| 61 | seen[key] = source |
| 62 | |
| 63 | # 3. Orphaned mappings: mapping rows referencing non-existent manpage sources. |
| 64 | orphans = conn.execute( |
| 65 | "SELECT m.src, m.dst FROM mappings m " |
| 66 | "LEFT JOIN parsed_manpages mp ON m.dst = mp.source WHERE mp.source IS NULL" |
| 67 | ).fetchall() |
| 68 | for row in orphans: |
| 69 | issues.append( |
| 70 | ( |
| 71 | "error", |
| 72 | f"orphaned mapping: src={row['src']!r} -> dst={row['dst']!r} " |
| 73 | f"(manpage does not exist)", |
| 74 | ) |
| 75 | ) |
| 76 | |
| 77 | # 4. positional set on flagged options. |
nothing calls this directly
no test coverage detected