test: remove flakiness from the performance and widget suites

A full-suite run failed intermittently, roughly one in six. Two causes, both
mine, both in test code rather than the library.

The performance fixture's setup repeated the same 100 mute-list writes 50 times
over with identical data — 5,000 calls where 100 give the same fixture — which
made construction expensive enough that individual tests occasionally exceeded
their timeout under load. The failures looked like assertion failures on
deterministic checks, which is what made them confusing. The fixture's shape
(5,000 targets, 500 authors, 100 muters per author, multiple categories and
contributors) is now asserted directly so it cannot silently degrade again.

The wall-clock assertion is gone. It measured the machine as much as the code —
85ms standalone versus 1606ms under vitest on the same commit — so it was flaky
rather than informative. Replaced with structural assertions that the snapshot
and its record maps are materialized once per batch, which is precisely the
regression that made a 5,000-target pass take ~47 seconds, and is deterministic.

Widget tests polled with vi.waitFor and its ~1s timeout. The async elements now
expose the in-flight promise as `pending`, so tests await completion directly.
That is also useful to hosts wanting to disable surrounding UI mid-action.

Six consecutive full-suite runs, 690 tests each, no failures.
This commit is contained in:
thePR0M3TH3AN committed 2026-08-09 19:36:30 -04:00
1 parent f17d917c9d
commit 7f70a64d61
6 files changed
+127 -24

No files matched your search

+16 -2
View File
@@ -98,6 +98,12 @@ export class GovernanceAction extends GovernanceElement {
this.commands = null;
/** @type {(() => Promise<any>)|null} */
this.action = null;
/**
* The in-flight action, or null when idle. Hosts can await it to disable
* surrounding UI; tests can await it instead of polling.
* @type {Promise<void>|null}
*/
this.pending = null;
this._status = "";
}
@@ -132,7 +138,9 @@ export class GovernanceAction extends GovernanceElement {
</div>
`);
this.$("#run")?.addEventListener("click", () => void this._run());
this.$("#run")?.addEventListener("click", () => {
this.pending = this._run();
});
}
async _run() {
@@ -154,6 +162,7 @@ export class GovernanceAction extends GovernanceElement {
}
this.render();
this.pending = null;
}
}
@@ -168,6 +177,8 @@ export class GovernanceAdminPanel extends GovernanceElement {
super();
/** @type {GovernanceCommands|null} */
this.commands = null;
/** @type {Promise<void>|null} */
this.pending = null;
this._status = "";
}
@@ -258,7 +269,9 @@ export class GovernanceAdminPanel extends GovernanceElement {
</div>
`);
this.$("#deny")?.addEventListener("click", () => void this._deny());
this.$("#deny")?.addEventListener("click", () => {
this.pending = this._deny();
});
}
async _deny() {
@@ -275,6 +288,7 @@ export class GovernanceAdminPanel extends GovernanceElement {
this._status = result.ok ? "Restricted" : `Refused: ${result.code}`;
this.emit(result.ok ? "account-restricted" : "action-refused", { pubkey, result });
this.render();
this.pending = null;
}
}
+7 -1
View File
@@ -195,6 +195,11 @@ export class GovernanceReport extends GovernanceElement {
this.categories = ["spam", "nudity", "profanity", "illegal", "malware", "impersonation", "other"];
/** @type {import('@nostr-governance/runtime').GovernanceCommands|null} */
this.commands = null;
/**
* The in-flight submission, or null when idle.
* @type {Promise<void>|null}
*/
this.pending = null;
this._status = "";
}
@@ -242,7 +247,7 @@ export class GovernanceReport extends GovernanceElement {
this.$("form")?.addEventListener("submit", (fromEvent) => {
fromEvent.preventDefault();
void this._submit();
this.pending = this._submit();
});
}
@@ -263,6 +268,7 @@ export class GovernanceReport extends GovernanceElement {
this._status = result.ok ? "Report published" : `Failed: ${result.code}`;
this.emit(result.ok ? "reported" : "report-failed", { target: this._target, category, result });
this.render();
this.pending = null;
}
}