Skip to content

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.

[Pages] Retry PAC uploads after safe manifest cleanup (#650)

Priyanshu Agrawal4c7056f6fd98
diff --git a/plugins/power-pages/.claude-plugin/plugin.json b/plugins/power-pages/.claude-plugin/plugin.json
index 85abb56e9..3fc02d5b7 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.1",
+ "version": "2.7.2",
"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.json
index 85abb56e9..3fc02d5b7 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.1",
+ "version": "2.7.2",
"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/provision-template-site.js b/plugins/power-pages/scripts/provision-template-site.js
index bcd4f626c..7c1e1af57 100644
--- a/plugins/power-pages/scripts/provision-template-site.js
+++ b/plugins/power-pages/scripts/provision-template-site.js
@@ -9,7 +9,9 @@ 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');
+const PORTAL_CONFIG_PATH = path.join('.powerpages-site', '.portalconfig');
+const GENERIC_MANIFEST_NAME = 'manifest.yml';
+const GENERIC_MANIFEST_PATH = path.join(PORTAL_CONFIG_PATH, GENERIC_MANIFEST_NAME);
function parseArgs(argv) {
const args = {};
@@ -61,10 +63,9 @@ 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);
- // 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.
+ // The released 311 template contains no portal manifest; PAC creates that state
+ // during clone/upload. Skipping a source manifest remains defense-in-depth for
+ // local or custom templates so PAC's generated clone state stays authoritative.
if (relativePath === CLONED_IDENTITY_PATH || relativePath === GENERIC_MANIFEST_PATH) continue;
const sourceEntryPath = path.join(sourcePath, relativePath);
const clonedEntryPath = path.join(clonedPath, relativePath);
@@ -261,55 +262,109 @@ function removeScriptCreatedOutputDirectory(outputDirectory, existedBeforeRun, f
}
}
-function isStaleManifestUploadFailure(result) {
+function isPortalFileContentUploadFailure(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);
+ return /PortalFileContentUploadFailed/i.test(output);
}
-function removeGenericManifestForRetry(clonedPath, deps = {}) {
+function isRetryManifestName(name, platform = process.platform) {
+ const comparableName = platform === 'win32' ? name.toLowerCase() : name;
+ return comparableName === GENERIC_MANIFEST_NAME ||
+ comparableName.endsWith('-manifest.yml');
+}
+
+function removePacManifestsForRetry(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);
+ const portalConfigPath = path.join(resolvedClonedPath, PORTAL_CONFIG_PATH);
- let manifestStat;
+ let clonedStat;
try {
- manifestStat = fsImpl.lstatSync(manifestPath);
+ clonedStat = fsImpl.lstatSync(resolvedClonedPath);
} catch (err) {
- throw new Error(`Generic PAC manifest is unavailable at ${manifestPath}: ${err.message}`);
+ throw new Error(`Could not inspect the cloned project safely: ${err.message}`);
}
- if (manifestStat.isSymbolicLink() || !manifestStat.isFile()) {
- throw new Error(`Generic PAC manifest is not a real regular file: ${manifestPath}`);
+ if (clonedStat.isSymbolicLink() || !clonedStat.isDirectory()) {
+ throw new Error(`Cloned project path is not a real directory: ${resolvedClonedPath}`);
}
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}`);
+ throw new Error(`Could not resolve the cloned project safely: ${err.message}`);
+ }
+
+ let portalConfigStat;
+ try {
+ portalConfigStat = fsImpl.lstatSync(portalConfigPath);
+ } catch (err) {
+ if (err && err.code === 'ENOENT') return [];
+ throw new Error(`Could not inspect the PAC portal configuration directory: ${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}`);
+ if (portalConfigStat.isSymbolicLink() || !portalConfigStat.isDirectory()) {
+ throw new Error(`PAC portal configuration path is not a real directory: ${portalConfigPath}`);
}
+ let canonicalPortalConfigPath;
try {
- fsImpl.unlinkSync(manifestPath);
+ canonicalPortalConfigPath = fsImpl.realpathSync(portalConfigPath);
} catch (err) {
- throw new Error(`Could not delete the generic PAC manifest at ${manifestPath}: ${err.message}`);
+ throw new Error(`Could not resolve the PAC portal configuration directory safely: ${err.message}`);
+ }
+ const expectedCanonicalPortalConfigPath = path.join(canonicalClonedPath, PORTAL_CONFIG_PATH);
+ if (!pathEquals(expectedCanonicalPortalConfigPath, canonicalPortalConfigPath, platform)) {
+ throw new Error(`PAC portal configuration directory resolves outside its expected path: ${portalConfigPath}`);
+ }
+
+ let entries;
+ try {
+ entries = fsImpl.readdirSync(portalConfigPath, { withFileTypes: true });
+ } catch (err) {
+ throw new Error(`Could not read the PAC portal configuration directory: ${err.message}`);
+ }
+
+ const manifests = [];
+ for (const entry of entries) {
+ if (!isRetryManifestName(entry.name, platform)) continue;
+ const manifestPath = path.join(portalConfigPath, entry.name);
+ let manifestStat;
+ try {
+ manifestStat = fsImpl.lstatSync(manifestPath);
+ } catch (err) {
+ throw new Error(`Could not inspect PAC manifest ${entry.name} safely: ${err.message}`);
+ }
+ if (manifestStat.isSymbolicLink() || !manifestStat.isFile()) {
+ throw new Error(`PAC manifest is not a real regular file: ${manifestPath}`);
+ }
+ let canonicalManifestPath;
+ try {
+ canonicalManifestPath = fsImpl.realpathSync(manifestPath);
+ } catch (err) {
+ throw new Error(`Could not resolve PAC manifest ${entry.name} safely: ${err.message}`);
+ }
+ if (
+ !pathEquals(path.dirname(canonicalManifestPath), canonicalPortalConfigPath, platform) ||
+ !pathEquals(
+ canonicalManifestPath,
+ path.join(canonicalPortalConfigPath, entry.name),
+ platform
+ )
+ ) {
+ throw new Error(`PAC manifest resolves through a linked or unexpected path: ${manifestPath}`);
+ }
+ manifests.push({ name: entry.name, path: manifestPath });
+ }
+
+ for (const manifest of manifests) {
+ try {
+ fsImpl.unlinkSync(manifest.path);
+ } catch (err) {
+ throw new Error(`Could not delete PAC manifest ${manifest.name}: ${err.message}`);
+ }
}
- return manifestPath;
+ return manifests.map((manifest) => manifest.name);
}
function provisionTemplateSite(options, deps = {}) {
@@ -470,16 +525,16 @@ function provisionTemplateSite(options, deps = {}) {
const uploadResult = pac(uploadArgs, pacCommandOptions);
if (uploadResult.status !== 0) {
const originalUploadError = commandError('pac pages upload-code-site', uploadResult);
- if (isStaleManifestUploadFailure(uploadResult)) {
+ if (isPortalFileContentUploadFailure(uploadResult)) {
try {
- removeGenericManifestForRetry(clonedPath, deps);
+ removePacManifestsForRetry(clonedPath, deps);
} catch (err) {
return {
ok: false,
step: 'upload',
clonedPath,
...clonedIdentity,
- error: `${originalUploadError}\nStale-manifest recovery could not continue: ${err.message}`,
+ error: `${originalUploadError}\nPAC manifest cleanup could not continue: ${err.message}`,
};
}
@@ -492,7 +547,7 @@ function provisionTemplateSite(options, deps = {}) {
...clonedIdentity,
error: [
`${originalUploadError}`,
- 'Stale-manifest recovery was attempted, but the upload retry failed.',
+ 'PAC manifest cleanup was attempted, but the upload retry failed.',
commandError('pac pages upload-code-site retry', retryResult),
].join('\n'),
};
@@ -530,12 +585,13 @@ module.exports = {
findCodeSiteRoot,
inspectCompiledOutput,
inspectClonedSiteIdentity,
- isStaleManifestUploadFailure,
+ isPortalFileContentUploadFailure,
+ isRetryManifestName,
parseArgs,
pathContains,
pathEquals,
provisionTemplateSite,
- removeGenericManifestForRetry,
+ removePacManifestsForRetry,
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.js
index 33d408615..42c4e9925 100644
--- a/plugins/power-pages/scripts/tests/provision-template-site.test.js
+++ b/plugins/power-pages/scripts/tests/provision-template-site.test.js
@@ -11,10 +11,11 @@ const {
findCodeSiteRoot,
inspectCompiledOutput,
inspectClonedSiteIdentity,
- isStaleManifestUploadFailure,
+ isPortalFileContentUploadFailure,
+ isRetryManifestName,
parseArgs,
provisionTemplateSite,
- removeGenericManifestForRetry,
+ removePacManifestsForRetry,
runNpm,
runPac,
} = require('../provision-template-site');
@@ -34,13 +35,12 @@ 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') {
+function portalFileUploadFailure(fileName = 'index.html') {
return {
status: 1,
stdout: '',
stderr: [
- `Upload failed for ${fileName}.`,
- `Entity 'powerpagecomponent' With Id = ${SOURCE_ID} Does Not Exist`,
+ `Error: Unable to upload webfile name '${fileName}' with record Id ${SOURCE_ID} due to below error(s).`,
'PortalFileContentUploadFailed',
].join('\n'),
};
@@ -50,20 +50,26 @@ function runUploadScenario(t, {
firstUploadResult,
fsImpl = fs,
retryUploadResult = { status: 0, stdout: 'uploaded', stderr: '' },
- manifestKind = 'file',
+ manifestEntries = [
+ { name: 'manifest.yml', kind: 'file', content: 'PAC-generated generic state\n' },
+ {
+ name: 'target-environment-manifest.yml',
+ kind: 'file',
+ content: 'PAC-generated environment state\n',
+ },
+ ],
+ portalConfigKind = 'directory',
} = {}) {
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'
- );
+ const portalConfigPath = path.join(clonedPath, '.powerpages-site', '.portalconfig');
+ const manifestPath = path.join(portalConfigPath, 'manifest.yml');
+ const environmentManifestPath = path.join(portalConfigPath, 'target-environment-manifest.yml');
+ const englishLanguagePath = path.join(portalConfigPath, 'English.portallanguage.yml');
+ const unrelatedYamlPath = path.join(portalConfigPath, 'unrelated.yml');
createSource(source);
const uploadCalls = [];
@@ -76,17 +82,34 @@ function runUploadScenario(t, {
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');
+ let manifestDirectory = portalConfigPath;
+ if (portalConfigKind === 'symlink') {
+ manifestDirectory = path.join(dir, 'outside-portalconfig');
+ fs.mkdirSync(manifestDirectory, { recursive: true });
+ fs.symlinkSync(
+ manifestDirectory,
+ portalConfigPath,
+ process.platform === 'win32' ? 'junction' : 'dir'
+ );
+ } else if (portalConfigKind !== 'missing') {
+ fs.mkdirSync(portalConfigPath, { recursive: true });
+ }
+ if (portalConfigKind !== 'missing') {
+ for (const entry of manifestEntries) {
+ const entryPath = path.join(manifestDirectory, entry.name);
+ if (entry.kind === 'directory') {
+ fs.mkdirSync(entryPath);
+ } else if (entry.kind === 'symlink') {
+ const outsideManifest = path.join(dir, `outside-${entry.name}`);
+ fs.writeFileSync(outsideManifest, 'outside clone\n');
+ fs.symlinkSync(outsideManifest, entryPath, 'file');
+ } else {
+ fs.writeFileSync(entryPath, entry.content || 'PAC-generated manifest state\n');
+ }
+ }
+ fs.writeFileSync(path.join(manifestDirectory, 'English.portallanguage.yml'), 'language\n');
+ fs.writeFileSync(path.join(manifestDirectory, 'unrelated.yml'), 'unrelated\n');
}
- fs.writeFileSync(environmentManifestPath, 'target environment state\n');
return { status: 0, stdout: 'cloned', stderr: '' };
}
uploadCalls.push({ args, cwd: commandOptions.cwd });
@@ -103,9 +126,12 @@ function runUploadScenario(t, {
return {
clonedPath,
+ englishLanguagePath,
environmentManifestPath,
manifestPath,
+ portalConfigPath,
result,
+ unrelatedYamlPath,
uploadCalls,
};
}
@@ -438,142 +464,123 @@ 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({
+test('isPortalFileContentUploadFailure detects the bounded PAC tail token', () => {
+ assert.equal(isPortalFileContentUploadFailure(portalFileUploadFailure('index.html')), true);
+ assert.equal(isPortalFileContentUploadFailure({
status: 1,
- stdout: 'portalfilecontentuploadfailed',
- stderr: `ENTITY 'POWERPAGECOMPONENT' WITH ID = ${SOURCE_ID} DOES NOT EXIST`,
+ stdout: 'pOrTaLfIlEcOnTeNtUpLoAdFaIlEd',
+ stderr: '',
}), true);
- assert.equal(isStaleManifestUploadFailure({
+ assert.equal(isPortalFileContentUploadFailure({
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({
+ assert.equal(isPortalFileContentUploadFailure({
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'),
+ stderr: 'upload rejected',
}), false);
});
-test('provisionTemplateSite deletes the generic manifest and retries once for index.html', (t) => {
+test('provisionTemplateSite retries once for an arbitrary webfile upload envelope', (t) => {
const scenario = runUploadScenario(t, {
- firstUploadResult: staleManifestFailure('index.html'),
+ firstUploadResult: portalFileUploadFailure("assets/customer's app.8c2f.js"),
});
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);
+ assert.equal(fs.existsSync(scenario.environmentManifestPath), false);
});
-test('provisionTemplateSite stale-manifest recovery is independent of compiled file names', (t) => {
+test('provisionTemplateSite retries once when the bounded tail contains only the PAC token', (t) => {
const scenario = runUploadScenario(t, {
- firstUploadResult: staleManifestFailure('assets/site.7f3a91c2.css'),
+ firstUploadResult: {
+ status: 1,
+ stdout: '',
+ stderr: 'PortalFileContentUploadFailed',
+ },
+ });
+
+ assert.equal(scenario.result.ok, true);
+ assert.equal(scenario.uploadCalls.length, 2);
+});
+
+test('provisionTemplateSite deletes generic and environment manifests but preserves other files', (t) => {
+ const secondEnvironmentManifest = 'regional-backup-manifest.yml';
+ const scenario = runUploadScenario(t, {
+ firstUploadResult: portalFileUploadFailure(),
+ manifestEntries: [
+ { name: 'manifest.yml', kind: 'file' },
+ { name: 'target-environment-manifest.yml', kind: 'file' },
+ { name: secondEnvironmentManifest, kind: 'file' },
+ ],
});
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);
+ assert.equal(fs.existsSync(scenario.environmentManifestPath), false);
+ assert.equal(
+ fs.existsSync(path.join(scenario.portalConfigPath, secondEnvironmentManifest)),
+ false
+ );
+ assert.equal(fs.readFileSync(scenario.englishLanguagePath, 'utf8'), 'language\n');
+ assert.equal(fs.readFileSync(scenario.unrelatedYamlPath, 'utf8'), 'unrelated\n');
});
-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'),
- },
- },
- ];
+test('provisionTemplateSite retries when PAC manifest files are absent', async (t) => {
+ await t.test('empty portalconfig directory', (subtest) => {
+ const scenario = runUploadScenario(subtest, {
+ firstUploadResult: portalFileUploadFailure(),
+ manifestEntries: [],
+ });
- 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');
+ assert.equal(scenario.result.ok, true);
+ assert.equal(scenario.uploadCalls.length, 2);
+ assert.equal(fs.existsSync(scenario.englishLanguagePath), true);
+ assert.equal(fs.existsSync(scenario.unrelatedYamlPath), true);
+ });
+
+ await t.test('missing portalconfig directory', (subtest) => {
+ const scenario = runUploadScenario(subtest, {
+ firstUploadResult: portalFileUploadFailure(),
+ portalConfigKind: 'missing',
});
- }
+
+ assert.equal(scenario.result.ok, true);
+ assert.equal(scenario.uploadCalls.length, 2);
+ });
});
-test('provisionTemplateSite fails closed when the generic manifest is missing', (t) => {
+test('provisionTemplateSite does not retry failed output without the PAC token', (t) => {
const scenario = runUploadScenario(t, {
- firstUploadResult: staleManifestFailure(),
- manifestKind: 'missing',
+ firstUploadResult: {
+ status: 1,
+ stdout: '',
+ stderr: `Entity 'powerpagecomponent' With Id = ${SOURCE_ID} Does Not Exist`,
+ },
});
assert.equal(scenario.result.ok, false);
+ assert.equal(scenario.result.step, 'upload');
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/);
+ assert.equal(fs.existsSync(scenario.manifestPath), true);
+ assert.equal(fs.existsSync(scenario.environmentManifestPath), true);
});
-test('provisionTemplateSite fails closed when the generic manifest is a symlink', (t) => {
+test('provisionTemplateSite fails closed when portalconfig is a parent symlink', (t) => {
let scenario;
try {
scenario = runUploadScenario(t, {
- firstUploadResult: staleManifestFailure(),
- manifestKind: 'symlink',
+ firstUploadResult: portalFileUploadFailure(),
+ portalConfigKind: 'symlink',
});
} catch (err) {
if (err.code === 'EPERM' || err.code === 'EACCES') {
- t.skip(`file symlinks are unavailable: ${err.code}`);
+ t.skip(`directory symlinks are unavailable: ${err.code}`);
return;
}
throw err;
@@ -581,20 +588,32 @@ test('provisionTemplateSite fails closed when the generic manifest is a symlink'
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/);
+ assert.match(scenario.result.error, /PAC manifest cleanup could not continue/);
+ assert.match(scenario.result.error, /portal configuration path is not a real directory/);
});
-test('provisionTemplateSite fails closed when the generic manifest is not a regular file', (t) => {
- const scenario = runUploadScenario(t, {
- firstUploadResult: staleManifestFailure(),
- manifestKind: 'directory',
- });
+test('provisionTemplateSite fails closed for unsafe matched manifest entries', async (t) => {
+ for (const kind of ['symlink', 'directory']) {
+ await t.test(kind, (subtest) => {
+ let scenario;
+ try {
+ scenario = runUploadScenario(subtest, {
+ firstUploadResult: portalFileUploadFailure(),
+ manifestEntries: [{ name: 'manifest.yml', kind }],
+ });
+ } catch (err) {
+ if (kind === 'symlink' && (err.code === 'EPERM' || err.code === 'EACCES')) {
+ subtest.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/);
+ assert.equal(scenario.result.ok, false);
+ assert.equal(scenario.uploadCalls.length, 1);
+ assert.match(scenario.result.error, /PAC manifest is not a real regular file/);
+ });
+ }
});
test('provisionTemplateSite preserves the PAC failure when manifest deletion fails', (t) => {
@@ -605,113 +624,84 @@ test('provisionTemplateSite preserves the PAC failure when manifest deletion fai
},
};
const scenario = runUploadScenario(t, {
- firstUploadResult: staleManifestFailure(),
+ firstUploadResult: portalFileUploadFailure(),
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, /PAC manifest cleanup could not continue/);
+ assert.match(scenario.result.error, /Could not delete 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;
- }
+test('provisionTemplateSite fails closed for a redirected canonical portalconfig path', (t) => {
+ const redirectedFs = {
+ ...fs,
+ realpathSync(targetPath) {
+ if (targetPath.endsWith(path.join('.powerpages-site', '.portalconfig'))) {
+ return path.join(path.dirname(targetPath), 'redirected-portalconfig');
+ }
+ return fs.realpathSync(targetPath);
+ },
+ };
+ const scenario = runUploadScenario(t, {
+ firstUploadResult: portalFileUploadFailure(),
+ fsImpl: redirectedFs,
+ });
- assert.throws(
- () => removeGenericManifestForRetry(clone),
- /resolves through a linked or unexpected path/
+ assert.equal(scenario.result.ok, false);
+ assert.equal(scenario.uploadCalls.length, 1);
+ assert.match(
+ scenario.result.error,
+ /portal configuration directory resolves outside its expected path/
);
- assert.equal(fs.readFileSync(path.join(outside, 'manifest.yml'), 'utf8'), 'outside clone\n');
+ assert.equal(fs.existsSync(scenario.manifestPath), true);
});
-test('removeGenericManifestForRetry rejects an in-tree parent symlink', (t) => {
+test('removePacManifestsForRetry uses Windows case-insensitive names and paths', (t) => {
const dir = tempDir();
- const clone = path.join(dir, 'clone');
- const otherState = path.join(clone, 'other-state');
+ const clone = path.join(dir, 'SiteClone');
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'
- );
-});
+ fs.mkdirSync(portalConfig, { recursive: true });
+ fs.writeFileSync(path.join(portalConfig, 'MANIFEST.YML'), 'generic\n');
+ fs.writeFileSync(path.join(portalConfig, 'WESTUS-MANIFEST.YML'), 'environment\n');
+ fs.writeFileSync(path.join(portalConfig, 'English.portallanguage.yml'), 'language\n');
+ const caseVariantFs = {
+ ...fs,
+ realpathSync(targetPath) {
+ return fs.realpathSync(targetPath).replace('SiteClone', 'siteclone');
+ },
+ };
-test('removeGenericManifestForRetry uses Windows case-insensitive containment', () => {
- const unlinked = [];
- removeGenericManifestForRetry('C:\\SiteClone', {
+ const removed = removePacManifestsForRetry(clone, {
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);
- },
- },
+ fs: caseVariantFs,
});
- assert.equal(unlinked.length, 1);
- assert.match(unlinked[0], /manifest\.yml$/);
+ assert.deepEqual(removed.sort(), ['MANIFEST.YML', 'WESTUS-MANIFEST.YML']);
+ assert.equal(fs.existsSync(path.join(portalConfig, 'MANIFEST.YML')), false);
+ assert.equal(fs.existsSync(path.join(portalConfig, 'WESTUS-MANIFEST.YML')), false);
+ assert.equal(fs.existsSync(path.join(portalConfig, 'English.portallanguage.yml')), true);
+ assert.equal(isRetryManifestName('REGION-MANIFEST.YML', 'win32'), true);
+ assert.equal(isRetryManifestName('REGION-MANIFEST.YML', 'linux'), false);
});
test('provisionTemplateSite reports a failed retry and stops after two upload calls', (t) => {
const scenario = runUploadScenario(t, {
- firstUploadResult: staleManifestFailure('assets/app.8c2f.js'),
+ firstUploadResult: portalFileUploadFailure('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, /PAC manifest cleanup was attempted/);
assert.match(scenario.result.error, /retry still rejected/);
assert.equal(fs.existsSync(scenario.manifestPath), false);
- assert.equal(fs.existsSync(scenario.environmentManifestPath), true);
+ assert.equal(fs.existsSync(scenario.environmentManifestPath), false);
});
test('provisionTemplateSite stops before upload when dependency installation fails', (t) => {