@codyswann/lisa 2.166.5 → 2.168.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.
Files changed (63) hide show
  1. package/package.json +1 -1
  2. package/plugins/lisa/.claude-plugin/plugin.json +1 -1
  3. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  4. package/plugins/lisa-agy/plugin.json +1 -1
  5. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  6. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  7. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  8. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  9. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  10. package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
  11. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  12. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  13. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  14. package/plugins/lisa-expo-agy/plugin.json +1 -1
  15. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  16. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  17. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  18. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  19. package/plugins/lisa-harper-fabric/skills/harper-rest-queries/SKILL.md +366 -0
  20. package/plugins/lisa-harper-fabric/skills/harper-rest-queries/agents/openai.yaml +4 -0
  21. package/plugins/lisa-harper-fabric/skills/harper-testing/SKILL.md +254 -0
  22. package/plugins/lisa-harper-fabric/skills/harper-testing/agents/openai.yaml +4 -0
  23. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  24. package/plugins/lisa-harper-fabric-agy/skills/harper-rest-queries/SKILL.md +366 -0
  25. package/plugins/lisa-harper-fabric-agy/skills/harper-testing/SKILL.md +254 -0
  26. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  27. package/plugins/lisa-harper-fabric-copilot/skills/harper-rest-queries/SKILL.md +366 -0
  28. package/plugins/lisa-harper-fabric-copilot/skills/harper-testing/SKILL.md +254 -0
  29. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  30. package/plugins/lisa-harper-fabric-cursor/skills/harper-rest-queries/SKILL.md +366 -0
  31. package/plugins/lisa-harper-fabric-cursor/skills/harper-testing/SKILL.md +254 -0
  32. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  33. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  34. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  35. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  36. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  37. package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
  38. package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
  39. package/plugins/lisa-openclaw-agy/plugin.json +1 -1
  40. package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
  41. package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
  42. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  43. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  44. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  45. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  46. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  47. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  48. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  49. package/plugins/lisa-rails-agy/plugin.json +1 -1
  50. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  51. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  52. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  53. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  54. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  55. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  56. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  57. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  58. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  59. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  60. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  61. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  62. package/plugins/src/harper-fabric/skills/harper-rest-queries/SKILL.md +366 -0
  63. package/plugins/src/harper-fabric/skills/harper-testing/SKILL.md +254 -0
