Release branch for 4.0.0.
This commit is contained in:
jubnl
2026-08-27 13:22:39 +02:00
committed by GitHub
parent e60427f813
commit 77dddd5e8a
3355 changed files with 403744 additions and 67215 deletions
@@ -1,6 +1,6 @@
import { describe, it, expect } from 'vitest';
import { evaluate } from '../../../src/systemNotices/conditions.js';
import type { SystemNotice } from '../../../src/systemNotices/types.js';
import type { NoticeCondition, SystemNotice } from '../../../src/systemNotices/types.js';
const baseNotice: SystemNotice = {
id: 'test',
@@ -13,14 +13,28 @@ const baseNotice: SystemNotice = {
publishedAt: '2026-01-01T00:00:00Z',
};
// Conditions have to be contextually typed as NoticeCondition, otherwise a literal like
// `roles: ['user']` widens to string[] and no longer matches the union's
// Array<'admin' | 'user'>. Going through this helper types every case at once.
const noticeWith = (...conditions: NoticeCondition[]): SystemNotice => ({ ...baseNotice, conditions });
const baseCtx = {
user: { login_count: 5, first_seen_version: '1.0.0', role: 'user' },
// noTrips joined the context when the 'noTrips' condition kind landed. 1 keeps
// every case below reading as it did: the condition is `noTrips === 0`, so a
// user WITH trips leaves it false and the other kinds decide on their own.
user: { login_count: 5, first_seen_version: '1.0.0', role: 'user', noTrips: 1 },
currentAppVersion: '2.0.0',
now: new Date('2026-06-01T00:00:00Z'),
// Threaded in by the caller since the addons.bridge import left this module;
// false keeps every case below reading as it did.
addonEnabled: () => false,
// The ordinary install, so every case below is unaffected by the flag; the
// managed condition itself is exercised in its own describe block at the end.
managed: false,
};
describe('firstLogin', () => {
const notice = { ...baseNotice, conditions: [{ kind: 'firstLogin' as const }] };
const notice = noticeWith({ kind: 'firstLogin' });
it('passes when login_count <= 1', () => {
expect(evaluate(notice, { ...baseCtx, user: { ...baseCtx.user, login_count: 1 } })).toBe(true);
});
@@ -30,7 +44,7 @@ describe('firstLogin', () => {
});
describe('existingUserBeforeVersion', () => {
const notice = { ...baseNotice, conditions: [{ kind: 'existingUserBeforeVersion' as const, version: '2.0.0' }] };
const notice = noticeWith({ kind: 'existingUserBeforeVersion', version: '2.0.0' });
it('passes for user with first_seen_version < notice version when current >= notice version', () => {
expect(evaluate(notice, baseCtx)).toBe(true);
});
@@ -50,36 +64,36 @@ describe('existingUserBeforeVersion', () => {
describe('dateWindow', () => {
it('passes when now is inside window', () => {
const notice = { ...baseNotice, conditions: [{ kind: 'dateWindow' as const, startsAt: '2026-05-01T00:00:00Z', endsAt: '2026-07-01T00:00:00Z' }] };
const notice = noticeWith({ kind: 'dateWindow', startsAt: '2026-05-01T00:00:00Z', endsAt: '2026-07-01T00:00:00Z' });
expect(evaluate(notice, baseCtx)).toBe(true);
});
it('fails when now is before start', () => {
const notice = { ...baseNotice, conditions: [{ kind: 'dateWindow' as const, startsAt: '2026-07-01T00:00:00Z' }] };
const notice = noticeWith({ kind: 'dateWindow', startsAt: '2026-07-01T00:00:00Z' });
expect(evaluate(notice, baseCtx)).toBe(false);
});
it('passes when no endsAt', () => {
const notice = { ...baseNotice, conditions: [{ kind: 'dateWindow' as const, startsAt: '2026-01-01T00:00:00Z' }] };
const notice = noticeWith({ kind: 'dateWindow', startsAt: '2026-01-01T00:00:00Z' });
expect(evaluate(notice, baseCtx)).toBe(true);
});
});
describe('role', () => {
it('passes for matching role', () => {
const notice = { ...baseNotice, conditions: [{ kind: 'role' as const, roles: ['user'] }] };
const notice = noticeWith({ kind: 'role', roles: ['user'] });
expect(evaluate(notice, baseCtx)).toBe(true);
});
it('fails for non-matching role', () => {
const notice = { ...baseNotice, conditions: [{ kind: 'role' as const, roles: ['admin'] }] };
const notice = noticeWith({ kind: 'role', roles: ['admin'] });
expect(evaluate(notice, baseCtx)).toBe(false);
});
});
describe('AND logic', () => {
it('requires all conditions to pass', () => {
const notice = { ...baseNotice, conditions: [
{ kind: 'firstLogin' as const },
{ kind: 'role' as const, roles: ['user'] },
]};
const notice = noticeWith(
{ kind: 'firstLogin' },
{ kind: 'role', roles: ['user'] },
);
// login_count=1 passes firstLogin, role=user passes role → true
expect(evaluate(notice, { ...baseCtx, user: { ...baseCtx.user, login_count: 1 } })).toBe(true);
// login_count=2 fails firstLogin → false
@@ -92,3 +106,27 @@ describe('empty conditions', () => {
expect(evaluate(baseNotice, baseCtx)).toBe(true);
});
});
describe('addonEnabled', () => {
it('asks the threaded-in check with the condition addon id', () => {
const notice = noticeWith({ kind: 'addonEnabled', addonId: 'journey' });
expect(evaluate(notice, { ...baseCtx, addonEnabled: (id) => id === 'journey' })).toBe(true);
expect(evaluate(notice, { ...baseCtx, addonEnabled: (id) => id === 'vacay' })).toBe(false);
expect(evaluate(notice, baseCtx)).toBe(false);
});
});
describe('managed', () => {
it('matches on the value asked for, in both directions', () => {
// Both directions on purpose: the registry uses `is: false` to keep a notice
// away from a centrally administered install, and a notice that only ever
// shows there would use `is: true`.
const wantsSelfRun = noticeWith({ kind: 'managed', is: false });
const wantsManaged = noticeWith({ kind: 'managed', is: true });
expect(evaluate(wantsSelfRun, { ...baseCtx, managed: false })).toBe(true);
expect(evaluate(wantsSelfRun, { ...baseCtx, managed: true })).toBe(false);
expect(evaluate(wantsManaged, { ...baseCtx, managed: true })).toBe(true);
expect(evaluate(wantsManaged, { ...baseCtx, managed: false })).toBe(false);
});
});
@@ -3,6 +3,7 @@ import fs from 'node:fs';
import path from 'node:path';
import semver from 'semver';
import { SYSTEM_NOTICES } from '../../../src/systemNotices/registry.js';
import { isNoticeVersionActive } from '../../../src/systemNotices/service.js';
/** Collect all actionIds registered via registerNoticeAction() in client source files. */
function collectRegisteredActionIds(): Set<string> {
@@ -63,4 +64,34 @@ describe('registry integrity', () => {
}
}
});
it('the 4.0.0 release notice is confined to the 4.0.x line', () => {
const release = SYSTEM_NOTICES.find(n => n.id === 'release-4-0-0');
expect(release).toBeDefined();
// Its copy is about this release, so it must not greet somebody who skipped
// straight past it, and it must not run alongside the next release's notice.
expect(isNoticeVersionActive(release!, '3.4.1')).toBe(false);
expect(isNoticeVersionActive(release!, '4.0.0')).toBe(true);
expect(isNoticeVersionActive(release!, '4.0.7')).toBe(true);
// The upper bound is exclusive, so every 4.0.x patch still gets it.
expect(isNoticeVersionActive(release!, '4.0.9')).toBe(true);
expect(isNoticeVersionActive(release!, '4.0.12')).toBe(true);
expect(isNoticeVersionActive(release!, '4.1.0')).toBe(false);
expect(isNoticeVersionActive(release!, '4.2.0')).toBe(false);
});
it('the thank-you notice hands over to the release modal at 4.0.0', () => {
const thankYou = SYSTEM_NOTICES.find(n => n.id === 'thank-you-support');
expect(thankYou).toBeDefined();
// Both carry the same thank-you and the same two support links, so exactly
// one of them may be active at any version.
expect(isNoticeVersionActive(thankYou!, '3.4.1')).toBe(true);
expect(isNoticeVersionActive(thankYou!, '4.0.0')).toBe(false);
const release = SYSTEM_NOTICES.find(n => n.id === 'release-4-0-0')!;
for (const version of ['3.4.1', '4.0.0', '4.0.7', '4.1.0', '5.0.0']) {
const active = [thankYou!, release].filter(n => isNoticeVersionActive(n, version));
expect(active.length, `both thank-you notices active at ${version}`).toBeLessThanOrEqual(1);
}
});
});