Skip to content

Code Quality Gate (CI)

squeal code --base <ref> is a standalone quality gate for pull requests and local pre-PR checks. It requires no daemon, no harness, and no agent session.

It analyzes every JS/TS function added or modified since git merge-base <ref> HEAD (including nested functions and test callbacks, excluding moved or body-unchanged functions), runs the tests that load those files with V8 coverage, and evaluates each function against two thresholds read from squeal.config.json at the merge base (so a branch cannot loosen its own check):

  • complexity.threshold (default 20): cyclomatic complexity (CC) limit.
  • crap.threshold (default 30): Change Risk Anti-Patterns (CRAP) score combining CC and branch/line coverage. Equality passes.
Code Verdict Meaning
0 pass Every changed function is within both limits (or skipped via coverage.exclude, or covered by --exceptions).
1 violations At least one changed function exceeds its CC or CRAP limit. Simplify it or increase test coverage.
3 incomplete Evidence is missing or partial, or a selected test failed. Each incomplete function reports its exact gap.
2 error Usage or setup error (bad <ref>, unresolvable Vitest, unreadable --exceptions file).
Terminal window
squeal code --base origin/main

Add --json for the machine-readable squeal-code-gate/1 report, --timeout <seconds> (default 600), --group <name> to include a "manual" check group, or --parts <dir> to reuse coverage parts recorded by squeal ci record.

Each release squeal--v<version> publishes squeal-codex-runtime.json.gz (~5 MB) plus a descriptor squeal-codex-runtime.json with its SHA-256. Read the descriptor once when pinning a version and verify the SHA-256 directly in the workflow:

name: Quality check
on: pull_request
permissions:
contents: read
jobs:
squeal-code:
runs-on: ubuntu-24.04
env:
SQUEAL_VERSION: 0.1.423
SQUEAL_SHA256: 6592435a2d62a3e17f619723f5e1f6098a734320de4192b308a79bf9bd97d651
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 24
- run: pnpm install --frozen-lockfile
- uses: actions/cache@v4
with:
path: ~/.cache/squeal
key: squeal-runtime-${{ env.SQUEAL_VERSION }}-${{ env.SQUEAL_SHA256 }}
- name: Install Squeal
run: |
file="$HOME/.cache/squeal/squeal-codex-runtime-$SQUEAL_VERSION.json.gz"
if [ ! -f "$file" ]; then
mkdir -p "$HOME/.cache/squeal"
curl -fsSL -o "$file" "https://github.com/hearsay-tools/squeal/releases/download/squeal--v$SQUEAL_VERSION/squeal-codex-runtime.json.gz"
fi
node -e '
const fs = require("node:fs"), path = require("node:path");
const [file, sha256, out] = process.argv.slice(1);
const bytes = fs.readFileSync(file);
const actual = require("node:crypto").createHash("sha256").update(bytes).digest("hex");
if (actual !== sha256) {
console.error(`${file} has SHA-256 ${actual}, not ${sha256}: refused`);
process.exit(1);
}
fs.mkdirSync(out);
for (const f of JSON.parse(require("node:zlib").gunzipSync(bytes)).files) {
fs.mkdirSync(path.dirname(path.join(out, f.path)), { recursive: true });
fs.writeFileSync(path.join(out, f.path), Buffer.from(f.data, "base64"), { mode: f.mode });
}
' "$file" "$SQUEAL_SHA256" "$RUNNER_TEMP/squeal"
- name: Check changed functions
run: |
status=0
node "$RUNNER_TEMP/squeal/dist/cli/squeal.mjs" code --base "origin/$GITHUB_BASE_REF" --json > "$RUNNER_TEMP/squeal-code-gate.json" || status=$?
jq -r '"Code gate: \(.verdict)", (.functions[] | select(.state != "pass") | " \(.path):\(.line) \(.qualifiedName) CC \(.complexity) CRAP \(.crap // "none"): \(.state) \(.gap // "")")' "$RUNNER_TEMP/squeal-code-gate.json" || true
exit "$status"
- uses: actions/upload-artifact@v4
if: always()
with:
name: squeal-code-gate
path: ${{ runner.temp }}/squeal-code-gate.json
  • coverage.children: true (at the merge base): measures code executed inside child Node processes and worker threads spawned by tests (such as CLI scripts), as a coverage lower bound.
  • nodeTest[].prepare: declares a build command (argument list, never a shell string) run once before selected node:test files in squeal code --base:
{
"nodeTest": [
{
"name": "package",
"include": ["test/e2e/*.test.mjs"],
"prepare": { "command": ["node", "scripts/build.mjs"], "timeoutSeconds": 600 }
}
]
}
Gap Meaning and fix
no-loader No selected test file imports the file. Add a test or pass --test <file> (or list browser-only files in coverage.exclude at base).
not-finished A test file exceeded --timeout. Speed it up or raise --timeout.
not-prepared nodeTest[].prepare failed, timed out, or is not yet declared on the base branch.
left-out A test file belongs to a check group out of scope (e.g., "manual"). Pass --group <name>.
test-failed A selected test failed; fix the test.
skipped A loader file skipped a test (skipped tests cannot prove a violation).
not-counted File has a parse error or exceeds complexity.maxFileBytes.
no-record File changed mid-run; re-run the check.