@mrciphersmith/keryx 0.4.28 → 0.4.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/dist/cli.js +4916 -3655
  2. package/dist/core.js +91 -28
  3. package/dist/keryx-general-worker-entry.js +413 -240
  4. package/package.json +1 -1
  5. package/src/gdskills/bundled/install-manifest.json +3 -0
  6. package/src/gdskills/bundled/rules/core/api-contracts.mdc +21 -136
  7. package/src/gdskills/bundled/rules/core/async-patterns.mdc +18 -171
  8. package/src/gdskills/bundled/rules/core/clean-architecture.mdc +40 -150
  9. package/src/gdskills/bundled/rules/core/cli-interface-design.mdc +63 -194
  10. package/src/gdskills/bundled/rules/core/code-style-patterns.mdc +36 -48
  11. package/src/gdskills/bundled/rules/core/concurrency-patterns.mdc +32 -0
  12. package/src/gdskills/bundled/rules/core/database-patterns.mdc +26 -148
  13. package/src/gdskills/bundled/rules/core/error-handling.mdc +57 -109
  14. package/src/gdskills/bundled/rules/core/frontend-assistant.mdc +14 -29
  15. package/src/gdskills/bundled/rules/core/layout-rendering.mdc +51 -0
  16. package/src/gdskills/bundled/rules/core/mobx-store-template.mdc +69 -511
  17. package/src/gdskills/bundled/rules/core/nestjs-dto.mdc +18 -36
  18. package/src/gdskills/bundled/rules/core/playwright-testing.mdc +35 -308
  19. package/src/gdskills/bundled/rules/core/security-baseline.mdc +18 -140
  20. package/src/gdskills/bundled/rules/core/skill-authoring.mdc +190 -0
  21. package/src/gdskills/bundled/rules/core/skills-storage-workflow.mdc +5 -0
  22. package/src/gdskills/bundled/rules/core/solid-principles.mdc +70 -121
  23. package/src/gdskills/bundled/rules/core/storybook-guidelines.mdc +20 -22
  24. package/src/gdskills/bundled/rules/core/tdd-workflow.mdc +37 -74
  25. package/src/gdskills/bundled/rules/core/ui-anti-slop.mdc +48 -37
  26. package/src/gdskills/bundled/skills/orchestration/task-implementer/SKILL.md +2 -2
  27. package/src/gdskills/bundled/skills/quality/deprecation-path/SKILL.md +1 -1
  28. package/src/gdskills/bundled/skills/quality/tests-creator/SKILL.md +1 -1
  29. package/src/gdskills/bundled/skills/review/review-architecture/SKILL.md +25 -61
  30. package/src/gdskills/bundled/skills/review/review-backend/SKILL.md +15 -69
  31. package/src/gdskills/bundled/skills/review/review-clean-code/SKILL.md +84 -418
  32. package/src/gdskills/bundled/skills/review/review-core-boundaries/SKILL.md +2 -2
  33. package/src/gdskills/bundled/skills/review/review-degradation/SKILL.md +1 -1
  34. package/src/gdskills/bundled/skills/review/review-flow-graph/SKILL.md +1 -1
  35. package/src/gdskills/bundled/skills/review/review-frontend/SKILL.md +17 -311
  36. package/src/gdskills/bundled/skills/review/review-frontend-conventions/SKILL.md +8 -22
  37. package/src/gdskills/bundled/skills/review/review-highload/SKILL.md +84 -228
  38. package/src/gdskills/bundled/skills/review/review-layout/SKILL.md +22 -28
  39. package/src/gdskills/bundled/skills/review/review-logic/SKILL.md +9 -10
  40. package/src/gdskills/bundled/skills/review/review-performance/SKILL.md +16 -38
  41. package/src/gdskills/bundled/skills/review/review-premise/SKILL.md +1 -1
  42. package/src/gdskills/bundled/skills/review/review-regression/SKILL.md +1 -1
  43. package/src/gdskills/bundled/skills/review/review-security-code/SKILL.md +8 -8
  44. package/src/gdskills/bundled/skills/review/review-style/SKILL.md +49 -88
  45. package/src/gdskills/bundled/skills/review/review-testing-practices/SKILL.md +22 -40
  46. package/src/gdskills/bundled/skills/review/review-ui-ux/SKILL.md +42 -82
  47. package/src/gdskills/bundled/stacks/angular/rules/coding-style.mdc +15 -57
  48. package/src/gdskills/bundled/stacks/angular/rules/patterns.mdc +16 -60
  49. package/src/gdskills/bundled/stacks/angular/rules/security.mdc +11 -49
  50. package/src/gdskills/bundled/stacks/angular/rules/testing.mdc +13 -52
  51. package/src/gdskills/bundled/stacks/c-cpp/rules/coding-style.mdc +33 -57
  52. package/src/gdskills/bundled/stacks/c-cpp/rules/patterns.mdc +35 -62
  53. package/src/gdskills/bundled/stacks/c-cpp/rules/security.mdc +35 -62
  54. package/src/gdskills/bundled/stacks/c-cpp/rules/testing.mdc +34 -54
  55. package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/patterns.mdc +27 -56
  56. package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/security.mdc +51 -119
  57. package/src/gdskills/bundled/stacks/csharp-dotnet/rules/coding-style.mdc +42 -74
  58. package/src/gdskills/bundled/stacks/csharp-dotnet/rules/patterns.mdc +45 -83
  59. package/src/gdskills/bundled/stacks/csharp-dotnet/rules/security.mdc +34 -59
  60. package/src/gdskills/bundled/stacks/csharp-dotnet/rules/testing.mdc +33 -62
  61. package/src/gdskills/bundled/stacks/django/rules/coding-style.mdc +15 -56
  62. package/src/gdskills/bundled/stacks/django/rules/patterns.mdc +16 -68
  63. package/src/gdskills/bundled/stacks/django/rules/security.mdc +13 -71
  64. package/src/gdskills/bundled/stacks/django/rules/testing.mdc +16 -62
  65. package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/coding-style.mdc +30 -53
  66. package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/patterns.mdc +20 -56
  67. package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/security.mdc +52 -122
  68. package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/testing.mdc +23 -42
  69. package/src/gdskills/bundled/stacks/fastapi/rules/coding-style.mdc +13 -47
  70. package/src/gdskills/bundled/stacks/fastapi/rules/patterns.mdc +18 -81
  71. package/src/gdskills/bundled/stacks/fastapi/rules/security.mdc +13 -75
  72. package/src/gdskills/bundled/stacks/fastapi/rules/testing.mdc +14 -58
  73. package/src/gdskills/bundled/stacks/flutter-dart/rules/coding-style.mdc +36 -74
  74. package/src/gdskills/bundled/stacks/flutter-dart/rules/patterns.mdc +30 -66
  75. package/src/gdskills/bundled/stacks/flutter-dart/rules/security.mdc +33 -67
  76. package/src/gdskills/bundled/stacks/flutter-dart/rules/testing.mdc +41 -73
  77. package/src/gdskills/bundled/stacks/go/rules/coding-style.mdc +36 -57
  78. package/src/gdskills/bundled/stacks/go/rules/patterns.mdc +27 -42
  79. package/src/gdskills/bundled/stacks/go/rules/security.mdc +26 -43
  80. package/src/gdskills/bundled/stacks/go/rules/testing.mdc +23 -41
  81. package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/coding-style.mdc +21 -40
  82. package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/patterns.mdc +26 -43
  83. package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/security.mdc +25 -37
  84. package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/testing.mdc +34 -50
  85. package/src/gdskills/bundled/stacks/kotlin-android/rules/coding-style.mdc +28 -65
  86. package/src/gdskills/bundled/stacks/kotlin-android/rules/patterns.mdc +34 -78
  87. package/src/gdskills/bundled/stacks/kotlin-android/rules/security.mdc +35 -68
  88. package/src/gdskills/bundled/stacks/kotlin-android/rules/testing.mdc +34 -68
  89. package/src/gdskills/bundled/stacks/mobx/rules/coding-style.mdc +18 -64
  90. package/src/gdskills/bundled/stacks/mobx/rules/patterns.mdc +13 -66
  91. package/src/gdskills/bundled/stacks/mobx/rules/security.mdc +8 -35
  92. package/src/gdskills/bundled/stacks/mobx/rules/testing.mdc +10 -39
  93. package/src/gdskills/bundled/stacks/nestjs/rules/coding-style.mdc +32 -45
  94. package/src/gdskills/bundled/stacks/nestjs/rules/patterns.mdc +40 -60
  95. package/src/gdskills/bundled/stacks/nestjs/rules/security.mdc +30 -50
  96. package/src/gdskills/bundled/stacks/nestjs/rules/testing.mdc +27 -47
  97. package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/coding-style.mdc +14 -48
  98. package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/patterns.mdc +15 -67
  99. package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/security.mdc +12 -50
  100. package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/testing.mdc +11 -43
  101. package/src/gdskills/bundled/stacks/php-laravel/rules/coding-style.mdc +17 -58
  102. package/src/gdskills/bundled/stacks/php-laravel/rules/patterns.mdc +15 -56
  103. package/src/gdskills/bundled/stacks/php-laravel/rules/security.mdc +13 -50
  104. package/src/gdskills/bundled/stacks/php-laravel/rules/testing.mdc +14 -55
  105. package/src/gdskills/bundled/stacks/python/rules/coding-style.mdc +13 -41
  106. package/src/gdskills/bundled/stacks/python/rules/patterns.mdc +20 -61
  107. package/src/gdskills/bundled/stacks/python/rules/security.mdc +15 -57
  108. package/src/gdskills/bundled/stacks/python/rules/testing.mdc +16 -50
  109. package/src/gdskills/bundled/stacks/react/rules/coding-style.mdc +14 -40
  110. package/src/gdskills/bundled/stacks/react/rules/patterns.mdc +15 -55
  111. package/src/gdskills/bundled/stacks/react/rules/security.mdc +13 -49
  112. package/src/gdskills/bundled/stacks/react/rules/testing.mdc +10 -37
  113. package/src/gdskills/bundled/stacks/ruby-rails/rules/coding-style.mdc +15 -48
  114. package/src/gdskills/bundled/stacks/ruby-rails/rules/patterns.mdc +18 -67
  115. package/src/gdskills/bundled/stacks/ruby-rails/rules/security.mdc +11 -60
  116. package/src/gdskills/bundled/stacks/ruby-rails/rules/testing.mdc +14 -65
  117. package/src/gdskills/bundled/stacks/rust/rules/coding-style.mdc +39 -65
  118. package/src/gdskills/bundled/stacks/rust/rules/patterns.mdc +33 -60
  119. package/src/gdskills/bundled/stacks/rust/rules/security.mdc +35 -57
  120. package/src/gdskills/bundled/stacks/rust/rules/testing.mdc +29 -52
  121. package/src/gdskills/bundled/stacks/sql-db/rules/coding-style.mdc +12 -48
  122. package/src/gdskills/bundled/stacks/sql-db/rules/patterns.mdc +22 -113
  123. package/src/gdskills/bundled/stacks/sql-db/rules/security.mdc +11 -56
  124. package/src/gdskills/bundled/stacks/sql-db/rules/testing.mdc +14 -59
  125. package/src/gdskills/bundled/stacks/swift-ios/rules/coding-style.mdc +29 -65
  126. package/src/gdskills/bundled/stacks/swift-ios/rules/patterns.mdc +41 -88
  127. package/src/gdskills/bundled/stacks/swift-ios/rules/security.mdc +28 -53
  128. package/src/gdskills/bundled/stacks/swift-ios/rules/testing.mdc +32 -65
  129. package/src/gdskills/bundled/stacks/vue/rules/coding-style.mdc +17 -52
  130. package/src/gdskills/bundled/stacks/vue/rules/patterns.mdc +17 -63
  131. package/src/gdskills/bundled/stacks/vue/rules/security.mdc +11 -41
  132. package/src/gdskills/bundled/stacks/vue/rules/testing.mdc +16 -48
