mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 02:57:37 +01:00
Brings seaweed-block main (v1.1.1 plus the docs and a test fix after it) into seaweed-block/ as one commit. Only files under seaweed-block/ change, and the subtree equals seaweed-block main exactly. The module's full history stays in the seaweed-block repository. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
97 lines
5.0 KiB
Bash
Executable File
97 lines
5.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Self-test of public-text-check.sh in a throwaway repository.
|
|
set -euo pipefail
|
|
here=$(cd "$(dirname "$0")" && pwd)
|
|
t=$(mktemp -d); trap 'rm -rf "$t"' EXIT
|
|
cd "$t"; git init -q .; git config user.email t@example.invalid; git config user.name t
|
|
echo base > a.txt; git add a.txt; git commit -q -m "base"
|
|
mb=$(git rev-parse HEAD)
|
|
: > title; : > body
|
|
run() { bash "$here/public-text-check.sh" "$@" >out 2>&1; }
|
|
expect() { # expect RC NAME
|
|
local want=$1 name=$2 rc=0
|
|
shift 2
|
|
run "$@" || rc=$?
|
|
[ "$rc" = "$want" ] || { echo "public-text-check-test: $name: exit $rc, want $want"; cat out; exit 1; }
|
|
}
|
|
echo "plain line" >> a.txt; git commit -q -am "add a plain line"
|
|
expect 0 "clean change" "$mb" HEAD title body
|
|
# Synthetic equivalents exercise private-path and run-metadata signatures.
|
|
for leaked in \
|
|
'Parsing file /home/example/run-1/Example.tla' \
|
|
'Synthetic model run with 1 worker on 2 cores with 123MB heap [pid: 12345]' \
|
|
'[pid: 12345]' \
|
|
'pid=12345' \
|
|
'2 cores with 123MB heap'; do
|
|
echo "$leaked" >> a.txt; git commit -q -am "model output"
|
|
expect 1 "raw run metadata in added text" "$mb" HEAD title body
|
|
git reset -q --hard HEAD~1
|
|
done
|
|
echo '/home/example/run-1' > body
|
|
expect 1 "home path in description" "$mb" HEAD title body; : > body
|
|
echo 'docs/spec/example/recorded-example/RESULT.txt' > body
|
|
expect 1 "artifact reference in description" "$mb" HEAD title body; : > body
|
|
echo '[pid: 12345]' > title
|
|
expect 1 "run metadata in title" "$mb" HEAD title body; : > title
|
|
for artifact in docs/spec/example/recorded-example/RESULT.txt docs/spec/recorded-example.txt; do
|
|
mkdir -p "$(dirname "$artifact")"; echo 'all checks passed' > "$artifact"
|
|
git add "$artifact"; git commit -q -m "add model artifact"
|
|
expect 1 "artifact path even with clean contents" "$mb" HEAD title body
|
|
artifact_base=$(git rev-parse HEAD)
|
|
git rm -q "$artifact"; git commit -q -m "remove model artifact"
|
|
expect 0 "artifact removal is allowed" "$artifact_base" HEAD title body
|
|
git reset -q --hard HEAD~2
|
|
done
|
|
echo 'Model workers execute in parallel; heap limits and PID namespaces are documented.' > body
|
|
expect 0 "ordinary explanatory prose" "$mb" HEAD title body; : > body
|
|
seat="clau""de06"; path="V:/sha""re/x"; nas="share/rd""ma/y"
|
|
echo "// asked by $seat" >> a.txt; git commit -q -am "comment"
|
|
expect 1 "seat name in an added line" "$mb" HEAD title body
|
|
grep -q "a.txt:3" out || { echo "public-text-check-test: hit does not name file and line"; cat out; exit 1; }
|
|
git reset -q --hard HEAD~1
|
|
echo "ok" >> a.txt; git commit -q -am "review by $seat"
|
|
expect 1 "seat name in a commit subject" "$mb" HEAD title body
|
|
git reset -q --hard HEAD~1
|
|
echo "see $path" > title; expect 1 "share path in the title" "$mb" HEAD title body; : > title
|
|
echo "results under $nas" > body; expect 1 "share path in the description" "$mb" HEAD title body; : > body
|
|
echo "an old line with $seat" >> a.txt; git commit -q -am "old"; mb2=$(git rev-parse HEAD)
|
|
echo "new clean line" >> a.txt; git commit -q -am "new"
|
|
expect 0 "an existing line is not this change's" "$mb2" HEAD title body
|
|
# A file line that begins with "++ " shows in the diff as "+++ ...": an added line, not a header.
|
|
printf '%s
|
|
' "++ $seat" >> a.txt; git commit -q -am "plus line"
|
|
expect 1 "an added line that looks like a diff header" "$mb2" HEAD title body
|
|
git reset -q --hard HEAD~1
|
|
bs=$(printf '\')
|
|
printf '%s
|
|
' "${bs}${bs}nas${bs}sha""re${bs}rd""ma${bs}z" > title
|
|
expect 1 "backslash form of the share path in the title" "$mb2" HEAD title body; : > title
|
|
expect 2 "a missing title file is an error, not clean" "$mb2" HEAD no-such-title body
|
|
expect 2 "a missing description file is an error, not clean" "$mb2" HEAD title no-such-body
|
|
expect 2 "an unknown commit is an error, not clean" 0000000000000000000000000000000000000000 HEAD title body
|
|
# Only the NUL-separated artifact enumeration fails, after partial output;
|
|
# every other git call delegates to the real executable.
|
|
real_git=$(command -v git)
|
|
mkdir -p fakegit
|
|
cat > fakegit/git <<'EOF'
|
|
#!/usr/bin/env bash
|
|
if [[ $1 == diff && ${2:-} == --name-only && ${3:-} == -z ]]; then
|
|
printf 'docs/spec/clean.txt\0'
|
|
exit 7
|
|
fi
|
|
exec "$PUBLIC_TEXT_REAL_GIT" "$@"
|
|
EOF
|
|
chmod +x fakegit/git
|
|
rc=0
|
|
PUBLIC_TEXT_REAL_GIT="$real_git" PATH="$PWD/fakegit:$PATH" bash "$here/public-text-check.sh" "$mb2" HEAD title body >out 2>&1 || rc=$?
|
|
[ "$rc" = 2 ] || { echo "public-text-check-test: failed artifact enumeration: exit $rc, want 2"; cat out; exit 1; }
|
|
if grep -q 'public-text: clean' out; then echo 'public-text-check-test: failed artifact enumeration printed clean'; cat out; exit 1; fi
|
|
# A grep that fails (exit 2) is an error: the check must refuse and never print "clean".
|
|
mkdir -p fakebin; printf '#!/bin/sh
|
|
exit 2
|
|
' > fakebin/grep; chmod +x fakebin/grep
|
|
rc=0; PATH="$PWD/fakebin:$PATH" bash "$here/public-text-check.sh" "$mb2" HEAD title body >out 2>&1 || rc=$?
|
|
[ "$rc" = 2 ] || { echo "public-text-check-test: failing grep: exit $rc, want 2"; cat out; exit 1; }
|
|
if PATH=/usr/bin:/bin grep -q "clean" out; then echo "public-text-check-test: failing grep printed clean"; cat out; exit 1; fi
|
|
echo "public-text-check-test: ok"
|