From 258da844a6c70f2b29ed00d69037f83c0c51436a Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 20 Feb 2026 18:07:22 +0000 Subject: [PATCH] refactor(governance): optimize applyProposal to reuse proposal object in validation Updates `validateProposal` to accept either a proposal ID or a proposal object. Updates `applyProposal` to pass the already-fetched proposal object to `validateProposal`, eliminating a redundant file system read. This improves efficiency and code health. Tests were verified to ensure no regression. Co-authored-by: PR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> --- src/services/governance/index.js | 12 +++++++++--- torch-config-test.json | 8 -------- 2 files changed, 9 insertions(+), 11 deletions(-) delete mode 100644 torch-config-test.json diff --git a/src/services/governance/index.js b/src/services/governance/index.js index 22cc434..dd3290b 100644 --- a/src/services/governance/index.js +++ b/src/services/governance/index.js @@ -132,8 +132,14 @@ export async function createProposal({ agent, target, newContent, reason }) { return { id, diff }; } -export async function validateProposal(id) { - const { meta, newContent } = await getProposal(id); +export async function validateProposal(proposalOrId) { + let proposal; + if (typeof proposalOrId === 'string') { + proposal = await getProposal(proposalOrId); + } else { + proposal = proposalOrId; + } + const { meta, newContent } = proposal; // 1. Allowlist check (redundant but safe) const { isAllowed } = resolveAndValidateTarget(meta.target); @@ -165,7 +171,7 @@ export async function applyProposal(id) { throw new Error(`Proposal is ${meta.status}, cannot apply.`); } - const validation = await validateProposal(id); + const validation = await validateProposal(proposal); if (!validation.valid) { // Mark as rejected if validation fails? // Or just throw? The governance agent should decide. diff --git a/torch-config-test.json b/torch-config-test.json deleted file mode 100644 index 3205b36..0000000 --- a/torch-config-test.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "dashboard": { - "auth": "admin:password123", - "relays": [ - "wss://secure.relay.com" - ] - } -} \ No newline at end of file