From d6715ca6ef9c886e4e6f5f494306e2be293f9a86 Mon Sep 17 00:00:00 2001 From: Kiran Kumar H V Date: Wed, 19 Aug 2026 18:05:58 +0530 Subject: [PATCH 1/3] bug: #706 edit link/button leads to 404 --- src/incremental.py | 12 +++++++++++- src/incremental_dirty_build_test.py | 27 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/incremental.py b/src/incremental.py index fdb692c4c..89d4bbb3d 100644 --- a/src/incremental.py +++ b/src/incremental.py @@ -86,6 +86,11 @@ def update_module_hash(build_dir: Path, sentinel_files: list[Path]) -> None: (build_dir / _MODULE_HASH_FILE).write_text(_compute_hash(sentinel_files)) +def _doc_path(package_dir_env: str, source_directory: str) -> Path: + """Repo-relative path to the Sphinx source dir (used for the edit-on-GitHub URL).""" + return Path(package_dir_env) / source_directory + + def _mounted_watch_dirs( manifest_path: Path, ws_root: Path | None, runfiles_dir: Path | None = None ) -> list[str]: @@ -196,7 +201,12 @@ def _mounted_watch_dirs( base_arguments.append(f"-A=github_user={github_user}") base_arguments.append(f"-A=github_repo={github_repo}") base_arguments.append("-A=github_version=main") - base_arguments.append(f"-A=doc_path={package_dir / source_directory}") + # doc_path must be repo-relative so the edit URL does not contain the + # absolute runner filesystem path (e.g. /home/runner/work/…/docs). + relative_doc_path = _doc_path( + os.environ.get("PACKAGE_DIR", ""), source_directory + ) + base_arguments.append(f"-A=doc_path={relative_doc_path}") if os.getenv("KNOWN_GOOD_JSON"): base_arguments.append(f"--define=KNOWN_GOOD_JSON={get_env('KNOWN_GOOD_JSON')}") diff --git a/src/incremental_dirty_build_test.py b/src/incremental_dirty_build_test.py index 7c13e6c8c..f024d663b 100644 --- a/src/incremental_dirty_build_test.py +++ b/src/incremental_dirty_build_test.py @@ -19,6 +19,7 @@ from pyfakefs.fake_filesystem import FakeFilesystem as FFS from incremental import ( + _doc_path, # pyright: ignore[reportPrivateUsage] - white-box unit test _mounted_watch_dirs, # pyright: ignore[reportPrivateUsage] - white-box unit test clean_builddir_if_stale, update_module_hash, @@ -148,3 +149,29 @@ def test_mounted_watch_dirs_match_sphinx_mount_paths(tmp_path: Path) -> None: str(workspace / "extensions/local/docs"), str(runfiles_dir / "vendor+" / "docs"), ] + + +# --- _doc_path (edit-on-GitHub URL) ------------------------------------------ + + +def test_doc_path_is_relative_for_root_package() -> None: + path = _doc_path("", "docs") + assert str(path) == "docs" + assert not path.is_absolute() + + +def test_doc_path_is_relative_for_nested_package() -> None: + path = _doc_path("submodule", "docs") + assert str(path) == "submodule/docs" + assert not path.is_absolute() + + +def test_doc_path_never_contains_absolute_runner_path() -> None: + # Regression test: previously doc_path was derived from BUILD_WORKSPACE_DIRECTORY. + absolute_ws = Path("/home/runner/work/docs-as-code/docs-as-code") + old_doc_path = absolute_ws / "docs" + assert str(absolute_ws) in str(old_doc_path) + + new_doc_path = _doc_path("", "docs") + assert str(absolute_ws) not in str(new_doc_path) + assert not new_doc_path.is_absolute() From 2131ecb157e72ad8905935be6a00850958b96525 Mon Sep 17 00:00:00 2001 From: Kiran Kumar H V Date: Thu, 20 Aug 2026 15:08:54 +0530 Subject: [PATCH 2/3] bug: #706 edit link/button leads to 404 Review comments taken care of --- src/incremental.py | 4 +--- src/incremental_dirty_build_test.py | 27 --------------------------- 2 files changed, 1 insertion(+), 30 deletions(-) diff --git a/src/incremental.py b/src/incremental.py index 89d4bbb3d..cd8bd318d 100644 --- a/src/incremental.py +++ b/src/incremental.py @@ -203,9 +203,7 @@ def _mounted_watch_dirs( base_arguments.append("-A=github_version=main") # doc_path must be repo-relative so the edit URL does not contain the # absolute runner filesystem path (e.g. /home/runner/work/…/docs). - relative_doc_path = _doc_path( - os.environ.get("PACKAGE_DIR", ""), source_directory - ) + relative_doc_path = Path(os.environ.get("PACKAGE_DIR", ""), source_directory) base_arguments.append(f"-A=doc_path={relative_doc_path}") if os.getenv("KNOWN_GOOD_JSON"): diff --git a/src/incremental_dirty_build_test.py b/src/incremental_dirty_build_test.py index f024d663b..7c13e6c8c 100644 --- a/src/incremental_dirty_build_test.py +++ b/src/incremental_dirty_build_test.py @@ -19,7 +19,6 @@ from pyfakefs.fake_filesystem import FakeFilesystem as FFS from incremental import ( - _doc_path, # pyright: ignore[reportPrivateUsage] - white-box unit test _mounted_watch_dirs, # pyright: ignore[reportPrivateUsage] - white-box unit test clean_builddir_if_stale, update_module_hash, @@ -149,29 +148,3 @@ def test_mounted_watch_dirs_match_sphinx_mount_paths(tmp_path: Path) -> None: str(workspace / "extensions/local/docs"), str(runfiles_dir / "vendor+" / "docs"), ] - - -# --- _doc_path (edit-on-GitHub URL) ------------------------------------------ - - -def test_doc_path_is_relative_for_root_package() -> None: - path = _doc_path("", "docs") - assert str(path) == "docs" - assert not path.is_absolute() - - -def test_doc_path_is_relative_for_nested_package() -> None: - path = _doc_path("submodule", "docs") - assert str(path) == "submodule/docs" - assert not path.is_absolute() - - -def test_doc_path_never_contains_absolute_runner_path() -> None: - # Regression test: previously doc_path was derived from BUILD_WORKSPACE_DIRECTORY. - absolute_ws = Path("/home/runner/work/docs-as-code/docs-as-code") - old_doc_path = absolute_ws / "docs" - assert str(absolute_ws) in str(old_doc_path) - - new_doc_path = _doc_path("", "docs") - assert str(absolute_ws) not in str(new_doc_path) - assert not new_doc_path.is_absolute() From 2ebbde405e98bfe98a1df272178aac21e9947b43 Mon Sep 17 00:00:00 2001 From: Kiran Kumar H V Date: Thu, 20 Aug 2026 16:15:23 +0530 Subject: [PATCH 3/3] bug: #706 edit link/button leads to 404 : Review comments taken care --- src/incremental.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/incremental.py b/src/incremental.py index cd8bd318d..8004271af 100644 --- a/src/incremental.py +++ b/src/incremental.py @@ -86,11 +86,6 @@ def update_module_hash(build_dir: Path, sentinel_files: list[Path]) -> None: (build_dir / _MODULE_HASH_FILE).write_text(_compute_hash(sentinel_files)) -def _doc_path(package_dir_env: str, source_directory: str) -> Path: - """Repo-relative path to the Sphinx source dir (used for the edit-on-GitHub URL).""" - return Path(package_dir_env) / source_directory - - def _mounted_watch_dirs( manifest_path: Path, ws_root: Path | None, runfiles_dir: Path | None = None ) -> list[str]: @@ -203,7 +198,7 @@ def _mounted_watch_dirs( base_arguments.append("-A=github_version=main") # doc_path must be repo-relative so the edit URL does not contain the # absolute runner filesystem path (e.g. /home/runner/work/…/docs). - relative_doc_path = Path(os.environ.get("PACKAGE_DIR", ""), source_directory) + relative_doc_path = Path(os.environ.get("PACKAGE_DIR", "")) / source_directory base_arguments.append(f"-A=doc_path={relative_doc_path}") if os.getenv("KNOWN_GOOD_JSON"):