Skip to content

test(install-dynamic-plugins): cover the unrecognised pullPolicy path, document two unreachable guards (RHIDP-16761) - #4555

Open
gustavolira wants to merge 2 commits into
redhat-developer:mainfrom
gustavolira:chore/rhidp-16761-unreachable-guards
Open

test(install-dynamic-plugins): cover the unrecognised pullPolicy path, document two unreachable guards (RHIDP-16761)#4555
gustavolira wants to merge 2 commits into
redhat-developer:mainfrom
gustavolira:chore/rhidp-16761-unreachable-guards

Conversation

@gustavolira

@gustavolira gustavolira commented Sep 2, 2026

Copy link
Copy Markdown
Member

What

Covers one branch in installer-oci.ts that a review of this PR's own first commit proved is reachable, and documents two that are not.

Closes RHIDP-16761. Follow-up to #4526 (RHIDP-16222).

The correction that shaped this PR

The first commit claimed three guards were unreachable and put an istanbul ignore on each. One of those claims was wrong, and the pragma was hiding a real branch rather than documenting a dead one.

if (pullPolicy !== PullPolicy.ALWAYS) return false;   // isAlreadyInstalled

The justification was that PullPolicy has exactly two members and IF_NOT_PRESENT already returned above. That only holds if the value really is one of the two, and nothing checks. installer.ts reads the config with parseYaml(rawContent) as DynamicPluginsConfig — a type assertion, no runtime validation — and effectivePullPolicy returns plugin.pullPolicy whenever it is truthy. So pullPolicy: Never, or a lower-cased always, travels from a user's dynamic-plugins.yaml straight into this comparison.

The behaviour on that path is the right one: fall through and re-install, rather than silently skip and strand the plugin at whatever version happens to be on disk. It simply had no test. It has one now, and removing the guard fails exactly that test and nothing else.

What is ignored, and why

The two remaining pragmas stand, with better reasons than the first commit gave. The original comments cited OCI_REGEX, which only explains why a trailing ! is rejected. The reason a package with no ! at all never reaches splitOciPackage with an empty side is that the merger appends the resolved path first — !plugin.package.includes('!') in mergePlugin, and resolveInherit for the {{inherit}} case. Both mechanisms are named in the comments now, so a reader can check whether the pragma still holds after changing either.

:45  splitOciPackage    if (!imagePart || !pluginPath) return null
:152 isAlreadyInstalled if (!parts) return false

They stay rather than being deleted: dropping the second downgrades a clean skip into a TypeError on parts.imagePart the moment upstream validation is relaxed, and both cost nothing at runtime.

The /* istanbul ignore next -- reason */ form follows the one existing use in this repo, augment-backend's HttpEmbedder.ts:47.

Coverage

installer-oci.ts was 95.08% statements / 90% branches with lines 45, 140 and 147 uncovered. It is 100% on all four metrics now — but the difference that matters is that the pullPolicy branch got there by being tested, not by being excluded.

Mutation

Mutation Failures Which test
if (pullPolicy !== PullPolicy.ALWAYS) return false removed 1 re-installs rather than skipping when the configured pullPolicy is not a recognised value

Checks

  • yarn tsc — clean
  • yarn prettier:check — clean
  • yarn lint:all — clean
  • CI=true yarn test — 19 suites, 259 tests, all passing

No behaviour change, no changeset.

Follow-up worth considering, not done here

pullPolicy is not validated at parse time. Falling through to a re-install is a safe default, but an operator who typos it gets no warning and a plugin that re-downloads on every run. Validating the value and logging when it is unrecognised would be a small, separate change — out of scope for a PR about coverage pragmas.


🤖 Generated with Claude Code

…able (RHIDP-16761)

installer-oci.ts had three branches that no test could ever reach, and they read
as a coverage gap to anyone looking at the report:

  :45  splitOciPackage   if (!imagePart || !pluginPath) return null
  :140 isAlreadyInstalled if (pullPolicy !== PullPolicy.ALWAYS) return false
  :147 isAlreadyInstalled if (!parts) return false

They are unreachable, verified rather than assumed. installOciPlugin is not part
of the package's public API — index.ts exports only the CLI module — so its sole
caller is installer.ts, downstream of merger.ts calling ociPluginKey, whose
OCI_REGEX already rejects a leading or trailing `!`. Those forms are in
oci-key.test.ts's invalidCases, which is why :45 and :147 cannot fire. :140
cannot fire because PullPolicy has exactly two members and IF_NOT_PRESENT
already returned three lines above.

Three reviewers on RHIDP-16222 proposed deleting them. Keeping them is the
better trade: deleting :147 in particular downgrades a clean skip into a
TypeError on parts.imagePart the moment the upstream validation is relaxed, and
the guards cost nothing at runtime. So they stay, and each carries an istanbul
ignore naming the invariant that makes it unreachable — which is the part that
matters. If someone loosens OCI_REGEX or adds a third PullPolicy, the comment
tells them the pragma is now wrong.

The `/* istanbul ignore next -- reason */` form follows the one existing use in
this repo, augment-backend's HttpEmbedder.ts.

Measured, full suite with --no-cache:

  before  95.08% stmts / 90% branch, uncovered lines 45, 140, 147
  after   100% stmts / 100% branch / 100% funcs / 100% lines

No behaviour change: the guards still run, and the same 258 tests pass. tsc,
prettier and lint clean.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@gustavolira
gustavolira requested review from a team as code owners September 2, 2026 22:18
@rhdh-gh-app

rhdh-gh-app Bot commented Sep 2, 2026

Copy link
Copy Markdown

Missing Changesets

The following package(s) are changed by this PR but do not have a changeset:

  • @red-hat-developer-hub/cli-module-install-dynamic-plugins

