Skip to content

URI handler (2/3): extract shared auth/environment service#1629

Open
amitjoshi438 wants to merge 1 commit into
mainfrom
amitjoshi-power-pages-uri-handlers-pr2
Open

URI handler (2/3): extract shared auth/environment service#1629
amitjoshi438 wants to merge 1 commit into
mainfrom
amitjoshi-power-pages-uri-handlers-pr2

Conversation

@amitjoshi438

Copy link
Copy Markdown
Contributor

PR 2 of 3 - Phase 0-1 foundation. Behavior-preserving refactor. Stacked on PR 1 (base branch = amitjoshi-power-pages-uri-handlers), so the diff shows only this PR's commit.

Focus commit

2c5d46e2 - Extract shared PAC auth/environment helpers into AuthEnvironmentService.

What changed

Moves prepareAuthenticationAndEnvironment / ensureAuthentication / ensureCorrectEnvironment / resetPacProcess* out of uriHandler.ts into a new reusable uriHandler/utils/authEnvironment.ts service, and refactors uriHandler.ts to compose/delegate to it. Verbatim moves - the auth/environment behavior of /open is unchanged. This service is what the new create handlers (PR 3) will reuse in later phases.

Tests

  • test/integration/authEnvironment.test.ts (new) - covers the extracted service.

Validation

gulp lint clean; compile-tests clean; npm test 106 passing; npm run build OK.

Stack

  1. PR 1/3 -> main
  2. this PR -> amitjoshi-power-pages-uri-handlers (auto-retargets to main when PR 1 merges)
  3. PR 3/3 -> based on this branch

Merge after PR 1.

Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com

Move the PAC CLI authentication, environment-selection, and process-reset
logic out of the `UriHandler` class into a new
`utils/authEnvironment.ts` `AuthEnvironmentService` that takes a
`PacWrapper`. `UriHandler` now composes the service and delegates:
- `handleOpenPowerPages` (`/open`) calls
  `authEnvironmentService.prepareAuthenticationAndEnvironment(...)`
- `executeDownload` calls `authEnvironmentService.resetPacProcessSafely(...)`

This is a behavior-preserving refactor: the moved methods
(`prepareAuthenticationAndEnvironment`, `ensureAuthentication`,
`ensureCorrectEnvironment`, `resetPacProcessAndThrow`,
`resetPacProcessSafely`) keep identical logic, telemetry, prompts, and
error handling. Extracting them lets the upcoming `/pacCreate` and
`/agenticCreate` handlers reuse the exact same auth/environment flow
instead of duplicating it.

Adds an integration test (`test/integration/authEnvironment.test.ts`)
covering the no-prompt happy path, the environment-switch path, and the
reset-safely / reset-and-throw error behaviors with a stubbed PacWrapper.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@amitjoshi438
amitjoshi438 force-pushed the amitjoshi-power-pages-uri-handlers-pr2 branch from 2c5d46e to a93ae2f Compare July 22, 2026 11:32
@amitjoshi438
amitjoshi438 marked this pull request as ready for review July 22, 2026 11:32
@amitjoshi438
amitjoshi438 requested review from a team as code owners July 22, 2026 11:32
@amitjoshi438

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main; now shows only its focus commit.

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.

1 participant