@@ -7,84 +7,35 @@ metadata:
7
7
 
8
8
  # Ruby on Rails security
9
9
 
10
- Narrows `core-common-rules`' stack-agnostic security rules to
11
- Rails-specific, OWASP-relevant risks and the safe framework API to use
12
- instead. Applies to `*.rb` and `*.erb` files.
10
+ Narrows `core-common-rules`' security rules to Rails-specific, OWASP-relevant risks and the safe framework API. Applies to `*.rb` and `*.erb` files.
13
11
 
14
12
  ## Mass assignment and strong parameters
15
13
 
16
- - Never build or update a model from a raw `params` hash
17
- (`Model.new(params[:model])`, `record.update(params)`); require the
18
- permitted shape first with `params.expect(model: [:field, ...])`
19
- (current Rails idiom) or `params.require(:model).permit(:field, ...)`,
20
- and never call `permit!` on user-controlled params — it disables
21
- strong parameters entirely and lets any attacker-supplied key through,
22
- including ones like `admin`/`role` that were never meant to be
23
- user-settable.
24
- - List every permitted attribute explicitly; do not permit a whole
25
- nested hash with a bare `permit(:nested)` when only specific
26
- sub-keys should be writable.
14
+ - Never build or update a model from a raw `params` hash; require the permitted shape with `params.expect(model: [:field, ...])` or `params.require(:model).permit(:field, ...)`, and never call `permit!` on user-controlled params.
15
+ - List every permitted attribute explicitly; no bare `permit(:nested)` for a whole nested hash when only some sub-keys are writable.
27
16
 
