From ffd23bfd13a2f009f4c1c6b355a5f895969f81fd Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Mon, 20 Jul 2026 10:18:48 -1000 Subject: Gate the stats page and add a language breakdown `max-stats` only bounds the selectable periods now and no longer doubles as the enable switch. The tree walk runs before the history walk on purpose. Releasing commit memory while walking history resets each commit slab index, and a commit graph lookup afterwards would read another commit slot and walk the wrong tree. The stats fixture writes a commit graph so the tests cover that path. The history walk bounds the window in process rather than passing a formatted since date to `setup_revisions`, and parses each commit once. --- tests/t0202-stats.sh | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100755 tests/t0202-stats.sh (limited to 'tests') diff --git a/tests/t0202-stats.sh b/tests/t0202-stats.sh new file mode 100755 index 0000000..1589776 --- /dev/null +++ b/tests/t0202-stats.sh @@ -0,0 +1,81 @@ +#!/bin/sh + +test_description='Check the statistics page' +. ./setup.sh + +# The default test config carries no enable-stats. +test_expect_success 'stats are off by default' ' + cgit_url "foo/stats" >tmp && + grep "Status: 404" tmp && + cgit_url "foo" >tmp && + ! grep ">stats" tmp +' + +# A repo with one commit dated now, so the authors table has something +# to count beside the 2005-dated fixture commits. The commit graph +# makes the language walk take the graph lookup path, which once +# returned another commit after the history walk released memory. +test_expect_success 'set up a stats config' ' + mkrepo repos/pulse 2 && + ( + cd repos/pulse && + GIT_AUTHOR_DATE="@$(date +%s) +0000" \ + GIT_COMMITTER_DATE="@$(date +%s) +0000" \ + git commit --allow-empty -m fresh && + git commit-graph write --reachable + ) && + { + echo "virtual-root=/" && + echo "cache-size=0" && + echo "enable-stats=1" && + echo "repo.url=stat" && + echo "repo.path=$PWD/repos/pulse/.git" + } >statsrc && + { + echo "virtual-root=/" && + echo "cache-size=0" && + echo "enable-stats=1" && + echo "max-stats=month" && + echo "repo.url=stat" && + echo "repo.path=$PWD/repos/pulse/.git" + } >statmaxrc +' + +statq() { CGIT_CONFIG="$PWD/statsrc" QUERY_STRING="$1" cgit; } + +test_expect_success 'stats tab appears when enabled' ' + statq "url=stat/" >tmp && + grep ">stats" tmp +' + +test_expect_success 'stats page renders both sections' ' + statq "url=stat/stats/" >tmp && + grep "

Languages" tmp && + grep "

Commits per author" tmp +' + +test_expect_success 'stat options sit above the content' ' + tr -d "\n" Commits per author.*//" | grep "cgit-panel" +' + +test_expect_success 'extensionless fixture files fold into Other' ' + grep "LanguageSizeShare" tmp && + grep "class=.left.>Other" tmp +' + +test_expect_success 'all four periods offered when max-stats is unset' ' + statq "url=stat/stats/" >tmp && + grep "