Files
archie/ui/test/settings-readonly.test.js
T
sam 6f34e34adb feat(webui): render configuration from a published snapshot
The configuration page had exactly one source: this process's own
config.Holder. The UI process has no holder and is not permitted one, so the
page was empty there and the shared-holder assumption was the thing blocking
the cutover.

GET /api/config now reads a ConfigViewSource. The daemon builds the
projection from the configuration it owns, as before, and publishes that same
document to the State Store on boot and on every republish -- reload, a
dashboard edit, a repository field change -- since those are exactly the
moments it changes. The UI process renders what it reads there and nothing
else; an unknown schema is refused rather than half-rendered, and nothing
published yet is the documented empty response, not an error.

Editable is a property of the process, not of the configuration, so each
source sets it: the daemon holds the update path, the reader does not. The
settings page honours it, rendering values where it would otherwise offer
controls whose PATCH would answer 503 -- the deliberate feature reduction
archie-core-ymut recorded, made visible instead of discovered by clicking.

A failed publish is logged and degrades to a stale page. It must never fail
the reload or the edit that produced the configuration, both of which have
already taken effect.
2026-09-09 23:43:17 +10:00

29 lines
1.3 KiB
JavaScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { render, cleanup } from "@testing-library/preact";
import { RepositoriesCard } from "../src/settings/settings.jsx";
const repos = [
{ owner: "acme", name: "widget", base: "main", allow_concurrent: true, max_retries: 3, review_enabled: false },
];
// A process that renders a published configuration snapshot has no write
// path: its PATCH routes answer 503. Offering a checkbox that fails on click
// is worse than not offering one (archie-core-ymut).
test("read-only repositories render values, not controls", () => {
const { container, unmount } = render(<RepositoriesCard repos={repos} editable={false} />);
assert.equal(container.querySelectorAll("input").length, 0, "a read-only page must render no repository inputs");
const row = container.querySelector("tbody tr");
assert.match(row.textContent, /acme\/widget/);
assert.match(row.textContent, /3/, "the value itself is still shown");
unmount();
});
test("editable repositories keep their controls", () => {
const { container, unmount } = render(<RepositoriesCard repos={repos} editable={true} />);
assert.ok(container.querySelectorAll("input").length > 0, "the owning process still edits repository fields");
unmount();
});
test("cleanup", () => cleanup());