28
17
  ## SQL and data access
29
18
 
30
- - Use ActiveRecord's parameterized conditions (`where("age > ?", age)`,
31
- `where(age: age)`, or named placeholders) — never
32
- string-interpolate a user-influenced value into `where`,
33
- `find_by_sql`, `order`, or any other query method
34
- (`where("name = '#{params[:name]}'")` is SQL injection).
35
- - When raw SQL genuinely cannot be avoided (a fragment passed to
36
- `order`/`pluck` built from a dynamic column list, for instance), pass
37
- untrusted values through `ActiveRecord::Base.sanitize_sql`/
38
- `sanitize_sql_array`, never through direct string interpolation.
19
+ - Use parameterized conditions (`where("age > ?", age)`, `where(age: age)`, named placeholders); never interpolate a user-influenced value into `where`, `find_by_sql`, `order` or any other query method.
20
+ - When raw SQL is unavoidable, pass untrusted values through `ActiveRecord::Base.sanitize_sql`/`sanitize_sql_array`.
39
21
 
40
22
  ## Output encoding and XSS
41
23
 
42
- - Rely on ERB's automatic HTML escaping for any value that can contain
43
- user input; using `raw(value)` or `value.html_safe` on
44
- user-controlled or user-influenced content reintroduces XSS by
45
- marking untrusted text as pre-escaped. Reserve `raw`/`html_safe` for
46
- genuinely static, developer-authored content, and prefer a sanitizer
47
- (`sanitize`) over `html_safe` when some user-supplied markup must be
48
- allowed through.
24
+ - Rely on ERB's automatic escaping; never use `raw(value)` or `value.html_safe` on user-influenced content. Reserve them for static, developer-authored content, and prefer `sanitize` when some user markup must be allowed.
49
25
 
50
26
  ## Authentication and authorization
51
27
 
52
- - Every controller action that requires a logged-in user runs a
53
- `before_action` (e.g. `:authenticate_user!` or the app's own
54
- equivalent) — an action added to an already-protected controller
55
- inherits the filter only if it is not explicitly skipped
56
- (`skip_before_action`); check that a new action was not accidentally
57
- excluded.
58
- - Authentication (who is this) is not authorization (what can they do):
59
- confirm the current user is allowed to act on *this specific* record
60
- (ownership/role check), not just that they are logged in at all —
61
- an unauthorized action on someone else's resource (IDOR) is a
62
- distinct bug from a missing login check.
28
+ - Every action requiring a logged-in user runs a `before_action` (e.g. `:authenticate_user!`); check that a new action is not excluded by `skip_before_action`.
29
+ - Check that the current user may act on this specific record (ownership/role), not just that they are logged in (IDOR).
63
30
 
64
31
  ## CSRF
65
32
 
66
- - Keep `protect_from_forgery with: :exception` (or the equivalent
67
- `ActionController::Base` default) enabled for any controller serving
68
- browser-submitted forms; do not disable CSRF protection
69
- (`skip_before_action :verify_authenticity_token`,
70
- `protect_from_forgery with: :null_session`) on an action reachable
71
- from a standard HTML form just to make a request easier to test or
72
- call from a script — scope any real exception (a webhook endpoint
73
- verified by its own signature, for instance) as narrowly as possible
74
- and say why in the change.
33
+ - Keep `protect_from_forgery with: :exception` (or the `ActionController::Base` default) for any controller serving browser forms; do not use `skip_before_action :verify_authenticity_token` or `protect_from_forgery with: :null_session` on an action reachable from an HTML form. Scope a real exception (a webhook verified by its own signature) as narrowly as possible and say why in the change.
75
34
 
76
35
  ## Background jobs
77
36
 
