-
Notifications
You must be signed in to change notification settings - Fork 14
feat: add plugin check-versions command and RHDH version resolution engine #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gashcrumb
merged 12 commits into
redhat-developer:main
from
gashcrumb:feat/plugin-check-versions
Sep 10, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
66352c2
feat: add plugin check-versions command and RHDH version resolution e…
gashcrumb 5b3e492
refactor: address SonarCloud maintainability and duplication findings
gashcrumb 3bd97a3
chore: bump version to 2.0.5 and update changelog
gashcrumb 9ffac3a
test: deduplicate test setup helpers in unit test suites
gashcrumb f84068a
test: streamline check-versions test setup to remove duplicated fixtu…
gashcrumb f9bb96a
feat: support in-development releases and direct backstage versions
gashcrumb 4b0a146
refactor: use optional chaining on parsed semver in rhdhVersion
gashcrumb ea4e76d
fix: address check-versions review feedback
gashcrumb e9c5e7e
fix: address check-versions review findings
gashcrumb 3b1a42e
docs: document compatibility matrix maintenance
gashcrumb bd68345
refactor: simplify unverifiable dependency output
gashcrumb 687923a
fix: default to RHDH 2.1.0
gashcrumb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,231 @@ | ||
| /* | ||
| * Copyright 2026 The Backstage Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import fs from 'fs-extra'; | ||
| import os from 'os'; | ||
| import path from 'node:path'; | ||
|
|
||
| import { ExitCodeError } from '../../lib/errors'; | ||
| import { resolveRhdhVersion } from '../../lib/rhdhVersion'; | ||
| import { checkPluginDependencies, command } from './command'; | ||
|
|
||
| jest.mock('../../lib/rhdhVersion', () => ({ | ||
| ...jest.requireActual('../../lib/rhdhVersion'), | ||
| resolveRhdhVersion: jest.fn(), | ||
| })); | ||
|
|
||
| describe('checkPluginDependencies', () => { | ||
| let tmpDir: string; | ||
| let originalCwd: string; | ||
| const mockResolveRhdhVersion = resolveRhdhVersion as jest.MockedFunction< | ||
| typeof resolveRhdhVersion | ||
| >; | ||
|
|
||
| async function setupFixture( | ||
| pkg: { | ||
| dependencies?: Record<string, string>; | ||
| devDependencies?: Record<string, string>; | ||
| peerDependencies?: Record<string, string>; | ||
| }, | ||
| manifestPackages: [string, string][] = [ | ||
| ['@backstage/core-plugin-api', '1.12.0'], | ||
| ], | ||
| ) { | ||
| await fs.writeJson(path.join(tmpDir, 'package.json'), { | ||
| name: 'test-plugin', | ||
| ...pkg, | ||
| }); | ||
| mockResolveRhdhVersion.mockResolvedValue({ | ||
| rhdhVersion: '2.0.0', | ||
| backstageVersion: '1.52.0', | ||
| source: 'matrix', | ||
| packages: new Map(manifestPackages), | ||
| }); | ||
| } | ||
|
|
||
| async function runCommandWithOutput(opts: any = {}) { | ||
| let stdout = ''; | ||
| let stderr = ''; | ||
| let error: Error | undefined; | ||
| const stdoutSpy = jest | ||
| .spyOn(process.stdout, 'write') | ||
| .mockImplementation((chunk: any) => { | ||
| stdout += chunk; | ||
| return true; | ||
| }); | ||
| const stderrSpy = jest | ||
| .spyOn(process.stderr, 'write') | ||
| .mockImplementation((chunk: any) => { | ||
| stderr += chunk; | ||
| return true; | ||
| }); | ||
|
|
||
| try { | ||
| await command(opts); | ||
| } catch (caughtError) { | ||
| error = caughtError as Error; | ||
| } finally { | ||
| stdoutSpy.mockRestore(); | ||
| stderrSpy.mockRestore(); | ||
| } | ||
|
|
||
| return { stdout, stderr, error }; | ||
| } | ||
|
|
||
| beforeEach(async () => { | ||
| originalCwd = process.cwd(); | ||
| tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'check-versions-test-')); | ||
| process.chdir(tmpDir); | ||
| process.exitCode = undefined; | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| process.chdir(originalCwd); | ||
| await fs.remove(tmpDir); | ||
| process.exitCode = undefined; | ||
| }); | ||
|
|
||
| it('throws error when package.json does not exist', async () => { | ||
| await expect( | ||
| checkPluginDependencies({ targetDir: tmpDir }), | ||
| ).rejects.toThrow(/No package\.json found/); | ||
| }); | ||
|
|
||
| it('reports matching dependencies when versions align with manifest', async () => { | ||
| await setupFixture( | ||
| { | ||
| dependencies: { | ||
| '@backstage/core-plugin-api': '^1.12.0', | ||
| '@backstage/catalog-model': '~1.7.6', | ||
| }, | ||
| devDependencies: { | ||
| '@backstage/cli': '0.36.3', | ||
| }, | ||
| peerDependencies: { | ||
| '@backstage/config': 'backstage:^', | ||
| }, | ||
| }, | ||
| [ | ||
| ['@backstage/core-plugin-api', '1.12.0'], | ||
| ['@backstage/catalog-model', '1.7.6'], | ||
| ['@backstage/cli', '0.36.3'], | ||
| ['@backstage/config', '1.3.8'], | ||
| ], | ||
| ); | ||
|
|
||
| const result = await checkPluginDependencies({ targetDir: tmpDir }); | ||
|
|
||
| expect(result.valid).toBe(true); | ||
| expect(result.counts.matching).toBe(3); | ||
| expect(result.counts.mismatched).toBe(0); | ||
| expect(result.counts.unmanifested).toBe(0); | ||
| expect(result.counts.unverifiable).toBe(1); | ||
| expect( | ||
| result.packages.find(p => p.name === '@backstage/config')?.status, | ||
| ).toBe('unverifiable'); | ||
| }); | ||
|
|
||
| it('reports mismatched and unmanifested dependencies when versions differ', async () => { | ||
| await setupFixture( | ||
| { | ||
| dependencies: { | ||
| '@backstage/core-plugin-api': '^1.9.0', | ||
| '@backstage/unknown-pkg': '^1.0.0', | ||
| lodash: '^4.17.21', | ||
| }, | ||
| devDependencies: { | ||
| '@backstage/cli': '^0.30.0', | ||
| }, | ||
| }, | ||
| [ | ||
| ['@backstage/core-plugin-api', '1.12.0'], | ||
| ['@backstage/cli', '0.36.3'], | ||
| ], | ||
| ); | ||
|
|
||
| const result = await checkPluginDependencies({ targetDir: tmpDir }); | ||
|
|
||
| expect(result.valid).toBe(false); | ||
| expect(result.counts.matching).toBe(0); | ||
| expect(result.counts.mismatched).toBe(2); | ||
| expect(result.counts.unmanifested).toBe(1); | ||
| expect(result.counts.unverifiable).toBe(0); | ||
| expect(result.counts.total).toBe(3); | ||
|
|
||
| const corePluginApi = result.packages.find( | ||
| p => p.name === '@backstage/core-plugin-api', | ||
| ); | ||
| expect(corePluginApi?.status).toBe('mismatch'); | ||
| expect(corePluginApi?.declared).toBe('^1.9.0'); | ||
| expect(corePluginApi?.expected).toBe('1.12.0'); | ||
|
|
||
| const unknownPkg = result.packages.find( | ||
| p => p.name === '@backstage/unknown-pkg', | ||
| ); | ||
| expect(unknownPkg?.status).toBe('unmanifested'); | ||
| expect(unknownPkg?.expected).toBeUndefined(); | ||
| }); | ||
|
|
||
| describe('CLI command handler', () => { | ||
| it('reports backstage:^ dependencies as unverifiable', async () => { | ||
| await setupFixture( | ||
| { peerDependencies: { '@backstage/config': 'backstage:^' } }, | ||
| [['@backstage/config', '1.3.8']], | ||
| ); | ||
|
|
||
| const res = await runCommandWithOutput({}); | ||
| expect(res.stderr).toContain('cannot verify backstage:^'); | ||
| expect(res.stderr).toContain('cannot be verified'); | ||
| expect(res.error).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('outputs JSON when --json flag is passed and sets exitCode on failure', async () => { | ||
| await setupFixture({ | ||
| dependencies: { '@backstage/core-plugin-api': '^1.9.0' }, | ||
| }); | ||
|
|
||
| const res = await runCommandWithOutput({ json: true }); | ||
| const parsed = JSON.parse(res.stdout); | ||
| expect(parsed.valid).toBe(false); | ||
| expect(parsed.counts.mismatched).toBe(1); | ||
| expect(res.error).toEqual(new ExitCodeError(1)); | ||
| }); | ||
|
|
||
| it('prints formatted table and remediation when run in human mode', async () => { | ||
| await setupFixture({ | ||
| dependencies: { '@backstage/core-plugin-api': '^1.9.0' }, | ||
| }); | ||
|
|
||
| const res = await runCommandWithOutput({}); | ||
| expect(res.stderr).toContain('Package'); | ||
| expect(res.stderr).toContain('@backstage/core-plugin-api'); | ||
| expect(res.stderr).toContain('mismatch'); | ||
| expect(res.stderr).toContain('rhdh-cli plugin upgrade 2.0.0'); | ||
| expect(res.error).toEqual(new ExitCodeError(1)); | ||
| }); | ||
|
|
||
| it('prints success message when dependencies are aligned', async () => { | ||
| await setupFixture({ | ||
| dependencies: { '@backstage/core-plugin-api': '^1.12.0' }, | ||
| }); | ||
|
|
||
| const res = await runCommandWithOutput({}); | ||
| expect(res.stderr).toContain('All @backstage dependencies are aligned'); | ||
| expect(res.error).toBeUndefined(); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.