fix: use s.remoteId == null check instead of !s.remoteId in getVisibleSessions()

Fixes falsy-0 bug where sessions with remoteId=0 (first remote instance) were
incorrectly hidden because !s.remoteId treats 0 as falsy. The null check
s.remoteId == null correctly handles:
- remoteId=0 (first remote instance) → truthy, not hidden
- remoteId=null or undefined (local sessions) → falsy, hidden if in hidden list

Changes:
- muxplex/frontend/app.js: Line 533 condition in getVisibleSessions()
- muxplex/frontend/tests/test_app.mjs: Added 2 tests for remoteId=0 behavior
- muxplex/tests/test_frontend_js.py: Added pattern test verifying source code

All 330 JS tests pass, all 200 Python tests pass.

Generated with Amplifier (https://github.com/microsoft/amplifier)

Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
This commit is contained in:
Brian Krabach
2026-04-08 18:04:45 -07:00
parent 4856094ca9
commit 5eb727fe86
3 changed files with 46 additions and 1 deletions
+1 -1
View File
@@ -530,7 +530,7 @@ function buildStatusTileHTML(deviceName, statusText, statusClass) {
function getVisibleSessions(sessions) {
var hidden = (_serverSettings && _serverSettings.hidden_sessions) || [];
return (sessions || []).filter(function(s) {
if (hidden.length > 0 && !s.remoteId && hidden.includes(s.name)) {
if (hidden.length > 0 && s.remoteId == null && hidden.includes(s.name)) {
return false;
}
return true;
+22
View File
@@ -4619,3 +4619,25 @@ test('getDisplaySettings reads display keys from _serverSettings with DISPLAY_DE
assert.ok(!('unknownKey' in ds), 'getDisplaySettings must not include keys not in DISPLAY_DEFAULTS');
app._setServerSettings(null);
});
// --- getVisibleSessions: remoteId=0 falsy-zero bug fix ---
test('getVisibleSessions does NOT hide sessions with remoteId 0 whose name is in hidden_sessions', () => {
app._setServerSettings({ hidden_sessions: ['work'] });
const sessions = [{ name: 'work', remoteId: 0 }];
const visible = app.getVisibleSessions(sessions);
assert.strictEqual(visible.length, 1, 'session with remoteId=0 must NOT be hidden even if name is in hidden_sessions');
app._setServerSettings(null);
});
test('getVisibleSessions hides local session (remoteId null) but keeps remote session (remoteId 0) with same name', () => {
app._setServerSettings({ hidden_sessions: ['work'] });
const sessions = [
{ name: 'work', remoteId: null },
{ name: 'work', remoteId: 0 },
];
const visible = app.getVisibleSessions(sessions);
assert.strictEqual(visible.length, 1, 'only the remote session (remoteId=0) should be visible');
assert.strictEqual(visible[0].remoteId, 0, 'the visible session must be the remote one with remoteId=0');
app._setServerSettings(null);
});
+23
View File
@@ -2710,3 +2710,26 @@ def test_bind_sidebar_click_away_calls_patch_server_setting() -> None:
assert "patchServerSetting" in body, (
"bindSidebarClickAway must call patchServerSetting to persist collapsed state"
)
# ─── task-1: getVisibleSessions falsy-0 bug fix ────────────────────────────
def test_get_visible_sessions_uses_null_check_not_falsy() -> None:
"""getVisibleSessions must use s.remoteId == null (not !s.remoteId) to avoid
treating remoteId=0 (first remote instance) as falsy and incorrectly hiding it."""
match = re.search(
r"function getVisibleSessions\s*\(\w+\)\s*\{(.*?)(?=\n(?:function|//|window\.))",
_JS,
re.DOTALL,
)
assert match, "getVisibleSessions function not found in app.js"
body = match.group(1)
assert "!s.remoteId" not in body, (
"getVisibleSessions must NOT use '!s.remoteId' — this treats remoteId=0 as falsy, "
"hiding the first remote instance. Use 's.remoteId == null' instead."
)
assert "s.remoteId == null" in body or "s.remoteId === null" in body, (
"getVisibleSessions must use 's.remoteId == null' (or '=== null') to correctly treat "
"remoteId=0 as a real remote while matching null/undefined as local sessions."
)