Skip to content

Fix duplicate missing packages badge - #16555

Merged
jmcphers merged 2 commits into
mainfrom
bugfix/duplicate-missing-packages-bar
Oct 10, 2026
Merged

jmcphers merged 2 commits into
mainfrom
bugfix/duplicate-missing-packages-bar

Conversation

@jmcphers

@jmcphers jmcphers commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

Fixes #16311

Positron notebooks showed the "missing packages" badge twice in the toolbar. There are two badges registered on the same toolbar menu: one for scripts and one for notebooks. The script badge did not exclude notebooks, and the notebook toolbar renders that same menu, so both appeared. The script badge is now hidden when the active editor is a Positron notebook, so notebooks show only their own badge.

This also adds an e2e test that opens a notebook that imports a missing package, switches to another tab and back, and checks that exactly one badge is shown.

Release Notes

New Features

  • N/A

Bug Fixes

Validation Steps

@:packages-pane @:positron-notebooks

  1. Enable Positron notebooks and open a notebook with a Python kernel that imports a package that isn't installed (e.g. import cowsay).
  2. Check that the toolbar shows one "missing package" badge.
  3. Switch to another editor tab and back, and check there is still only one badge.
  4. Open a Python script that imports a missing package and check that its badge still shows.

@jmcphers
jmcphers requested a review from midleman October 8, 2026 23:37
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

E2E Tests 🚀
This PR will run tests tagged with: @:critical @:packages-pane @:positron-notebooks

Why these tags?
Tag Source
@:critical Always runs (required)
@:packages-pane PR description
@:positron-notebooks PR description

More on automatic tags from changed files.

readme  valid tags

@midleman

midleman commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Thanks for adding a test for this, and for tracing the cause.

Since the bug was just the script badge's when clause matching inside notebooks, could a unit test cover it instead of the e2e? The rule can be checked directly: register the badges, ask the widget registry which ones show for each active editor, and check the result. I tried it on your branch. It fails without your fix (both badges come back) and passes with it, in a couple of seconds:

/// <reference types="vitest/globals" />

import { MenuId } from '../../../../../platform/actions/common/actions.js';
import { IContextKeyService } from '../../../../../platform/contextkey/common/contextkey.js';
import { PositronActionBarWidgetRegistry } from '../../../../../platform/positronActionBar/browser/positronActionBarWidgetRegistry.js';
import { stubInterface } from '../../../../../test/vitest/stubInterface.js';
import { POSITRON_NOTEBOOK_EDITOR_ID } from '../../../positronNotebook/common/positronNotebookCommon.js';
import { MISSING_PACKAGES_SUPPORTED_KEY } from '../../browser/missingPackagesContextKey.js';
// Registers the badge widgets as a side effect.
import '../../browser/positronMissingPackages.contribution.js';

function badgesFor(activeEditor: string): string[] {
	const values: Record<string, unknown> = {
		activeEditor,
		[MISSING_PACKAGES_SUPPORTED_KEY.key]: true,
	};
	const contextKeyService = stubInterface<IContextKeyService>({
		contextMatchesRules: rules => !rules || rules.evaluate({ getValue: <T>(key: string) => values[key] as T }),
	});
	return PositronActionBarWidgetRegistry.getWidgets(MenuId.EditorActionsRight, contextKeyService)
		.map(w => w.id)
		.filter(id => id.startsWith('positronMissingPackages.'));
}

describe('missing packages badge registration', () => {
	it('shows only the notebook badge in a Positron notebook', () => {
		expect(badgesFor(POSITRON_NOTEBOOK_EDITOR_ID)).toEqual(['positronMissingPackages.notebookBadge']);
	});

	it('shows only the editor badge in a text editor', () => {
		expect(badgesFor('workbench.editors.files.textFileEditor')).toEqual(['positronMissingPackages.editorBadge']);
	});
});

The second case also covers your validation step 4, that scripts still get their badge. Not a blocker, just a suggestion. Let me know what you think!

@jmcphers

jmcphers commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

@midleman thanks, replaced e2e with vitest in f74e0ac!

@midleman midleman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you! :)

@jmcphers
jmcphers merged commit 6b63b75 into main Oct 10, 2026
28 checks passed
@jmcphers
jmcphers deleted the bugfix/duplicate-missing-packages-bar branch October 10, 2026 00:17
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Notebooks: Notebook toolbar shows the missing packages badge twice

2 participants