Git Komut Rehberi & Terminal Asistanı
Sıfırdan Yeni Bir Depo Başlatın:
Mevcut Bir Git Deposu veya Klasörü Gönderin:
Hataları Geri Alma, İptal & Temizlik:
Son commit'i geri al (yapılan değişiklikleri korur):
git reset --soft HEAD~1
Yapılan yerel değişiklikleri iptal et (çalışma ağacını temizler):
git restore .
Takip edilmeyen gereksiz dosyaları sil:
git clean -fd
Değişiklikleri geçici sakla ve geri getir (stash):
git stash git stash pop
Dal (Branch) ve Sürüm Etiketleri:
Yeni dal aç ve geçiş yap:
git checkout -b yeni-ozellik git push -u origin yeni-ozellik
Sürüm etiketi (tag) oluştur ve gönder:
git tag -a v1.0.0 -m "Sürüm 1.0.0" git push origin --tags
200 lines
9.1 KiB
TypeScript
200 lines
9.1 KiB
TypeScript
import fs from "node:fs";
|
||||
|
|
import path from "node:path";
|
|||
|
|
import { describe, expect, it } from "vitest";
|
|||
|
|
import {
|
|||
|
|
exportFiltersForFilename,
|
|||
|
|
formatFriendlyUpdateError,
|
|||
|
|
getDesktopBridge,
|
|||
|
|
isAllowedExternalUrl,
|
|||
|
|
isDesktopRuntime,
|
|||
|
|
isEditorOnlyMenuAction,
|
|||
|
|
normalizeCloudApiPath,
|
|||
|
|
parseMenuAction,
|
|||
|
|
sanitizeDesktopTitle,
|
|||
|
|
} from "../../apps/web/src/lib/desktopBridge";
|
|||
|
|
import { SKF_CREATED_WITH_VERSION } from "../../apps/web/src/lib/skfProject";
|
|||
|
|
import { SERVICE_WORKER_VERSION } from "../../apps/web/src/lib/serviceWorker";
|
|||
|
|
import type { DesktopMenuAction, SnapCadDesktopBridge } from "../../apps/web/src/types/desktop";
|
|||
|
|
|
|||
|
|
describe("desktopBridge", () => {
|
|||
|
|
it("sanitizes desktop window titles and formats dirty indicator", () => {
|
|||
|
|
expect(sanitizeDesktopTitle(undefined, false)).toBe("SnapCAD Studio");
|
|||
|
|
expect(sanitizeDesktopTitle("SnapCAD Studio", true)).toBe("* SnapCAD Studio");
|
|||
|
|
expect(sanitizeDesktopTitle("Motor Braketi\n\r\t v2", false)).toBe("Motor Braketi v2 — SnapCAD Studio");
|
|||
|
|
expect(sanitizeDesktopTitle("Motor Braketi", true)).toBe("* Motor Braketi — SnapCAD Studio");
|
|||
|
|
expect(sanitizeDesktopTitle("Bileşen — SnapCAD Studio", false)).toBe("Bileşen — SnapCAD Studio");
|
|||
|
|
expect(sanitizeDesktopTitle("A".repeat(200), false).length).toBeLessThanOrEqual(140);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it("validates desktop menu actions against allowlist", () => {
|
|||
|
|
const samples: DesktopMenuAction[] = [
|
|||
|
|
"file:open",
|
|||
|
|
"file:save-as",
|
|||
|
|
"file:export-stl",
|
|||
|
|
"edit:make-component",
|
|||
|
|
"edit:chamfer",
|
|||
|
|
"view:zoom-extents",
|
|||
|
|
"view:toggle-tray",
|
|||
|
|
"view:style-blueprint",
|
|||
|
|
"camera:isometric",
|
|||
|
|
"camera:two-point",
|
|||
|
|
"draw:shape-box",
|
|||
|
|
"draw:sketch-extrude",
|
|||
|
|
"tool:push-pull",
|
|||
|
|
"tool:wall-opening",
|
|||
|
|
"tool:physics-toggle",
|
|||
|
|
"tray:entity-info",
|
|||
|
|
"tray:outliner",
|
|||
|
|
"window:settings",
|
|||
|
|
"window:command-palette",
|
|||
|
|
"window:keymap-classic",
|
|||
|
|
"help:audit",
|
|||
|
|
"help:tutorial",
|
|||
|
|
];
|
|||
|
|
for (const action of samples) {
|
|||
|
|
expect(parseMenuAction(action)).toBe(action);
|
|||
|
|
}
|
|||
|
|
expect(parseMenuAction("file:delete-system32")).toBeNull();
|
|||
|
|
expect(parseMenuAction(42)).toBeNull();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it("distinguishes global vs 3D-editor-only menu commands", () => {
|
|||
|
|
expect(isEditorOnlyMenuAction("file:new")).toBe(false);
|
|||
|
|
expect(isEditorOnlyMenuAction("file:open")).toBe(false);
|
|||
|
|
expect(isEditorOnlyMenuAction("file:dashboard")).toBe(false);
|
|||
|
|
expect(isEditorOnlyMenuAction("window:drawing")).toBe(false);
|
|||
|
|
expect(isEditorOnlyMenuAction("window:classrooms")).toBe(false);
|
|||
|
|
expect(isEditorOnlyMenuAction("window:shared")).toBe(false);
|
|||
|
|
expect(isEditorOnlyMenuAction("window:command-palette")).toBe(false);
|
|||
|
|
expect(isEditorOnlyMenuAction("window:a11y")).toBe(false);
|
|||
|
|
expect(isEditorOnlyMenuAction("window:settings")).toBe(false);
|
|||
|
|
expect(isEditorOnlyMenuAction("help:shortcuts")).toBe(false);
|
|||
|
|
|
|||
|
|
expect(isEditorOnlyMenuAction("file:export-stl")).toBe(true);
|
|||
|
|
expect(isEditorOnlyMenuAction("edit:delete")).toBe(true);
|
|||
|
|
expect(isEditorOnlyMenuAction("view:xray")).toBe(true);
|
|||
|
|
expect(isEditorOnlyMenuAction("camera:isometric")).toBe(true);
|
|||
|
|
expect(isEditorOnlyMenuAction("draw:shape-box")).toBe(true);
|
|||
|
|
expect(isEditorOnlyMenuAction("tool:push-pull")).toBe(true);
|
|||
|
|
expect(isEditorOnlyMenuAction("tool:physics-toggle")).toBe(true);
|
|||
|
|
expect(isEditorOnlyMenuAction("tray:outliner")).toBe(true);
|
|||
|
|
expect(isEditorOnlyMenuAction("window:workspace-settings")).toBe(true);
|
|||
|
|
expect(isEditorOnlyMenuAction("help:audit")).toBe(true);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it("keeps native Electron menu items in parity with desktopBridge allowlist and renderer handlers", () => {
|
|||
|
|
const repoRoot = path.resolve(__dirname, "../..");
|
|||
|
|
const mainSource = fs.readFileSync(path.join(repoRoot, "apps/desktop/main.cjs"), "utf8");
|
|||
|
|
const pageSource = fs.readFileSync(path.join(repoRoot, "apps/web/src/app/page.tsx"), "utf8");
|
|||
|
|
const editorSource = fs.readFileSync(path.join(repoRoot, "apps/web/src/components/SketchForgeEditor.tsx"), "utf8");
|
|||
|
|
|
|||
|
|
const menuBlockMatch = mainSource.match(/function buildNativeApplicationMenu\(\)[\s\S]*?^function setupDesktopIpc\(\)/m);
|
|||
|
|
expect(menuBlockMatch).not.toBeNull();
|
|||
|
|
const menuBlock = menuBlockMatch![0];
|
|||
|
|
|
|||
|
|
for (const label of ["Dosya", "Düzenle", "Görünüm", "Kamera", "Çizim", "Araçlar", "Pencere", "Stüdyolar", "Yardım"]) {
|
|||
|
|
expect(menuBlock).toContain(`label: "${label}"`);
|
|||
|
|
expect(menuBlock).not.toContain(`label: "&${label}"`);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const emittedActions = Array.from(menuBlock.matchAll(/sendMenuCommand\("([^"]+)"\)/g)).map((m) => m[1]);
|
|||
|
|
expect(emittedActions.length).toBeGreaterThanOrEqual(90);
|
|||
|
|
|
|||
|
|
for (const action of emittedActions) {
|
|||
|
|
expect(parseMenuAction(action), `parseMenuAction failed for ${action}`).toBe(action);
|
|||
|
|
const handledInPage = pageSource.includes(`case "${action}":`);
|
|||
|
|
const handledInEditor =
|
|||
|
|
editorSource.includes(`case "${action}":`) ||
|
|||
|
|
action.startsWith("draw:shape-") ||
|
|||
|
|
action.startsWith("tray:");
|
|||
|
|
expect(handledInPage || handledInEditor, `Unhandled native menu action: ${action}`).toBe(true);
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it("normalizes and allowlists only relative SnapCAD cloud API paths", () => {
|
|||
|
|
expect(normalizeCloudApiPath("/cloud-api.php")).toBe("/cloud-api.php");
|
|||
|
|
expect(normalizeCloudApiPath(" /cloud-api.php?action=session ")).toBe("/cloud-api.php?action=session");
|
|||
|
|
expect(normalizeCloudApiPath("https://snap.yakhub.com.tr/cloud-api.php?action=session")).toBeNull();
|
|||
|
|
expect(normalizeCloudApiPath("//evil.example/cloud-api.php")).toBeNull();
|
|||
|
|
expect(normalizeCloudApiPath("/login.php")).toBeNull();
|
|||
|
|
expect(normalizeCloudApiPath("/cloud-api.php.evil")).toBeNull();
|
|||
|
|
expect(normalizeCloudApiPath("")).toBeNull();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it("formats updater transport errors into readable Turkish copy", () => {
|
|||
|
|
expect(formatFriendlyUpdateError("")).toBe("Güncelleme denetlenemedi.");
|
|||
|
|
expect(formatFriendlyUpdateError("HttpError: 404 Not Found latest.yml")).toContain("henüz yeni bir masaüstü kurulum paketi yayınlanmadı");
|
|||
|
|
expect(formatFriendlyUpdateError("net::ERR_NETWORK")).toContain("İnternet bağlantınızı kontrol edin");
|
|||
|
|
expect(formatFriendlyUpdateError("Özel sunucu mesajı")).toBe("Özel sunucu mesajı");
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it("allows only http and https external URLs", () => {
|
|||
|
|
expect(isAllowedExternalUrl("https://snap.yakhub.com.tr")).toBe(true);
|
|||
|
|
expect(isAllowedExternalUrl("http://127.0.0.1:62158")).toBe(true);
|
|||
|
|
expect(isAllowedExternalUrl("file:///C:/Windows/System32/cmd.exe")).toBe(false);
|
|||
|
|
expect(isAllowedExternalUrl("javascript:alert(1)")).toBe(false);
|
|||
|
|
expect(isAllowedExternalUrl("")).toBe(false);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it("selects appropriate Electron file filters by extension", () => {
|
|||
|
|
expect(exportFiltersForFilename("parca.stl")[0].extensions).toEqual(["stl"]);
|
|||
|
|
expect(exportFiltersForFilename("govde.STEP")[0].extensions).toEqual(["step", "stp"]);
|
|||
|
|
expect(exportFiltersForFilename("proje.skf")[0].extensions).toEqual(["skf"]);
|
|||
|
|
expect(exportFiltersForFilename("bilinmeyen.bin")[0].extensions).toEqual(["*"]);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it("detects web vs injected Electron preload bridges cleanly", () => {
|
|||
|
|
const globalObj = globalThis as unknown as { window?: Partial<Window> };
|
|||
|
|
const prevWindow = globalObj.window;
|
|||
|
|
try {
|
|||
|
|
globalObj.window = undefined;
|
|||
|
|
expect(isDesktopRuntime()).toBe(false);
|
|||
|
|
expect(getDesktopBridge()).toBeNull();
|
|||
|
|
|
|||
|
|
const mockBridge: SnapCadDesktopBridge = {
|
|||
|
|
isDesktop: true,
|
|||
|
|
getVersion: async () => "1.0.10",
|
|||
|
|
checkForUpdates: async () => ({
|
|||
|
|
currentVersion: "1.0.10",
|
|||
|
|
latestVersion: null,
|
|||
|
|
updateAvailable: false,
|
|||
|
|
downloaded: false,
|
|||
|
|
checkedAt: "2026-01-01T00:00:00.000Z",
|
|||
|
|
}),
|
|||
|
|
installUpdate: async () => ({
|
|||
|
|
currentVersion: "1.0.10",
|
|||
|
|
latestVersion: null,
|
|||
|
|
updateAvailable: false,
|
|||
|
|
downloaded: false,
|
|||
|
|
checkedAt: "2026-01-01T00:00:00.000Z",
|
|||
|
|
}),
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
globalObj.window = { snapcadDesktop: mockBridge };
|
|||
|
|
expect(isDesktopRuntime()).toBe(true);
|
|||
|
|
expect(getDesktopBridge()).toBe(mockBridge);
|
|||
|
|
|
|||
|
|
globalObj.window = { sketchforgeDesktop: mockBridge };
|
|||
|
|
expect(isDesktopRuntime()).toBe(true);
|
|||
|
|
expect(getDesktopBridge()).toBe(mockBridge);
|
|||
|
|
} finally {
|
|||
|
|
globalObj.window = prevWindow as Window | undefined;
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it("keeps app version synchronized across package.json, lockfile, SKF metadata, and SW", () => {
|
|||
|
|
const repoRoot = path.resolve(__dirname, "../..");
|
|||
|
|
const pkg = JSON.parse(fs.readFileSync(path.join(repoRoot, "package.json"), "utf8")) as { version: string };
|
|||
|
|
const lock = JSON.parse(fs.readFileSync(path.join(repoRoot, "package-lock.json"), "utf8")) as {
|
|||
|
|
version: string;
|
|||
|
|
packages: Record<string, { version?: string }>;
|
|||
|
|
};
|
|||
|
|
const swSource = fs.readFileSync(path.join(repoRoot, "apps/web/public/sw.js"), "utf8");
|
|||
|
|
|
|||
|
|
expect(pkg.version).toBe("1.0.10");
|
|||
|
|
expect(lock.version).toBe(pkg.version);
|
|||
|
|
expect(lock.packages[""]?.version).toBe(pkg.version);
|
|||
|
|
expect(SKF_CREATED_WITH_VERSION).toBe(pkg.version);
|
|||
|
|
expect(swSource).toContain(`const CACHE_NAME = "snapcad-v${SERVICE_WORKER_VERSION}"`);
|
|||
|
|
});
|
|||
|
|
});
|