Skip to content

New-core template: core's quality bar, RLS guard and a CRUD reference slice - #16

Merged
darjss merged 10 commits into
mainfrom
chore/template-quality
Nov 14, 2026
Merged

darjss merged 10 commits into
mainfrom
chore/template-quality

Conversation

@darjss

@darjss darjss commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

A plugin generated with --erxes core sat below core's bar: no quality section, skills Claude Code never loaded, org filters next to RLS, no tenancy check, and an example feature without typed errors or delete. Agents copy the template, so they copied the gaps too.

Scope is templates/core/** plus the generator code and tests it needs. The old-platform templates are untouched.

What changed, one commit each

  1. Quality section. Root AGENTS.md carries core's <!-- quality:start --> block byte for byte (checked with diff against core-guard 13b5016274). The repo part below it keeps the fixed names, the prefix plus RLS rule, the SDK/pluginFetch boundary and the commands. knip, pnpm check:generated and the skipped-test check don't exist in a plugin yet, so those rules are marked [review] there. Lint now turns on the rules the section names: no-deprecated, no-non-null-assertion, ban-ts-comment, no-warning-comments, max-lines 300 and max-lines-per-function 80 on api/ and ui/, plain no-console. no-deprecated flagged module.register in telemetry, which moves to import-in-the-middle's registerHooks loader.
  2. Skills link. The generator writes .claude/skills -> ../.agents/skills. Templates embed files only, so it's a symlink call. Windows without Developer Mode gets a junction.
  3. api/AGENTS.md. node/no-process-env replaces the "only config.ts reads process.env" line. Telemetry reads its switch from config. Queries drop their org filters, since withOrg's RLS scopes them. Node 26 in .node-version, engines, @types/node and the Dockerfile.
  4. RLS guard. tools/check-rls.sql and .sh port core's pg_catalog check to the plugin prefix. pnpm check:rls runs in the plugin's CI and is the schema-change skill's done criterion. Tests and the guard share core's tenant functions from api/src/test/core-functions.sql. A new pnpm db:migrate runs migrations alone. Dropping the RLS line from the migration makes it fail with row level security is off, ... not forced, no tenant policy.
  5. Lint. @erxes/core-db is a restricted import. The zod .catch and session advisory lock rules need core's local anti-slop plugin, which the template doesn't have, so they wait for @erxes/lint.
  6. CRUD reference. <name>_items gets a unique index on (org_id, lower(name)), list (keyset), create, update and delete. ITEM_NAME_TAKEN is declared with .errors() and thrown as errors.ITEM_NAME_TAKEN(...). The 23505 maps to it in one function (nameTaken, via uniqueViolation in db/client.ts). Rows go out without org_id. Tests use createRouterClient: CRUD and paging, the conflict on create and update (case-insensitive), cross-org RLS (same name allowed, no read, update or delete of another org's row), and FORBIDDEN. The UI form shows the conflict on the name field through isDefinedError. Delete is optimistic through orpc.items.remove.mutationOptions, with rollback on error. No asChild anywhere.
  7. Migrate kit. plugin-migrate opens with the intent, drops the pointer to core's skill and says what to do when core lacks a feature. checklist.ts ticks an item only when it works and its old bugs and workarounds are gone, and points UI ports at packages/ui/MIGRATION.md.

Smaller fixes found on the way:

  • ui/package.json failed pnpm check in every generated plugin. @__id__/api sorted differently once it had the real name. The generator now sorts it.
  • migration/inventory.ts failed the formatter.
  • ItemsPage wrapped differently with a long plugin name.
  • Under pnpm 10, which the CLI pins when it's the installed pnpm, the UI couldn't find @<name>/api's types. pnpm 10 injects a copy of api that keeps only files, and src/ wasn't listed. pnpm 12 symlinks it, so this only showed up in CI. api now lists src.
  • @erxes/* skips pnpm's release-age gate. v2-next republishes daily, and a fresh install failed ERR_PNPM_MINIMUM_RELEASE_AGE_VIOLATION for a release 5 hours old.

CI

test:e2e gets a core-pnpm case, added to the deliverables matrix on Node 26 with a Postgres container. It generates inventory-tools, then runs install, check, test, check:rls and build. Locally it passes in about 25 s with a warm store. The plugin has 7 tests, all passing. The generator's own pnpm test passes 57 of 57.

Left for later

  • ui/AGENTS.md:6-8 and ui/rsbuild.config.ts copy core-ui's SHARED list. Once erxes-ui exports SHARED, the template should import it and drop the copy. That needs an erxes-ui release first, so this PR leaves it alone.
  • A few template lines sit near the 100-column limit and wrap with a long name or title: rsbuild.config.ts exposes, the manifest permissions in core.ts, the index in schema.ts. Formatting the output after install would remove that whole class of problem.
  • A migrate-kit plugin fails pnpm check until migrate:inventory writes migration/import-map.ts. The CLI runs it after install, so only --no-install users see this.

…t rules it names

AGENTS.md gets core's marked quality block unchanged; knip, check:generated and the skip check
are review here until the plugin has them. The deprecated module.register telemetry hook moves
to import-in-the-middle's registerHooks loader, @erxes/* skips pnpm's release-age gate since
v2-next publishes daily, and ui/package.json sorts once @__id__/api has its real name.
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b65f915c-e63d-4f7f-b63b-900ebb76be1b
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…e loads the template's skills

The template embeds files only, so the generator makes the link. Windows without Developer Mode
can't make a symlink and gets a junction instead.
@sourcery-ai

sourcery-ai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Schema and migrations

The items schema and its migration add case-insensitive, per-organisation name uniqueness, with the snapshot recording the resulting schema.

  • templates/core/base/api/drizzle/0000_items.sql L12
  • templates/core/base/api/drizzle/meta/0000_snapshot.json L2, L84-104
  • templates/core/base/api/src/db/schema.ts L2-10, L30-33

API

The items procedures define the typed CRUD interface, map the name constraint to a typed error, and return rows without the organisation identifier.

  • templates/core/base/api/src/modules/items/items.ts L1-36, L66-73, L81-99 (+4 small edits)

Implementation

The database client adds unique-violation handling and documents transaction-scoped RLS, while the migration runner gains a standalone command.

  • templates/core/base/api/src/db/client.ts L1, L13-23
  • templates/core/base/api/src/db/migrate.ts L6, L72-77

Telemetry switches to import-in-the-middle hooks and reads its tracing setting from validated configuration.

  • templates/core/base/api/src/telemetry.ts L1 (removed lines), L6-13

The RLS guard provisions a fresh database, applies migrations, and reports tenancy or naming violations from the catalog query.

  • templates/core/base/tools/check-rls.sh L1-30
  • templates/core/base/tools/check-rls.sql L1-80

The shared SQL fixture defines the tenant functions used by migrations, while test setup loads that fixture.

  • templates/core/base/api/src/test/core-functions.sql L1-18
  • templates/core/base/api/src/test/setup.ts L2, L19-20

The core scaffold sorts the generated UI dependencies and links Claude Code skills to the embedded skill directory.

  • src/core-scaffold.ts L2, L24-39, L58-62

UI

The item form presents typed name conflicts accessibly, and the list adds optimistic deletion with rollback and refetch.

  • templates/core/base/ui/src/items/ItemSheet.tsx L10-22, L34-77 (+2 small edits)
  • templates/core/base/ui/src/items/ItemsPage.tsx L18-36, L56-61 (+3 small edits)
  • templates/core/base/ui/src/items/useItems.ts L2-16, L28-69

Configuration

CI runs the tenancy guard and adds a Node 26 PostgreSQL-backed generated-core case to the deliverables matrix.

  • .github/workflows/deliverables.yml L31-36 (+3 small edits)
  • templates/core/base/.github/workflows/ci.yml L47-50

The template adopts Node 26 across its runtime, package requirements, Docker image, and type definitions.

  • templates/core/base/Dockerfile L3
  • templates/core/base/_node-version L1
  • templates/core/base/api/AGENTS.md L3, L8 (removed lines), L16-17
  • templates/core/base/api/src/config.ts L25-26, L42
  • templates/core/base/package.json L14-15, L21, L27

Package and lint configuration adds the RLS gate, release-age exclusion, restricted core database imports, and the quality rules enforced on API and UI code.

  • templates/core/base/api/package.json L7-8, L20, L36
  • templates/core/base/pnpm-workspace.yaml L9-12
  • templates/core/base/vite.config.ts L46-62, L68-84, L100-116 (+2 small edits)

Documentation

The root guide records the new-core template’s gates, RLS-backed reference feature, and skill links.

  • README.md L79-90

The template’s agent guide adds core’s quality section and clarifies the RLS, plugin boundary, and local checks.

  • templates/core/base/AGENTS.md L5-45, L53-54

The endpoint and schema-change skills teach agents to rely on tenant RLS and include the tenancy guard in schema completion.

  • templates/core/base/.agents/skills/endpoint/SKILL.md L10-11
  • templates/core/base/.agents/skills/schema-change/SKILL.md L3, L8-9, L18-28

The migration skill and generated checklist require parity without old bugs or workarounds and point UI ports to the component migration guide.

  • templates/core/migrate/.agents/skills/plugin-migrate/SKILL.md L6-14, L21-29, L36-44 (+1 small edits)
  • templates/core/migrate/migration/checklist.ts L264-266

Tests

The items tests exercise typed-client CRUD, paging, case-insensitive conflicts, organisation isolation, and permission enforcement against Postgres.

  • templates/core/base/api/src/modules/items/__tests__/items.test.ts L7-32, L42-84 (+2 small edits)

The end-to-end test generates a core plugin and runs its install, checks, tests, RLS guard, and build.

  • test/e2e.test.ts L30-34, L147-162

The scaffold test verifies the generated Claude skills link and that Claude can resolve a skill through it.

  • test/scaffold.test.ts L3, L331-335

The migration inventory registration formatting is adjusted to satisfy the formatter.

  • templates/core/migrate/migration/inventory.ts L76-82

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

…d leave tenancy to RLS

node/no-process-env replaces the AGENTS.md line asking for it, telemetry reads its switch from
config. Queries drop their org filters: withOrg's row-level security already scopes them.
@socket-security

socket-security Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​types/​node@​24.19.2 ⏵ 26.6.61001008194100

View full report

tools/check-rls.sql fails a table with org_id that lacks forced RLS and the tenant policy, a
table without org_id that isn't listed, and any name outside the plugin's prefix. Tests and the
guard share core's tenant functions from one SQL file; db:migrate runs the migrations alone.
…ugin SDK

The zod .catch and session advisory lock bans need core's local lint plugin, which the template
doesn't have; they wait for @erxes/lint.
…and CI runs a generated plugin's gates

Names are unique per organisation ignoring case; the 23505 becomes oRPC's typed ITEM_NAME_TAKEN in
one place, which the form shows on the field through isDefinedError. Delete is optimistic through
the oRPC query utils, lists keep keyset paging, rows go out without org_id. Tests use the typed
client, and the e2e core case installs a fresh plugin and runs check, test, check:rls and build.
…oves to a constant

The e2e case with a longer name caught the tableId line wrapping differently.
…ral fixes

An item ticks once it works and its old bugs and workarounds are gone. A missing core feature gets
an issue and waits for core, said as what to do. UI ports point at erxes-ui's old-to-new component
table, and the pointer to core's plugin-migrate skill goes, since core deletes it.
@darjss darjss changed the title New-core template: core's quality bar, RLS guard and a reference CRUD slice New-core template: core's quality bar, RLS guard and a CRUD reference slice Nov 13, 2026
@darjss
darjss marked this pull request as ready for review November 13, 2026 21:54
@sourcery-ai

sourcery-ai Bot commented Nov 13, 2026

Copy link
Copy Markdown

Sorry @darjss, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 4 days and 19 hours by commenting @sourcery-ai review. Upgrade to get a review now.

pnpm 10 injects a copy of api into ui that keeps only the listed files, so the router types were
missing and the UI failed its type check. pnpm 12 symlinks it, which hid this locally.
@darjss
darjss merged commit c2b6ee2 into main Nov 14, 2026
19 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