feat(health): pure helper to pick local/remote service URLs

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
root
2026-06-08 00:56:22 +10:00
parent 7f2a0ced72
commit a3662f6ff2
2 changed files with 57 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
import { describe, it, expect } from 'vitest';
import { isRemoteHost, pickServiceUrls } from '../../public/views/service_url.js';
describe('isRemoteHost', () => {
it('treats private/local hosts as not-remote', () => {
for (const h of ['localhost', '127.0.0.1', '192.168.1.216', '10.0.0.5', '172.16.0.1', 'void.local', 'ct311', 'nas.lan'])
expect(isRemoteHost(h)).toBe(false);
});
it('treats public domains as remote', () => {
for (const h of ['void.hynesy.com', 'dash.example.org'])
expect(isRemoteHost(h)).toBe(true);
});
});
describe('pickServiceUrls', () => {
const svc = { url: 'http://192.168.1.99', external: 'https://gramps.hynesy.com' };
it('remote + external → domain primary, LAN alt', () => {
expect(pickServiceUrls(svc, true)).toEqual({ primary: 'https://gramps.hynesy.com', alt: 'http://192.168.1.99', lanOnly: false });
});
it('local + external → LAN primary, domain alt', () => {
expect(pickServiceUrls(svc, false)).toEqual({ primary: 'http://192.168.1.99', alt: 'https://gramps.hynesy.com', lanOnly: false });
});
it('remote + no external → LAN primary, no alt, lanOnly', () => {
expect(pickServiceUrls({ url: 'http://192.168.1.5' }, true)).toEqual({ primary: 'http://192.168.1.5', alt: null, lanOnly: true });
});
it('local + no external → LAN primary, no alt', () => {
expect(pickServiceUrls({ url: 'http://192.168.1.5' }, false)).toEqual({ primary: 'http://192.168.1.5', alt: null, lanOnly: false });
});
});