Skip to content

Commit 7037d62

Browse files
committed
Add regression tests for second-hop discovery functionality
1 parent 308c949 commit 7037d62

4 files changed

Lines changed: 121 additions & 0 deletions

File tree

.github/workflows/manual.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ jobs:
3939
- name: Checkout repository
4040
uses: actions/checkout@v4
4141

42+
- name: Regression tests
43+
run: bash src/test/discovery.sh
44+
4245
- name: Tune dpkg
4346
uses: abbbi/github-actions-tune@v1
4447

.github/workflows/update.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ jobs:
3131
- name: Checkout repository
3232
uses: actions/checkout@v4
3333

34+
- name: Regression tests
35+
run: bash src/test/discovery.sh
36+
3437
- name: Tune dpkg
3538
uses: abbbi/github-actions-tune@v1
3639

src/lib/get.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ get_remaining() {
3737
grep -Fxf "$1" "$2"
3838
}
3939

40+
get_discovered() {
41+
{
42+
get_requests "$3"
43+
[ -n "$2" ] && echo "$2"
44+
cat "$1"
45+
} | awk 'NF && !seen[$0]++'
46+
}
47+
4048
get_owners(){
4149
git -C "$6" log --name-only --pretty=format:%ct -- . | awk '
4250
/^[0-9]+$/ { ts=$0; next } # commit timestamp line
@@ -45,6 +53,7 @@ index($0,"/")==0 { next } # skip root-level files
4553
{ split($0,a,"/"); d=a[1]; if(!(d in seen)) seen[d]=ts }
4654
END { for(d in seen) printf "%s %s\n", seen[d], d }
4755
' | sort -n | cut -d' ' -f2- >complete_owners
56+
get_discovered "$2" "$4" "$5" | grep -vFxf all_owners_in_db -
4857
get_remaining complete_owners "$2" "$4" "$5" | grep -vFxf all_owners_in_db -
4958
rm -f complete_owners
5059
[ "$1" = "0" ] || get_remaining owners_stale "$2" "$4" "$5"

src/test/discovery.sh

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/bin/bash
2+
3+
# shellcheck disable=SC1091,SC2034
4+
5+
set -euo pipefail
6+
7+
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
8+
src_dir=$(cd "$script_dir/.." && pwd)
9+
workdir=$(mktemp -d)
10+
11+
cleanup() {
12+
rm -rf "$workdir"
13+
}
14+
15+
fail() {
16+
echo "$1" >&2
17+
exit 1
18+
}
19+
20+
init_bkg_state() {
21+
local now
22+
now=$(date -u +%s)
23+
: >"$BKG_ENV"
24+
: >"$BKG_OWNERS"
25+
: >"$BKG_OPTOUT"
26+
mkdir -p "$BKG_INDEX_DIR"
27+
BKG_SCRIPT_START="$now"
28+
set_BKG BKG_SCRIPT_START "$now"
29+
set_BKG BKG_RATE_LIMIT_START "$now"
30+
set_BKG BKG_MIN_RATE_LIMIT_START "$now"
31+
set_BKG BKG_CALLS_TO_API "0"
32+
set_BKG BKG_MIN_CALLS_TO_API "0"
33+
}
34+
35+
trap cleanup EXIT
36+
37+
pushd "$src_dir" >/dev/null
38+
export BKG_SKIP_DEP_VERIFY=1
39+
source lib/owner.sh
40+
popd >/dev/null
41+
42+
BKG_ENV="$workdir/env.env"
43+
BKG_OWNERS="$workdir/owners.txt"
44+
BKG_OPTOUT="$workdir/optout.txt"
45+
BKG_INDEX_DIR="$workdir/index"
46+
47+
connections="$workdir/connections.txt"
48+
owners_file="$workdir/manual-owners.txt"
49+
index_repo="$workdir/index-repo"
50+
51+
mkdir -p "$index_repo"
52+
git -C "$index_repo" init -q
53+
git -C "$index_repo" config user.name test
54+
git -C "$index_repo" config user.email test@example.com
55+
echo README >"$index_repo/README.md"
56+
git -C "$index_repo" add README.md
57+
git -C "$index_repo" commit -qm init
58+
59+
printf '%s\n' gianlazz Lazztech >"$connections"
60+
: >"$owners_file"
61+
: >"$workdir/all_owners_in_db"
62+
: >"$workdir/owners_partially_updated"
63+
: >"$workdir/owners_stale"
64+
65+
pushd "$workdir" >/dev/null
66+
admitted=$(bash "$src_dir/lib/get.sh" 0 "$connections" 20 ipitio "$owners_file" "$index_repo")
67+
popd >/dev/null
68+
69+
grep -Fxq Lazztech <<<"$admitted" || fail "Expected discovered second-hop org to survive owner admission"
70+
71+
init_bkg_state
72+
save_owner "556677/Lazztech" >/dev/null
73+
grep -Fxq "556677/Lazztech" <<<"$(get_BKG_set BKG_OWNERS_QUEUE)" || fail "Expected discovered org to be queued for owner updates"
74+
75+
pushd "$workdir" >/dev/null
76+
: >packages_already_updated
77+
owner_id=556677
78+
owner=Lazztech
79+
owner_type=orgs
80+
fast_out=false
81+
82+
curl() {
83+
cat <<'EOF'
84+
<div>
85+
<a href="/orgs/Lazztech/packages/container/package/libre-closet">libre-closet</a>
86+
<a href="/Lazztech/Libre-Closet">Libre-Closet</a>
87+
</div>
88+
EOF
89+
}
90+
91+
run_parallel() {
92+
local function_name=$1
93+
local items=$2
94+
95+
while IFS= read -r item; do
96+
[ -n "$item" ] || continue
97+
"$function_name" "$item"
98+
done <<<"$items"
99+
}
100+
101+
page_package 1 >/dev/null
102+
popd >/dev/null
103+
104+
grep -Fxq "container/Libre-Closet/libre-closet" <<<"$(get_BKG_set BKG_PACKAGES_Lazztech)" || fail "Expected queued package list to include Lazztech/libre-closet"
105+
106+
echo "Second-hop discovery regression test passed"

0 commit comments

Comments
 (0)