---
id: w6/m10/t007
title: "Simplify: /simplify over the code this milestone changed"
worker: worker6
status: done
estimate: 30m
depends_on: [w6/m10/t006]
---

## Objective

Standing closing task. Run `/simplify` over the m10 diff (members service/fragments, api wiring, team feature) for reuse / simplification / efficiency — behavior-preserving only. Prime candidate: the enrichment loop now exists in both `workspaces.ListMembers` and `members.List` — evaluate whether a shared helper (or one service delegating to the other's projection) removes the duplication without crossing feature-package boundaries.

## Context

- `lego/backend/internal/members/`, `lego/backend/internal/api/server.go`, `dashboard/src/features/team/`.

## Steps

1. `/simplify` scoped to the milestone's changed files.
2. Apply behavior-preserving findings; re-run backend + dashboard tests.

## Files

- Whatever the m10 diff touched.

## Acceptance criteria

- [x] Findings applied or explicitly declined with a reason.
- [x] All tests green after.

## /simplify findings (2026-07-12)

Ran the 4-angle review (reuse / simplification / efficiency / altitude) over the milestone diff. All findings converged on the same shape and were **declined, not applied** — each has a concrete reason:

1. **The `members.List` enrichment loop near-duplicates `workspaces.ListMembers`'s loop; `members.EmailLookup` + `internal/api/server.go`'s `identityEmailLookup` adapter duplicate `workspaces.IdentityReader`'s shape.** Real, but this milestone's own task file (t002.md) explicitly prescribed this exact seam: _"members cannot structurally share it (named return type differs across packages) — give members its own narrow seam ... and adapt in the composition root."_ Not an oversight to fix here. The deeper fix an altitude-focused reviewer proposed — hoist `IdentityReader`/`IdentityAttrs` into `internal/core` (mirroring the existing `core.Checker`/`internal/authz` split) so `workspaces` and `members` share one interface and the adapter disappears — is a legitimate future improvement, but touches files entirely outside this diff (`workspaces/kratos.go`, `workspaces/service.go`, `workspaces/*_test.go`, `cmd/api/main.go`) and would re-touch an already-shipped w6/m2 surface. Declined as out-of-scope for a behavior-preserving milestone diff; worth a standalone follow-up task if a third caller ever needs the same lookup.
2. **`fakeStore.OwnerIDForSubject` in `members_test.go` is now a third byte-for-byte copy** of the same test fake (after `workspaces/workspaces_test.go` and `api/owners_rest_test.go`). Declined — no shared test-fakes package exists in this repo to break the cycle without a repo-wide test-infra change, and the two prior copies predate this milestone (this diff just follows established per-package-test-isolation convention, doesn't introduce a new pattern). Worth a follow-up if a fourth copy ever appears.
3. **`TestListEnrichesUserIDAndEmail` overlaps partially with the new three-surface parity test** (both assert a populated userId/email for the same fixture). Declined — the two operate at different layers (unit-level service test vs. REST/GraphQL/MCP integration test) and the codebase already has this same unit-vs-integration overlap pattern elsewhere (`workspaces/owners_test.go`); trimming would lose the layer-isolated failure signal for marginal LOC savings.
4. **The N+1 `OwnerIDForSubject`/`LookupEmail` pattern inside the `List` loop** (a DB round-trip + an uncached Kratos HTTP call per member) — confirmed to be an exact structural match of the pre-existing, already-accepted `workspaces.ListMembers` sibling, not a new inefficiency introduced by this diff. Fixing it here alone (e.g. concurrent per-member lookups) without fixing the sibling would create asymmetry between the two surfaces this milestone is explicitly trying to keep in lockstep. Declined; a pattern-wide fix (if ever needed) belongs to both surfaces at once, outside m10.

No code changes from this pass. Full backend suite re-run green after the review (no diff to introduce a regression).

## Out of scope

- Behavior changes, new features.