See CONTRIBUTING.md for more information about how to add changesets.

Changed Packages

Package Name Package Path Changeset Bump Current Version
@red-hat-developer-hub/cli-module-install-dynamic-plugins workspaces/install-dynamic-plugins/packages/install-dynamic-plugins none v0.4.1

@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.30%. Comparing base (a6fe7ec) to head (0c9c17c).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4555      +/-   ##
==========================================
- Coverage   62.31%   62.30%   -0.01%     
==========================================
  Files        2606     2606              
  Lines      104644   104642       -2     
  Branches    29391    29389       -2     
==========================================
- Hits        65204    65202       -2     
  Misses      37623    37623              
  Partials     1817     1817              
Flag Coverage Δ *Carryforward flag
adoption-insights 84.30% <ø> (ø) Carriedforward from 5fe4090
ai-integrations 76.15% <ø> (ø) Carriedforward from 5fe4090
app-defaults 56.22% <ø> (ø) Carriedforward from 5fe4090
augment 46.67% <ø> (ø) Carriedforward from 5fe4090
boost 80.51% <ø> (ø) Carriedforward from 5fe4090
bulk-import 73.12% <ø> (ø) Carriedforward from 5fe4090
cost-management 13.55% <ø> (ø) Carriedforward from 5fe4090
dcm 73.47% <ø> (ø) Carriedforward from 5fe4090
e2e-adoption-insights 60.00% <ø> (ø) Carriedforward from 5fe4090
e2e-extensions 62.32% <ø> (ø) Carriedforward from 5fe4090
e2e-global-header 50.35% <ø> (ø) Carriedforward from 5fe4090
e2e-homepage 61.11% <ø> (ø) Carriedforward from 5fe4090
e2e-intelligent-assistant 47.04% <ø> (ø) Carriedforward from 5fe4090
e2e-orchestrator 49.52% <ø> (ø) Carriedforward from 5fe4090
e2e-orchestrator-plugin 49.51% <ø> (ø) Carriedforward from 5fe4090
e2e-quickstart 55.21% <ø> (ø) Carriedforward from 5fe4090
e2e-scorecard 50.21% <ø> (ø) Carriedforward from 5fe4090
e2e-theme 16.36% <ø> (ø) Carriedforward from 5fe4090
extensions 56.66% <ø> (ø) Carriedforward from 5fe4090
global-floating-action-button 71.18% <ø> (ø) Carriedforward from 5fe4090
global-header 68.09% <ø> (ø) Carriedforward from 5fe4090
homepage 48.48% <ø> (ø) Carriedforward from 5fe4090
install-dynamic-plugins 71.26% <ø> (-0.05%) ⬇️
intelligent-assistant 76.40% <ø> (ø) Carriedforward from 5fe4090
konflux 91.98% <ø> (ø) Carriedforward from 5fe4090
lightspeed 69.02% <ø> (ø) Carriedforward from 5fe4090
mcp-integrations 84.14% <ø> (ø) Carriedforward from 5fe4090
orchestrator 71.13% <ø> (ø) Carriedforward from 5fe4090
quickstart 63.74% <ø> (ø) Carriedforward from 5fe4090
sandbox 79.56% <ø> (ø) Carriedforward from 5fe4090
scorecard 87.90% <ø> (ø) Carriedforward from 5fe4090
theme 87.91% <ø> (ø) Carriedforward from 5fe4090
translations 5.12% <ø> (ø) Carriedforward from 5fe4090
x2a 77.10% <ø> (ø) Carriedforward from 5fe4090

*This pull request uses carry forward flags. Click here to find out more.


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a6fe7ec...0c9c17c. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

… (RHIDP-16761)

Review of the previous commit. One of the three guards it called unreachable is
reachable from a user's config, so the claim was wrong and the istanbul ignore
was hiding a real branch rather than documenting a dead one.

`isAlreadyInstalled`'s `if (pullPolicy !== PullPolicy.ALWAYS) return false` was
justified on the grounds that PullPolicy has exactly two members and
IF_NOT_PRESENT already returned above. That reasoning only holds if the value is
actually one of the two. It is not checked: installer.ts reads the config with
`parseYaml(rawContent) as DynamicPluginsConfig`, a type assertion with no
runtime validation, and `effectivePullPolicy` returns `plugin.pullPolicy`
whenever it is truthy. So `pullPolicy: Never` — or `always`, lower-cased —
travels from dynamic-plugins.yaml straight into this comparison.

The behaviour on that path is the right one: fall through and re-install, rather
than silently skip and strand the plugin at whatever version is on disk. It just
had no test. It does now, and removing the guard fails exactly that test and
nothing else.

The pragma on that line is gone, replaced by a comment saying why the branch
exists. The line is now covered for real instead of excluded from the report.

The other two remain ignored, with better reasons than the first commit gave.
The original comments cited OCI_REGEX, which only explains why a trailing `!` is
rejected. The reason a package with no `!` at all never reaches splitOciPackage
with an empty side is that the merger appends the resolved path first —
`!plugin.package.includes('!')` in mergePlugin, and resolveInherit for the
{{inherit}} case. Both mechanisms are now named, so a reader can check whether
the pragma still holds after changing either.

installer-oci.ts stays at 100% on all four metrics, but one of those branches is
now covered by a test rather than excluded by a pragma.

259 tests / 19 suites. tsc, prettier and lint clean.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@gustavolira gustavolira changed the title chore(install-dynamic-plugins): document why three guards in installer-oci.ts are unreachable (RHIDP-16761) test(install-dynamic-plugins): cover the unrecognised pullPolicy path, document two unreachable guards (RHIDP-16761) Sep 2, 2026
@sonarqubecloud

sonarqubecloud Bot commented Sep 2, 2026

Copy link
Copy Markdown

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.

1 participant