Skip to content

Tune echo relays and keyset exit flow#8

Merged
AustinKelsay merged 1 commit intomasterfrom
staging
Oct 22, 2025
Merged

Tune echo relays and keyset exit flow#8
AustinKelsay merged 1 commit intomasterfrom
staging

Conversation

@AustinKelsay
Copy link
Copy Markdown
Member

@AustinKelsay AustinKelsay commented Oct 22, 2025

Summary by CodeRabbit

  • New Features

    • Automated and non-interactive runs now support automatic process termination upon completion
    • Environment variables now enable relay configuration for isolated testing scenarios
  • UI Changes

    • Updated setup screen greeting text
  • Tests

    • Added test coverage for environment-based relay override behavior

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Oct 22, 2025

Walkthrough

This pull request refactors relay computation logic to use a centralized computeEchoRelays function with environment-based override support, introduces automated exit behavior for non-interactive CLI runs in ShareSaver, updates corresponding tests, and changes Setup component UI text. Changes span relay resolution, automation control flow, and test coverage.

Changes

Cohort / File(s) Summary
UI text update
src/components/Setup.tsx
Updated Setup component heading from "Get started with FROSTR" to "Bootstrap your FROSTR signing circle"
Non-interactive automation behavior
src/components/keyset/ShareSaver.tsx
Added environment-based gates (IGLOO_DISABLE_RAW_MODE, IGLOO_CLI_NO_INPUT) to control prompting; introduced automatic process.exit() scheduling for non-interactive/automated runs based on share state and automation conditions
Relay computation refactoring
src/components/keyset/useShareEchoListener.ts, src/keyset/echoRelays.ts
Replaced multi-step relay extraction/decoding with centralized computeEchoRelays() call; added IGLOO_TEST_RELAY environment-based override to isolate test/local runs from public relays; restructured logic to prioritize explicit relays over group defaults
Echo relay documentation
src/keyset/echo.ts
Added clarifying comment about computeEchoRelays behavior when IGLOO_TEST_RELAY is set
Test coverage updates
tests/echoRelays.test.ts
Renamed existing test to clarify no-env-override case; removed prior env relay from expected results; added two new test cases for env override scenarios with and without explicit relays

Sequence Diagram(s)

sequenceDiagram
    participant CLI as ShareSaver
    participant Env as Environment
    participant Process as Node Process

    CLI->>Env: Read IGLOO_DISABLE_RAW_MODE<br/>IGLOO_CLI_NO_INPUT
    Env-->>CLI: inputDisabled, isAutomated flags
    
    CLI->>CLI: Compute shouldPrompt =<br/>!(isAutomated && inputDisabled)
    
    alt shouldPrompt = true
        CLI->>CLI: Render "Press Enter to finish"
        Note over CLI: Interactive mode
    else shouldPrompt = false
        alt No active share
            CLI->>Process: Schedule process.exit(0)
            Note over CLI,Process: Auto-exit path
        end
        
        alt autoState → 'done' or 'error'
            CLI->>Process: Schedule process.exit(0/1)
            Note over CLI,Process: Automated exit
        end
    end
Loading
sequenceDiagram
    participant Listener as useShareEchoListener
    participant ComputeFn as computeEchoRelays
    participant Env as Environment
    participant Relays as Relay Endpoints

    Listener->>Env: Read IGLOO_TEST_RELAY
    Env-->>Listener: envRelay value
    
    Listener->>ComputeFn: computeEchoRelays(groupCred,<br/>undefined, envRelay)
    
    alt envRelay provided
        ComputeFn->>ComputeFn: Prioritize envRelay<br/>over defaults
        Note over ComputeFn: Override mode
    else envRelay not provided
        ComputeFn->>ComputeFn: Use explicit relays<br/>+ group defaults
        Note over ComputeFn: Normal resolution
    end
    
    ComputeFn-->>Listener: Deduped relay list
    Listener->>Relays: Connect to relays
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

