Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/user-intent-kit/src/host-telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ function readNetwork(sources) {
// The Wi-Fi port maps to one device (often en1); anything else is wired.
const ports = sources.run('/usr/sbin/networksetup', ['-listallhardwareports']);
const wifiDev = (ports.match(/Hardware Port:\s*Wi-Fi\s*\nDevice:\s*(\S+)/) || [])[1];
out.network = iface === wifiDev ? 'wifi' : 'ethernet';
// Keep the legacy medium label separate from the structured network report.
out.network_summary = iface === wifiDev ? 'wifi' : 'ethernet';
} else if (os === 'linux') {
const iface = (sources.run('/sbin/ip', ['route', 'show', 'default']).match(/dev\s+(\S+)/) || [])[1];
if (!iface) return out;
Expand All @@ -305,9 +306,9 @@ function readNetwork(sources) {
if (ip) out.lan_ip = ip;
try {
readdirSync(`/sys/class/net/${iface}/wireless`);
out.network = 'wifi';
out.network_summary = 'wifi';
} catch {
out.network = 'ethernet';
out.network_summary = 'ethernet';
}
}
return out;
Expand Down
7 changes: 4 additions & 3 deletions packages/user-intent-kit/test/host-telemetry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ test('reports a wired Mac as ethernet, not wifi', () => {
'/usr/sbin/ipconfig getifaddr en0': '192.168.50.241',
'/usr/sbin/networksetup -listallhardwareports': 'Hardware Port: Wi-Fi\nDevice: en1\n',
}})});
assert.equal(host.network, 'ethernet');
assert.equal(host.network_summary, 'ethernet');
assert.ok(!('network' in host), 'legacy telemetry must not overwrite structured network reports');
assert.equal(host.lan_ip, '192.168.50.241');
});

Expand All @@ -232,13 +233,13 @@ test('reports a Mac on the wifi device as wifi', () => {
'/usr/sbin/ipconfig getifaddr en1': '192.168.50.99',
'/usr/sbin/networksetup -listallhardwareports': 'Hardware Port: Wi-Fi\nDevice: en1\n',
}})});
assert.equal(host.network, 'wifi');
assert.equal(host.network_summary, 'wifi');
});

test('omits hardware and network when the commands fail', () => {
const host = collectHostTelemetry({ sources: sources({ platform: 'darwin', commands: {} })});
assert.ok(!('hw' in host), 'invented a hardware description');
assert.ok(!('network' in host), 'guessed a network medium');
assert.ok(!('network_summary' in host), 'guessed a network medium');
assert.ok(!('lan_ip' in host));
});

Expand Down
Loading