Socket
Socket
Sign inDemoInstall

@prodperfect/cli

Package Overview
Dependencies
0
Maintainers
4
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @prodperfect/cli

A command-line client for ProdPerfect's public Test API


Version published
Weekly downloads
94
increased by54.1%
Maintainers
4
Created
Weekly downloads
 

Readme

Source

cli

A command-line client for ProdPerfect's public Test API

TL;DR

The New & Improved™️ P2 CLI replaces the existing prodperfectqa-runner CLI and will enable customers to interact with our new remote test harness infrastructure. It is, at least in this first incarnation, simply a command-line interface for a curated subset of the Test API, allowing users to

  • inspect the contents of test suites they can access,
  • submit execution requests for their test suites, or subsets of them, and
  • monitor the progress of those execution requests.

In-depth technical documentation can be found at our documentation site:

https://prodperfect.github.io/cli

The CLI itself will

  • be deployed as a versioned, standalone artifact
    • packaged & deployed via GitHub Actions
    • hosted by GitHub Releases
  • be documented via website hosted within the source repo
    • compiled via Docusaurus
    • hosted on GitHub Pages
  • be written as a Bash program
    • bootstrapped via Bashly
    • QA-tested via Approvals.bash
    • instrumented via Sentry
  • be housed in a publicly-visible-and-readonly GitHub repo
  • be called something other than "prodperfectqa-runner"
    • No mention of "P2": that's an internal thing, and also collides with the use of "2" in CLI command names (which conventionally is shorthand for "to" and reserved for conversion or translation operations)

Tech Stack

Language choice: Bash

Why?

  • robust & secure
  • light-weight & open-source
  • maintainable & easy to deploy cross-platform
  • unfamiliar to enough people that it encourages simplicity within the CLI
  • near-universal support in CI/CD ecosystems
  • designed to support CLI applications

CLI Framework choice: Bashly

Why?

  • Widely used
  • Open-source
  • actively maintained and supported
  • pleasant to use
  • easy to maintain
  • compiles CLI into a single script
  • support for user environment configuration

Development and QA Testing

A standard develop-review-merge workflow applies here, nothing special and nothing that needs going over. Deployment and distribution is outlined later.

Quality assurance will be encapsulated through a combination of approval testing, a style which requires manual approval anytime a test case produces different output than the previously approved one; and end-to-end testing using our own dogfed test suites as targets. When a feature PR is opened, a GitHub workflow will be triggered which runs our approval tests; the build will fail if any of the tests fail approval, at which point the developer must either fix what they broke, or run the tests on their local machine to approve the new behavior, and commit the approval to their feature branch.

If deemed necessary, such as when changing the way the CLI interacts with the underlying Test API it consumes, manual end-to-end testing will be performed. The scope of such testing will be decided upon and planned out along with the relevant feature work, but once the test plan is in hand, the release candidate can be tested leveraging one or more of our in-house, dog-fed test suites such as the ones for Mission Control and Operations.

Release & Distribution

We will be leveraging GitHub workflows and an update mechanism built into the CLI itself to automate deployment and distribution.

Releases

The release process will be encapsulated by a GitHub Actions Workflow on pull requests against the main project branch:

  1. Open a PR against the main project branch, which will trigger a GitHub Workflow to compile the distribution build:
    • Bashly will be used to compile the project down into a single script.
    • The resulting build will be committed to the feature branch, and can be used for testing the latest changes.
    • Approval tests will run once the build completes, blocking the release on failure.
  2. Continue iterating on the PR if needed (the build will be triggered again by each new push).
  3. When ready, bump the version in the CLI version file of your feature branch.
  4. Merge the PR. This will trigger another GitHub Workflow to release the distribution build:
    • The merge commit will be tagged with the CLI version.
    • A GitHub release will be created for that tag, containing the new CLI build.
    • (pending further discussion) The new version will be published to NPM.

Distribution

Option 1: GitHub Releases

Users will be able to download the CLI directly from our GitHub Releases repository (and/or, ideally, from our documentation site). This can be a manual process or a programmatic one via something simple like cURL.

For example, to download a specific release is simply:

$ curl -sOL https://github.com/ProdPerfect/cli/releases/download/2.7.42/cli \
  && chmod +x ./cli

To download the latest release is similarly simple:

$ curl -sOL https://github.com/ProdPerfect/cli/releases/latest/download/cli \
  && chmod +x ./cli

Option 2: Node Package Manager (NPM)

If we choose, it is also trivial to continue publishing our CLI to NPM under the same package name. Choosing to do so is beneficial only if it is imperative to maintain the current way in which the P2 CLI is installed in some cases, i.e. this method of installation (the incantation we currently serve to customers as copypasta) would continue to work:

$ npm install --no-save -E prodperfectqa-runner@<DIST TAG>

Note that customers will need to change their CLI usage, including CI integrations, regardless, because this would be the equivalent of a major version release and is not backwards-compatible. Choosing to continue publishing to NPM will not ensure a passive transition to the new CLI for CI integrations. See below in P2 CLI++: Tech Design for details on what that looks like.

Usage in Continuous Integration (CI)

Latest version

