@skyramp/mcp 0.1.1 → 0.1.3

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.
@@ -1,110 +1,28 @@
1
- import { getPersonaPrefix } from "../personas.js";
2
- export const CONTRACT_PROVIDER_ASSERTIONS_PROMPT = `${getPersonaPrefix()}Your task is to enhance assertions for the given contract-provider test.
3
- Rules 1–9 apply to success-path responses (2xx with a body). Rule 10 covers 4xx/5xx with a body and no-body responses (e.g. DELETE 204).
4
-
5
- ### Top Priorities
6
- You MUST output a \`<thinking>\` block that explicitly confirms each of these for the file:
7
- 1. Echo-back EVERY request body field with the exact sent value (no \`is not None\` for sent values)
8
- 2. Stable response values covers BOTH request-mirrored fields AND response-only fields (e.g. \`filename_download\`, \`type\`, \`size\`, \`url\`); use exact assertions, NOT \`>= 0\`, type-only, or null-only checks
9
- 3. **Status code matches the recorded/expected response exactly** if the expected response is \`201\`, assert \`201\`, not a default \`200\`/\`20x\`
10
- 4. Every array (data and error): per-item field + next-index-null guard. **Empty-array handling**: if \`expected_response_body\` shows \`[]\`, assert \`length == 0\` AND \`data[0]\` is null — do NOT add per-item field assertions on indices that do not exist (e.g. \`data.0.id is not None\` on an empty array is vacuous and forbidden)
11
- 5. All asserted values come from inline request body literals; no \`beforeAll\` provisioning data
12
- 6. Computed numeric fields use the exact pre-computed value from \`expected_response_body\`; never hardcoded without it
13
- 7. **Query-param constraints reflected in the response** — when the request includes \`limit\`, \`pageSize\`, \`offset\`, \`page\`, \`since\`, \`until\`, or \`filter\`, assert the response satisfies that constraint (array length \`<=\` limit, pagination metadata matches, filter values pass the predicate)
14
- 8. 4xx/5xx with a response body: exact values for every error-body field; status-only is NEVER sufficient
15
-
16
- ### SDK Helpers
17
- **IMPORTANT — How to access response body fields (use the SDK helpers already available in the generated file, NOT dict/attribute access on the response variable):**
18
- | Language | Helper |
19
- |----------|--------|
20
- | Python | \`skyramp.get_response_value(response, "json.path")\` |
21
- | TypeScript / JavaScript | Use the existing imported SDK JSON-path helper in the file: typically \`getValue(response, "json.path")\` or \`getResponseValue(response, "json.path")\` from \`@skyramp/skyramp\` |
22
- | Java | \`getValue(response, "json.path")\` |
23
-
24
- ### What Not to Doany of these is a violation
25
- - Do NOT access response fields via dict syntax (\`response["field"]\`) or attribute access (\`response.field\`).
26
- - Do NOT change imports solely to swap between \`getValue\` and \`getResponseValue\` — keep whichever SDK helper the generated file already imports.
27
- - Do NOT assert \`is not None\` / \`.not.toBeNull()\` on a field whose exact value was sent in the request body.
28
- - Do NOT remove or modify existing assertions.
29
- - Do NOT add assertions for **genuinely unpredictable** fields only (random tokens, opaque server-generated IDs without a known format, timestamps without a fixed format). This is NOT a license to skip body assertions on success responses or 4xx/5xx error bodies — every field present in \`expected_response_body\` IS inferable and MUST be asserted.
30
- - Do NOT use permissive status matchers — never \`checkStatusCode(response, '20x')\`, \`.toMatch(/^2/)\`, \`.toBeGreaterThanOrEqual(200)\`, or any range/pattern check on the status code. Always assert the exact status code from \`expected_response_body\` (e.g. \`expect(response.statusCode).toBe(204)\`).
31
- - Do NOT use type-only or shape-only assertions as a substitute for content validation. Specifically forbidden: \`Array.isArray(...)\`, \`typeof X === 'number'/'string'/'boolean'/'object'\`, \`X instanceof Array\`, \`Object.keys(X).length > 0\`. When \`expected_response_body\` shows actual values or items, assert exact values (scalars) and per-item fields + exact length (arrays).
32
- - Do NOT restructure, reformat, or reorder existing code.
33
- - Do NOT add comments or docstrings.
34
- - Do NOT change function signatures, imports, or variable names.
35
- - Do NOT touch \`beforeAll\`, \`afterAll\`, or setup/teardown helpers — only modify test functions.
36
- - Do NOT reference \`beforeAll\` provisioning data in assertions. Use inline request body literals for all fields.
37
-
38
- ### Assertion Rules [MANDATORY]
39
- 1. **Echo-back EVERY request body field** with the exact sent value.
40
- ❌ BAD: \`expect(getValue(response, "name")).not.toBeNull()\`
41
- ✅ GOOD: \`expect(getValue(response, "name")).toBe("Skyramp Tester")\`
42
-
43
- 2. **Stable response values** — assert exact values for ALL stable response fields. Covers BOTH:
44
- - **Response-only fields** (e.g. \`filename_download\`, \`type\`, \`size\`, \`url\`, \`mime_type\`) present in \`expected_response_body\` — do NOT stop at \`data.id is not None\` for resource responses
45
- - **Counts, booleans, status, enums** — never \`>= 0\`, type-only, or null-only checks
46
-
47
- ❌ BAD (range matcher on a known scalar): \`expect(getValue(response, "count")).toBeGreaterThanOrEqual(0)\`
48
- ✅ GOOD: \`expect(getValue(response, "count")).toBe(3)\`
49
-
50
- ❌ BAD (resource response with only id asserted): \`expect(getValue(response, "data.id")).not.toBeNull()\`
51
- ✅ GOOD: also assert response-only stable fields, e.g. \`expect(getValue(response, "data.filename_download")).toBe("invoice.pdf"); expect(getValue(response, "data.type")).toBe("application/pdf")\`
52
-
53
- ❌ BAD (type-only on a scalar, exact value ignored): \`expect(typeof getValue(response, "total_count")).toBe("number")\`
54
- ✅ GOOD: \`expect(getValue(response, "total_count")).toBe(<exact count from expected_response_body>)\`
55
-
56
- 3. **Server-generated IDs** — \`is not None\` only.
57
- 4. **Status code from expected response** — assert the exact status code from \`expected_response_body\` (e.g. \`201\` for create endpoints), not a generic \`200\` or \`20x\`.
58
- ❌ BAD (default status code, ignoring the expected response which is \`201\`): \`expect(response.statusCode).toBe(200)\`
59
- ✅ GOOD: \`expect(response.statusCode).toBe(201)\`
60
-
61
- ❌ BAD (permissive status matcher hides the exact code and skips body assertions): \`checkStatusCode(response, "20x")\` or \`expect(response.statusCode.toString()).toMatch(/^2/)\`
62
- ✅ GOOD: \`expect(response.statusCode).toBe(204)\` — exact code from \`expected_response_body\`, then add the body field assertions on top
63
-
64
- 5. **Arrays** — for every array (data and error):
65
- - **Empty array in expected response** (\`data: []\`) → assert exact \`length == 0\` AND \`data[0]\` is null/None. NEVER assert \`data.0.<field> is not None\` on an empty array — this is vacuous and forbidden.
66
- - **Non-empty array in expected response** → assert exact count (or count field), each present item's key fields, next index is null/None
67
- - if \`orderBy\`/\`sort\` is set, assert ordering across the first two items
68
- - **Shape-only check is NEVER sufficient** — \`Array.isArray(getValue(response, "results"))\` does not validate contents. When \`expected_response_body\` contains items, you MUST assert exact length AND per-item key fields, even if \`Array.isArray\` already passes.
69
-
70
- ❌ BAD (vacuous null-check on an empty-array expected response, where \`data: []\`): \`expect(getValue(response, "data.0.id")).not.toBeNull()\`
71
- ✅ GOOD: \`expect(getValue(response, "data").length).toBe(0); expect(getValue(response, "data.0")).toBeUndefined()\`
72
-
73
- ❌ BAD (shape-only check on a list endpoint, items never validated): \`expect(Array.isArray(getValue(response, "results"))).toBe(true)\`
74
- ✅ GOOD: \`expect(getValue(response, "results").length).toBe(2); expect(getValue(response, "results.0.id")).toBe(<exact id from expected_response_body>); expect(getValue(response, "results.0.title")).toBe(<exact title>); expect(getValue(response, "results.2")).toBeUndefined()\`
75
-
76
- 6. **Computed numeric fields** — use the exact pre-computed value from \`expected_response_body\` directly; never hardcode without it.
77
- ❌ BAD (hardcoded without checking expected_response_body): \`expect(getValue(response, "total_amount")).toBe(29.99)\`
78
- ✅ GOOD: use the exact value from \`expected_response_body\`
79
-
80
- 7. **Format/type** — dates, UUIDs, enums get pattern or type assertions, not just \`is not None\`.
81
- 8. **Parity** — every assertion derivable from the request/response must appear independently in both the contract and integration tests.
82
- 9. **Query-param constraints** — when the request URL includes \`limit\`, \`pageSize\`, \`offset\`, \`page\`, \`since\`, \`until\`, or \`filter\`, the response MUST be asserted against that constraint:
83
- - \`limit=N\` → assert returned array length \`<=\` N (or exactly N when \`expected_response_body\` shows it filled)
84
- - \`offset=N\` → assert pagination metadata reflects N
85
- - \`filter=k=v\` → assert every returned item satisfies the predicate
86
-
87
- ❌ BAD (\`?limit=10\` request, response length never asserted): \`expect(getValue(response, "data")).not.toBeNull()\`
88
- ✅ GOOD: \`expect(getValue(response, "data").length).toBeLessThanOrEqual(10)\` (use \`.toBe(10)\` if \`expected_response_body\` shows the limit was filled)
89
-
90
- 10. **Error-path** — for every 4xx/5xx with a response body, assert every error body field with exact values (\`error.code\`, \`error.message\`, \`detail\`, \`invalid_rows\`, etc.). Apply rule 5 to error arrays. No-body responses (DELETE 204): assert status code only.
91
- ❌ BAD (status only, error body never inspected): \`expect(getValue(response, "detail")).not.toBeNull()\`
92
- ✅ GOOD: \`expect(getValue(response, "detail")).toBe("Use POST /api/flow_runs/{id}/stop")\`
93
-
94
- ### Verification of enhanced assertions
95
- 1. Every request body field has an exact-value assertion or a documented server-generated reason
96
- 2. No \`is not None\` / \`.not.toBeNull()\` on any field whose exact value was sent in the request
97
- 3. All stable response values (request-mirrored AND response-only — \`filename_download\`, \`type\`, \`size\`, etc., AND counts/booleans/enums) use exact assertions — no leftover \`>= 0\` or type-only checks
98
- 4. Status code asserted matches \`expected_response_body\` exactly (e.g. \`201\` not a default \`200\`)
99
- 5. Every non-empty array has per-item field + next-index-null-guard assertions; every empty-array expected response asserts \`length == 0\` with no per-item field assertions on missing indices
100
- 6. No shape-only or type-only checks remain — every \`Array.isArray(...)\`, \`typeof X === '...'\`, \`instanceof Array\`, or \`Object.keys(...).length > 0\` has been replaced with exact value and per-item field assertions when \`expected_response_body\` contains data
101
- 7. If \`orderBy\`/\`sort\` is set, ordering direction asserted across the first two items
102
- 8. No references to \`beforeAll\` provisioning data — all values inline
103
- 9. Computed fields use exact pre-computed value from \`expected_response_body\`
104
- 10. Format/type fields (dates, UUIDs, enums) asserted with pattern or type check — not just \`is not None\`
105
- 11. Query-param constraints (\`limit\`, \`pageSize\`, \`offset\`, \`filter\`) reflected in response assertions
106
- 12. Every 4xx/5xx with a body has exact error-body assertions; status-only is never used
107
- 13. All field access uses SDK helpers; no dict/attribute access; no import swaps
108
-
109
- An item passes verification only when the assertion is present AND is a good assertion per the rules above. If any item is not satisfied — assertion missing, OR present but a bad assertion — add or fix it per the rules before completing, preferring the strongest applicable assertion for the scenario.
110
- `;
1
+ import { getAssertionsPrompt, } from "./sharedAssertionRules.js";
2
+ const specificRules = [
3
+ {
4
+ title: "Chained values from inline request data",
5
+ description: "Every value used in an assertion must come from what is written inline in the test function — the request body, path, or query parameters.",
6
+ subPoints: [
7
+ "Do not reference data set up in `beforeAll` or any other setup helper.",
8
+ "When an ID was sent in the request body, path, or query, assert its exact value in the response. Since the sent value is already known, asserting only that it is non-null is not sufficient.",
9
+ "Reserve `is not None` / `not.toBeNull()` for server-generated IDs only.",
10
+ "Apply the same rule to all other fields and to array items: use inline request body values as the expected values, not setup helper data.",
11
+ "Every assertion that can be derived from `expected_response_body`, the inline request body, or path/query literals must appear in this file — do not rely on the integration test to cover it.",
12
+ ],
13
+ examples: [
14
+ {
15
+ language: "javascript",
16
+ code: `expect(getResponseValue(productGetResponse, "id"), 'id').toBe(getResponseValue(productsPostResponse, "id"));`,
17
+ },
18
+ ],
19
+ },
20
+ ];
21
+ const SCOPE = `### Scope
22
+ - Only modify test functions — do not touch \`beforeAll\`, \`afterAll\`, or any setup or teardown helper.
23
+ - Only add assertions clearly supported by \`expected_response_body\`, inline request / path / query literals, codebase evidence, or the test generation recommendations received for this test. Do not invent constraints.
24
+ - Add new assertions immediately after the existing status-code assertion do not move or remove anything.
25
+ - Do not reference \`beforeAll\` / \`afterAll\` provisioning data in any assertion every assertion value must come from the inline request body, path, query, prior response, or \`expected_response_body\`.`;
26
+ export function getContractProviderAssertionsPrompt(testFile, enhanceType) {
27
+ return getAssertionsPrompt(specificRules, SCOPE, testFile, enhanceType);
28
+ }
@@ -1,128 +1,35 @@
1
- import { getPersonaPrefix } from "../personas.js";
2
- export const INTEGRATION_ASSERTIONS_PROMPT = `${getPersonaPrefix()}Your task is to enhance assertions for the given integration test.
3
- Rules 1–12 apply to success-path responses (2xx with a body). Rule 13 covers 4xx/5xx with a body and no-body responses (e.g. DELETE 204).
4
-
5
- ### Top Priorities
6
- You MUST output a \`<thinking>\` block that explicitly confirms each of these for the file:
7
- 1. Exact stable values from the recorded response covers BOTH request-mirrored fields AND response-only fields (e.g. \`filename_download\`, \`type\`, \`size\`, \`url\`); NOT \`>= 0\`, type-only, or null-only checks
8
- 2. **Status code matches the recorded trace exactly** if the trace recorded \`201\`, assert \`201\`, not a default \`200\`/\`20x\`
9
- 3. Every array (success-path AND error arrays): per-item field assertions + assert next index is null/None. **Empty-array handling**: if the recorded trace shows \`[]\`, assert \`length == 0\` AND \`data[0]\` is null do NOT add per-item field assertions on indices that do not exist in the trace (e.g. \`data.0.id is not None\` on an empty array is vacuous and forbidden)
10
- 4. POST response IDs chained into every subsequent path param, body, and assertion (no hardcoded IDs)
11
- 5. Non-ID response-derived values (e.g. \`collection\`, \`slug\`, \`role\`) extracted from prior responses, not hardcoded
12
- 6. **Cross-endpoint invariants** when one endpoint returns a scalar that describes a sibling endpoint's collection (e.g. \`active_session_count\` from \`/users/me\` and the array returned by \`/users/me/sessions\`), assert the relationship by extracting both and comparing — not by hardcoding the same value twice
13
- 7. Read steps re-assert chained values, exact stable values, and computed fields — no null/type/range fallbacks
14
- 8. Computed numeric fields use the source-derived formula from prior responses, never hardcoded numbers
15
- 9. **Query-param constraints reflected in the response** — when the request includes \`limit\`, \`pageSize\`, \`offset\`, \`page\`, \`since\`, \`until\`, or \`filter\`, assert the response satisfies that constraint (array length \`<=\` limit, pagination metadata matches, filter values pass the predicate)
16
- 10. 4xx/5xx with a response body: exact values for every error-body field; status-only is NEVER sufficient
17
-
18
- ### SDK Helpers
19
- **IMPORTANT — How to access response body fields (use the SDK helpers already available in the generated file, NOT dict/attribute access on the response variable):**
20
- | Language | Helper |
21
- |----------|--------|
22
- | Python | \`skyramp.get_response_value(response, "json.path")\` |
23
- | TypeScript / JavaScript | Use the existing imported SDK JSON-path helper in the file: typically \`getValue(response, "json.path")\` or \`getResponseValue(response, "json.path")\` from \`@skyramp/skyramp\` |
24
- | Java | \`getValue(response, "json.path")\` |
25
-
26
- ### What Not to Do — any of these is a violation
27
- - Do NOT access response fields via dict syntax (\`response["field"]\`) or attribute access (\`response.field\`).
28
- - Do NOT change imports solely to swap between \`getValue\` and \`getResponseValue\` — keep whichever SDK helper the generated file already imports.
29
- - Do NOT assert \`is not None\` / \`.not.toBeNull()\` on a field whose exact value was sent in the request body.
30
- - Do NOT remove or modify existing assertions.
31
- - Do NOT add assertions for **genuinely unpredictable** fields only (random tokens, opaque server-generated IDs without a known format, timestamps without a fixed format). This is NOT a license to skip body assertions on success responses or 4xx/5xx error bodies every field present in the recorded trace IS inferable and MUST be asserted.
32
- - Do NOT use permissive status matchers never \`checkStatusCode(response, '20x')\`, \`.toMatch(/^2/)\`, \`.toBeGreaterThanOrEqual(200)\`, or any range/pattern check on the status code. Always assert the exact status code from the trace (e.g. \`expect(response.statusCode).toBe(204)\`).
33
- - Do NOT use type-only or shape-only assertions as a substitute for content validation. Specifically forbidden: \`Array.isArray(...)\`, \`typeof X === 'number'/'string'/'boolean'/'object'\`, \`X instanceof Array\`, \`Object.keys(X).length > 0\`. When the trace shows actual values or items, assert exact values (scalars) and per-item fields + exact length (arrays).
34
- - Do NOT restructure, reformat, or reorder existing code.
35
- - Do NOT add comments or docstrings.
36
- - Do NOT change function signatures, imports, or variable names.
37
-
38
- ### Assertion Rules [MANDATORY]
39
- 1. **Echo-back EVERY request body field** with the exact sent value. \`is not None\` only for genuinely server-generated fields (timestamps, auto-incremented IDs).
40
- ❌ BAD: \`expect(getValue(response, "name")).not.toBeNull()\`
41
- ✅ GOOD: \`expect(getValue(response, "name")).toBe("Skyramp Tester")\`
42
-
43
- 2. **Stable response values** — assert exact values for ALL stable response fields. Covers BOTH:
44
- - **Response-only fields** (e.g. \`filename_download\`, \`type\`, \`size\`, \`url\`, \`mime_type\`) — do NOT stop at \`data.id is not None\` for resource responses
45
- - **Counts, booleans, status, enums** — never \`>= 0\`, type-only, or null-only checks
46
-
47
- ❌ BAD (range matcher on a known scalar): \`expect(getValue(response, "active_session_count")).toBeGreaterThanOrEqual(0)\`
48
- ✅ GOOD: \`expect(getValue(response, "active_session_count")).toBe(3)\`
49
-
50
- ❌ BAD (resource response with only id asserted): \`expect(getValue(response, "data.id")).not.toBeNull()\`
51
- ✅ GOOD: also assert response-only stable fields, e.g. \`expect(getValue(response, "data.filename_download")).toBe("invoice.pdf"); expect(getValue(response, "data.type")).toBe("application/pdf")\`
52
-
53
- ❌ BAD (type-only on a scalar, exact value ignored): \`expect(typeof getValue(response, "total_count")).toBe("number")\`
54
- ✅ GOOD: \`expect(getValue(response, "total_count")).toBe(<exact count from trace>)\`
55
-
56
- 3. **Status code from trace** — assert the exact status code recorded in the trace (e.g. \`201\` for create endpoints), not a generic \`200\` or \`20x\`. If the trace shows \`201\`, asserting \`200\` is a bug.
57
- ❌ BAD (default status code, ignoring the trace which recorded \`201\`): \`expect(response.statusCode).toBe(200)\`
58
- ✅ GOOD: \`expect(response.statusCode).toBe(201)\`
59
-
60
- ❌ BAD (permissive status matcher hides the exact code and skips body assertions): \`checkStatusCode(response, "20x")\` or \`expect(response.statusCode.toString()).toMatch(/^2/)\`
61
- ✅ GOOD: \`expect(response.statusCode).toBe(204)\` — exact code from the recorded trace, then add the body field assertions on top
62
-
63
- 4. **Chained IDs** — extract each POST ID once and reuse it in every subsequent step (path params, request bodies, assertions). Compare by value in later GET/PATCH/PUT responses; never null-check a chained ID.
64
- ❌ BAD (chained ID null-check): \`expect(getValue(get_response, "data.id")).not.toBeNull()\`
65
- ✅ GOOD: \`expect(getValue(get_response, "data.id")).toBe(getValue(post_response, "data.id"))\`
66
-
67
- 5. **Chained non-ID values** — extract response-driven values (\`collection\`, \`slug\`, \`role\`, etc.) from prior responses; never hardcode reused values.
68
- ❌ BAD (hardcoded reused value): \`let collection = "test_coerce_001"\`
69
- ✅ GOOD: \`let collection = getValue(collections_post_response, "data.collection")\`
70
-
71
- 6. **Cross-endpoint invariants** — when one response field encodes the count, identity, or summary of a collection returned by a sibling endpoint, assert the relationship by extracting both values from their respective responses and comparing them. Do not assume the count and the array length will both incidentally match the same hardcoded number.
72
- ❌ BAD (count and array length both hardcoded to the same number — no invariant): \`expect(getValue(me_response, "data.active_session_count")).toBe(3); expect(getValue(sessions_response, "data").length).toBe(3);\`
73
- ✅ GOOD: \`expect(getValue(sessions_response, "data").length).toBe(getValue(me_response, "data.active_session_count"))\`
74
-
75
- 7. **Arrays** — for every array (data and error):
76
- - **Empty array in trace** (\`data: []\`) → assert exact \`length == 0\` AND \`data[0]\` is null/None. NEVER assert \`data.0.<field> is not None\` on an empty array — this is vacuous and forbidden.
77
- - **Non-empty array in trace** → assert exact count (or count field), each present item's key fields, next index is null/None
78
- - if \`orderBy\`/\`sort\` is set, assert ordering across the first two items
79
- - **Shape-only check is NEVER sufficient** — \`Array.isArray(getValue(response, "results"))\` does not validate contents. When the trace contains items, you MUST assert exact length AND per-item key fields, even if \`Array.isArray\` already passes.
80
-
81
- ❌ BAD (null-check on a session/items array): \`expect(getValue(response, "data")).not.toBeNull()\`
82
- ✅ GOOD: assert exact count, per-item fields, and \`data[N]\` is null
83
-
84
- ❌ BAD (vacuous null-check on an empty-array trace, where \`data: []\`): \`expect(getValue(response, "data.0.id")).not.toBeNull()\`
85
- ✅ GOOD: \`expect(getValue(response, "data").length).toBe(0); expect(getValue(response, "data.0")).toBeUndefined()\`
86
-
87
- ❌ BAD (shape-only check on a list endpoint, items never validated): \`expect(Array.isArray(getValue(response, "results"))).toBe(true)\`
88
- ✅ GOOD: \`expect(getValue(response, "results").length).toBe(2); expect(getValue(response, "results.0.id")).toBe(<exact id from trace>); expect(getValue(response, "results.0.title")).toBe(<exact title>); expect(getValue(response, "results.2")).toBeUndefined()\`
89
-
90
- 8. **Computed numeric fields** — scan the source models/services for the arithmetic formula (e.g. \`total_amount = price * quantity\`), then derive dynamically from prior responses using that formula. Never guess or hardcode a computed number.
91
- ❌ BAD (hardcoded computed number): \`expect(getValue(patch_response, "total_amount")).toBe(29.99)\`
92
- ✅ GOOD: \`expect(getValue(patch_response, "total_amount")).toBe(getValue(product_post_response, "price") * quantitySent)\`
93
-
94
- 9. **Format/type** — dates, UUIDs, enums get pattern or type assertions, not just \`is not None\`.
95
- 10. **Read steps after POST/PATCH** — re-assert chained values, exact stable values, and computed fields; do not reduce to null/type/range checks.
96
- 11. **Parity** — every assertion derivable from the request/response must appear independently in both the contract and integration tests.
97
- 12. **Query-param constraints** — when the request URL includes \`limit\`, \`pageSize\`, \`offset\`, \`page\`, \`since\`, \`until\`, or \`filter\`, the response MUST be asserted against that constraint:
98
- - \`limit=N\` → assert returned array length \`<=\` N (or exactly N when the trace shows it filled)
99
- - \`offset=N\` → assert pagination metadata reflects N
100
- - \`filter=k=v\` → assert every returned item satisfies the predicate
101
-
102
- ❌ BAD (\`?limit=10\` request, response length never asserted): \`expect(getValue(response, "data")).not.toBeNull()\`
103
- ✅ GOOD: \`expect(getValue(response, "data").length).toBeLessThanOrEqual(10)\` (use \`.toBe(10)\` if the trace shows the limit was filled)
104
-
105
- 13. **Error-path** — for every 4xx/5xx with a response body, assert every error body field with exact values (\`error.code\`, \`error.message\`, \`detail\`, \`invalid_rows\`, etc.). Apply rule 7 to error arrays. No-body responses (DELETE 204): assert status code only.
106
- ❌ BAD (status only when the body has \`detail\`/\`errors\`): \`expect(response.statusCode).toBe(422)\`
107
- ✅ GOOD: \`expect(getValue(response, "detail")).toBe("Use POST /api/flow_runs/{id}/stop")\` plus exact assertions for each \`errors[i]\` field
108
-
109
- ### Verification of enhanced assertions
110
- 1. All stable response values (request-mirrored AND response-only — \`filename_download\`, \`type\`, \`size\`, etc., AND counts/booleans/enums) use exact assertions — no leftover \`>= 0\` or type-only checks
111
- 2. Status code asserted matches the recorded trace exactly (e.g. \`201\` not a default \`200\`)
112
- 3. Every non-empty array has per-item field + next-index-null-guard assertions; every empty-array trace asserts \`length == 0\` with no per-item field assertions on missing indices
113
- 4. No shape-only or type-only checks remain — every \`Array.isArray(...)\`, \`typeof X === '...'\`, \`instanceof Array\`, or \`Object.keys(...).length > 0\` has been replaced with exact value and per-item field assertions when the trace contains data
114
- 5. If \`orderBy\`/\`sort\` is set, ordering direction asserted across the first two items
115
- 6. POST IDs chained into all subsequent steps; no hardcoded IDs
116
- 7. Non-ID response values extracted from prior responses; no hardcoded reused values
117
- 8. Cross-endpoint invariants (e.g. count scalar from one endpoint vs. array length from a sibling endpoint) asserted by extract-and-compare; no twin hardcoded values
118
- 9. Read steps re-assert chained/exact/computed fields — no null/type/range fallbacks
119
- 10. Computed fields use source-derived formulas; no hardcoded computed numbers
120
- 11. Every request body field has an exact-value assertion or a documented server-generated reason
121
- 12. No \`is not None\` / \`.not.toBeNull()\` on any field whose exact value was sent in the request
122
- 13. Format/type fields (dates, UUIDs, enums) asserted with pattern or type check — not just \`is not None\`
123
- 14. Query-param constraints (\`limit\`, \`pageSize\`, \`offset\`, \`filter\`) reflected in response assertions
124
- 15. Every 4xx/5xx with a body has exact error-body assertions; status-only is never used
125
- 16. All field access uses SDK helpers; no dict/attribute access; no import swaps
126
-
127
- An item passes verification only when the assertion is present AND is a good assertion per the rules above. If any item is not satisfied — assertion missing, OR present but a bad assertion — add or fix it per the rules before completing, preferring the strongest applicable assertion for the scenario.
128
- `;
1
+ import { getAssertionsPrompt, } from "./sharedAssertionRules.js";
2
+ const specificRules = [
3
+ {
4
+ title: "Chained values across steps — chain, never hardcode",
5
+ description: "Every ID used in a later step must come from a prior step's response using the SDK helper — never hardcode an ID or declare it as a constant before the response that provides it.",
6
+ subPoints: [
7
+ "After a POST creates a resource, GET and PATCH steps should assert that the returned ID matches the one from the POST response.",
8
+ "When a non-ID response value (such as a collection name, slug, or timestamp) is reused in a later request, extract it from the prior response instead of hardcoding it.",
9
+ "After any POST, PATCH, DELETE, sort, reorder, or bulk operation, re-assert the chained, stable, and computed values on the follow-up read step: a follow-up GET after DELETE should return 404 or show the item absent; a follow-up GET after PATCH should assert the new value; a follow-up GET after sort/reorder should confirm the new ordering with chained IDs.",
10
+ "After a POST creates a resource and a GET retrieves the collection, assert that the created item appears in the list by its chained ID with its exact stable fields — do not stop at a null-check on the array or the id alone.",
11
+ "When one response field describes a count or summary of a collection returned by a related endpoint (for example, `active_session_count` from `/users/me` and the array length from `/users/me/sessions`), assert that relationship by comparing both extracted values — never hardcode the same number in two places.",
12
+ "Every assertion that can be derived from the request and response must appear in this file. If a test name claims a state change (such as \"Updates X\" or \"Increments Y\"), include an assertion that proves that state change across the relevant calls do not rely on the contract test to cover it.",
13
+ ],
14
+ examples: [
15
+ {
16
+ language: "javascript",
17
+ code: `expect(getResponseValue(productGetResponse, "id"), 'id').toBe(getResponseValue(productsPostResponse, "id"));
18
+ const collection = getValue(collectionsPostResponse, "data.collection");
19
+ expect(getValue(sessionsResponse, "data").length).toBe(getValue(meResponse, "data.active_session_count"));`,
20
+ },
21
+ {
22
+ language: "javascript",
23
+ code: `const orderId = getResponseValue(ordersPostResponse, "id");
24
+ await skyramp.sendRequest(\`/orders/\${orderId}\`);`,
25
+ },
26
+ ],
27
+ },
28
+ ];
29
+ const SCOPE = `### Scope
30
+ - Apply to every \`send_request\` / \`sendRequest\` call that returns a body.
31
+ - Only add assertions clearly supported by the request body, prior response values, field names, codebase evidence, or the test generation recommendations received for this test. Do not invent constraints.
32
+ - Add new assertions immediately after the existing status-code assertion do not move or remove anything.`;
33
+ export function getIntegrationAssertionsPrompt(testFile, enhanceType) {
34
+ return getAssertionsPrompt(specificRules, SCOPE, testFile, enhanceType);
35
+ }
@@ -0,0 +1,212 @@
1
+ import { getPersonaPrefix } from "../personas.js";
2
+ export const MAINTENANCE_SCOPE_NOTE = "Apply only to new test functions you are adding and existing test functions affected by changes in the diff. Do NOT modify test functions unrelated to the diff.";
3
+ export function maintenanceTaskSuffix(enhanceType) {
4
+ return enhanceType === "maintenance" ? ` ${MAINTENANCE_SCOPE_NOTE}` : "";
5
+ }
6
+ const SHARED_RULES = [
7
+ {
8
+ title: "Echo-back the request fields",
9
+ description: "For every field returned unchanged from the request body, assert the exact sent value.",
10
+ subPoints: [
11
+ "`is not None` / `not.toBeNull()` is only acceptable when the value is genuinely unknown — for server-generated timestamps or opaque IDs. This rule does not apply to computed fields.",
12
+ "When a response field's value equals the value sent in the request body, path, or query, assert that exact value rather than a null-check — the sent value is known and reproducible.",
13
+ "Also applies to response-only fields the server always returns the same value for (`filename_download`, `content_type`, `size`, `url`, enum status after creation). Asserting only the id on a multi-key resource response is not sufficient.",
14
+ "Range matchers like `toBeGreaterThanOrEqual(0)` and type-only checks like `typeof X === 'number'` are not acceptable for fields whose exact values are known.",
15
+ "Assert the exact status code from the recorded trace or `expected_response_body` — for example, `201` for create endpoints, not a generic `200`. Permissive status matchers are never acceptable.",
16
+ ],
17
+ examples: [
18
+ {
19
+ language: "javascript",
20
+ code: `expect(getValue(response, "data.filename_download")).toBe("invoice.pdf");
21
+ expect(getValue(response, "data.type")).toBe("application/pdf");
22
+ expect(response.statusCode).toBe(201);`,
23
+ },
24
+ {
25
+ language: "javascript",
26
+ code: `expect(getResponseValue(productsPostResponse, "name"), 'name').toBe("Skyramp Tester");`,
27
+ },
28
+ ],
29
+ },
30
+ {
31
+ title: "Error path (HTTP 4xx/5xx responses)",
32
+ description: "For every HTTP 4xx/5xx response that includes a response body, assert every error body field with its exact value — including `error.code`, `error.message`, `detail`, `errors[0].message`, and `errors[0].extensions.code`.",
33
+ subPoints: [
34
+ "Also apply the array-validation rule to any errors array.",
35
+ "Asserting only the status code is never sufficient when a body is present.",
36
+ "For no-body responses such as a successful DELETE (204): assert the status code only.",
37
+ ],
38
+ examples: [
39
+ {
40
+ language: "javascript",
41
+ code: `expect(response.statusCode).toBe(404);
42
+ expect(getValue(response, "errors.0.message")).toBe("Item not found");
43
+ expect(getValue(response, "errors.0.extensions.code")).toBe("RECORD_NOT_FOUND");
44
+ expect(getValue(response, "errors.1")).toBeUndefined();`,
45
+ },
46
+ ],
47
+ },
48
+ {
49
+ title: "Value ranges",
50
+ description: "For numeric fields where a realistic range is inferable from the field name, domain, or OpenAPI schema (`minimum` / `maximum`), assert the value falls within the expected range.",
51
+ examples: [
52
+ {
53
+ language: "javascript",
54
+ code: `expect(getResponseValue(productsPostResponse, "price")).toBeGreaterThanOrEqual(0);`,
55
+ },
56
+ ],
57
+ },
58
+ {
59
+ title: "Specific known values",
60
+ description: "For enum or status fields where only one outcome is valid for this flow, assert the exact expected value.",
61
+ subPoints: [
62
+ "When the OpenAPI schema defines allowed values, assert the schema-defined value.",
63
+ "Also assert cross-field invariants when one field encodes the count or summary of another (e.g. `total_count == results.length`).",
64
+ ],
65
+ examples: [
66
+ {
67
+ language: "javascript",
68
+ code: `expect(getResponseValue(ordersPostResponse, "status"), 'status').toBe("pending");`,
69
+ },
70
+ ],
71
+ },
72
+ {
73
+ title: "Array / Items validation",
74
+ description: "Only assert indices that exist in the recorded response — never infer array length from the request or scenario name.",
75
+ subPoints: [
76
+ "When the response is an empty array: assert the length is 0 and that the first index is absent. Never assert a field on index 0 of an empty array.",
77
+ "When the response is a non-empty array: assert the exact length, key fields on each item, and that the index after the last item is absent.",
78
+ "Shape-only checks such as `Array.isArray` or `typeof` are not sufficient when the response contains actual values.",
79
+ "If the response is sorted or ordered: assert the ordering direction across the first two items.",
80
+ "When the response is an empty or minimal body (an empty object, empty array, null, or only a few keys): assert the empty or minimal shape and the absence of error fields — do not stop at the status code.",
81
+ "When the request includes pagination or filter parameters, assert the response reflects them.",
82
+ ],
83
+ examples: [
84
+ {
85
+ language: "javascript",
86
+ code: `expect(getResponseValue(patchResponse, "items.0.product_id")).toBe(getResponseValue(productPostResponse, "id"));
87
+ expect(getResponseValue(patchResponse, "items.0.quantity")).toBe(2);
88
+ expect(getResponseValue(patchResponse, "items.1.product_id")).toBeNull();
89
+ expect(getValue(response, "data").length).toBeLessThanOrEqual(10); // request sent limit=10`,
90
+ },
91
+ {
92
+ language: "javascript",
93
+ code: `expect(getValue(response, "results").length).toBe(2);
94
+ expect(getValue(response, "results.0.id")).toBe("prod_001");
95
+ expect(getValue(response, "results.2")).toBeUndefined();`,
96
+ },
97
+ {
98
+ language: "javascript",
99
+ code: `expect(getValue(response, "data").length).toBe(0);
100
+ expect(getValue(response, "data.0")).toBeUndefined();`,
101
+ },
102
+ ],
103
+ },
104
+ {
105
+ title: "Format for server-generated fields",
106
+ description: "For fields whose exact value varies across runs — UUIDs, auto-incremented IDs, ISO timestamps, IP addresses, emails, and URLs — assert the format or pattern rather than the exact value.",
107
+ subPoints: [
108
+ "UUID matches `/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i`.",
109
+ "Auto-incremented ID is greater than 0.",
110
+ "ISO timestamp matches `/^\\d{4}-\\d{2}-\\d{2}T/`.",
111
+ "IP address matches IPv4 or IPv6 format.",
112
+ "Email contains `@` and a domain.",
113
+ "URL starts with `http://` or `https://`.",
114
+ "Use `not.toBeNull()` / `is not None` only for truly opaque random tokens where no format is recognizable.",
115
+ "Use format info from the OpenAPI schema (`format: uuid`, `format: date-time`) to identify these fields.",
116
+ ],
117
+ examples: [
118
+ {
119
+ language: "javascript",
120
+ code: `expect(getResponseValue(productsPostResponse, "id")).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i);
121
+ expect(getResponseValue(productsPostResponse, "created_at")).toMatch(/^\\d{4}-\\d{2}-\\d{2}T/);`,
122
+ },
123
+ ],
124
+ },
125
+ {
126
+ title: "Computed response fields, derived using dynamic formulas",
127
+ description: "When the response contains a field whose value is derived from a calculation, assert the result using a formula built from prior response values and request inputs, not a hardcoded literal.",
128
+ subPoints: [
129
+ "Use a dynamic formula when the formula is visible in source.",
130
+ "Fall back to the exact pre-computed value from `expected_response_body` only when no formula is knowable — all inputs must come from the inline request body or the response.",
131
+ ],
132
+ examples: [
133
+ {
134
+ language: "javascript",
135
+ code: `expect(getResponseValue(patchResponse, "discount_amount")).toBe(getResponseValue(patchResponse, "total_amount") * (getResponseValue(patchResponse, "discount_value") / 100));`,
136
+ },
137
+ {
138
+ language: "javascript",
139
+ code: `expect(getResponseValue(patchResponse, "total_amount")).toBe(getResponseValue(productPostResponse, "price") * quantitySent);`,
140
+ },
141
+ ],
142
+ },
143
+ ];
144
+ export function renderRule(index, rule) {
145
+ const subPoints = rule.subPoints && rule.subPoints.length > 0
146
+ ? "\n" + rule.subPoints.map((p) => `- ${p}`).join("\n")
147
+ : "";
148
+ const examplesBlock = rule.examples.length > 0
149
+ ? "\n" +
150
+ rule.examples
151
+ .map((ex) => `<example language="${ex.language}">
152
+ ${ex.code}
153
+ </example>`)
154
+ .join("\n")
155
+ : "";
156
+ return `${index}. ${rule.title}\n${rule.description}${subPoints}${examplesBlock}`;
157
+ }
158
+ function renderRules(rules) {
159
+ return rules.map((rule, i) => renderRule(i + 1, rule)).join("\n\n");
160
+ }
161
+ export function getAssertionsPrompt(specificRules, scope, testFile, enhanceType) {
162
+ const allRules = [...SHARED_RULES, ...specificRules];
163
+ const ruleChecklistKeys = allRules
164
+ .map((rule) => ` "${rule.title}": []`)
165
+ .join(",\n");
166
+ return `${getPersonaPrefix()}Your task is to enhance response body assertions in the given test file: \`${testFile}\`.${maintenanceTaskSuffix(enhanceType)}
167
+
168
+ ### Pre-Edit Assertion Analysis
169
+ Before editing the given file, you must output a \`<thinking>\` block. The aim of the \`<thinking>\` block is to analyze each in-scope response in the given test file and output a JSON array that ensures no assertion rule is overlooked. The JSON array should match the template below — every assertion rule title must appear as a key in the \`rule_checklist\`, even when the value is \`[]\`.
170
+ 1. Scan the given test file and expected responses based on the test recommendations for the code change tested.
171
+ 2. Classify each response first by its response status type and then assign the applicable assertion rules to the response.
172
+ 1. Success with body (2xx with a response body): all assertion rules below may apply — echo-back of request fields, computed response fields, array / items validation, and chained values across steps.
173
+ 2. Success with no body (204, or 202 with empty body): assert the status code only. Also apply chained-values rules if a follow-up step uses this response's ID.
174
+ 3. Error response (4xx/5xx with a body): assert every error body field with its exact value plus array / items validation on the \`errors[]\` array (exact length + per-item fields + next index undefined). Status code alone is never sufficient when a body is present — for example, also assert \`errors.0.extensions.code == 'INVALID_PAYLOAD'\` and that \`errors.1\` is undefined.
175
+ 3. For each in-scope response, output one JSON object using the template below. The output is an array — one object per in-scope response.
176
+ - \`step\`: the HTTP method, path, and response variable name for this request (e.g. \`POST /products → products_POST_response\`).
177
+ - \`response_status\`: one of \`success\`, \`no_body\`, or \`error\` based on the classification in step 2.
178
+ - \`rule_checklist\`: an object that MUST contain every rule title below as a key. For each rule, the value is an array of assertion lines you will add for this response under that rule. Use \`[]\` only when the rule does not apply to this response — every key must still be present. This forces you to consider every rule for every response.
179
+
180
+ \`\`\`json
181
+ [{
182
+ "step": "<METHOD> <path> → <responseVar>",
183
+ "response_status": "success | no_body | error",
184
+ "rule_checklist": {
185
+ ${ruleChecklistKeys}
186
+ }
187
+ }]
188
+ \`\`\`
189
+
190
+ ### SDK Helpers
191
+ Access response body fields via the SDK helper already imported in the generated file (never dict/attribute access on the response variable): Python \`skyramp.get_response_value(response, "json.path")\`; TypeScript / JavaScript \`getValue(response, "json.path")\` or \`getResponseValue(response, "json.path")\` from \`@skyramp/skyramp\`; Java \`getValue(response, "json.path")\`.
192
+
193
+ ### Assertion Rules with Examples
194
+ ${renderRules(allRules)}
195
+
196
+ ${scope}
197
+
198
+ ### What not to do
199
+ - Do not access response fields via dict syntax (\`response["field"]\`) or attribute access (\`response.field\`) — always use the SDK helper.
200
+ - Do not assert \`not.toBeNull()\` / \`is not None\` on a field whose exact value is in the request body, prior response, or trace.
201
+ - Do not skip body assertions citing genuinely unpredictable fields — every assertable field still needs an assertion.
202
+ - Do not use permissive status matchers (\`.toMatch(/^2/)\`, \`.toBeGreaterThanOrEqual(200)\`, \`checkStatusCode(response, '20x')\`).
203
+ - Do not use shape-only or type-only assertions as a substitute for exact value validation. Forbidden patterns: \`Array.isArray(...)\`, \`typeof X === '...'\`, \`X instanceof Array\`, \`Object.keys(X).length > 0\`. When the recorded response contains actual values, assert them exactly.
204
+ - Do not use shape-only, containment-only, range-only, or weak-length as the sole assertion on a populated array.
205
+ - Do not swap between \`getValue\` and \`getResponseValue\` — keep whichever SDK helper the file already imports.
206
+ - Do not restructure, reformat, reorder, or modify existing code; do not add comments or docstrings.
207
+ - Do not change function signatures, imports, or variable names.
208
+ - Do not remove existing assertions.
209
+
210
+ ### Verification of Assertions
211
+ After adding all assertion lines in the given test file, verify that every applicable rule has been applied correctly to each in-scope response. If any are missing or weakly applied, fix them before completing.`;
212
+ }