Migrate SPO user and web commands to Zod - #7555
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: d6c8be33-3d2b-441a-8903-6bd91286150e
There was a problem hiding this comment.
Pull request overview
This PR migrates the targeted SharePoint Online (spo user, spo userprofile, and selected spo web) commands from the legacy initOptions/initValidators pattern to Zod-based schemas, aligning them with the CLI’s schema-driven parsing/validation pipeline while updating the associated unit tests to validate through the refined schemas.
Changes:
- Introduces exported Zod
optionsschemas (+schemagetters /getRefinedSchemawhere needed) across the listedspo user,spo userprofile, andspo webcommands. - Updates unit tests to validate via
commandInfo.command.getSchemaToParse()and to pass parsed options intocommand.action. - Preserves “unknown option passthrough” behavior for
spo web setvia a loose schema and zod-aware unknown-option payload handling.
Reviewed changes
Copilot reviewed 38 out of 38 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/m365/spo/commands/web/web-set.ts | Migrates spo web set to a loose Zod schema and zod-based unknown-option passthrough. |
| src/m365/spo/commands/web/web-set.spec.ts | Updates tests to validate/parse via refined schema; keeps unknown-option acceptance coverage. |
| src/m365/spo/commands/web/web-roleinheritance-reset.ts | Migrates spo web roleinheritance reset to strict Zod schema (+ aliases). |
| src/m365/spo/commands/web/web-roleinheritance-reset.spec.ts | Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage. |
| src/m365/spo/commands/web/web-roleinheritance-break.ts | Migrates spo web roleinheritance break to strict Zod schema (+ aliases). |
| src/m365/spo/commands/web/web-roleinheritance-break.spec.ts | Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage. |
| src/m365/spo/commands/web/web-roleassignment-remove.ts | Migrates spo web roleassignment remove to strict Zod schema and option-set refinement. |
| src/m365/spo/commands/web/web-roleassignment-remove.spec.ts | Updates tests to validate/parse via refined schema; strengthens “request was called” assertions. |
| src/m365/spo/commands/web/web-roleassignment-add.ts | Migrates spo web roleassignment add to strict Zod schema with two option-set refinements. |
| src/m365/spo/commands/web/web-roleassignment-add.spec.ts | Updates tests to validate/parse via refined schema; strengthens “request was called” assertions. |
| src/m365/spo/commands/web/web-retentionlabel-list.ts | Migrates spo web retentionlabel list to strict Zod schema (+ alias). |
| src/m365/spo/commands/web/web-retentionlabel-list.spec.ts | Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage. |
| src/m365/spo/commands/web/web-remove.ts | Migrates spo web remove to strict Zod schema (+ aliases). |
| src/m365/spo/commands/web/web-remove.spec.ts | Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage. |
| src/m365/spo/commands/web/web-reindex.ts | Migrates spo web reindex to strict Zod schema (+ alias). |
| src/m365/spo/commands/web/web-reindex.spec.ts | Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage. |
| src/m365/spo/commands/web/web-list.ts | Migrates spo web list to strict Zod schema (+ alias). |
| src/m365/spo/commands/web/web-list.spec.ts | Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage. |
| src/m365/spo/commands/web/web-installedlanguage-list.ts | Migrates spo web installedlanguage list to strict Zod schema (+ alias). |
| src/m365/spo/commands/web/web-installedlanguage-list.spec.ts | Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage. |
| src/m365/spo/commands/web/web-get.ts | Migrates spo web get to strict Zod schema for URL + boolean flags. |
| src/m365/spo/commands/web/web-get.spec.ts | Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage. |
| src/m365/spo/commands/web/web-clientsidewebpart-list.ts | Migrates spo web clientsidewebpart list to strict Zod schema (+ alias). |
| src/m365/spo/commands/web/web-clientsidewebpart-list.spec.ts | Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage. |
| src/m365/spo/commands/web/web-add.ts | Migrates spo web add to strict Zod schema (+ aliases) and aligns verbose message with schema option naming. |
| src/m365/spo/commands/web/web-add.spec.ts | Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage. |
| src/m365/spo/commands/userprofile/userprofile-set.ts | Migrates spo userprofile set to strict Zod schema (+ aliases). |
| src/m365/spo/commands/userprofile/userprofile-set.spec.ts | Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage. |
| src/m365/spo/commands/userprofile/userprofile-get.ts | Migrates spo userprofile get to strict Zod schema with UPN validation. |
| src/m365/spo/commands/userprofile/userprofile-get.spec.ts | Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage. |
| src/m365/spo/commands/user/user-remove.ts | Migrates spo user remove to strict Zod schema + refined option-set validation. |
| src/m365/spo/commands/user/user-remove.spec.ts | Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage. |
| src/m365/spo/commands/user/user-list.ts | Migrates spo user list to strict Zod schema (+ alias). |
| src/m365/spo/commands/user/user-list.spec.ts | Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage. |
| src/m365/spo/commands/user/user-get.ts | Migrates spo user get to strict Zod schema + refined “at most one selector” validation. |
| src/m365/spo/commands/user/user-get.spec.ts | Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage. |
| src/m365/spo/commands/user/user-ensure.ts | Migrates spo user ensure to strict Zod schema + refined “exactly one selector” validation. |
| src/m365/spo/commands/user/user-ensure.spec.ts | Updates tests to validate/parse via refined schema; adds unknown-option rejection coverage. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Add principalId handling in web-roleassignment-add commandAction - Add principalId handling in web-roleassignment-remove removeRoleAssignment - Constrain id to positive integer in user-get and user-remove schemas - Assert request.post stub called in roleassignment add/remove tests Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Hi @waldekmastykarz, could you please resolve the conflicts? Thanks |
- Accept upstream npm-shrinkwrap.json and regenerate - Keep Zod migration changes in user-get.ts, add new id validation tests in Zod style - Accept deletion of fsUtil.spec.ts (moved elsewhere in main) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
MartinM85
left a comment
There was a problem hiding this comment.
Hi @waldekmastykarz, great work 🚀.
I have a couple of small comments, nothing major.
| export const options = z.strictObject({ | ||
| ...globalOptionsZod.shape, | ||
| webUrl: z.string().refine(webUrl => validation.isValidSharePointUrl(webUrl) === true, { | ||
| error: e => validation.isValidSharePointUrl(e.input as string).toString() |
There was a problem hiding this comment.
I see an inconsistency here. For some commands, you return ${e.input} is not a valid SharePoint Online site URL., while other commands return validation.isValidSharePointUrl(e.input as string).toString().
I would prefer returning ${e.input} is not a valid SharePoint Online site URL. to avoid calling validation.isValidSharePointUrl twice.
| export const options = z.strictObject({ | ||
| ...globalOptionsZod.shape, | ||
| webUrl: z.string().refine(webUrl => validation.isValidSharePointUrl(webUrl) === true, { | ||
| error: e => validation.isValidSharePointUrl(e.input as string).toString() |
| export const options = z.strictObject({ | ||
| ...globalOptionsZod.shape, | ||
| webUrl: z.string().refine(webUrl => validation.isValidSharePointUrl(webUrl) === true, { | ||
| error: e => validation.isValidSharePointUrl(e.input as string).toString() |
| export const options = z.strictObject({ | ||
| ...globalOptionsZod.shape, | ||
| webUrl: z.string().refine(webUrl => validation.isValidSharePointUrl(webUrl) === true, { | ||
| error: e => validation.isValidSharePointUrl(e.input as string).toString() |
Closes #7345
Changes
spo userandspo userprofilecommands to Zod schemasspo webcommands to Zod schemasspo web setValidation
npm run buildnpm run lint