@cratis/pi 7.136.0 → 7.137.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/package/corpus/harnesses/copilot/instructions/profiles.instructions.md +11 -7
- package/package/corpus/product-sync.json +9 -6
- package/package/corpus/rules/issue-assignment.md +2 -0
- package/package/corpus/rules/profiles.md +11 -7
- package/package/corpus/skills/cratis-arc-code-analysis-typescript/SKILL.md +96 -0
- package/package/corpus/skills/cratis-arc-command-typescript/SKILL.md +22 -13
- package/package/corpus/skills/cratis-arc-command-typescript/references/chronicle-events.md +5 -5
- package/package/corpus/skills/cratis-arc-command-typescript/references/command-operations.md +1 -1
- package/package/corpus/skills/cratis-arc-command-typescript/references/command-pipeline.md +137 -0
- package/package/corpus/skills/cratis-arc-command-typescript/references/configuration.md +83 -0
- package/package/corpus/skills/cratis-arc-command-typescript/references/hosting-and-storage.md +5 -4
- package/package/corpus/skills/cratis-arc-command-typescript/references/identity-and-introspection.md +1 -3
- package/package/corpus/skills/cratis-arc-command-typescript/references/observability-and-host-scopes.md +1 -1
- package/package/corpus/skills/cratis-arc-command-typescript/references/project-setup.md +14 -9
- package/package/corpus/skills/cratis-arc-command-typescript/references/proxy-generation.md +2 -2
- package/package/corpus/skills/cratis-arc-command-typescript/references/proxy-generator-options.md +90 -0
- package/package/corpus/skills/cratis-arc-command-typescript/verification.json +2 -2
- package/package/corpus/skills/cratis-arc-query-typescript/SKILL.md +4 -2
- package/package/corpus/skills/cratis-arc-query-typescript/references/product-sources.md +1 -2
- package/package/corpus/skills/cratis-arc-query-typescript/references/query-pipeline.md +125 -0
- package/package/corpus/skills/cratis-arc-query-typescript/references/storage-observation-and-compliance.md +1 -1
- package/package/corpus/skills/cratis-arc-query-typescript/verification.json +1 -1
- package/package/corpus/skills/cratis-arc-storage-typescript/SKILL.md +150 -0
- package/package/corpus/skills/cratis-arc-tenancy-typescript/LICENSE +2 -0
- package/package/corpus/skills/cratis-arc-tenancy-typescript/SKILL.md +125 -0
- package/package/corpus/skills/cratis-arc-testing-typescript/SKILL.md +153 -0
- package/package/corpus/skills/cratis-arc-validation-typescript/SKILL.md +3 -4
- package/package/corpus/skills/cratis-arc-validation-typescript/verification.json +1 -1
- package/package/corpus/skills/cratis-engineering-issue-design-note/SKILL.md +2 -1
- package/package/corpus/skills/cratis-engineering-issue-hygiene/SKILL.md +5 -2
- package/package/profile-catalog.json +5 -1
- package/package.json +1 -1
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cratis-arc-testing-typescript
|
|
3
|
+
description: Use when writing specs for an Arc Node.js server with @cratis/arc.testing, choosing between a direct handle() call and a pipeline scenario or testing routes and authentication. Not for React specs or framework-package tests.
|
|
4
|
+
license: MIT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Specify an Arc Node.js server with `@cratis/arc.testing`
|
|
8
|
+
|
|
9
|
+
A spec that calls `handle()` directly skips binding, authorization, validators,
|
|
10
|
+
services and the result envelope. The scenarios run the real Arc pipeline
|
|
11
|
+
in-process, with no network listener, so a spec can prove what Arc enforces.
|
|
12
|
+
`@cratis/arc.testing` is runner-neutral; the samples use Vitest (describe/it
|
|
13
|
+
with `given`), and `node:test` works too.
|
|
14
|
+
|
|
15
|
+
## Choose the boundary that can catch the bug
|
|
16
|
+
|
|
17
|
+
| Prove | Start with | Does not prove |
|
|
18
|
+
| --- | --- | --- |
|
|
19
|
+
| A calculation or decision | direct `handle()` with explicit inputs | validation, authorization, `provide()`, services |
|
|
20
|
+
| Validation, authorization, `provide()`, services, response | `CommandScenario` | HTTP routing, authentication handlers, real integrations |
|
|
21
|
+
| Operations executing and compensating in order | `CommandScenario` with fake providers | that a real provider undid anything |
|
|
22
|
+
| A query's arguments, paging, sorting, result shape | `QueryScenario` | the database's own query behavior |
|
|
23
|
+
| A live query's emissions | `ObservableQueryScenario` | a transport or browser client |
|
|
24
|
+
| Route, host and authentication | `ArcScenario` with HTTP requests | business edge cases you did not send |
|
|
25
|
+
| Events a command appends, from pinned or seeded read models | `ChronicleCommandScenario` | aggregates, unsupported projection shapes |
|
|
26
|
+
| Stored events or an aggregate | `ChronicleKernelScenario` against a running kernel | n/a |
|
|
27
|
+
|
|
28
|
+
Cover decision branches with fast direct specs and add scenario specs for the
|
|
29
|
+
rules Arc enforces. The Chronicle scenarios are in
|
|
30
|
+
`cratis-arc-command-typescript` (`chronicle-events.md`).
|
|
31
|
+
|
|
32
|
+
## CommandScenario
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { CommandScenario } from '@cratis/arc.testing';
|
|
36
|
+
|
|
37
|
+
const scenario = CommandScenario.for(ArchiveTask); // plus validators, other artifacts
|
|
38
|
+
// scenario.services.addSingleton(Token, fake); // before the first call
|
|
39
|
+
const result = await scenario.execute({ id: 't-1' });
|
|
40
|
+
result.shouldBeSuccessful();
|
|
41
|
+
await scenario.dispose();
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
- `CommandScenario.for(Command, ...artifacts)` takes the command and every
|
|
45
|
+
decorated validator or artifact it needs; it does not discover classes.
|
|
46
|
+
- `execute(values | instance)` runs the full pipeline; `validate(values)` runs
|
|
47
|
+
authorization and validation but never `provide()` or `handle()`.
|
|
48
|
+
- Register fakes on `scenario.services` before the first call
|
|
49
|
+
(`addSingleton(Token, instance)`, `addScoped(Token, factory)`). Use
|
|
50
|
+
`extend(builder => builder.useGeneratedMetadata(metadata))` when `handle(tasks:
|
|
51
|
+
Tasks)` binds by generated metadata instead of `@inject`.
|
|
52
|
+
- Always `await scenario.dispose()` after the assertions (`afterAll`/`after`).
|
|
53
|
+
- Inputs are encoded to Arc's wire shape before the pipeline decodes them, and
|
|
54
|
+
results round-trip through JSON by default; `withSerializationRoundTrip(false)`
|
|
55
|
+
turns that off for a scenario.
|
|
56
|
+
|
|
57
|
+
Assertions on the result: `shouldBeSuccessful()`, `shouldNotBeSuccessful()`,
|
|
58
|
+
`shouldBeValid()`, `shouldHaveValidationErrors()`,
|
|
59
|
+
`shouldHaveValidationErrorForMember('title')`,
|
|
60
|
+
`shouldHaveValidationErrorBecauseOf(...)`, `shouldBeAuthorized()`,
|
|
61
|
+
`shouldNotBeAuthorized()`, `shouldHaveExceptions()`, `shouldNotHaveExceptions()`,
|
|
62
|
+
and, for operations, `shouldHaveExecutedOperation`,
|
|
63
|
+
`shouldHaveCompensatedOperation`, `shouldHaveNoOperationInvocations` and
|
|
64
|
+
`shouldHaveIndeterminateRecovery`.
|
|
65
|
+
|
|
66
|
+
### Trusted context and authorization
|
|
67
|
+
|
|
68
|
+
`scenario.withContext({ principal, tenantId, correlationId, signal })` sets the
|
|
69
|
+
identity a trusted direct caller passes; `withAllowedValidationSeverity(...)`
|
|
70
|
+
changes which severities block. Specify who may call as deliberately as what
|
|
71
|
+
happens: a decorator moved to the wrong class leaves an operation open and no
|
|
72
|
+
other spec notices. Cover nobody, somebody without the role, and somebody with
|
|
73
|
+
it:
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
const planner = { id: 'ada', roles: ['Planner'], isAuthenticated: true };
|
|
77
|
+
(await scenario.execute({ id: 't-1' })).shouldNotBeAuthorized(); // anonymous
|
|
78
|
+
(await scenario.withContext({ principal: viewer }).execute({ id: 't-1' })).shouldNotBeAuthorized();
|
|
79
|
+
(await scenario.withContext({ principal: planner }).execute({ id: 't-1' })).shouldBeSuccessful();
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## QueryScenario and ObservableQueryScenario
|
|
83
|
+
|
|
84
|
+
`QueryScenario(Model, 'method', ...artifacts)` then `perform(args, options)`
|
|
85
|
+
returns the `QueryResult` (paging and sorting included); `withContext` sets the
|
|
86
|
+
caller. `ObservableQueryScenario` opens the query through the real observable
|
|
87
|
+
pipeline: `collect(count, timeoutMs = 5000, args = {}, options?)` waits for up to
|
|
88
|
+
`count` emissions or fails at the deadline, and closes the subscription either
|
|
89
|
+
way. Dispose each scenario. A streaming query a scenario cannot drive throws
|
|
90
|
+
`StreamingQueryNotSupportedError`.
|
|
91
|
+
|
|
92
|
+
## ArcScenario: routes, hosts and authentication
|
|
93
|
+
|
|
94
|
+
`new ArcScenario({ commands: [...], queries: [...], ... })` accepts the same
|
|
95
|
+
registrations as `ArcServer`, plus default context fields and per-call
|
|
96
|
+
overrides. It delegates to a real server:
|
|
97
|
+
|
|
98
|
+
| Method | Runs |
|
|
99
|
+
| --- | --- |
|
|
100
|
+
| `executeCommand(name, input, context?)` | the direct command pipeline |
|
|
101
|
+
| `validateCommand(name, input, context?)` | authorization and validation only |
|
|
102
|
+
| `performQuery(name, input, context?, options?)` | the direct query pipeline |
|
|
103
|
+
| `handle(request)` | the full HTTP pipeline, authenticating with the configured handlers |
|
|
104
|
+
|
|
105
|
+
Direct calls use the context you supply; `handle` authenticates from its
|
|
106
|
+
handlers. `shouldHaveRuleFailure(result, { reason, member?, severity?,
|
|
107
|
+
correlationId? })` checks a rule failure and throws when the only failure is
|
|
108
|
+
`dependencyUnavailable`.
|
|
109
|
+
|
|
110
|
+
## Share a context with `given`
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
export class a_task_registration {
|
|
114
|
+
tasks = new Tasks();
|
|
115
|
+
scenario = CommandScenario.for(RegisterTask, RegisterTaskValidator);
|
|
116
|
+
constructor() { this.scenario.services.addSingleton(Tasks, this.tasks); }
|
|
117
|
+
}
|
|
118
|
+
describe('when registering a task', given(a_task_registration, context => { /* ... */ }));
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Layout: `for_<Subject>/when_<action>/<case>.ts`, with shared setup in a `given/`
|
|
122
|
+
folder next to it; `discover()` skips both. See `cratis-specifications-typescript`
|
|
123
|
+
for the file and naming conventions. With Vitest or Vite, the transform must
|
|
124
|
+
lower standard decorators with `useDefineForClassFields: true`, or decorators
|
|
125
|
+
silently do nothing in specs.
|
|
126
|
+
|
|
127
|
+
## With `node:test`
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import { test, after } from 'node:test';
|
|
131
|
+
const scenario = CommandScenario.for(ArchiveTask);
|
|
132
|
+
after(async () => { await scenario.dispose(); });
|
|
133
|
+
test('archiving executes the handler', async () => {
|
|
134
|
+
(await scenario.execute({ id: 't-1' })).shouldBeSuccessful();
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Compile with the standard decorator configuration first; Node's type stripping
|
|
139
|
+
does not transform decorators.
|
|
140
|
+
|
|
141
|
+
## Pitfalls
|
|
142
|
+
|
|
143
|
+
- A scenario with fakes proves your code against the fake, not a real provider
|
|
144
|
+
or database; keep integration specs for storage.
|
|
145
|
+
- `withContext({ tenantId })` proves the code uses the tenant it is given, not
|
|
146
|
+
your resolver or storage mapping (`cratis-arc-tenancy-typescript`).
|
|
147
|
+
- Forgetting a validator in `for(...)` means its rules never run.
|
|
148
|
+
|
|
149
|
+
## Route near misses
|
|
150
|
+
|
|
151
|
+
- Writing the command or query itself: `cratis-arc-command-typescript`,
|
|
152
|
+
`cratis-arc-query-typescript`; the rule vocabulary: `cratis-arc-validation-typescript`.
|
|
153
|
+
- Specification naming and fixtures in general: `cratis-specification-by-example`.
|
|
@@ -12,16 +12,15 @@ the command's `POST <route>/validate`, so a form can ask before the user
|
|
|
12
12
|
submits. Every rejection comes back as a `ValidationResult` with a message and
|
|
13
13
|
the member it concerns — never as a thrown error.
|
|
14
14
|
|
|
15
|
-
Arc for TypeScript
|
|
16
|
-
|
|
15
|
+
Arc for TypeScript ships as stable 1.0.0 packages on npm (`@cratis/arc.core`
|
|
16
|
+
and the other server packages). The published
|
|
17
17
|
`@cratis/arc` client is separate; it runs the client-safe rules the proxy
|
|
18
18
|
generator copies into generated proxies. Setup is in
|
|
19
19
|
`cratis-arc-command-typescript`.
|
|
20
20
|
|
|
21
21
|
## Verified product sources
|
|
22
22
|
|
|
23
|
-
Source: `Cratis/Arc.TypeScript` (
|
|
24
|
-
server packages not on npm), reading `Source/Core/validation/**` (including
|
|
23
|
+
Source: `Cratis/Arc.TypeScript`, reading `Source/Core/validation/**` (including
|
|
25
24
|
`index.ts`, `ValidationResult.ts`, `Severity.ts`, `RuleBuilder.ts`),
|
|
26
25
|
`Source/Core/commands/Outcome.ts`, `Documentation/commands/command-validation.md`,
|
|
27
26
|
`validation-severity-filtering.md`, `command-outcomes.md`,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"input": "Reject an Arc for TypeScript command when the title is empty or unchanged.",
|
|
4
4
|
"fixtures": [],
|
|
5
5
|
"assertions": [
|
|
6
|
-
{ "kind": "skill-contains", "value": "
|
|
6
|
+
{ "kind": "skill-contains", "value": "ships as stable 1.0.0 packages on npm" },
|
|
7
7
|
{ "kind": "skill-contains", "value": "`ValidationResult.information/warning/error(message, options?)`" },
|
|
8
8
|
{ "kind": "skill-contains", "value": "`validation(message, members = [], reason = 'rule', severity = Severity.Error)`" },
|
|
9
9
|
{ "kind": "skill-contains", "value": "**Keep access control out of validators.**" },
|
|
@@ -120,7 +120,8 @@ There is no fast path that checks only the named files or only `--stat`.
|
|
|
120
120
|
|
|
121
121
|
## Public text
|
|
122
122
|
|
|
123
|
-
No
|
|
123
|
+
No customer or customer-of-customer names (keep every reference generic), local
|
|
124
|
+
paths (including the draft file path), model or agent names, session
|
|
124
125
|
IDs, verification receipts or work-folder names. Use absolute URLs and commit
|
|
125
126
|
permalinks.
|
|
126
127
|
|
|
@@ -73,7 +73,9 @@ duplicated or already managed by another active writer. A minimal template is:
|
|
|
73
73
|
Replace the example with the real scope and remaining work. Use public PR or
|
|
74
74
|
issue URLs when they exist. Summarize a local plan; never link its file path.
|
|
75
75
|
Do not put local paths, harness commands, credentials or private context in
|
|
76
|
-
public issue or PR text.
|
|
76
|
+
public issue or PR text. Never name a customer or a customer's customer in an
|
|
77
|
+
issue, comment or PR; describe the situation generically ("a large enterprise
|
|
78
|
+
tenant") and strip identifying products, systems and people. Read [secrets.md](../../rules/secrets.md) before handling
|
|
77
79
|
output, and [local-work-artifacts.md](../../rules/local-work-artifacts.md) before
|
|
78
80
|
creating the private working copy.
|
|
79
81
|
|
|
@@ -132,7 +134,8 @@ For example, use `gh issue view <n> --repo OWNER/REPO --comments` and
|
|
|
132
134
|
`gh issue list --repo OWNER/REPO --state all --search "<area> in:title,body"`.
|
|
133
135
|
Reuse an existing issue instead of duplicating it; comment only when that
|
|
134
136
|
effect is authorized and adds necessary context.
|
|
135
|
-
3.
|
|
137
|
+
3. Keep every issue generic: no customer or customer-of-customer names, ever.
|
|
138
|
+
Group related findings into one checklist issue per area. Include concrete,
|
|
136
139
|
testable `## Acceptance criteria`. No speculative hardening, ideas or
|
|
137
140
|
"investigate later" issues. If filing is outside the request, list necessary
|
|
138
141
|
follow-ups in the report instead of creating them.
|
|
@@ -394,7 +394,11 @@
|
|
|
394
394
|
"cratis-rtk",
|
|
395
395
|
"cratis-arc-command-typescript",
|
|
396
396
|
"cratis-arc-query-typescript",
|
|
397
|
-
"cratis-arc-validation-typescript"
|
|
397
|
+
"cratis-arc-validation-typescript",
|
|
398
|
+
"cratis-arc-tenancy-typescript",
|
|
399
|
+
"cratis-arc-storage-typescript",
|
|
400
|
+
"cratis-arc-testing-typescript",
|
|
401
|
+
"cratis-arc-code-analysis-typescript"
|
|
398
402
|
],
|
|
399
403
|
"languages": [
|
|
400
404
|
"typescript"
|