Skip to content
Draft
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
19 changes: 15 additions & 4 deletions src/analyzer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
/* eslint-disable indent */
import * as vscode from 'vscode';
import { spawn, execFile } from 'child_process';
import childProcess = require('child_process');
import { promisify } from 'util';
import { AnalysisData, AnalysisType, WebviewMessage } from './types';
import { WebviewContent } from './webview-content';
import { DEFAULT_PROMPT } from './constants';

const execAsync = promisify(execFile);
function execAsync(
file: string,
args: readonly string[],
options?: childProcess.ExecFileOptions
): Promise<{ stdout: string; stderr: string }> {
return promisify(childProcess.execFile)(file, args, options) as Promise<{
stdout: string;
stderr: string;
}>;
}

export class GitDiffAnalyzer {
private panel: vscode.WebviewPanel | undefined;
Expand All @@ -23,7 +32,7 @@ export class GitDiffAnalyzer {

this.isAnalyzing = true;

vscode.window.withProgress(
await vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: 'Analyzing changes with Claude...',
Expand Down Expand Up @@ -150,7 +159,9 @@ export class GitDiffAnalyzer {
}

return new Promise((resolve, reject) => {
const claudeProcess = spawn('claude', ['-p', '-'], { shell: false });
const claudeProcess = childProcess.spawn('claude', ['-p', '-'], {
shell: false
});

let stdoutData = '';
let stderrData = '';
Expand Down
10 changes: 6 additions & 4 deletions test/analyzer.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import * as sinon from 'sinon';
import { expect } from 'chai';
import { GitDiffAnalyzer } from '../src/analyzer';
let GitDiffAnalyzer: any;
import { mockVscode, createMockContext, createMockWebviewPanel, resetMocks } from './helpers/mock-vscode';
import { mockChildProcess, waitForAsync, mockAnalysisResponse } from './helpers/test-utils';
import * as childProcess from 'child_process';
import childProcess = require('child_process');

describe('GitDiffAnalyzer', () => {
let analyzer: GitDiffAnalyzer;
let analyzer: any;
let context: any;
let sandbox: sinon.SinonSandbox;
let mockCP: ReturnType<typeof mockChildProcess>;

beforeEach(() => {
sandbox = sinon.createSandbox();
context = createMockContext();
analyzer = new GitDiffAnalyzer(context);
// Setup mocks
mockCP = mockChildProcess();
sandbox.stub(childProcess, 'execFile').callsFake(mockCP.execFileStub as any);
Expand All @@ -33,6 +32,9 @@ describe('GitDiffAnalyzer', () => {
mockVscode.window.withProgress.callsFake(async (_options: any, task: any) => {
return task({ report: sinon.stub() }, { isCancellationRequested: false });
});

({ GitDiffAnalyzer } = require('../src/analyzer'));
analyzer = new GitDiffAnalyzer(context);
});

afterEach(() => {
Expand Down