-
Notifications
You must be signed in to change notification settings - Fork 164
Add /setup-prerequisites skill to the power-pages plugin #319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Priyanshu Agrawal (priyanshu92)
wants to merge
5
commits into
main
Choose a base branch
from
users/priyanshu92/crispy-guacamole
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5e65866
Add /setup-prerequisites skill to the power-pages plugin
priyanshu92 d7648a6
Make /setup-prerequisites user-invoked only
priyanshu92 83e28b5
Check and install Git in /setup-prerequisites
priyanshu92 b2e5d12
Check and install the GitHub CLI in /setup-prerequisites
priyanshu92 22f46bb
address PR review feedback
priyanshu92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
230 changes: 230 additions & 0 deletions
230
plugins/power-pages/scripts/tests/detect-prerequisites.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,230 @@ | ||
| const test = require('node:test'); | ||
| const assert = require('node:assert/strict'); | ||
|
|
||
| const { | ||
| buildProbeInvocation, | ||
| parsePacVersion, | ||
| parseAzVersion, | ||
| parseDotnetVersion, | ||
| parseGitVersion, | ||
| parsePacAuthWho, | ||
| parseAzAccountShow, | ||
| compareVersions, | ||
| latestStableVersion, | ||
| buildActions, | ||
| tenantMismatch, | ||
| } = require('../../skills/setup-prerequisites/scripts/detect-prerequisites'); | ||
|
|
||
| // Captured from `pac help` on 1.51.1 — the version carries a `+<git-sha>` build | ||
| // suffix that must not leak into the comparison against NuGet's plain semver. | ||
| const PAC_HELP = ` | ||
| Microsoft PowerPlatform CLI | ||
|
|
||
| Version: 1.51.1+g8a2ec33 | ||
|
|
||
| Usage: pac [command] [options] | ||
| `; | ||
|
|
||
| // Captured from `pac auth who` on 2.9.3. Note the "Tenant Id" casing, and that | ||
| // the banner opens with a "Connected as" line before the label/value block. | ||
| const PAC_AUTH_WHO = ` | ||
| Connected as user@contoso.com | ||
|
|
||
| Type: User | ||
| Cloud: Public | ||
| Tenant Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 | ||
| Tenant Country: IN | ||
| User: user@contoso.com | ||
| Environment Id: 11111111-1111-1111-1111-111111111111 | ||
| Organization Friendly Name: Contoso Dev | ||
| `; | ||
|
|
||
| function statusFixture(overrides = {}) { | ||
| return Object.assign( | ||
| { | ||
| node: { available: true, version: '22.11.0' }, | ||
| git: { available: true, version: '2.53.0' }, | ||
| dotnet: { available: true, version: '10.0.102' }, | ||
| pac: { available: true, version: '1.51.1', updateAvailable: false }, | ||
| az: { available: true, version: '2.77.0' }, | ||
| pacAuth: { signedIn: true, tenantId: 'tenant-a' }, | ||
| azAuth: { signedIn: true, tenantId: 'tenant-a' }, | ||
| }, | ||
| overrides | ||
| ); | ||
| } | ||
|
|
||
| // The Azure CLI installs only `az.cmd` on Windows, which Node refuses to spawn | ||
| // directly, so every Windows probe goes through `cmd.exe /c`. | ||
| test('buildProbeInvocation routes Windows probes through cmd.exe', () => { | ||
| assert.deepEqual(buildProbeInvocation('az', ['version', '-o', 'tsv'], 'win32'), { | ||
| file: 'cmd.exe', | ||
| args: ['/c', 'az', 'version', '-o', 'tsv'], | ||
| }); | ||
| }); | ||
|
|
||
| test('buildProbeInvocation runs the command directly off Windows', () => { | ||
| for (const platform of ['darwin', 'linux']) { | ||
| assert.deepEqual(buildProbeInvocation('az', ['account', 'show'], platform), { | ||
| file: 'az', | ||
| args: ['account', 'show'], | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| test('parsePacVersion strips the build-metadata suffix', () => { assert.equal(parsePacVersion(PAC_HELP), '1.51.1'); | ||
| }); | ||
|
|
||
| test('parsePacVersion returns null for missing or unparseable output', () => { | ||
| assert.equal(parsePacVersion(null), null); | ||
| assert.equal(parsePacVersion('command not found: pac'), null); | ||
| }); | ||
|
|
||
| test('parseAzVersion reads the version from tsv output', () => { | ||
| assert.equal(parseAzVersion('2.77.0\t2.77.0\t\t\n'), '2.77.0'); | ||
| assert.equal(parseAzVersion(null), null); | ||
| }); | ||
|
|
||
| test('parseDotnetVersion handles stable and preview SDKs', () => { | ||
| assert.equal(parseDotnetVersion('10.0.102\n'), '10.0.102'); | ||
| assert.equal(parseDotnetVersion('9.0.100-preview.1.24101.2\n'), '9.0.100-preview.1.24101.2'); | ||
| assert.equal(parseDotnetVersion(null), null); | ||
| }); | ||
|
|
||
| test('parseGitVersion reads upstream and Apple-shipped builds', () => { | ||
| assert.equal(parseGitVersion('git version 2.53.0\n'), '2.53.0'); | ||
| assert.equal(parseGitVersion('git version 2.39.5 (Apple Git-154)\n'), '2.39.5'); | ||
| assert.equal(parseGitVersion('git version 2.51.0.windows.1\n'), '2.51.0'); | ||
| assert.equal(parseGitVersion(null), null); | ||
| assert.equal(parseGitVersion('command not found: git'), null); | ||
| }); | ||
|
|
||
| test('parsePacAuthWho extracts tenant, user, and cloud', () => { | ||
| const auth = parsePacAuthWho(PAC_AUTH_WHO); | ||
| assert.equal(auth.signedIn, true); | ||
| assert.equal(auth.tenantId, '72f988bf-86f1-41af-91ab-2d7cd011db47'); | ||
| assert.equal(auth.user, 'user@contoso.com'); | ||
| assert.equal(auth.cloud, 'Public'); | ||
| }); | ||
|
|
||
| test('parsePacAuthWho accepts the older "Tenant ID" casing', () => { | ||
| const auth = parsePacAuthWho('Tenant ID: t-1\nUser: u@c.com'); | ||
| assert.equal(auth.tenantId, 't-1'); | ||
| }); | ||
|
|
||
| test('parsePacAuthWho reports signed out when no profile exists', () => { | ||
| assert.deepEqual(parsePacAuthWho('No profiles were found on this computer.'), { | ||
| signedIn: false, | ||
| tenantId: null, | ||
| user: null, | ||
| cloud: null, | ||
| }); | ||
| assert.equal(parsePacAuthWho(null).signedIn, false); | ||
| assert.equal(parsePacAuthWho('some unrelated banner text').signedIn, false); | ||
| }); | ||
|
|
||
| test('parseAzAccountShow extracts tenant, user, and subscription', () => { | ||
| const account = parseAzAccountShow( | ||
| JSON.stringify({ tenantId: 'tenant-a', user: { name: 'user@contoso.com' }, name: 'Pay-As-You-Go' }) | ||
| ); | ||
| assert.deepEqual(account, { | ||
| signedIn: true, | ||
| tenantId: 'tenant-a', | ||
| user: 'user@contoso.com', | ||
| subscription: 'Pay-As-You-Go', | ||
| }); | ||
| }); | ||
|
|
||
| test('parseAzAccountShow treats a subscription-less account as signed in', () => { | ||
| const account = parseAzAccountShow(JSON.stringify({ tenantId: 'tenant-a', user: { name: 'u@c.com' } })); | ||
| assert.equal(account.signedIn, true); | ||
| assert.equal(account.subscription, null); | ||
| }); | ||
|
|
||
| test('parseAzAccountShow reports signed out for null, non-JSON, and empty payloads', () => { | ||
| assert.equal(parseAzAccountShow(null).signedIn, false); | ||
| assert.equal(parseAzAccountShow("Please run 'az login' to setup account.").signedIn, false); | ||
| assert.equal(parseAzAccountShow('{}').signedIn, false); | ||
| assert.equal(parseAzAccountShow('null').signedIn, false); | ||
| }); | ||
|
|
||
| test('compareVersions orders versions and ignores prerelease suffixes', () => { | ||
| assert.equal(compareVersions('1.51.1', '1.52.0'), 1); | ||
| assert.equal(compareVersions('1.52.0', '1.51.1'), -1); | ||
| assert.equal(compareVersions('1.51.1', '1.51.1'), 0); | ||
| assert.equal(compareVersions('1.51.1-preview', '1.51.1'), 0); | ||
| assert.equal(compareVersions('1.51', '1.51.0'), 0); | ||
| assert.equal(compareVersions(null, '1.51.1'), 0); | ||
| }); | ||
|
|
||
| test('latestStableVersion picks the last stable entry', () => { | ||
| assert.equal(latestStableVersion(['1.50.1', '1.51.1', '1.52.1']), '1.52.1'); | ||
| assert.equal(latestStableVersion(['1.50.1', '1.52.0-preview']), '1.50.1'); | ||
| assert.equal(latestStableVersion([]), null); | ||
| assert.equal(latestStableVersion(undefined), null); | ||
| }); | ||
|
|
||
| test('buildActions is empty when everything is present and signed in', () => { | ||
| assert.deepEqual(buildActions(statusFixture()), []); | ||
| }); | ||
|
|
||
| test('buildActions reports one install per missing tool', () => { | ||
| const actions = buildActions( | ||
| statusFixture({ | ||
| git: { available: false, version: null }, | ||
| dotnet: { available: false, version: null }, | ||
| az: { available: false, version: null }, | ||
| azAuth: { signedIn: false, tenantId: null }, | ||
| }) | ||
| ); | ||
| assert.deepEqual(actions, [ | ||
| { tool: 'git', kind: 'install' }, | ||
| { tool: 'dotnet', kind: 'install' }, | ||
| { tool: 'az', kind: 'install' }, | ||
| ]); | ||
| }); | ||
|
|
||
| test('buildActions does not ask a missing CLI to sign in', () => { | ||
| const actions = buildActions( | ||
| statusFixture({ | ||
| pac: { available: false, version: null, updateAvailable: false }, | ||
| pacAuth: { signedIn: false, tenantId: null }, | ||
| }) | ||
| ); | ||
| assert.deepEqual(actions, [{ tool: 'pac', kind: 'install' }]); | ||
| }); | ||
|
|
||
| test('buildActions offers a pac update only when pac is installed', () => { | ||
| const actions = buildActions( | ||
| statusFixture({ pac: { available: true, version: '1.50.1', updateAvailable: true } }) | ||
| ); | ||
| assert.deepEqual(actions, [{ tool: 'pac', kind: 'update' }]); | ||
| }); | ||
|
|
||
| test('buildActions asks a signed-out but installed CLI to sign in', () => { | ||
| const actions = buildActions(statusFixture({ azAuth: { signedIn: false, tenantId: null } })); | ||
| assert.deepEqual(actions, [{ tool: 'az', kind: 'signin' }]); | ||
| }); | ||
|
|
||
| test('tenantMismatch flags differing tenants', () => { | ||
| const mismatch = tenantMismatch( | ||
| { signedIn: true, tenantId: 'tenant-a' }, | ||
| { signedIn: true, tenantId: 'tenant-b' } | ||
| ); | ||
| assert.deepEqual(mismatch, { pacTenantId: 'tenant-a', azTenantId: 'tenant-b' }); | ||
| }); | ||
|
|
||
| test('tenantMismatch ignores casing differences', () => { | ||
| assert.equal( | ||
| tenantMismatch({ signedIn: true, tenantId: 'TENANT-A' }, { signedIn: true, tenantId: 'tenant-a' }), | ||
| null | ||
| ); | ||
| }); | ||
|
|
||
| test('tenantMismatch stays silent when either side is signed out or unknown', () => { | ||
| assert.equal(tenantMismatch({ signedIn: false }, { signedIn: true, tenantId: 'tenant-b' }), null); | ||
| assert.equal( | ||
| tenantMismatch({ signedIn: true, tenantId: null }, { signedIn: true, tenantId: 'tenant-b' }), | ||
| null | ||
| ); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.