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

8.4 KB
Raw Blame
import { describe, it, expect } from 'vitest';
import { castAndSetsApprovalInputs, castAndSetsApprovalValues, productionReadiness, revertApprovedInput } from './productionReview.js';

const castAndSetsApproval = (project) => productionReadiness(project).castAndSets;

// Approval records the labeled inputs it was granted on, so a later change can be named.
const approvedArt = (project) => ({ ...project, productionReview: { ...project.productionReview,
  approvals: { art: { stage: 'art', basis: productionReadiness(project).basis.art, inputs: productionReadiness(project).inputs.art, approvedAt: '2026-01-01T00:00:00.000Z' } } } });

describe('stale approval reporting', () => {
  const base = { id: 'p1', concept: 'Example concept', scenes: [{ sceneId: 's1', startSec: 0, endSec: 4, prompt: 'a' }, { sceneId: 's2', startSec: 4, endSec: 8, prompt: 'b' }], productionReview: { draft: {} } };

  it('names the changed inputs once an approved basis moves', () => {
    const approved = approvedArt(base);
    expect(productionReadiness(approved).art.stale).toBeNull();
    const changed = { ...approved, concept: 'Different concept' };
    expect(productionReadiness(changed).art.stale).toEqual({ approvedAt: '2026-01-01T00:00:00.000Z', changedFields: ['concept'] });
  });

  it('reports no stale state for a stage that was never approved', () => {
    expect(productionReadiness(base).art.stale).toBeNull();
  });

  it('labels per-scene edits for the storyboard stage', () => {
    const inputs = productionReadiness(base).inputs.storyboard;
    const edited = productionReadiness({ ...base, scenes: [base.scenes[0], { ...base.scenes[1], prompt: 'c' }] }).inputs.storyboard;
    expect(Object.keys(edited).filter(k => edited[k] !== inputs[k])).toEqual(['scene 2 prompt']);
  });
});

describe('Cast & Sets approval basis', () => {
  const project = { id: 'p1', trackId: 't1', concept: { prompt: 'Example concept', style: 'ink', subjects: [{ id: 's1' }] },
    visualSpec: { palette: ['#000000'], references: [{ id: 'r1', imageId: 'a.png', role: 'character' }] } };
  const approved = (p) => ({ ...p, castAndSets: { status: 'approved', approvedAt: '2026-01-01T00:00:00.000Z', approvedInputs: castAndSetsApprovalInputs(p) } });

  it('names concept, style, subject and song changes separately', () => {
    const base = approved(project);
    expect(castAndSetsApproval(base)).toEqual({ approved: true, stale: null });
    const edited = { ...base, trackId: 't2', concept: { ...project.concept, style: 'oil' }, visualSpec: { ...project.visualSpec, references: [] } };
    expect(castAndSetsApproval(edited).stale.changedFields).toEqual(['style', 'subjects', 'song']);
  });

  it('ignores a reference re-normalized with default fields, and never flags a legacy approval without recorded inputs', () => {
    const base = approved(project);
    const normalized = { ...base, visualSpec: { ...project.visualSpec, typography: '', references: [{ id: 'r1', imageId: 'a.png', role: 'character', note: '', use: 'reference', condition: false }] } };
    expect(castAndSetsApproval(normalized).stale).toBeNull();
    const legacy = { ...project, concept: { prompt: 'Changed' }, castAndSets: { status: 'approved', approvedAt: '2026-01-01T00:00:00.000Z' } };
    expect(castAndSetsApproval(legacy)).toEqual({ approved: true, stale: null });
  });
});

describe('saving cast to the catalog after approval', () => {
  const project = { id: 'p1', concept: { prompt: 'Example concept', subjects: [{ id: 'cs-protagonist', kind: 'character', name: 'Ada' }, { id: 's2', kind: 'place', name: 'Diner' }] },
    visualSpec: {}, scenes: [], productionReview: { draft: {} } };
  const stamp = (p) => ({ ...p, concept: { ...p.concept, subjects: [{ ...p.concept.subjects[0], ingredientId: 'cat-chr-1' }, { ...p.concept.subjects[1], localOnly: true }] } });

  it('leaves the Cast & Sets and art approvals current, and a subject revert keeps the catalog link', () => {
    const approved = approvedArt({ ...project, castAndSets: { status: 'approved', approvedAt: '2026-01-01T00:00:00.000Z', approvedInputs: castAndSetsApprovalInputs(project), approvedValues: castAndSetsApprovalValues(project) } });
    const stamped = stamp(approved);
    expect(castAndSetsApproval(stamped).stale).toBeNull();
    expect(productionReadiness(stamped).art.stale).toBeNull();

    const renamed = { ...stamped, concept: { ...stamped.concept, subjects: [{ ...stamped.concept.subjects[0], name: 'Ada Lane' }, stamped.concept.subjects[1]] } };
    const reverted = revertApprovedInput(renamed, { stage: 'castAndSets', field: 'subjects' });
    expect(reverted.concept.subjects).toEqual(stamp(project).concept.subjects);
  });
});

describe('reverting a Cast & Sets approval (#10241)', () => {
  const project = { id: 'p1', concept: { prompt: 'Example concept', style: 'ink', subjects: [{ id: 's1' }] }, visualSpec: { palette: ['#000000'] } };
  const approved = { ...project, castAndSets: { status: 'approved', approvedInputs: castAndSetsApprovalInputs(project), approvedValues: castAndSetsApprovalValues(project) } };

  it('restores concept, style and subjects independently and clears the stale note', () => {
    const edited = { ...approved, concept: { prompt: 'Other', style: 'oil', subjects: [] }, visualSpec: { palette: ['#ffffff'] } };
    expect(productionReadiness(edited).castAndSets.stale.revertible).toEqual(['concept', 'style', 'subjects']);
    let next = edited;
    for (const field of ['concept', 'style', 'subjects']) next = revertApprovedInput(next, { stage: 'castAndSets', field });
    expect(next.concept).toEqual(project.concept);
    expect(next.visualSpec.palette).toEqual(['#000000']);
    expect(productionReadiness(next).castAndSets.stale).toBeNull();
  });

  it('refuses a legacy approval that kept no values', () => {
    const legacy = { ...approved, concept: { prompt: 'Other' }, castAndSets: { ...approved.castAndSets, approvedValues: undefined } };
    expect(() => revertApprovedInput(legacy, { stage: 'castAndSets', field: 'concept' })).toThrow(/not kept/);
  });
});

describe('storyboard camera (#10589)', () => {
  const scenes = [
    { sceneId: 's1', label: 'Verse 1', sectionLabel: 'Verse', sectionIndex: 0, startSec: 0, endSec: 4, prompt: 'a', camera: { move: 'locked-off', reason: 'the singer holds still' } },
    { sceneId: 's2', label: 'Verse 2', sectionLabel: 'Verse', sectionIndex: 0, startSec: 4, endSec: 8, prompt: 'b', camera: { move: 'locked-time-lapse', reason: 'clouds race' } },
    { sceneId: 's3', label: 'Verse 3', sectionLabel: 'Verse', sectionIndex: 0, startSec: 8, endSec: 12, prompt: 'c' },
    { sceneId: 's4', label: 'Chorus 1', sectionLabel: 'Chorus', sectionIndex: 1, startSec: 12, endSec: 16, prompt: 'd', camera: { move: 'truck-left' } },
  ];
  const project = { id: 'p1', scenes, productionReview: { draft: { storyboard: [{ sceneId: 's3', camera: 'Static tripod frame on the hands' }] } } };

  it('flags a static run (reading free-text draft cameras) and a chorus with no snap, without blocking', () => {
    const { storyboard } = productionReadiness(project);
    expect(storyboard.camera.staticRuns).toEqual([['Verse 1', 'Verse 2', 'Verse 3']]);
    expect(storyboard.camera.snaplessChoruses).toEqual([{ label: 'Chorus', startSec: 12 }]);
    expect(storyboard.camera.notes).toHaveLength(2);
    expect(storyboard.problems.some((problem) => /static|snap/i.test(problem))).toBe(false);
  });

  it('clears the chorus note once the chorus snaps', () => {
    const snapped = { ...project, scenes: scenes.map((s) => (s.sceneId === 's4' ? { ...s, camera: { move: 'whip-pan', onBeat: true } } : s)) };
    expect(productionReadiness(snapped).storyboard.camera.snaplessChoruses).toEqual([]);
  });

  it('labels a camera edit and leaves the basis of camera-less boards unchanged', () => {
    const plain = { id: 'p1', scenes: scenes.map(({ camera, ...s }) => s), productionReview: { draft: {} } };
    const before = productionReadiness(plain);
    const withCamera = productionReadiness({ ...plain, scenes: plain.scenes.map((s, i) => (i === 3 ? { ...s, camera: { move: 'whip-pan' } } : s)) });
    expect(Object.keys(withCamera.inputs.storyboard).filter((k) => withCamera.inputs.storyboard[k] !== before.inputs.storyboard[k])).toEqual(['scene 4 camera']);
    expect(withCamera.basis.storyboard).not.toBe(before.basis.storyboard);
    const undefinedCamera = productionReadiness({ ...plain, scenes: plain.scenes.map((s) => ({ ...s, camera: undefined })) });
    expect(undefinedCamera.basis.storyboard).toBe(before.basis.storyboard);
  });
});