refactor(realtime): the websocket welcome frame reads the running version from app-config

The gateway imported hostVersion from the plugin install code to put the
version in its welcome frame, which made the realtime domain, imported by
nearly every other, depend on plugins. The running version (image VERSION
or APP_VERSION, else package.json) is app config; runningVersion() holds it
and the plugin host-compat checks call the same function.
This commit is contained in:
Maurice
2026-10-10 12:20:38 +02:00
parent 01fd4e3739
commit 0c2226c5f0
6 changed files with 42 additions and 79 deletions
+1 -75
View File
@@ -12,27 +12,10 @@
"assignments -> mcp-shared",
"assignments -> realtime",
"atlas -> addons",
"auth -> budget",
"auth -> files",
"auth -> notifications",
"auth -> plugins",
"budget -> addons",
"budget -> mcp-shared",
"budget -> realtime",
"calendar -> days",
"calendar -> reservations",
"categories -> mcp-shared",
"collab -> addons",
"collab -> files",
"collab -> mcp-shared",
"collab -> notifications",
"collab -> realtime",
"collections -> addons",
"collections -> notifications",
"collections -> places",
"collections -> realtime",
"day-notes -> mcp-shared",
"day-notes -> realtime",
"days -> accommodations",
"days -> assignments",
"days -> mcp-shared",
@@ -55,7 +38,6 @@
"journey -> memories",
"journey -> photos",
"journey -> realtime",
"llm-parse -> addons",
"maps -> geo",
"mcp-shared -> realtime",
"memories -> addons",
@@ -63,10 +45,6 @@
"memories -> photos",
"memories -> realtime",
"notifications -> realtime",
"packing -> addons",
"packing -> mcp-shared",
"packing -> notifications",
"packing -> realtime",
"photos -> memories",
"places -> accommodations",
"places -> assignments",
@@ -74,29 +52,9 @@
"places -> journey",
"places -> mcp-shared",
"places -> realtime",
"plugins -> accommodations",
"plugins -> addons",
"plugins -> assignments",
"plugins -> atlas",
"plugins -> budget",
"plugins -> categories",
"plugins -> collab",
"plugins -> collections",
"plugins -> day-notes",
"plugins -> days",
"plugins -> files",
"plugins -> journey",
"plugins -> llm-parse",
"plugins -> notifications",
"plugins -> packing",
"plugins -> places",
"plugins -> realtime",
"plugins -> reservations",
"plugins -> todo",
"plugins -> trips",
"plugins -> vacay",
"realtime -> journey",
"realtime -> plugins",
"reservations -> accommodations",
"reservations -> assignments",
"reservations -> budget",
@@ -105,48 +63,17 @@
"reservations -> mcp-shared",
"reservations -> notifications",
"reservations -> realtime",
"todo -> addons",
"todo -> mcp-shared",
"todo -> realtime",
"transit -> days",
"transit -> mcp-shared",
"transit -> reservations",
"trip-members -> auth",
"trip-members -> budget",
"trip-members -> notifications",
"trip-members -> realtime",
"trip-members -> trips",
"trip-read-model -> accommodations",
"trip-read-model -> budget",
"trip-read-model -> collab",
"trip-read-model -> days",
"trip-read-model -> files",
"trip-read-model -> packing",
"trip-read-model -> places",
"trip-read-model -> reservations",
"trip-read-model -> todo",
"trip-read-model -> trip-members",
"trip-read-model -> trips",
"trips -> accommodations",
"trips -> addons",
"trips -> budget",
"trips -> calendar",
"trips -> collab",
"trips -> days",
"trips -> files",
"trips -> mcp-shared",
"trips -> packing",
"trips -> places",
"trips -> realtime",
"trips -> reservations",
"trips -> todo",
"trips -> trip-members",
"trips -> trip-read-model",
"trips -> vacay",
"vacay -> addons",
"vacay -> auth",
"vacay -> notifications",
"vacay -> realtime"
"vacay -> auth"
],
"sharedImportsDomain": [
"nest/common/idempotency-cleanup.job.ts -> nest/audit/audit-log.logger.ts",
@@ -201,7 +128,6 @@
"plugins -> maps/maps.helpers.ts",
"plugins -> notifications/channel-registry.ts",
"plugins -> notifications/notification-events.ts",
"realtime -> plugins/install/host-compat.ts",
"receipt-scan -> llm-parse/image-input.ts",
"reservation-import -> integrations/airtrail.dto.ts",
"reservation-import -> llm-parse/image-input.ts",
+1
View File
@@ -1,5 +1,6 @@
export { readEnv, validateEnvAtBoot } from './env';
export { getAppUrl, getMcpSafeUrl } from './app-url';
export { runningVersion } from './running-version';
export type { AppEnv, RawEnv } from './env';
export {
deriveAll,
+11
View File
@@ -0,0 +1,11 @@
import { readEnv } from './env';
/**
* The running TREK version: the image's VERSION file or APP_VERSION (both behind
* `readEnv().app.appVersion`), else server/package.json. The websocket welcome
* frame and the plugin host-compatibility checks both announce it, so it lives
* here rather than inside either domain.
*/
export function runningVersion(): string {
return readEnv().app.appVersion || (require('../../package.json') as { version: string }).version;
}
@@ -1,5 +1,5 @@
import semver from 'semver';
import { readEnv } from '../../../app-config';
import { readEnv, runningVersion } from '../../../app-config';
/**
* Host-version compatibility for plugins (#plugins). A manifest declares the TREK
@@ -12,7 +12,7 @@ import { readEnv } from '../../../app-config';
/** The running TREK version (same source as the rest of the app). */
export function hostVersion(): string {
return readEnv().app.appVersion || (require('../../../../package.json') as { version: string }).version;
return runningVersion();
}
let warnedUnparseable = false;
+2 -2
View File
@@ -31,8 +31,8 @@ import {
type TrekWebSocket,
} from './ws-state';
import { JourneyDomainService } from '../journey/journey-domain.service';
import { hostVersion } from '../plugins/install/host-compat';
import { readAppSetting } from '../common/app-settings.registry';
import { runningVersion } from '../../app-config';
const HEARTBEAT_INTERVAL = 30_000;
@@ -159,7 +159,7 @@ export class RealtimeGateway
// The version lets a client that stayed open across a deploy notice it
// runs the previous build: a deploy restarts the server, so every open
// client reconnects and reads this again.
socket.send(JSON.stringify({ type: 'welcome', socketId: sid, version: hostVersion() }));
socket.send(JSON.stringify({ type: 'welcome', socketId: sid, version: runningVersion() }));
socket.on('pong', () => { socket.isAlive = true; });
} catch (err) {
logError(`ws handshake failed: ${err instanceof Error ? err.message : String(err)}`);
@@ -0,0 +1,25 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { runningVersion } from '../../../src/app-config';
import { hostVersion } from '../../../src/nest/plugins/install/host-compat';
import pkg from '../../../package.json';
afterEach(() => {
vi.unstubAllEnvs();
});
describe('runningVersion', () => {
it('announces APP_VERSION when it is set', () => {
vi.stubEnv('APP_VERSION', '9.8.7');
expect(runningVersion()).toBe('9.8.7');
});
it('falls back to the server package version', () => {
vi.stubEnv('APP_VERSION', '');
expect(runningVersion()).toBe(pkg.version);
});
it('is what the plugin host-compatibility checks call the host version', () => {
vi.stubEnv('APP_VERSION', '1.2.3');
expect(hostVersion()).toBe(runningVersion());
});
});