The changes span multiple domains—UI updates, new automation control flow, relay computation refactoring, and test updates—requiring separate reasoning for each area. Logic modifications in ShareSaver and echoRelays introduce conditional paths and environment-based behavior that need careful verification, while the relay refactoring consolidates decoding logic into a centralized function and adjusts test expectations accordingly.

Possibly related PRs

Poem

🐰 Relays hop in priority, now with env-ears listening close,
Automated exits spring forth when prompts aren't the most,
Dedupe and override dance through computed arrays so neat,
Bootstrap thy signing circle—our refactored fleet complete!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "Tune echo relays and keyset exit flow" directly corresponds to the two main categories of changes in the changeset. The "echo relays" portion accurately reflects the modifications across echoRelays.ts, useShareEchoListener.ts, echo.ts, and related tests that refactor and adjust relay computation logic. The "keyset exit flow" portion accurately reflects the changes in ShareSaver.tsx that introduce automated exit behavior for non-interactive runs. The title is concise, specific, and avoids vague language while providing clear insight into the primary changes from a developer's perspective.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch staging

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/components/keyset/ShareSaver.tsx (1)

145-172: Consider extracting the exit delay constant.

The 20ms delay appears in both exit paths (lines 155 and 170). Consider extracting this as a named constant for clarity and maintainability.

Apply this diff to improve readability:

