interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / research / tests / refresh-transport.sh
| 1 | #!/bin/sh |
| 2 | # Private HTTPS oracle and actual wrapper/decoder/publisher. No public access or credentials. |
| 3 | set -eu |
| 4 | cd "$(dirname "$0")/../.." |
| 5 | ROOT=$PWD |
| 6 | T=$(mktemp -d /tmp/research-refresh.XXXXXXXX) |
| 7 | SERVER=; WORKER= |
| 8 | cleanup() { for pid in "$WORKER" "$SERVER"; do [ -z "$pid" ] || kill "$pid" 2>/dev/null || :; done; rm -rf "$T"; } |
| 9 | trap cleanup EXIT |
| 10 | trap 'exit 1' HUP INT TERM |
| 11 | pass=0; fail=0 |
| 12 | ok(){ pass=$((pass+1)); echo "PASS refresh $*"; } |
| 13 | bad(){ fail=$((fail+1)); echo "FAIL refresh $*"; } |
| 14 | check(){ if "$@"; then ok "$*"; else bad "$*"; fi; } |
| 15 | sh research/build-tools.sh "$T/bin" |
| 16 | export RESEARCH_TOOLS=$T/bin |
| 17 | D1=did:key:z6MkAbcdefghijkmnopqrstuvw111111111111111111111 |
| 18 | D2=did:key:z6MkAbcdefghijkmnopqrstuvw222222222222222222222 |
| 19 | O1=0009-0002-6890-7111 |
| 20 | O2=0000-0002-1825-0097 |
| 21 | export O1 O2 |
| 22 | mkdir -p "$T/adapter" "$T/curlhome" |
| 23 | # Only public fixture hostnames are SANs. The key and trust anchor never leave this test folder. |
| 24 | openssl req -x509 -newkey rsa:2048 -nodes -days 1 -subj /CN=research-private-test \ |
| 25 | -addext 'subjectAltName=DNS:zenodo.org,DNS:sandbox.zenodo.org' \ |
| 26 | -keyout "$T/key.pem" -out "$T/cert.pem" >/dev/null 2>&1 |
| 27 | cat > "$T/server.py" <<'PY' |
| 28 | import http.server,ssl,sys,pathlib,json,urllib.parse,time,threading |
| 29 | p=pathlib.Path(sys.argv[1]);lock=threading.Lock() |
| 30 | class H(http.server.BaseHTTPRequestHandler): |
| 31 | def log_message(self,*args):pass |
| 32 | def do_GET(self): |
| 33 | with lock: |
| 34 | with (p/'requests').open('a') as f:f.write(self.path+'\n') |
| 35 | url=urllib.parse.urlsplit(self.path);path=urllib.parse.unquote(url.path) |
| 36 | mode=(p/'mode').read_text().strip() if (p/'mode').exists() else '' |
| 37 | if mode.startswith('pause') and ((mode=='pause-api' and path=='/api/records') or ('/files/' in path and mode!='pause-api')): |
| 38 | (p/'ready').touch() |
| 39 | for _ in range(600): |
| 40 | if (p/'go').exists():break |
| 41 | time.sleep(.05) |
| 42 | else:self.send_error(504);return |
| 43 | if mode in ('pause-fail','pause-api'):self.send_error(503);return |
| 44 | if path=='/escaped':data=b'ESCAPED_CURLRC\n' |
| 45 | elif path.endswith('/redirect'): |
| 46 | self.send_response(302);self.send_header('Location','https://zenodo.org/escaped');self.end_headers();return |
| 47 | elif '/files/' in path: |
| 48 | data=(p/'paper.pdf').read_bytes() if path.endswith('.pdf') else ((p/'text-body').read_bytes() if (p/'text-body').exists() else b'FRESH_LITERAL_FULLTEXT\n\n') |
| 49 | elif path=='/api/records': |
| 50 | data=b'{"hits":{"total":0,"hits":[]}}' if urllib.parse.parse_qs(url.query).get('page',['1'])[0]!='1' else (p/'api.json').read_bytes() |
| 51 | elif path.startswith('/api/records/'): |
| 52 | data=json.dumps(json.loads((p/'api.json').read_text())['hits']['hits'][0]).encode() |
| 53 | else:self.send_error(404);return |
| 54 | self.send_response(200);self.send_header('Content-Length',str(len(data)));self.end_headers();self.wfile.write(data) |
| 55 | s=http.server.ThreadingHTTPServer(('127.0.0.1',0),H) |
| 56 | c=ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER);c.load_cert_chain(p/'cert.pem',p/'key.pem');s.socket=c.wrap_socket(s.socket,server_side=True) |
| 57 | (p/'port').write_text(str(s.server_port));s.serve_forever() |
| 58 | PY |
| 59 | # Normal adapter adds only loopback routing and CA; production flags are untouched. Controls remove |
| 60 | # exactly one guard. A public network route is impossible for either admitted fixture hostname. |
| 61 | cat > "$T/adapter/curl" <<'PY' |
| 62 | #!/usr/bin/python3 |
| 63 | import os,sys,json,pathlib |
| 64 | p=pathlib.Path(os.environ['FIXTURE_ROOT']);args=sys.argv[1:] |
| 65 | with (p/'argv').open('a') as f:f.write(json.dumps(args)+'\n') |
| 66 | control=os.environ.get('CURL_CONTROL','') |
| 67 | if control=='glob':args.remove('--globoff') |
| 68 | if control=='rc':args.remove('-q') |
| 69 | port=(p/'port').read_text();extra=['--cacert',str(p/'cert.pem'),'--connect-to','zenodo.org:443:127.0.0.1:'+port,'--connect-to','sandbox.zenodo.org:443:127.0.0.1:'+port] |
| 70 | if args and args[0]=='-q':args=[args[0]]+extra+args[1:] |
| 71 | else:args=extra+args |
| 72 | for i,a in enumerate(args): |
| 73 | if a=='--url' and not args[i+1].startswith(('https://zenodo.org/','https://sandbox.zenodo.org/')):raise SystemExit(2) |
| 74 | os.execv('/usr/bin/curl',['curl']+args) |
| 75 | PY |
| 76 | chmod 700 "$T/adapter/curl" |
| 77 | export FIXTURE_ROOT=$T PATH="$T/adapter:$PATH" CURL_HOME=$T/curlhome |
| 78 | python3 "$T/server.py" "$T" > "$T/server.log" 2>&1 & SERVER=$! |
| 79 | await(){ n=0; while [ ! -e "$1" ]; do n=$((n+1)); [ "$n" -lt 600 ] || { cat "$T/server.log" >&2; return 1; }; sleep .05; done; } |
| 80 | await "$T/port" |
| 81 | # Independent PDF fixture; all extraction goes through the actual authorised transient decoder. |
| 82 | python3 - "$T/paper.pdf" <<'PY' |
| 83 | import sys |
| 84 | stream=b'BT /F1 12 Tf 20 100 Td (SCOPED_PDF_PARAGRAPH.) Tj ET' |
| 85 | objs=[b'<< /Type /Catalog /Pages 2 0 R >>',b'<< /Type /Pages /Kids [3 0 R] /Count 1 >>',b'<< /Type /Page /Parent 2 0 R /MediaBox [0 0 300 200] /Resources << /Font << /F1 4 0 R >> >> /Contents 5 0 R >>',b'<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>',b'<< /Length '+str(len(stream)).encode()+b' >>\nstream\n'+stream+b'\nendstream'] |
| 86 | x=b'%PDF-1.4\n';offsets=[0] |
| 87 | for i,obj in enumerate(objs,1):offsets.append(len(x));x+=str(i).encode()+b' 0 obj\n'+obj+b'\nendobj\n' |
| 88 | pos=len(x);x+=b'xref\n0 6\n0000000000 65535 f \n'+b''.join(f'{o:010d} 00000 n \n'.encode() for o in offsets[1:])+b'trailer\n<< /Root 1 0 R /Size 6 >>\nstartxref\n'+str(pos).encode()+b'\n%%EOF\n';open(sys.argv[1],'wb').write(x) |
| 89 | PY |
| 90 | records(){ |
| 91 | python3 - "$T/api.json" "$1" "${2:-$O1}" <<'PY' |
| 92 | import json,sys |
| 93 | path,mode,orcid=sys.argv[1:] |
| 94 | def rec(i,ext): |
| 95 | r={'id':i,'doi':f'10.5281/zenodo.{i}','metadata':{'title':f'Fresh {mode} {i}','description':'public abstract','publication_date':'2026-11-12','license':{'id':'cc-by-4.0'},'creators':[{'name':'Fixture, Author','orcid':orcid}]}} |
| 96 | if ext:r['files']=[{'key':'paper.'+ext,'size':200,'links':{'self':f'https://zenodo.org/api/records/{i}/files/paper.'+ext}}] |
| 97 | return r |
| 98 | if mode=='pdfpdf':rs=[rec(201,'pdf'),rec(202,'pdf')] |
| 99 | elif mode=='txtpdf':rs=[rec(201,'txt'),rec(202,'pdf')] |
| 100 | elif mode=='empty':rs=[rec(201,None),rec(202,None)] |
| 101 | elif mode=='zip':rs=[rec(201,'zip'),rec(202,'zip')] |
| 102 | elif mode=='capacity': |
| 103 | rs=[rec(i,'txt' if i==1000 else None) for i in range(1000,1200)] |
| 104 | for r in rs:r['metadata']['description']='x'*12000 |
| 105 | elif mode=='fill':rs=[rec(i,'txt') for i in range(3000,3014)] |
| 106 | elif mode=='literal': |
| 107 | rs=[rec(201,'txt')];rs[0]['files'][0]['links']['self']='https://zenodo.org/api/records/201/files/literal{a,b}[1-2].txt' |
| 108 | elif mode=='glob': |
| 109 | rs=[rec(201,'txt')];rs[0]['files'][0]['links']['self']='https://zenodo.org/api/records/201/files/paper{a,b}.txt' |
| 110 | elif mode=='redirect': |
| 111 | rs=[rec(201,'txt')];rs[0]['files'][0]['links']['self']='https://zenodo.org/api/records/201/files/redirect' |
| 112 | else:rs=[rec(201,'txt')] |
| 113 | json.dump({'hits':{'total':len(rs),'hits':rs}},open(path,'w')) |
| 114 | PY |
| 115 | } |
| 116 | direct(){ sh research/sync.sh --zenodo "$O1" "$D1" 2026-11-12 "$O1" "$T/direct/a/$O1/zenodo.tsv"; } |
| 117 | publish_direct(){ |
| 118 | mkdir -p "$T/direct/show"; cp research/registry/catalog.tsv "$T/direct/catalog.tsv"; cp research/registry/text/*.txt "$T/direct/text/" |
| 119 | "$T/bin/research-sync" gather "$T/no-remove" "$T/no-shelf" < "$T/direct/a/$O1/zenodo.tsv" > "$T/direct/show/$O1.tsv" |
| 120 | sh research/publish.sh "$T/direct/site" "$T/direct/corpus" "$T/direct" > "$T/direct/publish.log" 2>&1 |
| 121 | } |
| 122 | records pdfpdf |
| 123 | direct > "$T/pdfpdf.log" 2>&1; publish_direct |
| 124 | check test "$(grep -c SCOPED_PDF_PARAGRAPH "$T/direct/corpus")" = 2 |
| 125 | records txtpdf |
| 126 | direct > "$T/txtpdf.log" 2>&1; publish_direct |
| 127 | check grep -q FRESH_LITERAL_FULLTEXT "$T/direct/corpus" |
| 128 | check grep -q SCOPED_PDF_PARAGRAPH "$T/direct/corpus" |
| 129 | # Fresh metadata with empty/zip-only files must not bind old immutable cache bytes. |
| 130 | for mode in empty zip; do |
| 131 | records "$mode"; direct > "$T/$mode.log" 2>&1; publish_direct |
| 132 | check test "$(grep '^T' "$T/direct/a/$O1/zenodo.tsv" | cut -f3 | grep -c '^-$')" = 2 |
| 133 | if grep -qE 'FRESH_LITERAL_FULLTEXT|SCOPED_PDF_PARAGRAPH' "$T/direct/corpus"; then bad "$mode stale text"; else ok "$mode metadata cannot reuse old cache"; fi |
| 134 | check test "$(find "$T/direct/text" -name 'z*.txt' ! -name '*.*.txt' | wc -l)" -eq 0 |
| 135 | done |
| 136 | # Actual curl, including search -G and bracket/brace attachment URLs. |
| 137 | : > "$T/requests"; records literal; direct > "$T/literal.log" 2>&1 |
| 138 | check test "$(grep -Fxc '/api/records/201/files/literal{a,b}[1-2].txt' "$T/requests")" = 1 |
| 139 | : > "$T/requests"; records glob; CURL_CONTROL=glob direct > "$T/glob-control.log" 2>&1 |
| 140 | check test "$(grep -c '^/api/records/201/files/paper[ab].txt$' "$T/requests")" = 2 |
| 141 | # Default-config attack enables redirect following: -q prevents /escaped, removing -q reaches it. |
| 142 | printf 'location\n' > "$CURL_HOME/.curlrc" |
| 143 | : > "$T/requests"; records redirect; direct > "$T/rc.log" 2>&1 |
| 144 | if grep -q '^/escaped$' "$T/requests"; then bad '.curlrc applied despite -q'; else ok '.curlrc ignored'; fi |
| 145 | : > "$T/requests"; CURL_CONTROL=rc direct > "$T/rc-control.log" 2>&1 |
| 146 | check grep -q '^/escaped$' "$T/requests" |
| 147 | rm "$CURL_HOME/.curlrc" |
| 148 | python3 - "$T/argv" <<'PY' |
| 149 | import json,sys |
| 150 | calls=list(map(json.loads,open(sys.argv[1]))) |
| 151 | for a in calls: |
| 152 | assert a[0]=='-q' and '--globoff' in a and a[a.index('--proxy')+1]=='' and a[a.index('--proto')+1]=='=https' and '--url' in a,a |
| 153 | assert not any(x.startswith('https://') for i,x in enumerate(a) if i==0 or a[i-1]!='--url'),a |
| 154 | assert any('-G' in a for a in calls) |
| 155 | print('PASS refresh actual curl argv: first -q, globoff, proxy empty, HTTPS, --url, search -G') |
| 156 | PY |
| 157 | pass=$((pass+1)) |
| 158 | # DOI is another owner: audit the real call without editing it. No token or deposit used here. |
| 159 | python3 - tools/doi/doi.sh <<'PY' |
| 160 | import pathlib,re,sys |
| 161 | s=pathlib.Path(sys.argv[1]).read_text();call=s[s.index(' curl -q'):].split(') || code=000',1)[0] |
| 162 | for t in ("--proto '=https'","--proxy ''",'--globoff','--url "$url"'):assert t in call,(t,call) |
| 163 | print('PASS refresh DOI real curl source contract (read-only audit)') |
| 164 | PY |
| 165 | pass=$((pass+1)) |
| 166 | newcase(){ c=$T/$1; mkdir -p "$c/add" "$c/reg"; printf '*\n' > "$c/allow"; : > "$c/remove"; : > "$c/list"; } |
| 167 | request(){ printf 'Z\t%s\t%s\t\n' "$1" "$2" >> "$c/add/queue"; } |
| 168 | worker(){ sh "${1:-research/sync.sh}" --queue "$c/add/" "$c/state" "$c/allow" "$c/remove" "$c/reg/" "$c/list" "$c/store" > "$c/log" 2>&1; } |
| 169 | publish(){ sh research/publish.sh "$c/site" "$c/corpus" "$c/reg" > "$c/publish.log" 2>&1; } |
| 170 | # A6: ACK during successful or failed in-flight transport is included in this pass, not the next. |
| 171 | # The helper must not wait for network IO: only the final commit holds REMOVE.lock. |
| 172 | for outcome in pause-ok pause-fail pause-api capacity; do |
| 173 | newcase "$outcome"; : > "$T/mode"; records txt "$O1"; request "$D1" "$O1"; worker |
| 174 | if [ "$outcome" = capacity ]; then records capacity "$O2"; transport=pause-ok; else records txt "$O2"; transport=$outcome; fi |
| 175 | request "$D2" "$O2"; rm -f "$T/ready" "$T/go"; printf '%s\n' "$transport" > "$T/mode" |
| 176 | worker & WORKER=$!; await "$T/ready" |
| 177 | pre=$(cat "$c/reg/current/.remove-sha256") |
| 178 | printf '%s\n' "$O1" | sh research/policy.sh "$c/remove" > "$c/policy-receipt" |
| 179 | # The actual helper ACKed while this pass is still in transport, before its final commit. |
| 180 | if kill -0 "$WORKER" && [ "$(cat "$c/reg/current/.remove-sha256")" = "$pre" ] && [ "$(sha256sum < "$c/remove" | cut -d ' ' -f1)" != "$pre" ]; then ok "$outcome policy ACK precedes final commit"; else bad "$outcome policy ACK not observed before final commit"; fi |
| 181 | touch "$T/go"; wait "$WORKER"; WORKER=; : > "$T/mode"; publish |
| 182 | if [ -e "$c/site/a/$O1.html" ]; then bad "$outcome acknowledged removal missed"; else ok "$outcome removal included without next pass"; fi |
| 183 | version=$(sha256sum < "$c/remove" | cut -d ' ' -f1) |
| 184 | check grep -Fxq "REMOVE_REPLACED sha256=$version" "$c/policy-receipt" |
| 185 | check grep -Fxq "$version" "$c/reg/current/.remove-sha256" |
| 186 | check test "$(grep 'active remove policy sha256=' "$c/log" | sed -n '1s/.*=//p')" = "$pre" |
| 187 | check test "$(grep 'active remove policy sha256=' "$c/log" | sed -n '$s/.*=//p')" = "$version" |
| 188 | if [ "$outcome" = pause-api ]; then check grep -q METADATA_OR_TRANSPORT "$c/log"; fi |
| 189 | if [ "$outcome" = capacity ]; then check grep -q PUBLICATION_CAPACITY_OR_VALIDATION "$c/log"; fi |
| 190 | done |
| 191 | # A6 negative control: a private copy of sync.sh without only the final policy revalidation under |
| 192 | # REMOVE.lock. The setup pass uses the real script; the same in-flight ACK must then stay unapplied. |
| 193 | python3 - "$ROOT" "$T/sync-no-a6.sh" <<'PY' |
| 194 | import sys |
| 195 | from pathlib import Path |
| 196 | root,out=sys.argv[1:] |
| 197 | s=Path('research/sync.sh').read_text() |
| 198 | needle='HERE=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)\n' |
| 199 | assert s.count(needle)==1 |
| 200 | s=s.replace(needle,"HERE='"+root+"'\n") |
| 201 | needle='''commit_policy "$base" || refuse 'final selection cannot publish; previous generation retained' |
| 202 | ''' |
| 203 | assert s.count(needle)==1 |
| 204 | s=s.replace(needle,"echo 'research sync: A6_MUTANT_FINAL_COMMIT_REACHED' >&2\n") |
| 205 | Path(out).write_text(s) |
| 206 | PY |
| 207 | check test "$(diff research/sync.sh "$T/sync-no-a6.sh" | grep -c '^<')" = 2 |
| 208 | check test "$(diff research/sync.sh "$T/sync-no-a6.sh" | grep -c '^>')" = 2 |
| 209 | check test "$(grep -c '^policy_lock$' "$T/sync-no-a6.sh")" = 2 |
| 210 | check test "$(grep -c '^policy_unlock$' "$T/sync-no-a6.sh")" = 2 |
| 211 | for outcome in pause-ok pause-fail pause-api capacity; do |
| 212 | newcase "mutant-$outcome"; : > "$T/mode"; records txt "$O1"; request "$D1" "$O1"; worker; publish |
| 213 | if [ ! -e "$c/site/a/$O1.html" ]; then bad "A6 mutant $outcome setup did not activate $O1"; continue; fi |
| 214 | if [ "$outcome" = capacity ]; then records capacity "$O2"; transport=pause-ok; else records txt "$O2"; transport=$outcome; fi |
| 215 | request "$D2" "$O2"; rm -f "$T/ready" "$T/go"; printf '%s\n' "$transport" > "$T/mode" |
| 216 | worker "$T/sync-no-a6.sh" & WORKER=$!; await "$T/ready" |
| 217 | pre=$(cat "$c/reg/current/.remove-sha256") |
| 218 | printf '%s\n' "$O1" | sh research/policy.sh "$c/remove" > "$c/policy-receipt" |
| 219 | if kill -0 "$WORKER" && [ "$(cat "$c/reg/current/.remove-sha256")" = "$pre" ] && [ "$(sha256sum < "$c/remove" | cut -d ' ' -f1)" != "$pre" ]; then ok "mutant $outcome policy ACK precedes final commit"; else bad "mutant $outcome policy ACK not observed before final commit"; fi |
| 220 | touch "$T/go"; rc=0; wait "$WORKER" || rc=$?; WORKER=; : > "$T/mode"; publish |
| 221 | version=$(sha256sum < "$c/remove" | cut -d ' ' -f1) |
| 222 | if [ "$rc" != 0 ] || ! grep -Fxq "REMOVE_REPLACED sha256=$version" "$c/policy-receipt" || [ "$version" = "$pre" ] || ! grep -Fxq 'research sync: A6_MUTANT_FINAL_COMMIT_REACHED' "$c/log"; then |
| 223 | bad "A6 mutant $outcome failed for unrelated reason rc=$rc" |
| 224 | elif [ ! -e "$c/site/a/$O1.html" ]; then |
| 225 | bad "A6 final revalidation mutant $outcome escaped" |
| 226 | elif [ "$(cat "$c/reg/current/.remove-sha256")" = "$pre" ] && ! grep -Fq "active remove policy sha256=$version" "$c/log"; then |
| 227 | ok "A6 mutant $outcome caught: FINAL_REVALIDATION_SKIPPED acknowledged removal stayed active" |
| 228 | else |
| 229 | bad "A6 mutant $outcome failed for unrelated reason (state)" |
| 230 | fi |
| 231 | done |
| 232 | # A6/A2: withdrawing the newer requester may reveal an older, larger eligible bundle. Keep |
| 233 | # previously validated unrelated works, withhold that reselection if needed, and retain its raw |
| 234 | # bundle/cache so freeing capacity can later restore the correct metadata and old text together. |
| 235 | newcase reselect; : > "$T/mode" |
| 236 | records txt "$O1" |
| 237 | python3 - "$T/text-body" <<'BODY' |
| 238 | import sys |
| 239 | open(sys.argv[1],'w').write('OLD_RESELECT_PUBLIC '+('a'*261970)+'\n\n') |
| 240 | BODY |
| 241 | printf 'Z\t%s\t%s\t10.5281/zenodo.201\n' "$D1" "$O1" >> "$c/add/queue" |
| 242 | worker |
| 243 | slug=$(grep '^W' "$c/reg/a/$O1/doi-201.tsv" | cut -f2) |
| 244 | oldidentity=$(grep '^T' "$c/reg/a/$O1/doi-201.tsv" | cut -f3) |
| 245 | rm "$T/text-body"; request "$D2" "$O1"; worker |
| 246 | records fill "$O2" |
| 247 | python3 - "$T/text-body" <<'BODY' |
| 248 | import sys |
| 249 | open(sys.argv[1],'w').write('FILLER_PUBLIC '+('b'*249970)+'\n\n') |
| 250 | BODY |
| 251 | request "$D1" "$O2"; worker; publish |
| 252 | check test "$(grep -h '^W' "$c/reg/show/"*.tsv | wc -l)" -eq 15 |
| 253 | rm "$T/text-body" |
| 254 | printf '%s\n' "$D2" | sh research/policy.sh "$c/remove" > "$c/policy-receipt" |
| 255 | worker; publish |
| 256 | check grep -q WITHHELD_RESELECTION "$c/log" |
| 257 | check test "$(grep -h '^W' "$c/reg/show/"*.tsv | wc -l)" -eq 14 |
| 258 | if grep -h '^W' "$c/reg/show/"*.tsv | grep -Fq "$(printf 'W\t%s\t' "$slug")"; then bad 'oversize old selection stayed active'; else ok 'oversize old selection safely withheld'; fi |
| 259 | check test -s "$c/reg/text/$slug.$oldidentity.txt" |
| 260 | # No A2 global poison: an unrelated small refresh is admitted, then the retained old bundle fits. |
| 261 | request "$D1" "$O2"; worker; publish |
| 262 | check grep -q 'admitted Z' "$c/log" |
| 263 | check test "$(grep -h '^W' "$c/reg/show/"*.tsv | wc -l)" -eq 15 |
| 264 | check grep -q OLD_RESELECT_PUBLIC "$c/corpus" |
| 265 | old=$(sha256sum < "$c/remove") |
| 266 | if head -c 65536 /dev/zero | sh research/policy.sh "$c/remove" > "$c/overflow.log" 2>&1; then bad 'policy overflow accepted'; else check test "$(sha256sum < "$c/remove")" = "$old"; fi |
| 267 | # Terminal 19-digit machine counter refuses the next import without wrapping or skipping removals. |
| 268 | printf '9223372036854775807\n' > "$c/reg/current/.serial" |
| 269 | records txt "$O2"; request "$D1" "$O2"; worker |
| 270 | check grep -q 'import serial exhausted' "$c/log" |
| 271 | check test "$(cat "$c/reg/current/.serial")" = 9223372036854775807 |
| 272 | # A failed precommit clone is cleaned by EXIT, not only startup recovery. |
| 273 | mkdir "$T/fault" |
| 274 | cat > "$T/fault/cp" <<'EOF' |
| 275 | #!/bin/sh |
| 276 | case "$*" in *'/.generations/snapshot.'*) exit 73;; esac |
| 277 | exec /usr/bin/cp "$@" |
| 278 | EOF |
| 279 | chmod 700 "$T/fault/cp" |
| 280 | old=$(readlink "$c/reg/current") |
| 281 | if PATH="$T/fault:$PATH" worker; then bad 'snapshot copy fault accepted'; else |
| 282 | check test "$(readlink "$c/reg/current")" = "$old" |
| 283 | check test "$(find "$c/reg/.generations" -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 |
| 284 | fi |
| 285 | echo "REFRESH_TRANSPORT_RESULT pass=$pass fail=$fail" |
| 286 | [ "$fail" = 0 ] |