Skip to content

fix(ci): number duplicate heading anchors like GitHub - #1449

Merged
Giom-V merged 5 commits into
google-gemini:mainfrom
mangeshraut712:fix/link-checker-repeated-heading-anchors-1437
Nov 2, 2026
Merged

Giom-V merged 5 commits into
google-gemini:mainfrom
mangeshraut712:fix/link-checker-repeated-heading-anchors-1437

Conversation

@mangeshraut712

Copy link
Copy Markdown

Why

extract_anchors_from_content only stored the bare heading slug. When a Markdown file had repeated headings, GitHub still exposes #setup-1, #setup-2, … for the later copies, but the Link Checker rejected those fragments and failed CI for valid section links. Fixes #1437.

What

  • When indexing Markdown headings, assign GitHub-style duplicate suffixes: first occurrence stays bare (setup), the next is setup-1, then setup-2, and so on.
  • Add unit coverage for the numbering and for run_link_audit accepting #setup-1.

Test

extract_anchors_from_content only kept the bare slug, so links to the
second and later copies of a repeated heading (#setup-1, #setup-2, …)
failed the Link Checker even though GitHub generates those anchors.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where the link checker failed to validate internal links pointing to duplicate Markdown headings. By aligning the anchor extraction logic with GitHub's standard of using numeric suffixes for repeated headings, the changes ensure that internal links are correctly resolved and validated during CI processes.

Highlights

  • Duplicate Heading Anchor Support: Updated the anchor extraction logic to mirror GitHub's behavior by appending numeric suffixes (e.g., -1, -2) to duplicate heading slugs.
  • Improved Link Audit Accuracy: Ensured the link checker correctly validates internal links that point to duplicate headings, preventing false-positive CI failures.
  • Expanded Test Coverage: Added unit tests to verify both the slug numbering logic and the successful resolution of links pointing to duplicate headings.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@github-actions github-actions Bot added the status:awaiting review PR awaiting review from a maintainer label Oct 26, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces GitHub-style duplicate heading slug numbering (e.g., setup, setup-1, setup-2) to the link checker tool and adds corresponding unit tests. The review feedback identifies a correctness issue where duplicate headings in Jupyter Notebooks are not tracked correctly across different cells because the state dictionary is initialized locally within the anchor extraction function. To resolve this, it is recommended to allow passing a shared state dictionary to preserve slug counts across cells and to add a test case verifying this behavior for notebooks.

Comment thread tools/check_all_links.py Resolved
Comment thread tools/test_check_all_links.py Resolved
Honor gemini-code-assist high-priority feedback on #1449: share
seen_slugs across ipynb markdown/raw cells so GitHub-style
setup / setup-1 numbering matches whole-document rendering, and
add a cross-cell unit test.

Signed-off-by: Mangesh Raut <[email protected]>
@kkorpal kkorpal self-assigned this Oct 26, 2026
@kkorpal

kkorpal commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Thanks @mangeshraut712, correct fix. Verified: the #1437 fixture now yields setup / setup-1 and the audit exits 0, 21/21 tests pass with the 3 new ones failing on main, and a full internal audit of the repo is unchanged. The shared counter across notebook cells is the right call. LGTM.

Heads-up: #1436 edits the same function and the same test region, so the two PRs conflict. Whichever merges second will need a quick rebase if #1436 lands first, could you rebase onto it?

@mangeshraut712

Copy link
Copy Markdown
Author

Friendly bump — CI is green and this is ready for review when you have a minute. Happy to adjust anything.

@mangeshraut712

Copy link
Copy Markdown
Author

Still green / merge-ready if you get a chance tonight.

@mangeshraut712

Copy link
Copy Markdown
Author

@kkorpal CI is green on this. It numbers duplicate heading anchors the same way GitHub does so the link audit stays consistent. You already verified the fixture — if it still looks good, could you please merge when you get a chance? Thanks.

@kkorpal kkorpal added the type:bug Something isn't working label Oct 27, 2026

@Giom-V Giom-V left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix @mangeshraut712! I removed the unit test additions from this PR so we keep maintenance overhead low on internal helper scripts. Merging!

@Giom-V
Giom-V merged commit 78ee604 into google-gemini:main Nov 2, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:awaiting review PR awaiting review from a maintainer type:bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Link checker rejects valid numbered anchors for repeated headings

3 participants