@soleur/opencode 3.361.6 → 3.362.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skills/plan/references/plan-sharp-edges.md +1 -0
- package/skills/registry-breakglass-mirror/SKILL.md +227 -0
- package/skills/registry-breakglass-mirror/scripts/mirror-ghcr-to-zot.sh +905 -0
- package/skills/registry-breakglass-mirror/test/mirror-ghcr-to-zot.test.sh +156 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Network-free fixture suite for mirror-ghcr-to-zot.sh (#11424, review coverage
|
|
3
|
+
# P3 — the engine's declared CRANE_CMD/PATH seams are exercised here).
|
|
4
|
+
#
|
|
5
|
+
# Method: a stub `curl` on PATH serves canned responses by URL shape (DoH JSON,
|
|
6
|
+
# token exchange, manifest GETs); a stub `crane` proves the binary is never
|
|
7
|
+
# invoked under --dry-run. The whole resolve→exchange→count→report path runs
|
|
8
|
+
# offline; nothing contacts GHCR, zot, or the internet.
|
|
9
|
+
#
|
|
10
|
+
# Run: bash plugins/soleur/skills/registry-breakglass-mirror/test/mirror-ghcr-to-zot.test.sh
|
|
11
|
+
set -uo pipefail
|
|
12
|
+
|
|
13
|
+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
14
|
+
SCRIPT="$DIR/../scripts/mirror-ghcr-to-zot.sh"
|
|
15
|
+
passes=0; fails=0
|
|
16
|
+
pass() { passes=$((passes + 1)); }
|
|
17
|
+
fail() { fails=$((fails + 1)); echo "FAIL: $1" >&2; }
|
|
18
|
+
|
|
19
|
+
[ -f "$SCRIPT" ] || { echo "FAIL: engine not found at $SCRIPT" >&2; exit 1; }
|
|
20
|
+
[ -x "$SCRIPT" ] || { echo "FAIL: engine not executable at $SCRIPT" >&2; exit 1; }
|
|
21
|
+
|
|
22
|
+
WORK_T="$(mktemp -d)"; trap 'rm -rf "$WORK_T"' EXIT
|
|
23
|
+
STUB="$WORK_T/bin"; mkdir -p "$STUB"
|
|
24
|
+
FIX="$WORK_T/fix"; mkdir -p "$FIX" "$FIX/blobs" "$FIX/bydigest"
|
|
25
|
+
|
|
26
|
+
# --- fixtures -----------------------------------------------------------------
|
|
27
|
+
# Real-content blobs: every digest the fixtures declare is backed by a file
|
|
28
|
+
# whose sha256 IS that digest — the script's every-byte-verified discipline
|
|
29
|
+
# can run honestly offline.
|
|
30
|
+
mkblob() { local c="$1" h; printf '%s' "$c" > "$FIX/raw"; h="$(sha256sum "$FIX/raw" | cut -d' ' -f1)"; cp "$FIX/raw" "$FIX/blobs/$h"; printf '%s' "$h"; }
|
|
31
|
+
CFG="$(mkblob 'cfg')" L1="$(mkblob 'l1')" L2="$(mkblob 'l2')"
|
|
32
|
+
SIGB="$(mkblob 'sig-payload')" SIGCFG="$(mkblob 'sigcfg')"
|
|
33
|
+
|
|
34
|
+
cat > "$FIX/manifest.json" <<EOF
|
|
35
|
+
{"schemaVersion":2,"mediaType":"application/vnd.oci.image.manifest.v1+json","config":{"mediaType":"application/vnd.oci.image.config.v1+json","digest":"sha256:${CFG}","size":3},"layers":[{"mediaType":"application/vnd.oci.image.layer.v1.tar+gzip","digest":"sha256:${L1}","size":2},{"mediaType":"application/vnd.oci.image.layer.v1.tar+gzip","digest":"sha256:${L2}","size":2}]}
|
|
36
|
+
EOF
|
|
37
|
+
MHEX="$(sha256sum "$FIX/manifest.json" | cut -d' ' -f1)"
|
|
38
|
+
cp "$FIX/manifest.json" "$FIX/bydigest/$MHEX"
|
|
39
|
+
# Signature child: a plain manifest whose subject binds the image digest.
|
|
40
|
+
cat > "$FIX/sigchild.json" <<EOF
|
|
41
|
+
{"schemaVersion":2,"mediaType":"application/vnd.oci.image.manifest.v1+json","config":{"mediaType":"application/vnd.oci.image.config.v1+json","digest":"sha256:${SIGCFG}","size":6},"layers":[{"mediaType":"application/vnd.dev.sigstore.bundle.v0.3+json","digest":"sha256:${SIGB}","size":10}],"subject":{"digest":"sha256:${MHEX}"}}
|
|
42
|
+
EOF
|
|
43
|
+
SCHEX="$(sha256sum "$FIX/sigchild.json" | cut -d' ' -f1)"
|
|
44
|
+
cp "$FIX/sigchild.json" "$FIX/bydigest/$SCHEX"
|
|
45
|
+
# Signature index: referrers tag sha256-<MHEX> serves this index.
|
|
46
|
+
SZC=$(stat -c %s "$FIX/sigchild.json")
|
|
47
|
+
cat > "$FIX/sigidx.json" <<EOF
|
|
48
|
+
{"schemaVersion":2,"mediaType":"application/vnd.oci.image.index.v1+json","manifests":[{"mediaType":"application/vnd.oci.image.manifest.v1+json","digest":"sha256:${SCHEX}","size":${SZC},"artifactType":"application/vnd.dev.sigstore.bundle.v0.3+json"}]}
|
|
49
|
+
EOF
|
|
50
|
+
SHEX="$(sha256sum "$FIX/sigidx.json" | cut -d' ' -f1)"
|
|
51
|
+
cp "$FIX/sigidx.json" "$FIX/bydigest/$SHEX"
|
|
52
|
+
cp "$FIX/sigidx.json" "$FIX/sig-tag.json" # the sha256-<hex> referrers tag body
|
|
53
|
+
|
|
54
|
+
cat > "$FIX/token.json" <<'EOF'
|
|
55
|
+
{"token":"test-bearer"}
|
|
56
|
+
EOF
|
|
57
|
+
cat > "$FIX/doh.json" <<'EOF'
|
|
58
|
+
{"Status":0,"Answer":[{"name":"ghcr.io","type":1,"data":"140.82.121.34"}]}
|
|
59
|
+
EOF
|
|
60
|
+
|
|
61
|
+
# --- stubs --------------------------------------------------------------------
|
|
62
|
+
cat > "$STUB/curl" <<EOF
|
|
63
|
+
#!/usr/bin/env bash
|
|
64
|
+
# Serve canned bodies by URL shape; -o FILE is the last-but-two arg convention
|
|
65
|
+
# the engine uses. http_code is printed to stdout by -w.
|
|
66
|
+
url=""; out=""; wfmt=""
|
|
67
|
+
while [[ \$# -gt 0 ]]; do
|
|
68
|
+
case "\$1" in
|
|
69
|
+
-o) out="\$2"; shift 2 ;;
|
|
70
|
+
-w) wfmt="\$2"; shift 2 ;;
|
|
71
|
+
http*|ghcr.io*|pkg-containers*) url="\$1"; shift ;;
|
|
72
|
+
*) shift ;;
|
|
73
|
+
esac
|
|
74
|
+
done
|
|
75
|
+
body=""
|
|
76
|
+
case "\$url" in
|
|
77
|
+
*dns-query*|*dns.google*|*resolve?*) body="$FIX/doh.json" ;;
|
|
78
|
+
*"/token?"*) body="$FIX/token.json" ;;
|
|
79
|
+
*/manifests/sha256-*) body="$FIX/sig-tag.json" ;; # referrers tag
|
|
80
|
+
*/manifests/sha256:*)
|
|
81
|
+
hex="\${url##*sha256:}"; [[ -f "$FIX/bydigest/\$hex" ]] && body="$FIX/bydigest/\$hex" ;;
|
|
82
|
+
*/manifests/*) body="$FIX/manifest.json" ;;
|
|
83
|
+
*/blobs/sha256:*)
|
|
84
|
+
hex="\${url##*sha256:}"; [[ -f "$FIX/blobs/\$hex" ]] && body="$FIX/blobs/\$hex" ;;
|
|
85
|
+
*) body="" ;;
|
|
86
|
+
esac
|
|
87
|
+
if [[ -n "\$out" ]]; then
|
|
88
|
+
[[ -n "\$body" ]] && cp "\$body" "\$out" || printf '{}' > "\$out"
|
|
89
|
+
elif [[ -n "\$body" ]]; then
|
|
90
|
+
cat "\$body" # no -o: caller (DoH probe) reads the body on stdout
|
|
91
|
+
fi
|
|
92
|
+
[[ "\$wfmt" == *http_code* ]] && printf '200'
|
|
93
|
+
exit 0
|
|
94
|
+
EOF
|
|
95
|
+
cat > "$STUB/crane" <<EOF
|
|
96
|
+
#!/usr/bin/env bash
|
|
97
|
+
echo "STUB-CRANE-INVOKED \$*" >> "\${CRANE_LOG:-/dev/null}"
|
|
98
|
+
sub="\$1"; shift 2>/dev/null || true
|
|
99
|
+
ref=""
|
|
100
|
+
for a in "\$@"; do case "\$a" in *@sha256:*|*:sha256-*) ref="\$a" ;; esac; done
|
|
101
|
+
case "\$sub" in
|
|
102
|
+
manifest) hex="\${ref##*sha256:}"; [[ -f "$FIX/bydigest/\$hex" ]] && cat "$FIX/bydigest/\$hex" || exit 1 ;;
|
|
103
|
+
digest) case "\$ref" in *:sha256-*) printf 'sha256:%s\n' "\$(sha256sum "$FIX/sig-tag.json" | cut -d' ' -f1)" ;; *) grep -oE 'sha256:[0-9a-f]{64}' <<<"\$ref" | head -1 ;; esac ;;
|
|
104
|
+
push|blob|validate|auth) exit 0 ;;
|
|
105
|
+
*) exit 0 ;;
|
|
106
|
+
esac
|
|
107
|
+
exit 0
|
|
108
|
+
EOF
|
|
109
|
+
chmod +x "$STUB/curl" "$STUB/crane"
|
|
110
|
+
|
|
111
|
+
run_dry() { # <args...> → OUT/RC; stub PATH + token + CRANE_CMD
|
|
112
|
+
CRANE_LOG="$WORK_T/crane.log"; : > "$CRANE_LOG"; export CRANE_LOG
|
|
113
|
+
OUT="$(env PATH="$STUB:$PATH" GHCR_TOKEN="test-pat" CRANE_CMD="$STUB/crane" GHCR_IP="" PKGC_IP="" \
|
|
114
|
+
bash "$SCRIPT" --dry-run "$@" 2>/dev/null)"
|
|
115
|
+
RC=$?
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
# ── (a) a manifest ref dry-runs with measured blob counts — kills the
|
|
119
|
+
# `[.layers | .size]` array-index bug class (must print blobs=3 bytes=7) ──
|
|
120
|
+
HEX="$MHEX"
|
|
121
|
+
run_dry jikig-ai/soleur-web-platform "jikig-ai/soleur-web-platform@sha256:${HEX}"
|
|
122
|
+
if [[ "$RC" -eq 0 ]] && [[ "$OUT" == *"blobs=3"* ]]; then pass; else fail "(a) manifest dry-run → expected rc=0 blobs=3, got rc=$RC OUT='$OUT'"; fi
|
|
123
|
+
|
|
124
|
+
# ── (b) crane is never invoked under --dry-run (the fetch is gated) ──
|
|
125
|
+
if [[ ! -s "$CRANE_LOG" ]]; then pass; else fail "(b) dry-run invoked crane: $(cat "$CRANE_LOG")"; fi
|
|
126
|
+
|
|
127
|
+
# ── (c) tokenless dry-run prints blobs=unmeasured and exits 0 ──
|
|
128
|
+
OUT="$(env -u GHCR_TOKEN PATH="$STUB:$PATH" CRANE_CMD="$STUB/crane" bash "$SCRIPT" --dry-run jikig-ai/soleur-web-platform v1.2.3 2>/dev/null)"
|
|
129
|
+
RC=$?
|
|
130
|
+
if [[ "$RC" -eq 0 ]] && [[ "$OUT" == *"blobs=unmeasured"* ]]; then pass; else fail "(c) tokenless dry-run → expected rc=0 blobs=unmeasured, got rc=$RC OUT='$OUT'"; fi
|
|
131
|
+
|
|
132
|
+
# ── (d) malformed ref dies 1 (usage), never reaches the network leg ──
|
|
133
|
+
OUT="$(env PATH="$STUB:$PATH" bash "$SCRIPT" --dry-run jikig-ai/soleur-web-platform 'not a ref' 2>&1 >/dev/null)"
|
|
134
|
+
RC=$?
|
|
135
|
+
if [[ "$RC" -eq 1 ]] && [[ "$OUT" == *"mirror-ghcr-to-zot:"* ]]; then pass; else fail "(d) malformed ref → expected rc=1 + diagnostic, got rc=$RC OUT='$OUT'"; fi
|
|
136
|
+
|
|
137
|
+
# ── (e) ZOT_TARGET shape guard fails closed on a hostile value ──
|
|
138
|
+
OUT="$(env PATH="$STUB:$PATH" GHCR_TOKEN="x" ZOT_TARGET="evil host:5000" bash "$SCRIPT" --dry-run jikig-ai/soleur-web-platform v1.2.3 2>&1 >/dev/null)"
|
|
139
|
+
RC=$?
|
|
140
|
+
if [[ "$RC" -eq 1 ]] && [[ "$OUT" == *"ZOT_TARGET"* ]]; then pass; else fail "(e) hostile ZOT_TARGET → expected rc=1 naming ZOT_TARGET, got rc=$RC OUT='$OUT'"; fi
|
|
141
|
+
|
|
142
|
+
# ── (h) LIVE path end-to-end with stubs: pull→layout→push→verify → result=ok.
|
|
143
|
+
# Exercises verify_blobs_of's manifest arm (the signature child) — the
|
|
144
|
+
# array-index jq bug class must never regress on the verify path. ──
|
|
145
|
+
OUT="$(env PATH="$STUB:$PATH" GHCR_TOKEN="test-pat" ZOT_PUSH_USER="u" ZOT_PUSH_TOKEN="t" CRANE_CMD="$STUB/crane" GHCR_IP="" PKGC_IP="" \
|
|
146
|
+
bash "$SCRIPT" "jikig-ai/soleur-web-platform" "jikig-ai/soleur-web-platform@sha256:${MHEX}" 2>/dev/null)"
|
|
147
|
+
RC=$?
|
|
148
|
+
if [[ "$RC" -eq 0 ]] && [[ "$OUT" == *"result=ok"* && "$OUT" == *"mode=signature"* ]]; then pass; else fail "(h) live run → expected rc=0 result=ok + signature verify, got rc=$RC OUT='$OUT'"; fi
|
|
149
|
+
|
|
150
|
+
# ── (f) GHCR_USER charset guard fails closed ──
|
|
151
|
+
OUT="$(env PATH="$STUB:$PATH" GHCR_TOKEN="x" GHCR_USER='bad"user' bash "$SCRIPT" --dry-run jikig-ai/soleur-web-platform "jikig-ai/soleur-web-platform@sha256:${HEX}" 2>&1 >/dev/null)"
|
|
152
|
+
RC=$?
|
|
153
|
+
if [[ "$RC" -eq 5 ]] && [[ "$OUT" == *"GHCR_USER"* ]]; then pass; else fail "(f) bad GHCR_USER → expected rc=5 naming GHCR_USER, got rc=$RC OUT='$OUT'"; fi
|
|
154
|
+
|
|
155
|
+
echo "mirror-ghcr-to-zot: $passes passed, $fails failed"
|
|
156
|
+
[ "$fails" -eq 0 ] || exit 1
|