diff --git a/controller/app/src/main/java/org/iiab/controller/redesign/ModuleDetailFragment.java b/controller/app/src/main/java/org/iiab/controller/redesign/ModuleDetailFragment.java index aff4e8fd6..c744427a9 100644 --- a/controller/app/src/main/java/org/iiab/controller/redesign/ModuleDetailFragment.java +++ b/controller/app/src/main/java/org/iiab/controller/redesign/ModuleDetailFragment.java @@ -90,7 +90,47 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c if (lic != null) licView.setText(getString(R.string.k2go_mod_license_fmt, lic)); else licView.setVisibility(View.GONE); + // ADFA-5104: the detail offered Install now and Schedule on a module that is already + // installed. The hub stopped doing that; this screen is one tap behind it, and it is the + // louder of the two — a full-width button reads as an invitation in a way a checkbox does + // not. Both actions go, and a chip says why. + // + // Read off the main thread and applied when it returns: the buttons start hidden rather + // than start visible, because showing them and then taking them away is how a user ends + // up tapping one in the gap. + final Button installNowBtn = root.findViewById(R.id.k2go_moddet_install_now); + final ViewGroup chipRow = chips; + installNowBtn.setVisibility(View.GONE); + Button schedule = root.findViewById(R.id.k2go_moddet_schedule); + schedule.setVisibility(View.GONE); + + final android.content.Context appCtx = requireContext().getApplicationContext(); + org.iiab.controller.util.AppExecutors.get().io().execute(() -> { + final java.util.Set onDisk = + org.iiab.controller.system.data.InstalledModulesReader.installedKeys(appCtx); + // Null is "could not read", not "nothing installed" — same distinction the hub keeps. + final boolean isInstalled = onDisk != null && onDisk.contains(c.key()); + final boolean unknown = onDisk == null; + // root, not requireView(): inside onCreateView the fragment's view is not set yet, + // so requireView() would throw. root is already inflated and its handler is the + // main looper's. + root.post(() -> { + if (!isAdded()) return; + if (isInstalled) { + chipRow.addView(chip(getString(R.string.k2go_mod_phase_done), R.color.k2go_leaf)); + return; // nothing to offer: a module cannot be uninstalled or reinstalled here + } + if (unknown) { + chipRow.addView(chip(getString(R.string.k2go_state_no_answer), + R.color.k2go_amber_text)); + return; // no grounds to offer work either way + } + installNowBtn.setVisibility(View.VISIBLE); + if (!c.hasSelector) schedule.setVisibility(View.VISIBLE); + }); + }); + boolean scheduled = ModuleWishlist.contains(requireContext(), c.key()); schedule.setText(getString(scheduled ? R.string.k2go_mod_unschedule : R.string.k2go_mod_schedule)); schedule.setOnClickListener(v -> { @@ -99,9 +139,10 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c requireActivity().getOnBackPressedDispatcher().onBackPressed(); // back to the hub (shows ✓) }); - if (c.hasSelector) schedule.setVisibility(View.GONE); // ADFA-4958: maps schedules via its selector, not here + // ADFA-4958: maps schedules via its selector, not here — folded into the callback above, + // which is now the only thing that makes either button visible. - Button installNow = root.findViewById(R.id.k2go_moddet_install_now); + Button installNow = installNowBtn; installNow.setOnClickListener(v -> { if (org.iiab.controller.env.EnvironmentLock.isHeld(requireContext())) { Snackbars.make(v, R.string.k2go_install_busy).show(); return; } if (getActivity() instanceof SetupLibraryActivity) { diff --git a/controller/app/src/main/java/org/iiab/controller/redesign/ModuleHubFragment.java b/controller/app/src/main/java/org/iiab/controller/redesign/ModuleHubFragment.java index 9c6b4ab5f..64ce9e508 100644 --- a/controller/app/src/main/java/org/iiab/controller/redesign/ModuleHubFragment.java +++ b/controller/app/src/main/java/org/iiab/controller/redesign/ModuleHubFragment.java @@ -48,7 +48,47 @@ public class ModuleHubFragment extends Fragment { private final Handler main = new Handler(Looper.getMainLooper()); - private final Set installable = new HashSet<>(); // yamlBaseKeys not yet installed + /** + * ADFA-5104: yamlBaseKeys the installer's flags say are installed. + * + *

Read from {@code local_vars.yml} on disk rather than derived from who answers, so it is + * right with the box stopped. A module install only ever adds, so within one system's life + * this can grow and cannot shrink — and a system replacement takes the file with it, so the + * answer invalidates itself. + */ + private final Set installed = new HashSet<>(); + /** + * ADFA-5104: whether there is a system to install modules into. + * + *

The precondition nobody was asking. A module install lays files into the rootfs and runs + * a runrole inside it; with no rootfs there is nothing to install into and nothing to run it + * with. The screen still listed all six as installable, because it decided that from a probe + * — and with no system nothing answers, so everything looked missing. + * + *

Reachable, not theoretical: {@code pref_key_setup_complete} is only ever written true — + * five writers, none of them clears it — so after a reset or a failed restore the app still + * routes to the Library, and Settings still opens this screen over an empty rootfs. + * + *

Seeded true so the first frame looks like the ordinary case; the background pass + * corrects it before anything is offered. + */ + private boolean systemPresent = true; + /** + * ADFA-5104: whether the first disk pass has answered. + * + *

Without it the list renders every module as "Not installed" for the instant before the + * read returns and then corrects itself — a flicker that says the wrong thing, which is what + * this screen is being fixed for. "Checking" is the honest word for that instant. + */ + private boolean loaded = false; + /** + * ADFA-5104: true when a system exists but its flags could not be read. + * + *

Its own state, not folded into "nothing installed". A half-written or unreadable + * local_vars.yml is silence, and reading silence as absence is the defect this screen is + * being fixed for — collapsing it here would have reproduced it one layer down. + */ + private boolean stateUnknown = false; private int probesPending = 0; private int probeGen = 0; // ADFA-4842: supersedes an in-flight probe batch (e.g. onResume re-probe) private LinearLayout host; @@ -107,39 +147,101 @@ public void onResume() { refreshProceed(); // scheduled set may have changed (returned from a detail) } - /** Probe every presentable module's endpoint; a module is INSTALLABLE when it is NOT reachable - * (not installed yet) and its 64-bit requirement is met. */ + /** + * ADFA-5104: one pass that asks the disk, then lets a probe add to it. + * + *

