interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / server / tests / sitechrome.sh
| 1 | #!/usr/bin/env bash |
| 2 | # One site: every forged HTML page wears the interplane.io header and footer, and the two do not drift. |
| 3 | # bash server/tests/sitechrome.sh (spark; FORGED_CPUS default 4,5; FORGE_CHROME_PORT default 18574) |
| 4 | # The header, the footer and their stylesheet lines are generated at every build from the site source |
| 5 | # (server/chromegen.om, run by ./run.sh units into .build/chrome.om): forged is one program, the site |
| 6 | # has its own builder, and no copy is kept by hand. This gate checks the generated result against the |
| 7 | # site source, independently of the generator, and that a changed site reaches the forge with no edit. |
| 8 | # Reference (the source of truth): the interplane.io repository, read from SITE_SRC (a checkout) or, |
| 9 | # by default, from the canonical main of rad:z399yKvnXcBQNkKoq86iBDgTvQ5QV in local Radicle storage |
| 10 | # (git archive, read-only). content/_layout.html is read as the release build renders it with its |
| 11 | # optional data present (receipts, map, hop): {{#flag}} marks dropped, the TEST DATA banner removed; |
| 12 | # a {{^flag}} block refuses the run. Site-relative links are resolved against https://interplane.io. |
| 13 | # Checks, under both bases (/ and /forge/) on explore, a project page, its patches and issues, search, |
| 14 | # stars, login and a 404: |
| 15 | # 1. one site header, one Main nav, one footer; the brand goes to https://interplane.io/; Projects is |
| 16 | # the current entry; the page names no script and no inline style or decorative rope band |
| 17 | # 2. Main nav, header button, brand, all three footer columns and the SI line: markup, labels and |
| 18 | # absolute targets equal the reference; the footer's div structure is balanced |
| 19 | # 3. the forge row keeps its controls on the base: Explore, Stars, the entries the composed slices |
| 20 | # add (Open builds; Research on base / only), the search form, Sign in |
| 21 | # and on <base>assets/forge.css: |
| 22 | # 4. every line between the site-chrome marks is a whole line of the reference public/style.css, inside |
| 23 | # the same @-block; and every reference rule that names a header or footer class (CHROME_SEL) is |
| 24 | # copied, in its block, unless CHROME_SKIP names the rule or CHROME_SKIP_IN its block as left out |
| 25 | # 5. every custom property the forge :root shares with the site :root has the site's value, and the |
| 26 | # core tokens are shared; the stylesheet names no url() and no outside address |
| 27 | # 6. the Content-Security-Policy of every page is the one forged sent before this change |
| 28 | # Negative controls: a forged built with one nav label changed fails 2; reference copies with the |
| 29 | # Forge entry removed, a footer target changed, --paper changed and one copied CSS line changed fail |
| 30 | # 2, 2, 5 and 4; a forge stylesheet without the 380 px nav rule, a reference with one new header rule, |
| 31 | # a forge stylesheet with one copied rule moved out of its @media block and a forge stylesheet without |
| 32 | # the footer column heading rule (its text-transform must not exempt it) fail 4; and every line of the |
| 33 | # copied block, removed alone from forge.css (a sweep), fails 4. |
| 34 | # Entirely private: own port, own storage fixture, never 18480 or ~/forge-data. |
| 35 | set -euo pipefail |
| 36 | cd "$(dirname "$0")/../.." |
| 37 | OMC=$HOME/work/flux/omega-mv/seed/out/omc |
| 38 | PIN=3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194 |
| 39 | PORT=${FORGE_CHROME_PORT:-18574} |
| 40 | SITE_RID=z399yKvnXcBQNkKoq86iBDgTvQ5QV |
| 41 | CSP="default-src 'none'; style-src 'self'; img-src 'self'; script-src 'none'; form-action 'self'; frame-ancestors 'none'; base-uri 'none'" |
| 42 | case "$PORT" in 185[5-9][0-9]|1999[0-9]) ;; *) echo 'REFUSED: use a private port in 18550..18599 or 19990..19999'; exit 2;; esac |
| 43 | [ "$(sha256sum "$OMC" | cut -d' ' -f1)" = "$PIN" ] || { echo 'FAIL compiler pin'; exit 1; } |
| 44 | if ss -ltnH "sport = :$PORT" | grep -q .; then echo "NOT_RUN: private port $PORT busy"; exit 3; fi |
| 45 | T=$(mktemp -d) |
| 46 | pid= |
| 47 | pass=0 |
| 48 | ok() { pass=$((pass+1)); echo "PASS $*"; } |
| 49 | die() { echo "FAIL $*"; exit 1; } |
| 50 | cleanup() { |
| 51 | if [ -n "$pid" ]; then kill "$pid" 2>/dev/null || true; wait "$pid" 2>/dev/null || true; fi |
| 52 | if [ "${KEEP_TEST_TMP:-0}" = 1 ]; then echo "Evidence: $T"; else rm -rf "$T"; fi |
| 53 | } |
| 54 | trap cleanup EXIT |
| 55 | run() { taskset -c "${FORGED_CPUS:-4,5}" nice -n 10 "$@"; } |
| 56 | |
| 57 | # ---- the reference |
| 58 | mkdir -p "$T/ref" |
| 59 | if [ -n "${SITE_SRC:-}" ]; then |
| 60 | cp "$SITE_SRC/content/_layout.html" "$T/ref/layout.html" |
| 61 | cp "$SITE_SRC/public/style.css" "$T/ref/style.css" |
| 62 | REF="$SITE_SRC at $(git -C "$SITE_SRC" rev-parse HEAD 2>/dev/null || echo 'no git')" |
| 63 | export FORGE_SITE_SRC=$SITE_SRC |
| 64 | else |
| 65 | # the site repository: FORGE_SITE_STORE, else the frozen copy kept after the Radicle removal |
| 66 | S=${FORGE_SITE_STORE:-$HOME/radicle-storage-frozen/storage/$SITE_RID} |
| 67 | export FORGE_SITE_STORE=$S |
| 68 | SITE_SHA=$(git --git-dir="$S" rev-parse refs/heads/main) |
| 69 | git --git-dir="$S" archive "$SITE_SHA" content/_layout.html public/style.css | tar -x -C "$T/ref" |
| 70 | mv "$T/ref/content/_layout.html" "$T/ref/layout.html"; mv "$T/ref/public/style.css" "$T/ref/style.css" |
| 71 | REF="rad:$SITE_RID main $SITE_SHA" |
| 72 | # the build reads the same site commit as this reference, even if the site main moves meanwhile |
| 73 | export FORGE_SITE_REF=$SITE_SHA |
| 74 | fi |
| 75 | echo "reference: $REF" |
| 76 | |
| 77 | # flat FILE: one line, no newlines, without translate="no" (forged adds that hint when it sends a page, |
| 78 | # server/tr.om; the site layout may carry it too. A hint is not a label or a target, so it is not compared; the header count is checked on its own below) |
| 79 | flat() { tr -d '\n' < "$1" | sed 's/ translate="no"//g'; } |
| 80 | # release FILE: the layout as the release build renders it with all optional data |
| 81 | release() { |
| 82 | local f |
| 83 | f=$(flat "$1") |
| 84 | case "$f" in *'{{^'*) die "reference layout has a {{^flag}} block; teach this gate its rule";; esac |
| 85 | printf '%s' "$f" | sed -e 's/{{#test_data}}.*{{\/test_data}}//' -e 's/{{[#/][a-z_]*}}//g' |
| 86 | } |
| 87 | # cut TEXT START END: from the first START up to and including the next END |
| 88 | cut1() { awk -v s="$2" -v e="$3" '{ i = index($0, s); if (!i) exit 1; r = substr($0, i); j = index(r, e); if (!j) exit 1; print substr(r, 1, j + length(e) - 1) }' <<< "$1"; } |
| 89 | # links TEXT: one "label<TAB>absolute target" line per <a>, in order; ignores other attributes |
| 90 | links() { |
| 91 | grep -oE '<a [^>]*>[^<]*</a>' <<< "$1" | sed -E \ |
| 92 | -e 's|^<a [^>]*href="([^"]*)"[^>]*>(.*)</a>$|\2\t\1|' \ |
| 93 | -e 's|\t/|\thttps://interplane.io/|' |
| 94 | } |
| 95 | # absol TEXT: the markup with site-relative href values made absolute |
| 96 | absol() { sed -E 's|href="/|href="https://interplane.io/|g' <<< "$1"; } |
| 97 | |
| 98 | # parts FILE OUT: the compared parts of a page (or of the reference layout) into OUT.* |
| 99 | parts() { |
| 100 | local page=$1 o=$2 h f |
| 101 | h=$(cut1 "$page" '<header class="site-head">' '</header>') || return 1 |
| 102 | f=$(cut1 "$page" '<footer class="site-foot">' '</footer>') || return 1 |
| 103 | links "$(cut1 "$h" '<nav aria-label="Main">' '</nav>')" > "$o.nav" || return 1 |
| 104 | links "$(cut1 "$h" '<a class="btn btn-primary btn-sm"' '</a>')" > "$o.button" || return 1 |
| 105 | absol "$(cut1 "$h" '<a class="brand"' '</a>')" > "$o.brand" || return 1 |
| 106 | # The old foot-brand/nav.foot-cols became three div.foot-col inside div.foot-grid. |
| 107 | # Compare the entire grid (not just its links): headings, order, wrappers and attributes matter. |
| 108 | absol "$(cut1 "$f" '<div class="foot-grid">' '<div class="foot-base">')" > "$o.grid" || return 1 |
| 109 | sed -E 's|<p class="foot-h">([^<]*)</p>|\n# \1\n|g' "$o.grid" > "$o.cols.raw" |
| 110 | { while IFS= read -r l; do case "$l" in '# '*) printf '%s\n' "$l";; *) links "$l" || true;; esac; done < "$o.cols.raw"; } > "$o.cols" |
| 111 | absol "$(cut1 "$f" '<p class="si-line">' '</p>')" > "$o.si" || return 1 |
| 112 | } |
| 113 | release "$T/ref/layout.html" > "$T/ref/release.html" |
| 114 | parts "$(cat "$T/ref/release.html")" "$T/ref/p" || die "reference layout: header or footer part not found" |
| 115 | # Projects is the forge's entry; its target, not the former label Forge, determines current marking. |
| 116 | grep -qx $'Projects\thttps://interplane.io/explore' "$T/ref/p.nav" || die "reference Main nav has no Projects entry to https://interplane.io/explore" |
| 117 | [ "$(wc -l < "$T/ref/p.nav")" -ge 5 ] && [ "$(grep -c '^# ' "$T/ref/p.cols")" = 3 ] || die "reference parts look wrong: $(wc -l < "$T/ref/p.nav") nav entries" |
| 118 | ok "reference parts read: $(wc -l < "$T/ref/p.nav") Main nav entries, $(grep -vc '^# ' "$T/ref/p.cols") footer links in 3 columns" |
| 119 | |
| 120 | # cmpparts PREFIX WHAT: compare a page's parts with the reference; prints the first difference |
| 121 | cmpparts() { |
| 122 | local p=$1 x |
| 123 | for x in nav button brand grid cols si; do |
| 124 | if ! cmp -s "$T/ref/p.$x" "$p.$x"; then echo "$x differs:"; diff "$T/ref/p.$x" "$p.$x" | head -6; return 1; fi |
| 125 | done |
| 126 | } |
| 127 | |
| 128 | # ---- the forge, built from this tree |
| 129 | RID=z4ChromeFixtureRid1111111111 |
| 130 | mkdir -p "$T/repo" "$T/storage" "$T/data/logs" "$T/ng" "$T/bin" |
| 131 | cp server/tests/fake/rad server/tests/fake/getent "$T/bin/" |
| 132 | chmod 755 "$T/bin/rad" "$T/bin/getent" |
| 133 | : > "$T/ng/dl.log"; : > "$T/ng/access.log" |
| 134 | printf 'chrome fixture\n' > "$T/repo/README.md" |
| 135 | git -C "$T/repo" init -q -b main |
| 136 | git -C "$T/repo" add . |
| 137 | git -C "$T/repo" -c user.name=Fixture -c user.email=fixture@example.invalid commit -qm 'chrome fixture' |
| 138 | git clone -q --bare "$T/repo" "$T/storage/$RID" |
| 139 | printf '| repo | RID | default branch |\n|---|---|---|\n| chromefixture | rad:%s | main |\n' "$RID" > "$T/RIDS.md" |
| 140 | # STORE_VARIANT=1 (with IPL_DIR): the same gates on the store-reading build (the fixture made a store) |
| 141 | SV=${STORE_VARIANT:-0} |
| 142 | if [ "$SV" = 1 ]; then |
| 143 | bash store/tests/fixstore.sh "$T/RIDS.md" "$T/storage" "$T/store" || die "fixture store" |
| 144 | export FORGE_STORE=$T/store |
| 145 | echo "STORE_VARIANT: store-reading build, store $T/store" |
| 146 | fi |
| 147 | # build NAME [SED]: compose this tree's units with every live target moved into $T, compile to $T/NAME.bin |
| 148 | build() { |
| 149 | local name=$1 extra=() |
| 150 | [ -n "${2:-}" ] && extra=(-e "$2") |
| 151 | { printf 'om2\n'; for u in $(./run.sh units); do cat "$u"; done; } > "$T/$name.base.om" |
| 152 | sed -e "s|2130706433 18480|2130706433 $PORT|" \ |
| 153 | -e "s|/home/drakestapleton/handoffs/radicle/RIDS.md|$T/RIDS.md|g" \ |
| 154 | -e "s|/home/drakestapleton/.radicle/storage/|$T/storage/|g" \ |
| 155 | -e "s|/home/drakestapleton/forge-data/|$T/data/|g" \ |
| 156 | -e "s|^text tfzp0 \".*\"|text tfzp0 \"$T/ng/dl.log\"|" \ |
| 157 | -e "s|^text tfzp1 \".*\"|text tfzp1 \"$T/ng/access.log\"|" \ |
| 158 | -e "s|^text tfzwal \".*\"|text tfzwal \"$T/ng/wal\"|" \ |
| 159 | -e "s|^text tfzrad \".*\"|text tfzrad \"$T/bin/rad\"|" \ |
| 160 | -e "s|^text tfzspth \".*\"|text tfzspth \"$T/counts.snapshot\"|" \ |
| 161 | -e "s|^text tfzgent \".*\"|text tfzgent \"$T/bin/getent\"|" "${extra[@]}" "$T/$name.base.om" > "$T/$name.om" |
| 162 | local marks=("2130706433 $PORT" "$T/RIDS.md" "$T/storage/" "$T/data/") |
| 163 | [ "$SV" = 1 ] && marks=("2130706433 $PORT" "$T/store/" "$T/data/") |
| 164 | for marker in "${marks[@]}"; do grep -qF "$marker" "$T/$name.om"; done |
| 165 | if grep -qE '2130706433 18480|/home/drakestapleton/(forge-data|\.radicle|handoffs/radicle)' "$T/$name.om"; then |
| 166 | die "live target remains in $name" |
| 167 | fi |
| 168 | run "$OMC" < "$T/$name.om" > "$T/$name.bin" 2> "$T/$name.err" || { cat "$T/$name.err"; die "compile $name"; } |
| 169 | chmod 755 "$T/$name.bin" |
| 170 | } |
| 171 | start() { |
| 172 | FORGE_SOCIAL_DIR="$T/data/" taskset -c "${FORGED_CPUS:-4,5}" nice -n 10 "$T/$1.bin" > "$T/$1.log" 2>&1 & |
| 173 | pid=$! |
| 174 | for _ in $(seq 50); do |
| 175 | kill -0 "$pid" 2>/dev/null || die "$1 server exited during startup" |
| 176 | curl --max-time 1 -fsS -o /dev/null "http://127.0.0.1:$PORT/explore" && return 0 |
| 177 | sleep 0.1 |
| 178 | done |
| 179 | die "$1 server not ready" |
| 180 | } |
| 181 | stop() { kill "$pid" 2>/dev/null || true; wait "$pid" 2>/dev/null || true; pid=; } |
| 182 | # get PATH BASE: status on stdout; body $T/body, headers $T/hdr |
| 183 | get() { |
| 184 | local p=$1 b=$2; shift 2 |
| 185 | curl --max-time 10 -sS -o "$T/body" -D "$T/hdr" -H "X-Forge-Base: $b" "$@" "http://127.0.0.1:$PORT/$p" -w '%{http_code}' |
| 186 | } |
| 187 | hdr() { grep -i "^$1:" "$T/hdr" | head -1 | tr -d '\r' | cut -d' ' -f2-; } |
| 188 | PAGES="explore:200 drakestapleton/chromefixture:200 drakestapleton/chromefixture/patches:200 drakestapleton/chromefixture/issues:200 search?q=chrome:200 stars:303 login:200 no-such-page-xyz:404" |
| 189 | # Both builds serve patch and issue lists: the store build uses patch/ and collab/native/. |
| 190 | # Keep the same 200 + chrome checks there, rather than the old pre-native 501 expectations. |
| 191 | # pagechecks BASE: checks 1 to 3 and 6 on every page; returns 1 with the reason on the first failure |
| 192 | pagechecks() { |
| 193 | local b=$1 pc page want code body cur |
| 194 | for pc in $PAGES; do |
| 195 | page=${pc%:*}; want=${pc##*:} |
| 196 | code=$(get "$page" "$b") |
| 197 | [ "$code" = "$want" ] || { echo "$b$page HTTP $code, expected $want"; return 1; } |
| 198 | # stars without a session sends the visitor to sign in: no page of its own to check |
| 199 | if [ "$code" = 303 ]; then |
| 200 | [ "$(hdr location)" = "${b}login" ] || { echo "$b$page Location '$(hdr location)'"; return 1; } |
| 201 | continue |
| 202 | fi |
| 203 | [ "$(hdr content-security-policy)" = "$CSP" ] || { echo "$b$page CSP '$(hdr content-security-policy)'"; return 1; } |
| 204 | body=$(flat "$T/body") |
| 205 | [ "$(grep -o '<header class="site-head">' <<< "$body" | wc -l)" = 1 ] || { echo "$b$page: site header missing or repeated"; return 1; } |
| 206 | [ "$(grep -o '<nav aria-label="Main">' <<< "$body" | wc -l)" = 1 ] || { echo "$b$page: Main nav missing or repeated"; return 1; } |
| 207 | [ "$(grep -o '<footer class="site-foot">' <<< "$body" | wc -l)" = 1 ] || { echo "$b$page: site footer missing or repeated"; return 1; } |
| 208 | if grep -qiE '<script|<style| style="' <<< "$body"; then echo "$b$page: script or inline style"; return 1; fi |
| 209 | parts "$body" "$T/pg" || { echo "$b$page: a compared part was not found"; return 1; } |
| 210 | cmpparts "$T/pg" || { echo " on $b$page"; return 1; } |
| 211 | cur=$(cut1 "$body" '<nav aria-label="Main">' '</nav>' | grep -o '<a [^>]*aria-current="[a-z]*"[^>]*>[^<]*</a>' || true) |
| 212 | [ "$cur" = '<a href="https://interplane.io/explore" aria-current="true">Projects</a>' ] || { echo "$b$page: current entry is '$cur'"; return 1; } |
| 213 | grep -qF '<a class="brand" href="https://interplane.io/" aria-label="Interplane home">' <<< "$body" || { echo "$b$page: brand target"; return 1; } |
| 214 | if grep -qE 'rope-band|foot-rope|strand-thread|\{\{' <<< "$body"; then echo "$b$page: page decoration or unresolved layout mark copied"; return 1; fi |
| 215 | cut1 "$body" '<footer class="site-foot">' '</footer>' | sed 's/></>\n</g' | |
| 216 | awk '/^<div([ >])/{n++} /^<\/div>/{n--; if(n<0) bad=1} END{exit (bad || n)}' || |
| 217 | { echo "$b$page: unbalanced footer divs"; return 1; } |
| 218 | # slice entries after Stars: Open builds on every base; Research on base / only; Bring your build |
| 219 | # only while the salvage store is on, and it is off in this build; Feed (door/ evnav) on every base |
| 220 | # (the store-reading build composes open/ out: no Open builds entry there) |
| 221 | more="<a href=\"${b}open/\">Open builds</a>"; [ "$SV" = 1 ] && more="" |
| 222 | [ "$b" = / ] && more="$more<a href=\"/research\">Research</a>" |
| 223 | more="$more<a href=\"${b}feed\">Feed</a>" |
| 224 | grep -qF "<nav class=\"forge-nav\" aria-label=\"Forge\"><a href=\"${b}explore\">Explore</a><a href=\"${b}stars\">Stars</a>$more</nav><form class=\"search\" method=\"get\" action=\"${b}search\" role=\"search\">" <<< "$body" || { echo "$b$page: forge row controls"; return 1; } |
| 225 | grep -qF "<div class=\"who\"><a href=\"${b}login\">Sign in</a></div>" <<< "$body" || { echo "$b$page: Sign in"; return 1; } |
| 226 | done |
| 227 | } |
| 228 | # ctxlines FILE: "<enclosing @-block line or ->TAB<rule line>" for every rule line of a stylesheet |
| 229 | ctxlines() { awk '/^@[^}]*\{$/{c=$0; next} /^\}+$/{c=""; next} {print (c == "" ? "-" : c) "\t" $0}' "$1"; } |
| 230 | # The reference rules the chrome needs: a header/footer class or the btn/primary/small header button. |
| 231 | # CHROME_SKIP: the rules left out on purpose (print, hopbot.org's nav.short, buttons in page sections, |
| 232 | # the Hop page's night hero, whose .hop-stage .shell rule (site 1daf702) only positions its own rings, |
| 233 | # the reading measure of main p, the decorative foot-rope), matched on the rule; CHROME_SKIP_IN: motion |
| 234 | # matched on the enclosing @-block, so a property name such as text-transform exempts nothing. |
| 235 | # A new or changed site rule outside both must be copied. |
| 236 | # The page-wide base rules the chrome stands on (box model, body palette and type, link look, code |
| 237 | # face) are named exactly by their selector; a header or footer class is matched anywhere in the rule. |
| 238 | export CHROME_SEL='^(\*|html|body|a|a:hover|a:active|a:focus-visible,summary:focus-visible|code,pre,\.mono)\{|\.(site-head|head-inner|brand|site-foot|foot-[a-z]+|si-line|skip|shell|btn|btn-primary|btn-sm)([^a-z-]|$)' |
| 239 | export CHROME_SKIP='^@media print|nav\.short|^main p:where|^\.(invite|actions) \.button|^\.hop-stage |^\.foot-rope' |
| 240 | export CHROME_SKIP_IN='prefers-reduced-motion' |
| 241 | # csschecks STYLE: checks 4 and 5 of the stylesheet in $T/css against the reference STYLE |
| 242 | csschecks() { |
| 243 | local style=$1 n=0 l name val sv |
| 244 | awk '/^\/\* site chrome: copied from interplane.io public\/style.css \*\/$/{on=1; next} /^\/\* end site chrome \*\/$/{on=0; next} on' "$T/css" > "$T/chrome.lines" |
| 245 | [ "$(wc -l < "$T/chrome.lines")" -ge 30 ] || { echo "site-chrome block missing or short ($(wc -l < "$T/chrome.lines") lines)"; return 1; } |
| 246 | # every @-block of the copy is closed by its own } before the next one opens (a lost } nests blocks) |
| 247 | awk '/^@[^}]*\{$/{ if (o) bad=1; o=1; next } /^\}+$/{ if (!o) bad=1; o=0 } END{ exit (bad || o) }' "$T/chrome.lines" || { echo "copied @-blocks are not closed one by one"; return 1; } |
| 248 | while IFS= read -r l; do |
| 249 | grep -qxF -- "$l" "$style" || { echo "copied line is not in the site stylesheet: $l"; return 1; } |
| 250 | n=$((n+1)) |
| 251 | done < "$T/chrome.lines" |
| 252 | head -1 "$style" | grep -oE -- '--[a-z0-9-]+:[^;}]*' > "$T/site.tokens" |
| 253 | head -1 "$T/css" | grep -oE -- '--[a-z0-9-]+:[^;}]*' > "$T/forge.tokens" |
| 254 | for name in --paper --ink --muted --line --orange --orange-ink; do |
| 255 | grep -q -- "^$name:" "$T/forge.tokens" || { echo "core token $name is not in the forge :root"; return 1; } |
| 256 | done |
| 257 | while IFS= read -r l; do |
| 258 | name=${l%%:*}; val=${l#*:} |
| 259 | sv=$(grep -- "^$name:" "$T/site.tokens" | head -1 | cut -d: -f2-) || true |
| 260 | if [ -n "$sv" ] && [ "$sv" != "$val" ]; then echo "token $name: forge $val, site $sv"; return 1; fi |
| 261 | done < "$T/forge.tokens" |
| 262 | if grep -qiE 'url\(|https?:|@import' "$T/css"; then echo "forge.css names a url or an outside address"; return 1; fi |
| 263 | ctxlines "$style" > "$T/site.ctx" |
| 264 | ctxlines "$T/chrome.lines" > "$T/chrome.ctx" |
| 265 | while IFS= read -r l; do |
| 266 | grep -qxF -- "$l" "$T/site.ctx" || { echo "copied line sits in another block than on the site: $l"; return 1; } |
| 267 | done < "$T/chrome.ctx" |
| 268 | awk -F'\t' '$2 ~ ENVIRON["CHROME_SEL"] && $2 !~ ENVIRON["CHROME_SKIP"] && $1 !~ ENVIRON["CHROME_SKIP_IN"]' "$T/site.ctx" > "$T/chrome.want" |
| 269 | [ "$(wc -l < "$T/chrome.want")" -ge 30 ] || { echo "reference chrome rules look wrong: $(wc -l < "$T/chrome.want")"; return 1; } |
| 270 | while IFS= read -r l; do |
| 271 | grep -qxF -- "$l" "$T/chrome.ctx" || { echo "site chrome rule not copied: $l"; return 1; } |
| 272 | done < "$T/chrome.want" |
| 273 | echo "$n copied lines (all $(wc -l < "$T/chrome.want") site chrome rules, each in its block), $(wc -l < "$T/forge.tokens") tokens" |
| 274 | } |
| 275 | |
| 276 | build new |
| 277 | start new |
| 278 | for base in / /forge/; do |
| 279 | r=$(pagechecks "$base") || die "base $base: $r" |
| 280 | ok "base $base: explore, project, patches, issues, search, stars, login, 404: one site header and footer equal to the reference, Projects current, brand to https://interplane.io/, forge row on the base, CSP unchanged" |
| 281 | code=$(get assets/forge.css "$base"); [ "$code" = 200 ] || die "${base}assets/forge.css HTTP $code" |
| 282 | cp "$T/body" "$T/css" |
| 283 | r=$(csschecks "$T/ref/style.css") || die "stylesheet: $r" |
| 284 | ok "base $base: assets/forge.css: $r equal to the reference, no url() or outside address" |
| 285 | done |
| 286 | code=$(get explore / -H 'Accept: application/json'); [ "$code" = 200 ] && ! grep -q 'site-head' "$T/body" || die "explore JSON carries the chrome (HTTP $code)" |
| 287 | ok "JSON answers carry no page chrome" |
| 288 | # translate="no" hints: the forge header carries at least the ones the site header has (forged may add more when it sends) |
| 289 | code=$(get explore /); [ "$code" = 200 ] || die "explore HTTP $code" |
| 290 | trhints() { tr -d '\n' < "$1" | sed -e 's|.*<header class="site-head">||' -e 's|</header>.*||' | grep -o 'translate="no"' | wc -l; } |
| 291 | hp=$(trhints "$T/body") |
| 292 | hr=$(trhints "$T/ref/layout.html") |
| 293 | [ "$hp" -ge "$hr" ] || die "translate hints: the page header has $hp, fewer than the site header's $hr" |
| 294 | ok "translate=\"no\" hints in the header: $hp on the page (send-time hints of server/tr.om included), at least the $hr of the site layout" |
| 295 | kill -0 "$pid" || die "server died" |
| 296 | stop |
| 297 | |
| 298 | # ---- negative controls |
| 299 | build lab 's|>Mission</a>|>Missions</a>|' |
| 300 | grep -q '>Missions</a>' "$T/lab.om" || die "control lab: the label mutation did not apply" |
| 301 | start lab |
| 302 | if r=$(pagechecks /); then die "control: a forged with the nav label Missions passed"; fi |
| 303 | grep -q 'nav differs' <<< "$r" || die "control lab failed for another reason: $r" |
| 304 | ok "NEG forged with one Main nav label changed: refused ($(head -1 <<< "$r"))" |
| 305 | stop |
| 306 | start new |
| 307 | code=$(get explore /); [ "$code" = 200 ] || die "explore HTTP $code" |
| 308 | parts "$(flat "$T/body")" "$T/pg" || die "page parts" |
| 309 | # mutant NAME FILE SEDEXPR: a copy of the reference with one change, in $T/n-NAME/ |
| 310 | mutant() { |
| 311 | mkdir -p "$T/n-$1"; cp "$T/ref/layout.html" "$T/ref/style.css" "$T/n-$1/" |
| 312 | sed -i -e "$3" "$T/n-$1/$2" |
| 313 | if cmp -s "$T/ref/$2" "$T/n-$1/$2"; then die "control $1: the mutation did not apply"; fi |
| 314 | } |
| 315 | mutant noforge layout.html 's|<a href="https://interplane.io/explore">Projects</a>||' |
| 316 | parts "$(release "$T/n-noforge/layout.html")" "$T/n-noforge/p" || die "control noforge: parts" |
| 317 | if cmp -s "$T/n-noforge/p.nav" "$T/pg.nav"; then die "control noforge: a reference without Forge compares equal"; fi |
| 318 | ok "NEG reference without the Forge entry: Main nav differs" |
| 319 | mutant foot layout.html 's|<a href="/privacy/">Privacy</a>|<a href="/privacy-x/">Privacy</a>|' |
| 320 | parts "$(release "$T/n-foot/layout.html")" "$T/n-foot/p" || die "control foot: parts" |
| 321 | if cmp -s "$T/n-foot/p.cols" "$T/pg.cols"; then die "control foot: a changed footer target compares equal"; fi |
| 322 | ok "NEG reference with one footer target changed: footer columns differ" |
| 323 | code=$(get assets/forge.css /); [ "$code" = 200 ] || die "forge.css HTTP $code" |
| 324 | cp "$T/body" "$T/css" |
| 325 | mutant paper style.css '1s/--paper:[^;]*/--paper:#ff0000/' |
| 326 | if r=$(csschecks "$T/n-paper/style.css"); then die "control paper: a changed --paper passed"; fi |
| 327 | grep -q 'token --paper' <<< "$r" || die "control paper failed for another reason: $r" |
| 328 | ok "NEG reference with --paper changed: refused ($r)" |
| 329 | mutant line style.css 's/^\.head-inner,\.head-row{display:flex;align-items:center;gap:24px;min-height:64px}$/.head-inner,.head-row{display:flex;align-items:center;gap:30px;min-height:64px}/' |
| 330 | if r=$(csschecks "$T/n-line/style.css"); then die "control line: a changed copied line passed"; fi |
| 331 | grep -q 'copied line' <<< "$r" || die "control line failed for another reason: $r" |
| 332 | ok "NEG reference with one copied line changed: refused" |
| 333 | # The old 480 px grid-nav rule became the 380 px nav-font rule: still a mobile-only rule. |
| 334 | NAVSM='.site-head nav a{font-size:13px}' |
| 335 | grep -qxF "$NAVSM" "$T/css" || die "control omit380: the rule is not in forge.css" |
| 336 | grep -vxF "$NAVSM" "$T/body" > "$T/css" |
| 337 | if r=$(csschecks "$T/ref/style.css"); then die "control omit380: a forge.css without the 380 px nav rule passed"; fi |
| 338 | grep -q 'rule not copied' <<< "$r" || die "control omit380 failed for another reason: $r" |
| 339 | ok "NEG forge stylesheet without the 380 px nav rule: refused" |
| 340 | cp "$T/body" "$T/css" |
| 341 | mutant addrule style.css 's/^\.site-head{[^}]*}$/&\n.site-head{position:relative}/' |
| 342 | if r=$(csschecks "$T/n-addrule/style.css"); then die "control addrule: a reference with a new header rule passed"; fi |
| 343 | grep -qF $'rule not copied: -\t.site-head{position:relative}' <<< "$r" || die "control addrule failed for another reason: $r" |
| 344 | ok "NEG reference with one new header rule: refused" |
| 345 | grep -qx '@media(max-width:380px){' "$T/css" || die "control moved: no 380 px block in forge.css" |
| 346 | grep -vx '@media(max-width:380px){' "$T/body" > "$T/css" |
| 347 | if r=$(csschecks "$T/ref/style.css"); then die "control moved: rules moved out of their @media block passed"; fi |
| 348 | grep -qE "another block|not closed one by one" <<< "$r" || die "control moved failed for another reason: $r" |
| 349 | ok "NEG forge stylesheet with the 380 px rules out of their block: refused" |
| 350 | cp "$T/body" "$T/css" |
| 351 | FOOTH='.foot-col .foot-h,.foot-cols .foot-h{margin:0 0 10px;font-family:ui-monospace,SFMono-Regular,"SF Mono",Menlo,Consolas,monospace;font-size:12px;font-weight:500;letter-spacing:.1em;text-transform:uppercase;color:var(--muted)}' |
| 352 | grep -qxF "$FOOTH" "$T/css" || die "control omitfooth: the rule is not in forge.css" |
| 353 | grep -vxF "$FOOTH" "$T/body" > "$T/css" |
| 354 | if r=$(csschecks "$T/ref/style.css"); then die "control omitfooth: a forge.css without the footer column heading rule passed"; fi |
| 355 | grep -q 'rule not copied' <<< "$r" || die "control omitfooth failed for another reason: $r" |
| 356 | ok "NEG forge stylesheet without the footer column heading rule: refused" |
| 357 | # Sweep (bays 4 and 1 each found a copied rule no check needed): every line of the copied block, |
| 358 | # removed alone from the served forge.css, must be refused. A line that passes is a gap in check 4. |
| 359 | code=$(get assets/forge.css /); [ "$code" = 200 ] || die "forge.css HTTP $code" |
| 360 | cp "$T/body" "$T/css.orig" |
| 361 | awk '/^\/\* site chrome: copied from interplane.io public\/style.css \*\/$/{on=1; next} /^\/\* end site chrome \*\/$/{on=0} on' "$T/css.orig" > "$T/sweep.lines" |
| 362 | k=0; gaps= |
| 363 | while IFS= read -r l; do |
| 364 | k=$((k+1)) |
| 365 | awk -v k="$k" '/^\/\* site chrome: copied from interplane.io public\/style.css \*\/$/{on=1; print; next} /^\/\* end site chrome \*\/$/{on=0} { if (on) { i++; if (i == k) next } print }' "$T/css.orig" > "$T/css" |
| 366 | [ "$(wc -l < "$T/css")" = "$(( $(wc -l < "$T/css.orig") - 1 ))" ] || die "sweep line $k: the deletion did not apply" |
| 367 | if csschecks "$T/ref/style.css" > /dev/null; then gaps="$gaps $k:$l"; fi |
| 368 | done < "$T/sweep.lines" |
| 369 | [ -z "$gaps" ] || die "sweep: removing these copied lines is not refused:$gaps" |
| 370 | ok "NEG sweep: each of the $k copied lines, removed alone from forge.css, is refused" |
| 371 | cp "$T/css.orig" "$T/css" |
| 372 | stop |
| 373 | |
| 374 | # ---- the forge follows the site with no edit (the chrome is generated at build, server/chromegen.om) |
| 375 | # A site checkout with one Main nav label changed and one new header rule: a build from it shows the |
| 376 | # new label and serves the new rule in its block, and still passes checks 4 and 5 against that site. |
| 377 | mkdir -p "$T/follow/content" "$T/follow/public" |
| 378 | sed 's|>Mission</a>|>Missions</a>|' "$T/ref/layout.html" > "$T/follow/content/_layout.html" |
| 379 | sed 's/^\.site-head{[^}]*}$/&\n.site-head{position:relative}/' "$T/ref/style.css" > "$T/follow/public/style.css" |
| 380 | cmp -s "$T/ref/layout.html" "$T/follow/content/_layout.html" && die "follow: the layout change did not apply" |
| 381 | cmp -s "$T/ref/style.css" "$T/follow/public/style.css" && die "follow: the stylesheet change did not apply" |
| 382 | FORGE_SITE_SRC=$T/follow build follow |
| 383 | start follow |
| 384 | code=$(get explore /); [ "$code" = 200 ] || die "follow: explore HTTP $code" |
| 385 | grep -qF '>Missions</a>' "$T/body" && grep -qF '<a href="https://interplane.io/explore" aria-current="true">Projects</a>' "$T/body" || die "follow: the changed site label or current Projects entry is not on the page" |
| 386 | code=$(get assets/forge.css /); [ "$code" = 200 ] || die "follow: forge.css HTTP $code" |
| 387 | cp "$T/body" "$T/css" |
| 388 | grep -qxF '.site-head{position:relative}' "$T/css" || die "follow: the new site header rule is not in forge.css" |
| 389 | r=$(csschecks "$T/follow/public/style.css") || die "follow: stylesheet against the changed site: $r" |
| 390 | ok "a changed site (one nav label, one new header rule) reaches a build with no forge edit: label on the page, rule served ($r)" |
| 391 | stop |
| 392 | # ---- a site layout the generator cannot read stops the build, with the reason |
| 393 | mkdir -p "$T/broken/content" "$T/broken/public" |
| 394 | sed 's|<header class="site-head">|<header class="site-top">|' "$T/ref/layout.html" > "$T/broken/content/_layout.html" |
| 395 | cp "$T/ref/style.css" "$T/broken/public/style.css" |
| 396 | rc=0; FORGE_SITE_SRC=$T/broken ./run.sh chrome > "$T/broken.out" 2> "$T/broken.err" || rc=$? |
| 397 | [ "$rc" != 0 ] && grep -q 'chromegen: the layout has no <header class="site-head">' "$T/broken.err" || die "broken layout: run.sh chrome rc $rc, $(head -c 300 "$T/broken.err")" |
| 398 | ok "NEG a site layout without the site header: ./run.sh chrome stops (rc $rc) and names why" |
| 399 | sed 's|{{#receipts}}|{{^receipts}}|' "$T/ref/layout.html" > "$T/broken/content/_layout.html" |
| 400 | rc=0; FORGE_SITE_SRC=$T/broken ./run.sh chrome > "$T/broken.out" 2> "$T/broken.err" || rc=$? |
| 401 | [ "$rc" != 0 ] && grep -q 'chromegen: the site header or footer holds a {{ mark' "$T/broken.err" || die "broken mark: run.sh chrome rc $rc, $(head -c 300 "$T/broken.err")" |
| 402 | ok "NEG a {{^flag}} mark in the site header: ./run.sh chrome stops (rc $rc) and names why" |
| 403 | # New layout hazards: a changed footer container must not leave the forge's footer unclosed, and |
| 404 | # a missing CSS block terminator must not silently flatten the following responsive rules. |
| 405 | cp "$T/ref/layout.html" "$T/broken/content/_layout.html" |
| 406 | sed 's|</div></footer>|<aside>changed</aside></div></footer>|' "$T/ref/layout.html" > "$T/broken/content/_layout.html" |
| 407 | rc=0; FORGE_SITE_SRC=$T/broken ./run.sh chrome > "$T/broken.out" 2> "$T/broken.err" || rc=$? |
| 408 | [ "$rc" != 0 ] && grep -q 'chromegen: the footer has something other than </div>' "$T/broken.err" || die "broken footer tail: rc $rc" |
| 409 | ok "NEG unsupported footer tail stops chrome generation with its reason" |
| 410 | cp "$T/ref/layout.html" "$T/broken/content/_layout.html" |
| 411 | awk '!lost && /^}$/ {lost=1; next} {print}' "$T/ref/style.css" > "$T/broken/public/style.css" |
| 412 | rc=0; FORGE_SITE_SRC=$T/broken ./run.sh chrome > "$T/broken.out" 2> "$T/broken.err" || rc=$? |
| 413 | [ "$rc" != 0 ] && grep -q 'chromegen: unsupported or unbalanced stylesheet block' "$T/broken.err" || die "broken CSS block: rc $rc" |
| 414 | ok "NEG missing CSS block terminator stops chrome generation with its reason" |
| 415 | ./run.sh chrome > /dev/null || die "run.sh chrome on the real site failed after the controls" |
| 416 | sha256sum "$OMC" "$T/new.om" "$T/new.bin" "$T/lab.bin" |
| 417 | echo "sitechrome.sh: PASS $pass (reference $REF)" |