Files
computer-playbook/scripts/tests/deploy/local/exec/container.sh
T
kevinveenbirkenbachandClaude Opus 4.7 d3afe0bc81 test(lint): forbid a file from referencing its own path as a string
Hard-coded self-path references rot the moment the file moves: a header
comment ``# utils/foo/bar.py`` at the top of a module, a docstring
mentioning ``utils/foo/bar.py``, or a docs entry linking
``utils/foo/bar.py`` from inside ``utils/foo/bar.py`` itself all silently
desync from reality after the next ``git mv``.

The new lint walks every project file, computes its POSIX-style relative
path from PROJECT_ROOT, and reports any line whose text contains that
path as a substring. Files at the repo root (no ``/`` in their relative
path) and setuptools-generated ``*.egg-info/`` artefacts are exempt.
Per-line opt-out via ``# nocheck: self-path-reference`` on the offending
line, registered in the suppression catalog.

Existing offenders cleaned up:
- 72 redundant ``# <self-path>`` header lines removed across roles,
  cli, plugins, scripts, tests, and utils.
- 4 prometheus templates that told consumers to "update
  <self-template-path>" rewritten to drop the redundant self-reference.
- 8 docstring/comment self-references in cli, plugins, tests, utils,
  and the dashboard oidc.js.j2 header rewritten to describe the layout
  without naming the file's own path.
- 17 legitimate usage examples (shell scripts, test data lists, one
  template self-include doc-block) marked with ``nocheck:
  self-path-reference``.
- ``container.sh`` heredoc usage strings switched to ``${0}`` so the
  marker stays out of the user-visible help output.
- ``healthcheck/http.yml.j2`` doc-block rewritten to prose because
  ``{# ... #}`` Jinja comments cannot host an inner ``{# nocheck #}``
  (the inner ``#}`` closes the outer comment).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 03:53:44 +02:00

81 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Open an interactive shell in the running infinito container, or execute a
# one-off command inside it when CMD or positional arguments are set.
#
# Usage:
# scripts/tests/deploy/local/exec/container.sh [command...] # nocheck: self-path-reference
#
# Environment:
# INFINITO_DISTRO arch|debian|ubuntu|fedora|centos
# INFINITO_CONTAINER Optional explicit container name
# CMD One-off shell command to run instead of an interactive shell
#
# Examples:
# scripts/tests/deploy/local/exec/container.sh whoami # nocheck: self-path-reference
# CMD='whoami && id' scripts/tests/deploy/local/exec/container.sh # nocheck: self-path-reference
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "${SCRIPT_DIR}/../../../../../" && pwd)"
usage() {
cat <<EOF
Usage:
${0}
${0} [command...]
Environment:
INFINITO_DISTRO arch|debian|ubuntu|fedora|centos
INFINITO_CONTAINER Optional explicit container name
CMD One-off shell command to run instead of an interactive shell
Examples:
${0}
${0} whoami
CMD='whoami && id' ${0}
EOF
}
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
usage
exit 0
fi
cd "${REPO_ROOT}"
if [[ -f "scripts/meta/env/all.sh" ]]; then
# shellcheck source=scripts/meta/env/all.sh
source "scripts/meta/env/all.sh"
else
echo "ERROR: missing scripts/meta/env/all.sh" >&2
exit 2
fi
# defaults.sh exports INFINITO_CONTAINER from INFINITO_DISTRO (single SPOT
# for the formula). Read strictly here — no local re-derivation.
: "${INFINITO_CONTAINER:?INFINITO_CONTAINER not set after sourcing scripts/meta/env/all.sh — bug in defaults.sh?}"
container="${INFINITO_CONTAINER}"
docker_exec_flags=(-i)
if [[ -t 0 && -t 1 ]]; then
docker_exec_flags=(-it)
fi
if [[ $# -gt 0 ]]; then
if [[ "${1:-}" == "--" ]]; then
shift
fi
if [[ $# -eq 0 ]]; then
usage
exit 2
fi
exec docker exec "${docker_exec_flags[@]}" -w /opt/src/infinito "${container}" "$@"
fi
if [[ -n "${CMD:-}" ]]; then
exec docker exec "${docker_exec_flags[@]}" -w /opt/src/infinito "${container}" sh -lc "${CMD}"
fi
exec docker exec "${docker_exec_flags[@]}" -w /opt/src/infinito "${container}" sh