A plugin marketplace for GitHub Copilot and other AI agents that provides Power Platform development plugins, including reusable skills, agents, and commands for building and deploying solutions.
JavaScript claude-code-pluginclaude-code-skillscode-appsgithub-copilot-pluginpower-appspower-pagespower-platform
Fix stale PAC manifest recovery during template provisioning (#649)
Priyanshu Agrawalf86af4837d8b
diff --git a/plugins/power-pages/.claude-plugin/plugin.json b/plugins/power-pages/.claude-plugin/plugin.jsonindex 89a3893b1..85abb56e9 100644--- a/plugins/power-pages/.claude-plugin/plugin.json+++ b/plugins/power-pages/.claude-plugin/plugin.json@@ -1,6 +1,6 @@{"name": "power-pages",- "version": "2.7.0",+ "version": "2.7.1","description": "Create and deploy Power Pages sites using modern development approaches. Supports code sites (SPAs) with React, Angular, Vue, or Astro. Includes ALM orchestration (plan-alm) with a solution-splitting decision tree, per-solution pipelines, Azure Blob asset advisory, manifest schema v2 for multi-solution deployments, and force-link remediation for cross-host pipeline migrations.","author": {"name": "Microsoft",diff --git a/plugins/power-pages/.plugin/plugin.json b/plugins/power-pages/.plugin/plugin.jsonindex 89a3893b1..85abb56e9 100644--- a/plugins/power-pages/.plugin/plugin.json+++ b/plugins/power-pages/.plugin/plugin.json@@ -1,6 +1,6 @@{"name": "power-pages",- "version": "2.7.0",+ "version": "2.7.1","description": "Create and deploy Power Pages sites using modern development approaches. Supports code sites (SPAs) with React, Angular, Vue, or Astro. Includes ALM orchestration (plan-alm) with a solution-splitting decision tree, per-solution pipelines, Azure Blob asset advisory, manifest schema v2 for multi-solution deployments, and force-link remediation for cross-host pipeline migrations.","author": {"name": "Microsoft",diff --git a/plugins/power-pages/scripts/lib/create-site-template-telemetry.js b/plugins/power-pages/scripts/lib/create-site-template-telemetry.jsindex 87edc4ea7..2eb3b842f 100644--- a/plugins/power-pages/scripts/lib/create-site-template-telemetry.js+++ b/plugins/power-pages/scripts/lib/create-site-template-telemetry.js@@ -100,7 +100,7 @@ function buildTemplateOutcomeEvent(fields = {}, deps = {}) {: { ...readAiAgent(deps.env || process.env), pacCliVersion: readPacCliVersion() };const payload = {pluginName: 'power-pages',- pluginVersion: readPluginVersion({ ...deps, pluginVersion: fields.pluginVersion }),+ pluginVersion: readPluginVersion(deps),sessionId: getSessionId(resolveSessionId(fields, deps.env || process.env)),correlationId: fields.correlationId || (deps.randomUUID || crypto.randomUUID)(),osName: fields.osName || osFriendlyName(os.platform()),diff --git a/plugins/power-pages/scripts/provision-template-site.js b/plugins/power-pages/scripts/provision-template-site.jsindex ac23490fb..bcd4f626c 100644--- a/plugins/power-pages/scripts/provision-template-site.js+++ b/plugins/power-pages/scripts/provision-template-site.js@@ -9,6 +9,7 @@ const { readWebsiteYml } = require('./lib/detect-project-context');const GUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;const CLONED_IDENTITY_PATH = path.join('.powerpages-site', 'website.yml');+const GENERIC_MANIFEST_PATH = path.join('.powerpages-site', '.portalconfig', 'manifest.yml');function parseArgs(argv) {const args = {};@@ -60,7 +61,11 @@ function copyMissingTemplateFiles(sourcePath, clonedPath, fsImpl = fs) {const sourceDir = path.join(sourcePath, relativeDir);for (const entry of fsImpl.readdirSync(sourceDir, { withFileTypes: true })) {const relativePath = path.join(relativeDir, entry.name);- if (relativePath === CLONED_IDENTITY_PATH) continue;+ // PAC clone has been observed to report:+ // Deleted manifest file from cloned output: ...\.powerpages-site\.portalconfig\manifest.yml+ // Both files are PAC-owned clone identity/state. Restoring the source manifest can+ // reintroduce stale powerpagecomponent IDs that do not exist in the new environment.+ if (relativePath === CLONED_IDENTITY_PATH || relativePath === GENERIC_MANIFEST_PATH) continue;const sourceEntryPath = path.join(sourcePath, relativePath);const clonedEntryPath = path.join(clonedPath, relativePath);const sourceStat = fsImpl.lstatSync(sourceEntryPath);@@ -203,13 +208,19 @@ function canonicalPathForCreation(targetPath, fsImpl = fs) {return path.join(canonicalParent, ...missingSegments);}+function normalizePathForPlatform(value, platform = process.platform) {+ const resolved = path.resolve(value);+ return platform === 'win32' ? resolved.toLowerCase() : resolved;+}++function pathEquals(firstPath, secondPath, platform = process.platform) {+ return normalizePathForPlatform(firstPath, platform) ===+ normalizePathForPlatform(secondPath, platform);+}+function pathContains(parentPath, childPath, platform = process.platform) {- const normalize = (value) => {- const resolved = path.resolve(value);- return platform === 'win32' ? resolved.toLowerCase() : resolved;- };- const parent = normalize(parentPath);- const child = normalize(childPath);+ const parent = normalizePathForPlatform(parentPath, platform);+ const child = normalizePathForPlatform(childPath, platform);return child === parent || child.startsWith(parent + path.sep);}@@ -250,6 +261,57 @@ function removeScriptCreatedOutputDirectory(outputDirectory, existedBeforeRun, f}}+function isStaleManifestUploadFailure(result) {+ const output = `${String(result.stderr || '')}\n${String(result.stdout || '')}`;+ const authenticationFailure = /(?:Authentication failed|not authenticated|AADSTS\d+|401 Unauthorized|403 Forbidden|access token (?:has )?expired|run\s+pac\s+auth)/i;+ const missingComponent = new RegExp(+ String.raw`Entity\s+'powerpagecomponent'\s+With\s+Id\s*=\s*\{?` ++ String.raw`[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}` ++ String.raw`\}?\s+Does\s+Not\s+Exist`,+ 'i'+ );+ return !authenticationFailure.test(output) &&+ missingComponent.test(output) &&+ /PortalFileContentUploadFailed/i.test(output);+}++function removeGenericManifestForRetry(clonedPath, deps = {}) {+ const fsImpl = deps.fs || fs;+ const platform = deps.platform || process.platform;+ const resolvedClonedPath = path.resolve(clonedPath);+ const manifestPath = path.join(resolvedClonedPath, GENERIC_MANIFEST_PATH);++ let manifestStat;+ try {+ manifestStat = fsImpl.lstatSync(manifestPath);+ } catch (err) {+ throw new Error(`Generic PAC manifest is unavailable at ${manifestPath}: ${err.message}`);+ }+ if (manifestStat.isSymbolicLink() || !manifestStat.isFile()) {+ throw new Error(`Generic PAC manifest is not a real regular file: ${manifestPath}`);+ }++ let canonicalClonedPath;+ let canonicalManifestPath;+ try {+ canonicalClonedPath = fsImpl.realpathSync(resolvedClonedPath);+ canonicalManifestPath = fsImpl.realpathSync(manifestPath);+ } catch (err) {+ throw new Error(`Could not resolve the generic PAC manifest safely: ${err.message}`);+ }+ const expectedCanonicalManifestPath = path.join(canonicalClonedPath, GENERIC_MANIFEST_PATH);+ if (!pathEquals(expectedCanonicalManifestPath, canonicalManifestPath, platform)) {+ throw new Error(`Generic PAC manifest resolves through a linked or unexpected path: ${manifestPath}`);+ }++ try {+ fsImpl.unlinkSync(manifestPath);+ } catch (err) {+ throw new Error(`Could not delete the generic PAC manifest at ${manifestPath}: ${err.message}`);+ }+ return manifestPath;+}+function provisionTemplateSite(options, deps = {}) {const fsImpl = deps.fs || fs;const sourcePath = path.resolve(options.sourcePath || '');@@ -400,19 +462,50 @@ function provisionTemplateSite(options, deps = {}) {};}- const uploadResult = pac([+ const uploadArgs = ['pages', 'upload-code-site','--rootPath', clonedPath,'--siteName', siteName,- ], pacCommandOptions);+ ];+ const uploadResult = pac(uploadArgs, pacCommandOptions);if (uploadResult.status !== 0) {- return {- ok: false,- step: 'upload',- clonedPath,- ...clonedIdentity,- error: commandError('pac pages upload-code-site', uploadResult),- };+ const originalUploadError = commandError('pac pages upload-code-site', uploadResult);+ if (isStaleManifestUploadFailure(uploadResult)) {+ try {+ removeGenericManifestForRetry(clonedPath, deps);+ } catch (err) {+ return {+ ok: false,+ step: 'upload',+ clonedPath,+ ...clonedIdentity,+ error: `${originalUploadError}\nStale-manifest recovery could not continue: ${err.message}`,+ };+ }++ const retryResult = pac(uploadArgs, pacCommandOptions);+ if (retryResult.status !== 0) {+ return {+ ok: false,+ step: 'upload',+ clonedPath,+ ...clonedIdentity,+ error: [+ `${originalUploadError}`,+ 'Stale-manifest recovery was attempted, but the upload retry failed.',+ commandError('pac pages upload-code-site retry', retryResult),+ ].join('\n'),+ };+ }+ } else {+ return {+ ok: false,+ step: 'upload',+ clonedPath,+ ...clonedIdentity,+ error: originalUploadError,+ };+ }}return {ok: true,@@ -437,9 +530,12 @@ module.exports = {findCodeSiteRoot,inspectCompiledOutput,inspectClonedSiteIdentity,+ isStaleManifestUploadFailure,parseArgs,pathContains,+ pathEquals,provisionTemplateSite,+ removeGenericManifestForRetry,removeScriptCreatedOutputDirectory,runNpm,runPac,diff --git a/plugins/power-pages/scripts/tests/provision-template-site.test.js b/plugins/power-pages/scripts/tests/provision-template-site.test.jsindex 2a22675a1..33d408615 100644--- a/plugins/power-pages/scripts/tests/provision-template-site.test.js+++ b/plugins/power-pages/scripts/tests/provision-template-site.test.js@@ -11,8 +11,10 @@ const {findCodeSiteRoot,inspectCompiledOutput,inspectClonedSiteIdentity,+ isStaleManifestUploadFailure,parseArgs,provisionTemplateSite,+ removeGenericManifestForRetry,runNpm,runPac,} = require('../provision-template-site');@@ -32,6 +34,82 @@ function createSource(root, { id = SOURCE_ID, name = 'Template Site' } = {}) {fs.writeFileSync(path.join(root, '.npmrc'), 'omit-lockfile-registry-resolved=true\n');}+function staleManifestFailure(fileName = 'index.html') {+ return {+ status: 1,+ stdout: '',+ stderr: [+ `Upload failed for ${fileName}.`,+ `Entity 'powerpagecomponent' With Id = ${SOURCE_ID} Does Not Exist`,+ 'PortalFileContentUploadFailed',+ ].join('\n'),+ };+}++function runUploadScenario(t, {+ firstUploadResult,+ fsImpl = fs,+ retryUploadResult = { status: 0, stdout: 'uploaded', stderr: '' },+ manifestKind = 'file',+} = {}) {+ const dir = tempDir();+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));+ const source = path.join(dir, 'source');+ const output = path.join(dir, 'output');+ const clonedPath = path.join(output, 'supplier-portal');+ const manifestPath = path.join(clonedPath, '.powerpages-site', '.portalconfig', 'manifest.yml');+ const environmentManifestPath = path.join(+ clonedPath,+ '.powerpages-site',+ '.portalconfig',+ 'target-environment-manifest.yml'+ );+ createSource(source);+ const uploadCalls = [];++ const result = provisionTemplateSite({+ sourcePath: source,+ outputDirectory: output,+ siteName: 'Supplier Portal',+ }, {+ fs: fsImpl,+ runPac(args, commandOptions) {+ if (args[1] === 'clone') {+ createSource(clonedPath, { id: CLONED_ID, name: 'Supplier Portal' });+ fs.mkdirSync(path.dirname(manifestPath), { recursive: true });+ if (manifestKind === 'file') {+ fs.writeFileSync(manifestPath, 'stale clone state\n');+ } else if (manifestKind === 'directory') {+ fs.mkdirSync(manifestPath);+ } else if (manifestKind === 'symlink') {+ const outsideManifest = path.join(dir, 'outside-manifest.yml');+ fs.writeFileSync(outsideManifest, 'outside clone\n');+ fs.symlinkSync(outsideManifest, manifestPath, 'file');+ }+ fs.writeFileSync(environmentManifestPath, 'target environment state\n');+ return { status: 0, stdout: 'cloned', stderr: '' };+ }+ uploadCalls.push({ args, cwd: commandOptions.cwd });+ return uploadCalls.length === 1 ? firstUploadResult : retryUploadResult;+ },+ runNpm(args, cwd) {+ if (args[0] === 'run') {+ fs.mkdirSync(path.join(cwd, 'dist'));+ fs.writeFileSync(path.join(cwd, 'dist', 'index.html'), '<html></html>');+ }+ return { status: 0, stdout: 'ok', stderr: '' };+ },+ });++ return {+ clonedPath,+ environmentManifestPath,+ manifestPath,+ result,+ uploadCalls,+ };+}+test('parseArgs accepts source, output, and site name', () => {assert.deepEqual(parseArgs(['--sourcePath', '/tmp/source',@@ -360,6 +438,282 @@ test('provisionTemplateSite reports upload failure without retrying', (t) => {assert.equal(calls, 2);});+test('isStaleManifestUploadFailure requires both exact PAC signatures', () => {+ assert.equal(isStaleManifestUploadFailure(staleManifestFailure('index.html')), true);+ assert.equal(isStaleManifestUploadFailure({+ status: 1,+ stdout: 'portalfilecontentuploadfailed',+ stderr: `ENTITY 'POWERPAGECOMPONENT' WITH ID = ${SOURCE_ID} DOES NOT EXIST`,+ }), true);+ assert.equal(isStaleManifestUploadFailure({+ status: 1,+ stdout: '',+ stderr: `Entity 'powerpagecomponent' With Id = ${SOURCE_ID} Does Not Exist`,+ }), false);+ assert.equal(isStaleManifestUploadFailure({+ status: 1,+ stdout: '',+ stderr: 'PortalFileContentUploadFailed',+ }), false);+ assert.equal(isStaleManifestUploadFailure({+ status: 1,+ stdout: '',+ stderr: [+ `Entity 'adx_webfile' With Id = ${SOURCE_ID} Does Not Exist`,+ 'PortalFileContentUploadFailed',+ ].join('\n'),+ }), false);+ assert.equal(isStaleManifestUploadFailure({+ status: 1,+ stdout: '',+ stderr: [+ `Entity 'powerpagecomponent' With Id = ${SOURCE_ID} Does Not Exist`,+ 'PortalFileContentUploadFailed',+ 'Authentication failed. Run pac auth create.',+ ].join('\n'),+ }), false);+});++test('provisionTemplateSite deletes the generic manifest and retries once for index.html', (t) => {+ const scenario = runUploadScenario(t, {+ firstUploadResult: staleManifestFailure('index.html'),+ });++ assert.equal(scenario.result.ok, true);+ assert.equal(scenario.uploadCalls.length, 2);+ assert.deepEqual(scenario.uploadCalls[1], scenario.uploadCalls[0]);+ assert.equal(fs.existsSync(scenario.manifestPath), false);+ assert.equal(fs.existsSync(scenario.environmentManifestPath), true);+});++test('provisionTemplateSite stale-manifest recovery is independent of compiled file names', (t) => {+ const scenario = runUploadScenario(t, {+ firstUploadResult: staleManifestFailure('assets/site.7f3a91c2.css'),+ });++ assert.equal(scenario.result.ok, true);+ assert.equal(scenario.uploadCalls.length, 2);+ assert.equal(fs.existsSync(scenario.manifestPath), false);+ assert.equal(fs.existsSync(scenario.environmentManifestPath), true);+});++test('provisionTemplateSite does not recover unrelated or partial upload failures', async (t) => {+ const failures = [+ {+ name: 'unrelated upload error',+ result: { status: 1, stdout: '', stderr: 'upload rejected' },+ },+ {+ name: 'only missing-component signature',+ result: {+ status: 1,+ stdout: '',+ stderr: `Entity 'powerpagecomponent' With Id = ${SOURCE_ID} Does Not Exist`,+ },+ },+ {+ name: 'only file-upload signature',+ result: { status: 1, stdout: '', stderr: 'PortalFileContentUploadFailed' },+ },+ {+ name: 'authentication failure',+ result: {+ status: 1,+ stdout: '',+ stderr: [+ `Entity 'powerpagecomponent' With Id = ${SOURCE_ID} Does Not Exist`,+ 'PortalFileContentUploadFailed',+ 'Authentication failed. Run pac auth create.',+ ].join('\n'),+ },+ },+ {+ name: 'different missing entity',+ result: {+ status: 1,+ stdout: '',+ stderr: [+ `Entity 'adx_webfile' With Id = ${SOURCE_ID} Does Not Exist`,+ 'PortalFileContentUploadFailed',+ ].join('\n'),+ },+ },+ ];++ for (const failure of failures) {+ await t.test(failure.name, (subtest) => {+ const scenario = runUploadScenario(subtest, { firstUploadResult: failure.result });+ assert.equal(scenario.result.ok, false);+ assert.equal(scenario.result.step, 'upload');+ assert.equal(scenario.uploadCalls.length, 1);+ assert.equal(fs.readFileSync(scenario.manifestPath, 'utf8'), 'stale clone state\n');+ });+ }+});++test('provisionTemplateSite fails closed when the generic manifest is missing', (t) => {+ const scenario = runUploadScenario(t, {+ firstUploadResult: staleManifestFailure(),+ manifestKind: 'missing',+ });++ assert.equal(scenario.result.ok, false);+ assert.equal(scenario.uploadCalls.length, 1);+ assert.match(scenario.result.error, /Entity 'powerpagecomponent'/);+ assert.match(scenario.result.error, /Stale-manifest recovery could not continue/);+ assert.match(scenario.result.error, /Generic PAC manifest is unavailable/);+});++test('provisionTemplateSite fails closed when the generic manifest is a symlink', (t) => {+ let scenario;+ try {+ scenario = runUploadScenario(t, {+ firstUploadResult: staleManifestFailure(),+ manifestKind: 'symlink',+ });+ } catch (err) {+ if (err.code === 'EPERM' || err.code === 'EACCES') {+ t.skip(`file symlinks are unavailable: ${err.code}`);+ return;+ }+ throw err;+ }++ assert.equal(scenario.result.ok, false);+ assert.equal(scenario.uploadCalls.length, 1);+ assert.match(scenario.result.error, /Entity 'powerpagecomponent'/);+ assert.match(scenario.result.error, /not a real regular file/);+});++test('provisionTemplateSite fails closed when the generic manifest is not a regular file', (t) => {+ const scenario = runUploadScenario(t, {+ firstUploadResult: staleManifestFailure(),+ manifestKind: 'directory',+ });++ assert.equal(scenario.result.ok, false);+ assert.equal(scenario.uploadCalls.length, 1);+ assert.match(scenario.result.error, /Entity 'powerpagecomponent'/);+ assert.match(scenario.result.error, /not a real regular file/);+});++test('provisionTemplateSite preserves the PAC failure when manifest deletion fails', (t) => {+ const failingFs = {+ ...fs,+ unlinkSync() {+ throw new Error('permission denied');+ },+ };+ const scenario = runUploadScenario(t, {+ firstUploadResult: staleManifestFailure(),+ fsImpl: failingFs,+ });++ assert.equal(scenario.result.ok, false);+ assert.equal(scenario.uploadCalls.length, 1);+ assert.match(scenario.result.error, /Entity 'powerpagecomponent'/);+ assert.match(scenario.result.error, /Stale-manifest recovery could not continue/);+ assert.match(scenario.result.error, /Could not delete the generic PAC manifest/);+ assert.match(scenario.result.error, /permission denied/);+ assert.equal(fs.existsSync(scenario.manifestPath), true);+});++test('removeGenericManifestForRetry rejects a manifest reached through an escaping parent symlink', (t) => {+ const dir = tempDir();+ const clone = path.join(dir, 'clone');+ const outside = path.join(dir, 'outside');+ const portalConfig = path.join(clone, '.powerpages-site', '.portalconfig');+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));+ fs.mkdirSync(path.join(clone, '.powerpages-site'), { recursive: true });+ fs.mkdirSync(outside);+ fs.writeFileSync(path.join(outside, 'manifest.yml'), 'outside clone\n');+ try {+ fs.symlinkSync(outside, portalConfig, process.platform === 'win32' ? 'junction' : 'dir');+ } catch (err) {+ if (err.code === 'EPERM' || err.code === 'EACCES') {+ t.skip(`directory symlinks are unavailable: ${err.code}`);+ return;+ }+ throw err;+ }++ assert.throws(+ () => removeGenericManifestForRetry(clone),+ /resolves through a linked or unexpected path/+ );+ assert.equal(fs.readFileSync(path.join(outside, 'manifest.yml'), 'utf8'), 'outside clone\n');+});++test('removeGenericManifestForRetry rejects an in-tree parent symlink', (t) => {+ const dir = tempDir();+ const clone = path.join(dir, 'clone');+ const otherState = path.join(clone, 'other-state');+ const portalConfig = path.join(clone, '.powerpages-site', '.portalconfig');+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));+ fs.mkdirSync(path.join(clone, '.powerpages-site'), { recursive: true });+ fs.mkdirSync(otherState);+ fs.writeFileSync(path.join(otherState, 'manifest.yml'), 'unrelated clone state\n');+ try {+ fs.symlinkSync(otherState, portalConfig, process.platform === 'win32' ? 'junction' : 'dir');+ } catch (err) {+ if (err.code === 'EPERM' || err.code === 'EACCES') {+ t.skip(`directory symlinks are unavailable: ${err.code}`);+ return;+ }+ throw err;+ }++ assert.throws(+ () => removeGenericManifestForRetry(clone),+ /resolves through a linked or unexpected path/+ );+ assert.equal(+ fs.readFileSync(path.join(otherState, 'manifest.yml'), 'utf8'),+ 'unrelated clone state\n'+ );+});++test('removeGenericManifestForRetry uses Windows case-insensitive containment', () => {+ const unlinked = [];+ removeGenericManifestForRetry('C:\\SiteClone', {+ platform: 'win32',+ fs: {+ lstatSync() {+ return {+ isFile: () => true,+ isSymbolicLink: () => false,+ };+ },+ realpathSync(targetPath) {+ return targetPath.endsWith('manifest.yml')+ ? path.join('/tmp/siteclone', '.powerpages-site', '.portalconfig', 'manifest.yml')+ : '/tmp/SiteClone';+ },+ unlinkSync(targetPath) {+ unlinked.push(targetPath);+ },+ },+ });++ assert.equal(unlinked.length, 1);+ assert.match(unlinked[0], /manifest\.yml$/);+});++test('provisionTemplateSite reports a failed retry and stops after two upload calls', (t) => {+ const scenario = runUploadScenario(t, {+ firstUploadResult: staleManifestFailure('assets/app.8c2f.js'),+ retryUploadResult: { status: 1, stdout: '', stderr: 'retry still rejected' },+ });++ assert.equal(scenario.result.ok, false);+ assert.equal(scenario.result.step, 'upload');+ assert.equal(scenario.uploadCalls.length, 2);+ assert.match(scenario.result.error, /Stale-manifest recovery was attempted/);+ assert.match(scenario.result.error, /retry still rejected/);+ assert.equal(fs.existsSync(scenario.manifestPath), false);+ assert.equal(fs.existsSync(scenario.environmentManifestPath), true);+});+test('provisionTemplateSite stops before upload when dependency installation fails', (t) => {const dir = tempDir();t.after(() => fs.rmSync(dir, { recursive: true, force: true }));@@ -614,6 +968,10 @@ test('provisionTemplateSite restores project files omitted by PAC without replacfs.writeFileSync(path.join(source, 'tests', 'serviceRequests.test.mjs'), 'export {};\n');fs.mkdirSync(path.join(source, '.powerpages-site', '.portalconfig'));fs.writeFileSync(path.join(source, '.powerpages-site', '.portalconfig', 'manifest.yml'), 'portalVersion: 1\n');+ fs.writeFileSync(+ path.join(source, '.powerpages-site', '.portalconfig', 'source-environment-manifest.yml'),+ 'environment: source\n'+ );const npmCalls = [];let pacCalls = 0;@@ -636,7 +994,13 @@ test('provisionTemplateSite restores project files omitted by PAC without replacassert.equal(fs.existsSync(path.join(cwd, '.npmrc')), true);assert.equal(fs.existsSync(path.join(cwd, 'dataverse-choice-values.json')), true);assert.equal(fs.existsSync(path.join(cwd, 'tests', 'serviceRequests.test.mjs')), true);- assert.equal(fs.existsSync(path.join(cwd, '.powerpages-site', '.portalconfig', 'manifest.yml')), true);+ assert.equal(fs.existsSync(path.join(cwd, '.powerpages-site', '.portalconfig', 'manifest.yml')), false);+ assert.equal(+ fs.existsSync(+ path.join(cwd, '.powerpages-site', '.portalconfig', 'source-environment-manifest.yml')+ ),+ true+ );if (args[0] === 'run') {fs.mkdirSync(path.join(cwd, 'dist'));fs.writeFileSync(path.join(cwd, 'dist', 'index.html'), '<html></html>');@@ -655,7 +1019,7 @@ test('provisionTemplateSite restores project files omitted by PAC without replac);});-test('copyMissingTemplateFiles rejects source symlinks and preserves cloned website metadata', (t) => {+test('copyMissingTemplateFiles skips PAC-owned identity files and restores ordinary files', (t) => {const dir = tempDir();t.after(() => fs.rmSync(dir, { recursive: true, force: true }));const source = path.join(dir, 'source');@@ -663,13 +1027,30 @@ test('copyMissingTemplateFiles rejects source symlinks and preserves cloned webscreateSource(source, { id: SOURCE_ID });createSource(clone, { id: CLONED_ID });fs.writeFileSync(path.join(source, 'extra.json'), '{}');+ fs.mkdirSync(path.join(source, '.powerpages-site', '.portalconfig'));+ fs.writeFileSync(+ path.join(source, '.powerpages-site', '.portalconfig', 'manifest.yml'),+ 'stale clone state\n'+ );assert.deepEqual(copyMissingTemplateFiles(source, clone), ['extra.json']);assert.match(fs.readFileSync(path.join(clone, '.powerpages-site', 'website.yml'), 'utf8'),new RegExp(CLONED_ID));+ assert.equal(+ fs.existsSync(path.join(clone, '.powerpages-site', '.portalconfig', 'manifest.yml')),+ false+ );+});+test('copyMissingTemplateFiles rejects source symlinks', (t) => {+ const dir = tempDir();+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));+ const source = path.join(dir, 'source');+ const clone = path.join(dir, 'clone');+ createSource(source);+ createSource(clone);const target = path.join(dir, 'outside.json');const link = path.join(source, 'linked.json');fs.writeFileSync(target, '{}');