Skip to content

Consolidate grant tool/providerModel/cwd scoping into one predicate - #402

Merged
TheGreatAxios merged 2 commits into
mainfrom
cl-5676-grant-scoping-filter-is-duplicated-across-three-matchers-one
Aug 8, 2026
Merged

Consolidate grant tool/providerModel/cwd scoping into one predicate#402
TheGreatAxios merged 2 commits into
mainfrom
cl-5676-grant-scoping-filter-is-duplicated-across-three-matchers-one

Conversation

@TheGreatAxios

Copy link
Copy Markdown
Collaborator

Summary

  • Extracted a shared grantScopeMatches predicate (src/permission/authz-grants.ts) covering tool/providerModel/cwd scoping, reusing the existing cwdMatchesGrant helper for the cwd dimension
  • evaluateApprovals, isRequestCoveredByGrant (src/permission/gate.ts), and hasExactFullCommandGrant (src/permission/gate.ts) now delegate to it instead of each reimplementing the condition
  • Removed the dead isApproved matcher (src/permission/matcher.ts) and its dedicated tests, which lacked the specificity-ranking behavior the live path has

Test plan

  • New failing-first test (src/permission/grant-scope.test.ts) proving evaluateApprovals and isRequestCoveredByGrant agree with the shared predicate across a tool/providerModel/cwd matrix
  • bun run typecheck
  • bun run build
  • bun run test (4189 pass, 0 fail)

@linear-code

linear-code Bot commented Aug 8, 2026

Copy link
Copy Markdown

CL-5676

evaluateApprovals, isRequestCoveredByGrant, and hasExactFullCommandGrant
each reimplemented the same tool/providerModel/cwd scoping condition
independently (src/permission/authz-grants.ts, src/permission/gate.ts),
so a scoping-dimension change required editing three sites in lockstep.
A fourth copy, matcher.ts's isApproved, was dead in production and only
exercised by its own test, and lacked the specificity-ranking behavior
evaluateApprovals gets from @intx/authz's evaluateGrants.

All three live call sites now delegate to a single exported
grantScopeMatches predicate. The dead isApproved matcher and its tests
are removed.
…ectly

The other two live call sites (evaluateApprovals, isRequestCoveredByGrant)
get a direct cross-check against grantScopeMatches; hasExactFullCommandGrant
isn't exported, so it only had indirect coverage through evaluate()'s
multi-segment replay path elsewhere in the suite. Drive that path directly
with grants grantScopeMatches would refuse (wrong cwd, wrong providerModel)
to confirm the replay never fires when the shared predicate says no.
@TheGreatAxios
TheGreatAxios force-pushed the cl-5676-grant-scoping-filter-is-duplicated-across-three-matchers-one branch from 0819b25 to 028c438 Compare August 8, 2026 19:27
@TheGreatAxios
TheGreatAxios merged commit 093408a into main Aug 8, 2026
4 of 5 checks passed
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.

1 participant