-
Notifications
You must be signed in to change notification settings - Fork 2.8k
refactor(onboard): extract initial policy helpers #3295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+416
−213
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
73c58d2
refactor(cli): group remaining architecture modules
cv 8f3ebc1
refactor(onboard): extract initial policy helpers
cv 57b3d61
Merge remote-tracking branch 'origin/main' into refactor/cli-architec…
cv 1783c07
Merge branch 'refactor/cli-architecture-layout' into refactor/onboard…
cv bd0ffe5
test(inference): expect Kimi status thinking flag
cv 5f51c03
Merge branch 'refactor/cli-architecture-layout' into refactor/onboard…
cv 374abc5
Merge remote-tracking branch 'origin/main' into refactor/cli-architec…
cv 76500de
Merge branch 'refactor/cli-architecture-layout' into refactor/onboard…
cv 955225f
Merge branch 'main' into refactor/cli-architecture-layout
cv 18ee079
merge main into cli architecture layout
cv 2cbb302
test(policy): update tier onboarding policy import
cv ed06048
Merge branch 'refactor/cli-architecture-layout' of https://github.com…
cv d775298
Merge branch 'refactor/cli-architecture-layout' into refactor/onboard…
cv 13bcc3a
Merge branch 'main' into refactor/cli-architecture-layout
cv 96008e0
merge(main): update architecture layout stack base
cv 32cb2b7
merge(stack): update initial policy helpers branch
cv c86a8ed
merge(main): refresh architecture layout branch
cv 31b255d
Merge branch 'main' into refactor/cli-architecture-layout
cv 23efdf3
Merge branch 'main' into refactor/cli-architecture-layout
cv 37d5704
merge(main): refresh architecture layout branch
cv 5177213
Potential fix for pull request finding 'CodeQL / Unused variable, imp…
cv de52330
Merge branch 'refactor/cli-architecture-layout' into refactor/onboard…
cv b78185f
Merge remote-tracking branch 'origin/main' into refactor/onboard-init…
cv 2972356
fix(onboard): harden temp file cleanup
cv 6ba281c
Merge branch 'main' into refactor/onboard-initial-policy
cv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import fs from "node:fs"; | ||
| import os from "node:os"; | ||
| import path from "node:path"; | ||
|
|
||
| import { afterEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| vi.mock("../policy", () => ({ | ||
| mergePresetNamesIntoPolicy: (policy: string, presetNames: string[]) => ({ | ||
| policy: `${policy.trimEnd()}\n slack: {}\n`, | ||
| appliedPresets: presetNames, | ||
| missingPresets: [], | ||
| }), | ||
| })); | ||
|
|
||
| import { getNetworkPolicyNames, prepareInitialSandboxCreatePolicy } from "./initial-policy"; | ||
|
|
||
| const tmpRoots: string[] = []; | ||
|
|
||
| function tmpPolicy(content: string): string { | ||
| const dir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-initial-policy-test-")); | ||
| tmpRoots.push(dir); | ||
| const file = path.join(dir, "base.yaml"); | ||
| fs.writeFileSync(file, content, "utf-8"); | ||
| return file; | ||
| } | ||
|
|
||
| afterEach(() => { | ||
| for (const dir of tmpRoots.splice(0)) { | ||
| fs.rmSync(dir, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| describe("initial sandbox policy helpers", () => { | ||
| it("returns network policy names from a policy document", () => { | ||
| expect(getNetworkPolicyNames("version: 1\nnetwork_policies:\n slack: {}\n npm: {}\n")).toEqual( | ||
| new Set(["slack", "npm"]), | ||
| ); | ||
| }); | ||
|
|
||
| it("returns null when policy YAML cannot be parsed", () => { | ||
| expect(getNetworkPolicyNames("network_policies: [unterminated")).toBeNull(); | ||
| }); | ||
|
|
||
| it("keeps the base policy when no channel needs a create-time preset", () => { | ||
| const basePolicyPath = tmpPolicy("version: 1\nnetwork_policies:\n base: {}\n"); | ||
|
|
||
| expect(prepareInitialSandboxCreatePolicy(basePolicyPath, ["telegram"])).toEqual({ | ||
| policyPath: basePolicyPath, | ||
| appliedPresets: [], | ||
| }); | ||
| }); | ||
|
|
||
| it("records an existing create-time preset without writing a temp policy", () => { | ||
| const basePolicyPath = tmpPolicy("version: 1\nnetwork_policies:\n slack: {}\n"); | ||
|
|
||
| expect(prepareInitialSandboxCreatePolicy(basePolicyPath, ["slack"])).toEqual({ | ||
| policyPath: basePolicyPath, | ||
| appliedPresets: ["slack"], | ||
| }); | ||
| }); | ||
|
|
||
| it("merges missing create-time presets into a temporary policy", () => { | ||
| const basePolicyPath = tmpPolicy("version: 1\nnetwork_policies:\n base: {}\n"); | ||
|
|
||
| const prepared = prepareInitialSandboxCreatePolicy(basePolicyPath, ["slack"]); | ||
|
|
||
| expect(prepared.policyPath).not.toBe(basePolicyPath); | ||
| expect(prepared.appliedPresets).toEqual(["slack"]); | ||
| expect(fs.readFileSync(prepared.policyPath, "utf-8")).toContain("slack"); | ||
| expect(prepared.cleanup?.()).toBe(true); | ||
| expect(fs.existsSync(prepared.policyPath)).toBe(false); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.