accuracy(Bash): measure import graph accuracy and close gaps below 90%
Part of #237.
Starting estimate: 50-70% recall. This is an unmeasured guess.
Measure
Run codemap on real Bash repositories at pinned commits and compare it to ground truth.
- Suggested ground truth: Manual sample of source lines.
- Report: recall, precision, and whether the coverage status was honest for each file.
Likely gaps to check
source with variables, paths relative to the script, whether dropped edges are reported.
Done when
- Repositories, commits, method and numbers are recorded here.
- Each miss has a root cause.
- Recall is at or above 90%, or the remaining gap is one codemap cannot close and its coverage status says so.
Bash import graph accuracy (#247)
Repos: bats-core/bats-core @ 5b61d8f22b46abf001e218cdd63f2938c356fa93 (385 files, sampled .sh/.bash/.bats), Bash-it/bash-it @ 72ea9e285fe1828977d1cd2bc596b901bcc57440 (498 files). Pyenv (@ e6669f0a84df60daba8672c3b3f0caebd0fdcef8, 1826 files) was cloned but replaced as a sampling target because its scripts are extensionless (see cause 3).
Method: git clone --depth 1, static reading only (no scripts, builds or tests executed). Sample: 30 files per repo via shuf -n 30 with a fixed seed (a sample, not the whole repo). For each sampled file F, codemap --json --importers F (codemap 4.6.3) was compared to a ground-truth importer set. Because 9 s per call ruled out querying every file, the unit is incoming edges to the sampled file. Truth was built by a regex resolver I wrote (tools/truth.py in the local scratch dir) and the disagreements were reviewed by hand. Intra-project edges only. Recall = TP/(TP+FN), precision = TP/(TP+FP) over edges. Honesty = whether coverage_status for a sampled file with a miss was something other than complete. Auto-written .codemap/config.json only lists were checked and include the target language. Bash truth = source/. lines, bats load lines, with $BATS_ROOT/$BATS_LIBDIR -> lib/, $BASH_IT -> repo root, ${BATS_TEST_DIRNAME} -> file dir; computed/dynamic paths and source <(...) skipped.
| repo | sampled | TP | FP | FN | recall | precision | files with a miss | miss under complete |
|---|---|---|---|---|---|---|---|---|
| bats-core | 30 | 0 | 0 | 18 | 0.00 | n/a (0 reported) | 2 | 2 |
| bash-it | 30 | 0 | 0 | 4 | 0.00 | n/a (0 reported) | 3 | 3 |
Whole-repo cross-check using --deps imports: my resolver finds 53 (bats-core) and 56 (bash-it) resolvable intra-project edges; codemap emitted 0 intra-project edges in either (its only raw imports were <(grep, ~/.fzf.bash, virtualenvwrapper.sh). Every miss was labeled complete.
Root causes, ranked:
- Quoted and variable-prefixed source arguments are not captured (bats-core 22 source lines, bash-it 72, nearly all quoted). Example: bash-it bash_it.sh:21
source "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"; bats-core libexecsource "$BATS_ROOT/$BATS_LIBDIR/bats-core/validator.bash". Code: scanner/sg-rules/bash.yml patternssource $FILEand. $FILEonly matched bare words. Even a literalsource "nonexistent file"is skipped. Fix: small to capture strings, medium to resolve $VAR prefixes (repo-root or script-dir heuristics), not closable for truly dynamic paths. - bats
loadnot modeled. Example: test/bats.bats:736load 'concurrent-coordination'-> test/concurrent-coordination.bash (17 of the 18 bats-core misses). Fix: small (new rule plus .bash/.sh suffix probing relative to the file). - Extensionless scripts and the auto
onlyfilter. Pyenv's auto configonly= [bats, yml, bash, agignore, dockerignore]; 50 shebang shell scripts (libexec/pyenv-*, etc.) were not indexed, 40 files indexed in total, statuscomplete. Also bats-core test/fixtures/bats/external_functions.bash returned not_indexed=true (excluded by the auto configexclude: fixtures) with statuscomplete. Fix: small (shebang detection; make not_indexed or filtered files downgrade status).
Caveat: sampled misses are few (bats-core 2 files, bash-it 3 files) because the sample mostly drew leaf files; the whole-repo 0/53 and 0/56 is the stronger number.
Correction after re-testing on 4.6.3
The claim that quoted source arguments are not matched is wrong as stated. In a minimal repo, source ./lib/b.sh and source "./lib/c.sh" both produce edges. source "${DIR}/lib/d.sh" produces none. The cause to fix for this root is the variable prefix, not the quoting.
Measured with codemap 4.6.3. Sampled numbers are samples, not a census.
Released in v4.6.4. Behavior change: a dynamic prefix such as $(dirname "$0") links only when it is self-locating or assigned in the repo. Relative $(cd .. && pwd) no longer links and reads partial, and so does a variable set only by CI or the environment. load links only in files bats reaches. Remaining gaps: command/builtin/eval source, one-line case, function-body source, and extensionless scripts.