78
- - An `ActiveJob` must tolerate being run more than once for the same
79
- logical unit of work (most production queue adapters are at-least-once) —
80
- guard non-idempotent side effects (charging a card, sending an email)
81
- with a uniqueness check or an idempotency key rather than assuming
82
- single delivery.
37
+ - Make an `ActiveJob` tolerate running more than once (adapters are at-least-once); guard non-idempotent side effects (charging a card, sending an email) with a uniqueness check or idempotency key.
83
38
 
84
39
  ## Secrets
85
40
 
86
- - Never commit a credential, API key, or signing secret in source —
87
- store it in Rails encrypted credentials (`bin/rails credentials:edit`)
88
- or an environment variable the deployment already manages, and load it
89
- through `Rails.application.credentials`/`ENV`, not a literal in a
90
- `.rb` file.
41
+ - Never commit a credential, API key or signing secret; use Rails encrypted credentials (`bin/rails credentials:edit`) or a deployment-managed environment variable, loaded via `Rails.application.credentials`/`ENV`.
@@ -7,83 +7,32 @@ metadata:
7
7
 
8
8
  # Ruby on Rails testing
9
9
 
10
- Narrows `core-common-rules`' stack-agnostic testing rules to Rails
11
- testing idiom. Covers RSpec (the more common choice in current Rails
12
- apps) and notes the Minitest equivalent where it differs meaningfully.
13
- Applies only to `*.rb` files.
10
+ Narrows `core-common-rules`' testing rules to Rails: RSpec, with the Minitest equivalent where it differs. Applies only to `*.rb` files.
14
11
 
15
12
  ## Layout and framework choice
16
13
 
17
- - Match whichever framework the project already uses — `spec/` with
18
- RSpec (`*_spec.rb`) or `test/` with Minitest (`*_test.rb`); do not
19
- introduce the other framework into a project that has standardized on
20
- one.
21
- - Mirror `app/`'s structure under `spec/`/`test/`: a model at
22
- `app/models/order.rb` gets a spec at `spec/models/order_spec.rb`, a
23
- job at `app/jobs/charge_job.rb` gets
24
- `spec/jobs/charge_job_spec.rb`, and so on.
14
+ - Match the project's framework (`spec/` with RSpec `*_spec.rb`, or `test/` with Minitest `*_test.rb`); do not introduce the other.
15
+ - Mirror `app/` under `spec/`/`test/` (`app/models/order.rb` gets `spec/models/order_spec.rb`).
25
16
 
26
17
  ## RSpec conventions
27
18
 
28
- - `describe`/`context`/`it` read as a sentence — `context` for a
29
- precondition ("when the user is not signed in"), `it` for the
30
- observable behavior ("redirects to the login page"); avoid vague
31
- `it "works"` descriptions.
32
- - Use `let`/`let!` for lazily/eagerly built fixtures shared across
33
- examples in a block instead of repeating setup in every `it`;
34
- `before` blocks for side effects that must run before each example.
35
- - Request specs (`spec/requests`) exercise a controller action through
36
- the full stack (routing, before_actions, rendering) and are generally
37
- preferred over controller specs for new Rails apps; system specs
38
- (`spec/system`, via Capybara) exercise a full browser flow — pick the
39
- narrowest layer that actually covers what changed.
40
- - Use FactoryBot (`create`/`build`, `build_stubbed` when persistence
41
- isn't needed) if the project already has it configured, matching its
42
- existing factory definitions rather than hand-building fixtures a
43
- different way.
19
+ - Use `context` for a precondition and `it` for the observable behavior; no vague `it "works"`.
20
+ - Use `let`/`let!` for shared fixtures and `before` for side effects, not repeated setup per `it`.
21
+ - Prefer request specs (`spec/requests`) over controller specs for new Rails apps; use system specs (`spec/system`, Capybara) for browser flows; pick the narrowest layer that covers the change.
22
+ - Use FactoryBot (`create`/`build`, `build_stubbed` when persistence is not needed) if configured, matching existing factories.
44
23
 
45
24
  ## Minitest conventions (when the project uses it instead)
46
25
 
47
- - `test "does something" do ... end` inside a `class XyzTest <
48
- ActiveSupport::TestCase` (or `ActionDispatch::IntegrationTest` for
49
- request tests); fixtures come from `test/fixtures/*.yml` or the
50
- project's own factory setup.
51
- - Assertions read `assert_equal expected, actual` (expected first) and
52
- `assert_predicate`/`assert_raises` over a bare `assert` on a boolean
53
- expression, for a clearer failure message.
26
+ - Write `test "does something" do ... end` in `ActiveSupport::TestCase` (or `ActionDispatch::IntegrationTest` for request tests); fixtures come from `test/fixtures/*.yml` or the project's factory setup.
27
+ - Use `assert_equal expected, actual` (expected first) and `assert_predicate`/`assert_raises` over a bare `assert` on a boolean.
54
28
 
55
29
  ## Database and external boundaries
56
30
 
57
- - Tests run inside a transaction per example (RSpec's
58
- `use_transactional_fixtures`/Rails' default Minitest behavior) that
59
- rolls back automatically — do not manually clean up records created
60
- in a test unless the app has opted out of transactional tests for a
61
- specific reason (e.g. system specs across threads), in which case
62
- match whatever cleanup strategy (DatabaseCleaner, truncation) it
63
- already uses.
64
- - Stub/mock an external HTTP call (a third-party API, a webhook) at the
65
- boundary (WebMock, VCR cassettes, or the project's existing tooling)
66
- — a test must not make a real network call.
67
- - Assert an `ActiveJob` was enqueued with `have_enqueued_job`
68
- (RSpec) / `assert_enqueued_with` (Minitest) rather than asserting on
69
- its side effects by actually running it, unless the test's purpose is
70
- specifically to exercise the job's `perform` behavior — in which case
71
- drain the queue explicitly (`perform_enqueued_jobs`) instead of
72
- sleeping or polling for it to run.
31
+ - Rely on per-example transactional rollback; do not manually clean up records unless the app has opted out (e.g. system specs across threads), then match its cleanup strategy (DatabaseCleaner, truncation).
32
+ - Stub external HTTP calls at the boundary (WebMock, VCR cassettes, or the project's tooling); no real network calls.
33
+ - Assert enqueuing with `have_enqueued_job` (RSpec) / `assert_enqueued_with` (Minitest); to exercise `perform`, drain with `perform_enqueued_jobs`.
73
34
 
74
35
  ## Determinism
75
36
 
76
- - Never synchronize with `sleep` to wait for a background job, an
77
- async callback, or an eventually-consistent read — use
78
- `perform_enqueued_jobs`, a Capybara-provided wait matcher
79
- (`have_content` retries automatically), or an explicit polling helper
80
- with a timeout.
81
- - Freeze time (`travel_to`/`Timecop`, matching whatever the project
82
- already uses) for any test asserting on a timestamp or a
83
- time-dependent calculation, instead of asserting against
84
- `Time.current` computed twice and racing a clock tick.
85
-
86
- ## Regression discipline
87
-
88
- - A bug fix gets a regression test that fails before the fix and passes
89
- after; new behavior gets new coverage in the same change.
37
+ - Never synchronize with `sleep`; use `perform_enqueued_jobs`, a Capybara wait matcher (`have_content`), or a polling helper with a timeout.
38
+ - Freeze time (`travel_to`/`Timecop`, matching the project) for any timestamp or time-dependent assertion.
@@ -8,86 +8,60 @@ metadata:
8
8
  # Rust coding style
9
9
 
10
10
  Narrows `core-common-rules`' stack-agnostic style rules to modern Rust
11
- (2021/2024 edition) idiom. Applies only to `*.rs` files — everything not
12
- Rust-specific still comes from the common rules this file `extends`.
11
+ (2021/2024 edition) idiom, following the Rust API Guidelines. Applies only
12
+ to `*.rs` files.
13
13
 
14
14
  ## Naming and structure
15
15
 
16
- - `snake_case` for functions, methods, variables, and modules;
17
- `UpperCamelCase` for types, traits, and enum variants; `SCREAMING_SNAKE_CASE`
18
- for constants and statics — `rustfmt`/`rustc` will warn on a mismatch.
19
- - A crate's public surface lives at the paths re-exported from `lib.rs`;
20
- keep implementation details `pub(crate)` or private and re-export
21
- deliberately, rather than making every module `pub` by default.
22
- - An identifier's name shrinks with its scope: a short-lived closure
23
- parameter can be `x`, a `pub` function gets a full descriptive name.
16
+ - A crate's public surface is what `lib.rs` re-exports; keep details
17
+ `pub(crate)` or private rather than every module `pub`.
24
18
 
25
19
  ## Ownership, borrowing, and errors
26
20
 
27
- - Prefer borrowing (`&T`/`&mut T`) over taking ownership when the callee
28
- does not need to keep the value; prefer `&str`/`&[T]` parameters over
29
- `&String`/`&Vec<T>` so callers can pass either owned or borrowed data.
30
- - Resolve a borrow-checker conflict by restructuring ownership, splitting
31
- the borrow, or shortening a borrow's lifetime — reach for `.clone()`
32
- only when the value genuinely needs to be duplicated, and say why in a
33
- comment when the clone is non-obvious; an unnecessary `.clone()` used
34
- purely to silence the borrow checker is a cost paid on every call.
35
- - `Result<T, E>` for anything that can fail; propagate with the `?`
36
- operator rather than a manual `match` that just re-returns `Err`.
37
- `Option<T>` for genuine absence, not as a substitute for `Result` on an
38
- operation that can fail for a reason worth naming.
39
- - Never call `.unwrap()`/`.expect()` on a `Result`/`Option` built from
40
- fallible or untrusted input (a parsed argument, a network response, a
41
- file read, a map lookup on external data) in production code without a
42
- stated invariant that makes it truly infallible; prefer `?`, a `match`,
43
- or a combinator (`unwrap_or`, `unwrap_or_else`, `ok_or`) that handles the
44
- failure path.
45
- - Use `thiserror` to derive `std::error::Error` for a library's own error
46
- enum (`#[error("...")]` per variant, `#[source]`/`#[from]` to preserve
47
- the underlying cause); use `anyhow::Result`/`.context()`/`.with_context()`
48
- in application/binary code that just needs to propagate and annotate
49
- errors up to `main`, not to dictate a precise error type to its own
50
- callers.
21
+ - Borrow (`&T`/`&mut T`) unless the callee keeps the value; `&str`/`&[T]`
22
+ parameters over `&String`/`&Vec<T>`.
23
+ - Resolve a borrow-checker conflict by restructuring ownership, splitting the
24
+ borrow, or shortening a lifetime; `.clone()` only when a duplicate is
25
+ needed, with a comment when non-obvious.
26
+ - `Result<T, E>` for anything that can fail, propagated with `?` rather than
27
+ a `match` that re-returns `Err`; `Option<T>` for genuine absence, not
28
+ instead of `Result`.
29
+ - No `.unwrap()`/`.expect()` on a `Result`/`Option` built from fallible or
30
+ untrusted input in production code without a stated invariant; use `?`, a
31
+ `match`, or `unwrap_or`/`unwrap_or_else`/`ok_or`.
32
+ - `thiserror` for a library's own error enum (`#[error("...")]`,
33
+ `#[source]`/`#[from]`); `anyhow::Result` with `.context()`/`.with_context()`
34
+ in application/binary code.
51
35
 
52
36
  ## Traits and generics
53
37
 
54
- - Accept the narrowest trait bound a function actually needs (`AsRef<str>`
55
- over `&String`, `Iterator<Item = T>` over `Vec<T>`) so callers keep
56
- flexibility in what they pass.
57
- - Prefer returning a concrete type (`impl Trait` in return position) over
58
- a boxed trait object (`Box<dyn Trait>`) unless runtime polymorphism
59
- (a heterogeneous collection, a plugin-style callback list) is actually
60
- needed — `impl Trait` avoids the allocation and indirection.
61
- - Derive `Debug`, `Clone`, `PartialEq`, etc. instead of hand-writing them
62
- when the type's fields support it; hand-write only when the derived
63
- behavior would be wrong for the type's invariants.
38
+ - Narrowest trait bound the function needs (`AsRef<str>` over `&String`,
39
+ `Iterator<Item = T>` over `Vec<T>`).
40
+ - Return `impl Trait` over `Box<dyn Trait>` unless runtime polymorphism is
41
+ needed.
42
+ - Derive `Debug`, `Clone`, `PartialEq`, etc.; hand-write only when the
43
+ derived behavior would be wrong for the type's invariants.
64
44
 
65
45
  ## Iterators and control flow
66
46
 
67
- - Prefer an iterator chain (`.map`/`.filter`/`.fold`/`.collect`) over a
68
- hand-rolled indexed loop when it expresses the transformation as clearly
69
- — but do not force a chain that reads worse than a plain `for` loop just
70
- to look idiomatic; readability wins over either style has priority.
71
- - Use pattern matching (`match`, `if let`, `let else`) to handle every
72
- variant of an enum explicitly; avoid a catch-all `_ =>` arm on a `match`
73
- over your own enum where a new variant should force every call site to
74
- be revisited.
47
+ - An iterator chain over an indexed loop when it reads as clearly; do not
48
+ force a chain that reads worse than a `for` loop.
49
+ - Match every variant of your own enum explicitly; no catch-all `_ =>` arm
50
+ where a new variant should force call sites to be revisited.
75
51
 
76
52
  ## Async conventions (when the crate uses async)
77
53
 
78
- - `async fn` for I/O-bound work; never call a blocking operation
79
- (`std::thread::sleep`, a synchronous file/socket read, a `std::sync`
80
- primitive held across an `.await` point) inside an `async fn` running on
81
- a multi-threaded executor — use the async equivalent (`tokio::time::sleep`,
82
- `tokio::fs`, `tokio::sync::Mutex`) or `tokio::task::spawn_blocking` for
83
- genuinely CPU-bound or blocking work.
84
- - Keep a `Mutex` guard's scope as short as possible and never hold one
85
- across an `.await`; prefer `tokio::sync::Mutex` when the lock itself
86
- must be held across an await point, `std::sync::Mutex` when it never is.
54
+ - No blocking operation (`std::thread::sleep`, synchronous file/socket read,
55
+ a `std::sync` primitive held across `.await`) inside an `async fn` on a
56
+ multi-threaded executor; use `tokio::time::sleep`, `tokio::fs`,
57
+ `tokio::sync::Mutex`, or `tokio::task::spawn_blocking`.
58
+ - Keep a `Mutex` guard's scope short, never across an `.await`;
59
+ `tokio::sync::Mutex` when the lock must be held across an await,
60
+ `std::sync::Mutex` when it never is.
87
61
 
88
62
  ## Formatting and lints
89
63
 
90
- - Format with `rustfmt` (`cargo fmt`) before finishing a change; do not
91
- hand-format around a formatter that is already configured.
92
- - Run `cargo clippy -- -D warnings` and fix findings at the root cause
93
- rather than adding a blanket `#[allow(...)]`.
64
+ - Format with `rustfmt` (`cargo fmt`); do not hand-format around a
65
+ configured formatter.
66
+ - `cargo clippy -- -D warnings`; fix at the root cause, not with a blanket
67
+ `#[allow(...)]`.
@@ -8,78 +8,51 @@ metadata:
8
8
  # Rust patterns
9
9
 
10
10
  Narrows `core-common-rules`' stack-agnostic design guidance to idiomatic
11
- Rust design and its common anti-patterns. Applies only to `*.rs` files.
11
+ Rust design (Rust API Guidelines, the Rust Design Patterns book). Applies
12
+ only to `*.rs` files.
12
13
 
13
14
  ## Crate and module layout
14
15
 
15
- - `src/lib.rs` (or `src/main.rs` for a binary) is the crate root; group
16
- related functionality into modules under `src/`, each with a clear
17
- single responsibility — a module that only holds shared types with no
18
- behavior ("models", "types", "common") invites the same cross-module
19
- coupling a Go "utils" package does.
20
- - A workspace (`[workspace]` in the root `Cargo.toml`) splits genuinely
21
- independent crates (a library plus a CLI that depends on it, or several
22
- services sharing a core crate) — do not default to a workspace for a
23
- single-binary project that has no reason to publish separate crates.
24
- - Keep `pub` surface intentional: re-export the types callers need from
25
- `lib.rs`, keep internal modules `pub(crate)` or private so the compiler
26
- (not convention) enforces the boundary.
16
+ - No shared-types-only modules ("models", "types", "common").
17
+ - A `[workspace]` only for genuinely independent crates (a library plus a
18
+ CLI, services sharing a core crate), not a single-binary project.
19
+ - Re-export the types callers need from `lib.rs`; keep internal modules
20
+ `pub(crate)` or private.
27
21
 
28
22
  ## Error handling design
29
23
 
30
- - A library crate defines its own error enum with `thiserror`, one
31
- variant per failure mode, `#[source]`/`#[from]` on any variant that
32
- wraps another error so `source()` and `?`-based conversion both work —
33
- never collapse distinct failure modes into a single `Other(String)`
34
- variant that erases the caller's ability to match on what happened.
35
- - An application/binary crate uses `anyhow::Result` at its outer layers
36
- and `.context("doing x")`/`.with_context(|| ...)` at each call to `?`
37
- that crosses a meaningful boundary, so a failure's final error chain
38
- reads as a story, not a single opaque message.
39
- - Never use a `Result<T, String>`/`Result<T, Box<dyn Error>>` as a
40
- permanent design in a library — `Box<dyn Error>` is a reasonable
41
- quick-prototype return type but forces every caller to string-match or
42
- downcast; graduate to a concrete `thiserror` enum once the error shapes
43
- stabilize.
24
+ - A library defines its own `thiserror` enum, one variant per failure mode,
25
+ `#[source]`/`#[from]` on variants wrapping another error; no single
26
+ `Other(String)` variant.
27
+ - An application/binary crate uses `anyhow::Result` at its outer layers and
28
+ `.context("doing x")`/`.with_context(|| ...)` at each `?` that crosses a
29
+ meaningful boundary.
30
+ - No `Result<T, String>`/`Result<T, Box<dyn Error>>` as a permanent library
31
+ design; `Box<dyn Error>` is for prototypes, graduate to a `thiserror` enum.
44
32
 
45
33
  ## Ownership-driven API design
46
34
 
47
- - Take `&self`/`&mut self`/`self` deliberately: `self` (by value) only
48
- when the method consumes or transforms the value into something else
49
- (a builder's terminal `.build()`), `&mut self` when it mutates in place,
50
- `&self` otherwise.
51
- - The typestate/builder pattern (a `FooBuilder` with chained `with_x`
52
- methods returning `Self`, a terminal `.build() -> Result<Foo, ...>`) for
53
- a constructor with many optional parameters, instead of a boolean-heavy
54
- positional signature.
55
- - Prefer newtypes (`struct UserId(u64);`) over a bare primitive when a
56
- value has domain meaning distinct from its representation — the
57
- compiler then rejects passing a `ProductId` where a `UserId` is
58
- expected, which a bare `u64` parameter cannot.
35
+ - `self` by value only when the method consumes the value (a builder's
36
+ `.build()`), `&mut self` to mutate, `&self` otherwise.
37
+ - Builder (`FooBuilder`, chained `with_x` returning `Self`, terminal
38
+ `.build() -> Result<Foo, ...>`) for a constructor with many optional
39
+ parameters.
40
+ - Newtypes (`struct UserId(u64);`) over a bare primitive when the value has
41
+ domain meaning.
59
42
 
60
43
  ## Trait design
61
44
 
62
- - Define a trait at the point of abstraction a consumer actually needs
63
- (an `impl Trait` argument or a generic bound), sized to the methods that
64
- consumer calls — a trait with every method the concrete type happens to
65
- have is not an abstraction, it is a restatement of the type.
66
- - Prefer generics (`fn process<T: Processor>(p: &T)`) for a hot path where
67
- monomorphization's code-size cost is acceptable and static dispatch
68
- matters; use `Box<dyn Trait>`/`&dyn Trait` when you need a heterogeneous
69
- collection or a boundary (a plugin registry, a callback list) where the
70
- concrete type varies at runtime.
45
+ - Define a trait at the abstraction a consumer needs, sized to the methods
46
+ that consumer calls, not every method the concrete type has.
47
+ - Generics (`fn process<T: Processor>(p: &T)`) for hot paths where static
48
+ dispatch matters; `Box<dyn Trait>`/`&dyn Trait` for heterogeneous
49
+ collections or boundaries where the type varies at runtime.
71
50
 
72
51
  ## Anti-patterns to flag
73
52
 
74
- - A `.clone()` inserted to make the borrow checker pass without
75
- considering whether restructuring ownership or borrowing differently
76
- would avoid the copy — flag any clone in a hot path with no comment
77
- explaining why it is necessary.
78
- - Stringly-typed errors (`Err(format!("something went wrong: {e}"))`
79
- returned as `Result<T, String>`) in a library crate instead of a
80
- `thiserror`-derived enum a caller can match on.
81
- - A "god module" (`utils`, `helpers`, `common`) accumulating unrelated
82
- free functions — split by what the code actually does, the same
83
- anti-pattern flagged in Go/Python's own pattern rules.
84
- - `unwrap()`/`expect()` reached for as a shortcut past a type error during
85
- development and never revisited before the change ships.
53
+ - A `.clone()` inserted to pass the borrow checker; flag any clone in a hot
54
+ path with no comment explaining it.
55
+ - Stringly-typed errors (`Result<T, String>`) in a library crate.
56
+ - A "god module" (`utils`, `helpers`, `common`).
57
+ - `unwrap()`/`expect()` left in as a development shortcut when the change
58
+ ships.
@@ -7,79 +7,57 @@ metadata:
7
7
 
8
8
  # Rust security
9
9
 
10
- Narrows `core-common-rules`' stack-agnostic security rules to Rust-specific,
11
- OWASP-relevant risks and the safe standard-library/ecosystem API to use
12
- instead. `unsafe` and panic-on-untrusted-input risks can appear anywhere a
13
- crate touches attacker-influenced data, so this file stays broad rather
14
- than narrowing to a single subdirectory.
10
+ Narrows `core-common-rules`' stack-agnostic security rules to Rust-specific
11
+ risks (OWASP) and the safe standard-library/ecosystem API. This file stays
12
+ broad rather than narrowing to a subdirectory, since `unsafe` and
13
+ panic-on-untrusted-input risks appear wherever a crate touches
14
+ attacker-influenced data.
15
15
 
16
16
  ## `unsafe` blocks
17
17
 
18
- - Every `unsafe` block carries a `# Safety` doc comment (on the block or
19
- the function containing it) stating the exact invariants the caller or
20
- the block itself must uphold for the operation to be sound — not a
21
- generic "this is safe" note, but the specific precondition (pointer
22
- validity, alignment, lifetime, no concurrent mutation) that makes it so.
23
- - Keep an `unsafe` block as small as possible — wrap only the operation
24
- that actually requires it (a raw pointer deref, an FFI call, a
25
- `mem::transmute`), not the surrounding safe code, so the audited surface
26
- stays minimal.
27
- - Never widen an `unsafe` block or drop its `# Safety` comment to silence
28
- a compiler or clippy complaint; if the invariant cannot be stated, the
29
- code is not actually sound and needs a different approach.
18
+ - Every `unsafe` block carries a `# Safety` doc comment stating the specific
19
+ invariants (pointer validity, alignment, lifetime, no concurrent mutation)
20
+ that make it sound.
21
+ - Keep an `unsafe` block as small as possible: wrap only the operation that
22
+ requires it (a raw pointer deref, an FFI call, `mem::transmute`).
23
+ - Never widen an `unsafe` block or drop its `# Safety` comment to silence the
24
+ compiler or clippy.
30
25
 
31
26
  ## Panics on untrusted input
32
27
 
33
- - Never call `.unwrap()`/`.expect()` on a `Result`/`Option` derived from
34
- network input, file contents, CLI arguments, or any other
35
- attacker-influenced source — a panic there is a denial-of-service vector
36
- (the process/thread aborts) even when the underlying bug is minor.
37
- Propagate with `?`, or handle explicitly.
38
- - Guard array/slice indexing on untrusted-derived indices with `.get(i)`
39
- (returns `Option`) instead of `arr[i]` (panics out of bounds); guard
40
- integer arithmetic on untrusted values with `checked_add`/`checked_mul`/
41
- `saturating_*`/`wrapping_*` as the operation's semantics require, instead
42
- of a bare `+`/`*` that panics on overflow in debug builds and silently
43
- wraps in release builds — both are wrong for a value an attacker
44
- influences.
28
+ - No `.unwrap()`/`.expect()` on a `Result`/`Option` derived from network
29
+ input, file contents, CLI arguments, or any attacker-influenced source;
30
+ propagate with `?` or handle explicitly.
31
+ - `.get(i)` instead of `arr[i]` for untrusted-derived indices;
32
+ `checked_add`/`checked_mul`/`saturating_*`/`wrapping_*` as the semantics
33
+ require instead of bare `+`/`*` on untrusted values.
45
34
 
46
35
  ## FFI boundaries
47
36
 
48
- - Validate every value crossing an `extern "C"` boundary before trusting
49
- it — a raw pointer from C is not guaranteed non-null, valid, or
50
- correctly aligned; check before dereferencing, and document the
51
- ownership/lifetime contract (who frees it, using what allocator) in the
52
- function's `# Safety` comment.
53
- - Never let a Rust panic unwind across an `extern "C"` boundary — undefined
54
- behavior in most toolchains; catch it with `std::panic::catch_unwind` at
55
- the FFI edge and convert it to an error code instead.
37
+ - Validate every value crossing an `extern "C"` boundary (null, validity,
38
+ alignment before dereferencing); document the ownership/lifetime contract
39
+ (who frees it, with which allocator) in the `# Safety` comment.
40
+ - Never let a panic unwind across an `extern "C"` boundary; catch it with
41
+ `std::panic::catch_unwind` at the FFI edge and return an error code.
56
42
 
57
43
  ## Dependency and supply-chain hygiene
58
44
 
59
- - Run `cargo audit` (or the project's already-configured equivalent) when
60
- introducing or updating a dependency, or when asked to check for known
61
- vulnerabilities — it checks `Cargo.lock` against the RustSec advisory
62
- database.
63
- - Pin dependency versions deliberately in `Cargo.toml`; avoid a bare `*`
64
- or an overly wide range that lets an unreviewed major/minor bump in.
45
+ - Run `cargo audit` (or the project's equivalent) when introducing or
46
+ updating a dependency, or when asked to check for known vulnerabilities.
47
+ - Pin dependency versions deliberately in `Cargo.toml`; no bare `*` or overly
48
+ wide range.
65
49
 
66
50
  ## Deserialization
67
51
 
68
52
  - When deserializing untrusted input with `serde`, apply size/depth limits
69
- appropriate to the format and deserializer (a bounded reader, a
70
- recursion-depth guard, or the deserializer's own limit configuration
71
- where it exposes one) — an unbounded deserialize of attacker-controlled
72
- JSON/bincode/etc. is a memory-exhaustion or stack-overflow
73
- (deeply-nested structures) vector.
74
- - Never derive `Deserialize` for a type and then trust its field values
75
- as pre-validated — validate ranges/formats/invariants after
76
- deserializing, the same as any other externally-sourced value.
53
+ appropriate to the format (bounded reader, recursion-depth guard, the
54
+ deserializer's own limit configuration).
55
+ - Do not trust a `Deserialize`d type's field values as pre-validated;
56
+ validate ranges/formats/invariants afterwards.
77
57
 
78
58
  ## Randomness and secrets
79
59
 
80
- - Use a CSPRNG (the `rand` crate's default `ThreadRng`/`OsRng`, or the
81
- `getrandom`/`ring` crates) for anything security-sensitive — tokens,
82
- session IDs, keys, nonces; a non-cryptographic PRNG seeded predictably
83
- is unsuitable for secrets even when its API looks the same.
84
- - Never hard-code a credential, API key, or signing secret in source; load
85
- it from environment/secret storage the project already uses.
60
+ - A CSPRNG (`rand`'s `ThreadRng`/`OsRng`, `getrandom`, `ring`) for tokens,
61
+ session IDs, keys, nonces.
62
+ - No hard-coded credential, API key, or signing secret; load from the
63
+ environment/secret storage the project already uses.