fix(cli): warn that telegram/discord/slack presets don't enable messaging - #1898
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds an exported helper that returns a user-facing warning for messaging presets Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/policies.test.ts (1)
754-762: Consider asserting warning appears before confirmation prompt.The current test validates message presence; adding an ordering assertion would lock in the UX-critical sequencing.
Suggested test hardening
it("warns the user that the telegram preset alone does not enable Telegram messaging", () => { const result = runPolicyAdd("y", [], "telegram"); expect(result.status).toBe(0); expect(result.stdout).toMatch( /Note: the 'telegram' preset only opens network egress to the Telegram API\./, ); expect(result.stdout).toMatch(/re-run 'nemoclaw onboard' and select Telegram/); + const warningIdx = result.stdout.indexOf("Note: the 'telegram' preset only opens network egress"); + const promptIdx = result.stdout.indexOf("Apply 'telegram' to sandbox 'test-sandbox'?"); + expect(warningIdx).toBeGreaterThanOrEqual(0); + expect(promptIdx).toBeGreaterThanOrEqual(0); + expect(warningIdx).toBeLessThan(promptIdx); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/policies.test.ts` around lines 754 - 762, The test "warns the user that the telegram preset alone does not enable Telegram messaging" currently only checks that two messages exist; update the assertion to lock in ordering by verifying the warning about the 'telegram' preset appears before the confirmation prompt text in runPolicyAdd's output. Locate the spec (the it block) and add an ordering check using result.stdout.indexOf(...) or a regex capture to ensure the warning string (/Note: the 'telegram' preset only opens network egress to the Telegram API\./) has a lower index than the confirmation prompt string (/re-run 'nemoclaw onboard' and select Telegram/), failing the test if the prompt appears first.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@test/policies.test.ts`:
- Around line 754-762: The test "warns the user that the telegram preset alone
does not enable Telegram messaging" currently only checks that two messages
exist; update the assertion to lock in ordering by verifying the warning about
the 'telegram' preset appears before the confirmation prompt text in
runPolicyAdd's output. Locate the spec (the it block) and add an ordering check
using result.stdout.indexOf(...) or a regex capture to ensure the warning string
(/Note: the 'telegram' preset only opens network egress to the Telegram API\./)
has a lower index than the confirmation prompt string (/re-run 'nemoclaw
onboard' and select Telegram/), failing the test if the prompt appears first.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 94a999bb-e6ac-4b87-bffd-42b0ef049800
📒 Files selected for processing (3)
src/lib/policies.tssrc/nemoclaw.tstest/policies.test.ts
|
Added the ordering assertion ( |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/policies.test.ts (1)
23-65: Consider cleaning up temporary test directories afterspawnSync.
runPolicyAddcreates a unique temp directory per invocation and never removes it. This can accumulate temp files across local/CI runs.♻️ Proposed cleanup
function runPolicyAdd(confirmAnswer, extraArgs = [], presetName = "pypi") { const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-policy-add-")); const scriptPath = path.join(tmpDir, "policy-add-check.js"); const script = String.raw` @@ `; fs.writeFileSync(scriptPath, script); - return spawnSync(process.execPath, [scriptPath], { - cwd: REPO_ROOT, - encoding: "utf-8", - env: { - ...process.env, - HOME: tmpDir, - }, - }); + try { + return spawnSync(process.execPath, [scriptPath], { + cwd: REPO_ROOT, + encoding: "utf-8", + env: { + ...process.env, + HOME: tmpDir, + }, + }); + } finally { + fs.rmSync(tmpDir, { recursive: true, force: true }); + } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/policies.test.ts` around lines 23 - 65, runPolicyAdd creates a temp directory via fs.mkdtempSync (tmpDir) and writes scriptPath but never removes it; update runPolicyAdd to ensure the temporary directory is removed after spawnSync finishes (and on errors) by wrapping the spawnSync call in a try/finally or equivalent and deleting tmpDir (e.g., fs.rmSync or fs.rmdirSync with recursive/force options) in the finally block so cleanup always runs; keep references to tmpDir and scriptPath so you remove the written file(s) and directory.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@test/policies.test.ts`:
- Around line 23-65: runPolicyAdd creates a temp directory via fs.mkdtempSync
(tmpDir) and writes scriptPath but never removes it; update runPolicyAdd to
ensure the temporary directory is removed after spawnSync finishes (and on
errors) by wrapping the spawnSync call in a try/finally or equivalent and
deleting tmpDir (e.g., fs.rmSync or fs.rmdirSync with recursive/force options)
in the finally block so cleanup always runs; keep references to tmpDir and
scriptPath so you remove the written file(s) and directory.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 6629d118-a197-4aac-9d24-d061b2bea576
📒 Files selected for processing (1)
test/policies.test.ts
|
✨ Thanks for submitting this PR, which proposes a way to improve the NemoClaw CLI by warning about messaging presets. Possibly related open issues: |
04d6aa3 to
2771882
Compare
2771882 to
f6f0f67
Compare
65e6b1d to
0831f57
Compare
Head branch was pushed to by a user without write access
df6d543 to
0477938
Compare
…aging (NVIDIA#1691) When a sandbox is created without enabling Telegram (or Discord, or Slack) during `nemoclaw onboard`, applying the matching policy preset via `nemoclaw <name> policy-add` only opens network egress to the channel API. The bot token, channel configuration, and in-sandbox bridge are wired up at onboard time, so users who apply the preset after onboarding without having enabled the channel can reasonably believe they have enabled messaging when only the firewall has been widened. Add `getMessagingPresetWarning()` in `src/lib/policies.ts` and surface it in `addSandboxPolicy()` (now in `src/lib/policy-channel-actions.ts` after the recent CLI dispatch refactor) before the apply confirmation so users see, for example, that the `telegram` preset alone does not enable Telegram bots and that re-running `nemoclaw onboard` with Telegram selected is the path to actually enabling the channel. This is a rebase of an earlier branch onto current main: - Hook moved from the legacy `src/nemoclaw.ts` dispatcher to the new `src/lib/policy-channel-actions.ts:addSandboxPolicy` after NVIDIA#2899 / NVIDIA#2901 / NVIDIA#2907 extracted dispatch. - `getMessagingPresetWarning` got an explicit TS signature (`presetName: string): string | null`) to match the rest of `src/lib/policies.ts`. - Replaced the em dash in the warning message with a period for consistency with project style. Originally three commits (warning logic + ordering assertion + tmpDir cleanup) on the prior branch; consolidated here because the rebase needed the dispatcher hook ported to a new file. Closes NVIDIA#1691 Re-ran `npx vitest run test/policies.test.ts` after rebase: 120/120 pass. Signed-off-by: latenighthackathon <latenighthackathon@users.noreply.github.com>
0477938 to
5248b9c
Compare
Wrap the spawnSync call in try/finally so the tmpDir created by fs.mkdtempSync is removed after each invocation, regardless of test outcome. Without this, every runPolicyAdd call leaves behind a nemoclaw-policy-add-* directory under os.tmpdir(); across full test suites and CI runs that adds up. This restores the cleanup that was on the prior branch as a separate commit but was lost during the rebase consolidation. Addresses the CodeRabbit nit from 2026-04-15 that pointed at the same gap. Re-ran `npx vitest run test/policies.test.ts`: 120/120 pass. Signed-off-by: latenighthackathon <latenighthackathon@users.noreply.github.com>
Summary
When a sandbox is created without enabling Telegram (or Discord, or Slack) during
nemoclaw onboard, applying the matching policy preset vianemoclaw <name> policy-addonly opens network egress to the channel's API. The bot token, channel configuration, and in-sandbox bridge are wired up at onboard time, so users who apply the preset later can reasonably believe they have enabled messaging when only the firewall has been widened.Problem
sandboxPolicyAddlists preset endpoints and asks for confirmation, but treatstelegram/discord/slackidentically tonpm/pypi/github. There is no indication that the messaging preset alone won't make messaging work — the user-visible effect is a successful● telegrammarker inpolicy-listfollowed by a non-responding bot, which is easy to misdiagnose as broken integration or missing tokens (#1691).Fix
Add
getMessagingPresetWarning(presetName)tolib/policies, which returns a short note for the three messaging presets (telegram,discord,slack) andnullfor everything else.sandboxPolicyAddprints the note between the endpoint disclosure and the apply confirmation so the user reads it at the decision point:The warning is universally true (even if Telegram was onboarded, the preset still doesn't do the wiring), so it also serves as accurate documentation of what
policy-addactually does.Test plan
getMessagingPresetWarning: returns a warning fortelegram/discord/slack,nullfor all other presets and unknown namestelegrampreset inpolicy-addprints the warning and the expected confirmation promptpypi) does not print the warningpolicies.test.tstests pass (64 existing + 4 new)npm run lint/npm run typecheck/npm run build:clicleanCloses #1691
Signed-off-by: latenighthackathon latenighthackathon@users.noreply.github.com
Summary by CodeRabbit