@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.
- package/dist/cli.js +4916 -3655
- package/dist/core.js +91 -28
- package/dist/keryx-general-worker-entry.js +413 -240
- package/package.json +1 -1
- package/src/gdskills/bundled/install-manifest.json +3 -0
- package/src/gdskills/bundled/rules/core/api-contracts.mdc +21 -136
- package/src/gdskills/bundled/rules/core/async-patterns.mdc +18 -171
- package/src/gdskills/bundled/rules/core/clean-architecture.mdc +40 -150
- package/src/gdskills/bundled/rules/core/cli-interface-design.mdc +63 -194
- package/src/gdskills/bundled/rules/core/code-style-patterns.mdc +36 -48
- package/src/gdskills/bundled/rules/core/concurrency-patterns.mdc +32 -0
- package/src/gdskills/bundled/rules/core/database-patterns.mdc +26 -148
- package/src/gdskills/bundled/rules/core/error-handling.mdc +57 -109
- package/src/gdskills/bundled/rules/core/frontend-assistant.mdc +14 -29
- package/src/gdskills/bundled/rules/core/layout-rendering.mdc +51 -0
- package/src/gdskills/bundled/rules/core/mobx-store-template.mdc +69 -511
- package/src/gdskills/bundled/rules/core/nestjs-dto.mdc +18 -36
- package/src/gdskills/bundled/rules/core/playwright-testing.mdc +35 -308
- package/src/gdskills/bundled/rules/core/security-baseline.mdc +18 -140
- package/src/gdskills/bundled/rules/core/skill-authoring.mdc +190 -0
- package/src/gdskills/bundled/rules/core/skills-storage-workflow.mdc +5 -0
- package/src/gdskills/bundled/rules/core/solid-principles.mdc +70 -121
- package/src/gdskills/bundled/rules/core/storybook-guidelines.mdc +20 -22
- package/src/gdskills/bundled/rules/core/tdd-workflow.mdc +37 -74
- package/src/gdskills/bundled/rules/core/ui-anti-slop.mdc +48 -37
- package/src/gdskills/bundled/skills/orchestration/task-implementer/SKILL.md +2 -2
- package/src/gdskills/bundled/skills/quality/deprecation-path/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/quality/tests-creator/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-architecture/SKILL.md +25 -61
- package/src/gdskills/bundled/skills/review/review-backend/SKILL.md +15 -69
- package/src/gdskills/bundled/skills/review/review-clean-code/SKILL.md +84 -418
- package/src/gdskills/bundled/skills/review/review-core-boundaries/SKILL.md +2 -2
- package/src/gdskills/bundled/skills/review/review-degradation/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-flow-graph/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-frontend/SKILL.md +17 -311
- package/src/gdskills/bundled/skills/review/review-frontend-conventions/SKILL.md +8 -22
- package/src/gdskills/bundled/skills/review/review-highload/SKILL.md +84 -228
- package/src/gdskills/bundled/skills/review/review-layout/SKILL.md +22 -28
- package/src/gdskills/bundled/skills/review/review-logic/SKILL.md +9 -10
- package/src/gdskills/bundled/skills/review/review-performance/SKILL.md +16 -38
- package/src/gdskills/bundled/skills/review/review-premise/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-regression/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-security-code/SKILL.md +8 -8
- package/src/gdskills/bundled/skills/review/review-style/SKILL.md +49 -88
- package/src/gdskills/bundled/skills/review/review-testing-practices/SKILL.md +22 -40
- package/src/gdskills/bundled/skills/review/review-ui-ux/SKILL.md +42 -82
- package/src/gdskills/bundled/stacks/angular/rules/coding-style.mdc +15 -57
- package/src/gdskills/bundled/stacks/angular/rules/patterns.mdc +16 -60
- package/src/gdskills/bundled/stacks/angular/rules/security.mdc +11 -49
- package/src/gdskills/bundled/stacks/angular/rules/testing.mdc +13 -52
- package/src/gdskills/bundled/stacks/c-cpp/rules/coding-style.mdc +33 -57
- package/src/gdskills/bundled/stacks/c-cpp/rules/patterns.mdc +35 -62
- package/src/gdskills/bundled/stacks/c-cpp/rules/security.mdc +35 -62
- package/src/gdskills/bundled/stacks/c-cpp/rules/testing.mdc +34 -54
- package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/patterns.mdc +27 -56
- package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/security.mdc +51 -119
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/coding-style.mdc +42 -74
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/patterns.mdc +45 -83
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/security.mdc +34 -59
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/testing.mdc +33 -62
- package/src/gdskills/bundled/stacks/django/rules/coding-style.mdc +15 -56
- package/src/gdskills/bundled/stacks/django/rules/patterns.mdc +16 -68
- package/src/gdskills/bundled/stacks/django/rules/security.mdc +13 -71
- package/src/gdskills/bundled/stacks/django/rules/testing.mdc +16 -62
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/coding-style.mdc +30 -53
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/patterns.mdc +20 -56
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/security.mdc +52 -122
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/testing.mdc +23 -42
- package/src/gdskills/bundled/stacks/fastapi/rules/coding-style.mdc +13 -47
- package/src/gdskills/bundled/stacks/fastapi/rules/patterns.mdc +18 -81
- package/src/gdskills/bundled/stacks/fastapi/rules/security.mdc +13 -75
- package/src/gdskills/bundled/stacks/fastapi/rules/testing.mdc +14 -58
- package/src/gdskills/bundled/stacks/flutter-dart/rules/coding-style.mdc +36 -74
- package/src/gdskills/bundled/stacks/flutter-dart/rules/patterns.mdc +30 -66
- package/src/gdskills/bundled/stacks/flutter-dart/rules/security.mdc +33 -67
- package/src/gdskills/bundled/stacks/flutter-dart/rules/testing.mdc +41 -73
- package/src/gdskills/bundled/stacks/go/rules/coding-style.mdc +36 -57
- package/src/gdskills/bundled/stacks/go/rules/patterns.mdc +27 -42
- package/src/gdskills/bundled/stacks/go/rules/security.mdc +26 -43
- package/src/gdskills/bundled/stacks/go/rules/testing.mdc +23 -41
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/coding-style.mdc +21 -40
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/patterns.mdc +26 -43
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/security.mdc +25 -37
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/testing.mdc +34 -50
- package/src/gdskills/bundled/stacks/kotlin-android/rules/coding-style.mdc +28 -65
- package/src/gdskills/bundled/stacks/kotlin-android/rules/patterns.mdc +34 -78
- package/src/gdskills/bundled/stacks/kotlin-android/rules/security.mdc +35 -68
- package/src/gdskills/bundled/stacks/kotlin-android/rules/testing.mdc +34 -68
- package/src/gdskills/bundled/stacks/mobx/rules/coding-style.mdc +18 -64
- package/src/gdskills/bundled/stacks/mobx/rules/patterns.mdc +13 -66
- package/src/gdskills/bundled/stacks/mobx/rules/security.mdc +8 -35
- package/src/gdskills/bundled/stacks/mobx/rules/testing.mdc +10 -39
- package/src/gdskills/bundled/stacks/nestjs/rules/coding-style.mdc +32 -45
- package/src/gdskills/bundled/stacks/nestjs/rules/patterns.mdc +40 -60
- package/src/gdskills/bundled/stacks/nestjs/rules/security.mdc +30 -50
- package/src/gdskills/bundled/stacks/nestjs/rules/testing.mdc +27 -47
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/coding-style.mdc +14 -48
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/patterns.mdc +15 -67
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/security.mdc +12 -50
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/testing.mdc +11 -43
- package/src/gdskills/bundled/stacks/php-laravel/rules/coding-style.mdc +17 -58
- package/src/gdskills/bundled/stacks/php-laravel/rules/patterns.mdc +15 -56
- package/src/gdskills/bundled/stacks/php-laravel/rules/security.mdc +13 -50
- package/src/gdskills/bundled/stacks/php-laravel/rules/testing.mdc +14 -55
- package/src/gdskills/bundled/stacks/python/rules/coding-style.mdc +13 -41
- package/src/gdskills/bundled/stacks/python/rules/patterns.mdc +20 -61
- package/src/gdskills/bundled/stacks/python/rules/security.mdc +15 -57
- package/src/gdskills/bundled/stacks/python/rules/testing.mdc +16 -50
- package/src/gdskills/bundled/stacks/react/rules/coding-style.mdc +14 -40
- package/src/gdskills/bundled/stacks/react/rules/patterns.mdc +15 -55
- package/src/gdskills/bundled/stacks/react/rules/security.mdc +13 -49
- package/src/gdskills/bundled/stacks/react/rules/testing.mdc +10 -37
- package/src/gdskills/bundled/stacks/ruby-rails/rules/coding-style.mdc +15 -48
- package/src/gdskills/bundled/stacks/ruby-rails/rules/patterns.mdc +18 -67
- package/src/gdskills/bundled/stacks/ruby-rails/rules/security.mdc +11 -60
- package/src/gdskills/bundled/stacks/ruby-rails/rules/testing.mdc +14 -65
- package/src/gdskills/bundled/stacks/rust/rules/coding-style.mdc +39 -65
- package/src/gdskills/bundled/stacks/rust/rules/patterns.mdc +33 -60
- package/src/gdskills/bundled/stacks/rust/rules/security.mdc +35 -57
- package/src/gdskills/bundled/stacks/rust/rules/testing.mdc +29 -52
- package/src/gdskills/bundled/stacks/sql-db/rules/coding-style.mdc +12 -48
- package/src/gdskills/bundled/stacks/sql-db/rules/patterns.mdc +22 -113
- package/src/gdskills/bundled/stacks/sql-db/rules/security.mdc +11 -56
- package/src/gdskills/bundled/stacks/sql-db/rules/testing.mdc +14 -59
- package/src/gdskills/bundled/stacks/swift-ios/rules/coding-style.mdc +29 -65
- package/src/gdskills/bundled/stacks/swift-ios/rules/patterns.mdc +41 -88
- package/src/gdskills/bundled/stacks/swift-ios/rules/security.mdc +28 -53
- package/src/gdskills/bundled/stacks/swift-ios/rules/testing.mdc +32 -65
- package/src/gdskills/bundled/stacks/vue/rules/coding-style.mdc +17 -52
- package/src/gdskills/bundled/stacks/vue/rules/patterns.mdc +17 -63
- package/src/gdskills/bundled/stacks/vue/rules/security.mdc +11 -41
- package/src/gdskills/bundled/stacks/vue/rules/testing.mdc +16 -48
|
@@ -7,67 +7,28 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# Angular testing
|
|
9
9
|
|
|
10
|
-
Test layout, runner, and fixture conventions for Angular
|
|
11
|
-
|
|
12
|
-
`TestBed`-based Angular idiom.
|
|
10
|
+
Test layout, runner, and fixture conventions for Angular, narrowing the
|
|
11
|
+
common testing rules to `TestBed`-based idiom.
|
|
13
12
|
|
|
14
13
|
## Layout and runner
|
|
15
14
|
|
|
16
|
-
- Co-locate a unit test with its source (`order-summary.ts`
|
|
17
|
-
|
|
18
|
-
spec files already do; do not invent a parallel `__tests__/` tree in an
|
|
19
|
-
Angular CLI project that uses co-located `.spec.ts` files.
|
|
20
|
-
- Run the project's configured runner (`ng test`, or a Jest/Vitest setup if
|
|
21
|
-
the project has migrated off Karma) rather than assuming Karma is
|
|
22
|
-
present — check `angular.json`'s `test` builder or the project's
|
|
23
|
-
`package.json` `test` script before invoking a specific runner by name.
|
|
15
|
+
- Co-locate a unit test with its source (`order-summary.spec.ts` beside `order-summary.ts`), matching existing spec files; no parallel `__tests__/` tree in a CLI project with co-located specs.
|
|
16
|
+
- Run the project's configured runner (`ng test`, or Jest/Vitest if migrated off Karma); check `angular.json`'s `test` builder or `package.json` before naming a runner.
|
|
24
17
|
|
|
25
18
|
## Component tests
|
|
26
19
|
|
|
27
|
-
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
- Set signal-based inputs through `fixture.componentRef.setInput('name',
|
|
32
|
-
value)`, not by assigning the component instance's field directly —
|
|
33
|
-
direct field assignment on a signal input does not go through Angular's
|
|
34
|
-
input-binding machinery and can silently not reflect in the template the
|
|
35
|
-
way a real caller's binding would.
|
|
36
|
-
- After a change that affects the DOM (setting an input, clicking a
|
|
37
|
-
button, resolving a promise/observable the component depends on), call
|
|
38
|
-
`fixture.detectChanges()` (or `await fixture.whenStable()` for
|
|
39
|
-
async work) before asserting on the rendered DOM — an assertion made
|
|
40
|
-
before change detection runs reads stale markup.
|
|
41
|
-
- Query the DOM through `fixture.debugElement.query(By.css(...))` /
|
|
42
|
-
`By.directive(...)`, or `fixture.nativeElement.querySelector(...)` for
|
|
43
|
-
plain DOM assertions — prefer a stable selector (a `data-testid`, a
|
|
44
|
-
semantic role/label) over a CSS class that styling changes could break.
|
|
20
|
+
- Use `TestBed.configureTestingModule` with the standalone component in `imports`, then `TestBed.createComponent`.
|
|
21
|
+
- Set signal-based inputs with `fixture.componentRef.setInput('name', value)`, not by assigning the instance field.
|
|
22
|
+
- Call `fixture.detectChanges()` (or `await fixture.whenStable()` for async work) before asserting on the DOM.
|
|
23
|
+
- Query with `fixture.debugElement.query(By.css(...))`/`By.directive(...)` or `fixture.nativeElement.querySelector(...)`; prefer a stable selector (`data-testid`, role/label) over a styling class.
|
|
45
24
|
|
|
46
25
|
## Services, HTTP, and doubles
|
|
47
26
|
|
|
48
|
-
- Test
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
instance.
|
|
52
|
-
- Mock `HttpClient`-backed calls with `provideHttpClientTesting()` /
|
|
53
|
-
`HttpTestingController` (`expectOne`, `.flush(...)`) rather than a
|
|
54
|
-
hand-rolled fetch stub — it verifies the exact request was made and lets
|
|
55
|
-
the test control the exact response, and `httpTestingController.verify()`
|
|
56
|
-
at the end of each test catches an unexpected extra request.
|
|
57
|
-
- Stub a genuinely external dependency (a third-party SDK, `window`/
|
|
58
|
-
browser APIs the test environment can't provide) at that boundary via
|
|
59
|
-
Angular's provider overrides (`TestBed.overrideProvider`) — do not mock
|
|
60
|
-
the component's own signals/services, which is what the test is supposed
|
|
61
|
-
to exercise.
|
|
27
|
+
- Test a service through `TestBed.inject(MyService)` (or direct instantiation if it has no dependencies), not through a component's private field.
|
|
28
|
+
- Mock HTTP with `provideHttpClientTesting()`/`HttpTestingController` (`expectOne`, `.flush(...)`), not a hand-rolled fetch stub; call `httpTestingController.verify()` at the end of each test.
|
|
29
|
+
- Stub external dependencies (third-party SDK, browser APIs the environment lacks) at the boundary with `TestBed.overrideProvider`; do not mock the component's own signals/services.
|
|
62
30
|
|
|
63
31
|
## Determinism
|
|
64
32
|
|
|
65
|
-
- Prefer `fakeAsync`/`tick()` (or `waitForAsync`) over
|
|
66
|
-
|
|
67
|
-
timers/microtasks explicitly rather than adding an arbitrary `tick(1000)`
|
|
68
|
-
guess.
|
|
69
|
-
- Reset any shared test state (a spy's call count, a `TestBed` module
|
|
70
|
-
configured with `teardown: { destroyAfterEach: true }`, which is
|
|
71
|
-
Angular's own default) between tests so one spec's setup cannot leak
|
|
72
|
-
into the next — do not disable that default teardown to "fix" a
|
|
73
|
-
cross-test leak instead of finding the actual shared state.
|
|
33
|
+
- Prefer `fakeAsync`/`tick()` (or `waitForAsync`) over real `setTimeout`; flush timers explicitly, not with an arbitrary `tick(1000)`.
|
|
34
|
+
- Reset shared test state between tests; keep `TestBed`'s default `teardown: { destroyAfterEach: true }` and do not disable it to hide a cross-test leak.
|
|
@@ -8,73 +8,49 @@ metadata:
|
|
|
8
8
|
# C / C++ coding style
|
|
9
9
|
|
|
10
10
|
Narrows `core-common-rules`' stack-agnostic style rules to modern C++
|
|
11
|
-
(17/20/23) and modern C idiom. Applies to
|
|
12
|
-
`.cpp`/`.cc`/`.cxx`/`.hpp`/`.hxx` files
|
|
13
|
-
still comes from the common rules this file `extends`.
|
|
11
|
+
(17/20/23) and modern C idiom, following the C++ Core Guidelines. Applies to
|
|
12
|
+
both `.c`/`.h` and `.cpp`/`.cc`/`.cxx`/`.hpp`/`.hxx` files.
|
|
14
13
|
|
|
15
14
|
## Naming and structure
|
|
16
15
|
|
|
17
16
|
- `snake_case` for functions, variables, and namespaces; `PascalCase` for
|
|
18
|
-
types
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
to pull in transitively.
|
|
25
|
-
- One translation unit's private helpers go in an anonymous namespace
|
|
26
|
-
(C++) or are declared `static` (C) — do not give internal linkage away
|
|
27
|
-
by leaving a file-local helper externally visible.
|
|
28
|
-
- An identifier's name shrinks with its scope: a loop index is `i`, a
|
|
29
|
-
header-exposed public function gets a full descriptive name.
|
|
17
|
+
types; `SCREAMING_SNAKE_CASE` for macros and compile-time constants; an
|
|
18
|
+
established project convention wins over this default.
|
|
19
|
+
- A header is self-contained: `#pragma once` (or a project-consistent include
|
|
20
|
+
guard) and every symbol it uses `#include`d, not pulled in transitively.
|
|
21
|
+
- A translation unit's private helpers go in an anonymous namespace (C++) or
|
|
22
|
+
are `static` (C).
|
|
30
23
|
|
|
31
24
|
## Modern C++ idiom (17/20/23)
|
|
32
25
|
|
|
33
|
-
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
by-value and `std::move` into place, or take an rvalue-reference
|
|
47
|
-
overload, rather than accepting `const&` and copying when the caller's
|
|
48
|
-
object was about to be discarded anyway.
|
|
49
|
-
- Prefer a range-`for` or a `<ranges>` (C++20) pipeline over a manual
|
|
50
|
-
index loop or raw iterator pair when the loop is a plain traversal —
|
|
51
|
-
keep the manual iterator form for cases that need the iterator itself
|
|
52
|
-
(insertion position, mutation while iterating with an explicit
|
|
53
|
-
erase-returns-next-iterator pattern).
|
|
54
|
-
- `constexpr`/`consteval` any function or value that can be computed at
|
|
55
|
-
compile time; `const` (or nothing, per project convention) otherwise —
|
|
56
|
-
do not default to `#define` for a typed constant.
|
|
26
|
+
- `std::unique_ptr` by default; `std::shared_ptr` only for genuinely shared
|
|
27
|
+
ownership.
|
|
28
|
+
- `std::make_unique`/`std::make_shared` over a bare `new` passed to a smart
|
|
29
|
+
pointer constructor.
|
|
30
|
+
- `std::span` (C++20) for a non-owning view over a contiguous range instead
|
|
31
|
+
of a raw `(pointer, length)` pair.
|
|
32
|
+
- Move, don't copy, when ownership transfers: by-value plus `std::move`, or
|
|
33
|
+
an rvalue-reference overload.
|
|
34
|
+
- Range-`for` or `<ranges>` (C++20) over a manual index loop for plain
|
|
35
|
+
traversal; keep the manual iterator form where the iterator itself is
|
|
36
|
+
needed.
|
|
37
|
+
- `constexpr`/`consteval` for anything computable at compile time; no
|
|
38
|
+
`#define` for a typed constant.
|
|
57
39
|
|
|
58
40
|
## Modern C safety practices
|
|
59
41
|
|
|
60
|
-
-
|
|
61
|
-
`
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
-
|
|
68
|
-
|
|
69
|
-
carried only in a comment.
|
|
70
|
-
- Const-qualify a pointer parameter the function does not mutate through
|
|
71
|
-
(`const char *`, not `char *`) — it documents the contract and lets the
|
|
72
|
-
compiler catch an accidental write.
|
|
42
|
+
- `snprintf`, not `sprintf`; `strncpy`/explicit length checks, not
|
|
43
|
+
`strcpy`/`strcat`; `fgets`, never `gets`; every buffer write states or
|
|
44
|
+
checks its destination's capacity.
|
|
45
|
+
- Check every `malloc`/`calloc`/`realloc` return for `NULL`; on `realloc`
|
|
46
|
+
failure keep the original pointer.
|
|
47
|
+
- C99 designated initializers and fixed arrays with an explicit, checked
|
|
48
|
+
bound over a raw pointer with a length carried in a comment.
|
|
49
|
+
- `const`-qualify a pointer parameter the function does not mutate through
|
|
50
|
+
(`const char *`).
|
|
73
51
|
|
|
74
52
|
## Formatting
|
|
75
53
|
|
|
76
|
-
- Format with the project's
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
- Braces and brace-placement follow the project's existing style over any
|
|
80
|
-
default preference in this file — match neighboring code.
|
|
54
|
+
- Format with the project's `clang-format`/`.clang-format` if present; do
|
|
55
|
+
not hand-format around it.
|
|
56
|
+
- Brace placement follows the project's existing style.
|
|
@@ -8,80 +8,53 @@ metadata:
|
|
|
8
8
|
# C / C++ patterns
|
|
9
9
|
|
|
10
10
|
Narrows `core-common-rules`' stack-agnostic design guidance to idiomatic
|
|
11
|
-
C/C++ ownership
|
|
12
|
-
|
|
11
|
+
C/C++ ownership and resource management (C++ Core Guidelines). Applies to
|
|
12
|
+
both C and C++ files.
|
|
13
13
|
|
|
14
14
|
## RAII and ownership (C++)
|
|
15
15
|
|
|
16
|
-
- Every resource (heap memory,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
or
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
define all five, or `= delete` the ones that should not exist).
|
|
27
|
-
- A function that hands back a resource does so by return value (RVO/move
|
|
28
|
-
makes this free), not by an out-parameter raw pointer the caller must
|
|
29
|
-
remember to release.
|
|
30
|
-
- Never return a pointer or reference to a local (stack) variable, or to a
|
|
31
|
-
member of a temporary — the referent is destroyed when the function
|
|
32
|
-
returns, and the caller is left with a dangling reference.
|
|
16
|
+
- Every resource (heap memory, file handle, mutex lock, socket) is owned by
|
|
17
|
+
exactly one object whose destructor releases it; no hand-written `new`/
|
|
18
|
+
`delete` pair. Use a smart pointer, `std::lock_guard`/`std::unique_lock`,
|
|
19
|
+
or another RAII type.
|
|
20
|
+
- Rule of Zero by default; when a class must own a resource directly, Rule
|
|
21
|
+
of Five (define all five special members, or `= delete` the unwanted
|
|
22
|
+
ones).
|
|
23
|
+
- Hand a resource back by return value, not by an out-parameter raw pointer.
|
|
24
|
+
- Never return a pointer or reference to a local variable or a member of a
|
|
25
|
+
temporary.
|
|
33
26
|
|
|
34
27
|
## Manual resource management (C)
|
|
35
28
|
|
|
36
|
-
- Pair every `malloc`/`fopen`/`pthread_mutex_lock`-style acquire with
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
-
|
|
42
|
-
|
|
43
|
-
API with no stated ownership contract is a leak or a double-free
|
|
44
|
-
waiting to happen at the call site.
|
|
45
|
-
- Never call `free` on a pointer twice, and set a pointer to `NULL`
|
|
46
|
-
immediately after freeing it when it could otherwise be read or freed
|
|
47
|
-
again on a later path — a double-free and a use-after-free are both
|
|
48
|
-
more likely once a stale non-null value survives past its `free`.
|
|
29
|
+
- Pair every `malloc`/`fopen`/`pthread_mutex_lock`-style acquire with its
|
|
30
|
+
release on every exit path, error paths included; use a `goto cleanup;`
|
|
31
|
+
single exit-and-release block.
|
|
32
|
+
- A function that allocates and returns a pointer documents in its header
|
|
33
|
+
comment who owns the result and how to release it.
|
|
34
|
+
- Never `free` a pointer twice; set a pointer to `NULL` right after freeing
|
|
35
|
+
it when it could be read or freed again on a later path.
|
|
49
36
|
|
|
50
37
|
## Containers and iterators
|
|
51
38
|
|
|
52
|
-
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
- Prefer `std::vector`/`std::array`/`std::string` over a raw
|
|
58
|
-
owning array or a hand-rolled dynamic buffer — the standard container
|
|
59
|
-
already manages growth, bounds, and destruction correctly.
|
|
39
|
+
- Do not hold an iterator, pointer, or reference into a `std::vector` across
|
|
40
|
+
`push_back` past capacity, `insert`, or `erase`; re-fetch it or use the
|
|
41
|
+
iterator `erase`/`insert` return.
|
|
42
|
+
- `std::vector`/`std::array`/`std::string` over a raw owning array or
|
|
43
|
+
hand-rolled dynamic buffer.
|
|
60
44
|
|
|
61
45
|
## Composition and interfaces
|
|
62
46
|
|
|
63
|
-
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
`virtual`) destructor — a non-virtual destructor on a polymorphic base
|
|
70
|
-
is undefined behavior when deleting through the base pointer.
|
|
71
|
-
- Keep a public C API's surface small and its ownership rules explicit in
|
|
72
|
-
the header; do not expose an internal struct's full layout when an
|
|
73
|
-
opaque handle plus accessor functions would let the implementation
|
|
74
|
-
change without breaking callers.
|
|
47
|
+
- Composition over deep inheritance; polymorphism only when callers must
|
|
48
|
+
treat different concrete types uniformly.
|
|
49
|
+
- A polymorphic C++ base class has a `virtual` destructor.
|
|
50
|
+
- A public C API keeps its surface small with ownership rules explicit in the
|
|
51
|
+
header; prefer an opaque handle plus accessors over exposing a struct's
|
|
52
|
+
layout.
|
|
75
53
|
|
|
76
54
|
## Anti-patterns to flag
|
|
77
55
|
|
|
78
|
-
- A "god header"
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
-
|
|
82
|
-
(
|
|
83
|
-
which conversion is actually intended and let the compiler catch the
|
|
84
|
-
wrong one.
|
|
85
|
-
- Output parameters used to fake multiple return values where
|
|
86
|
-
`std::tuple`/`std::pair`/a small struct (or, in C, a returned struct)
|
|
87
|
-
would be clearer and harder to call incorrectly.
|
|
56
|
+
- A "god header" (`utils.h`, `common.h`).
|
|
57
|
+
- C-style casts (`(Type)x`) in C++; use `static_cast`/`dynamic_cast`/
|
|
58
|
+
`const_cast`/`reinterpret_cast`.
|
|
59
|
+
- Output parameters faking multiple return values where `std::tuple`/
|
|
60
|
+
`std::pair`/a small struct (in C, a returned struct) fits.
|
|
@@ -8,83 +8,56 @@ metadata:
|
|
|
8
8
|
# C / C++ security
|
|
9
9
|
|
|
10
10
|
Narrows `core-common-rules`' stack-agnostic security rules to C/C++
|
|
11
|
-
memory-safety and undefined-behavior risks, and the sanitizers/safe APIs
|
|
12
|
-
|
|
11
|
+
memory-safety and undefined-behavior risks, and the sanitizers/safe APIs to
|
|
12
|
+
use. Applies to both C and C++ files.
|
|
13
13
|
|
|
14
14
|
## Memory safety
|
|
15
15
|
|
|
16
|
-
- Never dereference, write through, or `free` a pointer after it
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
- Never `free`/`delete` the same pointer twice (double-free) — a
|
|
21
|
-
freed-and-nulled pointer makes a second `free`/`delete` a harmless
|
|
22
|
-
no-op instead of heap corruption.
|
|
16
|
+
- Never dereference, write through, or `free` a pointer after it was freed or
|
|
17
|
+
left scope (use-after-free); set a freed pointer to `NULL` when it could be
|
|
18
|
+
read again.
|
|
19
|
+
- Never `free`/`delete` the same pointer twice.
|
|
23
20
|
- Bounds-check every array/buffer index and every pointer arithmetic
|
|
24
|
-
expression built from untrusted input before it
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
is not already statically known to fit the destination — use
|
|
29
|
-
`snprintf`, a length-checked copy, or a `std::string`/`std::vector`
|
|
30
|
-
that manages its own capacity.
|
|
21
|
+
expression built from untrusted input before it reads or writes memory.
|
|
22
|
+
- Never `strcpy`, `strcat`, `sprintf`, or `gets` on data not statically known
|
|
23
|
+
to fit; use `snprintf`, a length-checked copy, or `std::string`/
|
|
24
|
+
`std::vector`.
|
|
31
25
|
|
|
32
26
|
## Undefined behavior
|
|
33
27
|
|
|
34
|
-
- Signed integer overflow is
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
value happened to be left on the stack or heap.
|
|
43
|
-
- Never access an object through a pointer of an incompatible type (a
|
|
44
|
-
strict-aliasing violation) — use `memcpy` for a type-punning copy, or
|
|
45
|
-
(C++20+) `std::bit_cast`, instead of reinterpreting a pointer's type
|
|
46
|
-
and dereferencing it.
|
|
47
|
-
- Do not read past the end of an array via pointer arithmetic even when
|
|
48
|
-
the read "usually" lands in valid memory — an out-of-bounds read past
|
|
49
|
-
the last element is undefined behavior regardless of what happens to be
|
|
50
|
-
mapped there.
|
|
28
|
+
- Signed integer overflow is UB (unsigned wraparound is not): check bounds
|
|
29
|
+
before a signed addition/multiplication, or use an unsigned/wider type or a
|
|
30
|
+
checked-arithmetic helper, for size computations from untrusted input.
|
|
31
|
+
- Never read an uninitialized local or heap allocation; value-initialize
|
|
32
|
+
(`Type x{};` in C++, `= 0`/`memset` in C).
|
|
33
|
+
- No strict-aliasing violations; use `memcpy`, or `std::bit_cast` (C++20+),
|
|
34
|
+
for type punning.
|
|
35
|
+
- No out-of-bounds read past the last element via pointer arithmetic.
|
|
51
36
|
|
|
52
37
|
## Concurrency
|
|
53
38
|
|
|
54
|
-
- Every variable read
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
deadlock; prefer `std::lock_guard`/`std::scoped_lock` (which also
|
|
60
|
-
supports locking multiple mutexes deadlock-free in one call) over
|
|
61
|
-
manual `lock()`/`unlock()` pairs, since a manual pair skips the unlock
|
|
62
|
-
on an early return or exception.
|
|
39
|
+
- Every variable read by more than one thread while one writes it is guarded
|
|
40
|
+
by a mutex or is `std::atomic`/C11 `_Atomic`.
|
|
41
|
+
- Acquire locks in a consistent global order; prefer `std::lock_guard`/
|
|
42
|
+
`std::scoped_lock` (the latter locks several mutexes deadlock-free) over
|
|
43
|
+
manual `lock()`/`unlock()` pairs.
|
|
63
44
|
|
|
64
45
|
## Sanitizers
|
|
65
46
|
|
|
66
47
|
- Build and run with AddressSanitizer + UndefinedBehaviorSanitizer
|
|
67
48
|
(`-fsanitize=address,undefined -fno-omit-frame-pointer -g`, Clang/GCC)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
-
|
|
74
|
-
|
|
75
|
-
one build — whenever investigating a suspected data race or before
|
|
76
|
-
trusting a fix for one.
|
|
77
|
-
- A memory-safety, UB, or concurrency bug report is not actually verified
|
|
78
|
-
fixed until it has been reproduced and re-run under the relevant
|
|
79
|
-
sanitizer and comes back clean; a fix that only "looks right" by
|
|
80
|
-
inspection, or that only passes without a sanitizer attached, has not
|
|
81
|
-
been verified.
|
|
49
|
+
when investigating a memory-safety or UB report, or before trusting a fix
|
|
50
|
+
for one.
|
|
51
|
+
- Build and run with ThreadSanitizer (`-fsanitize=thread`) as a separate
|
|
52
|
+
binary from ASan/UBSan, since the runtimes are not composable, when
|
|
53
|
+
investigating a data race or before trusting a fix for one.
|
|
54
|
+
- A memory-safety, UB, or concurrency bug is not verified fixed until it is
|
|
55
|
+
reproduced and re-run clean under the relevant sanitizer.
|
|
82
56
|
|
|
83
57
|
## Dependency and input hygiene
|
|
84
58
|
|
|
85
|
-
- Validate the length/format of any externally-sourced buffer (network,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
load it from environment/secret storage the project already uses.
|
|
59
|
+
- Validate the length/format of any externally-sourced buffer (network, file,
|
|
60
|
+
IPC, command-line argument) before parsing; check a length field in the
|
|
61
|
+
input against the buffer's actual size.
|
|
62
|
+
- No hard-coded credential, API key, or signing secret; load from the
|
|
63
|
+
environment/secret storage the project already uses.
|
|
@@ -7,77 +7,57 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# C / C++ testing
|
|
9
9
|
|
|
10
|
-
Narrows `core-common-rules`' stack-agnostic testing rules to GoogleTest
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
Narrows `core-common-rules`' stack-agnostic testing rules to GoogleTest (and
|
|
11
|
+
Catch2, where a project already uses it) plus sanitizer-backed verification.
|
|
12
|
+
Applies to both C and C++ test files.
|
|
13
13
|
|
|
14
14
|
## Layout and naming
|
|
15
15
|
|
|
16
|
-
- Tests live
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
- `TEST_P` with `INSTANTIATE_TEST_SUITE_P` for a parameterized case run
|
|
25
|
-
against a range of inputs, instead of copy-pasting the same body with
|
|
26
|
-
different literals across several `TEST`s.
|
|
16
|
+
- Tests live in the project's existing test tree (`tests/`, `test/`, or
|
|
17
|
+
beside the source with a `_test.cpp` suffix); do not invent a second
|
|
18
|
+
convention.
|
|
19
|
+
- `TEST(SuiteName, CaseName)` standalone; `TEST_F(FixtureName, CaseName)` for
|
|
20
|
+
shared `SetUp()`/`TearDown()` state. Name for the behavior, not
|
|
21
|
+
`Test1`/`Test2`.
|
|
22
|
+
- `TEST_P` with `INSTANTIATE_TEST_SUITE_P` for a case run against a range of
|
|
23
|
+
inputs.
|
|
27
24
|
|
|
28
25
|
## Fixtures and lifecycle
|
|
29
26
|
|
|
30
|
-
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
- A fixture that owns a resource (a temp file, a mock server, a thread)
|
|
35
|
-
releases it in `TearDown()` even when the test body fails an assertion
|
|
36
|
-
partway through — do not rely on a `TEST_F` body reaching a cleanup
|
|
37
|
-
statement at its end.
|
|
27
|
+
- Per-test setup that can fail in `SetUp()`, teardown in `TearDown()`, not
|
|
28
|
+
the fixture's constructor/destructor.
|
|
29
|
+
- A fixture owning a resource (temp file, mock server, thread) releases it in
|
|
30
|
+
`TearDown()` even when the body fails partway.
|
|
38
31
|
|
|
39
32
|
## Assertions
|
|
40
33
|
|
|
41
|
-
- `ASSERT_*` when the test cannot
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
configured style) when the test binary is multi-threaded, since the
|
|
49
|
-
default `fast` style can misbehave by forking a process with more than
|
|
50
|
-
one live thread.
|
|
51
|
-
- Compare floating-point values with `EXPECT_NEAR`/`EXPECT_FLOAT_EQ`, not
|
|
52
|
-
`EXPECT_EQ`, unless the value is provably exact (an integer-valued
|
|
53
|
-
computation stored in a float).
|
|
34
|
+
- `ASSERT_*` when the test cannot continue after a failure; `EXPECT_*` when
|
|
35
|
+
later checks still give information.
|
|
36
|
+
- `ASSERT_DEATH`/`EXPECT_DEATH` for code whose contract is to terminate; set
|
|
37
|
+
`GTEST_FLAG_SET(death_test_style, "threadsafe")` (or the project's style)
|
|
38
|
+
when the binary is multi-threaded.
|
|
39
|
+
- `EXPECT_NEAR`/`EXPECT_FLOAT_EQ` for floating point, not `EXPECT_EQ`, unless
|
|
40
|
+
the value is provably exact.
|
|
54
41
|
|
|
55
42
|
## Determinism and concurrency
|
|
56
43
|
|
|
57
44
|
- Never synchronize a multi-threaded test with `sleep`/`usleep`/
|
|
58
|
-
`std::this_thread::sleep_for
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
(`-fsanitize=thread`) at least once before being trusted, since a data
|
|
63
|
-
race can pass every assertion while still being undefined behavior.
|
|
45
|
+
`std::this_thread::sleep_for`; join, wait on a condition variable, or use a
|
|
46
|
+
future/promise.
|
|
47
|
+
- A test of concurrent code is run under ThreadSanitizer
|
|
48
|
+
(`-fsanitize=thread`) at least once.
|
|
64
49
|
|
|
65
50
|
## Sanitizer-backed verification
|
|
66
51
|
|
|
67
|
-
-
|
|
68
|
-
|
|
69
|
-
pointer arithmetic — a leaking or corrupting test can still report
|
|
70
|
-
green under plain assertions while ASan/UBSan catch the actual bug.
|
|
52
|
+
- Run the suite under AddressSanitizer + UndefinedBehaviorSanitizer for any
|
|
53
|
+
change touching manual memory management, buffers, or pointer arithmetic.
|
|
71
54
|
- New behavior gets a new test in the same change; a bug fix (especially
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
after it.
|
|
55
|
+
memory-safety or UB) gets a regression test that reproduces the failure
|
|
56
|
+
under the relevant sanitizer before the fix and passes clean after.
|
|
75
57
|
|
|
76
58
|
## Fuzzing
|
|
77
59
|
|
|
78
|
-
- A parser
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
added — do not skip fuzz coverage for a new untrusted-input parser
|
|
83
|
-
solely because unit tests pass.
|
|
60
|
+
- A parser or decoder of untrusted input formats gets a libFuzzer harness
|
|
61
|
+
(`LLVMFuzzerTestOneInput`, `-fsanitize=fuzzer,address,undefined`) when the
|
|
62
|
+
project has fuzzing infrastructure, or a documented seed corpus ready for
|
|
63
|
+
one.
|