Skip to content

armgit / SOMA

Public Imported from GitHub
0

Desktop app for designing parametric 3D models in CadQuery together with the coding agent of your choice

App: Karte „Updates“ auf der Startseite (E98)

Kai-Jungsthoefel1a072e13542c
diff --git a/app/resources/skills/soma-app.md b/app/resources/skills/soma-app.md
index 011e3ce..9153d10 100644
--- a/app/resources/skills/soma-app.md
+++ b/app/resources/skills/soma-app.md
@@ -54,6 +54,10 @@ The logo at the top left opens the start page.
7. **Settings**: viewer, shortcuts, skills, storage and version.
8. **Back to the model**: returns to the open model.
+Below the agents, a card shows whether a newer version of SOMA is available on GitHub. **Open release page** opens the
+download page in your browser; SOMA downloads and installs nothing by itself. Settings > About > **Check for new
+versions** turns the check off.
+
**Start tutorial** opens a new example model called "Tutorial" and walks you through the window in ten steps: starting
the agent, the code, clicking a part, measuring, marking up, parameters, history, saving and export, and help. An orange
frame shows where to look, and you can try everything right away. Back, Skip and Next move through the steps, Esc ends
@@ -180,7 +184,7 @@ Reference parts (for example an imported circuit board) are not included in "All
2. **Shortcuts**: all keys and mouse actions.
3. **Skills**: edit the built-in skills or write your own. They are available in every model.
4. **Storage**: how much space SOMA's data takes, and clearing the preview cache.
-5. **About**: versions, components and the agents found.
+5. **About**: versions, components and the agents found, and whether the start page checks GitHub for new versions.
## When something goes wrong
diff --git a/app/src/main/main.ts b/app/src/main/main.ts
index 8b37b0a..41f4fd8 100644
--- a/app/src/main/main.ts
+++ b/app/src/main/main.ts
@@ -13,6 +13,7 @@ import { terminalEnv } from './terminals';
import { readHelp, readHelpImage } from './help';
import { adoptLoginShellPath, appIcon, editBackupsDir, helpDir, libraryBackupsDir, skillDirs, skillsDir, thumbnailsDir, userSkillsDir } from './paths';
import { readSettings, writeSettings } from './settings';
+import { checkUpdate } from './updates';
import { areaDir, clearPreviews, isStorageArea, storageStats } from './storage';
import { checkLibraryText, createLibrarySkill, importLibrarySkills, libraryState, ownFile, readLibrarySkill, removeLibrarySkill, renameOldSkillFiles, saveLibrarySkill } from './skilllibrary';
import { isSkillId, isSkillMode, librarySkill } from './skills';
@@ -251,6 +252,8 @@ function registerIpc(ctl: ProjectController): void {
return true;
});
ipcMain.handle('about:info', () => aboutInfo(agents));
+ // Nur wenn die Einstellung es erlaubt: Ausgeschaltet geht keine Anfrage ins Netz
+ ipcMain.handle('updates:check', () => checkUpdate(readSettings().settings.start.updateCheck));
ipcMain.handle('about:copy', async (): Promise<FileOpResult> => {
const text = aboutText(await aboutInfo(agents));
if (process.env.SOMA_TEST === '1') testClipboard = text; else clipboard.writeText(text);
diff --git a/app/src/main/updates.ts b/app/src/main/updates.ts
new file mode 100644
index 0000000..e9376e1
--- /dev/null
+++ b/app/src/main/updates.ts
@@ -0,0 +1,68 @@
+import { net } from 'electron';
+import type { UpdateInfo } from '../shared/types';
+import { SOMA_VERSION, isNewerVersion, parseVersion } from '../shared/version';
+
+/**
+ * Neue Version auf GitHub (Startseite): fragt die Liste unter Releases ab und nimmt die höchste Versionsnummer. Nicht
+ * `releases/latest`: Das übergeht Vorabversionen, und die CI veröffentlicht alle 0.x als „Pre-release“. Entwürfe zählen
+ * nicht (ohne Anmeldung ohnehin unsichtbar). Nur lesen und anzeigen, die
+ * App lädt und installiert nichts (E28). Über net.fetch, damit der Proxy des Systems gilt. Einmal je Sitzung: Ohne Anmeldung
+ * erlaubt GitHub 60 Anfragen pro Stunde. Ein Fehler wird höchstens einmal pro Minute wiederholt.
+ * `SOMA_UPDATE_URL` ersetzt die Adresse (Tests). Im Test ohne sie gibt es keine Anfrage ins Netz.
+ */
+
+const REPO = 'https://github.com/Kai-Jungsthoefel/SOMA';
+const API = 'https://api.github.com/repos/Kai-Jungsthoefel/SOMA/releases?per_page=30';
+const RELEASES = `${REPO}/releases`;
+const RETRY_MS = 60_000;
+
+let done: UpdateInfo | null = null;
+let running: Promise<UpdateInfo> | null = null;
+let failedAt = 0;
+let lastError: UpdateInfo | null = null;
+
+/** `enabled`: Einstellung „updateCheck“. Ausgeschaltet geht keine Anfrage ins Netz. */
+export async function checkUpdate(enabled: boolean): Promise<UpdateInfo> {
+ if (!enabled) return { state: 'skipped', current: SOMA_VERSION, url: RELEASES };
+ if (done) return done;
+ if (running) return running;
+ if (lastError && Date.now() - failedAt < RETRY_MS) return lastError;
+ running = fetchLatest().finally(() => { running = null; });
+ const r = await running;
+ if (r.state === 'error') { lastError = r; failedAt = Date.now(); } else done = r;
+ return r;
+}
+
+async function fetchLatest(): Promise<UpdateInfo> {
+ const base = { current: SOMA_VERSION, url: RELEASES };
+ const url = process.env.SOMA_UPDATE_URL || (process.env.SOMA_TEST === '1' ? '' : API);
+ if (!url) return { ...base, state: 'skipped' };
+ let res: Response;
+ try {
+ res = await net.fetch(url, { headers: { Accept: 'application/vnd.github+json', 'User-Agent': `SOMA/${SOMA_VERSION}` }, signal: AbortSignal.timeout(10_000), cache: 'no-store' });
+ } catch (e) {
+ const msg = e instanceof Error ? e.message : String(e);
+ return { ...base, state: 'error', error: /abort|timeout/i.test(msg) ? 'GitHub did not answer in time.' : `GitHub could not be reached (${msg}).` };
+ }
+ // 404: Projekt nicht (mehr) öffentlich, 403/429: Grenze der Anfragen erreicht
+ if (res.status === 404) return { ...base, state: 'error', error: 'GitHub does not find the project.' };
+ if (res.status === 403 || res.status === 429) return { ...base, state: 'error', error: 'GitHub limits requests at the moment. Try again later.' };
+ if (!res.ok) return { ...base, state: 'error', error: `GitHub answered with status ${res.status}.` };
+ let body: unknown;
+ try { body = await res.json(); } catch { return { ...base, state: 'error', error: 'GitHub sent an answer SOMA cannot read.' }; }
+ // Die Antwort ist nicht vertrauenswürdig: nur lesbare Nummern und Links auf die Seite des Projekts übernehmen
+ if (!Array.isArray(body)) return { ...base, state: 'error', error: 'GitHub sent an answer SOMA cannot read.' };
+ const list = body.filter((x): x is Record<string, unknown> => !!x && typeof x === 'object' && (x as Record<string, unknown>).draft !== true);
+ if (!list.length) return { ...base, state: 'error', error: 'GitHub lists no release yet.' };
+ const tagOf = (x: Record<string, unknown>) => (typeof x.tag_name === 'string' ? x.tag_name.trim() : '');
+ let b: Record<string, unknown> | null = null;
+ for (const x of list) {
+ const v = tagOf(x).replace(/^v/i, '');
+ if (parseVersion(v) && (!b || isNewerVersion(v, tagOf(b).replace(/^v/i, '')))) b = x;
+ }
+ if (!b) return { ...base, state: 'error', error: `No release has a version SOMA can read (${tagOf(list[0]).slice(0, 40) || 'none'}).` };
+ const latest = tagOf(b).replace(/^v/i, '');
+ const page = typeof b.html_url === 'string' && b.html_url.startsWith(`${RELEASES}/`) ? b.html_url : RELEASES;
+ const published = typeof b.published_at === 'string' && !Number.isNaN(Date.parse(b.published_at)) ? b.published_at : undefined;
+ return { ...base, state: isNewerVersion(latest) ? 'newer' : 'current', latest, url: page, ...(published ? { published } : {}) };
+}
diff --git a/app/src/preload/preload.ts b/app/src/preload/preload.ts
index d665488..9dd3a90 100644
--- a/app/src/preload/preload.ts
+++ b/app/src/preload/preload.ts
@@ -112,6 +112,9 @@ const api: SomaApi = {
info: () => ipcRenderer.invoke('about:info'),
copy: () => ipcRenderer.invoke('about:copy'),
},
+ updates: {
+ check: () => ipcRenderer.invoke('updates:check'),
+ },
anim: {
list: () => ipcRenderer.invoke('anim:list'),
build: (file) => ipcRenderer.invoke('anim:build', file ?? null),
diff --git a/app/src/renderer/index.html b/app/src/renderer/index.html
index ce2ed84..929633f 100644
--- a/app/src/renderer/index.html
+++ b/app/src/renderer/index.html
@@ -521,6 +521,8 @@
<div class="ph"><b>Agents on this computer</b><span class="c3 small">You bring your own agent and install it yourself.</span></div>
<div id="start-agents"></div>
</section>
+ <!-- Neue Version unter GitHub Releases (updates.ts). Inhalt baut main.ts, ausgeschaltet in Settings › About bleibt die Karte weg -->
+ <section id="start-update" class="panel-card update" aria-label="Updates" hidden></section>
<section id="start-note" class="panel-card note">
<span class="note-ico"><i data-icon="info" data-size="18"></i></span>
<div class="note-text"><b>Good to know</b>
diff --git a/app/src/renderer/main.ts b/app/src/renderer/main.ts
index 6a6f8e0..8923483 100644
--- a/app/src/renderer/main.ts
+++ b/app/src/renderer/main.ts
@@ -1,6 +1,6 @@
import { affectsBuild } from '../shared/editable';
import { DEFAULT_SETTINGS, type SettingsPatch, type SettingsResult, type SettingsState } from '../shared/settings';
-import type { AgentInfo, AnimEntry, BuildStatus, DrawingEntry, DrawingList, ExportResult, FileNode, ImportResult, ModelMap, PartMap, PreviewResult, ProjectInfo, ProjectListEntry, ResultEntry, SaveState } from '../shared/types';
+import type { AgentInfo, AnimEntry, BuildStatus, DrawingEntry, DrawingList, ExportResult, FileNode, ImportResult, ModelMap, PartMap, PreviewResult, ProjectInfo, ProjectListEntry, ResultEntry, SaveState, UpdateInfo } from '../shared/types';
import { AnalysisPanel } from './analysispanel';
import { AnimPanel, animKey, videoKey } from './animpanel';
import { SOMA_VERSION } from '../shared/version';
@@ -250,6 +250,8 @@ const aboutPage = new AboutPage($('st-about'), {
api: api.about, toast,
openUrl: (url) => void api.openUrl(url).then((r) => { if (!r.ok) toast(r.error ?? `${url} could not be opened.`, 'error'); }),
openFolder: (area) => void api.storage.open(area).then((r) => { if (!r.ok) toast(`The folder could not be opened: ${r.error ?? 'unknown error'}`, 'error'); }),
+ updateCheck: () => appSettings.settings.start.updateCheck,
+ setUpdateCheck: async (on) => { const r = await changeSettings({ start: { updateCheck: on } }); if (!$('start').hidden) void renderUpdate(); return r; },
});
// Einstellungen (E78, E81): Reiter Viewer, Skills, Speicher und Info, auch von der Startseite aus. Änderungen an den
@@ -1568,6 +1570,7 @@ async function showStart(on: boolean): Promise<void> {
$('btn-start-close').hidden = !project;
$('start-note').hidden = store.get('soma.noteSeen') === '1';
renderTourCard();
+ void renderUpdate();
let list: ProjectListEntry[] = [];
try { list = await api.project.list(); } catch { /* ohne Liste */ }
list.sort((a, b) => b.modified - a.modified);
@@ -1599,6 +1602,39 @@ async function showStart(on: boolean): Promise<void> {
$('btn-start-close').addEventListener('click', () => showStart(false));
$('start-new').addEventListener('click', () => { void doNew(); showStart(false); });
$('start-open').addEventListener('click', () => { void doOpen().then((ok) => { if (ok) showStart(false); }); });
+/**
+ * Karte „Updates“: neueste Version unter GitHub Releases (updates.ts, einmal je Sitzung). Der Knopf öffnet die Seite im
+ * Browser, laden und installieren tut der Nutzer selbst. Ausgeschaltet (Settings › About) oder im Test ohne Adresse: keine Karte.
+ */
+let updateInfo: UpdateInfo | null = null;
+async function renderUpdate(): Promise<void> {
+ const card = $('start-update');
+ if (!appSettings.settings.start.updateCheck) { card.hidden = true; return; }
+ if (!updateInfo) {
+ card.hidden = false;
+ card.className = 'panel-card update checking';
+ card.replaceChildren(el('span', { className: 'up-ico' }, icon('refresh', 18)),
+ el('div', { className: 'up-text' }, el('b', { textContent: 'Updates' }), el('span', { className: 'c2', textContent: 'Checking GitHub for a new version …' })));
+ }
+ try { updateInfo = await api.updates.check(); } catch (e) {
+ updateInfo = { state: 'error', current: SOMA_VERSION, url: RELEASES_URL, error: e instanceof Error ? e.message : String(e) };
+ }
+ const u = updateInfo;
+ if (u.state === 'skipped') { card.hidden = true; return; }
+ const when = u.published ? ` on ${new Date(u.published).toLocaleDateString('en-GB', { day: 'numeric', month: 'short', year: 'numeric' })}` : '';
+ const [ico, title, text, label] = u.state === 'newer'
+ ? ['refresh', `SOMA ${u.latest} is available`, `You have ${u.current}. The new version was released${when}. Download it from the release page and install it, your models stay.`, 'Open release page']
+ : u.state === 'current'
+ ? ['okcirc', 'SOMA is up to date', `${u.current} is the latest release on GitHub.`, 'All releases']
+ : ['alert', 'Updates', `Could not check for a new version. ${u.error ?? ''}`.trim(), 'Open releases'];
+ const btn = el('button', { id: 'btn-start-update', className: `btn sm${u.state === 'newer' ? ' acc' : ''}`, title: u.url }, el('span', { textContent: label }), icon('openext', 13, 1.9));
+ btn.addEventListener('click', () => void api.openUrl(u.url).then((r) => { if (!r.ok) toast(r.error ?? `${u.url} could not be opened.`, 'error'); }));
+ card.hidden = false;
+ card.className = `panel-card update ${u.state}`;
+ card.replaceChildren(el('span', { className: 'up-ico' }, icon(ico, 18)),
+ el('div', { className: 'up-text' }, el('b', { textContent: title }), el('span', { className: 'c2', textContent: text }), btn));
+}
+const RELEASES_URL = 'https://github.com/Kai-Jungsthoefel/SOMA/releases';
$('btn-note-ok').addEventListener('click', () => { store.set('soma.noteSeen', '1'); $('start-note').hidden = true; });
// ---- Ereignisse vom Hauptprozess --------------------------------------------------------------------------------
diff --git a/app/src/renderer/settingspages.ts b/app/src/renderer/settingspages.ts
index 17d6814..a57156b 100644
--- a/app/src/renderer/settingspages.ts
+++ b/app/src/renderer/settingspages.ts
@@ -231,7 +231,11 @@ export class StoragePage implements SettingsPage {
// ---- Info -----------------------------------------------------------------------------------------------------------
-interface AboutDeps { api: SomaApi['about']; openUrl(url: string): void; openFolder(area: StorageArea): void; toast: Toast }
+interface AboutDeps {
+ api: SomaApi['about']; openUrl(url: string): void; openFolder(area: StorageArea): void; toast: Toast;
+ /** Einstellung „Check for new versions“ (Karte auf der Startseite). */
+ updateCheck(): boolean; setUpdateCheck(on: boolean): Promise<SettingsResult>;
+}
const REPO = 'https://github.com/Kai-Jungsthoefel/SOMA';
@@ -257,6 +261,12 @@ export class AboutPage implements SettingsPage {
this.deps.toast(r.ok ? 'System info copied. Paste it into a bug report or a message.' : `Could not copy: ${r.error ?? 'unknown error'}`, r.ok ? 'ok' : 'error');
}
+ private async setUpdateCheck(on: boolean): Promise<void> {
+ const r = await this.deps.setUpdateCheck(on).catch((e) => ({ ok: false, error: errText(e) }));
+ if (!r.ok) this.deps.toast(r.error ?? 'The setting could not be saved.', 'error');
+ this.render();
+ }
+
private link(label: string, url: string, title: string): HTMLElement {
const b = el('button', { className: 'btn sm', title }, el('span', { textContent: label }), icon('openext', 13, 1.9));
b.addEventListener('click', () => this.deps.openUrl(url));
@@ -288,6 +298,8 @@ export class AboutPage implements SettingsPage {
'SOMA is free software under the GNU GPL, version 3 or later. The SOMA Model Exception makes sure that what you design belongs to you: your models, their files and everything SOMA creates from them.'),
el('div', { className: 'st-actions' }, this.link('License', `${REPO}/blob/main/LICENSE`, 'GNU General Public License, version 3'), this.link('Model Exception', `${REPO}/blob/main/MODEL-EXCEPTION.md`, 'Additional permission for your models')),
];
+ kids.push(group('Updates', field('Check for new versions', 'The start page asks GitHub once per session whether a newer release exists. SOMA downloads and installs nothing by itself.',
+ toggle('st-update', this.deps.updateCheck(), 'Check for new versions', (on) => void this.setUpdateCheck(on)))));
if (this.error) kids.push(el('div', { className: 'st-problem' }, icon('alert', 14, 2), el('span', { textContent: `The information could not be collected: ${this.error}` })));
if (!a) {
kids.push(el('div', { className: 'st-wait', textContent: this.loading ? 'Collecting versions …' : '' }));
diff --git a/app/src/renderer/style.css b/app/src/renderer/style.css
index 7abe5c2..b4b0d68 100644
--- a/app/src/renderer/style.css
+++ b/app/src/renderer/style.css
@@ -987,6 +987,13 @@ code { font-family:var(--mono); font-size:.95em; }
.agrow .ok { color:var(--ok); display:flex; } .agrow .no { color:var(--tx3); display:flex; }
.agrow div { display:flex; flex-direction:column; }
.agrow div span { font-size:12px; color:var(--tx3); }
+/* Neue Version (Startseite): grün bei aktuellem Stand, orange wenn es eine neuere gibt */
+.update { padding:16px; display:flex; gap:12px; }
+.update .up-ico { display:flex; color:var(--tx3); }
+.update.newer { border-color:var(--acc-line); }
+.update.newer .up-ico { color:var(--acc); } .update.current .up-ico { color:var(--ok); }
+.update .up-text { display:flex; flex-direction:column; gap:8px; font-size:12.5px; min-width:0; }
+.update .up-text .btn { align-self:flex-start; }
.note { padding:16px; display:flex; gap:12px; }
.note-ico { color:var(--vio); display:flex; }
.note-text { display:flex; flex-direction:column; gap:8px; font-size:12.5px; }
diff --git a/app/src/shared/settings.ts b/app/src/shared/settings.ts
index a7cfa17..a1fa0ff 100644
--- a/app/src/shared/settings.ts
+++ b/app/src/shared/settings.ts
@@ -22,8 +22,8 @@ export interface ViewerPrefs {
/** Nachkommastellen der Messwerte in der Oberfläche. Der Text für den Agenten hat immer drei. */
decimals: number;
}
-/** Startseite (E94): Karte „New to SOMA?“ mit dem Tutorial. „Got it“ blendet sie aus. */
-export interface StartPrefs { tutorialCard: boolean }
+/** Startseite (E94): Karte „New to SOMA?“ mit dem Tutorial. „Got it“ blendet sie aus. `updateCheck`: auf GitHub nach einer neuen Version fragen. */
+export interface StartPrefs { tutorialCard: boolean; updateCheck: boolean }
export interface AppSettings { viewer: ViewerPrefs; start: StartPrefs }
/** Änderung aus dem Renderer: nur die Werte, die sich ändern sollen. */
export interface SettingsPatch { viewer?: Partial<ViewerPrefs>; start?: Partial<StartPrefs> }
@@ -34,7 +34,7 @@ export interface SettingsResult extends SettingsState { ok: boolean; error?: str
export const DECIMALS = { min: 0, max: 4 };
export const DEFAULT_SETTINGS: AppSettings = {
viewer: { navigation: 'soma', invertZoom: false, projection: 'perspective', edges: true, wireframe: false, transparent: false, decimals: 2 },
- start: { tutorialCard: true },
+ start: { tutorialCard: true, updateCheck: true },
};
const NAV = (spec: string): NavBinding[] => spec.split(',').map((s) => {
@@ -91,7 +91,7 @@ const isBool = (v: unknown): v is boolean => typeof v === 'boolean';
const VIEWER_CHECKS: { [K in keyof ViewerPrefs]: (v: unknown) => boolean } = {
navigation: isNav, invertZoom: isBool, projection: isProjection, edges: isBool, wireframe: isBool, transparent: isBool, decimals: isDecimals,
};
-const START_CHECKS: { [K in keyof StartPrefs]: (v: unknown) => boolean } = { tutorialCard: isBool };
+const START_CHECKS: { [K in keyof StartPrefs]: (v: unknown) => boolean } = { tutorialCard: isBool, updateCheck: isBool };
/** Bereiche der Einstellungen mit der Prüfung je Wert. */
const SECTIONS: Record<keyof AppSettings, Record<string, (v: unknown) => boolean>> = { viewer: VIEWER_CHECKS, start: START_CHECKS };
const isObj = (v: unknown): v is Record<string, unknown> => !!v && typeof v === 'object' && !Array.isArray(v);
diff --git a/app/src/shared/types.ts b/app/src/shared/types.ts
index c264819..ddcb2cd 100644
--- a/app/src/shared/types.ts
+++ b/app/src/shared/types.ts
@@ -245,6 +245,15 @@ export interface StorageStats { dir: string; total: number; areas: StorageEntry[
/** Vorschau-Cache leeren. `kept`: Die Vorschauen des offenen Modells blieben. `canceled`: Rückfrage abgelehnt. */
export interface StorageClear { ok: boolean; canceled?: boolean; freed?: number; kept?: boolean; error?: string; stats?: StorageStats }
+/**
+ * Neue Version unter GitHub Releases (Startseite). `skipped`: nicht gefragt (Test ohne Adresse). `url`: Seite der neuesten
+ * Veröffentlichung, sonst die Liste aller.
+ */
+export interface UpdateInfo {
+ state: 'newer' | 'current' | 'error' | 'skipped';
+ current: string; latest?: string; url: string; published?: string; error?: string;
+}
+
/** Eine mitgelieferte Komponente: npm-Paket der App oder Python-Paket, das soma voraussetzt. Lizenz wie in ihren Metadaten. */
export interface ComponentInfo { name: string; version: string; license: string }
/** Angaben für „About“ in den Einstellungen (E81). */
@@ -550,6 +559,8 @@ export interface SomaApi {
/** Der Viewer bekam keinen WebGL-Kontext. true: Die App startet mit Software-Rendering neu (nur Linux, einmal). */
gpu: { webglFailed(): Promise<boolean> };
about: { info(): Promise<AboutInfo>; copy(): Promise<FileOpResult> };
+ /** Neueste Version auf GitHub, einmal je Sitzung gefragt. */
+ updates: { check(): Promise<UpdateInfo> };
/** Animationen (E58): Liste aus .soma/anim/index.json, bauen über `soma anim build`. */
anim: {
list(): Promise<AnimList>;
diff --git a/app/test/updates.mjs b/app/test/updates.mjs
new file mode 100644
index 0000000..e03c067
--- /dev/null
+++ b/app/test/updates.mjs
@@ -0,0 +1,103 @@
+// Test der Karte „Updates“ auf der Startseite: Ein lokaler Server spielt die GitHub-API (SOMA_UPDATE_URL). Neuere Version mit
+// Knopf zur Release-Seite, aktueller Stand, Fehler von GitHub, fremder Link in der Antwort, Ausschalten unter Settings › About
+// (danach keine Anfrage mehr). Aufruf: npm run test:updates (baut vorher).
+import fs from 'node:fs';
+import http from 'node:http';
+import path from 'node:path';
+import { APP, checker, cleanup, sleep, startApp } from './harness.mjs';
+
+const t = checker();
+const { check } = t;
+const VERSION = JSON.parse(fs.readFileSync(path.join(APP, 'package.json'), 'utf8')).version;
+const RELEASES = 'https://github.com/Kai-Jungsthoefel/SOMA/releases';
+
+let answer = { status: 200, body: {} };
+let requests = 0;
+const srv = http.createServer((req, res) => {
+ requests++;
+ res.writeHead(answer.status, { 'Content-Type': 'application/json' });
+ res.end(JSON.stringify(answer.body));
+});
+await new Promise((r) => srv.listen(0, '127.0.0.1', r));
+const URL = `http://127.0.0.1:${srv.address().port}/releases`;
+
+let app = null;
+/** App mit der Antwort `a` starten, Startseite zeigen und warten, bis die Karte fertig ist. */
+async function startWith(a, name) {
+ answer = a;
+ app = await startApp({ name: `updates-${name}`, env: { SOMA_UPDATE_URL: URL } });
+ await app.waitFor('App bereit', () => !!window.__t && !!window.__t.project(), 90000);
+ await app.ev(() => window.__t.showStart(true));
+ await app.waitFor('Karte Updates', () => { const c = document.getElementById('start-update'); return !c.hidden && !c.classList.contains('checking'); }, 20000);
+ return app.ev(() => {
+ const c = document.getElementById('start-update');
+ const b = document.getElementById('btn-start-update');
+ return { cls: c.className, text: c.innerText, button: b?.textContent.trim(), url: b?.title };
+ });
+}
+async function stop() { if (app) { await app.stop(); cleanup(app.ud); app = null; } }
+
+try {
+ // ---- 1) Neuere Version --------------------------------------------------------------------------------------------
+ const newerUrl = `${RELEASES}/tag/v99.1.0`;
+ let c = await startWith({ status: 200, body: [
+ { tag_name: 'v99.2.0', draft: true, html_url: `${RELEASES}/tag/v99.2.0` },
+ { tag_name: 'v0.1.0', html_url: `${RELEASES}/tag/v0.1.0` },
+ { tag_name: 'v99.1.0', prerelease: true, html_url: newerUrl, published_at: '2026-10-01T10:00:00Z' },
+ { tag_name: 'nightly' },
+ ] }, 'newer');
+ check('Neuere Version (höchste Nummer, Vorabversion zählt, Entwurf nicht): Karte orange mit Nummer, eigener und Datum', c.cls.includes('newer') && c.text.includes('SOMA 99.1.0 is available') && c.text.includes(`You have ${VERSION}`) && c.text.includes('1 Oct 2026'), c.text);
+ check('Knopf führt zur Seite der Veröffentlichung', c.button === 'Open release page' && c.url === newerUrl, `${c.button} ${c.url}`);
+ if (process.env.SMOKE_SHOTS) {
+ fs.mkdirSync(path.join(APP, 'test', 'shots'), { recursive: true });
+ await sleep(900);
+ await app.screenshot(path.join(APP, 'test', 'shots', 'updates-newer.png')).catch((e) => console.log('Screenshot:', e.message));
+ }
+ const opened = await app.ev(() => { document.getElementById('btn-start-update').click(); return true; });
+ check('Knopf lässt sich drücken', opened);
+ const before = requests;
+ await app.ev(() => window.__t.showStart(false));
+ await app.ev(() => window.__t.showStart(true));
+ await sleep(500);
+ check('Einmal je Sitzung: erneutes Öffnen der Startseite fragt nicht noch einmal', requests === before && requests === 1, `${requests} Anfragen`);
+
+ // Ausschalten unter Settings › About: Karte weg, settings.json, keine weitere Anfrage
+ await app.ev(() => window.__t.settingsShow('about'));
+ await app.waitFor('Schalter', () => !!document.getElementById('st-update'), 20000);
+ check('Schalter unter About ist an', await app.ev(() => document.getElementById('st-update').checked));
+ await app.ev(() => { const s = document.getElementById('st-update'); s.checked = false; s.dispatchEvent(new Event('change')); });
+ await app.waitFor('Einstellung aus', () => window.__t.appSettings().settings.start.updateCheck === false, 10000);
+ await app.ev(() => window.__t.closeSettings());
+ await sleep(300);
+ const file = JSON.parse(fs.readFileSync(path.join(app.ud, 'settings.json'), 'utf8'));
+ check('Ausgeschaltet: Karte weg, in settings.json gespeichert', await app.ev(() => document.getElementById('start-update').hidden) && file.start?.updateCheck === false);
+ await app.ev(() => window.__t.showStart(true));
+ await sleep(500);
+ check('Ausgeschaltet: keine Anfrage', requests === 1 && await app.ev(() => document.getElementById('start-update').hidden), `${requests} Anfragen`);
+ const relevant = app.page.errors.filter((e) => !/favicon/i.test(e));
+ check('Keine Konsolenfehler im Renderer', relevant.length === 0, relevant.slice(0, 2).join(' | ').slice(0, 120));
+ await stop();
+
+ // ---- 2) Aktueller Stand, fremder Link in der Antwort ----------------------------------------------------------------
+ c = await startWith({ status: 200, body: [{ tag_name: `v${VERSION}`, prerelease: true, html_url: 'https://example.com/evil' }, { tag_name: 'v0.0.1' }] }, 'current');
+ check('Aktueller Stand: grün, „up to date“', c.cls.includes('current') && c.text.includes('SOMA is up to date') && c.text.includes(VERSION), c.text);
+ check('Fremder Link wird nicht übernommen, Knopf zur Liste der Releases', c.button === 'All releases' && c.url === RELEASES, `${c.button} ${c.url}`);
+ await stop();
+
+ // ---- 3) Fehler von GitHub -----------------------------------------------------------------------------------------
+ c = await startWith({ status: 403, body: { message: 'rate limit' } }, 'error');
+ check('Grenze der Anfragen: Meldung statt Absturz, Knopf zu den Releases', c.cls.includes('error') && c.text.includes('limits requests') && c.url === RELEASES, c.text);
+ await stop();
+ c = await startWith({ status: 200, body: [{ tag_name: 'nightly' }] }, 'badtag');
+ check('Unlesbare Versionsnummer wird gemeldet', c.cls.includes('error') && c.text.includes('nightly'), c.text);
+ await stop();
+ c = await startWith({ status: 200, body: [] }, 'empty');
+ check('Keine Veröffentlichung: Meldung', c.cls.includes('error') && c.text.includes('no release yet'), c.text);
+} catch (e) {
+ console.log('ABBRUCH:', e.message);
+ t.fail();
+}
+await stop();
+srv.close();
+console.log(t.fails ? `\n${t.fails} Prüfung(en) fehlgeschlagen` : '\nALLE PRÜFUNGEN BESTANDEN');
+process.exit(t.fails ? 1 : 0);