Skip to content

refactor(ts-migration): move policies to typescript - #1670

Merged
ericksoa merged 11 commits into
mainfrom
ts-migration/07-policies
Apr 9, 2026
Merged

refactor(ts-migration): move policies to typescript#1670
ericksoa merged 11 commits into
mainfrom
ts-migration/07-policies

Conversation

@cv

@cv cv commented Apr 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add the policies migration phase manifest
  • mechanically move bin/lib/policies.js into src/lib/policies.ts
  • keep a compatibility wrapper in bin/lib/policies.js
  • rename test/policies.test.js to .ts

Testing

  • npm run build:cli
  • npm run typecheck:cli
  • npm run lint
  • npx vitest run test/policies.test.ts
  • npm test

Summary by CodeRabbit

  • New Features

    • Added policy preset management system enabling users to list, load, and apply network policy presets to sandboxes.
    • Interactive preset selection interface with status indicators showing applied and available presets.
    • Automatic YAML policy merging and validation for sandbox configuration.
  • Chores

    • Internal restructuring of policy management components.

@coderabbitai

coderabbitai Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The changes migrate policy preset management functionality from JavaScript to TypeScript. A new src/lib/policies.ts module implements preset management with functions for listing, loading, parsing, and applying presets to sandboxes. The original bin/lib/policies.js is converted into a re-export layer, and a TypeScript migration configuration file is added to coordinate the transition.

Changes

Cohort / File(s) Summary
TypeScript Implementation
src/lib/policies.ts
New module implementing preset discovery, loading, YAML parsing, policy merging, and preset application via openshell commands. Includes logic for sandbox name validation, temporary file handling, and recording applied presets in registry.
Migration Configuration
scripts/ts-migration/phases/07-policies.json
Configuration for TypeScript migration phase specifying test relocation, runtime move to src/lib/policies.ts, and simple shim strategy for the old bin/lib/policies.js.
JavaScript Re-export Layer
bin/lib/policies.js
Converted to forward all exports from the compiled TypeScript module at ../../dist/lib/policies, replacing ~352 lines of local implementation with forwarding assignments.
Test File
test/policies.test.ts
Added TypeScript directive // @ts-nocheck`` to disable type checking for this file.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant Code as applyPreset()
    participant FS as File System
    participant YAML as YAML Parser
    participant Registry as Sandbox Registry
    participant CLI as openshell CLI

    User->>Code: applyPreset(sandboxName, presetName)
    Code->>Code: Validate sandbox name (RFC1123)
    Code->>FS: Load preset YAML file
    FS-->>Code: Preset content
    Code->>YAML: Extract network_policies section
    YAML-->>Code: Preset entries
    Code->>CLI: buildPolicyGetCommand(sandboxName)
    CLI-->>Code: Current policy YAML
    Code->>YAML: parseCurrentPolicy(raw)
    YAML-->>Code: Parsed current policy
    Code->>Code: mergePresetIntoPolicy(current, preset)
    Code-->>Code: Merged policy
    Code->>FS: Write merged policy to temp file (mode 0600)
    FS-->>Code: Temp file created
    Code->>CLI: openshell policy set (via temp file)
    CLI-->>Code: Success/Failure
    Code->>Registry: getSandbox(sandboxName)
    Registry-->>Code: Sandbox object
    Code->>Registry: updateSandbox (record applied preset)
    Registry-->>Code: Updated
    Code->>FS: Clean up temp files/directories
    FS-->>Code: Cleanup complete
    Code-->>User: Result
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Hops through the TypeScript migration dreams,
Presets now flow through YAML streams,
From bin to src, the logic takes flight,
Policy merging done just right!
Bunny code bounces, hopping with glee, 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 46.15% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: moving the policies module from JavaScript to TypeScript as part of the ts-migration effort.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ts-migration/07-policies

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

@wscurran wscurran added CI/CD refactor PR restructures code without intended behavior change labels Apr 9, 2026
@cv cv added the v0.0.11 label Apr 9, 2026
@ericksoa
ericksoa changed the base branch from ts-migration/06-runner to main April 9, 2026 17:53
Signed-off-by: Aaron Erickson <aerickson@nvidia.com>

# Conflicts:
#	scripts/migrate-js-to-ts.ts
#	test/skills-frontmatter.test.ts
@ericksoa
ericksoa merged commit 15c0049 into main Apr 9, 2026
8 of 9 checks passed
gemini2026 pushed a commit to gemini2026/NemoClaw that referenced this pull request Apr 14, 2026
## Summary
- add the policies migration phase manifest
- mechanically move `bin/lib/policies.js` into `src/lib/policies.ts`
- keep a compatibility wrapper in `bin/lib/policies.js`
- rename `test/policies.test.js` to `.ts`

## Testing
- npm run build:cli
- npm run typecheck:cli
- npm run lint
- npx vitest run test/policies.test.ts
- npm test


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Added policy preset management system enabling users to list, load,
and apply network policy presets to sandboxes.
* Interactive preset selection interface with status indicators showing
applied and available presets.
* Automatic YAML policy merging and validation for sandbox
configuration.

* **Chores**
  * Internal restructuring of policy management components.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Aaron Erickson <aerickson@nvidia.com>
@cv
cv deleted the ts-migration/07-policies branch May 27, 2026 21:19
@wscurran wscurran added area: ci CI workflows, checks, release automation, or GitHub Actions chore Build, CI, dependency, or tooling maintenance and removed CI/CD chore Build, CI, dependency, or tooling maintenance labels Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ci CI workflows, checks, release automation, or GitHub Actions refactor PR restructures code without intended behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants