Files
logos-test-framework/nix/mkLogosModuleTests.nix
Dario LipicarandClaude Opus 5 5f75c9418b chore(deps): track master for protocol, cpp-sdk, plugin-qt and qt-sdk (#6)
* feat: take the Qt host runtime from logos-qt-host, not logos-qt-sdk

LogosTest.cmake linked logos-qt-sdk::logos_qt_sdk for the host runtime a
module test needs — LogosAPI, LogosAPIProvider, the provider bases. B1 moved
that code to logos-plugin-qt, which exports it as logos-qt-host::logos_qt_host,
so name that target instead.

The root it comes from is picked from LOGOS_QT_HOST_ROOT, falling back to
LOGOS_QT_SDK_ROOT. The fallback is not decoration: every caller today reaches
this file through logos-module-builder, which passes only LOGOS_QT_SDK_ROOT,
and requiring the new variable would take every module's unit-tests check down
until that repo moves. Whichever root is chosen is reported by name in the
configure log, and the imported target is checked before it is linked — a
find_package that hands back no target now stops the configure instead of
deferring to a wall of undefined LogosAPI symbols.

logos-qt-sdk stays an input and stays on the include path when a caller
supplies both roots, because it still owns the Qt-typed headers that are NOT
the host runtime: logos_qt_lp_bridge.h and logos_qt_wire.h (generated consumer
wrappers include them by name) and logos_ui_plugin_context.h. It is ordered
after the host runtime's include dir so the five shared header names resolve
to qt-host.

Two things this repo never had are added so the repoint is verifiable here at
all: `checks.<sys>.example-tests` builds and runs examples/basic-module-test
through LogosTest.cmake on the qt-host path, and `example-tests-qt-sdk` does
the same on the fallback path so a change to one cannot quietly break the
other. Both were needed to find two latent breaks in nix/mkLogosModuleTests.nix
— it never passed CMAKE_MODULE_PATH, so `include(LogosTest)` could not resolve,
and its checkPhase drove ctest, which reports "No tests were found!!!" and
exits 0. The check phase now locates the test binaries itself and fails when
there are none.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* feat(b2b): LOGOS_QT_HOST_ROOT is the only host-runtime root

LogosTest.cmake accepted LOGOS_QT_SDK_ROOT as an alternative source of the Qt
host runtime, for callers that had not migrated. logos-qt-sdk stopped forwarding
those headers, so that branch now configures cleanly -- QT_HOST_INCLUDE is set,
find_package(logos-qt-sdk) resolves, the target imports -- and then dies much
later on "logos_api.h: No such file". It is deleted; a missing LOGOS_QT_HOST_ROOT
is a FATAL_ERROR that names logos-qt-sdk as explicitly NOT a substitute.

LOGOS_QT_SDK_ROOT keeps its other, real job: the Qt-typed consumer headers
logos-qt-sdk owns (logos_qt_lp_bridge.h, logos_qt_wire.h,
logos_ui_plugin_context.h). That block's layout probe moves off logos_api.h --
absent from both of that prefix's layouts now -- onto logos_qt_wire.h.

mkLogosModuleTests.nix makes logosQtHost a required argument instead of one half
of a two-way assert, and the flake drops the example-tests-qt-sdk check, which
existed to cover the pre-split path that no longer exists. logosQtSdk is passed
alongside logosQtHost in the remaining check so the Qt-typed headers stay
covered.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* chore(deps): rev-pin the B4 chain at the revs that are actually pushed

The lock this branch carried named logos-plugin-qt 8ccb1fc, which is a stale
commit on feat/sdk-codegen-b3-d11 and an ancestor of NEITHER b4 branch, so the
qt-host this repo's LogosTest.cmake links predated the windows-target work
every other consumer in the chain has moved to. The other three inputs were
worse than stale: their urls tracked master, and the revs beside them were only
ever right by accident.

All four are now rev-pinned in the url, because none of them is on a master:

  logos-protocol   c8bab12  feat/per-client-token-store (contains e6d5b57)
  logos-cpp-sdk    a04b278  feat/sdk-codegen-b3-d11     (contains e3744fb8)
  logos-plugin-qt  cc24fa1  feat/b4-qt-host-windows-target (contains 8846fc5)
  logos-qt-sdk     8a06b87  feat/sdk-codegen-b3-d11     (contains c6be61d)

Every one is a fast-forward from its own master, so nothing is dropped, and
each is the rev logos-qt-sdk and logos-view-module-runtime already pin — which
is the point of cc24fa1 in particular. logos-qt-sdk pins plugin-qt in its own
url and this flake does not redirect it, so a different root pin would put two
logos-qt-host prefixes on one link line. They resolve to a single store path
(v780ipqq), verified by evaluating both instances.

checks.aarch64-darwin.example-tests builds and its six tests run and pass.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* chore(deps): track master for protocol, cpp-sdk, plugin-qt and qt-sdk

All four upstream PRs merged (#59, #138, #19, #33), so the rev pins that bridged
to them are retired and their rationales rewritten.

The logos-plugin-qt `follows` on the logos-qt-sdk input STAYS, and is now the
only thing holding the property the rev pin used to hold with it: qt-sdk's
default package propagates whatever logos-qt-host it resolved, so without the
follows the example tests could see two logos-qt-host store paths. Verified: the
example-tests closure contains exactly ONE logos-qt-host derivation.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-19 18:40:53 -03:00

153 lines
4.5 KiB
Nix

# mkLogosModuleTests — Nix builder for Logos module unit tests
#
# Builds the test executable from test sources, module sources, and the
# logos-test-framework. Runs the tests as a derivation so they can be
# used as `checks.<system>.unit-tests` in a module's flake.
#
# Usage (in a module's flake.nix):
#
# checks.${system}.unit-tests = logos-test-framework.lib.mkLogosModuleTests {
# inherit pkgs;
# src = ./.;
# testDir = ./tests;
# configFile = ./metadata.json;
# logosSdk = logos-cpp-sdk.packages.${system}.default;
# logosQtHost = logos-plugin-qt.packages.${system}.logos-qt-host;
# logosProtocol = logos-protocol.packages.${system}.default;
# testFramework = logos-test-framework.packages.${system}.default;
# moduleDeps = { test_basic_module = inputs.test_basic_module.packages.${system}.default; };
# mockCLibs = [ "gowalletsdk" ]; # optional
# preConfigure = ""; # optional
# };
{ pkgs
, src
, testDir
, configFile ? null
, logosSdk
# The Qt host runtime (logos-plugin-qt's `logos-qt-host`). Required.
, logosQtHost
# logos-qt-sdk, for the Qt-typed consumer headers it owns (logos_qt_wire.h,
# logos_qt_lp_bridge.h, logos_ui_plugin_context.h). NOT a source of the host
# runtime — it stopped re-exporting those headers when the consumers were
# repointed — so it is genuinely optional here.
, logosQtSdk ? null
, logosProtocol
, testFramework
, moduleDeps ? {}
, mockCLibs ? []
, preConfigure ? ""
, extraBuildInputs ? []
, extraCmakeFlags ? []
}:
let
lib = pkgs.lib;
# Copy dependency include files into generated_code/
depIncludeSetup = lib.concatMapStringsSep "\n" (name:
let dep = moduleDeps.${name} or null;
in if dep != null then ''
if [ -d "${dep}/include" ]; then
echo "Copying include files from ${name}..."
cp -r "${dep}/include"/* ./generated_code/ 2>/dev/null || true
fi
'' else ""
) (lib.attrNames moduleDeps);
qtLayerRoots = [ logosQtHost ]
++ lib.optional (logosQtSdk != null) logosQtSdk;
in
pkgs.stdenv.mkDerivation {
pname = "logos-module-tests";
version = "0.0.1";
inherit src;
nativeBuildInputs = with pkgs; [
cmake
pkg-config
qt6.wrapQtAppsHook
] ++ extraBuildInputs;
buildInputs = with pkgs; [
qt6.qtbase
qt6.qtremoteobjects
logosSdk
logosProtocol
testFramework
] ++ qtLayerRoots;
cmakeFlags = [
"-DLOGOS_CPP_SDK_ROOT=${logosSdk}"
"-DLOGOS_PROTOCOL_ROOT=${logosProtocol}"
"-DLOGOS_TEST_FRAMEWORK_ROOT=${testFramework}"
# A test CMakeLists starts with `include(LogosTest)`, which resolves off
# CMAKE_MODULE_PATH. Without this the configure fails on an unknown
# `logos_test` command, never reaching any of the roots above.
"-DCMAKE_MODULE_PATH=${testFramework}/cmake"
]
++ [ "-DLOGOS_QT_HOST_ROOT=${logosQtHost}" ]
++ lib.optional (logosQtSdk != null) "-DLOGOS_QT_SDK_ROOT=${logosQtSdk}"
++ extraCmakeFlags;
# Build from the test directory
cmakeDir = toString testDir;
preConfigure = ''
# Set up generated code directory
mkdir -p ./generated_code
# Copy dependency includes
${depIncludeSetup}
# Run logos-cpp-generator if available and metadata exists
${lib.optionalString (configFile != null) ''
if command -v logos-cpp-generator &>/dev/null && [ -f "${configFile}" ]; then
echo "Running logos-cpp-generator..."
logos-cpp-generator --metadata "${configFile}" --general-only --output-dir ./generated_code || true
fi
''}
# Custom preConfigure
${preConfigure}
'';
buildPhase = ''
cmake --build . --parallel $NIX_BUILD_CORES
'';
installPhase = ''
mkdir -p $out/bin
find . -maxdepth 2 -type f -executable \( -name "*_tests" -o -name "*_test" \) | while read bin; do
cp "$bin" $out/bin/
done
'';
# Run tests as a check.
#
# The binaries are located and executed directly rather than through ctest.
# `ctest` reports "No tests were found!!!" and exits 0, so a test project
# that registered nothing — a real outcome here — produced a green check
# that ran no tests at all. Finding zero binaries is now a hard failure.
doCheck = true;
checkPhase = ''
runHook preCheck
echo "Running module unit tests..."
testBins=$(find . -maxdepth 2 -type f -executable \( -name "*_tests" -o -name "*_test" \) | sort)
if [ -z "$testBins" ]; then
echo "ERROR: no test executable was built (looked for *_tests / *_test)" >&2
exit 1
fi
for bin in $testBins; do
echo "Executing: $bin"
"$bin"
done
runHook postCheck
'';
}