Merge branch 'v0.15.0rc' into feat/new-claude-and-codex-models

This commit is contained in:
Shirone
2026-02-15 16:49:41 +01:00
8 changed files with 237 additions and 178 deletions

View File

@@ -0,0 +1,106 @@
import { describe, it, expect, vi, beforeEach, type Mock } from 'vitest';
import type { Request, Response } from 'express';
import { createMockExpressContext } from '../../../utils/mocks.js';
vi.mock('child_process', async (importOriginal) => {
const actual = await importOriginal<typeof import('child_process')>();
return {
...actual,
exec: vi.fn(),
};
});
vi.mock('util', async (importOriginal) => {
const actual = await importOriginal<typeof import('util')>();
return {
...actual,
promisify: (fn: unknown) => fn,
};
});
import { exec } from 'child_process';
import { createSwitchBranchHandler } from '@/routes/worktree/routes/switch-branch.js';
const mockExec = exec as Mock;
describe('switch-branch route', () => {
let req: Request;
let res: Response;
beforeEach(() => {
vi.clearAllMocks();
const context = createMockExpressContext();
req = context.req;
res = context.res;
});
it('should allow switching when only untracked files exist', async () => {
req.body = {
worktreePath: '/repo/path',
branchName: 'feature/test',
};
mockExec.mockImplementation(async (command: string) => {
if (command === 'git rev-parse --abbrev-ref HEAD') {
return { stdout: 'main\n', stderr: '' };
}
if (command === 'git rev-parse --verify feature/test') {
return { stdout: 'abc123\n', stderr: '' };
}
if (command === 'git status --porcelain') {
return { stdout: '?? .automaker/\n?? notes.txt\n', stderr: '' };
}
if (command === 'git checkout "feature/test"') {
return { stdout: '', stderr: '' };
}
return { stdout: '', stderr: '' };
});
const handler = createSwitchBranchHandler();
await handler(req, res);
expect(res.json).toHaveBeenCalledWith({
success: true,
result: {
previousBranch: 'main',
currentBranch: 'feature/test',
message: "Switched to branch 'feature/test'",
},
});
expect(mockExec).toHaveBeenCalledWith('git checkout "feature/test"', { cwd: '/repo/path' });
});
it('should block switching when tracked files are modified', async () => {
req.body = {
worktreePath: '/repo/path',
branchName: 'feature/test',
};
mockExec.mockImplementation(async (command: string) => {
if (command === 'git rev-parse --abbrev-ref HEAD') {
return { stdout: 'main\n', stderr: '' };
}
if (command === 'git rev-parse --verify feature/test') {
return { stdout: 'abc123\n', stderr: '' };
}
if (command === 'git status --porcelain') {
return { stdout: ' M src/index.ts\n?? notes.txt\n', stderr: '' };
}
if (command === 'git status --short') {
return { stdout: ' M src/index.ts\n?? notes.txt\n', stderr: '' };
}
return { stdout: '', stderr: '' };
});
const handler = createSwitchBranchHandler();
await handler(req, res);
expect(res.status).toHaveBeenCalledWith(400);
expect(res.json).toHaveBeenCalledWith({
success: false,
error:
'Cannot switch branches: you have uncommitted changes (M src/index.ts). Please commit your changes first.',
code: 'UNCOMMITTED_CHANGES',
});
});
});

View File

@@ -1,6 +1,9 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { AutoModeService } from '@/services/auto-mode-service.js';
import type { Feature } from '@automaker/types';
import fs from 'fs/promises';
import os from 'os';
import path from 'path';
describe('auto-mode-service.ts', () => {
let service: AutoModeService;
@@ -842,4 +845,76 @@ describe('auto-mode-service.ts', () => {
expect(service.isFeatureRunning('feature-3')).toBe(false);
});
});
describe('interrupted recovery', () => {
async function createFeatureFixture(
projectPath: string,
feature: Partial<Feature> & Pick<Feature, 'id'>
): Promise<string> {
const featureDir = path.join(projectPath, '.automaker', 'features', feature.id);
await fs.mkdir(featureDir, { recursive: true });
await fs.writeFile(
path.join(featureDir, 'feature.json'),
JSON.stringify(
{
title: 'Feature',
description: 'Feature description',
category: 'implementation',
status: 'backlog',
...feature,
},
null,
2
)
);
return featureDir;
}
it('should resume features marked as interrupted after restart', async () => {
const projectPath = await fs.mkdtemp(path.join(os.tmpdir(), 'automaker-resume-'));
try {
const featureDir = await createFeatureFixture(projectPath, {
id: 'feature-interrupted',
status: 'interrupted',
});
await fs.writeFile(path.join(featureDir, 'agent-output.md'), 'partial progress');
await createFeatureFixture(projectPath, {
id: 'feature-complete',
status: 'completed',
});
const resumeFeatureMock = vi.fn().mockResolvedValue(undefined);
(service as any).resumeFeature = resumeFeatureMock;
await (service as any).resumeInterruptedFeatures(projectPath);
expect(resumeFeatureMock).toHaveBeenCalledTimes(1);
expect(resumeFeatureMock).toHaveBeenCalledWith(projectPath, 'feature-interrupted', true);
} finally {
await fs.rm(projectPath, { recursive: true, force: true });
}
});
it('should include interrupted features in pending recovery candidates', async () => {
const projectPath = await fs.mkdtemp(path.join(os.tmpdir(), 'automaker-pending-'));
try {
await createFeatureFixture(projectPath, {
id: 'feature-interrupted',
status: 'interrupted',
});
await createFeatureFixture(projectPath, {
id: 'feature-waiting-approval',
status: 'waiting_approval',
});
const pendingFeatures = await (service as any).loadPendingFeatures(projectPath, null);
const pendingIds = pendingFeatures.map((feature: Feature) => feature.id);
expect(pendingIds).toContain('feature-interrupted');
expect(pendingIds).not.toContain('feature-waiting-approval');
} finally {
await fs.rm(projectPath, { recursive: true, force: true });
}
});
});
});