Skip to content
Draft
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
1 change: 1 addition & 0 deletions docs/lessons-learned.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ This document records project lessons that should guide future changes to Python
- Unit tests are good for catalog integrity, rendering contracts, Dynamic Worker code generation, and cache-policy source checks.
- Browser tests are necessary for Shiki/CodeMirror layout behavior and visual regressions.
- Local `uv run ...` can hide CI import assumptions. GitHub's verify job may invoke `python3 -m unittest` before runtime dependencies such as FastAPI are importable, so tests that import `src/main.py` should either install the dependency explicitly or stub FastAPI/Starlette/Workers modules with purpose-built fakes.
- Example source files cross a TOML/Markdown grammar boundary. Generate valid TOML fields and an independent arbitrary Markdown body, then assert exact metadata, exact body preservation, and the first body line through `_split_frontmatter`. Arbitrary text alone rarely reaches the valid-frontmatter path, while properties that rebuild the parser's result can repeat its bug.
- SEO and cache-busting deserve a dedicated linter because errors are easy to reintroduce when adding pages or assets.
- Always run the full pre-push set before publishing. Start `pywrangler dev --port 9696`, then run:

Expand Down
91 changes: 44 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"node": "22.x"
},
"devDependencies": {
"wrangler": "4.114.0"
"wrangler": "4.127.1"
}
}
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ workers = [
"workers-runtime-sdk",
]
dev = [
"hypothesis>=6.0",
"pillow>=11.3,<12",
"ruff==0.16.0",
]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,9 @@ def test_generated_drift_is_blocked_before_commit_and_merge(self):
self.assertIn('"preview_urls": false', wrangler_config)
package = json.loads((ROOT / "package.json").read_text())
lock = json.loads((ROOT / "package-lock.json").read_text())
self.assertEqual(package["devDependencies"]["wrangler"], "4.114.0")
self.assertEqual(package["devDependencies"]["wrangler"], "4.127.1")
self.assertEqual(package["engines"]["node"], "22.x")
self.assertEqual(lock["packages"][""]["devDependencies"]["wrangler"], "4.114.0")
self.assertEqual(lock["packages"][""]["devDependencies"]["wrangler"], "4.127.1")
makefile = (ROOT / "Makefile").read_text()
self.assertIn("check-node-version", makefile)
self.assertIn("pywrangler sync --force", makefile)
Expand Down
45 changes: 45 additions & 0 deletions tests/test_parser_properties.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""Structured properties for the Markdown example source boundary."""

import json
import unittest

from hypothesis import given
from hypothesis import strategies as st
from src.example_loader import _split_frontmatter

TOML_TEXT = st.text(
alphabet=st.characters(blacklist_categories=("Cc", "Cs")),
max_size=200,
)
MARKDOWN_BODY = st.text(max_size=1_000)


class ExampleSourceParserProperties(unittest.TestCase):
@given(slug=TOML_TEXT, title=TOML_TEXT, body=MARKDOWN_BODY)
def test_toml_frontmatter_round_trips_without_changing_markdown(
self,
slug,
title,
body,
):
"""Generated TOML metadata and arbitrary Markdown stay separated."""
source = (
"+++\n"
f"slug = {json.dumps(slug, ensure_ascii=False)}\n"
f"title = {json.dumps(title, ensure_ascii=False)}\n"
"+++\n"
f"{body}"
)

metadata, parsed_body, body_line = _split_frontmatter(
source,
"generated.md",
)

self.assertEqual(metadata, {"slug": slug, "title": title})
self.assertEqual(parsed_body, body)
self.assertEqual(body_line, 5)


if __name__ == "__main__":
unittest.main()
Loading
Loading