Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/interplane-forge/blob/main/visits/tests/run.sh # interplane-forge INTERPLANE Forge Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `interplane-forge / visits / tests / run.sh` 199 lines ยท 12999 bytes Raw Blame History 1 #!/bin/sh 2 # visits/tests/run.sh: gate for visits.om (the owner's view of who visited). 3 # OMC=/abs/seed/out/omc sh visits/tests/run.sh 4 # Makes a log of 6,000 requests over three days from 31 addresses to 9 projects, the first 3,000 in 5 # the seven-field form (before forged logged the agent) and the rest with agent and referrer, with 6 # seven kinds of line that must be skipped, and requires visits.tsv to equal what awk, sort and uniq 7 # compute from the same log (the oracle never runs the program under test). Then the page and the 8 # file modes. Negative controls: each mutant at the end of this file changes one line of visits.om 9 # and must not pass. 10 set -u 11 HERE=$(cd "$(dirname "$0")" && pwd) 12 V=$HERE/.. 13 OMC=${OMC:-$HOME/canon/omega-mv/seed/out/omc} 14 PIN=`34d611ca0415eab1728d3234911d90e74af17ba9ab0c581d559f48274d7ca6d3` 15 T=$(mktemp -d) || exit 2 16 trap 'rm -rf "$T"' EXIT 17 pass=0 18 fail=0 19 ok() { pass=$((pass + 1)); echo "PASS $1"; } 20 no() { fail=$((fail + 1)); echo "FAIL $1"; } 21 eq() { if [ "$2" = "$3" ]; then ok "$1"; else no "$1: got '$2' want '$3'"; fi; } 22 23 got=$(sha256sum "$OMC" 2>/dev/null | cut -d' ' -f1) 24 if [ "$got" != "$PIN" ]; then 25 echo "compiler pin mismatch: $got" >&2 26 exit 2 27 fi 28 "$OMC" <"$V/visits.om" >"$T/visits" 2>"$T/visits.err" 29 eq "compile exit" "$?" 0 30 chmod +x "$T/visits" 31 32 # the log: deterministic, no clock and no random source 33 awk 'BEGIN { 34 split("/ /explore /galaxy /drakestapleton/omega-mv/blob/abc/x.om /drakestapleton/omega-mv /drakestapleton/CUDApp/tree/main?tab=1 /drakestapleton/aienux/ /assets/galaxy.css /drakestapleton/a&\"c/raw /search?q=x", P, " ") 35 split("200 200 200 303 404 200 500 200 200 304", S, " ") 36 t = `1794182400` 37 for (i = 0; i < 6000; i++) { 38 t += (i * 7) % 61 39 ip = (i % 31 < 4) ? sprintf("2001:db8::%x", i % 31) : sprintf("203.0.113.%d", i % 31) 40 p = P[(i * 7 + int(i / 13)) % 10 + 1]; s = S[(i * 3) % 10 + 1] 41 split("Mozilla/5.0+(compatible;+Googlebot/2.1;++http://www.google.com/bot.html) Mozilla/5.0+(X11;+Linux+x86_64)+Firefox/130.0 - AhrefsBOT/7.0 ExampleCRAWLer/1.0 Baiduspider+2 Yahoo!+Slurp curl/8.5.0 Mozilla/5.0+(compatible;+GoogleOther) Mozilla/5.0+(Macintosh)+Version/17.0+Safari/605.1.15 python-requests/2.32.3 Mozilla/5.0+(X11;+Linux+x86_64)+HeadlessChrome/140.0.0.0+Safari/537.36", A, " ") 42 m = i % 31; ag = A[m % 12 + 1]; if (m == 9 && i % 2) ag = A[1] 43 if (i < 3000) printf "%d %s %d %s %s %d %d\n", t, ip, 1 + (i % 3 == 0), p, s, (i * 37) % 9000, i % 50 44 else printf "%d %s %d %s %s %d %d %s %s\n", t, ip, 1 + (i % 3 == 0), p, s, (i * 37) % 9000, i % 50, ag, (i % 4) ? "-" : "https://example.org/a+page" 45 if (i % 1000 == 500) print "forged: reloaded, public repos 30" 46 if (i % 1000 == 501) printf "%d 198.51.100.9 1 nopath 200 5 1\n", t 47 if (i % 1000 == 502) printf "soon 198.51.100.9 1 / 200 5 1\n" 48 if (i % 1000 == 503) printf "%d 198.51.100.9 1 / 200 5 1 extra\n", t 49 if (i % 1000 == 504) printf "%d 198.51.100.9 1 / 2x0 5 1\n", t 50 if (i % 1000 == 505) printf "%d 198.51.100.9 1 / 200 5 1 a b c\n", t 51 if (i == 2505) { printf "%d 198.51.100.9 1 /", t; for (k = 0; k < 5000; k++) printf "a"; print " 200 5 1" } 52 } 53 }' >"$T/log" 54 eq "log lines" "$(wc -l <"$T/log" | tr -d ' ')" 6037 55 56 # the oracle 57 awk -F' ' ' 58 function key(p, q) { q = p; sub(/\?.*/, "", q); if (match(q, /^\/[^\/]*(\/[^\/]*)?/)) q = substr(q, 1, RLENGTH); return q } 59 (NF != 7 && NF != 9) || $1 !~ /^[0-9]+$/ || $5 !~ /^[0-9]+$/ || $6 !~ /^[0-9]+$/ || substr($4, 1, 1) != "/" || length($0) > 4095 { skip++; next } 60 { 61 n++; by += $6; if (!first) first = $1; last = $1; if (n == 1) fd = int($1 / 86400) 62 c = int($5 / 100); if (c >= 2 && c <= 5) cls[c]++ 63 if (!($2 in vr)) { nv++; vf[$2] = $1 } 64 vr[$2]++; vb[$2] += $6; vl[$2] = $1 65 d = int($1 / 86400); if (d < fd || d - fd >= 512) out++; else { dr[d]++; if (!((d, $2) in du)) { du[d, $2] = 1; dn[d]++ } } 66 k = key($4); if (!(k in pr)) np++ 67 pr[k]++; if (!((k, $2) in pu)) { pu[k, $2] = 1; pn[k]++ } 68 if (NF == 7) un++ 69 else if ($8 == "-") nn++ 70 else if (tolower($8) ~ /bot|crawl|spider|slurp|googleother|google-|mediapartners|feedfetcher|facebookexternalhit|preview|curl|wget|python|go-http|java\/|scrapy|httpclient|libwww|headless|okhttp|aiohttp|axios|node-fetch/) { cr++; kind[$2] = "c" } 71 else { ot++; if (kind[$2] != "c") kind[$2] = "o" } 72 } 73 END { 74 printf "T\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t0\t0\t%d\n", n, nv, np, by, first, last, cls[2], cls[3], cls[4], cls[5], skip, out 75 for (d in dr) printf "D\t%d\t%d\t%d\n", d, dr[d], dn[d] 76 for (k in pr) printf "P\t%s\t%d\t%d\n", k, pr[k], pn[k] 77 for (a in vr) { k = (a in kind) ? kind[a] : "-"; if (k == "c") kc++; if (k == "o") ko++; printf "V\t%s\t%d\t%d\t%d\t%d\t%s\n", a, vr[a], vb[a], vf[a], vl[a], k } 78 printf "A\t%d\t%d\t%d\t%d\t%d\t%d\n", cr, ot, nn, un, kc, ko 79 }' "$T/log" | while IFS=' ' read -r a b rest; do 80 if [ "$a" = D ]; then printf 'D\t%s\t%s\n' "$(date -u -d "@$((b * 86400))" +%F)" "$rest"; else printf '%s\t%s\t%s\n' "$a" "$b" "$rest"; fi 81 done | sort >"$T/want.tsv" 82 83 mkdir "$T/w" 84 (cd "$T/w" && "$T/visits" "$T/log") 85 eq "run exit" "$?" 0 86 sort "$T/w/visits.tsv" >"$T/got.tsv" 87 if cmp -s "$T/got.tsv" "$T/want.tsv"; then ok "visits.tsv equals the awk oracle"; else no "visits.tsv equals the awk oracle"; diff "$T/got.tsv" "$T/want.tsv" | head -12; fi 88 eq "oracle saw 31 visitors and 9 projects" "$(grep -c '^V' "$T/want.tsv") $(grep -c '^P' "$T/want.tsv")" "31 9" 89 eq "seven kinds of bad line were skipped" "$(grep '^T' "$T/want.tsv" | cut -f12)" 37 90 AL=$(grep '^A' "$T/want.tsv") 91 eq "oracle saw all four kinds of request and both kinds of visitor" "$(printf '%s\n' "$AL" | awk -F'\t' '{ print ($2 > 0 && $3 > 0 && $4 > 0 && $5 == 3000 && $6 > 0 && $7 > 0) }')" 1 92 eq "an address that used a crawler name and a browser name is a crawler" "$(grep -c "^V 203.0.113.9 .* c$" "$T/want.tsv")" 1 93 eq "page names crawlers or tools and browsers" "$(grep -c '