@@ -0,0 +1,366 @@
1
+ ---
2
+ name: harper-rest-queries
3
+ description: This skill should be used when building or debugging Harper (HarperDB/Fabric) REST collection queries and Resource search methods - filters, FIQL comparison operators, OR/grouping, select, sort, limit/offset pagination, relationship traversal, request context, and transaction boundaries. Use it when adding list endpoints, admin filters, query builders, or multi-write resource methods. Pairs with harper-resources and harper-schema-graphql.
4
+ ---
5
+
6
+ # Harper REST Queries
7
+
8
+ ## Overview
9
+
10
+ Harper exposes exported tables and custom Resources as REST endpoints when
11
+ `rest: true` is enabled. Collection `GET` requests use URL query parameters for
12
+ filtering, sorting, projection, pagination, and relationship traversal. The same
13
+ query shape is available inside Resources through `search(query)` and
14
+ `tables.X.search(query)`.
15
+
16
+ Use Harper's native query surface before hand-filtering records in JavaScript.
17
+ Hand-filtering is only acceptable after a selective indexed condition has already
18
+ narrowed the candidate set and the behavior cannot be represented by the REST
19
+ query language.
20
+
21
+ Cross-check endpoint ownership and generated resource conventions in
22
+ [[harper-resources]]. Cross-check table names, indexes, exported resources, and
23
+ relationships in [[harper-schema-graphql]].
24
+
25
+ ## REST collection syntax
26
+
27
+ REST queries run against collection paths with a trailing slash:
28
+
29
+ ```text
30
+ GET /products/?category=software
31
+ GET /products/?category=software&active=true
32
+ ```
33
+
34
+ Rules:
35
+
36
+ - Query attributes that appear in conditions should be indexed with `@indexed`.
37
+ - Multiple `&` conditions are ANDed.
38
+ - `|` combines conditions with OR logic.
39
+ - Use square brackets for grouping generated from user input because they encode
40
+ cleanly in URLs.
41
+ - Encode reserved characters, especially `:` in dates as `%3A`.
42
+
43
+ Common condition examples:
44
+
45
+ ```text
46
+ GET /products/?category=software
47
+ GET /products/?price=gt=100
48
+ GET /products/?price=ge=100&price=lt=200
49
+ GET /products/?price=gt=100&price=lt=200
50
+ GET /products/?name==Keyboard*
51
+ GET /products/?rating=5|featured=true
52
+ GET /products/?rating=5&[tag=fast|tag=scalable|tag=efficient]
53
+ GET /products/?discount=null
54
+ GET /products/?listDate=gt=2026-01-05T20%3A07%3A27.955Z
55
+ ```
56
+
57
+ ## Operators
58
+
59
+ Harper REST comparison operators use FIQL-style syntax:
60
+
61
+ | URL operator | Programmatic comparator | Meaning |
62
+ | --- | --- | --- |
63
+ | `==` | `equals` | Equal with type conversion |
64
+ | `=lt=` / `lt=` | `less_than` | Less than |
65
+ | `=le=` / `le=` | `less_than_equal` | Less than or equal |
66
+ | `=gt=` / `gt=` | `greater_than` | Greater than |
67
+ | `=ge=` / `ge=` | `greater_than_equal` | Greater than or equal |
68
+ | `=ne=` / `!=` | `not_equal` | Not equal |
69
+ | `=ct=` | `contains` | String contains |
70
+ | `=sw=` / `==value*` | `starts_with` | String starts with |
71
+ | `=ew=` | `ends_with` | String ends with |
72
+ | `=` / `===` | strict equality | No automatic URL-value conversion |
73
+ | `!==` | strict inequality | No automatic URL-value conversion |
74
+
75
+ For FIQL comparators, Harper converts strings such as `null`, `true`, numbers,
76
+ and schema-typed values before searching. Use explicit prefixes when a generated
77
+ URL must control conversion:
78
+
79
+ ```text
80
+ GET /products/?price==number:123
81
+ GET /products/?active==boolean:true
82
+ GET /products/?sku==string:00123
83
+ GET /products/?createdAt==date:2026-01-05T20%3A07%3A27.955Z
84
+ ```
85
+
86
+ ## Select, sort, and pagination
87
+
88
+ Use query functions for projection, paging, and order:
89
+
90
+ ```text
91
+ GET /products/?category=software&select(id,name,price)
92
+ GET /products/?category=software&select([id,name])
93
+ GET /products/?category=software&limit(20)
94
+ GET /products/?category=software&limit(40,60)
95
+ GET /products/?category=software&sort(+name)
96
+ GET /products/?category=software&sort(+rating,-price)
97
+ ```
98
+
99
+ Guidance:
100
+
101
+ - `select(property)` returns a single property directly.
102
+ - `select(property1,property2)` returns objects with those properties.
103
+ - `select([property1,property2])` returns arrays of selected property values.
104
+ - `limit(end)` returns the first `end` records.
105
+ - `limit(start,end)` uses `start` as the offset and returns through `end`.
106
+ - Prefix sort fields with `+` for ascending and `-` for descending.
107
+ - Prefer sorting on an indexed field used by the primary condition, or a narrow
108
+ result set that can be sorted cheaply.
109
+
110
+ Programmatic pagination normally uses `limit` and `offset`:
111
+
112
+ ```javascript
113
+ const pageSize = 20;
114
+ const page = Number(url.searchParams.get('page') ?? 0);
115
+
116
+ const products = await tables.Products.search({
117
+ conditions: [{ attribute: 'category', value: 'software' }],
118
+ sort: { attribute: 'createdAt', descending: true },
119
+ limit: pageSize,
120
+ offset: page * pageSize,
121
+ });
122
+ ```
123
+
124
+ ## Relationship queries
125
+
126
+ Relationship attributes can be queried with dot syntax when the relationship is
127
+ declared in `schema.graphql` and the foreign key fields are indexed:
128
+
129
+ ```graphql
130
+ type Product @table @export(name: "products") {
131
+ id: Long @primaryKey
132
+ name: String
133
+ brandId: Long @indexed
134
+ brand: Brand @relationship(from: brandId)
135
+ }
136
+
137
+ type Brand @table @export(name: "brands") {
138
+ id: Long @primaryKey
139
+ name: String @indexed
140
+ products: [Product] @relationship(to: brandId)
141
+ }
142
+ ```
143
+
144
+ ```text
145
+ GET /products/?brand.name=Microsoft
146
+ GET /brands/?products.name=Keyboard
147
+ GET /products/?brand.name=Microsoft&select(id,name,brand{name})
148
+ ```
149
+
150
+ Filtering on a related table behaves like an inner join. Selecting a relationship
151
+ without filtering can behave like a left join; missing relationships may be
152
+ omitted from returned records. Keep relationship names and directives aligned
153
+ with [[harper-schema-graphql]] before changing a route.
154
+
155
+ ## Programmatic search
156
+
157
+ Use `search(query)` inside custom Resources when the endpoint needs validation,
158
+ authorization, response shaping, or side effects around Harper's native query
159
+ engine:
160
+
161
+ ```javascript
162
+ export class Products extends tables.Products {
163
+ static async search(query, context) {
164
+ const safeQuery = {
165
+ ...query,
166
+ conditions: [
167
+ ...(Array.isArray(query.conditions) ? query.conditions : []),
168
+ { attribute: 'tenantId', value: context.user.tenantId },
169
+ ],
170
+ limit: Math.min(query.limit ?? 50, 100),
171
+ };
172
+
173
+ return super.search(safeQuery, context);
174
+ }
175
+ }
176
+ ```
177
+
178
+ Call table resources directly from other resource methods when you are composing
179
+ server-side behavior:
180
+
181
+ ```javascript
182
+ const products = await tables.Products.search({
183
+ conditions: [
184
+ { attribute: 'category', value: 'software' },
185
+ { attribute: 'price', comparator: 'less_than', value: 200 },
186
+ ],
187
+ sort: { attribute: 'rating', descending: true },
188
+ limit: 20,
189
+ });
190
+ ```
191
+
192
+ Useful query keys:
193
+
194
+ | Key | Use |
195
+ | --- | --- |
196
+ | `conditions` | Attribute predicates. Use an array for AND-style filters. |
197
+ | `sort` | Sort descriptor. Prefer indexed fields for large result sets. |
198
+ | `limit` | Maximum records returned. Always cap client-controlled values. |
199
+ | `offset` | Pagination offset. Prefer stable sort when offset is used. |
200
+ | `select` | Projection list. Keep admin-only fields out of public responses. |
201
+ | `explain` | Debug execution order and index usage while tuning. |
202
+
203
+ `search()` can return an `AsyncIterable`. When iterating manually or stopping
204
+ early, drain it or call the iterator's `return()` in `finally` so Harper can
205
+ release the read transaction:
206
+
207
+ ```javascript
208
+ const iterator = tables.Products
209
+ .search({ conditions: [{ attribute: 'status', value: 'active' }] })
210
+ [Symbol.asyncIterator]();
211
+
212
+ try {
213
+ const first = await iterator.next();
214
+ return first.value;
215
+ } finally {
216
+ await iterator.return?.();
217
+ }
218
+ ```
219
+
220
+ ## Context in resource methods
221
+
222
+ Resource methods may receive request context from Harper's REST runtime. Treat
223
+ that context as the authoritative place for user identity, request headers, and
224
+ request-scoped metadata supplied by the server:
225
+
226
+ ```javascript
227
+ export class Orders extends tables.Orders {
228
+ static async post(data, context) {
229
+ const userId = context.user?.id;
230
+ if (!userId) {
231
+ throw new Error('Authentication required');
232
+ }
233
+
234
+ return super.post(
235
+ {
236
+ ...(await data),
237
+ createdBy: userId,
238
+ },
239
+ context,
240
+ );
241
+ }
242
+ }
243
+ ```
244
+
245
+ When one resource delegates to another, pass the same `context` through. This
246
+ keeps authorization, headers/request metadata, and transaction ownership aligned
247
+ for nested operations:
248
+
249
+ ```javascript
250
+ await tables.OrderEvents.post(
251
+ {
252
+ orderId,
253
+ type: 'created',
254
+ },
255
+ context,
256
+ );
257
+ ```
258
+
259
+ Do not store `context` in module-level variables. It is request-scoped data and
260
+ must not leak between concurrent requests.
261
+
262
+ ## Transactions
263
+
264
+ Harper databases are transactionally consistent. Tables in the same database can
265
+ participate in the same atomic unit of work; separate databases do not preserve
266
+ cross-database atomicity.
267
+
268
+ Resource methods should assume a request-level transaction boundary:
269
+
270
+ - Reads inside a single request observe a consistent transaction context.
271
+ - Writes across tables in the same database commit together when the request
272
+ completes successfully.
273
+ - Throwing from the resource method before completion rolls the request work back.
274
+ - Nested table/resource operations should receive the same `context` to stay in
275
+ the same request transaction.
276
+ - Long-running external calls should happen before writes or after commit-aware
277
+ handoff; do not hold a transaction open while waiting on an avoidable network
278
+ dependency.
279
+
280
+ Example multi-table write:
281
+
282
+ ```javascript
283
+ export class Orders extends tables.Orders {
284
+ static async post(data, context) {
285
+ const order = await super.post(await data, context);
286
+
287
+ await tables.OrderEvents.post(
288
+ {
289
+ orderId: order.id,
290
+ type: 'created',
291
+ },
292
+ context,
293
+ );
294
+
295
+ return order;
296
+ }
297
+ }
298
+ ```
299
+
300
+ If `OrderEvents.post()` throws, the order creation should not be reported as
301
+ successful. Verify the rollback behavior with an integration test against a real
302
+ Harper process when the route writes more than one table.
303
+
304
+ ## Verification recipes
305
+
306
+ Filtered, sorted, paginated REST query:
307
+
308
+ ```bash
309
+ curl -fsS "$BASE_URL/products/?category=software&price=gt=100&sort(-rating)&limit(10)" \
310
+ | jq -e '
311
+ length <= 10 and
312
+ all(.[]; .category == "software" and .price > 100)
313
+ '
314
+ ```
315
+
316
+ Projection:
317
+
318
+ ```bash
319
+ curl -fsS "$BASE_URL/products/?category=software&select(id,name)" \
320
+ | jq -e 'all(.[]; has("id") and has("name") and (has("cost") | not))'
321
+ ```
322
+
323
+ Relationship traversal:
324
+
325
+ ```bash
326
+ curl -fsS "$BASE_URL/products/?brand.name=Microsoft&select(id,name,brand{name})" \
327
+ | jq -e 'all(.[]; .brand.name == "Microsoft")'
328
+ ```
329
+
330
+ Pagination stability:
331
+
332
+ ```bash
333
+ first="$(curl -fsS "$BASE_URL/products/?sort(+createdAt)&limit(0,20)")"
334
+ second="$(curl -fsS "$BASE_URL/products/?sort(+createdAt)&limit(20,40)")"
335
+ jq -e --argjson a "$first" --argjson b "$second" -n '
336
+ (($a | map(.id)) as $left |
337
+ ($b | map(.id)) as $right |
338
+ (($left + $right) | unique | length) == (($left | length) + ($right | length)))
339
+ '
340
+ ```
341
+
342
+ Multi-table rollback:
343
+
344
+ ```bash
345
+ order_id="rollback-$(date +%s)"
346
+
347
+ curl -sS -o /tmp/order-response.json -w "%{http_code}" \
348
+ -X POST "$BASE_URL/orders/" \
349
+ -H 'content-type: application/json' \
350
+ --data "{\"id\":\"$order_id\",\"forceEventFailure\":true}" \
351
+ | grep -E '4[0-9][0-9]|5[0-9][0-9]'
352
+
353
+ curl -fsS "$BASE_URL/orders/$order_id" \
354
+ | jq -e '.error or .message or (.id != "'$order_id'")'
355
+ ```
356
+
357
+ For routes with auth rules, add a negative assertion that a user without the
358
+ required role cannot filter, select, or sort on restricted data.
359
+
360
+ ## Sources
361
+
362
+ - [REST overview](https://docs.harperdb.io/reference/v5/rest/overview)
363
+ - [REST querying](https://docs.harperdb.io/reference/v5/rest/querying)
364
+ - [Resources overview](https://docs.harperdb.io/reference/v5/resources/overview)
365
+ - [Query optimization](https://docs.harperdb.io/reference/v5/resources/query-optimization)
366
+ - [Database overview](https://docs.harperdb.io/reference/v5/database/overview)
@@ -0,0 +1,254 @@
1
+ ---
2
+ name: harper-testing
3
+ description: This skill should be used when adding, repairing, or designing tests for a Harper (HarperDB/Fabric) component app — Vitest unit tests for pure functions and Resource methods, local Harper integration tests that boot/symlink/seed/assert real endpoints, Playwright e2e tests against REST/GraphQL routes, and schema/verify-script coupling. Use it when a Harper app needs its first test suite, endpoint coverage, seed isolation, or a local smoke/verify path. Pairs with harper-build-and-deploy, harper-schema-graphql, and e2e-coverage-gaps.
4
+ ---
5
+
6
+ # Harper Testing
7
+
8
+ ## Overview
9
+
10
+ Test Harper apps at the layer that proves the risk:
11
+
12
+ 1. **Pure unit tests** for TypeScript helpers and data transforms.
13
+ 2. **Resource unit tests** for `Resource` methods with mocked Harper runtime globals.
14
+ 3. **Integration tests** against a running local Harper component with real schema,
15
+ resources, seed data, and REST/GraphQL responses.
16
+ 4. **Playwright e2e tests** against the same HTTP surface a user or client calls.
17
+
18
+ Harper application source lives in TypeScript under `src/`; deployable
19
+ `harper-app/resources.js`, `harper-app/resource-*.js`, and `harper-app/web/**` are
20
+ generated. Build before integration or e2e tests so the runtime loads the code you
21
+ just changed. See [[harper-build-and-deploy]].
22
+
23
+ ## Test pyramid
24
+
25
+ | Layer | Tool | Use when | Avoid |
26
+ | --- | --- | --- | --- |
27
+ | Pure unit | Vitest | Validating transforms, validators, serializers, query builders, and other code with no Harper runtime dependency. | Mocking HTTP or tables for logic that can stay pure. |
28
+ | Resource unit | Vitest | Exercising `get`, `post`, `search`, `patch`, or permission/error logic in a resource class without booting Harper. | Treating mocked tables as proof that `config.yaml`, `schema.graphql`, or REST exposure works. |
29
+ | Integration | Vitest or shell smoke | Proving Harper boots, schema loads, `jsResource` registers code, data seeds, and endpoints respond. | Replacing this with resource mocks after config, schema, or generated artifact changes. |
30
+ | E2E | Playwright | Verifying client-observable REST/GraphQL behavior, auth states, error paths, and browser workflows. | Re-testing every pure branch through the browser. |
31
+
32
+ Use [[e2e-coverage-gaps]] after a suite exists to find missing routes and
33
+ non-happy paths. Use this skill when creating or repairing the test patterns
34
+ themselves.
35
+
36
+ ## Pure unit tests
37
+
38
+ Keep business transforms importable without Harper globals:
39
+
40
+ ```typescript
41
+ import { describe, expect, it } from 'vitest';
42
+ import { normalizePetName } from '../src/pets/normalize';
43
+
44
+ describe('normalizePetName', () => {
45
+ it('trims and title-cases names', () => {
46
+ expect(normalizePetName(' ada LOVELACE ')).toBe('Ada Lovelace');
47
+ });
48
+ });
49
+ ```
50
+
51
+ If a resource method contains complex transformation logic, extract the pure part
52
+ and test it directly. Leave a thinner resource test for runtime wiring,
53
+ authorization, and persistence behavior.
54
+
55
+ ## Resource unit tests
56
+
57
+ Harper injects runtime globals such as `Resource` and `tables` when it loads
58
+ `resources.js`. Unit tests do not get those globals automatically. Test resource
59
+ methods by importing code through a seam that accepts mocks, or by setting the
60
+ minimal globals before importing the resource module.
61
+
62
+ Prefer dependency injection for new code:
63
+
64
+ ```typescript
65
+ import { describe, expect, it, vi } from 'vitest';
66
+ import { createPetsResource } from '../src/resources/pets';
67
+
68
+ describe('PetsResource.get', () => {
69
+ it('adds adoption status from the table record', async () => {
70
+ const table = {
71
+ get: vi.fn(async () => ({ id: 'pet-1', name: 'Mina', adoptedAt: null })),
72
+ };
73
+ const Pets = createPetsResource({ Resource: class {}, table });
74
+
75
+ await expect(Pets.get({ id: 'pet-1' })).resolves.toMatchObject({
76
+ id: 'pet-1',
77
+ name: 'Mina',
78
+ adoptionStatus: 'available',
79
+ });
80
+ expect(table.get).toHaveBeenCalledWith({ id: 'pet-1' });
81
+ });
82
+ });
83
+ ```
84
+
85
+ When existing code must extend `tables.X` directly, isolate the runtime globals in
86
+ a test helper and import the module after setup:
87
+
88
+ ```typescript
89
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
90
+
91
+ describe('Pets resource', () => {
92
+ beforeEach(() => {
93
+ vi.resetModules();
94
+ vi.stubGlobal('Resource', class {});
95
+ vi.stubGlobal('tables', {
96
+ Pets: class {
97
+ static async get(target: { id: string }) {
98
+ return { id: target.id, name: 'Mina' };
99
+ }
100
+ },
101
+ });
102
+ });
103
+
104
+ it('wraps the runtime table', async () => {
105
+ const { Pets } = await import('../src/resources/pets');
106
+ await expect(Pets.get({ id: 'pet-1' })).resolves.toMatchObject({
107
+ id: 'pet-1',
108
+ name: 'Mina',
109
+ });
110
+ });
111
+ });
112
+ ```
113
+
114
+ Keep mocks narrow. Mock only the table methods, `Resource` base behavior,
115
+ `server.resources`, or external fetch calls the method actually uses. If the test
116
+ starts recreating Harper's schema, REST routing, or auth behavior, move it to an
117
+ integration test.
118
+
119
+ ## Integration tests with local Harper
120
+
121
+ Use integration tests to prove the component runs as Harper will load it:
122
+
123
+ 1. Install dependencies and build TypeScript: `bun install --frozen-lockfile`
124
+ when needed, then `bun run build`.
125
+ 2. Start a local Harper process against the component, usually
126
+ `harper dev harper-app` for watch mode or `harper run harper-app` for a
127
+ one-shot test process. Use the project's wrapper command when present.
128
+ 3. If the test lives outside the app repo, symlink the built component into
129
+ Harper's component directory rather than copying generated artifacts by hand.
130
+ Clean the symlink in teardown.
131
+ 4. Seed data through `dataLoader` fixtures when the project owns static fixtures,
132
+ or through REST/Operations API calls when each test needs dynamic setup.
133
+ 5. Assert the real REST/GraphQL endpoint and response body.
134
+ 6. Stop Harper and remove test data, temp components, and symlinks.
135
+
136
+ Shell smoke tests are acceptable when the project already has that convention.
137
+ Keep them strict: exit non-zero on boot failure, seed failure, missing endpoint,
138
+ wrong status, or wrong response shape.
139
+
140
+ Example integration skeleton:
141
+
142
+ ```bash
143
+ #!/usr/bin/env bash
144
+ set -euo pipefail
145
+
146
+ bun run build
147
+
148
+ HARPER_APP_DIR="${PWD}/harper-app"
149
+ HARPER_HOME="${HARPER_HOME:-${PWD}/.harper-test}"
150
+ BASE_URL="${BASE_URL:-http://127.0.0.1:9926}"
151
+
152
+ mkdir -p "$HARPER_HOME/components"
153
+ ln -sfn "$HARPER_APP_DIR" "$HARPER_HOME/components/pets"
154
+
155
+ HARPER_HOME="$HARPER_HOME" harper run "$HARPER_APP_DIR" > /tmp/harper-test.log 2>&1 &
156
+ HARPER_PID=$!
157
+ trap 'kill "$HARPER_PID" 2>/dev/null || true; rm -f "$HARPER_HOME/components/pets"' EXIT
158
+
159
+ for _ in {1..30}; do
160
+ curl -fsS "$BASE_URL/health" >/dev/null && break
161
+ sleep 1
162
+ done
163
+
164
+ curl -fsS -X POST "$BASE_URL/Pets" \
165
+ -H 'content-type: application/json' \
166
+ --data '{"id":"pet-it-1","name":"Mina"}' >/dev/null
167
+
168
+ curl -fsS "$BASE_URL/Pets/pet-it-1" | jq -e '.name == "Mina"'
169
+ ```
170
+
171
+ Adjust the health path, component name, port, and endpoint names to the project.
172
+ Do not commit local `HARPER_HOME`, logs, generated component copies, or secrets.
173
+
174
+ ## Seeding and isolation
175
+
176
+ Use deterministic test data that cannot collide with developer or CI data:
177
+
178
+ - Prefix IDs with the test name and a run ID, for example
179
+ `pet-${process.env.GITHUB_RUN_ID ?? Date.now()}`.
180
+ - Prefer per-test setup/teardown through REST or Operations API when tests mutate
181
+ records.
182
+ - Prefer `dataLoader` fixtures for stable baseline data that every local boot
183
+ should have.
184
+ - Make teardown idempotent; deleting a record that is already gone should not fail
185
+ the suite.
186
+ - Keep seed fixtures aligned with [[harper-schema-graphql]]. A field or type rename
187
+ must update fixtures, resource tests, verify scripts, and Playwright assertions in
188
+ the same PR.
189
+
190
+ `dataLoader` is good for fast, declarative baseline rows. REST seeding is better
191
+ when the test must exercise validation, defaults, auth, or generated IDs exactly as
192
+ clients see them.
193
+
194
+ ## Playwright endpoint tests
195
+
196
+ Use Playwright for HTTP behavior that needs browser tooling, request contexts,
197
+ storage state, tracing, or cross-browser/project coverage. A first endpoint spec
198
+ should cover one happy path and one non-happy path:
199
+
200
+ ```typescript
201
+ import { expect, test } from '@playwright/test';
202
+
203
+ test.describe('Pets REST endpoint', () => {
204
+ test('creates and reads a pet', async ({ request }) => {
205
+ const id = `pet-pw-${Date.now()}`;
206
+
207
+ const create = await request.post('/Pets', {
208
+ data: { id, name: 'Mina' },
209
+ });
210
+ expect(create.ok()).toBe(true);
211
+
212
+ const read = await request.get(`/Pets/${id}`);
213
+ expect(read.status()).toBe(200);
214
+ await expect(read).toHaveJSON(expect.objectContaining({ id, name: 'Mina' }));
215
+ });
216
+
217
+ test('rejects invalid payloads', async ({ request }) => {
218
+ const response = await request.post('/Pets', {
219
+ data: { name: '' },
220
+ });
221
+
222
+ expect(response.status()).toBeGreaterThanOrEqual(400);
223
+ await expect(response).toHaveJSON(
224
+ expect.objectContaining({
225
+ error: expect.any(String),
226
+ }),
227
+ );
228
+ });
229
+ });
230
+ ```
231
+
232
+ If the project uses custom auth, set `storageState`, headers, or a request fixture
233
+ in Playwright config instead of embedding credentials in specs. Never commit
234
+ tokens or local `.env` values.
235
+
236
+ ## Schema and verify coupling
237
+
238
+ A schema rename or resource route change is a breaking change for every verify
239
+ path that names that table, field, endpoint, fixture, or response shape.
240
+
241
+ In the same PR as a schema/resource change:
242
+
243
+ - Update `schema.graphql`, TypeScript resources, fixtures, and data loaders.
244
+ - Update Vitest resource tests and Playwright endpoint specs.
245
+ - Update shell smoke or `scripts/verify*` paths that assert row counts, joins, or
246
+ response keys.
247
+ - Run `bun run build`, `bun run typecheck`, and the smallest relevant test command.
248
+ - For deploy-affecting changes, boot local Harper or run the project smoke command
249
+ against the deployed endpoint. See [[harper-build-and-deploy]].
250
+
251
+ Do not report a Harper test change done only because mocks pass. At least one
252
+ verify path must prove the generated app still boots and exposes the expected
253
+ surface whenever config, schema, resources, generated artifacts, or endpoints are
254
+ part of the change.