It used to be N probes and nothing else, so the screen's answer to "what is installed" + * was really "what is answering" — and with the box stopped that is nothing, which is how an + * installed module came to be offered for installation. + */ private void probeAll() { final int gen = ++probeGen; // supersede any batch still in flight; its callbacks will bail - List cards = ModuleCards.all(); - final Set found = new HashSet<>(); - probesPending = 0; - for (final ModuleCards.Card c : cards) { + final Context appCtx = requireContext().getApplicationContext(); + AppExecutors.get().io().execute(() -> { + // Both reads touch the filesystem and neither needs the network or a proot. + final boolean present = + org.iiab.controller.SystemStateEvaluator.isSystemInstalled(appCtx); + // Null means the flags could not be read; empty means they were read and claim + // nothing. The screen must not treat those alike. + final Set fromDisk = present + ? org.iiab.controller.system.data.InstalledModulesReader.installedKeys(appCtx) + : java.util.Collections.emptySet(); + main.post(() -> { + if (!isAdded() || gen != probeGen) return; + systemPresent = present; + loaded = true; + stateUnknown = present && fromDisk == null; + installed.clear(); + if (fromDisk != null) installed.addAll(fromDisk); + // ADFA-5104: an order for something already installed is moot, and leaving it + // banked means the button counts it and the drain would rebuild what is there. + // The pill says "Installed"; the button has to agree. + for (String key : installed) ModuleWishlist.remove(requireContext(), key); + probesPending = 0; + buildCards(); // the disk answer is already showable; do not wait on HTTP + refreshProceed(); + // A probe can still rescue the unknown case: it only ever adds, so whatever + // answers is real even when the file could not be read. + if (present) confirmByProbe(gen); + }); + }); + } + + /** + * Ask the running box, and let it add only. + * + *

A probe that answers proves a platform is there, which is worth having: it covers + * anything installed by a route that did not write the flag. A probe that 404s proves much + * less — the service can be installed and switched off, and nginx answers the same way — so + * it does not demote a module the installer's own flags claim. + * + *

