Skip to content
Merged
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
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:
- name: Compile
run: npm run compile

- name: Run Tests
- name: Run Unit Tests
run: npm run test:unit

- name: Run Integration Tests
# VS Code tests require a display server on Linux
run: xvfb-run -a npm test
run: xvfb-run -a npm run test:integration
2 changes: 1 addition & 1 deletion .vscode-test.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from '@vscode/test-cli';

export default defineConfig({
files: 'out/test/**/*.test.js',
files: 'out/test/integration/**/*.test.js',
});
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,15 @@
"pretest": "npm run compile-tests && npm run compile && npm run lint",
"check-types": "node ./node_modules/typescript/bin/tsc --noEmit",
"lint": "node ./node_modules/eslint/bin/eslint.js src",
"test": "node ./node_modules/@vscode/test-cli/out/bin.mjs",
"test": "npm run test:unit && npm run test:integration",
"test:unit": "npm run compile-tests && npx mocha out/test/unit/**/*.test.js --ui tdd",
"test:integration": "node ./node_modules/@vscode/test-cli/out/bin.mjs",
"prepare": "husky"
},
"lint-staged": {
"*.ts": [
"eslint --fix"
"eslint --fix",
"bash -c 'npm run test:unit'"
]
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/ai/registry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from 'vscode';
import type { PredicteCommitConfig } from '../core/config';
import type * as vscode from 'vscode';
import type { PredicteCommitConfig } from '../core/types';
import type { ProviderClient } from './types';

export interface ProviderDefinition {
Expand Down
4 changes: 2 additions & 2 deletions src/ai/selector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type * as vscode from 'vscode';
import type { PredicteCommitConfig } from '../core/config';
import { getEffectiveProviderId } from '../core/config';
import type { PredicteCommitConfig } from '../core/types';
import { getEffectiveProviderId } from '../core/logic';
import type { ProviderClient } from './types';
import { getProviderDefinition } from './registry';

Expand Down
3 changes: 2 additions & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from 'vscode';
import { getConfig, getEffectiveProviderId } from './core/config';
import { getConfig } from './core/config';
import { getEffectiveProviderId } from './core/logic';
import { getGitExtension } from './modules/git/vscode';
import { getTargetRepository } from './modules/git/repo';
import { toRepoRelativePosixPath } from './utils/paths';
Expand Down
29 changes: 2 additions & 27 deletions src/core/config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import * as vscode from 'vscode';

export type PredicteCommitConfig = {
provider: string;
models: string[];
ignoredFiles: string[];
useLocal: boolean;
localBaseUrl: string;
localModel: string;
debugLogging: boolean;
};

export const DEFAULT_LOCAL_URL = '';
import { PredicteCommitConfig } from './types';
import { DEFAULT_LOCAL_URL } from './constants';

export function getConfig(): PredicteCommitConfig {
const cfg = vscode.workspace.getConfiguration('predicteCommit');
Expand All @@ -26,18 +16,3 @@ export function getConfig(): PredicteCommitConfig {
debugLogging: cfg.get<boolean>('debugLogging', false),
};
}

export const DIFF_CAPS: { maxCharsPerFile: number; maxCharsTotal: number } = {
maxCharsPerFile: 8000,
maxCharsTotal: 32000,
};

export const TRUNCATION_MARKER = '...TRUNCATED...';

export function getEffectiveProviderId(cfg: PredicteCommitConfig): string {
// Backwards compatibility: existing users may rely on useLocal.
if (cfg.useLocal) {
return 'ollama';
}
return cfg.provider;
}
8 changes: 8 additions & 0 deletions src/core/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const DEFAULT_LOCAL_URL = '';

export const DIFF_CAPS: { maxCharsPerFile: number; maxCharsTotal: number } = {
maxCharsPerFile: 8000,
maxCharsTotal: 32000,
};

export const TRUNCATION_MARKER = '...TRUNCATED...';
9 changes: 9 additions & 0 deletions src/core/logic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { PredicteCommitConfig } from './types';

export function getEffectiveProviderId(cfg: PredicteCommitConfig): string {
// Backwards compatibility: existing users may rely on useLocal.
if (cfg.useLocal) {
return 'ollama';
}
return cfg.provider;
}
9 changes: 9 additions & 0 deletions src/core/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export type PredicteCommitConfig = {
provider: string;
models: string[];
ignoredFiles: string[];
useLocal: boolean;
localBaseUrl: string;
localModel: string;
debugLogging: boolean;
};
2 changes: 1 addition & 1 deletion src/providers/local/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { postChatCompletion } from '../../ai/http';
import type { GenerateRequest, GenerateResult, ProviderClient } from '../../ai/types';
import { registerProvider } from '../../ai/registry';
import { DEFAULT_LOCAL_URL } from '../../core/config';
import { DEFAULT_LOCAL_URL } from '../../core/constants';

export class LocalProvider implements ProviderClient {
constructor(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import * as assert from 'assert';
import { getEffectiveProviderId, getConfig, PredicteCommitConfig, DEFAULT_LOCAL_URL } from '../core/config';
import { getConfig } from '../../core/config';
import { PredicteCommitConfig } from '../../core/types';
import { getEffectiveProviderId } from '../../core/logic';
import { DEFAULT_LOCAL_URL } from '../../core/constants';

suite('Config Test Suite', () => {
test('getEffectiveProviderId', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import * as assert from 'assert';
// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode';
// import * as myExtension from '../../extension';
// import * as myExtension from '../../../extension';

import { truncateWithMarker } from '../utils/truncate';
import { isTransientStatus, isAuthOrConfigStatus } from '../ai/errors';
import { truncateWithMarker } from '../../utils/truncate';
import { isTransientStatus, isAuthOrConfigStatus } from '../../ai/errors';

suite('Extension Test Suite', () => {
vscode.window.showInformationMessage('Start all tests.');
Expand Down
8 changes: 4 additions & 4 deletions src/test/ai.test.ts → src/test/unit/ai.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as assert from 'assert';
import { selectProvider } from '../ai/selector';
import { registerProvider } from '../ai/registry';
import { PredicteCommitConfig } from '../core/config';
import { ProviderClient, GenerateRequest, GenerateResult } from '../ai/types';
import { selectProvider } from '../../ai/selector';
import { registerProvider } from '../../ai/registry';
import { PredicteCommitConfig } from '../../core/types';
import { ProviderClient, GenerateRequest, GenerateResult } from '../../ai/types';

suite('AI Selector Test Suite', () => {
test('selectProvider selects correct provider', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from 'assert';
import { postChatCompletion } from '../ai/http';
import { ProviderError } from '../ai/errors';
import { postChatCompletion } from '../../ai/http';
import { ProviderError } from '../../ai/errors';

suite('HTTP Error Handling', () => {
test('ECONNREFUSED returns friendly message', async () => {
Expand Down
6 changes: 3 additions & 3 deletions src/test/utils.test.ts → src/test/unit/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as assert from 'assert';
import { isIgnored } from '../utils/ignore';
import { truncateWithMarker, capDiffsByFileAndTotal } from '../utils/truncate';
import { DIFF_CAPS, TRUNCATION_MARKER } from '../core/config';
import { isIgnored } from '../../utils/ignore';
import { truncateWithMarker, capDiffsByFileAndTotal } from '../../utils/truncate';
import { DIFF_CAPS, TRUNCATION_MARKER } from '../../core/constants';

suite('Utils Test Suite', () => {
test('isIgnored', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/truncate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DIFF_CAPS, TRUNCATION_MARKER } from '../core/config';
import { DIFF_CAPS, TRUNCATION_MARKER } from '../core/constants';

export function truncateWithMarker(input: string, maxChars: number): string {
if (input.length <= maxChars) {
Expand Down
Loading