GWT framework

Canonical Given/When/Then test enrichment framework for Go, shell, and Python.

Module
eleglicity.com/go-modules/gwt-framework
Latest version
v0.3.0
Docs source
b8d50cd83bf5f0c86132640f8737e224e68e74fa (b8d50cd83bf5f0c86132640f8737e224e68e74fa)
Artifact release
v0.3.0
Release commit
f75f3d951ff5fbd3258df77b5a424be931903eaa
Tools image
gwt-framework-tools:v0.3.0
Tarball SHA-256
a2afc5c0debec46337bc9d3ecba2a77aa953e397759eb1ae63dddf3abf4244b2

Go import metadata is used by go get; it is not documentation and is intentionally blank in a browser.

Versionless commands resolve to the latest published release (v0.3.0):

go install eleglicity.com/go-modules/gwt-framework/cmd/gwt

Explicit @latest forms:

go install eleglicity.com/go-modules/gwt-framework/cmd/gwt@latest

Versions

VersionCommitGo commandsArtifacts
v0.3.0 (latest) f75f3d951ff5fbd3258df77b5a424be931903eaa go install eleglicity.com/go-modules/gwt-framework/cmd/gwt@v0.3.0
tools image / tarball
v0.2.0 cb3ce384058273844e8486042c65e89f174cc615 go install eleglicity.com/go-modules/gwt-framework/cmd/gwt@v0.2.0
—
v0.1.0 d8a60a0781f9d89913095808b1cdb711236c946f go install eleglicity.com/go-modules/gwt-framework/cmd/gwt@v0.1.0
—

Overview

The GWT framework is the canonical producer and SDK for Given/When/Then test enrichment. Go, shell, and Python suites emit Schema V per-class reports that the standalone renderer consumes.

It is not the renderer: this module provides the test libraries, shell shim, converter CLI, release tarball, and framework-baked tools image.

Install

Use the published Go module:

go get eleglicity.com/go-modules/gwt-framework

The release tarball and checksum are published under https://eleglicity.com/gwt-framework/. The gwt-framework-tools image bakes that published tarball for host test suites.

Usage

How the pieces fit

gwt-framework produces Schema V per-class JSON. It does not aggregate or serve reports. gwt-renderer is a stateless HTTP consumer that turns those documents into the JSONP viewer bundle.

test -> per-class JSON (Schema V) -> POST /v1/report -> JSONP viewer bundle

Pin one immutable framework release (gwt-framework.lock) and one renderer version. Never pin latest in automation; it is for human browsing.

Shared prerequisites

RENDERER="https://eleglicity.com/gwt-renderer/<version>"
curl -fsS "$RENDERER/health"
gwt compat check --renderer "$RENDERER" --require-known-good

Go client projects

  1. Pin the module in go.mod (no replace):
require eleglicity.com/go-modules/gwt-framework vX.Y.Z

Then run go mod tidy.

  1. Use pkg/gwt/testing in tests:
package calc_test

import (
    "testing"

    gwt_testing "eleglicity.com/go-modules/gwt-framework/pkg/gwt/testing"
)

func TestAdd(t *testing.T) {
    g := gwt_testing.New(t, "go")
    g.Given("two numbers", "1", "2")
    g.When("they are added")
    g.Then("the sum is 3")
    if got := 1 + 2; got != 3 {
        t.Fatalf("sum = %d, want 3", got)
    }
    g.AssertContains("sum=3", "3")
}
  1. For data-driven tests, add sample data and Specification / Execute:
func TestAddRows(t *testing.T) {
    g := gwt_testing.New(t, "go")
    g.WithSampleData(func(cfg *gwt_testing.SampleDataConfig) {
        cfg.WithDataHeaderRow("a", "b", "want").
            WithDataRow("1", "2", "3").
            WithDataRow("10", "20", "30")
    })
    g.Specification(func() {
        a, _ := strconv.Atoi(g.GetDataCurrentRow("a"))
        b, _ := strconv.Atoi(g.GetDataCurrentRow("b"))
        want, _ := strconv.Atoi(g.GetDataCurrentRow("want"))
        g.Given("two numbers")
        g.When("they are added")
        g.Then("the sum matches the data row")
        if a+b != want {
            t.Fatalf("sum = %d, want %d", a+b, want)
        }
    })
    g.Execute()
}
  1. Emit and validate:
