mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-17 03:39:33 +01:00
fix: address the release-prep review of #680
Claude history merges, never overwriting, into a project directory a deleted case of the new name left behind, instead of staying orphaned under the old key. The free-target pre-check also refuses a dangling symlink (lstat), so stopSessions no longer ends sessions before a 409 EXISTS. The rename dialog says stopped sessions are closed (their tabs go away) and, after a failed rename, how many were already closed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
ac6d4aa2db
commit
d1e0e0aea6
10 files changed
+185
-39
No files matched your search
@@ -170,6 +170,8 @@ describe('renameCase / submitRenameCase', () => {
|
||||
|
||||
await t.app.submitRenameCase();
|
||||
expect(t.els.renameCaseError.textContent).toContain('w1-alpha');
|
||||
// "stop" closes them through the server's session cleanup: say that their tabs go away
|
||||
expect(t.els.renameCaseError.textContent).toContain('They will be closed (their tabs go away');
|
||||
expect(t.els.renameCaseSubmit.textContent).toBe('Stop sessions and rename');
|
||||
expect(t.els.renameCaseModal.classes.has('active')).toBe(true);
|
||||
expect(t.calls).toHaveLength(1);
|
||||
@@ -179,6 +181,20 @@ describe('renameCase / submitRenameCase', () => {
|
||||
expect(t.els.renameCaseModal.classes.has('active')).toBe(false);
|
||||
});
|
||||
|
||||
it('says how many sessions were already closed when the rename fails after closing them', async () => {
|
||||
const refusal = { success: false, error: 'busy', requiresStop: true, sessions: [{ id: 's', name: 'w1-alpha' }] };
|
||||
const failed = { success: false, error: 'The registry could not be written.', stoppedSessions: 2 };
|
||||
const t = makeApp({ responses: [refusal, failed], cases: [{ name: 'alpha' }] });
|
||||
t.app.renameCase('alpha');
|
||||
t.els.renameCaseInput.value = 'beta';
|
||||
await t.app.submitRenameCase();
|
||||
await t.app.submitRenameCase();
|
||||
expect(t.els.renameCaseError.textContent).toBe(
|
||||
'The registry could not be written. (2 sessions were already closed.)'
|
||||
);
|
||||
expect(t.els.renameCaseModal.classes.has('active')).toBe(true);
|
||||
});
|
||||
|
||||
it('cancelling the dialog stops nothing and renames nothing', async () => {
|
||||
const t = makeApp({ responses: [], cases: [{ name: 'alpha' }] });
|
||||
t.app.renameCase('alpha');
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* migration. Real filesystem under test/setup.ts's temp HOME. Port: N/A.
|
||||
*/
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { existsSync, mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';
|
||||
import { existsSync, mkdirSync, mkdtempSync, readFileSync, symlinkSync, writeFileSync } from 'node:fs';
|
||||
import fsp from 'node:fs/promises';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
@@ -135,7 +135,7 @@ describe('Claude history', () => {
|
||||
expect(claudeProjectDirName('/home/devvyn/.dotcase')).toBe('-home-devvyn--dotcase');
|
||||
});
|
||||
|
||||
it('moves the old path’s history to the new one, and leaves existing history alone', async () => {
|
||||
it('moves the old path’s history to the new one', async () => {
|
||||
const cfg = tmp();
|
||||
const projects = join(cfg, 'projects');
|
||||
const oldPath = join(tmp(), 'alpha');
|
||||
@@ -145,12 +145,59 @@ describe('Claude history', () => {
|
||||
expect(await moveClaudeHistory(oldPath, newPath, cfg)).toBe(true);
|
||||
expect(existsSync(join(projects, claudeProjectDirName(newPath), 'c.jsonl'))).toBe(true);
|
||||
expect(existsSync(join(projects, claudeProjectDirName(oldPath)))).toBe(false);
|
||||
|
||||
mkdirSync(join(projects, claudeProjectDirName(oldPath)), { recursive: true });
|
||||
expect(await moveClaudeHistory(oldPath, newPath, cfg)).toBe(false); // the target already has history
|
||||
expect(existsSync(join(projects, claudeProjectDirName(oldPath)))).toBe(true);
|
||||
expect(await moveClaudeHistory(join(tmp(), 'none'), newPath, cfg)).toBe(false);
|
||||
});
|
||||
|
||||
it('merges into history already at the new path (a deleted case’s leftovers) without overwriting any of it', async () => {
|
||||
const cfg = tmp();
|
||||
const projects = join(cfg, 'projects');
|
||||
const oldPath = join(tmp(), 'alpha');
|
||||
const newPath = join(tmp(), 'beta');
|
||||
const from = join(projects, claudeProjectDirName(oldPath));
|
||||
const to = join(projects, claudeProjectDirName(newPath));
|
||||
mkdirSync(join(from, 'conv-a', 'subagents'), { recursive: true });
|
||||
writeFileSync(join(from, 'conv-a.jsonl'), 'alpha');
|
||||
writeFileSync(join(from, 'conv-a', 'subagents', 'agent-1.jsonl'), 'alpha agent');
|
||||
mkdirSync(join(from, 'memory'));
|
||||
writeFileSync(join(from, 'memory', 'MEMORY.md'), 'alpha memory');
|
||||
// Claude Code never removes a project directory, so a case deleted earlier under the new name left this.
|
||||
mkdirSync(join(to, 'memory'), { recursive: true });
|
||||
writeFileSync(join(to, 'conv-old.jsonl'), 'old beta');
|
||||
writeFileSync(join(to, 'memory', 'MEMORY.md'), 'old beta memory');
|
||||
|
||||
expect(await moveClaudeHistory(oldPath, newPath, cfg)).toBe(true);
|
||||
|
||||
expect(readFileSync(join(to, 'conv-a.jsonl'), 'utf8')).toBe('alpha');
|
||||
expect(readFileSync(join(to, 'conv-a', 'subagents', 'agent-1.jsonl'), 'utf8')).toBe('alpha agent');
|
||||
expect(readFileSync(join(to, 'conv-old.jsonl'), 'utf8')).toBe('old beta');
|
||||
// an entry both have is never overwritten: it stays where it was
|
||||
expect(readFileSync(join(to, 'memory', 'MEMORY.md'), 'utf8')).toBe('old beta memory');
|
||||
expect(readFileSync(join(from, 'memory', 'MEMORY.md'), 'utf8')).toBe('alpha memory');
|
||||
expect(existsSync(join(from, 'conv-a.jsonl'))).toBe(false);
|
||||
});
|
||||
|
||||
it('removes the old project directory once a merge has emptied it, and never merges into a symlink', async () => {
|
||||
const cfg = tmp();
|
||||
const projects = join(cfg, 'projects');
|
||||
const oldPath = join(tmp(), 'alpha');
|
||||
const newPath = join(tmp(), 'beta');
|
||||
const from = join(projects, claudeProjectDirName(oldPath));
|
||||
const to = join(projects, claudeProjectDirName(newPath));
|
||||
mkdirSync(from, { recursive: true });
|
||||
mkdirSync(to, { recursive: true });
|
||||
writeFileSync(join(from, 'conv-a.jsonl'), 'alpha');
|
||||
expect(await moveClaudeHistory(oldPath, newPath, cfg)).toBe(true);
|
||||
expect(existsSync(from)).toBe(false);
|
||||
|
||||
const elsewhere = tmp();
|
||||
const linkedPath = join(tmp(), 'gamma');
|
||||
mkdirSync(from);
|
||||
writeFileSync(join(from, 'conv-b.jsonl'), 'alpha');
|
||||
symlinkSync(elsewhere, join(projects, claudeProjectDirName(linkedPath)));
|
||||
expect(await moveClaudeHistory(oldPath, linkedPath, cfg)).toBe(false);
|
||||
expect(existsSync(join(from, 'conv-b.jsonl'))).toBe(true);
|
||||
expect(existsSync(join(elsewhere, 'conv-b.jsonl'))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('small helpers', () => {
|
||||
|
||||
@@ -5,7 +5,16 @@
|
||||
* test/setup.ts's temp HOME; every folder is removed through safeRmHomeTree. Port: N/A (app.inject()).
|
||||
*/
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
|
||||
import {
|
||||
chmodSync,
|
||||
existsSync,
|
||||
mkdirSync,
|
||||
mkdtempSync,
|
||||
readFileSync,
|
||||
realpathSync,
|
||||
symlinkSync,
|
||||
writeFileSync,
|
||||
} from 'node:fs';
|
||||
import fs from 'node:fs/promises';
|
||||
import { homedir } from 'node:os';
|
||||
import { basename, dirname, join } from 'node:path';
|
||||
@@ -72,6 +81,43 @@ describe('POST /api/cases/:name/rename (a case under the cases directory)', () =
|
||||
expect(existsSync(join(claudeCfg, 'projects', claudeProjectDirName(newDir), 'c.jsonl'))).toBe(true);
|
||||
});
|
||||
|
||||
it('carries Claude history into the project directory a deleted case of the new name left behind', async () => {
|
||||
const { app } = await createRouteTestHarness(registerCaseRoutes);
|
||||
const oldDir = localCase('alpha');
|
||||
const newDir = join(CASES_DIR(), 'beta');
|
||||
const oldKey = join(claudeCfg, 'projects', claudeProjectDirName(oldDir));
|
||||
const newKey = join(claudeCfg, 'projects', claudeProjectDirName(newDir));
|
||||
mkdirSync(oldKey, { recursive: true });
|
||||
writeFileSync(join(oldKey, 'conv-alpha.jsonl'), '{}');
|
||||
// case delete never removes Claude Code's history, so an earlier "beta" left its project directory
|
||||
mkdirSync(newKey, { recursive: true });
|
||||
writeFileSync(join(newKey, 'conv-old-beta.jsonl'), '{}');
|
||||
|
||||
const res = await rename(app, 'alpha', { newName: 'beta' });
|
||||
made.push(newDir);
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(existsSync(join(newKey, 'conv-alpha.jsonl'))).toBe(true);
|
||||
expect(existsSync(join(newKey, 'conv-old-beta.jsonl'))).toBe(true);
|
||||
expect(existsSync(oldKey)).toBe(false);
|
||||
});
|
||||
|
||||
it('refuses a dangling symlink at the new folder before it stops any session', async () => {
|
||||
const { app, ctx } = await createRouteTestHarness(registerCaseRoutes);
|
||||
const oldDir = localCase('alpha');
|
||||
const target = join(CASES_DIR(), 'beta');
|
||||
symlinkSync(join(work, 'nowhere'), target);
|
||||
made.push(target);
|
||||
(ctx.sessions as Map<string, unknown>).set('s1', { id: 's1', name: 'w1', workingDir: oldDir });
|
||||
|
||||
const res = await rename(app, 'alpha', { newName: 'beta', stopSessions: true });
|
||||
|
||||
expect(res.statusCode).toBe(409);
|
||||
expect(res.json().errorCode).toBe('ALREADY_EXISTS');
|
||||
expect(ctx.cleanupSession).not.toHaveBeenCalled();
|
||||
expect(existsSync(oldDir)).toBe(true);
|
||||
});
|
||||
|
||||
it('refuses a name that is taken (local or linked), the same name, or one that is not allowed', async () => {
|
||||
const { app } = await createRouteTestHarness(registerCaseRoutes);
|
||||
localCase('alpha');
|
||||
|
||||
Reference in new issue
Block a user