Skip to content

Bash extractor: a call from one sourced library to another, both loaded by the same script, gets no edge #5564

Done

Description

@yashsaxena

What happens

In bash, everything one script loads lands in one shell: a library can call a function from another library the same script loaded, without loading it itself.

# bin/tool loads lib/a.sh and lib/b.sh
# lib/a.sh:  greet() { shout hello; }   # shout is in lib/b.sh

Graphify resolves a call only against the caller's own file and the files that file loads, so greet -> shout is lost and shout looks unused.

Reproduced on graphifyy 0.9.122 (newest on PyPI), installed with pip, nothing patched, Python 3.12, Ubuntu.

Reproduction

Three files in a new git repo:

# bin/tool
#!/usr/bin/env bash
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
. "$ROOT/lib/a.sh"
. "$ROOT/lib/b.sh"
greet
# lib/a.sh
greet() { shout hello; }
# lib/b.sh
shout() { echo "$1"; }

Command:

graphify extract "$PWD" --code-only --out /tmp/out
jq -r '.links[] | select(.relation != "contains" and .relation != "defines")
       | "\(.relation) \(.source) -> \(.target)"' /tmp/out/graphify-out/graph.json

Expected

imports_from bin/tool -> lib/a.sh
imports_from bin/tool -> lib/b.sh
calls lib/a.sh greet -> lib/b.sh shout

Got

calls bin/tool (script) -> lib/a.sh greet
imports_from bin/tool -> lib/a.sh
imports_from bin/tool -> lib/b.sh

Suggested fix

For bash, resolve a call that has no match in the caller's own reach against the pool of files one entry script loads (its own loads, and theirs), when the caller is in that pool.
When more than one pool has a match, an edge per pool keeps it correct for each script.
Related: #2141 (calls into a sourced file, fixed for the direct case).

Activity

  1. github-actions commented on Nov 28, 2026

    @github-actions

    Thanks for opening this issue, @yashsaxena. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

  2. added a commit that references this issue on Nov 28, 2026
    4b198d1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions