SINGULARITY ACCURACY FIXES

Ecosistema completo para organización y gestión de contenido con interfaces espaciales

Singularity Logic Builder - Accuracy Fixes

Date: October 12, 2025 Status: ✅ Completed

Overview

Fixed critical accuracy issues in the Logic Builder where test inputs and port connection status were not reflecting the actual flow configuration.


Issue 1: Test Inputs Not Matching Block Requirements ❌→✅

Problem

The Flow Tester was showing generic test inputs (testValue, testString) instead of detecting the actual required inputs from the logic blocks (e.g., Calculate block needs a and b).

Root Cause

The detectFlowInputs() method was only looking at trigger blocks, not analyzing all blocks to find unconnected required input ports.

Solution

File: libs/singularity-lib/src/lib/components/logic-builder/components/flow-tester/flow-tester.component.ts

// Before: Only looked at trigger blocks
const triggers = f.blocks.filter(b => b.type === 'trigger');

// After: Analyzes ALL blocks for unconnected required inputs
// Create a set of connected input ports
const connectedInputs = new Set<string>();
f.connections.forEach(conn => {
  connectedInputs.add(`${conn.targetBlockId}:${conn.targetPointId}`);
});

// Find all blocks with unconnected required input ports
f.blocks.forEach(block => {
  block.inputs?.forEach(input => {
    const inputKey = `${block.id}:${input.id}`;
    
    // Only add if required and NOT connected
    if (input.required && !connectedInputs.has(inputKey)) {
      inputs.push({
        name: input.name,
        value: this.getDefaultValue(input.dataType),
        type: this.mapDataType(input.dataType)
      });
    }
  });
});

Result


Issue 2: Port Connection Status Always "NOT AVAILABLE" ❌→✅

Problem

All logic block input/output ports were showing as "NOT AVAILABLE" even when they were connected, making it impossible to understand the flow's state.

Root Cause

The isPortConnected() method in logic-block.component.ts was hardcoded to return false:

// Before: Hardcoded to always return false
isPortConnected(port: ConnectionPoint): boolean {
  return false;
}

Solution Implemented

1. Added Connections Input to LogicBlockComponent

File: libs/singularity-lib/src/lib/components/logic-builder/components/logic-block/logic-block.component.ts

// Import LogicConnection type
import { LogicBlock, ConnectionPoint, LogicConnection } from '../../../../types/logic-builder.types';

// Add connections input
@Input() connections: LogicConnection[] = [];

2. Fixed isPortConnected() Method

isPortConnected(port: ConnectionPoint): boolean {
  if (!this.connections || this.connections.length === 0) {
    return false;
  }

  // Check if this port is connected as either source or target
  return this.connections.some(conn => 
    // Check as target (input port)
    (conn.targetBlockId === this.block.id && conn.targetPointId === port.id) ||
    // Check as source (output port)
    (conn.sourceBlockId === this.block.id && conn.sourcePointId === port.id)
  );
}

3. Pass Connections from Parent

File: libs/singularity-lib/src/lib/components/logic-builder/logic-builder.component.html

<app-logic-block
  [block]="block"
  [connections]="canvasConnections()"
  ...other inputs...
/>

Result


Additional Enhancement: Dynamic Test Input Updates

Added OnChanges Lifecycle

File: flow-tester.component.ts

export class FlowTesterComponent implements OnInit, OnChanges {
  ngOnInit(): void {
    this.detectFlowInputs();
  }

  ngOnChanges(): void {
    // Re-detect inputs when flow changes
    this.detectFlowInputs();
  }
}

Benefit


Testing Verification

Test Case 1: Calculate Block with Two Inputs

Setup:

Expected:

Result: ✅ PASS

Test Case 2: Connected Button → Calculate

Setup:

Expected:

Result: ✅ PASS

Test Case 3: Full Flow with All Connections

Setup:

Expected:

Result: ✅ PASS


Files Modified

  1. libs/singularity-lib/src/lib/components/logic-builder/components/flow-tester/flow-tester.component.ts

    • Enhanced detectFlowInputs() to analyze all blocks
    • Added OnChanges for dynamic updates
  2. libs/singularity-lib/src/lib/components/logic-builder/components/logic-block/logic-block.component.ts

    • Added connections input
    • Implemented accurate isPortConnected() logic
  3. libs/singularity-lib/src/lib/components/logic-builder/logic-builder.component.html

    • Pass canvasConnections() to all logic blocks

Impact

Before ❌

After ✅


Next Steps

  1. ✅ Test inputs detection - COMPLETE
  2. ✅ Port connection status - COMPLETE
  3. ⏳ Variable passing between blocks during execution
  4. ⏳ Pre-built flow templates
  5. ⏳ Real-world usage examples

Status: 🎉 100% Accurate Data Display!

The Logic Builder now shows accurate, real-time information about:

All data is synchronized with the actual flow state and updates dynamically! 🚀