+const EXIT_DELAY_MS = 20; // Brief delay to ensure UI renders before exit
+
 export function ShareSaver({
   keysetName,
   groupCredential,
   shareCredentials,
   onComplete,
   autoPassword,
   outputDir
 }: ShareSaverProps) {
   ...
   
   useEffect(() => {
     if (!done || shouldPrompt) return;
-    const timer = setTimeout(() => {
+    const timer = setTimeout(() => {
       try {
         if (typeof process !== 'undefined' && typeof process.exit === 'function') {
           process.exit(0);
         }
       } catch {}
-    }, 20);
+    }, EXIT_DELAY_MS);
     return () => clearTimeout(timer);
   }, [done, shouldPrompt]);

   useEffect(() => {
     if (!isAutomated || shouldPrompt) return;
     if (autoState !== 'done' && autoState !== 'error') return;
     const code = autoState === 'done' ? 0 : 1;
-    const timer = setTimeout(() => {
+    const timer = setTimeout(() => {
       try {
         if (typeof process !== 'undefined' && typeof process.exit === 'function') {
           process.exit(code);
         }
       } catch {}
-    }, 20);
+    }, EXIT_DELAY_MS);
     return () => clearTimeout(timer);
   }, [isAutomated, shouldPrompt, autoState]);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4d5d643 and 697f352.

📒 Files selected for processing (6)
  • src/components/Setup.tsx (1 hunks)
  • src/components/keyset/ShareSaver.tsx (3 hunks)
  • src/components/keyset/useShareEchoListener.ts (2 hunks)
  • src/keyset/echo.ts (1 hunks)
  • src/keyset/echoRelays.ts (1 hunks)
  • tests/echoRelays.test.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
**/*.test.ts

📄 CodeRabbit inference engine (AGENTS.md)

**/*.test.ts: Allow colocated test files named feature.test.ts beside implementations
Test files should exercise both happy paths and failure modes

Files:

  • tests/echoRelays.test.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use TypeScript with ESM, 2-space indentation, single quotes, and trailing commas
Order imports from shallow-to-deep
Use camelCase for utility function and variable names
Use SCREAMING_SNAKE_CASE for constants

Files:

  • tests/echoRelays.test.ts
  • src/components/keyset/ShareSaver.tsx
  • src/components/keyset/useShareEchoListener.ts
  • src/components/Setup.tsx
  • src/keyset/echo.ts
  • src/keyset/echoRelays.ts
src/**/*.tsx

📄 CodeRabbit inference engine (CLAUDE.md)

Use Ink components (, , etc.) for terminal UI and do not use HTML elements

Files:

  • src/components/keyset/ShareSaver.tsx
  • src/components/Setup.tsx
src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

All import specifiers must include .js extensions (TypeScript ESM requirement) even though source files are .ts/.tsx

Files:

  • src/components/keyset/ShareSaver.tsx
  • src/components/keyset/useShareEchoListener.ts
  • src/components/Setup.tsx
  • src/keyset/echo.ts
  • src/keyset/echoRelays.ts
src/components/**

📄 CodeRabbit inference engine (CLAUDE.md)

All UI components should live under src/components/

Files:

  • src/components/keyset/ShareSaver.tsx
  • src/components/keyset/useShareEchoListener.ts
  • src/components/Setup.tsx
src/components/**/*.tsx

📄 CodeRabbit inference engine (CLAUDE.md)

When adding a new command, implement it as a component under src/components/

Store reusable UI components under src/components/

Files:

  • src/components/keyset/ShareSaver.tsx
  • src/components/Setup.tsx
src/components/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Name React components using PascalCase

Files:

  • src/components/keyset/ShareSaver.tsx
  • src/components/keyset/useShareEchoListener.ts
  • src/components/Setup.tsx
src/keyset/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

src/keyset/**/*.ts: Keep key exchange and credential helpers under src/keyset/
Document non-obvious flows with concise comments, especially around key lifecycle management

Files:

  • src/keyset/echo.ts
  • src/keyset/echoRelays.ts
🧬 Code graph analysis (2)
tests/echoRelays.test.ts (1)
src/keyset/echoRelays.ts (1)
  • computeEchoRelays (43-84)
src/components/keyset/useShareEchoListener.ts (1)
src/keyset/echoRelays.ts (1)
  • computeEchoRelays (43-84)
🔇 Additional comments (9)
src/components/Setup.tsx (1)

15-15: LGTM! Clearer onboarding message.

The updated text "Bootstrap your FROSTR signing circle" is more specific and descriptive than the previous "Get started with FROSTR".

src/keyset/echo.ts (1)

31-32: LGTM! Helpful clarification.

The comment clearly documents the test isolation behavior when IGLOO_TEST_RELAY is set, improving code maintainability.

src/keyset/echoRelays.ts (2)

50-68: LGTM! Well-documented environment override logic.

The envRelay handling correctly implements test isolation:

  • Returns only envRelay when no explicit relays (full isolation)
  • Merges envRelay with explicit relays when provided (controlled overlap)
  • Skips group/base relays in both env cases to prevent accidental public connections

The deduplication logic properly preserves original casing while using case-insensitive keys.


77-77: LGTM! Correctly excludes envRelay from final deduplication.

Since envRelay is now handled separately in the conditional block above (lines 50-68), removing it from the final deduplication pass is correct and prevents double-processing.

src/components/keyset/ShareSaver.tsx (2)

76-81: LGTM! Environment-driven input control.

The inputDisabled and shouldPrompt flags correctly handle non-interactive/automated environments by checking both IGLOO_DISABLE_RAW_MODE and IGLOO_CLI_NO_INPUT.


125-141: LGTM! Conditional finish prompt.

The finish prompt is correctly rendered only when shouldPrompt is true, preventing hangs in non-interactive environments.

src/components/keyset/useShareEchoListener.ts (1)

58-62: LGTM! Excellent refactoring.

Replacing the local relay resolution logic with a centralized computeEchoRelays call:

  • Eliminates code duplication
  • Simplifies the hook
  • Ensures consistent relay behavior across the codebase
  • Properly handles IGLOO_TEST_RELAY for test isolation
tests/echoRelays.test.ts (2)

23-46: LGTM! Test clarified for no env override scenario.

The test name and parameters now explicitly indicate this tests the non-override path, and the expected results correctly exclude the env relay.


65-83: LGTM! Comprehensive coverage of env override behavior.

The new tests properly verify:

  1. Env override with explicit relays → explicit + env (no group/base)
  2. Env override without explicit relays → only env (full isolation)

This ensures the test isolation behavior works as designed.

@AustinKelsay AustinKelsay merged commit 032f47a into master Oct 22, 2025
3 checks passed
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.

1 participant