Skip to content

Commit

Permalink
Remove unused code and features (#142)
Browse files Browse the repository at this point in the history
* Big tidyup

- Remove unnecessary configurability of check-references
- Remove category support (generally unused)
- Remove next-file (totally unused)
- Remove unnecessary configurability of minimumAcceptableAcs

* Big tidyup

- Remove unnecessary configurability of check-references
- Remove category support (generally unused)
- Remove next-file (totally unused)
- Remove unnecessary configurability of minimumAcceptableAcs

* handle a feature/release with 0 specs and 0 coverage

* bump version and run audit
  • Loading branch information
edd authored Aug 19, 2024
1 parent 7f271c4 commit a78dc80
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 794 deletions.
26 changes: 3 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,6 @@ npx github:vegaprotocol/approbation@latest check-references --specs="./specs/pro
docker run -v "$(pwd):/run" ghcr.io/vegaprotocol/approbation:latest check-references --specs="/run/specs/protocol/**/*.{md,ipynb}" --tests="/run/MultisigControl/test/*.js" --ignore="/run/specs/protocol/{0001-*}" --categories="/run/specs/protocol/categories.json" --show-branches --show-mystery --output-csv --output="/run/results/"
```
## next-filename
> Suggests what file sequence number to use next, given a list of spec files
**Arguments**
| **Parameter** | **Type** | **Description** | **Example** |
|-----------------|----------|--------------------------------------|----------------------|
| `--specs` | glob | specs to pull AC codes from | `{specs/**/*.md}` |
| `--ignore` | glob | glob of files not to include | `specs/0001-spec.md` |
| `--verbose` | boolean | Display extra output | - |
In the case of three specs, ['001...', '002...', '003...'] this would suggest '004'. However if '002' didn't exist, it would indicate that '002' is available, as well as '004'.
### next-filename example
```bash
# Use node
npx @vegaprotocol/approbation next-filename --specs="./specs/protocol/**/*.{md,ipynb}"
# Or run the docker image
docker run -v "$(pwd):/run" ghcr.io/vegaprotocol/approbation:latest next-filename --specs="/run/specs/protocol/**/*.{md,ipynb}"
```
## next-code
> Suggests what AC code to use next given a spec file
Expand All @@ -136,15 +116,15 @@ docker run -v "$(pwd):/run" ghcr.io/vegaprotocol/approbation:latest next-filenam
| `--ignore` | glob | glob of files not to include | `specs/0001-spec.md` |
| `--verbose` | boolean | Display extra output | - |
Like `next-filename`, `next-code` will suggest the lowest available code in the sequence (e.g. if there is `0001-SPEC-001` and `0001-SPEC-003`), it will suggest both `0001-SPEC-002` and `000-SPEC-004`. If using the lowest available code, ensure it isn't already referenced by any tests (i.e. isn't listed as a 'Mystery Criteria' by `check-references`).
`next-code` will suggest the lowest available code in the sequence (e.g. if there is `0001-SPEC-001` and `0001-SPEC-003`), it will suggest both `0001-SPEC-002` and `000-SPEC-004`. If using the lowest available code, ensure it isn't already referenced by any tests (i.e. isn't listed as a 'Mystery Criteria' by `check-references`).
### next-code example
```bash
# Use node
npx @vegaprotocol/approbation next-filename --specs="./specs/protocol/**/*.{md,ipynb}"
npx @vegaprotocol/approbation next-code --specs="./0030-ETHM-multisig_control_spec.md"
# Or run the docker image
docker run -v "$(pwd):/run" ghcr.io/vegaprotocol/approbation:latest next-filename --specs="/run/specs/protocol/**/*.{md,ipynb}"
docker run -v "$(pwd):/run" ghcr.io/vegaprotocol/approbation:latest next-code --specs="./0030-ETHM-multisig_control_spec.md"
```
Expand Down
108 changes: 9 additions & 99 deletions bin/approbation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const packageJson = require('../package.json')
const { checkFilenames } = require('../src/check-filenames')
const { nextFilename } = require('../src/next-filename')
const { nextCode } = require('../src/next-code')
const { checkCodes } = require('../src/check-codes')
const { checkFeatures } = require('../src/check-features')
Expand All @@ -13,12 +12,6 @@ const argv = require('minimist')(process.argv.slice(2))
const command = argv._[0]
const IS_DEBUG = process.env.debug !== undefined

function debugOutput(text) {
if (IS_DEBUG) {
console.log(pc.purple(text))
}
}

function warn(lines) {
console.warn('')
lines.map(l => console.warn(pc.yellow(`! ${l}`)))
Expand All @@ -44,99 +37,38 @@ if (argv && argv['show-branches']) {
console.log()
}

if (command === 'check-filenames') {
let paths = '{./non-protocol-specs/**/*.md,./protocol/**/*.md}'
const ignoreGlob = argv.ignore

if (!argv.specs) {
warn(['No --specs argument provided, defaulting to:', `--specs="${paths}"`, '(This behaviour will be deprecated in 3.0.0)'])
} else {
paths = argv.specs
}
const paths = argv.specs
const ignoreGlob = argv.ignore
const isVerbose = argv.verbose === true
if (!argv.specs) {
process.exit('All commands require a --specs argument')
}

if (command === 'check-filenames') {
res = checkFilenames(paths, ignoreGlob)
process.exit(res.exitCode)
} else if (command === 'next-filename') {
let paths = '{./non-protocol-specs/**/*.md,./protocol/**/*.md}'
const ignoreGlob = argv.ignore

if (!argv.specs) {
warn(['No --specs argument provided, defaulting to:', `--specs="${paths}"`, '(This behaviour will be deprecated in 3.0.0)'])
} else {
paths = argv.specs
}
const isVerbose = argv.verbose === true

res = nextFilename(paths, ignoreGlob, isVerbose)
process.exit(res.exitCode)
} else if (command === 'next-code') {
let paths = '{./non-protocol-specs/**/*.md,./protocol/**/*.md}'
const ignoreGlob = argv.ignore
const isVerbose = argv.verbose === true

if (!argv.specs) {
warn(['No --specs argument provided, defaulting to:', `--specs="${paths}"`, '(This behaviour will be deprecated in 3.0.0)'])
} else {
paths = argv.specs
}

res = nextCode(paths, ignoreGlob, isVerbose)
process.exit(res.exitCode)
} else if (command === 'check-codes') {
let paths = '{./non-protocol-specs/**/*.md,./protocol/**/*.md}'
const ignoreGlob = argv.ignore
const isVerbose = argv.verbose === true

if (!argv.specs) {
warn(['No --specs argument provided, defaulting to:', `--specs="${paths}"`, '(This behaviour will be deprecated in 3.0.0)'])
} else {
paths = argv.specs
}

res = checkCodes(paths, ignoreGlob, isVerbose)
process.exit(res.exitCode)
} else if (command === 'check-features') {
let specs, features
const isVerbose = argv.verbose === true
const ignoreGlob = argv.ignore

if (!argv.features) {
warn(['No --features argument provided)'])
process.exit(1);
} else {
features = argv.features
}

if (!argv.specs) {
warn(['No --specs argument provided'])
process.exit(1);
} else {
specs = argv.specs
}

res = checkFeatures(specs, features, ignoreGlob, isVerbose)
res = checkFeatures(specs, argv.features, ignoreGlob, isVerbose)
process.exit(res.exitCode)
} else if (command === 'check-references') {
debugOutput('check-references')
const specsGlob = argv.specs
const testsGlob = argv.tests
const categories = argv.categories
const features = argv.features
const ignoreGlob = argv.ignore
const currentMilestone = argv['current-milestone']
const showMystery = argv['show-mystery'] === true
const showCategoryStats = argv['category-stats'] === true
const isVerbose = argv.verbose === true
const showFiles = argv['show-files'] === true
const shouldOutputCSV = argv['output-csv'] === true
let outputPath = argv.output
const shouldOutputJenkins = argv['output-jenkins'] === true
const shouldShowFileStats = argv['show-file-stats'] === true

if (!argv.specs) {
warn(['No --specs argument provided, exiting'])
process.exit(1)
}

if (!argv.tests) {
warn(['No --tests argument provided, exiting'])
Expand All @@ -148,22 +80,8 @@ if (command === 'check-filenames') {
process.exit(1)
}

if (shouldOutputCSV || shouldOutputJenkins) {
if (!outputPath || outputPath.length === 0) {
console.error(pc.yellow('Output path should be provided with --output if CSV or Jenkins output are enabled. Defaulting to ./results'))
outputPath = './results'
} else {
// Ensure we don't have a trailing slash for consistency with the default
if (outputPath && outputPath.endsWith('/')) {
debugOutput(`Removing trailing slash from output path: ${outputPath}`)
outputPath = outputPath.slice(0, -1)
}
console.info(pc.yellow(`Output folder: ${outputPath}`))
}
}

// TODO: Turn in to an object
res = checkReferences(specsGlob, testsGlob, categories, ignoreGlob, features, showMystery, isVerbose, showCategoryStats, showFiles, shouldOutputCSV, shouldOutputJenkins, shouldShowFileStats, currentMilestone, outputPath)
res = checkReferences(paths, testsGlob, ignoreGlob, features, currentMilestone, outputPath)

process.exit(res.exitCode)
} else {
Expand Down Expand Up @@ -203,14 +121,6 @@ if (command === 'check-filenames') {
showArg(`--categories="${pc.yellow('./specs/protocol/categories.json')}"`, 'Single JSON file that contains the categories for this test run')
showArg(`--features="${pc.yellow('./specs/protocol/features.json')}"`, 'Single JSON file that contains the features for this test run')
showArg(`--ignore="${pc.yellow('{tests/**/*.{py,feature}')}"`, 'glob of files to ignore for both tests and specs')
showArg('--show-mystery', 'If set, display criteria in tests that are not in any specs matched by --specs')
showArg('--category-stats', 'Show more detail for referenced/unreferenced codes')
showArg('--show-branches', 'Show git branches for subfolders of the current folder')
showArg('--show-files', 'Show basic stats per file')
showArg('--show-file-stats', 'Show detailed stats per file')
showArg('--verbose', 'Show more detail for each file')
showArg('--output-csv', 'Show more detail for each file')
showArg('--output-jenkins', 'Output a quick summary for CI')
console.groupEnd('Arguments')
console.groupEnd('check-references')
}
22 changes: 13 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vegaprotocol/approbation",
"version": "4.8.0",
"version": "4.9.0",
"description": "Match Acceptance Criteria Codes with the tests that test them",
"engine": ">= 18",
"bin": "./bin/approbation.js",
Expand Down
5 changes: 2 additions & 3 deletions src/check-codes.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const fs = require('fs')
const glob = require('fast-glob')
const path = require('path')
const { validSpecificationPrefix, ignoreFiles } = require('./lib')
const { minimumAcceptableACsPerSpec } = require('./config')
const pc = require('picocolors')

/**
Expand Down Expand Up @@ -145,7 +144,7 @@ function checkPath (files, output = true) {


// The files are *valid*, at least. But do they have enough ACs?
if (totalAcceptanceCriteria.length >= minimumAcceptableACsPerSpec) {
if (totalAcceptanceCriteria.length >= 1) {
countAcceptableFiles++
if (output && verbose) {
console.group(pc.bold(file))
Expand Down Expand Up @@ -181,7 +180,7 @@ function checkCodes (paths, ignoreGlob, isVerbose = false) {
if (fileList.length > 0) {
res = checkPath(fileList)
console.log('\r\n--------------------------------------------------')
console.log(`Acceptable ${res.countAcceptableFiles} (files with more than ${minimumAcceptableACsPerSpec} ACs)`)
console.log(`Acceptable ${res.countAcceptableFiles} (files with more than 1 ACs)`)
console.log(`Need work ${res.countEmptyFiles}`)
console.log(`Files with errors ${res.countErrorFiles}`)
console.log(`Total ACs ${res.countAcceptanceCriteria}`)
Expand Down
4 changes: 1 addition & 3 deletions src/check-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
*/
const fs = require('fs')
const glob = require('fast-glob')
const path = require('path')
const { validSpecificationPrefix, ignoreFiles } = require('./lib')
const { minimumAcceptableACsPerSpec } = require('./config')
const { ignoreFiles } = require('./lib')
const pc = require('picocolors')
const { gatherSpecs, findDuplicateAcs } = require('./check-references')
const { setFeatures } = require('./lib/feature')
Expand Down
Loading

0 comments on commit a78dc80

Please sign in to comment.