mirror of
https://github.com/logos-co/logos-app.git
synced 2026-08-30 19:01:09 +00:00
* test(deps): pin what the load gate actually admits
The gate in front of a UI plugin load reads
package_manager.resolveFlatDependencies and classifies each row BY
EXCLUSION:
if (m.value("status").toString() == "not_installed") missing << s;
else installed << s;
`status` is a closed vocabulary owned by logos-package-manager, and it
gained a fourth word. Anything invented after that line was written lands
in `installed`, so a plugin is admitted on top of a dependency the
resolver rejected — with no diagnostic anywhere.
Lift the predicate into app/utils/DependencyBlocker.h VERBATIM, alongside
the message-building it will need, and put the desired behaviour under
test. The three fixtures are wire payloads captured from a real logoscore
daemon over a real installed tree, parsed with QJsonDocument so the suite
consumes exactly the bytes the module emits.
Red at this commit — the classification cases fail, which is master's
behaviour.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* feat(deps): refuse a load on a version-mismatched dependency, and say which
The gate in front of a UI plugin load treated every status except
"not_installed" as satisfied, so a dependency the resolver had just
rejected for being the wrong version was admitted — the plugin mounted on
top of it, or liblogos refused with a bare "plugin load failed".
Name the blocking statuses instead of excluding one, and carry the reason
as far as the user:
* PackageCoordinator gains m_blockingDepsByModule alongside the existing
name list — same membership, filled in the same pass, one map per
blocking dependency. missingDepsOf keeps returning names, so the
sidebar marker, AppsModel::setMissingDeps and installStatus are
untouched; blockingDepsOf is for callers that must TELL the user
something.
* ConfirmationDialog says one of three sentences. "cannot be loaded
because the following modules are not installed" is a lie about a
module that is installed at the wrong version, and it sends the user
to reinstall something they already have. Each row now names the
constraint and what was found — "depsvc — requires ^2.0.0, found
1.0.0" — because a complaint the user cannot act on is barely better
than silence.
* The sidebar marker keeps the red cross for an absent dependency and
draws an amber "!" for a version conflict. "mixed" keeps the cross:
something IS absent, and that is the fact to act on first.
* ModuleInstanceModel's badge reads "Version conflict" rather than
"Missing deps" for the same reason. depBlockKind joins the diffRoles
mask because replaceRows SKIPS a row whose mask is empty, so a row
going absent -> mismatch would otherwise keep the stale word forever.
Deliberately still admitted, both pinned by tests: "cycle" (never driven
against a real cyclic install — blocking it would be a behaviour change
made blind) and an unrecognised status (this gate is advisory in front of
liblogos' own resolver; refusing on a word this build does not know would
block loads that work).
Consequence worth naming: a version-mismatched app now demotes to
installStatus NotInstalled in the App Manager, exactly as one with an
absent dependency already did. The remedy the button offers — reinstall,
which re-resolves dependencies — is right for both.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* test(plugins): pin what the core-dependency loader actually reads
PluginLoader::loadCoreDependencies read each `dependencies[]` entry as
QString depName = dep.toString();
if (depName.isEmpty()) continue;
QVariant::toString() on a QVariantMap returns a NULL QString — no
diagnostic, no exception. So the moment the module ABI is widened to send
the object form {"name": …, "version": "^2.0.0", "signer": "did:…"} that
the LGX spec already allows and lgpm already parses, every CONSTRAINED
core dependency is silently skipped and the ui plugin mounts on top of an
unloaded dependency.
This commit changes no behaviour. It gives that decision a name
(logos::readDependencyEntry) and a test, so the next commit's fix is
visible as a diff in outcomes rather than a diff in expressions.
Red, as expected — 5 of 14 cases fail against the extracted behaviour:
FAIL! : object_entry_yields_its_name() kind 1, want 0
FAIL! : object_entry_without_constraints_yields_its_name() kind 1, want 0
FAIL! : json_object_entry_yields_its_name() kind 1, want 0
FAIL! : hash_object_entry_yields_its_name() kind 1, want 0
FAIL! : a_number_is_unrecognised() kind 0, want 1
(1 = Unrecognised, i.e. skipped. The last one is the mirror image: a
non-string scalar is currently stringified and loaded as a module name.)
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* fix(plugins): read object-form core dependency entries, refuse the rest
The load gate now understands both forms the LGX spec allows, and reports
what it cannot understand instead of walking past it.
Green — 14/14, was 9/14:
PASS : object_entry_yields_its_name()
PASS : object_entry_without_constraints_yields_its_name()
PASS : json_object_entry_yields_its_name()
PASS : hash_object_entry_yields_its_name()
PASS : a_number_is_unrecognised()
Totals: 14 passed, 0 failed
Two behaviour changes at PluginLoader::loadCoreDependencies:
* {"name": "wallet_module", "version": "^2.0.0", "signer": "did:…"} now
loads wallet_module. Before, QVariant::toString() returned a null
QString for it and the `if (depName.isEmpty()) continue;` skipped the
dependency with no error and no log line — the ui plugin then mounted
on top of a core module that was never loaded, and the first symptom
was a dead endpoint somewhere else entirely.
Latent today only because the module ABI still sends bare strings
(package_manager_impl.cpp's toLogosMap flattens the constraint away).
It arms itself the moment that is widened. Every other reader in the
fleet already handles both forms — logos-module's module_metadata.cpp,
logos-standalone-app's mainwindow.cpp, logos-cpp-sdk's
metadata_dependencies.h, lgpm's manifest scan. Basecamp was the outlier.
* An entry that is neither a name nor an object with a string "name" is
now a hard, logged load failure rather than a silent skip. Same reason:
we cannot honour a dependency we cannot name, and mounting anyway hides
it. This also stops a stray scalar being stringified into a module
name — QVariant(42).toString() is "42", and the old loop would have
gone looking for a module called that.
Unreachable from `lgpm install` today: logos-package's Manifest::fromJson
rejects a non-string/non-object entry outright, and lgpm's own scan warns
and drops what gets past it. The branch exists for the manifests that
bypass both — embedded installs written at build time, and anything
edited in place afterwards.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* feat(deps): refuse a load on a dependency published by a different signer
A dependency can now fail its dependant in a third way, and it needs a third
sentence. The gate already separated "not installed" from "installed at a
version it does not accept", because "install it" and "get another version" are
different instructions. `signer_mismatch` is a package installed under the RIGHT
NAME by the WRONG PUBLISHER — somebody else's package — and neither of those
instructions works on it. Installing gets the same package back; no version of
what is on disk is the package the module named.
blockSummary headline body
"absent" Missing Dependencies "…are not installed"
"mismatch" Incompatible Dependencies "…installed at a version it does
not accept"
"signer" Unexpected Publisher "…were published by a different
signer than it requires … reinstall
these from the publisher the module
names"
"mixed" Missing Dependencies "…missing, the wrong version, or from
a different publisher"
Per row, the detail clause names BOTH DIDs: "published by a different signer;
requires <pin>, found <observed>". The pin alone does not say what went wrong;
the observation alone is an accusation with no charge attached.
THE DESIGN CALL, and it is pinned by a test rather than left as an omission.
`signer_unknown` — the edge pins a publisher and NOTHING RECORDS who published
the installed package — does NOT block. Absence of evidence is not evidence of
mismatch, and this is the expected state for two whole populations: every
EMBEDDED package (placed by the build, never through the installer that records
a publisher, so it can never acquire one) and everything installed before the
record existed. Blocking here would make a pin on an embedded dependency
unsatisfiable by construction, forever, with no action a user could take.
logos-package-manager owns the call and can flip it in one place
(UnknownSignerPolicy::Strict makes its scanner emit signer_mismatch, which this
gate already blocks), which is exactly why this gate must not second-guess it.
Three places in this header classified by testing ONE value and sweeping the
rest into a default, and all three are now switches or named alternatives:
readDependencyBlocker the trailing `else` that made version_mismatch
count as satisfied — already fixed, extended
dependencyBlockerToMap `VersionMismatch ? … : "not_installed"`, which
would have crossed into QML labelling a signer
mismatch "not_installed"
summariseDependencyBlockers tested one kind and swept the rest into `absent`,
so a pure signer set summarised as "not installed"
dependencyIsPresent stays written by exclusion, and that is the one place it is
right: exactly one kind means "nothing under this name", so a kind added later
is by definition about a package that IS installed and should count as present
by default. The comment now says so.
The sidebar marker generalises from `_versionConflictOnly` to
`_presentButRejected` — the amber "!" means "everything needed is on disk and
this app rejects it", which is true of both mismatch kinds, while "mixed" keeps
the red cross because something really is absent. The marker's objectName
splits three ways so a UI test can tell the two amber states apart, which a
screenshot cannot. ModuleInstanceModel's badge gains "Signer conflict".
The signer wire rows in dependency_gate_test.cpp are VERBATIM payloads captured
from a real logoscore daemon over a real installed tree, like the rows beside
them, varying only the `signer` sidecar in the dependency's install directory.
RED (signer_mismatch unrecognised, and the summariser back to one kind):
Totals: 27 passed, 6 failed
a_signer_mismatch_blocks b.kind 0, expected 3
a_signer_mismatched_dependency_blocks_… b.kind 0, expected 3
a_signer_mismatch_says_publisher_not_version… detail was empty
the_wire_map_carries_the_signer_kind… kind "not_installed"
summary_of_only_signer_blockers_is_signer summary "absent"
summary_of_a_signer_and_an_absent_blocker… summary "absent"
GREEN, every check individually (nix build --print-out-paths; empty = FAILED):
unit-tests /nix/store/kdml49yg3pcjazdynnq29311wvk7s03d-logos-basecamp-unit-tests-0.0.0
qml-tests /nix/store/k5gmfqwa749nbipam0w9sfdq8cnrdraj-logos-basecamp-qml-tests-0.0.0
smoke-test /nix/store/qhilqrrmlxgi1r6rkk3f2xdhzad1khbs-logos-basecamp-smoke-test
integration-test /nix/store/rda92q559abgp57y5nqn5db1n0p9zwjd-logos-basecamp-integration-test
sandbox-test /nix/store/ip1flrwh4sf05jn747rj9fgrfn8zk7h8-logos-basecamp-sandbox-test-0.0.0
shutdown-test /nix/store/q9a0z0d0c83kl3z17r1d3pps6qp1fgs0-logos-basecamp-shutdown-test
host-services-test /nix/store/9szcjfih4hvc40wvlsihf4yy2l7616gc-logos-basecamp-host-services-test
symbol-gate /nix/store/pbflp7xdnf5py676ii0mwqi0xpkdfg1c-logos-basecamp-symbol-gate
symbol-gate-negative /nix/store/v5vmswffkfq82qhnl9z9q17zz17smbp9-logos-basecamp-symbol-gate-negative
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* refactor(deps): follow observedSigner to signerDid, and say what actually failed
logos-package-manager stopped recording who it verified at install and started
carrying the package's own manifest.sig into the install tree. The row key that
reaches this header changed name because it changed meaning, and the message
built from it was describing the old one.
`observedSigner` was the DID a signature had been VERIFIED against by the
installer. `signerDid` is what the installed signature says about itself, once
checked against the key its own DID carries. Nothing outside the document
corroborates it, so "found <did>" overstated it: it read as an established
publisher when it is the package's own claim, backed by a real key but not by
anything that says which key is the right one.
The detail line now says what failed:
signed by a different key; requires <pin>, signed by <did>
not signed by the required key; requires <pin> (nothing usable installed)
signed by a different key (neither DID available)
And a note this header needs to carry, because the shortcut is inviting and
unsound: do NOT re-derive the verdict by comparing `signerDid` to
`requiredSigner`. A signature document supplies both a DID and a signature, so
it can always be made to agree with itself; that comparison accepts somebody
else's genuine signature relabelled to name the pinned DID. The scanner decides
by verifying the installed signature under the PIN's key, which is why a
signer_mismatch row legitimately carries a signerDid that differs from
requiredSigner.
The dialog headline is unchanged: "published by a different signer" is the
right register for a user, and the mechanism belongs on the row.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* test(deps): re-capture the signer rows against real signatures, and say what a satisfied pin looks like
These rows are documented as verbatim wire payloads, and they were — of a rig
that no longer exists. They were captured by varying a `signer` sidecar, which
logos-package-manager has deleted; and the DID they pinned,
did:jwk:eyJrdHkiOiJPS1AiLCJjcnYiOiJFZDI1NTE5In0, decodes to
{"kty":"OKP","crv":"Ed25519"} — no `x` member, so NO KEY AT ALL.
Against the sidecar that string was only ever COMPARED, so a keyless DID worked
fine. Against a signature it is an UNPARSEABLE PIN, which the library also
reports as signer_mismatch (fail-closed, with a warning naming the depending
manifest). So this suite would have stayed green while every signer row
documented the wrong cause: "this pin cannot be parsed" wearing the label
"a different key signed it".
Re-captured through the real stack — a real logoscore daemon, package_manager
built against the branch, depsvc INSTALLED FROM A REALLY-SIGNED .lgx so the
manifest.sig in its install directory is the one `lgx sign` produced. Nothing
is hand-planted; the only thing that varies is the `signer` pin in the
depending manifest, which is a developer declaration and is meant to vary. Both
DIDs are now real keypairs, and the mismatch row is a package really signed by
one key against a pin naming another.
Adds the row that was missing: a SATISFIED pin. It carries a signerDid, because
that is a property of the package rather than of the edge, and a gate that read
"signer information is present" as a signal in itself would refuse every
correctly-signed dependency in the fleet. Proven by mutation.
Also proven by mutation, and the reason NO comparison guard is added here:
replacing the status check with `signerDid != requiredSigner` — the inviting
shortcut, and the unsound one — turns a_signer_that_cannot_be_checked_does_not_block
red, because a signer_unknown row has a pin and no signerDid. The existing
suite already holds that line; the gate needs no new defence, it needs to keep
deciding from `status`.
The dialog now says what is actually known. "Published by a different signer"
reported a record the installer had written and could be no better than that
record. The scanner now extracts the key from the DID the module itself names
and checks the installed signature against it, so the claim is "not signed by
the key it requires" — which no relabelling on the package side can change.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* docs(deps): cut this PR's comments back to what a reader needs
608 added comment lines -> 351. Comments only; no code line moved or changed.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* chore(deps): relock onto the merged package-manager chain
Takes logos-package-manager-module 5feeb67 (#64) and logos-package-manager
1218d74 (#38), so the gate this PR adds is no longer inert.
Also adds logos-package-manager-ui.inputs.package_manager.follows: without it
the UI brought its own package_manager and the closure carried two, with the
UI that drives installs on the one that has no VersionMismatch. Same shape as
the package_downloader follows in #360.
Verified in the artifact, not the lock: the shipped
modules/package_manager/libpackage_manager_lib.so carries version_mismatch,
signer_mismatch and dependencyConstraints, and is md5-identical to the
relocked lib output.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* test(deps): drive every dependency-gate verdict against the real binary
Adds basecamp-dependency-gate.test.yaml: one launch covering all five —
satisfied admits (exact and range), signer-satisfied admits, signer-unknown
admits, absent blocks, version blocks, signer blocks — each asserting its own
message, not just that something was refused.
Fixtures are real: two Ed25519 keys, both anchored, so the signer refusal is
identity and not trust. The spec fails if either DID carries no `x` member,
and if the app ever logs an unparseable pin — a keyless pin reports
signer_mismatch too, so without that check the suite stays green documenting
the wrong cause.
Also fixes a regression this PR introduced: an absent dependency with no
declared range added "— not installed" to its row, which broke
basecamp-missing-deps ("• demo_core_module" is an exact match) and changed the
text for every bare dependency in the fleet. The dialog heading already says
it; the detail is now empty unless there is a range to name.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* fix(deps): one package_downloader in the closure too, not two
Folds in #360, which is closed. Same defect as the package_manager follows
directly above: logos-package-manager-ui declares neither, so the closure
carried two logos-package-downloader revisions with the UI that drives
installs on the older one.
That one matters because lgpd's resolver is the only component in the stack
that evaluates a version range or a signer pin at all. After: downloader
b6624a3, carrying both the empty-signer-pin fix and the signer binding that
never checked the signature.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* fix(deps): one liblgx in the closure, not two
b75bae8 moved the bundled package_manager onto logos-package 49151f00,
which adds lgx_get_manifest_sig_json and lgx_check_manifest_signature.
logos-liblogos still pinned its own older logos-package-manager, and
liblogos_core links libpackage_manager_lib, so liblogos put the older
liblgx into the bundle's flat lib/.
The two platforms then resolved that ambiguity in opposite directions:
bundle.sh rewrites a Mach-O @rpath dep to a flat @loader_path/../../lib
path, while its ELF arm leaves a bare NEEDED with $ORIGIN first. macOS
bound package_manager to the 34-export lib/ copy and Linux to the
36-export sibling — so the module crashed at its first signature check
on macOS with every Linux job green. Mach-O binds lazily, so it loaded
cleanly and died at the call, three hops from anything that named it.
Follows removes the second revision rather than adding one: no root
input rev changes, 18 nodes drop out of the lock, and lib/liblgx gains
the two symbols. Fixes the macOS package-lifecycle, dependency-gate and
persistence doctests, all 8 failures.
* test(deps): assert the plugin binary by the platform's own suffix
expect_contains matched "depsvc_plugin.so" verbatim — expand_vars runs
over run: but not over the expected strings, so {ext} cannot be used
there. Assert on a string the script emits instead.
The install itself was fine on macOS; the step listed depsvc_plugin.dylib
and exited 0.
* test(deps): gate a library staged twice against symbol skew
Where the bundle stages one library name in lib/ AND beside a module,
both copies must satisfy that module's imports — macOS binds to lib/,
Linux to the sibling, so a skew is fatal on exactly one platform. The
gate intersects each consumer's undefined symbols against both copies
and fails when the two answers differ.
Intersecting against bundled definers keeps host and system symbols out
of scope. Vacuity guards abort if no duplicated name is found or nm
reads nothing, so the gate cannot pass by measuring zero.
On the pre-fix bundle it fails on BOTH platforms, including the Linux
one CI called green. Wired into build-appimage and build-macos-app,
which already build this bundle; not on Windows, where a PE has no
nm -D symbol table.
* fix(ci): the link gate must not clobber ./result
nix build without --out-link writes ./result, so the gate replaced the
bundle symlink that "Rename AppImage with architecture" and "Package app
bundle as tarball" both find their artifact through. The gate itself
passed on aarch64-linux; the step after it failed.
--no-link: the gate's output is a marker, nothing reads it.
* fix(deps): the load gate must not read the cache before it is filled
blockingDepsOf returns an empty list for a cache MISS, and loadUiModule
read that as "nothing blocks this". PackageCoordinator.h states the
opposite contract — "Empty when the async refresh chain hasn't completed
yet; treat empty as not known — show safe defaults" — and the tiles are
published before the dependency fan-out is dispatched, so the window is
real: clicking inside it loads the plugin.
Pre-existing, but this PR is what makes it matter. The only verdict that
could slip through before was not_installed, which liblogos refuses on
its own. version_mismatch and signer_mismatch have no enforcement below
Basecamp at all — DependencyEntry carries {kind, name}, and the resolver
tests isKnown() — so losing the race now mounts a plugin against a
dependency of a rejected version.
Park the load on dependencyDataReadyChanged, mirroring
PackageCoordinator::uninstallApp: same disconnect-prior, same QPointer
guard, last click wins.
* chore(deps): take the staging install (lgpm d88abaa)
Install stages beside the destination and swaps it in rather than copying
over the existing tree, so a failed install leaves no merged directory,
an upgrade drops files the new package stopped shipping, and a module
dir left 0555 no longer wedges the package.
Both pins move together: basecamp declares logos-package-manager
directly AND gets one through the module, with no follows between them,
so moving one would leave two lgpm builds in one closure. Verified they
converge on d88abaa, and liblogos still follows the root pin.
Folded in here rather than raised separately because this branch already
touches flake.lock.
* fix(intents): the missing-deps lambda must match the widened signal
Master's intent broker connects to missingDepsPopupRequested with
(QString, QStringList) — the signature before this branch widened it to
(QString, QVariantList blockers, QString summary). Git merges both sides
cleanly and the result does not compile:
qobject.h:244: no type named 'type' in FunctorReturnType<lambda, List<>>
The lambda only needs the name, so it takes the two extra parameters
unnamed. Also relocks onto master's flake.lock, which has moved
logos-liblogos to a2da65f; the follows here still resolves liblogos'
lgpm to the root pin (d88abaa) and keeps the lock at 3574 nodes against
master's 5152.
* chore(deps): logos-liblogos ca0d5bf — the runtime range gate
This PR gates a UI plugin at the Basecamp layer; liblogos#196 gates any
module at load, on the declared version range. Same feature, two layers,
and until now the app only had the upper one.
The follows still resolves liblogos' lgpm to the root pin (d88abaa) and
the lock grows by one node, the logos-package that logos-module now
carries.
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
466 lines
18 KiB
C++
466 lines
18 KiB
C++
#include "PluginLoader.h"
|
|
|
|
#include <QCoreApplication>
|
|
#include <QDebug>
|
|
#include <QDir>
|
|
#include <QFile>
|
|
#include <QFileInfo>
|
|
#include <QIcon>
|
|
#include <QMutexLocker>
|
|
#include <QPluginLoader>
|
|
#include "win_dll_search.h"
|
|
#include <QQmlComponent>
|
|
#include <QQmlContext>
|
|
#include <QQmlEngine>
|
|
#include <QQmlError>
|
|
#include <QQuickWidget>
|
|
#include <QThread>
|
|
#include <QTimer>
|
|
#include <QUrl>
|
|
|
|
#include <memory>
|
|
|
|
#include "CoreModuleManager.h"
|
|
#include "IComponent.h"
|
|
#include "IntentBridgeAdapter.h"
|
|
#include "LogosQmlBridge.h"
|
|
#include "logos_api.h"
|
|
#include "logos_consumer.h"
|
|
#include "restricted/QmlSandbox.h"
|
|
#include "utils/DependencyEntry.h"
|
|
#include <ViewModuleHost.h>
|
|
|
|
PluginLoader::PluginLoader(LogosAPI* logosAPI,
|
|
CoreModuleManager* coreModuleManager,
|
|
QObject* parent)
|
|
: QObject(parent)
|
|
, m_logosAPI(logosAPI)
|
|
, m_coreModuleManager(coreModuleManager)
|
|
{
|
|
}
|
|
|
|
void PluginLoader::load(const PluginLoadRequest& request)
|
|
{
|
|
if (isLoading(request.name)) {
|
|
qDebug() << "Plugin" << request.name << "is already loading";
|
|
return;
|
|
}
|
|
|
|
setLoading(request.name, true);
|
|
|
|
// Yield to the event loop so the UI can paint the loading state
|
|
QTimer::singleShot(0, this, [this, request]() {
|
|
startLoad(request);
|
|
});
|
|
}
|
|
|
|
bool PluginLoader::isLoading(const QString& name) const
|
|
{
|
|
QMutexLocker lock(&m_mutex);
|
|
return m_loading.contains(name);
|
|
}
|
|
|
|
QStringList PluginLoader::loadingPlugins() const
|
|
{
|
|
QMutexLocker lock(&m_mutex);
|
|
return m_loading.values();
|
|
}
|
|
|
|
void PluginLoader::setLoading(const QString& name, bool loading)
|
|
{
|
|
{
|
|
QMutexLocker lock(&m_mutex);
|
|
if (loading)
|
|
m_loading.insert(name);
|
|
else
|
|
m_loading.remove(name);
|
|
}
|
|
emit loadingChanged();
|
|
}
|
|
|
|
logos::ConsumerIdentity PluginLoader::consumerFor(const QString& name)
|
|
{
|
|
if (name.isEmpty()) {
|
|
qWarning() << "PluginLoader: refusing to build an identity for an unnamed plugin";
|
|
return {};
|
|
}
|
|
|
|
auto it = m_consumers.constFind(name);
|
|
if (it != m_consumers.constEnd())
|
|
return it.value();
|
|
|
|
// logos::admitConsumer isolates the store, constructs the LogosAPI on it,
|
|
// mints a credential, registers it with capability_module over the HOST's
|
|
// trusted channel, and only then installs it in the identity's store. The
|
|
// ordering notes that used to live here — isolate before constructing
|
|
// anything (a LogosAPIClient captures its store as a raw pointer), and
|
|
// register synchronously before the plugin's first QTimer::singleShot(0)
|
|
// call can fire — are now stated once, next to the implementation.
|
|
logos::ConsumerIdentity consumer = logos::admitConsumer(name, m_logosAPI, this);
|
|
if (!consumer) {
|
|
qWarning() << "PluginLoader: could not admit" << name
|
|
<< "as a consumer - refusing to load it with the host's authority";
|
|
return {};
|
|
}
|
|
m_consumers.insert(name, consumer);
|
|
|
|
return consumer;
|
|
}
|
|
|
|
void PluginLoader::startLoad(const PluginLoadRequest& request)
|
|
{
|
|
if (request.coreDependencies.isEmpty()) {
|
|
continueLoad(request);
|
|
return;
|
|
}
|
|
|
|
loadCoreDependencies(request);
|
|
}
|
|
|
|
void PluginLoader::loadCoreDependencies(const PluginLoadRequest& request)
|
|
{
|
|
// liblogos is not thread-safe for plugin loading; call only from the GUI thread.
|
|
// Every core-plugin load goes through CoreModuleManager so the logos_core_*
|
|
// C API is centralised in one place.
|
|
for (const QVariant& dep : request.coreDependencies) {
|
|
// Bare name or {"name": …, "version": …, "signer": …} — either way we
|
|
// need the name. See utils/DependencyEntry.h for why this must not be
|
|
// a bare dep.toString().
|
|
const logos::DependencyEntry entry = logos::readDependencyEntry(dep);
|
|
if (entry.kind == logos::DependencyEntryKind::Unrecognised) {
|
|
// No name means no way to honour the declaration. Refuse rather
|
|
// than continue: mounting the plugin with a declared dependency
|
|
// silently unloaded surfaces later as a missing method or a dead
|
|
// endpoint, with nothing in the log pointing here.
|
|
qWarning() << "Unrecognised core dependency entry" << dep
|
|
<< "for" << request.name
|
|
<< "- expected a module name, or an object with a "
|
|
"string \"name\"; refusing to load";
|
|
setLoading(request.name, false);
|
|
emit pluginLoadFailed(request.name,
|
|
QStringLiteral("Unrecognised dependency entry in ")
|
|
+ request.name + QStringLiteral("'s manifest"));
|
|
return;
|
|
}
|
|
const QString depName = entry.name;
|
|
if (!m_coreModuleManager) {
|
|
qWarning() << "Failed to load core dependency" << depName
|
|
<< "for" << request.name;
|
|
setLoading(request.name, false);
|
|
emit pluginLoadFailed(request.name,
|
|
QStringLiteral("Failed to load core dependencies for ") + request.name);
|
|
return;
|
|
}
|
|
qDebug() << "Loading core dependency for" << request.name << ":" << depName;
|
|
if (!m_coreModuleManager->loadModule(depName)) {
|
|
qWarning() << "Failed to load core dependency" << depName
|
|
<< "for" << request.name;
|
|
setLoading(request.name, false);
|
|
emit pluginLoadFailed(request.name,
|
|
QStringLiteral("Failed to load core dependencies for ") + request.name);
|
|
return;
|
|
}
|
|
}
|
|
continueLoad(request);
|
|
}
|
|
|
|
void PluginLoader::continueLoad(const PluginLoadRequest& request)
|
|
{
|
|
switch (request.type) {
|
|
case UIPluginType::UiQml:
|
|
loadUiQmlModule(request);
|
|
break;
|
|
case UIPluginType::Legacy:
|
|
loadCppPluginAsync(request);
|
|
break;
|
|
}
|
|
}
|
|
|
|
// ---------- Legacy ui plugin path ----------
|
|
|
|
void PluginLoader::loadCppPluginAsync(const PluginLoadRequest& request)
|
|
{
|
|
// Pre-load the shared library in a background thread.
|
|
// Qt's QLibraryStore caches loaded libraries globally, so the subsequent
|
|
// QPluginLoader::load() on the main thread will be instant.
|
|
QThread* thread = QThread::create([path = request.pluginPath]() {
|
|
// Add the plugin's OWN directory to the DLL search before the image is
|
|
// mapped, so a UI plugin can resolve libraries vendored beside it.
|
|
// Windows searches the EXECUTABLE's directory, not the importing DLL's.
|
|
// No-op off Windows. The reference is deliberately not released: these
|
|
// plugins stay resident for the process lifetime (QPluginLoader's
|
|
// destructor does not unload), and this is the load that actually maps
|
|
// the image -- the main-thread load below then hits Qt's cache.
|
|
ModuleLib::preloadPluginWithOwnDirSearch(path);
|
|
QPluginLoader loader(path);
|
|
loader.load();
|
|
});
|
|
|
|
connect(thread, &QThread::finished, this,
|
|
[this, thread, request]() {
|
|
thread->deleteLater();
|
|
finishCppPluginLoad(request);
|
|
});
|
|
|
|
thread->start();
|
|
}
|
|
|
|
void PluginLoader::finishCppPluginLoad(const PluginLoadRequest& request)
|
|
{
|
|
// Normally a no-op: loadCppPluginAsync already mapped the image. Kept so
|
|
// this path is correct on its own, since a caller reaching it without the
|
|
// async pre-load would otherwise fail to resolve vendored DLLs.
|
|
ModuleLib::preloadPluginWithOwnDirSearch(request.pluginPath);
|
|
QPluginLoader loader(request.pluginPath);
|
|
if (!loader.load()) {
|
|
qWarning() << "Failed to load plugin:" << request.name << "-" << loader.errorString();
|
|
setLoading(request.name, false);
|
|
emit pluginLoadFailed(request.name, loader.errorString());
|
|
return;
|
|
}
|
|
|
|
QObject* plugin = loader.instance();
|
|
if (!plugin) {
|
|
qWarning() << "Failed to get plugin instance:" << request.name;
|
|
setLoading(request.name, false);
|
|
emit pluginLoadFailed(request.name, QStringLiteral("Failed to get plugin instance"));
|
|
return;
|
|
}
|
|
|
|
IComponent* component = qobject_cast<IComponent*>(plugin);
|
|
if (!component) {
|
|
qWarning() << "Plugin does not implement IComponent:" << request.name;
|
|
loader.unload();
|
|
setLoading(request.name, false);
|
|
emit pluginLoadFailed(request.name, QStringLiteral("Plugin does not implement IComponent"));
|
|
return;
|
|
}
|
|
|
|
// The plugin's own identity, not the host's. A legacy widget plugin calls
|
|
// modules through whatever LogosAPI it is handed, so handing it m_logosAPI
|
|
// handed it the host's ambient token ring.
|
|
//
|
|
// One call where there were two. The old pair minted a UUID, registered it,
|
|
// and then DROPPED it — the identity was registered under a credential
|
|
// nobody held, and it worked only because the isolated store had been born
|
|
// holding a copy of the host's anchor. That copy is gone; the credential is
|
|
// now installed in the store admitConsumer built.
|
|
const logos::ConsumerIdentity consumer = consumerFor(request.name);
|
|
if (!consumer) {
|
|
loader.unload();
|
|
setLoading(request.name, false);
|
|
emit pluginLoadFailed(request.name,
|
|
QStringLiteral("Could not establish an isolated identity for ") + request.name);
|
|
return;
|
|
}
|
|
|
|
QWidget* widget = component->createWidget(consumer.api);
|
|
if (!widget) {
|
|
qWarning() << "Component returned null widget:" << request.name;
|
|
loader.unload();
|
|
setLoading(request.name, false);
|
|
emit pluginLoadFailed(request.name, QStringLiteral("Component returned null widget"));
|
|
return;
|
|
}
|
|
|
|
if (!request.iconPath.isEmpty())
|
|
widget->setWindowIcon(QIcon(request.iconPath));
|
|
|
|
setLoading(request.name, false);
|
|
emit pluginLoaded(request.name, widget, component, UIPluginType::Legacy, nullptr);
|
|
}
|
|
|
|
// ---------- ui_qml module path ----------
|
|
|
|
void PluginLoader::loadUiQmlModule(const PluginLoadRequest& request)
|
|
{
|
|
if (request.qmlViewPath.isEmpty() || !QFile::exists(request.qmlViewPath)) {
|
|
qWarning() << "ui_qml module QML file not found:" << request.qmlViewPath;
|
|
setLoading(request.name, false);
|
|
emit pluginLoadFailed(request.name,
|
|
QStringLiteral("QML view file not found: ") + request.qmlViewPath);
|
|
return;
|
|
}
|
|
|
|
// The bridge the QML gets speaks AS this module, from this module's own
|
|
// token store — not as basecamp.
|
|
//
|
|
// ONE ADMISSION, ONE CREDENTIAL, BOTH PATHS. Two separate things used to be
|
|
// conflated here, and only the second one needs a ui-host:
|
|
//
|
|
// 1. Making `request.name` a KNOWN CALLER at capability_module, which is
|
|
// what lets its very first requestModule get past the known-caller
|
|
// gate. Needed by the pure-QML path too — in fact especially there,
|
|
// since the QML is the only thing calling out.
|
|
// 2. Giving ui-host the credential its backend accepts inbound calls with.
|
|
//
|
|
// The old code did (1) inside the has-a-backend branch, below an early
|
|
// return, so the pure-QML path registered nothing at all. It got away with
|
|
// it because it was calling with the host's ambient ring, where every
|
|
// target's token was already present and no handshake ever happened. Both
|
|
// are now one call that cannot be branched around, and the credential it
|
|
// returns is the SAME value in the store and on the wire to ui-host —
|
|
// where it used to be minted here and never given to the in-process bridge.
|
|
const logos::ConsumerIdentity consumer = consumerFor(request.name);
|
|
if (!consumer) {
|
|
setLoading(request.name, false);
|
|
emit pluginLoadFailed(request.name,
|
|
QStringLiteral("Could not establish an isolated identity for ") + request.name);
|
|
return;
|
|
}
|
|
auto* bridge = new LogosQmlBridge(consumer.api, this);
|
|
|
|
if (request.mainFilePath.isEmpty()) {
|
|
loadQmlView(request, bridge, nullptr);
|
|
return;
|
|
}
|
|
|
|
// Has a backend plugin — spawn a ViewModuleHost process.
|
|
//
|
|
// The credential goes to ui-host, which adopts it into its own image's
|
|
// token store (logos::adoptConsumerCredential). admitConsumer registered it
|
|
// synchronously above, before this process spawns, which is the race the
|
|
// old comment here described: plugin ctors commonly schedule their first
|
|
// IPC via QTimer::singleShot(0, ...) and those fire the instant ui-host
|
|
// enters its event loop, so a registration deferred to onHostReady would
|
|
// lose to them and capability_module would refuse with "auth token not
|
|
// recognized".
|
|
auto* viewHost = new ViewModuleHost(this);
|
|
if (!viewHost->spawn(request.name, request.mainFilePath, consumer.credential)) {
|
|
qWarning() << "Failed to spawn ui-host for ui_qml module" << request.name;
|
|
delete viewHost;
|
|
delete bridge;
|
|
setLoading(request.name, false);
|
|
emit pluginLoadFailed(request.name,
|
|
QStringLiteral("Failed to spawn ui-host for ") + request.name);
|
|
return;
|
|
}
|
|
|
|
auto onHostReady = [this, request, bridge, viewHost]() {
|
|
bridge->setViewModuleSocket(request.name, viewHost->socketName());
|
|
|
|
const QString base = QFileInfo(request.mainFilePath).absolutePath()
|
|
+ QStringLiteral("/") + request.name
|
|
+ QStringLiteral("_replica_factory");
|
|
for (const QString& suffix : { QStringLiteral(".dylib"),
|
|
QStringLiteral(".so"),
|
|
QStringLiteral(".dll") }) {
|
|
const QString factoryPath = base + suffix;
|
|
if (QFile::exists(factoryPath)) {
|
|
bridge->setViewReplicaPlugin(request.name, factoryPath);
|
|
break;
|
|
}
|
|
}
|
|
loadQmlView(request, bridge, viewHost);
|
|
};
|
|
|
|
auto* timeout = new QTimer(this);
|
|
timeout->setSingleShot(true);
|
|
auto readyConn = std::make_shared<QMetaObject::Connection>();
|
|
auto timeoutConn = std::make_shared<QMetaObject::Connection>();
|
|
*readyConn = connect(viewHost, &ViewModuleHost::ready, this,
|
|
[timeout, readyConn, timeoutConn, onHostReady]() {
|
|
QObject::disconnect(*readyConn);
|
|
QObject::disconnect(*timeoutConn);
|
|
timeout->stop();
|
|
timeout->deleteLater();
|
|
onHostReady();
|
|
});
|
|
*timeoutConn = connect(timeout, &QTimer::timeout, this,
|
|
[this, request, viewHost, bridge, timeout, readyConn, timeoutConn]() {
|
|
QObject::disconnect(*readyConn);
|
|
QObject::disconnect(*timeoutConn);
|
|
timeout->deleteLater();
|
|
qWarning() << "Timeout waiting for ui-host ready signal for" << request.name;
|
|
viewHost->stop();
|
|
viewHost->deleteLater();
|
|
delete bridge;
|
|
setLoading(request.name, false);
|
|
emit pluginLoadFailed(request.name,
|
|
QStringLiteral("Timeout waiting for ui-host for ") + request.name);
|
|
});
|
|
timeout->start(30000);
|
|
}
|
|
|
|
void PluginLoader::loadQmlView(const PluginLoadRequest& request,
|
|
LogosQmlBridge* bridge,
|
|
ViewModuleHost* viewHost)
|
|
{
|
|
auto* qmlWidget = new QQuickWidget;
|
|
qmlWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
|
if (QQmlEngine* engine = qmlWidget->engine()) {
|
|
const QString appLibDir =
|
|
QDir(QCoreApplication::applicationDirPath() + "/../lib").canonicalPath();
|
|
QmlSandbox::configure(engine, request.installDir, request.qmlViewPath,
|
|
appLibDir, request.name);
|
|
engine->setBaseUrl(QUrl::fromLocalFile(request.installDir + "/"));
|
|
}
|
|
|
|
// Async pre-compile: the engine caches compiled types so setSource() is fast.
|
|
QUrl sourceUrl = QUrl::fromLocalFile(request.qmlViewPath);
|
|
auto* preloader = new QQmlComponent(qmlWidget->engine(), sourceUrl,
|
|
QQmlComponent::Asynchronous);
|
|
|
|
auto finishOrCleanup = [this, preloader, qmlWidget, request, bridge,
|
|
viewHost](QQmlComponent::Status status) {
|
|
preloader->deleteLater();
|
|
if (status == QQmlComponent::Ready) {
|
|
finishUiQmlLoad(qmlWidget, request, bridge, viewHost);
|
|
} else {
|
|
QString errors;
|
|
for (const auto& e : preloader->errors())
|
|
errors += e.toString() + QStringLiteral("\n");
|
|
qWarning() << "Failed to compile ui_qml view" << request.name << ":" << errors;
|
|
qmlWidget->deleteLater();
|
|
delete bridge;
|
|
if (viewHost) { viewHost->stop(); delete viewHost; }
|
|
setLoading(request.name, false);
|
|
emit pluginLoadFailed(request.name, errors);
|
|
}
|
|
};
|
|
|
|
if (preloader->isReady() || preloader->isError()) {
|
|
finishOrCleanup(preloader->status());
|
|
} else {
|
|
connect(preloader, &QQmlComponent::statusChanged, this, finishOrCleanup);
|
|
}
|
|
}
|
|
|
|
void PluginLoader::finishUiQmlLoad(QQuickWidget* qmlWidget,
|
|
const PluginLoadRequest& request,
|
|
LogosQmlBridge* bridge,
|
|
ViewModuleHost* viewHost)
|
|
{
|
|
bridge->setParent(qmlWidget);
|
|
|
|
// Attach BEFORE setSource() below, which is where QML actually runs: an app
|
|
// calling logos.request() from Component.onCompleted would otherwise be an
|
|
// unknown bridge and get `unavailable` from its own shell.
|
|
// The single funnel for every ui_qml app — the QML-only and backend paths
|
|
// both converge here.
|
|
if (m_intentAdapter)
|
|
m_intentAdapter->attach(request.name, bridge);
|
|
|
|
qmlWidget->rootContext()->setContextProperty("logos", bridge);
|
|
qmlWidget->rootContext()->setContextProperty("isActiveTab", true);
|
|
qmlWidget->setSource(QUrl::fromLocalFile(request.qmlViewPath));
|
|
|
|
if (!request.iconPath.isEmpty())
|
|
qmlWidget->setWindowIcon(QIcon(request.iconPath));
|
|
|
|
if (qmlWidget->status() == QQuickWidget::Error) {
|
|
qWarning() << "Failed to load ui_qml view" << request.name;
|
|
const auto errors = qmlWidget->errors();
|
|
for (const QQmlError& error : errors) qWarning() << error.toString();
|
|
qmlWidget->deleteLater();
|
|
if (viewHost) { viewHost->stop(); delete viewHost; }
|
|
setLoading(request.name, false);
|
|
emit pluginLoadFailed(request.name,
|
|
QStringLiteral("Failed to load QML view for ") + request.name);
|
|
return;
|
|
}
|
|
|
|
setLoading(request.name, false);
|
|
emit pluginLoaded(request.name, qmlWidget, nullptr, UIPluginType::UiQml, viewHost);
|
|
}
|