Module dependencies vs functional test module dependencies

Hi devs,

While reviewing a recent PR, I noticed that several runtime dependencies had been added to a -test-docker module. That’s sometimes needed, but I think it often means that the module under test is missing a dependency for a feature it implements: the test passes, but someone who installs that extension gets a broken feature.

So I had a look at the runtime dependencies of all our -test-docker poms (50 poms, 196 dependencies outside the feature being tested), and I’d like to brainstorm with you about some best practices for this. If we reach an agreement, I’d then document them on dev.xwiki.org and in our LLM knowledge base, and fix the poms.

I haven’t found any previous discussion on this exact topic. Related past discussions:

Here are some ideas to start the discussion.

Idea 1: A module declares the dependencies that its own features need

If the module’s pages, templates, JS or Java use a macro, script service, component, XClass, page, translation bundle, webjar or RequireJS module provided by another module, then the module declares a dependency on it. This would include the default implementation of an API the module depends on, when the feature can’t work without one (e.g. depending on wiki-user-api but needing a WikiUserManager implementation).

In other words, we wouldn’t rely on a test module, a flavor or the WAR to bring it. Declaring a dependency that the WAR also brings (e.g. through xwiki-platform-minimaldependencies) would be fine.

Question 2: What do we do for optional integrations?

Some dependencies only enable an integration that the module works without. The most common case is a module’s administration section: it needs administration-ui (for XWiki.ConfigurableClass), but without it the module works fine, its admin UI is just not visible. Same for a panel contributed by a module.

Today we do different things:

  • a mandatory dependency (e.g. export-pdf-ui, search-ui and ckeditor-ui → administration-ui),
  • an optional dependency (e.g. legacy-messagestream-ui → administration-ui, filter-ui/menu-ui/release-ui → panels-ui, linkchecker-ui → index-ui, like-ui → user-profile-ui),
  • no dependency at all, with the test module adding it (12 modules for administration-ui, e.g. annotation-ui, like-ui, logging-ui, notifications-ui).

Since 2017, Extension Manager installs optional dependencies by default and lets users uninstall them, so <optional>true</optional> (with a comment saying what it enables) looks like a possible fit to me. However, in the 2017 thread Thomas said that optional dependencies were mainly meant for flavors, and that extensions should depend on what they use.

So, what do you think we should do?

  1. Mandatory dependency
  2. Optional dependency
  3. Something else?

Idea 3: A functional test module only adds runtime dependencies that the test itself needs, each with a comment

Every non-test-scope dependency of a -test-docker pom gets installed into the tested XWiki instance, so it can hide a missing dependency (see idea 1). A runtime dependency would stay in the test pom only when:

  • it’s test infrastructure (e.g. @WikisSource needs wiki-creationjob + wiki-template-default, startup-time components, stubs),
  • it’s a feature the scenario only uses as a means (setting rights from the administration, sample pages to visit),
  • it’s an optional integration that the test checks on purpose,
  • the module can’t declare it (dependency cycle).

Each such dependency (or group) would have an XML comment saying what in the test needs it (and for a cycle, why the module can’t depend on it). “Required by FooIT” wouldn’t be enough.

A way to check: remove the dependency and run the test. If the feature itself breaks (and not just the test setup), it belongs in the module. When moving a dependency into a module, the functional tests of the modules depending on it also need to be run, since they now get it too (see XWIKI-23351, where adding websocket to realtime-ui broke the CKEditor tests and was reverted).

Idea 4: Dependencies needed by skin files are declared by the skin

xwiki-platform-minimaldependencies is only meant to define a minimal XWiki WAR, so it wouldn’t be the place to declare a dependency that a module is missing. Dependencies needed by Flamingo skin files (templates, etc.) would be declared in xwiki-platform-flamingo-skin-resources.

Question 5: What about the WAR templates (xwiki-platform-web-templates)?

