dxw / whippet

Whippet is a framework for building WordPress sites that eases deployment, plugin management and build steps.
MIT License
14 stars 3 forks source link

Feature/validate whippet files #163

Closed RobjS closed 3 years ago

RobjS commented 3 years ago

This PR adds a new whippet dependencies validate command. It checks the contents of whippet.json and whippet.lock against one another, and throws an error if:

  1. Either isn't present or is invalid JSON
  2. The hash in whippet.lock is not what would be expected based on the contents of whippet.json (the hash is based on a sha of whippet.json's contents)
  3. There isn't the same number of dependencies listed in both
  4. Any dependency listed in one does not have a corresponding entry in the other
  5. Any entry in whippet.lock is malformed (i.e. does not have a name, src and revision)

This should allow us to run whippet deps validate in a CI environment and pick up any problems with the whippet.json or whippet.lock files much sooner than we currently do (i.e. when a PR is opened) - currently, those things are only picked up when an attempted whippet app deploy fails (i.e. after everything is merged and the project is attempting to deploy).

I've introduced Kahlan to write the tests for the new Validator class. Previously, we were only using PHPUnit, but that is painful to use and results in much less readable tests. We should probably migrate the PHPUnit tests into Kahlan at some point, but that's beyond the scope of this PR.

RobjS commented 3 years ago

@brent-dxw If you'd e.g. added a new plugin to whippet.json, but not yet run whippet deps update, I'd expect the validate command to fail at that point because the two files aren't aligned (i.e. whippet.lock isn't reflecting the intention of whippet.json, which is to install the new plugin). Is that what you meant? There may be another scenario I'm missing.

brent-dxw commented 3 years ago

@brent-dxw If you'd e.g. added a new plugin to whippet.json, but not yet run whippet deps update, I'd expect the validate command to fail at that point because the two files aren't aligned (i.e. whippet.lock isn't reflecting the intention of whippet.json, which is to install the new plugin). Is that what you meant? There may be another scenario I'm missing.

Yes, that scenario. Ok, so that makes sense as expected behaviour, as in its validating the further steps.