Relax some tests when shell integration is off

This commit is contained in:
Alex Dima
2026-03-21 19:56:04 +01:00
parent 22913a387d
commit f4c042bfc8

View File

@@ -168,16 +168,16 @@ function extractTextContent(result: vscode.LanguageModelToolResult): string {
await toolConfig.update('idlePollInterval', undefined, vscode.ConfigurationTarget.Global); await toolConfig.update('idlePollInterval', undefined, vscode.ConfigurationTarget.Global);
}); });
defineTests(); defineTests(false);
}); });
// --- Shell integration ON --- // --- Shell integration ON ---
suite('shell integration on', () => { suite('shell integration on', () => {
defineTests(); defineTests(true);
}); });
function defineTests() { function defineTests(hasShellIntegration: boolean) {
// --- Sandbox OFF tests --- // --- Sandbox OFF tests ---
@@ -220,7 +220,12 @@ function extractTextContent(result: vscode.LanguageModelToolResult): string {
const command = isWindows ? 'cmd /c exit 42' : 'bash -c "exit 42"'; const command = isWindows ? 'cmd /c exit 42' : 'bash -c "exit 42"';
const output = await invokeRunInTerminal(command); const output = await invokeRunInTerminal(command);
assert.strictEqual(output.trim(), 'Command produced no output\nCommand exited with code 42'); // Without shell integration, exit codes are unavailable
const acceptable = [
'Command produced no output\nCommand exited with code 42',
...(!hasShellIntegration ? ['Command produced no output'] : []),
];
assert.ok(acceptable.includes(output.trim()), `Unexpected output: ${JSON.stringify(output.trim())}`);
}); });
test('output with special characters is captured verbatim', async function () { test('output with special characters is captured verbatim', async function () {
@@ -262,20 +267,25 @@ function extractTextContent(result: vscode.LanguageModelToolResult): string {
const output = await invokeRunInTerminal('curl -s --max-time 5 https://example.com'); const output = await invokeRunInTerminal('curl -s --max-time 5 https://example.com');
// The sandbox blocks network access. curl fails and the sandbox // Without shell integration, exit code is unavailable and
// output analyzer prepends its error message. // curl produces no sandbox-specific error strings, so the
assert.strictEqual(output.trim(), [ // sandbox analyzer may not trigger.
'Command failed while running in sandboxed mode. If the command failed due to sandboxing:', const acceptable = [
`- If it would be reasonable to extend the sandbox rules, work with the user to update allowWrite for file system access problems in ${sandboxFileSystemSetting}, or to add required domains to chat.tools.terminal.sandbox.network.allowedDomains.`, [
'- Otherwise, immediately retry the command with requestUnsandboxedExecution=true. Do NOT ask the user \u2014 setting this flag automatically shows a confirmation prompt to the user.', 'Command failed while running in sandboxed mode. If the command failed due to sandboxing:',
'', `- If it would be reasonable to extend the sandbox rules, work with the user to update allowWrite for file system access problems in ${sandboxFileSystemSetting}, or to add required domains to chat.tools.terminal.sandbox.network.allowedDomains.`,
'Here is the output of the command:', '- Otherwise, immediately retry the command with requestUnsandboxedExecution=true. Do NOT ask the user \u2014 setting this flag automatically shows a confirmation prompt to the user.',
'', '',
'', 'Here is the output of the command:',
'', '',
'Command produced no output', '',
'Command exited with code 56', '',
].join('\n')); 'Command produced no output',
'Command exited with code 56',
].join('\n'),
...(!hasShellIntegration ? ['Command produced no output'] : []),
];
assert.ok(acceptable.includes(output.trim()), `Unexpected output: ${JSON.stringify(output.trim())}`);
}); });
test('cannot write to /tmp', async function () { test('cannot write to /tmp', async function () {
@@ -284,18 +294,21 @@ function extractTextContent(result: vscode.LanguageModelToolResult): string {
const marker = `SANDBOX_TMP_${Date.now()}`; const marker = `SANDBOX_TMP_${Date.now()}`;
const output = await invokeRunInTerminal(`echo "${marker}" > /tmp/${marker}.txt`); const output = await invokeRunInTerminal(`echo "${marker}" > /tmp/${marker}.txt`);
assert.strictEqual(output.trim(), [ const sandboxBody = [
'Command failed while running in sandboxed mode. If the command failed due to sandboxing:',
`- If it would be reasonable to extend the sandbox rules, work with the user to update allowWrite for file system access problems in ${sandboxFileSystemSetting}, or to add required domains to chat.tools.terminal.sandbox.network.allowedDomains.`, `- If it would be reasonable to extend the sandbox rules, work with the user to update allowWrite for file system access problems in ${sandboxFileSystemSetting}, or to add required domains to chat.tools.terminal.sandbox.network.allowedDomains.`,
'- Otherwise, immediately retry the command with requestUnsandboxedExecution=true. Do NOT ask the user \u2014 setting this flag automatically shows a confirmation prompt to the user.', '- Otherwise, immediately retry the command with requestUnsandboxedExecution=true. Do NOT ask the user \u2014 setting this flag automatically shows a confirmation prompt to the user.',
'', '',
'Here is the output of the command:', 'Here is the output of the command:',
'', '',
`/bin/bash: /tmp/${marker}.txt: Operation not permitted`, `/bin/bash: /tmp/${marker}.txt: Operation not permitted`,
'', ].join('\n');
'', const acceptable = [
'Command exited with code 1', // With shell integration: known failure with exit code
].join('\n')); `Command failed while running in sandboxed mode. If the command failed due to sandboxing:\n${sandboxBody}\n\n\nCommand exited with code 1`,
// Without shell integration: heuristic detection, no exit code
...(!hasShellIntegration ? [`Command ran in sandboxed mode and may have been blocked by the sandbox. If the command failed due to sandboxing:\n${sandboxBody}`] : []),
];
assert.ok(acceptable.includes(output.trim()), `Unexpected output: ${JSON.stringify(output.trim())}`);
}); });
test('can read files outside the workspace', async function () { test('can read files outside the workspace', async function () {