clone

a personal forge on plain git: static pages, stacked-diff reviews, signed local ci, repo sites and releases

main
forge / test / scenarios / lake-truncate.sh
lake-truncate.sh 2.3K
1# cmd_build cuts events.jsonl to its last 1000 lines once it passes 1 MB,2# into a new file. The lake picks up after the last line it read: what it3# had is kept, nothing is added twice, and lines appended before the cut4# that it hadn't read yet still arrive. A cut past where it had got to says5# so; only the lines that were gone by then are missing.6. "$(dirname "$0")/../lib.sh"7user dami8repo dami/greet9clone dami dami/greet "$T/w/d"10at "$T/w/d" commit "first"11push_as dami "$T/w/d" origin main12ev=$FORGE_ROOT/.forge/events.jsonl13pad=$(printf '%0360d' 0)14# events from to: synthetic pushes, about 400 bytes each, numbered.15events() {16 awk -v a="$1" -v b="$2" -v p="$pad" 'BEGIN { for (i = a; i <= b; i++) printf "{\"t\":%d000,\"repo\":\"dami/greet\",\"type\":\"push\",\"user\":\"dami\",\"refs\":\"refs/heads/n%d %s\"}\n", 1788220800 + i, i, p }' >>"$ev"17}18synthetic() { lq "SELECT count(*) || ' ' || count(DISTINCT refs) FROM events WHERE refs LIKE 'refs/heads/n%'"; }19events 1 300020ok forge lake21has "$T_LOG" '^lake: added 3001 events,'22# 200 more, not read yet, then a build cuts the file.23events 3001 320024ino=$(ls -i "$ev" | awk '{ print $1 }')25build dami/greet26[ "$(ls -i "$ev" | awk '{ print $1 }')" != "$ino" ] || fail "the build didn't cut events.jsonl"27eq "$(wc -l <"$ev" | tr -d ' ')" 100028ok forge lake29has "$T_LOG" 'events.jsonl was cut or replaced; picked up where the last run left off'30has "$T_LOG" '^lake: added 201 events, 1 build,'31eq "$(synthetic)" "3200 3200"32eq "$(lq "SELECT count(*) FROM events WHERE type = 'built'")" 133# Appended to after the cut, the new file is read on from where it was.34events 3201 321035ok forge lake36has "$T_LOG" '^lake: added 10 events,'37eq "$(synthetic)" "3210 3210"38# Now a cut past the last line read: 2000 lines arrive and the build keeps39# the last 1000 of them (with its own event), so the first 1001 are gone.40events 3211 521041build dami/greet42ok forge lake43has "$T_LOG" 'events.jsonl was cut past where the last run left off; what was in between is gone'44has "$T_LOG" '^lake: added 1000 events,'45eq "$(synthetic)" "4209 4209"46n="CAST(regexp_extract(refs, 'n([0-9]+)', 1) AS INTEGER)"47eq "$(lq "SELECT count(*) FILTER ($n BETWEEN 3211 AND 4211) || ' ' || count(*) FILTER ($n BETWEEN 4212 AND 5210) FROM events WHERE refs LIKE 'refs/heads/n%'")" "0 999"