Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ parsers are included. There is no second download and nothing is fetched at runt
```python
from intentumdiff import SemanticDiffer

old = "def greet(name):
old = """def greet(name):
return 'hi ' + name
"
new = "def greet(name):
"""
new = """def greet(name):
if not name:
return None
return 'hi ' + name
"
"""

diff = SemanticDiffer().diff_strings(old, new, "example.py")
for change in diff.changes:
Expand Down
49 changes: 49 additions & 0 deletions scripts/smoke_published_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from __future__ import annotations

import argparse
import re
import shutil
import subprocess
import sys
Expand Down Expand Up @@ -76,6 +77,24 @@ def run(self, *args: str, **kw) -> subprocess.CompletedProcess[str]:
)



def _repo_readme() -> str | None:
"""The README a user reads. Checked in preference order, nearest first."""
here = Path(__file__).resolve()
for candidate in (here.parent.parent / "README.md", here.parent / "README.md"):
if candidate.is_file():
return candidate.read_text(encoding="utf-8")
Comment on lines +83 to +86

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Test the README embedded in the wheel

When --wheel points to an artifact built before the checkout README was edited—or the default command installs a published release while the script comes from another revision—this reads the checkout's README.md, not the long description embedded in the installed distribution. A stale wheel containing the broken example can therefore pass after the source README is repaired, even though PyPI will render the stale content. Extract the README/description from the artifact or installed distribution metadata so the smoke test validates what will actually be published.

Useful? React with 👍 / 👎.

return None


def _first_python_block(markdown: str) -> str | None:
"""The first fenced ``python`` block — the headline example, the one people copy."""
fence = "`" * 3
pattern = fence + r"python\n(.*?)" + fence
match = re.search(pattern, markdown, re.DOTALL)
return match.group(1) if match else None


def main() -> int:
ap = argparse.ArgumentParser(description=__doc__)
ap.add_argument("--wheel", help="local wheel or sdist; defaults to installing from PyPI")
Expand Down Expand Up @@ -116,6 +135,36 @@ def main() -> int:
r = s.run(str(script))
s.check("SemanticDiffer produces a diff", "CHANGES" in r.stdout, r.stderr)

# 5b. THE README'S OWN EXAMPLE, extracted and executed verbatim.
#
# Check 5 above runs OLD_SRC/NEW_SRC — this file's PRIVATE copy of the example.
# That proves the library works; it proves nothing about what we published. The
# 0.0.1 README shipped a headline example that raised NameError, and a gate that
# asserts on its own copy would have passed that release too.
#
# It nearly happened again: on the 0.0.2 release candidate the example's triple
# quotes had collapsed to single quotes, so it died with SyntaxError at PARSE
# time — before importing anything — while every other check here stayed green.
#
# So extract the first ```python fence from the README a user actually reads and
# run it against the INSTALLED wheel.
readme = _repo_readme()
if readme is None:
s.check("README example runs verbatim", False, "README.md not found")
else:
block = _first_python_block(readme)
if block is None:
s.check("README example runs verbatim", False, "no ```python block in README.md")
else:
example = root / "readme_example.py"
example.write_text(block, encoding="utf-8")
r_readme = s.run(str(example))
s.check(
"README example runs verbatim",
r_readme.returncode == 0,
(r_readme.stderr or r_readme.stdout).strip()[:400],
)

# 6. THE ONE THAT MATTERS. 0.0.1 emitted ~69 plugin-catalogue errors on every
# invocation while still returning a result, so exit code alone said "fine".
noise = [
Expand Down
Loading