mirror of
https://github.com/PR0M3TH3AN/bitgate.git
synced 2026-11-04 04:21:00 +00:00
feat(runtime): close the wiring gaps between interfaces and pipelines
Several contracts existed and were tested in isolation while nothing actually used them. Reported as complete previously; this corrects that. - storage was injected and never referenced. Adds persist/hydrate, hydration before querying relays, and last-known-good state with a stale flag when a relay is unreachable, which is what makes the characterized cache-fallback behavior real rather than reduction-level only - signature verification existed as a tested helper the load path never called. Now applied through an injected verifier before state becomes authoritative, with rejection counts and an enabled/disabled readout in diagnostics - trusted mute lists had no subscription flow, so the store never populated in a real deployment. Subscribes by author, chunked - community source references decoded but were never resolved. Curator lists are now fetched and merged with a source marker, still capability-checked - root-published policy was announced and discarded. Now applied, accepted only from the root, and a malformed document leaves the working policy intact - adds import/export and capability queries Two design corrections found while wiring: - the cache key hashed the entire roster, so it rotated whenever a moderator was added and the cache was discarded. Now derived from root identity alone. - the root administrator is a constructor option: it is deployment config, and hydration could not otherwise find its own cache, since the key derives from the very fingerprint the cache would have supplied. 634 tests; lint, typecheck, and the declaration build clean.
This commit is contained in:
1 parent
c4477ae84b
commit
da2c1cd923
5 files changed
+888
-17
No files matched your search
@@ -169,17 +169,59 @@ describe("ingestEvent", () => {
|
||||
expect(runtime.mutes.toRecordMap().get(`user:${CREATOR}`)).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("emits a policy document rather than applying it blindly", () => {
|
||||
it("rejects a policy document from anyone but the root", () => {
|
||||
const { runtime } = makeRuntime();
|
||||
const handler = vi.fn();
|
||||
runtime.on("policy-document", handler);
|
||||
runtime.ingestEvent(rolesEvent());
|
||||
|
||||
const rejected = vi.fn();
|
||||
runtime.on("policy-rejected", rejected);
|
||||
runtime.ingestEvent(
|
||||
event({
|
||||
pubkey: MODERATOR,
|
||||
tags: [["d", canonicalIdentifier("app", "policy")]],
|
||||
content: JSON.stringify({ id: "x" }),
|
||||
content: JSON.stringify({ id: "x", version: "1", profiles: { f: { name: "f" } } }),
|
||||
}),
|
||||
);
|
||||
expect(handler).toHaveBeenCalled();
|
||||
|
||||
expect(rejected).toHaveBeenCalledWith(expect.objectContaining({ reason: "not-root" }));
|
||||
expect(runtime.policies.rootPolicy).toBeNull();
|
||||
});
|
||||
|
||||
it("applies a root-published policy", () => {
|
||||
const { runtime } = makeRuntime();
|
||||
runtime.ingestEvent(rolesEvent());
|
||||
|
||||
runtime.ingestEvent(
|
||||
event({
|
||||
pubkey: ROOT,
|
||||
tags: [["d", canonicalIdentifier("app", "policy")]],
|
||||
content: JSON.stringify({
|
||||
id: "root-policy",
|
||||
version: "3.0.0",
|
||||
profiles: { feed: { name: "feed" } },
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
expect(runtime.policies.policy.id).toBe("root-policy");
|
||||
});
|
||||
|
||||
it("keeps the working policy when the root publishes a malformed one", () => {
|
||||
const { runtime } = makeRuntime();
|
||||
runtime.ingestEvent(rolesEvent());
|
||||
|
||||
const rejected = vi.fn();
|
||||
runtime.on("policy-rejected", rejected);
|
||||
runtime.ingestEvent(
|
||||
event({
|
||||
pubkey: ROOT,
|
||||
tags: [["d", canonicalIdentifier("app", "policy")]],
|
||||
content: JSON.stringify({ id: "broken" }),
|
||||
}),
|
||||
);
|
||||
|
||||
expect(rejected).toHaveBeenCalledWith(expect.objectContaining({ reason: "invalid" }));
|
||||
expect(runtime.policies.policy.id).toBe("app");
|
||||
});
|
||||
|
||||
it("counts unrecognized events instead of throwing", () => {
|
||||
|
||||
Reference in new issue
Block a user