refactor: keep pure logic importable in tests on any OS
- netinfo_helper imports the Linux-only fcntl inside ipv4_of(), so detect() can be unit-tested on Windows/macOS - SUPPORTED_API_VERSIONS moves to src/native/apiVersion.js (no Vite-only imports), so rediscovery.js runs under plain Node Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -21,7 +21,6 @@ reports no IP instead of a wrong one.
|
|||||||
Standalone on purpose: standard library only, no app imports, no database.
|
Standalone on purpose: standard library only, no app imports, no database.
|
||||||
Run: python -m services.netinfo_helper
|
Run: python -m services.netinfo_helper
|
||||||
"""
|
"""
|
||||||
import fcntl
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
@@ -37,6 +36,7 @@ SIOCGIFADDR = 0x8915
|
|||||||
|
|
||||||
def ipv4_of(ifname: str) -> str | None:
|
def ipv4_of(ifname: str) -> str | None:
|
||||||
"""Primary IPv4 address of an interface, or None if it has none."""
|
"""Primary IPv4 address of an interface, or None if it has none."""
|
||||||
|
import fcntl # Linux-only; imported here so detect() stays testable anywhere
|
||||||
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
|
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
|
||||||
try:
|
try:
|
||||||
packed = fcntl.ioctl(s.fileno(), SIOCGIFADDR, struct.pack("256s", ifname[:15].encode()))
|
packed = fcntl.ioctl(s.fileno(), SIOCGIFADDR, struct.pack("256s", ifname[:15].encode()))
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// api_version values (from /api/system/identity) this build can talk to.
|
||||||
|
// Own module (no Vite-only imports) so the pure native logic stays testable in Node.
|
||||||
|
export const SUPPORTED_API_VERSIONS = [1]
|
||||||
@@ -13,8 +13,9 @@
|
|||||||
import { deliveryMode, saveVenue } from '../config/server'
|
import { deliveryMode, saveVenue } from '../config/server'
|
||||||
import { syncTrustedKeys, tlsBaseUrl } from './tls'
|
import { syncTrustedKeys, tlsBaseUrl } from './tls'
|
||||||
|
|
||||||
// api_version values (from /api/system/identity) this build can talk to.
|
import { SUPPORTED_API_VERSIONS } from './apiVersion'
|
||||||
export const SUPPORTED_API_VERSIONS = [1]
|
|
||||||
|
export { SUPPORTED_API_VERSIONS }
|
||||||
|
|
||||||
const PROBE_TIMEOUT_MS = 5000
|
const PROBE_TIMEOUT_MS = 5000
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
* (new router, different subnet) still has the manual fallback: scan the QR.
|
* (new router, different subnet) still has the manual fallback: scan the QR.
|
||||||
* Contract: docs/reference/lan-access.md
|
* Contract: docs/reference/lan-access.md
|
||||||
*/
|
*/
|
||||||
import { SUPPORTED_API_VERSIONS } from './pairing'
|
import { SUPPORTED_API_VERSIONS } from './apiVersion.js'
|
||||||
|
|
||||||
const PROBE_TIMEOUT_MS = 1500
|
const PROBE_TIMEOUT_MS = 1500
|
||||||
// The first TLS connection to a venue server in a fresh app process takes ~2s
|
// The first TLS connection to a venue server in a fresh app process takes ~2s
|
||||||
|
|||||||
Reference in New Issue
Block a user