Skip to content

fix(cli): fix flaky config set help text test caused by env var leakage and word wrapping#83423

Merged
altaywtf merged 3 commits into
openclaw:mainfrom
medns:fix/config-cli-test-flakiness
May 18, 2026
Merged

fix(cli): fix flaky config set help text test caused by env var leakage and word wrapping#83423
altaywtf merged 3 commits into
openclaw:mainfrom
medns:fix/config-cli-test-flakiness

Conversation

@medns

@medns medns commented May 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Problem: The config cli > config set parsing flags > shows --strict-json... test is flaky.
  • Why it matters: When tests run in the same worker, environment variables like OPENCLAW_PROFILE leak, causing commander to inject flags and word-wrap the help text, breaking the toContain assertions.
  • What changed: Replaced toContain with a whitespace-normalized string match (replace(/\s+/g, " ")) to make the assertions immune to flag injection and line reflowing.
  • What did NOT change (scope boundary): The actual CLI functionality or commander configuration.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Closes #
  • Related #
  • This PR fixes a bug or regression

Real behavior proof (required for external PRs)

  • Behavior or issue addressed: Flaky test failure in config-cli.test.ts due to commander word-wrapping injected flags.
  • Real environment tested: Local Windows environment running Vitest with injected OPENCLAW_PROFILE env vars.
  • Exact steps or command run after this patch:
    $env:OPENCLAW_PROFILE="test-profile-extreme-long-name-that-will-wrap-multiple-times-and-break-everything-in-the-middle-of-the-string"
    pnpm test src/cli/config-cli.test.ts -t "shows --strict-json and keeps --json as a legacy alias in help"
  • Evidence after fix:
    $ node scripts/test-projects.mjs "src/cli/config-cli.test.ts" "-t" "shows --strict-json and keeps --json as a legacy alias in help"
    [test] starting test/vitest/vitest.cli.config.ts
    
     RUN  v4.1.6 D:/openclaw
    
     Test Files  1 passed (1)
          Tests  1 passed | 94 skipped (95)
       Start at  11:47:36
       Duration  3.61s (transform 2.57s, setup 543ms, import 129ms, tests 2.62s, environment 0ms)
    
    [test] passed 1 Vitest shard in 11.60s
    
  • Observed result after fix: The test passes reliably even when the help text is heavily word-wrapped due to long leaked environment variables.
  • What was not tested: None.
  • Before evidence (optional but encouraged):
    AssertionError: expected 'Usage:  config set [options] [path] […' to contain 'config set gateway.port 19001 --stric…'
    - Expected
    + Received
    - config set gateway.port 19001 --strict-json
    + Usage:  config set [options] [path] [value]
    + openclaw --profile test-profile-extreme-long-name-that-will-wrap-multiple-times-and-break-everything-in-the-middle-of-the-string config
    + set gateway.port 19001 --strict-json
    

Root Cause (if applicable)

  • Root cause: commander automatically word-wraps help text based on terminal width and command length. Leaked env vars like OPENCLAW_PROFILE inject flags into the command, pushing the length past the wrap boundary and replacing spaces with newlines, which breaks strict string assertions.
  • Missing detection / guardrail: Tests were assuming a single-line format for help text fragments.
  • Contributing context (if known): Vitest runs tests in shared workers, so env vars set by previous tests persist.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: src/cli/config-cli.test.ts
  • Scenario the test should lock in: Help text parsing with injected flags and word-wrapping.
  • Why this is the smallest reliable guardrail: The test itself is the guardrail.
  • Existing test that already covers this (if any): N/A
  • If no new test is added, why not: The fix is applied directly to the failing test.

User-visible / Behavior Changes

None.

Diagram (if applicable)

N/A

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No
  • If any Yes, explain risk + mitigation: N/A

Repro + Verification

Environment

  • OS: Windows 11
  • Runtime/container: Node.js
  • Model/provider: N/A
  • Integration/channel (if any): N/A
  • Relevant config (redacted): N/A

Steps

  1. Set a long OPENCLAW_PROFILE environment variable.
  2. Run pnpm test src/cli/config-cli.test.ts -t "shows --strict-json and keeps --json as a legacy alias in help".

Expected

  • Test passes.

