5.5 KiB
Agent Note: Keep port forwarding usable when host OS metadata is missing
Status: implemented
Problem
Issue #3748 reports that the
port-forwarding page displays Port forwarding could not load. when rendering
a selected host whose legacy os value is absent, null, or an empty string.
EditPanel, NewFormPanel, and both host-selection steps in WizardContent
evaluate selectedHost.os[0].toUpperCase() while constructing DistroAvatar
props. Missing or null values fail on indexing; an empty string fails on
toUpperCase. This happens before the avatar can render its generic icon.
Although Host.os is required by TypeScript, persisted runtime records can lack
that metadata. The original source of the affected records is not established.
Decision
The four call sites use (selectedHost.os || 'unknown').charAt(0).toUpperCase()
to keep the required string fallback safe without changing the shared avatar
API. Valid OS values retain their existing initials. Missing and empty values
use the explicit unknown fallback, and the avatar keeps its existing generic
icon behavior.
The fix stays in the affected presentation code. It does not change host data, normalization, persistence, or tunnel lifecycle behavior. A shared helper for a single short expression would add indirection without a separate responsibility, so the four call sites use the same expression directly.
Validation
components/PortForwardingPanels.test.tsx renders the real components with
react-dom/server, the existing i18n provider, and the tooltip provider. It does
not mock the panels or avatar and does not inspect their source text.
The table-driven cases cover all four entry points, all three forwarding types,
and missing, undefined, null, empty, Linux, Windows, and macOS values. Separate
checks preserve distro icons and host-picker behavior when no host is selected
or the selected host is no longer available. Invalid legacy fixture shapes use
one explicit type assertion rather than weakening the production Host type.
Before the fix, 48 of the 96 new cases fail with the reported TypeError; the other 48 pass. After the fix, all 96 pass. Together with the existing avatar, port-forwarding toolbar, and utility tests, the focused run passes 109 tests:
node --test --import tsx components/PortForwardingPanels.test.tsx \
components/PortForwardingNew.test.ts components/portForwardingUtils.test.ts \
components/DistroAvatar.test.tsx --test-concurrency=2
These are rendering regression tests, not SSH or network end-to-end tests.
Additional checks against upstream commit 786a317:
npm run buildsucceeds.npm run lintsucceeds with the same eight existing warnings as upstream. The four changed TypeScript/TSX files also pass lint with--max-warnings=0.LC_ALL=C npm test -- --test-concurrency=1runs 13,986 tests: 13,944 pass, four fail, and 38 are skipped. An unmodified upstream worktree runs 13,890 tests with the same four failures and 38 skips, so this change adds 96 passing cases without adding a failing case. The baseline failures are the SFTP large-directory persistence timing test, two Bash OSC 7 setup tests, and the README clipboard-paste screenshot-dimension assertion. The SFTP timing test passes in isolated runs on both checkouts but fails in these full-suite runs. A non-English locale additionally causes the existing fish error-message assertion to fail; both comparison runs use the C locale.- The full-project
tsc --noEmit --pretty falsecheck has 759 existing errors. Its complete output matches the unmodified upstream output after normalizing checkout paths; none of the changed files has a diagnostic. This is not a claim that full-project type checking passes.
Upstream CI follow-up
The original PR CI run 39215269619, attempt 2
passes all 96 new regression cases and fails only the existing README paste
assertion. Upstream commit b366967 fixes that assertion by removing its
coupling to changing screenshot dimensions. The branch incorporates this fix
through a normal merge of upstream main at 42b8e2f, without rewriting the
original fix commit or adding an independent change to the unrelated test.
After synchronization, the focused run including the entire clipboard-paste
test file passes 149 tests. Lint and the production build also pass; lint keeps
the same eight existing warnings. The earlier full-suite and type-check
comparison above describes the original 786a317 baseline, not the updated
base. Current remote CI results are tracked on the PR.
Alternatives considered
- Remove the unused fallback prop from the four calls: the shared avatar still requires it in its TypeScript contract. Changing that API and cleaning up all callers is unnecessary for this targeted bug fix.
- Normalize or rewrite stored host records: broadens the persistence scope, obscures the rendering assumption, and cannot replace guarding optional runtime metadata at the point of use.
- Add a new avatar wrapper or fallback utility: unnecessary for this small expression and would expand the production change without improving the boundary being fixed.
Consequences
Incomplete host OS metadata no longer prevents new/edit panels or wizard host-selection steps from rendering. Existing icons, component contracts, and host records remain unchanged. The guard is local to port forwarding; auditing unrelated callers or redesigning the unused fallback API remains out of scope.