Skip to content

Commit da90917

Browse files
authored
fix: ACNA-2967 - web actions and web sequences with the same name can be deployed, web action implementation is unreachable (#190)
1 parent 4cec293 commit da90917

File tree

7 files changed

+156
-41
lines changed

7 files changed

+156
-41
lines changed

src/deploy-actions.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,16 @@ async function deployActions (config, deployConfig = {}, logFunc) {
9696
}
9797
for (const [pkgName, pkg] of Object.entries(manifest.packages)) {
9898
pkg.version = config.app.version
99-
for (const [name, action] of Object.entries(pkg.actions || {})) {
99+
const sequences = pkg.sequences || {}
100+
const actions = pkg.actions || {}
101+
102+
Object.keys(sequences).forEach((sequenceName) => {
103+
if (actions[sequenceName]) {
104+
throw new Error(`Sequence '${sequenceName}' is already defined as an action under the same package. Actions and sequences can not have the same name in a single package.`)
105+
}
106+
})
107+
108+
for (const [name, action] of Object.entries(actions)) {
100109
// change path to built action
101110
const zipFileName = utils.getActionZipFileName(pkgName, name, false) + '.zip'
102111
action.function = path.join(relDist, zipFileName)

test/.eslintrc.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
"fixtureFile": true,
44
"fixtureJson": true,
55
"fakeFileSystem": true,
6-
"fetch": true
6+
"fetch": true,
7+
"addSampleAppFiles": true,
8+
"addSampleAppReducedFiles": true,
9+
"addSampleAppDuplicateFiles": true,
10+
"addNamedPackageFiles": true
711
},
812
"rules": {
913
"node/no-unpublished-require": 0,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
Copyright 2024 Adobe. All rights reserved.
3+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License. You may obtain a copy
5+
of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
Unless required by applicable law or agreed to in writing, software distributed under
8+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
OF ANY KIND, either express or implied. See the License for the specific language
10+
governing permissions and limitations under the License.
11+
*/
12+
function main (args) {
13+
return 'hello'
14+
}
15+
exports.main = main
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
packages:
2+
__APP_PACKAGE__:
3+
license: Apache-2.0
4+
sequences:
5+
someAction: 'anotherAction'
6+
actions:
7+
someAction:
8+
function: actions/action.js
9+
web: yes
10+
runtime: 'nodejs:18'
11+
anotherAction:
12+
function: actions/action.js
13+
web: yes
14+
runtime: 'nodejs:18'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"version": "1.0.0",
3+
"name": "sample-app-duplicate"
4+
}

test/deploy.actions.test.js

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,18 @@ test('if actions are deployed and part of the manifest it should return their ur
596596
})
597597
})
598598

