@@ -13,6 +13,7 @@ import { unescapeHtmlEntities } from "../../../utils/text-normalization"
1313import { Terminal } from "../../../integrations/terminal/Terminal"
1414import { TerminalRegistry } from "../../../integrations/terminal/TerminalRegistry"
1515import type { RooTerminalCallbacks , RooTerminalProcess } from "../../../integrations/terminal/types"
16+ import { t } from "../../../i18n"
1617
1718// Mock dependencies
1819vitest . mock ( "execa" , ( ) => ( {
@@ -61,6 +62,15 @@ vitest.mock("../../task/Task", async (importOriginal) => {
6162} )
6263vitest . mock ( "../../prompts/responses" )
6364
65+ // Tests run with empty translation resources, so `t` returns the key without its namespace.
66+ // Keep that default, and let individual tests replace it with an interpolating fake.
67+ const stripNamespace = ( key : string ) => key . replace ( / ^ \w + : / , "" )
68+
69+ vitest . mock ( "../../../i18n" , async ( importOriginal ) => {
70+ const actual = await importOriginal < typeof import ( "../../../i18n" ) > ( )
71+ return { ...actual , t : vitest . fn ( ( key : string ) => key . replace ( / ^ \w + : / , "" ) ) }
72+ } )
73+
6474const mockRunDcg = vitest . fn ( )
6575const mockEnsureDcgInstalled = vitest . fn ( )
6676
@@ -93,6 +103,7 @@ describe("executeCommandTool", () => {
93103 beforeEach ( ( ) => {
94104 // Reset mocks
95105 vitest . clearAllMocks ( )
106+ vitest . mocked ( t ) . mockImplementation ( stripNamespace )
96107 vitest . useRealTimers ( )
97108
98109 // Spy on executeCommandInTerminal and mock its return value
@@ -320,14 +331,27 @@ describe("executeCommandTool", () => {
320331 } )
321332
322333 it . each ( [
323- [ "C:\\Windows\\System32\\cmd.exe" , true ] ,
324- [ "C:\\Program Files\\PowerShell\\7\\pwsh.exe" , true ] ,
325- [ "/bin/bash" , false ] ,
326- [ undefined , false ] ,
327- ] ) ( "appends the POSIX-assumption note only for non-POSIX shell %s" , ( shellPath , expectNote ) => {
334+ [ "C:\\Windows\\System32\\cmd.exe" , "cmd.exe" ] ,
335+ [ "C:\\Program Files\\PowerShell\\7\\pwsh.exe" , "pwsh.exe" ] ,
336+ [ "/bin/bash" , undefined ] ,
337+ [ undefined , undefined ] ,
338+ ] ) ( "appends the POSIX-assumption note only for non-POSIX shell %s" , ( shellPath , expectedShell ) => {
339+ // Interpolate like the real translation so a dropped `shell` option fails the test.
340+ vitest
341+ . mocked ( t )
342+ . mockImplementation ( ( key : string , options ?: Record < string , unknown > ) =>
343+ options ?. shell ? `${ stripNamespace ( key ) } [shell=${ String ( options . shell ) } ]` : stripNamespace ( key ) ,
344+ )
345+
328346 const message = executeCommandModule . formatDcgBlockedMessage ( undefined , undefined , shellPath )
329347
330- expect ( message . includes ( "executeCommand.destructiveCommandGuard.assumedPosixNote" ) ) . toBe ( expectNote )
348+ if ( expectedShell ) {
349+ expect ( message ) . toContain (
350+ `executeCommand.destructiveCommandGuard.assumedPosixNote[shell=${ expectedShell } ]` ,
351+ )
352+ } else {
353+ expect ( message ) . not . toContain ( "assumedPosixNote" )
354+ }
331355 } )
332356
333357 it ( "shows a DCG block message as an error before requesting explicit approval" , async ( ) => {
0 commit comments