fix(assembly): gate enactment on a real pass at replay + honest live-tally label

decisionFor derived `enacted` from mere membership in the enacted set, so a forged or peer-synced governance.proposal.enacted for a proposal that did NOT pass would render as Enacted. Now enacted requires the proposal to actually pass (isProposalPassed over the signed ballots, the ground truth), so a forged enactment of a failing proposal is ignored. Also relabeled the badge's tally 'Current tally' (it is the live replay-derived tally, not a frozen snapshot) to stop implying the numbers are recorded. New test: a forged enactment of a failing proposal shows no Enacted badge.
This commit is contained in:
OmO Orchestrator committed 2026-11-20 05:42:33 -05:00
1 parent 127f646412
commit 1cbc223ef9
3 files changed
+41 -3

No files matched your search

@@ -767,6 +767,39 @@ describe("AssemblyScreen (enactment - governance teeth)", () => {
expect(enactedEntries[0]!.payload).toMatchObject({ proposalId: "p1" });
});
it("ignores a forged or peer-synced enactment of a proposal that did NOT pass (replay-time pass gate)", async () => {
const { publicKey } = await init();
const meId = toAccountId(publicKey);
const dbName = uniqueDbName("enact-forged");
const { assembly, governance }: { assembly: AssemblyDoc; governance: GovernanceDoc } =
getAssemblyEngineForTesting(dbName);
putRosterEntry(assembly, { id: meId, residentId: meId, displayName: "Me", joinedAt: 0, active: true });
putProposal(assembly, {
id: "pf",
title: "Does not pass",
description: "A single No vote.",
authorId: meId,
createdAt: 1,
status: "open",
});
putResidentCredit(governance, { proposalId: "pf", residentId: meId, credits: 9 });
await postQvBallot({ proposalId: "pf", voterId: meId, choice: "no", credits: 9 });
// Forge the enactment directly, bypassing the enact() UI guard exactly as a
// malicious or merely-synced peer's governance.proposal.enacted would arrive.
await postEnactment("pf");
render(<AssemblyScreen dbName={dbName} />);
await waitFor(() => {
expect(screen.getByTestId("assembly-tally-no-pf")).toHaveTextContent("No 3.00");
});
// The forged enactment is ignored because the proposal did not pass: no
// Enacted badge, and no Enact affordance either.
expect(screen.queryByTestId("assembly-enacted-pf")).not.toBeInTheDocument();
expect(screen.queryByTestId("assembly-enact-pf")).not.toBeInTheDocument();
});
it("offers NO Enact action on a not-passed proposal (Yes 3 === No 3 is not a pass)", async () => {
const { publicKey } = await init();
const meId = toAccountId(publicKey);
+1 -1
View File
@@ -461,7 +461,7 @@ export function AssemblyScreen({ dbName }: AssemblyScreenProps = {}) {
className={styles.enactedTally}
data-testid={`assembly-enacted-tally-${proposal.id}`}
>
Recorded tally: Yes {tally.tally.yes.toFixed(2)} · No{" "}
Current tally: Yes {tally.tally.yes.toFixed(2)} · No{" "}
{tally.tally.no.toFixed(2)} · Abstain {tally.tally.abstain.toFixed(2)}
</span>
<span className={styles.enactedNote}>
+7 -2
View File
@@ -354,9 +354,14 @@ export function useAssemblyEngine(dbName: string = DEFAULT_ASSEMBLY_DB_NAME): {
}
function decisionFor(proposalId: string): { passed: boolean; enacted: boolean } {
const passed = isProposalPassed(tallyFor(proposalId));
return {
passed: isProposalPassed(tallyFor(proposalId)),
enacted: enactedProposalIds.has(proposalId),
passed,
// An enactment counts ONLY if the proposal actually passed: the signed QV
// ballots are the ground truth, so a forged or peer-synced
// governance.proposal.enacted for a proposal that did not pass is ignored
// (never shown as enacted) rather than trusted on its own membership.
enacted: passed && enactedProposalIds.has(proposalId),
};
}