diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..4c12a0b --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,91 @@ +name: Test + +# Runs the tests on each pull request and merge, nightly, and after each pull +# request merged in super (sent by super's notify-downstream-merge.yaml). Since +# super-ts decodes and formats what super writes, the tests also run against +# fixtures made fresh by super, so a change in super that super-ts doesn't +# match yet fails here. + +on: + schedule: + - cron: '5 8 * * *' + workflow_dispatch: + inputs: + super_ref: + description: 'superdb/super branch, tag, or SHA to test against' + default: main + required: false + repository_dispatch: + types: [super-pr-merged] + push: + branches: [main] + pull_request: + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + with: + path: super-ts + + - name: Check out super + uses: actions/checkout@v4 + with: + repository: superdb/super + # After a merge in super, test the commit that merged. + ref: ${{ inputs.super_ref || github.event.client_payload.merge_commit_sha || 'main' }} + path: super + # Tags are needed for the version super reports. + fetch-depth: 0 + + - uses: actions/setup-go@v5 + with: + go-version-file: super/go.mod + cache-dependency-path: super/go.sum + + # The oldest Node that super-ts supports (see engines in package.json). + - uses: actions/setup-node@v4 + with: + node-version: '22.18' + + - name: Install + working-directory: super-ts + run: npm ci + + - name: Type check + working-directory: super-ts + run: npm run check + + - name: Test with the saved fixtures + working-directory: super-ts + run: npm test + + - name: Build super + run: | + make -C super build + super/dist/super -version + + - name: Make the reference fixtures with super + working-directory: super-ts + run: SUPER="$GITHUB_WORKSPACE/super/dist/super" npm run fixtures + + - name: Test with super's fixtures + working-directory: super-ts + run: npm test + + # Runs by hand, e.g., against an old super, are watched by whoever ran + # them. + - name: Inform Slack users of test failures + uses: tiloio/slack-webhook-action@v1.1.2 + if: failure() && github.ref_name == 'main' && github.event_name != 'workflow_dispatch' + with: + slack_web_hook_url: ${{ secrets.SLACK_WEBHOOK_BRIMLABS_TEST }} + slack_json: | + { + "username": "super-ts", + "text": "super-ts tests failed: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" + } diff --git a/README.md b/README.md index c4f90aa..160d320 100644 --- a/README.md +++ b/README.md @@ -202,9 +202,16 @@ The tests check the decoder against three kinds of fixtures: produced from them. The tests decode the BSUP and require that the formatted text match super's byte for byte. To regenerate the output with your `super` build, run `npm run fixtures` (or `SUPER=/path/to/super npm run fixtures`). + It exits nonzero if `super` can't make all of them. * Hand-built row and column frames (`test/helpers/encode.ts`) for cases that are easier to construct directly. +CI runs the tests on each pull request and merge, nightly, and after each +pull request merged in super, first with the saved fixtures and then with +fixtures made by `super` from its `main` branch (or, when run by hand, from a +branch, tag, or commit you choose). So a change in super that super-ts +doesn't match yet makes CI fail, even on a pull request that didn't cause it. + ## Notes and known gaps * The decoder reads BSUP version 0.31 only, and it rejects other 0.x versions diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..8595c06 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,50 @@ +{ + "name": "@superdb/super-ts", + "version": "0.1.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@superdb/super-ts", + "version": "0.1.0", + "devDependencies": { + "@types/node": "^22.0.0", + "typescript": "^5.8.0" + }, + "engines": { + "node": ">=22.18" + } + }, + "node_modules/@types/node": { + "version": "22.20.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.20.5.tgz", + "integrity": "sha512-U2+DNr+wSjpsTS/wZGYHq7GcwfuSmKiKvoPvK22zwTlRhU91yOniN4qRR5KhIjvif7ysw/dz/hKmfDH0Ris4aA==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~6.21.0" + } + }, + "node_modules/typescript": { + "version": "5.9.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", + "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", + "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", + "dev": true, + "license": "MIT" + } + } +} diff --git a/scripts/gen-fixtures.sh b/scripts/gen-fixtures.sh index c2b39de..550cc24 100644 --- a/scripts/gen-fixtures.sh +++ b/scripts/gen-fixtures.sh @@ -10,6 +10,9 @@ # If test/reference/sup/NAME.args exists, its contents are extra arguments # for super (e.g., `-c fuse` or `-fusion`). # +# If super can't make a fixture, the script goes on to the next one, and at +# the end it exits nonzero, since the tests skip missing fixtures. +# # Usage: npm run fixtures (or SUPER=/path/to/super sh scripts/gen-fixtures.sh) set -u @@ -20,6 +23,7 @@ out=test/reference/out rm -rf "$out" mkdir -p "$out" "$SUPER" -version 2>/dev/null > "$out/VERSION" || true +failed=0 for src in "$in"/*.sup; do name=$(basename "$src" .sup) args="" @@ -27,10 +31,15 @@ for src in "$in"/*.sup; do if ! "$SUPER" $args -f sup -pretty 0 -o "$out/$name.sup" "$src" 2> "$out/$name.err"; then echo "skipping $name: $(head -1 "$out/$name.err")" rm -f "$out/$name.sup" + failed=1 continue fi rm -f "$out/$name.err" - "$SUPER" $args -f bsup -o "$out/$name.col.bsup" "$src" - "$SUPER" $args -f bsup -rows -o "$out/$name.row.bsup" "$src" + "$SUPER" $args -f bsup -o "$out/$name.col.bsup" "$src" || failed=1 + "$SUPER" $args -f bsup -rows -o "$out/$name.row.bsup" "$src" || failed=1 done echo "wrote fixtures to $out" +if [ $failed -ne 0 ]; then + echo "super couldn't make some of the fixtures" >&2 + exit 1 +fi