Actual

  • Test passes.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: Ran the specific test with a very long OPENCLAW_PROFILE to force commander to word-wrap the help text.
  • Edge cases checked: Verified that replacing all whitespace with a single space correctly normalizes both regular spaces and newlines.
  • What you did not verify: Other tests in the file (they don't assert on commander's auto-wrapped output).

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No
  • If yes, exact upgrade steps: N/A

Risks and Mitigations

None.

Copilot AI review requested due to automatic review settings May 18, 2026 03:57
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: XS proof: supplied External PR includes structured after-fix real behavior proof. labels May 18, 2026
@clawsweeper

clawsweeper Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

Workflow note: Future ClawSweeper reviews update this same comment in place.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

Summary
The PR changes src/cli/config-cli.test.ts so the config set help-text assertions normalize whitespace before checking example-command fragments.

Reproducibility: yes. Source inspection shows the asserted examples are passed through env-aware formatCliCommand, and the PR body provides before/after terminal output for the long-profile wrapping case.

PR rating
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster
Patch quality: 🦞 diamond lobster
Summary: Strong focused proof and a small test-only patch leave only ordinary maintainer review and CI before merge.

What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

PR egg
✨ Hatched: 🥚 common Clockwork Patch Peep

        .--^^^^--.           
     .-'  o    o  '-.        
    /       \__/      \      
   |    /\  ____  /\   |     
   |   /  \/____\/  \  |     
    \  \_.------._/  /       
     '._  `----'  _.'        
        '-.____.-'           
       _/|_|  |_|\_          
      /__|      |__\         
       .-----------.         
      '-------------'        

Rarity: 🥚 common.
Trait: hums during re-review.
Share on X: post this hatch
Copy: My PR egg hatched a 🥚 common Clockwork Patch Peep in ClawSweeper.

What is this egg doing here?
  • Eggs appear after the PR passes real-behavior proof. It is here for vibes, not verdicts: it does not change labels, ratings, merge decisions, or automation.
  • The shell reacts to review momentum: open follow-up work warms it up, re-review makes it wobble, and a clean final review lets it hatch.
  • How to hatch it: reach status: 👀 ready for maintainer look or status: 🚀 automerge armed; that usually means sufficient real-behavior proof, no blocking P0/P1/P2 findings, no security attention needed, and clean correctness.
  • The hatch is seeded from this repository and PR number, so the same PR keeps the same creature; the reviewed head SHA can only change safe visual details.
  • Rarity is just collectible sparkle: 🥚 common, 🌱 uncommon, 💎 rare, ✨ glimmer, and 🌈 legendary.

Real behavior proof
Sufficient (terminal): The PR body includes copied before-failure and after-fix Windows terminal output for the affected filtered test with a long OPENCLAW_PROFILE.

Next step before merge
No repair lane is needed because the latest diff has no blocking findings and the remaining action is ordinary maintainer review plus CI.

Security
Cleared: The diff is limited to a CLI test assertion and does not change runtime command execution, secrets, dependencies, workflows, or package metadata.

Review details

Best possible solution:

Land the focused test-only assertion update after ordinary maintainer and CI review so CLI help tests tolerate env-injected prefixes and Commander wrapping without changing runtime behavior.

Do we have a high-confidence way to reproduce the issue?

Yes. Source inspection shows the asserted examples are passed through env-aware formatCliCommand, and the PR body provides before/after terminal output for the long-profile wrapping case.

Is this the best way to solve the issue?

Yes. Normalizing whitespace in the assertion is the narrowest maintainable fix because it keeps checking the important help examples while removing sensitivity to line wrapping and injected CLI prefixes.

Label justifications:

  • P3: This is a low-risk CLI test flake fix with no runtime, config, dependency, or user-facing behavior change.

What I checked:

  • Current main has single-line-sensitive assertions: Current main still checks exact help fragments such as openclaw config set gateway.port 19001 --strict-json, which can fail when Commander reflows the example text. (src/cli/config-cli.test.ts:1227, b2c5ba6d4c4e)
  • Help examples are env-aware: The config set examples are built through formatCliCommand, including the SecretRef and batch examples asserted by the test. (src/cli/config-cli.ts:272, b2c5ba6d4c4e)
  • Environment variables can alter the help command prefix: formatCliCommand reads OPENCLAW_PROFILE and OPENCLAW_CONTAINER_HINT and inserts --profile or --container into CLI examples when appropriate, matching the PR's env-leakage explanation. (src/cli/command-format.ts:12, b2c5ba6d4c4e)
  • Latest PR head preserves meaningful example coverage: At PR head, normalizedHelp is checked for the strict-json example, the SecretRef fragment including --ref-source env --ref-id DISCORD_BOT_TOKEN, and the batch-file dry-run example. (src/cli/config-cli.test.ts:1225, 2fc21aa5a07f)
  • History points to the current CLI help test surface: Blame for the current config set help-text test and adjacent CLI example helpers points to commit f0b43bfd34c42398d3825315e4fabff7c0ab60c4 by Peter Steinberger on 2026-05-18. (src/cli/config-cli.test.ts:1206, f0b43bfd34c4)
  • PR proof is terminal output from the affected environment: The PR body supplies before-failure output and after-fix Windows terminal output for a filtered config-cli.test.ts run with a long OPENCLAW_PROFILE, showing the affected test passing after the patch. (2fc21aa5a07f)

Likely related people:

  • steipete: Current main blame ties the config set help test, the CONFIG_SET_EXAMPLE_* helpers, and formatCliCommand to f0b43bfd34c42398d3825315e4fabff7c0ab60c4, so Peter is the clearest routing candidate for this CLI test surface. (role: recent area contributor; confidence: high; commits: f0b43bfd34c4; files: src/cli/config-cli.test.ts, src/cli/config-cli.ts, src/cli/command-format.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against b2c5ba6d4c4e.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a flaky CLI help-text unit test in config-cli.test.ts by making assertions resilient to commander word-wrapping and environment-driven flag injection (e.g., OPENCLAW_PROFILE/OPENCLAW_CONTAINER_HINT) when tests share a worker.

Changes:

  • Adds whitespace normalization (replace(/\s+/g, " ")) for config set help text before matching.
  • Updates help-text assertions to match stable substrings rather than exact single-line examples.

Comment thread src/cli/config-cli.test.ts Outdated
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels May 18, 2026
@medns medns changed the title test(cli): fix flaky config set help text test caused by env var leakage and word wrapping WIP(cli): fix flaky config set help text test caused by env var leakage and word wrapping May 18, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 18, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels May 18, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 18, 2026
@medns medns force-pushed the fix/config-cli-test-flakiness branch from c79323f to 86d81ac Compare May 18, 2026 08:04
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels May 18, 2026
@medns medns changed the title WIP(cli): fix flaky config set help text test caused by env var leakage and word wrapping fix(cli): fix flaky config set help text test caused by env var leakage and word wrapping May 18, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 18, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 18, 2026
@altaywtf altaywtf assigned steipete and altaywtf and unassigned steipete May 18, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 18, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 18, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 18, 2026
@altaywtf altaywtf merged commit d124c5a into openclaw:main May 18, 2026
100 of 101 checks passed
@altaywtf

Copy link
Copy Markdown
Member

Merged via squash.

Thanks @medns!

karmafeast added a commit to karmaterminal/openclaw that referenced this pull request May 18, 2026
…k / continue_delegate / request_compaction)

This is the continuation feature presented in full against current upstream/main.
Per upstream's stated cadence canon this is XL; opened as DRAFT for review-quality engagement.

Cure-(20)v3 = drift + 2 substrate-restores + 2 surgical test-cascade-fixes:
- Class-1 drift-rebase onto upstream/main d124c5a (3 commits beyond cure-(19)'s parent
  424c6d0: fix(outbound): resolve send-capable channel registry openclaw#83733, fix: keep
  inter-session provenance out of transcripts openclaw#83755, fix(cli): fix flaky config set help
  text test caused by env var leakage and word wrapping openclaw#83423 — all orthogonal to
  orphan-restore + cascade-fix scope)
- Class-2 cure-substrate-original revert restoring 4 deleted files + 1 modified file:
  src/flows/doctor-repair-flow.{ts,test.ts}, src/commands/doctor-session-snapshots.{ts,test.ts},
  src/flows/doctor-health-contributions.ts (4 hunks). All orthogonal to continuation surface
  (0 keyword hits). Caught by local impacted-vitest after cure-(19) Class-2 revert of
  src/config/io.ts.
- Class-3 cascade-fix in src/agents/subagent-registry.test.ts (test substrate only; runtime
  unchanged): added resolveSessionStoreEntry mock (cure-(17) family cascade-miss for cure's
  added call at subagent-registry-helpers.ts:79+102) + renamed/inverted the "preserves run-mode
  keep entries past SESSION_RUN_TTL_MS sweep" test to "sweeps...after cleanup completes" with
  expect(run).toBeUndefined() matching cure's intentional cleanupCompletedAt-based deferred-
  cleanup-sweep policy for continue_delegate lifecycle (cohort byte-walks at Discord
  1506039161 + 1506039225 + 1506039263 confirmed cure-behavior IS correct continuation-feature
  substrate).

Co-Authored-By: scribe.dandelion.cult <scribe.dandelion.cult@hotmail.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
SebTardif pushed a commit to SebTardif/openclaw that referenced this pull request May 24, 2026
…ge and word wrapping (openclaw#83423)

Merged via squash.

Prepared head SHA: 7ba1bac
Co-authored-by: medns <1575008+medns@users.noreply.github.com>
Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com>
Reviewed-by: @altaywtf
SebTardif pushed a commit to SebTardif/openclaw that referenced this pull request May 24, 2026
…ge and word wrapping (openclaw#83423)

Merged via squash.

Prepared head SHA: 7ba1bac
Co-authored-by: medns <1575008+medns@users.noreply.github.com>
Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com>
Reviewed-by: @altaywtf
SebTardif pushed a commit to SebTardif/openclaw that referenced this pull request May 24, 2026
…ge and word wrapping (openclaw#83423)

Merged via squash.

Prepared head SHA: 7ba1bac
Co-authored-by: medns <1575008+medns@users.noreply.github.com>
Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com>
Reviewed-by: @altaywtf
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…ge and word wrapping (openclaw#83423)

Merged via squash.

Prepared head SHA: 7ba1bac
Co-authored-by: medns <1575008+medns@users.noreply.github.com>
Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com>
Reviewed-by: @altaywtf
galiniliev pushed a commit to galiniliev/openclaw that referenced this pull request May 25, 2026
…ge and word wrapping (openclaw#83423)

Merged via squash.

Prepared head SHA: 7ba1bac
Co-authored-by: medns <1575008+medns@users.noreply.github.com>
Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com>
Reviewed-by: @altaywtf
SebTardif pushed a commit to SebTardif/openclaw that referenced this pull request May 26, 2026
…ge and word wrapping (openclaw#83423)

Merged via squash.

Prepared head SHA: 7ba1bac
Co-authored-by: medns <1575008+medns@users.noreply.github.com>
Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com>
Reviewed-by: @altaywtf
SebTardif pushed a commit to SebTardif/openclaw that referenced this pull request May 26, 2026
…ge and word wrapping (openclaw#83423)

Merged via squash.

Prepared head SHA: 7ba1bac
Co-authored-by: medns <1575008+medns@users.noreply.github.com>
Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com>
Reviewed-by: @altaywtf
SebTardif pushed a commit to SebTardif/openclaw that referenced this pull request May 26, 2026
…ge and word wrapping (openclaw#83423)

Merged via squash.

Prepared head SHA: 7ba1bac
Co-authored-by: medns <1575008+medns@users.noreply.github.com>
Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com>
Reviewed-by: @altaywtf
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
…ge and word wrapping (openclaw#83423)

Merged via squash.

Prepared head SHA: 7ba1bac
Co-authored-by: medns <1575008+medns@users.noreply.github.com>
Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com>
Reviewed-by: @altaywtf
SYU8384 pushed a commit to SYU8384/openclaw that referenced this pull request Jun 3, 2026
…ge and word wrapping (openclaw#83423)

Merged via squash.

Prepared head SHA: 7ba1bac
Co-authored-by: medns <1575008+medns@users.noreply.github.com>
Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com>
Reviewed-by: @altaywtf
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
…ge and word wrapping (openclaw#83423)

Merged via squash.

Prepared head SHA: 7ba1bac
Co-authored-by: medns <1575008+medns@users.noreply.github.com>
Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com>
Reviewed-by: @altaywtf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants