Skip to content

Commit d4b9beb

Browse files
sndagsterDagster Devtools
authored andcommitted
Fix layout-fragile git-root assertion in source code metadata test (#25855)
## Summary & Motivation The `test_link_code_references_to_git_if_cloud_cloud_context[github]`, `[gitlab]`, and `test_link_code_references_to_git_if_cloud_override_cloud_context` cases were failing in buildkite. The expected git URLs hardcoded `dagster-oss/python_modules/dagster-cloud`, but `link_code_references_to_git_if_cloud` derives the repository path as the file path relative to the nearest `.git` ancestor (via `_locate_git_root` + `AnchorBasedFilePathMapping`). That is checkout-layout-dependent: it resolves to `dagster-oss/python_modules/dagster-cloud/...` in an internal dev checkout (so the test passed locally) but to `python_modules/dagster-cloud/...` in buildkite, where the package sits at the OSS-style layout under its own git root. The code is correct — the test was layout-fragile. The fix asserts only the layout-independent parts of the URL: the branch-base prefix (`startswith`) and the stable `dagster-cloud/.../file#Ln` tail (`endswith`). The repo prefix in between (`dagster-oss/python_modules/` vs `python_modules/`) is exactly the env-dependent segment that shouldn't be pinned — pinning it was the original bug. It also drops the dead, wrong-depth `GIT_ROOT_PATH` constant. Since this file is copybara-synced, the fix propagates to `dagster-io/dagster`, whose identical copy has the same fragility. ## Test Plan `tox -e py312-default -- -k link_code_references` — all 6 cases pass. ruff and ty clean. The assertions no longer depend on where `.git` sits relative to the package, so they hold in every layout (internal dev, buildkite, OSS). ## Changelog NOCHANGELOG Internal-RevId: 75edf6efe4e5f540e1b9fe26a28ac3641b39cbc1
1 parent 93a9d89 commit d4b9beb

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

python_modules/dagster-cloud/dagster_cloud_tests/metadata_tests/test_source_code_metadata.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
# path of the `dagster` package on the filesystem
2222
DAGSTER_CLOUD_PACKAGE_PATH = os.path.normpath(file_relative_path(__file__, "../../"))
23-
GIT_ROOT_PATH = os.path.normpath(os.path.join(DAGSTER_CLOUD_PACKAGE_PATH, "../../../"))
2423

2524
# path of the current file relative to the `dagster` package root
2625
PATH_IN_PACKAGE = "/dagster_cloud_tests/metadata_tests/"
@@ -152,10 +151,10 @@ def test_link_code_references_to_git_if_cloud_cloud_context(
152151
asset.metadata_by_key[key]["dagster/code_references"].code_references[-1],
153152
)
154153

155-
assert meta.url == (
156-
f"{source_control_branch_base}/dagster-oss/python_modules/dagster-cloud"
157-
+ (expected_file_path[len(DAGSTER_CLOUD_PACKAGE_PATH) :])
158-
+ f"#L{expected_line_number}"
154+
path_in_package = expected_file_path[len(DAGSTER_CLOUD_PACKAGE_PATH) :]
155+
assert meta.url.startswith(f"{source_control_branch_base}/")
156+
assert meta.url.endswith(
157+
f"dagster-cloud{path_in_package}#L{expected_line_number}"
159158
)
160159

161160

@@ -225,10 +224,12 @@ def test_link_code_references_to_git_if_cloud_override_cloud_context() -> None:
225224
asset.metadata_by_key[key]["dagster/code_references"].code_references[-1],
226225
)
227226

228-
assert meta.url == (
229-
"https://github.com/dagster-io/other-repo/tree/main/dagster-oss/python_modules/dagster-cloud"
230-
+ (expected_file_path[len(DAGSTER_CLOUD_PACKAGE_PATH) :])
231-
+ f"#L{expected_line_number}"
227+
path_in_package = expected_file_path[len(DAGSTER_CLOUD_PACKAGE_PATH) :]
228+
assert meta.url.startswith(
229+
"https://github.com/dagster-io/other-repo/tree/main/"
230+
)
231+
assert meta.url.endswith(
232+
f"dagster-cloud{path_in_package}#L{expected_line_number}"
232233
)
233234

234235

0 commit comments

Comments
 (0)