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

3.2 KB
Raw Blame
import { describe, expect, it } from 'vitest';
import { createHash } from 'node:crypto';
import { buildEidoverseCitySurface } from './eidoverseCitySurface.js';
import { EIDOVERSE_WORLD_DESIGN_V3 } from './eidoverseWorldDesign.js';

// Serialization boundary: readers require exact chunk lengths, finite accessors,
// valid indices, and an entirely self-contained artifact on every install.
describe('Commons portable GLB', () => {
  it('encodes valid self-contained geometry at a stable content address', () => {
    const first = buildEidoverseCitySurface(EIDOVERSE_WORLD_DESIGN_V3.districts);
    expect(buildEidoverseCitySurface([...EIDOVERSE_WORLD_DESIGN_V3.districts].reverse())).toEqual(first);
    const { bytes } = first;
    expect(bytes.length).toBeLessThan(1_500_000);
    expect(bytes.readUInt32LE(0)).toBe(0x46546c67);
    expect(bytes.readUInt32LE(4)).toBe(2);
    expect(bytes.readUInt32LE(8)).toBe(bytes.length);
    const jsonLength = bytes.readUInt32LE(12);
    const gltf = JSON.parse(bytes.subarray(20, 20 + jsonLength).toString());
    const binStart = 28 + jsonLength;
    expect(bytes.readUInt32LE(24 + jsonLength)).toBe(0x004e4942);
    expect(gltf.buffers).toEqual([{ byteLength: bytes.length - binStart }]);
    expect(gltf.images).toBeUndefined();
    const land = gltf.accessors[gltf.meshes[0].primitives[0].attributes.POSITION];
    const ocean = gltf.accessors[gltf.meshes[2].primitives[0].attributes.POSITION];
    expect(land.max[1]).toBeGreaterThan(200); // Mountain silhouettes beyond town.
    expect(ocean.max[0]).toBeGreaterThan(7000); // No nearby rectangular stage edge.
    expect(ocean.min[0]).toBeLessThan(-7000);
    expect(ocean.max[1]).toBeLessThan(0); // Water cannot cover the arrival plaza.
    const legacy = buildEidoverseCitySurface(EIDOVERSE_WORLD_DESIGN_V3.districts, { landscape: false });
    const legacyJson = JSON.parse(legacy.bytes.subarray(20, 20 + legacy.bytes.readUInt32LE(12)).toString());
    expect(legacyJson.meshes).toHaveLength(2); // Older collision grids keep their compact scene.
    expect(legacy.bytes.length).toBeLessThan(1_000_000);
    for (const mesh of gltf.meshes) for (const primitive of mesh.primitives) {
      const positions = gltf.accessors[primitive.attributes.POSITION];
      expect(positions.count).toBeGreaterThan(0);
      const indices = gltf.accessors[primitive.indices];
      const view = gltf.bufferViews[indices.bufferView];
      const references = Array.from({ length: indices.count }, (_, i) => bytes.readUInt32LE(binStart + view.byteOffset + i * 4));
      expect(references.every((index) => index < positions.count)).toBe(true);
    }
    for (const accessor of gltf.accessors) {
      expect([...accessor.min, ...accessor.max].every(Number.isFinite)).toBe(true);
      const view = gltf.bufferViews[accessor.bufferView];
      expect(view.byteOffset + view.byteLength).toBeLessThanOrEqual(gltf.buffers[0].byteLength);
      expect(view.byteOffset % 4).toBe(0);
    }
    expect(first.path).toBe(`store/${createHash('sha256').update(bytes).digest('hex').slice(0, 16)}.glb`);
    const renamed = structuredClone(EIDOVERSE_WORLD_DESIGN_V3.districts);
    renamed[0].label = 'Example civic hall';
    expect(buildEidoverseCitySurface(renamed).path).not.toBe(first.path);
  });
});