Repository navigation
Serve website examples as real Leaf sessions - #313
Conversation
# Conflicts: # docs/session.js # scripts/site.py
# Conflicts: # skills/leaf/assets/runtime/banner.js
# Conflicts: # README.md # docs/leaf.js # docs/session.js # docs/sitenote.js # scripts/site.py # tests/test_site.py
# Conflicts: # docs/leaf.js # docs/session.js
# Conflicts: # docs/session.js
leaf-agent
left a comment
There was a problem hiding this comment.
Routing the published examples through the canonical Python server instead of a website-only projection is clearly the right direction, and the run_worker_first / asset split keeps the product pages honest. Four things, three inline plus two notes here.
scripts/CLAUDE.md's Website and demo section still describes the path this PR removed — it says site.py "materializes the version responses Leaf's server normally supplies at virtual routes" (that's publish_static_versions, deleted here) and that --serve will "keep that built site open locally", when --serve now shells out to wrangler dev and needs npm ci --prefix worker plus a running Docker. The README picked both up; the scoped instructions for the area being changed did not. Happy to push that edit if you want it in this PR.
with_sitenote in worker/server.py re-derives the canonical-script offset exactly the way runtime_document does in skills/leaf/scripts/leaf/http.py — same parse_structure(...).external_scripts filter on {"src": "/leaf.js", "type": "module"}, same sum(len(part) + 1 for part in source.split("\n")[: line - 1]) + column arithmetic. Two trees now assert that contract independently. If the canonical script ever gains an attribute, the local server keeps working while the website answers 500 out of _answer's catch-all for every example. One exported helper beside runtime_document would leave a single statement of it.
Capacity, for the record rather than as a finding: max_instances = 10 with sleepAfter = "10m" is the entire public site's example budget, and run_worker_first = ["/examples/*"] leaves no static fallback, so the eleventh concurrent reader meets the container error instead of a page. The SameSite point below makes that budget spend faster than one-per-browser suggests.
The root instructions say the everyday suite and pre-commit never read
`worker/`, so a worker change is ungated until CI's `website-worker` job
runs. That is true of `worker/src/`, but not of `worker/server.py`,
which both gates already cover — and `worker/server.py` is where the
container adapter lives, including the website-agent turn and reply
endpoints added yesterday. A session that takes the paragraph literally
runs the npm gate, which never touches `server.py`, and skips the suite
that does.
This rewrites both passages to say which half is ungated. No behavior
changes, so there is no regression test to add; the claim is checked
below against the two gates it describes, and the existing
`test_the_root_instructions_name_every_directory_ci_gates_on_its_own`
still passes because `` `worker/` `` stays named in the repository map.
<details><summary>Evidence</summary>
`tests/test_website_server.py` loads the adapter directly rather than
importing a package, so a grep for `import` in the suite does not show
it:
```python
_spec = importlib.util.spec_from_file_location(
"website_server", ROOT / "worker" / "server.py"
)
```
Both gates, run on this branch:
```
$ uv run pytest tests/test_website_server.py -q
4 passed in 2.09s
$ uv run pre-commit run ruff-check --files worker/server.py
ruff check...............................................................Passed
```
`.pre-commit-config.yaml`'s `exclude` does not name `worker/`, so every
Python hook takes `worker/server.py`. `ci.yaml`'s `website-worker` job
runs `npm ci`, `npm run typecheck`, `npm test`, and the wrangler dry run
— all under `working-directory: worker`, all against the TypeScript
project, none of which reads `server.py`.
The paragraph landed in #331 the day after
`tests/test_website_server.py` landed in #313, so it has been describing
the wrong half since it was written.
</details>
---------
Co-authored-by: leaf-agent <[email protected]>
The root instructions say the everyday suite and pre-commit never read
`worker/`, so a worker change is ungated until CI's `website-worker` job
runs. That is true of `worker/src/`, but not of `worker/server.py`,
which both gates already cover — and `worker/server.py` is where the
container adapter lives, including the website-agent turn and reply
endpoints added yesterday. A session that takes the paragraph literally
runs the npm gate, which never touches `server.py`, and skips the suite
that does.
This rewrites both passages to say which half is ungated. No behavior
changes, so there is no regression test to add; the claim is checked
below against the two gates it describes, and the existing
`test_the_root_instructions_name_every_directory_ci_gates_on_its_own`
still passes because `` `worker/` `` stays named in the repository map.
<details><summary>Evidence</summary>
`tests/test_website_server.py` loads the adapter directly rather than
importing a package, so a grep for `import` in the suite does not show
it:
```python
_spec = importlib.util.spec_from_file_location(
"website_server", ROOT / "worker" / "server.py"
)
```
Both gates, run on this branch:
```
$ uv run pytest tests/test_website_server.py -q
4 passed in 2.09s
$ uv run pre-commit run ruff-check --files worker/server.py
ruff check...............................................................Passed
```
`.pre-commit-config.yaml`'s `exclude` does not name `worker/`, so every
Python hook takes `worker/server.py`. `ci.yaml`'s `website-worker` job
runs `npm ci`, `npm run typecheck`, `npm test`, and the wrangler dry run
— all under `working-directory: worker`, all against the TypeScript
project, none of which reads `server.py`.
The paragraph landed in #331 the day after
`tests/test_website_server.py` landed in #313, so it has been describing
the wrong half since it was written.
</details>
---------
Co-authored-by: leaf-agent <[email protected]>
This week's duplicate sweep of `dev/`, `build/`, `tests/` and `worker/` (week 47) moves six duplicated helpers onto one home each and moves every caller. Behavior stays the same. The touched model tests, the dev js_facts tests and the Worker's routing, storage and index tests pass. A script compared the old and new outputs of the consolidated `leaf_dev` functions and the seeded-log reads across the corpus, and they match. | Question | Home | Copies removed (introducing PR) | |---|---|---| | Which stylesheets do the core and the bundled packages ship, leaving out vendored files? | new `interact_support.shipped_sheets` | `sheets()` in `test_interface_fonts.py` (#4804) and `test_theme_tokens.py` (#6025). Five inline loops in `test_interact_layer.py` (#3138, #3886) | | Run `tests/js_facts.mjs` | `interact_support.js_facts` (#2666) | its own subprocess call in `dev/tests/test_js_facts.py` (#5118) | | Lowercase hex of bytes in the Worker | `routing.hex`, which is `newSessionId` (#313) renamed, plus a `sha256Hex` in `storage.ts` | the publication-identity and chunk-digest copies in `storage.ts` (#2652) | | Is this pid alive? | `leaf.machine.pid_alive` | `_alive` in `tests/process/test_codex_tool.py` (#3331). `running()` in `test_interact_layer.py` (#1774) | | Read an example's seeded log | `read_event_lines(seed_log(source))` (#4484) | inline parsers in `test_render_pages.py`, `test_interact_product.py` (#924) and `test_render_gate.py` (#509). The last one split lines with `splitlines()`, which also breaks at U+2028 | | Paths of the bundled registries and packages; which registry keys name elements | `leaf.schema.ASSETS` / `BUNDLED_PACKAGES` / `DEFAULT_PACKAGE`, `leaf.registry.contract.is_element_name`, `docs.registries()` | `docs.py`'s own `ASSETS`/`PACKAGES` (#3593) and its `startswith("lf-")` checks (#2660). `logs usage`'s hand-written regex and registry list (#5970). `ROOT / "packages" / "default"` in `stills.py` (#3927) and `test_product_page.py` (#3593) | `is_element_name` and the two checks it replaces give the same answer for every key in the bundled registries today. A selector key such as `lf-options.selected` would have passed the `lf-` prefix test. <details><summary>Sets found and left alone</summary> - **Sets an open PR is changing.** Nothing in this diff overlaps another open PR's hunks. #6732 moves tests out of `test_render_gate.py`, `test_render_pages.py` and `test_interact_layer.py`, but none of the tests changed here. - **Changes to browser tests with nothing run to check them.** The WCAG contrast computation exists as about 11 copies across browser, journey and model tests. Other copies: about 9 `EDITOR_ROOTS` shadow-root keepers, the `/api/interaction` batch predicates, CDP `touch()` closures, one-line patch templates, reply-holding route handlers, and the `data-lf-entry` runtime-module import snippet in `dev/leaf_dev/states.py` and in tests. Each would mean editing browser tests that this sweep can't run on a shared host. They suit a sweep that can run those tests. - **Vendor bundling.** `build/browser/build.mjs` builds signals-core and Lit with esbuild calls that repeat `build/vendor.mjs`'s `bundle()`. Merging them changes build options and needs a full `check:browser` byte comparison, so it was left for a change that runs that. - **Copies that are near but not the same.** `_build.py`'s `check_links` repeats `leaf_website.released_path`, but it also needs the matched page's root and kind. The list of API-key variables an eval drops is repeated across Python and the Promptfoo configs, as subsets and supersets of one another. The Codex token-expiry check has different thresholds, 1 h and 60 s. - **Too small to be worth it.** Picking a free loopback port (`eval_user.py`, `interact_support.available_loopback_port`). The XDG state root in `leaf_dev.state_home` and `leaf.state.state_home`. The `settled` helper in two `tests/runtime` files. </details> Co-authored-by: leaf-agent <[email protected]>
Summary
cloudflare-deployenvironment, restricted tomain, and verify the public state API after rollout.Verification
uv run pytest tests— 885 passeduv run pytest tests/test_site.py tests/test_website_server.py tests/test_render_startup.py -q -n0— 97 passedpre-commit run --all-fileswrangler deploy --dry-run— 1,749 assets and the container image built