Templates in web-templates (e.g. diff_macros.vm needs $services.diff, macros.vm needs $services.wiki.user) have no runtime dependencies at all. Ideally web-templates would declare them and flamingo-skin-resources would depend on it. From what I found, here’s why it isn’t done today:

  • web-templates was split out of xwiki-platform-web in 2021 only to be able to test the templates, and it inherited the “skinny WAR” decision of 2011 (XWIKI-6581, “[VOTE] Remove distribution (war) from xwiki-platform”: https://lists.xwiki.org/hyperkitty/list/xwiki-devs@xwiki.org/thread/VCXKXZKZKXPXLRCS3RJ4PPKBVSDREJ5B/): the WAR has no JAR dependencies because of Maven duplicating JARs with WAR dependencies, and the runtime dependencies are listed in minimaldependencies / distribution-war-dependencies instead (see the FIXME comments in minimaldependencies/pom.xml).
  • web-war depends on web-templates with the provided scope and unpacks it into /templates/. It’s not a core extension, and a runtime dependency on it makes EM install it as an extension (XWIKI-20964, XWIKI-20965 still open).
  • Doing it would need care: avoid web-templates.jar ending up in WEB-INF/lib (e.g. depend on it with <type>pom</type>), reactor cycles (rest-server and attachment-api have test dependencies on web-templates but provide $services.rest / $services.attachment), and many services used by templates are optional.

Should we try to make web-templates declare its runtime deps (and if so, how), or keep the current approach for it?

What it would mean in practice

To give an idea of the impact, here’s what would need to change if we go with the ideas above. Module names omit the xwiki-platform- prefix.

Idea 1 (add a dependency to the module)

  • rest-server ← wiki-user-default (WikiUserManager is injected, only the API is declared). Would also fix the rest and appwithinminutes tests.
  • realtime-ui ← websocket (XWIKI-23351, reopened)
  • blocknote-api ← websocket, wysiwyg-ui; blocknote-webjar ← user-rest-default
  • attachment-ui ← wysiwyg-ui (the attachment selector uploads through XWiki.WYSIWYG.FileUploader)
  • notifications-ui ← xwiki-commons-diff-script (mail template → diff_macros.vm); depends on question 5
  • localization-webjar ← localization-rest-default (needed by every xwiki-l10n! user; would fix the poms of attachment-picker, export-pdf, image-lightbox, livedata, panels, realtime and security-requiredrights in one place). Already in every WAR, so no user-visible bug.
  • livedata-livetable ← livetable-ui; repository-server-ui ← icon-script (both already in every WAR)

Question 2 (depending on the answer)

  • administration-ui in: annotation-ui, attachment-validation-ui, image-style-ui, index-ui, index-tree-ui, like-ui, logging-ui, model-validation-ui, notifications-ui, office-ui, xclass-ui, repository-server-ui
  • panels-ui in help-ui
  • user-profile-ui in administration-ui
  • Possibly aligning export-pdf-ui, search-ui and ckeditor-ui, which have a mandatory dependency on administration-ui

Idea 3 (test poms: add or fix comments, remove what moved)

  • Missing comment (19): extension-test-docker (8 deps), export-pdf, extension-security, filter, flamingo-skin, flamingo-theme, notifications, realtime-wysiwyg, repository, skin, webjars (2), whatsnew (where commons-io should also be test scoped)
  • Vague or wrong comment (31): administration, appwithinminutes, ckeditor, edit, flamingo-skin (6), image-style, invitation, like, localization, notifications, rest, search, security-authentication, security-requiredrights, sharepage, tour, user-profile, user-rest, wiki
  • Redundant (11, already brought by the module under test or by the test framework): administration, ckeditor, filter, flamingo-skin, linkchecker, menu, panels
  • To verify by running the test without them (15): administration, blocknote, extension (4), flamingo-skin (3), flamingo-theme, index, livedata, observation (2), repository

Idea 4

  • flamingo-skin-resources ← xwiki-commons-diff-script, diff-xml (previewdiff.vm and changes.vm need the diff services), removing them from flamingo-skin-test-docker

WDYT? Any other ideas or cases I’ve missed?

Thanks

PS: This post was co-written with Claude Code, which also did the review of the test poms.

A dependency of scope compile or runtime, that’s my understanding of how we deal with dependencies.

-1 for mandatory dependencies as I fear it would make reducing the size of a distribution more difficult.
+1 for optional dependencies, I read it as “it is best to have this dependency install, but the module will continue to work gracefully if the dependency is removed”.

A more involved solution (warning: brainstorming) it to introduce the notion of “conditional module”.
The idea is to be ables to express that module X must be installed if module A and B are installed.
For instances, only install annotation-administration-ui if annotation-ui and administration-ui are installed (and to remove `annotation-administration-ui’ if any of the two is uninstalled later).
This is just a high level view of what I envision, I did not consider the technical and UX implication for the Extension Manager (EM).

+1 that’s also my understanding of how functional test dependencies are expected to be handled.

-0, it doesn’t feel right to enforce a specific implementation at the module level. For me this is the concern of the packaging / flavor or the Extension Manager. Otherwise, what’s the point of having two separate -api and -default modules? If anyone using the API declares the dependency on -default then why not move everything in -api? Well, because in some cases you can have cyclic dependencies. So in the end what you propose is not always possible:

  • a-default depends on a-api and b-api
  • b-default depends on b-api and a-api

+1 for mandatory dependency, at least for the administration section case. Optional dependencies are installed by default, so their main benefit is being able to uninstall them without uninstalling the application that depends on them. Why would an administrator uninstall the administration application? What’s the benefit of declaring the administration application as optional?

Thanks,
Marius

Thanks Marius.

On the default implementations, I see it the other way round. As you say, cycles are the reason we split -api and -default. Ideally we wouldn’t have the split at all. It’s a workaround, not a way to let the packaging choose the implementation. So when there’s a single implementation and depending on it creates no cycle, I think the module should depend on it. Otherwise every flavor, WAR or test module has to remember to add it, and an extension installed on its own gets a feature that breaks at runtime (which is the problem this thread started from).

So the rule would be: depend on the -default implementation you need, unless that creates a cycle or there are really several implementations to choose from. In those two cases, the extension users install for the feature (usually its -ui module) or the flavor declares the implementation, with a comment saying why. rest-server → wiki-user-default is the simple case: no cycle (wiki-user-default only depends on wiki-user-api, wiki-api and oldcore) and a single implementation.

On optional integrations, we now have Manuel at +1 optional and you at +1 mandatory. Deciding per target extension whether uninstalling it is reasonable would be subjective, so I’d propose a rule we can check instead: uninstall the target and see what happens to the module that depends on it.

  • If a feature of the module breaks, it’s a mandatory dependency (Idea 1).
  • If only an integration disappears (its admin section, a panel, a profile tab), it’s an optional dependency, with a comment saying what it enables.

The rule follows the code as it is today. If something breaks but we think the target should be uninstallable, the dependency stays mandatory until the code is fixed to degrade gracefully (with a JIRA issue for it), and then it becomes optional.

I agree that nobody will uninstall administration-ui, but since optional dependencies are installed by default, declaring it optional costs nothing. In return, everyone applies the same rule and the pom documents which dependencies are integrations. Would that work for you? Manuel’s conditional-module idea is interesting but needs Extension Manager work, so I’d treat it separately.

Thanks

One more thought, to anticipate an objection: depending on -default doesn’t prevent a custom flavor from using another implementation. It can either:

  • register its implementation with a higher priority in components.txt (e.g. 500:com.acme.AcmeWikiUserManager), which overrides the default component for everyone, or
  • declare the id of the -default extension in the xwiki.extension.features of its own extension, so that the Extension Manager considers the dependency satisfied and doesn’t install -default (as done in icon-fontawesome or lesscss-api for example).

So depending on -default only changes the default from “missing unless the packaging adds it” to “present unless the packaging replaces it”, which looks safer to me.

OK, +0. I’m not +1 because I have the feeling it makes it easy to use by mistake stuff that is not part of the API.

I suppose it depends on what you understand by a broken feature. You seem to suggest that removing a feature by installing an extension is not a breakage. Does it depend on how important that feature is? For instance the icons used by an extension and the notification messages it generates should also be optional no? Same for the pickers used by an application: the users will still be able to input values using plain text fields if we uninstall them. So I guess my question is how far do we want to go with making dependencies optional?