1
0

audit.sh 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env bash
  2. # One-shot CodeGraph quality audit:
  3. # set version -> ensure corpus repo -> wipe+reindex with that version ->
  4. # run with/without A/B -> restore the local dev link.
  5. #
  6. # Usage: audit.sh <version> <repo-name> <repo-url> "<question>" [headless|all]
  7. # <version> "local" (build + npm link this repo) | "latest" | a version (e.g. 0.7.10)
  8. # <repo-name> dir name under the corpus dir
  9. # <repo-url> git URL (cloned --depth 1 when the repo dir is missing)
  10. # [mode] headless (default) | all (also the interactive tmux arms)
  11. # Env: CORPUS corpus dir (default: /tmp/codegraph-corpus)
  12. set -uo pipefail
  13. VERSION="${1:?usage: audit.sh <version> <repo-name> <repo-url> \"<question>\" [mode]}"
  14. NAME="${2:?repo-name required}"
  15. URL="${3:?repo-url required}"
  16. Q="${4:?question required}"
  17. MODE="${5:-headless}"
  18. HARNESS="$(cd "$(dirname "$0")" && pwd)"
  19. REPO_ROOT="$(cd "$HARNESS/../.." && pwd)" # codegraph repo root
  20. CORPUS="${CORPUS:-/tmp/codegraph-corpus}"
  21. REPO="$CORPUS/$NAME"
  22. PKG="@colbymchenry/codegraph"
  23. echo "==================== CodeGraph audit ===================="
  24. echo "version=$VERSION repo=$NAME mode=$MODE corpus=$CORPUS"
  25. echo
  26. # 1. Set the codegraph version under test (mutates the global install).
  27. if [ "$VERSION" = local ]; then
  28. echo "→ [1/4] building + linking local dev build (local-install.sh)"
  29. ( cd "$REPO_ROOT" && ./scripts/local-install.sh ) || { echo "local-install.sh failed"; exit 1; }
  30. else
  31. echo "→ [1/4] installing $PKG@$VERSION globally"
  32. npm install -g "$PKG@$VERSION" || { echo "npm install -g $PKG@$VERSION failed"; exit 1; }
  33. fi
  34. ACTUAL="$(codegraph --version 2>/dev/null || echo '?')"
  35. echo " codegraph on PATH: $(command -v codegraph) -> $ACTUAL"
  36. # 2. Ensure the corpus repo exists (clone shallow if missing, reuse if present).
  37. mkdir -p "$CORPUS"
  38. if [ -d "$REPO/.git" ]; then
  39. echo "→ [2/4] reusing existing checkout: $REPO"
  40. else
  41. echo "→ [2/4] cloning $URL"
  42. git clone --depth 1 "$URL" "$REPO" || { echo "git clone failed"; exit 1; }
  43. fi
  44. # 3. Wipe + re-index with THIS version (the index must be built by the same
  45. # binary that serves it — different versions extract differently).
  46. echo "→ [3/4] wiping .codegraph and re-indexing with $ACTUAL"
  47. rm -rf "$REPO/.codegraph"
  48. ( cd "$REPO" && codegraph init -i ) || { echo "indexing failed"; exit 1; }
  49. # 4. Run the with/without A/B.
  50. echo "→ [4/4] running A/B harness (mode=$MODE)"
  51. bash "$HARNESS/run-all.sh" "$REPO" "$Q" "$MODE"
  52. # Restore the dev link (the normal working state in this repo).
  53. echo
  54. echo "→ restoring local dev link (local-install.sh)"
  55. if ( cd "$REPO_ROOT" && ./scripts/local-install.sh >/dev/null 2>&1 ); then
  56. echo " global codegraph restored to dev build"
  57. else
  58. echo " WARN: restore failed — run ./scripts/local-install.sh manually"
  59. fi
  60. echo "==================== audit complete ===================="