Skip to content

Commit

Permalink
fix: ACNA-2967 - web actions and web sequences with the same name can…
Browse files Browse the repository at this point in the history
… be deployed, web action implementation is unreachable (#190)
  • Loading branch information
shazron authored May 29, 2024
1 parent 4cec293 commit da90917
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 41 deletions.
11 changes: 10 additions & 1 deletion src/deploy-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,16 @@ async function deployActions (config, deployConfig = {}, logFunc) {
}
for (const [pkgName, pkg] of Object.entries(manifest.packages)) {
pkg.version = config.app.version
for (const [name, action] of Object.entries(pkg.actions || {})) {
const sequences = pkg.sequences || {}
const actions = pkg.actions || {}

Object.keys(sequences).forEach((sequenceName) => {
if (actions[sequenceName]) {
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.`)
}
})

for (const [name, action] of Object.entries(actions)) {
// change path to built action
const zipFileName = utils.getActionZipFileName(pkgName, name, false) + '.zip'
action.function = path.join(relDist, zipFileName)
Expand Down
6 changes: 5 additions & 1 deletion test/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
"fixtureFile": true,
"fixtureJson": true,
"fakeFileSystem": true,
"fetch": true
"fetch": true,
"addSampleAppFiles": true,
"addSampleAppReducedFiles": true,
"addSampleAppDuplicateFiles": true,
"addNamedPackageFiles": true
},
"rules": {
"node/no-unpublished-require": 0,
Expand Down
15 changes: 15 additions & 0 deletions test/__fixtures__/sample-app-duplicate/actions/action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
Copyright 2024 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
function main (args) {
return 'hello'
}
exports.main = main
14 changes: 14 additions & 0 deletions test/__fixtures__/sample-app-duplicate/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
packages:
__APP_PACKAGE__:
license: Apache-2.0
sequences:
someAction: 'anotherAction'
actions:
someAction:
function: actions/action.js
web: yes
runtime: 'nodejs:18'
anotherAction:
function: actions/action.js
web: yes
runtime: 'nodejs:18'
4 changes: 4 additions & 0 deletions test/__fixtures__/sample-app-duplicate/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"version": "1.0.0",
"name": "sample-app-duplicate"
}
51 changes: 12 additions & 39 deletions test/deploy.actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,18 @@ test('if actions are deployed and part of the manifest it should return their ur
})
})

test('if sequence name is the same as an action name, throw an error', async () => {
addSampleAppDuplicateFiles()

const buildDir = global.sampleAppDuplicateConfig.actions.dist
// fake a previous build
addFakeFiles(buildDir)

await expect(deployActions(global.sampleAppDuplicateConfig))
.rejects
.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.')
})

test('if actions are deployed with custom package and part of the manifest it should return their url', async () => {
addNamedPackageFiles()

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

/**
*
*/
function addSampleAppFiles () {
global.fakeFileSystem.addJson({
'actions/action-zip/index.js': global.fixtureFile('/sample-app/actions/action-zip/index.js'),
'actions/action-zip/package.json': global.fixtureFile('/sample-app/actions/action-zip/package.json'),
'actions/action.js': global.fixtureFile('/sample-app/actions/action.js'),
'web-src/index.html': global.fixtureFile('/sample-app/web-src/index.html'),
'manifest.yml': global.fixtureFile('/sample-app/manifest.yml'),
'package.json': global.fixtureFile('/sample-app/package.json')
})
}

/**
*
*/
function addNamedPackageFiles () {
global.fakeFileSystem.addJson({
'actions/action-zip/index.js': global.fixtureFile('/named-package/actions/action-zip/index.js'),
'actions/action-zip/package.json': global.fixtureFile('/named-package/actions/action-zip/package.json'),
'actions/action.js': global.fixtureFile('/named-package/actions/action.js'),
'web-src/index.html': global.fixtureFile('/named-package/web-src/index.html'),
'manifest.yml': global.fixtureFile('/named-package/manifest.yml'),
'package.json': global.fixtureFile('/named-package/package.json')
})
}

/**
*
*/
function addSampleAppReducedFiles () {
global.fakeFileSystem.addJson({
'actions/action.js': global.fixtureFile('/sample-app-reduced/actions/action.js'),
'manifest.yml': global.fixtureFile('/sample-app-reduced/manifest.yml'),
'package.json': global.fixtureFile('/sample-app-reduced/package.json')
})
}

/**
* @param {string} buildDir build dir path
*/
Expand Down
96 changes: 96 additions & 0 deletions test/jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ global.namedPackageConfig = {
actions: { src: '/actions', dist: '/dist/actions', devRemote: false },
root: '/'
}

global.sampleAppReducedConfig = {
app: {
hasFrontend: false,
Expand Down Expand Up @@ -459,6 +460,93 @@ global.sampleAppReducedConfig = {
root: '/'
}

global.sampleAppDuplicateConfig = {
app: {
hasFrontend: false,
hasBackend: true,
version: '1.0.0',
name: 'sample-app-reduced',
defaultHostname: 'https://adobeio-static.net',
hostname: 'https://adobeio-static.net',
htmlCacheDuration: '60',
jsCacheDuration: '604800',
cssCacheDuration: '604800',
imageCacheDuration: '604800'
},
ow: {
namespace: 'fake_ns',
auth: 'fake:auth',
apihost: 'https://adobeioruntime.net',
defaultApihost: 'https://adobeioruntime.net',
apiversion: 'v1',
package: 'sample-app-duplicate-1.0.0'
},
s3: {
credsCacheFile: '/.aws.tmp.creds.json',
creds: undefined,
folder: 'fake_ns',
tvmUrl: 'https://adobeio.adobeioruntime.net/apis/tvm/'
},
web: {
src: '/web-src',
distDev: '/dist/web-src-dev',
distProd: '/dist/web-src-prod',
injectedConfig: '/web-src/src/config.json'
},
manifest: {
src: '/manifest.yml',
packagePlaceholder: '__APP_PACKAGE__',
full: {
packages: {
__APP_PACKAGE__: {
license: 'Apache-2.0',
sequences: {
someAction: {
actions: 'anotherAction',
web: 'yes'
}
},
actions: {
someAction: {
function: 'actions/action.js',
web: 'yes',
runtime: 'nodejs:18'
},
anotherAction: {
function: 'actions/action.js',
web: 'yes',
runtime: 'nodejs:18'
}
}
}
}
},
package: {
license: 'Apache-2.0',
sequences: {
someAction: {
actions: 'anotherAction',
web: 'yes'
}
},
actions: {
someAction: {
function: 'actions/action.js',
web: 'yes',
runtime: 'nodejs:18'
},
anotherAction: {
function: 'actions/action.js',
web: 'yes',
runtime: 'nodejs:18'
}
}
}
},
actions: { src: '/actions', dist: '/dist/actions', devRemote: false },
root: '/'
}

global.sampleAppDefaultPackageConfig = {
app: {
hasFrontend: false,
Expand Down Expand Up @@ -568,3 +656,11 @@ global.addSampleAppReducedFiles = () => {
'package.json': global.fixtureFile('/sample-app-reduced/package.json')
})
}

global.addSampleAppDuplicateFiles = () => {
global.fakeFileSystem.addJson({
'actions/action.js': global.fixtureFile('/sample-app-duplicate/actions/action.js'),
'manifest.yml': global.fixtureFile('/sample-app-duplicate/manifest.yml'),
'package.json': global.fixtureFile('/sample-app-duplicate/package.json')
})
}

0 comments on commit da90917

Please sign in to comment.