Skip to content

Commit d7a518f

Browse files
committed
test(core): pin api target interpolation for a registered handler; changeset
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jTDpMW8KaXLg1DFU6f
1 parent 5675303 commit d7a518f

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/core': patch
3+
---
4+
5+
fix(core): an `api` action's target is interpolated before a registered `api` handler sends it
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
An `api` action whose `target` carries `${ctx.recordId}` (or any other `${ctx.X}` / `${param.X}` token) went out on the wire with the literal placeholder (`/api/v1/data/gapdata_item/$%7Bctx.recordId%7D`) when a host had registered its own `api` handler, as the Console does, so a record-level PATCH or POST hit a record that does not exist. A `url` action with the same token already resolved it. `ActionRunner` now runs its one target substitution on an `api` target before handing the action to a registered `api` handler, with the same scopes and the same per-value `encodeURIComponent` a `url` target gets. The built-in executor already did this and is unchanged; a registered handler for any other type still receives its target as authored.

‎ui/packages/core/src/actions/__tests__/ActionRunner.apiHandlerTarget-26722.test.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ const RECORD_PAGE: ActionContext = {
2525
};
2626

2727
const TARGET = '/api/v1/data/gapdata_item/${ctx.recordId}';
28+
// A url target under `/api/` leaves through `window.location`, not the host's
29+
// navigation handler, so the url control uses a route path with the same token.
30+
const URL_TARGET = '/gapdata_item/${ctx.recordId}';
2831

2932
function recordingApiHandler() {
3033
const seen: ActionDef[] = [];
@@ -62,10 +65,10 @@ describe('api targets interpolate before a registered api handler (objectstack#2
6265
runner.setNavigationHandler(navigate);
6366

6467
await runner.execute({ type: 'api', name: 'call_api', target: TARGET, method: 'PATCH' });
65-
await runner.execute({ type: 'url', name: 'open', target: TARGET });
68+
await runner.execute({ type: 'url', name: 'open', target: URL_TARGET });
6669

6770
expect(seen[0].target).toBe('/api/v1/data/gapdata_item/a%2Fb%20c');
68-
expect(navigate.mock.calls[0][0]).toContain('/api/v1/data/gapdata_item/a%2Fb%20c');
71+
expect(navigate.mock.calls[0][0]).toBe('/gapdata_item/a%2Fb%20c');
6972
});
7073

7174
it('the built-in executor sends the same resolved path', async () => {
@@ -86,12 +89,11 @@ describe('api targets interpolate before a registered api handler (objectstack#2
8689
const navigate = vi.fn();
8790
runner.setNavigationHandler(navigate);
8891

89-
const result = await runner.execute({ type: 'url', name: 'open', target: TARGET });
92+
const result = await runner.execute({ type: 'url', name: 'open', target: URL_TARGET });
9093

9194
expect(result.success).toBe(true);
9295
expect(navigate).toHaveBeenCalledTimes(1);
93-
expect(navigate.mock.calls[0][0]).toContain('/api/v1/data/gapdata_item/gd_001');
94-
expect(navigate.mock.calls[0][0]).not.toContain('${');
96+
expect(navigate.mock.calls[0][0]).toBe('/gapdata_item/gd_001');
9597
});
9698

9799
it('a registered non-api handler still receives its target as authored', async () => {

0 commit comments

Comments
 (0)