Skip to content

Commit ca24cec

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(oci-compute): normalize native block optional parameters
1 parent eb3e7bb commit ca24cec

3 files changed

Lines changed: 95 additions & 5 deletions

File tree

apps/sim/blocks/blocks/oci_compute.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,7 +1686,7 @@ export const OciComputeBlock: BlockConfig<OciComputeResponse> = {
16861686
integer: true,
16871687
min: field === 'size' ? 0 : 1,
16881688
})
1689-
} else delete result[field]
1689+
} else result[field] = undefined
16901690
}
16911691
const booleanOperations: Record<string, readonly string[]> = {
16921692
allowDenseRebootMigration: ALLOW_DENSE_REBOOT_MIGRATION_OPERATIONS,
@@ -1699,7 +1699,7 @@ export const OciComputeBlock: BlockConfig<OciComputeResponse> = {
16991699
}
17001700
for (const [field, operations] of Object.entries(booleanOperations)) {
17011701
if (operations.includes(params.operation)) result[field] = optionalBoolean(params[field])
1702-
else delete result[field]
1702+
else result[field] = undefined
17031703
}
17041704
if (params.operation === 'oci_compute_create_instance_pool') {
17051705
if (result.instanceDisplayNameFormatter === '')
@@ -1708,7 +1708,7 @@ export const OciComputeBlock: BlockConfig<OciComputeResponse> = {
17081708
}
17091709
if (
17101710
params.operation === 'oci_compute_list_instances' &&
1711-
result.capacityReservationId === ''
1711+
(result.capacityReservationId === '' || result.capacityReservationId === null)
17121712
) {
17131713
result.capacityReservationId = undefined
17141714
}
@@ -1760,7 +1760,11 @@ export const OciComputeBlock: BlockConfig<OciComputeResponse> = {
17601760
'resourceId',
17611761
'workRequestId',
17621762
]) {
1763-
if (result[field] === '') delete result[field]
1763+
if (
1764+
result[field] === '' ||
1765+
(result[field] === null && params.operation.startsWith('oci_compute_list_'))
1766+
)
1767+
result[field] = undefined
17641768
}
17651769
if (params.operation === 'oci_compute_launch_instance') {
17661770
let vnic = result.createVnicDetails

apps/sim/lib/internal/oci-compute/execute-tool.test.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ vi.mock('@/lib/internal/oci-compute/operations', () => ({
1818
}))
1919

2020
import { executeOciComputeTool } from '@/lib/internal/oci-compute/execute-tool'
21+
import { OciComputeBlock } from '@/blocks/blocks/oci_compute'
22+
import { ociComputeListImagesTool } from '@/tools/oci_compute/list_images'
23+
import { ociComputeListInstanceConfigurationsTool } from '@/tools/oci_compute/list_instance_configurations'
24+
import { ociComputeListInstancePoolsTool } from '@/tools/oci_compute/list_instance_pools'
25+
import { ociComputeListInstancesTool } from '@/tools/oci_compute/list_instances'
26+
import { ociComputeListShapesTool } from '@/tools/oci_compute/list_shapes'
27+
import { ociComputeListSubnetsTool } from '@/tools/oci_compute/list_subnets'
2128

2229
function call(overrides: Partial<InternalToolOperationCall> = {}): InternalToolOperationCall {
2330
return {
@@ -42,6 +49,85 @@ beforeEach(() => {
4249
})
4350

4451
describe('OCI Compute trusted execution wiring', () => {
52+
it.each([
53+
ociComputeListInstancesTool,
54+
ociComputeListImagesTool,
55+
ociComputeListShapesTool,
56+
ociComputeListSubnetsTool,
57+
ociComputeListInstanceConfigurationsTool,
58+
ociComputeListInstancePoolsTool,
59+
])('normalizes native blank discovery filters for $id', async (tool) => {
60+
for (const blank of [null, '', undefined]) {
61+
const raw = {
62+
operation: tool.id,
63+
oauthCredential: 'submitted',
64+
region: 'us-ashburn-1',
65+
compartmentId: 'compartment',
66+
limit: '10',
67+
page: blank,
68+
sortBy: blank,
69+
sortOrder: blank,
70+
displayName: blank,
71+
availabilityDomain: blank,
72+
lifecycleState: blank,
73+
capacityReservationId: blank,
74+
operatingSystemVersion: blank,
75+
shape: blank,
76+
imageId: blank,
77+
vcnId: blank,
78+
}
79+
const params = { ...raw, ...OciComputeBlock.tools.config?.params?.(raw) }
80+
const response = await executeOciComputeTool(
81+
call({ toolId: tool.id, input: tool.operation.input(params) })
82+
)
83+
expect(response.status).toBe(200)
84+
expect(mocks.execute).toHaveBeenLastCalledWith(
85+
expect.anything(),
86+
tool.id.replace('oci_compute_', ''),
87+
expect.objectContaining({ compartmentId: 'compartment', limit: 10 }),
88+
undefined
89+
)
90+
expect(mocks.execute.mock.lastCall?.[2].page).toBeUndefined()
91+
}
92+
})
93+
94+
it('keeps meaningful zero, false and empty mutation values while rejecting invalid list input', async () => {
95+
const raw = {
96+
operation: 'oci_compute_update_instance',
97+
capacityReservationId: '',
98+
preserveBootVolume: false,
99+
}
100+
const params = { ...raw, ...OciComputeBlock.tools.config?.params?.(raw) }
101+
expect(params.capacityReservationId).toBe('')
102+
const resized = OciComputeBlock.tools.config?.params?.({
103+
operation: 'oci_compute_update_instance_pool',
104+
size: 0,
105+
})
106+
expect(resized?.size).toBe(0)
107+
const terminated = OciComputeBlock.tools.config?.params?.({
108+
operation: 'oci_compute_terminate_instance',
109+
preserveBootVolume: false,
110+
})
111+
expect(terminated?.preserveBootVolume).toBe(false)
112+
const invalid = {
113+
operation: ociComputeListInstancesTool.id,
114+
oauthCredential: 'submitted',
115+
region: 'us-ashburn-1',
116+
compartmentId: 'compartment',
117+
page: 12,
118+
}
119+
const response = await executeOciComputeTool(
120+
call({
121+
toolId: ociComputeListInstancesTool.id,
122+
input: ociComputeListInstancesTool.operation.input({
123+
...invalid,
124+
...OciComputeBlock.tools.config?.params?.(invalid),
125+
}),
126+
})
127+
)
128+
expect(response.status).toBe(400)
129+
expect(mocks.execute).not.toHaveBeenCalled()
130+
})
45131
it('authorizes submitted identity and binds only the resolved credential and trusted scope', async () => {
46132
const signal = new AbortController().signal
47133
expect((await executeOciComputeTool(call({ signal }))).status).toBe(200)

apps/sim/lib/internal/oci-compute/projection-contract.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe('OCI Compute input and resource projections', () => {
102102
size: 0,
103103
instanceDisplayNameFormatter: '',
104104
})
105-
expect(values).not.toHaveProperty('isAutoTerminate')
105+
expect(values.isAutoTerminate).toBeUndefined()
106106
expect(
107107
normalize({
108108
operation: 'oci_compute_detach_instance_pool_instance',

0 commit comments

Comments
 (0)