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 sprite publication inside the managed app (#9668)

Adam Eivy4829232e39f6
diff --git a/server/services/sprites/publish.js b/server/services/sprites/publish.js
index b944c1fd07..c13acfbf60 100644
--- a/server/services/sprites/publish.js
+++ b/server/services/sprites/publish.js
@@ -31,11 +31,12 @@
* posture) nested inside the record's walk write tail.
*/
-import { join, resolve } from 'path';
-import { readFile, stat } from 'fs/promises';
+import { dirname, join, relative, resolve, sep } from 'path';
+import { lstat, mkdir, readFile, realpath, stat } from 'fs/promises';
import {
atomicWrite, isPathInsideDir, readJSONFile, safeJSONParse, sha256File, pathExists,
} from '../../lib/fileUtils.js';
+import { isPathAtOrInsideDir } from '../../lib/pathContainment.js';
import { ServerError } from '../../lib/errorHandler.js';
import { createKeyCachedQueue } from '../../lib/createKeyCachedQueue.js';
import { getAppById } from '../apps.js';
@@ -58,8 +59,7 @@ import {
presentationIdleSidecarPath,
} from './presentationIdle.js';
-// Per-repo serialization: keyed by the resolved repoPath (matching
-// appDeployer's `deployingApps` key), so two app records pointing at the
+// Per-repo serialization: keyed by the real repoPath, so two app records pointing at the
// same checkout — or two characters publishing into one game — queue behind
// each other instead of interleaving writes to the same tree.
const repoPublishTail = createKeyCachedQueue();
@@ -68,16 +68,36 @@ const bindingError = (message, code) => new ServerError(message, { status: 400,
/**
* Anchor a repo-relative path under a managed app's repoPath, refusing
- * absolute paths, traversal, and the repo root itself.
+ * absolute paths, traversal, the repo root itself, and symlink components.
+ * Missing tails are allowed only below a verified existing directory.
*/
-function anchorRepoPath(repoRoot, relPath, label) {
- if (typeof relPath !== 'string' || !relPath || relPath.startsWith('/') || relPath.includes('\\')) {
+async function anchorRepoPath(repoRoot, relPath, label) {
+ if (typeof relPath !== 'string' || !relPath || relPath.startsWith('/') || relPath.includes('\\') || relPath.includes('\0')) {
throw bindingError(`${label} must be a repo-relative path`, 'INVALID_PUBLISH_PATH');
}
const abs = resolve(repoRoot, relPath);
if (abs === resolve(repoRoot) || !isPathInsideDir(repoRoot, abs)) {
throw bindingError(`${label} escapes the app repository: ${relPath}`, 'INVALID_PUBLISH_PATH');
}
+ const invalid = () => bindingError(`${label} must stay inside the app repository without symlinks: ${relPath}`, 'INVALID_PUBLISH_PATH');
+ // Walk from the real root so even dangling or contained symlinks are refused,
+ // rather than mistaken for a missing destination or silently followed.
+ const rootStat = await lstat(repoRoot);
+ if (rootStat.isSymbolicLink() || !rootStat.isDirectory()) throw invalid();
+ let existing = repoRoot;
+ const parts = relative(repoRoot, abs).split(sep);
+ for (const [index, part] of parts.entries()) {
+ const next = join(existing, part);
+ const info = await lstat(next).catch((err) => {
+ if (err.code === 'ENOENT') return null;
+ throw err;
+ });
+ if (!info) break;
+ if (info.isSymbolicLink()
+ || (index < parts.length - 1 ? !info.isDirectory() : !info.isFile())) throw invalid();
+ existing = next;
+ }
+ if (!isPathAtOrInsideDir(repoRoot, await realpath(existing))) throw invalid();
return abs;
}
@@ -93,7 +113,7 @@ async function requireAppRepo(appId, status) {
if (!repoStat?.isDirectory()) {
throw new ServerError(`App ${app.name || appId} has no accessible repoPath`, { status, code: 'APP_REPO_MISSING' });
}
- return { app, repoRoot: app.repoPath };
+ return { app, repoRoot: await realpath(app.repoPath) };
}
/**
@@ -135,19 +155,20 @@ export async function validatePublishBinding(binding) {
appId, atlasDestPath, portraitDestPath, presentationIdleDestPath,
codeBinding, runtimeContract,
} = binding;
- const { app } = await requireAppRepo(appId, 400);
- anchorRepoPath(app.repoPath, atlasDestPath, 'atlasDestPath');
+ const { repoRoot } = await requireAppRepo(appId, 400);
+ await anchorRepoPath(repoRoot, atlasDestPath, 'atlasDestPath');
// The sidecar lands beside the atlas, so its path must anchor too — catch a
// destination whose sidecar would escape the repo at SAVE time, not mid-publish.
- anchorRepoPath(app.repoPath, layoutSidecarPath(atlasDestPath), 'atlas layout sidecar');
+ await anchorRepoPath(repoRoot, layoutSidecarPath(atlasDestPath), 'atlas layout sidecar');
if (portraitDestPath) {
- anchorRepoPath(app.repoPath, portraitDestPath, 'portraitDestPath');
+ await anchorRepoPath(repoRoot, portraitDestPath, 'portraitDestPath');
}
if (presentationIdleDestPath) {
- anchorRepoPath(app.repoPath, presentationIdleDestPath, 'presentationIdleDestPath');
+ await anchorRepoPath(repoRoot, presentationIdleDestPath, 'presentationIdleDestPath');
+ await anchorRepoPath(repoRoot, presentationIdleSidecarPath(presentationIdleDestPath), 'picker animation sidecar');
}
if (codeBinding) {
- anchorRepoPath(app.repoPath, codeBinding.path, 'codeBinding.path');
+ await anchorRepoPath(repoRoot, codeBinding.path, 'codeBinding.path');
if (typeof codeBinding.resourcePath !== 'string' || !codeBinding.resourcePath.trim()) {
throw bindingError('codeBinding.resourcePath is required', 'INVALID_CODE_BINDING');
}
@@ -191,17 +212,16 @@ export async function validatePublishBinding(binding) {
*/
export async function setPublishBinding(recordId, binding) {
const record = await requireAnimatable(recordId);
- const validated = await validatePublishBinding(binding);
const stored = record.publishBinding;
- if (validated && binding.runtimeContract === undefined && validated.appId === stored?.appId) {
- validated.runtimeContract = stored.runtimeContract ?? null;
- }
- if (validated && binding.portraitDestPath === undefined && validated.appId === stored?.appId) {
- validated.portraitDestPath = stored.portraitDestPath ?? null;
- }
- if (validated && binding.presentationIdleDestPath === undefined && validated.appId === stored?.appId) {
- validated.presentationIdleDestPath = stored.presentationIdleDestPath ?? null;
+ const effective = binding ? { ...binding } : null;
+ if (effective && effective.appId === stored?.appId) {
+ // Validate inherited paths too: a symlink may have appeared since the
+ // previous save, even when an older client omits optional destinations.
+ for (const field of ['runtimeContract', 'portraitDestPath', 'presentationIdleDestPath']) {
+ if (effective[field] === undefined) effective[field] = stored[field] ?? null;
+ }
}
+ const validated = await validatePublishBinding(effective);
return updateRecord(recordId, { publishBinding: validated });
}
@@ -237,7 +257,7 @@ const countOccurrences = (text, needle) => (needle ? text.split(needle).length -
* Returns the publication's codeBinding summary; throws on drift.
*/
async function applyCodeBinding(repoRoot, codeBinding, previousResourcePath) {
- const abs = anchorRepoPath(repoRoot, codeBinding.path, 'codeBinding.path');
+ const abs = await anchorRepoPath(repoRoot, codeBinding.path, 'codeBinding.path');
const required = codeBinding.requiredOccurrenceCount ?? 1;
const text = await readFile(abs, 'utf8').catch(() => null);
if (text === null) {
@@ -252,6 +272,7 @@ async function applyCodeBinding(repoRoot, codeBinding, previousResourcePath) {
if (previousResourcePath && previousResourcePath !== codeBinding.resourcePath) {
const previousCount = countOccurrences(text, previousResourcePath);
if (previousCount === required) {
+ await anchorRepoPath(repoRoot, codeBinding.path, 'codeBinding.path');
await atomicWrite(abs, text.split(previousResourcePath).join(codeBinding.resourcePath));
return { ...codeBinding, rewritten: true, previousResourcePath };
}
@@ -348,23 +369,52 @@ async function publishAtlasImpl(recordId, { acknowledgeOverwrite = false } = {})
// Don't mutate a tree a deploy is currently building from — appDeployer
// keys its lock by repoPath, so honor it here (the reverse direction —
// deploy checking publishes — isn't needed; publishes are sub-second).
- if (isDeploying(repoRoot)) {
+ if (isDeploying(app.repoPath)) {
throw new ServerError(`App ${appLabel} is deploying — retry when the deploy finishes`, { status: 409, code: 'APP_DEPLOY_IN_PROGRESS' });
}
- const destAbs = anchorRepoPath(repoRoot, binding.atlasDestPath, 'atlasDestPath');
+ const destAbs = await anchorRepoPath(repoRoot, binding.atlasDestPath, 'atlasDestPath');
// The sidecar is repo-anchored and written inside this same per-repo tail
// as the PNG, so the pair is never interleaved with another publish into
// the same checkout.
- const layoutAbs = anchorRepoPath(repoRoot, layoutDestPath, 'atlas layout sidecar');
+ const layoutAbs = await anchorRepoPath(repoRoot, layoutDestPath, 'atlas layout sidecar');
const portraitAbs = portrait
- ? anchorRepoPath(repoRoot, binding.portraitDestPath, 'portraitDestPath')
+ ? await anchorRepoPath(repoRoot, binding.portraitDestPath, 'portraitDestPath')
: null;
const presentationIdleAbs = presentationIdle
- ? anchorRepoPath(repoRoot, binding.presentationIdleDestPath, 'presentationIdleDestPath')
+ ? await anchorRepoPath(repoRoot, binding.presentationIdleDestPath, 'presentationIdleDestPath')
: null;
const presentationIdleLayoutAbs = presentationIdle
- ? anchorRepoPath(repoRoot, presentationIdleLayoutDestPath, 'picker animation sidecar')
+ ? await anchorRepoPath(repoRoot, presentationIdleLayoutDestPath, 'picker animation sidecar')
: null;
+ const destinations = [
+ [binding.atlasDestPath, 'atlasDestPath'],
+ [layoutDestPath, 'atlas layout sidecar'],
+ ...(portrait ? [[binding.portraitDestPath, 'portraitDestPath']] : []),
+ ...(presentationIdle ? [
+ [binding.presentationIdleDestPath, 'presentationIdleDestPath'],
+ [presentationIdleLayoutDestPath, 'picker animation sidecar'],
+ ] : []),
+ ...(binding.codeBinding ? [[binding.codeBinding.path, 'codeBinding.path']] : []),
+ ];
+ const preflightDestinations = async () => {
+ for (const [path, label] of destinations) await anchorRepoPath(repoRoot, path, label);
+ };
+ // Media paths were checked above; check source before any app-file reads.
+ if (binding.codeBinding) await anchorRepoPath(repoRoot, binding.codeBinding.path, 'codeBinding.path');
+ // Repeat the complete preflight after creating output parents, before
+ // either branch can rewrite source.
+ const prepareDestinations = async () => {
+ for (const [path, label] of destinations) {
+ const abs = await anchorRepoPath(repoRoot, path, label);
+ await mkdir(dirname(abs), { recursive: true });
+ await anchorRepoPath(repoRoot, path, label);
+ }
+ await preflightDestinations();
+ };
+ const writeDestination = async (path, label, buffer) => {
+ const abs = await anchorRepoPath(repoRoot, path, label);
+ await atomicWrite(abs, buffer);
+ };
const existingLayout = await readFile(layoutAbs).catch(() => null);
const layoutUpToDate = Boolean(existingLayout?.equals(layoutBuffer));
// Occupied-destination guard, mirroring the atlas's: PortOS owns files it
@@ -392,7 +442,7 @@ async function publishAtlasImpl(recordId, { acknowledgeOverwrite = false } = {})
// so the two can never be permanently out of step.
const writeLayoutSidecar = async () => {
if (layoutUpToDate) return false;
- await atomicWrite(layoutAbs, layoutBuffer);
+ await writeDestination(layoutDestPath, 'atlas layout sidecar', layoutBuffer);
return true;
};
const atlasBuffer = await readFile(join(dir, compiled.atlasPath)).catch(() => null);
@@ -483,7 +533,7 @@ async function publishAtlasImpl(recordId, { acknowledgeOverwrite = false } = {})
};
const writePortrait = async () => {
if (!portrait || portraitUpToDate) return false;
- await atomicWrite(portraitAbs, portrait.buffer);
+ await writeDestination(binding.portraitDestPath, 'portraitDestPath', portrait.buffer);
return true;
};
const presentationIdleDestSha256 = presentationIdle && await pathExists(presentationIdleAbs)
@@ -513,7 +563,7 @@ async function publishAtlasImpl(recordId, { acknowledgeOverwrite = false } = {})
};
const writePresentationIdle = async () => {
if (!presentationIdle || presentationIdleUpToDate) return false;
- await atomicWrite(presentationIdleAbs, presentationIdle.buffer);
+ await writeDestination(binding.presentationIdleDestPath, 'presentationIdleDestPath', presentationIdle.buffer);
return true;
};
const existingPresentationIdleLayout = presentationIdle
@@ -537,7 +587,7 @@ async function publishAtlasImpl(recordId, { acknowledgeOverwrite = false } = {})
};
const writePresentationIdleLayout = async () => {
if (!presentationIdle || presentationIdleLayoutUpToDate) return false;
- await atomicWrite(presentationIdleLayoutAbs, presentationIdleLayoutBuffer);
+ await writeDestination(presentationIdleLayoutDestPath, 'picker animation sidecar', presentationIdleLayoutBuffer);
return true;
};
@@ -547,6 +597,7 @@ async function publishAtlasImpl(recordId, { acknowledgeOverwrite = false } = {})
assertPortraitDestWritable();
assertPresentationIdleDestWritable();
assertPresentationIdleLayoutWritable();
+ await prepareDestinations();
// Verify the code binding even on a no-op so drift never hides.
const codeBinding = binding.codeBinding
? await applyCodeBinding(repoRoot, binding.codeBinding, previousForCode?.codeBinding?.resourcePath)
@@ -613,6 +664,7 @@ async function publishAtlasImpl(recordId, { acknowledgeOverwrite = false } = {})
assertPortraitDestWritable();
assertPresentationIdleDestWritable();
assertPresentationIdleLayoutWritable();
+ await prepareDestinations();
const codeBinding = binding.codeBinding
? await applyCodeBinding(repoRoot, binding.codeBinding, previousForCode?.codeBinding?.resourcePath)
: null;
@@ -626,7 +678,7 @@ async function publishAtlasImpl(recordId, { acknowledgeOverwrite = false } = {})
const portraitWritten = await writePortrait();
const presentationIdleLayoutWritten = await writePresentationIdleLayout();
const presentationIdleWritten = await writePresentationIdle();
- await atomicWrite(destAbs, atlasBuffer);
+ await writeDestination(binding.atlasDestPath, 'atlasDestPath', atlasBuffer);
const publication = await recordPublication({
destPreviousSha256: destSha256, codeBinding, layoutDestPath, layoutSha256,
diff --git a/server/services/sprites/publish.test.js b/server/services/sprites/publish.test.js
index 5bc6d19a11..89f7a86aaf 100644
--- a/server/services/sprites/publish.test.js
+++ b/server/services/sprites/publish.test.js
@@ -14,7 +14,7 @@ import { describe, it, expect, beforeEach, afterAll, vi } from 'vitest';
import { mkdtempSync, rmSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
-import { mkdir, writeFile, readFile } from 'fs/promises';
+import { mkdir, writeFile, readFile, realpath, symlink, unlink } from 'fs/promises';
import { createHash } from 'crypto';
import sharp from 'sharp';
import { trackSpan as fullSpan } from './spriteTestFixtures.js';
@@ -22,6 +22,19 @@ import { trackSpan as fullSpan } from './spriteTestFixtures.js';
const TEST_ROOT = mkdtempSync(join(tmpdir(), 'sprite-publish-test-'));
const APP_REPO = join(TEST_ROOT, 'game-repo');
+const filesystemMocks = vi.hoisted(() => ({ afterMkdir: null }));
+vi.mock('fs/promises', async (importOriginal) => {
+ const actual = await importOriginal();
+ return {
+ ...actual,
+ mkdir: async (...args) => {
+ const result = await actual.mkdir(...args);
+ await filesystemMocks.afterMkdir?.(args[0]);
+ return result;
+ },
+ };
+});
+
vi.mock('../../lib/fileUtils.js', async (importOriginal) => {
const actual = await importOriginal();
Object.assign(actual.PATHS, {
@@ -145,6 +158,8 @@ async function addLockedMainReference(id) {
beforeEach(async () => {
getAppById.mockClear();
+ APPS['game-app'].repoPath = APP_REPO;
+ filesystemMocks.afterMkdir = null;
isDeploying.mockReset();
isDeploying.mockReturnValue(false);
compileAtlasInTail.mockReset();
@@ -788,6 +803,149 @@ describe('layout sidecar (#2982)', () => {
});
});
+describe('publication filesystem boundary', () => {
+ const sourcePath = 'src/Hero.cs';
+ const portraitDestPath = 'assets/portraits/hero.png';
+ const presentationIdleDestPath = 'assets/picker/hero.png';
+ const targets = [
+ ['atlas', BINDING.atlasDestPath, {}],
+ ['atlas sidecar', sidecarPath(BINDING.atlasDestPath), {}],
+ ['portrait', portraitDestPath, { portraitDestPath }],
+ ['picker animation', presentationIdleDestPath, { presentationIdleDestPath }],
+ ['picker sidecar', presentationIdleDestPath.replace(/\.png$/, '.presentation.json'), { presentationIdleDestPath }],
+ ['code binding', sourcePath, {}],
+ ];
+
+ // Each destination has its own read/write call site. Both branches can
+ // rewrite source, so this security matrix pins preflight ordering for all.
+ describe.each(['normal', 'up-to-date'])('%s publication', (branch) => {
+ it.each(targets)('rejects a newly symlinked %s before any app-file rewrite', async (_label, target, extra) => {
+ const { id, atlasBytes } = await characterWithAtlas();
+ const oldResource = 'res://old-atlas.png';
+ const newResource = 'res://new-atlas.png';
+ const sourceBefore = `load("${oldResource}");\n`;
+ await mkdir(join(APP_REPO, 'src'), { recursive: true });
+ await writeFile(join(APP_REPO, sourcePath), sourceBefore);
+ await setPublishBinding(id, {
+ ...BINDING,
+ atlasDestPath: 'assets/old-atlas.png',
+ codeBinding: { path: sourcePath, resourcePath: oldResource },
+ });
+ await publishAtlas(id);
+ const historyPath = join(TEST_ROOT, 'sprites', id, 'runtime/publications.json');
+ const historyBefore = await readFile(historyPath);
+ if (extra.portraitDestPath) await addLockedMainReference(id);
+ const strip = Buffer.from('synthetic-picker-strip');
+ presentationIdleMocks.buildPresentationIdle.mockResolvedValue({
+ buffer: strip, sha256: sha256(strip), frameCount: 3, frameRate: 6, cellSize: 512,
+ });
+ const binding = {
+ ...BINDING, ...extra,
+ codeBinding: { path: sourcePath, resourcePath: newResource },
+ };
+ await setPublishBinding(id, binding);
+ await mkdir(join(APP_REPO, 'assets/sprites/hero'), { recursive: true });
+ if (branch === 'up-to-date') await writeFile(join(APP_REPO, BINDING.atlasDestPath), atlasBytes);
+
+ const outsidePath = join(OTHER_APP_REPO, 'outside-target');
+ const outsideBefore = target === sourcePath ? sourceBefore : atlasBytes;
+ await writeFile(outsidePath, outsideBefore);
+ await mkdir(join(APP_REPO, target, '..'), { recursive: true });
+ await unlink(join(APP_REPO, target)).catch((err) => { if (err.code !== 'ENOENT') throw err; });
+ await symlink(outsidePath, join(APP_REPO, target), 'file');
+
+ // Save-time validation and use-time validation share the same refusal.
+ await expect(validatePublishBinding(binding)).rejects.toMatchObject({ code: 'INVALID_PUBLISH_PATH' });
+ await expect(publishAtlas(id, { acknowledgeOverwrite: true })).rejects.toMatchObject({ code: 'INVALID_PUBLISH_PATH' });
+ expect(await readFile(outsidePath, 'utf8')).toBe(outsideBefore);
+ expect(await readFile(join(APP_REPO, sourcePath), 'utf8')).toBe(sourceBefore);
+ expect(await readFile(historyPath)).toEqual(historyBefore);
+ expect(await readFile(join(APP_REPO, 'assets/old-atlas.png'), 'utf8')).toBe(atlasBytes);
+ if (target !== sidecarPath(BINDING.atlasDestPath)) {
+ await expect(readFile(join(APP_REPO, sidecarPath(BINDING.atlasDestPath)))).rejects.toMatchObject({ code: 'ENOENT' });
+ }
+ });
+ });
+
+ it('rejects an escaping parent introduced after saving a missing nested output path', async () => {
+ const { id } = await characterWithAtlas();
+ const binding = { ...BINDING, atlasDestPath: 'linked-assets/missing/nested/atlas.png' };
+ await setPublishBinding(id, binding);
+ await writeFile(join(OTHER_APP_REPO, 'sentinel'), 'outside-before');
+ await symlink(OTHER_APP_REPO, join(APP_REPO, 'linked-assets'), 'junction');
+ await expect(validatePublishBinding(binding)).rejects.toMatchObject({ code: 'INVALID_PUBLISH_PATH' });
+ await expect(publishAtlas(id)).rejects.toMatchObject({ code: 'INVALID_PUBLISH_PATH' });
+ expect(await readFile(join(OTHER_APP_REPO, 'sentinel'), 'utf8')).toBe('outside-before');
+ await expect(readFile(join(OTHER_APP_REPO, 'missing/nested/atlas.png'))).rejects.toMatchObject({ code: 'ENOENT' });
+ });
+
+ it('refuses contained and dangling symlinks instead of treating them as ordinary destinations', async () => {
+ await writeFile(join(APP_REPO, 'contained.png'), 'contained-before');
+ for (const target of ['contained.png', 'missing.png']) {
+ const link = join(APP_REPO, 'alias.png');
+ await symlink(join(APP_REPO, target), link, 'file');
+ await expect(validatePublishBinding({ ...BINDING, atlasDestPath: 'alias.png' })).rejects.toMatchObject({ code: 'INVALID_PUBLISH_PATH' });
+ await unlink(link);
+ }
+ await mkdir(join(APP_REPO, 'contained-dir'));
+ await symlink(join(APP_REPO, 'contained-dir'), join(APP_REPO, 'alias-dir'), 'junction');
+ await expect(validatePublishBinding({ ...BINDING, atlasDestPath: 'alias-dir/missing/atlas.png' })).rejects.toMatchObject({ code: 'INVALID_PUBLISH_PATH' });
+ expect(await readFile(join(APP_REPO, 'contained.png'), 'utf8')).toBe('contained-before');
+ });
+
+ it('revalidates a completed output parent before rewriting source', async () => {
+ const { id } = await characterWithAtlas();
+ const sourceBefore = 'load("res://old.png");';
+ await mkdir(join(APP_REPO, 'src'));
+ await writeFile(join(APP_REPO, sourcePath), sourceBefore);
+ await setPublishBinding(id, {
+ ...BINDING, codeBinding: { path: sourcePath, resourcePath: 'res://old.png' },
+ });
+ await publishAtlas(id);
+ const atlasDestPath = 'new-output/nested/atlas.png';
+ await setPublishBinding(id, {
+ ...BINDING, atlasDestPath,
+ codeBinding: { path: sourcePath, resourcePath: 'res://new.png' },
+ });
+ await writeFile(join(OTHER_APP_REPO, 'atlas.png'), 'outside-before');
+ const completedParent = join(await realpath(APP_REPO), 'new-output/nested');
+ filesystemMocks.afterMkdir = async (path) => {
+ if (path !== completedParent) return;
+ filesystemMocks.afterMkdir = null;
+ rmSync(path, { recursive: true });
+ await symlink(OTHER_APP_REPO, path, 'junction');
+ };
+ await expect(publishAtlas(id)).rejects.toMatchObject({ code: 'INVALID_PUBLISH_PATH' });
+ expect(await readFile(join(APP_REPO, sourcePath), 'utf8')).toBe(sourceBefore);
+ expect(await readFile(join(OTHER_APP_REPO, 'atlas.png'), 'utf8')).toBe('outside-before');
+ await expect(readFile(join(OTHER_APP_REPO, 'atlas.layout.json'))).rejects.toMatchObject({ code: 'ENOENT' });
+ });
+
+ it('validates inherited optional destinations before saving an older-client binding', async () => {
+ const { id } = await characterWithAtlas();
+ await setPublishBinding(id, { ...BINDING, portraitDestPath });
+ await mkdir(join(APP_REPO, 'assets/portraits'), { recursive: true });
+ const outsidePath = join(OTHER_APP_REPO, 'portrait.png');
+ await writeFile(outsidePath, 'outside-before');
+ await symlink(outsidePath, join(APP_REPO, portraitDestPath), 'file');
+ await expect(setPublishBinding(id, BINDING)).rejects.toMatchObject({ code: 'INVALID_PUBLISH_PATH' });
+ expect(await readFile(outsidePath, 'utf8')).toBe('outside-before');
+ });
+
+ it('publishes through a configured repository alias while creating contained output directories', async () => {
+ const { id, atlasBytes } = await characterWithAtlas();
+ const alias = join(TEST_ROOT, `repo-alias-${id}`);
+ await symlink(APP_REPO, alias, 'junction');
+ APPS['game-app'].repoPath = alias;
+ await setPublishBinding(id, BINDING);
+ const result = await publishAtlas(id);
+ expect(result.published).toBe(true);
+ expect(await readFile(join(APP_REPO, BINDING.atlasDestPath), 'utf8')).toBe(atlasBytes);
+ expect((await readSidecar(BINDING.atlasDestPath)).kind).toBe('portos-sprite-atlas-layout');
+ expect(isDeploying).toHaveBeenCalledWith(alias);
+ });
+});
+
describe('unreadable publication state', () => {
it.each(['current.json', 'publications.json'])('refuses publication with damaged %s', async (name) => {
const { id } = await characterWithAtlas();