Skip to content

Comments

refactor(agents-core): enforce data-access layer boundary for auth queries#2196

Open
amikofalvy wants to merge 1 commit intomainfrom
implement/data-access-layer-enforcement
Open

refactor(agents-core): enforce data-access layer boundary for auth queries#2196
amikofalvy wants to merge 1 commit intomainfrom
implement/data-access-layer-enforcement

Conversation

@amikofalvy
Copy link
Collaborator

Summary

  • Extract 3 inline Drizzle queries from auth/auth.ts into new data-access/runtime/auth.ts (curried pattern matching existing conventions)
  • Add scripts/lint-data-access-boundary.sh lint-staged rule that prevents new drizzle-orm imports outside allowed directories (data-access/, db/, dolt/, __tests__/, test files)
  • Barrel export added to data-access/index.ts

Test plan

  • pnpm typecheck passes (agents-core)
  • pnpm lint passes (285 files, no warnings)
  • pnpm test passes (96 files, 1512 tests)
  • knip passes (no unused exports)
  • Lint script catches violations: file outside allowed dirs with from 'drizzle-orm' → exit 1
  • Lint script allows: data-access/, db/, dolt/, __tests__/, *.test.ts, *.spec.ts, test-* files
  • Pre-commit hook runs the new lint-staged entry on staged agents-core files (confirmed during commit)

🤖 Generated with Claude Code

…eries

Extract 3 inline Drizzle queries from auth/auth.ts into data-access/runtime/auth.ts
and add a lint-staged script that prevents new drizzle-orm imports outside allowed
directories (data-access/, db/, dolt/, __tests__/).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Feb 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agents-api Ready Ready Preview, Comment Feb 20, 2026 0:11am
agents-docs Ready Ready Preview, Comment Feb 20, 2026 0:11am
agents-manage-ui Ready Ready Preview, Comment Feb 20, 2026 0:11am

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Feb 20, 2026

⚠️ No Changeset found

Latest commit: bba76ab

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review Summary

(1) Total Issues | Risk: Medium

🟠⚠️ Major (1) 🟠⚠️

Inline Comments:

  • 🟠 Major: scripts/lint-data-access-boundary.sh:13-17 Allowlist missing auth/ and validation/ directories with legitimate drizzle-orm imports

🟡 Minor (1) 🟡

Inline Comments:

  • 🟡 Minor: packages/agents-core/src/data-access/index.ts:29-31 Comment placement inconsistent with established pattern

💭 Consider (3) 💭

💭 1) scripts/lint-data-access-boundary.sh CI enforcement gap

Issue: The lint script only runs via lint-staged on pre-commit hooks, not in CI. Developers can bypass with --no-verify, and PRs merged via GitHub UI skip hooks entirely.

Why: The existing createProtectedRoute enforcement uses Biome's noRestrictedImports rule (biome.jsonc lines 58-71), which runs in CI via pnpm check and cannot be bypassed. This creates an inconsistent enforcement model.

Fix: Consider adding the script to CI (run against all agents-core/src/**/*.ts files in .github/workflows/ci.yml), or migrate to Biome's noRestrictedImports rule for consistency. Not blocking since pre-commit enforcement is a reasonable starting point.

💭 2) scripts/lint-data-access-boundary.sh:25 Shell array check could be quoted

Issue: if [ ${#VIOLATIONS[@]} -gt 0 ] could be if [ "${#VIOLATIONS[@]}" -gt 0 ] for strictness consistency.

Why: Extremely minor — bash handles this correctly, but the script uses set -euo pipefail for strictness.

💭 3) scripts/lint-data-access-boundary.sh:1 Consider adding SPDX license header

Issue: Other scripts in the repository (e.g., setup-optional.sh) include an SPDX license identifier.

Why: Style consistency across scripts directory.


🚫 REQUEST CHANGES

Summary: The data-access extraction is clean and follows established curried patterns well. The lint-staged boundary enforcement is a solid architectural improvement. However, the allowlist needs to include auth/*-schema* and validation/drizzle-* patterns to avoid blocking legitimate schema definition files. Once that's fixed, this is ready to merge.

Discarded (5)
Location Issue Reason Discarded
runtime/auth.ts JSDoc documentation missing Inconsistent pattern in codebase — apiKeys.ts has no JSDoc, users.ts does. 50/50 convention.
runtime/auth.ts:5 Function naming could be getInitialMembershipForUser Intentional naming matching original code intent; naming is clear.
runtime/auth.ts Curried pattern conformance Positive observation, not an issue.
package.json:125-127 lint-staged entry well-structured Positive observation, not an issue.
lint-data-access-boundary.sh Allowlist drift concern Overlaps with the MAJOR finding about missing auth/validation directories.
Reviewers (4)
Reviewer Returned Main Findings Consider While You're Here Inline Comments Pending Recs Discarded
pr-review-standards 0 0 0 0 0 0 0
pr-review-architecture 3 0 1 0 0 0 2
pr-review-devops 5 0 2 0 2 0 1
pr-review-consistency 4 0 0 0 0 0 4
Total 12 0 3 0 2 0 7

Note: Some findings merged across reviewers (e.g., comment ordering flagged by both devops and consistency).

Comment on lines +13 to +17
case "$file" in
*/data-access/* | */db/* | */dolt/* | */__tests__/* | *.test.ts | *.spec.ts | */test-*)
continue
;;
esac
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 MAJOR Allowlist missing auth/ and validation/ directories

Issue: The allowlist doesn't include auth/ or validation/ directories, but existing files in these directories have legitimate drizzle-orm imports for schema definitions and type helpers. When any staged change touches these files, commits will be blocked.

Why:

  • packages/agents-core/src/auth/auth-schema.ts imports relations from drizzle-orm (line 1)
  • packages/agents-core/src/validation/drizzle-schema-helpers.ts imports from drizzle-orm/sqlite-core (line 2)

These are schema/type definition files, not query logic that should be encapsulated in data-access.

Fix: (1-click apply)

Suggested change
case "$file" in
*/data-access/* | */db/* | */dolt/* | */__tests__/* | *.test.ts | *.spec.ts | */test-*)
continue
;;
esac
case "$file" in
*/data-access/* | */db/* | */dolt/* | */__tests__/* | *.test.ts | *.spec.ts | */test-* | */auth/*-schema* | */validation/drizzle-*)
continue
;;
esac

Refs:

Comment on lines 29 to +31
export * from './runtime/apiKeys';
// Runtime data access (Postgres - not versioned)
export * from './runtime/auth';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Minor Comment placement inconsistent with established pattern

Issue: The section comment // Runtime data access (Postgres - not versioned) was moved to between apiKeys and auth exports, but the established pattern places section comments before the first export of that section.

Why: Minor readability impact — section comments demarcate where a group starts.

Fix: (1-click apply)

Suggested change
export * from './runtime/apiKeys';
// Runtime data access (Postgres - not versioned)
export * from './runtime/auth';
// Runtime data access (Postgres - not versioned)
export * from './runtime/apiKeys';
export * from './runtime/auth';

Refs:

@github-actions github-actions bot deleted a comment from claude bot Feb 20, 2026
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