Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions TECHNICAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,7 @@ There is no service to restart, no rollback beyond `npm uninstall -g codeshot` /
- A cyclic call graph (recursion, or A and B calling each other) can cause `--depth`'s transitive traversal to rediscover the root symbol or an already-drawn depth-1 node as a "from"/"to" endpoint of a deeper edge. This is harmless (graphviz just draws the extra edge; `dedupeEdges` still collapses exact repeats) but can occasionally show what looks like a redundant edge back into an already-visible node.
- **`--architecture` mode's edges can be misattributed to the wrong file when symbol names collide.** `codegraph callees <name>` takes a bare name with no way to disambiguate which file's symbol is meant (unlike `codegraph node -f <file>`, which does support this). In symbol mode this ambiguity affects exactly one user-chosen name — a corner case. In `--architecture` mode, Codeshot probes `codegraph callees` for every enumerated symbol in the whole repo, where generically-named methods (`render`, `init`, `get`, `run`, `String`) existing in more than one file is common, not rare, in most real codebases (confirmed: 12 duplicate names out of 500 probed symbols on a real ~1,900-node Go repo). `duplicateNameWarning` surfaces this on stderr with real examples from the current run, but Codeshot has no way to fix the underlying ambiguity — same as the other `codegraph` indexing gaps documented above, it can only draw what `codegraph` returns.
- **`--architecture` mode's enumeration query (`codegraph query --json --limit <big> -- ''`) has confirmed, inconsistent `--limit` behavior worth knowing before trusting it.** Without `--limit`, an empty-string query silently caps around 50 results regardless of actual repo size (confirmed on a real 1,870-node index). Passing a large `--limit` (confirmed with both 500 and 2000 against that same index) instead returns *every* result codegraph has — more than the requested number, not capped at it. Codeshot works around this by always passing a very large `--limit` to force the "return everything" behavior, then applying the real `--max-symbols` cap client-side — but the *order* codegraph returns results in in that case is unknown (untested whether it's insertion order, alphabetical, ID-based, or something else), so on a repo larger than `--max-symbols`, the kept subset should not be assumed to sample evenly across the whole repo — it could be clustered by file, directory, or however codegraph happens to have stored them.

<!-- codeshot:arch:start -->
![Architecture — generated by codeshot](docs/architecture.svg)
<!-- codeshot:arch:end -->
32 changes: 32 additions & 0 deletions docs/architecture.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion render/callgraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,13 @@ async function main() {

if (values.architecture) {
const dot = await runArchitectureMode(repoPath, { limit, maxSymbols, maxRender });
const alt = `${path.basename(path.resolve(repoPath))} architecture — generated by codeshot`;
// Fixed, path-independent alt: deriving it from the checkout's directory
// basename made the embedded markdown vary by where the repo was cloned
// (a bare-worktree dir, "master", a branch name...), which both read wrong
// and broke --check portability — a fresh clone under a different dir name
// would report the committed diagram as drifted. The repo name is redundant
// anyway; the diagram lives in that repo's own doc.
const alt = 'Architecture — generated by codeshot';
finishOutput(dot, { format, outFile, embedFile, check: values.check, markerId: 'arch', alt });
return;
}
Expand Down
5 changes: 5 additions & 0 deletions test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,11 @@ test('CLI --embed --architecture round-trips: writes image + block, --check then
const md = fs.readFileSync(doc, 'utf8');
assert.match(md, /<!-- codeshot:arch:start -->/);
assert.match(md, /!\[[^\]]*generated by codeshot\]\(codeshot-arch-[^)]+\.svg\)/);
// The arch alt must be path-independent (not the checkout dir basename), so
// the embedded markdown is reproducible across clones and --check is stable.
// Before the fix it was `<basename(repoRoot)> architecture — ...`.
assert.match(md, /!\[Architecture — generated by codeshot\]/);
assert.doesNotMatch(md, new RegExp(`!\\[${path.basename(path.resolve(repoRoot))} architecture`), 'alt must not leak the checkout dir name');
const imgName = md.match(/\]\((codeshot-arch-[^)]+\.svg)\)/)[1];
assert.ok(fs.existsSync(path.join(dir, imgName)), 'expected the image written next to the doc');

Expand Down
Loading