Browse Source

fix(interview): simplify session rename and harden update call

Michael Henke 1 month ago
parent
commit
c9baa86efb
2 changed files with 55 additions and 13 deletions
  1. 49 0
      src/interview/interview.test.ts
  2. 6 13
      src/interview/service.ts

+ 49 - 0
src/interview/interview.test.ts

@@ -174,6 +174,55 @@ describe('interview service', () => {
       await fs.rm(tempDir, { recursive: true, force: true });
     });
 
+    test('renames session with interview title on creation', async () => {
+      const tempDir = await fs.mkdtemp('/tmp/interview-test-');
+      const ctx = createMockContext({ directory: tempDir });
+      const service = createInterviewService(ctx);
+      service.setBaseUrlResolver(async () => 'http://localhost:9999');
+      const output = { parts: [] as Array<{ type: string; text?: string }> };
+
+      await service.handleCommandExecuteBefore(
+        {
+          command: 'interview',
+          sessionID: 'session-rename',
+          arguments: 'build a task manager',
+        },
+        output,
+      );
+
+      expect(ctx.client.session.update).toHaveBeenCalledTimes(1);
+      expect(ctx.client.session.update.mock.calls[0][0]).toEqual({
+        path: { id: 'session-rename' },
+        body: { title: 'Interview: build a task manager' },
+      });
+
+      await fs.rm(tempDir, { recursive: true, force: true });
+    });
+
+    test('truncates session title to 50 chars with ellipsis', async () => {
+      const tempDir = await fs.mkdtemp('/tmp/interview-test-');
+      const ctx = createMockContext({ directory: tempDir });
+      const service = createInterviewService(ctx);
+      service.setBaseUrlResolver(async () => 'http://localhost:9999');
+      const output = { parts: [] as Array<{ type: string; text?: string }> };
+
+      const longIdea = 'a'.repeat(60);
+      await service.handleCommandExecuteBefore(
+        {
+          command: 'interview',
+          sessionID: 'session-truncate',
+          arguments: longIdea,
+        },
+        output,
+      );
+
+      const title = ctx.client.session.update.mock.calls[0][0].body.title;
+      expect(title.length).toBe(50);
+      expect(title.endsWith('…')).toBe(true);
+
+      await fs.rm(tempDir, { recursive: true, force: true });
+    });
+
     test('creates markdown file with slug-only filename (no timestamp prefix)', async () => {
       const tempDir = await fs.mkdtemp('/tmp/interview-test-');
       const ctx = createMockContext({ directory: tempDir });

+ 6 - 13
src/interview/service.ts

@@ -688,24 +688,17 @@ export function createInterviewService(
     );
 
     // best-effort: rename the session so it's identifiable in the session list.
-    // strip a leading imperative verb (e.g. "build a") and cap length so the
-    // title stays short in the session list. never block interview creation
-    // if the rename fails.
-    const titleIdea = idea.replace(
-      /^(build|create|make|write|design|implement|add|set up)\s+(a|an|the)\s+/i,
-      '',
-    );
-    let sessionTitle = `Interview: ${titleIdea}`;
-    const MAX_TITLE = 50;
-    if (sessionTitle.length > MAX_TITLE) {
-      sessionTitle = `${sessionTitle.slice(0, MAX_TITLE - 1)}…`;
+    // never block interview creation if the rename fails.
+    let sessionTitle = `Interview: ${idea}`;
+    if (sessionTitle.length > 50) {
+      sessionTitle = `${sessionTitle.slice(0, 49)}…`;
     }
     ctx.client.session
-      .update({
+      .update?.({
         path: { id: input.sessionID },
         body: { title: sessionTitle },
       })
-      .catch(() => {});
+      ?.catch(() => {});
   }
 
   async function handleEvent(input: {