GWT_OUTPUT_DIR="$PWD/gwt" go test ./...
gwt schema validate gwt/go/*.json

gwt_testing.New(t, "go") writes gwt/go/<package>.<Class>.json. cmd/gwtreport in a consumer is optional project-specific tooling for go test -json; it is not part of this framework.

  1. Render the report (see the shared renderer step below) with name="go" and gwt/go/*.json.

Shell client projects

  1. Provision the pinned framework. The tools image provides /opt/gwt; otherwise fetch the lock's tarball and verify its SHA-256.
GWT_HOME="${GWT_FRAMEWORK_DIR:-/opt/gwt}"
[ -x "$GWT_HOME/bin/gwt" ] || {
    echo "install gwt-framework-tools or set GWT_FRAMEWORK_DIR" >&2
    exit 1
}
export PATH="$GWT_HOME/bin:$PATH"
export GWT_OUTPUT_DIR="$PWD/gwt/shell"
  1. Source base assertions, then the shim:
source "$PROJECT_DIR/tests/lib/test_helpers.sh"   # ok/fail/skip
source "$GWT_HOME/shell/gwt_enrich.sh"            # GWT event recording

The shim installs trap gwt_finalize EXIT. If you install your own trap, chain it: trap 'cleanup; gwt_finalize' EXIT.

  1. Write the test inside a test_* function so the method name auto-captures:
test_addition() {
    gwt_given "two numbers"
    gwt_when "they are added"
    gwt_then "the sum is 3"
    if [ $((1 + 2)) -eq 3 ]; then
        ok "sum is 3"
    else
        fail "sum was not 3"
    fi
}
test_addition
  1. Convert and validate. The shim calls gwt convert -strict on exit; to run it explicitly:
gwt convert -strict "$GWT_OUTPUT_DIR"
gwt schema validate "$GWT_OUTPUT_DIR"/*.json

Orphaned methods (registered but never completed) become FAILED. A missing gwt binary is a loud failure, never a silent skip.

  1. Render with name="shell-tests" and gwt/shell/*.json.

Python client projects

  1. Install the wheel. The generated contract models are wheel-only, so the source tree is not the supported install path:
python/build-wheel.sh dist
pip install dist/gwt_python-*.whl
  1. Register the pytest plugin in conftest.py:
pytest_plugins = ["gwt_framework.pytest_plugin"]
  1. Write the test:
def test_addition(gwt):
    def spec():
        a, b = 1, 2
        gwt.GIVEN("two numbers", str(a), str(b))
        gwt.WHEN("they are added")
        gwt.THEN("the sum is 3")
        assert a + b == 3

    gwt.with_method_title("Addition works") \
        .specification(spec) \
        .execute()
  1. Emit and validate:
GWT_OUTPUT_DIR="$PWD/gwt" pytest
gwt schema validate gwt/python/**/*.json

The plugin writes gwt/python/<package>/<Class>.json.

  1. Render with name="python-tests" and gwt/python/**/*.json.

Renderer integration (all client types)

Post one or more modules; each payload is:

{
  "modules": [
    { "name": "go", "classes": [ /* Schema V per-class documents */ ] }
  ]
}

Example for the Go output:

RENDERER="https://eleglicity.com/gwt-renderer/<version>"   # pin, never latest
name=go
jq -s --arg name "$name" '{modules:[{name:$name,classes:.}]}' gwt/go/*.json \
  > gwt/request.json
curl -fsS -H 'Content-Type: application/json' \
  --data-binary @gwt/request.json "$RENDERER/v1/report" > gwt/response.json
mkdir -p gwt/report
for f in index.html viewer.js viewer.css data.jsonp modules.jsonp "data.$name.jsonp"; do
  jq -r --arg f "$f" '.files[$f] // empty' gwt/response.json > "gwt/report/$f"
done

The response .files map is the viewer bundle: index.html, viewer.js, viewer.css, data.jsonp, modules.jsonp, and data.<name>.jsonp. Publish that directory from your app or CI artifact store; the framework never serves reports. A non-2xx response is a hard failure. Do not fall back to a fake viewer in production.

Verifying the contract

gwt schema version
gwt schema validate <path...>
gwt compat check --renderer "$RENDERER" --require-known-good

gwt compat check verifies the renderer's transport API, accepted data contract, and optional exact known-good release. Use it in CI before posting a report.

Mechanism

Every producer writes the Schema V per-class JSON shape: package and class metadata, methods, Given/When/Then labels, results, and optional sample data. The Go test library, shell event parser, and Python plugin all target that shape.

The standalone renderer consumes the per-class JSON; this module does not aggregate or serve reports. The root module stays stdlib-only, and the consumer lock pins one immutable release.

Maintenance

Release one immutable tag at a clean HEAD; the release tooling builds the static gwt CLI, the sha256-verified tarball, the tools image, and the consumer lock from that tag. Versions and checksums in the catalog come from gwt-framework.lock, not from this document.

Upgrade consumers by updating the lock to a new immutable tag. Run GOWORK=off go test ./... in the repository and in this nested docs module before publishing. The documentation contract is owned by the site-catalog module; widening it requires a new schema release.