Skip to content

Commit eb56179

Browse files
authored
fix(policy): ignore dotfile presets from directories (#2679)
Replays the approved functional change from @WuKongAI-CMU in #2525 onto current main. Original PR: - #2525 by @WuKongAI-CMU Behavior: - `policy-add --from-dir` ignores hidden dotfile YAML entries while still applying non-hidden `.yaml`/`.yml` files in lexicographic order. - Explicit `policy-add --from-file .hidden.yaml` behavior is unchanged because the `--from-file` path is not filtered. Replacement rationale: - #2525 was already approved but is currently blocked by branch/process state. - This PR carries the same functional change forward on a clean replay branch so it can be validated and merged without waiting on the original branch update. Validation: - `git diff --check` passed. - `npm test -- test/policies.test.ts -t="--from-dir skips hidden dotfile yaml presets"` passed after installing dependencies and rebuilding the CLI. - GitHub checks are being monitored before merge. Signed-off-by: Aaron Erickson <aerickson@nvidia.com>
1 parent e225dfb commit eb56179

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

src/nemoclaw.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,9 +2116,9 @@ function buildSandboxLogsArgs(sandboxName: string, follow: boolean): string[] {
21162116
* for a single custom preset YAML, and `--from-dir <path>` for every
21172117
* `.yaml`/`.yml` file in a directory. `--dry-run` previews without applying,
21182118
* `--yes`/`-y`/`--force` (or `NEMOCLAW_NON_INTERACTIVE=1`) skips the
2119-
* confirmation prompt. `--from-dir` applies files in lexicographic order
2120-
* and aborts at the first failure (already-applied presets are not rolled
2121-
* back).
2119+
* confirmation prompt. `--from-dir` applies non-hidden files in lexicographic
2120+
* order and aborts at the first failure (already-applied presets are not
2121+
* rolled back).
21222122
*/
21232123
async function sandboxPolicyAdd(sandboxName: string, args: string[] = []): Promise<void> {
21242124
const dryRun = args.includes("--dry-run");
@@ -2161,7 +2161,8 @@ async function sandboxPolicyAdd(sandboxName: string, args: string[] = []): Promi
21612161
const files = fs
21622162
.readdirSync(absDir, { withFileTypes: true })
21632163
.filter(
2164-
(ent: { name: string; isFile(): boolean }) => ent.isFile() && /\.ya?ml$/i.test(ent.name),
2164+
(ent: { name: string; isFile(): boolean }) =>
2165+
ent.isFile() && !ent.name.startsWith(".") && /\.ya?ml$/i.test(ent.name),
21652166
)
21662167
.map((ent: { name: string }) => path.join(absDir, ent.name))
21672168
.sort();

test/policies.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,21 @@ setImmediate(() => {
14751475
expect(result.stderr).toMatch(/Aborting --from-dir/);
14761476
});
14771477

1478+
it("--from-dir skips hidden dotfile yaml presets", () => {
1479+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-from-dir-hidden-"));
1480+
fs.writeFileSync(
1481+
path.join(dir, ".bad.yaml"),
1482+
"preset:\n name: bad\nnetwork_policies: {}\n",
1483+
);
1484+
fs.writeFileSync(path.join(dir, "real.yaml"), "preset:\n name: real\nnetwork_policies: {}\n");
1485+
const result = runPolicyAddExternal(["--from-dir", dir, "--yes"]);
1486+
expect(result.status).toBe(0);
1487+
const calls = JSON.parse(result.stdout.split("__CALLS__")[1].trim()) as PolicyCall[];
1488+
const loads = calls.filter((c) => c.type === "load").map((c) => c.path);
1489+
expect(loads.length).toBe(1);
1490+
expect(loads[0]).toMatch(/real\.yaml$/);
1491+
});
1492+
14781493
it("errors when --from-dir points at a non-directory", () => {
14791494
const result = runPolicyAddExternal(["--from-dir", "/does/not/exist"]);
14801495
expect(result.status).not.toBe(0);

0 commit comments

Comments
 (0)