tooling: make the docs link check platform-independent #1525

Merged
RenzoWit35 merged 1 commit from upstream-pr/1532 into main 2026-11-24 14:15:00 +00:00
RenzoWit35 commented 2026-11-24 13:43:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RenzoWit35 on 2026-11-24T13:43:35Z.


Change

tests/docs_links_check.py resolved link targets with Path/os.path.normpath, whose behavior depends on the OS:

  • On Windows a backslash is a path separator, so [x](docs\Guide.md) was accepted. On Linux normpath keeps the backslash as part of a filename, so the target is not a tracked file and the check fails. GitHub also treats it as a broken link. The same tree could pass on a Windows machine and fail on Linux CI.
  • [x](docs/Guide.md/) (trailing slash on a file) was accepted on both platforms because normpath drops the trailing slash. GitHub does not resolve it as the file.

link_error now rejects a target containing a backslash (after the script's own unescape and URL-decode) with backslash in path (use /), and rejects a trailing slash on a tracked file with trailing slash on a file. A trailing slash on a tracked directory is still accepted. Only tests/docs_links_check.py changes (+15 lines).

Verification

Before (unmodified main, Windows, Python 3.14.5), scratch repo with tracked docs/Guide.md:

  • [x](docs\Guide.md) -> accepted (no error)
  • [x](docs/Guide.md/) -> accepted (no error)
  • Linux behavior, shown with posixpath.normpath: docs\Guide.md stays a single filename containing a backslash (not a tracked path, so rejected); docs/Guide.md/ becomes docs/Guide.md (accepted). I did not run the check on Linux itself.

Negative control: the new self-test block run against the unmodified link_error from main fails with an AssertionError.

After:

python -B tests/docs_links_check.py    -> Self-test passed. Checked 16 Markdown files and 340 links. (exit 0)
python -B tests/bidi_controls_check.py -> Self-test passed. Checked 1239 tracked ... no bidirectional controls. (exit 0)

New self-test cases: backslash link (rejected), trailing slash on a file (rejected), [dir](docs/) (accepted, control). No real link in the tree trips the new rules.

Evidence and follow-up

  • Base origin/main 1ca0dec1. Run on Windows 11 only; the Linux behavior for the backslash case is reasoned from posixpath, not run on Linux here.
  • Not done: [x](file.md#) (empty fragment) is reported as "heading does not exist" while GitHub treats it as no fragment. Separate behavior, left for a follow-up.
  • The check is already listed in AGENTS.md and the python-linux job, so no registration change.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6583158544 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1532). Originally posted by [RenzoWit35](https://github.com/RenzoWit35) on 2026-11-24T13:43:35Z. --- ## Change `tests/docs_links_check.py` resolved link targets with `Path`/`os.path.normpath`, whose behavior depends on the OS: - On Windows a backslash is a path separator, so `[x](docs\Guide.md)` was accepted. On Linux `normpath` keeps the backslash as part of a filename, so the target is not a tracked file and the check fails. GitHub also treats it as a broken link. The same tree could pass on a Windows machine and fail on Linux CI. - `[x](docs/Guide.md/)` (trailing slash on a file) was accepted on both platforms because `normpath` drops the trailing slash. GitHub does not resolve it as the file. `link_error` now rejects a target containing a backslash (after the script's own unescape and URL-decode) with `backslash in path (use /)`, and rejects a trailing slash on a tracked file with `trailing slash on a file`. A trailing slash on a tracked directory is still accepted. Only `tests/docs_links_check.py` changes (+15 lines). ## Verification Before (unmodified `main`, Windows, Python 3.14.5), scratch repo with tracked `docs/Guide.md`: - `[x](docs\Guide.md)` -> accepted (no error) - `[x](docs/Guide.md/)` -> accepted (no error) - Linux behavior, shown with `posixpath.normpath`: `docs\Guide.md` stays a single filename containing a backslash (not a tracked path, so rejected); `docs/Guide.md/` becomes `docs/Guide.md` (accepted). I did not run the check on Linux itself. Negative control: the new self-test block run against the unmodified `link_error` from `main` fails with an `AssertionError`. After: ``` python -B tests/docs_links_check.py -> Self-test passed. Checked 16 Markdown files and 340 links. (exit 0) python -B tests/bidi_controls_check.py -> Self-test passed. Checked 1239 tracked ... no bidirectional controls. (exit 0) ``` New self-test cases: backslash link (rejected), trailing slash on a file (rejected), `[dir](docs/)` (accepted, control). No real link in the tree trips the new rules. ## Evidence and follow-up - Base `origin/main` 1ca0dec1. Run on Windows 11 only; the Linux behavior for the backslash case is reasoned from `posixpath`, not run on Linux here. - Not done: `[x](file.md#)` (empty fragment) is reported as "heading does not exist" while GitHub treats it as no fragment. Separate behavior, left for a follow-up. - The check is already listed in `AGENTS.md` and the `python-linux` job, so no registration change. AI-assisted.
upstream-sync closed this pull request 2026-11-24 15:01:53 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!1525
No description provided.