Skip to content

test: dune utop absolute-path crash (#15108) - #15116

Merged
Alizter merged 1 commit into
ocaml:mainfrom
Alizter:push-yptuyqrprxry
Jun 26, 2026
Merged

Alizter merged 1 commit into
ocaml:mainfrom
Alizter:push-yptuyqrprxry

Conversation

@Alizter

@Alizter Alizter commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Reproduction case for #15108. dune utop $PWD/lib crashes with a Code_error instead of accepting the absolute form of the workspace-relative path that works today.

@Alizter Alizter added test-suite cli Command line related labels Jun 10, 2026
@Alizter Alizter self-assigned this Jun 10, 2026
@Alizter
Alizter force-pushed the push-yptuyqrprxry branch from 5683b91 to 5bff500 Compare June 10, 2026 17:12
@Alizter Alizter changed the title test: dune utop absolute-path crash test: dune utop absolute-path crash (#15108) Jun 10, 2026
@Alizter
Alizter force-pushed the push-yptuyqrprxry branch from 5bff500 to 18626c3 Compare June 10, 2026 18:01
@Alizter
Alizter marked this pull request as ready for review June 10, 2026 18:05
@Alizter
Alizter force-pushed the push-yptuyqrprxry branch from 18626c3 to b736cbd Compare June 10, 2026 22:15
Adds a cram test demonstrating that dune utop crashes with a Code_error
when given an absolute path to a workspace directory: Common.prefix_target
is a no-op for absolute strings, leaving Path.Build.relative to receive
an absolute string and raise.

The outside-workspace case already short-circuits via the
Fpath.is_directory existence check, so it produces a clean user error
today and must not regress.

Tracks ocaml#15108 (sub-issue of ocaml#12230). Recorded with CR-someday Alizter
for a follow-up fix that migrates the DIR argument to
Arg.Workspace_path.

Signed-off-by: Ali Caglayan <[email protected]>
@Alizter
Alizter force-pushed the push-yptuyqrprxry branch from b736cbd to 29763b5 Compare June 26, 2026 13:29
@Alizter
Alizter merged commit ff424e3 into ocaml:main Jun 26, 2026
29 checks passed
@Alizter
Alizter deleted the push-yptuyqrprxry branch June 26, 2026 21:40
Alizter added a commit that referenced this pull request Jun 29, 2026
Fixes #15108.

`dune utop $PWD/lib` crashed with an internal `Code_error` while `dune
utop lib` worked. `Common.prefix_target` is a no-op on absolute strings,
so the absolute path reached `Path.Build.relative`, which raises on
absolute input.

This change localizes an absolute `DIR` argument with
`Path.Expert.try_localize_external` before use. this is the same
approach that `dune exec` (#12094) and `dune runtest` (#11936) already
uses. A relative path still goes through `Common.prefix_target` so the
run-from-a-subdirectory case is unchanged, and a part outside the
workspace stays external and still produces the clean `Error: cannot
find directory: ...` message.

Based on @Alizter's repro in #15116, the test was flipped from asserting
the crash to checking the working `foolib` output.

questions I have:

* The issue suggests migrating `DIR` to `Arg.Workspace_path`. That
converter doesn't exist yet, and a cmdliner conv can't localize at parse
time since localization needs `Build.build_dir`, which is only set after
`Common.init`. I went with the inline localization that `exec` and
`runtest` already use. Happy to extract a shared `Arg.Workspace_path`
for #15109/#15110 if thats preferred. Should that live in this PR or a
follow-up?
* An absolute path pointing into `_build` would localize to an in-build
path. `exec` handles that through
`Path.relative_to_source_in_build_or_external`. This isn't covered by
the repro or the issue's required behaviors, so I left it out for now.
Let me know if you would like that included here.
* I also wasnt sure if there is a preferred place for sharing this
localization logic across commands instead of keeping it inline.
@Alizter Alizter added this to the 3.25.0 milestone Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli Command line related test-suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant