From 679e00d563ad55cf6f1e000ab44559bebb23d34f Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Wed, 28 Oct 2026 07:52:33 -0500 Subject: [PATCH 1/2] Triage issue #944: opt-in for case-sensitive hosts so case-only alias/page pairs render (bd-ex8qvuwu) Triage record and minimal repro for GH #944. Q-5-25 reproduces at main @ 49cb226de; it implements decision 3 of the 2026-08-12 aliases plan, which the issue deliberately revisits. Direction: keep the error by default, add an affirmative website.* option declaring the deployment target case-sensitive, and document the Quarto 1 discrepancy. Co-Authored-By: Claude Fable 5.1 --- .../issue-reports/944/repro/.gitignore | 2 + .../issue-reports/944/repro/_quarto.yml | 3 + .../issue-reports/944/repro/index.qmd | 5 + .../issue-reports/944/repro/r/index.qmd | 7 + claude-notes/issue-reports/944/triage.md | 240 ++++++++++++++++++ 5 files changed, 257 insertions(+) create mode 100644 claude-notes/issue-reports/944/repro/.gitignore create mode 100644 claude-notes/issue-reports/944/repro/_quarto.yml create mode 100644 claude-notes/issue-reports/944/repro/index.qmd create mode 100644 claude-notes/issue-reports/944/repro/r/index.qmd create mode 100644 claude-notes/issue-reports/944/triage.md diff --git a/claude-notes/issue-reports/944/repro/.gitignore b/claude-notes/issue-reports/944/repro/.gitignore new file mode 100644 index 0000000000..f6bae5814e --- /dev/null +++ b/claude-notes/issue-reports/944/repro/.gitignore @@ -0,0 +1,2 @@ +_site/ +.quarto/ diff --git a/claude-notes/issue-reports/944/repro/_quarto.yml b/claude-notes/issue-reports/944/repro/_quarto.yml new file mode 100644 index 0000000000..f38988263f --- /dev/null +++ b/claude-notes/issue-reports/944/repro/_quarto.yml @@ -0,0 +1,3 @@ +project: + type: website + output-dir: _site diff --git a/claude-notes/issue-reports/944/repro/index.qmd b/claude-notes/issue-reports/944/repro/index.qmd new file mode 100644 index 0000000000..b7ddf5b07f --- /dev/null +++ b/claude-notes/issue-reports/944/repro/index.qmd @@ -0,0 +1,5 @@ +--- +title: Home +--- + +Home. diff --git a/claude-notes/issue-reports/944/repro/r/index.qmd b/claude-notes/issue-reports/944/repro/r/index.qmd new file mode 100644 index 0000000000..7d96edc579 --- /dev/null +++ b/claude-notes/issue-reports/944/repro/r/index.qmd @@ -0,0 +1,7 @@ +--- +title: R example +aliases: + - /R/ +--- + +The page that used to live at `/R/`. diff --git a/claude-notes/issue-reports/944/triage.md b/claude-notes/issue-reports/944/triage.md new file mode 100644 index 0000000000..ee61103182 --- /dev/null +++ b/claude-notes/issue-reports/944/triage.md @@ -0,0 +1,240 @@ +# Issue #944 — alias differing from its page only by case (Q-5-25) is a hard error with no escape hatch + +- **GitHub**: https://github.com/quarto-dev/q2/issues/944 +- **Reporter**: @cscheid (Carlos Scheidegger), 2026-10-27, relaying @atheriel's Posit Connect docs port +- **Triage date**: 2026-10-28 +- **Branch**: `issue-944` in the main checkout (topic branch, no worktree — per user request), based on `main` \@ `49cb226de` (v0.37.0) +- **Braid strand**: bd-ex8qvuwu +- **Scope**: the whole issue — it is a single report. Both shapes of `Q-5-25` are in scope (alias vs. rendered page, which is the reporter's case, and alias vs. alias), because one option must govern both. + +## Summary + +Reproduced exactly as described at `main` \@ `49cb226de`. A page at `r/index.qmd` +declaring `aliases: [/R/]` fails the render with `Q-5-25`, and there is no +configuration that lets it through. The behaviour is not a bug in the usual +sense: it implements decision 3 of +`claude-notes/plans/2026-08-12-aliases-redirect-stubs.md` ("case-insensitive +collisions — error, on every platform"), which was taken on the premise that +"no realistic scenario was identified in which an author wants a colliding +alias to survive the render". Connect's deployment is that scenario: the site +is served from S3, where `R/index.html` and `r/index.html` are distinct keys, +and the old `/R/` URLs must keep working. The issue therefore asks for a +deliberate, partial reversal of that decision. + +**Direction (set by the user at triage):** keep the error as the default and +add an *affirmative* project option that declares the deployment target +case-sensitive. With the option set, the case-only pair is allowed and the +stub is written. The discrepancy with Quarto 1 gets documented. Filed as a +feature strand; fix scope below. + +## Reproduction + +Fixture: `claude-notes/issue-reports/944/repro/` (`_quarto.yml` website +project, `index.qmd`, and `r/index.qmd` with `aliases: [/R/]`). Binary built +from `main` \@ `49cb226de` by the pre-flight verify. + +```bash +cd claude-notes/issue-reports/944/repro +../../../../target/debug/q2 render +``` + +Observed (macOS, APFS case-insensitive): + +```text +Rendering project: .../issue-reports/944/repro (type: website) +Error: [Q-5-25] Alias differs only by case from a rendered page + ╭─[ r/index.qmd:4:5 ] + 4 │ - /R/ + │ ─┬─ + │ ╰─── `/R/` in `r/index.qmd` resolves to `R/index.html`, which differs only in + │ capitalization from `r/index.html` rendered by `r/index.qmd`. macOS and + │ Windows treat those as one file. +───╯ +ℹ Rename the alias so it cannot collide with the page? +``` + +Pages render (`_site/index.html`, `_site/r/index.html` exist) but the render +aborts in the post-render hook: no "Rendered N of N" summary, no stubs, no +`search.json`. Exit status is 1. + +Control: the same project with the alias changed to `/old-r/` renders +`Rendered 2 of 2 files` and writes `_site/old-r/index.html` as a redirect +stub. So the only thing standing between Connect and its redirects is the +case-fold check. + +## Localization + +- **Detection** — `crates/quarto-core/src/project/aliases.rs` + - `plan_alias_stubs` (≈ line 326) buckets every stub claim by + `fold(stub_href)` (ASCII lowercase, line ≈ 510), and puts rendered pages + in the same folded keyspace. + - `plan_one_bucket` (≈ line 374) emits `AliasConflict::CaseOnlyPageCollision` + when the bucket's folded key matches a page but the spelling differs + (≈ line 413), and `AliasConflict::CaseOnlyAliasCollision` when two claims + in one bucket spell the path differently (≈ line 428). Both set `fatal`, + so the stub is dropped from the plan. + - `plan_alias_stubs` is **pure** — it takes only `&[DocumentProfile]` and + has no access to project config. Threading an option in means a new + parameter (or an options struct), which touches its unit tests. +- **Reporting** — `crates/quarto-core/src/project/website_post_render.rs` + - `write_alias_redirects` (≈ line 826): any non-empty `plan.conflicts` + becomes a `QuartoError::Parse` and nothing is written. + - `alias_conflict_diagnostic` (≈ lines 1055 and 1083): the two `Q-5-25` + diagnostics. Neither mentions an escape hatch (there is none). +- **Config readers** — `crates/quarto-core/src/project/website_config.rs` + holds the `website.*` readers; `website_llms_txt_enabled` is the model for + a boolean key. The "key has no effect in this project type" warning + pattern for non-website projects is in + `crates/quarto-core/src/project/orchestrator.rs` ≈ line 426. +- **Docs that assert the current policy** and will need to change: + `docs/errors/project/Q-5-25.qmd` (sections "Why it is checked everywhere", + "How to fix it", "Difference from Quarto 1"), + `docs/guides/projects/aliases.qmd` ("When aliases conflict" and + "Differences from Quarto 1" → "Capitalization counts, on every platform"), + and the `Q-5-25` entry in `crates/quarto-error-catalog/error_catalog.json` + (its `message_template` repeats the "checked on every platform" rationale). +- **Tests** — `crates/quarto-core/tests/integration/website_aliases.rs` + (`aliases_case_only_collision_is_error`, ≈ line 591) and the unit tests in + `aliases.rs` (`plan_rejects_a_case_only_collision_*`, + `plan_case_folding_is_platform_independent`, ≈ lines 1012–1060). + +## What Quarto 1 does (for the documentation) + +`external-sources/quarto-cli/src/project/types/website/website-aliases.ts`: +the overwrite guard is `allOutputFiles.find((outputFile) => outputFile === +targetFile)` — an exact string compare. For the repro: + +- **Linux (case-sensitive)**: Q1 writes `R/index.html` as a redirect to + `../r/index.html`. Both files exist. This is what Connect's CI produces and + what `https://docs.posit.co/connect/cookbook/.../viewer/R/` serves today. +- **macOS / Windows (case-insensitive)**: the same write lands on + `r/index.html` and **replaces the page with a redirect to itself** + (`../r/index.html` resolved from `R/` is the same file). Q1 does not notice. + +So Quarto 1's output for this input depends on the build host's filesystem. +Quarto 2's current rule makes it deterministic by forbidding the input; the +proposed option makes it deterministic by letting the author state which +host they are building for. + +## Open questions — resolved during triage + +**Q1. Is this a bug or a design reversal?** A reversal. Decision 3 in the +2026-08-12 plan is explicit and the docs (`Q-5-25.qmd`, `aliases.qmd`) defend +it. The premise it rested on ("no realistic scenario") is what the issue +refutes. The user has confirmed the reversal is acceptable, gated behind an +affirmative option. + +**Q2. Downgrade to a warning by default (reporter's option 1), or opt-in +(option 2 / 3)?** Opt-in, per the user. Rationale: an unconditional downgrade +would, on a case-insensitive output directory, write the stub *over the +rendered page* — the post-render hook runs after every page has been written, +so the stub wins and the page becomes a self-redirect. That is the Q1 macOS +failure mode, and a warning in a long build log is not enough protection +against it. + +**Q3. With the option on, what happens on a case-insensitive output +directory?** This is the one design point the fix must get right, and the +reporter's option 3 is the answer: the writer has to know whether the output +directory is case-insensitive. If it is, the stub must **not** be written +(it would clobber the page) — skip it and say so, as a warning. On such a +host the page already answers for the aliased URL, so nothing is lost +locally; the stub only matters on the case-sensitive deployment target. +Checking requires a runtime probe of the *output directory* (not the project +directory — they can be on different volumes): either write a probe file and +test `path_exists` on its case-swapped name, or compare `canonicalize` +results for the two spellings. `SystemRuntime` already exposes +`file_write`, `path_exists`, `file_remove`, and `canonicalize` +(`crates/quarto-system-runtime/src/native.rs`). Without the option set, +nothing changes and no probe runs. + +**Q4. Does the option also cover two *aliases* that differ only by case?** +Yes — same bucket, same mechanism, same deployment-target semantics. The +case-insensitive-host skip from Q3 applies to the second stub in the bucket. + +**Q5. Option name.** The reporter floated `website.aliases.case-sensitive`. +Two concerns: `aliases` is a document-level *list* key, so a `website.aliases` +*map* invites confusion; and the fact being declared is a property of the +deployment target, not of aliases. Recommendation: +`website: case-sensitive-paths: true`, with the semantics "paths that differ +only by case are distinct on the host this site is served from". That name +also leaves room for the adjacent check q2 does not do today (two *pages* +whose output paths differ only by case, e.g. `R/index.qmd` and `r/index.qmd`, +which silently overwrite each other on macOS). **Final name is the user's +call**; alternatives considered: `website.aliases-case-sensitive`, +`project.case-sensitive-output`. + +**Q6. Should the option, when set, silence `Q-5-25` or leave an info-level +note?** Silence. An affirmative option is the author saying "I know". The +only diagnostic with the option on is the Q3 skip warning on a +case-insensitive host, which is actionable (build on CI / the deployment +target to get the stub). + +**Q7. Is there an existing strand?** `braid search alias` finds +bd-hzwecpyk (closed as duplicate) and bd-aliases-redirects-missing-sch7cd1g +(the implementation strand, still `in_progress` even though the feature +shipped and the plan is `status: complete`). Neither covers this request; +filed a new strand and linked it `related:` to the implementation strand. +The stale `in_progress` status is an incidental finding — flagged to the +user, not closed here. + +## Outcome / recommended next step + +Filed **bd-ex8qvuwu** with this fix scope: + +1. **Option.** Add a `website.*` boolean reader in `website_config.rs` + (name per Q5, to be confirmed). Thread it into + `plan_alias_stubs` (new parameter or options struct); when set, the two + `CaseOnly*` conflicts are not raised and the stubs are planned with their + declared spelling. Warn "has no effect in this project type" for + non-website projects, mirroring `website.llms-txt` in `orchestrator.rs`. +2. **Case-insensitive host guard (Q3).** In `write_alias_redirects`, when the + option is on and a planned stub's folded path matches a rendered page or an + earlier stub, probe the output directory. Case-insensitive → skip the stub + with a warning naming the file and the reason. Case-sensitive → write it. +3. **Diagnostics.** Both `Q-5-25` messages gain a hint naming the option. + Update `error_catalog.json`'s `message_template` so it no longer claims + the check is unconditional. +4. **Docs.** `docs/errors/project/Q-5-25.qmd`: add the option to "How to fix + it", qualify "Why it is checked everywhere", and expand "Difference from + Quarto 1" with the host-dependent Q1 behaviour above (Linux writes both; + macOS/Windows replace the page with a self-redirect). + `docs/guides/projects/aliases.qmd`: add the option under "When aliases + conflict" and amend "Capitalization counts, on every platform". Consider a + short "Deploying to a case-sensitive host" subsection. Amend decision 3 in + `claude-notes/plans/2026-08-12-aliases-redirect-stubs.md` with a pointer + to this triage so the plan does not read as current policy. +5. **Tests.** Unit: `plan_alias_stubs` with the option on produces stubs for + both `CaseOnly*` shapes. Integration (`website_aliases.rs`): option off is + unchanged (`aliases_case_only_collision_is_error` stays); option on renders + to completion; the stub assertion must branch on the *runtime* probe + result, not on `cfg!(target_os)` — a macOS developer's APFS is normally + case-insensitive but can be formatted case-sensitive, and Linux CI's tmpfs + is case-sensitive. Expect both files on a case-sensitive dir, and the page + intact plus the skip warning on a case-insensitive one. Cross-check + Windows with `cargo clippy -p quarto-core --all-targets --target + x86_64-pc-windows-msvc -- -D warnings` per `.claude/rules/cross-platform.md`. + +Out of scope, noted for later: q2 has no check for two *pages* whose output +paths differ only by case (they overwrite each other on macOS/Windows with no +diagnostic). The option name in Q5 is chosen so it could gate that check too. + +## Verification commands used + +```bash +cargo xtask verify --skip-hub-build # pre-flight on main @ 49cb226de — green (exit 0) +gh issue view 944 --repo quarto-dev/q2 --json title,body,author,createdAt,labels,comments +git switch -c issue-944 +cd claude-notes/issue-reports/944/repro && ../../../../target/debug/q2 render # reproduces Q-5-25 +# control: same fixture with the alias renamed to /old-r/ renders 2 of 2 and writes _site/old-r/index.html +braid search alias; braid show bd-aliases-redirects-missing-sch7cd1g; braid show bd-hzwecpyk +``` + +## Cross-references + +- bd-aliases-redirects-missing-sch7cd1g — implementation strand for `aliases:` (still `in_progress`, see Q7) +- bd-hzwecpyk — earlier duplicate, closed +- `claude-notes/plans/2026-08-12-aliases-redirect-stubs.md` — decisions 2 and 3 are what this issue revisits +- `docs/errors/project/Q-5-25.qmd`, `docs/guides/projects/aliases.qmd` +- `external-sources/quarto-cli/src/project/types/website/website-aliases.ts` — Q1 behaviour +- `.claude/rules/cross-platform.md` — runtime probe over `#[cfg]` gating for the tests +- GH #939 — the sibling list this issue was split out of From 7e4ed504e6b70f24ec8554531524eac50d772b4d Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Wed, 28 Oct 2026 08:57:08 -0500 Subject: [PATCH 2/2] aliases: website.case-sensitive-paths opts in to case-only alias/page pairs (#944, bd-ex8qvuwu) Q-5-25 rejected an alias whose stub differs from a rendered page only by case, with no escape hatch. Posit Connect's docs need exactly that pair: served from S3, R/ and r/ are distinct keys and the old URL must redirect. Keep the error as the default; add `website: case-sensitive-paths: true`. With it, plan_alias_stubs compares paths exactly and marks each stub that would have collided with a CaseFoldTwin. write_alias_redirects probes the output directory and, where it folds case, skips the twinned stub with the new Q-5-51 warning instead of overwriting the page. Both Q-5-25 shapes now hint at the option; non-website projects warn that it has no effect. Docs: Q-5-25, new Q-5-51, aliases guide, catalog, sidebar; decision 3 of the 2026-08-12 plan amended. Integration tests branch on a runtime probe of the temp dir so Linux CI exercises the write and macOS/Windows the skip. Triage doc: escape @-mentions and a possessive so claude-notes renders under --strict. Co-Authored-By: Claude Fable 5.1 --- .../944/exp-case-sensitive-paths/.gitignore | 2 + .../944/exp-case-sensitive-paths/_quarto.yml | 5 + .../944/exp-case-sensitive-paths/index.qmd | 5 + .../944/exp-case-sensitive-paths/r/index.qmd | 7 + claude-notes/issue-reports/944/triage.md | 27 +- .../2026-08-12-aliases-redirect-stubs.md | 9 + crates/quarto-core/src/project/aliases.rs | 432 ++++++++++++++---- .../quarto-core/src/project/orchestrator.rs | 20 +- .../quarto-core/src/project/website_config.rs | 14 + .../src/project/website_post_render.rs | 144 +++++- .../tests/integration/website_aliases.rs | 210 ++++++++- .../quarto-error-catalog/error_catalog.json | 9 +- docs/_quarto.yml | 1 + docs/errors/project/Q-5-25.qmd | 40 +- docs/errors/project/Q-5-51.qmd | 70 +++ docs/guides/projects/aliases.qmd | 28 +- 16 files changed, 931 insertions(+), 92 deletions(-) create mode 100644 claude-notes/issue-reports/944/exp-case-sensitive-paths/.gitignore create mode 100644 claude-notes/issue-reports/944/exp-case-sensitive-paths/_quarto.yml create mode 100644 claude-notes/issue-reports/944/exp-case-sensitive-paths/index.qmd create mode 100644 claude-notes/issue-reports/944/exp-case-sensitive-paths/r/index.qmd create mode 100644 docs/errors/project/Q-5-51.qmd diff --git a/claude-notes/issue-reports/944/exp-case-sensitive-paths/.gitignore b/claude-notes/issue-reports/944/exp-case-sensitive-paths/.gitignore new file mode 100644 index 0000000000..f6bae5814e --- /dev/null +++ b/claude-notes/issue-reports/944/exp-case-sensitive-paths/.gitignore @@ -0,0 +1,2 @@ +_site/ +.quarto/ diff --git a/claude-notes/issue-reports/944/exp-case-sensitive-paths/_quarto.yml b/claude-notes/issue-reports/944/exp-case-sensitive-paths/_quarto.yml new file mode 100644 index 0000000000..cb3f156b62 --- /dev/null +++ b/claude-notes/issue-reports/944/exp-case-sensitive-paths/_quarto.yml @@ -0,0 +1,5 @@ +project: + type: website + output-dir: _site +website: + case-sensitive-paths: true diff --git a/claude-notes/issue-reports/944/exp-case-sensitive-paths/index.qmd b/claude-notes/issue-reports/944/exp-case-sensitive-paths/index.qmd new file mode 100644 index 0000000000..b7ddf5b07f --- /dev/null +++ b/claude-notes/issue-reports/944/exp-case-sensitive-paths/index.qmd @@ -0,0 +1,5 @@ +--- +title: Home +--- + +Home. diff --git a/claude-notes/issue-reports/944/exp-case-sensitive-paths/r/index.qmd b/claude-notes/issue-reports/944/exp-case-sensitive-paths/r/index.qmd new file mode 100644 index 0000000000..7d96edc579 --- /dev/null +++ b/claude-notes/issue-reports/944/exp-case-sensitive-paths/r/index.qmd @@ -0,0 +1,7 @@ +--- +title: R example +aliases: + - /R/ +--- + +The page that used to live at `/R/`. diff --git a/claude-notes/issue-reports/944/triage.md b/claude-notes/issue-reports/944/triage.md index ee61103182..a3c867b0b1 100644 --- a/claude-notes/issue-reports/944/triage.md +++ b/claude-notes/issue-reports/944/triage.md @@ -1,7 +1,7 @@ # Issue #944 — alias differing from its page only by case (Q-5-25) is a hard error with no escape hatch - **GitHub**: https://github.com/quarto-dev/q2/issues/944 -- **Reporter**: @cscheid (Carlos Scheidegger), 2026-10-27, relaying @atheriel's Posit Connect docs port +- **Reporter**: \@cscheid (Carlos Scheidegger), 2026-10-27, relaying \@atheriel's Posit Connect docs port - **Triage date**: 2026-10-28 - **Branch**: `issue-944` in the main checkout (topic branch, no worktree — per user request), based on `main` \@ `49cb226de` (v0.37.0) - **Braid strand**: bd-ex8qvuwu @@ -192,7 +192,7 @@ Filed **bd-ex8qvuwu** with this fix scope: earlier stub, probe the output directory. Case-insensitive → skip the stub with a warning naming the file and the reason. Case-sensitive → write it. 3. **Diagnostics.** Both `Q-5-25` messages gain a hint naming the option. - Update `error_catalog.json`'s `message_template` so it no longer claims + Update the `message_template` of `error_catalog.json` so it no longer claims the check is unconditional. 4. **Docs.** `docs/errors/project/Q-5-25.qmd`: add the option to "How to fix it", qualify "Why it is checked everywhere", and expand "Difference from @@ -218,6 +218,29 @@ Out of scope, noted for later: q2 has no check for two *pages* whose output paths differ only by case (they overwrite each other on macOS/Windows with no diagnostic). The option name in Q5 is chosen so it could gate that check too. +## Implementation (same branch, 2026-10-28) + +Option name settled by the user: `website.case-sensitive-paths: true`. Landed on +`issue-944` after this triage commit: + +- `AliasPlanOptions` threads the option into `plan_alias_stubs`, which then keys + buckets and pages by exact spelling; each stub that would have collided carries a + `CaseFoldTwin` (the page or earlier stub it folds onto). +- `write_alias_redirects` probes the output directory (probe file under a lowercase + name, looked up uppercase) only when a twin exists, and skips twinned stubs with the + new warning **`Q-5-51`** when the directory folds case. Pages always win; between two + stubs the one sorting first wins. +- Both `Q-5-25` diagnostics gain a hint naming the option; a non-website project with + the option set gets a "no effect" warning. +- Docs: `Q-5-25.qmd`, new `Q-5-51.qmd`, `aliases.qmd`, sidebar, catalog; decision 3 of + the 2026-08-12 plan amended. +- Tests branch on a runtime probe of the temp dir, so one test asserts the write on a + case-sensitive directory and the skip on a case-insensitive one. Locally both branches + ran: default APFS (skip) and a `Case-sensitive APFS` disk image mounted as `TMPDIR` + (write). CI covers Linux and Windows. + +`exp-case-sensitive-paths/` is the repro with the option on, for a side-by-side run. + ## Verification commands used ```bash diff --git a/claude-notes/plans/2026-08-12-aliases-redirect-stubs.md b/claude-notes/plans/2026-08-12-aliases-redirect-stubs.md index 5cd7140ca2..796a4b08d6 100644 --- a/claude-notes/plans/2026-08-12-aliases-redirect-stubs.md +++ b/claude-notes/plans/2026-08-12-aliases-redirect-stubs.md @@ -400,6 +400,15 @@ led to each. when checked out on a case-insensitive filesystem. Deterministic cross-platform behavior is the point; Q1's guard is an exact string compare and catches none of this. + > **Amended 2026-10-28 (GH #944, bd-ex8qvuwu).** The premise "no realistic scenario + > wants a case-only pair" was wrong: Posit Connect's docs are served from S3, where + > `R/index.html` and `r/index.html` are distinct keys, and a renamed directory needs + > its old-case URL to keep redirecting. The error stays the **default**, and + > `website.case-sensitive-paths: true` opts out: the pair plans two stubs, and the + > writer probes the output directory, skipping (with `Q-5-51`) any stub that would + > clobber its case-twin on a case-insensitive filesystem. See + > `claude-notes/issue-reports/944/triage.md`. + 4. **Stub template — candidate B.** Written out at `aliases-redirect-stubs-investigation/stub-candidate-b-improved.html` (A, the Q1 byte-parity version, is kept alongside it for comparison). B adds a diff --git a/crates/quarto-core/src/project/aliases.rs b/crates/quarto-core/src/project/aliases.rs index dcc83a14af..8aff31ee3c 100644 --- a/crates/quarto-core/src/project/aliases.rs +++ b/crates/quarto-core/src/project/aliases.rs @@ -205,7 +205,7 @@ fn normalize_segments(base: &str, rel: &str) -> Result { /// One alias as the author wrote it, with enough provenance for a /// diagnostic to point at it. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, Default, PartialEq)] pub struct AliasRef { /// The alias verbatim, e.g. `"/cookbook/runtime-caches/#delete"`. pub alias: String, @@ -226,6 +226,49 @@ pub struct PlannedStub { /// fragment with the default (`""`) first, so the rendered stub is /// byte-stable across runs. pub redirects: Vec<(String, String)>, + /// Something else in the site occupies this path under + /// case-folding. Only ever set when + /// [`AliasPlanOptions::case_sensitive_paths`] is on — otherwise + /// the same situation is an [`AliasConflict`] and the stub is not + /// planned at all. The writer uses it to avoid clobbering the + /// occupant on a case-insensitive output directory. + pub case_fold_twin: Option, + /// The alias that claimed the default route; the first claim in + /// the bucket. Kept so [`CaseFoldTwin`] can name it. + pub claimant: AliasRef, +} + +/// What a planned stub would overwrite on a case-insensitive +/// filesystem. +#[derive(Debug, Clone, PartialEq)] +pub struct CaseFoldTwin { + /// The alias that claimed the stub's default route — the one to + /// name when the stub is skipped. + pub alias: AliasRef, + /// The file already at the folded path. + pub occupant: CaseFoldOccupant, +} + +/// The file a stub collides with under case-folding. +#[derive(Debug, Clone, PartialEq)] +pub enum CaseFoldOccupant { + /// A page the project renders. + Page { + page_href: String, + page_source: PathBuf, + }, + /// Another alias stub, written first because it sorts first. + Stub { stub_href: String }, +} + +/// Project-level settings the planner reads. +#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] +pub struct AliasPlanOptions { + /// `website.case-sensitive-paths: true`: the host the site is + /// served from keeps `R/index.html` and `r/index.html` apart, so a + /// pair that differs only by case is two files, not a collision. + /// Off by default — see `Q-5-25` (GH #944). + pub case_sensitive_paths: bool, } /// A reason the alias pass refuses to render. @@ -319,15 +362,32 @@ struct Claim { /// which avoids the surprises of full Unicode case folding (Turkish /// dotless ı, ligatures, normalization forms) at the cost of missing /// collisions no real filesystem is likely to conflate. -pub fn plan_alias_stubs(profiles: &[DocumentProfile]) -> AliasPlan { +/// +/// With [`AliasPlanOptions::case_sensitive_paths`] the author has +/// declared the deployment target case-sensitive (GH #944: Posit +/// Connect's docs are served from S3, where `R/` and `r/` are distinct +/// keys and the old `/R/` URLs must keep redirecting). Paths are then +/// compared exactly, a case-only pair plans two stubs, and each stub +/// that *would* have collided carries a [`CaseFoldTwin`] so the writer +/// can still refuse to clobber a page on a case-insensitive build +/// host. +pub fn plan_alias_stubs(profiles: &[DocumentProfile], options: AliasPlanOptions) -> AliasPlan { let mut plan = AliasPlan::default(); + let key = |href: &str| -> String { + if options.case_sensitive_paths { + href.to_string() + } else { + fold(href) + } + }; - // Every rendered page's output href, keyed by its folded form. - // Drafts are included: they render, so they occupy a path. + // Every rendered page's output href, keyed by its folded form (or + // exactly, when the target is case-sensitive). Drafts are + // included: they render, so they occupy a path. let mut pages: BTreeMap = BTreeMap::new(); for profile in profiles { pages.insert( - fold(&profile.output_href), + key(&profile.output_href), (profile.output_href.as_str(), profile.source_path.as_path()), ); } @@ -355,7 +415,7 @@ pub fn plan_alias_stubs(profiles: &[DocumentProfile]) -> AliasPlan { Ok(resolved) => { let target_href = relative_href(&resolved.stub_href, &profile.output_href); buckets - .entry(fold(&resolved.stub_href)) + .entry(key(&resolved.stub_href)) .or_default() .push(Claim { stub_spelling: resolved.stub_href, @@ -378,9 +438,60 @@ pub fn plan_alias_stubs(profiles: &[DocumentProfile]) -> AliasPlan { } } + if options.case_sensitive_paths { + mark_case_fold_twins(&mut plan.stubs, profiles); + } + plan } +/// Record, on every planned stub, what it would overwrite on a +/// case-insensitive filesystem. +/// +/// Only called when paths are compared exactly, so the buckets above +/// never saw these as collisions. Pages always win against a stub (a +/// redirect replacing the page it points at is a loop). Between two +/// stubs the one that sorts first wins — an arbitrary but stable +/// choice, and the loser is named in the warning either way. +fn mark_case_fold_twins(stubs: &mut [PlannedStub], profiles: &[DocumentProfile]) { + let pages: BTreeMap = profiles + .iter() + .map(|p| { + ( + fold(&p.output_href), + (p.output_href.as_str(), p.source_path.as_path()), + ) + }) + .collect(); + + // `stubs` is sorted by `stub_href` (BTreeMap iteration order), so + // "first stub seen under this folded key" is "the one that sorts + // first" and therefore the one written first. + let mut seen: BTreeMap = BTreeMap::new(); + for stub in stubs.iter_mut() { + let folded = fold(&stub.stub_href); + let occupant = match (pages.get(&folded), seen.get(&folded)) { + (Some((page_href, page_source)), _) if *page_href != stub.stub_href => { + Some(CaseFoldOccupant::Page { + page_href: (*page_href).to_string(), + page_source: page_source.to_path_buf(), + }) + } + (None, Some(earlier)) => Some(CaseFoldOccupant::Stub { + stub_href: earlier.clone(), + }), + _ => None, + }; + seen.entry(folded).or_insert_with(|| stub.stub_href.clone()); + if let Some(occupant) = occupant { + stub.case_fold_twin = Some(CaseFoldTwin { + alias: stub.claimant.clone(), + occupant, + }); + } + } +} + /// Turn one folded bucket's claims into a stub, or into conflicts. /// /// Returns `None` when the bucket cannot produce a defensible stub. @@ -501,6 +612,8 @@ fn plan_one_bucket( Some(PlannedStub { stub_href: stub_spelling, redirects, + case_fold_twin: None, + claimant: claims[0].who.clone(), }) } @@ -859,20 +972,26 @@ mod tests { #[test] fn plan_is_empty_without_aliases() { - let plan = plan_alias_stubs(&[page("index.qmd", "index.html", &[])]); + let plan = plan_alias_stubs( + &[page("index.qmd", "index.html", &[])], + AliasPlanOptions::default(), + ); assert_eq!(plan, AliasPlan::default()); } #[test] fn plan_maps_each_alias_to_its_own_stub() { - let plan = plan_alias_stubs(&[ - page("index.qmd", "index.html", &[]), - page( - "current/index.qmd", - "current/index.html", - &["/old-name.html", "../previous/index.html"], - ), - ]); + let plan = plan_alias_stubs( + &[ + page("index.qmd", "index.html", &[]), + page( + "current/index.qmd", + "current/index.html", + &["/old-name.html", "../previous/index.html"], + ), + ], + AliasPlanOptions::default(), + ); assert!(plan.conflicts.is_empty(), "{:?}", plan.conflicts); assert_eq!(stub_paths(&plan), ["old-name.html", "previous/index.html"]); assert_eq!( @@ -889,14 +1008,17 @@ mod tests { fn plan_merges_fragments_from_two_pages_into_one_stub() { // The Connect-docs shape: two pages route different fragments // through one old URL, and one of them owns the bare URL. - let plan = plan_alias_stubs(&[ - page( - "build/index.qmd", - "build/index.html", - &["/hub", "/hub/#image"], - ), - page("deploy/index.qmd", "deploy/index.html", &["/hub/#deploy"]), - ]); + let plan = plan_alias_stubs( + &[ + page( + "build/index.qmd", + "build/index.html", + &["/hub", "/hub/#image"], + ), + page("deploy/index.qmd", "deploy/index.html", &["/hub/#deploy"]), + ], + AliasPlanOptions::default(), + ); assert!(plan.conflicts.is_empty(), "{:?}", plan.conflicts); assert_eq!(stub_paths(&plan), ["hub/index.html"]); assert_eq!( @@ -915,7 +1037,10 @@ mod tests { // One page, one fragment, no bare alias: that page is the // unambiguous owner of the bare URL. Q1 would have sent a // fragment-less visitor to the site root. - let plan = plan_alias_stubs(&[page("p/index.qmd", "p/index.html", &["/old.html#sec"])]); + let plan = plan_alias_stubs( + &[page("p/index.qmd", "p/index.html", &["/old.html#sec"])], + AliasPlanOptions::default(), + ); assert!(plan.conflicts.is_empty(), "{:?}", plan.conflicts); assert_eq!( plan.stubs[0].redirects, @@ -930,10 +1055,13 @@ mod tests { fn plan_refuses_when_no_page_owns_the_bare_url() { // Two pages, fragments only, no bare alias. Choosing an owner // would be a guess about intent. - let plan = plan_alias_stubs(&[ - page("a/index.qmd", "a/index.html", &["/hub/#one"]), - page("b/index.qmd", "b/index.html", &["/hub/#two"]), - ]); + let plan = plan_alias_stubs( + &[ + page("a/index.qmd", "a/index.html", &["/hub/#one"]), + page("b/index.qmd", "b/index.html", &["/hub/#two"]), + ], + AliasPlanOptions::default(), + ); assert!(plan.stubs.is_empty(), "no stub without an owner"); match plan.conflicts.as_slice() { [ @@ -951,10 +1079,13 @@ mod tests { #[test] fn plan_rejects_a_stub_over_a_rendered_page() { - let plan = plan_alias_stubs(&[ - page("index.qmd", "index.html", &[]), - page("p/index.qmd", "p/index.html", &["/index.html"]), - ]); + let plan = plan_alias_stubs( + &[ + page("index.qmd", "index.html", &[]), + page("p/index.qmd", "p/index.html", &["/index.html"]), + ], + AliasPlanOptions::default(), + ); assert!(plan.stubs.is_empty()); match plan.conflicts.as_slice() { [ @@ -973,10 +1104,13 @@ mod tests { #[test] fn plan_rejects_two_pages_claiming_one_route() { - let plan = plan_alias_stubs(&[ - page("one/index.qmd", "one/index.html", &["/shared.html"]), - page("two/index.qmd", "two/index.html", &["/shared.html"]), - ]); + let plan = plan_alias_stubs( + &[ + page("one/index.qmd", "one/index.html", &["/shared.html"]), + page("two/index.qmd", "two/index.html", &["/shared.html"]), + ], + AliasPlanOptions::default(), + ); assert!(plan.stubs.is_empty()); match plan.conflicts.as_slice() { [ @@ -999,21 +1133,27 @@ mod tests { fn plan_tolerates_a_page_repeating_its_own_alias() { // Redundant, not contradictory: the route asked for twice is // the one the page would get anyway. - let plan = plan_alias_stubs(&[page( - "p/index.qmd", - "p/index.html", - &["/old.html", "/old.html"], - )]); + let plan = plan_alias_stubs( + &[page( + "p/index.qmd", + "p/index.html", + &["/old.html", "/old.html"], + )], + AliasPlanOptions::default(), + ); assert!(plan.conflicts.is_empty(), "{:?}", plan.conflicts); assert_eq!(stub_paths(&plan), ["old.html"]); } #[test] fn plan_rejects_a_case_only_collision_between_aliases() { - let plan = plan_alias_stubs(&[ - page("one/index.qmd", "one/index.html", &["/Shared.html"]), - page("two/index.qmd", "two/index.html", &["/shared.html"]), - ]); + let plan = plan_alias_stubs( + &[ + page("one/index.qmd", "one/index.html", &["/Shared.html"]), + page("two/index.qmd", "two/index.html", &["/shared.html"]), + ], + AliasPlanOptions::default(), + ); assert!(plan.stubs.is_empty()); assert!( plan.conflicts @@ -1026,10 +1166,13 @@ mod tests { #[test] fn plan_rejects_a_case_only_collision_with_a_page() { - let plan = plan_alias_stubs(&[ - page("readme.qmd", "README.html", &[]), - page("p/index.qmd", "p/index.html", &["/readme.html"]), - ]); + let plan = plan_alias_stubs( + &[ + page("readme.qmd", "README.html", &[]), + page("p/index.qmd", "p/index.html", &["/readme.html"]), + ], + AliasPlanOptions::default(), + ); assert!(plan.stubs.is_empty()); match plan.conflicts.as_slice() { [ @@ -1051,19 +1194,135 @@ mod tests { // The collision above must be found on Linux too, where the // filesystem would happily keep both files. Shipping such a // site breaks it the moment it is served from macOS. - let plan = plan_alias_stubs(&[ - page("one/index.qmd", "one/index.html", &["/A/B.html"]), - page("two/index.qmd", "two/index.html", &["/a/b.html"]), - ]); + let plan = plan_alias_stubs( + &[ + page("one/index.qmd", "one/index.html", &["/A/B.html"]), + page("two/index.qmd", "two/index.html", &["/a/b.html"]), + ], + AliasPlanOptions::default(), + ); assert!( !plan.conflicts.is_empty(), "case-only collision must be detected regardless of host filesystem" ); } + // ── `website.case-sensitive-paths` (GH #944) ───────────────── + + const CASE_SENSITIVE: AliasPlanOptions = AliasPlanOptions { + case_sensitive_paths: true, + }; + + #[test] + fn case_sensitive_paths_plans_a_stub_beside_its_case_twin_page() { + // The Connect docs shape: `r/index.qmd` keeps the old `/R/` + // URL alive. On a case-sensitive host these are two files. + let plan = plan_alias_stubs( + &[ + page("index.qmd", "index.html", &[]), + page("r/index.qmd", "r/index.html", &["/R/"]), + ], + CASE_SENSITIVE, + ); + assert!(plan.conflicts.is_empty(), "{:?}", plan.conflicts); + assert_eq!(stub_paths(&plan), ["R/index.html"]); + assert_eq!( + plan.stubs[0].redirects, + [(String::new(), "../r/index.html".to_string())] + ); + // ...but the writer must know it would clobber the page on a + // case-insensitive build host. + match &plan.stubs[0].case_fold_twin { + Some(CaseFoldTwin { + alias, + occupant: + CaseFoldOccupant::Page { + page_href, + page_source, + }, + }) => { + assert_eq!(alias.alias, "/R/"); + assert_eq!(page_href, "r/index.html"); + assert_eq!(page_source, Path::new("r/index.qmd")); + } + other => panic!("expected a Page twin, got {other:?}"), + } + } + + #[test] + fn case_sensitive_paths_plans_both_stubs_of_a_case_only_pair() { + let plan = plan_alias_stubs( + &[ + page("one/index.qmd", "one/index.html", &["/Shared.html"]), + page("two/index.qmd", "two/index.html", &["/shared.html"]), + ], + CASE_SENSITIVE, + ); + assert!(plan.conflicts.is_empty(), "{:?}", plan.conflicts); + // Byte order: uppercase sorts first, so it is the one written + // first and the one the other is a twin of. + assert_eq!(stub_paths(&plan), ["Shared.html", "shared.html"]); + assert_eq!(plan.stubs[0].case_fold_twin, None); + match &plan.stubs[1].case_fold_twin { + Some(CaseFoldTwin { + alias, + occupant: CaseFoldOccupant::Stub { stub_href }, + }) => { + assert_eq!(alias.alias, "/shared.html"); + assert_eq!(alias.source_path, Path::new("two/index.qmd")); + assert_eq!(stub_href, "Shared.html"); + } + other => panic!("expected a Stub twin, got {other:?}"), + } + } + + #[test] + fn case_sensitive_paths_keeps_the_exact_collisions() { + // Only the *case-only* rule relaxes. An alias landing exactly + // on a page, or two pages claiming one spelling, are still + // errors — and stubs with no twin carry none. + let plan = plan_alias_stubs( + &[ + page("index.qmd", "index.html", &[]), + page( + "one/index.qmd", + "one/index.html", + &["/index.html", "/old.html"], + ), + page("two/index.qmd", "two/index.html", &["/old.html"]), + ], + CASE_SENSITIVE, + ); + assert!(plan.stubs.is_empty()); + assert!( + plan.conflicts + .iter() + .any(|c| matches!(c, AliasConflict::OverwritesPage { .. })), + "{:?}", + plan.conflicts + ); + assert!( + plan.conflicts + .iter() + .any(|c| matches!(c, AliasConflict::DuplicateClaim { .. })), + "{:?}", + plan.conflicts + ); + + let plan = plan_alias_stubs( + &[page("p/index.qmd", "p/index.html", &["/old.html"])], + CASE_SENSITIVE, + ); + assert_eq!(stub_paths(&plan), ["old.html"]); + assert_eq!(plan.stubs[0].case_fold_twin, None); + } + #[test] fn plan_rejects_an_alias_escaping_the_output_dir() { - let plan = plan_alias_stubs(&[page("index.qmd", "index.html", &["../escaped.html"])]); + let plan = plan_alias_stubs( + &[page("index.qmd", "index.html", &["../escaped.html"])], + AliasPlanOptions::default(), + ); assert!(plan.stubs.is_empty()); match plan.conflicts.as_slice() { [AliasConflict::EscapesOutputDir { alias }] => { @@ -1077,15 +1336,21 @@ mod tests { #[test] fn plan_skips_draft_pages_but_still_guards_their_output() { // A draft contributes no redirect... - let plan = plan_alias_stubs(&[draft("wip.qmd", "wip.html", &["/old.html"])]); + let plan = plan_alias_stubs( + &[draft("wip.qmd", "wip.html", &["/old.html"])], + AliasPlanOptions::default(), + ); assert!(plan.stubs.is_empty(), "a draft's alias must not go live"); assert!(plan.conflicts.is_empty()); // ...but it still renders, so its output path is occupied. - let plan = plan_alias_stubs(&[ - draft("wip.qmd", "wip.html", &[]), - page("p/index.qmd", "p/index.html", &["/wip.html"]), - ]); + let plan = plan_alias_stubs( + &[ + draft("wip.qmd", "wip.html", &[]), + page("p/index.qmd", "p/index.html", &["/wip.html"]), + ], + AliasPlanOptions::default(), + ); assert!( matches!( plan.conflicts.as_slice(), @@ -1100,15 +1365,18 @@ mod tests { fn plan_reports_every_conflict_in_one_pass() { // A project with several mistakes should learn about all of // them from a single render. - let plan = plan_alias_stubs(&[ - page("index.qmd", "index.html", &[]), - page( - "one/index.qmd", - "one/index.html", - &["/shared.html", "/index.html", "../../escaped.html"], - ), - page("two/index.qmd", "two/index.html", &["/shared.html"]), - ]); + let plan = plan_alias_stubs( + &[ + page("index.qmd", "index.html", &[]), + page( + "one/index.qmd", + "one/index.html", + &["/shared.html", "/index.html", "../../escaped.html"], + ), + page("two/index.qmd", "two/index.html", &["/shared.html"]), + ], + AliasPlanOptions::default(), + ); assert!(plan.stubs.is_empty()); assert!( plan.conflicts @@ -1136,6 +1404,8 @@ mod tests { .iter() .map(|(f, t)| (f.to_string(), t.to_string())) .collect(), + case_fold_twin: None, + claimant: AliasRef::default(), }) } @@ -1233,16 +1503,22 @@ mod tests { // byte-identical sites. // Stub names deliberately unrelated to the page names, so no // alias lands on a rendered page. - let forward = plan_alias_stubs(&[ - page("a.qmd", "a.html", &["/old-z.html"]), - page("b.qmd", "b.html", &["/old-m.html"]), - page("c.qmd", "c.html", &["/old-a.html"]), - ]); - let reversed = plan_alias_stubs(&[ - page("c.qmd", "c.html", &["/old-a.html"]), - page("b.qmd", "b.html", &["/old-m.html"]), - page("a.qmd", "a.html", &["/old-z.html"]), - ]); + let forward = plan_alias_stubs( + &[ + page("a.qmd", "a.html", &["/old-z.html"]), + page("b.qmd", "b.html", &["/old-m.html"]), + page("c.qmd", "c.html", &["/old-a.html"]), + ], + AliasPlanOptions::default(), + ); + let reversed = plan_alias_stubs( + &[ + page("c.qmd", "c.html", &["/old-a.html"]), + page("b.qmd", "b.html", &["/old-m.html"]), + page("a.qmd", "a.html", &["/old-z.html"]), + ], + AliasPlanOptions::default(), + ); assert!(forward.conflicts.is_empty(), "{:?}", forward.conflicts); assert_eq!( stub_paths(&forward), diff --git a/crates/quarto-core/src/project/orchestrator.rs b/crates/quarto-core/src/project/orchestrator.rs index 879763f68b..8581d6833c 100644 --- a/crates/quarto-core/src/project/orchestrator.rs +++ b/crates/quarto-core/src/project/orchestrator.rs @@ -442,6 +442,24 @@ pub trait ProjectType { .build(), ); } + // And for `website.case-sensitive-paths` (GH #944): it only + // changes how alias stubs are planned, which only website + // projects do. + if let Some(meta) = project.config.metadata.as_ref() + && super::website_config::website_case_sensitive_paths(meta) + { + diagnostics.push( + quarto_error_reporting::DiagnosticMessageBuilder::warning( + "`website.case-sensitive-paths: true` has no effect in this project type", + ) + .problem( + "The option only governs `aliases:` redirect stubs, which are written only \ + for `website` projects.", + ) + .add_hint("Set `project: type: website` in `_quarto.yml`?") + .build(), + ); + } Ok(()) } @@ -558,7 +576,7 @@ impl ProjectType for WebsiteProjectType { // collision is an error, not a warning, because the // alternative is a redirect silently pointing at the // wrong page. See the `Q-5-23`..`Q-5-26` docs pages. - write_alias_redirects(project, index, runtime)?; + write_alias_redirects(project, index, runtime, diagnostics)?; // L7 (`bd-qf7r`): replace listing description / image // placeholder envelopes with engine-rendered preview // content read from sibling outputs. Bracketed feature diff --git a/crates/quarto-core/src/project/website_config.rs b/crates/quarto-core/src/project/website_config.rs index 50218c2952..471050fa93 100644 --- a/crates/quarto-core/src/project/website_config.rs +++ b/crates/quarto-core/src/project/website_config.rs @@ -89,6 +89,20 @@ pub fn website_llms_txt_enabled(meta: &ConfigValue) -> bool { .unwrap_or(false) } +/// Read `website.case-sensitive-paths` from a merged metadata value. +/// +/// `true` declares that the host the site is served from keeps paths +/// that differ only by case apart (S3, most Linux web servers), so an +/// alias such as `/R/` on a page rendered to `r/index.html` is a +/// redirect to write rather than a `Q-5-25` collision. Absent, +/// `false`, and non-boolean values all read as `false` — the default +/// assumes the stricter, case-insensitive host (GH #944). +pub fn website_case_sensitive_paths(meta: &ConfigValue) -> bool { + meta.get_path(&["website", "case-sensitive-paths"]) + .and_then(|v| v.as_bool()) + .unwrap_or(false) +} + /// Read `website.favicon` from a merged metadata value. /// /// Returns the favicon path as written by the user. **Does not diff --git a/crates/quarto-core/src/project/website_post_render.rs b/crates/quarto-core/src/project/website_post_render.rs index 843916107b..539c87932d 100644 --- a/crates/quarto-core/src/project/website_post_render.rs +++ b/crates/quarto-core/src/project/website_post_render.rs @@ -821,16 +821,29 @@ pub(super) fn write_robots_txt( /// /// Unlike the other hooks here this one is not gated on a config key: /// `aliases:` is per-document, so the plan is simply empty when no -/// page declares any. +/// page declares any. `website.case-sensitive-paths` only changes +/// what counts as a collision (GH #944): with it set, a stub that +/// differs from a page only by case is planned — and then written +/// only if the output directory can actually hold both, otherwise it +/// is skipped with `Q-5-51` rather than overwriting the page. #[cfg(not(target_arch = "wasm32"))] pub(super) fn write_alias_redirects( project: &ProjectContext, index: &ProjectIndex, runtime: &dyn SystemRuntime, + diagnostics: &mut Vec, ) -> Result<()> { - use crate::project::aliases::{plan_alias_stubs, render_stub}; - - let plan = plan_alias_stubs(index.profiles()); + use crate::project::aliases::{AliasPlanOptions, plan_alias_stubs, render_stub}; + use crate::project::website_config::website_case_sensitive_paths; + + let options = AliasPlanOptions { + case_sensitive_paths: project + .config + .metadata + .as_ref() + .is_some_and(website_case_sensitive_paths), + }; + let plan = plan_alias_stubs(index.profiles(), options); if !plan.conflicts.is_empty() { return Err(QuartoError::Parse(alias_conflicts_to_parse_error( @@ -840,7 +853,19 @@ pub(super) fn write_alias_redirects( ))); } + // Probe once, and only when something would actually collide: + // the common case has no twins and never touches the probe file. + let output_dir_folds_case = if plan.stubs.iter().any(|s| s.case_fold_twin.is_some()) { + dir_is_case_insensitive(runtime, &project.output_dir)? + } else { + false + }; + for stub in &plan.stubs { + if output_dir_folds_case && let Some(twin) = &stub.case_fold_twin { + diagnostics.push(skipped_case_fold_stub_warning(stub, twin)); + continue; + } let dst = project.output_dir.join(&stub.stub_href); if let Some(parent) = dst.parent() { runtime.dir_create(parent, true).map_err(|e| { @@ -865,6 +890,110 @@ pub(super) fn write_alias_redirects( Ok(()) } +/// Does `dir` treat two spellings that differ only by case as one +/// file? +/// +/// Answered by experiment, not by `cfg!(target_os)`: a macOS volume +/// can be formatted either way, Windows can be told per directory, +/// and a Linux build can write to a mounted case-insensitive share. +/// The probe goes in the **output** directory specifically — it is the +/// directory the stubs land in, and it need not be on the same volume +/// as the project. +/// +/// A probe file is created under a lowercase name and looked up under +/// an uppercase one. The nanosecond nonce keeps two concurrent renders +/// into one directory from reading each other's probe. +#[cfg(not(target_arch = "wasm32"))] +fn dir_is_case_insensitive(runtime: &dyn SystemRuntime, dir: &Path) -> Result { + use std::time::UNIX_EPOCH; + + let nonce = SystemTime::now() + .duration_since(UNIX_EPOCH) + .map_or(0, |d| d.as_nanos()); + let lower = dir.join(format!(".q2-case-probe-{nonce}")); + let upper = dir.join(format!(".Q2-CASE-PROBE-{nonce}")); + + let io_err = |what: &str, e: quarto_system_runtime::RuntimeError| { + QuartoError::other(format!( + "Failed to {what} case-sensitivity probe in {}: {}", + dir.display(), + e + )) + }; + + runtime + .dir_create(dir, true) + .map_err(|e| io_err("create the output directory for the", e))?; + runtime + .file_write(&lower, b"") + .map_err(|e| io_err("write", e))?; + let folds = runtime.path_exists(&upper, Some(quarto_system_runtime::PathKind::File)); + // Remove before inspecting the result so the probe never lingers + // in the site, whichever way the lookup went. + runtime + .file_remove(&lower) + .map_err(|e| io_err("remove", e))?; + folds.map_err(|e| io_err("check", e)) +} + +/// `Q-5-51`: a stub allowed by `website.case-sensitive-paths` could not +/// be written here because this output directory would have put it on +/// top of the file it differs from only by case. +/// +/// A warning, not an error: the author asked for a case-sensitive +/// site and will get one from a case-sensitive build host. On this +/// host the occupant already answers for the stub's URL, so nothing +/// 404s locally; the warning says which redirect is missing and why. +/// +/// Span-less on purpose. Project-level diagnostics are rendered +/// without a shared `SourceContext`, and the message names the file +/// and alias in text. +#[cfg(not(target_arch = "wasm32"))] +fn skipped_case_fold_stub_warning( + stub: &crate::project::aliases::PlannedStub, + twin: &crate::project::aliases::CaseFoldTwin, +) -> DiagnosticMessage { + use crate::project::aliases::CaseFoldOccupant; + + let (occupant, consequence) = match &twin.occupant { + CaseFoldOccupant::Page { + page_href, + page_source, + } => ( + format!( + "`{page_href}`, the page rendered by `{}`", + page_source.display() + ), + "Writing it would have replaced that page with a redirect.", + ), + CaseFoldOccupant::Stub { stub_href } => ( + format!("`{stub_href}`, another alias redirect"), + "Writing it would have replaced that redirect, sending its visitors to the wrong page.", + ), + }; + + quarto_error_reporting::DiagnosticMessageBuilder::warning( + "Alias redirect skipped on a case-insensitive output directory", + ) + .with_code("Q-5-51") + .problem(format!( + "`{}` in `{}` resolves to `{}`, which this output directory treats as the same file \ + as {occupant}. {consequence}", + twin.alias.alias, + twin.alias.source_path.display(), + stub.stub_href + )) + .add_info( + "`website.case-sensitive-paths: true` says the site is served from a host that keeps \ + the two apart. The redirect is written when the directory being rendered into does \ + too. Here the existing file already answers for the redirect's URL.", + ) + .add_hint( + "Render on a case-sensitive filesystem (for example Linux CI) to produce this redirect?", + ) + .build() +} + /// Turn every conflict into a diagnostic, sharing one `SourceContext`. /// /// All of them, not the first: a site with dozens of aliasing files @@ -886,6 +1015,11 @@ fn alias_conflicts_to_parse_error( crate::error::ParseError::new(diagnostics, source_context) } +/// The escape hatch both `Q-5-25` shapes point at (GH #944). +#[cfg(not(target_arch = "wasm32"))] +const CASE_SENSITIVE_PATHS_HINT: &str = "Serving from a host that keeps both spellings apart \ + (such as S3)? Set `website: case-sensitive-paths: true` in `_quarto.yml` to allow the pair."; + /// Register the file an alias was written in and return its span, /// re-keyed so several documents can share one `SourceContext`. /// @@ -1077,6 +1211,7 @@ fn alias_conflict_diagnostic( }; builder .add_hint("Rename one so the two differ by more than capitalization?") + .add_hint(CASE_SENSITIVE_PATHS_HINT) .build() } @@ -1102,6 +1237,7 @@ fn alias_conflict_diagnostic( page_source.display() )) .add_hint("Rename the alias so it cannot collide with the page?") + .add_hint(CASE_SENSITIVE_PATHS_HINT) .build() } diff --git a/crates/quarto-core/tests/integration/website_aliases.rs b/crates/quarto-core/tests/integration/website_aliases.rs index e8ef3c0388..c6629de60a 100644 --- a/crates/quarto-core/tests/integration/website_aliases.rs +++ b/crates/quarto-core/tests/integration/website_aliases.rs @@ -23,10 +23,14 @@ //! - Paths that differ only by case collide **on every platform**, not //! just on case-insensitive filesystems, so a Linux CI build fails //! the same way a macOS build does instead of shipping a site that -//! breaks when checked out on macOS or Windows. +//! breaks when checked out on macOS or Windows. The author can opt +//! out with `website.case-sensitive-paths: true` (GH #944); the +//! tests for that branch on what the temp directory actually does, +//! so the same test checks the write on Linux CI and the skip on a +//! default macOS volume. //! //! See `claude-notes/plans/2026-08-12-aliases-redirect-stubs.md` -//! §"Design decisions". +//! §"Design decisions" and `claude-notes/issue-reports/944/triage.md`. //! //! The helpers below mirror those in `website_post_render.rs` — this //! crate's integration tests keep their fixtures per-file rather than @@ -168,6 +172,33 @@ fn expect_error_code(result: Result, code: &s strip_ansi(&parse.render()) } +/// Codes of every diagnostic the render produced, project-level and +/// per-page. +fn diagnostic_codes(summary: &ProjectRenderSummary) -> Vec { + summary + .outputs + .iter() + .flat_map(|o| o.render_output.diagnostics.iter()) + .chain(summary.project_diagnostics.iter()) + .filter_map(|d| d.code.clone()) + .collect() +} + +/// Does `dir` treat `probe` and `PROBE` as one file? +/// +/// Decided at run time, the same way the product decides it, rather +/// than by `cfg!(target_os)`: a macOS volume can be formatted either +/// way, and CI runs on both kinds of filesystem. Each +/// `case-sensitive-paths` test asserts whichever outcome the +/// directory it rendered into calls for. +fn dir_folds_case(dir: &Path) -> bool { + let lower = dir.join("case-probe"); + std::fs::write(&lower, "").unwrap(); + let folds = dir.join("CASE-PROBE").exists(); + std::fs::remove_file(&lower).unwrap(); + folds +} + /// Every HTML file under the output dir, as output-dir-relative /// forward-slash paths, sorted. fn output_html_files(project_dir: &Path) -> Vec { @@ -608,6 +639,181 @@ fn aliases_case_only_collision_is_error() { ); } +// ═══════════════════════════════════════════════════════════════════ +// `website.case-sensitive-paths` (GH #944) +// ═══════════════════════════════════════════════════════════════════ + +/// A website config that declares the deployment target case-sensitive. +const CASE_SENSITIVE_WEBSITE_YML: &str = + "project:\n type: website\n output-dir: _site\nwebsite:\n case-sensitive-paths: true\n"; + +/// The Posit Connect docs shape: `viewer/R/` was renamed `viewer/r/` +/// and the old URL must keep working on S3, where the two are distinct +/// keys. With the option set the render succeeds everywhere. Whether +/// the stub is *written* depends on the directory rendered into: a +/// case-sensitive one holds both files; a case-insensitive one keeps +/// the page and warns `Q-5-51` instead of replacing it with a redirect +/// to itself. +#[test] +fn case_sensitive_paths_allows_alias_differing_from_page_only_by_case() { + let (dir, summary) = render_project(|dir| { + write(&dir.join("_quarto.yml"), CASE_SENSITIVE_WEBSITE_YML); + write(&dir.join("index.qmd"), "---\ntitle: Home\n---\n\nH.\n"); + write( + &dir.join("r/index.qmd"), + "---\ntitle: R example\naliases:\n - /R/\n---\n\nThe R page body.\n", + ); + }); + + // The page survives on every filesystem. + let page = read(&dir.join("_site/r/index.html")); + assert!( + page.contains("The R page body."), + "page was clobbered:\n{page}" + ); + assert!( + !page.contains("Redirect"), + "page became a redirect stub:\n{page}" + ); + + let codes = diagnostic_codes(&summary); + if dir_folds_case(&dir.join("_site")) { + assert!( + codes.iter().any(|c| c == "Q-5-51"), + "case-insensitive output dir should warn that the stub was skipped; got {codes:?}" + ); + assert_eq!(output_html_files(&dir), ["index.html", "r/index.html"]); + } else { + assert!( + !codes.iter().any(|c| c == "Q-5-51"), + "case-sensitive output dir should write the stub silently; got {codes:?}" + ); + assert_eq!( + output_html_files(&dir), + ["R/index.html", "index.html", "r/index.html"] + ); + let stub = read(&dir.join("_site/R/index.html")); + assert!(stub.contains("Redirect"), "{stub}"); + assert_eq!(redirect_map(&stub), r#"{"":"../r/index.html"}"#); + } + assert!( + !dir.join("_site").read_dir().unwrap().any(|e| { + e.unwrap() + .file_name() + .to_string_lossy() + .to_ascii_lowercase() + .starts_with(".q2-case-probe") + }), + "the case-sensitivity probe must not linger in the site" + ); +} + +/// Two aliases differing only by case, each pointing at a different +/// page. Case-sensitive directory: both stubs, each to its own page. +/// Case-insensitive: the one that sorts first is written, the other +/// is skipped with `Q-5-51` rather than silently redirecting the +/// first stub's visitors to the wrong page. +#[test] +fn case_sensitive_paths_allows_two_aliases_differing_only_by_case() { + let (dir, summary) = render_project(|dir| { + write(&dir.join("_quarto.yml"), CASE_SENSITIVE_WEBSITE_YML); + write( + &dir.join("one/index.qmd"), + "---\ntitle: One\naliases:\n - /Shared.html\n---\n\n1.\n", + ); + write( + &dir.join("two/index.qmd"), + "---\ntitle: Two\naliases:\n - /shared.html\n---\n\n2.\n", + ); + }); + + // `Shared.html` sorts before `shared.html`, so it is written first + // and wins on a case-insensitive directory. + let first = read(&dir.join("_site/Shared.html")); + assert_eq!(redirect_map(&first), r#"{"":"one/index.html"}"#); + + let codes = diagnostic_codes(&summary); + if dir_folds_case(&dir.join("_site")) { + assert!(codes.iter().any(|c| c == "Q-5-51"), "{codes:?}"); + assert_eq!( + output_html_files(&dir), + ["Shared.html", "one/index.html", "two/index.html"] + ); + } else { + assert!(!codes.iter().any(|c| c == "Q-5-51"), "{codes:?}"); + assert_eq!( + output_html_files(&dir), + [ + "Shared.html", + "one/index.html", + "shared.html", + "two/index.html" + ] + ); + let second = read(&dir.join("_site/shared.html")); + assert_eq!(redirect_map(&second), r#"{"":"two/index.html"}"#); + } +} + +/// The option relaxes only the case-only rule. An alias landing +/// exactly on a page is still `Q-5-23`, and the diagnostic for the +/// pair it *does* relax now names the option. +#[test] +fn case_sensitive_paths_keeps_exact_collisions_fatal() { + let (_dir, result) = try_render_project(|dir| { + write(&dir.join("_quarto.yml"), CASE_SENSITIVE_WEBSITE_YML); + write(&dir.join("index.qmd"), "---\ntitle: Home\n---\n\nH.\n"); + write( + &dir.join("page/index.qmd"), + "---\ntitle: Page\naliases:\n - /index.html\n---\n\nP.\n", + ); + }); + expect_error_code(result, "Q-5-23"); +} + +/// Without the option the pair is still an error — and the error now +/// tells the author about the option. +#[test] +fn case_only_collision_error_names_the_escape_hatch() { + let (_dir, result) = try_render_project(|dir| { + write(&dir.join("_quarto.yml"), WEBSITE_YML); + write(&dir.join("index.qmd"), "---\ntitle: Home\n---\n\nH.\n"); + write( + &dir.join("r/index.qmd"), + "---\ntitle: R\naliases:\n - /R/\n---\n\nR.\n", + ); + }); + let rendered = expect_error_code(result, "Q-5-25"); + assert!( + rendered.contains("case-sensitive-paths"), + "Q-5-25 should name the escape hatch; got:\n{rendered}" + ); +} + +/// The option is inert outside website projects, and says so. +#[test] +fn case_sensitive_paths_in_default_project_warns() { + let (_dir, summary) = render_project(|dir| { + write( + &dir.join("_quarto.yml"), + "project:\n type: default\n output-dir: _out\nwebsite:\n case-sensitive-paths: true\n", + ); + write(&dir.join("index.qmd"), "---\ntitle: Home\n---\n\nH.\n"); + }); + assert!( + summary + .project_diagnostics + .iter() + .any(|d| d.title.contains("case-sensitive-paths")), + "expected a warning naming the option; got: {:?}", + summary + .project_diagnostics + .iter() + .map(|d| d.title.clone()) + .collect::>() + ); +} + /// An alias that climbs above the output directory would write outside /// the site. Q1 has no guard here at all. #[test] diff --git a/crates/quarto-error-catalog/error_catalog.json b/crates/quarto-error-catalog/error_catalog.json index c5f13df4b5..345755422b 100644 --- a/crates/quarto-error-catalog/error_catalog.json +++ b/crates/quarto-error-catalog/error_catalog.json @@ -1577,7 +1577,7 @@ "Q-5-25": { "subsystem": "project", "title": "Alias Paths Differ Only by Case", - "message_template": "Two paths differ only in capitalization, which macOS and Windows treat as the same file. Checked on every platform so a Linux build cannot ship a site that breaks when served elsewhere.", + "message_template": "Two paths differ only in capitalization, which macOS and Windows treat as the same file. Checked on every platform so a Linux build cannot ship a site that breaks when served elsewhere, unless `website.case-sensitive-paths: true` declares the host keeps them apart.", "docs_url": "https://quarto.org/docs/errors/project/Q-5-25", "since_version": "99.9.9" }, @@ -1819,6 +1819,13 @@ "docs_url": "https://quarto.org/docs/errors/project/Q-5-50", "since_version": "99.9.9" }, + "Q-5-51": { + "subsystem": "project", + "title": "Alias Redirect Skipped on a Case-Insensitive Output Directory", + "message_template": "`website.case-sensitive-paths: true` allowed an alias that differs from an existing file only by case, but the directory being rendered into treats the two as one file. The redirect was not written so the existing file survives; render on a case-sensitive filesystem to produce it.", + "docs_url": "https://quarto.org/docs/errors/project/Q-5-51", + "since_version": "99.9.9" + }, "Q-13-8": { "subsystem": "navigation", "title": "Unsupported toc-location value", diff --git a/docs/_quarto.yml b/docs/_quarto.yml index 141ed12758..3b1add1f80 100644 --- a/docs/_quarto.yml +++ b/docs/_quarto.yml @@ -372,6 +372,7 @@ website: - errors/project/Q-5-48.qmd - errors/project/Q-5-49.qmd - errors/project/Q-5-50.qmd + - errors/project/Q-5-51.qmd - section: "include" contents: - errors/include/Q-17-1.qmd diff --git a/docs/errors/project/Q-5-25.qmd b/docs/errors/project/Q-5-25.qmd index f123c7a4e5..6091232a32 100644 --- a/docs/errors/project/Q-5-25.qmd +++ b/docs/errors/project/Q-5-25.qmd @@ -46,14 +46,48 @@ filesystem — or let a contributor check it out on a Mac — and one redirect silently disappears. Catching it at build time on every platform is what makes the output portable. +The default assumes the stricter host. If yours is not — see below +— you can say so. + ## How to fix it Rename one of the two so they differ by more than capitalization. If both spellings need to work, pick one as the real alias; a case-insensitive host will serve it for either spelling anyway. +### When the two really are different URLs + +Some hosts keep paths that differ only by case apart: Amazon S3, +most Linux web servers, and anything else that treats a URL path as +an opaque string. A site served from one of these may have *renamed* +a directory from `R/` to `r/` and need the old `/R/` URLs to keep +redirecting — which is exactly the pair this error rejects. + +Declare the host case-sensitive in `_quarto.yml`: + +```yaml +website: + case-sensitive-paths: true +``` + +With this set, a pair that differs only by case is two files, not a +collision, and the redirect is written. The check does not go away +entirely: when the directory being rendered into is itself +case-insensitive (a default macOS or Windows volume), writing the +redirect would replace the page it points at, so Quarto skips it +and warns [`Q-5-51`](Q-5-51.qmd) instead. Render on a case-sensitive +filesystem — typically the CI job that publishes the site — to get +both files. + ## Difference from Quarto 1 -Quarto 1 compares paths as exact strings, so it never notices. -On a case-insensitive filesystem the redirects overwrite each -other silently. +Quarto 1 compares paths as exact strings, so it never notices, and +what it produces depends on where it runs. On Linux it writes both +files, which is why sites deployed from Linux CI to a +case-sensitive host have worked. On macOS or Windows the redirect +lands on the page and replaces it with a redirect to itself. + +Quarto 2 makes the outcome independent of the build machine: by +default the pair is rejected everywhere, and with +`website.case-sensitive-paths: true` the redirect is written where +the filesystem allows and reported where it does not. diff --git a/docs/errors/project/Q-5-51.qmd b/docs/errors/project/Q-5-51.qmd new file mode 100644 index 0000000000..555c9f24af --- /dev/null +++ b/docs/errors/project/Q-5-51.qmd @@ -0,0 +1,70 @@ +--- +title: "Alias Redirect Skipped on a Case-Insensitive Output Directory" +description: "`website.case-sensitive-paths: true` allowed an alias that differs from an existing file only by case, but the directory being rendered into treats the two as one file, so the redirect was not written." +code: Q-5-51 +subsystem: project +status: complete +since: "99.9.9" +categories: + - project +--- + +# `Q-5-51` — Alias Redirect Skipped on a Case-Insensitive Output Directory + +> `website.case-sensitive-paths: true` allowed an alias that differs +> from an existing file only by case, but the directory being +> rendered into treats the two as one file, so the redirect was not +> written. + +## What this means + +With `website.case-sensitive-paths: true` you have told Quarto that +the host your site is served from keeps `R/index.html` and +`r/index.html` apart, so an alias that differs from a page (or from +another alias) only by case is a redirect to write rather than a +[`Q-5-25`](Q-5-25.qmd) collision: + +```yaml +# _quarto.yml +website: + case-sensitive-paths: true + +# r/index.qmd +aliases: + - /R/ # the old URL, before the directory was renamed +``` + +That is true of the deployment target. It is not necessarily true of +the machine doing the rendering. On a default macOS or Windows +filesystem, `_site/R/index.html` and `_site/r/index.html` *are* one +file, and writing the redirect would replace the page with a redirect +— here, a redirect to itself. + +Quarto checks the output directory before writing — by experiment, +not by operating system, since a macOS volume can be formatted either +way. When the directory folds case, the redirect is skipped and this +warning names it. The page is left intact. Everything else about the +render is unaffected, and on this machine the page already answers +for the redirect's URL, so nothing is missing locally. + +When two *aliases* differ only by case, the one that sorts first is +written and the other is skipped. + +## How to fix it + +Nothing is wrong with the project. To produce the redirect, render on +a case-sensitive filesystem — typically the Linux CI job that builds +the published site. The output there contains both files. + +If you did not mean to declare the host case-sensitive, remove +`website.case-sensitive-paths` and rename the alias so it differs from +the page by more than capitalization; see [`Q-5-25`](Q-5-25.qmd). + +## Difference from Quarto 1 + +Quarto 1 has no such check and no such option. It compares paths +exactly, so on Linux it writes both files, and on macOS or Windows it +silently overwrites the page with the redirect. Quarto 2 never +overwrites the page: it either refuses the pair (`Q-5-25`, the +default) or, with `website.case-sensitive-paths: true`, writes the +redirect where the filesystem allows and warns where it does not. diff --git a/docs/guides/projects/aliases.qmd b/docs/guides/projects/aliases.qmd index 54318de340..578c807ecd 100644 --- a/docs/guides/projects/aliases.qmd +++ b/docs/guides/projects/aliases.qmd @@ -115,6 +115,29 @@ redirect is silently missing or silently points at the wrong page — is much harder to notice: the build log looks clean and the old links keep failing with nothing to explain why. +### Hosts that distinguish case + +`Q-5-25` assumes the site may be served from a filesystem where +`/Deploy/` and `/deploy/` are one file. Some hosts — Amazon S3, most +Linux web servers — keep them apart, and a site on such a host may +need both: say a directory was renamed from `R/` to `r/` and the old +`/R/` links must keep working. Tell Quarto the host is case-sensitive: + +```yaml +# _quarto.yml +website: + case-sensitive-paths: true +``` + +Now a pair that differs only by case is two files, and the redirect is +written. One safeguard remains. If the directory you are rendering +*into* folds case — a default macOS or Windows volume — writing +`_site/R/index.html` would overwrite `_site/r/index.html`, so Quarto +skips that redirect and warns +[`Q-5-51`](../../errors/project/Q-5-51.qmd) instead of replacing the +page. Render on a case-sensitive filesystem, such as a Linux CI job, +to produce both files. Nothing else about the render changes. + ## Differences from Quarto 1 If you are porting a site, three behaviours changed. @@ -129,7 +152,10 @@ exactly, so `/Deploy/` and `/deploy/` look distinct to it. On macOS and Windows they are the same file, and one silently overwrites the other — which, when the loser is a real page, replaces that page with a redirect pointing at itself. Quarto 2 rejects such a pair even on -Linux, so a site built in CI cannot break when served elsewhere. +Linux, so a site built in CI cannot break when served elsewhere. If +your host really does keep the two apart, set +`website.case-sensitive-paths: true` (see above); Quarto 1 had no +such option because it never checked. **The redirect works without JavaScript.** Quarto 1's redirect runs a script and does nothing else; a reader without JavaScript sees a blank