Skip to content

test: dune must not internal-error on invalid -open argument - #14403

Merged
robinbb merged 1 commit into
ocaml:mainfrom
robinbb:robinbb-invalid-open-flag-guard
May 6, 2026
Merged

robinbb merged 1 commit into
ocaml:mainfrom
robinbb:robinbb-invalid-open-flag-guard

Conversation

@robinbb

@robinbb robinbb commented May 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds test/blackbox-tests/test-cases/per-module-lib-deps/open-flag-invalid-identifier.t, asserting that when a stanza's (flags ... -open <name>) receives a syntactically invalid OCaml identifier (e.g. starting with a digit, like 1bad), dune does not abort with an internal error, does not pre-empt the compiler with its own "invalid module name" diagnostic, and does not silently drop the -open argument. Instead, the build fails with an OCaml compiler error whose File "command line argument: ..." preamble is unmistakably the compiler's CLI-parser diagnostic format. The test pins this exact output.

Today on main, no in-dune code path parses -open argument names through Module_name.of_string, so the test passes trivially. The guard is forward-looking: it pins the invariant for any future code (notably the per-module dependency filter in #14116) that reads -open argument names while computing rule-time module references.

Test plan

  • dune runtest test/blackbox-tests/test-cases/per-module-lib-deps/open-flag-invalid-identifier.t passes on this branch.

@robinbb
robinbb requested a review from Copilot May 3, 2026 01:58
@robinbb robinbb self-assigned this May 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a blackbox regression test around the per-module inter-library dependency work, documenting that Dune must not raise an internal error when future rule-generation code inspects an invalid -open argument. It fits into the per-module-lib-deps test suite as a forward-looking guard for changes like #14116 that may start reading -open flags while computing module references.

Changes:

  • Add a new cram test for a library stanza that passes an invalid OCaml module name to -open.
  • Build the minimal project with dune build @check to exercise rule generation in the per-module-lib-deps path.
  • Assert that the output does not contain Internal error, preserving the current non-crashing behavior.

@robinbb
robinbb force-pushed the robinbb-invalid-open-flag-guard branch from ac0275d to 90ec2dc Compare May 3, 2026 02:50
@robinbb
robinbb requested a review from Copilot May 3, 2026 02:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

@robinbb
robinbb force-pushed the robinbb-invalid-open-flag-guard branch from 90ec2dc to b70bb6e Compare May 3, 2026 03:03
@robinbb
robinbb requested a review from Copilot May 3, 2026 03:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

@robinbb
robinbb force-pushed the robinbb-invalid-open-flag-guard branch from b70bb6e to db767fc Compare May 3, 2026 03:31
@robinbb
robinbb requested a review from Copilot May 3, 2026 03:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@robinbb
robinbb marked this pull request as ready for review May 3, 2026 03:36
Adds [test-cases/per-module-lib-deps/open-flag-non-uppercase-name.t]:
when [(flags ... -open <name>)] receives a syntactically invalid
OCaml module name (e.g. starting with a digit), dune must not raise
an internal error during rule generation. The compiler is the
authority on whether a given [-open] argument is acceptable; dune
should not pre-empt that decision.

Signed-off-by: Robin Bate Boerop <[email protected]>
@robinbb
robinbb force-pushed the robinbb-invalid-open-flag-guard branch from db767fc to 8cc8241 Compare May 6, 2026 01:43

@Sudha247 Sudha247 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, and makes sense to have this futuristic guard.

I was wondering if the case of the -open flag working as expected is already covered, and that seems to be done in auto-wrapped-child-reexport.t.

@robinbb
robinbb removed request for ElectreAAS and punchagan May 6, 2026 17:38
@robinbb
robinbb merged commit 824816b into ocaml:main May 6, 2026
29 checks passed
@robinbb
robinbb deleted the robinbb-invalid-open-flag-guard branch May 6, 2026 17:41
robinbb added a commit that referenced this pull request May 11, 2026
…4440)

## Summary

Adds
`test/blackbox-tests/test-cases/per-module-lib-deps/ppx-runtime-libraries.t`,
a forward-looking guard that asserts a consumer using `(preprocess (pps
bar))` — where `bar` declares `(ppx_runtime_libraries baz)` — has a
compile-rule dep that covers every cmi in `baz`'s objdir. A glob over
`baz/.baz.objs/byte/*.cmi` is the natural shape and what this test pins.

The runtime libraries' modules are referenced by ppx-rewritten output,
so ocamldep on the consumer's source cannot reason about which of them
are referenced — the next ppx invocation may use any module of `baz`.
Without a recorded dep that covers all of `baz`'s cmis, a change to any
cmi in `baz` would not invalidate the consumer's `.cmi` rule and an
incremental rebuild could silently use a stale artefact.

Same shape as #14400, #14403, and #14439 — small standalone tests landed
ahead of larger work that would touch the same code paths. Spun out of
#14116 so its chain doesn't carry the test. Reported by @rgrinberg via
@art-w in
#14116 (comment).

---------

Signed-off-by: Robin Bate Boerop <[email protected]>
robinbb added a commit that referenced this pull request May 12, 2026
## Summary

Adds
`test/blackbox-tests/test-cases/per-module-lib-deps/root-module-tight-deps.t`,
a forward-looking guard that asserts a library declaring `(root_module
...)` alongside `(libraries ...)` builds correctly when its modules
reference the dep library through the Root alias.

Root modules carry no ocamldep dep-rule: the kind matches `Root | Alias
_` in `Dep_rules.read_transitive_deps_of_module` and
`read_immediate_deps_of`, both of which short-circuit to empty deps,
avoiding the cycle that would otherwise arise from a Root that
references itself transitively. Any future change to inter-library dep
handling that misses this short-circuit would regress this scenario.

Same shape as #14400 (cross-lib pre-pp guard) and #14403 (invalid
`-open` guard) — small standalone tests landed ahead of larger work that
would touch the same code paths. Spun out of #14116 so #14116's chain
doesn't carry the test.

---------

Signed-off-by: Robin Bate Boerop <[email protected]>
@Alizter Alizter added this to the 3.24.0 milestone Jul 8, 2026
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.

4 participants