Repository navigation
fix(jetson): use python3 to patch daemon.json instead of sed #1913
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
ericksoa
merged 10 commits into
NVIDIA:main
from
BenediktSchackenberg:fix/jetson-daemon-json-comma-1875
Apr 23, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
602b87f
fix(jetson): use python3 to patch daemon.json instead of sed
BenediktSchackenberg 9994711
fix(jetson): fix f.write outside with block and add atomic write + JS…
BenediktSchackenberg f2c102b
fix(jetson): preserve daemon.json file permissions after atomic replace
BenediktSchackenberg ddafbf2
fix(jetson): restore daemon.json mode after atomic replace
BenediktSchackenberg 75022f3
fix(jetson): add python3 preflight and JSON root type guard
BenediktSchackenberg 1d5f8dd
ci: retrigger checks after force-push cancellation
BenediktSchackenberg 5921102
Merge branch 'main' into fix/jetson-daemon-json-comma-1875
cv ea29e21
Merge branch 'main' into fix/jetson-daemon-json-comma-1875
cv bb70b57
test(jetson): add daemon.json patcher coverage
cv e6bcec1
Merge branch 'main' into fix/jetson-daemon-json-comma-1875
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { execFileSync } from "node:child_process"; | ||
| import { chmodSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import path from "node:path"; | ||
|
|
||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| const SCRIPT_PATH = path.join(import.meta.dirname, "..", "scripts", "setup-jetson.sh"); | ||
|
|
||
| function extractDaemonJsonPatcher(): string { | ||
| const script = readFileSync(SCRIPT_PATH, "utf-8"); | ||
| const match = script.match(/<<'PYEOF'\n([\s\S]*?)\nPYEOF/); | ||
| if (!match) { | ||
| throw new Error("Failed to extract inline daemon.json patcher from scripts/setup-jetson.sh"); | ||
| } | ||
| return match[1]; | ||
| } | ||
|
|
||
| function runDaemonJsonPatcher(daemonPath: string): void { | ||
| execFileSync("python3", ["-", daemonPath], { | ||
| input: extractDaemonJsonPatcher(), | ||
| encoding: "utf-8", | ||
| }); | ||
| } | ||
|
|
||
| function getExecErrorOutput(error: unknown): string { | ||
| if (!(error instanceof Error)) { | ||
| return String(error); | ||
| } | ||
|
|
||
| const stderr = "stderr" in error ? error.stderr : ""; | ||
| if (typeof stderr === "string") { | ||
| return stderr; | ||
| } | ||
| if (Buffer.isBuffer(stderr)) { | ||
| return stderr.toString("utf-8"); | ||
| } | ||
| return error.message; | ||
| } | ||
|
|
||
| describe("setup-jetson daemon.json patcher", () => { | ||
| it("repairs the missing-comma regression and removes iptables and bridge keys", () => { | ||
| const tempDir = mkdtempSync(path.join(tmpdir(), "nemoclaw-jetson-patcher-")); | ||
| const daemonPath = path.join(tempDir, "daemon.json"); | ||
|
|
||
| try { | ||
| writeFileSync( | ||
| daemonPath, | ||
| [ | ||
| "{", | ||
| ' "default-runtime": "nvidia"', | ||
| ' "runtimes": {', | ||
| ' "nvidia": {', | ||
| ' "path": "nvidia-container-runtime",', | ||
| ' "runtimeArgs": []', | ||
| " }", | ||
| " },", | ||
| ' "iptables": false,', | ||
| ' "bridge": "none"', | ||
| "}", | ||
| "", | ||
| ].join("\n"), | ||
| ); | ||
| chmodSync(daemonPath, 0o640); | ||
|
|
||
| runDaemonJsonPatcher(daemonPath); | ||
|
|
||
| const patched = readFileSync(daemonPath, "utf-8"); | ||
| const parsed = JSON.parse(patched) as Record<string, unknown>; | ||
|
|
||
| expect(parsed).toEqual({ | ||
| "default-runtime": "nvidia", | ||
| runtimes: { | ||
| nvidia: { | ||
| path: "nvidia-container-runtime", | ||
| runtimeArgs: [], | ||
| }, | ||
| }, | ||
| }); | ||
| expect(patched.endsWith("\n")).toBe(true); | ||
| expect(statSync(daemonPath).mode & 0o777).toBe(0o640); | ||
| } finally { | ||
| rmSync(tempDir, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| it("fails cleanly for unrecoverable malformed JSON without clobbering the file", () => { | ||
| const tempDir = mkdtempSync(path.join(tmpdir(), "nemoclaw-jetson-patcher-")); | ||
| const daemonPath = path.join(tempDir, "daemon.json"); | ||
| const original = '{"default-runtime": "nvidia",\n'; | ||
|
|
||
| try { | ||
| writeFileSync(daemonPath, original); | ||
|
|
||
| expect(() => runDaemonJsonPatcher(daemonPath)).toThrowError( | ||
| /daemon\.json is malformed and could not be repaired automatically/, | ||
| ); | ||
| expect(readFileSync(daemonPath, "utf-8")).toBe(original); | ||
| } finally { | ||
| rmSync(tempDir, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| it("rejects non-object JSON roots before mutating keys", () => { | ||
| const tempDir = mkdtempSync(path.join(tmpdir(), "nemoclaw-jetson-patcher-")); | ||
| const daemonPath = path.join(tempDir, "daemon.json"); | ||
|
|
||
| try { | ||
| writeFileSync(daemonPath, '["not", "an", "object"]\n'); | ||
|
|
||
| let output = ""; | ||
| try { | ||
| runDaemonJsonPatcher(daemonPath); | ||
| } catch (error) { | ||
| output = getExecErrorOutput(error); | ||
| } | ||
|
|
||
| expect(output).toContain("daemon.json must contain a top-level JSON object"); | ||
| expect(readFileSync(daemonPath, "utf-8")).toBe('["not", "an", "object"]\n'); | ||
| } finally { | ||
| rmSync(tempDir, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| it("creates a new daemon.json with 0644 permissions when the file is missing", () => { | ||
| const tempDir = mkdtempSync(path.join(tmpdir(), "nemoclaw-jetson-patcher-")); | ||
| const daemonPath = path.join(tempDir, "daemon.json"); | ||
|
|
||
| try { | ||
| runDaemonJsonPatcher(daemonPath); | ||
|
|
||
| expect(readFileSync(daemonPath, "utf-8")).toBe("{}\n"); | ||
| expect(statSync(daemonPath).mode & 0o777).toBe(0o644); | ||
| } finally { | ||
| rmSync(tempDir, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
| }); |
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.