Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: keep app icon bytes inside the repository

Adam Eivyef42e7d53d09
diff --git a/server/routes/apps/icons.js b/server/routes/apps/icons.js
index 8f00fa67d9..926890bc29 100644
--- a/server/routes/apps/icons.js
+++ b/server/routes/apps/icons.js
@@ -12,7 +12,7 @@ import sharp from 'sharp';
import * as appsService from '../../services/apps.js';
import { notifyAppsChanged } from '../../services/apps.js';
import { asyncHandler, ServerError } from '../../lib/errorHandler.js';
-import { detectAppIcon, getIconContentType, isUsableSvg } from '../../services/appIconDetect.js';
+import { detectAppIcon, getIconContentType, isUsableSvg, resolveContainedIcon } from '../../services/appIconDetect.js';
import { loadApp, pathExists } from './shared.js';
const router = Router();
@@ -41,25 +41,22 @@ router.get('/:id/icon', loadApp, asyncHandler(async (req, res) => {
const { appIconQuerySchema, validateRequest } = await import('../../lib/validation.js');
const { size } = validateRequest(appIconQuerySchema, req.query);
- // Use stored appIconPath, or detect on-the-fly. Stored SVGs that embed an
- // external <image href="..."> render blank under the route's `default-src
- // 'none'` CSP, so re-detect when the cached path is an unusable SVG (e.g.
- // PortOS's own favicon.svg, which wraps a /portos-logo.png reference) —
- // otherwise installs that resolved an icon BEFORE the detector learned to
- // skip these stay broken until the user manually re-detects.
- let iconPath = app.appIconPath;
- const stale =
- !iconPath ||
- !await pathExists(iconPath) ||
- (extname(iconPath).toLowerCase() === '.svg' && !await isUsableSvg(iconPath));
- if (stale) {
- iconPath = await detectAppIcon(app.repoPath, app.type);
- if (iconPath && iconPath !== app.appIconPath) {
- await appsService.updateApp(app.id, { appIconPath: iconPath });
+ // Use a stored path only when it still resolves to an icon inside the
+ // repo. Re-detect when it is missing, escapes through `..` or a symlink,
+ // or is an SVG that embeds an external <image href="..."> (those render
+ // blank under this route's CSP — PortOS's own favicon.svg is the example).
+ // Containment is checked before ETag so a symlink swapped onto a host file
+ // cannot answer 304 with the escaped file's metadata.
+ let iconPath = await resolveContainedIcon(app.repoPath, app.appIconPath);
+ if (!iconPath || (extname(iconPath).toLowerCase() === '.svg' && !await isUsableSvg(iconPath))) {
+ const detected = await detectAppIcon(app.repoPath, app.type);
+ if (detected && detected !== app.appIconPath) {
+ await appsService.updateApp(app.id, { appIconPath: detected });
}
+ iconPath = detected;
}
- if (!iconPath || !await pathExists(iconPath)) {
+ if (!iconPath) {
throw new ServerError('No app icon found', { status: 404 });
}
diff --git a/server/routes/apps/icons.test.js b/server/routes/apps/icons.test.js
index d10132bbe4..26f156f132 100644
--- a/server/routes/apps/icons.test.js
+++ b/server/routes/apps/icons.test.js
@@ -1,4 +1,4 @@
-import { describe, it, expect, vi, beforeEach, afterAll } from 'vitest';
+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import express from 'express';
import { closeLoopbackServer, request, startLoopbackServer } from '../../lib/testHelper.js';
import iconRoutes from './icons.js';
@@ -12,15 +12,8 @@ vi.mock('../../services/apps.js', () => ({
PORTOS_APP_ID: 'portos-default'
}));
-vi.mock('../../services/appIconDetect.js', () => ({
- detectAppIcon: vi.fn(),
- getIconContentType: vi.fn(),
- isUsableSvg: vi.fn().mockResolvedValue(true)
-}));
-
import * as appsService from '../../services/apps.js';
-import { detectAppIcon, getIconContentType, isUsableSvg } from '../../services/appIconDetect.js';
-import { writeFileSync, mkdirSync, rmSync, utimesSync } from 'fs';
+import { mkdtempSync, realpathSync, writeFileSync, mkdirSync, rmSync, utimesSync, symlinkSync, unlinkSync } from 'fs';
import { join } from 'path';
import { tmpdir } from 'os';
@@ -49,19 +42,23 @@ describe('Apps Icon Routes', () => {
});
describe('GET /api/apps/:id/icon', () => {
- const iconDir = join(tmpdir(), 'portos-test-icon');
- const iconPath = join(iconDir, 'icon.png');
- const mockApp = { id: 'app-001', name: 'Test App', appIconPath: iconPath, repoPath: '/tmp/test', pm2ProcessNames: [] };
+ let scratch;
+ let iconDir;
+ let iconPath;
+ let mockApp;
beforeEach(async () => {
+ scratch = realpathSync(mkdtempSync(join(tmpdir(), 'portos-test-icon-')));
+ iconDir = join(scratch, 'repo');
+ iconPath = join(iconDir, 'icon.png');
mkdirSync(iconDir, { recursive: true });
await sharp({ create: { width: 512, height: 512, channels: 3, background: '#ff0000' } }).png().toFile(iconPath);
+ mockApp = { id: 'app-001', name: 'Test App', appIconPath: iconPath, repoPath: iconDir, pm2ProcessNames: [] };
appsService.getAppById.mockResolvedValue(mockApp);
- getIconContentType.mockImplementation((path) => path.endsWith('.svg') ? 'image/svg+xml' : 'image/png');
});
- afterAll(() => {
- rmSync(iconDir, { recursive: true, force: true });
+ afterEach(() => {
+ rmSync(scratch, { recursive: true, force: true });
});
it('should return icon with ETag header', async () => {
@@ -140,22 +137,127 @@ describe('Apps Icon Routes', () => {
// Simulate the bad-state PortOS install: appIconPath stored as an SVG
// that exists on disk but embeds <image href="/portos-logo.png"> — CSP
// blocks the embed, so it renders blank. The route must re-detect.
- const badSvgPath = join(iconDir, 'favicon.svg');
- const goodPngPath = join(iconDir, 'redetected.png');
+ mkdirSync(join(iconDir, 'public'));
+ const badSvgPath = join(iconDir, 'public', 'favicon.svg');
+ const goodPngPath = join(iconDir, 'public', 'apple-touch-icon.png');
writeFileSync(badSvgPath, '<svg><image href="/logo.png"/></svg>');
await sharp({ create: { width: 64, height: 64, channels: 3, background: '#00ff00' } }).png().toFile(goodPngPath);
appsService.getAppById.mockResolvedValue({
...mockApp,
appIconPath: badSvgPath,
});
- isUsableSvg.mockResolvedValueOnce(false);
- detectAppIcon.mockResolvedValueOnce(goodPngPath);
-
const response = await request(app).get('/api/apps/app-001/icon');
expect(response.status).toBe(200);
- expect(detectAppIcon).toHaveBeenCalledWith('/tmp/test', undefined);
expect(appsService.updateApp).toHaveBeenCalledWith('app-001', { appIconPath: goodPngPath });
});
+
+ it('replaces a cached outside path with a safe detected icon without serving outside bytes', async () => {
+ const outside = join(scratch, 'outside.svg');
+ writeFileSync(outside, 'synthetic-private-marker');
+ mockApp.appIconPath = outside;
+
+ const response = await requestBinary(app, '/api/apps/app-001/icon');
+
+ expect(response.status).toBe(200);
+ expect(response.body.toString()).not.toContain('synthetic-private-marker');
+ expect(await sharp(response.body).metadata()).toMatchObject({ width: 128, height: 128 });
+ expect(appsService.updateApp).toHaveBeenCalledWith('app-001', { appIconPath: iconPath });
+ });
+
+ it('does not expose a host file selected by a traversing Xcode icon manifest', async () => {
+ unlinkSync(iconPath);
+ const iconSet = join(iconDir, 'Assets.xcassets', 'AppIcon.appiconset');
+ mkdirSync(iconSet, { recursive: true });
+ writeFileSync(join(scratch, 'outside.txt'), 'synthetic-private-marker');
+ writeFileSync(join(iconSet, 'Contents.json'), JSON.stringify({
+ images: [{ filename: '../../../outside.txt', size: '1024x1024', scale: '1x' }],
+ }));
+ mockApp.appIconPath = null;
+ mockApp.type = 'xcode';
+
+ const response = await request(app).get('/api/apps/app-001/icon');
+
+ expect(response.status).toBe(404);
+ expect(response.text).not.toContain('synthetic-private-marker');
+ expect(appsService.updateApp).not.toHaveBeenCalled();
+ });
+
+ it('revalidates a cached symlink before returning a matching conditional response', async () => {
+ unlinkSync(iconPath);
+ mkdirSync(join(iconDir, 'public'));
+ mkdirSync(join(iconDir, 'assets'));
+ const inside = join(iconDir, 'assets', 'safe.svg');
+ const outside = join(scratch, 'outside.svg');
+ const link = join(iconDir, 'public', 'favicon.svg');
+ const svg = '<svg xmlns="http://www.w3.org/2000/svg"><circle r="3"/></svg>';
+ writeFileSync(inside, svg);
+ writeFileSync(outside, 'synthetic-private-marker'.padEnd(Buffer.byteLength(svg), ' '));
+ const timestamp = new Date(Date.now() - 60_000);
+ utimesSync(inside, timestamp, timestamp);
+ utimesSync(outside, timestamp, timestamp);
+ symlinkSync(inside, link, 'file');
+ mockApp.appIconPath = link;
+
+ const first = await request(app).get('/api/apps/app-001/icon');
+ expect(first.status).toBe(200);
+ expect(first.text).toBe(svg);
+ unlinkSync(link);
+ symlinkSync(outside, link, 'file');
+
+ const second = await request(app).get('/api/apps/app-001/icon').set('If-None-Match', first.headers.etag);
+
+ expect(second.status).toBe(404);
+ expect(second.text).not.toContain('synthetic-private-marker');
+ });
+
+ it('refuses an icon beneath an escaping directory symlink', async () => {
+ unlinkSync(iconPath);
+ const outsideDir = join(scratch, 'outside');
+ mkdirSync(outsideDir);
+ writeFileSync(join(outsideDir, 'favicon.svg'), 'synthetic-private-marker');
+ symlinkSync(outsideDir, join(iconDir, 'public'), process.platform === 'win32' ? 'junction' : 'dir');
+ mockApp.appIconPath = join(iconDir, 'public', 'favicon.svg');
+
+ const response = await request(app).get('/api/apps/app-001/icon');
+
+ expect(response.status).toBe(404);
+ expect(response.text).not.toContain('synthetic-private-marker');
+ });
+
+ it('does not serve an in-repository private file through an icon-shaped symlink', async () => {
+ unlinkSync(iconPath);
+ mkdirSync(join(iconDir, 'public'));
+ const privateFile = join(iconDir, '.env');
+ const link = join(iconDir, 'public', 'favicon.svg');
+ writeFileSync(privateFile, 'synthetic-private-marker');
+ symlinkSync(privateFile, link, 'file');
+ mockApp.appIconPath = link;
+
+ const response = await request(app).get('/api/apps/app-001/icon');
+
+ expect(response.status).toBe(404);
+ expect(response.text).not.toContain('synthetic-private-marker');
+ });
+
+ it('detects and serves an internal icon symlink when the repository root is also a symlink', async () => {
+ unlinkSync(iconPath);
+ mkdirSync(join(iconDir, 'assets'));
+ mkdirSync(join(iconDir, 'public'));
+ const realIcon = join(iconDir, 'assets', 'logo.svg');
+ const svg = '<svg xmlns="http://www.w3.org/2000/svg"><rect width="4" height="4"/></svg>';
+ writeFileSync(realIcon, svg);
+ symlinkSync(realIcon, join(iconDir, 'public', 'favicon.svg'), 'file');
+ const linkedRepo = join(scratch, 'linked-repo');
+ symlinkSync(iconDir, linkedRepo, process.platform === 'win32' ? 'junction' : 'dir');
+ mockApp.repoPath = linkedRepo;
+ mockApp.appIconPath = null;
+
+ const response = await request(app).get('/api/apps/app-001/icon');
+
+ expect(response.status).toBe(200);
+ expect(response.text).toBe(svg);
+ expect(response.headers['content-security-policy']).toBe("default-src 'none'; style-src 'unsafe-inline'");
+ });
});
});
diff --git a/server/routes/apps/lifecycle.js b/server/routes/apps/lifecycle.js
index 56a75dfbe0..e5a9eb4c11 100644
--- a/server/routes/apps/lifecycle.js
+++ b/server/routes/apps/lifecycle.js
@@ -26,7 +26,7 @@ import { logAction } from '../../services/history.js';
import { asyncHandler, ServerError } from '../../lib/errorHandler.js';
import { parseEcosystemFromPath } from '../../services/streamingDetect.js';
import { usesPm2, isDesktopType } from '../../services/appProcessTypes.js';
-import { detectAppIcon, isUsableSvg } from '../../services/appIconDetect.js';
+import { detectAppIcon, isUsableSvg, resolveContainedIcon } from '../../services/appIconDetect.js';
import { loadApp, pathExists, deriveUiPort } from './shared.js';
import { EIDOVERSE_PROCESS_NAME, EIDOVERSE_MAX_MEMORY_RESTART } from '../../services/eidoverse.js';
@@ -355,12 +355,12 @@ router.post('/:id/refresh-config', loadApp, asyncHandler(async (req, res) => {
updates.uiPort = deriveUiPort(updates.uiPort, updates.apiPort, updates.devUiPort || app.devUiPort);
}
- // Detect app icon if not already set, missing on disk, or stored as an
- // unusable external-image SVG (won't render under the icon route's CSP).
+ // Same containment rule as the icon route: a stored path outside the repo
+ // is stale and must not be opened just to test whether the SVG is usable.
+ const containedIcon = await resolveContainedIcon(app.repoPath, app.appIconPath);
const iconStale =
- !app.appIconPath ||
- !await pathExists(app.appIconPath) ||
- (extname(app.appIconPath).toLowerCase() === '.svg' && !await isUsableSvg(app.appIconPath));
+ !containedIcon ||
+ (extname(containedIcon).toLowerCase() === '.svg' && !await isUsableSvg(containedIcon));
if (iconStale) {
const detectedIcon = await detectAppIcon(app.repoPath, app.type);
if (detectedIcon) updates.appIconPath = detectedIcon;
diff --git a/server/routes/apps/lifecycle.test.js b/server/routes/apps/lifecycle.test.js
index c9ff6a2c39..94d570c557 100644
--- a/server/routes/apps/lifecycle.test.js
+++ b/server/routes/apps/lifecycle.test.js
@@ -58,7 +58,9 @@ vi.mock('../../services/appUpdater.js', () => ({
vi.mock('../../services/appIconDetect.js', () => ({
detectAppIcon: vi.fn(),
- isUsableSvg: vi.fn().mockResolvedValue(true)
+ isUsableSvg: vi.fn().mockResolvedValue(true),
+ // Tests store synthetic paths; treat a non-empty one as already inside the repo.
+ resolveContainedIcon: vi.fn(async (_repoPath, iconPath) => iconPath || null)
}));
import * as appsService from '../../services/apps.js';
diff --git a/server/services/appIconDetect.js b/server/services/appIconDetect.js
index f904781e1d..14e063dada 100644
--- a/server/services/appIconDetect.js
+++ b/server/services/appIconDetect.js
@@ -1,7 +1,7 @@
import { existsSync } from 'fs';
-import { readdir } from 'fs/promises';
+import { readdir, realpath, stat } from 'fs/promises';
import { join, extname } from 'path';
-import { safeJSONParse, tryReadFile } from '../lib/fileUtils.js';
+import { isPathInsideDir, isTopLevelEntryName, safeJSONParse, tryReadFile } from '../lib/fileUtils.js';
/**
* Well-known icon paths to check, ordered by priority.
@@ -56,6 +56,52 @@ const CONTENT_TYPES = {
'.webp': 'image/webp',
};
+const ICON_EXTENSIONS = new Set(Object.keys(CONTENT_TYPES));
+
+/**
+ * Real path of a regular file that stays inside `repoPath` after symlinks are
+ * resolved. A stored icon, an Xcode manifest, or a repo symlink can otherwise
+ * name a host file and the icon route will return its bytes. `extensions`
+ * limits the resolved target, so `favicon.svg -> .env` is not an icon.
+ * @param {string} repoPath
+ * @param {string} candidatePath
+ * @param {Set<string>} extensions lowercase extensions including the dot
+ * @returns {Promise<string|null>}
+ */
+async function resolveContainedFile(repoPath, candidatePath, extensions) {
+ if (typeof repoPath !== 'string' || !repoPath || typeof candidatePath !== 'string' || !candidatePath) {
+ return null;
+ }
+ if (!(extensions instanceof Set) || extensions.size === 0) return null;
+ try {
+ const root = await realpath(repoPath);
+ const resolved = await realpath(candidatePath);
+ const info = await stat(resolved);
+ if (!info.isFile()) return null;
+ if (!extensions.has(extname(resolved).toLowerCase())) return null;
+ if (!isPathInsideDir(root, resolved)) return null;
+ return resolved;
+ } catch {
+ return null;
+ }
+}
+
+/** @param {string} repoPath @param {string} candidatePath @returns {Promise<string|null>} */
+export function resolveContainedIcon(repoPath, candidatePath) {
+ return resolveContainedFile(repoPath, candidatePath, ICON_EXTENSIONS);
+}
+
+async function isContainedDirectory(repoPath, candidatePath) {
+ try {
+ const root = await realpath(repoPath);
+ const resolved = await realpath(candidatePath);
+ const info = await stat(resolved);
+ return info.isDirectory() && isPathInsideDir(root, resolved);
+ } catch {
+ return false;
+ }
+}
+
// SVGs that embed an external <image href="..."> won't render under the icon
// endpoint's strict `default-src 'none'` CSP, so they are unusable as app icons
// even though the file exists. Skip them and let detection fall through to a
@@ -110,59 +156,71 @@ async function findXcodeAppIcon(repoPath) {
}
for (const iconSetPath of appIconSetPaths) {
- if (!existsSync(iconSetPath)) continue;
-
- // Read Contents.json to find actual icon filenames and sizes
- const contentsPath = join(iconSetPath, 'Contents.json');
- if (existsSync(contentsPath)) {
- const contents = await tryReadFile(contentsPath);
- if (contents) {
- const parsed = safeJSONParse(contents, {})?.images || [];
- // Find the largest icon by parsing size (prefer 1024x1024, then smaller)
- let bestIcon = null;
- let bestSize = 0;
-
- for (const img of parsed) {
- if (!img.filename) continue;
- const filePath = join(iconSetPath, img.filename);
- if (!existsSync(filePath)) continue;
-
- // Parse size from the "size" field (e.g., "1024x1024")
- const sizeMatch = img.size?.match(/(\d+)x(\d+)/);
- const scale = parseFloat(img.scale) || 1;
- const size = sizeMatch ? parseInt(sizeMatch[1]) * scale : 0;
-
- if (size > bestSize) {
- bestSize = size;
- bestIcon = filePath;
- }
- }
-
- // If Contents.json didn't yield results, fall back to scanning files
- if (!bestIcon) {
- const files = await readdir(iconSetPath).catch(() => []);
- const pngs = files.filter(f => f.endsWith('.png')).sort().reverse();
- if (pngs.length > 0) {
- bestIcon = join(iconSetPath, pngs[0]);
- }
- }
-
- if (bestIcon) return bestIcon;
- }
- }
+ if (!await isContainedDirectory(repoPath, iconSetPath)) continue;
- // Fallback: just grab the largest PNG by filename
- const files = await readdir(iconSetPath).catch(() => []);
- const pngs = files.filter(f => f.endsWith('.png')).sort().reverse();
- if (pngs.length > 0) {
- return join(iconSetPath, pngs[0]);
- }
+ const bestFromManifest = await bestManifestIcon(repoPath, iconSetPath);
+ if (bestFromManifest) return bestFromManifest;
+
+ const fallback = await firstContainedPng(repoPath, iconSetPath);
+ if (fallback) return fallback;
}
}
return null;
}
+/**
+ * Largest contained icon named by Contents.json. A manifest that itself
+ * resolves outside the repo is ignored: its filenames are attacker-controlled
+ * even when they point back at local images. Non-array `images` is the same
+ * as no manifest so the PNG filename fallback can still run.
+ * @param {string} repoPath
+ * @param {string} iconSetPath
+ * @returns {Promise<string|null>}
+ */
+async function bestManifestIcon(repoPath, iconSetPath) {
+ const manifestPath = await resolveContainedFile(
+ repoPath,
+ join(iconSetPath, 'Contents.json'),
+ new Set(['.json'])
+ );
+ if (!manifestPath) return null;
+ const contents = await tryReadFile(manifestPath);
+ if (!contents) return null;
+ const images = safeJSONParse(contents, {})?.images;
+ if (!Array.isArray(images)) return null;
+
+ let bestIcon = null;
+ let bestSize = 0;
+ for (const img of images) {
+ // Basename only: `join` treats an absolute filename as the whole path,
+ // and `../` walks out of the asset catalog.
+ if (!isTopLevelEntryName(img?.filename)) continue;
+ const resolved = await resolveContainedIcon(repoPath, join(iconSetPath, img.filename));
+ if (!resolved) continue;
+ const sizeMatch = typeof img.size === 'string' ? img.size.match(/(\d+)x(\d+)/) : null;
+ const scale = parseFloat(img.scale) || 1;
+ const size = sizeMatch ? parseInt(sizeMatch[1], 10) * scale : 0;
+ if (size > bestSize) {
+ bestSize = size;
+ bestIcon = resolved;
+ }
+ }
+ return bestIcon;
+}
+
+/** Reverse-sorted contained PNG in the icon set, for a missing or unusable manifest. */
+async function firstContainedPng(repoPath, iconSetPath) {
+ const files = await readdir(iconSetPath).catch(() => []);
+ const pngs = files.filter(f => f.endsWith('.png')).sort().reverse();
+ for (const name of pngs) {
+ if (!isTopLevelEntryName(name)) continue;
+ const resolved = await resolveContainedIcon(repoPath, join(iconSetPath, name));
+ if (resolved) return resolved;
+ }
+ return null;
+}
+
/**
* Detect the app icon path for a given project directory.
* Returns the absolute path to the icon file, or null if none found.
@@ -179,12 +237,13 @@ export async function detectAppIcon(repoPath, appType) {
if (xcodeIcon) return xcodeIcon;
}
- // Check well-known paths
+ // Check well-known paths. Resolve symlinks before accepting the file so
+ // `public/` or the icon itself cannot point at a file outside the repo.
for (const relPath of ICON_SEARCH_PATHS) {
- const fullPath = join(repoPath, relPath);
- if (!existsSync(fullPath)) continue;
- if (extname(fullPath).toLowerCase() === '.svg' && !await isUsableSvg(fullPath)) continue;
- return fullPath;
+ const contained = await resolveContainedIcon(repoPath, join(repoPath, relPath));
+ if (!contained) continue;
+ if (extname(contained).toLowerCase() === '.svg' && !await isUsableSvg(contained)) continue;
+ return contained;
}
// For any project type, also try Xcode icon detection as a fallback
diff --git a/server/services/appIconDetect.test.js b/server/services/appIconDetect.test.js
index 345ad297b8..16c8820433 100644
--- a/server/services/appIconDetect.test.js
+++ b/server/services/appIconDetect.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
-import { mkdtempSync, rmSync, mkdirSync, writeFileSync } from 'fs';
+import { mkdtempSync, realpathSync, rmSync, mkdirSync, writeFileSync, symlinkSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
import { detectAppIcon } from './appIconDetect.js';
@@ -8,13 +8,16 @@ const PNG_BYTES = Buffer.from('89504e470d0a1a0a', 'hex');
describe('detectAppIcon', () => {
let repoPath;
+ let scratch;
beforeEach(() => {
- repoPath = mkdtempSync(join(tmpdir(), 'icon-detect-'));
+ scratch = realpathSync(mkdtempSync(join(tmpdir(), 'icon-detect-')));
+ repoPath = join(scratch, 'repo');
+ mkdirSync(repoPath);
});
afterEach(() => {
- rmSync(repoPath, { recursive: true, force: true });
+ rmSync(scratch, { recursive: true, force: true });
});
it('returns null for missing repoPath', async () => {
@@ -56,4 +59,41 @@ describe('detectAppIcon', () => {
const result = await detectAppIcon(repoPath, 'express');
expect(result).toBe(join(repoPath, 'public', 'favicon.svg'));
});
+
+ it('ranks only contained PNG members in an Xcode manifest', async () => {
+ const iconSet = join(repoPath, 'Assets.xcassets', 'AppIcon.appiconset');
+ mkdirSync(iconSet, { recursive: true });
+ writeFileSync(join(scratch, 'outside.png'), PNG_BYTES);
+ writeFileSync(join(iconSet, 'small.png'), PNG_BYTES);
+ writeFileSync(join(iconSet, 'large.png'), PNG_BYTES);
+ writeFileSync(join(iconSet, 'Contents.json'), JSON.stringify({ images: [
+ { filename: '../../../outside.png', size: '4096x4096', scale: '1x' },
+ { filename: 'small.png', size: '128x128', scale: '1x' },
+ { filename: 'large.png', size: '256x256', scale: '2x' },
+ ] }));
+
+ expect(await detectAppIcon(repoPath, 'xcode')).toBe(join(iconSet, 'large.png'));
+ });
+
+ it('falls back to contained PNG files when a manifest has the wrong images shape', async () => {
+ const iconSet = join(repoPath, 'Assets.xcassets', 'AppIcon.appiconset');
+ mkdirSync(iconSet, { recursive: true });
+ writeFileSync(join(iconSet, 'icon.png'), PNG_BYTES);
+ writeFileSync(join(iconSet, 'Contents.json'), JSON.stringify({ images: { filename: 'icon.png' } }));
+
+ expect(await detectAppIcon(repoPath, 'xcode')).toBe(join(iconSet, 'icon.png'));
+ });
+
+ it('ignores an external manifest symlink and uses the local fallback', async () => {
+ const iconSet = join(repoPath, 'Assets.xcassets', 'AppIcon.appiconset');
+ mkdirSync(iconSet, { recursive: true });
+ writeFileSync(join(iconSet, 'a.png'), PNG_BYTES);
+ writeFileSync(join(iconSet, 'z.png'), PNG_BYTES);
+ const externalManifest = join(scratch, 'manifest.json');
+ writeFileSync(externalManifest, JSON.stringify({ images: [{ filename: 'a.png', size: '1024x1024' }] }));
+ symlinkSync(externalManifest, join(iconSet, 'Contents.json'), 'file');
+
+ // The external manifest would pick a.png; filename fallback picks z.png.
+ expect(await detectAppIcon(repoPath, 'xcode')).toBe(join(iconSet, 'z.png'));
+ });
});