For customers using us in CI integrations, they will first need to ensure their authentication token (issued by us to them directly) are available in their CI environment, a standard process for using any paid service and thus most clients should be familiar with it.

Once that's set, a sample integration would look like one of the following.

Option 1: Installing from GitHub

Super straightforward: just download the latest release asset every time to a sandbox directory (to avoid clobbering project source code) then make it executable and run it the way you want.

# in package.json
{
  ...
  "scripts": {
    "prodperfect": "mkdir -p .prodperfect && cd .prodperfect && curl -sL https://github.com/ProdPerfect/cli/releases/latest/download/cli > cli && chmod +x ./cli && ./cli suites run <SUITE ID>"
  }
}
Option 2: Installing from NPM

Also super straightforward: NPM installs the latest version by default if no version is specified:

# in package.json
{
  ...
  "scripts": {
    "prodperfect": "npm install --no-save -E prodperfectqa-runner && prodperfectqa-runner suites run <SUITE ID>"
  }
}

Pinned version

For customers using us in CI integrations, they will first need to ensure their authentication token (issued by us to them directly) are available in their CI environment, a standard process for using any paid service and thus most clients should be familiar with it.

Once that's set, a sample integration would look like one of the following.

Option 1: Installing from GitHub

The basic version is again super straightforward: just download the specific version asset every time to a sandbox directory, make it executable, and run it the way you want.

# in package.json
{
  ...
  "scripts": {
    "prodperfect": "mkdir -p .prodperfect && cd .prodperfect && curl -sL https://github.com/ProdPerfect/cli/releases/download/2.7.42/cli > cli && chmod +x ./cli; ./cli suites run <SUITE ID>"
  }
}

If we wanted to put a mild cache guard in place, we could gate the download with a basic existence+version check:

# in package.json
{
  ...
  "scripts": {
    "prodperfect": "mkdir -p .prodperfect && cd .prodperfect; [[ ! -e \"./cli\" || ! \"$(./cli -v)\" = \"2.7.42\" ]] && curl -sOL https://github.com/ProdPerfect/cli/releases/download/2.7.42/cli && chmod +x ./cli; ./cli suites run <SUITE ID>"
  }
}

If we don't like the ugliness of having a long one-liner integration, the best thing to do would be to simply give them a tiny driver script, complete with embedded auth token, to put wherever they want and tell them to call it, like so:

#! /bin/env bash
AUTH_TOKEN=${AUTH_TOKEN:-<blah>}
TARGET_CLI_VERSION=2.7.42
# Bail if anything goes wrong
set -e
# Make a sandbox
mkdir -p .prodperfect
cd .prodperfect
# Install the CLI if needed
if [[ ! -e "./cli" || ! "$(./cli -v)" = "$TARGET_CLI_VERSION" ]]; then
  curl -sOL https://github.com/ProdPerfect/cli/releases/download/${TARGET_CLI_VERSION}/cli
  chmod +x ./cli
fi
# Run the CLI with authentication.
env AUTH_TOKEN=$AUTH_TOKEN ./cli "$@"
# in package.json
{
  ...
  "scripts": {
    "prodperfect": "path/to/install-and-execute-p2.sh suites run <SUITE ID>"
  }
}
Option 2: Installing from NPM

Virtually identical to installing the latest, the only difference is you just specify the version you want to install:

# in package.json
{
  ...
  "scripts": {
    "prodperfect": "npm install --no-save -E prodperfectqa-runner@<VERSION TAG> && prodperfectqa-runner suites run <SUITE ID>"
  }
}

One nice thing about NPM is that it'll handle the 'smarts' of the installation process so that we don't have to.

Monitoring and Maintenance

The Sentry CLI can be used to instrument Bash scripts in similar ways as their other SDKs, and we will take full advantage of that to monitor user experience errors in our CLI.

It does not support performance monitoring, however, so we won't be able to leverage Sentry for tracking user engagement statistics; and we don't seem to have any other business subscriptions to applicable tools. So for now, we'll need to rely indirectly on the observability of the underlying Test API to build a picture of CLI usage.

As a CLI, limited maintenance is expected. The surface area for trouble is more or less limited to:

  • bugs
  • environment compatibility issues (e.g. someone doesn't have access to Bash or a compatible version of it)
  • breaking changes in the Test API

When maintenance is needed, it will follow the same workflow as general development, plus whatever additional legwork is necessary to confirm the particular issue has been addressed.

Public Documentation (🚧 wip 🚧)

todo

What's the API?

Core features

  • auth token required (no login flow)
  • executes a test suite given its ID
    • outputs for humans or machines as desired
    • accepts metadata for customer usage (see Test API for details)
    • accepts overrides for execution parameters (see Test API for details)
    • option for blocking and non-blocking execution
    • network timeouts and other local-machine errors on blocking execution fail gracefully by converting to non-blocking
    • links back to the execution view in our platform (MC) for posterity
  • executes a subset of a test suite given its ID and relevant test IDs
    • (support as above)
  • polls an execution for progress info
    • outputs for humans or machines as desired

Supplementary features

  • reads from a config file + env vars
  • pre-distributed auth token can be configured for set-and-forget usage
  • list accessible test suites
  • list tests in a given test suite

FAQs

Last updated on 14 Apr 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc