Skip to content

Commit 910352e

Browse files
committed
test(rest): the after-insert path of an unevaluable hook condition answers the same coded refusal
The dogfood pin flipped by the previous commit drives an afterInsert hook whose condition reads previous on an insert, through the write door's unit. The same shape is now pinned in process on the REST create door: 400 VALIDATION_ERROR naming the hook, the row rolled back, no Unhandled line. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LmjU2x1faLZ39DVTFyVca6
1 parent 3ed86f1 commit 910352e

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

‎packages/rest/src/rest-hook-condition-unevaluable-refusal.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ const UNEVALUABLE = {
5454
name: 'qa_failclosed', object: 'inquiry', events: ['beforeInsert'],
5555
condition: CARD_CONDITION, handler: async () => {},
5656
};
57+
/**
58+
* The `after*` path: a condition reading `previous` on an insert (unbound
59+
* there), on an `onError: 'log'` hook — the shape
60+
* `hook-after-condition-rollback.dogfood.test.ts` pins through a booted stack.
61+
* The throw reaches the door from inside the write door's unit (#22782 /
62+
* #22856) rather than ahead of the insert, and must answer the same refusal.
63+
*/
64+
const AFTER_UNEVALUABLE = {
65+
name: 'qa_after_watch', object: 'inquiry', events: ['afterInsert'], onError: 'log',
66+
condition: 'previous.name != record.name', handler: async () => {},
67+
};
5768
/** CONTROL: a hook that refuses on purpose, declaring its ADR-0112 envelope. */
5869
const REFUSING = {
5970
name: 'qa_refuse', object: 'inquiry', events: ['beforeInsert'],
@@ -163,6 +174,19 @@ describe('[#24662] an unevaluable hook condition is a coded refusal on the REST
163174
expect(stack.unhandledLines()).toEqual([]);
164175
});
165176

177+
it('an afterInsert condition that reads previous on an insert: the same coded refusal, the row rolled back', async () => {
178+
const stack = await boot([AFTER_UNEVALUABLE]);
179+
180+
const res = await stack.create({ id: 'r1', name: 'x' });
181+
182+
expect(res.status).toBe(400);
183+
expect(res.body.code).toBe('VALIDATION_ERROR');
184+
expect(String(res.body.error)).toContain("Hook 'qa_after_watch' could not evaluate its condition");
185+
expect(String(res.body.error)).not.toContain('previous.name != record.name');
186+
expect(await stack.rows()).toBe(0);
187+
expect(stack.unhandledLines()).toEqual([]);
188+
});
189+
166190
it('CONTROL: a hook that refuses on purpose answers exactly as before', async () => {
167191
const stack = await boot([REFUSING]);
168192

0 commit comments

Comments
 (0)