599+
test('if sequence name is the same as an action name, throw an error', async () => {
600+
addSampleAppDuplicateFiles()
601+
602+
const buildDir = global.sampleAppDuplicateConfig.actions.dist
603+
// fake a previous build
604+
addFakeFiles(buildDir)
605+
606+
await expect(deployActions(global.sampleAppDuplicateConfig))
607+
.rejects
608+
.toThrow('Sequence \'someAction\' is already defined as an action under the same package. Actions and sequences can not have the same name in a single package.')
609+
})
610+
599611
test('if actions are deployed with custom package and part of the manifest it should return their url', async () => {
600612
addNamedPackageFiles()
601613

@@ -991,45 +1003,6 @@ test('No backend is present', async () => {
9911003
await expect(deployActions(global.sampleAppConfig)).rejects.toThrow('cannot deploy actions, app has no backend')
9921004
})
9931005

994-
/**
995-
*
996-
*/
997-
function addSampleAppFiles () {
998-
global.fakeFileSystem.addJson({
999-
'actions/action-zip/index.js': global.fixtureFile('/sample-app/actions/action-zip/index.js'),
1000-
'actions/action-zip/package.json': global.fixtureFile('/sample-app/actions/action-zip/package.json'),
1001-
'actions/action.js': global.fixtureFile('/sample-app/actions/action.js'),
1002-
'web-src/index.html': global.fixtureFile('/sample-app/web-src/index.html'),
1003-
'manifest.yml': global.fixtureFile('/sample-app/manifest.yml'),
1004-
'package.json': global.fixtureFile('/sample-app/package.json')
1005-
})
1006-
}
1007-
1008-
/**
1009-
*
1010-
*/
1011-
function addNamedPackageFiles () {
1012-
global.fakeFileSystem.addJson({
1013-
'actions/action-zip/index.js': global.fixtureFile('/named-package/actions/action-zip/index.js'),
1014-
'actions/action-zip/package.json': global.fixtureFile('/named-package/actions/action-zip/package.json'),
1015-
'actions/action.js': global.fixtureFile('/named-package/actions/action.js'),
1016-
'web-src/index.html': global.fixtureFile('/named-package/web-src/index.html'),
1017-
'manifest.yml': global.fixtureFile('/named-package/manifest.yml'),
1018-
'package.json': global.fixtureFile('/named-package/package.json')
1019-
})
1020-
}
1021-
1022-
/**
1023-
*
1024-
*/
1025-
function addSampleAppReducedFiles () {
1026-
global.fakeFileSystem.addJson({
1027-
'actions/action.js': global.fixtureFile('/sample-app-reduced/actions/action.js'),
1028-
'manifest.yml': global.fixtureFile('/sample-app-reduced/manifest.yml'),
1029-
'package.json': global.fixtureFile('/sample-app-reduced/package.json')
1030-
})
1031-
}
1032-
10331006
/**
10341007
* @param {string} buildDir build dir path
10351008
*/

test/jest.setup.js

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ global.namedPackageConfig = {
392392
actions: { src: '/actions', dist: '/dist/actions', devRemote: false },
393393
root: '/'
394394
}
395+
395396
global.sampleAppReducedConfig = {
396397
app: {
397398
hasFrontend: false,
@@ -459,6 +460,93 @@ global.sampleAppReducedConfig = {
459460
root: '/'
460461
}
461462

463+
global.sampleAppDuplicateConfig = {
464+
app: {
465+
hasFrontend: false,
466+
hasBackend: true,
467+
version: '1.0.0',
468+
name: 'sample-app-reduced',
469+
defaultHostname: 'https://adobeio-static.net',
470+
hostname: 'https://adobeio-static.net',
471+
htmlCacheDuration: '60',
472+
jsCacheDuration: '604800',
473+
cssCacheDuration: '604800',
474+
imageCacheDuration: '604800'
475+
},
476+
ow: {
477+
namespace: 'fake_ns',
478+
auth: 'fake:auth',
479+
apihost: 'https://adobeioruntime.net',
480+
defaultApihost: 'https://adobeioruntime.net',
481+
apiversion: 'v1',
482+
package: 'sample-app-duplicate-1.0.0'
483+
},
484+
s3: {
485+
credsCacheFile: '/.aws.tmp.creds.json',
486+
creds: undefined,
487+
folder: 'fake_ns',
488+
tvmUrl: 'https://adobeio.adobeioruntime.net/apis/tvm/'
489+
},
490+
web: {
491+
src: '/web-src',
492+
distDev: '/dist/web-src-dev',
493+
distProd: '/dist/web-src-prod',
494+
injectedConfig: '/web-src/src/config.json'
495+
},
496+
manifest: {
497+
src: '/manifest.yml',
498+
packagePlaceholder: '__APP_PACKAGE__',
499+
full: {
500+
packages: {
501+
__APP_PACKAGE__: {
502+
license: 'Apache-2.0',
503+
sequences: {
504+
someAction: {
505+
actions: 'anotherAction',
506+
web: 'yes'
507+
}
508+
},
509+
actions: {
510+
someAction: {
511+
function: 'actions/action.js',
512+
web: 'yes',
513+
runtime: 'nodejs:18'
514+
},
515+
anotherAction: {
516+
function: 'actions/action.js',
517+
web: 'yes',
518+
runtime: 'nodejs:18'
519+
}
520+
}
521+
}
522+
}
523+
},
524+
package: {
525+
license: 'Apache-2.0',
526+
sequences: {
527+
someAction: {
528+
actions: 'anotherAction',
529+
web: 'yes'
530+
}
531+
},
532+
actions: {
533+
someAction: {
534+
function: 'actions/action.js',
535+
web: 'yes',
536+
runtime: 'nodejs:18'
537+
},
538+
anotherAction: {
539+
function: 'actions/action.js',
540+
web: 'yes',
541+
runtime: 'nodejs:18'
542+
}
543+
}
544+
}
545+
},
546+
actions: { src: '/actions', dist: '/dist/actions', devRemote: false },
547+
root: '/'
548+
}
549+
462550
global.sampleAppDefaultPackageConfig = {
463551
app: {
464552
hasFrontend: false,
@@ -568,3 +656,11 @@ global.addSampleAppReducedFiles = () => {
568656
'package.json': global.fixtureFile('/sample-app-reduced/package.json')
569657
})
570658
}
659+
660+
global.addSampleAppDuplicateFiles = () => {
661+
global.fakeFileSystem.addJson({
662+
'actions/action.js': global.fixtureFile('/sample-app-duplicate/actions/action.js'),
663+
'manifest.yml': global.fixtureFile('/sample-app-duplicate/manifest.yml'),
664+
'package.json': global.fixtureFile('/sample-app-duplicate/package.json')
665+
})
666+
}

0 commit comments

Comments
 (0)