Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 52 additions & 51 deletions integration-tests/context-compress-interactive.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,55 +18,56 @@ describe('Interactive Mode', () => {
await rig.cleanup();
});

it.skipIf(process.platform === 'win32')(
'should trigger chat compression with /compress command',
async () => {
await rig.setup('interactive-compress-test');

const { ptyProcess } = rig.runInteractive();
await rig.ensureReadyForInput(ptyProcess);

const longPrompt =
'Dont do anything except returning a 1000 token long paragragh with the <name of the scientist who discovered theory of relativity> at the end to indicate end of response. This is a moderately long sentence.';

await type(ptyProcess, longPrompt);
await type(ptyProcess, '\r');

await rig.waitForText('einstein', 25000);

await type(ptyProcess, '/compress');
// A small delay to allow React to re-render the command list.
await new Promise((resolve) => setTimeout(resolve, 100));
await type(ptyProcess, '\r');

const foundEvent = await rig.waitForTelemetryEvent(
'chat_compression',
90000,
);
expect(foundEvent, 'chat_compression telemetry event was not found').toBe(
true,
);
},
);

it.skipIf(process.platform === 'win32')(
'should handle compression failure on token inflation',
async () => {
await rig.setup('interactive-compress-test');

const { ptyProcess } = rig.runInteractive();
await rig.ensureReadyForInput(ptyProcess);

await type(ptyProcess, '/compress');
await new Promise((resolve) => setTimeout(resolve, 100));
await type(ptyProcess, '\r');

const compressionFailed = await rig.waitForText(
'compression was not beneficial',
25000,
);

expect(compressionFailed).toBe(true);
},
);
it('should trigger chat compression with /compress command', async () => {
await rig.setup('interactive-compress-test');

const { ptyProcess } = rig.runInteractive();
await rig.ensureReadyForInput(ptyProcess);

const longPrompt =
'Dont do anything except returning a 1000 token long paragragh with the <name of the scientist who discovered theory of relativity> at the end to indicate end of response. This is a moderately long sentence.';

await type(ptyProcess, longPrompt);
await type(ptyProcess, '\r');

await rig.waitForText('einstein', 25000);

await type(ptyProcess, '/compress');
// A small delay to allow React to re-render the command list.
await new Promise((resolve) => setTimeout(resolve, 100));
await type(ptyProcess, '\r');

const foundEvent = await rig.waitForTelemetryEvent(
'chat_compression',
90000,
);
expect(foundEvent, 'chat_compression telemetry event was not found').toBe(
true,
);
});

it('should handle compression failure on token inflation', async () => {
await rig.setup('interactive-compress-test');

const { ptyProcess } = rig.runInteractive();
await rig.ensureReadyForInput(ptyProcess);

await type(ptyProcess, '/compress');

const suggestionsReady = await rig.waitForText(
'Compresses the context by replacing it with a summary.',
15000,
);
expect(suggestionsReady, 'Command suggestions did not appear in time').toBe(
true,
);
await type(ptyProcess, '\r');

const compressionFailed = await rig.waitForText(
'compression was not beneficial',
25000,
);

expect(compressionFailed).toBe(true);
});
});
121 changes: 58 additions & 63 deletions integration-tests/file-system-interactive.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,69 +18,64 @@ describe('Interactive file system', () => {
await rig.cleanup();
});

it.skipIf(process.platform === 'win32')(
'should perform a read-then-write sequence',
async () => {
const fileName = 'version.txt';
await rig.setup('interactive-read-then-write');
rig.createFile(fileName, '1.0.0');

const { ptyProcess } = rig.runInteractive();

const authDialogAppeared = await rig.waitForText(
'How would you like to authenticate',
5000,
);

// select the second option if auth dialog come's up
if (authDialogAppeared) {
ptyProcess.write('2');
}

// Wait for the app to be ready
const isReady = await rig.waitForText('Type your message', 15000);
expect(
isReady,
'CLI did not start up in interactive mode correctly',
).toBe(true);

// Step 1: Read the file
const readPrompt = `Read the version from ${fileName}`;
await type(ptyProcess, readPrompt);
await type(ptyProcess, '\r');

const readCall = await rig.waitForToolCall('read_file', 30000);
expect(readCall, 'Expected to find a read_file tool call').toBe(true);

const containsExpectedVersion = await rig.waitForText('1.0.0', 15000);
expect(
containsExpectedVersion,
'Expected to see version "1.0.0" in output',
).toBe(true);

// Step 2: Write the file
const writePrompt = `now change the version to 1.0.1 in the file`;
await type(ptyProcess, writePrompt);
await type(ptyProcess, '\r');

const toolCall = await rig.waitForAnyToolCall(
['write_file', 'replace'],
30000,
);

if (!toolCall) {
printDebugInfo(rig, rig._interactiveOutput, {
toolCall,
});
}

expect(
it('should perform a read-then-write sequence', async () => {
const fileName = 'version.txt';
await rig.setup('interactive-read-then-write');
rig.createFile(fileName, '1.0.0');

const { ptyProcess } = rig.runInteractive();

const authDialogAppeared = await rig.waitForText(
'How would you like to authenticate',
5000,
);

// select the second option if auth dialog come's up
if (authDialogAppeared) {
ptyProcess.write('2');
}

// Wait for the app to be ready
const isReady = await rig.waitForText('Type your message', 15000);
expect(isReady, 'CLI did not start up in interactive mode correctly').toBe(
true,
);

// Step 1: Read the file
const readPrompt = `Read the version from ${fileName}`;
await type(ptyProcess, readPrompt);
await type(ptyProcess, '\r');

const readCall = await rig.waitForToolCall('read_file', 30000);
expect(readCall, 'Expected to find a read_file tool call').toBe(true);

const containsExpectedVersion = await rig.waitForText('1.0.0', 15000);
expect(
containsExpectedVersion,
'Expected to see version "1.0.0" in output',
).toBe(true);

// Step 2: Write the file
const writePrompt = `now change the version to 1.0.1 in the file`;
await type(ptyProcess, writePrompt);
await type(ptyProcess, '\r');

const toolCall = await rig.waitForAnyToolCall(
['write_file', 'replace'],
30000,
);

if (!toolCall) {
printDebugInfo(rig, rig._interactiveOutput, {
toolCall,
'Expected to find a write_file or replace tool call',
).toBe(true);
});
}

const newFileContent = rig.readFile(fileName);
expect(newFileContent).toBe('1.0.1');
},
);
expect(toolCall, 'Expected to find a write_file or replace tool call').toBe(
true,
);

const newFileContent = rig.readFile(fileName);
expect(newFileContent).toBe('1.0.1');
});
});