mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-12 21:50:52 +01:00
Two levels of pure taxonomy carrying no information, and a 2-directory
cap leaves no room for them. Categories now sit directly under
linux_configuration/: features, fixes, utils, misc, fresh-install,
installers, diagnostics, gaming, boot_recovery, periodic_background, lib,
meta, tests. A script's own lib/ and tests/ are exempt from the cap, so
those stay put.
Depth violations 248 -> 139; roughly 40 of the remainder are inside
digital_wellbeing and hosts, deferred until the guard-lib repoint.
The moves are the easy half. What breaks is every path that counted
levels, and three classes of it had to be found by resolving paths rather
than reading diffs:
- 52 relative `source` lines for lib/common.sh and lib/android.sh. The
correct prefix differs per file: 40 were ../../ and 12 were ../../../,
so a blanket replace would have fixed one set and broken the other.
- REPO_ROOT in 7 fixes/lib/tests harnesses and setup_syncyomi_guard.sh,
each walking up four levels from a directory now two levels shallower.
This caused a real regression -- the fixes suite went red with
"log_warn: command not found" -- caught by running it and comparing
against the pre-move baseline worktree.
- conftest.py's sys.path entries, which took the pytest gate down with
14 collection errors, and the `# shellcheck source=` directives, which
took shellcheck down with SC1091.
16 symlinks in $HOME broke, including the entire i3blocks bar. All
repointed, and cpu_monitor/memory/disk/time/volume were run to confirm
they emit real output rather than merely resolving.
Verified: 1798 tests pass at 100% coverage, 8 of 9 lib/tests suites pass
(the ninth needs the coverage jail, identically at baseline), pre-commit
is clean, and the two untracked secret configs are still ignored after
their gitignore paths changed.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
130 lines
5.2 KiB
Bash
Executable File
130 lines
5.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Tests for lib/study_doc_lookup.sh — offline lookup, language dispatch and
|
|
# language detection.
|
|
#
|
|
# The interesting behaviour is the preference order: when an offline mirror is
|
|
# installed, a term should resolve to a local FILE PATH an assistant can read
|
|
# with `cat`, and only fall back to an online URL when the mirror has no answer.
|
|
# That distinction is the whole point of the offline path — a card citing a URL
|
|
# the assistant cannot fetch is a card it will answer from memory instead.
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
# shellcheck source=study_harness.sh
|
|
. "${SCRIPT_DIR}/study_harness.sh"
|
|
# shellcheck source=../study_doc_urls.sh
|
|
. "${SCRIPT_DIR}/../study_doc_urls.sh"
|
|
# shellcheck source=../study_doc_urls_more.sh
|
|
. "${SCRIPT_DIR}/../study_doc_urls_more.sh"
|
|
# shellcheck source=../study_doc_lookup.sh
|
|
. "${SCRIPT_DIR}/../study_doc_lookup.sh"
|
|
|
|
echo "== lookup_offline: disabled =="
|
|
reset_state
|
|
if lookup_offline "os" python "" >/dev/null 2>&1; then
|
|
_t_fail "with offline docs off, lookup_offline fails"
|
|
else
|
|
_t_pass "with offline docs off, lookup_offline fails"
|
|
fi
|
|
|
|
echo "== lookup_offline: a term lookup =="
|
|
reset_state
|
|
enable_offline_docs "${OFFLINE_DOCS_DIR}/python/os.md"
|
|
_t_eq "${OFFLINE_DOCS_DIR}/python/os.md" "$(lookup_offline "os" python "")" \
|
|
"a term resolves to the local file path"
|
|
|
|
echo "== lookup_offline: an import-aware lookup =="
|
|
reset_state
|
|
enable_offline_docs "${OFFLINE_DOCS_DIR}/js/array.md"
|
|
_t_eq "${OFFLINE_DOCS_DIR}/js/array.md" "$(lookup_offline "" javascript "import { x } from 'y'")" \
|
|
"an import line resolves through the --import path"
|
|
|
|
echo "== lookup_offline: mirror has no answer =="
|
|
reset_state
|
|
enable_offline_docs_empty
|
|
if lookup_offline "frobnicate" python "" >/dev/null 2>&1; then
|
|
_t_fail "an unanswered term fails rather than returning empty"
|
|
else
|
|
_t_pass "an unanswered term fails rather than returning empty"
|
|
fi
|
|
|
|
echo "== get_doc_url: dispatches per language =="
|
|
reset_state
|
|
_t_has "$(get_doc_url "def" python "")" "docs.python.org" "python dispatches to python_doc_url"
|
|
_t_has "$(get_doc_url "const" javascript "")" "developer.mozilla.org" "javascript dispatches to js_doc_url"
|
|
_t_has "$(get_doc_url "interface" typescript "")" "typescriptlang.org" "typescript dispatches to ts_doc_url"
|
|
_t_has "$(get_doc_url "printf" c "")" "cppreference.com" "c dispatches to c_doc_url"
|
|
_t_has "$(get_doc_url "vector" cpp "")" "cppreference.com" "cpp dispatches to cpp_doc_url"
|
|
_t_has "$(get_doc_url "fn" rust "")" "rust-lang.org" "rust dispatches to rust_doc_url"
|
|
_t_has "$(get_doc_url "func" go "")" "go.dev" "go dispatches to go_doc_url"
|
|
_t_has "$(get_doc_url "def" ruby "")" "ruby-doc.org" "ruby dispatches to ruby_doc_url"
|
|
_t_has "$(get_doc_url "class" java "")" "oracle.com" "java dispatches to java_doc_url"
|
|
_t_has "$(get_doc_url "if" shell "")" "gnu.org" "shell dispatches to shell_doc_url"
|
|
|
|
echo "== get_doc_url: an unknown language still answers =="
|
|
reset_state
|
|
out="$(get_doc_url "something" brainfuck "")"
|
|
if [[ -n "$out" ]]; then
|
|
_t_pass "an unrecognised language still produces a link"
|
|
else
|
|
_t_fail "an unrecognised language still produces a link (returned nothing)"
|
|
fi
|
|
|
|
echo "== get_doc_url: prefers the offline mirror when it has an answer =="
|
|
reset_state
|
|
enable_offline_docs "${OFFLINE_DOCS_DIR}/python/os.md"
|
|
out="$(get_doc_url "os" python "")"
|
|
_t_has "$out" "${OFFLINE_DOCS_DIR}" "an offline hit wins over the online URL"
|
|
|
|
echo "== get_doc_url: falls back online when the mirror misses =="
|
|
reset_state
|
|
enable_offline_docs_empty
|
|
_t_has "$(get_doc_url "os" python "")" "docs.python.org" "an offline miss falls back to the online URL"
|
|
|
|
echo "== get_doc_url: TypeScript borrows the JavaScript offline mirror =="
|
|
reset_state
|
|
# The mirror answers for "js" and nothing else, which is the real shape: an
|
|
# offline-docs install carries MDN, not a separate TypeScript tree. A TS lookup
|
|
# therefore misses under "typescript" and only succeeds on the retry under
|
|
# "js". Without that retry a TS repo would silently never use the docs it has.
|
|
enable_offline_docs_for_lang js "${OFFLINE_DOCS_DIR}/js/const.md"
|
|
_t_has "$(get_doc_url "const" typescript "")" "${OFFLINE_DOCS_DIR}" \
|
|
"a TS term resolves through the JS mirror"
|
|
|
|
echo "== get_doc_url: a TS runtime term falls through to the JS builder =="
|
|
reset_state
|
|
_t_has "$(get_doc_url "const" typescript "")" "developer.mozilla.org" \
|
|
"a runtime term prefers MDN over the TS handbook"
|
|
_t_has "$(get_doc_url "interface" typescript "")" "typescriptlang.org" \
|
|
"a TS-only term still gets the TS handbook"
|
|
|
|
echo "== detect_language =="
|
|
reset_state
|
|
stage_tokei "Python" "JavaScript"
|
|
_t_eq "python" "$(detect_language)" "the language with the most code wins"
|
|
|
|
reset_state
|
|
stage_tokei "Rust"
|
|
_t_eq "rust" "$(detect_language)" "a single-language repo detects that language"
|
|
|
|
reset_state
|
|
stage_tokei "C++"
|
|
out="$(detect_language)"
|
|
if [[ -n "$out" ]]; then
|
|
_t_pass "a punctuated language name still maps to something ('${out}')"
|
|
else
|
|
_t_fail "a punctuated language name still maps to something"
|
|
fi
|
|
|
|
echo "== detect_language: no stats file =="
|
|
reset_state
|
|
out="$(detect_language)"
|
|
if [[ -n "$out" ]]; then
|
|
_t_pass "a missing tokei_stats.txt falls back to a default ('${out}')"
|
|
else
|
|
_t_fail "a missing tokei_stats.txt falls back to a default"
|
|
fi
|
|
|
|
_t_summary
|