feat: in-app help, notifications panel and global search (#32)

F1 and "?" now open the wiki page of the screen inside the application
(/aiuto, mockup 011) from a copy of the wiki shipped next to the program,
so help works offline and always matches the installed version. Markdown
is converted in-house and fully encoded; images of the repository are
served from the copy. KHAEMHAT_HELP_URL sets the online wiki behind
"Apri nel wiki"; "Segnala un problema" opens a new issue of that repo.
A test checks that every page and menu entry has an existing wiki page.

The bell opens a notifications panel (mockup 010) with all/unread
filters and mark read. Broadcast notifications are now read per user
through sys_notification_reads / notification_reads instead of one
shared read_at.

The global search asks ISearchProvider implementations through
GlobalSearchService after a short pause; the first provider finds help
pages and sections, # and @ say which modules will fill them.

Escape also closes a side panel when the focus fell out of it.
Decisions in ADR 0023.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-11 19:39:17 +01:00
1 parent acb7e598d1
commit f415dc37a8
39 files changed
+1976 -107

No files matched your search

@@ -0,0 +1,69 @@
using Khaemhat.Application.Search;
using Khaemhat.Application.Security;
using Khaemhat.Core.Security;
using Microsoft.Extensions.Logging.Abstractions;
namespace Khaemhat.Application.Tests;
/// <summary>The global search of SPEC §10.2 (issue #32, mockup 009).</summary>
[TestClass]
public sealed class GlobalSearchTests
{
private static readonly Actor Root = new("root", UserLevel.SuperUser, 1, null, null);
[TestMethod]
[DataRow(" fattura ", SearchScope.All, "fattura")]
[DataRow("> tema", SearchScope.Commands, "tema")]
[DataRow("#FT 12", SearchScope.Documents, "FT 12")]
[DataRow("@rossi", SearchScope.People, "rossi")]
[DataRow("", SearchScope.All, "")]
public void Query_ReadsThePrefix(string input, SearchScope scope, string text)
{
var query = SearchQuery.Parse(input);
Assert.AreEqual(scope, query.Scope);
Assert.AreEqual(text, query.Text);
}
[TestMethod]
public void Query_MatchesEveryWord_IgnoringCase()
{
var query = SearchQuery.Parse("iva liq");
Assert.IsTrue(query.Matches("Liquidazione IVA"));
Assert.IsFalse(query.Matches("Registri IVA"));
Assert.IsFalse(query.Matches(null));
Assert.IsTrue(SearchQuery.Parse(" ").Matches("qualsiasi"));
}
[TestMethod]
public async Task Search_AsksTheProvidersOfTheScope_AndLeavesOutTheOnesThatFail()
{
var search = new GlobalSearchService(
[new Provider([SearchScope.All], "Aiuto"), new Failing(), new Provider([SearchScope.All, SearchScope.Documents], "Documento")],
NullLogger<GlobalSearchService>.Instance);
var all = await search.SearchAsync(Root, SearchQuery.Parse("ab"));
Assert.HasCount(2 * GlobalSearchService.PerProvider, all);
CollectionAssert.AreEqual(new[] { "Aiuto ab", "Documento ab" }, all.Select(h => h.Title).Distinct().ToList());
CollectionAssert.AreEqual(new[] { "Documento ab" }, (await search.SearchAsync(Root, SearchQuery.Parse("#ab"))).Select(h => h.Title).Distinct().ToList());
Assert.IsEmpty(await search.SearchAsync(Root, SearchQuery.Parse("a")), "Too short.");
Assert.IsEmpty(await search.SearchAsync(Root, SearchQuery.Parse(">ab")), "Commands are not records.");
Assert.IsTrue(search.Covers(SearchScope.Documents));
Assert.IsFalse(search.Covers(SearchScope.People));
}
private sealed class Provider(SearchScope[] scopes, string title) : ISearchProvider
{
public IReadOnlyCollection<SearchScope> Scopes => scopes;
public Task<IReadOnlyList<SearchHit>> SearchAsync(Actor actor, SearchQuery query, CancellationToken cancellationToken) =>
Task.FromResult<IReadOnlyList<SearchHit>>([.. Enumerable.Range(0, 20).Select(i => new SearchHit("g", "file", title + " " + query.Text, null, "x"))]);
}
private sealed class Failing : ISearchProvider
{
public IReadOnlyCollection<SearchScope> Scopes => [SearchScope.All];
public Task<IReadOnlyList<SearchHit>> SearchAsync(Actor actor, SearchQuery query, CancellationToken cancellationToken) =>
throw new InvalidOperationException("broken");
}
}
@@ -45,6 +45,20 @@ public sealed class SystemRulesTests
Assert.IsFalse(error.Errors.Any(e => e.Contains(Key, StringComparison.Ordinal)), "Errors never repeat a secret.");
}
[TestMethod]
public void Configuration_HelpUrl_IsAnAbsoluteWebAddress()
{
var variables = Required();
variables["KHAEMHAT_HELP_URL"] = "https://git.example.com/acme/khaemhat/wiki/";
var options = new EnvironmentConfigurationReader(n => variables.GetValueOrDefault(n)).Read();
options.EnsureValid();
Assert.AreEqual("https://git.example.com/acme/khaemhat/wiki/", options.HelpUrl);
variables["KHAEMHAT_HELP_URL"] = "wiki/locale";
var error = Assert.ThrowsExactly<ConfigurationException>(() => new EnvironmentConfigurationReader(n => variables.GetValueOrDefault(n)).Read().EnsureValid());
Assert.IsTrue(error.Errors.Any(e => e.StartsWith("KHAEMHAT_HELP_URL", StringComparison.Ordinal)));
}
[TestMethod]
public void Configuration_ReportsEveryMissingVariableAtOnce()
{