@openreachtech/hora-skills-ort-renchan 0.0.0
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/LICENSE +201 -0
- package/README.ja.md +135 -0
- package/README.md +135 -0
- package/dist/skills/hor-agent-loop/SKILL.md +123 -0
- package/dist/skills/hor-agent-loop/references/core.md +485 -0
- package/dist/skills/hor-agent-loop/references/graphql-integration.md +178 -0
- package/dist/skills/hor-agent-loop/references/renchan-job-integration.md +368 -0
- package/dist/skills/hor-agent-loop/references/testing.md +492 -0
- package/dist/skills/hor-ai-agent-structure/SKILL.md +403 -0
- package/dist/skills/hor-ai-agent-structure/references/loop-and-actions.md +100 -0
- package/dist/skills/hor-ai-prompt-document-store/SKILL.md +220 -0
- package/dist/skills/hor-ai-prompt-document-store/references/models-and-composition.md +156 -0
- package/dist/skills/hor-backend-testing/SKILL.md +118 -0
- package/dist/skills/hor-backend-testing/references/placement-and-ordering.md +89 -0
- package/dist/skills/hor-backend-testing/references/purity-and-mocks.md +82 -0
- package/dist/skills/hor-backend-testing/references/running-tests.md +186 -0
- package/dist/skills/hor-bank-id/SKILL.md +91 -0
- package/dist/skills/hor-build-e2e-test-environment/SKILL.md +609 -0
- package/dist/skills/hor-build-e2e-test-environment/references/compose-definition.md +368 -0
- package/dist/skills/hor-build-e2e-test-environment/references/edge-and-proxy.md +287 -0
- package/dist/skills/hor-build-e2e-test-environment/references/environment-and-ports.md +201 -0
- package/dist/skills/hor-build-e2e-test-environment/references/runner-and-lifecycle.md +330 -0
- package/dist/skills/hor-build-e2e-test-environment/references/seed-data.md +145 -0
- package/dist/skills/hor-build-e2e-test-environment/references/windows-runner.md +146 -0
- package/dist/skills/hor-constant-definition/SKILL.md +139 -0
- package/dist/skills/hor-cookie-authentication/SKILL.md +33 -0
- package/dist/skills/hor-cookie-authentication/references/auth-filter.md +55 -0
- package/dist/skills/hor-cookie-authentication/references/cookie-context.md +53 -0
- package/dist/skills/hor-cookie-authentication/references/dev-login-seeder.md +22 -0
- package/dist/skills/hor-cookie-authentication/references/environment.md +64 -0
- package/dist/skills/hor-cookie-authentication/references/error-codes.md +24 -0
- package/dist/skills/hor-cookie-authentication/references/migrations.md +18 -0
- package/dist/skills/hor-cookie-authentication/references/resolvers.md +97 -0
- package/dist/skills/hor-cookie-authentication/references/session-clerk.md +41 -0
- package/dist/skills/hor-cookie-authentication/references/token-models.md +125 -0
- package/dist/skills/hor-database-design/SKILL.md +54 -0
- package/dist/skills/hor-database-design/references/column-types.md +92 -0
- package/dist/skills/hor-database-design/references/datetimes.md +88 -0
- package/dist/skills/hor-database-design/references/master-tables.md +117 -0
- package/dist/skills/hor-database-design/references/normalization.md +40 -0
- package/dist/skills/hor-database-design/references/update-history.md +35 -0
- package/dist/skills/hor-execution-placement-pattern/SKILL.md +216 -0
- package/dist/skills/hor-external-api-client/SKILL.md +99 -0
- package/dist/skills/hor-external-api-client/references/architecture.md +127 -0
- package/dist/skills/hor-external-api-client/references/authorization.md +105 -0
- package/dist/skills/hor-external-api-client/references/capsule.md +130 -0
- package/dist/skills/hor-external-api-client/references/conventions.md +68 -0
- package/dist/skills/hor-external-api-client/references/launcher.md +138 -0
- package/dist/skills/hor-external-api-client/references/payload.md +176 -0
- package/dist/skills/hor-external-api-client/references/sdk-wrapper.md +291 -0
- package/dist/skills/hor-external-api-client/references/testing.md +130 -0
- package/dist/skills/hor-external-api-client/references/usage.md +152 -0
- package/dist/skills/hor-graphql-schema/SKILL.md +360 -0
- package/dist/skills/hor-graphql-server-engine/SKILL.md +356 -0
- package/dist/skills/hor-light-rag/SKILL.md +242 -0
- package/dist/skills/hor-light-rag/references/retrieval-internals.md +143 -0
- package/dist/skills/hor-multi-llm-provider/SKILL.md +288 -0
- package/dist/skills/hor-multi-llm-provider/references/provider-internals.md +153 -0
- package/dist/skills/hor-mutation-resolver/SKILL.md +360 -0
- package/dist/skills/hor-mutation-resolver/references/dependency-injection.md +148 -0
- package/dist/skills/hor-mutation-resolver/references/errors.md +120 -0
- package/dist/skills/hor-mutation-resolver/references/resolve-flow.md +275 -0
- package/dist/skills/hor-mutation-resolver/references/testing.md +125 -0
- package/dist/skills/hor-mutation-resolver/references/transaction.md +197 -0
- package/dist/skills/hor-post-worker/SKILL.md +320 -0
- package/dist/skills/hor-query-resolver/SKILL.md +246 -0
- package/dist/skills/hor-query-resolver/references/anatomy.md +384 -0
- package/dist/skills/hor-query-resolver/references/data-access.md +248 -0
- package/dist/skills/hor-query-resolver/references/errors-and-context.md +172 -0
- package/dist/skills/hor-query-resolver/references/testing.md +241 -0
- package/dist/skills/hor-renchan-job-bullmq/SKILL.md +178 -0
- package/dist/skills/hor-renchan-job-bullmq/references/daemon-and-scheduler.md +182 -0
- package/dist/skills/hor-renchan-job-bullmq/references/engine-and-infra.md +106 -0
- package/dist/skills/hor-renchan-job-bullmq/references/job-triple.md +189 -0
- package/dist/skills/hor-renchan-job-bullmq/references/queues.md +74 -0
- package/dist/skills/hor-renchan-job-bullmq/references/subscriptions.md +113 -0
- package/dist/skills/hor-resolver-share/SKILL.md +262 -0
- package/dist/skills/hor-resolver-validator/SKILL.md +194 -0
- package/dist/skills/hor-resolver-validator/references/inspector-api.md +115 -0
- package/dist/skills/hor-resolver-validator/references/validator-pattern.md +281 -0
- package/dist/skills/hor-restfulapi-architecture/SKILL.md +275 -0
- package/dist/skills/hor-restfulapi-architecture/references/engine-and-context.md +192 -0
- package/dist/skills/hor-restfulapi-architecture/references/renderers.md +204 -0
- package/dist/skills/hor-restfulapi-architecture/references/response-and-flusher.md +118 -0
- package/dist/skills/hor-restfulapi-architecture/references/validation.md +229 -0
- package/dist/skills/hor-security-audit/SKILL.md +110 -0
- package/dist/skills/hor-security-audit/references/application-surface.md +90 -0
- package/dist/skills/hor-security-audit/references/auth-and-transport.md +147 -0
- package/dist/skills/hor-security-audit/references/code-safety.md +74 -0
- package/dist/skills/hor-security-audit/references/dependencies.md +72 -0
- package/dist/skills/hor-security-audit/references/network-and-logging.md +56 -0
- package/dist/skills/hor-security-audit/references/secrets.md +95 -0
- package/dist/skills/hor-sequelize-migration/SKILL.md +336 -0
- package/dist/skills/hor-sequelize-migration/references/alter-table.md +147 -0
- package/dist/skills/hor-sequelize-migration/references/foreign-keys.md +107 -0
- package/dist/skills/hor-sequelize-migration/references/indexes.md +149 -0
- package/dist/skills/hor-sequelize-migration/references/notation.md +215 -0
- package/dist/skills/hor-sequelize-model/SKILL.md +69 -0
- package/dist/skills/hor-sequelize-model/references/associations.md +218 -0
- package/dist/skills/hor-sequelize-model/references/default-methods.md +244 -0
- package/dist/skills/hor-sequelize-model/references/mixins.md +247 -0
- package/dist/skills/hor-sequelize-model/references/notation.md +225 -0
- package/dist/skills/hor-sequelize-model/references/timestamps.md +74 -0
- package/dist/skills/hor-sequelize-seeder/SKILL.md +275 -0
- package/dist/skills/hor-sequelize-seeder/references/development-coverage.md +74 -0
- package/dist/skills/hor-sequelize-seeder/references/directory-structure.md +113 -0
- package/dist/skills/hor-sequelize-seeder/references/id-numbering.md +133 -0
- package/dist/skills/hor-sequelize-seeder/references/naming.md +59 -0
- package/dist/skills/hor-sequelize-seeder/references/notation.md +170 -0
- package/dist/skills/hor-sequelize-subquery/SKILL.md +369 -0
- package/dist/skills/hor-strategy-pattern/SKILL.md +371 -0
- package/dist/skills/hor-stub-api/SKILL.md +330 -0
- package/dist/skills/hor-subscription-resolver/SKILL.md +105 -0
- package/dist/skills/hor-subscription-resolver/references/authentication.md +99 -0
- package/dist/skills/hor-subscription-resolver/references/basic-notation.md +116 -0
- package/dist/skills/hor-subscription-resolver/references/design-philosophy.md +68 -0
- package/dist/skills/hor-type-interface/SKILL.md +200 -0
- package/docs/skills.ja.md +40 -0
- package/docs/skills.md +40 -0
- package/lib/equip/CommandLineArguments.js +178 -0
- package/lib/equip/HoraSkillsCli.js +590 -0
- package/lib/equip/SkillsInstaller.js +443 -0
- package/lib/equip/SkillsManifestFile.js +260 -0
- package/lib/equip/constants/CLI_COMMAND.js +8 -0
- package/lib/equip/hora-skills-ort-renchan.js +8 -0
- package/package.json +51 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Test purity & test doubles
|
|
2
|
+
|
|
3
|
+
Why a test may only lean on already-tested code, and where test doubles live. Referenced from §3 of
|
|
4
|
+
[SKILL.md](../SKILL.md). Names are illustrative fakes.
|
|
5
|
+
|
|
6
|
+
## No new logic in a test
|
|
7
|
+
|
|
8
|
+
Never define a function or class **inside a test** to compute an expected value or to reproduce
|
|
9
|
+
production behavior. Logic written in a test is **untested logic**: if it is wrong, the test passes (or
|
|
10
|
+
fails) for the wrong reason — the test lies instead of catching the bug.
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
// Avoid: an untested helper defined in the test computes the expectation
|
|
14
|
+
function buildExpectedLabel ({
|
|
15
|
+
first,
|
|
16
|
+
last,
|
|
17
|
+
}) {
|
|
18
|
+
return `${last} ${first}` // if this is wrong, the assertion is meaningless
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
expect(formatLabel(input))
|
|
22
|
+
.toBe(buildExpectedLabel(input))
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
// Good: assert against a literal expected value — no logic in the test
|
|
27
|
+
expect(formatLabel({
|
|
28
|
+
first: 'Ada',
|
|
29
|
+
last: 'Byte',
|
|
30
|
+
}))
|
|
31
|
+
.toBe('Byte Ada')
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
- Assert against **literals** (or values a test fixture already provides), not against something the
|
|
35
|
+
test recomputes.
|
|
36
|
+
- If the expectation is tedious to write out, that is a signal to build a **tested** fixture/factory
|
|
37
|
+
(below), not to inline a calculation.
|
|
38
|
+
|
|
39
|
+
## Everything a test uses must already be tested
|
|
40
|
+
|
|
41
|
+
Every function, class, mock, and tool a test leans on has its **own** test cases. The chain of trust
|
|
42
|
+
only holds if each link is verified:
|
|
43
|
+
|
|
44
|
+
- Exercising production code A that internally calls B is fine — B is production code with its own
|
|
45
|
+
tests. What is banned is **new** code that exists only to serve the test and has no tests of its own.
|
|
46
|
+
- If a test needs a helper to build inputs or doubles, that helper is a **tested tool** (below), not an
|
|
47
|
+
inline function.
|
|
48
|
+
|
|
49
|
+
## Mock only when necessary — default to real
|
|
50
|
+
|
|
51
|
+
A method that **can** run for real must not be mocked: mocking the very behavior a test exists to
|
|
52
|
+
verify lets a hard-coded or regressed implementation still pass. Reach for a mock in only two cases —
|
|
53
|
+
**external systems** (third-party APIs that must never be hit, in success *and* failure tests) and
|
|
54
|
+
**steering an otherwise-unreachable branch** (e.g. forcing a not-found guard that seeded data cannot
|
|
55
|
+
naturally trigger).
|
|
56
|
+
|
|
57
|
+
- **Never mock a database row — add a seeder instead.** DB-touching tests read real seeded data; if
|
|
58
|
+
the data you need is missing, extend the seed fixtures rather than stubbing a row. Stubbing a call
|
|
59
|
+
that could have run for real, or mocking rows, is over-mocking and defeats the test.
|
|
60
|
+
- **Don't hand-query the DB inside a test to check a result.** Assert only the return value of the
|
|
61
|
+
method under test; never call `Model.findOne` / `findAll` / `update` directly in the test body to
|
|
62
|
+
fetch or verify state. Exercising the method *is* the test — re-reading the row yourself tests the
|
|
63
|
+
ORM, not the code under test.
|
|
64
|
+
- A double that is *only ever* borrowed as a stub must still be exercised **for real** in its own
|
|
65
|
+
test (below) — always test it too.
|
|
66
|
+
|
|
67
|
+
## Test doubles live under `tests/`, and are themselves tested
|
|
68
|
+
|
|
69
|
+
Shared test infrastructure has a home, and is held to the same bar as production code.
|
|
70
|
+
|
|
71
|
+
| Directory | Holds |
|
|
72
|
+
| --- | --- |
|
|
73
|
+
| `tests/mocks/` | mock/stub classes that stand in for a collaborator (a fake model, a fake client, a fake tokenizer) |
|
|
74
|
+
| `tests/tools/` | shared test tools — factories, builders, fixtures used across many tests |
|
|
75
|
+
|
|
76
|
+
- **Each mock class has its own test file.** A mock is code; an untested mock can drift from the real
|
|
77
|
+
collaborator's contract and silently invalidate every test that uses it. Test the mock's behavior
|
|
78
|
+
just like a unit.
|
|
79
|
+
- **Prefer explicit fakes** — obviously-fake class and data names (e.g. `Alpha` / `Beta` sample models,
|
|
80
|
+
clearly-fake tokens) so a reader never mistakes a double for real data or production code.
|
|
81
|
+
- A double or tool used by exactly one test can sit beside it, but the moment a second test needs it,
|
|
82
|
+
move it to `tests/mocks/` or `tests/tools/` (with its own test) rather than copy it.
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# Running tests
|
|
2
|
+
|
|
3
|
+
How to run the whole suite, a single test (with and without rebuilding the database), reset the
|
|
4
|
+
database piecemeal, size the worker/heap budget so a run cannot take the machine down, and what a
|
|
5
|
+
live (real-dialect) run requires. Referenced from §2 of [SKILL.md](../SKILL.md). Commands are the
|
|
6
|
+
recommended shape; adapt the script names to your project (they are defined in `package.json`).
|
|
7
|
+
|
|
8
|
+
## The whole suite
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm run test
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
- Runs on **SQLite** — the local default (fast, zero external services), under
|
|
15
|
+
`NODE_ENV=development`.
|
|
16
|
+
- **Rebuilds the database first**, then runs, so every full run starts clean:
|
|
17
|
+
1. teardown (drop the local DB)
|
|
18
|
+
2. migrate (recreate the schema)
|
|
19
|
+
3. seed (master, then the development / dev-master fixtures)
|
|
20
|
+
4. run `tests/__tests__/` (read-only) and `tests/_orders/` (DB-writing, in category order)
|
|
21
|
+
|
|
22
|
+
Because the suite re-seeds up front, a green full run proves the tests pass **from a clean database in
|
|
23
|
+
the committed order**. It is the authoritative run — and the slowest.
|
|
24
|
+
|
|
25
|
+
## Parallelism and memory: the worker budget
|
|
26
|
+
|
|
27
|
+
Jest runs test files in **parallel workers** — roughly one per core by default — and each worker is
|
|
28
|
+
its own Node process with its own heap. Two levers set the budget, and they must be set **together**:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# the shape — the numbers come from the measurement below, never from a default
|
|
32
|
+
NODE_OPTIONS="--experimental-vm-modules --max-old-space-size=1536" npx jest --maxWorkers=4
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
- **`--max-old-space-size` is a ceiling, not a reservation.** It does not set memory aside; it is
|
|
36
|
+
the point up to which V8 may **defer garbage collection**. A generous value therefore gives no
|
|
37
|
+
headroom — it just lets each worker grow that far before the GC is forced to run. Set it above
|
|
38
|
+
what the machine can actually give and the limit never engages: the worker keeps growing until the
|
|
39
|
+
**operating system**, not V8, ends it — and **one worker is enough** to take the machine down.
|
|
40
|
+
- **The budget is a multiplication.** Every worker may sit at its peak at once, so the invariant is:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
workers × (heap cap + per-process overhead) ≤ memory actually free
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
"Actually free" means what is left **after everything else resident on the machine** — a local
|
|
47
|
+
database, an E2E stack's daemons and pollers — not the installed total.
|
|
48
|
+
- **Derive the cap from a measured peak, not from hope.** Run the suite once with `--logHeapUsage`
|
|
49
|
+
(Jest prints each test file's heap as it finishes) and set the cap comfortably above the largest
|
|
50
|
+
value. A cap below the real peak thrashes the GC and fails anyway; a cap far above it only shifts
|
|
51
|
+
where the crash happens — from V8's out-of-memory error (which comes with a trace) to the
|
|
52
|
+
machine's (which comes with nothing).
|
|
53
|
+
- **The budget goes stale as the project grows.** Per-worker usage rises with every model, seeder
|
|
54
|
+
and test added, so a workers × cap pair that fit when it was chosen silently stops fitting. When a
|
|
55
|
+
previously green suite starts dying without output, **re-measure the peak and re-do the
|
|
56
|
+
multiplication** before suspecting the tests.
|
|
57
|
+
|
|
58
|
+
You can tell the two failures apart by how each announces itself: a worker stopped **by the cap**
|
|
59
|
+
throws `JavaScript heap out of memory` with a stack trace; a worker stopped **by the machine** is
|
|
60
|
+
killed silently and can take the whole run — and every other process on the box — with it.
|
|
61
|
+
|
|
62
|
+
### Check the machine first, then dial parallelism to fit it
|
|
63
|
+
|
|
64
|
+
The default worker count (one per core) is sized for an **idle** machine with nothing else resident.
|
|
65
|
+
A real developer machine rarely is: an editor, a browser, a local database, and, worst of all, a
|
|
66
|
+
running E2E stack's daemons and pollers are all holding memory before the suite starts. So **read
|
|
67
|
+
the machine's actual free resources before a full run**, and set the workers to what is free, not to
|
|
68
|
+
what is installed:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
# free memory and core count — the two inputs to the worker budget above
|
|
72
|
+
free -h # Linux: the "available" column is what a run may actually use
|
|
73
|
+
nproc # cores — the ceiling on useful workers
|
|
74
|
+
# macOS equivalents: `vm_stat` (free/inactive pages) and `sysctl -n hw.ncpu`
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
- **When the machine is under pressure, lower `--maxWorkers` before anything else.** The budget is
|
|
78
|
+
`workers × (heap cap + overhead) ≤ available memory`; when `available` shrinks because something
|
|
79
|
+
else is resident, the only lever that keeps the product ≤ available without re-measuring the heap is
|
|
80
|
+
the worker count. Halve it and re-run — `--maxWorkers=2`, then `1` — rather than letting the OS pick
|
|
81
|
+
which process to kill. `--maxWorkers=50%` expresses it as a fraction of cores when the constraint is
|
|
82
|
+
CPU rather than memory.
|
|
83
|
+
- **If one worker's cap already approaches what is free, go serial.** When even a single worker at
|
|
84
|
+
its measured peak does not comfortably fit beside what else is resident, there is no room left for
|
|
85
|
+
parallelism — run the suite in-band:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
NODE_OPTIONS="--experimental-vm-modules --max-old-space-size=1536" npx jest --runInBand
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`--runInBand` runs every test file in the **main process, one after another**, so the peak is one
|
|
92
|
+
worker's, not `workers ×` it. It is slower, but a serial run that finishes beats a parallel one the
|
|
93
|
+
OS kills halfway. This is the same flag the single-test fast loop uses for DB-writing tests below —
|
|
94
|
+
there for correctness, here for memory; both reasons point the same way on a constrained machine.
|
|
95
|
+
- **Bring the E2E stack down before a full run, or count it in.** A running E2E stack
|
|
96
|
+
([hor-build-e2e-test-environment](../../hor-build-e2e-test-environment/SKILL.md)) is capped, but its
|
|
97
|
+
capped footprint is still spent memory: subtract it from `available` before doing the
|
|
98
|
+
multiplication, or run `e2e/down.sh` first so the suite has the machine. Size the run with the
|
|
99
|
+
stack counted in.
|
|
100
|
+
|
|
101
|
+
## A single test through the suite runner
|
|
102
|
+
|
|
103
|
+
Run the runner against **one path**, choosing which seed set the database has. It re-establishes the
|
|
104
|
+
seeds, then runs only that path:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# with the development (dev-master) seeds applied — the usual mode for a DB-writing test
|
|
108
|
+
./test.sh --seeded tests/_orders/<Category>/SomeCreator.js
|
|
109
|
+
|
|
110
|
+
# with master seeds only (no development fixtures)
|
|
111
|
+
./test.sh --empty tests/__tests__/<path>/SomeUnit.js
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
- **`--seeded`** applies the development fixtures before running; **`--empty`** runs against master
|
|
115
|
+
seeds only.
|
|
116
|
+
- Point the path at a category's `_.test.js` to run the whole category in order, or at a single file.
|
|
117
|
+
|
|
118
|
+
## A single test without rebuilding the database (fastest)
|
|
119
|
+
|
|
120
|
+
For a tight edit-run loop, invoke Jest **directly** against the file — this skips migrations and
|
|
121
|
+
seeders entirely and runs against the database **exactly as it currently is**:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
NODE_OPTIONS="--experimental-vm-modules" NODE_ENV=development npx jest <path-of-test-file>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
For a DB-writing or order-sensitive test, run the cases **serially** with `--runInBand` (no parallel
|
|
128
|
+
workers racing on the same database):
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
NODE_OPTIONS="--experimental-vm-modules" NODE_ENV=development npx jest --runInBand <path-of-test-file>
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
- **Prerequisite: the database must already be prepared** (migrated + seeded once). This mode does not
|
|
135
|
+
set anything up — it assumes the schema and fixtures the test expects are already present. Prepare
|
|
136
|
+
them once with `npm run test` (or the piecemeal commands below), then iterate with `npx jest`.
|
|
137
|
+
- `--experimental-vm-modules` is required for the ES-module test loader; `NODE_ENV=development`
|
|
138
|
+
selects the SQLite config.
|
|
139
|
+
- **`_orders` caveat**: a DB-writing test **mutates shared state**. After running one this way, the
|
|
140
|
+
database no longer matches its seeded baseline, so a later fast run can produce a **different
|
|
141
|
+
result**. Before trusting subsequent runs, **restore the database** — re-run the relevant migrations
|
|
142
|
+
/ seeders (below), or a full `npm run test`.
|
|
143
|
+
|
|
144
|
+
## Preparing or resetting the database piecemeal
|
|
145
|
+
|
|
146
|
+
When you only need to re-establish part of the state — instead of a full rebuild — run just that
|
|
147
|
+
step. This is what makes the fast `npx jest` loop usable.
|
|
148
|
+
|
|
149
|
+
**Migrations only** (schema):
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
npm run db:teardown # drop the local DB
|
|
153
|
+
NODE_ENV=development npm run db:setup # re-apply migrations (schema only, no data)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
**One seeder set only** — undo or (re)apply a single set without touching the others. The general
|
|
157
|
+
lever is `sequelize-cli` with an explicit `--seeders-path`:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
NODE_ENV=development npx sequelize-cli db:seed:undo:all --seeders-path sequelize/seeders/<set>/
|
|
161
|
+
NODE_ENV=development npx sequelize-cli db:seed:all --seeders-path sequelize/seeders/<set>/
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
The three standard sets, and the npm wrappers the project provides for the common two:
|
|
165
|
+
|
|
166
|
+
| Seeder set (dir) | Undo | (Re)apply |
|
|
167
|
+
| --- | --- | --- |
|
|
168
|
+
| dev-master fixtures (`sequelize/seeders/dev-master/`) | `sequelize-cli db:seed:undo:all --seeders-path sequelize/seeders/dev-master/` | `npm run db:seed:master` |
|
|
169
|
+
| development fixtures (`sequelize/seeders/development/`) | `sequelize-cli db:seed:undo:all --seeders-path sequelize/seeders/development/` | `npm run db:seed:dev` |
|
|
170
|
+
| production master (`sequelize/seeders/master/`) | `sequelize-cli db:seed:undo:all --seeders-path sequelize/seeders/master/` | `sequelize-cli db:seed:all --seeders-path sequelize/seeders/master --debug` |
|
|
171
|
+
|
|
172
|
+
- Prefix each `sequelize-cli` / `npm run` command with `NODE_ENV=development` (SQLite).
|
|
173
|
+
- **After running `_orders` tests**, re-applying the mutated seeder set (undo → apply) is usually
|
|
174
|
+
enough to get back to a known baseline without a full teardown/migrate.
|
|
175
|
+
- The rebuild-everything shortcut is `npm run db:refresh` (alias `npm run r`): teardown → migrate →
|
|
176
|
+
seed dev-master → seed dev, in one command.
|
|
177
|
+
|
|
178
|
+
## A live (real-dialect) run
|
|
179
|
+
|
|
180
|
+
Everything above runs on **SQLite**, the local default. A test that depends on real-dialect behavior
|
|
181
|
+
SQLite does not emulate has to run against **MariaDB**, and that means **a MariaDB running locally**;
|
|
182
|
+
`NODE_ENV=live` selects its connection config, and the same test files run unchanged — only the
|
|
183
|
+
dialect differs.
|
|
184
|
+
|
|
185
|
+
Standing that database up is deliberately **not covered here**: this skill governs where tests go and
|
|
186
|
+
how they are run, not how a database is provisioned.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: hor-bank-id
|
|
3
|
+
description: Allocate an exclusive, collision-free row-id prefix for a requester inside one backend repository, so two writers never pick the same id. Use it before writing an explicit id into a seeder or a test that creates its own rows.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# hor-bank-id
|
|
7
|
+
|
|
8
|
+
Hand this skill a **requester id** and it returns an **id prefix** you may use, exclusively, for every row you create in this repository — in any table, in any seeder or test — for as long as this project exists.
|
|
9
|
+
|
|
10
|
+
## Why
|
|
11
|
+
|
|
12
|
+
Several writers touch the same backend repository over time: every feature `/hora-build` takes through its checkpoints writes into the same tables, and a human team may split work by hand. When two of them pick the same explicit row `id`, whichever runs its seeder last silently overwrites or collides with the other's data. `hor-bank-id` gives each requester its own slice of the id space, once.
|
|
13
|
+
|
|
14
|
+
**Being serial does not remove the need.** A seeder written for feature A is still in the tree when feature B writes its own, and both are loaded together on the next database refresh. What has to be exclusive is the id space across time, not across concurrent processes.
|
|
15
|
+
|
|
16
|
+
## The id shape
|
|
17
|
+
|
|
18
|
+
Every explicit id is an 8-digit integer, split into two parts.
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
1 0 0 0 0 0 0 1
|
|
22
|
+
└──┬──┘ └────┬────┘
|
|
23
|
+
prefix free (yours alone)
|
|
24
|
+
(100-999) (00000-99999)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
- **The first 3 digits (100-999, 900 values)** are the prefix this skill hands out. One requester, one prefix, forever
|
|
28
|
+
- **The last 5 digits (00000-99999)** are yours to use however you like, in whatever order is convenient
|
|
29
|
+
- **A prefix is not scoped to one table.** Once you hold `137`, you may use `13700001` in `users` and `13700001` in `reservations` — different tables have independent primary keys
|
|
30
|
+
|
|
31
|
+
900 prefixes comfortably exceeds the number of features any one project realistically produces. Overflow is not handled.
|
|
32
|
+
|
|
33
|
+
## The requester id
|
|
34
|
+
|
|
35
|
+
Whatever uniquely names the caller, chosen by the caller:
|
|
36
|
+
|
|
37
|
+
- **`/hora-build`'s own main session** passes the feature's `id`, once per feature, and hands the prefix it gets back to every agent working in that repository. **The agents themselves never call this skill** — several units of one checkpoint run at once, and each asking for itself would queue them behind one another's `mkdir` for no gain
|
|
38
|
+
- a human working by hand picks their own name (`alice`), or a per-feature name for more than one slice
|
|
39
|
+
|
|
40
|
+
The same requester id always gets back the same prefix. Asking twice, or retrying after a crash, is always safe.
|
|
41
|
+
|
|
42
|
+
## State
|
|
43
|
+
|
|
44
|
+
Both live directly under the backend repository's own root — never under the outer app repository's `.hora/`, which belongs to `/hora` and means something unrelated there.
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
<backend-repo>/.hora/id-bank.json the registry
|
|
48
|
+
<backend-repo>/.hora/id-bank.lock/ the lock (a directory — mkdir is atomic on POSIX)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`id-bank.json` is a flat object, requester id to prefix, as a string so a leading `1` is never mistaken for an octal digit:
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"sign-up": "100",
|
|
56
|
+
"verify-two-factor": "101",
|
|
57
|
+
"alice": "102"
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Allocating (the normal call)
|
|
62
|
+
|
|
63
|
+
1. Try `mkdir <backend-repo>/.hora/id-bank.lock`.
|
|
64
|
+
2. If it fails because the directory already exists, wait 1 second and retry. **Stop retrying after 5 attempts (5 seconds total)** and go to "A lock that will not clear" — do not remove the lock yourself here.
|
|
65
|
+
3. Once `mkdir` succeeds, you hold the lock. Read `id-bank.json` (treat a missing file as `{}`).
|
|
66
|
+
4. If the requester id is already a key, that value is the answer. Go to step 6.
|
|
67
|
+
5. Otherwise, pick the lowest integer in `100..999` not already used as a value, add `{ "<requester id>": "<that number>" }`, and write the whole file back (rewrite it whole — a partial write would corrupt the JSON for the next reader).
|
|
68
|
+
6. `rmdir <backend-repo>/.hora/id-bank.lock` to release the lock, then return the prefix.
|
|
69
|
+
|
|
70
|
+
**Never skip the lock**, even to only read the file — a reader running concurrently with a writer's rewrite can observe a half-written file.
|
|
71
|
+
|
|
72
|
+
## A lock that will not clear
|
|
73
|
+
|
|
74
|
+
Reaching the retry limit means another writer is either still working or died mid-update. From outside these look identical, so **never remove the lock yourself to force through.** Report the failure instead:
|
|
75
|
+
|
|
76
|
+
- **`/hora` stops the whole session** and states plainly: "the lock `hor-bank-id` uses did not clear, so this session is ending. Running `/hora` again will clear it automatically and continue" (see "Clearing a stale lock"). This should be rare — the lock is taken once per feature, by the main session, for the few seconds one allocation takes
|
|
77
|
+
- **A human running this by hand** may wait and retry, or run the clearing step below themselves
|
|
78
|
+
|
|
79
|
+
## Clearing a stale lock
|
|
80
|
+
|
|
81
|
+
A lock still standing at the very start of a fresh run cannot belong to anything still alive — nothing in this project holds it across separate invocations. Clearing it is therefore safe at that moment, and only then.
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
rm -rf <backend-repo>/.hora/id-bank.lock
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`/hora-build` runs this, unconditionally, as its very first action against the backend row on any invocation. A human recovering from the failure above runs the same command by hand.
|
|
88
|
+
|
|
89
|
+
## Using the prefix once you have it
|
|
90
|
+
|
|
91
|
+
Combine it with your own 5 digits when you write an explicit id — in a seeder, or inside a test that creates its own fixture. Do not derive ids from anything but your own prefix, and do not read or reason about another requester's rows.
|