Merge branch 'worktree-agent-acc3f1d43a77011ac' into claude/practical-noether-1hb2s1
This commit is contained in:
12 files changed
+421
-23
No files matched your search
@@ -0,0 +1,44 @@
|
||||
// [268] Electron: externe Links im System-Browser, keine Kindfenster, keine fremde Navigation (reine Entscheide).
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createRequire } from "node:module";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
|
||||
const links = createRequire(import.meta.url)("../../scripts/electron-links.cjs");
|
||||
const ORIGINS = ["dossier://app", "http://localhost:5187"];
|
||||
|
||||
describe("[268] Electron-Links", () => {
|
||||
it("window.open: nie ein Kindfenster; https/mailto gehen in den System-Browser", () => {
|
||||
expect(links.windowOpenDecision("https://git.openbureau.ch/karim/dossier/issues/new")).toEqual({
|
||||
action: "deny",
|
||||
external: "https://git.openbureau.ch/karim/dossier/issues/new",
|
||||
});
|
||||
expect(links.windowOpenDecision("mailto:a@b.ch").external).toBe("mailto:a@b.ch");
|
||||
for (const bad of ["http://example.org", "file:///etc/passwd", "javascript:alert(1)", "dossier://app/x", "data:text/html,x", "", "kaputt"]) {
|
||||
expect(links.windowOpenDecision(bad), bad).toEqual({ action: "deny", external: null });
|
||||
}
|
||||
});
|
||||
|
||||
it("Navigation: nur App-Ursprung und Dev-Server, fremde https gehen extern", () => {
|
||||
expect(links.navigationDecision("dossier://app/index.html", ORIGINS).allow).toBe(true);
|
||||
expect(links.navigationDecision("http://localhost:5187/?x=1", ORIGINS).allow).toBe(true);
|
||||
expect(links.navigationDecision("https://example.org/", ORIGINS)).toEqual({ allow: false, external: "https://example.org/" });
|
||||
expect(links.navigationDecision("http://localhost:5188/", ORIGINS)).toEqual({ allow: false, external: null });
|
||||
expect(links.navigationDecision("file:///etc/passwd", ORIGINS)).toEqual({ allow: false, external: null });
|
||||
expect(links.navigationDecision("dossier://evil/", ORIGINS).allow).toBe(false);
|
||||
});
|
||||
|
||||
it("CSP nur für den App-Ursprung", () => {
|
||||
expect(links.shouldSetCsp("dossier://app/assets/x.js", ORIGINS)).toBe(true);
|
||||
expect(links.shouldSetCsp("https://example.org/", ORIGINS)).toBe(false);
|
||||
expect(links.shouldSetCsp("devtools://devtools/x", ORIGINS)).toBe(false);
|
||||
});
|
||||
|
||||
it("Hauptprozess verdrahtet Handler, Navigation und Weiterleitung", () => {
|
||||
const main = readFileSync(join(__dirname, "..", "..", "scripts", "electron-main.cjs"), "utf8");
|
||||
expect(main).toMatch(/setWindowOpenHandler/);
|
||||
expect(main).toMatch(/"will-navigate"/);
|
||||
expect(main).toMatch(/"will-redirect"/);
|
||||
expect(main).toMatch(/shell\.openExternal/);
|
||||
});
|
||||
});
|
||||
@@ -113,6 +113,23 @@ export interface BackupOffer {
|
||||
lockOwned: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* [268] Datei-Zustand der Sitzung AUSSERHALB von React: Ein Sprachwechsel baut die App neu auf (`LanguageRoot`, [264]).
|
||||
* Mit `useRef` gingen dabei der zuletzt gespeicherte Stand (Rückfrage „Ungespeicherte Änderungen“ bei Neu/Öffnen/
|
||||
* Schliessen entfiel, Änderungen gingen ohne Rückfrage verloren), Pfad (Cmd+S fragte neu), Lock und Autosave-Stand
|
||||
* verloren, und die Autosave-Kopie der laufenden Sitzung erschien als „Ungesicherte Arbeit gefunden“.
|
||||
*/
|
||||
interface FileSession {
|
||||
openedProjectPathRef: { current: string | null };
|
||||
savePathRef: { current: string | null };
|
||||
projectLockOwnedRef: { current: boolean };
|
||||
lastSavedProjectRef: { current: Project };
|
||||
autosaveTracker: ReturnType<typeof createAutosaveTracker>;
|
||||
/** Kopie eines nie gespeicherten Projekts schon gesucht (einmal je Seitenladen). */
|
||||
recoveryOffered: boolean;
|
||||
}
|
||||
let fileSession: FileSession | null = null;
|
||||
|
||||
export function useProjectFileActions(
|
||||
setImportState: (next: ImportDialogState) => void,
|
||||
setExportSaveFormat: (format: ExportSaveFormat | null) => void,
|
||||
@@ -141,10 +158,19 @@ export function useProjectFileActions(
|
||||
const projectTemplateFileInputRef = useRef<HTMLInputElement>(null);
|
||||
// Pfad + Lock-Status der aktuell offenen .obp/.json-Datei (nur Tauri; sonst
|
||||
// bleibt beides null/false — Browser-Blob-Pfad hat keinen echten Pfad).
|
||||
const openedProjectPathRef = useRef<string | null>(null);
|
||||
// [268] Zustand der Sitzung, übersteht den Neuaufbau beim Sprachwechsel (s. `FileSession`).
|
||||
const session = (fileSession ??= {
|
||||
openedProjectPathRef: { current: null },
|
||||
savePathRef: { current: null },
|
||||
projectLockOwnedRef: { current: false },
|
||||
lastSavedProjectRef: { current: getState().project },
|
||||
autosaveTracker: createAutosaveTracker(),
|
||||
recoveryOffered: false,
|
||||
});
|
||||
const openedProjectPathRef = session.openedProjectPathRef;
|
||||
// Zielpfad für „Speichern" (Cmd/Ctrl+S): gesetzt beim Öffnen und nach „Speichern unter".
|
||||
const savePathRef = useRef<string | null>(null);
|
||||
const projectLockOwnedRef = useRef(false);
|
||||
const savePathRef = session.savePathRef;
|
||||
const projectLockOwnedRef = session.projectLockOwnedRef;
|
||||
// Konflikt-Zustand: Datei ist in einer anderen Instanz gesperrt → Dialog mit
|
||||
// „Schreibgeschützt öffnen"/„Trotzdem erzwingen"/„Abbrechen" (kein window.confirm!).
|
||||
const [lockConflict, setLockConflict] = useState<{
|
||||
@@ -159,7 +185,7 @@ export function useProjectFileActions(
|
||||
// JSON-Diff. Start = das beim allerersten Render aktive Projekt (Startzustand
|
||||
// gilt als "gespeichert", noch nichts zu verlieren).
|
||||
// [121] Das Projekt kommt beim Aufruf aus dem Store (`getState()`); App abonniert es nicht mehr.
|
||||
const lastSavedProjectRef = useRef(getState().project);
|
||||
const lastSavedProjectRef = session.lastSavedProjectRef;
|
||||
// Eine verworfene Aktion (Neu/Öffnen), die erst nach Bestätigung des
|
||||
// "Ungespeicherte Änderungen"-Dialogs ausgeführt wird — s. `guardDiscard`.
|
||||
const [pendingDiscard, setPendingDiscard] = useState<(() => void) | null>(null);
|
||||
@@ -189,7 +215,7 @@ export function useProjectFileActions(
|
||||
};
|
||||
|
||||
// ── Autosave + Wiederherstellen (s. state/autosave.ts) ─────────────────────
|
||||
const autosaveTracker = useRef(createAutosaveTracker()).current;
|
||||
const autosaveTracker = session.autosaveTracker;
|
||||
const [recovery, setRecovery] = useState<AutosaveRecovery | null>(null);
|
||||
// Kopie unter dem Schlüssel der Zieldatei (`savePathRef`: nach „Speichern unter" der NEUE Pfad). Misslingt das
|
||||
// Schreiben (Kontingent voll, kein IndexedDB), gilt der Stand wieder als ungesichert (nächster Versuch) und der
|
||||
@@ -250,7 +276,12 @@ export function useProjectFileActions(
|
||||
});
|
||||
};
|
||||
// Start: Kopie eines nie gespeicherten Projekts aus der letzten Sitzung?
|
||||
useEffect(() => offerRecovery(null), []);
|
||||
// [268] Nur beim ersten Aufbau je Seitenladen: nach einem Sprachwechsel wäre die Kopie die der laufenden Sitzung.
|
||||
useEffect(() => {
|
||||
if (session.recoveryOffered) return;
|
||||
session.recoveryOffered = true;
|
||||
offerRecovery(null);
|
||||
}, []);
|
||||
const onRecoverRestore = () => {
|
||||
if (!recovery) return;
|
||||
if (openProjectOrReport(recovery.text, notify)) setAnonymityProjectFileName(recovery.path); // [208] bleibt „ungespeichert" bis zum Speichern
|
||||
|
||||
@@ -51,4 +51,47 @@ describe("release-gitea-lib", () => {
|
||||
expect(lib.mergeVersions([e, ...old], { ...e, notes: "neu" })[0].notes).toBe("neu");
|
||||
expect(lib.mergeVersions(old, { ...e, dmg: null })).toEqual(old);
|
||||
});
|
||||
|
||||
// [268] Vorhandene Anhänge lesen: nur „gibt es nicht“ (404) gilt als leer. Bisher ergab jeder Fehler (Netz, 5xx, Proxy)
|
||||
// eine leere Liste — `--publish` überschrieb dann versions.json mit nur der neuen Version (Verlauf weg), und ein
|
||||
// nicht lesbares SHA256SUMS.txt der anderen Plattform fiel stillschweigend aus den Prüfsummen.
|
||||
it("fetchExisting: Text, null bei 404, sonst Fehler", async () => {
|
||||
const res = (status: number, body = "") => async () => new Response(body, { status });
|
||||
expect(await lib.fetchExisting(res(200, "[1]"), "u")).toBe("[1]");
|
||||
expect(await lib.fetchExisting(res(404), "u")).toBeNull();
|
||||
await expect(lib.fetchExisting(res(502, "bad gateway"), "u")).rejects.toThrow(/502/);
|
||||
await expect(lib.fetchExisting(async () => { throw new TypeError("fetch failed"); }, "u")).rejects.toThrow(/fetch failed/);
|
||||
});
|
||||
|
||||
it("parseSums liest sha256sum-Zeilen, ignoriert Fremdes", () => {
|
||||
const h = "a".repeat(64);
|
||||
expect(lib.parseSums(`${h} x.AppImage\n\nkaputt\n${"b".repeat(64)} y.dmg\n`)).toEqual({ "x.AppImage": h, "y.dmg": "b".repeat(64) });
|
||||
});
|
||||
|
||||
// [268] Ersetzen eines Anhangs: erst hochladen (temporärer Name), dann löschen und umbenennen — nie ohne `latest.json`.
|
||||
it("tempAssetName: anderer Name als das Original, Stempel enthalten", () => {
|
||||
expect(lib.tempAssetName("latest.json", 7)).toBe("latest.json.upload-7");
|
||||
});
|
||||
|
||||
it("preflight: ohne --publish nicht auf ein veröffentlichtes Release", () => {
|
||||
const base = { localFiles: ["a.AppImage"], publish: false, replacePublished: false, linuxOnly: false };
|
||||
expect(lib.preflight({ ...base, release: { tag_name: "v1", draft: false, assets: [] } })).toMatch(/--replace-published/);
|
||||
expect(lib.preflight({ ...base, release: { tag_name: "v1", draft: false, assets: [] }, replacePublished: true })).toBeNull();
|
||||
expect(lib.preflight({ ...base, release: { tag_name: "v1", draft: true, assets: [] } })).toBeNull();
|
||||
expect(lib.preflight({ ...base, release: null })).toBeNull();
|
||||
});
|
||||
|
||||
it("preflight: --publish nur mit Mac-Paketen (lokal oder am Release), sonst --linux-only", () => {
|
||||
const base = { publish: true, replacePublished: false, linuxOnly: false };
|
||||
const draft = (names: string[]) => ({ draft: true, assets: names.map((name) => ({ name })) });
|
||||
expect(lib.preflight({ ...base, localFiles: ["a.AppImage"], release: draft([]) })).toMatch(/--linux-only/);
|
||||
expect(lib.preflight({ ...base, localFiles: ["a.AppImage"], release: null })).toMatch(/--linux-only/);
|
||||
expect(lib.preflight({ ...base, localFiles: ["a.AppImage"], release: draft([]), linuxOnly: true })).toBeNull();
|
||||
expect(lib.preflight({ ...base, localFiles: ["a.AppImage", "b.dmg"], release: draft([]) })).toBeNull();
|
||||
expect(lib.preflight({ ...base, localFiles: ["a.AppImage"], release: draft(["b.dmg"]) })).toBeNull();
|
||||
// --publish auf ein veröffentlichtes Release bleibt erlaubt (Nachführen), wenn Mac-Pakete da sind
|
||||
expect(lib.preflight({ ...base, localFiles: ["b.dmg"], release: { draft: false, assets: [] } })).toBeNull();
|
||||
expect(lib.hasMacPackages(["x.AppImage", "SHA256SUMS.txt"])).toBe(false);
|
||||
expect(lib.hasMacPackages(["x.app.tar.gz"])).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user