From 95389f69d33f9489b0b8cb56345d2ac7695b7f10 Mon Sep 17 00:00:00 2001 From: dsh Date: Thu, 8 Oct 2026 16:23:57 +0100 Subject: [PATCH] Add .gitmodules for src/rosaria, and tests that a clean clone brings code src/rosaria and src/waypoints are gitlinks (index mode 160000) with no .gitmodules entry, so a fresh clone created EMPTY directories. Because src/robot/package.xml declares rosaria, a clean clone could not be built, and the `rosrun waypoints waypoints_server` step in guide.txt could not resolve. - .gitmodules: declare src/rosaria -> github.com/amor-ros-pkg/rosaria.git. Verified rather than guessed: commit 204dc0c6785abb4037c1c5ee76439cf5f50cb880 exists on that repository's master branch. - src/waypoints: its origin could NOT be identified (not in the Gitea instance, not in the author's GitHub account, not on the machine, not on the web), so no entry was invented for it. It is documented in the README as a known gap and listed in tests/known-gaps.txt. - tests/run.sh: offline integrity checks - packages complete, package names present and unique, catkin toplevel symlink, every gitlink declared or a documented gap, src/rosaria resolves at the pinned commit, every in-tree points at a package that exists. Exits non-zero on failure. - tests/negative.sh: proves that suite has teeth by breaking one thing at a time in a throwaway copy, with a positive control first. - README: where each gitlink comes from, what a clean clone still lacks, the darknet_ros reference in guide.txt that matches no package, and the stale rosaria licence row (left for the author to decide). Known limitation, documented in the README: the untargeted `git submodule update --init` still aborts, because the unmapped src/waypoints gitlink has no URL to resolve. Initialise by path instead: `git submodule update --init -- src/rosaria`. That works today and will keep working once src/waypoints is sorted out. No package code, CMakeLists or third-party licences were changed; the repository stays GPL-3.0. Not proven: that the workspace builds - there is no ROS in this environment, so catkin_make was never run. --- .gitmodules | 13 ++ README.md | 98 +++++++++++++ tests/expected-submodules.txt | 9 ++ tests/known-gaps.txt | 14 ++ tests/negative.sh | 110 ++++++++++++++ tests/run.sh | 267 ++++++++++++++++++++++++++++++++++ 6 files changed, 511 insertions(+) create mode 100644 .gitmodules create mode 100644 tests/expected-submodules.txt create mode 100644 tests/known-gaps.txt create mode 100755 tests/negative.sh create mode 100755 tests/run.sh diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..4a11034 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,13 @@ +# Submodules of this catkin workspace. +# +# src/rosaria is pinned to the upstream commit recorded in this repository's +# history; tests/run.sh verifies that it resolves and that the checkout matches +# the pin. +# +# src/waypoints is ALSO a gitlink (index mode 160000) in this repository's +# history, but its origin could not be identified, so it deliberately has NO +# entry here: inventing a URL would be worse than the honest gap. See README.md, +# "The waypoints package is missing" and tests/known-gaps.txt. +[submodule "src/rosaria"] + path = src/rosaria + url = https://github.com/amor-ros-pkg/rosaria.git diff --git a/README.md b/README.md index 4e0405e..ba32ca0 100644 --- a/README.md +++ b/README.md @@ -39,3 +39,101 @@ OpenNI2 headers remain in the repository under next to the source can drop them back into `src/ros_astra_camera/include/openni2_redist//`; that directory is now ignored by git so it will not be committed again. + +## Submodules: a clean clone must bring code, not empty directories + +`src/rosaria` and `src/waypoints` are recorded in this repository's history as +**gitlinks** (index mode `160000`, i.e. submodule entries), not as plain +directories. A gitlink stores only a commit id — the code itself lives in another +repository. For a clone to bring that code, each gitlink needs a matching entry in +`.gitmodules`; without one, `git clone` simply creates an **empty directory**. + +That was the state of this repository until this fix, and it broke the build: +`src/robot/package.xml` declares `rosaria`, so while `src/rosaria` +was empty a clean clone could not be built. + +### `src/rosaria` — origin identified, fixed here + +`src/rosaria` points at commit `204dc0c6785abb4037c1c5ee76439cf5f50cb880` of +****. This was verified rather than +guessed: the commit exists on that repository's `master` branch (it is the merge +commit of pull request #56) and its tree contains `package.xml`, `CMakeLists.txt` +and `RosAria.cpp`. + +A `.gitmodules` entry now declares it, so a clean clone brings the code: + +```sh +git clone p3dx-catkin +cd p3dx-catkin +git submodule update --init -- src/rosaria +``` + +**Note the `-- src/rosaria`.** The untargeted `git submodule update --init` still +aborts, because `src/waypoints` is a gitlink with no `.gitmodules` mapping and git +cannot resolve a URL for it. The same applies to a bare `git submodule status`. +Initialising by path works today and keeps working once `waypoints` is sorted out. + +### `src/waypoints` — origin NOT identified; the author must supply it + +`src/waypoints` points at commit `115553cfa8c2ace122414ac5a9b235cd2e225693`, but +**that code does not exist in any remote that could be found** — this was checked, +not assumed. It is not: + +- in the Gitea instance (`aneto/*`) — no repository matches `waypoints`; +- in the author's GitHub account (`ags-neto`) — 15 public repositories, none named + `waypoints`, and `ags-neto/waypoints` returns 404; +- anywhere on the machine where these checks were run — there is no + `waypoints_server` source on it; +- on the web — the commit `115553c…` is not reachable from any candidate repository. + +Because the origin is unknown, **no `.gitmodules` entry was invented for it**: a +guessed URL would be worse than an honest gap. `tests/run.sh` reports it as a *known +gap* and fails only if that list grows (see `tests/known-gaps.txt`). + +The consequence is concrete: `guide.txt` tells you to run +`rosrun waypoints waypoints_server`, and in a clean clone that does **not** resolve, +because `src/waypoints` is empty. + +Only the author has this code, and there are two honest ways to close the gap. Both +are his call: + +1. **Create a repository for it** (Gitea is the natural home), push the package, then + add the `[submodule "src/waypoints"]` section to `.gitmodules` with its path and + URL; or +2. **Bring the directory into this repository** — `git rm --cached src/waypoints` and + commit the real files, so the package is plain content and needs no submodule. + +Either way, once it is fixed, remove the `src/waypoints` line from +`tests/known-gaps.txt`: the suite reports the baseline as stale until you do. + +## `guide.txt` also runs a package that is not in this workspace + +The object-detection section of `guide.txt` says to run +`roslaunch darknet_ros darknet_ros.launch`, but there is **no `darknet_ros` package +under `src/`**. This is a documentation-conformance gap, not a gitlink — the package +presumably came from another workspace or from a system install. It is recorded here +and not fixed: `guide.txt` is the author's. + +## One observation left for the author (licences) + +The licence table above was written when `rosaria` was still an empty gitlink, so its +row reads "gitlinks with no content, no licence file to read". Now that `src/rosaria` +resolves, that row is stale: at the pinned commit, `rosaria/package.xml` declares +`GPLv2` (version 0.9.0). That matters for the repository-wide +GPL-3.0 decision, because GPLv2 without "or later" is not compatible with GPL-3.0. +The row was deliberately **left untouched** — the licence decision is the author's, +not this fix's. + +## Tests + +`tests/run.sh` checks what can be checked without ROS: that every package recorded in +the index has `package.xml` and `CMakeLists.txt`, that package names are present and +unique, that `src/CMakeLists.txt` is catkin's toplevel symlink, that every gitlink is +either declared in `.gitmodules` or a documented known gap, that `src/rosaria` +resolves at the pinned commit, that the declared submodule URL is the verified one, +that every in-tree `` points at a package that exists, and that every known +gap is documented here. `tests/negative.sh` proves the suite has teeth by breaking one +thing at a time in a throwaway copy. + +They do **not** prove that the workspace builds — no ROS was available where they were +written, so `catkin_make` was never run. diff --git a/tests/expected-submodules.txt b/tests/expected-submodules.txt new file mode 100644 index 0000000..ed59fa6 --- /dev/null +++ b/tests/expected-submodules.txt @@ -0,0 +1,9 @@ +# Submodules whose origin has been identified and verified. +# +# One entry per line: " ". Tests/run.sh checks that .gitmodules +# declares exactly these URLs, so a wrong or edited URL is caught even without +# network access. Reachability is not checked here (tests/run.sh stays offline). +# +# src/rosaria -> verified: commit 204dc0c6785abb4037c1c5ee76439cf5f50cb880 +# exists on that repository's master branch. +src/rosaria https://github.com/amor-ros-pkg/rosaria.git diff --git a/tests/known-gaps.txt b/tests/known-gaps.txt new file mode 100644 index 0000000..d0eb6e4 --- /dev/null +++ b/tests/known-gaps.txt @@ -0,0 +1,14 @@ +# Gitlinks (index mode 160000) that are KNOWN to have no `.gitmodules` entry. +# +# One path per line, relative to the repository root. Blank lines and lines +# starting with '#' are ignored. +# +# tests/run.sh FAILS if a gitlink shows up that is not listed here (a +# regression), and only prints a NOTE if a path listed here is no longer a gap +# (meaning this baseline is stale and should be pruned). +# +# src/waypoints - the package is a gitlink in this repository's history, but its +# origin could not be identified anywhere (not in Gitea, not in the author's +# GitHub account, not on the machine, not on the web). No `.gitmodules` entry +# could be written without inventing a URL. See README.md. +src/waypoints diff --git a/tests/negative.sh b/tests/negative.sh new file mode 100755 index 0000000..81aad7b --- /dev/null +++ b/tests/negative.sh @@ -0,0 +1,110 @@ +#!/usr/bin/env bash +# +# tests/negative.sh - proves that tests/run.sh has teeth. +# +# Each case copies the working tree into a temporary directory, breaks exactly +# one thing THERE, and asserts that tests/run.sh then fails with the expected +# check id. Nothing in the real repository is modified: every mutation happens +# in the throwaway copy. +# +# Usage: tests/negative.sh +# Exit status: 0 = every case behaved as expected. + +set -uo pipefail + +ROOT=$(git rev-parse --show-toplevel 2>/dev/null) || true +if [ -z "${ROOT:-}" ]; then + printf 'tests/negative.sh: not inside a git work tree\n' >&2 + exit 2 +fi +cd "$ROOT" || exit 2 + +TMP=$(mktemp -d) +trap 'rm -rf "$TMP"' EXIT + +fails=0 + +# --- mutations, each executed with the throwaway copy as cwd --------------- + +mut_none() { :; } + +# make src/rosaria an undeclared gitlink again (its .gitmodules section gone) +mut_drop_rosaria_entry() { + awk ' + /^\[submodule "src\/rosaria"\]/ { skip = 1; next } + /^\[/ { skip = 0 } + !skip { print } + ' .gitmodules > .gitmodules.new + mv .gitmodules.new .gitmodules +} + +# no .gitmodules at all +mut_hide_gitmodules() { mv .gitmodules .gitmodules.hidden; } + +# an entry that matches no gitlink +mut_add_orphan_entry() { + { + printf '\n[submodule "src/does-not-exist"]\n' + printf '\tpath = src/does-not-exist\n' + printf '\turl = https://example.invalid/does-not-exist.git\n' + } >> .gitmodules +} + +# a declared package that lost a required file +mut_break_package() { mv src/robot/CMakeLists.txt src/robot/CMakeLists.txt.hidden; } + +# --- runner --------------------------------------------------------------- + +case_expect() { + local label=$1 expect=$2 + local dir="$TMP/$label" + mkdir -p "$dir" + cp -a "$ROOT/." "$dir/" + ( cd "$dir" && "$label" ) + + local out rc + out=$(cd "$dir" && tests/run.sh 2>&1) + rc=$? + + printf -- '--- %s ---\n' "$label" + if [ "$expect" = "PASS" ]; then + if [ "$rc" -eq 0 ]; then + printf ' PASS run.sh exited 0 as expected\n' + else + printf ' FAIL run.sh exited %s, expected 0\n' "$rc" + printf '%s\n' "$out" | sed 's/^/ /' + fails=$((fails + 1)) + fi + return 0 + fi + if [ "$rc" -eq 0 ]; then + printf ' FAIL run.sh exited 0, but [%s] was expected to fail\n' "$expect" + fails=$((fails + 1)) + elif printf '%s\n' "$out" | grep -q "FAIL \[$expect\]"; then + printf ' PASS run.sh failed with [%s] (exit %s)\n' "$expect" "$rc" + else + printf ' FAIL run.sh failed, but without the expected id [%s]\n' "$expect" + printf '%s\n' "$out" | sed 's/^/ /' + fails=$((fails + 1)) + fi + return 0 +} + +echo "== negative tests for tests/run.sh ==" +echo + +# The positive control runs first: on an untouched copy the suite must be green, +# so any failure below really is caused by the mutation and not by a broken suite. +case_expect mut_none PASS +case_expect mut_drop_rosaria_entry gitlink-undeclared +case_expect mut_hide_gitmodules gitmodules-missing +case_expect mut_add_orphan_entry gitmodules-orphan +case_expect mut_break_package cmakelists-missing + +echo +if [ "$fails" -eq 0 ]; then + echo "ALL NEGATIVE CASES BEHAVED AS EXPECTED" + exit 0 +fi +printf '%s negative case(s) did not behave as expected\n' "$fails" +exit 1 diff --git a/tests/run.sh b/tests/run.sh new file mode 100755 index 0000000..d714a12 --- /dev/null +++ b/tests/run.sh @@ -0,0 +1,267 @@ +#!/usr/bin/env bash +# +# tests/run.sh - integrity checks for a clean clone of p3dx-catkin. +# +# These checks verify what CAN be verified without ROS: that a fresh clone +# brings real code instead of empty submodule directories, that every package +# recorded in the index is complete, and that every in-tree points at +# a package that actually exists. +# +# What this does NOT prove: that the workspace builds. There is no ROS in the +# environment where these checks were written, so catkin_make was never run. +# +# Usage, from a clean clone: +# git clone p3dx-catkin +# cd p3dx-catkin +# git submodule update --init -- src/rosaria +# tests/run.sh +# +# Exit status: 0 = every check passed; non-zero = at least one check failed. + +# Note: src/waypoints is a gitlink with no .gitmodules mapping (see +# tests/known-gaps.txt), and that makes the UNTARGETED `git submodule +# update --init` abort. Initialise the declared submodule by path, as above. +# +set -uo pipefail + +ROOT=$(git rev-parse --show-toplevel 2>/dev/null) || true +if [ -z "${ROOT:-}" ]; then + printf 'tests/run.sh: not inside a git work tree\n' >&2 + exit 2 +fi +cd "$ROOT" || exit 2 + +failed=0 +pass() { printf 'PASS [%s] %s\n' "$1" "$2"; } +fail() { printf 'FAIL [%s] %s\n' "$1" "$2"; failed=1; } +note() { printf 'NOTE [%s] %s\n' "$1" "$2"; } + +# has_word +has_word() { + case " ${2:-} " in + *" $1 "*) return 0 ;; + *) return 1 ;; + esac +} + +# Read a one-column list file, skipping blanks and # comments. +read_list() { + [ -f "$1" ] || return 0 + while IFS= read -r line || [ -n "$line" ]; do + case "$line" in + '' | '#'*) continue ;; + esac + printf '%s\n' "$line" + done < "$1" +} + +known=$(read_list tests/known-gaps.txt | tr '\n' ' ') + +echo "== p3dx-catkin integrity checks ==" +echo "root: $ROOT" +echo + +# --- 1. every package directory in the index is complete ------------------- +npkg=0 +allnames="" +while IFS=$'\t' read -r meta path; do + [ "${meta%% *}" = "040000" ] || continue + npkg=$((npkg + 1)) + if [ ! -f "$path/package.xml" ]; then + fail "package-xml-missing" "$path has no package.xml" + continue + fi + if [ ! -f "$path/CMakeLists.txt" ]; then + fail "cmakelists-missing" "$path has no CMakeLists.txt" + fi + declared_name=$(sed -n 's:.*[[:space:]]*\([^<]*\).*:\1:p' "$path/package.xml" 2>/dev/null | head -1 | tr -d ' \t\r') + if [ -z "$declared_name" ]; then + fail "package-name-missing" "$path/package.xml declares no " + elif has_word "$declared_name" "$allnames"; then + fail "package-name-duplicate" "the package name '$declared_name' is declared by more than one package.xml" + fi + # NB: in catkin the directory name need not equal the package name - + # src/ros_astra_camera declares astra_camera - so the two are + # deliberately NOT compared. + allnames="$allnames $declared_name" +done < <(git ls-tree HEAD src/) + +if [ "$npkg" -gt 0 ]; then + pass "packages-complete" "$npkg package directories in the index have package.xml + CMakeLists.txt" +else + fail "no-packages" "no package directories found under src/ in the index" +fi +echo + +# --- 2. src/CMakeLists.txt is the catkin toplevel symlink ------------------ +sl=$(git ls-tree HEAD src/CMakeLists.txt) +if [ -z "$sl" ]; then + fail "toplevel-missing" "src/CMakeLists.txt is not tracked" +else + slmode=${sl%% *} + slsha=$(printf '%s' "$sl" | awk '{print $3}') + if [ "$slmode" != "120000" ]; then + fail "toplevel-not-symlink" "src/CMakeLists.txt is mode $slmode, expected 120000 (catkin toplevel symlink)" + else + sltarget=$(git cat-file blob "$slsha" 2>/dev/null) + case "$sltarget" in + *catkin/cmake/toplevel.cmake) pass "toplevel-symlink" "src/CMakeLists.txt -> $sltarget" ;; + *) fail "toplevel-target" "src/CMakeLists.txt points at '$sltarget', expected catkin's toplevel.cmake" ;; + esac + fi +fi +echo + +# --- 3. gitlinks vs .gitmodules ------------------------------------------- +gitlinks="" +unmapped="" +while IFS=$'\t' read -r meta path; do + [ "${meta%% *}" = "160000" ] || continue + gitlinks="$gitlinks $path" +done < <(git ls-tree HEAD src/) +ngit=$(printf '%s' "$gitlinks" | wc -w) + +declared="" +if [ -f .gitmodules ]; then + declared=$(git config -f .gitmodules --get-regexp '^submodule\..*\.path$' 2>/dev/null | awk '{print $2}' | tr '\n' ' ') +else + fail "gitmodules-missing" ".gitmodules does not exist, but the index has gitlinks:$gitlinks" +fi + +for p in $gitlinks; do + if ! has_word "$p" "$declared"; then + unmapped="$unmapped $p" + if has_word "$p" "$known"; then + note "gitlink-known-gap" "$p is a gitlink with no .gitmodules entry (known gap, see tests/known-gaps.txt)" + else + fail "gitlink-undeclared" "$p is a gitlink (mode 160000) with no .gitmodules entry" + fi + fi +done + +for p in $declared; do + if ! has_word "$p" "$gitlinks"; then + fail "gitmodules-orphan" ".gitmodules declares '$p', which is not a gitlink in the index" + fi +done + +for p in $known; do + if ! has_word "$p" "$gitlinks" || has_word "$p" "$declared"; then + note "known-gap-stale" "tests/known-gaps.txt lists '$p', which is no longer a gap" + fi +done + +if [ -n "$unmapped" ]; then + note "submodule-command-blocked" "unmapped gitlink(s):$unmapped - plain 'git submodule update --init' and 'git submodule status' abort; initialise the declared paths explicitly: git submodule update --init -- src/rosaria" +fi + +echo "($ngit gitlink(s) in the index; $(printf '%s' "$declared" | wc -w) declared in .gitmodules)" +echo + +# --- 4. the verified submodule resolves ------------------------------------ +pin=$(git ls-tree HEAD src/rosaria 2>/dev/null | awk '{print $3}') +if [ -z "$pin" ]; then + fail "rosaria-not-gitlink" "src/rosaria is not a gitlink in the index" +else + if [ -f src/rosaria/package.xml ] && [ -f src/rosaria/CMakeLists.txt ]; then + pass "rosaria-populated" "src/rosaria brings package.xml and CMakeLists.txt (not an empty directory)" + else + fail "rosaria-populated" "src/rosaria is empty - run: git submodule update --init -- src/rosaria" + fi + actual="" + if [ -e src/rosaria/.git ]; then + actual=$(git -C src/rosaria rev-parse HEAD 2>/dev/null) + fi + if [ -n "$actual" ]; then + if [ "$actual" = "$pin" ]; then + pass "rosaria-pin" "src/rosaria checked out at the pinned commit $pin" + else + fail "rosaria-pin" "src/rosaria is at $actual but the index pins $pin" + fi + else + note "rosaria-pin" "src/rosaria has no git metadata, cannot compare against the pin $pin" + fi +fi + +# the declared URL is the one that was verified by hand +while read -r epath eurl; do + case "$epath" in '' | '#'*) continue ;; esac + got=$(git config -f .gitmodules --get "submodule.$epath.url" 2>/dev/null) + if [ "$got" = "${eurl:-}" ]; then + pass "submodule-url" "$epath is declared with the verified URL" + else + fail "submodule-url" "$epath is declared with '${got:-}', expected '$eurl'" + fi +done < <(read_list tests/expected-submodules.txt) +echo + +# --- 5. in-tree entries point at packages that exist -------------- +edges=0 +broken=0 +for d in src/*/; do + [ -f "$d/package.xml" ] || continue + pkg=$(basename "$d") + for n in $(sed -n 's:.*<\(depend\|build_depend\|build_export_depend\|exec_depend\|run_depend\)>[[:space:]]*\([^<]*\)rosaria' src/robot/package.xml; then + pass "robot-depends-rosaria" "src/robot still declares rosaria" + else + fail "robot-depends-rosaria" "src/robot no longer declares rosaria; this check lost its purpose" + fi +fi +echo + +# --- 6. every package.xml is well-formed XML ------------------------------- +if command -v python3 >/dev/null 2>&1; then + badxml=$(python3 - <<'PYEOF' +import glob +import xml.etree.ElementTree as ET +for f in sorted(glob.glob('src/*/package.xml')): + try: + ET.parse(f) + except Exception as exc: + print('%s: %s' % (f, exc)) +PYEOF +) + if [ -n "$badxml" ]; then + while IFS= read -r line; do fail "package-xml-invalid" "$line"; done </dev/null; then + pass "gap-documented" "$p is documented in README.md" + else + fail "gap-undocumented" "$p is a known gap but README.md does not mention it" + fi +done +echo + +if [ "$failed" -eq 0 ]; then + echo "ALL CHECKS PASSED" + exit 0 +fi +echo "SOME CHECKS FAILED" +exit 1