Skip to content

Conversation

@yannrichet
Copy link
Member

No description provided.

Implements support for connecting to legacy Java Funz calculator servers
via the Funz protocol. This allows FZ to integrate with existing Funz
server infrastructure.

Features:
- Text-based TCP socket communication with Funz servers
- Calculator reservation and authentication
- Automatic file upload/download
- Result archive extraction
- Interrupt handling support
- Automatic cleanup and unreservation

Usage:
  calculators = "funz://:5555/R"
  calculators = "funz://server.example.com:5555/Python"

Protocol implementation based on:
https://github.com/Funz/funz-client/blob/master/src/main/java/org/funz/run/Client.java

Changes:
- fz/runners.py: Add run_funz_calculation() and funz:// URI support
- tests/test_funz_runner.py: Add basic tests for Funz runner
- README.md: Document Funz server execution in Calculator Types
- CLAUDE.md: Update runners.py description
Adds a dedicated GitHub Actions workflow to test Funz calculator
integration with real Java Funz calculator servers.

CI Workflow (.github/workflows/funz-calculator.yml):
- Ubuntu-only workflow to reduce CI minutes usage
- Sets up Java 11 and Python 3.11
- Clones and builds funz-core, funz-client, and funz-calculator
- Starts 3 calculator instances on ports 5555, 5556, 5557
- Runs integration tests with actual Funz servers
- Captures and displays logs on failure
- Gracefully stops calculators on completion

Integration Tests (tests/test_funz_integration.py):
- test_funz_sequential_simple_calculation: Tests sequential execution
  with a single Funz calculator using shell-based calculations
- test_funz_parallel_calculation: Tests parallel execution with 3
  Funz calculators, verifying parallel speedup
- test_funz_error_handling: Tests graceful error handling when
  calculations fail

Features:
- Real Funz server testing (not mocked)
- Tests both sequential and parallel execution modes
- Verifies calculation correctness
- Validates parallel performance improvements
- Tests error handling and recovery

The workflow ensures that the funz:// calculator type works correctly
with legacy Java Funz servers in both sequential and parallel modes.
The funz-core build requires funz-profile to be present for the
funz.properties file. Added a step to clone funz-profile before
building funz-core to resolve the build error.

Fixes: /home/runner/work/fz/fz/funz-core/build.xml:8 error
Updated the CI workflow to use the same Java command pattern as
FunzDaemon_start.sh from the official Funz calculator scripts.

