feat: rename to BitGate and close the drop-in gap

Renames the project and makes it as easy to adopt as BitLogin, which was the
stated bar and which it did not previously meet.

Rename (ADR 0005): @nostr-governance/* -> @bitgate/*, governance-* elements ->
bitgate-*, createGovernanceRuntime -> createBitGate. "Governance" reads as DAO
voting to this audience and named a category rather than a product; BitGate
names the benefit and joins the bit- family that BitVid and BitRoad compose
with. Domain types keep their names — the product is BitGate, the subject
matter is still governance. The migration plan is left as written; this ADR
records the change rather than rewriting history.

Drop-in distribution (ADR 0006): adopting BitGate meant supplying a transport,
authoring a policy, and wiring every element in JavaScript. Now:

- createRelayTransport(urls) — WebSocket transport with reconnection, backoff,
  subscription replay, and cross-relay dedupe
- policy presets (social, commerce, admin-only) addressable by name; the engine
  still carries no thresholds of its own
- <bitgate-provider> — configuration in markup, with descendants finding the
  runtime through a bubbling context event rather than DOM walking, which
  breaks across shadow boundaries
- npm run build:widget — a self-contained dist/bitgate.js

That last one came from running it in a browser rather than from a test. Bare
specifiers resolve in Node and vitest but not in a browser, so the widget
source worked everywhere except a plain static page — the one place it exists
to serve. The bundle is not committed: consumers build from reviewed source.

Also found by running it: the provider's ready event fires during element
upgrade, before a page that defines elements after parsing can attach a
listener, so it now exposes `ready` as a promise too.

Four bugs fixed along the way, three found by new tests and one by the browser:
admin state stayed silent when a roster change altered capabilities but no
denials; the relay transport sent every subscription twice on connect; the
commerce preset computed a meaningless visibility verdict at checkout and could
hide a listing from its own seller; <bitgate-status> threw on an unusable
decision.

759 tests; lint, typecheck, and both builds clean.
This commit is contained in:
thePR0M3TH3AN committed 2026-08-09 19:58:45 -04:00
1 parent 7f70a64d61
commit adeba151b8
63 files changed
+2774 -401

No files matched your search

+39 -39
View File
@@ -2,15 +2,15 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { createPolicyDefinition } from "@nostr-governance/core";
import { createPolicyDefinition } from "@bitgate/core";
import {
createCommands,
createGovernanceRuntime,
createBitGate,
createMemoryTransport,
} from "@nostr-governance/runtime";
} from "@bitgate/runtime";
import { CAPABILITY_LABELS } from "../src/admin.js";
import { defineGovernanceElements } from "../src/index.js";
import { defineBitGateElements } from "../src/index.js";
import { shortenKey } from "../src/base.js";
const ROOT = "a1".repeat(32);
@@ -26,10 +26,10 @@ const POLICY = createPolicyDefinition({
profiles: { feed: { name: "feed", reports: {}, mutes: {} } },
});
defineGovernanceElements();
defineBitGateElements();
function makeRuntime(viewer) {
const runtime = createGovernanceRuntime({
const runtime = createBitGate({
applicationId: "widget-test",
namespace: "widget",
transport: createMemoryTransport(),
@@ -71,21 +71,21 @@ beforeEach(() => {
document.body.innerHTML = "";
});
describe("<governance-capabilities>", () => {
describe("<bitgate-capabilities>", () => {
it("says when nobody is signed in", () => {
const panel = mount("governance-capabilities", makeRuntime());
const panel = mount("bitgate-capabilities", makeRuntime());
expect(panel.shadowRoot.textContent).toContain("Not signed in");
});
it("lists what a moderator holds", () => {
const panel = mount("governance-capabilities", makeRuntime(MODERATOR));
const panel = mount("bitgate-capabilities", makeRuntime(MODERATOR));
const text = panel.shadowRoot.textContent;
expect(text).toContain(CAPABILITY_LABELS["contribute-user-deny"]);
expect(text).toContain(shortenKey(MODERATOR));
});
it("shows capabilities an actor lacks rather than omitting them", () => {
const panel = mount("governance-capabilities", makeRuntime(CURATOR));
const panel = mount("bitgate-capabilities", makeRuntime(CURATOR));
// A curator holds only contribute-user-deny, but every capability is
// listed so the boundary is legible.
for (const label of Object.values(CAPABILITY_LABELS)) {
@@ -94,7 +94,7 @@ describe("<governance-capabilities>", () => {
});
it("marks held capabilities distinctly from unheld ones", () => {
const panel = mount("governance-capabilities", makeRuntime(CURATOR));
const panel = mount("bitgate-capabilities", makeRuntime(CURATOR));
const items = [...panel.shadowRoot.querySelectorAll("li")];
const held = items.filter((item) => item.textContent.includes("✓"));
expect(held).toHaveLength(1);
@@ -102,12 +102,12 @@ describe("<governance-capabilities>", () => {
});
it("tells an account with no authority that it has none", () => {
const panel = mount("governance-capabilities", makeRuntime(STRANGER));
const panel = mount("bitgate-capabilities", makeRuntime(STRANGER));
expect(panel.shadowRoot.textContent).toContain("no governance capabilities");
});
it("grants the root everything", () => {
const panel = mount("governance-capabilities", makeRuntime(ROOT));
const panel = mount("bitgate-capabilities", makeRuntime(ROOT));
const held = [...panel.shadowRoot.querySelectorAll("li")].filter((item) =>
item.textContent.includes("✓"),
);
@@ -115,9 +115,9 @@ describe("<governance-capabilities>", () => {
});
});
describe("<governance-action>", () => {
describe("<bitgate-action>", () => {
it("enables the control when the actor holds the capability", () => {
const action = mount("governance-action", makeRuntime(MODERATOR), {
const action = mount("bitgate-action", makeRuntime(MODERATOR), {
capability: "contribute-user-deny",
label: "Restrict",
});
@@ -125,7 +125,7 @@ describe("<governance-action>", () => {
});
it("disables it and explains why when they do not", () => {
const action = mount("governance-action", makeRuntime(CURATOR), {
const action = mount("bitgate-action", makeRuntime(CURATOR), {
capability: "contribute-event-deny",
label: "Restrict post",
});
@@ -136,7 +136,7 @@ describe("<governance-action>", () => {
});
it("keeps the control visible rather than hiding it", () => {
const action = mount("governance-action", makeRuntime(CURATOR), {
const action = mount("bitgate-action", makeRuntime(CURATOR), {
capability: "manage-roles",
label: "Edit roles",
});
@@ -145,14 +145,14 @@ describe("<governance-action>", () => {
});
it("runs the action and announces completion", async () => {
const action = mount("governance-action", makeRuntime(MODERATOR), {
const action = mount("bitgate-action", makeRuntime(MODERATOR), {
capability: "contribute-user-deny",
label: "Restrict",
});
action.action = vi.fn().mockResolvedValue({ ok: true });
const completed = vi.fn();
action.addEventListener("governance:action-completed", completed);
action.addEventListener("bitgate:action-completed", completed);
action.shadowRoot.querySelector("#run").click();
await action.pending;
expect(completed).toHaveBeenCalled();
@@ -161,14 +161,14 @@ describe("<governance-action>", () => {
});
it("reports a refusal with its stable code", async () => {
const action = mount("governance-action", makeRuntime(MODERATOR), {
const action = mount("bitgate-action", makeRuntime(MODERATOR), {
capability: "contribute-user-deny",
label: "Restrict",
});
action.action = vi.fn().mockResolvedValue({ ok: false, code: "protected-target" });
const refused = vi.fn();
action.addEventListener("governance:action-refused", refused);
action.addEventListener("bitgate:action-refused", refused);
action.shadowRoot.querySelector("#run").click();
await action.pending;
expect(refused).toHaveBeenCalled();
@@ -177,13 +177,13 @@ describe("<governance-action>", () => {
});
it("reports a thrown failure without breaking the element", async () => {
const action = mount("governance-action", makeRuntime(MODERATOR), {
const action = mount("bitgate-action", makeRuntime(MODERATOR), {
capability: "contribute-user-deny",
});
action.action = vi.fn().mockRejectedValue(new Error("relay down"));
const failed = vi.fn();
action.addEventListener("governance:action-failed", failed);
action.addEventListener("bitgate:action-failed", failed);
action.shadowRoot.querySelector("#run").click();
await action.pending;
expect(failed).toHaveBeenCalled();
@@ -193,7 +193,7 @@ describe("<governance-action>", () => {
it("re-evaluates permission when the roster changes", () => {
const runtime = makeRuntime(MODERATOR);
const action = mount("governance-action", runtime, {
const action = mount("bitgate-action", runtime, {
capability: "contribute-user-deny",
});
expect(action.shadowRoot.querySelector("#run").disabled).toBe(false);
@@ -203,7 +203,7 @@ describe("<governance-action>", () => {
});
});
describe("<governance-admin-panel>", () => {
describe("<bitgate-admin-panel>", () => {
/**
* @param {any} runtime
* @param {Object} [options]
@@ -220,13 +220,13 @@ describe("<governance-admin-panel>", () => {
}
it("reports when no runtime is attached", () => {
const panel = /** @type {any} */ (document.createElement("governance-admin-panel"));
const panel = /** @type {any} */ (document.createElement("bitgate-admin-panel"));
document.body.append(panel);
expect(panel.shadowRoot.textContent).toContain("No runtime attached");
});
it("shows the roster summary", () => {
const panel = mount("governance-admin-panel", makeRuntime(MODERATOR));
const panel = mount("bitgate-admin-panel", makeRuntime(MODERATOR));
expect(panel.shadowRoot.textContent).toContain(shortenKey(ROOT));
expect(panel.shadowRoot.textContent).toContain("actor(s)");
});
@@ -234,27 +234,27 @@ describe("<governance-admin-panel>", () => {
it("lists restricted accounts", () => {
const runtime = makeRuntime(MODERATOR);
denyCreator(runtime);
const panel = mount("governance-admin-panel", runtime);
const panel = mount("bitgate-admin-panel", runtime);
expect(panel.shadowRoot.textContent).toContain(shortenKey(CREATOR));
});
it("distinguishes a community list from a moderator action", () => {
const runtime = makeRuntime(MODERATOR);
denyCreator(runtime, { source: "curated-list" });
const panel = mount("governance-admin-panel", runtime);
const panel = mount("bitgate-admin-panel", runtime);
expect(panel.shadowRoot.textContent).toContain("community list");
});
it("attributes a direct action to a moderator", () => {
const runtime = makeRuntime(MODERATOR);
denyCreator(runtime);
const panel = mount("governance-admin-panel", runtime);
const panel = mount("bitgate-admin-panel", runtime);
expect(panel.shadowRoot.textContent).toContain("moderator");
expect(panel.shadowRoot.textContent).not.toContain("community list");
});
it("disables restriction for an actor without the capability", () => {
const panel = mount("governance-admin-panel", makeRuntime(STRANGER));
const panel = mount("bitgate-admin-panel", makeRuntime(STRANGER));
expect(panel.shadowRoot.querySelector("#deny").disabled).toBe(true);
expect(panel.shadowRoot.textContent).toContain("Requires permission");
});
@@ -264,12 +264,12 @@ describe("<governance-admin-panel>", () => {
const commands = createCommands(runtime);
vi.spyOn(commands, "denyUser").mockResolvedValue({ ok: true });
const panel = mount("governance-admin-panel", runtime);
const panel = mount("bitgate-admin-panel", runtime);
panel.commands = commands;
panel.shadowRoot.querySelector("#pubkey").value = CREATOR;
const restricted = vi.fn();
panel.addEventListener("governance:account-restricted", restricted);
panel.addEventListener("bitgate:account-restricted", restricted);
panel.shadowRoot.querySelector("#deny").click();
await panel.pending;
expect(restricted).toHaveBeenCalled();
@@ -282,12 +282,12 @@ describe("<governance-admin-panel>", () => {
const commands = createCommands(runtime);
vi.spyOn(commands, "denyUser").mockResolvedValue({ ok: false, code: "protected-target" });
const panel = mount("governance-admin-panel", runtime);
const panel = mount("bitgate-admin-panel", runtime);
panel.commands = commands;
panel.shadowRoot.querySelector("#pubkey").value = ROOT;
const refused = vi.fn();
panel.addEventListener("governance:action-refused", refused);
panel.addEventListener("bitgate:action-refused", refused);
panel.shadowRoot.querySelector("#deny").click();
await panel.pending;
expect(refused).toHaveBeenCalled();
@@ -298,13 +298,13 @@ describe("<governance-admin-panel>", () => {
it("warns when serving cached state", () => {
const runtime = makeRuntime(MODERATOR);
runtime.stale = true;
const panel = mount("governance-admin-panel", runtime);
const panel = mount("bitgate-admin-panel", runtime);
expect(panel.shadowRoot.textContent).toContain("relays unreachable");
});
it("updates when administrative state changes", () => {
const runtime = makeRuntime(MODERATOR);
const panel = mount("governance-admin-panel", runtime);
const panel = mount("bitgate-admin-panel", runtime);
expect(panel.shadowRoot.textContent).toContain("Restricted accounts (0)");
denyCreator(runtime);
@@ -315,7 +315,7 @@ describe("<governance-admin-panel>", () => {
describe("element registration", () => {
it("is idempotent", () => {
// Elements were registered at module load; a second call must not throw.
expect(() => defineGovernanceElements()).not.toThrow();
expect(defineGovernanceElements()).toEqual([]);
expect(() => defineBitGateElements()).not.toThrow();
expect(defineBitGateElements()).toEqual([]);
});
});
+275
View File
@@ -0,0 +1,275 @@
// @vitest-environment happy-dom
//
// The drop-in path: configuration in markup, descendants finding the runtime
// themselves, and targets read from attributes.
import { beforeEach, describe, expect, it, vi } from "vitest";
import { defineBitGateElements } from "../src/index.js";
import { targetFromAttributes } from "../src/base.js";
const ROOT = "a1".repeat(32);
const CREATOR = "d4".repeat(32);
const EVENT_ID = "1b".repeat(32);
defineBitGateElements();
/** Sockets opened during a test, so nothing tries to reach a real relay. */
let sockets = [];
class FakeSocket {
constructor(url) {
this.url = url;
this.sent = [];
this.onopen = null;
this.onmessage = null;
this.onclose = null;
this.onerror = null;
sockets.push(this);
// Open on a microtask so listeners are attached first.
queueMicrotask(() => this.onopen?.());
}
send(payload) {
const frame = JSON.parse(payload);
this.sent.push(frame);
// Answer every REQ immediately so loadAdministrativeState resolves.
if (frame[0] === "REQ") {
queueMicrotask(() => this.onmessage?.({ data: JSON.stringify(["EOSE", frame[1]]) }));
}
}
close() {}
}
/**
* Mount a provider and wait for it to finish loading.
* @param {Record<string, string|null>} [attributes]
* @param {string} [children]
* @returns {Promise<any>}
*/
async function mountProvider(attributes = {}, children = "") {
const provider = /** @type {any} */ (document.createElement("bitgate-provider"));
for (const [name, value] of Object.entries({
relays: "wss://relay.example",
root: ROOT,
policy: "social",
...attributes,
})) {
if (value !== null) {
provider.setAttribute(name, value);
}
}
provider.innerHTML = children;
const loaded = new Promise((resolve) => {
provider.addEventListener("bitgate:loaded", resolve, { once: true });
provider.addEventListener("bitgate:error", resolve, { once: true });
});
document.body.append(provider);
await loaded;
return provider;
}
beforeEach(() => {
document.body.innerHTML = "";
sockets = [];
globalThis.WebSocket = /** @type {any} */ (FakeSocket);
globalThis.localStorage?.clear?.();
});
describe("targetFromAttributes", () => {
const parse = (attributes) => {
const element = document.createElement("div");
for (const [name, value] of Object.entries(attributes)) {
element.setAttribute(name, value);
}
return targetFromAttributes(element);
};
it("reads a user target", () => {
expect(parse({ "target-user": CREATOR })).toEqual({ type: "user", pubkey: CREATOR });
});
it("reads an event target with author and kind", () => {
expect(parse({ "target-event": EVENT_ID, "target-author": CREATOR, "target-kind": "1" })).toEqual({
type: "event",
id: EVENT_ID,
author: CREATOR,
kind: 1,
});
});
it("reads an address coordinate", () => {
expect(parse({ "target-address": `30078:${CREATOR}:sku-001` })).toEqual({
type: "address",
kind: "30078",
pubkey: CREATOR,
identifier: "sku-001",
});
});
it("keeps colons inside the d-tag", () => {
const target = parse({ "target-address": `30078:${CREATOR}:shop:sku:1` });
expect(target?.type === "address" && target.identifier).toBe("shop:sku:1");
});
it("returns null when no target attribute is present", () => {
expect(parse({})).toBeNull();
});
it("returns null for a malformed coordinate", () => {
expect(parse({ "target-address": "garbage" })).toBeNull();
});
});
describe("<bitgate-provider>", () => {
it("builds a runtime from attributes alone", async () => {
const provider = await mountProvider();
expect(provider.runtime).toBeTruthy();
expect(provider.commands).toBeTruthy();
expect(provider.runtime.admin.authority.root).toBe(ROOT);
});
it("uses the named policy preset", async () => {
const provider = await mountProvider({ policy: "commerce" });
expect(provider.runtime.policies.policy.id).toBe("bitgate-commerce");
});
it("defaults to administrative-only governance", async () => {
const provider = await mountProvider({ policy: null });
expect(provider.runtime.policies.policy.id).toBe("bitgate-admin-only");
});
it("opens a socket per relay", async () => {
await mountProvider({ relays: "wss://one.example, wss://two.example" });
expect(sockets.map((socket) => socket.url)).toEqual(["wss://one.example", "wss://two.example"]);
});
it("sets the viewer when given one", async () => {
const provider = await mountProvider({ viewer: CREATOR });
expect(provider.runtime.viewerPubkey).toBe(CREATOR);
});
it("reports an unknown policy without throwing", async () => {
const provider = await mountProvider({ policy: "invented" });
expect(provider.runtime).toBeNull();
expect(provider.getAttribute("data-error")).toMatch(/Unknown policy preset/);
});
it("reports a missing relays attribute", async () => {
const provider = await mountProvider({ relays: null });
expect(provider.getAttribute("data-error")).toMatch(/relays attribute/);
});
it("announces readiness before administrative state finishes loading", async () => {
const provider = /** @type {any} */ (document.createElement("bitgate-provider"));
provider.setAttribute("relays", "wss://relay.example");
provider.setAttribute("policy", "social");
const ready = vi.fn();
provider.addEventListener("bitgate:ready", ready);
document.body.append(provider);
await new Promise((resolve) => provider.addEventListener("bitgate:loaded", resolve, { once: true }));
expect(ready).toHaveBeenCalled();
});
it("tears the runtime down when removed", async () => {
const provider = await mountProvider();
const runtime = provider.runtime;
provider.remove();
expect(provider.runtime).toBeNull();
expect(runtime.destroyed).toBe(true);
});
it("accepts a signer and adopts its pubkey as the viewer", async () => {
const provider = await mountProvider();
const signer = {
async getPublicKey() {
return CREATOR;
},
async signEvent(template) {
return { ...template, id: "ff".repeat(32), pubkey: CREATOR, sig: "00".repeat(64) };
},
};
const pubkey = await provider.useSigner(signer);
expect(pubkey).toBe(CREATOR);
expect(provider.runtime.viewerPubkey).toBe(CREATOR);
expect(provider.runtime.signer).toBe(signer);
});
it("refuses a signer before it is ready", async () => {
const provider = /** @type {any} */ (document.createElement("bitgate-provider"));
await expect(provider.useSigner(/** @type {any} */ ({}))).rejects.toThrow(/not ready/);
});
});
describe("context discovery", () => {
it("gives a descendant the runtime without any JavaScript", async () => {
const provider = await mountProvider(
{},
`<bitgate-veil profile="feed" target-user="${CREATOR}"><p>content</p></bitgate-veil>`,
);
const veil = /** @type {any} */ (provider.querySelector("bitgate-veil"));
expect(veil.runtime).toBe(provider.runtime);
});
it("hands commands to elements that publish", async () => {
const provider = await mountProvider(
{},
`<bitgate-report target-user="${CREATOR}"></bitgate-report>`,
);
const report = /** @type {any} */ (provider.querySelector("bitgate-report"));
expect(report.commands).toBe(provider.commands);
});
it("renders a decision from markup alone", async () => {
const provider = await mountProvider(
{ policy: "admin-only" },
`<bitgate-veil target-user="${CREATOR}"><p>content</p></bitgate-veil>`,
);
provider.runtime.admin.setRoles({ root: ROOT, actors: { [ROOT]: ["super_admin"] } });
provider.runtime.admin.upsertContribution({
actor: ROOT,
kind: "user-deny",
targets: [{ type: "user", pubkey: CREATOR }],
createdAt: 1,
});
const veil = /** @type {any} */ (provider.querySelector("bitgate-veil"));
expect(veil.shadowRoot.textContent).toContain("Content hidden");
});
it("lets a directly assigned runtime win over the provider's", async () => {
const provider = await mountProvider(
{},
`<bitgate-status target-user="${CREATOR}"></bitgate-status>`,
);
const status = /** @type {any} */ (provider.querySelector("bitgate-status"));
const other = { on: () => () => {}, evaluate: () => null };
status.runtime = /** @type {any} */ (other);
expect(status.runtime).toBe(other);
});
it("leaves an element outside any provider unconfigured", () => {
const veil = /** @type {any} */ (document.createElement("bitgate-veil"));
document.body.append(veil);
expect(veil.runtime).toBeNull();
});
it("adopts a provider that becomes ready later", async () => {
// An element parsed before its provider finishes starting must still end up
// configured, or markup order would silently decide whether it works.
const veil = /** @type {any} */ (document.createElement("bitgate-veil"));
veil.setAttribute("target-user", CREATOR);
document.body.append(veil);
expect(veil.runtime).toBeNull();
const provider = await mountProvider();
expect(veil.runtime).toBe(provider.runtime);
});
});
+32 -32
View File
@@ -2,15 +2,15 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { createPolicyDefinition } from "@nostr-governance/core";
import { createPolicyDefinition } from "@bitgate/core";
import {
createCommands,
createGovernanceRuntime,
createBitGate,
createMemoryTransport,
} from "@nostr-governance/runtime";
} from "@bitgate/runtime";
import { DEFAULT_REASON_TEXT, describeReasons } from "../src/viewer.js";
import { defineGovernanceElements } from "../src/index.js";
import { defineBitGateElements } from "../src/index.js";
import { escapeHtml, shortenKey } from "../src/base.js";
const ROOT = "a1".repeat(32);
@@ -48,10 +48,10 @@ const POLICY = createPolicyDefinition({
},
});
defineGovernanceElements();
defineBitGateElements();
function makeRuntime() {
const runtime = createGovernanceRuntime({
const runtime = createBitGate({
applicationId: "widget-test",
namespace: "widget",
transport: createMemoryTransport(),
@@ -140,10 +140,10 @@ describe("describeReasons", () => {
});
});
describe("<governance-veil>", () => {
describe("<bitgate-veil>", () => {
it("renders content untouched when nothing objects", () => {
const runtime = makeRuntime();
const veil = mount("governance-veil", {
const veil = mount("bitgate-veil", {
runtime,
target: { type: "user", pubkey: CREATOR },
});
@@ -154,7 +154,7 @@ describe("<governance-veil>", () => {
it("hides content behind a disclosure when the decision hides", () => {
const runtime = makeRuntime();
denyCreator(runtime);
const veil = mount("governance-veil", {
const veil = mount("bitgate-veil", {
runtime,
target: { type: "user", pubkey: CREATOR },
profile: "feed",
@@ -167,7 +167,7 @@ describe("<governance-veil>", () => {
it("explains why rather than vanishing silently", () => {
const runtime = makeRuntime();
denyCreator(runtime);
const veil = mount("governance-veil", {
const veil = mount("bitgate-veil", {
runtime,
target: { type: "user", pubkey: CREATOR },
profile: "feed",
@@ -178,7 +178,7 @@ describe("<governance-veil>", () => {
it("keeps hidden content out of the accessibility tree", () => {
const runtime = makeRuntime();
denyCreator(runtime);
const veil = mount("governance-veil", {
const veil = mount("bitgate-veil", {
runtime,
target: { type: "user", pubkey: CREATOR },
profile: "feed",
@@ -191,14 +191,14 @@ describe("<governance-veil>", () => {
it("reveals on request and announces it", () => {
const runtime = makeRuntime();
denyCreator(runtime);
const veil = mount("governance-veil", {
const veil = mount("bitgate-veil", {
runtime,
target: { type: "user", pubkey: CREATOR },
profile: "feed",
});
const revealed = vi.fn();
veil.addEventListener("governance:revealed", revealed);
veil.addEventListener("bitgate:revealed", revealed);
veil.shadowRoot.querySelector("#reveal").click();
expect(revealed).toHaveBeenCalled();
@@ -208,7 +208,7 @@ describe("<governance-veil>", () => {
it("offers no reveal when the profile forbids overrides", () => {
const runtime = makeRuntime();
denyCreator(runtime);
const veil = mount("governance-veil", {
const veil = mount("bitgate-veil", {
runtime,
target: { type: "user", pubkey: CREATOR },
profile: "locked",
@@ -224,7 +224,7 @@ describe("<governance-veil>", () => {
{ reporter: TRUSTED, category: "spam", createdAt: NOW },
`user:${CREATOR}`,
);
const veil = mount("governance-veil", {
const veil = mount("bitgate-veil", {
runtime,
target: { type: "user", pubkey: CREATOR },
profile: "detail",
@@ -236,7 +236,7 @@ describe("<governance-veil>", () => {
it("re-renders when governance state changes", () => {
const runtime = makeRuntime();
const veil = mount("governance-veil", {
const veil = mount("bitgate-veil", {
runtime,
target: { type: "user", pubkey: CREATOR },
profile: "feed",
@@ -249,7 +249,7 @@ describe("<governance-veil>", () => {
it("stops re-rendering once detached", () => {
const runtime = makeRuntime();
const veil = mount("governance-veil", {
const veil = mount("bitgate-veil", {
runtime,
target: { type: "user", pubkey: CREATOR },
profile: "feed",
@@ -261,27 +261,27 @@ describe("<governance-veil>", () => {
});
it("renders plainly without a runtime", () => {
const veil = mount("governance-veil", {});
const veil = mount("bitgate-veil", {});
expect(veil.shadowRoot.querySelector("slot")).not.toBeNull();
});
it("tolerates an invalid target instead of throwing", () => {
const runtime = makeRuntime();
const veil = mount("governance-veil", { runtime });
const veil = mount("bitgate-veil", { runtime });
expect(() => {
veil.target = { type: "user", pubkey: "not-a-key" };
}).not.toThrow();
});
});
describe("<governance-report>", () => {
describe("<bitgate-report>", () => {
it("disables submission with no target or commands", () => {
const report = mount("governance-report", { runtime: makeRuntime() });
const report = mount("bitgate-report", { runtime: makeRuntime() });
expect(report.shadowRoot.querySelector("#submit").disabled).toBe(true);
});
it("states plainly that reports are public", () => {
const report = mount("governance-report", { runtime: makeRuntime() });
const report = mount("bitgate-report", { runtime: makeRuntime() });
expect(report.shadowRoot.textContent).toContain("public");
});
@@ -290,12 +290,12 @@ describe("<governance-report>", () => {
const commands = createCommands(runtime);
vi.spyOn(commands, "report").mockResolvedValue({ ok: true, accepted: ["wss://a"] });
const report = mount("governance-report", { runtime });
const report = mount("bitgate-report", { runtime });
report.commands = commands;
report.target = { type: "event", id: EVENT_ID };
const reported = vi.fn();
report.addEventListener("governance:reported", reported);
report.addEventListener("bitgate:reported", reported);
report.shadowRoot.querySelector("#category").value = "spam";
report.shadowRoot.querySelector("form").dispatchEvent(new Event("submit"));
@@ -311,12 +311,12 @@ describe("<governance-report>", () => {
const commands = createCommands(runtime);
vi.spyOn(commands, "report").mockResolvedValue({ ok: false, code: "invalid-target" });
const report = mount("governance-report", { runtime });
const report = mount("bitgate-report", { runtime });
report.commands = commands;
report.target = { type: "event", id: EVENT_ID };
const failed = vi.fn();
report.addEventListener("governance:report-failed", failed);
report.addEventListener("bitgate:report-failed", failed);
report.shadowRoot.querySelector("form").dispatchEvent(new Event("submit"));
await report.pending;
expect(failed).toHaveBeenCalled();
@@ -325,11 +325,11 @@ describe("<governance-report>", () => {
});
});
describe("<governance-status>", () => {
describe("<bitgate-status>", () => {
it("reports the effect and reasons", () => {
const runtime = makeRuntime();
denyCreator(runtime);
const status = mount("governance-status", {
const status = mount("bitgate-status", {
runtime,
target: { type: "user", pubkey: CREATOR },
profile: "feed",
@@ -340,7 +340,7 @@ describe("<governance-status>", () => {
});
it("says so when there is nothing to report", () => {
const status = mount("governance-status", {
const status = mount("bitgate-status", {
runtime: makeRuntime(),
target: { type: "user", pubkey: CREATOR },
profile: "feed",
@@ -354,7 +354,7 @@ describe("<governance-status>", () => {
{ reporter: TRUSTED, category: "spam", createdAt: NOW },
`user:${CREATOR}`,
);
const status = mount("governance-status", {
const status = mount("bitgate-status", {
runtime,
target: { type: "user", pubkey: CREATOR },
profile: "feed",
@@ -370,7 +370,7 @@ describe("<governance-status>", () => {
{ reporter: TRUSTED, category: "spam", createdAt: NOW },
`user:${CREATOR}`,
);
const status = mount("governance-status", {
const status = mount("bitgate-status", {
runtime,
target: { type: "user", pubkey: CREATOR },
profile: "detail",
@@ -381,7 +381,7 @@ describe("<governance-status>", () => {
});
it("renders no status without a target", () => {
const status = mount("governance-status", { runtime: makeRuntime() });
const status = mount("bitgate-status", { runtime: makeRuntime() });
expect(status.shadowRoot.querySelector("[part='status']")).toBeNull();
});
});