-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(shields): refuse a corrupt transition lock without a raw stack trace #8122
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
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d1729d9
fix(shields): refuse a corrupt transition lock without a raw stack trace
laitingsheng 6ef49bb
test(shields): cover corrupt lock refusal for shields up
cv 29f5161
merge(main): refresh #8122 against current main
cv e319668
merge(main): refresh #8122 against current main
cv 1763ff0
merge(main): refresh #8122 against current main
cv f070bbe
merge(main): refresh PR #8122 after dependency remediation
cv 9cec86a
Merge branch 'main' into fix/shields-lock-timeout-clean-failure
laitingsheng a986513
Merge remote-tracking branch 'origin/main' into fix/shields-lock-time…
laitingsheng 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
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,69 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import fs from "node:fs"; | ||
| import path from "node:path"; | ||
|
|
||
| import { describe, expect, test as it } from "../helpers/owned-test-resources"; | ||
|
|
||
| import { runWithEnv, testTimeoutOptions, writeSandboxRegistry } from "./helpers"; | ||
|
|
||
| const REFUSAL_BUDGET_MS = 15_000; | ||
|
|
||
| function writeCorruptTransitionLock(home: string, sandboxName: string): string { | ||
| const stateDir = path.join(home, ".nemoclaw", "state"); | ||
| fs.mkdirSync(stateDir, { recursive: true }); | ||
| const lockPath = path.join(stateDir, `shields-transition-lock-${sandboxName}.json`); | ||
| fs.writeFileSync(lockPath, "", { mode: 0o600 }); | ||
| fs.utimesSync(lockPath, new Date(1_000), new Date(1_000)); | ||
| return lockPath; | ||
| } | ||
|
|
||
| function expectCleanRefusal(out: string): void { | ||
| expect(out).toContain("the owner record is incomplete"); | ||
| expect(out).toContain("Recovery:"); | ||
| expect(out).toContain("manually"); | ||
| expect(out).not.toContain("ShieldsTransitionLockManager"); | ||
| expect(out).not.toMatch(/^\s+at /m); | ||
| expect(out).not.toContain("Node.js v"); | ||
| } | ||
|
|
||
| describe("shields commands with a corrupt transition lock", () => { | ||
| it( | ||
| "refuses read-only status without a raw stack trace (#8108)", | ||
| testTimeoutOptions(30_000), | ||
| ({ testHome }) => { | ||
| const { home } = testHome; | ||
| writeSandboxRegistry(home); | ||
| const lockPath = writeCorruptTransitionLock(home, "alpha"); | ||
|
|
||
| const startedAt = Date.now(); | ||
| const status = runWithEnv("alpha shields status 2>&1", testHome.environment()); | ||
| const elapsedMs = Date.now() - startedAt; | ||
|
|
||
| expect(status.code).toBe(1); | ||
| expectCleanRefusal(status.out); | ||
| expect(elapsedMs).toBeLessThan(REFUSAL_BUDGET_MS); | ||
| expect(fs.readFileSync(lockPath, "utf8")).toBe(""); | ||
| }, | ||
| ); | ||
|
|
||
| it( | ||
| "refuses shields down without a raw stack trace (#8108)", | ||
| testTimeoutOptions(30_000), | ||
| ({ testHome }) => { | ||
| const { home } = testHome; | ||
| writeSandboxRegistry(home); | ||
| const lockPath = writeCorruptTransitionLock(home, "alpha"); | ||
|
|
||
| const startedAt = Date.now(); | ||
| const down = runWithEnv("alpha shields down --reason test 2>&1", testHome.environment()); | ||
| const elapsedMs = Date.now() - startedAt; | ||
|
|
||
| expect(down.code).toBe(1); | ||
| expectCleanRefusal(down.out); | ||
| expect(elapsedMs).toBeLessThan(REFUSAL_BUDGET_MS); | ||
| expect(fs.readFileSync(lockPath, "utf8")).toBe(""); | ||
| }, | ||
| ); | ||
| }); | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Add corrupt-lock coverage for
shields up.This suite covers
shields statusandshields downonly. Add ashields upcase that verifies exit code1, clean recovery output, prompt refusal, and preservation of the malformed lock file.As per path instructions, tests must prove that public entrypoints reach the new path. The PR objective includes
shields up,shields down, andshields status.🧰 Tools
🪛 ast-grep (0.45.0)
[warning] 46-46: Filesystem path is not a string literal; a request-/variable-derived path can enable path traversal. Validate and normalize the path before use.
Context: fs.readFileSync(lockPath, "utf8")
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
(detect-non-literal-fs-filename-typescript)
[warning] 65-65: Filesystem path is not a string literal; a request-/variable-derived path can enable path traversal. Validate and normalize the path before use.
Context: fs.readFileSync(lockPath, "utf8")
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
(detect-non-literal-fs-filename-typescript)
🤖 Prompt for AI Agents
Source: Path instructions