if
if copied to clipboard
[WIP] Build `if-check`
What
Build a command line tool called if-check that wraps calls to if-env and if-diff. On the command line, a user can call if-check, passing an output file, and the tool will install the necessary dependencies as defined by if-env and then if-diff the provided output file against a newly generated version obtained by executing the context and tree sections from the given output file as if it were a fresh manifest.
Why
As a user I want to be able to re-execute a manifest and verify that the outputs are correctly reported. if-check is a convenience tool that wraps the individual steps required to verify a manifest into a single command.
The point of this is to verify that a given output file was correctly reported
Say someone gives you a manifest file to demonstrate the environmental impact of their application. Maybe you don't trust them completely, or are suspicious they've made a mistake. You can just pass their manifest to if-check and it will run it back through IF and report whether the given data is accurate or not - if not, if-check will report where there are differences.
In terms of the implementation, if-check should do the following under the hood:
- run
if-envon the given manifest (which we can refer to asmanifest.ymlwhich will recreate the original runtime environment reported in the manifest locally - run the manifest and save the output to a temporary file (here we can refer to it as
re-executed.yml) - run
if-diffwithif-diff --source manifest --target re-executed.yml - report the output from
if-diffto the console
This means the if-check CLI tool can be an alias to:
if-env && ie given-file.yml --stdout | if-diff --target given-file.yml
The result should be an if-diff output, for example:
Files match!
or
Files do not match!
tree.children.child.inputs[0]['cpu/energy']
source: 50
target: 30
Acceptance Criteria
-
A command line tool,
if-checkexists that takes an output file as input, and returns the output fromif-diff- The command line tool
if-checkshould take a single argument,--filewhose value should be a path to an output file. - IThe
if-envtool can be run on the output file, given information in it'sexecutionblock. The output file can then be used as an input toie, to re-run the given it in precisely the same environment (at least at the level ofpackage.json, not necessarily at the Node or OS level). - The given output file and the file generated by rerunning the manifest should be compared. The
if-checkcommand should yield precisely the same output as runningif-envandif-diffseparately on a file.
- The command line tool
-
GIVEN a user has downloaded and installed
if
WHEN they runif-checkpassing a valid output file
THEN they receive theif-diffoutput comparing their given output file with a new one generated by re-executing the given onee.g. the following output file (
example-file.yml) is provided:
name: sum
description: successful path
tags: null
initialize:
plugins:
sum:
path: '@grnsft/if-plugins'
method: Sum
global-config:
input-parameters:
- cpu/energy
- network/energy
output-parameter: energy
outputs:
- yaml
execution:
command: >-
/home/user/.npm/_npx/1bf7c3c15bf47d04/node_modules/.bin/ts-node
/home/user/Code/if/src/index.ts -m manifests/outputs/test.yaml -o
manifests/outputs/test2.yml
environment:
if-version: v0.3.2
os: linux
os-version: 5.15.0-105-generic
node-version: 21.4.0
date-time: 2024-05-15T10:28:36.414Z (UTC)
dependencies:
- '@babel/[email protected]'
- '@babel/[email protected]'
- '@commitlint/[email protected]'
- '@commitlint/[email protected]'
- '@grnsft/[email protected]'
- '@grnsft/[email protected]'
- '@jest/[email protected]'
- '@types/[email protected]'
- '@types/[email protected]'
- '@types/[email protected]'
- '@types/[email protected]'
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
tree:
children:
child:
pipeline:
- sum
config:
sum: null
inputs:
- timestamp: 2023-08-06T00:00
duration: 3600
cpu/energy: 0.001
network/energy: 0.001
outputs:
- timestamp: 2023-08-06T00:00
duration: 3600
cpu/energy: 0.001
network/energy: 0.001
energy: 0.002
The following command is executed:
if-check example-file.yml
The following response is expected:
Files match!
The following output file has a deliberate error introduced in the outputs/energy field.
name: sum
description: successful path
tags: null
initialize:
plugins:
sum:
path: '@grnsft/if-plugins'
method: Sum
global-config:
input-parameters:
- cpu/energy
- network/energy
output-parameter: energy
outputs:
- yaml
execution:
command: >-
/home/user/.npm/_npx/1bf7c3c15bf47d04/node_modules/.bin/ts-node
/home/user/Code/if/src/index.ts -m manifests/outputs/test.yaml -o
manifests/outputs/test2.yml
environment:
if-version: v0.3.2
os: linux
os-version: 5.15.0-105-generic
node-version: 21.4.0
date-time: 2024-05-15T10:28:36.414Z (UTC)
dependencies:
- '@babel/[email protected]'
- '@babel/[email protected]'
- '@commitlint/[email protected]'
- '@commitlint/[email protected]'
- '@grnsft/[email protected]'
- '@grnsft/[email protected]'
- '@jest/[email protected]'
- '@types/[email protected]'
- '@types/[email protected]'
- '@types/[email protected]'
- '@types/[email protected]'
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
tree:
children:
child:
pipeline:
- sum
config:
sum: null
inputs:
- timestamp: 2023-08-06T00:00
duration: 3600
cpu/energy: 0.001
network/energy: 0.001
outputs:
- timestamp: 2023-08-06T00:00
duration: 3600
cpu/energy: 0.001
network/energy: 0.001
energy: 0.0005
Running if-check example-file-2.yml should yield:
File do not match!
tree.children.child.intputs[0]['energy']
source: 0.002
target: 0.0005
-
A set of identical and non-identical manifests exist as a test set, whose
if-checkoutcome we know a priori and can be used to verify thatif-checkis operating correctly.- This might be satisfied naturally as part of Build
if-diffcore feature #637
- This might be satisfied naturally as part of Build
-
GIVEN the test set exists
WHEN a user runsif-checkon those test manifests
THEN theif-checkoutput matches the expected outputs -
Documentation exists in the form of a README in the IF repository and a section on
if.greensoftware.foundation/docs/reference/cli -
GIVEN the documentation has been added to if-greensoftware.foundation
WHEN a user visits the site and searches forif-check
THEN they will find a dedicated page explaining the tool, with usage examples.
Prerequisites
@jmcook1186 I saw this mentioned in the #615 and got the impression that we expect the dev work to start on this fairly soon, however, there is no acceptance criteria, is this something that should be brought into this week for designing / refining? 🙏
Yes this needs design work! @zanete
Updated Acceptance criteria and description following discussion in IF weekly call
@jawache please take a look at the latest AC to move it along
@jawache please check over the AC and then we can move it to post #636 and #637 as those are blocking
@jawache please check over the AC and then we can move it to post https://github.com/Green-Software-Foundation/if/issues/636 and https://github.com/Green-Software-Foundation/if/issues/637 as those are blocking
@zanete and @jmcook1186 same feedback as the other tickets, can you make the AC with actual manifest files and command lines and actual output/console messages!
Roughly reading then it's on the right lines but there is so much that is left to assumptions at this point. It's a cli tool so the ACs should run this command line, with these exact params and files, and this should be the exact output.
@jawache issue is updated with manifests and more specific acceptance criteria - appreciate your sign-off before this gets worked on next week
Thanks @jmcook1186 looks good however I think we need to think about the context of (a) running a folder of files (b) how this integrates into ci/cd since one ultimate goal is to use this as our test infrastructure for changes to code.
PR Runs if-check on folder of manifests If it passes all good If one fails then should return fail and the logs show which one failed.
Not sure if to meet the above if-check needs functionality OR we can just create a bash script that runs if-check for us in a loop.
If it's bash script I think if-check needs to return, pass through, the return error code from if diff.
I think it would be nicer to handle multiple files inside if-check rather than relying on bash scripts or other 'external' solutions. I added some description to the ticket related to this.
@jmcook1186, can we change the flags? The -m flag would refer to the manifest file, and the -f ( or -d) to the folder (either --directory or --dir). I think this will be more relevant to our CLI commands. What do you think?
Hi @manushak - yes, fine!
there could be a PR for this tomorrow 💪