feat(p8): vue IDE /workspace (arbre + Monaco + diff + terminal)
- backend: garde-fou conflit d'édition par mtime (GET renvoie mtime, PUT refuse en 409 STALE_FILE si baseMtime périmé) - lib: wt-key (base64url du chemin worktree), diff-parse (parseur pur du diff unifié → hunks) - composables: useMonaco (import dynamique → chunk isolé), useWorkspaceLayout (largeurs/panneau persistés) - components/workspace: GitStatusBadge, FileTree+FileTreeNode (lazy fs/list includeFiles), ChangedFilesPanel, DiffViewer (coloration +/-), MonacoEditor (Ctrl+S + bannière conflit reload/overwrite) - views/WorkspaceView: 3 colonnes desktop redimensionnables + SegmentedControl mobile, header live (GitStatusBadge), watchWorktree → refresh diff/changements, terminal de la session corrélée - router meta 'ide' + route /workspace/:repoId/:wt ; App.vue plein écran sans AppShell ; WorktreeCard bouton « Ouvrir l'IDE » - deps: monaco-editor (lazy, vendor-monaco isolé, 0 impact bundle initial) ; vite manualChunks - i18n EN+FR (workspace/editor/diff/git) ; tests diff-parse + wt-key ; acceptance-p8.mjs (mtime/409 + diff)
This commit is contained in:
60
packages/web/test/diff-parse.test.ts
Normal file
60
packages/web/test/diff-parse.test.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { parseUnifiedDiff } from '../src/lib/diff-parse';
|
||||
|
||||
const SAMPLE = `diff --git a/README.md b/README.md
|
||||
index 1234567..89abcde 100644
|
||||
--- a/README.md
|
||||
+++ b/README.md
|
||||
@@ -1,3 +1,4 @@
|
||||
# demo
|
||||
+edited line
|
||||
second
|
||||
-old third
|
||||
+new third
|
||||
@@ -10,2 +11,2 @@
|
||||
ten
|
||||
-eleven
|
||||
+ELEVEN`;
|
||||
|
||||
describe('parseUnifiedDiff', () => {
|
||||
it('ignore les en-têtes de fichier avant le premier @@', () => {
|
||||
const r = parseUnifiedDiff(SAMPLE);
|
||||
expect(r.hunks).toHaveLength(2);
|
||||
expect(r.hunks[0].header).toBe('@@ -1,3 +1,4 @@');
|
||||
});
|
||||
|
||||
it('compte additions et suppressions', () => {
|
||||
const r = parseUnifiedDiff(SAMPLE);
|
||||
expect(r.additions).toBe(3); // edited line, new third, ELEVEN
|
||||
expect(r.deletions).toBe(2); // old third, eleven
|
||||
});
|
||||
|
||||
it('numérote correctement les lignes ancien/nouveau', () => {
|
||||
const { hunks } = parseUnifiedDiff(SAMPLE);
|
||||
const lines = hunks[0].lines;
|
||||
expect(lines[0]).toMatchObject({ type: 'context', content: ' # demo'.slice(1), oldLine: 1, newLine: 1 });
|
||||
const add = lines.find((l) => l.type === 'add');
|
||||
expect(add).toMatchObject({ oldLine: null, newLine: 2, content: 'edited line' });
|
||||
const del = lines.find((l) => l.type === 'del');
|
||||
expect(del).toMatchObject({ newLine: null, content: 'old third' });
|
||||
});
|
||||
|
||||
it('ignore le marqueur « \\ No newline at end of file »', () => {
|
||||
const diff = `@@ -1 +1 @@\n-a\n+b\n\\ No newline at end of file`;
|
||||
const r = parseUnifiedDiff(diff);
|
||||
expect(r.additions).toBe(1);
|
||||
expect(r.deletions).toBe(1);
|
||||
expect(r.hunks[0].lines).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('diff vide → aucun hunk', () => {
|
||||
expect(parseUnifiedDiff('').hunks).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('gère un fichier untracked (--- /dev/null)', () => {
|
||||
const diff = `--- /dev/null\n+++ b/new.txt\n@@ -0,0 +1,2 @@\n+line one\n+line two`;
|
||||
const r = parseUnifiedDiff(diff);
|
||||
expect(r.additions).toBe(2);
|
||||
expect(r.hunks[0].lines.every((l) => l.type === 'add')).toBe(true);
|
||||
});
|
||||
});
|
||||
24
packages/web/test/wt-key.test.ts
Normal file
24
packages/web/test/wt-key.test.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { encodeWtKey, decodeWtKey } from '../src/lib/wt-key';
|
||||
|
||||
describe('wt-key (base64url)', () => {
|
||||
const paths = [
|
||||
'/home/johan/WebstormProjects/arboretum',
|
||||
'/srv/code/feature-branch',
|
||||
'/tmp/with space/and-dash',
|
||||
'/projets/accentué/café/é',
|
||||
'/a/b/c/d/e/f/g',
|
||||
];
|
||||
|
||||
it('round-trip encode → decode pour divers chemins', () => {
|
||||
for (const p of paths) expect(decodeWtKey(encodeWtKey(p))).toBe(p);
|
||||
});
|
||||
|
||||
it('produit un segment d’URL sûr (pas de + / =)', () => {
|
||||
for (const p of paths) {
|
||||
const key = encodeWtKey(p);
|
||||
expect(key).not.toMatch(/[+/=]/);
|
||||
expect(encodeURIComponent(key)).toBe(key); // déjà URL-safe
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user