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
20 changes: 20 additions & 0 deletions src/app/new/form-reducer.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, it, expect } from 'vitest';
import { formReducer, initialFormState } from './form-reducer';
import { SESSION_NAME_MAX_LENGTH } from '@/lib/types';
import type { FormState } from './form-reducer';
import type { Repo } from '@/components/RepoSelector';
import type { Issue } from '@/lib/types';
Expand Down Expand Up @@ -204,6 +205,25 @@ describe('formReducer', () => {
expect(result.initialPrompt).toBe('');
});

it('truncates session name to max length when issue title is very long', () => {
const longTitle = 'A'.repeat(200);
const longIssue: Issue = {
...mockIssue,
number: 1,
title: longTitle,
};
const state: FormState = {
...initialFormState,
selectedRepo: mockRepo,
selectedBranch: 'main',
};

const result = formReducer(state, { type: 'selectIssue', issue: longIssue });

expect(result.sessionName.length).toBe(SESSION_NAME_MAX_LENGTH);
expect(result.sessionName).toBe(`#1: ${longTitle}`.slice(0, SESSION_NAME_MAX_LENGTH));
});

it('preserves session name when issue is deselected and name was manually edited', () => {
const state: FormState = {
...initialFormState,
Expand Down
4 changes: 2 additions & 2 deletions src/app/new/form-reducer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Repo } from '@/components/RepoSelector';
import type { Issue } from '@/lib/types';
import { SESSION_NAME_MAX_LENGTH, type Issue } from '@/lib/types';

export interface FormState {
selectedRepo: Repo | null;
Expand Down Expand Up @@ -44,7 +44,7 @@ export function formReducer(state: FormState, action: FormAction): FormState {
sessionName: state.nameManuallyEdited
? state.sessionName
: action.issue
? `#${action.issue.number}: ${action.issue.title}`
? `#${action.issue.number}: ${action.issue.title}`.slice(0, SESSION_NAME_MAX_LENGTH)
: '',
initialPrompt: state.promptManuallyEdited
? state.initialPrompt
Expand Down
8 changes: 5 additions & 3 deletions src/app/new/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { BranchSelector } from '@/components/BranchSelector';
import { IssueSelector } from '@/components/IssueSelector';
import type { Repo } from '@/components/RepoSelector';
import type { Issue } from '@/lib/types';
import { SESSION_NAME_MAX_LENGTH } from '@/lib/types';
import { formReducer, initialFormState } from './form-reducer';

function generateIssuePrompt(issue: Issue, repoFullName: string): string {
Expand Down Expand Up @@ -115,9 +116,9 @@ function NewSessionForm() {
return;
}

const defaultName = isNoRepo
? 'Workspace'
: `${form.selectedRepo.name} - ${form.selectedBranch}`;
const defaultName = (
isNoRepo ? 'Workspace' : `${form.selectedRepo.name} - ${form.selectedBranch}`
).slice(0, SESSION_NAME_MAX_LENGTH);

createMutation.mutate({
name: form.sessionName || defaultName,
Expand Down Expand Up @@ -164,6 +165,7 @@ function NewSessionForm() {
type="text"
value={form.sessionName}
onChange={handleNameChange}
maxLength={SESSION_NAME_MAX_LENGTH}
placeholder={
isNoRepo
? 'Workspace'
Expand Down
3 changes: 3 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export const MessageType = {

export type MessageType = (typeof MessageType)[keyof typeof MessageType];

// Session constants
export const SESSION_NAME_MAX_LENGTH = 100;

// Session interface
export interface Session {
id: string;
Expand Down
3 changes: 2 additions & 1 deletion src/server/routers/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { runClaudeCommand, stopSession } from '../services/claude-runner';
import { sseEvents } from '../services/events';
import { createLogger, toError } from '@/lib/logger';
import { env } from '@/lib/env';
import { SESSION_NAME_MAX_LENGTH } from '@/lib/types';

const log = createLogger('sessions');

Expand Down Expand Up @@ -111,7 +112,7 @@ export const sessionsRouter = router({
create: protectedProcedure
.input(
z.object({
name: z.string().min(1).max(100),
name: z.string().min(1).max(SESSION_NAME_MAX_LENGTH),
repoFullName: z
.string()
.regex(/^[\w-]+\/[\w.-]+$/)
Expand Down
Loading