Skip to content

fix(server): name recipes relative to the collection in GET /api/recipes - #639

Merged
LeMyst merged 1 commit into
cooklang:mainfrom
LeMyst:fix/recipes-api-paths
Oct 8, 2026
Merged

LeMyst merged 1 commit into
cooklang:mainfrom
LeMyst:fix/recipes-api-paths

Conversation

@LeMyst

@LeMyst LeMyst commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

Closes #638.

GET /api/recipes answered with cooklang_find's tree as is, so every node's path and every recipe's source.path was the file's absolute path on the server (/home/<user>/recipes/Breakfast/Pancakes.cook). This started with be92001; before it, the endpoint returned relative names.

The read is open to everyone: with sign-in on, visitors who have not signed in get it. It is also on the --recipes-only allowlist, so guests limited to recipes get it too. It told them where the collection sits on the server and, usually, which account runs it.

Change

  • all_recipes rewrites the serialised tree (relative_tree_paths, next to the existing normalize_tree_tags).
  • Every path and recipe.source.path is now relative to the recipe directory: Breakfast/Pancakes.cook, with the root's being "". That is exactly what GET /api/recipes/{*path} takes.
  • A path outside the directory, which cooklang_find does not produce, would come back as its bare file name rather than leak.
  • The recipe picker (static/js/src/picker.js), the only client in the repo, already reduced the absolute paths to these relative ones, and works unchanged; only its comment changed.
  • docs/api.md / /api-docs now document relative paths.

Visible change: an outside client that relied on absolute paths would now get paths relative to the collection.

Tests

  • Unit tests: tree rewrite (root, folder, recipe, source.path) and the outside-the-directory fallback.
  • tests/recipe_tree_paths_test.rs boots cook server on a temp collection (via with_isolated_config). It checks that the raw answer never contains the temp directory, that the paths are exactly the expected relative ones (root recipe, recipe in a folder, a menu), and that each opens its recipe through GET /api/recipes/{path}.
  • cargo fmt, cargo clippy --workspace --all-targets --all-features -- -D warnings and cargo test (1103 passed) are clean.
  • Full Chromium Playwright run: 255 passed. The failures were static-file-search (needs a cook binary in the container), one parallel shopping-list race, and the known-flaky recipe-scaling › should send the scale…. That race and the flaky test pass when run serially, along with menu-editor (which uses the picker): 64/64.

Related: #637 (the Preferences page shows absolute paths too), and #631, which keeps them out of the new aisles API.

🤖 Generated with Claude Code

Since be92001 the recipe tree has been `cooklang_find`'s, serialised as
is, so every node's `path` and every recipe's `source.path` was the
file's absolute path on the server. That read is open to anyone, a
visitor who is not signed in included, and it is on the --recipes-only
allowlist: it told them where the collection sits and, usually, the
account the server runs as.

Both are now relative to the recipe directory (`Breakfast/Pancakes.cook`),
the root's being "". They are what `GET /api/recipes/{*path}` takes. The
recipe picker, the one client in the repo, already reduced the absolute
paths to these, and works unchanged.

Closes cooklang#638

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@LeMyst
LeMyst requested a review from dubadub October 7, 2026 19:57
@LeMyst
LeMyst marked this pull request as ready for review October 7, 2026 21:23
@LeMyst
LeMyst merged commit 457e3f7 into cooklang:main Oct 8, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GET /api/recipes sends the absolute path of every recipe

1 participant