11#! /bin/sh
22# L1: unit tests — fast, no external deps, no Docker.
33#
4- # Time guard: each successful run is appended to .test-time-log and the
5- # elapsed time is compared against .test-time-baseline. Both files are
6- # committed so the history is visible and shared.
4+ # Time guard: elapsed seconds are compared against .test-time-baseline.
5+ # The baseline file is committed so the reference survives machine changes.
76#
8- # .test-time-baseline — last recorded elapsed time (seconds), updated on
9- # every pass. Fail if current > baseline * 1.5.
10- # .test-time-log — append-only history: one line per run, format:
11- # ISO8601 elapsed_s git_sha branch
7+ # .test-time-baseline — last recorded elapsed time (seconds). Updated on
8+ # every passing run. Fail if current > baseline * 1.5.
129#
13- # To reset the baseline after intentional perf change:
10+ # To reset after an intentional perf change:
1411# echo <new_seconds> > .test-time-baseline
15- # git add .test-time-baseline .test-time-log && git commit -m "perf: reset test baseline"
12+ # git add .test-time-baseline && git commit -m "perf: reset test baseline"
1613
1714REPO=" $( git rev-parse --show-toplevel) "
1815LOG_FILE=" ${REPO} /.test-fail.log"
1916BASELINE_FILE=" ${REPO} /.test-time-baseline"
20- TIMELOG_FILE=" ${REPO} /.test-time-log"
2117rm -f " $LOG_FILE "
2218
2319echo " pre-commit: running unit tests..."
@@ -36,12 +32,6 @@ END=$(date +%s)
3632ELAPSED=$(( END - START))
3733rm -f " $LOG_FILE "
3834
39- # Append to time log.
40- SHA=$( git rev-parse --short HEAD 2> /dev/null || echo " unknown" )
41- BRANCH=$( git rev-parse --abbrev-ref HEAD 2> /dev/null || echo " unknown" )
42- TS=$( date -u +" %Y-%m-%dT%H:%M:%SZ" )
43- printf " %s\t%ss\t%s\t%s\n" " $TS " " $ELAPSED " " $SHA " " $BRANCH " >> " $TIMELOG_FILE "
44-
4535# Time guard: compare against last successful run.
4636if [ -f " $BASELINE_FILE " ]; then
4737 BASELINE=$( cat " $BASELINE_FILE " )
@@ -52,14 +42,11 @@ if [ -f "$BASELINE_FILE" ]; then
5242 echo " Current: ${ELAPSED} s" >&2
5343 echo " Baseline: ${BASELINE} s (limit: ${THRESHOLD} s = baseline × 1.5)" >&2
5444 echo " " >&2
55- tail -10 " $TIMELOG_FILE " | awk -F' \t' ' {printf " %s\t%s\n", $1, $2}' >&2
56- echo " " >&2
5745 echo " To reset: echo ${ELAPSED} > .test-time-baseline" >&2
5846 exit 1
5947 fi
6048fi
6149
62- # Update baseline to the current run so the guard tracks recent history .
50+ # Update baseline to current run time .
6351echo " $ELAPSED " > " $BASELINE_FILE "
64-
6552echo " pre-commit: unit tests passed (${ELAPSED} s)."
0 commit comments