This repository has no description
1set shell := ["bash", "-eu", "-o", "pipefail", "-c"]
2
3default:
4 @just --list
5
6gen-config:
7 cargo run -p knot-server -- config-template > example.toml
8
9fmt:
10 cargo fmt --all
11
12fmt-check:
13 cargo fmt --all --check
14
15clippy:
16 cargo clippy --locked -p 'knot-*' --all-targets -- -D warnings
17
18test:
19 cargo test --locked -p 'knot-*'
20
21fuzz crate='knot-pack' target='pack' time='60':
22 cd crates/{{crate}}/fuzz && RUSTUP_TOOLCHAIN=nightly cargo fuzz run {{target}} -- -max_total_time={{time}}
23
24fuzz-ci: (fuzz "knot-pack" "pkt" "30") (fuzz "knot-pack" "pack" "30") (fuzz "knot-pack" "receive_commands" "30") (fuzz "knot-pack" "upload_args" "30") (fuzz "knot-git" "patch" "30") (fuzz "knot-cobs" "cob_change" "30") (fuzz "knot-cobs" "cob_ref" "30") (fuzz "knot-atproto" "pubkey" "30") (fuzz "knot-atproto" "did_document" "30") (fuzz "knot-edge" "spki" "30") (fuzz "knot-edge" "spki_pin" "30") (fuzz "knot-lfs" "transfer" "30") (fuzz "knot-lfs" "batch" "30") (fuzz "knot-lfs" "pointer" "30")
25
26bench filter='':
27 cargo bench -p knot-bench --bench pack -- {{filter}}
28 cargo bench -p knot-bench --bench cob -- {{filter}}
29 cargo bench -p knot-bench --bench projection -- {{filter}}
30
31bench-scaling:
32 cargo bench -p knot-bench --bench coldstart
33
34instrument-tests:
35 cargo test --locked -p knot-bench --features instrument --tests
36
37differential:
38 cargo test -p knot-pack --test differential
39
40t55xx *tests:
41 internal_docs/t55xx/run.sh {{tests}}
42
43ci: fmt-check clippy test checks instrument-tests fuzz-ci
44
45checks: require-tools check-no-subprocess (check-no-banned-deps "no-sql" "an embedded database" "rusqlite|libsqlite3-sys|sqlx|sqlx-core|sled|fjall|redb") (check-no-banned-deps "no-native-git" "a native git or TLS shim" "git2|libgit2-sys|openssl-sys|zlib-ng|zlib-ng-sys") check-no-string-ids check-no-unguarded-receive check-fuzz-targets-enumerated check-workflow-toolchain
46
47require-tools:
48 #!/usr/bin/env bash
49 set -euo pipefail
50 missing=""
51 for tool in cargo comm cut find grep head just mktemp rm sed sort tr; do
52 command -v "$tool" >/dev/null 2>&1 || missing="$missing $tool"
53 done
54 if [ -n "$missing" ]; then
55 echo "require-tools failed, these aren't on PATH:$missing" >&2
56 exit 1
57 fi
58 echo "ok: every tool the checks below run is on PATH"
59
60check-no-subprocess:
61 #!/usr/bin/env bash
62 set -euo pipefail
63 hits=$(grep -rn --include="*.rs" --exclude-dir=_lex "process::Command" crates/*/src || [ $? = 1 ])
64 if [ -n "$hits" ]; then
65 echo "no-subprocess check failed: server source spawns processes" >&2
66 echo "$hits" >&2
67 exit 1
68 fi
69 echo "ok: no process spawning in server source"
70
71check-no-banned-deps name subject pattern:
72 #!/usr/bin/env bash
73 set -euo pipefail
74 tree=$(cargo tree --locked -p knot-server --edges normal,build --prefix none | sort -u)
75 hits=$(printf '%s\n' "$tree" | grep -iE '^({{pattern}}) v' || [ $? = 1 ])
76 if [ -n "$hits" ]; then
77 echo "{{name}} check failed: {{subject}} is in the knot-server dependency tree" >&2
78 echo "$hits" >&2
79 exit 1
80 fi
81 echo "ok: {{subject}} isn't in the knot-server dependency tree"
82
83check-no-string-ids:
84 #!/usr/bin/env bash
85 set -euo pipefail
86 declared=$(grep -nE 'pub fn .*(-> *String|: *String\b)' crates/knot-types/src/ids.rs || [ $? = 1 ])
87 hits=$(printf '%s\n' "$declared" | grep -v 'fn to_hex' || [ $? = 1 ])
88 if [ -n "$hits" ]; then
89 echo "no-string-ids check failed: a String-typed id crosses the knot-types boundary" >&2
90 echo "$hits" >&2
91 exit 1
92 fi
93 echo "ok: no String-typed id crosses the knot-types boundary"
94
95check-no-unguarded-receive:
96 #!/usr/bin/env bash
97 set -euo pipefail
98 called=$(grep -rn --include="*.rs" 'receive_pack(\|receive_pack_with_limits(' crates/*/src || [ $? = 1 ])
99 hits=$(printf '%s\n' "$called" | grep -v 'pub fn ' || [ $? = 1 ])
100 if [ -n "$hits" ]; then
101 echo "no-unguarded-receive check failed: server source calls the unguarded receive path, use receive_pack_guarded" >&2
102 echo "$hits" >&2
103 exit 1
104 fi
105 echo "ok: the unguarded receive path is reached only from tests"
106
107check-fuzz-targets-enumerated:
108 #!/usr/bin/env bash
109 set -euo pipefail
110 disk=$(mktemp)
111 recipe=$(mktemp)
112 triplet=$(mktemp)
113 trap 'rm -f "$disk" "$recipe" "$triplet"' EXIT
114 find crates -path '*/fuzz/fuzz_targets/*.rs' -not -path '*/target/*' | sed -E 's#crates/([^/]+)/fuzz/fuzz_targets/(.+)\.rs#\1 \2#' | sort -u > "$disk"
115 just --show fuzz-ci | grep -oE '\(fuzz "[^"]+" "[^"]+" "[^"]+"' | sed -E 's#\(fuzz "([^"]+)" "([^"]+)" "([^"]+)"#\1 \2 \3#' | sort -u > "$triplet"
116 cut -d' ' -f1,2 "$triplet" > "$recipe"
117 while read -r crate target secs; do
118 if ! [[ "$secs" =~ ^[1-9][0-9]*$ ]]; then
119 echo "fuzz-targets-enumerated check failed: target '$crate $target' runs for '$secs', not a positive number of seconds" >&2
120 exit 1
121 fi
122 done < "$triplet"
123 missing=$(comm -23 "$disk" "$recipe")
124 extra=$(comm -13 "$disk" "$recipe")
125 if [ -n "$missing" ] || [ -n "$extra" ]; then
126 echo "fuzz-targets-enumerated check failed: the fuzz-ci recipe and the targets on disk disagree" >&2
127 if [ -n "$missing" ]; then
128 echo "on disk but absent from fuzz-ci:" >&2
129 echo "$missing" >&2
130 fi
131 if [ -n "$extra" ]; then
132 echo "in fuzz-ci but no matching target on disk:" >&2
133 echo "$extra" >&2
134 fi
135 exit 1
136 fi
137 while read -r crate target; do
138 manifest="crates/$crate/fuzz/Cargo.toml"
139 if ! grep -qF "name = \"$target\"" "$manifest" || ! grep -qF "path = \"fuzz_targets/$target.rs\"" "$manifest"; then
140 echo "fuzz-targets-enumerated check failed: $manifest has no [[bin]] declaring target '$target'" >&2
141 exit 1
142 fi
143 entry=$(grep -oE 'knot_[a-z0-9_]+::fuzz::[a-z0-9_]+' "crates/$crate/fuzz/fuzz_targets/$target.rs" | head -1 | sed -E 's#.*::fuzz::##' || true)
144 smoke="crates/$crate/tests/fuzz_smoke.rs"
145 if [ -z "$entry" ] || ! grep -qE "fuzz::${entry}\(" "$smoke"; then
146 echo "fuzz-targets-enumerated check failed: target '$target' entry point $(echo "$crate" | tr - _)::fuzz::$entry has no smoke-test coverage in $smoke" >&2
147 exit 1
148 fi
149 done < "$disk"
150 echo "ok: every fuzz target is enumerated in fuzz-ci, declared in its fuzz manifest, and smoke-tested"
151
152check-workflow-toolchain:
153 #!/usr/bin/env bash
154 set -euo pipefail
155 locked=$(sed -n '/^ "fenix": {/,/^ }/p' ../flake.lock | sed -nE 's/.*"rev": "([0-9a-f]{40})".*/\1/p' | head -1)
156 if [ -z "$locked" ]; then
157 echo "workflow-toolchain check failed: no fenix node with a revision in flake.lock" >&2
158 exit 1
159 fi
160 used=$(grep -hoE 'github:nix-community/fenix/[0-9a-f]{40}' ../.tangled/workflows/*.yml | sed -E 's#.*/##' | sort -u || [ $? = 1 ])
161 if [ -z "$used" ]; then
162 echo "workflow-toolchain check failed: no workflow in ../.tangled/workflows references a fenix revision" >&2
163 exit 1
164 fi
165 if [ "$used" != "$locked" ]; then
166 echo "workflow-toolchain check failed: flake.lock records fenix $locked and the workflows reference '$used'" >&2
167 exit 1
168 fi
169 echo "ok: every workflow builds with the fenix revision flake.lock records"