Compare commits

Author SHA1 Message Date
xavierk 482c2ac72a prototype: explore dashboard clarity treatments 2026-09-10 11:03:47 +05:30
xavierk 4a7661d81c chore: bump version to 0.3.3 (missed from #54 fix commit)
Release / release (push) Successful in 55s
2026-09-10 10:01:28 +05:30
xavierk fb683f52ba fix(store): degrade on store permission errors, keep store group-readable (issue #54)
Release / release (push) Successful in 53s
- open_store_readonly(): stat() PermissionError (non-group user on the
  2750 store dir) now maps to StoreFault so status/TUI degrade instead
  of crashing with a traceback.
- init_store(): chmod db + -wal/-shm group rw after WAL setup — SQLite
  WAL readers need write access to sidecars even for mode=ro opens.
- Store dir 2750 → 2770 (tmpfiles + make install) and UMask=002 on the
  collect unit so root-created files stay group-accessible.
- rpm %post upgrade path re-runs systemd-tmpfiles --create to correct
  placement modes on existing machines.
Bump to 0.3.3.
2026-09-10 09:58:24 +05:30
xavierk 512df2ae83 fix(store): default store_path when config omits it (issue #53)
Release / release (push) Successful in 59s
Fresh installs shipped a config template with no store_path key while
collector.py demanded one via get_store_path() — every first collect
crashed with KeyError 'store_path'. Resolve to the packaged default
(/var/lib/fenris/observations.db) when absent, document the key in the
template, and cover the fresh-install path with regression tests.
Bump to 0.3.2.
2026-09-10 09:45:02 +05:30
12 changed files with 257 additions and 7 deletions
+5
View File
@@ -8,4 +8,9 @@
#
# device = /dev/disk/by-id/nvme-Samsung_SSD_980_PRO_500GB_S5PANS0T123456
#
# The observation store path is optional and defaults to
# /var/lib/fenris/observations.db when unset:
#
# store_path = /var/lib/fenris/observations.db
#
# See https://git.bongbetic.com/xavierk/Fenris for documentation.
+2
View File
@@ -44,4 +44,6 @@ print(f'Fenris migration: {n} step(s) applied') if n else None
fi
rm -f "${OLD_CONTENT}"
done
# Re-apply placement modes (store dir group access, issue #54)
systemd-tmpfiles --create || true
fi
+1 -1
View File
@@ -1,2 +1,2 @@
# Type Path Mode User Group Age Argument
d /var/lib/fenris 2750 root fenris - -
d /var/lib/fenris 2770 root fenris - -
+23
View File
@@ -0,0 +1,23 @@
# Fenris dashboard clarity PROTOTYPE (throwaway)
**Question:** How should five fixed dashboard additions look without redesigning Panes information architecture?
Three treatments of existing dense screen, switchable via `?variant=a|b|c`. Active/paused selector exposes visual distinction between quitting TUI and Deliberate disable.
## Run
```sh
./prototype/dashboard-clarity/run
```
Open <http://127.0.0.1:8765/prototype/dashboard-clarity/?variant=a>.
## Variants
- **A — Quiet integration:** low-noise banner, green persistence line, inverse quit key.
- **B — Labelled rails:** explicit labels, left-edge alerts, separated action row.
- **C — Strong state blocks:** highest contrast paused state, service/action blocks.
Use left/right arrows or buttons. Switch state between `active` and `paused`.
Throwaway artifact for [Prototype the dashboard clarity additions](https://git.bongbetic.com/xavierk/Fenris/issues/56). No production code or final wording.
+48
View File
@@ -0,0 +1,48 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Fenris dashboard clarity prototype</title>
<style>
:root{color-scheme:dark;--bg:#111318;--panel:#191c23;--line:#586071;--text:#e7eaf0;--dim:#a1a8b7;--cyan:#71d6e6;--green:#74d99f;--yellow:#f0cb72;--red:#ff7e86}
*{box-sizing:border-box}body{margin:0;background:#090b0f;color:var(--text);font:15px/1.35 ui-monospace,SFMono-Regular,Consolas,monospace}.note{max-width:1120px;margin:18px auto 8px;color:#adb5c5}.terminal{width:min(1120px,calc(100vw - 32px));min-height:650px;margin:0 auto 100px;background:var(--bg);border:1px solid #343a46;box-shadow:0 20px 60px #000;border-radius:8px;overflow:hidden}.header{height:42px;padding:10px 16px;text-align:center;font-weight:800;background:#272c37}.auth{padding:8px 14px}.grid{display:grid;grid-template-columns:3fr 2fr;gap:8px;padding:8px}.box{border:1px solid var(--line);padding:10px 13px;background:var(--panel);min-height:170px}.headline{grid-column:1/-1;min-height:145px}.title{color:var(--dim);margin:-20px 0 8px 3px;background:var(--panel);width:max-content;padding:0 6px}.big{font-size:20px;font-weight:800}.cyan{color:var(--cyan)}.green{color:var(--green)}.yellow{color:var(--yellow)}.red{color:var(--red)}.dim{color:var(--dim)}.service{margin:0 8px 8px;border:1px solid var(--line);padding:8px 12px;background:var(--panel)}.row{display:flex;justify-content:space-between;gap:18px;align-items:center;flex-wrap:wrap}.quit{font-weight:900}.paused{display:none}.terminal[data-state=paused] .paused{display:block}.terminal[data-state=paused] .active-only{display:none}.switcher{position:fixed;z-index:9;bottom:18px;left:50%;transform:translateX(-50%);display:flex;gap:8px;align-items:center;background:#f4f6fa;color:#15171b;padding:8px 10px;border-radius:999px;box-shadow:0 5px 24px #000}.switcher button{border:0;border-radius:999px;padding:8px 13px;font:700 13px ui-monospace,monospace;cursor:pointer}.switcher .active{background:#212631;color:white}.switcher select{font:700 13px ui-monospace,monospace;padding:7px;border-radius:6px}.variant{display:none}.variant.active{display:block}
/* A: quiet information hierarchy */
#a .auth{background:#17232a;color:#b8dce4;border-bottom:1px solid #31505b}#a .paused{margin:0 8px;padding:11px 14px;background:#392d15;border:2px solid var(--yellow);color:#ffe4a1;font-weight:800}#a .persist{color:var(--green)}#a .quit{background:#e9edf5;color:#111;padding:4px 10px;border-radius:3px}
/* B: explicit labelled rails */
#b .header{text-align:left;border-bottom:3px solid var(--cyan)}#b .auth{margin:8px;border-left:6px solid var(--cyan);background:#19242b}#b .paused{margin:8px;border-left:8px solid var(--yellow);background:#352b18;padding:10px 14px}.rail{display:grid;grid-template-columns:145px 1fr;gap:7px}.rail b{color:var(--dim)}#b .service{border-width:2px}.actionbar{border-top:1px dashed var(--line);margin-top:8px;padding-top:8px}#b .quit{color:#fff;border:2px solid #fff;padding:3px 9px}
/* C: strongest state separation */
#c .header{background:#e8ecf3;color:#111;font-size:16px}#c .auth{text-align:center;background:#22283a;color:#ceddff}#c .paused{margin:0;background:var(--yellow);color:#17130a;padding:12px 18px;font-size:17px;font-weight:900;text-align:center}#c .service{padding:0;border:0;background:transparent;display:grid;grid-template-columns:1fr auto}.statusblock{border:1px solid var(--line);padding:9px 13px;background:var(--panel)}#c .persist{font-weight:900;color:var(--green)}#c .actions{background:#272d39;padding:10px 13px;display:flex;align-items:center}#c .quit{background:var(--red);color:#190608;padding:6px 12px;border-radius:4px}
</style>
</head>
<body>
<p class="note"><b>PROTOTYPE:</b> same Panes dashboard, three treatments. Switch variant/state below. Nothing here ships.</p>
<main id="a" class="terminal variant" data-state="active">
<div class="header">Fenris — NVMe endurance monitor</div>
<div class="auth">ⓘ Privileged actions will prompt for authentication.</div>
<div class="paused">⏸ MONITORING PAUSED · Deliberate disable · paused time excluded from observed usage habit</div>
<div class="grid"><section class="box headline"><div class="title">headline</div><div class="big">Usage-adjusted theoretical lifespan: <span class="cyan">8 yr 103 d remaining</span></div><p>if current habits continue · sustained regime: 46 days</p><b>Projection confidence: <span class="green">Supported</span></b><p class="dim">46 complete days · 98% coverage · stable write rate</p></section><section class="box"><div class="title">usage history</div><b>Usage history · 46 days · 8.1–14.7 GB/day</b><p class="cyan">▂▃▃▄▅▄▃▃▄▅▆▅▄▃▃▂▃▄▅▄</p><p>active 42% · idle 31% · powered off 27%</p></section><section class="box"><div class="title">drive</div><b>Drive health · Samsung SSD 990 PRO</b><p>temperature 41°C · spare 100%<br>media errors 0 · unsafe shutdowns 2</p><b>Settings</b><p>vendor wear: 3% used · 18.4 TB written</p></section></div>
<div class="service"><div>boot: enabled · timer: active · last collect: ok · freshness: fresh</div><div class="row"><span class="persist active-only">monitoring: active in background · persists across reboots</span><span class="paused">monitoring: paused by Deliberate disable</span><span>Bongbetic · p pause · r resume · c collect · d disclosures · <span class="quit">q QUIT TUI</span></span></div></div>
</main>
<main id="b" class="terminal variant" data-state="active">
<div class="header">FENRIS <span class="dim">— NVMe endurance monitor</span></div>
<div class="auth"><b>AUTHENTICATION</b> · Privileged actions will prompt when used (polkit).</div>
<div class="paused"><b>MONITORING PAUSED</b><br>Deliberate disable closed monitoring period; paused time is excluded from observed usage habit.</div>
<div class="grid"><section class="box headline"><div class="title">headline</div><div class="big">Usage-adjusted theoretical lifespan: <span class="cyan">8 yr 103 d remaining</span></div><p>if current habits continue · sustained regime: 46 days</p><div class="rail"><b>CONFIDENCE</b><span class="green">SUPPORTED</span><b>EVIDENCE</b><span>46 complete days · 98% coverage · stable write rate</span></div></section><section class="box"><div class="title">usage history</div><b>46 days · 8.1–14.7 GB/day</b><p class="cyan">▂▃▃▄▅▄▃▃▄▅▆▅▄▃▃▂▃▄▅▄</p><p>active 42%<br>idle 31%<br>powered off 27%</p></section><section class="box"><div class="title">drive</div><b>Samsung SSD 990 PRO</b><p>41°C · spare 100% · errors 0<br>18.4 TB written · wear 3%</p></section></div>
<div class="service"><div class="rail"><b>SERVICE</b><span>boot enabled · timer active · last collect ok · fresh</span><b>CONTINUITY</b><span class="persist active-only">monitoring active in background · persists across reboots</span><span class="paused">monitoring paused by Deliberate disable</span><b>BY</b><span>Bongbetic</span></div><div class="actionbar">p pause · r resume · c collect now · d disclosures <span style="float:right" class="quit">q · QUIT TUI</span></div></div>
</main>
<main id="c" class="terminal variant" data-state="active">
<div class="header">Fenris — NVMe endurance monitor</div>
<div class="auth">Privileged actions → authentication prompt</div>
<div class="paused">⏸ MONITORING PAUSED — DELIBERATE DISABLE</div>
<div class="grid"><section class="box headline"><div class="title">headline</div><div class="big">Usage-adjusted theoretical lifespan<br><span class="cyan">8 yr 103 d remaining</span></div><p>if current habits continue</p><p><span class="green">● SUPPORTED</span> · 46 complete days · 98% coverage · stable write rate</p></section><section class="box"><div class="title">usage history</div><b>46 days · 8.1–14.7 GB/day</b><p class="cyan">▂▃▃▄▅▄▃▃▄▅▆▅▄▃▃▂▃▄▅▄</p><p>active 42% · idle 31%<br>powered off 27%</p></section><section class="box"><div class="title">drive</div><b>Samsung SSD 990 PRO</b><p>41°C · spare 100% · errors 0<br>18.4 TB written · wear 3%</p></section></div>
<div class="service"><div class="statusblock"><b class="active-only">● COLLECTION ACTIVE</b><b class="paused">■ COLLECTION PAUSED</b><br><span class="persist active-only">Runs in background · survives reboots</span><span class="paused">Deliberate disable · paused time excluded</span><br><span class="dim">boot enabled · timer active · last collect ok · fresh · Bongbetic</span></div><div class="actions">p pause · r resume · c collect · d disclosures &nbsp; <span class="quit">q QUIT TUI</span></div></div>
</main>
<nav class="switcher" aria-label="Prototype controls"><button id="prev">←</button><span id="label"></span><button id="next">→</button><select id="state"><option value="active">active</option><option value="paused">paused</option></select></nav>
<script>
const variants=[['a','A · Quiet integration'],['b','B · Labelled rails'],['c','C · Strong state blocks']];
const params=new URLSearchParams(location.search);let i=Math.max(0,variants.findIndex(v=>v[0]===(params.get('variant')||'a')));
function show(){document.querySelectorAll('.variant').forEach(x=>x.classList.remove('active'));const el=document.getElementById(variants[i][0]);el.classList.add('active');el.dataset.state=document.getElementById('state').value;document.getElementById('label').textContent=variants[i][1];params.set('variant',variants[i][0]);history.replaceState(null,'','?'+params)}
function cycle(n){i=(i+n+variants.length)%variants.length;show()}document.getElementById('prev').onclick=()=>cycle(-1);document.getElementById('next').onclick=()=>cycle(1);document.getElementById('state').onchange=show;addEventListener('keydown',e=>{if(e.key==='ArrowLeft')cycle(-1);if(e.key==='ArrowRight')cycle(1)});show();
</script>
</body></html>
+6
View File
@@ -0,0 +1,6 @@
#!/bin/sh
# PROTOTYPE: static local server; no dependencies or persistence.
set -eu
cd "$(git rev-parse --show-toplevel)"
printf '%s\n' 'Open http://127.0.0.1:8765/prototype/dashboard-clarity/?variant=a'
exec python3 -m http.server 8765 --bind 127.0.0.1
+1 -1
View File
@@ -1,6 +1,6 @@
[project]
name = "fenris"
version = "0.3.1"
version = "0.3.3"
description = "NVMe wear monitor with persistent TUI"
requires-python = ">=3.9"
dependencies = [
+7 -1
View File
@@ -88,7 +88,13 @@ def open_store_readonly(store_path: Path) -> sqlite3.Connection:
Raises StoreFault if unreadable, NewerSchema if user_version > SCHEMA_VERSION.
"""
if not store_path.exists():
try:
exists = store_path.exists()
except OSError as e:
# A non-group user stat()ing a 2750 store directory gets
# PermissionError before any StoreFault can be raised (issue #54).
raise StoreFault("observation store not readable: %s" % e)
if not exists:
raise StoreFault("observation store not found at %s" % store_path)
try:
+28 -4
View File
@@ -15,9 +15,19 @@ from typing import Optional
SCHEMA_VERSION = 1
# Packaged default placement (spec §8.3). The config may override it, but a
# fresh install that sets only the device selector must collect cleanly.
DEFAULT_STORE_PATH = Path("/var/lib/fenris/observations.db")
def get_store_path(config: dict) -> Path:
"""Get the store path from config."""
return Path(config["store_path"])
"""Get the store path from config.
Falls back to the packaged default when the config does not pin one,
so a fresh install whose config holds only the device selector works
instead of crashing with KeyError 'store_path' (issue #53).
"""
return Path(config.get("store_path", DEFAULT_STORE_PATH))
def init_store(store_path: Path) -> sqlite3.Connection:
@@ -27,10 +37,24 @@ def init_store(store_path: Path) -> sqlite3.Connection:
Returns a connection to the store.
"""
conn = sqlite3.connect(str(store_path))
# Enable WAL mode for concurrent reads during writes
conn.execute("PRAGMA journal_mode=WAL")
# Group members (fenris group) read the live store read-only, but SQLite
# in WAL mode needs write access to the db and its -wal/-shm sidecars even
# for readers. Best effort: root-created stores stay group-accessible
# without relying on the creating process's umask (issue #54).
import os as _os
for sidecar in (store_path,
store_path.with_name(store_path.name + "-wal"),
store_path.with_name(store_path.name + "-shm")):
try:
mode = _os.stat(sidecar).st_mode & 0o777
_os.chmod(sidecar, mode | 0o060)
except OSError:
pass
# Check if this is a new database
cursor = conn.execute("PRAGMA user_version")
current_version = cursor.fetchone()[0]
+56
View File
@@ -0,0 +1,56 @@
"""Store path resolution from config — regression coverage for issue #53.
A fresh install ships a placeholder-commented config whose only required
key is the device selector. The collector must not crash with
KeyError 'store_path' when the key is absent.
"""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
from fenris.store import DEFAULT_STORE_PATH, get_store_path
REPO_ROOT = Path(__file__).resolve().parent.parent
TEMPLATE = REPO_ROOT / "packaging" / "fenris.conf"
def _parse_like_load_config(text: str) -> dict:
"""Mirror collect.load_config()'s key=value parsing rules."""
config = {}
for line in text.splitlines():
line = line.strip()
if not line or line.startswith("#"):
continue
if "=" in line:
key, value = line.split("=", 1)
config[key.strip()] = value.strip()
return config
def test_missing_store_path_falls_back_to_default():
"""Config with only the device selector resolves to the packaged default."""
assert get_store_path({"device": "/dev/nvme0n1"}) == DEFAULT_STORE_PATH
def test_explicit_store_path_wins():
"""An explicit store_path override is honored."""
assert get_store_path({"store_path": "/tmp/other.db"}) == Path("/tmp/other.db")
def test_packaged_template_yields_collectable_config():
"""The packaged template, once a device is set, must be collector-ready.
Reproduces the fresh-install path: parse packaging/fenris.conf the way
collect.load_config() does, add the device selector, then resolve the
store. Issue #53 made this raise KeyError.
"""
config = _parse_like_load_config(TEMPLATE.read_text())
config["device"] = "/dev/nvme0n1"
assert get_store_path(config) == DEFAULT_STORE_PATH
def test_template_documents_store_path():
"""The template must mention store_path so admins know it is overridable."""
assert "store_path" in TEMPLATE.read_text()
+79
View File
@@ -0,0 +1,79 @@
"""Group access to the observation store — regression coverage for issue #54.
Two defects: (1) a non-group user's stat() on the store directory raised
PermissionError straight through open_store_readonly(), crashing status/TUI
instead of degrading to the Store fault view; (2) even group members could
not open the WAL-mode store because root-created sidecars lacked group write
and the store directory lacked group execute-then-write.
"""
import sqlite3
import sys
from pathlib import Path
import pytest
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
from fenris.store import DEFAULT_STORE_PATH, init_store
from fenris.status import StoreFault, open_store_readonly
def test_stat_permission_error_becomes_store_fault(monkeypatch, tmp_path):
"""stat() denied (non-group user on a 2750 dir) → StoreFault, not crash."""
store = tmp_path / "observations.db"
store.write_bytes(b"")
import pathlib
def denied(self, follow_symlinks=True):
raise PermissionError(13, "Permission denied")
monkeypatch.setattr(pathlib.Path, "exists", denied)
with pytest.raises(StoreFault):
open_store_readonly(store)
def test_connect_failure_becomes_store_fault(tmp_path):
"""sqlite failures stay wrapped as StoreFault (existing contract)."""
garbage = tmp_path / "observations.db"
garbage.write_bytes(b"not a database" * 100)
with pytest.raises(StoreFault):
open_store_readonly(garbage)
def test_init_store_leaves_files_group_writable(tmp_path):
"""Root-created stores must stay readable by WAL readers: db and sidecars
need group write after init_store (issue #54)."""
store = tmp_path / "observations.db"
conn = init_store(store)
try:
assert (store.stat().st_mode & 0o060) == 0o060, "db not group rw"
wal = store.with_name(store.name + "-wal")
shm = store.with_name(store.name + "-shm")
if wal.exists():
assert (wal.stat().st_mode & 0o060) == 0o060, "wal not group rw"
if shm.exists():
assert (shm.stat().st_mode & 0o060) == 0o060, "shm not group rw"
finally:
conn.close()
def test_readonly_open_works_after_init_store(tmp_path):
"""The shipped read path opens a store created by init_store."""
store = tmp_path / "observations.db"
writer = init_store(store)
writer.execute("INSERT INTO monitoring_periods (started_at) VALUES ('2026-01-01T00:00:00+00:00')")
writer.commit()
conn = open_store_readonly(store)
assert conn is not None
conn.close()
writer.close()
def test_packaging_ships_group_access():
"""tmpfiles must create the store dir group-writable; collect unit must
keep the umask loose so root-created sidecars stay group-accessible."""
repo = Path(__file__).resolve().parent.parent
assert "2770" in (repo / "packaging" / "tmpfiles.d" / "fenris.conf").read_text()
assert "2750" not in (repo / "packaging" / "tmpfiles.d" / "fenris.conf").read_text()
assert "UMask=002" in (repo / "units" / "fenris-collect.service").read_text()
+1
View File
@@ -7,3 +7,4 @@ After=local-fs.target
Type=oneshot
ExecStart=/usr/libexec/fenris/fenris-collect
TimeoutStartSec=90
UMask=002