Skip to content

Fix exact-port rule clearing inherited protocol from range - #344775

Closed
Ayush Kr Singh (ayushkrsingh946) wants to merge 2 commits into
microsoft:mainfrom
ayushkrsingh946:fix/exact-port-protocol-inheritance
Closed

Ayush Kr Singh (ayushkrsingh946) wants to merge 2 commits into
microsoft:mainfrom
ayushkrsingh946:fix/exact-port-protocol-inheritance

Conversation

@ayushkrsingh946

Copy link
Copy Markdown
Contributor

Fixes #344750.

Problem

An exact-port rule in remote.portsAttributes that omits protocol (for instance, a rule that only sets a label such as "3500": { "label": "Application" }) clears the protocol inherited from an overlapping port range (e.g. "3000-4000": { "protocol": "https" }). Because sortAttributes orders rules by start port / exact port, the range rule runs first and sets attributes.protocol = 'https', but the exact-port rule then unconditionally assigned:

attributes.protocol = found.protocol;

which overwrote attributes.protocol back to undefined when omitted by the exact rule. The Ports view consequently falls back to HTTP.

Solution

In PortsAttributes.getAttributes, merge the exact-port protocol with fallback to accumulated attributes:

attributes.protocol = found.protocol ?? attributes.protocol;

This preserves any protocol inherited from a matching range or regex rule when the exact-port rule leaves protocol unset, while still allowing an exact-port rule with an explicit protocol to override it.

Tests

  • Added unit tests in src/vs/workbench/services/remote/test/browser/tunnelModel.test.ts:
    • preserves exact-port protocol over matching range and regex rules
    • preserves range protocol when an exact-port rule leaves it unset
  • Ran the unit test suite (PortsAttributes suite passing 17/17).
  • Verified npm run typecheck-client and ESLint pass with no errors.

Fixes microsoft#344750.

When resolving port attributes, an exact-port rule that omits protocol
(such as an entry setting only a label) should preserve any protocol
inherited from a matching range or regex rule, while an exact rule that
explicitly sets a protocol should override it.

In PortsAttributes.getAttributes, use found.protocol ?? attributes.protocol
instead of unconditionally assigning found.protocol, matching the behavior
of other attributes.
Copilot AI balanced review requested due to automatic review settings October 28, 2026 16:04
@ayushkrsingh946

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

Copilot AI 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.

🟢 Approval recommended

No active review issues are reported for the change preserving inherited port protocols.

No open issues 🎉

What changed in this PR

Fixes #344750 by preserving an inherited port protocol when an exact-port rule omits protocol, preventing the Ports view from incorrectly falling back to HTTP.

Changes:

  • Retains the accumulated protocol unless the exact-port rule explicitly overrides it.
  • Adds tests for protocol inheritance and exact-port precedence using both HTTP and HTTPS.
File Description
src/​vs/​workbench/​services/​remote/​test/​browser/​tunnelModel.test.ts Adds protocol support to the test helper and regression tests for inheritance and precedence.
src/​vs/​workbench/​services/​remote/​common/​tunnelModel.ts Preserves the inherited protocol when an exact-port rule leaves it unset.

Review effort: Balanced

@alexr00

Copy link
Copy Markdown
Member

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.

remote.portsAttributes: exact-port label clears HTTPS protocol inherited from a range

3 participants