Changes:
- Copy FunzDaemon_start.sh to dist directory
- Create separate calculator-{port}.xml config for each instance
- Build classpath following FunzDaemon_start.sh pattern (all lib/*.jar)
- Use proper Java command: java -Dapp.home=. -classpath $LIB
  org.funz.calculator.Calculator file:calculator-{port}.xml
- Run calculators from dist/ directory where all JARs are located
- Create separate spool directories for each calculator instance
- Update log file paths to dist/calculator_{port}.log

This matches the official Funz startup mechanism and should properly
initialize the calculator daemon processes.
The Calculator class expects uppercase XML elements per Calculator.java.

Changes:
- Fix XML root: <calculator> → <CALCULATOR> (uppercase required)
- Use proper XML structure with CODE and HOST elements:
  <CODE cplugin="shell">bash</CODE>
  <HOST>127.0.0.1</HOST>
- Add CALCULATOR attributes: name, port, spool
- Add extensive debug output to startup section:
  - Show classpath being built
  - Display Java command being executed
  - Show initial log output immediately after each calculator starts (2s delay)
  - Display configuration file content for verification

This should resolve the "wrong XML document calculator" error from
Calculator.loadConf() at line 582.
Remove cplugin attribute and use simple CODE elements without
requiring plugin JARs. This creates a minimal configuration that
just specifies script executables (bash, sh, shell) directly.

Changes:
- Remove cplugin="shell" attribute from CODE elements
- Use plain <CODE>bash</CODE> instead of <CODE cplugin="shell">bash</CODE>
- Add simple wrapper script run_shell.sh for execution
- Support bash, sh, and shell as code names
- Minimal configuration without plugin dependencies

This should work with the basic Funz calculator without needing
separate plugin JAR files.
The HOST element requires 'name' and 'port' attributes for remote
execution hosts. Since we're running calculators locally, we don't
need HOST elements at all.

Changes:
- Remove <HOST>127.0.0.1</HOST> from all calculator configs
- Use minimal configuration with just CALCULATOR attributes and CODE elements
- Remove unnecessary run_shell.sh wrapper script

This fixes the NumberFormatException when Host constructor tries to
parse empty port attribute at Host.java:31.
The proper Funz calculator.xml structure uses attributes:
- <HOST name="127.0.0.1" port="5555" />
- <CODE name="bash" command="/bin/bash" />

Not text content like <CODE>bash</CODE>.

Changes:
- HOST element: Add name and port attributes
- CODE element: Add name and command attributes
- Remove port attribute from CALCULATOR element (it's in HOST)
- Use self-closing tags for HOST and CODE elements

This matches the expected XML structure that Host and Code
constructors parse (Host.java:31 expects name and port attributes).
Temporarily disable non-Funz CI workflows to focus on Funz calculator
integration testing. Remove TCP port checking since Funz uses UDP for
discovery.

Changes:
- Disable main CI (ci.yml) for claude/* branches
- Temporarily disable: cli-tests, ssh-localhost, examples, docs, README
- Remove check_port_available() - not needed (Funz uses UDP discovery)
- Remove check_funz_calculators fixture
- Tests now directly attempt calculations without pre-checking ports
- Calculators announce themselves via UDP, so TCP check is irrelevant

The integration tests will now just try to run calculations and fail
gracefully if calculators aren't available, relying on Funz's UDP-based
discovery mechanism.
The fzr() function doesn't accept a timeout parameter, which was
causing test failures with 'unexpected keyword argument' error.

Changes:
- Remove timeout=30 from sequential test
- Remove timeout=60 from parallel test
- Remove timeout=15 from error handling test

Timeout handling is done internally by the calculator runners,
not as a parameter to fzr().
The 'port' attribute on the <CALCULATOR> element makes the calculator
listen for incoming TCP connections. The <HOST> elements are for
defining remote execution hosts, not the calculator's listening port.

Changes:
- Add port="5555" attribute to CALCULATOR element (was missing)
- Remove HOST elements (not needed for local TCP listening)
- Keep CODE elements with name and command attributes

This should fix the 'Connection refused' errors - calculators will now
listen on TCP ports 5555, 5556, 5557 for incoming Funz protocol connections.
- Added <HOST name="localhost" /> to all three calculators (5555, 5556, 5557)
- HOST element is mandatory per Funz requirements
- Defines where calculator runs (localhost for local execution)
- Updated comments to clarify port and HOST element purposes
- Removed port attribute from CALCULATOR element
- Added port attribute to HOST element (5555, 5556, 5557)
- HOST port is UDP broadcast port where daemon sends availability info every 5s
- TCP port for client connections is communicated in UDP messages
- Updated comments to clarify correct Funz architecture
@yannrichet-asnr yannrichet-asnr force-pushed the claude/add-funz-runner-support-01SifVDFcYc6HT3Fudv4U6rq branch from 8ff48b9 to a217d78 Compare November 23, 2025 20:09
Enhanced debug information for troubleshooting:
- URI parsing steps with detailed logging
- Socket connection details (local/remote addresses, timeouts)
- Protocol message tracking (sent → and received ←)
- Step-by-step progress indicators with emojis
- File upload/download progress with byte counts
- Execution timing and timestamps
- ZIP archive extraction details
- Enhanced error messages with context and stack traces
- Socket state and cleanup logging

Debug output now includes:
- Connection establishment details
- Calculator reservation with secret codes
- Individual file upload progress
- Case creation confirmation
- Execution timing and status
- Download progress tracking
- Archive extraction file lists
- Unreserve acknowledgment
- Detailed error diagnostics for timeouts and socket errors

This will help diagnose issues with:
- Connection failures (timeout, refused, etc.)
- Protocol errors (unexpected responses)
- File transfer problems
- Execution failures
- Result download issues
Implements Python equivalents of Java tests from:
- NetworkTest.java (funz-calculator)
- ClientTest.java (funz-client)

New test file: tests/test_funz_protocol.py

Test Coverage:
- Low-level TCP protocol communication
- Connection/disconnection handling
- Calculator reservation and unreservation
- File upload/download via protocol
- Full protocol cycle (reserve → upload → execute → download → unreserve)
- Multiple sequential cases (like test10Cases)
- Concurrent client connections (like testListening)
- Reservation timeout behavior (like testReserveTimeOut)
- Failed execution handling (like testFailedCase)
- Client disconnection during operation (like testCaseBreakClient)
- Activity and info queries

FunzProtocolClient class:
- Low-level protocol implementation
- Methods: connect, reserve, unreserve, put_file, execute, get_results
- Protocol constants matching Java implementation
- Support for heartbeats, info messages, and error handling

Test methods:
1. test_connection - Basic TCP connection
2. test_reserve_unreserve - Reservation cycle
3. test_get_activity - Activity status queries
4. test_get_info - Calculator info queries
5. test_full_protocol_cycle - Complete protocol flow
6. test_multiple_sequential_cases - Sequential case execution
7. test_concurrent_clients - Multiple simultaneous connections
8. test_reserve_timeout_behavior - Auto-unreserve after timeout
9. test_failed_execution - Invalid code handling
10. test_disconnect_during_reservation - Unexpected disconnection

CI Integration:
- Added protocol test step to funz-calculator.yml workflow
- Runs before integration tests with DEBUG logging
- Tests against calculator on port 5555
@yannrichet-asnr yannrichet-asnr merged commit 20a5b0c into main Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants