Skip to content

test(runtime): add unit tests for terminal runtime helpers#96736

Merged
vincentkoc merged 1 commit into
openclaw:mainfrom
dwc1997:test/runtime-only
Jun 29, 2026
Merged

test(runtime): add unit tests for terminal runtime helpers#96736
vincentkoc merged 1 commit into
openclaw:mainfrom
dwc1997:test/runtime-only

Conversation

@dwc1997

@dwc1997 dwc1997 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

The runtime.ts module provides terminal runtime helpers for CLI command implementations. However, this module lacked unit tests to verify the runtime behavior, which could lead to regressions when the function is modified.

Why This Change Was Made

Add unit tests for createNonExitingRuntime and writeRuntimeJson functions to verify runtime behavior. This improves test coverage and prevents regressions.

Focused tests cover runtime creation, exit behavior, JSON writing, and error handling.

User Impact

Terminal runtime helpers now have comprehensive test coverage, reducing the risk of regressions when the function is modified.

Evidence

Reproducibility: not applicable. This PR adds direct coverage for existing helper behavior rather than reporting a user-visible runtime bug. Source inspection confirms the helper behavior the tests target.

Direct behavior probe:

$ node --import tsx -e "import('./src/runtime.js').then(({ createNonExitingRuntime, writeRuntimeJson }) => console.log(JSON.stringify([{ desc: 'createNonExitingRuntime returns object', result: typeof createNonExitingRuntime() === 'object' }, { desc: 'createNonExitingRuntime has exit function', result: typeof createNonExitingRuntime().exit === 'function' }, { desc: 'createNonExitingRuntime exit throws', result: (() => { try { createNonExitingRuntime().exit(1); return false; } catch { return true; } })() }, { desc: 'writeRuntimeJson calls writeJson when available', result: (() => { const runtime = { log: () => {}, error: () => {}, exit: () => {}, writeStdout: () => {}, writeJson: () => {} }; writeRuntimeJson(runtime, { key: 'value' }); return true; })() }], null, 2)))"
[
  {
    "desc": "createNonExitingRuntime returns object",
    "result": true
  },
  {
    "desc": "createNonExitingRuntime has exit function",
    "result": true
  },
  {
    "desc": "createNonExitingRuntime exit throws",
    "result": true
  },
  {
    "desc": "writeRuntimeJson calls writeJson when available",
    "result": true
  }
]

Targeted test:

$ node scripts/run-vitest.mjs run src/runtime.test.ts

 RUN  v4.1.8 /home/0668001110/ZTEProject/openclaw-worktrees/pr-94335

 Test Files  1 passed (1)
      Tests  7 passed (7)
   Start at  18:06:38
   Duration  711ms (transform 306ms, setup 306ms, import 44ms, tests 96ms)

[test] passed 1 Vitest shard in 9.57s

Formatting:

$ npx oxfmt --check src/runtime.ts src/runtime.test.ts
Checking formatting...

All matched files use the correct format.
Finished in 51ms on 2 files using 8 threads.

Whitespace:

$ git diff --check

AI-assisted

Prepared with Codex. I reviewed the change, understand the touched code path, and kept the PR focused on the bug described above.

Add unit tests for createNonExitingRuntime and writeRuntimeJson
functions in src/runtime.ts to verify runtime behavior.

Tests cover:
- createNonExitingRuntime returns runtime with exit function
- exit function throws error with code
- writeRuntimeJson writes JSON using writeJson when available
- writeRuntimeJson writes JSON using log when writeJson not available
- uses custom space parameter
- handles zero space parameter
@clawsweeper

clawsweeper Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 25, 2026, 6:19 AM ET / 10:19 UTC.

Summary
The branch adds src/runtime.test.ts with Vitest coverage for createNonExitingRuntime and writeRuntimeJson.

PR surface: Tests +76. Total +76 across 1 file.

Reproducibility: not applicable. this is a test-coverage PR rather than a user-visible bug report. The PR body includes a live helper probe and targeted Vitest output for the behavior being covered.

Review metrics: none identified.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • none.

Next step before merge

  • No ClawSweeper repair lane is needed because the patch has no discrete blocking defect.

Security
Cleared: The diff only adds a Vitest test file and does not change dependencies, workflows, secret handling, packaging, or runtime execution paths.

Review details

Best possible solution:

Land the focused colocated tests after ordinary maintainer review and required checks complete.

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

Not applicable: this is a test-coverage PR rather than a user-visible bug report. The PR body includes a live helper probe and targeted Vitest output for the behavior being covered.

Is this the best way to solve the issue?

Yes: adding a colocated Vitest file is the narrowest maintainable way to cover these existing helpers, and current main does not already have direct duplicate coverage.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 4ecb45bf7729.

Label changes

Label justifications:

  • P3: This is low-risk test coverage for existing terminal runtime helper behavior, with no user-facing runtime change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The contributor provided copied terminal output from a direct helper probe and a targeted Vitest run, which is sufficient for this test-only runtime-helper coverage PR.
  • proof: sufficient: Contributor real behavior proof is sufficient. The contributor provided copied terminal output from a direct helper probe and a targeted Vitest run, which is sufficient for this test-only runtime-helper coverage PR.
Evidence reviewed

PR surface:

Tests +76. Total +76 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 76 0 +76
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 76 0 +76

What I checked:

  • PR diff: The patch adds one colocated Vitest file covering non-exiting runtime exit behavior, writeJson delegation, fallback logging, custom indentation, and zero-space JSON output. (src/runtime.test.ts:1, 7aa3cbcff208)
  • Current helper behavior: Current main defines createNonExitingRuntime and writeRuntimeJson, including the space > 0 ? space : undefined JSON formatting branch the new tests exercise. (src/runtime.ts:98, 4ecb45bf7729)
  • Caller coverage context: A current command caller writes JSON through writeRuntimeJson, while adjacent command tests mock the helper rather than directly asserting helper behavior, so the PR adds unique direct coverage. (src/commands/status-json-command.ts:30, 4ecb45bf7729)
  • Existing test usage: Current tests already use createNonExitingRuntime as a shared test seam in setup flows, which supports covering the helper directly rather than treating it as unused. (src/flows/search-setup.test.ts:184, 4ecb45bf7729)
  • No duplicate colocated test: Current main does not contain src/runtime.test.ts; local and GitHub searches found this PR as the only exact runtime-helper test PR. (src/runtime.test.ts, 4ecb45bf7729)
  • History provenance: Blame and git log -S tie the current helper definitions to commit 0cdb050bac194ac2c5356ed7c877acca38ad81ec, which GitHub maps to jalehman. (src/runtime.ts:98, 0cdb050bac19)

Likely related people:

  • jalehman: GitHub commit metadata maps the commit that currently owns src/runtime.ts and the helper definitions under review to this handle. (role: recent area contributor; confidence: medium; commits: 0cdb050bac19; files: src/runtime.ts)
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.

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.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Jun 25, 2026
@vincentkoc
vincentkoc merged commit 0635a8c into openclaw:main Jun 29, 2026
131 of 136 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 29, 2026
…96736)

Add unit tests for createNonExitingRuntime and writeRuntimeJson
functions in src/runtime.ts to verify runtime behavior.

Tests cover:
- createNonExitingRuntime returns runtime with exit function
- exit function throws error with code
- writeRuntimeJson writes JSON using writeJson when available
- writeRuntimeJson writes JSON using log when writeJson not available
- uses custom space parameter
- handles zero space parameter
QiuYuang pushed a commit to QiuYuang/openclaw that referenced this pull request Jul 1, 2026
…96736)

Add unit tests for createNonExitingRuntime and writeRuntimeJson
functions in src/runtime.ts to verify runtime behavior.

Tests cover:
- createNonExitingRuntime returns runtime with exit function
- exit function throws error with code
- writeRuntimeJson writes JSON using writeJson when available
- writeRuntimeJson writes JSON using log when writeJson not available
- uses custom space parameter
- handles zero space parameter
chenyangjun-xy pushed a commit to chenyangjun-xy/openclaw that referenced this pull request Jul 1, 2026
…96736)

Add unit tests for createNonExitingRuntime and writeRuntimeJson
functions in src/runtime.ts to verify runtime behavior.

Tests cover:
- createNonExitingRuntime returns runtime with exit function
- exit function throws error with code
- writeRuntimeJson writes JSON using writeJson when available
- writeRuntimeJson writes JSON using log when writeJson not available
- uses custom space parameter
- handles zero space parameter
chenyangjun-xy pushed a commit to chenyangjun-xy/openclaw that referenced this pull request Jul 3, 2026
…96736)

Add unit tests for createNonExitingRuntime and writeRuntimeJson
functions in src/runtime.ts to verify runtime behavior.

Tests cover:
- createNonExitingRuntime returns runtime with exit function
- exit function throws error with code
- writeRuntimeJson writes JSON using writeJson when available
- writeRuntimeJson writes JSON using log when writeJson not available
- uses custom space parameter
- handles zero space parameter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

2 participants