lantern

sprout-garden-phase-6-test

Test: Sprout Garden Phase 6

Following [[pattern-looking-glass-development]] - the tests ARE the documentation.

Subject

Phase 6 plot types: rabbit-hole, input, return (sub-gardens and functions)

config

path: null
plots_dir: /Users/graemefawcett/working/ben.fawcett.family/activities/sprout-garden/src/plots/types

Spec

Test: Rabbit Hole Executes Sub-Garden

describe('Rabbit Hole', () => {
  it('executes sub-garden on sprout', () => {
    const hole = createRabbitHole({
      subGarden: tripleRipenGarden
    });
    
    const sprout = { shape: 'circle', color: 'red' };
    const result = hole.grow(sprout);
    
    // circle β†’ square β†’ triangle β†’ star
    expect(result.shape).toBe('star');
    expect(result.color).toBe('red'); // unchanged
  });
  
  it('has pass-through fruits', () => {
    const hole = createRabbitHole({ subGarden: simpleGarden });
    expect(hole.fruits).toContain('pass-through');
  });
  
  it('accepts from all directions', () => {
    const hole = createRabbitHole({ subGarden: simpleGarden });
    expect(hole.seeds.length).toBe(4);
  });
});

Test: Sub-Garden Input/Return

describe('Sub-Garden I/O', () => {
  it('input plot receives sprout from parent', () => {
    const subSim = new SubSimulation(subGarden);
    const sprout = { shape: 'circle', color: 'red' };
    
    subSim.inject(sprout, 'A1'); // Input at A1
    
    expect(subSim.sprouts[0].position).toBe('A1');
  });
  
  it('return plot sends sprout back to parent', () => {
    const subSim = new SubSimulation(subGarden);
    const sprout = { shape: 'circle', color: 'red' };
    
    subSim.inject(sprout);
    const result = subSim.run();
    
    expect(result.returned).toBeDefined();
    expect(result.returned.shape).toBe('star'); // After transforms
  });
});

Test: Recursion Depth Limit

describe('Recursion Safety', () => {
  it('limits recursion depth', () => {
    // Create a rabbit hole that contains itself
    const infiniteHole = createRabbitHole({
      id: 'infinite',
      subGarden: {
        plots: {
          'A1': { type: 'input' },
          'A2': { type: 'rabbit-hole', ref: 'infinite' }, // Self-reference!
          'A3': { type: 'return' }
        }
      }
    });
    
    const sprout = { shape: 'circle', color: 'red' };
    const result = infiniteHole.grow(sprout, 0);
    
    expect(result.status).toBe('recursion-overflow');
  });
  
  it('allows reasonable nesting depth', () => {
    // 5 levels deep should be fine
    const sprout = { shape: 'circle', color: 'red' };
    const result = nestedHoles.grow(sprout, 0);
    
    expect(result.status).not.toBe('recursion-overflow');
  });
  
  it('tracks depth correctly', () => {
    const hole = createRabbitHole({ subGarden: simpleGarden });
    
    // Should pass depth to sub-simulation
    const subSim = hole.createSubSimulation();
    expect(subSim.depth).toBe(1);
  });
});

Test: Function Library

describe('Function Library', () => {
  it('saves rabbit hole to library', () => {
    const library = getFunctionLibrary();
    const hole = createRabbitHole({
      id: 'my-function',
      name: 'My Function',
      subGarden: simpleGarden
    });
    
    library.save(hole);
    
    expect(library.has('my-function')).toBe(true);
  });
  
  it('loads rabbit hole from library', () => {
    const library = getFunctionLibrary();
    const hole = library.get('triple-ripen');
    
    expect(hole).toBeDefined();
    expect(hole.subGarden).toBeDefined();
  });
  
  it('lists all saved functions', () => {
    const library = getFunctionLibrary();
    const functions = library.list();
    
    expect(Array.isArray(functions)).toBe(true);
  });
  
  it('persists to localStorage', () => {
    const library = getFunctionLibrary();
    library.save(testHole);
    
    // Reload library
    const newLibrary = new FunctionLibrary();
    expect(newLibrary.has(testHole.id)).toBe(true);
  });
});

Test: Sub-Garden UI

describe('Sub-Garden UI', () => {
  it('can zoom into rabbit hole', () => {
    openSubGarden('triple-ripen');
    
    expect(gardenStack.length).toBe(1);
    expect(currentGarden.id).toBe('triple-ripen-sub');
  });
  
  it('can return from sub-garden', () => {
    openSubGarden('triple-ripen');
    closeSubGarden();
    
    expect(gardenStack.length).toBe(0);
    expect(currentGarden.id).toBe('main');
  });
  
  it('shows breadcrumb path', () => {
    openSubGarden('triple-ripen');
    openSubGarden('nested-function');
    
    expect(getBreadcrumb()).toEqual(['Main', 'triple-ripen', 'nested-function']);
  });
});

Results

{
  "summary": "0/5 tests passing",
  "phase": "Phase 6: Rabbit Holes",
  "status": "not yet implemented",
  "tests": [
    {
      "test": "rabbit-hole.js exists",
      "status": "fail",
      "details": "not yet implemented"
    },
    {
      "test": "input.js exists",
      "status": "fail",
      "details": "not yet implemented"
    },
    {
      "test": "return.js exists",
      "status": "fail",
      "details": "not yet implemented"
    },
    {
      "test": "sub-simulation.js exists",
      "status": "fail",
      "details": "not yet implemented"
    },
    {
      "test": "functions.js exists",
      "status": "fail",
      "details": "not yet implemented"
    }
  ]
}

Provenance

Fences

test-rabbit-hole-basic

  • Status: Spec only (Phase 6 not implemented)
  • By: Claude (2025-11-29)
  • Note: Basic rabbit hole execution

test-sub-garden-io

  • Status: Spec only
  • By: Claude (2025-11-29)
  • Note: Input/return plot behavior

test-recursion-limit

  • Status: Spec only
  • By: Claude (2025-11-29)
  • Note: Recursion safety

test-function-library

  • Status: Spec only
  • By: Claude (2025-11-29)
  • Note: Save/load functions

test-sub-garden-ui

  • Status: Spec only
  • By: Claude (2025-11-29)
  • Note: Zoom in/out UI

sprout-garden-phase-6-results

  • Status: Verified (checks for implementation)
  • By: Claude (2025-11-29)
  • Note: Reports Phase 6 implementation status

Slots

North

slots:
- sprout-garden-phase-6

South

slots: []

East

slots: []

West

slots:
- pattern-looking-glass-development
↑ northsprout-garden-phase-6