Files
Aemeath ac90575b0b
Build packages / CI (push) Blocked by required conditions
Build packages / Version (push) Waiting to run
CI / Web (format, types, tests, bundles) (push) Blocked by required conditions
CI / ShellCheck (push) Blocked by required conditions
CI / Backend (Go: vet, tests, a real ubusd and uhttpd) (push) Blocked by required conditions
CI / Package files (push) Blocked by required conditions
Dawnline 0.20.0
- **Backend rewritten in Go.** One daemon, `dawnlined`, replaces the whole ucode backend: the rpcd plugin, the agent, the CLI and the updater. The package no longer depends on ucode.
- **Per-architecture builds.** The release carries the backend for arm64, ARMv7, mips, mipsle and amd64; the router fetches its own after the package is installed and checks its sha256. Dawnline does not run on other architectures (older ARM, 32-bit x86, RISC-V).
- **Faster on the router.** A firewall sync takes 0.06 s instead of 0.9 s; a full apply takes about 300 ms. The portal is served by the daemon itself, without a CGI process per request.
- **Live pages.** The admin and the portal follow a live stream from the router instead of re-fetching the whole state every 30 seconds.
- **Admin redesigned in the portal's style.** Three sections (Overview · Log · Settings); a server is a page of its own with People, Places and Settings; a device opens as a dialog over its person.
- **Changes wait for «Apply».** Every setting, and a person's access, is staged in one dock before it reaches the router.
- **Configuration rollout.** After a change that makes devices fetch their configuration again, the admin shows how many have fetched it and who has not. Every setting shows beforehand (⟳N) how many devices it will touch.
- **Waiting for a decision.** Overview and People put first the people who need one (access ended, limit reached, a device that does not connect), each with its one action a tap away.
- **Bulk actions on people.** «Select» (or a long press on a card) picks several people to extend by a month, pause or resume at once.
- **Undo.** An action done from a card or a request is undone from its toast.
- **Update dialogs redesigned.** An update is one view from its question to its result; Dawnline's own update runs in it like every other, and the page reloads itself once the new version answers. Other versions are a list, each with its notes and Install on a page of its own.
- **Site to site: networks behind a router.** A router connected as a device can have networks behind it (up to eight, /16 to /30): the server routes them and applies the router's access to them. A network that shares addresses with a tunnel, the router's own networks or another site is refused by name.
- **Routers from the portal.** People can add a router and name its networks on their own page; the admin accepts or declines with a reason, or lets them through without asking.
- **Check access and Health know the networks behind routers.**
- **Usage limits reworked.** A monthly limit no longer follows the calendar. A person's month starts with their first traffic and ends a month later; the next one starts only when they connect again, so time away uses up none of it. Before, everyone's limit reset on the 1st.
- Extra data lasts until that person's month ends; «Reset usage» starts the month anew.
- A limit is for a month or for the whole term; the admin and the portal show when it resets.
- Charts that said «this month» show the last 30 days.
- After the update nobody loses what was counted: the month that was running becomes the person's first and ends on the 1st.
- **Access by time of day removed.** The Hours limit is gone from the admin, the portal and the backend; saved hours are dropped.
- **Expiry simplified.** An end date always stops access, with a heads-up three days before; the per-person choice is gone.
- **No false disconnects from sleeping phones.** A phone or a tablet stays online through ten minutes of silence.
- **Mobile Safari fixes.** Pressing a control no longer sends the page to its top; tab tracks that do not fit scroll; switches animate after a press.
2026-11-13 09:43:50 +03:00

