Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

fix(ui): name the real last line of a file in the source pager

Bernhard Jackiewiczec5fa40949df
diff --git a/graph-ui/src/architecture/SourceEvidenceDrawer.test.tsx b/graph-ui/src/architecture/SourceEvidenceDrawer.test.tsx
index 6812221c1..fa859c26e 100644
--- a/graph-ui/src/architecture/SourceEvidenceDrawer.test.tsx
+++ b/graph-ui/src/architecture/SourceEvidenceDrawer.test.tsx
@@ -181,14 +181,25 @@ it('focuses close, lets Escape close the modeless drawer, then restores its orig
});
it('says "end of file" when the last page reaches the end of the Module, so a disabled Next is not a mystery (hand test K13)', async () => {
- // django/contrib/postgres/aggregates/general.py: 65 lines plus the empty EOF line, read from line 42.
- const last = { start_line: 42, end_line: 66, source: Array.from({ length: 25 }, (_, i) => `line ${42 + i}`).join('\n'),
+ // django/contrib/postgres/aggregates/general.py: 65 lines; the Module range ends at 66, the empty segment after the last line break.
+ const last = { start_line: 42, end_line: 66, source: `${Array.from({ length: 24 }, (_, i) => `line ${42 + i}`).join('\n')}\n`,
source_truncated: false, source_clipped: false, next_start_line: undefined, original_end_line: undefined };
const ui = await mount(vi.fn(async () => page(42, last)));
await act(async () => { await new Promise(resolve => setTimeout(resolve, 0)); });
const pager = ui.container.querySelector('nav[aria-label="Source pages"]')!;
+ expect(ui.container.querySelector('[role=alert]')).toBeNull();
expect(pager.textContent).toContain('Lines 42 to 66 · end of file');
const next = [...pager.querySelectorAll('button')].find(button => button.textContent === 'Next lines')!;
expect(next.disabled).toBe(true);
- expect(next.title).toBe('Line 66 is the end of this file.');
+ // The title names the file's real last line, not the empty end segment the range counts.
+ expect(next.title).toBe('Line 65 is the last line of this file.');
+});
+
+it('names the last line itself when a file ends without a final line break (hand test K13)', async () => {
+ const last = { start_line: 42, end_line: 66, source: Array.from({ length: 25 }, (_, i) => `line ${42 + i}`).join('\n'),
+ source_truncated: false, source_clipped: false, next_start_line: undefined, original_end_line: undefined };
+ const ui = await mount(vi.fn(async () => page(42, last)));
+ await act(async () => { await new Promise(resolve => setTimeout(resolve, 0)); });
+ const next = [...ui.container.querySelectorAll('nav[aria-label="Source pages"] button')].find(button => button.textContent === 'Next lines')!;
+ expect(next.getAttribute('title')).toBe('Line 66 is the last line of this file.');
});
diff --git a/graph-ui/src/architecture/SourceEvidenceDrawer.tsx b/graph-ui/src/architecture/SourceEvidenceDrawer.tsx
index dcf74682e..e56b2da1d 100644
--- a/graph-ui/src/architecture/SourceEvidenceDrawer.tsx
+++ b/graph-ui/src/architecture/SourceEvidenceDrawer.tsx
@@ -9,7 +9,7 @@ export interface SourceEvidenceTarget { filePath: string; line?: number; name?:
const PAGE_LINES = 160;
/* Hand test K13: a disabled "Next lines" at the last page read like a fault. The page says where the file ends. */
const END_OF_FILE = ' · end of file';
-const endOfFileTitle = (line: number) => `Line ${line} is the end of this file.`;
+const endOfFileTitle = (line: number) => `Line ${line} is the last line of this file.`;
const validLine = (value: number | undefined): value is number => value !== undefined && Number.isSafeInteger(value) && value > 0;
export function fileQualifiedName(graph: GraphData | undefined, path: string): string | undefined {
@@ -104,6 +104,8 @@ export default function SourceEvidenceDrawer({ project, target, graph, client, o
const next = source?.next_start_line;
const canNext = Boolean(more && validLine(next) && validLine(lastLine) && next === lastLine + 1 && rangeMatches);
const atEnd = Boolean(source && !more && rangeMatches && validLine(lastLine));
+ // The Module range counts the empty segment after the final line break; the file's last line is the one before it.
+ const lastFileLine = atEnd && lines.length > 1 && lines.at(-1) === '' ? lastLine! - 1 : lastLine;
const locationVisible = requestedLine !== undefined && validLine(firstLine) && validLine(lastLine)
&& requestedLine >= firstLine && requestedLine <= lastLine && rangeMatches;
useEffect(() => {
@@ -150,7 +152,7 @@ export default function SourceEvidenceDrawer({ project, target, graph, client, o
{more && !canNext && <p role="status">The source is truncated, but no valid next page was supplied. Refresh or open Explore to inspect the available source.</p>}
<nav aria-label="Source pages"><button disabled={!rangeMatches || !firstLine || firstLine <= 1} onClick={() => moveTo(Math.max(1, firstLine! - PAGE_LINES))}>Previous lines</button>
<span>{rangeMatches ? `Lines ${firstLine} to ${lastLine}` : 'Unverified line range'}{source.original_end_line ? ` · reported end ${source.original_end_line}` : ''}{atEnd ? END_OF_FILE : ''}</span>
- <button disabled={!canNext} title={atEnd ? endOfFileTitle(lastLine!) : undefined} onClick={() => moveTo(next!)}>Next lines</button></nav>
+ <button disabled={!canNext} title={atEnd ? endOfFileTitle(lastFileLine!) : undefined} onClick={() => moveTo(next!)}>Next lines</button></nav>
</>}
</aside>;
}