feat(web): search the whole panel from one place
Finding anything meant knowing which tab it lived in — fine once you have learned the panel, hopeless before. ⌘K now covers cards, repositories, issues, wiki pages and members at once. Pages are matched in the browser, so the palette answers before it has asked the server and stays useful while the forge is down. Each remote source is queried independently and a source that fails is simply absent from the results, rather than taking the others with it. Issues come from one organization-wide request: per repository, the palette could not afford them on every keystroke. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
fcc82d82d6
commit
9acb523510
10 files changed
+926
-3
No files matched your search
@@ -0,0 +1,100 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, it } from 'node:test';
|
||||
import { grouped, localPages } from '../src/web/public/core/palette.js';
|
||||
|
||||
/**
|
||||
* Command palette, the parts that hold no DOM (M19).
|
||||
*
|
||||
* Both are small and both are the kind of thing that degrades quietly: a
|
||||
* heading above every line, or a page offered to someone who cannot open it.
|
||||
*/
|
||||
|
||||
const result = (kind, title) => ({ kind, title });
|
||||
|
||||
describe('grouping the results', () => {
|
||||
/** The forge returns issues and pull requests interleaved. */
|
||||
it('gathers each kind, however they arrive', () => {
|
||||
const order = grouped([
|
||||
result('issue', 'i1'),
|
||||
result('pull', 'p1'),
|
||||
result('issue', 'i2'),
|
||||
result('pull', 'p2'),
|
||||
]).map((entry) => entry.kind);
|
||||
|
||||
assert.deepEqual(order, ['issue', 'issue', 'pull', 'pull']);
|
||||
});
|
||||
|
||||
it('keeps the order the server chose inside a group', () => {
|
||||
const titles = grouped([
|
||||
result('card', 'première'),
|
||||
result('page', 'une page'),
|
||||
result('card', 'seconde'),
|
||||
])
|
||||
.filter((entry) => entry.kind === 'card')
|
||||
.map((entry) => entry.title);
|
||||
|
||||
assert.deepEqual(titles, ['première', 'seconde']);
|
||||
});
|
||||
|
||||
it('puts the pages first and the members last', () => {
|
||||
const order = grouped([
|
||||
result('member', 'quelqu’un'),
|
||||
result('repository', 'FWS/x'),
|
||||
result('page', 'Dépôts'),
|
||||
]).map((entry) => entry.kind);
|
||||
|
||||
assert.deepEqual(order, ['page', 'repository', 'member']);
|
||||
});
|
||||
|
||||
it('sends an unknown kind to the end rather than dropping it', () => {
|
||||
const order = grouped([result('inconnu', '?'), result('page', 'Dépôts')]).map((entry) => entry.kind);
|
||||
assert.deepEqual(order, ['page', 'inconnu']);
|
||||
});
|
||||
|
||||
it('survives an empty answer', () => {
|
||||
assert.deepEqual(grouped([]), []);
|
||||
});
|
||||
});
|
||||
|
||||
describe('matching the pages locally', () => {
|
||||
const pages = [
|
||||
{ path: '', label: 'Vue d’ensemble', group: 'Pilotage' },
|
||||
{ path: 'tasks', label: 'Mes tâches', group: 'Pilotage' },
|
||||
{ path: 'repos', label: 'Dépôts', group: 'Code' },
|
||||
{ path: 'settings', label: 'Paramètres', group: 'Système' },
|
||||
];
|
||||
|
||||
it('lists everything when nothing is typed', () => {
|
||||
assert.equal(localPages(pages, '').length, pages.length);
|
||||
});
|
||||
|
||||
it('matches on the label', () => {
|
||||
assert.deepEqual(
|
||||
localPages(pages, 'tâche').map((entry) => entry.title),
|
||||
['Mes tâches'],
|
||||
);
|
||||
});
|
||||
|
||||
/** Typing the section is how people who know the panel navigate it. */
|
||||
it('matches on the group', () => {
|
||||
assert.deepEqual(
|
||||
localPages(pages, 'pilotage').map((entry) => entry.title),
|
||||
['Vue d’ensemble', 'Mes tâches'],
|
||||
);
|
||||
});
|
||||
|
||||
it('points at the hash route of each page', () => {
|
||||
const [overview] = localPages(pages, 'ensemble');
|
||||
assert.equal(overview.href, '#/');
|
||||
assert.equal(localPages(pages, 'dépôt')[0].href, '#/repos');
|
||||
});
|
||||
|
||||
/**
|
||||
* The caller passes only the pages the visitor can see, so a page missing
|
||||
* from that list must never surface — the palette does no filtering of its own.
|
||||
*/
|
||||
it('offers nothing beyond the list it was given', () => {
|
||||
const visible = pages.filter((page) => page.path !== 'settings');
|
||||
assert.deepEqual(localPages(visible, 'paramètres'), []);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,199 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { createServer } from 'node:http';
|
||||
import { after, before, beforeEach, describe, it } from 'node:test';
|
||||
import { ACCESS_LEVELS } from '../src/config/constants.js';
|
||||
import { closeDatabase, getDatabase, initDatabase } from '../src/database/index.js';
|
||||
import {
|
||||
addCard,
|
||||
createBoard,
|
||||
listColumns,
|
||||
searchCards,
|
||||
} from '../src/database/repositories/project-repository.js';
|
||||
import { createApiToken } from '../src/database/repositories/web-session-repository.js';
|
||||
import { createPage } from '../src/database/repositories/wiki-repository.js';
|
||||
import { hashToken } from '../src/web/auth/session.js';
|
||||
import { createHandler } from '../src/web/server.js';
|
||||
|
||||
/**
|
||||
* Global search behind the command palette (M19).
|
||||
*
|
||||
* Gitea is deliberately left unconfigured here: the point is that the local
|
||||
* sources answer on their own, so a forge that is down costs the palette its
|
||||
* repositories and nothing else.
|
||||
*/
|
||||
|
||||
const GUILD = '';
|
||||
const TOKEN = 'fws_search-test';
|
||||
|
||||
describe('global search', () => {
|
||||
let app;
|
||||
let board;
|
||||
let columns;
|
||||
|
||||
before(async () => {
|
||||
initDatabase(':memory:');
|
||||
createApiToken({
|
||||
name: 'recherche',
|
||||
tokenHash: hashToken(TOKEN),
|
||||
prefix: TOKEN.slice(0, 12),
|
||||
accessLevel: ACCESS_LEVELS.STAFF,
|
||||
});
|
||||
app = createServer(createHandler({ client: null, setupOnly: false }));
|
||||
await new Promise((resolve) => app.listen(0, '127.0.0.1', resolve));
|
||||
});
|
||||
after(async () => {
|
||||
await new Promise((resolve) => app.close(resolve));
|
||||
closeDatabase();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
getDatabase().exec('DELETE FROM project_boards; DELETE FROM wiki_pages;');
|
||||
board = createBoard({ guildId: GUILD, scope: 'org', name: 'Organisation' });
|
||||
columns = listColumns(board.id);
|
||||
});
|
||||
|
||||
const search = (term) =>
|
||||
fetch(`http://127.0.0.1:${app.address().port}/api/search?q=${encodeURIComponent(term)}`, {
|
||||
headers: { Authorization: `Bearer ${TOKEN}` },
|
||||
});
|
||||
|
||||
const results = (term) => search(term).then((response) => response.json());
|
||||
|
||||
const card = (title, overrides = {}) =>
|
||||
addCard({ boardId: board.id, columnId: columns[0].id, title, ...overrides });
|
||||
|
||||
const page = (title, overrides = {}) =>
|
||||
createPage({
|
||||
slug: title.toLowerCase().replaceAll(' ', '-'),
|
||||
title,
|
||||
published: true,
|
||||
category: 'Guides',
|
||||
...overrides,
|
||||
});
|
||||
|
||||
it('refuses a visitor without a session', async () => {
|
||||
const response = await fetch(`http://127.0.0.1:${app.address().port}/api/search?q=test`);
|
||||
assert.equal(response.status, 401);
|
||||
});
|
||||
|
||||
/** One or two letters match half the organization, which helps nobody. */
|
||||
it('stays silent on a term too short to mean anything', async () => {
|
||||
card('Pterodactyl');
|
||||
assert.deepEqual((await results('p')).results, []);
|
||||
});
|
||||
|
||||
it('finds a card and says which board it is on', async () => {
|
||||
card('Corriger le démarrage');
|
||||
|
||||
const [found] = (await results('démarrage')).results;
|
||||
assert.equal(found.kind, 'card');
|
||||
assert.equal(found.title, 'Corriger le démarrage');
|
||||
assert.equal(found.subtitle, 'Organisation · À faire');
|
||||
assert.equal(found.href, `#/projects/${board.id}`);
|
||||
});
|
||||
|
||||
it('finds a published wiki page at its public address', async () => {
|
||||
page('Installer FWS Arch', { summary: 'Le guide pas à pas.' });
|
||||
|
||||
const [found] = (await results('Installer')).results;
|
||||
assert.equal(found.kind, 'wiki');
|
||||
assert.equal(found.href, '/wiki/installer-fws-arch');
|
||||
assert.equal(found.external, true);
|
||||
});
|
||||
|
||||
it('leaves an unpublished page out of the results', async () => {
|
||||
page('Brouillon interne', { published: false });
|
||||
assert.deepEqual((await results('Brouillon')).results, []);
|
||||
});
|
||||
|
||||
/** The legal pages live at the root, not under /wiki. */
|
||||
it('sends a root page to its own address', async () => {
|
||||
page('Conditions', { slug: 'terms-of-service' });
|
||||
|
||||
const [found] = (await results('Conditions')).results;
|
||||
assert.equal(found.href, '/terms-of-service');
|
||||
});
|
||||
|
||||
it('gathers several kinds under one answer', async () => {
|
||||
card('Sauvegarde automatique');
|
||||
page('Sauvegarde et restauration');
|
||||
|
||||
const kinds = (await results('Sauvegarde')).results.map((entry) => entry.kind);
|
||||
assert.deepEqual(kinds.slice().sort(), ['card', 'wiki']);
|
||||
});
|
||||
|
||||
it('puts the local results first', async () => {
|
||||
card('Wiki à relire');
|
||||
page('Wiki public');
|
||||
|
||||
assert.equal((await results('Wiki')).results[0].kind, 'card');
|
||||
});
|
||||
|
||||
it('answers with nothing rather than failing when nothing matches', async () => {
|
||||
const body = await results('introuvable-xyz');
|
||||
assert.deepEqual(body.results, []);
|
||||
assert.equal(body.term, 'introuvable-xyz');
|
||||
});
|
||||
|
||||
/** Gitea is not configured here; the palette must still answer. */
|
||||
it('answers although the forge is absent', async () => {
|
||||
card('Déploiement');
|
||||
const response = await search('Déploiement');
|
||||
|
||||
assert.equal(response.status, 200);
|
||||
assert.equal((await response.json()).results.length, 1);
|
||||
});
|
||||
});
|
||||
|
||||
/** The query behind the palette's card results, exercised without HTTP. */
|
||||
describe('searching the cards directly', () => {
|
||||
let board;
|
||||
let columns;
|
||||
|
||||
before(() => initDatabase(':memory:'));
|
||||
after(() => closeDatabase());
|
||||
beforeEach(() => {
|
||||
getDatabase().exec('DELETE FROM project_boards;');
|
||||
board = createBoard({ guildId: GUILD, scope: 'org', name: 'Organisation' });
|
||||
columns = listColumns(board.id);
|
||||
});
|
||||
|
||||
const put = (title, overrides = {}) =>
|
||||
addCard({ boardId: board.id, columnId: columns[0].id, title, ...overrides });
|
||||
|
||||
it('matches the title', () => {
|
||||
put('Corriger le démarrage');
|
||||
put('Documenter le wiki');
|
||||
|
||||
assert.deepEqual(
|
||||
searchCards(GUILD, 'démarrage').map((entry) => entry.title),
|
||||
['Corriger le démarrage'],
|
||||
);
|
||||
});
|
||||
|
||||
it('matches the body, the labels and the issue', () => {
|
||||
put('Sans rapport', { body: 'contient pterodactyl' });
|
||||
put('Étiquetée', { labels: ['urgent'] });
|
||||
put('Liée', { issueRef: 'FWS/FWS-Arch#42' });
|
||||
|
||||
assert.equal(searchCards(GUILD, 'pterodactyl').length, 1);
|
||||
assert.equal(searchCards(GUILD, 'urgent').length, 1);
|
||||
assert.equal(searchCards(GUILD, '#42').length, 1);
|
||||
});
|
||||
|
||||
/** A finished card is still a result, just never the first one. */
|
||||
it('puts the finished cards last', () => {
|
||||
addCard({ boardId: board.id, columnId: columns.at(-1).id, title: 'sujet fini' });
|
||||
put('sujet en cours');
|
||||
|
||||
assert.deepEqual(
|
||||
searchCards(GUILD, 'sujet').map((entry) => entry.title),
|
||||
['sujet en cours', 'sujet fini'],
|
||||
);
|
||||
});
|
||||
|
||||
it('honours the limit', () => {
|
||||
for (let index = 0; index < 5; index += 1) put(`sujet ${index}`);
|
||||
assert.equal(searchCards(GUILD, 'sujet', 2).length, 2);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user