291 lines
12 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from 'vitest';
import { monthOn, personLine, share } from '../src/admin/people/lines';
import { groupOf } from '../src/admin/people/card';
import { find, litAt, words } from '../src/admin/people/find';
import { inFilter, lastPlace, onlineAbove, scoped, sortBy, sortOf, sortPeople } from '../src/admin/people/roster';
import { extendAll, pauseAll, resumes } from '../src/admin/people/bulk';
import { refetchCount } from '../src/admin/people/refetch';
import type { Device, Person } from '../src/shared/types';
// The router at 2026-11-08 12:40 UTC+3.
const NOW = Date.UTC(2026, 10, 8, 9, 40) / 1000;
const T = { today: '2026-11-08', now: NOW };
const GB = 2 ** 30;
const dev = (o: Partial<Device> = {}): Device =>
({
id: 'd1',
name: 'Phone',
kind: 'phone',
address: '10.8.0.2',
disabled: false,
online: false,
handshake: NOW - 3600,
endpoint: '91.1.2.3:51820',
hostname: 'phone',
config_stale: false,
lan_bypass: false,
link: null,
spark: [],
month: [0, 0],
total: [0, 0],
...o,
}) as Device;
const person = (o: Partial<Person> = {}): Person =>
({
id: 'p1',
name: 'Lena',
server: 's1',
access: 'internet',
device_limit: 3,
expires: '',
quota_gb: 0,
quota_period: 'month',
quota_used: 0,
quota_limit: 0,
bonus_gb: 0,
dns_mode: 'device',
paused: false,
state: 'active',
month: [0, 0],
total: [0, 0],
online: 0,
last_seen: NOW - 3600,
devices: [dev()],
has_link: true,
...o,
}) as Person;
describe('personLine', () => {
it('names the backend state in its order, each with the action that fixes it', () => {
expect(personLine(person({ state: 'no_server' }), T)).toMatchObject({ text: 'No server', tone: 'bad', act: { id: 'server' } });
expect(personLine(person({ state: 'server_off', paused: true }), T)).toMatchObject({ tone: 'warn', act: { id: 'enable' } });
expect(personLine(person({ state: 'paused', paused: true }), T)).toMatchObject({ text: 'Paused', act: { id: 'resume' } });
// paused, and the end date passed while paused: resuming alone would end at once
expect(personLine(person({ state: 'paused', paused: true, expires: '2026-11-01' }), T).act).toMatchObject({
id: 'resume',
extend: true,
});
expect(personLine(person({ state: 'expired', expires: '2026-11-03' }), T)).toMatchObject({ tone: 'bad', act: { id: 'extend' } });
});
it('offers data that leaves them 10 GB or more (in tens), or the limit itself for a whole-term limit', () => {
const monthly = personLine(person({ state: 'quota', quota_used: 53 * GB, quota_limit: 50 * GB }), T);
expect(monthly.act).toMatchObject({ id: 'bonus', gb: 20 });
const over = personLine(person({ state: 'quota', quota_used: 75 * GB, quota_limit: 50 * GB }), T);
expect(over.act?.gb).toBe(40);
expect(personLine(person({ state: 'quota', quota_period: 'total', quota_used: 9 * GB, quota_limit: 5 * GB }), T).act?.id).toBe('limit');
});
it('warns of an end date in its last three days, for everyone alike', () => {
expect(personLine(person({ expires: '2026-11-10' }), T)).toMatchObject({ tone: 'warn', act: { id: 'extend' } });
expect(personLine(person({ expires: '2026-11-12' }), T).tone).toBe('');
});
it('says a device that needs something, and what fixes it', () => {
const trying = (stale: boolean) =>
personLine(person({ devices: [dev({ link: { state: 'trying', since: NOW - 600 } as Device['link'], config_stale: stale })] }), T).act;
expect(trying(false)).toMatchObject({ id: 'tell', device: 'd1' });
expect(trying(true)).toMatchObject({ id: 'show', device: 'd1' });
const stale = personLine(person({ devices: [dev({ config_stale: true })] }), T);
expect(stale).toMatchObject({ tone: 'warn', act: { id: 'show' } });
});
it('invites someone without devices where the portal is on, else offers adding one', () => {
expect(personLine(person({ devices: [] }), T).act?.id).toBe('invite');
expect(personLine(person({ devices: [], has_link: false }), T).act?.id).toBe('add-device');
expect(personLine(person({ last_seen: 0 }), T).text).toBe('No connections yet');
expect(personLine(person({ online: 2 }), T)).toMatchObject({ tone: 'ok', text: 'Online · 2 devices' });
});
});
describe('groups and order', () => {
it('puts a person in the group of what they need', () => {
expect(groupOf(person({ state: 'paused', paused: true }), T)).toBe('paused');
expect(groupOf(person({ state: 'expired', expires: '2026-11-03' }), T)).toBe('need');
// waiting on the person to fetch a new configuration is not the admin's decision
expect(groupOf(person({ devices: [dev({ config_stale: true })] }), T)).toBe('rest');
expect(groupOf(person({ online: 1 }), T)).toBe('online');
});
it('extends a month from the later of today and the end date, clamped to the month', () => {
expect(monthOn({ expires: '' }, '2026-11-08')).toBe('2026-12-08');
expect(monthOn({ expires: '2026-11-03' }, '2026-11-08')).toBe('2026-12-08');
expect(monthOn({ expires: '2027-01-31' }, '2026-11-08')).toBe('2027-02-28');
expect(share({ quota_used: 45, quota_limit: 50 })).toBe(0.9);
});
});
describe('find', () => {
const p = person({
name: 'Алёна Ким',
note: 'сестра',
devices: [
dev({ id: 'd1', name: 'MacBook Air', address: '10.8.0.7', hostname: 'macbook.alena.lan', endpoint: '[2a02:6b8::1]:4500' }),
dev({ id: 'd2', name: 'iPhone', address: '10.8.0.8', endpoint: '176.59.46.100:51820' }),
],
});
const hit = (q: string) => find(p, words(q)).hit;
it('finds by every word, in names, notes, devices and addresses, ё as е', () => {
expect(hit('')).toBe(true);
expect(hit('алена')).toBe(true);
expect(hit('ким macbook')).toBe(true);
expect(hit('10.8.0.7')).toBe(true);
expect(hit('2a02:6b8::1')).toBe(true);
expect(hit('СЕСТРА')).toBe(true);
expect(hit('ким ipad')).toBe(false);
});
it('says which device a word was found on and by what, not when the person answers it', () => {
expect(find(p, words('алена сестра')).match).toBeNull();
expect(find(p, words('176.59')).match).toMatchObject({ device: { id: 'd2' }, what: 'ip', value: '176.59.46.100' });
expect(find(p, words('10.8.0.7')).match).toMatchObject({ device: { id: 'd1' }, what: 'address' });
expect(find(p, words('ким alena.lan')).match).toMatchObject({ device: { id: 'd1' }, what: 'hostname', value: 'macbook.alena.lan' });
expect(find(p, words('iphone')).match).toMatchObject({ device: { id: 'd2' }, what: 'name' });
// the first device found is the one shown
expect(find(p, words('macbook iphone')).match).toMatchObject({ device: { id: 'd1' } });
expect(find(p, words('macbook pixel')).match).toBeNull();
});
it('finds where the longest word stands in a text', () => {
expect(litAt('176.59.46.100', words('176.59'))).toEqual([0, 6]);
expect(litAt('Алёна Ким', words('ким алена'))).toEqual([0, 5]);
expect(litAt('MacBook Air', words('pixel'))).toBeNull();
});
});
describe('the roster', () => {
const a = person({
id: 'a',
name: 'Аня',
server: 's1',
online: 1,
last_seen: NOW,
month: [GB, GB],
devices: [dev({ id: 'da', online: true })],
});
const b = person({
id: 'b',
name: 'Боря',
server: 's2',
expires: '2026-11-09',
last_seen: NOW - 3600,
devices: [dev({ id: 'db', config_stale: true })],
});
const c = person({
id: 'c',
name: 'Вика',
server: 's1',
state: 'paused',
paused: true,
expires: '2026-12-01',
quota_limit: 10 * GB,
quota_used: 9 * GB,
});
const d = person({
id: 'd',
name: 'Гена',
server: 's1',
online: 1,
state: 'quota',
quota_limit: GB,
quota_used: GB,
devices: [dev({ id: 'dd', online: true })],
});
const all = [a, b, c, d];
const ids = (ps: Person[]) => ps.map((p) => p.id).join('');
it('keeps who the address asks for: the server, a waiting configuration, a chip', () => {
expect(ids(scoped(all, {}, T))).toBe('abcd');
expect(ids(scoped(all, { server: 's1' }, T))).toBe('acd');
expect(ids(scoped(all, { need: 'config' }, T))).toBe('b');
expect(ids(scoped(all, { group: 'online' }, T))).toBe('ad');
expect(ids(scoped(all, { group: 'paused' }, T))).toBe('c');
expect(ids(scoped(all, { group: 'need' }, T))).toBe(ids(all.filter((p) => groupOf(p, T) === 'need')));
// a chip's count is of the people the other filters leave
expect(ids(scoped(all, { group: 'paused', server: 's1' }, T, false))).toBe('acd');
expect(inFilter(d, 'online', T)).toBe(true);
});
it('counts online the same in the head and in the groups', () => {
// Гена is online and needs a decision: «Online» lists Аня alone and owes one more above
expect(groupOf(d, T)).toBe('need');
expect(all.filter((p) => groupOf(p, T) === 'online').length + onlineAbove(all, T)).toBe(all.filter((p) => p.online > 0).length);
expect(onlineAbove(all, T)).toBe(1);
expect(onlineAbove([a], T)).toBe(0);
});
it('sorts by a column, names breaking ties', () => {
expect(ids(sortPeople(all, { key: 'name', dir: -1 }))).toBe('dcba');
// no end date sorts as the farthest
expect(ids(sortPeople(all, { key: 'term', dir: 1 }))).toBe('bcad');
expect(ids(sortPeople(all, { key: 'traffic', dir: -1 }))).toBe('dcab');
expect(ids(sortPeople(all, { key: 'seen', dir: -1 })).slice(0, 2)).toBe('ad');
});
it('keeps an order in the address: its key, the other way round after a dash', () => {
expect(sortBy('term')).toBe('term');
expect(sortBy('traffic')).toBe('-traffic');
expect(sortOf('-traffic')).toEqual({ key: 'traffic', dir: -1 });
expect(sortOf('term')).toEqual({ key: 'term', dir: 1 });
expect(sortOf('nope')).toBeNull();
});
it('knows where someone was last: live first, then the newest', () => {
const pt = (o: object) => ({
person: 'a',
device: 'da',
ip: '1.1.1.1',
ts: 1,
online: false,
lat: 0,
lon: 0,
city: 'A',
country: '',
cc: '',
asn: 0,
org: '',
...o,
});
const geo = {
enabled: true,
points: [pt({ city: 'Old', ts: 5 }), pt({ city: 'Live', ts: 2, online: true }), pt({ person: 'b', city: 'Other', ts: 9 })],
};
expect(lastPlace(a, geo as never)?.city).toBe('Live');
expect(lastPlace(c, geo as never)).toBeNull();
});
});
describe('picks', () => {
it('extends only those with an end date, and undoes to what each had', () => {
const b = extendAll([person({ id: 'a', expires: '2026-11-03' }), person({ id: 'b' })], '2026-11-08');
expect(b.changes).toEqual([{ id: 'a', patch: { expires: '2026-12-08' } }]);
expect(b.undo).toEqual([{ id: 'a', patch: { expires: '2026-11-03' } }]);
});
it('pauses those not paused yet; resumes when everyone picked is paused', () => {
const ps = [person({ id: 'a', paused: true }), person({ id: 'b' })];
expect(resumes(ps)).toBe(false);
expect(pauseAll(ps, true)).toEqual({ changes: [{ id: 'b', patch: { paused: true } }], undo: [{ id: 'b', patch: { paused: false } }] });
expect(resumes([ps[0]])).toBe(true);
expect(pauseAll([ps[0]], false).changes).toEqual([{ id: 'a', patch: { paused: false } }]);
expect(resumes([])).toBe(false);
});
});
describe('refetchCount', () => {
const p = person({
devices: [dev({ id: 'a' }), dev({ id: 'b', lan_bypass: true }), dev({ id: 'c', handshake: 0 }), dev({ id: 'd', disabled: true })],
});
it('counts the devices that have connected whose configuration the change rewrites', () => {
expect(refetchCount(p, { access: 'both' })).toBe(1);
expect(refetchCount(p, { access: 'lan' })).toBe(2);
expect(refetchCount(person({ ...p, access: 'lan' }), { access: 'internet' })).toBe(2);
expect(refetchCount(p, { dns_mode: 'home' })).toBe(0);
expect(refetchCount(person({ ...p, access: 'lan' }), { dns_mode: 'home' })).toBe(2);
expect(refetchCount(person({ ...p, access: 'both' }), { home_nets: ['lan'] })).toBe(1);
expect(refetchCount(p, { access: 'internet' })).toBe(0);
});
});