From ab55e5d88d0e1c1f449ab60a63974c74a67a55c6 Mon Sep 17 00:00:00 2001 From: Marius S <39998+winding-lines@users.noreply.github.com> Date: Sun, 29 Nov 2026 21:15:20 -0800 Subject: [PATCH 1/3] Leave incidental Mojo repos out of the rankings by default A repo is incidental Mojo when it entered the census only through a pushed commit that changed a .mojo file (found_by's check is `push` and GitHub's search didn't give it) and its last commit has fewer than 50 lines of Mojo (INCIDENTAL_LINES in src/incidental.mojo). The Repos table, the Overview's numbers and top tables and MCP list_repos leave them out unless asked (?incidental=1, incidental: true); their pages, get_repo and /api/repos keep them and say they are incidental and why. A data check keeps them out of the top tables. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017TycsyUqdnuDeZrYc3z6wV --- README.md | 5 +- bin/console.mojo | 8 +++- src/checks.mojo | 48 +++++++++++++++++++- src/console_api.mojo | 6 ++- src/console_cache.mojo | 29 ++++++++++-- src/console_list.mojo | 53 ++++++++++++++++++++-- src/console_mcp.mojo | 25 ++++++++-- src/console_overview.mojo | 21 +++++++-- src/console_pages.mojo | 8 ++-- src/console_repo.mojo | 13 +++++- src/incidental.mojo | 83 ++++++++++++++++++++++++++++++++++ src/listing.mojo | 58 +++++++++++++++++++----- src/overview.mojo | 36 ++++++++++++--- tests/test_checks.mojo | 42 ++++++++++++++++- tests/test_console_routes.mojo | 50 ++++++++++++++++++++ tests/test_incidental.mojo | 82 +++++++++++++++++++++++++++++++++ tests/test_mcp.mojo | 55 +++++++++++++++++++++- tests/test_overview.mojo | 80 +++++++++++++++++++++++++++++++- 18 files changed, 654 insertions(+), 48 deletions(-) create mode 100644 src/incidental.mojo create mode 100644 tests/test_incidental.mojo diff --git a/README.md b/README.md index 684bd1d..d757cfe 100644 --- a/README.md +++ b/README.md @@ -249,7 +249,10 @@ GH Archive ──gharchive──▶ gharchive.events ──mojo_repos──▶ m monthly curves from `mojo.commits`, adoption of the newest version, tooling share, the repos rising in stars), the repos by size and age (`/repos`, sortable by lines, files or stars with `?sort=`, filterable - with `?version=1.x` and `?active=1y`), search by name, topic or + with `?version=1.x` and `?active=1y`; incidental Mojo repos, which + entered only by a pushed commit and have fewer than 50 lines of Mojo, are + left out of it and of the Overview's numbers unless `?incidental=1`: + `src/incidental.mojo`), search by name, topic or description (`/search`), the Mojo versions they moved to over time (`/migrations`), and a page per repository (`/repos//`: current stars, forks and topics from the latest `mojo.repo_stats` row, diff --git a/bin/console.mojo b/bin/console.mojo index 90632a5..89cb2d5 100644 --- a/bin/console.mojo +++ b/bin/console.mojo @@ -6,7 +6,8 @@ mojo.repo_deps, mojo.dep_forks and mojo.dep_names. Pages: `/` the overview (cards, repos per Mojo version, growth curves), `/repos` the repos by size and age (`?sort=lines|files|stars|forks|used_by&dir=asc|desc`, -`?version=1.x`, `?active=1y`), `/search?q=` finds repos by name, GitHub topic +`?version=1.x`, `?active=1y`, `?incidental=1` to include the incidental Mojo +repos it leaves out, `incidental.mojo`), `/search?q=` finds repos by name, GitHub topic or description, then by meaning (the query embedded with mojo_embed's model, which the console downloads on its first start; CONSOLE_SEMANTIC=0 turns it off), `/migrations` the migrations to each Mojo version over time, `/how`, `/how/optimizations` and `/how/changelog` how the census is built, @@ -66,7 +67,7 @@ def _check(c: Cache, t: Int64) raises -> CheckRun: repos.append( RepoFacts( l.repo, l.commits, c.commits30[i], c.history[i], l.mojo_lines, l.stars, - Int64(len(l.used_by)), page^, + Int64(len(l.used_by)), page^, c.incidental[i] if i < len(c.incidental) else False, ) ) var tops = Tops() @@ -79,6 +80,9 @@ def _check(c: Cache, t: Int64) raises -> CheckRun: tops.rising_used_by = c.rising_used_by.copy() tops.rising_score = c.rising_score.copy() tops.rising_stars = c.rising_stars.copy() + tops.starred = c.starred.copy() + tops.overview_repos = c.ov.repos + tops.overview_incidental = c.ov.incidental # An owner/* row is checked by its repos. for ref d in c.depended: for m in d.members: diff --git a/src/checks.mojo b/src/checks.mojo index 9ccd94a..ea33a11 100644 --- a/src/checks.mojo +++ b/src/checks.mojo @@ -89,6 +89,9 @@ struct RepoFacts(Copyable, Movable): var stars: Int64 var used_by: Int64 var page: PageFacts + var incidental: Bool + """Incidental Mojo (`incidental.is_incidental`), which the top tables + and the Overview's numbers leave out.""" struct Tops(Movable): @@ -105,6 +108,12 @@ struct Tops(Movable): var rising_stars: List[Int64] var depended: List[String] var depended_used_by: List[Int64] + var starred: List[String] + """Most stars' names.""" + var overview_repos: Int + """The Overview's repos and the incidental ones it left out; -1 for not + checked.""" + var overview_incidental: Int def __init__(out self): self.active = List[String]() @@ -118,12 +127,25 @@ struct Tops(Movable): self.rising_stars = List[Int64]() self.depended = List[String]() self.depended_used_by = List[Int64]() + self.starred = List[String]() + self.overview_repos = -1 + self.overview_incidental = -1 def _differs(name: String, what: String, shown: Int64, own: Int64) -> String: return String(name, ": ", what, " ", shown, ", its own ", own) +def _none_incidental( + mut check: Check, table: String, shown: List[String], at: Dict[String, Int], repos: List[RepoFacts] +): + """Fails `check` for each name of `shown` that is an incidental repo.""" + for ref n in shown: + var k = at.get(n, -1) + if k >= 0 and repos[k].incidental: + check.fail(String(table, ": ", n, " is incidental")) + + def run_checks( repo_rows: Int, repos: List[RepoFacts], tops: Tops ) -> List[Check]: @@ -273,7 +295,31 @@ def run_checks( repos[k].used_by, ) ) - return [unique^, within^, within30^, names^, nums^, table^, lines^] + var left = Check( + "incidental_left_out", + ( + "no incidental Mojo repo in Rising, Most stars, Most active or Most" + " depended on, and the Overview's repos + the incidental ones it" + " left out = the repos" + ), + ) + _none_incidental(left, "Rising", tops.rising, at, repos) + _none_incidental(left, "Most stars", tops.starred, at, repos) + _none_incidental(left, "Most active", tops.active, at, repos) + _none_incidental(left, "Most depended on", tops.depended, at, repos) + if tops.overview_repos >= 0: + var inc = 0 + for ref r in repos: + if r.incidental: + inc += 1 + if tops.overview_incidental != inc or tops.overview_repos + inc != len(repos): + left.fail( + String( + "Overview: ", tops.overview_repos, " repos and ", tops.overview_incidental, + " incidental left out; ", len(repos), " repos, ", inc, " incidental", + ) + ) + return [unique^, within^, within30^, names^, nums^, table^, lines^, left^] def when(secs: Int64) -> String: diff --git a/src/console_api.mojo b/src/console_api.mojo index 02983ec..52da1ef 100644 --- a/src/console_api.mojo +++ b/src/console_api.mojo @@ -6,6 +6,7 @@ from flare.http import Request, Response, internal_error, not_found, ok_json, re from days import day_text from deps import other_owners +from incidental import is_incidental from jscan import micros_to_iso from committype import typed_commits from contributors import RepoContributors @@ -48,6 +49,7 @@ def overview_json(req: Request, c: Cache) raises -> Response: '{"as_of":', _q(micros_to_iso(c.sources.as_of_ms * 1000)), ',"days_loaded":', c.sources.days, ',"first_day":', _q(c.sources.first_day), ',"last_day":', _q(c.sources.last_day), ',"repos":', ov.repos, + ',"incidental_repos_left_out":', ov.incidental, ',"repos_with_history":', ov.with_history, ',"repos_30d_ago":', ov.repos_30_ago, ',"coverage":{"repos":', ov.repos, ',"repos_with_history":', ov.with_history, ',"gharchive_days_loaded":', min(c.sources.archive_days, archive_days_due(c.built_day)), @@ -218,7 +220,9 @@ def _lib_json(l: Library, category: String = String()) -> String: '{"repo":', _q(l.repo), ',"description":', _q(l.description), ',"created_at":', _q(micros_to_iso(l.created_at) if l.created_at else ""), ',"first_seen":', _q(micros_to_iso(l.first_seen)), - ',"found_by":', _q(l.found_by), ',"stars":', l.stars, + ',"found_by":', _q(l.found_by), + ',"incidental":', "true" if is_incidental(l.found_by, l.mojo_lines, l.commits) else "false", + ',"stars":', l.stars, ',"forks":', l.forks, ',"license":', _q(l.license), ',"size_kb":', l.size_kb, ',"commits":', l.commits, ',"mojo_lines":', l.mojo_lines, ',"mojo_files":', l.mojo_files, diff --git a/src/console_cache.mojo b/src/console_cache.mojo index 288306a..39df011 100644 --- a/src/console_cache.mojo +++ b/src/console_cache.mojo @@ -45,6 +45,7 @@ from measures import Measure, latest_measures from issues import RepoIssues, add_issue_months, read_issue_rows, summarize from similar import Embeddings, Neighbor, nearest, read_embeddings from categories import categorize +from incidental import is_incidental, without_incidental comptime REFRESH_SECS = 1800 @@ -112,6 +113,10 @@ struct Cache(Movable): var news: List[Int] """Bits of `listing.new_bit` for when each repo's first Mojo commit was.""" var active: List[Bool] + var incidental: List[Bool] + """Whether each repo is incidental Mojo (`incidental.is_incidental`): + the Repos table, the Overview's numbers and its top tables leave those + out unless asked.""" var ov: Overview var details: Dict[String, RepoData] """Per repo: the lists its page shows, all read at once at each build.""" @@ -191,6 +196,7 @@ struct Cache(Movable): self.est_families = List[String]() self.news = List[Int]() self.active = List[Bool]() + self.incidental = List[Bool]() self.ov = Overview() self.details = Dict[String, RepoData]() self.loaded = List[String]() @@ -229,7 +235,14 @@ struct Cache(Movable): def _build(mut self, today: Int, var src: Sources) raises: var b = Builder(today) var libs = libraries(b) - var ov = b.finish(len(libs)) + var incidental = List[Bool]() + var skip = Dict[String, Bool]() + for ref l in libs: + var inc = is_incidental(l.found_by, l.mojo_lines, l.commits) + incidental.append(inc) + if inc: + skip[l.repo] = True + var ov = b.finish(len(libs), skip) # Per repo in `libs`' order (biggest first), joined by name: `b.accs` # is in mojo.repos' order, so its index is no repo's index in `libs`. var names = List[String]() @@ -315,6 +328,13 @@ struct Cache(Movable): self.starred_gain = List[Int64]() self.starred_forks = List[Int64]() self.starred_used_by = List[Int64]() + # The top tables rank no incidental repo. + score_list = without_incidental(score_list, incidental) + var top_stars = without_incidental(stars, incidental) + var top_commits30 = without_incidental(commits30, incidental) + var top_users = List[List[String]]() + for i in range(len(libs)): + top_users.append(List[String]() if incidental[i] else users[i].copy()) for i in top_gains(score_list, RISING_SHOWN): var g = gains.get(libs[i].repo, Gain(0, 0)) self.rising.append(libs[i].repo) @@ -323,13 +343,13 @@ struct Cache(Movable): self.rising_used_by.append(Int64(len(libs[i].used_by))) self.rising_score.append(score_list[i]) self.rising_stars.append(libs[i].stars) - for i in top_gains(stars, STARRED_SHOWN): + for i in top_gains(top_stars, STARRED_SHOWN): self.starred.append(libs[i].repo) self.starred_stars.append(libs[i].stars) self.starred_gain.append(gains.get(libs[i].repo, Gain(0, 0)).stars) self.starred_forks.append(libs[i].forks) self.starred_used_by.append(Int64(len(libs[i].used_by))) - self.depended = most_depended(names, users, stars, forks, DEPENDED_SHOWN) + self.depended = most_depended(names, top_users, stars, forks, DEPENDED_SHOWN) var details = Dict[String, RepoData]() for e in histories().items(): if _duplicate(e.key, key_of, name_of): @@ -386,7 +406,7 @@ struct Cache(Movable): self.active_repos = List[String]() self.active_commits = List[Int64]() self.active_lines = List[Int64]() - for i in top_gains(commits30, ACTIVE_SHOWN): + for i in top_gains(top_commits30, ACTIVE_SHOWN): self.active_repos.append(libs[i].repo) self.active_commits.append(commits30[i]) self.active_lines.append(lines_delta[i]) @@ -402,6 +422,7 @@ struct Cache(Movable): self.est_families = est_families^ self.news = news^ self.active = active^ + self.incidental = incidental^ self.libs = libs^ self.history = history^ var keep = Dict[String, Bool]() diff --git a/src/console_list.mojo b/src/console_list.mojo index 919c312..94340a9 100644 --- a/src/console_list.mojo +++ b/src/console_list.mojo @@ -12,11 +12,13 @@ from listing import ( with_active, with_category, with_estimate, + with_incidental, with_new, with_version, ) from model import Library, day from categories import category_keys, category_title +from incidental import INCIDENTAL_LINES from querymodel import Related, related from search import names_score, url_decode, url_encode @@ -91,6 +93,7 @@ def _list_query(req: Request) -> ListQuery: req.query_param("sort"), req.query_param("dir"), url_decode(req.query_param("version")), req.query_param("active"), req.query_param("new"), req.query_param("estimate"), req.query_param("category"), + req.query_param("incidental"), ) @@ -107,12 +110,27 @@ def _raw_query(req: Request) -> String: return s^ +def _left_out(q: ListQuery, c: Cache, i: Int) -> Bool: + """Whether repo `i` is incidental and `q` leaves those out.""" + return not q.incidental and i < len(c.incidental) and c.incidental[i] + + +def incidental_count(c: Cache) -> Int: + var n = 0 + for b in c.incidental: + if b: + n += 1 + return n + + def _filter_options(q: ListQuery, c: Cache) -> String: """The version families and the activity filter as links, with how many repos each has under the other filter; the ones in use are marked.""" var per = Dict[String, Int]() var total = 0 for i in range(len(c.libs)): + if _left_out(q, c, i): + continue if q.active and not c.active[i]: continue if q.new.byte_length() > 0 and c.news[i] & new_bit(q.new) == 0: @@ -155,6 +173,8 @@ def _filter_options(q: ListQuery, c: Cache) -> String: var cats = Dict[String, Int]() var all = 0 for i in range(len(c.libs)): + if _left_out(q, c, i): + continue if q.active and not c.active[i]: continue if q.new.byte_length() > 0 and c.news[i] & new_bit(q.new) == 0: @@ -185,10 +205,27 @@ def _filter_options(q: ListQuery, c: Cache) -> String: "", titles[k], "", ) + var inc = incidental_count(c) + if inc > 0: + h.write( + "Incidental Mojo", + "left out", + "included (", inc, ")", + ) h.write("") return h^ +def incidental_title() -> String: + """What incidental Mojo means, in a line for a tooltip.""" + return String( + "Repos that entered the census only through a pushed commit that changed a .mojo file, and have fewer than ", + INCIDENTAL_LINES, " lines of Mojo", + ) + + def _filter_chips(q: ListQuery) -> String: """The filters in use, each a chip that removes it.""" if not q.has_filter(): @@ -231,7 +268,7 @@ def repos_page(req: Request, c: Cache) raises -> Response: q, c.lines, c.files, c.stars, c.est_buckets if q.estimate else c.buckets, c.active, c.est_families if q.estimate else c.families, c.news, c.commits30, - c.forks, c.used_by, c.categories, + c.forks, c.used_by, c.categories, c.incidental, ) var h = String( "

Mojo repos

Mojo repos, versions and growth, counted", @@ -247,10 +284,20 @@ def repos_page(req: Request, c: Cache) raises -> Response: ) ) return _page("Repos", h^, "repos", description=page_line("/repos"), alternate=page_json("/repos")) + var inc = incidental_count(c) + var counted = len(c.libs) if q.incidental else len(c.libs) - inc + var inc_note = String() + if inc > 0: + inc_note = String( + " ", String(inc) if not q.incidental else String("The"), " incidental Mojo ", + "repo" if inc == 1 and not q.incidental else "repos", + String(" left out") if not q.incidental else String(" are included"), ".", + ) h.write( "

", len(idx), " repo" if len(idx) == 1 else " repos", - "", " of " if q.has_filter() else "", String(len(c.libs)) if q.has_filter() else "", - " found in GH Archive.", + "", " of " if q.has_filter() else "", String(counted) if q.has_filter() else "", + " found in GH Archive.", inc_note, _help( "h-repos", "the Repos table", "Size is lines of Mojo at the last commit read; age is since GitHub created the" diff --git a/src/console_mcp.mojo b/src/console_mcp.mojo index c6716c4..c10ce8c 100644 --- a/src/console_mcp.mojo +++ b/src/console_mcp.mojo @@ -51,7 +51,8 @@ from swap import Swap from console_cache import Cache from console_layout import SITE_URL, census_version -from console_list import _matches, meaning_hits +from console_list import _matches, incidental_count, meaning_hits +from incidental import INCIDENTAL_LINES, incidental_why, is_incidental from mcp_events import ( ClientIds, EventQueue, HEADER_MAX, INTENT_MAX, MISSING_CAPABILITY, McpEvent, client_of_agent, cut, event_json, js, session_id, trim_arguments, @@ -393,7 +394,9 @@ def tools_json() -> String: String( "List Mojo repos ranked by stars, by commits in the last 30 days (commits), by their last" " commit (recent), or by rising (stars, forks and dependents gained in 30 days; the top 10" - " only), optionally only one Mojo version, one category or the ones active in the last year.", + " only), optionally only one Mojo version, one category or the ones active in the last year." + " Incidental Mojo repos (entered only through a pushed commit that changed a .mojo file, under ", + INCIDENTAL_LINES, " lines of Mojo) are left out unless `incidental` is true.", DATA_NOTE, ) ), @@ -401,6 +404,8 @@ def tools_json() -> String: '"sort":{"type":"string","enum":["stars","commits","recent","rising"],"default":"stars"},', VERSION_PROP, ",", category_prop, ',"active":{"type":"boolean","description":"Only repos with a commit in the last 12 months."},', + '"incidental":{"type":"boolean","default":false,"description":"Include the incidental Mojo repos:', + ' multi-language collections and the like with only a few lines of Mojo. Rising never has them."},', limit_prop, "}}},", '{"name":"get_repo","title":"One Mojo repo","description":', js( @@ -508,6 +513,7 @@ def repo_brief(c: Cache, i: Int) -> String: ',"tooling":', js(l.tooling), ',"used_by":', len(l.used_by), ',"category":', js(c.categories[i]) if i < len(c.categories) and c.categories[i].byte_length() > 0 else "null", ',"archived":', "true" if l.archived else "false", + ',"incidental":', "true" if i < len(c.incidental) and c.incidental[i] else "false", ) @@ -573,6 +579,7 @@ def list_repos(c: Cache, b: Span[UInt8, _], args: Range) raises -> ToolOut: var version = _str_arg(b, args, "version") var category = _category_arg(b, args) var active = _bool_arg(b, args, "active") + var incidental = _bool_arg(b, args, "incidental") var limit = _int_arg(b, args, "limit", LIMIT_DEFAULT, LIMIT_MAX) var idx = List[Int]() var url = String(SITE_URL, "/repos") @@ -585,11 +592,11 @@ def list_repos(c: Cache, b: Span[UInt8, _], args: Range) raises -> ToolOut: elif sort == "stars" or sort == "commits" or sort == "recent": var q = ListQuery( "stars" if sort == "stars" else ("commits30" if sort == "commits" else "lines"), False, version, active, - String(), False, category, + String(), False, category, incidental, ) idx = select_repos( q, c.lines, c.files, c.stars, c.buckets, c.active, c.families, c.news, c.commits30, c.forks, - c.used_by, c.categories, + c.used_by, c.categories, c.incidental, ) if sort == "recent": var last = List[Int64]() @@ -601,7 +608,8 @@ def list_repos(c: Cache, b: Span[UInt8, _], args: Range) raises -> ToolOut: else: raise Error("`sort` must be stars, commits, recent or rising.") var out = String( - '{"as_of":', _as_of(c), ',"url":', js(url), ',"sort":', js(sort), ',"total":', len(idx), ',"results":[', + '{"as_of":', _as_of(c), ',"url":', js(url), ',"sort":', js(sort), ',"total":', len(idx), + ',"incidental_left_out":', 0 if incidental and sort != "rising" else incidental_count(c), ',"results":[', ) var n = min(limit, len(idx)) for k in range(n): @@ -664,6 +672,12 @@ def get_repo(c: Cache, b: Span[UInt8, _], args: Range) raises -> ToolOut: ',"description":', js(l.description), ',"topics":', _strs(l.topics), ',"license":', js(l.license), ',"stars":', l.stars, ',"forks":', l.forks, ',"open_issues":', l.open_issues, ',"archived":', "true" if l.archived else "false", + ',"found_by":', js(l.found_by), + ',"incidental":', "true" if is_incidental(l.found_by, l.mojo_lines, l.commits) else "false", + ) + if is_incidental(l.found_by, l.mojo_lines, l.commits): + out.write(',"incidental_why":', js(incidental_why(l.mojo_lines))) + out.write( ',"category":', js(c.categories[i]) if i < len(c.categories) and c.categories[i].byte_length() > 0 else "null", ',"created_at":', _iso_or_null(l.created_at), ',"last_commit":', _iso_or_null(l.last_commit), ',"commits":', l.commits, ',"commits_30d":', c.commits30[i] if i < len(c.commits30) else 0, @@ -794,6 +808,7 @@ def overview_tool(c: Cache) -> ToolOut: ref ov = c.ov var out = String( '{"as_of":', _as_of(c), ',"url":', js(String(SITE_URL, "/")), ',"repos":', ov.repos, + ',"incidental_repos_left_out":', ov.incidental, ',"repos_with_history":', ov.with_history, ',"repos_30d_ago":', ov.repos_30_ago, ',"active_repos":', ov.active, ',"new_repos_this_month":', ov.new_this_month, ',"new_repos_last_month":', ov.new_last_month, ',"commits":', ov.commits, diff --git a/src/console_overview.mojo b/src/console_overview.mojo index 352f262..d0fcfd5 100644 --- a/src/console_overview.mojo +++ b/src/console_overview.mojo @@ -24,7 +24,7 @@ from console_cache import Cache, refresh_secs from console_how import MORCA_UI from console_layout import _empty, _help, _n, _page, _this_month from console_pages import page_json, page_line -from console_list import _raw_query +from console_list import _raw_query, incidental_title def _signed(v: Int64) -> String: @@ -111,8 +111,9 @@ def _categories_card(c: Cache) -> String: if c.embed_snapshot < 0 or len(c.categories) != len(c.libs): return String() var per = Dict[String, Int]() - for ref k in c.categories: - if k.byte_length() > 0: + for i in range(len(c.categories)): + ref k = c.categories[i] + if k.byte_length() > 0 and not (i < len(c.incidental) and c.incidental[i]): per[k] = per.get(k, 0) + 1 var total = 0 for e in per.items(): @@ -367,6 +368,17 @@ comptime ARCHIVE_COVERAGE = MORCA_UI + "/pipelines/gharchive?tab=operate&cov=yea """gharchive's coverage calendar on morca, by year: which days are loaded.""" +def _incidental_note(n: Int) -> String: + """The sentence that says how many incidental Mojo repos every number + and table here leaves out; empty for none.""" + if n == 0: + return String() + return String( + " The repo counts, curves and tables here leave out ", + _n(Int64(n)), " incidental Mojo repo" if n == 1 else " incidental Mojo repos", ".", + ) + + def overview(req: Request, c: Cache) raises -> Response: if _raw_query(req).byte_length() > 0 and ( req.query_param("sort").byte_length() > 0 @@ -414,7 +426,8 @@ def overview(req: Request, c: Cache) raises -> Response: h.write( "

Coverage: git histories read for ", hist_a, hist_of, " (", hist_pct, "); GH Archive loaded for ", days_a, days_of, " since ", day_text(Int64(ARCHIVE_START)), - " (", days_pct, "). Numbers that rest on either are partial and grow as the pipelines catch up.

", + " (", days_pct, "). Numbers that rest on either are partial and grow as the pipelines catch up.", + _incidental_note(ov.incidental), "

", "
", _kpi( "Repos", String("", _n(Int64(ov.repos)), ""), diff --git a/src/console_pages.mojo b/src/console_pages.mojo index 253943f..b4dd676 100644 --- a/src/console_pages.mojo +++ b/src/console_pages.mojo @@ -40,7 +40,9 @@ def site_pages() -> List[SitePage]: "Repos", ( "Every Mojo repo the census found, by lines of Mojo, files, stars, forks," - " age or dependents, filterable by Mojo version, activity and category." + " age or dependents, filterable by Mojo version, activity and category;" + " incidental Mojo repos (a few lines of Mojo in another language's repo)" + " are left out unless `?incidental=1`." ), "/api/repos", ), @@ -110,8 +112,8 @@ def api_pages() -> List[SitePage]: "All repos", ( "Every repo with its description, topics, stars, forks, license, lines of" - " Mojo, Mojo version, tooling, dependencies and category; `?q=` keeps the" - " ones /api/search finds." + " Mojo, Mojo version, tooling, dependencies and category, incidental Mojo" + " ones included and marked; `?q=` keeps the ones /api/search finds." ), "", ), diff --git a/src/console_repo.mojo b/src/console_repo.mojo index bcc13bd..a2dad83 100644 --- a/src/console_repo.mojo +++ b/src/console_repo.mojo @@ -6,6 +6,7 @@ from flare.http import Request, Response, html_escape, internal_error, not_found from contributors import RepoContributors from days import day_text from deps import other_owners +from incidental import incidental_why, is_incidental from model import Library, MonthActivity, Point, day from similar import Neighbor from categories import CATEGORIES_VERSION, VOTERS, category_title @@ -525,6 +526,16 @@ def _version_stat(l: Library) -> String: return _stat("Mojo version", _or_dash(String()), note) +def _incidental_line(l: Library) -> String: + """For an incidental Mojo repo, the line that says so and why; else "".""" + if not is_incidental(l.found_by, l.mojo_lines, l.commits): + return String() + return String( + "

Counted as incidental Mojo. ", html_escape(incidental_why(l.mojo_lines)), + " The Repos table with them.

", + ) + + def _formerly(aliases: List[String]) -> String: """" · formerly a/b, c/d": the names a renamed or transferred repo had, or "".""" @@ -564,7 +575,7 @@ def repo_page(req: Request, c: Cache) raises -> Response: _formerly(l.aliases), String(" · GitHub says ", html_escape(l.state), "") if l.state.byte_length() > 0 and l.state != "ok" and l.state != "renamed" else String(), - "

", + "

", _incidental_line(l), "
", _stat("Stars", _n(l.stars), String("as of ", day_text(l.stats_as_of)) if l.stats_as_of > 0 else String("when found")), _stat("Forks", _n(l.forks), String("as of ", day_text(l.stats_as_of)) if l.stats_as_of > 0 else String("when found")), _deps_stat(l), diff --git a/src/incidental.mojo b/src/incidental.mojo new file mode 100644 index 0000000..cabc256 --- /dev/null +++ b/src/incidental.mojo @@ -0,0 +1,83 @@ +"""Incidental Mojo: a repository the census counts that has almost no Mojo in +it, such as a collection of exercises in many languages where one pushed +commit added a `.mojo` file. + +mojo_repos accepts a repository by one of three checks (`detect.verify`): +GitHub says its main language is Mojo (`language`), a `pixi.toml` or +`mojoproject.toml` names a Mojo package (`manifest ...`), or a pushed commit +changed a `.mojo` or `.🔥` file (`push`). The first two say the repository +is a Mojo project; the third only that it has some Mojo. A repository is +incidental when it entered by `push` alone (GitHub's search, which gives +`language:Mojo` repositories, didn't give it either) and its history, once +read, has fewer than `INCIDENTAL_LINES` lines of Mojo at its last commit. + +Incidental repositories stay in the data and keep their pages; the Repos +table, the Overview's numbers and top tables and the MCP `list_repos` tool +leave them out unless asked (`?incidental=1`, `incidental: true`).""" + +comptime INCIDENTAL_LINES = Int64(50) +"""Below this many lines of Mojo at its last commit, a repository that +entered only by a pushed commit is incidental.""" + + +def how_of(found_by: String) -> String: + """The check that accepted the repository: what mojo.repos' `found_by` + (`signals / how`, e.g. `name,push / push`) has after ` / `; all of it + when there is no ` / `.""" + var at = found_by.find(" / ").or_else(-1) + if at < 0: + return String(found_by.strip()) + return String(found_by[byte = at + 3 :].strip()) + + +def signals_of(found_by: String) -> List[String]: + """The signals the candidate had (`name`, `description`, `push`, + `search`, ...): what `found_by` has before ` / `, split at commas.""" + var out = List[String]() + var at = found_by.find(" / ").or_else(-1) + var head = String(found_by[byte=:at]) if at >= 0 else String() + for part in head.split(","): + var s = String(part.strip()) + if s.byte_length() > 0: + out.append(s^) + return out^ + + +def push_only(found_by: String) -> Bool: + """Whether the repository entered only by a pushed commit: accepted by + `push`, and not given by GitHub's search for `language:Mojo`.""" + if how_of(found_by) != "push": + return False + for ref s in signals_of(found_by): + if s == "search": + return False + return True + + +def is_incidental(found_by: String, mojo_lines: Int64, commits: Int) -> Bool: + """Whether a repository counts as incidental Mojo (the module's rule). + One whose history isn't read yet (`commits` 0) isn't: its lines aren't + known.""" + return commits > 0 and mojo_lines < INCIDENTAL_LINES and push_only(found_by) + + +def incidental_why(mojo_lines: Int64) -> String: + """Why a repository is incidental, as a sentence for its page and + `get_repo`.""" + return String( + "It entered the census only through a pushed commit that changed a .mojo file (GitHub didn't", + " say its main language is Mojo, and no pixi.toml or mojoproject.toml names a Mojo package),", + " and it has ", mojo_lines, " line" if mojo_lines == 1 else " lines", " of Mojo now, under ", + INCIDENTAL_LINES, ". It is left out of the rankings and the overview's numbers by default.", + ) + + +def without_incidental(values: List[Int64], incidental: List[Bool]) -> List[Int64]: + """`values` with each incidental repository's set to 0, so the top + tables' `overview.top_gains`, which passes over values of 0 and less, + ranks none of them.""" + var out = values.copy() + for i in range(min(len(out), len(incidental))): + if incidental[i]: + out[i] = 0 + return out^ diff --git a/src/listing.mojo b/src/listing.mojo index de0c14f..a99cd29 100644 --- a/src/listing.mojo +++ b/src/listing.mojo @@ -1,16 +1,16 @@ """The Repos table's query: which column it sorts by, which filters it has, and the repositories that pass, from plain arrays so the tests need no lake. - /repos?sort=lines|files|stars|forks|used_by|commits30&dir=asc|desc&version=1.2&active=1y&new=month&category=ml + /repos?sort=lines|files|stars|forks|used_by|commits30&dir=asc|desc&version=1.2&active=1y&new=month&category=ml&incidental=1 The default is the order the repositories come in (most lines of Mojo -first), which is `sort=lines&dir=desc`. +first), which is `sort=lines&dir=desc`. Incidental Mojo repositories +(`incidental.is_incidental`) are left out unless `incidental=1`. """ from categories import is_category -@fieldwise_init struct ListQuery(Copyable, Movable): var sort: String """`lines`, `files`, `stars`, `forks`, `used_by` (census repos that @@ -29,6 +29,29 @@ struct ListQuery(Copyable, Movable): estimates (`?estimate=1`); only the version filter looks at it.""" var category: String """A category key (`categories.category_keys`); empty for any.""" + var incidental: Bool + """Include the incidental Mojo repositories (`?incidental=1`), which are + left out by default.""" + + def __init__( + out self, + sort: String, + asc: Bool, + version: String, + active: Bool, + new: String, + estimate: Bool, + category: String, + incidental: Bool = False, + ): + self.sort = sort + self.asc = asc + self.version = version + self.active = active + self.new = new + self.estimate = estimate + self.category = category + self.incidental = incidental def is_default_order(self) -> Bool: return self.sort == "lines" and not self.asc @@ -48,6 +71,7 @@ def parse_list_query( new: String = String(), estimate: String = String(), category: String = String(), + incidental: String = String(), ) -> ListQuery: """The query from the raw parameters; what isn't recognised is the default.""" @@ -60,7 +84,7 @@ def parse_list_query( var cat = String() if is_category(category): cat = category - return ListQuery(s, dir == "asc", String(version.strip()), active == "1y", n, estimate == "1", cat^) + return ListQuery(s, dir == "asc", String(version.strip()), active == "1y", n, estimate == "1", cat^, incidental == "1") def list_url(q: ListQuery, base: String = "/repos") -> String: @@ -80,6 +104,8 @@ def list_url(q: ListQuery, base: String = "/repos") -> String: parts.append(String("estimate=1")) if q.category.byte_length() > 0: parts.append(String("category=", q.category)) + if q.incidental: + parts.append(String("incidental=1")) if len(parts) == 0: return base var out = String(base, "?") @@ -94,24 +120,24 @@ def sorted_by(q: ListQuery, column: String) -> ListQuery: """`q` after clicking `column`'s header: the same column flips the direction, another starts largest first.""" if q.sort == column: - return ListQuery(q.sort, not q.asc, q.version, q.active, q.new, q.estimate, q.category) - return ListQuery(column, False, q.version, q.active, q.new, q.estimate, q.category) + return ListQuery(q.sort, not q.asc, q.version, q.active, q.new, q.estimate, q.category, q.incidental) + return ListQuery(column, False, q.version, q.active, q.new, q.estimate, q.category, q.incidental) def with_version(q: ListQuery, version: String) -> ListQuery: - return ListQuery(q.sort, q.asc, version, q.active, q.new, q.estimate, q.category) + return ListQuery(q.sort, q.asc, version, q.active, q.new, q.estimate, q.category, q.incidental) def with_estimate(q: ListQuery, estimate: Bool) -> ListQuery: - return ListQuery(q.sort, q.asc, q.version, q.active, q.new, estimate, q.category) + return ListQuery(q.sort, q.asc, q.version, q.active, q.new, estimate, q.category, q.incidental) def with_active(q: ListQuery, active: Bool) -> ListQuery: - return ListQuery(q.sort, q.asc, q.version, active, q.new, q.estimate, q.category) + return ListQuery(q.sort, q.asc, q.version, active, q.new, q.estimate, q.category, q.incidental) def with_new(q: ListQuery, new: String) -> ListQuery: - return ListQuery(q.sort, q.asc, q.version, q.active, new, q.estimate, q.category) + return ListQuery(q.sort, q.asc, q.version, q.active, new, q.estimate, q.category, q.incidental) comptime NEW_MONTH = 1 @@ -120,7 +146,11 @@ comptime NEW_30D = 4 def with_category(q: ListQuery, category: String) -> ListQuery: - return ListQuery(q.sort, q.asc, q.version, q.active, q.new, q.estimate, category) + return ListQuery(q.sort, q.asc, q.version, q.active, q.new, q.estimate, category, q.incidental) + + +def with_incidental(q: ListQuery, incidental: Bool) -> ListQuery: + return ListQuery(q.sort, q.asc, q.version, q.active, q.new, q.estimate, q.category, incidental) def new_bit(new: String) -> Int: @@ -145,12 +175,16 @@ def select_repos( forks: List[Int64] = List[Int64](), used_by: List[Int64] = List[Int64](), categories: List[String] = List[String](), + incidental: List[Bool] = List[Bool](), ) -> List[Int]: """The indices of the repositories that pass `q`'s filters, in its order. The arrays are one entry per repository, in the default order; - equal values stay in that order.""" + equal values stay in that order. A repository `incidental` marks is + left out unless `q.incidental`.""" var idx = List[Int]() for i in range(len(lines)): + if not q.incidental and i < len(incidental) and incidental[i]: + continue if q.version.byte_length() > 0 and families[i] != q.version: if len(legacy) == 0 or legacy[i] != q.version: continue diff --git a/src/overview.mojo b/src/overview.mojo index 51a1962..34578dc 100644 --- a/src/overview.mojo +++ b/src/overview.mojo @@ -130,7 +130,10 @@ struct Overview(Movable): """The numbers of the Overview page.""" var repos: Int - """Repositories in mojo.repos.""" + """Repositories in mojo.repos, less the incidental ones.""" + var incidental: Int + """The incidental Mojo repositories (`incidental.is_incidental`) left + out of every number here.""" var with_history: Int var commits: Int var commits_30: Int @@ -184,6 +187,7 @@ struct Overview(Movable): def __init__(out self): self.repos = 0 + self.incidental = 0 self.with_history = 0 self.commits = 0 self.commits_30 = 0 @@ -253,6 +257,9 @@ struct Builder(Movable): in the month, -1 for none.""" var cell_lines: List[Int64] var cell_tool: List[UInt8] + var cell_commits: List[Int32] + """The repository's commits in the month, so `finish` can leave a + skipped repository's out of `commits_by_month`.""" var commits_by_month: List[Int64] var cut30: Int64 var cut60: Int64 @@ -267,6 +274,7 @@ struct Builder(Movable): self.cell_seq = List[Int64]() self.cell_lines = List[Int64]() self.cell_tool = List[UInt8]() + self.cell_commits = List[Int32]() self.commits_by_month = List[Int64](length=self.months, fill=0) self.cut30 = Int64(now_days - 30) * DAY_US self.cut60 = Int64(now_days - 60) * DAY_US @@ -285,6 +293,7 @@ struct Builder(Movable): self.cell_seq.resize(n, -1) self.cell_lines.resize(n, 0) self.cell_tool.resize(n, 0) + self.cell_commits.resize(n, 0) return len(self.accs) - 1 def id_of(self, name: String) -> Int: @@ -321,6 +330,7 @@ struct Builder(Movable): ) self.commits_by_month[k] += 1 var cell = id * self.months + k + self.cell_commits.unsafe_ptr()[unsafe_offset=cell] += 1 if seq >= self.cell_seq.unsafe_ptr()[unsafe_offset=cell]: self.cell_seq.unsafe_ptr()[unsafe_offset=cell] = seq self.cell_lines.unsafe_ptr()[unsafe_offset=cell] = lines @@ -350,13 +360,18 @@ struct Builder(Movable): self.accs[id].version = version self.accs[id].estimate = estimate - def finish(self, repos: Int) -> Overview: - """The overview, for `repos` repositories in mojo.repos.""" + def finish(self, repos: Int, skip: Dict[String, Bool] = Dict[String, Bool]()) -> Overview: + """The overview, for `repos` repositories in mojo.repos, leaving out + the ones `skip` names (the incidental ones): they count in no number, + series or bucket, and `incidental` says how many there were.""" var o = Overview() - o.repos = repos + for ref a in self.accs: + if a.name in skip: + o.incidental += 1 + o.repos = repos - o.incidental var now_month = month_of_days(self.now_days) for ref a in self.accs: - if a.commits == 0: + if a.commits == 0 or a.name in skip: continue o.with_history += 1 o.commits += a.commits @@ -381,6 +396,8 @@ struct Builder(Movable): var ebg = Groups() var efg = Groups() for ref a in self.accs: + if a.name in skip: + continue var is_active = a.commits > 0 and a.last_at >= self.cut_active var why = unversioned(a.commits, a.tool) bg.add(bucket_of(a.version, why), a.version, is_active) @@ -421,7 +438,14 @@ struct Builder(Movable): var seq_p = self.cell_seq.unsafe_ptr() var lines_p = self.cell_lines.unsafe_ptr() var tool_p = self.cell_tool.unsafe_ptr() + var commits_by_month = self.commits_by_month.copy() for r in range(len(self.accs)): + if self.accs[r].name in skip: + for k in range(m): + commits_by_month[k] -= Int64(self.cell_commits[r * m + k]) + for r in range(len(self.accs)): + if self.accs[r].name in skip: + continue var started = False var carry_lines = Int64(0) var carry_tool = TOOL_NONE @@ -451,7 +475,7 @@ struct Builder(Movable): o.months.append(month_label(BASE_MONTH + k)) o.lines_series.append(lines[k]) o.repos_series.append(nrepos[k]) - o.commits_series.append(self.commits_by_month[k]) + o.commits_series.append(commits_by_month[k]) o.tool_none.append(none[k]) o.tool_magic.append(magic[k]) o.tool_pixi.append(pixi[k]) diff --git a/tests/test_checks.mojo b/tests/test_checks.mojo index 0e1c24c..1d1003a 100644 --- a/tests/test_checks.mojo +++ b/tests/test_checks.mojo @@ -31,7 +31,11 @@ def _pt(day: Int64, lines: Int64) -> Point: def _repo( - name: String, var pts: List[Point], stars: Int64 = 5, used_by: Int64 = 1 + name: String, + var pts: List[Point], + stars: Int64 = 5, + used_by: Int64 = 1, + incidental: Bool = False, ) -> RepoFacts: """A repo whose numbers all agree with its commit list.""" var p = page_facts(pts, CUT) @@ -44,6 +48,7 @@ def _repo( stars, used_by, p^, + incidental, ) @@ -105,7 +110,7 @@ def test_page_facts() raises: def test_all_agree() raises: var checks = run_checks(3, _good(), _tops()) - assert_equal(len(checks), 7) + assert_equal(len(checks), 8) assert_equal(len(_failing(checks)), 0) @@ -189,6 +194,39 @@ def test_lines_not_last_commit() raises: ) +def test_incidental_left_out() raises: + """An incidental repo in a top table, or an Overview whose counts don't + add up to the repos, fails `incidental_left_out`.""" + var repos = _good() + repos.append(_repo("o/exercises", [_pt(110, 2)], 5663, 0, True)) + var tops = _tops() + tops.starred = ["o/big"] + tops.overview_repos = 3 + tops.overview_incidental = 1 + assert_equal(len(_failing(run_checks(4, repos, tops))), 0) + tops.starred = ["o/exercises", "o/big"] + tops.rising = ["o/big", "o/exercises"] + tops.rising_gain = [7, 1] + tops.rising_forks = [2, 0] + tops.rising_used_by = [3, 0] + tops.rising_score = [rising_score(7, 2, 3), rising_score(1, 0, 0)] + tops.rising_stars = [40, 5663] + var checks = run_checks(4, repos, tops) + var bad = _failing(checks) + assert_equal(len(bad), 1) + assert_equal(bad[0], "incidental_left_out") + var rows = _rows(checks, "incidental_left_out") + assert_equal(rows[0], "Rising: o/exercises is incidental") + assert_equal(rows[1], "Most stars: o/exercises is incidental") + # The Overview counted it. + var t2 = _tops() + t2.overview_repos = 4 + t2.overview_incidental = 0 + var rows2 = _rows(run_checks(4, repos, t2), "incidental_left_out") + assert_equal(len(rows2), 1) + assert_equal(rows2[0], "Overview: 4 repos and 0 incidental left out; 4 repos, 1 incidental") + + def test_rows_capped() raises: var repos = List[RepoFacts]() for i in range(20): diff --git a/tests/test_console_routes.mojo b/tests/test_console_routes.mojo index 9135467..23c6a3c 100644 --- a/tests/test_console_routes.mojo +++ b/tests/test_console_routes.mojo @@ -554,5 +554,55 @@ def test_most_stars() raises: assert_true('"most_starred":[{"repo":"acme/tomlkit","stars":12,"stars_30d":4,"forks":3,"used_by":1}]' in j) +def test_incidental_repos() raises: + """An incidental repo is left out of the Repos table unless + `?incidental=1`, and its own page and JSON still work and say so.""" + var c = _cache() + var l = _lib("someone/exercises", "Exercises in 40 languages", List[String]()) + l.found_by = "push / push" + l.mojo_lines = 2 + l.stars = 5663 + c.lines.append(l.mojo_lines) + c.files.append(l.mojo_files) + c.stars.append(l.stars) + c.forks.append(l.forks) + c.used_by.append(0) + c.buckets.append("25.x") + c.families.append("25.x") + c.est_buckets.append("25.x") + c.est_families.append("25.x") + c.news.append(0) + c.active.append(True) + c.commits30.append(1) + c.categories.append("") + c.history.append(Int64(l.commits)) + c.libs.append(l^) + c.incidental = [False, False, True] + c.ov.repos = 2 + c.ov.incidental = 1 + var r = _router_of(c^) + var page = _body(_get(r, "/repos?sort=stars")) + assert_false("href='/repos/someone/exercises'" in page) + assert_true("2 repos found in GH Archive." in page, page) + assert_true(">1 incidental Mojo repo left out" in page) + assert_true("href='/repos?sort=stars&incidental=1'" in page) + var all = _body(_get(r, "/repos?sort=stars&incidental=1")) + assert_true("3 repos found in GH Archive." in all) + assert_true(">The incidental Mojo repos are included" in all) + var first = all.find("Counted as incidental Mojo. It entered the census only through a pushed commit" in own) + assert_false("Counted as incidental Mojo" in _body(_get(r, "/repos/acme/tomlkit"))) + var j = _body(_get(r, "/api/repos")) + assert_true('"repo":"someone/exercises"' in j) + assert_true('"found_by":"push / push","incidental":true' in j) + var home = _body(_get(r, "/")) + assert_true(">1 incidental Mojo repo." in home) + assert_true('"incidental_repos_left_out":1' in _body(_get(r, "/api/overview"))) + + def main() raises: TestSuite.discover_tests[__functions_in_module()]().run() diff --git a/tests/test_incidental.mojo b/tests/test_incidental.mojo new file mode 100644 index 0000000..520862f --- /dev/null +++ b/tests/test_incidental.mojo @@ -0,0 +1,82 @@ +"""Incidental Mojo (`incidental`): which repositories the rule marks, from +mojo.repos' `found_by` and the lines of Mojo at the last commit, and the +top tables' keys with them left out. + + pixi run test +""" + +from std.testing import TestSuite, assert_equal, assert_false, assert_true + +from incidental import ( + INCIDENTAL_LINES, + how_of, + incidental_why, + is_incidental, + push_only, + signals_of, + without_incidental, +) +from overview import top_gains + + +def test_how_and_signals() raises: + assert_equal(how_of("push / push"), "push") + assert_equal(how_of("name,description / manifest pixi.toml"), "manifest pixi.toml") + assert_equal(how_of("search / language"), "language") + assert_equal(how_of("language"), "language") + var s = signals_of("name,description,push / push") + assert_equal(len(s), 3) + assert_equal(s[0], "name") + assert_equal(s[2], "push") + assert_equal(len(signals_of("push")), 0) + + +def test_push_only() raises: + assert_true(push_only("push / push")) + assert_true(push_only("name,description,push / push")) + # Accepted by GitHub's language or a manifest, even with a push signal. + assert_false(push_only("push / language")) + assert_false(push_only("name,push / manifest pixi.toml")) + assert_false(push_only("search / language")) + # GitHub's search said language:Mojo: not push-only, whatever settled it. + assert_false(push_only("search,push / push")) + + +def test_is_incidental() raises: + assert_equal(INCIDENTAL_LINES, 50) + # mouredev/retos-programacion-2023: 2 lines, entered by a push. + assert_true(is_incidental("push / push", 2, 5990)) + assert_true(is_incidental("name,description,push / push", 0, 119)) + assert_true(is_incidental("push / push", INCIDENTAL_LINES - 1, 3)) + assert_false(is_incidental("push / push", INCIDENTAL_LINES, 3)) + assert_false(is_incidental("push / push", 4_000, 3)) + # Few lines, but GitHub or a manifest says it is a Mojo project. + assert_false(is_incidental("name / language", 2, 10)) + assert_false(is_incidental("name / manifest mojoproject.toml", 0, 10)) + # History not read yet: its lines aren't known. + assert_false(is_incidental("push / push", 0, 0)) + + +def test_why() raises: + var w = incidental_why(2) + assert_true("only through a pushed commit" in w, w) + assert_true("2 lines of Mojo now, under 50" in w, w) + assert_true("1 line of Mojo" in incidental_why(1)) + + +def test_top_tables_leave_them_out() raises: + var stars: List[Int64] = [5663, 40, 135, 12] + var inc: List[Bool] = [True, False, True, False] + var kept = without_incidental(stars, inc) + assert_equal(kept[0], 0) + assert_equal(kept[1], 40) + var top = top_gains(kept, 10) + assert_equal(len(top), 2) + assert_equal(top[0], 1) + assert_equal(top[1], 3) + # The values themselves are untouched. + assert_equal(stars[0], 5663) + + +def main() raises: + TestSuite.discover_tests[__functions_in_module()]().run() diff --git a/tests/test_mcp.mojo b/tests/test_mcp.mojo index 5d07a36..142cd66 100644 --- a/tests/test_mcp.mojo +++ b/tests/test_mcp.mojo @@ -87,9 +87,36 @@ def _state(per_minute: Int = 60, key: String = String()) raises -> Int: return Int(p) -def _router(state: Int) raises -> Router: +def _with_incidental() raises -> Cache: + """`_cache` and a third repo, an exercise collection with 2 lines of + Mojo that entered by a push: incidental, and the most starred.""" + var c = _cache() + var l = _lib("someone/exercises", "Exercises in 40 languages", List[String](), 5663) + l.found_by = "name,push / push" + l.mojo_lines = 2 + c.lines.append(l.mojo_lines) + c.files.append(l.mojo_files) + c.stars.append(l.stars) + c.forks.append(l.forks) + c.used_by.append(0) + c.buckets.append("pre-1.0") + c.families.append("25.x") + c.est_buckets.append("pre-1.0") + c.est_families.append("25.x") + c.news.append(0) + c.active.append(True) + c.commits30.append(1) + c.categories.append("") + c.history.append(Int64(l.commits)) + c.libs.append(l^) + c.incidental = [False, False, True] + c.ov.incidental = 1 + return c^ + + +def _router(state: Int, incidental: Bool = False) raises -> Router: var p = unsafe_alloc[Swap[Cache]](1) - p.unsafe_write(Swap[Cache](_cache())) + p.unsafe_write(Swap[Cache](_with_incidental() if incidental else _cache())) var pc = unsafe_alloc[Swap[CheckRun]](1) pc.unsafe_write(Swap[CheckRun](CheckRun())) var pm = unsafe_alloc[Swap[QueryModel]](1) @@ -262,6 +289,30 @@ def test_list_repos() raises: assert_true('"total":2' in recent) +def test_list_repos_incidental() raises: + var r = _router(_state(), incidental=True) + var s = _body(_post(r, _call("list_repos", "{}"))) + assert_true('"total":2,"incidental_left_out":1' in s, s) + assert_false("someone/exercises" in s) + var all = _body(_post(r, _call("list_repos", '{"incidental":true}'))) + assert_true('"total":3,"incidental_left_out":0' in all, all) + # The most starred comes first once included, marked. + assert_true('"results":[{"repo":"someone/exercises"' in all, all) + assert_true('"incidental":true' in all) + assert_true('"url":"https://mojourney.dev/repos?sort=stars&incidental=1"' in all) + assert_true('"isError":true' in _body(_post(r, _call("list_repos", '{"incidental":"yes"}')))) + # Its own answer still works, and says why. + var one = _body(_post(r, _call("get_repo", '{"repo":"someone/exercises"}'))) + assert_true('"found_by":"name,push / push","incidental":true,"incidental_why":"It entered the census only' in one, one) + var other = _body(_post(r, _call("get_repo", '{"repo":"acme/http"}'))) + assert_true('"incidental":false' in other) + assert_false("incidental_why" in other) + # Search still finds it. + assert_true("someone/exercises" in _body(_post(r, _call("search_repos", '{"query":"exercises"}')))) + assert_true('"incidental_repos_left_out":1' in _body(_post(r, _call("overview", "{}")))) + assert_true('"incidental":{"type":"boolean"' in _body(_post(r, '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'))) + + def test_get_repo() raises: var r = _router(_state()) var s = _body(_post(r, _call("get_repo", '{"repo":"acme/tomlkit"}'))) diff --git a/tests/test_overview.mojo b/tests/test_overview.mojo index 5ebb224..e6f9d8a 100644 --- a/tests/test_overview.mojo +++ b/tests/test_overview.mojo @@ -4,7 +4,7 @@ sorting and filtering, and the charts' text. pixi run test """ -from std.testing import TestSuite, assert_equal, assert_true +from std.testing import TestSuite, assert_equal, assert_false, assert_true from charts import compact, compact_bytes, donut, grid_line, line_chart, nice_ceil from jscan import days_from_civil @@ -16,6 +16,7 @@ from listing import ( parse_list_query, select_repos, sorted_by, + with_incidental, with_version, ) from overview import ( @@ -442,5 +443,82 @@ def test_add_repo_twice_and_recent() raises: assert_equal(r.lines_delta[2], 5) +def test_finish_leaves_out_skipped() raises: + """An incidental repo (`skip`) counts in no total, bucket or series, and + `incidental` says how many were left out.""" + var skip = Dict[String, Bool]() + skip["o/b"] = True + var ov = _small().finish(4, skip) + var all = _small().finish(4) + assert_equal(ov.repos, 3) + assert_equal(ov.incidental, 1) + assert_equal(all.incidental, 0) + assert_equal(ov.with_history, 2) + assert_equal(ov.commits, 3) + assert_equal(ov.lines, 150 + 10) + assert_equal(ov.commits_30, 1) + assert_equal(ov.lines_30_ago, 110) + assert_equal(ov.active, 1) + # b was the pre-1.0 bucket's only repo. + assert_false("pre-1.0" in ov.buckets) + assert_true("pre-1.0" in all.buckets) + var buckets = 0 + for n in ov.bucket_repos: + buckets += n + assert_equal(buckets, 3) + # The series: b's two commits and its lines are gone from every month. + var commits = Int64(0) + var commits_all = Int64(0) + for v in ov.commits_series: + commits += v + for v in all.commits_series: + commits_all += v + assert_equal(commits, 3) + assert_equal(commits_all, 5) + assert_equal(ov.lines_series[len(ov.lines_series) - 1], 160) + assert_equal(ov.repos_series[len(ov.repos_series) - 1], 2) + assert_equal(all.repos_series[len(all.repos_series) - 1], 3) + + +def test_select_incidental() raises: + """The Repos table leaves incidental repos out unless `incidental=1`, + under every sort and filter.""" + var lines: List[Int64] = [900, 500, 40, 2] + var files: List[Int64] = [9, 5, 1, 1] + var stars: List[Int64] = [3, 40, 0, 5663] + var fams: List[String] = ["1.x", "1.x", "unknown", "unknown"] + var active: List[Bool] = [True, True, True, True] + var inc: List[Bool] = [False, False, False, True] + var none = List[String]() + var no_news = List[Int]() + var no64 = List[Int64]() + var by_stars = select_repos( + parse_list_query("stars", "", "", ""), lines, files, stars, fams, active, none, no_news, no64, no64, no64, + none, inc, + ) + assert_equal(len(by_stars), 3) + assert_equal(by_stars[0], 1) + var q = parse_list_query("stars", "", "", "", "", "", "", "1") + assert_true(q.incidental) + assert_equal(list_url(q), "/repos?sort=stars&incidental=1") + var with_them = select_repos(q, lines, files, stars, fams, active, none, no_news, no64, no64, no64, none, inc) + assert_equal(len(with_them), 4) + assert_equal(with_them[0], 3) + var unknown = select_repos( + parse_list_query("", "", "unknown", ""), lines, files, stars, fams, active, none, no_news, no64, no64, no64, + none, inc, + ) + assert_equal(len(unknown), 1) + assert_equal(unknown[0], 2) + # Including them isn't a filter, and every link keeps it. + assert_false(q.has_filter()) + assert_equal(list_url(sorted_by(q, "lines")), "/repos?incidental=1") + assert_equal(list_url(with_version(q, "1.x")), "/repos?sort=stars&version=1.x&incidental=1") + assert_equal(list_url(with_incidental(q, False)), "/repos?sort=stars") + assert_false(parse_list_query("", "", "", "", "", "", "", "yes").incidental) + # No marks given: nothing is left out. + assert_equal(len(select_repos(parse_list_query("", "", "", ""), lines, files, stars, fams, active)), 4) + + def main() raises: TestSuite.discover_tests[__functions_in_module()]().run() From 3286bdebb8a49753e6b72777e4b597d7029e4cd1 Mon Sep 17 00:00:00 2001 From: Marius S <39998+winding-lines@users.noreply.github.com> Date: Sun, 29 Nov 2026 21:15:57 -0800 Subject: [PATCH 2/3] Changelog fragment for #268 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017TycsyUqdnuDeZrYc3z6wV --- changes/268-incidental-mojo.minor.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/268-incidental-mojo.minor.md diff --git a/changes/268-incidental-mojo.minor.md b/changes/268-incidental-mojo.minor.md new file mode 100644 index 0000000..5d170e2 --- /dev/null +++ b/changes/268-incidental-mojo.minor.md @@ -0,0 +1 @@ +- **Incidental Mojo left out of the rankings**: repos that entered only by a pushed commit and have under 50 lines of Mojo are left out of the Repos table, the Overview and `list_repos` unless asked for with `?incidental=1`. (#268) From 7bfe485daf8fa755ec149292606f7c5b9b2c72f8 Mon Sep 17 00:00:00 2001 From: Marius S <39998+winding-lines@users.noreply.github.com> Date: Sun, 29 Nov 2026 21:38:35 -0800 Subject: [PATCH 3/3] Not incidental when the name or description says Mojo A `name` or `description` signal in found_by means the repository's name or description mentions Mojo, as rd4com/mojo-learning's does: it is a Mojo repository however little code it has, so it is no longer incidental. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017TycsyUqdnuDeZrYc3z6wV --- README.md | 3 ++- src/console_list.mojo | 3 ++- src/console_mcp.mojo | 3 ++- src/incidental.mojo | 15 ++++++++++----- tests/test_incidental.mojo | 10 ++++++++-- tests/test_mcp.mojo | 4 ++-- 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index d757cfe..e3bf7b0 100644 --- a/README.md +++ b/README.md @@ -250,7 +250,8 @@ GH Archive ──gharchive──▶ gharchive.events ──mojo_repos──▶ m tooling share, the repos rising in stars), the repos by size and age (`/repos`, sortable by lines, files or stars with `?sort=`, filterable with `?version=1.x` and `?active=1y`; incidental Mojo repos, which - entered only by a pushed commit and have fewer than 50 lines of Mojo, are + entered only by a pushed commit (no `language`, manifest, search, or Mojo in + the name or description) and have fewer than 50 lines of Mojo, are left out of it and of the Overview's numbers unless `?incidental=1`: `src/incidental.mojo`), search by name, topic or description (`/search`), the Mojo versions they moved to over time diff --git a/src/console_list.mojo b/src/console_list.mojo index 94340a9..2443b57 100644 --- a/src/console_list.mojo +++ b/src/console_list.mojo @@ -221,7 +221,8 @@ def _filter_options(q: ListQuery, c: Cache) -> String: def incidental_title() -> String: """What incidental Mojo means, in a line for a tooltip.""" return String( - "Repos that entered the census only through a pushed commit that changed a .mojo file, and have fewer than ", + "Repos that entered the census only through a pushed commit that changed a .mojo file, with no Mojo in", + " their name or description, and have fewer than ", INCIDENTAL_LINES, " lines of Mojo", ) diff --git a/src/console_mcp.mojo b/src/console_mcp.mojo index c10ce8c..b175c4a 100644 --- a/src/console_mcp.mojo +++ b/src/console_mcp.mojo @@ -395,7 +395,8 @@ def tools_json() -> String: "List Mojo repos ranked by stars, by commits in the last 30 days (commits), by their last" " commit (recent), or by rising (stars, forks and dependents gained in 30 days; the top 10" " only), optionally only one Mojo version, one category or the ones active in the last year." - " Incidental Mojo repos (entered only through a pushed commit that changed a .mojo file, under ", + " Incidental Mojo repos (entered only through a pushed commit that changed a .mojo file, with no" + " Mojo in their name or description, under ", INCIDENTAL_LINES, " lines of Mojo) are left out unless `incidental` is true.", DATA_NOTE, ) diff --git a/src/incidental.mojo b/src/incidental.mojo index cabc256..8f7de2d 100644 --- a/src/incidental.mojo +++ b/src/incidental.mojo @@ -8,8 +8,10 @@ GitHub says its main language is Mojo (`language`), a `pixi.toml` or changed a `.mojo` or `.🔥` file (`push`). The first two say the repository is a Mojo project; the third only that it has some Mojo. A repository is incidental when it entered by `push` alone (GitHub's search, which gives -`language:Mojo` repositories, didn't give it either) and its history, once -read, has fewer than `INCIDENTAL_LINES` lines of Mojo at its last commit. +`language:Mojo` repositories, didn't give it either, and its name and +description don't say Mojo: no `name` or `description` signal) and its +history, once read, has fewer than `INCIDENTAL_LINES` lines of Mojo at its +last commit. Incidental repositories stay in the data and keep their pages; the Repos table, the Overview's numbers and top tables and the MCP `list_repos` tool @@ -45,11 +47,13 @@ def signals_of(found_by: String) -> List[String]: def push_only(found_by: String) -> Bool: """Whether the repository entered only by a pushed commit: accepted by - `push`, and not given by GitHub's search for `language:Mojo`.""" + `push`, not given by GitHub's search for `language:Mojo`, and with no + `name` or `description` signal (its name or description says Mojo, so it + is a Mojo repository however little code it has yet).""" if how_of(found_by) != "push": return False for ref s in signals_of(found_by): - if s == "search": + if s == "search" or s == "name" or s == "description": return False return True @@ -66,7 +70,8 @@ def incidental_why(mojo_lines: Int64) -> String: `get_repo`.""" return String( "It entered the census only through a pushed commit that changed a .mojo file (GitHub didn't", - " say its main language is Mojo, and no pixi.toml or mojoproject.toml names a Mojo package),", + " say its main language is Mojo, no pixi.toml or mojoproject.toml names a Mojo package, and its", + " name and description don't mention Mojo),", " and it has ", mojo_lines, " line" if mojo_lines == 1 else " lines", " of Mojo now, under ", INCIDENTAL_LINES, ". It is left out of the rankings and the overview's numbers by default.", ) diff --git a/tests/test_incidental.mojo b/tests/test_incidental.mojo index 520862f..18af234 100644 --- a/tests/test_incidental.mojo +++ b/tests/test_incidental.mojo @@ -33,7 +33,10 @@ def test_how_and_signals() raises: def test_push_only() raises: assert_true(push_only("push / push")) - assert_true(push_only("name,description,push / push")) + # The name or the description says Mojo: a Mojo repo, however small. + assert_false(push_only("name,push / push")) + assert_false(push_only("description,push / push")) + assert_false(push_only("name,description,push / push")) # Accepted by GitHub's language or a manifest, even with a push signal. assert_false(push_only("push / language")) assert_false(push_only("name,push / manifest pixi.toml")) @@ -46,7 +49,10 @@ def test_is_incidental() raises: assert_equal(INCIDENTAL_LINES, 50) # mouredev/retos-programacion-2023: 2 lines, entered by a push. assert_true(is_incidental("push / push", 2, 5990)) - assert_true(is_incidental("name,description,push / push", 0, 119)) + # rd4com/mojo-learning: 0 lines, but its name and description say Mojo. + assert_false(is_incidental("name,description,push / push", 0, 119)) + assert_false(is_incidental("name,push / push", 2, 2)) + assert_false(is_incidental("description,push / push", 2, 2)) assert_true(is_incidental("push / push", INCIDENTAL_LINES - 1, 3)) assert_false(is_incidental("push / push", INCIDENTAL_LINES, 3)) assert_false(is_incidental("push / push", 4_000, 3)) diff --git a/tests/test_mcp.mojo b/tests/test_mcp.mojo index 142cd66..d053369 100644 --- a/tests/test_mcp.mojo +++ b/tests/test_mcp.mojo @@ -92,7 +92,7 @@ def _with_incidental() raises -> Cache: Mojo that entered by a push: incidental, and the most starred.""" var c = _cache() var l = _lib("someone/exercises", "Exercises in 40 languages", List[String](), 5663) - l.found_by = "name,push / push" + l.found_by = "push / push" l.mojo_lines = 2 c.lines.append(l.mojo_lines) c.files.append(l.mojo_files) @@ -303,7 +303,7 @@ def test_list_repos_incidental() raises: assert_true('"isError":true' in _body(_post(r, _call("list_repos", '{"incidental":"yes"}')))) # Its own answer still works, and says why. var one = _body(_post(r, _call("get_repo", '{"repo":"someone/exercises"}'))) - assert_true('"found_by":"name,push / push","incidental":true,"incidental_why":"It entered the census only' in one, one) + assert_true('"found_by":"push / push","incidental":true,"incidental_why":"It entered the census only' in one, one) var other = _body(_post(r, _call("get_repo", '{"repo":"acme/http"}'))) assert_true('"incidental":false' in other) assert_false("incidental_why" in other)