mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-06 15:39:41 +02:00
Merge pull request #535 from opticon454/feat/case-custom-path
feat(cases): create a new case in a custom folder
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
/** @fileoverview Add Case → Create New → "Create in a custom folder", end to end: real server, real Chromium, real folders. */
|
||||
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
||||
import { homedir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
||||
import { chromium, type Browser, type Page } from 'playwright';
|
||||
import { WebServer } from '../src/web/server.js';
|
||||
|
||||
declare const PathPicker: any; // evaluated inside the page, where it is a global
|
||||
|
||||
const PORT = 3193;
|
||||
|
||||
describe('Create a case in a custom folder', () => {
|
||||
let server: WebServer;
|
||||
let browser: Browser;
|
||||
let page: Page;
|
||||
let parent: string;
|
||||
|
||||
beforeAll(async () => {
|
||||
parent = mkdtempSync(join(homedir(), 'custom-case-'));
|
||||
server = new WebServer(PORT, false, true);
|
||||
await server.start();
|
||||
browser = await chromium.launch({ headless: true });
|
||||
page = await browser.newPage();
|
||||
await page.goto(`http://localhost:${PORT}`, { waitUntil: 'domcontentloaded' });
|
||||
await page.waitForFunction(() => (window as any).app?.terminal, null, { timeout: 30000 });
|
||||
}, 90000);
|
||||
|
||||
afterAll(async () => {
|
||||
if (browser) await browser.close();
|
||||
if (server) await server.stop();
|
||||
rmSync(parent, { recursive: true, force: true });
|
||||
}, 60000);
|
||||
|
||||
const open = async () => {
|
||||
await page.evaluate(() => {
|
||||
(window as any).app.showCreateCaseModal();
|
||||
(window as any).app.switchCaseModalTab('case-create');
|
||||
});
|
||||
};
|
||||
const toastText = () =>
|
||||
page.evaluate(() => [...document.querySelectorAll('.toast')].map((t) => t.textContent).join('|'));
|
||||
|
||||
it('hides the parent-folder field until the box is ticked, and shows what it will create', async () => {
|
||||
await open();
|
||||
expect(await page.isVisible('#newCaseCustomPathRow')).toBe(false);
|
||||
await page.click('label.checkbox-row:has(#newCaseCustomPathToggle)');
|
||||
expect(await page.isVisible('#newCaseCustomPathRow')).toBe(true);
|
||||
await page.fill('#newCaseName', 'my-app');
|
||||
await page.fill('#newCasePath', '~/projects/');
|
||||
expect(await page.textContent('#newCasePathPreview')).toBe('Will create: ~/projects/my-app');
|
||||
});
|
||||
|
||||
it('is exclusive with the Docker option, in both directions', async () => {
|
||||
await open();
|
||||
await page.click('label.checkbox-row:has(#newCaseCustomPathToggle)');
|
||||
expect(await page.isDisabled('#newCaseDocker')).toBe(true);
|
||||
await page.click('label.checkbox-row:has(#newCaseCustomPathToggle)');
|
||||
expect(await page.isDisabled('#newCaseDocker')).toBe(false);
|
||||
await page.click('label.checkbox-row:has(#newCaseDocker)');
|
||||
expect(await page.isDisabled('#newCaseCustomPathToggle')).toBe(true);
|
||||
await page.click('label.checkbox-row:has(#newCaseDocker)');
|
||||
});
|
||||
|
||||
it('Browse opens the folder picker for directories only and fills the field with the choice', async () => {
|
||||
await open();
|
||||
await page.click('label.checkbox-row:has(#newCaseCustomPathToggle)');
|
||||
await page.fill('#newCaseName', 'picked');
|
||||
const opts = await page.evaluate(() => {
|
||||
// A top-level `const` in a classic script: a global binding, not a window property.
|
||||
const picker = PathPicker;
|
||||
let captured: any = null;
|
||||
const original = picker.open;
|
||||
picker.open = (o: any) => (captured = o);
|
||||
(document.querySelector('#newCaseCustomPathRow .path-input-browse') as HTMLElement).click();
|
||||
picker.open = original;
|
||||
captured.onSelect('/srv/work');
|
||||
return { directoriesOnly: captured.directoriesOnly };
|
||||
});
|
||||
expect(opts.directoriesOnly).toBe(true);
|
||||
expect(await page.inputValue('#newCasePath')).toBe('/srv/work');
|
||||
expect(await page.textContent('#newCasePathPreview')).toBe('Will create: /srv/work/picked');
|
||||
});
|
||||
|
||||
it('asks for a folder when the box is ticked and the field is empty, and creates nothing', async () => {
|
||||
await open();
|
||||
await page.click('label.checkbox-row:has(#newCaseCustomPathToggle)');
|
||||
await page.fill('#newCaseName', 'no-folder');
|
||||
await page.evaluate(() => (window as any).app.createCase());
|
||||
expect(await toastText()).toMatch(/Choose the folder/);
|
||||
});
|
||||
|
||||
it('creates the case in the chosen folder, scaffolds it, and lists it at that path', async () => {
|
||||
await open();
|
||||
await page.click('label.checkbox-row:has(#newCaseCustomPathToggle)');
|
||||
await page.fill('#newCaseName', 'in-custom');
|
||||
await page.fill('#newCasePath', parent);
|
||||
await page.evaluate(() => (window as any).app.submitCaseModal());
|
||||
await page.waitForFunction(() =>
|
||||
/created in/.test([...document.querySelectorAll('.toast')].map((t) => t.textContent).join('|'))
|
||||
);
|
||||
const target = join(parent, 'in-custom');
|
||||
expect(readFileSync(join(target, 'CLAUDE.md'), 'utf8')).toContain('in-custom');
|
||||
expect(existsSync(join(target, 'src'))).toBe(true);
|
||||
const cases = await page.evaluate(async () => {
|
||||
const body = await (await fetch('/api/cases')).json();
|
||||
return Array.isArray(body) ? body : body.data;
|
||||
});
|
||||
expect(cases.find((c: { name: string }) => c.name === 'in-custom')).toMatchObject({ path: target });
|
||||
expect(existsSync(join(homedir(), 'codeman-cases', 'in-custom'))).toBe(false);
|
||||
expect(await page.isVisible('#createCaseModal.active')).toBe(false);
|
||||
});
|
||||
|
||||
it('shows the server’s reason for a folder that already has files, and leaves it untouched', async () => {
|
||||
const busy = join(parent, 'busy');
|
||||
mkdirSync(busy);
|
||||
writeFileSync(join(busy, 'keep.txt'), 'mine');
|
||||
await open();
|
||||
await page.click('label.checkbox-row:has(#newCaseCustomPathToggle)');
|
||||
await page.fill('#newCaseName', 'busy');
|
||||
await page.fill('#newCasePath', parent);
|
||||
await page.evaluate(() => (window as any).app.createCase());
|
||||
await page.waitForFunction(() =>
|
||||
/Link Existing/.test([...document.querySelectorAll('.toast')].map((t) => t.textContent).join('|'))
|
||||
);
|
||||
expect(readFileSync(join(busy, 'keep.txt'), 'utf8')).toBe('mine');
|
||||
expect(existsSync(join(busy, 'CLAUDE.md'))).toBe(false);
|
||||
});
|
||||
|
||||
it('starts unticked every time the modal opens', async () => {
|
||||
await open();
|
||||
await page.click('label.checkbox-row:has(#newCaseCustomPathToggle)');
|
||||
await page.fill('#newCasePath', '/tmp');
|
||||
await open();
|
||||
expect(await page.isChecked('#newCaseCustomPathToggle')).toBe(false);
|
||||
expect(await page.inputValue('#newCasePath')).toBe('');
|
||||
expect(await page.isVisible('#newCaseCustomPathRow')).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,147 @@
|
||||
// @vitest-environment node
|
||||
import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
||||
import { blockedReason, expandHome, prepareNewCasePath, type NewCasePathContext } from '../src/web/case-path.js';
|
||||
|
||||
let root: string;
|
||||
let home: string;
|
||||
let ctx: NewCasePathContext;
|
||||
|
||||
beforeEach(() => {
|
||||
root = mkdtempSync(join(tmpdir(), 'case-path-'));
|
||||
home = join(root, 'home');
|
||||
mkdirSync(join(home, 'code'), { recursive: true });
|
||||
ctx = { home, dataDir: join(home, '.codeman') };
|
||||
});
|
||||
afterEach(() => rmSync(root, { recursive: true, force: true }));
|
||||
|
||||
describe('expandHome', () => {
|
||||
it('expands ~ and ~/x only', () => {
|
||||
expect(expandHome('~', '/h')).toBe('/h');
|
||||
expect(expandHome('~/code/app', '/h')).toBe('/h/code/app');
|
||||
expect(expandHome('~other/x', '/h')).toBe('~other/x');
|
||||
expect(expandHome('/abs/~/x', '/h')).toBe('/abs/~/x');
|
||||
});
|
||||
});
|
||||
|
||||
describe('blockedReason', () => {
|
||||
const c = { home: '/home/u', dataDir: '/home/u/.codeman' };
|
||||
it.each([
|
||||
['/', /root/],
|
||||
['/etc', /system directory/],
|
||||
['/etc/cron.d/x', /system directory/],
|
||||
['/usr/local/src', /system directory/],
|
||||
['/proc/1', /system directory/],
|
||||
['/home/u', /home folder itself/],
|
||||
['/home/u/.ssh', /credentials/],
|
||||
['/home/u/.ssh/proj', /credentials/],
|
||||
['/home/u/.aws/x', /credentials/],
|
||||
['/home/u/.claude/skills/x', /configuration/],
|
||||
['/home/u/.codeman/cases/x', /data folder/],
|
||||
['/home/u/.codeman-beta/x', /data folder/],
|
||||
])('refuses %s', (p, why) => expect(blockedReason(p, c)).toMatch(why));
|
||||
|
||||
it.each(['/home/u/code/app', '/home/u/.config/app', '/srv/projects/x', '/opt/work', '/tmp/x', '/home/u/etc/app'])(
|
||||
'allows %s (a name that merely contains a blocked word is fine)',
|
||||
(p) => expect(blockedReason(p, c)).toBeNull()
|
||||
);
|
||||
|
||||
it('does not treat /etcetera or /usrlocal as the system directories', () => {
|
||||
expect(blockedReason('/etcetera/x', c)).toBeNull();
|
||||
expect(blockedReason('/usrlocal', c)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('prepareNewCasePath', () => {
|
||||
it('accepts a new folder under an existing parent and reports it does not exist yet', async () => {
|
||||
const r = await prepareNewCasePath(join(home, 'code', 'new-app'), ctx);
|
||||
expect(r).toMatchObject({ ok: true, existedEmpty: false });
|
||||
if (r.ok) expect(r.path).toMatch(/code\/new-app$/);
|
||||
});
|
||||
|
||||
it('accepts an existing EMPTY folder and says so', async () => {
|
||||
mkdirSync(join(home, 'code', 'empty'));
|
||||
expect(await prepareNewCasePath(join(home, 'code', 'empty'), ctx)).toMatchObject({ ok: true, existedEmpty: true });
|
||||
});
|
||||
|
||||
it('expands ~, tolerates a trailing slash and a ./ segment, and accepts spaces', async () => {
|
||||
const a = await prepareNewCasePath('~/code/from-tilde', ctx);
|
||||
expect(a.ok && a.path).toBe(join(home, 'code', 'from-tilde'));
|
||||
// A "./" segment and a trailing slash normalise away; the folder name may contain a space.
|
||||
const b = await prepareNewCasePath(`${join(home, 'code')}/./with space/`, ctx);
|
||||
expect(b.ok && b.path).toBe(join(home, 'code', 'with space'));
|
||||
// ...and a folder with a space in it can be the PARENT of the next one.
|
||||
mkdirSync(join(home, 'code', 'with space'));
|
||||
expect(await prepareNewCasePath(`${join(home, 'code', 'with space')}/proj/`, ctx)).toMatchObject({ ok: true });
|
||||
});
|
||||
|
||||
it.each([
|
||||
['empty', ''],
|
||||
['whitespace', ' '],
|
||||
['relative', 'code/app'],
|
||||
['dot-relative', './app'],
|
||||
['traversal', '/tmp/../etc/x'],
|
||||
['shell metacharacters', '/tmp/a;rm -rf /'],
|
||||
['command substitution', '/tmp/$(id)'],
|
||||
['quotes', "/tmp/it's"],
|
||||
['newline', '/tmp/a\nb'],
|
||||
])('rejects %s as invalid', async (_label, raw) => {
|
||||
expect(await prepareNewCasePath(raw, ctx)).toMatchObject({ ok: false, code: 'INVALID' });
|
||||
});
|
||||
|
||||
it('refuses system, home, credential and Codeman folders as BLOCKED', async () => {
|
||||
for (const raw of [
|
||||
'/etc/proj',
|
||||
'/usr/src/x',
|
||||
home,
|
||||
join(home, '.ssh', 'x'),
|
||||
join(home, '.codeman', 'cases', 'x'),
|
||||
]) {
|
||||
expect(await prepareNewCasePath(raw, ctx), raw).toMatchObject({ ok: false, code: 'BLOCKED' });
|
||||
}
|
||||
});
|
||||
|
||||
it('judges the symlink-resolved path too: a link into a blocked tree is not a way around it', async () => {
|
||||
symlinkSync('/etc', join(home, 'code', 'sneaky'));
|
||||
expect(await prepareNewCasePath(join(home, 'code', 'sneaky', 'proj'), ctx)).toMatchObject({
|
||||
ok: false,
|
||||
code: 'BLOCKED',
|
||||
});
|
||||
});
|
||||
|
||||
it('reports a missing parent as NOT_FOUND and never makes a chain of folders', async () => {
|
||||
const r = await prepareNewCasePath(join(home, 'code', 'nope', 'deeper', 'app'), ctx);
|
||||
expect(r).toMatchObject({ ok: false, code: 'NOT_FOUND' });
|
||||
});
|
||||
|
||||
it('refuses a parent that is a file', async () => {
|
||||
writeFileSync(join(home, 'code', 'afile'), 'x');
|
||||
expect(await prepareNewCasePath(join(home, 'code', 'afile', 'app'), ctx)).toMatchObject({ ok: false });
|
||||
});
|
||||
|
||||
it('refuses a folder that already has files in it, pointing at Link Existing', async () => {
|
||||
mkdirSync(join(home, 'code', 'mine'));
|
||||
writeFileSync(join(home, 'code', 'mine', 'README.md'), 'hello');
|
||||
const r = await prepareNewCasePath(join(home, 'code', 'mine'), ctx);
|
||||
expect(r).toMatchObject({ ok: false, code: 'EXISTS' });
|
||||
if (!r.ok) expect(r.reason).toMatch(/Link Existing/);
|
||||
});
|
||||
|
||||
it('refuses a target that is a file or a symbolic link', async () => {
|
||||
writeFileSync(join(home, 'code', 'plain'), 'x');
|
||||
expect(await prepareNewCasePath(join(home, 'code', 'plain'), ctx)).toMatchObject({ ok: false, code: 'INVALID' });
|
||||
mkdirSync(join(home, 'code', 'real'));
|
||||
symlinkSync(join(home, 'code', 'real'), join(home, 'code', 'link'));
|
||||
const r = await prepareNewCasePath(join(home, 'code', 'link'), ctx);
|
||||
expect(r).toMatchObject({ ok: false, code: 'INVALID' });
|
||||
if (!r.ok) expect(r.reason).toMatch(/symbolic link/);
|
||||
});
|
||||
|
||||
it('never creates anything', async () => {
|
||||
await prepareNewCasePath(join(home, 'code', 'dry-run'), ctx);
|
||||
const { existsSync } = await import('node:fs');
|
||||
expect(existsSync(join(home, 'code', 'dry-run'))).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
* @fileoverview POST /api/cases with a `path`: create a new case in a custom folder. Real
|
||||
* filesystem under test/setup.ts's temp HOME (the path policy itself is in test/case-path.test.ts).
|
||||
* Port: N/A (app.inject()).
|
||||
*/
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
||||
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
||||
import { homedir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { createRouteTestHarness } from './_route-test-utils.js';
|
||||
import { registerCaseRoutes } from '../../src/web/routes/case-routes.js';
|
||||
import { dataPath } from '../../src/config/instance.js';
|
||||
|
||||
const LINKED = () => dataPath('linked-cases.json');
|
||||
const work = () => join(homedir(), 'projects');
|
||||
const linked = (): Record<string, string> => (existsSync(LINKED()) ? JSON.parse(readFileSync(LINKED(), 'utf8')) : {});
|
||||
const create = (app: Awaited<ReturnType<typeof createRouteTestHarness>>['app'], payload: Record<string, unknown>) =>
|
||||
app.inject({ method: 'POST', url: '/api/cases', payload });
|
||||
|
||||
beforeEach(() => {
|
||||
rmSync(work(), { recursive: true, force: true });
|
||||
rmSync(LINKED(), { recursive: true, force: true });
|
||||
mkdirSync(work(), { recursive: true });
|
||||
});
|
||||
afterEach(() => {
|
||||
delete process.env.CODEMAN_MULTIUSER;
|
||||
rmSync(work(), { recursive: true, force: true });
|
||||
rmSync(LINKED(), { recursive: true, force: true });
|
||||
});
|
||||
|
||||
describe('POST /api/cases with a custom path', () => {
|
||||
it('creates the folder, scaffolds it like a normal case, and registers it as a linked case', async () => {
|
||||
const { app } = await createRouteTestHarness(registerCaseRoutes);
|
||||
const target = join(work(), 'my-app');
|
||||
const res = await create(app, { name: 'my-app', description: 'A thing', path: target });
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.json().data.case).toEqual({ name: 'my-app', path: target });
|
||||
expect(readFileSync(join(target, 'CLAUDE.md'), 'utf8')).toContain('my-app');
|
||||
expect(existsSync(join(target, 'src'))).toBe(true);
|
||||
expect(existsSync(join(target, '.claude', 'settings.local.json'))).toBe(true);
|
||||
expect(linked()).toEqual({ 'my-app': target });
|
||||
});
|
||||
|
||||
it('appears in GET /api/cases at its custom path', async () => {
|
||||
const { app } = await createRouteTestHarness(registerCaseRoutes);
|
||||
const target = join(work(), 'listed');
|
||||
await create(app, { name: 'listed', path: target });
|
||||
const list = (await app.inject({ method: 'GET', url: '/api/cases' })).json();
|
||||
const cases = Array.isArray(list) ? list : list.data;
|
||||
expect(cases.find((c: { name: string }) => c.name === 'listed')).toMatchObject({ path: target });
|
||||
});
|
||||
|
||||
it('expands ~ and fills an existing EMPTY folder', async () => {
|
||||
const { app } = await createRouteTestHarness(registerCaseRoutes);
|
||||
mkdirSync(join(work(), 'empty-one'));
|
||||
const res = await create(app, { name: 'empty-one', path: '~/projects/empty-one' });
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(existsSync(join(work(), 'empty-one', 'CLAUDE.md'))).toBe(true);
|
||||
});
|
||||
|
||||
it('leaves the cases directory alone: nothing is created under codeman-cases', async () => {
|
||||
const { app } = await createRouteTestHarness(registerCaseRoutes);
|
||||
await create(app, { name: 'elsewhere', path: join(work(), 'elsewhere') });
|
||||
expect(existsSync(join(homedir(), 'codeman-cases', 'elsewhere'))).toBe(false);
|
||||
});
|
||||
|
||||
it('refuses a folder that already has files (409) and touches nothing', async () => {
|
||||
const { app } = await createRouteTestHarness(registerCaseRoutes);
|
||||
mkdirSync(join(work(), 'existing'));
|
||||
writeFileSync(join(work(), 'existing', 'keep.txt'), 'mine');
|
||||
const res = await create(app, { name: 'existing', path: join(work(), 'existing') });
|
||||
expect(res.statusCode).toBe(409);
|
||||
expect(res.json().error).toMatch(/Link Existing/);
|
||||
expect(readdirSync(join(work(), 'existing'))).toEqual(['keep.txt']);
|
||||
expect(linked()).toEqual({});
|
||||
});
|
||||
|
||||
it.each([
|
||||
['a system folder', () => '/etc/my-case', 400],
|
||||
['a credential folder', () => join(homedir(), '.ssh', 'x'), 400],
|
||||
['the home folder itself', () => homedir(), 400],
|
||||
['a relative path', () => 'projects/x', 400],
|
||||
['a path with traversal', () => `${work()}/../x`, 400],
|
||||
['a missing parent', () => join(work(), 'nope', 'deep', 'app'), 404],
|
||||
] as const)('refuses %s', async (_label, path, status) => {
|
||||
const { app } = await createRouteTestHarness(registerCaseRoutes);
|
||||
const res = await create(app, { name: 'x', path: path() });
|
||||
expect(res.statusCode).toBe(status);
|
||||
expect(linked()).toEqual({});
|
||||
});
|
||||
|
||||
it('refuses a duplicate case name, and a folder that is already a case, without creating anything', async () => {
|
||||
const { app } = await createRouteTestHarness(registerCaseRoutes);
|
||||
await create(app, { name: 'one', path: join(work(), 'one') });
|
||||
const dupName = await create(app, { name: 'one', path: join(work(), 'two') });
|
||||
expect(dupName.statusCode).toBe(409);
|
||||
expect(existsSync(join(work(), 'two'))).toBe(false);
|
||||
// Same folder under another name: the first case's folder now has files, which is refused earlier.
|
||||
const dupPath = await create(app, { name: 'other', path: join(work(), 'one') });
|
||||
expect(dupPath.statusCode).toBe(409);
|
||||
expect(linked()).toEqual({ one: join(work(), 'one') });
|
||||
});
|
||||
|
||||
it('validates the case name like a normal create', async () => {
|
||||
const { app } = await createRouteTestHarness(registerCaseRoutes);
|
||||
const res = await create(app, { name: '../evil', path: join(work(), 'x') });
|
||||
expect(res.statusCode).toBe(400);
|
||||
expect(existsSync(join(work(), 'x'))).toBe(false);
|
||||
});
|
||||
|
||||
it('undoes what it created when registering fails (a new folder is removed entirely)', async () => {
|
||||
const { app } = await createRouteTestHarness(registerCaseRoutes);
|
||||
mkdirSync(LINKED(), { recursive: true }); // writeFile onto a directory fails
|
||||
const res = await create(app, { name: 'doomed', path: join(work(), 'doomed') });
|
||||
expect(res.statusCode).toBe(500);
|
||||
expect(existsSync(join(work(), 'doomed'))).toBe(false);
|
||||
});
|
||||
|
||||
it('undoes only the scaffold inside an empty folder the user picked, leaving the folder', async () => {
|
||||
const { app } = await createRouteTestHarness(registerCaseRoutes);
|
||||
mkdirSync(join(work(), 'picked'));
|
||||
mkdirSync(LINKED(), { recursive: true });
|
||||
const res = await create(app, { name: 'picked', path: join(work(), 'picked') });
|
||||
expect(res.statusCode).toBe(500);
|
||||
expect(existsSync(join(work(), 'picked'))).toBe(true);
|
||||
expect(readdirSync(join(work(), 'picked'))).toEqual([]);
|
||||
});
|
||||
|
||||
it('a request without a path still creates under the cases directory, as before', async () => {
|
||||
const { app } = await createRouteTestHarness(registerCaseRoutes);
|
||||
const res = await create(app, { name: 'plain-case' });
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(existsSync(join(homedir(), 'codeman-cases', 'plain-case', 'CLAUDE.md'))).toBe(true);
|
||||
expect(linked()).toEqual({});
|
||||
rmSync(join(homedir(), 'codeman-cases', 'plain-case'), { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it('multi-user: a non-admin is refused (403) and nothing is created; an admin is allowed', async () => {
|
||||
process.env.CODEMAN_MULTIUSER = '1';
|
||||
const user = await createRouteTestHarness(registerCaseRoutes, { authUser: { username: 'bob', role: 'user' } });
|
||||
const denied = await create(user.app, { name: 'bobs', path: join(work(), 'bobs') });
|
||||
expect(denied.statusCode).toBe(403);
|
||||
expect(existsSync(join(work(), 'bobs'))).toBe(false);
|
||||
expect(linked()).toEqual({});
|
||||
const admin = await createRouteTestHarness(registerCaseRoutes, { authUser: { username: 'root', role: 'admin' } });
|
||||
expect((await create(admin.app, { name: 'roots', path: join(work(), 'roots') })).statusCode).toBe(200);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user