That leaves one known gap, deliberately: {@code InstallService} writes the flag before + * the runrole and reverts it if the run fails, so a process death between the two leaves a + * claim that never came true, and nothing here will correct it. The alternative is letting a + * 404 demote, and that costs more — it is the error that offers a multi-hour reinstall of + * something already present, which is the defect this ticket exists to remove. + */ + private void confirmByProbe(final int gen) { + final Set answered = new HashSet<>(); + for (final ModuleCards.Card c : ModuleCards.all()) { if (c.requires64Bit() && !is64Bit()) continue; // hidden on this device + if (installed.contains(c.key())) continue; // disk already says yes probesPending++; final String key = c.key(); final String endpoint = c.endpoint(); AppExecutors.get().io().execute(() -> { - final boolean installed = reachable(endpoint); + final boolean present = reachable(endpoint); main.post(() -> { - if (!isAdded() || gen != probeGen) return; // fragment gone or batch superseded - if (!installed) found.add(key); + if (!isAdded() || gen != probeGen) return; + if (present) answered.add(key); probesPending--; - if (probesPending <= 0) { - installable.clear(); - installable.addAll(found); + if (probesPending <= 0 && !answered.isEmpty()) { + installed.addAll(answered); buildCards(); refreshProceed(); } }); }); } - if (probesPending == 0) { installable.clear(); buildCards(); } } private void buildCards() { if (host == null) return; host.removeAllViews(); + // ADFA-5104: with no system there is nothing to install into, so nothing is offered and + // the screen says why. Listing modules here would be an invitation the box cannot honour. + if (!systemPresent) { + TextView msg = new TextView(requireContext()); + msg.setGravity(Gravity.CENTER); + msg.setPadding(px(8), px(24), px(8), px(24)); + msg.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_BodyMedium); + msg.setTextColor(ContextCompat.getColor(requireContext(), R.color.k2go_muted)); + msg.setText(R.string.k2go_mod_needs_system); + host.addView(msg); + addHiddenSection(); + return; + } + TextView helper = new TextView(requireContext()); // ADFA-4958 helper.setText(R.string.k2go_mod_mgmt_helper); helper.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_BodySmall); @@ -149,34 +251,53 @@ private void buildCards() { helperLp.bottomMargin = px(8); host.addView(helper, helperLp); - // ADFA-5011: the dash-node REST core is a system module — always present (not installable/ - // removable), with a single Rebuild action. Shown at the top, above the installable list. + // ADFA-5011: the dash-node REST core is a system module — present once a system is + // (not installable/removable), with a single Rebuild action. Shown at the top. addSystemDashboardCard(); + // ADFA-5104: everything presentable, with its state. Hiding installed modules answered a + // question nobody asked — "what can I still add" — while users were asking the other one, + // "what do I have". A module cannot be uninstalled, so the row is not an offer to undo + // anything; it is the only place the answer exists. List items = new ArrayList<>(); - for (ModuleCards.Card c : ModuleCards.all()) if (installable.contains(c.key())) items.add(c); - - if (items.isEmpty()) { + for (ModuleCards.Card c : ModuleCards.all()) { + if (c.requires64Bit() && !is64Bit()) continue; // never going to run here + items.add(c); + } + boolean anyInstallable = false; + for (ModuleCards.Card c : items) if (!installed.contains(c.key())) { anyInstallable = true; break; } + + // ADFA-5104: k2go_mod_none is gone from here. It said "everything available is already + // installed", which was true while the list was filtered to installables and is not now + // that the list shows everything — and with the filter gone the branch could only fire on + // a device where every module needs 64 bits, where the sentence would be wrong anyway. + if (!loaded || items.isEmpty()) { TextView msg = new TextView(requireContext()); msg.setGravity(Gravity.CENTER); msg.setPadding(0, px(24), 0, px(24)); msg.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_BodyMedium); msg.setTextColor(ContextCompat.getColor(requireContext(), R.color.k2go_muted)); - msg.setText(probesPending > 0 ? R.string.k2go_gm_checking : R.string.k2go_mod_none); + msg.setText(R.string.k2go_gm_checking); host.addView(msg); } else { // ADFA-4958: last informed step before the locked install index. A build takes time. - TextView note = new TextView(requireContext()); - note.setText(R.string.k2go_mod_time_note); - note.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_BodySmall); - note.setTextColor(ContextCompat.getColor(requireContext(), R.color.k2go_warn_ink)); - note.setBackgroundResource(R.drawable.k2go_warn_bg); - note.setPadding(px(16), px(14), px(16), px(14)); - LinearLayout.LayoutParams nlp = new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); - nlp.bottomMargin = px(12); - host.addView(note, nlp); - for (ModuleCards.Card c : items) host.addView(cardRow(c)); + // ADFA-5104: only when something is still installable — over a list of modules that + // are all installed, the warning describes work nobody is about to start. + if (anyInstallable && !stateUnknown) { + TextView note = new TextView(requireContext()); + note.setText(R.string.k2go_mod_time_note); + note.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_BodySmall); + note.setTextColor(ContextCompat.getColor(requireContext(), R.color.k2go_warn_ink)); + note.setBackgroundResource(R.drawable.k2go_warn_bg); + note.setPadding(px(16), px(14), px(16), px(14)); + LinearLayout.LayoutParams nlp = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); + nlp.bottomMargin = px(12); + host.addView(note, nlp); + } + for (ModuleCards.Card c : items) { + host.addView(cardRow(c, installed.contains(c.key()), stateUnknown)); + } } addHiddenSection(); } @@ -244,7 +365,8 @@ private void addHiddenSection() { /** A full-width tappable module row: title + subtitle + one-line description, with a "Scheduled" * badge when banked, else a chevron. */ - private View cardRow(final ModuleCards.Card c) { + private View cardRow(final ModuleCards.Card c, final boolean isInstalled, + final boolean unknown) { LinearLayout row = new LinearLayout(requireContext()); row.setOrientation(LinearLayout.HORIZONTAL); row.setGravity(Gravity.CENTER_VERTICAL); @@ -261,7 +383,12 @@ private View cardRow(final ModuleCards.Card c) { } }); - if (!c.hasSelector) { // ADFA-4958: tick to schedule several at once (maps uses its own selector) + // ADFA-5104: no tick on an installed module. There is nothing to schedule — installing it + // again is not an action the app offers, and a checkbox that does nothing is worse than + // no checkbox. The row still opens its detail, which is where "what is this" lives. + // ADFA-5104: and no tick when the flags could not be read either. Ticking would bank an + // order we have no grounds to take. + if (!isInstalled && !unknown && !c.hasSelector) { // ADFA-4958: tick to schedule several at once (maps uses its own selector) com.google.android.material.checkbox.MaterialCheckBox cb = new com.google.android.material.checkbox.MaterialCheckBox(requireContext()); cb.setChecked(ModuleWishlist.contains(requireContext(), c.key())); @@ -305,11 +432,18 @@ private View cardRow(final ModuleCards.Card c) { row.addView(col, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f)); - boolean scheduled = ModuleWishlist.contains(requireContext(), c.key()); // ADFA-4958 §5.2: state pill + // ADFA-4958 §5.2: state pill. ADFA-5104: installed outranks scheduled — a module that is + // already there cannot meaningfully be waiting to be installed, and if a stale wishlist + // entry survived an install, saying "Scheduled" over it would be the older lie again. + boolean scheduled = !isInstalled && !unknown && ModuleWishlist.contains(requireContext(), c.key()); TextView pill = statePill( - scheduled ? getString(R.string.k2go_mod_scheduled) - : getString(R.string.k2go_state_not_installed), - scheduled ? R.color.k2go_teal : R.color.k2go_muted); + isInstalled ? getString(R.string.k2go_mod_phase_done) + : unknown ? getString(R.string.k2go_state_no_answer) + : scheduled ? getString(R.string.k2go_mod_scheduled) + : getString(R.string.k2go_state_not_installed), + isInstalled ? R.color.k2go_leaf + : unknown ? R.color.k2go_amber_text + : scheduled ? R.color.k2go_teal : R.color.k2go_muted); LinearLayout.LayoutParams tlp = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); tlp.leftMargin = px(10); @@ -382,6 +516,10 @@ private void fetchDashVersion(final TextView sub) { private void refreshProceed() { if (proceed == null || !isAdded()) return; int n = ModuleWishlist.size(requireContext()); + // ADFA-5104: a banked order cannot be drained into a system that is not there. The drain + // itself now refuses (SystemDoor), but offering the button and then refusing is a worse + // answer than not offering it. + if (!systemPresent || stateUnknown) { proceed.setVisibility(View.GONE); return; } proceed.setVisibility(n > 0 ? View.VISIBLE : View.GONE); proceed.setEnabled(n > 0); if (n > 0) proceed.setText(getString(R.string.k2go_mod_proceed_fmt, n)); diff --git a/controller/app/src/main/java/org/iiab/controller/system/data/InstalledModulesReader.java b/controller/app/src/main/java/org/iiab/controller/system/data/InstalledModulesReader.java new file mode 100644 index 000000000..3859bbb11 --- /dev/null +++ b/controller/app/src/main/java/org/iiab/controller/system/data/InstalledModulesReader.java @@ -0,0 +1,133 @@ +/* + * ============================================================================ + * Name : InstalledModulesReader.java + * Author : AppDevForAll + * Copyright : Copyright (c) 2026 AppDevForAll + * Description : ADFA-5104. Reads the installer's flags off the rootfs, with the + * box up or down. No proot, no network. + * ============================================================================ + */ +package org.iiab.controller.system.data; + +import android.content.Context; +import android.util.Log; + +import org.iiab.controller.ModuleRegistry; +import org.iiab.controller.SystemStateEvaluator; +import org.iiab.controller.system.domain.InstalledModules; +import org.iiab.controller.system.domain.PlatformPresence; +import org.iiab.controller.util.LocalVarsYamlParser; +import org.json.JSONObject; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.nio.charset.StandardCharsets; +import java.util.Set; + +/** + * What is installed, read from the rootfs instead of asked over HTTP. + * + *

{@code etc/iiab/local_vars.yml} is a plain file inside the rootfs directory, so this is an + * ordinary file read on the host filesystem — no proot is entered and no service needs to be + * running. That is the whole reason this exists: the screens that ask "what is installed" must + * keep working with the box stopped, and until now they asked a probe, which cannot. + * + *

Invalidation is free. The file lives inside the rootfs, so a reset, restore, clone or + * reinstall replaces or removes it along with everything else. There is no cache to clear and no + * destructive route that can be forgotten — the failure mode that a SharedPreferences copy of the + * same fact would have had, and does have: {@code installed_tier} is written once and cleared by + * nobody. + * + *

Not free of I/O. Small file, but a file: call this off the main thread. It is cheap + * enough to call per screen and too expensive to call per row. + */ +public final class InstalledModulesReader { + + private static final String TAG = "K2Go-Modules"; + private static final String LOCAL_VARS = "etc/iiab/local_vars.yml"; + + /** Refuse to read anything absurd for this file; a real one is a few KB. */ + private static final long MAX_BYTES = 512L * 1024L; + + private InstalledModulesReader() { + } + + /** + * The installer's flags, or {@code null} when they cannot be read. + * + *

Null is a distinct answer and callers must keep it distinct: no system, a system being + * laid down right now, or a rootfs we cannot read. None of those mean "nothing is installed". + */ + public static JSONObject readFlags(Context ctx) { + if (ctx == null) { + return null; + } + File file = new File(SystemStateEvaluator.rootfsDir(ctx), LOCAL_VARS); + try { + if (!file.isFile() || !file.canRead()) { + return null; + } + if (file.length() > MAX_BYTES) { + Log.w(TAG, "local_vars.yml is " + file.length() + " bytes; refusing to parse"); + return null; + } + return LocalVarsYamlParser.parseToJson(readUtf8(file)); + } catch (Exception e) { + // Vanished mid-read, permissions, a wipe in flight. All of them are "not established". + Log.w(TAG, "could not read local_vars.yml", e); + return null; + } + } + + /** + * The file as text. + * + *

Plain streams rather than {@code Files.readAllBytes}: {@code java.nio.file} is API 26 and + * this app ships to 24 with no desugaring, so the tidier call would crash on the oldest + * devices we support — which are exactly the ones this product exists for. + */ + private static String readUtf8(File file) throws Exception { + try (FileInputStream in = new FileInputStream(file)) { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + byte[] buf = new byte[8192]; + int read; + while ((read = in.read(buf)) != -1) { + out.write(buf, 0, read); + } + return new String(out.toByteArray(), StandardCharsets.UTF_8); + } + } + + /** + * Which presentable modules the flags claim are installed, or {@code null} when the flags + * could not be read at all. + * + *

Null rather than an empty set, and the difference is the whole point. "Nothing is + * installed" and "I could not look" are different answers, and a caller that receives the + * empty set for both will offer to install what is already there the moment the file is + * missing, unreadable or half-written — which is the defect this class exists to remove, + * reappearing one layer down. An earlier version of this method did exactly that. + */ + public static Set installedKeys(Context ctx) { + JSONObject flags = readFlags(ctx); + if (flags == null) { + return null; + } + return InstalledModules.from(flags, ModuleRegistry.validYamlKeys()); + } + + /** + * Disk evidence for one module, ready to be weighed against a probe. + * + *

Disk wins where the two disagree, and the reason is in the asymmetry rather than in a + * preference: a readable file that does not carry the flag is a statement by the installer, + * while a probe that does not answer is usually a statement about the network. The probe's + * job here is to correct the one window disk cannot see — the flag is written before the + * runrole and reverted if it fails, so a process death in between leaves a claim that never + * came true. + */ + public static PlatformPresence.Evidence evidenceFor(Context ctx, String yamlBaseKey) { + return InstalledModules.evidenceFor(readFlags(ctx), yamlBaseKey); + } +} diff --git a/controller/app/src/main/java/org/iiab/controller/system/domain/InstalledModules.java b/controller/app/src/main/java/org/iiab/controller/system/domain/InstalledModules.java new file mode 100644 index 000000000..cff9c8f0f --- /dev/null +++ b/controller/app/src/main/java/org/iiab/controller/system/domain/InstalledModules.java @@ -0,0 +1,108 @@ +/* + * ============================================================================ + * Name : InstalledModules.java + * Author : AppDevForAll + * Copyright : Copyright (c) 2026 AppDevForAll + * Description : ADFA-5104. What the installer's own flags say is installed. + * Pure JVM, no Android, no I/O. + * ============================================================================ + */ +package org.iiab.controller.system.domain; + +import org.json.JSONObject; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +/** + * Reads "what is installed" out of the installer's own flags, rather than out of who answers. + * + *

Why the flags and not a probe. A probe answers "is this platform serving right now", + * which is a different question and a worse one for this purpose: it needs the box up, it needs + * the network stack, and it turns every kind of silence into "absent". The flags are written by + * the thing that does the installing, they live on disk, and they can be read with the box + * stopped. + * + *

Why this is allowed to be remembered. A module install only ever adds. There is no + * uninstall today, so within one system's life the set can grow and cannot shrink — which is + * what makes a stored answer safe, where a stored answer about a *running* service would not be. + * The exit from that is a system replacement (reset, restore, clone, reinstall), and the flags + * handle it for free: they live inside the rootfs, so a replacement takes them with it. Nothing + * has to remember to invalidate anything. + * + *

What this is not. Intention, not result — {@code InstallService} writes + * {@code _install: True} before the runrole and reverts it if the run fails, so a process + * death between the two leaves a flag claiming an install that never finished. That window is + * narrow and it is why a live probe still gets to confirm or correct this. It is not a reason to + * prefer the probe: a flag that is wrong for minutes beats a probe that is wrong whenever the box + * is off. + */ +public final class InstalledModules { + + /** The suffix the installer appends to a module's yaml base key. */ + private static final String INSTALL_SUFFIX = "_install"; + + private InstalledModules() { + } + + /** + * Whether the flags claim this module is installed. + * + *

{@code _install} only. The installer also writes {@code _enabled}, but that is + * a different statement — a module can be installed and switched off — and reading both would + * make "installed" mean "installed and running", which is the conflation this ticket exists to + * undo. + * + * @param flags parsed {@code local_vars.yml} flags, as {@code LocalVarsYamlParser} + * produces them; null is treated as "nothing known" + * @param yamlBaseKey the module's key in {@code local_vars.yml}, e.g. {@code calibreweb} + */ + public static boolean isInstalled(JSONObject flags, String yamlBaseKey) { + if (flags == null || yamlBaseKey == null || yamlBaseKey.isEmpty()) { + return false; + } + return flags.optBoolean(yamlBaseKey + INSTALL_SUFFIX, false); + } + + /** + * The subset of {@code knownKeys} the flags claim is installed. + * + *

Restricted to the roster on purpose: {@code local_vars.yml} carries a flag for every + * IIAB role that exists, most of which this app does not present and cannot install. Reading + * them all would put names on screen that no card can render. + */ + public static Set from(JSONObject flags, Collection knownKeys) { + if (flags == null || knownKeys == null) { + return Collections.emptySet(); + } + Set installed = new HashSet<>(); + for (String key : knownKeys) { + if (isInstalled(flags, key)) { + installed.add(key); + } + } + return installed; + } + + /** + * What the flags amount to as evidence about one module. + * + *

The asymmetry matters and is the reason this returns {@link PlatformPresence.Evidence} + * rather than a boolean. A readable file that does not claim the module is a real + * {@code ABSENT} — the installer would have written the flag — and that is stronger than a + * 404, which only says nothing is serving that path right now. An unreadable file is + * {@code NONE}: no rootfs, or no system yet, and the caller must not read that as absence. + * + * @param flags null when the file could not be read at all + */ + public static PlatformPresence.Evidence evidenceFor(JSONObject flags, String yamlBaseKey) { + if (flags == null) { + return PlatformPresence.Evidence.NONE; + } + return isInstalled(flags, yamlBaseKey) + ? PlatformPresence.Evidence.PRESENT + : PlatformPresence.Evidence.ABSENT; + } +} diff --git a/controller/app/src/main/res/values-ar/strings_k2go.xml b/controller/app/src/main/res/values-ar/strings_k2go.xml index fc050ddb0..86bbe7e67 100644 --- a/controller/app/src/main/res/values-ar/strings_k2go.xml +++ b/controller/app/src/main/res/values-ar/strings_k2go.xml @@ -771,4 +771,5 @@ افتراضي مخصص غير مثبَّت + تُثبَّت الوحدات داخل نظام، ولا يوجد نظام بعد. ثبِّت نظامًا أولًا. diff --git a/controller/app/src/main/res/values-az/strings_k2go.xml b/controller/app/src/main/res/values-az/strings_k2go.xml index 6fc10d8a4..7d3e06a26 100644 --- a/controller/app/src/main/res/values-az/strings_k2go.xml +++ b/controller/app/src/main/res/values-az/strings_k2go.xml @@ -771,4 +771,5 @@ Standart Fərdi Quraşdırılmayıb + Modullar sistemin içinə quraşdırılır, sistem isə hələ yoxdur. Əvvəlcə sistem quraşdırın. diff --git a/controller/app/src/main/res/values-bg/strings_k2go.xml b/controller/app/src/main/res/values-bg/strings_k2go.xml index 03ba5b546..51b130172 100644 --- a/controller/app/src/main/res/values-bg/strings_k2go.xml +++ b/controller/app/src/main/res/values-bg/strings_k2go.xml @@ -771,4 +771,5 @@ По подразбиране Персонализиран Не е инсталирано + Модулите се инсталират в система, а такава още няма. Първо инсталирайте система. diff --git a/controller/app/src/main/res/values-bn/strings_k2go.xml b/controller/app/src/main/res/values-bn/strings_k2go.xml index 9a8840b5b..2f98226fc 100644 --- a/controller/app/src/main/res/values-bn/strings_k2go.xml +++ b/controller/app/src/main/res/values-bn/strings_k2go.xml @@ -771,4 +771,5 @@ ডিফল্ট কাস্টম ইনস্টল করা নেই + মডিউলগুলি একটি সিস্টেমের ভেতরে ইনস্টল হয়, আর এখনো কোনো সিস্টেম নেই। আগে একটি সিস্টেম ইনস্টল করুন। diff --git a/controller/app/src/main/res/values-cs/strings_k2go.xml b/controller/app/src/main/res/values-cs/strings_k2go.xml index 64620850c..ce2e70796 100644 --- a/controller/app/src/main/res/values-cs/strings_k2go.xml +++ b/controller/app/src/main/res/values-cs/strings_k2go.xml @@ -771,4 +771,5 @@ Výchozí Vlastní Nenainstalováno + Moduly se instalují do systému a ten zatím neexistuje. Nejprve nainstalujte systém. diff --git a/controller/app/src/main/res/values-de/strings_k2go.xml b/controller/app/src/main/res/values-de/strings_k2go.xml index a015ebc09..27f370e37 100644 --- a/controller/app/src/main/res/values-de/strings_k2go.xml +++ b/controller/app/src/main/res/values-de/strings_k2go.xml @@ -772,4 +772,5 @@ Standard Eigene Nicht installiert + Module werden in ein System installiert, und es gibt noch keines. Installieren Sie zuerst ein System. diff --git a/controller/app/src/main/res/values-el/strings_k2go.xml b/controller/app/src/main/res/values-el/strings_k2go.xml index b399bd30b..ebdfe27b0 100644 --- a/controller/app/src/main/res/values-el/strings_k2go.xml +++ b/controller/app/src/main/res/values-el/strings_k2go.xml @@ -772,4 +772,5 @@ Προεπιλογή Προσαρμοσμένο Δεν έχει εγκατασταθεί + Τα αρθρώματα εγκαθίστανται μέσα σε ένα σύστημα, και δεν υπάρχει ακόμη. Εγκαταστήστε πρώτα ένα σύστημα. diff --git a/controller/app/src/main/res/values-es/strings_k2go.xml b/controller/app/src/main/res/values-es/strings_k2go.xml index cb0424d2a..f60be4e66 100644 --- a/controller/app/src/main/res/values-es/strings_k2go.xml +++ b/controller/app/src/main/res/values-es/strings_k2go.xml @@ -771,4 +771,5 @@ Predeterminado Personalizado No instalado + Los módulos se instalan dentro de un sistema, y todavía no hay uno. Instala primero un sistema. diff --git a/controller/app/src/main/res/values-fa/strings_k2go.xml b/controller/app/src/main/res/values-fa/strings_k2go.xml index 962d341ed..33cc8227c 100644 --- a/controller/app/src/main/res/values-fa/strings_k2go.xml +++ b/controller/app/src/main/res/values-fa/strings_k2go.xml @@ -771,4 +771,5 @@ پیش‌فرض سفارشی نصب‌نشده + ماژول‌ها درون یک سیستم نصب می‌شوند و هنوز سیستمی وجود ندارد. ابتدا یک سیستم نصب کنید. diff --git a/controller/app/src/main/res/values-fr/strings_k2go.xml b/controller/app/src/main/res/values-fr/strings_k2go.xml index be0c2269b..efd0d9d2d 100644 --- a/controller/app/src/main/res/values-fr/strings_k2go.xml +++ b/controller/app/src/main/res/values-fr/strings_k2go.xml @@ -781,4 +781,5 @@ Par défaut Personnalisé Non installé + Les modules s\'installent dans un système, et il n\'y en a pas encore. Installez d\'abord un système. diff --git a/controller/app/src/main/res/values-gu/strings_k2go.xml b/controller/app/src/main/res/values-gu/strings_k2go.xml index b92c468d6..2f8715bd8 100644 --- a/controller/app/src/main/res/values-gu/strings_k2go.xml +++ b/controller/app/src/main/res/values-gu/strings_k2go.xml @@ -771,4 +771,5 @@ ડિફૉલ્ટ કસ્ટમ ઇન્સ્ટૉલ થયેલ નથી + મોડ્યુલ સિસ્ટમની અંદર ઇન્સ્ટોલ થાય છે, અને હજી કોઈ સિસ્ટમ નથી. પહેલાં સિસ્ટમ ઇન્સ્ટોલ કરો. diff --git a/controller/app/src/main/res/values-hi/strings_k2go.xml b/controller/app/src/main/res/values-hi/strings_k2go.xml index ee470aa0c..18d565a04 100644 --- a/controller/app/src/main/res/values-hi/strings_k2go.xml +++ b/controller/app/src/main/res/values-hi/strings_k2go.xml @@ -771,4 +771,5 @@ डिफ़ॉल्ट कस्टम इंस्टॉल नहीं है + मॉड्यूल किसी सिस्टम के भीतर इंस्टॉल होते हैं, और अभी कोई सिस्टम नहीं है। पहले एक सिस्टम इंस्टॉल करें। diff --git a/controller/app/src/main/res/values-hu/strings_k2go.xml b/controller/app/src/main/res/values-hu/strings_k2go.xml index 794117e33..d4b33d0b5 100644 --- a/controller/app/src/main/res/values-hu/strings_k2go.xml +++ b/controller/app/src/main/res/values-hu/strings_k2go.xml @@ -771,4 +771,5 @@ Alapértelmezett Egyéni Nincs telepítve + A modulok egy rendszerbe települnek, és még nincs ilyen. Először telepítsen egy rendszert. diff --git a/controller/app/src/main/res/values-in/strings_k2go.xml b/controller/app/src/main/res/values-in/strings_k2go.xml index a60b9ff17..515df3ea9 100644 --- a/controller/app/src/main/res/values-in/strings_k2go.xml +++ b/controller/app/src/main/res/values-in/strings_k2go.xml @@ -771,4 +771,5 @@ Default Khusus Belum terpasang + Modul dipasang ke dalam sebuah sistem, dan belum ada sistem. Pasang sistem terlebih dahulu. diff --git a/controller/app/src/main/res/values-it/strings_k2go.xml b/controller/app/src/main/res/values-it/strings_k2go.xml index 22377aeda..dab1a9b56 100644 --- a/controller/app/src/main/res/values-it/strings_k2go.xml +++ b/controller/app/src/main/res/values-it/strings_k2go.xml @@ -771,4 +771,5 @@ Predefinito Personalizzato Non installato + I moduli si installano dentro un sistema, e non ce n\'è ancora uno. Installa prima un sistema. diff --git a/controller/app/src/main/res/values-ja/strings_k2go.xml b/controller/app/src/main/res/values-ja/strings_k2go.xml index 1da351e89..7deb32916 100644 --- a/controller/app/src/main/res/values-ja/strings_k2go.xml +++ b/controller/app/src/main/res/values-ja/strings_k2go.xml @@ -771,4 +771,5 @@ デフォルト カスタム 未インストール + モジュールはシステムの中にインストールされますが、まだシステムがありません。先にシステムをインストールしてください。 diff --git a/controller/app/src/main/res/values-ko/strings_k2go.xml b/controller/app/src/main/res/values-ko/strings_k2go.xml index 799dd9c52..d1253ba45 100644 --- a/controller/app/src/main/res/values-ko/strings_k2go.xml +++ b/controller/app/src/main/res/values-ko/strings_k2go.xml @@ -771,4 +771,5 @@ 기본값 맞춤 설치되지 않음 + 모듈은 시스템 안에 설치되는데 아직 시스템이 없습니다. 먼저 시스템을 설치하세요. diff --git a/controller/app/src/main/res/values-lt/strings_k2go.xml b/controller/app/src/main/res/values-lt/strings_k2go.xml index 105e550d7..980819b93 100644 --- a/controller/app/src/main/res/values-lt/strings_k2go.xml +++ b/controller/app/src/main/res/values-lt/strings_k2go.xml @@ -781,4 +781,5 @@ Numatytasis Pasirinktinis Neįdiegta + Moduliai diegiami į sistemą, o jos dar nėra. Pirmiausia įdiekite sistemą. diff --git a/controller/app/src/main/res/values-nl/strings_k2go.xml b/controller/app/src/main/res/values-nl/strings_k2go.xml index 4eae8956d..ca85cece7 100644 --- a/controller/app/src/main/res/values-nl/strings_k2go.xml +++ b/controller/app/src/main/res/values-nl/strings_k2go.xml @@ -771,4 +771,5 @@ Standaard Aangepast Niet geïnstalleerd + Modules worden in een systeem geïnstalleerd, en dat is er nog niet. Installeer eerst een systeem. diff --git a/controller/app/src/main/res/values-no/strings_k2go.xml b/controller/app/src/main/res/values-no/strings_k2go.xml index 6a8e688c7..0aa423339 100644 --- a/controller/app/src/main/res/values-no/strings_k2go.xml +++ b/controller/app/src/main/res/values-no/strings_k2go.xml @@ -781,4 +781,5 @@ Standard Egendefinert Ikke installert + Moduler installeres i et system, og det finnes ikke ennå. Installer et system først. diff --git a/controller/app/src/main/res/values-pl/strings_k2go.xml b/controller/app/src/main/res/values-pl/strings_k2go.xml index 3578ba09d..24d042f26 100644 --- a/controller/app/src/main/res/values-pl/strings_k2go.xml +++ b/controller/app/src/main/res/values-pl/strings_k2go.xml @@ -781,4 +781,5 @@ Domyślne Niestandardowe Niezainstalowane + Moduły instalują się w systemie, a tego jeszcze nie ma. Najpierw zainstaluj system. diff --git a/controller/app/src/main/res/values-pt/strings_k2go.xml b/controller/app/src/main/res/values-pt/strings_k2go.xml index 905f4054a..6f6b72dc1 100644 --- a/controller/app/src/main/res/values-pt/strings_k2go.xml +++ b/controller/app/src/main/res/values-pt/strings_k2go.xml @@ -771,4 +771,5 @@ Predefinição Personalizado Não instalado + Os módulos são instalados dentro de um sistema, e ainda não existe um. Instale primeiro um sistema. diff --git a/controller/app/src/main/res/values-ro/strings_k2go.xml b/controller/app/src/main/res/values-ro/strings_k2go.xml index 31f1503a7..84d0e0a7b 100644 --- a/controller/app/src/main/res/values-ro/strings_k2go.xml +++ b/controller/app/src/main/res/values-ro/strings_k2go.xml @@ -771,4 +771,5 @@ Implicit Personalizat Neinstalat + Modulele se instalează într-un sistem, iar acesta încă nu există. Instalați mai întâi un sistem. diff --git a/controller/app/src/main/res/values-ru-rRU/strings_k2go.xml b/controller/app/src/main/res/values-ru-rRU/strings_k2go.xml index b7a7d008b..a2b69580c 100644 --- a/controller/app/src/main/res/values-ru-rRU/strings_k2go.xml +++ b/controller/app/src/main/res/values-ru-rRU/strings_k2go.xml @@ -771,4 +771,5 @@ По умолчанию Свой Не установлено + Модули устанавливаются в систему, а её ещё нет. Сначала установите систему. diff --git a/controller/app/src/main/res/values-sk/strings_k2go.xml b/controller/app/src/main/res/values-sk/strings_k2go.xml index 8ed010ac9..826356cb7 100644 --- a/controller/app/src/main/res/values-sk/strings_k2go.xml +++ b/controller/app/src/main/res/values-sk/strings_k2go.xml @@ -771,4 +771,5 @@ Predvolené Vlastné Nenainštalované + Moduly sa inštalujú do systému a ten zatiaľ neexistuje. Najprv nainštalujte systém. diff --git a/controller/app/src/main/res/values-sr/strings_k2go.xml b/controller/app/src/main/res/values-sr/strings_k2go.xml index 08c1418ca..a8b8f49ca 100644 --- a/controller/app/src/main/res/values-sr/strings_k2go.xml +++ b/controller/app/src/main/res/values-sr/strings_k2go.xml @@ -771,4 +771,5 @@ Подразумевано Прилагођено Није инсталирано + Модули се инсталирају у систем, а њега још нема. Прво инсталирајте систем. diff --git a/controller/app/src/main/res/values-sw/strings_k2go.xml b/controller/app/src/main/res/values-sw/strings_k2go.xml index 091369cf9..7b0a1d8f6 100644 --- a/controller/app/src/main/res/values-sw/strings_k2go.xml +++ b/controller/app/src/main/res/values-sw/strings_k2go.xml @@ -771,4 +771,5 @@ Chaguo-msingi Maalum Haijasakinishwa + Moduli husakinishwa ndani ya mfumo, na bado hakuna mfumo. Sakinisha mfumo kwanza. diff --git a/controller/app/src/main/res/values-ta/strings_k2go.xml b/controller/app/src/main/res/values-ta/strings_k2go.xml index aff45a9e2..7b3372e07 100644 --- a/controller/app/src/main/res/values-ta/strings_k2go.xml +++ b/controller/app/src/main/res/values-ta/strings_k2go.xml @@ -771,4 +771,5 @@ இயல்புநிலை தனிப்பயன் நிறுவப்படவில்லை + தொகுதிகள் ஒரு அமைப்பினுள் நிறுவப்படுகின்றன, இன்னும் அமைப்பு எதுவும் இல்லை. முதலில் ஒரு அமைப்பை நிறுவுங்கள். diff --git a/controller/app/src/main/res/values-tr/strings_k2go.xml b/controller/app/src/main/res/values-tr/strings_k2go.xml index 24726d444..989a5652c 100644 --- a/controller/app/src/main/res/values-tr/strings_k2go.xml +++ b/controller/app/src/main/res/values-tr/strings_k2go.xml @@ -771,4 +771,5 @@ Varsayılan Özel Yüklü değil + Modüller bir sistemin içine kurulur ve henüz bir sistem yok. Önce bir sistem kurun. diff --git a/controller/app/src/main/res/values-uk/strings_k2go.xml b/controller/app/src/main/res/values-uk/strings_k2go.xml index 76d546fff..3800f9327 100644 --- a/controller/app/src/main/res/values-uk/strings_k2go.xml +++ b/controller/app/src/main/res/values-uk/strings_k2go.xml @@ -771,4 +771,5 @@ За замовчуванням Власний Не встановлено + Модулі встановлюються в систему, а її ще немає. Спершу встановіть систему. diff --git a/controller/app/src/main/res/values-vi/strings_k2go.xml b/controller/app/src/main/res/values-vi/strings_k2go.xml index e91ab56aa..b8c114f95 100644 --- a/controller/app/src/main/res/values-vi/strings_k2go.xml +++ b/controller/app/src/main/res/values-vi/strings_k2go.xml @@ -771,4 +771,5 @@ Mặc định Tùy chỉnh Chưa cài đặt + Các mô-đun được cài vào một hệ thống, và hiện chưa có hệ thống nào. Hãy cài hệ thống trước. diff --git a/controller/app/src/main/res/values-yo/strings_k2go.xml b/controller/app/src/main/res/values-yo/strings_k2go.xml index 54e11897e..1a58f5423 100644 --- a/controller/app/src/main/res/values-yo/strings_k2go.xml +++ b/controller/app/src/main/res/values-yo/strings_k2go.xml @@ -771,4 +771,5 @@ Àbùdá Àdáni Kò tíì fi sórí ẹ̀rọ + A ń fi àwọn módù sínú ètò kan, kò sì tí ì sí ọ̀kan. Fi ètò kan sílẹ̀ ṣáájú. diff --git a/controller/app/src/main/res/values-zh-rCN/strings_k2go.xml b/controller/app/src/main/res/values-zh-rCN/strings_k2go.xml index fbf1b97ca..2d2d4fca8 100644 --- a/controller/app/src/main/res/values-zh-rCN/strings_k2go.xml +++ b/controller/app/src/main/res/values-zh-rCN/strings_k2go.xml @@ -771,4 +771,5 @@ 默认 自定义 未安装 + 模块要安装到系统里,而目前还没有系统。请先安装一个系统。 diff --git a/controller/app/src/main/res/values/strings_k2go.xml b/controller/app/src/main/res/values/strings_k2go.xml index a37929980..67c1b20ab 100644 --- a/controller/app/src/main/res/values/strings_k2go.xml +++ b/controller/app/src/main/res/values/strings_k2go.xml @@ -840,4 +840,5 @@ the real removal waits for that download's reindex. --> Deleted — hidden for now, fully removed once the current download finishes. Couldn\'t delete. Please try again. + Modules are installed into a system, and there isn\'t one yet. Install a system first. diff --git a/controller/app/src/test/java/org/iiab/controller/system/domain/InstalledModulesTest.java b/controller/app/src/test/java/org/iiab/controller/system/domain/InstalledModulesTest.java new file mode 100644 index 000000000..d79c179ac --- /dev/null +++ b/controller/app/src/test/java/org/iiab/controller/system/domain/InstalledModulesTest.java @@ -0,0 +1,147 @@ +package org.iiab.controller.system.domain; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.iiab.controller.util.LocalVarsYamlParser; +import org.json.JSONObject; +import org.junit.Test; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +/** + * Unit tests for {@link InstalledModules} — the rule that reads "what is installed" out of the + * installer's own flags instead of out of who answers a probe. Pure JVM, no emulator. + * + *

Fed through the real {@link LocalVarsYamlParser} wherever the input is a file's worth of + * text, so the two are pinned together: the rule is only as good as what the parser hands it, and + * a change to either that breaks the pair should fail here. + */ +public class InstalledModulesTest { + + private static final Set ROSTER = new HashSet<>(Arrays.asList( + "kolibri", "calibreweb", "kiwix", "code", "matomo", "maps")); + + private static JSONObject parse(String yaml) { + return LocalVarsYamlParser.parseToJson(yaml); + } + + // ---- the ordinary reading ---------------------------------------------- + + @Test + public void anInstallFlagMeansInstalled() { + JSONObject flags = parse("kolibri_install: True\nkiwix_install: False\n"); + assertTrue(InstalledModules.isInstalled(flags, "kolibri")); + assertFalse(InstalledModules.isInstalled(flags, "kiwix")); + } + + @Test + public void aModuleWithNoFlagAtAllIsNotInstalled() { + assertFalse(InstalledModules.isInstalled(parse("kolibri_install: True\n"), "matomo")); + } + + /** + * Installed and enabled are different statements. Reading both would make "installed" mean + * "installed and running", which is the conflation this work exists to undo. + */ + @Test + public void enabledOnItsOwnIsNotInstalled() { + JSONObject flags = parse("calibreweb_enabled: True\n"); + assertFalse(InstalledModules.isInstalled(flags, "calibreweb")); + } + + @Test + public void installedWhileDisabledIsStillInstalled() { + JSONObject flags = parse("calibreweb_install: True\ncalibreweb_enabled: False\n"); + assertTrue(InstalledModules.isInstalled(flags, "calibreweb")); + } + + // ---- the set, and why it is restricted --------------------------------- + + @Test + public void theSetIsTheRosterIntersection() { + JSONObject flags = parse( + "kolibri_install: True\n" + + "calibreweb_install: yes\n" + + "kiwix_install: False\n"); + assertEquals(new HashSet<>(Arrays.asList("kolibri", "calibreweb")), + InstalledModules.from(flags, ROSTER)); + } + + /** + * local_vars carries a flag for every IIAB role that exists, most of which this app neither + * presents nor can install. Reading them all would put names on screen no card can render. + */ + @Test + public void rolesOutsideTheRosterAreIgnored() { + JSONObject flags = parse("nextcloud_install: True\nosm_vector_maps_install: True\n"); + assertTrue(InstalledModules.from(flags, ROSTER).isEmpty()); + } + + @Test + public void nothingKnownYieldsAnEmptySet() { + assertTrue(InstalledModules.from(null, ROSTER).isEmpty()); + assertTrue(InstalledModules.from(parse(""), ROSTER).isEmpty()); + assertTrue(InstalledModules.from(parse("kolibri_install: True\n"), Collections.emptySet()) + .isEmpty()); + } + + // ---- the asymmetry that makes this worth an Evidence ------------------- + + /** + * The whole point of returning Evidence rather than a boolean: a readable file that does not + * claim the module is a real absence, because the installer would have written the flag. An + * unreadable file is not — and a caller that cannot tell those apart is the bug. + */ + @Test + public void anUnreadableFileIsSilence_notAbsence() { + assertEquals(PlatformPresence.Evidence.NONE, + InstalledModules.evidenceFor(null, "kolibri")); + } + + @Test + public void areadableFileWithoutTheFlagIsAbsence() { + assertEquals(PlatformPresence.Evidence.ABSENT, + InstalledModules.evidenceFor(parse("kiwix_install: True\n"), "kolibri")); + } + + @Test + public void areadableFileWithTheFlagIsPresence() { + assertEquals(PlatformPresence.Evidence.PRESENT, + InstalledModules.evidenceFor(parse("kolibri_install: True\n"), "kolibri")); + } + + /** Silence must not be resolved as absent; absence must. That is what the caller acts on. */ + @Test + public void resolveKeepsSilenceOnTheSafeSide() { + assertTrue(PlatformPresence.resolve(InstalledModules.evidenceFor(null, "kolibri"))); + assertFalse(PlatformPresence.resolve( + InstalledModules.evidenceFor(parse("kiwix_install: True\n"), "kolibri"))); + } + + // ---- what the parser actually survives --------------------------------- + + /** + * Pinned deliberately. LocalVarsYamlParser is not a YAML parser (tech-debt D14) — it splits on + * the first colon and knows nothing about nesting, quoting or inline comments. That was + * tolerable while it fed a cosmetic grid; it is load-bearing now, so the shapes it does and + * does not survive are written down rather than assumed. + */ + @Test + public void theParsersKnownLimitsAreRecordedHere() { + assertTrue(InstalledModules.isInstalled(parse("kolibri_install: yes"), "kolibri")); + assertTrue(InstalledModules.isInstalled(parse("kolibri_install: 1"), "kolibri")); + assertFalse(InstalledModules.isInstalled(parse("# kolibri_install: True"), "kolibri")); + + // Indented keys are read as top level: the parser trims, so nesting is invisible to it. + assertTrue(InstalledModules.isInstalled(parse(" kolibri_install: True"), "kolibri")); + + // An inline comment is part of the value, so the flag reads false. A real local_vars.yml + // written by InstallService never has one; a hand-edited file could. + assertFalse(InstalledModules.isInstalled(parse("kolibri_install: True # on"), "kolibri")); + } +}