@mrciphersmith/keryx 0.4.29 → 0.4.31
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 +2446 -1391
- package/dist/core.js +90 -27
- package/dist/keryx-general-worker-entry.js +82 -25
- package/package.json +1 -1
- package/src/gdskills/bundled/install-manifest.json +2 -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 +21 -3
- package/src/gdskills/bundled/rules/core/cli-interface-design.mdc +63 -194
- package/src/gdskills/bundled/rules/core/code-style-patterns.mdc +36 -49
- 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 +7 -8
- 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/solid-principles.mdc +31 -7
- 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/quality/deprecation-path/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-architecture/SKILL.md +24 -60
- package/src/gdskills/bundled/skills/review/review-backend/SKILL.md +13 -65
- package/src/gdskills/bundled/skills/review/review-clean-code/SKILL.md +22 -35
- package/src/gdskills/bundled/skills/review/review-frontend/SKILL.md +16 -309
- package/src/gdskills/bundled/skills/review/review-frontend-conventions/SKILL.md +7 -21
- package/src/gdskills/bundled/skills/review/review-highload/SKILL.md +83 -227
- package/src/gdskills/bundled/skills/review/review-layout/SKILL.md +22 -28
- package/src/gdskills/bundled/skills/review/review-logic/SKILL.md +8 -8
- package/src/gdskills/bundled/skills/review/review-performance/SKILL.md +15 -37
- package/src/gdskills/bundled/skills/review/review-security-code/SKILL.md +7 -7
- package/src/gdskills/bundled/skills/review/review-style/SKILL.md +31 -66
- package/src/gdskills/bundled/skills/review/review-testing-practices/SKILL.md +21 -39
- 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 -84
- 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 +18 -37
- 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 +12 -45
- 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
|
@@ -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.
|
|
@@ -7,71 +7,42 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# CI workflow patterns (GitHub Actions & GitLab CI)
|
|
9
9
|
|
|
10
|
-
Narrows `core-common-rules`'
|
|
11
|
-
structure and reuse. Applies only to GitHub Actions workflow files under
|
|
12
|
-
`.github/workflows/`, GitHub composite `action.yml`/`action.yaml` files
|
|
13
|
-
under `.github/actions/`, `.gitlab-ci.yml`, and GitLab CI included config
|
|
14
|
-
under `.gitlab/` — not to Kubernetes manifests,
|
|
15
|
-
Docker Compose files, or any other YAML the `docker-k8s-terraform` pack
|
|
16
|
-
already scopes to.
|
|
10
|
+
Narrows `core-common-rules`' design guidance to workflow-YAML structure and reuse. Applies only to GitHub Actions workflows under `.github/workflows/`, composite `action.yml`/`action.yaml` under `.github/actions/`, `.gitlab-ci.yml` and GitLab CI included config under `.gitlab/`, not to YAML the `docker-k8s-terraform` pack scopes.
|
|
17
11
|
|
|
18
12
|
## Trigger and concurrency shape
|
|
19
13
|
|
|
20
|
-
- Scope `on:`/`rules:` to the events a
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
`
|
|
28
|
-
|
|
29
|
-
`interruptible: true` here: that flag means the OPPOSITE (this job is
|
|
30
|
-
SAFE to auto-cancel when a newer pipeline starts), which is right for a
|
|
31
|
-
build/test job made obsolete by a newer commit, not for a deploy already
|
|
32
|
-
in flight.
|
|
33
|
-
- Keep `pull_request` as the default trigger for anything that only builds
|
|
34
|
-
or tests untrusted contributions; reach for `pull_request_target` only
|
|
35
|
-
when the job genuinely needs base-repo secrets, and see
|
|
36
|
-
`rules/security.mdc` for what that requires.
|
|
14
|
+
- Scope `on:`/`rules:` to the events needed (a branch, path filter or event type),
|
|
15
|
+
not every push.
|
|
16
|
+
- Add a `concurrency:` group (GitHub Actions) or `resource_group` (GitLab CI) to
|
|
17
|
+
any workflow that deploys or mutates shared state. Not `interruptible: true` for
|
|
18
|
+
a deploy: it means the job is SAFE to auto-cancel, which fits a build/test job
|
|
19
|
+
made obsolete by a newer commit, not a deploy in flight.
|
|
20
|
+
- Keep `pull_request` as the default trigger for anything that only builds or
|
|
21
|
+
tests untrusted contributions; `pull_request_target` only when the job needs
|
|
22
|
+
base-repo secrets, see `rules/security.mdc`.
|
|
37
23
|
|
|
38
24
|
## Job structure and reuse
|
|
39
25
|
|
|
40
|
-
- Give every job an explicit `name:` and a `timeout-minutes` (GitHub
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
- Pin a `runs-on`/`image:` to a specific, known runner or image tag rather
|
|
49
|
-
than a rolling `latest`, so a runner image update cannot silently change
|
|
50
|
-
build behavior underneath an unrelated change.
|
|
51
|
-
- Use a job-level `needs:` (GitHub Actions) or `needs:`/stage ordering
|
|
52
|
-
(GitLab CI) to express real dependencies between jobs explicitly, rather
|
|
53
|
-
than relying on default stage ordering to imply an ordering the config
|
|
54
|
-
does not actually state.
|
|
26
|
+
- Give every job an explicit `name:` and a `timeout-minutes` (GitHub Actions) or
|
|
27
|
+
job-level `timeout` (GitLab CI).
|
|
28
|
+
- Factor a step sequence used by more than one workflow into a reusable workflow
|
|
29
|
+
(`workflow_call`) or composite action (GitHub Actions), or an
|
|
30
|
+
`include:`/`extends:` template (GitLab CI).
|
|
31
|
+
- Pin `runs-on`/`image:` to a specific runner or image tag, not a rolling `latest`.
|
|
32
|
+
- Express real job dependencies with `needs:` (GitHub Actions) or
|
|
33
|
+
`needs:`/stage ordering (GitLab CI), not implied default stage order.
|
|
55
34
|
|
|
56
35
|
## Caching and artifacts
|
|
57
36
|
|
|
58
|
-
- Key a cache (`actions/cache`, GitLab
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
- Scope `artifacts:`/`actions/upload-artifact` to the files a later job
|
|
63
|
-
actually consumes, with an explicit retention/expiry, rather than
|
|
64
|
-
uploading an entire working directory that balloons storage and
|
|
65
|
-
transfer time.
|
|
37
|
+
- Key a cache (`actions/cache`, GitLab `cache:key`) off the lockfile or dependency
|
|
38
|
+
manifest hash, not a static string.
|
|
39
|
+
- Scope `artifacts:`/`actions/upload-artifact` to the files a later job consumes,
|
|
40
|
+
with an explicit retention/expiry, not a whole working directory.
|
|
66
41
|
|
|
67
42
|
## Anti-patterns to flag
|
|
68
43
|
|
|
69
|
-
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
answer).
|
|
75
|
-
- A cache key that never changes (a literal string with no hash of the
|
|
76
|
-
lockfile), which either never invalidates or never actually caches
|
|
77
|
-
anything useful.
|
|
44
|
+
- The same 10+ line step sequence duplicated across jobs or files instead of a
|
|
45
|
+
reusable workflow, composite action or `include:`/`extends:` template.
|
|
46
|
+
- A job with no `timeout-minutes`/`timeout` on a step that can hang (a network
|
|
47
|
+
call, a wait loop, an interactive prompt).
|
|
48
|
+
- A cache key that never changes (a literal string with no lockfile hash).
|