Skip to content

Commit c0104ff

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(oci-compute): isolate selector scope and follow CI conventions
1 parent 1118499 commit c0104ff

13 files changed

Lines changed: 599 additions & 278 deletions

File tree

apps/sim/blocks/blocks/oci_compute.ts

Lines changed: 82 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,7 @@ const INSTANCE_POOL_ID_OPERATIONS = [
310310
'oci_compute_detach_instance_pool_instance',
311311
]
312312

313-
const SIZE_OPERATIONS = [
314-
'oci_compute_create_instance_pool',
315-
'oci_compute_update_instance_pool',
316-
]
313+
const SIZE_OPERATIONS = ['oci_compute_create_instance_pool', 'oci_compute_update_instance_pool']
317314

318315
const PLACEMENT_CONFIGURATIONS_OPERATIONS = [
319316
'oci_compute_create_instance_pool',
@@ -330,42 +327,23 @@ const INSTANCE_HOSTNAME_FORMATTER_OPERATIONS = [
330327
'oci_compute_update_instance_pool',
331328
]
332329

333-
const IS_AUTO_TERMINATE_OPERATIONS = [
334-
'oci_compute_detach_instance_pool_instance',
335-
]
330+
const IS_AUTO_TERMINATE_OPERATIONS = ['oci_compute_detach_instance_pool_instance']
336331

337-
const IS_DECREMENT_SIZE_OPERATIONS = [
338-
'oci_compute_detach_instance_pool_instance',
339-
]
332+
const IS_DECREMENT_SIZE_OPERATIONS = ['oci_compute_detach_instance_pool_instance']
340333

341-
const NAME_OPERATIONS = [
342-
'oci_compute_list_compartments',
343-
]
334+
const NAME_OPERATIONS = ['oci_compute_list_compartments']
344335

345-
const ACCESS_LEVEL_OPERATIONS = [
346-
'oci_compute_list_compartments',
347-
]
336+
const ACCESS_LEVEL_OPERATIONS = ['oci_compute_list_compartments']
348337

349-
const COMPARTMENT_ID_IN_SUBTREE_OPERATIONS = [
350-
'oci_compute_list_compartments',
351-
]
338+
const COMPARTMENT_ID_IN_SUBTREE_OPERATIONS = ['oci_compute_list_compartments']
352339

353-
const VCN_ID_OPERATIONS = [
354-
'oci_compute_list_subnets',
355-
]
340+
const VCN_ID_OPERATIONS = ['oci_compute_list_subnets']
356341

357-
const SUBNET_ID_OPERATIONS = [
358-
'oci_compute_get_subnet',
359-
'oci_compute_launch_instance',
360-
]
342+
const SUBNET_ID_OPERATIONS = ['oci_compute_get_subnet', 'oci_compute_launch_instance']
361343

362-
const VNIC_ID_OPERATIONS = [
363-
'oci_compute_get_vnic',
364-
]
344+
const VNIC_ID_OPERATIONS = ['oci_compute_get_vnic']
365345

366-
const RESOURCE_ID_OPERATIONS = [
367-
'oci_compute_list_work_requests',
368-
]
346+
const RESOURCE_ID_OPERATIONS = ['oci_compute_list_work_requests']
369347

370348
const WORK_REQUEST_ID_OPERATIONS = [
371349
'oci_compute_get_work_request',
@@ -411,7 +389,9 @@ export const OciComputeBlock: BlockConfig<OciComputeResponse> = {
411389
oci_compute_delete_image: ['Delete image'],
412390
oci_compute_change_image_compartment: ['Change image compartment'],
413391
oci_compute_list_shapes: ['List shapes'],
414-
oci_compute_list_image_shape_compatibility_entries: ['List image shape compatibility entries'],
392+
oci_compute_list_image_shape_compatibility_entries: [
393+
'List image shape compatibility entries',
394+
],
415395
oci_compute_get_image_shape_compatibility_entry: ['Get image shape compatibility entry'],
416396
oci_compute_create_compute_capacity_report: ['Create compute capacity report'],
417397
oci_compute_list_instance_configurations: ['List instance configurations'],
@@ -420,7 +400,9 @@ export const OciComputeBlock: BlockConfig<OciComputeResponse> = {
420400
oci_compute_update_instance_configuration: ['Update instance configuration'],
421401
oci_compute_delete_instance_configuration: ['Delete instance configuration'],
422402
oci_compute_launch_instance_configuration: ['Launch instance configuration'],
423-
oci_compute_change_instance_configuration_compartment: ['Change instance configuration compartment'],
403+
oci_compute_change_instance_configuration_compartment: [
404+
'Change instance configuration compartment',
405+
],
424406
oci_compute_list_instance_pools: ['List instance pools'],
425407
oci_compute_get_instance_pool: ['Get instance pool'],
426408
oci_compute_create_instance_pool: ['Create instance pool'],
@@ -489,31 +471,49 @@ export const OciComputeBlock: BlockConfig<OciComputeResponse> = {
489471
{ label: 'Instance Action', id: 'oci_compute_instance_action' },
490472
{ label: 'Terminate Instance', id: 'oci_compute_terminate_instance' },
491473
{ label: 'Change Instance Compartment', id: 'oci_compute_change_instance_compartment' },
492-
{ label: 'Get Instance Maintenance Reboot', id: 'oci_compute_get_instance_maintenance_reboot' },
474+
{
475+
label: 'Get Instance Maintenance Reboot',
476+
id: 'oci_compute_get_instance_maintenance_reboot',
477+
},
493478
{ label: 'List Images', id: 'oci_compute_list_images' },
494479
{ label: 'Get Image', id: 'oci_compute_get_image' },
495480
{ label: 'Create Image', id: 'oci_compute_create_image' },
496481
{ label: 'Update Image', id: 'oci_compute_update_image' },
497482
{ label: 'Delete Image', id: 'oci_compute_delete_image' },
498483
{ label: 'Change Image Compartment', id: 'oci_compute_change_image_compartment' },
499484
{ label: 'List Shapes', id: 'oci_compute_list_shapes' },
500-
{ label: 'List Image Shape Compatibility Entries', id: 'oci_compute_list_image_shape_compatibility_entries' },
501-
{ label: 'Get Image Shape Compatibility Entry', id: 'oci_compute_get_image_shape_compatibility_entry' },
502-
{ label: 'Create Compute Capacity Report', id: 'oci_compute_create_compute_capacity_report' },
485+
{
486+
label: 'List Image Shape Compatibility Entries',
487+
id: 'oci_compute_list_image_shape_compatibility_entries',
488+
},
489+
{
490+
label: 'Get Image Shape Compatibility Entry',
491+
id: 'oci_compute_get_image_shape_compatibility_entry',
492+
},
493+
{
494+
label: 'Create Compute Capacity Report',
495+
id: 'oci_compute_create_compute_capacity_report',
496+
},
503497
{ label: 'List Instance Configurations', id: 'oci_compute_list_instance_configurations' },
504498
{ label: 'Get Instance Configuration', id: 'oci_compute_get_instance_configuration' },
505499
{ label: 'Create Instance Configuration', id: 'oci_compute_create_instance_configuration' },
506500
{ label: 'Update Instance Configuration', id: 'oci_compute_update_instance_configuration' },
507501
{ label: 'Delete Instance Configuration', id: 'oci_compute_delete_instance_configuration' },
508502
{ label: 'Launch Instance Configuration', id: 'oci_compute_launch_instance_configuration' },
509-
{ label: 'Change Instance Configuration Compartment', id: 'oci_compute_change_instance_configuration_compartment' },
503+
{
504+
label: 'Change Instance Configuration Compartment',
505+
id: 'oci_compute_change_instance_configuration_compartment',
506+
},
510507
{ label: 'List Instance Pools', id: 'oci_compute_list_instance_pools' },
511508
{ label: 'Get Instance Pool', id: 'oci_compute_get_instance_pool' },
512509
{ label: 'Create Instance Pool', id: 'oci_compute_create_instance_pool' },
513510
{ label: 'Update Instance Pool', id: 'oci_compute_update_instance_pool' },
514511
{ label: 'Instance Pool Action', id: 'oci_compute_instance_pool_action' },
515512
{ label: 'Terminate Instance Pool', id: 'oci_compute_terminate_instance_pool' },
516-
{ label: 'Change Instance Pool Compartment', id: 'oci_compute_change_instance_pool_compartment' },
513+
{
514+
label: 'Change Instance Pool Compartment',
515+
id: 'oci_compute_change_instance_pool_compartment',
516+
},
517517
{ label: 'List Instance Pool Instances', id: 'oci_compute_list_instance_pool_instances' },
518518
{ label: 'Get Instance Pool Instance', id: 'oci_compute_get_instance_pool_instance' },
519519
{ label: 'Attach Instance Pool Instance', id: 'oci_compute_attach_instance_pool_instance' },
@@ -824,7 +824,7 @@ export const OciComputeBlock: BlockConfig<OciComputeResponse> = {
824824
id: 'retryToken',
825825
title: 'Retry Token',
826826
type: 'short-input',
827-
placeholder: 'Optional 1–64 character retry token. Reuse only for the same logical creation request; otherwise Sim derives an invocation key',
827+
placeholder: 'Optional 1–64 character retry token. Reuse only for the same logical request; otherwise Sim derives an invocation key',
828828
mode: 'advanced',
829829
condition: { field: 'operation', value: RETRY_TOKEN_OPERATIONS },
830830
required: false,
@@ -1373,11 +1373,39 @@ export const OciComputeBlock: BlockConfig<OciComputeResponse> = {
13731373
tool: (params) => params.operation,
13741374
params: (params) => {
13751375
const result: Record<string, unknown> = { ...params }
1376-
for (const field of ['limit', 'bootVolumeSizeInGBs', 'bootVolumeVpusPerGB', 'size']) {
1377-
result[field] = parseOptionalNumberInput(params[field], field, { integer: true, min: field === 'size' ? 0 : 1 })
1376+
const numericOperations: Record<string, readonly string[]> = {
1377+
limit: LIMIT_OPERATIONS,
1378+
bootVolumeSizeInGBs: BOOT_VOLUME_SIZE_IN_GBS_OPERATIONS,
1379+
bootVolumeVpusPerGB: BOOT_VOLUME_VPUS_PER_GB_OPERATIONS,
1380+
size: SIZE_OPERATIONS,
1381+
}
1382+
for (const [field, operations] of Object.entries(numericOperations)) {
1383+
if (operations.includes(params.operation)) {
1384+
result[field] = parseOptionalNumberInput(params[field], field, {
1385+
integer: true,
1386+
min: field === 'size' ? 0 : 1,
1387+
})
1388+
} else delete result[field]
1389+
}
1390+
const booleanOperations: Record<string, readonly string[]> = {
1391+
allowDenseRebootMigration: ALLOW_DENSE_REBOOT_MIGRATION_OPERATIONS,
1392+
deleteLocalStorage: DELETE_LOCAL_STORAGE_OPERATIONS,
1393+
preserveBootVolume: PRESERVE_BOOT_VOLUME_OPERATIONS,
1394+
preserveDataVolumesCreatedAtLaunch: PRESERVE_DATA_VOLUMES_CREATED_AT_LAUNCH_OPERATIONS,
1395+
isAutoTerminate: IS_AUTO_TERMINATE_OPERATIONS,
1396+
isDecrementSize: IS_DECREMENT_SIZE_OPERATIONS,
1397+
compartmentIdInSubtree: COMPARTMENT_ID_IN_SUBTREE_OPERATIONS,
1398+
}
1399+
for (const [field, operations] of Object.entries(booleanOperations)) {
1400+
if (operations.includes(params.operation)) result[field] = optionalBoolean(params[field])
1401+
else delete result[field]
1402+
}
1403+
if (params.operation === 'oci_compute_create_instance_pool') {
1404+
if (result.instanceDisplayNameFormatter === '') result.instanceDisplayNameFormatter = undefined
1405+
if (result.instanceHostnameFormatter === '') result.instanceHostnameFormatter = undefined
13781406
}
1379-
for (const field of ['allowDenseRebootMigration', 'deleteLocalStorage', 'preserveBootVolume', 'preserveDataVolumesCreatedAtLaunch', 'isAutoTerminate', 'isDecrementSize', 'compartmentIdInSubtree']) {
1380-
result[field] = optionalBoolean(params[field])
1407+
if (params.operation === 'oci_compute_list_instances' && result.capacityReservationId === '') {
1408+
result.capacityReservationId = undefined
13811409
}
13821410
for (const field of ['compartmentId', 'page', 'sortBy', 'sortOrder', 'displayName', 'availabilityDomain', 'lifecycleState', 'instanceId', 'shape', 'sourceMode', 'imageId', 'imageFilter', 'bootVolumeId', 'kmsKeyId', 'freeformTags', 'definedTags', 'retryToken', 'shapeConfig', 'createVnicDetails', 'faultDomain', 'metadata', 'extendedMetadata', 'agentConfig', 'availabilityConfig', 'instanceOptions', 'dedicatedVmHostId', 'ifMatch', 'timeMaintenanceRebootDue', 'updateOperationConstraint', 'action', 'timeScheduled', 'operatingSystem', 'operatingSystemVersion', 'shapeAvailabilities', 'instanceConfigurationId', 'configurationSource', 'instanceDetails', 'instancePoolId', 'placementConfigurations', 'name', 'accessLevel', 'vcnId', 'subnetId', 'vnicId', 'resourceId', 'workRequestId']) {
13831411
if (result[field] === '') delete result[field]
@@ -1389,22 +1417,22 @@ export const OciComputeBlock: BlockConfig<OciComputeResponse> = {
13891417
throw new Error('Primary VNIC settings must be a JSON object')
13901418
}
13911419
result.createVnicDetails = { ...(vnic ?? {}), subnetId: params.subnetId }
1392-
if (params.sourceMode !== 'image') delete result.imageId
1393-
if (params.sourceMode !== 'imageFilter') delete result.imageFilter
1394-
if (params.sourceMode !== 'bootVolume') delete result.bootVolumeId
1420+
if (params.sourceMode !== 'image') result.imageId = undefined
1421+
if (params.sourceMode !== 'imageFilter') result.imageFilter = undefined
1422+
if (params.sourceMode !== 'bootVolume') result.bootVolumeId = undefined
13951423
if (params.sourceMode === 'bootVolume') {
13961424
for (const field of ['bootVolumeSizeInGBs', 'bootVolumeVpusPerGB', 'kmsKeyId']) delete result[field]
13971425
}
13981426
}
13991427
if (params.operation === 'oci_compute_create_instance_configuration') {
1400-
if (params.configurationSource === 'INSTANCE') delete result.instanceDetails
1401-
else delete result.instanceId
1428+
if (params.configurationSource === 'INSTANCE') result.instanceDetails = undefined
1429+
else result.instanceId = undefined
14021430
}
14031431
if (params.operation === 'oci_compute_instance_action') {
1404-
if (params.action !== 'RESET' && params.action !== 'SOFTRESET') delete result.allowDenseRebootMigration
1432+
if (params.action !== 'RESET' && params.action !== 'SOFTRESET') result.allowDenseRebootMigration = undefined
14051433
if (params.action !== 'REBOOTMIGRATE') {
1406-
delete result.deleteLocalStorage
1407-
delete result.timeScheduled
1434+
result.deleteLocalStorage = undefined
1435+
result.timeScheduled = undefined
14081436
}
14091437
}
14101438
return result
@@ -1436,7 +1464,7 @@ export const OciComputeBlock: BlockConfig<OciComputeResponse> = {
14361464
kmsKeyId: { type: 'string', description: 'Existing Vault key OCID for a newly created image-source boot volume' },
14371465
freeformTags: { type: 'json', description: 'Free-form tags as a string-to-string JSON map' },
14381466
definedTags: { type: 'json', description: 'Defined string tags grouped by namespace, for example {Operations: {CostCenter: "42"}}' },
1439-
retryToken: { type: 'string', description: 'Optional 1–64 character retry token. Reuse only for the same logical creation request; otherwise Sim derives an invocation key' },
1467+
retryToken: { type: 'string', description: 'Optional 1–64 character retry token. Reuse only for the same logical request; otherwise Sim derives an invocation key' },
14401468
shapeConfig: { type: 'json', description: 'Shape resources: ocpus OR vcpus, memoryInGBs, baselineOcpuUtilization, nvmes; use List Shapes for valid ranges' },
14411469
createVnicDetails: { type: 'json', description: 'Primary VNIC settings: subnetId (required), displayName, assignPublicIp, assignPrivateDnsRecord, hostnameLabel, privateIp/privateIpId/subnetCidr, nsgIds, skipSourceDestCheck, assignIpv6Ip, ipv6AddressIpv6SubnetCidrPairDetails' },
14421470
faultDomain: { type: 'string', description: 'Fault domain within the selected availability domain' },

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,17 @@ describe('OCI Compute trusted execution wiring', () => {
6060
})
6161

6262
it('does not accept payload workspace or compatibility token as authority', async () => {
63-
const response = await executeOciComputeTool(call({
64-
input: { oauthCredential: 'submitted', region: 'us-ashburn-1', instanceId: 'instance', workspaceId: 'other', accessToken: 'token' },
65-
}))
63+
const response = await executeOciComputeTool(
64+
call({
65+
input: {
66+
oauthCredential: 'submitted',
67+
region: 'us-ashburn-1',
68+
instanceId: 'instance',
69+
workspaceId: 'other',
70+
accessToken: 'token',
71+
},
72+
})
73+
)
6674
expect(response.status).toBe(400)
6775
expect(mocks.createClient).not.toHaveBeenCalled()
6876
})

0 commit comments

Comments
 (0)