diff --git a/apps/sim/blocks/blocks/onedrive.ts b/apps/sim/blocks/blocks/onedrive.ts index a867888c9e4..442a9ba51f3 100644 --- a/apps/sim/blocks/blocks/onedrive.ts +++ b/apps/sim/blocks/blocks/onedrive.ts @@ -156,6 +156,7 @@ export const OneDriveBlock: BlockConfig = { placeholder: 'Select file type', condition: { field: 'operation', value: 'create_file' }, required: true, + value: () => 'text/plain', }, // Excel values input when creating an .xlsx file { @@ -558,6 +559,7 @@ export const OneDriveBlock: BlockConfig = { placeholder: 'Select link type', condition: { field: 'operation', value: 'create_share_link' }, required: true, + value: () => 'view', }, { id: 'linkScope', diff --git a/apps/sim/lib/workflows/code/hand-written.test.ts b/apps/sim/lib/workflows/code/hand-written.test.ts index dd3bcb92150..363295285c0 100644 --- a/apps/sim/lib/workflows/code/hand-written.test.ts +++ b/apps/sim/lib/workflows/code/hand-written.test.ts @@ -272,6 +272,37 @@ export default workflow('Lookup', {}, () => { expect(paramsOf(diagnostics, 'W_REQUIRED_MISSING')).toEqual([]) }) + it('types and compiles OneDrive calls that leave out the link type and file type the tools default', () => { + const text = `${HEADER}import { credential, onedrive, trigger, workflow } from '@sim/workflow-sdk' +export default workflow('Share', {}, () => { + trigger.start('Start', {}) + onedrive.createFile('Create', { + credential: credential('drive'), + fileName: 'notes.txt', + content: 'hello', + }) + onedrive.createSharingLink('Share', { + credential: credential('drive'), + shareLinkFileId: 'file-1', + }) +}) +` + expect(typeCheck('onedrive-defaults', text)).toBe('') + const compiled = compile(text) + expect(compiled.diagnostics.filter((d) => d.severity !== 'info')).toEqual([]) + if (!compiled.workflow) throw new Error('OneDrive source did not compile') + const stored = materialize(compiled.workflow, null, { + catalog, + hooks, + resources: RESOURCES, + lockFreshness: 'none', + }).state + const byName = new Map(Object.values(stored.blocks).map((block) => [block.name, block])) + const created = byName.get('Create')?.subBlocks + expect([created?.mimeType?.value, created?.content?.value]).toEqual(['text/plain', 'hello']) + expect(byName.get('Share')?.subBlocks.linkType?.value).toBe('view') + }, 120_000) + it('keeps a credential in a workflow variable out of the file and compiles it back', () => { const key = ['sk-proj-', 'abcdefghijklmnopqrstuvwxyz', '123456'].join('') const text = `${HEADER}import { trigger, workflow } from '@sim/workflow-sdk' diff --git a/packages/workflow-sdk/src/codegen/generate.ts b/packages/workflow-sdk/src/codegen/generate.ts index a871b6192b0..c6155a6a840 100644 --- a/packages/workflow-sdk/src/codegen/generate.ts +++ b/packages/workflow-sdk/src/codegen/generate.ts @@ -236,7 +236,7 @@ export interface ParamFacts { common: ParamFact[] gate: { key: string - /** The gate's value when it is omitted, if any. */ + /** The value an omitted gate is documented as (see `defaultGateValue`), if any. */ default?: Scalar variants: Array<{ values: Scalar[]; params: ParamFact[] }> } | null @@ -268,9 +268,12 @@ export function operationLabel(block: CatalogBlock, operation: string): string | } /** - * The value an omitted gate runs as: its declared default, else its first option. A gate the - * builder requires has none (`requiredForBuilder`), since creation stores `null` for it and the - * compiler reports it missing. + * The value the params type documents an omitted gate as: its declared default, else its first + * option. Creation stores the declared default; a gate with none is stored `null`, so the first + * option holds only because its tool reads a missing value as that option (`github`'s + * `commentType`, `textract`'s `processingMode`, `mistral_parse`'s `inputMethod`): an optional gate + * with no default must keep that true. A gate the builder requires has none + * (`requiredForBuilder`): the compiler reports it missing. */ function defaultGateValue( candidates: readonly CatalogSubBlock[], diff --git a/packages/workflow-sdk/src/codegen/reference.test.ts b/packages/workflow-sdk/src/codegen/reference.test.ts index 5dd3dc059d9..fe3258e97be 100644 --- a/packages/workflow-sdk/src/codegen/reference.test.ts +++ b/packages/workflow-sdk/src/codegen/reference.test.ts @@ -105,13 +105,22 @@ function fieldsRead(sub: CatalogSubBlock): string[] { } /** - * Compiles `('X', {})` for every builder and returns each `W_REQUIRED_MISSING` param the - * builder's params facts show optional. A field whose requirement reads another field the call may - * set (`provider`, `authType`) is not counted: the type cannot know that value. + * Compiles `('X', {})` for every builder and compares its `W_REQUIRED_MISSING` params with + * the builder's params facts: `optional` lists each refused param the facts show optional, and + * `accepted` each param the facts show required that the compiler let the call omit. A field whose + * requirement reads another field the call may set (`provider`, `authType`) is not counted as + * refused: the type cannot know that value. */ -function optionalButRefused(catalog: BlockCatalog): { refused: number; optional: string[] } { +function requiredMismatches(catalog: BlockCatalog): { + refused: number + typedRequired: number + optional: string[] + accepted: string[] +} { const optional: string[] = [] + const accepted: string[] = [] let refused = 0 + let typedRequired = 0 for (const key of catalogBuilderPaths(catalog)) { const reference = describeBuilder(catalog, key) const builder = catalogBuilder(catalog, key) @@ -128,8 +137,10 @@ function optionalButRefused(catalog: BlockCatalog): { refused: number; optional: catalog, sdkMajor: catalog.sdkMajor, }) + const missing = new Set() for (const { code, param } of result.diagnostics) { if (code !== 'W_REQUIRED_MISSING' || !param) continue + missing.add(param) const declarations = block.subBlocks.filter( (sub) => sub.id === param || sub.canonicalParamId === param ) @@ -146,8 +157,15 @@ function optionalButRefused(catalog: BlockCatalog): { refused: number; optional: optional.push(`${key}.${param}`) } } + const { common, gate } = reference.params + const required = [ + ...common.filter((fact) => fact.required).map((fact) => fact.key), + ...(gate && gate.default === undefined ? [gate.key] : []), + ] + typedRequired += required.length + for (const param of required) if (!missing.has(param)) accepted.push(`${key}.${param}`) } - return { refused, optional } + return { refused, typedRequired, optional, accepted } } /** The fixture catalog with Slack's required `listShareTarget` gate stripped of its default. */ @@ -174,8 +192,18 @@ describe('required params', () => { ['the fixture catalog', () => CATALOG], ['a required gate with no default', withBareRequiredGate], ])('marks required every param the compiler refuses to omit, over %s', (_label, catalog) => { - const { refused, optional } = optionalButRefused(catalog()) + const { refused, optional } = requiredMismatches(catalog()) expect(refused).toBeGreaterThan(0) expect(optional).toEqual([]) }) + + /** The reverse: a param the type shows required is one `check` refuses a call to omit. */ + it.each([ + ['the fixture catalog', () => CATALOG], + ['a required gate with no default', withBareRequiredGate], + ])('refuses to compile a call that omits a param typed required, over %s', (_label, catalog) => { + const { typedRequired, accepted } = requiredMismatches(catalog()) + expect(typedRequired).toBeGreaterThan(0) + expect(accepted).toEqual([]) + }) })