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

address review (claude): unit-test toRecordRelativeAssetPath, match importer's leading-slash handling

[._.]/ Adam Eivy8518e3138ca1
diff --git a/server/services/sprites/paths.js b/server/services/sprites/paths.js
index 5cac0834ab..8308b9e25d 100644
--- a/server/services/sprites/paths.js
+++ b/server/services/sprites/paths.js
@@ -50,7 +50,10 @@ export function toRecordRelativeAssetPath(recordId, rawPath) {
if (typeof rawPath !== 'string' || !rawPath) return null;
const marker = `art-source/sprites/${recordId}/`;
const idx = rawPath.indexOf(marker);
- const rel = idx >= 0 ? rawPath.slice(idx + marker.length) : rawPath;
+ // Match importer.js's relToCharacterDir: an already-relative path may still
+ // carry a leading slash (an absolute-style source value) — strip it before
+ // validating, same as the importer's twin function does.
+ const rel = idx >= 0 ? rawPath.slice(idx + marker.length) : rawPath.replace(/^\/+/, '');
if (idx < 0 && /^(art-pipeline|art-source|game)\//.test(rel)) return null;
if (!rel || rel.split(/[\\/]/).some((seg) => seg === '..' || seg === '')) return null;
return rel;
diff --git a/server/services/sprites/paths.test.js b/server/services/sprites/paths.test.js
new file mode 100644
index 0000000000..f19a7be36f
--- /dev/null
+++ b/server/services/sprites/paths.test.js
@@ -0,0 +1,52 @@
+/**
+ * toRecordRelativeAssetPath (#2895 importer follow-up): pure path-rebasing
+ * helper used by walk.js to normalize source-pipeline-relative asset paths
+ * embedded in imported manifests down to the record-relative form PortOS's
+ * own client reads. No PATHS/spriteDir dependency — kept dependency-free so
+ * this suite runs with zero mocking.
+ */
+
+import { describe, it, expect } from 'vitest';
+import { toRecordRelativeAssetPath } from './paths.js';
+
+describe('toRecordRelativeAssetPath', () => {
+ it('strips the source-repo marker for this record', () => {
+ expect(toRecordRelativeAssetPath('pioneer', 'art-source/sprites/pioneer/grok/walk-east-abc/generated/strip.png'))
+ .toBe('grok/walk-east-abc/generated/strip.png');
+ });
+
+ it('passes through an already record-relative path unchanged', () => {
+ expect(toRecordRelativeAssetPath('pioneer', 'grok/walk-east-abc/generated/strip.png'))
+ .toBe('grok/walk-east-abc/generated/strip.png');
+ });
+
+ it('strips a leading slash on an already record-relative path (matches importer.js relToCharacterDir)', () => {
+ expect(toRecordRelativeAssetPath('pioneer', '/grok/walk-east-abc/generated/strip.png'))
+ .toBe('grok/walk-east-abc/generated/strip.png');
+ });
+
+ it('rejects a repo-anchored path outside this record (provenance, not a copied asset)', () => {
+ expect(toRecordRelativeAssetPath('pioneer', 'art-pipeline/sprite-manager/animation_postprocess.py')).toBeNull();
+ expect(toRecordRelativeAssetPath('pioneer', 'game/assets/sprites/pioneer/pioneer-animation-atlas.png')).toBeNull();
+ });
+
+ it('rejects the marker for a DIFFERENT record id (cross-record confinement)', () => {
+ expect(toRecordRelativeAssetPath('pioneer', 'art-source/sprites/trailhand/reference/main.png')).toBeNull();
+ });
+
+ it('rejects traversal segments', () => {
+ expect(toRecordRelativeAssetPath('pioneer', '../../etc/passwd')).toBeNull();
+ expect(toRecordRelativeAssetPath('pioneer', 'grok/../../../etc/passwd')).toBeNull();
+ });
+
+ it('rejects empty path segments', () => {
+ expect(toRecordRelativeAssetPath('pioneer', 'grok//strip.png')).toBeNull();
+ });
+
+ it('rejects missing/empty/non-string input', () => {
+ expect(toRecordRelativeAssetPath('pioneer', '')).toBeNull();
+ expect(toRecordRelativeAssetPath('pioneer', null)).toBeNull();
+ expect(toRecordRelativeAssetPath('pioneer', undefined)).toBeNull();
+ expect(toRecordRelativeAssetPath('pioneer', 42)).toBeNull();
+ });
+});