Skip to content

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

Closed
amitjoshi438 wants to merge 2 commits into
microsoft:mainfrom
amitjoshi438:amitjoshi-power-pages-uri-handlers-pr2
Closed

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

Conversation

@amitjoshi438

Copy link
Copy Markdown
Contributor

PR 2 of 3 (Phase 0-1 foundation). Stacked on #1625.

Focus commit

2c5d46e - Extract shared PAC auth/environment helpers into AuthEnvironmentService (behavior-preserving). Moves prepareAuthenticationAndEnvironment / ensureAuthentication / ensureCorrectEnvironment / resetPacProcess* out of uriHandler.ts into a reusable AuthEnvironmentService so the upcoming create handlers can share them.

Validation

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

Note on diff

Base is main because the PR 1 branch cannot be pushed to the upstream repo (contributor works from fork amitjoshi438/powerplatform-vscode). This PR's diff therefore also contains PR 1's commit (9d91979). Review only the focus commit 2c5d46e, and merge after #1625.

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

Amit Joshi and others added 2 commits July 21, 2026 16:18
Convert `UriHandler.handleUri` from an if/else chain into a
`ReadonlyMap<string, UriRouteHandler>` built in the constructor. The two
existing paths (`/pcfInit`, `/open`) keep identical behavior; unrecognized
paths are now ignored for forward compatibility instead of falling through.

Add the versioned deep-link contract constants that the Power Pages home
page will use to launch VS Code:
- reserved paths `/agenticCreate` and `/pacCreate` (registered but not yet
  wired to any handler)
- shared params `region`, `tenantid`, `source`, `agenthost`, `v`
- enumerated `SOURCE_VALUES`, `AGENT_HOST_VALUES`, and `CONTRACT_VERSION`

Export the `UriHandler` class so dispatch can be covered by an integration
test. Adds a pure unit test asserting the constants contract and an
integration test asserting each path routes correctly (including the
reserved/unknown no-op paths).

This change is behavior-preserving and ships dark: no new user-facing
behavior. Follow-up PRs extract shared auth/env helpers and add the
flag-gated skeleton handlers.

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

Copy link
Copy Markdown
Contributor Author

Superseded: re-raised directly against the base repo (no fork) so CI secrets are available and the stack has proper isolated per-PR diffs. Replaced by #1628 / #1629 / #1630.

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