From aff7ba289a49b95eed75392fb86d08674fe7a3e4 Mon Sep 17 00:00:00 2001 From: jay-m-dev Date: Thu, 7 Sep 2023 15:31:45 -0700 Subject: [PATCH 1/6] Add integration test for code run endpoint --- tests/integration/jest/labApi.js | 1 + tests/integration/jest/machineApi.test.ts | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/tests/integration/jest/labApi.js b/tests/integration/jest/labApi.js index 88652c2d2..e180137a6 100644 --- a/tests/integration/jest/labApi.js +++ b/tests/integration/jest/labApi.js @@ -60,3 +60,4 @@ export const getAiStatus = (datasetId) => get(`http://lab:5080/api/userdatasets/ export const fetchExperimentModel = (id) => get(`http://lab:5080/api/v1/experiments/${id}/model`); export const fetchExperimentScript = (id) => get(`http://lab:5080/api/v1/experiments/${id}/script`); +export const postCodeExecutions = (params) => post('http://lab:5080/execapi/v1/executions', params) diff --git a/tests/integration/jest/machineApi.test.ts b/tests/integration/jest/machineApi.test.ts index 8bcd1f880..05ee41f90 100644 --- a/tests/integration/jest/machineApi.test.ts +++ b/tests/integration/jest/machineApi.test.ts @@ -77,6 +77,13 @@ describe('machine', () => { expect(data.capacity).toEqual(1) }); + it('Test the code run API endpoint results are correct.', async () => { + var labCodeRun = await labApi.postCodeExecutions({ src_code: "print('hello world')" }) + expect(labCodeRun.status).toBeTruthy() + expect(labCodeRun._id).toBeTruthy() + expect(labCodeRun.result).toEqual('hello world\n') + }); + }); describe('startup validation', () => From aeb781bb264b4ef93aa283cc7700ac45dfad2595 Mon Sep 17 00:00:00 2001 From: jay-m-dev Date: Thu, 7 Sep 2023 16:44:50 -0700 Subject: [PATCH 2/6] Add test for package install API endpoint and restore equality checks in execapi --- lab/routes/execapi.js | 26 +++++++++++------------ tests/integration/jest/labApi.js | 1 + tests/integration/jest/machineApi.test.ts | 18 ++++++++++++++++ 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/lab/routes/execapi.js b/lab/routes/execapi.js index 3988b29f2..5108947b9 100644 --- a/lab/routes/execapi.js +++ b/lab/routes/execapi.js @@ -12,7 +12,7 @@ const { } = require('../execapiutils'); router.post('/executions', async (req, res, next) => { - if (req.body.src_code === null) { + if (req.body.src_code == null) { return res.status(400).json({ message: 'No src_code provided' }); } @@ -34,17 +34,17 @@ router.post('/executions', async (req, res, next) => { files: [] }); - if (req.body.dataset_file_id !== null) { + if (req.body.dataset_file_id != null) { execution._dataset_file_id = req.body.dataset_file_id; - } else if (req.body.dataset_id !== null) { + } else if (req.body.dataset_id != null) { execution._dataset_id = req.body.dataset_id; let dataset = await getDatasetById(req.body.dataset_id); - if (dataset !== null) { + if (dataset != null) { execution._dataset_file_id = dataset.files[0]._id; } } - if (req.body.experiment_id !== null) { + if (req.body.experiment_id != null) { execution._experiment_id = req.body.experiment_id; } @@ -67,7 +67,7 @@ router.post('/executions', async (req, res, next) => { let machines; try { machines = await Machine.find({}, { address: 1 }); - if (machines.length === 0) { + if (machines.length == 0) { return res.status(400).json({ message: 'No machines available' }); } // call the machine api @@ -110,19 +110,19 @@ router.post('/executions', async (req, res, next) => { router.post('/executions/install', async (req, res, next) => { - if (req.body.command !== 'install' && req.body.command !== 'freeze') { + if (req.body.command != 'install' && req.body.command != 'freeze') { return res.status(400).json({ message: 'Invalid command' }); } - if ( (req.body.packages === null || req.body.packages.length === 0) - && req.body.command !== 'freeze') { + if ( (req.body.packages == null || req.body.packages.length == 0) + && req.body.command != 'freeze') { return res.status(400).json({ message: 'No packages provided' }); } let machines; try { machines = await Machine.find({}, { address: 1 }); - if (machines.length === 0) { + if (machines.length == 0) { return res.status(400).json({ message: 'No machines available' }); } // call the machine api @@ -147,13 +147,13 @@ router.get('/executions/:id', getExecutionById, async (req, res, next) => { }); router.patch('/executions/:id', getExecutionById, async (req, res, next) => { - if (req.body.status !== null) { + if (req.body.status != null) { res.execution.status = req.body.status; } - if (req.body.result !== null) { + if (req.body.result != null) { res.execution.result = req.body.result; } - if (req.body.files !== null) { + if (req.body.files != null) { res.execution.files = req.body.files; } try { diff --git a/tests/integration/jest/labApi.js b/tests/integration/jest/labApi.js index e180137a6..ea5fd4449 100644 --- a/tests/integration/jest/labApi.js +++ b/tests/integration/jest/labApi.js @@ -61,3 +61,4 @@ export const fetchExperimentModel = (id) => get(`http://lab:5080/api/v1/experime export const fetchExperimentScript = (id) => get(`http://lab:5080/api/v1/experiments/${id}/script`); export const postCodeExecutions = (params) => post('http://lab:5080/execapi/v1/executions', params) +export const postPackageInstall = (params) => post('http://lab:5080/execapi/v1/executions/install', params) diff --git a/tests/integration/jest/machineApi.test.ts b/tests/integration/jest/machineApi.test.ts index 05ee41f90..36bd19a02 100644 --- a/tests/integration/jest/machineApi.test.ts +++ b/tests/integration/jest/machineApi.test.ts @@ -80,10 +80,28 @@ describe('machine', () => { it('Test the code run API endpoint results are correct.', async () => { var labCodeRun = await labApi.postCodeExecutions({ src_code: "print('hello world')" }) expect(labCodeRun.status).toBeTruthy() + expect(labCodeRun.status).toEqual('completed') expect(labCodeRun._id).toBeTruthy() expect(labCodeRun.result).toEqual('hello world\n') }); + // I'll need a specific dataset id for this test to work. + // it('Test code run API endpoint recognizes df.', async () => { + // var labCodeRun = await labApi.postCodeExecutions({ src_code: "print(df.head(1))", dataset_id: }) + // expect(labCodeRun.status).toBeTruthy() + // expect(labCodeRun.status).toEqual('completed') + // expect(labCodeRun._id).toBeTruthy() + // expect(labCodeRun.result).toBeTruthy() + // }); + + // it('Test code run API endpoint recognizes model') + + it('Test the package install API endpoint.', async () => { + var labCodeInstall = await labApi.postPackageInstall({ command: 'install', packages: ['numpy'] }) + expect(labCodeInstall.exec_results.code).toEqual(0) + expect(labCodeInstall.exec_results.stdout).toBeTruthy() + }); + }); describe('startup validation', () => From c01061f80d2747362bd66f756322d4d4d9c65ea6 Mon Sep 17 00:00:00 2001 From: jay-m-dev Date: Thu, 7 Sep 2023 16:50:27 -0700 Subject: [PATCH 3/6] Add full output of code executions in the response --- machine/machine.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/machine/machine.js b/machine/machine.js index ab654fb27..abaf5f57d 100644 --- a/machine/machine.js +++ b/machine/machine.js @@ -489,12 +489,12 @@ app.post("/code/run/install", jsonParser, (req, res) => { pyProc.stdout.on("data", (data) => { // result.exec_results = JSON.parse(data.toString()); console.log(`stdout: ${data}`); - result.exec_results.stdout = data.toString(); + result.exec_results.stdout += data.toString(); }); pyProc.stderr.on("data", (data) => { console.log(`stderr: ${data}`); - result.exec_results.stderr = data.toString(); + result.exec_results.stderr += data.toString(); // try { // result.exec_results = JSON.parse(data.toString()); // } From 75e415a45b6ba15e660409b854661e0d9aaa91ba Mon Sep 17 00:00:00 2001 From: jay-m-dev Date: Thu, 7 Sep 2023 17:15:09 -0700 Subject: [PATCH 4/6] Add test for good and bad package installs on install API endpoint --- tests/integration/jest/machineApi.test.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/integration/jest/machineApi.test.ts b/tests/integration/jest/machineApi.test.ts index 36bd19a02..f438563bd 100644 --- a/tests/integration/jest/machineApi.test.ts +++ b/tests/integration/jest/machineApi.test.ts @@ -96,12 +96,18 @@ describe('machine', () => { // it('Test code run API endpoint recognizes model') - it('Test the package install API endpoint.', async () => { + it('Test the package install API endpoint with good package.', async () => { var labCodeInstall = await labApi.postPackageInstall({ command: 'install', packages: ['numpy'] }) expect(labCodeInstall.exec_results.code).toEqual(0) expect(labCodeInstall.exec_results.stdout).toBeTruthy() }); + it('Test the package install API endpoint with a bad package.', async () => { + var labCodeInstall = await labApi.postPackageInstall({ command: 'install', packages: ['test'] }) + expect(labCodeInstall.exec_results.code).toEqual(1) + expect(labCodeInstall.exec_results.stderr).toBeTruthy() + }) + }); describe('startup validation', () => From 10ce674df67d0763ae63d9b2ae7c090b0c68ee4d Mon Sep 17 00:00:00 2001 From: jay-m-dev Date: Thu, 7 Sep 2023 17:31:52 -0700 Subject: [PATCH 5/6] Fix check for packages property in request body --- lab/routes/execapi.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lab/routes/execapi.js b/lab/routes/execapi.js index 5108947b9..47a4a9955 100644 --- a/lab/routes/execapi.js +++ b/lab/routes/execapi.js @@ -114,8 +114,8 @@ router.post('/executions/install', async (req, res, next) => { return res.status(400).json({ message: 'Invalid command' }); } - if ( (req.body.packages == null || req.body.packages.length == 0) - && req.body.command != 'freeze') { + if (req.body.command != 'freeze' && (req.body.packages == null || + req.body.packages.length == 0)) { return res.status(400).json({ message: 'No packages provided' }); } From b4f13c337603d017aac5622c5c01bd960c52f613 Mon Sep 17 00:00:00 2001 From: jay-m-dev Date: Thu, 7 Sep 2023 17:31:52 -0700 Subject: [PATCH 6/6] Fix link to aliro_imager_start page in userguide --- docs/guides/userGuide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guides/userGuide.md b/docs/guides/userGuide.md index 80213849a..8d249bf99 100644 --- a/docs/guides/userGuide.md +++ b/docs/guides/userGuide.md @@ -75,7 +75,7 @@ to be up and running as soon as you boot up the Operating System.) ![Aliro Imager Install](https://media.githubusercontent.com/media/EpistasisLab/Aliro/master/docs/source/_static/aliro_imager_install.png?raw=true "Aliro Imager Install") 4. Once installed, you can run the **AliroEd Imager** from the Start Menu. When the program starts up you will see this screen: - ![Aliro Imager Start](https://media.githubusercontent.com/EpistasisLab/Aliro/master/docs/source/_static/aliro_imager_start.png?raw=true "Aliro Imager Start") + ![Aliro Imager Start](https://media.githubusercontent.com/media/EpistasisLab/Aliro/master/docs/source/_static/aliro_imager_start.png?raw=true "Aliro Imager Start") 5. Click the **CHOOSE STORAGE** button and select your MicroSD Card from the popup menu. ![Aliro Imager Choose Storage](https://media.githubusercontent.com/media/EpistasisLab/Aliro/master/docs/source/_static/aliro_imager_choose_storage.png?raw=true "Aliro Imager Choose Storage")