Skip to content

Migrates flow commands to Zod#7373

Open
waldekmastykarz wants to merge 2 commits into
pnp:mainfrom
waldekmastykarz:waldekmastykarz/migrate-flow-to-zod
Open

Migrates flow commands to Zod#7373
waldekmastykarz wants to merge 2 commits into
pnp:mainfrom
waldekmastykarz:waldekmastykarz/migrate-flow-to-zod

Conversation

@waldekmastykarz
Copy link
Copy Markdown
Member

Closes #7304

Summary

Migrates all 13 remaining flow commands from the legacy Options/constructor validation pattern to Zod schema validation.

Commands migrated

  • flow disable, flow enable, flow get, flow export, flow list, flow remove
  • flow owner list, flow owner ensure, flow owner remove
  • flow run cancel, flow run get, flow run list, flow run resubmit

Changes

  • Replaced interface Options extends GlobalOptions + #initOptions/#initValidators/#initTelemetry with exported Zod schemas using z.strictObject() and globalOptionsZod.shape
  • Added get schema() getter and getRefinedSchema() where cross-field validation is needed
  • Used z.uuid() for GUID validation, z.enum() for enum options, .refine() for UPN and ISO datetime validation
  • Updated all 13 test files to use commandOptionsSchema.safeParse() pattern
  • Added accessToken.assertAccessTokenType stub to all test files
  • Removed obsolete "supports specifying" tests

Testing

  • All 15720 tests pass
  • Build passes

Migrates all flow commands to use Zod schema validation,
replacing the old interface-based Options pattern with
exported Zod schemas.

Commands migrated:
- flow disable, enable, get, export, list, remove
- flow owner list, ensure, remove
- flow run cancel, get, list, resubmit

Closes pnp#7304

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request migrates the remaining flow commands from the legacy option/validator/telemetry pattern to the repository’s Zod-based schema validation, aligning them with the newer command framework behavior (schema-driven option metadata, validation, and telemetry).

Changes:

  • Introduces exported Zod options schemas (plus schema / getRefinedSchema) for flow run/owner/flow commands.
  • Replaces custom GUID/status/datetime validation logic with Zod primitives (z.uuid(), z.enum(), .refine()), including cross-field rules via getRefinedSchema.
  • Updates corresponding Mocha tests to validate inputs via commandInfo.command.getSchemaToParse().safeParse(...) and stubs accessToken.assertAccessTokenType.

Reviewed changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/m365/flow/commands/run/run-resubmit.ts Migrates flow run resubmit options/validation to Zod schema.
src/m365/flow/commands/run/run-resubmit.spec.ts Updates validation tests to use schema safeParse and adds access token stub.
src/m365/flow/commands/run/run-list.ts Migrates flow run list to Zod, including refined cross-field validation for withTrigger.
src/m365/flow/commands/run/run-list.spec.ts Updates validation tests to schema-based safeParse and stubs access token assertion.
src/m365/flow/commands/run/run-get.ts Migrates flow run get options/validation to Zod schema.
src/m365/flow/commands/run/run-get.spec.ts Updates validation tests to schema-based safeParse and stubs access token assertion.
src/m365/flow/commands/run/run-cancel.ts Migrates flow run cancel options/validation to Zod schema.
src/m365/flow/commands/run/run-cancel.spec.ts Updates validation tests to schema-based safeParse and stubs access token assertion.
src/m365/flow/commands/owner/owner-remove.ts Migrates flow owner remove to Zod and replaces option set logic with refined schema rule.
src/m365/flow/commands/owner/owner-remove.spec.ts Updates validation tests to schema safeParse, adds tests for option set behavior, and stubs access token assertion.
src/m365/flow/commands/owner/owner-list.ts Migrates flow owner list options/validation to Zod schema.
src/m365/flow/commands/owner/owner-list.spec.ts Updates validation tests to schema-based safeParse and stubs access token assertion.
src/m365/flow/commands/owner/owner-ensure.ts Migrates flow owner ensure to Zod and replaces option set logic with refined schema rule.
src/m365/flow/commands/owner/owner-ensure.spec.ts Updates validation tests to schema safeParse, adds tests for option set behavior, and stubs access token assertion.
src/m365/flow/commands/flow-remove.ts Migrates flow remove GUID validation to Zod (z.uuid()) and schema-based parsing.
src/m365/flow/commands/flow-remove.spec.ts Updates validation tests to schema-based safeParse and stubs access token assertion.
src/m365/flow/commands/flow-list.ts Migrates flow list to Zod and adds refined validation for mutually exclusive options.
src/m365/flow/commands/flow-list.spec.ts Updates validation tests to schema-based safeParse and stubs access token assertion.
src/m365/flow/commands/flow-get.ts Migrates flow get to Zod schema.
src/m365/flow/commands/flow-get.spec.ts Adds access token assertion stub (no schema-based validation tests added here).
src/m365/flow/commands/flow-export.ts Migrates flow export to Zod schema with refined validations (format-related and filesystem path checks).
src/m365/flow/commands/flow-export.spec.ts Updates validation tests to schema-based safeParse.
src/m365/flow/commands/flow-enable.ts Migrates flow enable to Zod schema.
src/m365/flow/commands/flow-enable.spec.ts Adds access token assertion stub.
src/m365/flow/commands/flow-disable.ts Migrates flow disable to Zod schema.
src/m365/flow/commands/flow-disable.spec.ts Adds access token assertion stub.

Comment thread src/m365/flow/commands/owner/owner-ensure.ts Outdated
Comment thread src/m365/flow/commands/owner/owner-remove.ts Outdated
Comment thread src/m365/flow/commands/run/run-get.spec.ts Outdated
@MartinM85 MartinM85 marked this pull request as draft June 3, 2026 05:40
- Replace z.uuid() with z.string().refine(validation.isValidGuid) for userId
  and groupId in owner-ensure and owner-remove to support @meid token
- Fix misleading test description in run-get.spec.ts

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@waldekmastykarz waldekmastykarz marked this pull request as ready for review June 5, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate flow commands to Zod

2 participants