Skip to content

refactor(console): extract the approvals audience-scope rule from buildApprovalsView - #958

Merged
rapp992 merged 2 commits into
mainfrom
refactor/approvals-scope
Oct 9, 2026
Merged

rapp992 merged 2 commits into
mainfrom
refactor/approvals-scope

Conversation

@rapp992

@rapp992 rapp992 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

What changed

buildApprovalsView (Console approvals screen) mixed three jobs in one body with a nested switch/if over the scope rule. It now:

  • delegates the audience-scope rule ("mine" default, never-empty fallback, explicit all) to (*approvalsView).applyScope, written with guard clauses instead of nested branches;
  • replaces two hand-rolled filter loops with one selectRows helper (used for both the narrowing filters and approvalRow.mine).

Net: the 55-line function with a nested switch becomes a ~20-line orchestrator plus a ~20-line, independently testable rule.

Why behavior is preserved

Pure restructuring inside the Console adapter; no change to Policy, dispatch, auth, wire format, or rendered output. I added TestApprovals_ScopeRules before refactoring (it passed against the old code), pinning: default keeps mine+own, default never empties a non-empty queue, default on an empty queue, explicit mine may empty, explicit all. It passes unchanged after.

Verification

  • go vet and gofmt clean on the package.
  • go test ./internal/controlplane/... passes before and after.
  • Not run: golangci-lint (the installed binary was built with Go 1.25, below the repo's 1.26.9, so it refuses to load config) and full make verify (this PR touches only Console view code, no /proto, so proto gates are not in play). CI will run the full gate.

Other candidates, ranked (not taken)

  1. approvalFilter: the filter-key list "who","op","risk","quorum","scope" is repeated in parseApprovalFilter, value, query and chip builders — replace with named key constants.
  2. approvals.go (~2000 lines) and activity.go (~1850) mix view-building with embedded templates; split templates/filters into separate files.
  3. activityFilter/accessFilter/approvalFilter each reimplement href/query/withX URL-building — a shared small helper could unify them.
  4. cmd/relay/main.go (1280 lines) composition root could be split by concern (security-surface, so needs human review).

🤖 Generated with Claude Code

https://claude.ai/code/session_01TKUbxQw6dBGysLA9CtZkFy


Generated by Claude Code

claude added 2 commits October 9, 2026 05:42
…ldApprovalsView

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUbxQw6dBGysLA9CtZkFy

rapp992 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Fixed the red Docs & paths job: this branch predated #956, so zizmor's online audit flagged the old dtolnay/rust-toolchain pin. I merged main in (merge commit b65838f, no conflicts). On the merged tree, make lint-ci is clean, and go build, go vet and the full go test ./... pass.


Generated by Claude Code

@rapp992
rapp992 merged commit 54ed3d7 into main Oct 9, 2026
7 checks passed
@rapp992
rapp992 deleted the refactor/approvals-scope branch October 9, 2026 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants