-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ENG-9503: Serve integration docs images locally #6671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
carlosabadia
wants to merge
7
commits into
main
Choose a base branch
from
carlos/self-serve-integrations-docs-images
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e1f5dc0
init
carlosabadia 9261e3a
updates
carlosabadia 46125dd
update
carlosabadia 78e669f
Merge branch 'main' of https://github.com/reflex-dev/reflex into carl…
carlosabadia 46391fc
update
carlosabadia cc6ec5b
update
carlosabadia 5c8edef
add tests here
carlosabadia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| """Tests for reflex_site_shared.integrations URL helpers.""" | ||
|
|
||
| import re | ||
| from pathlib import Path | ||
|
|
||
| import integrations_docs | ||
| import pytest | ||
| from reflex_site_shared.integrations import ( | ||
| RAW_DOC_IMAGES_PREFIX, | ||
| _integrations_doc_images_url, | ||
| rewrite_integration_doc_images_in_source, | ||
| ) | ||
|
|
||
| DOC_IMAGES_DIR = Path(integrations_docs.__file__).parent / "images" / "docs" | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def _backend_only(monkeypatch: pytest.MonkeyPatch) -> None: | ||
| """Skip the symlink step so the helpers run without filesystem side effects.""" | ||
| monkeypatch.setenv("REFLEX_BACKEND_ONLY", "true") | ||
|
|
||
|
|
||
| def test_rewrite_source_replaces_all_doc_image_urls() -> None: | ||
| """Every raw GitHub doc-image URL in the source is rewritten to its local asset URL.""" | ||
| source = ( | ||
| f"\n" | ||
| f"text\n" | ||
| f"\n" | ||
| ) | ||
| rewritten = rewrite_integration_doc_images_in_source(source) | ||
| local_prefix = _integrations_doc_images_url() | ||
| assert RAW_DOC_IMAGES_PREFIX not in rewritten | ||
| assert f"({local_prefix}okta_auth_1.png)" in rewritten | ||
| assert f"({local_prefix}descope.webp)" in rewritten | ||
|
|
||
|
|
||
| def test_rewrite_source_without_doc_images_unchanged() -> None: | ||
| """Source without any raw GitHub doc-image URL is returned unchanged.""" | ||
| source = ( | ||
| "# Title\n\n" | ||
| "\n" | ||
| "\n" | ||
| ) | ||
| assert rewrite_integration_doc_images_in_source(source) == source | ||
|
|
||
|
|
||
| def test_doc_image_references_exist_locally() -> None: | ||
| """Every screenshot URL in the docs must resolve to a local image, since the rewrite serves it locally.""" | ||
| missing = [ | ||
| f"{md.name}: {image_name}" | ||
| for md in sorted(integrations_docs.DOCS_DIR.glob("*.md")) | ||
| for image_name in re.findall( | ||
| re.escape(RAW_DOC_IMAGES_PREFIX) + r"([^)\s]+)", md.read_text() | ||
| ) | ||
| if not (DOC_IMAGES_DIR / image_name).is_file() | ||
| ] | ||
| assert not missing, f"docs reference images missing from images/docs/: {missing}" | ||
|
|
||
|
|
||
| def test_doc_image_references_use_image_syntax() -> None: | ||
| """Screenshot URLs must use  image syntax, not a [!alt](url) link typo.""" | ||
| malformed = [ | ||
| md.name | ||
| for md in sorted(integrations_docs.DOCS_DIR.glob("*.md")) | ||
| if re.search( | ||
| r"(?<!!)\[[^\]]*\]\(" + re.escape(RAW_DOC_IMAGES_PREFIX), md.read_text() | ||
| ) | ||
| ] | ||
| assert not malformed, ( | ||
| f"docs embed screenshots as links instead of images: {malformed}" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.