feat(app): add the Nostro app, a window for phones and desktops
Linux phones have no banking apps, and a command line is no answer on a phone. The app does everything the nostro command does and, like it, only talks to nostrod: it holds no key and no token. - Nostro.Ui, a toolkit whose screens are functions that fill a frame, ported from imsd-messages ca5cd72d; Nostro.App, the app's state, forms and screens; Nostro.Ui.Shell, which puts them on a Wayland window with Crafter.Graphics; nostro-app; and Nostro.DebugCommands for the --debug-api build. - Client: every method also in an asynchronous form for an sd-event loop, with DaemonMissing and OutcomeUnknown. - nostrod's Flatpak is net.catcrafts.Nostrod now and the app takes net.catcrafts.Nostro; install.sh moves the state. The app's Flatpak, both Flatpaks cross-built for aarch64, and the licence texts they carry. - nostro-fake-system, a made-up bus and bank with a real nostrod on them, to look at the app against. The README's screenshots are taken on it. - The nostro command: an API key's environment is the key's own to say, so --sandbox is for bunq-oauth alone, and a virtual card is listed as VIRTUAL. The published contract changes in three places, before any release (design rule 10): - Transactions' query takes `stored`: answered from what nostrod has stored, without asking the bank. The app searches with it; before, every search was a call to bunq. - AddBunq's `environment` no longer chooses over what the key says of itself: a key of the other environment is refused. - SetCardStatus refuses to freeze or unfreeze a virtual card. bunq reports one as DEACTIVATED however well it pays, and leaves it as it is when asked, without an error. The app is GPL-3.0-only, the library stays LGPL-3.0-only, and no code moved from one to the other (design rule 13). Transaction's schema is unchanged. Verified: the 17 tests pass with every line, function and region of what they link run, and the five lint runs are clean. Every screen was looked at on the made-up system, at a phone's and a desktop's sizes in the light and the dark look, on Plasma under Wayland. What is said of bunq's cards comes from its sandbox, with throwaway users, and from one real virtual card. Known to have been used against production: connecting, and reading accounts, payments and cards. Not known to have been tried: a payment from the app against bunq, OAuth against bunq, and anything on a phone. Building the app takes --graphics=, a Crafter.Graphics checkout on its branch claude/nostro-app, until that branch is merged and pinned here. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
1ea50c50bc
commit
5b4037955b
106 changed files with 17804 additions and 289 deletions
261
project.cpp
261
project.cpp
|
|
@ -5,6 +5,9 @@ import std;
|
|||
import Crafter.Build;
|
||||
#pragma crafter dependency "https://forgejo.catcrafts.net/Catcrafts/Crafter.LintRules.git"
|
||||
import Crafter.LintRules;
|
||||
// What puts Crafter.Debug into the app under --debug-api, and into no other build.
|
||||
#pragma crafter dependency "https://forgejo.catcrafts.net/Catcrafts/Crafter.Debug.git" commit "98e92c1976f32c6f9beb6ea38a0522a3bbdabed7" project "tooling/project.cpp"
|
||||
import Crafter.Debug.Build;
|
||||
namespace fs = std::filesystem;
|
||||
using namespace Crafter;
|
||||
|
||||
|
|
@ -27,6 +30,143 @@ static Configuration CheckoutLibrary(std::span<const std::string_view> args, con
|
|||
return checkout;
|
||||
}
|
||||
|
||||
// Nostro.Ui: the toolkit the app's screens are built with. It imports std alone, so its tests need no window, no bank
|
||||
// and no bus, and it is built only for what depends on it: those tests, and the app.
|
||||
static Configuration UiLibrary(std::span<const std::string_view> args, const std::vector<std::string>& compileFlags) {
|
||||
Configuration ui;
|
||||
ui.path = "./";
|
||||
ui.name = "nostro-ui";
|
||||
ui.outputName = "nostro-ui";
|
||||
ui.type = ConfigurationType::LibraryStatic;
|
||||
ApplyStandardArgs(ui, args);
|
||||
ui.compileFlags.insert(ui.compileFlags.end(), compileFlags.begin(), compileFlags.end());
|
||||
std::array<fs::path, 11> interfaces = {
|
||||
"interfaces/Nostro.Ui",
|
||||
"interfaces/Nostro.Ui-Geometry",
|
||||
"interfaces/Nostro.Ui-Text",
|
||||
"interfaces/Nostro.Ui-Edit",
|
||||
"interfaces/Nostro.Ui-Gesture",
|
||||
"interfaces/Nostro.Ui-Draw",
|
||||
"interfaces/Nostro.Ui-Theme",
|
||||
"interfaces/Nostro.Ui-Input",
|
||||
"interfaces/Nostro.Ui-Context",
|
||||
"interfaces/Nostro.Ui-Layout",
|
||||
"interfaces/Nostro.Ui-Widgets",
|
||||
};
|
||||
std::array<fs::path, 7> implementations = {
|
||||
"implementations/Nostro.Ui-Text",
|
||||
"implementations/Nostro.Ui-Edit",
|
||||
"implementations/Nostro.Ui-Gesture",
|
||||
"implementations/Nostro.Ui-Draw",
|
||||
"implementations/Nostro.Ui-Theme",
|
||||
"implementations/Nostro.Ui-Context",
|
||||
"implementations/Nostro.Ui-Widgets",
|
||||
};
|
||||
ui.GetInterfacesAndImplementations(interfaces, implementations);
|
||||
LintRules::AddLiteRules(ui);
|
||||
return ui;
|
||||
}
|
||||
|
||||
// Nostro.App: the app without its window: what it knows, what is filled in, and its screens, built with the toolkit
|
||||
// over the library's client. Like the toolkit it is built only for what depends on it: its tests, and the app.
|
||||
static Configuration AppLibrary(std::span<const std::string_view> args, const std::vector<std::string>& compileFlags, Configuration* library, Configuration* ui) {
|
||||
Configuration app;
|
||||
app.path = "./";
|
||||
app.name = "nostro-app-core";
|
||||
app.outputName = "nostro-app-core";
|
||||
app.type = ConfigurationType::LibraryStatic;
|
||||
app.dependencies = {library, ui};
|
||||
ApplyStandardArgs(app, args);
|
||||
app.compileFlags.insert(app.compileFlags.end(), compileFlags.begin(), compileFlags.end());
|
||||
std::array<fs::path, 6> interfaces = {
|
||||
"interfaces/Nostro.App",
|
||||
"interfaces/Nostro.App-Banks",
|
||||
"interfaces/Nostro.App-Format",
|
||||
"interfaces/Nostro.App-Forms",
|
||||
"interfaces/Nostro.App-Errors",
|
||||
"interfaces/Nostro.App-App",
|
||||
};
|
||||
std::array<fs::path, 7> implementations = {
|
||||
"implementations/Nostro.App-Banks",
|
||||
"implementations/Nostro.App-Format",
|
||||
"implementations/Nostro.App-Forms",
|
||||
"implementations/Nostro.App-Errors",
|
||||
"implementations/Nostro.App-App",
|
||||
"implementations/Nostro.App-Screens",
|
||||
"implementations/Nostro.App-Bunq",
|
||||
};
|
||||
app.GetInterfacesAndImplementations(interfaces, implementations);
|
||||
LintRules::AddLiteRules(app);
|
||||
return app;
|
||||
}
|
||||
|
||||
// Nostro.Ui.Shell: what puts the toolkit's screens on a display, on Crafter.Graphics and one sd-event loop. The one part
|
||||
// of the app that needs a compositor and a graphics device, so only the app is built with it and no test is.
|
||||
static Configuration ShellLibrary(std::span<const std::string_view> args, Configuration* ui, Configuration* graphics) {
|
||||
Configuration shell;
|
||||
shell.path = "./";
|
||||
shell.name = "nostro-ui-shell";
|
||||
shell.outputName = "nostro-ui-shell";
|
||||
shell.type = ConfigurationType::LibraryStatic;
|
||||
shell.linkFlags.push_back("-lsystemd");
|
||||
shell.dependencies = {ui, graphics};
|
||||
ApplyStandardArgs(shell, args);
|
||||
std::array<fs::path, 5> interfaces = {
|
||||
"interfaces/Nostro.Ui.Shell",
|
||||
"interfaces/Nostro.Ui.Shell-Loop",
|
||||
"interfaces/Nostro.Ui.Shell-Canvas",
|
||||
"interfaces/Nostro.Ui.Shell-Window",
|
||||
"interfaces/Nostro.Ui.Shell-Portal",
|
||||
};
|
||||
std::array<fs::path, 4> implementations = {
|
||||
"implementations/Nostro.Ui.Shell-Loop",
|
||||
"implementations/Nostro.Ui.Shell-Canvas",
|
||||
"implementations/Nostro.Ui.Shell-Window",
|
||||
"implementations/Nostro.Ui.Shell-Portal",
|
||||
};
|
||||
shell.GetInterfacesAndImplementations(interfaces, implementations);
|
||||
LintRules::AddLiteRules(shell);
|
||||
return shell;
|
||||
}
|
||||
|
||||
// nostro-fake-system: the tests' fake bus and fake bunq with nostrod on them, as a program to run the app against.
|
||||
static Configuration FakeSystem(std::span<const std::string_view> args, const std::vector<Define>& defines, const std::vector<Configuration*>& dependencies) {
|
||||
Configuration fake;
|
||||
fake.path = "./";
|
||||
fake.name = "nostro-fake-system";
|
||||
fake.outputName = "nostro-fake-system";
|
||||
fake.defines = defines;
|
||||
ApplyStandardArgs(fake, args);
|
||||
fake.dependencies = dependencies;
|
||||
std::array<fs::path, 0> interfaces = {};
|
||||
std::array<fs::path, 1> implementations = {"tests/FakeSystem/main"};
|
||||
fake.GetInterfacesAndImplementations(interfaces, implementations);
|
||||
LintRules::AddLiteRules(fake);
|
||||
return fake;
|
||||
}
|
||||
|
||||
// `crafter-build … --product=app --debug-api run fake [the fake system's options] [-- the app's options]`: the app on
|
||||
// the made-up system, both as the build before left them. `-r` passes a program no arguments, and the app has a few.
|
||||
static std::int32_t RunOnFakeSystem(ScriptContext& ctx) {
|
||||
const auto harness = std::ranges::find(ctx.project.dependencies, std::string_view("nostro-fake-system"), [](const Configuration* dependency) { return std::string_view(dependency->name); });
|
||||
if(harness == ctx.project.dependencies.end()) {
|
||||
throw std::runtime_error("the fake system is built with the app under --debug-api: name both before `run`");
|
||||
}
|
||||
const auto separator = std::ranges::find(ctx.args, std::string_view("--"));
|
||||
std::string command = ShellQuote(((*harness)->BinDir() / (*harness)->outputName).string());
|
||||
command += std::format(" --dir {}", ShellQuote((ctx.projectDir / "build" / "fake-system").string()));
|
||||
for(const std::string& arg : std::ranges::subrange(ctx.args.begin(), separator)) {
|
||||
command += std::format(" {}", ShellQuote(arg));
|
||||
}
|
||||
command += std::format(" --run {}", ShellQuote((ctx.project.ProgramDir() / ctx.project.outputName).string()));
|
||||
if(separator != ctx.args.end()) {
|
||||
for(const std::string& arg : std::ranges::subrange(separator + 1, ctx.args.end())) {
|
||||
command += std::format(" {}", ShellQuote(arg));
|
||||
}
|
||||
}
|
||||
return ctx.Run(command);
|
||||
}
|
||||
|
||||
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> args) {
|
||||
constexpr std::string_view bankArgName = "--banks=";
|
||||
|
||||
|
|
@ -36,9 +176,16 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
|||
bool coverage = false;
|
||||
std::string profileRuntime;
|
||||
constexpr std::string_view profileRuntimeArgName = "--profile-runtime=";
|
||||
// What a build makes: the CLI by default, "daemon" for nostrod, or "checkout" for the checkout client library.
|
||||
// What a build makes: the CLI by default, "daemon" for nostrod, "app" for the window, "checkout" for the checkout
|
||||
// client library, or "fake-system" for a made-up system to look at the app against.
|
||||
std::string product;
|
||||
constexpr std::string_view productArgName = "--product=";
|
||||
// Crafter.Graphics from a checkout: the project.cpp to build the app against, in place of the forge's.
|
||||
std::string graphicsProject;
|
||||
constexpr std::string_view graphicsArgName = "--graphics=";
|
||||
// The app with Crafter.Debug in it, for an agent to drive: nostro's own flag, which no dependency is handed.
|
||||
bool debugApiRequested = false;
|
||||
constexpr std::string_view debugApiArgName = "--debug-api";
|
||||
|
||||
std::vector<std::string> depArgs;
|
||||
|
||||
|
|
@ -51,6 +198,10 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
|||
dbusRequested = true;
|
||||
} else if(arg.starts_with(productArgName)) {
|
||||
product = arg.substr(productArgName.size());
|
||||
} else if(arg.starts_with(graphicsArgName)) {
|
||||
graphicsProject = arg.substr(graphicsArgName.size());
|
||||
} else if(arg == debugApiArgName) {
|
||||
debugApiRequested = true;
|
||||
} else if(arg == "--coverage") {
|
||||
coverage = true;
|
||||
} else if(arg.starts_with(profileRuntimeArgName)) {
|
||||
|
|
@ -88,7 +239,7 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
|||
if(product == "checkout") {
|
||||
return CheckoutLibrary(args, coverageCompileFlags);
|
||||
}
|
||||
if(!product.empty() && product != "daemon") {
|
||||
if(!product.empty() && product != "daemon" && product != "app" && product != "fake-system") {
|
||||
throw std::runtime_error(std::format("unknown product '{}' in {}", product, productArgName));
|
||||
}
|
||||
if(!bunqEnabled) {
|
||||
|
|
@ -109,11 +260,17 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
|||
libcfg.defines.push_back({"NOSTRO_DBUS_ENABLED"});
|
||||
}
|
||||
Configuration* checkout = new Configuration(CheckoutLibrary(args, coverageCompileFlags));
|
||||
Configuration* ui = new Configuration(UiLibrary(args, coverageCompileFlags));
|
||||
|
||||
// nostro uses Crafter.Network's HTTP/1.1 client alone: --no-quic leaves out msquic, its CMake build, and the runpath
|
||||
// into the building user's cache that a binary linked against it carries.
|
||||
// into the building user's cache that a binary linked against it carries. Crafter.Debug talks QUIC, and takes
|
||||
// Crafter.Network with the args it is handed: a dependency two paths share gets one list of them, so the app's
|
||||
// debug build has QUIC in.
|
||||
const bool debugApi = debugApiRequested && product == "app";
|
||||
std::vector<std::string> networkArgs = depArgs;
|
||||
networkArgs.emplace_back("--no-quic");
|
||||
if(!debugApi) {
|
||||
networkArgs.emplace_back("--no-quic");
|
||||
}
|
||||
Configuration* network = GitProject({
|
||||
.source = { .url = "https://forgejo.catcrafts.net/Catcrafts/Crafter.Network.git" },
|
||||
.args = networkArgs,
|
||||
|
|
@ -189,6 +346,7 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
|||
// configurations exporting the same module in one build are an error.
|
||||
const auto defines = libcfg.defines;
|
||||
Configuration* library = new Configuration(std::move(libcfg));
|
||||
Configuration* appCore = new Configuration(AppLibrary(args, coverageCompileFlags, library, ui));
|
||||
|
||||
// nostrod: the daemon that holds the connectors and answers the CLI over the system bus.
|
||||
if(product == "daemon") {
|
||||
|
|
@ -208,6 +366,60 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
|||
return daemon;
|
||||
}
|
||||
|
||||
if(product == "fake-system") {
|
||||
return FakeSystem(args, defines, { library, network, db, checkout });
|
||||
}
|
||||
|
||||
// nostro-app: the window. Its fonts go beside it, where the window library's shaders are put too.
|
||||
if(product == "app") {
|
||||
// The app asks the input method for a field's purpose and hints, which Crafter.Graphics has on its branch
|
||||
// claude/nostro-app and not yet on master: until that is merged and pinned here, a checkout of it is named.
|
||||
if(graphicsProject.empty()) {
|
||||
throw std::runtime_error(std::format("--product=app needs {}<a Crafter.Graphics checkout's project.cpp> for now: the branch claude/nostro-app", graphicsArgName));
|
||||
}
|
||||
Configuration* graphics = LocalProject({ .projectFile = graphicsProject, .args = depArgs });
|
||||
Configuration* shell = new Configuration(ShellLibrary(args, ui, graphics));
|
||||
Configuration app;
|
||||
app.path = "./";
|
||||
app.name = "nostro-app";
|
||||
app.outputName = "nostro-app";
|
||||
app.defines = defines;
|
||||
// What the app says its version is: the metainfo's release is the same.
|
||||
app.defines.push_back({"NOSTRO_VERSION", "0.1.0"});
|
||||
ApplyStandardArgs(app, args);
|
||||
app.dependencies = { library, ui, appCore, shell };
|
||||
app.files.push_back("assets/NotoSans-Regular.ttf");
|
||||
app.files.push_back("assets/NotoSans-Medium.ttf");
|
||||
// What the app is as a Flatpak (--packaging=flatpak, with `install` or `bundle`): the compositor, the graphics
|
||||
// device, and nostrod on the system bus. No network and no files: it talks to no bank itself and keeps
|
||||
// nothing. The desktop's portals, for the look and for opening a browser, need no permission.
|
||||
app.flatpak.appId = "net.catcrafts.Nostro";
|
||||
app.flatpak.permissions = {"--socket=wayland", "--device=dri", "--system-talk-name=net.catcrafts.Nostro1"};
|
||||
app.flatpak.desktopFile = "packaging/flatpak/net.catcrafts.Nostro.desktop";
|
||||
app.flatpak.metainfo = "packaging/flatpak/net.catcrafts.Nostro.metainfo.xml";
|
||||
app.flatpak.icons = {"packaging/flatpak/net.catcrafts.Nostro.svg"};
|
||||
// The licences of what it carries; packaging/licenses/NOTICE says what each text covers.
|
||||
app.flatpak.share = {
|
||||
{"LICENSE", "licenses/net.catcrafts.Nostro/LICENSE"},
|
||||
{"LICENSE.GPL", "licenses/net.catcrafts.Nostro/LICENSE.GPL"},
|
||||
{"assets/OFL.txt", "licenses/net.catcrafts.Nostro/OFL.txt"},
|
||||
{"packaging/licenses", "licenses/net.catcrafts.Nostro"},
|
||||
};
|
||||
std::vector<fs::path> appInterfaces;
|
||||
std::vector<fs::path> appImplementations = {"implementations/nostro-app"};
|
||||
// With --debug-api: Crafter.Debug, what an agent drives the app with, and the made-up system to drive it on,
|
||||
// built in the same pass. Any process of the user's can drive and read such a build: it is no build to ship.
|
||||
if(Debug::Use(app, { .enabled = debugApi, .flag = std::string(debugApiArgName), .define = "NOSTRO_DEBUG_API", .args = depArgs })) {
|
||||
appInterfaces.emplace_back("interfaces/Nostro.DebugCommands");
|
||||
appImplementations.emplace_back("implementations/Nostro.DebugCommands");
|
||||
app.dependencies.push_back(new Configuration(FakeSystem(args, defines, { library, network, db, checkout })));
|
||||
app.scripts.push_back({"fake", RunOnFakeSystem});
|
||||
}
|
||||
app.GetInterfacesAndImplementations(appInterfaces, appImplementations);
|
||||
LintRules::AddLiteRules(app);
|
||||
return app;
|
||||
}
|
||||
|
||||
Configuration execfg;
|
||||
execfg.path = "./";
|
||||
execfg.name = "nostro";
|
||||
|
|
@ -228,9 +440,20 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
|||
execfg.dependencies = { library };
|
||||
execfg.GetInterfacesAndImplementations(exeInterfaces, exeImplementations);
|
||||
|
||||
// `crafter-build test --banks=bunq`: each test is tests/<Name>/main.cpp, linked against the library. The ones that
|
||||
// `crafter-build test --banks=bunq`: each test is tests/<Name>/main.cpp, linked against what it tests. The ones that
|
||||
// talk to bunq talk to a fake of it on 127.0.0.1 (tests/Support/FakeBunq.inc), never to bunq itself.
|
||||
constexpr std::array<std::string_view, 9> tests = {
|
||||
const auto addTests = [&execfg, &coverageCompileFlags, &coverageLinkFlags](std::span<const std::string_view> names, const std::vector<Configuration*>& dependencies) {
|
||||
for(const std::string_view name : names) {
|
||||
TestBuilder test = execfg.AddTest(name).Dependencies(dependencies).Timeout(std::chrono::seconds(180));
|
||||
for(const std::string& flag : coverageCompileFlags) {
|
||||
test.CompileFlag(flag);
|
||||
}
|
||||
for(const std::string& flag : coverageLinkFlags) {
|
||||
test.LinkFlag(flag);
|
||||
}
|
||||
}
|
||||
};
|
||||
constexpr std::array<std::string_view, 10> libraryTests = {
|
||||
"ShouldHandleMoneyAndText",
|
||||
"ShouldSignAndVerify",
|
||||
"ShouldStoreTransactions",
|
||||
|
|
@ -240,16 +463,24 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
|||
"ShouldMoveMoney",
|
||||
"ShouldRunCommands",
|
||||
"ShouldServeEveryUser",
|
||||
"ShouldAnswerAsynchronously",
|
||||
};
|
||||
for(const std::string_view name : tests) {
|
||||
TestBuilder test = execfg.AddTest(name).Dependencies({ library, network, db, checkout }).Timeout(std::chrono::seconds(180));
|
||||
for(const std::string& flag : coverageCompileFlags) {
|
||||
test.CompileFlag(flag);
|
||||
}
|
||||
for(const std::string& flag : coverageLinkFlags) {
|
||||
test.LinkFlag(flag);
|
||||
}
|
||||
}
|
||||
addTests(libraryTests, { library, network, db, checkout });
|
||||
// The toolkit's, which need the toolkit alone.
|
||||
constexpr std::array<std::string_view, 5> uiTests = {
|
||||
"ShouldWrapText",
|
||||
"ShouldEditText",
|
||||
"ShouldRecognizeGestures",
|
||||
"ShouldBuildFrames",
|
||||
"ShouldLayOutWidgets",
|
||||
};
|
||||
addTests(uiTests, { ui });
|
||||
// The app's, which drive it against a real nostrod on the fake bus.
|
||||
constexpr std::array<std::string_view, 2> appTests = {
|
||||
"ShouldValidateForms",
|
||||
"ShouldDriveTheApp",
|
||||
};
|
||||
addTests(appTests, { appCore, ui, library, network, db, checkout });
|
||||
|
||||
LintRules::AddLiteRules(execfg);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue