diff --git a/.cursor/agents/ci-watcher.md b/.cursor/agents/ci-watcher.md new file mode 100644 index 0000000..d58cac5 --- /dev/null +++ b/.cursor/agents/ci-watcher.md @@ -0,0 +1,17 @@ +--- +name: ci-watcher +description: >- + Waits for the current PR's CI and returns only the failing jobs with the + tail of their logs. Use after every push instead of watching runs in the + main thread. +model: composer-2.5[fast=false] +readonly: true +--- + +# ci-watcher + +1. Run `gh pr checks --watch --fail-fast > /dev/null 2>&1 || true`, then + `gh pr checks`. +2. For each failing check, run `gh run view RUN_ID --log-failed | tail -n 80`. +3. Report PASS, or for each failure: the job name, the run URL and those 80 + lines. No analysis, no fixes, never full logs. diff --git a/.cursor/agents/ci-workflow.md b/.cursor/agents/ci-workflow.md new file mode 100644 index 0000000..a8cf4c8 --- /dev/null +++ b/.cursor/agents/ci-workflow.md @@ -0,0 +1,36 @@ +--- +name: ci-workflow +description: >- + Makes GitHub Actions workflow and dependabot.yml edits that the parent has + fully specified (SHA pins, timeouts, permissions, env indirection, + concurrency, branch filters). Not for designing new workflows or release + flows. +model: composer-2.5[fast=false] +--- + +# ci-workflow + +Rules: + +- Pin every action to a full 40-character commit SHA with an exact + `# vX.Y.Z` comment. Look the SHA up, never guess: + `gh api repos/OWNER/REPO/git/ref/tags/vX.Y.Z --jq .object`; if its type + is "tag", dereference with + `gh api repos/OWNER/REPO/git/tags/SHA --jq .object.sha`. + Reuse SHAs already pinned in this repo's other workflows. +- `runs-on: ubuntu-24.04`. `timeout-minutes` on every job. +- Workflow-level `permissions: {}` or `contents: read`; write scopes only on + the job that needs them. +- `persist-credentials: false` on checkout unless the job pushes. +- No `${{ }}` inside `run:`. Pass values through `env:` and quote them + ("$VAR"). For a list: `read -r -a args <<< "$VAR"`, then + `cmd "${args[@]}"`. +- No `pull_request_target` or `workflow_run`. +- Do not change triggers, job names or the job graph unless told to. + +Steps: make the edits, run `actionlint` and +`zizmor --offline .github/workflows`, and fix until both are clean for the +files you touched. + +Report: changes per file, each SHA with its tag, and the actionlint and +zizmor output. diff --git a/.cursor/agents/lint-fixer.md b/.cursor/agents/lint-fixer.md new file mode 100644 index 0000000..a69fde7 --- /dev/null +++ b/.cursor/agents/lint-fixer.md @@ -0,0 +1,23 @@ +--- +name: lint-fixer +description: >- + Fixes findings from scripts/lint.sh (actionlint, zizmor, shellcheck, shfmt, + eslint) that need no design change. Use whenever scripts/lint.sh fails. +model: composer-2.5[fast=false] +--- + +# lint-fixer + +You fix lint findings in this repo and nothing else. + +1. Run `scripts/lint.sh`. +2. Fix each finding at its file:line with the smallest change that follows + AGENTS.md. +3. Never add disable comments, eslint-disable, ignore files or `|| true`. Never change + workflow triggers, permissions or the job graph to silence a finding. If a + finding needs a design change, stop and report it. +4. Rerun `scripts/lint.sh`. Stop when it passes or after 3 rounds. +5. Do not commit or push. + +Report: each fix as file:line and rule, anything left and why, and the last +10 lines of `scripts/lint.sh` output. diff --git a/.cursor/environment.json b/.cursor/environment.json new file mode 100644 index 0000000..c73c3b5 --- /dev/null +++ b/.cursor/environment.json @@ -0,0 +1 @@ +{"install": "bash scripts/install-lint-tools.sh && npm ci"} diff --git a/.cursor/hooks.json b/.cursor/hooks.json new file mode 100644 index 0000000..3184952 --- /dev/null +++ b/.cursor/hooks.json @@ -0,0 +1,6 @@ +{ + "version": 1, + "hooks": { + "stop": [{ "command": ".cursor/hooks/lint-on-stop.sh", "loop_limit": 2 }] + } +} diff --git a/.cursor/hooks/lint-on-stop.sh b/.cursor/hooks/lint-on-stop.sh new file mode 100755 index 0000000..c57c746 --- /dev/null +++ b/.cursor/hooks/lint-on-stop.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +# Cursor stop hook: when scripts/lint.sh fails, send its output back to the +# agent as a follow-up. hooks.json caps the re-prompts with loop_limit. + +set -euo pipefail + +main() { + local output + if output="$(scripts/lint.sh 2>&1 =24" } }, + "node_modules/@eslint/js": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-10.0.1.tgz", + "integrity": "sha512-zeR9k5pd4gxjZ0abRoIaxdc7I3nDktoXZk2qOv9gCNWx3mVwEn32VRhyLaRsDiJjTs0xq/T8mfPtyuXu7GWBcA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^20.19.0 || ^22.13.0 || >=24" + }, + "funding": { + "url": "https://eslint.org/donate" + }, + "peerDependencies": { + "eslint": "^10.0.0" + }, + "peerDependenciesMeta": { + "eslint": { + "optional": true + } + } + }, "node_modules/@eslint/object-schema": { "version": "3.0.5", "resolved": "https://registry.npmjs.org/@eslint/object-schema/-/object-schema-3.0.5.tgz", @@ -2105,6 +2128,19 @@ "node": ">=10.13.0" } }, + "node_modules/globals": { + "version": "16.5.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-16.5.0.tgz", + "integrity": "sha512-c/c15i26VrJ4IRt5Z89DnIzCGDn9EcebibhAOjw5ibqEHsE1wLUgkPn9RDmNcUKyU87GeaL633nyJ+pplFR2ZQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/gopd": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", diff --git a/package.json b/package.json index 6c94ac8..f2d0cf1 100644 --- a/package.json +++ b/package.json @@ -156,8 +156,10 @@ } }, "devDependencies": { + "@eslint/js": "^10.0.1", "axios": "^1.7.0", "eslint": "^10.0.3", + "globals": "^16.5.0", "got": "^16.0.0", "ky": "^2.0.0", "make-fetch-happen": "^16.0.1", diff --git a/scripts/install-lint-tools.sh b/scripts/install-lint-tools.sh new file mode 100755 index 0000000..3cf32cd --- /dev/null +++ b/scripts/install-lint-tools.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +# Install the pinned lint tools into ~/.local/bin (linux x86_64). +# CI and .cursor/environment.json both run this script. + +set -euo pipefail + +readonly BIN_DIR="${HOME}/.local/bin" +readonly GH="https://github.com" + +err() { + echo "$*" >&2 +} + +# Download a URL to a file and check its sha256. +fetch() { + local url="$1" + local sha="$2" + local dest="$3" + curl -fsSL -o "${dest}" "${url}" + echo "${sha} ${dest}" | sha256sum -c --quiet - || { + err "checksum mismatch: ${url}" + exit 1 + } +} + +install_actionlint() { + local version="1.7.12" + local sha="8aca8db96f1b94770f1b0d72b6dddcb1ebb8123cb3712530b08cc387b349a3d8" + fetch \ + "${GH}/rhysd/actionlint/releases/download/v${version}/actionlint_${version}_linux_amd64.tar.gz" \ + "${sha}" "${TMP}/actionlint.tar.gz" + tar -xzf "${TMP}/actionlint.tar.gz" -C "${BIN_DIR}" actionlint +} + +install_shellcheck() { + local version="0.11.0" + local sha="b7af85e41cc99489dcc21d66c6d5f3685138f06d34651e6d34b42ec6d54fe6f6" + fetch \ + "${GH}/koalaman/shellcheck/releases/download/v${version}/shellcheck-v${version}.linux.x86_64.tar.gz" \ + "${sha}" "${TMP}/shellcheck.tar.gz" + tar -xzf "${TMP}/shellcheck.tar.gz" -C "${TMP}" + install -m 755 "${TMP}/shellcheck-v${version}/shellcheck" "${BIN_DIR}" +} + +install_shfmt() { + local version="3.14.1" + local sha="76e77641faa025814b77f153b29796b8e6fa2fca03e0c76a691608b86c7ea7bf" + fetch \ + "${GH}/mvdan/sh/releases/download/v${version}/shfmt_v${version}_linux_amd64" \ + "${sha}" "${TMP}/shfmt" + install -m 755 "${TMP}/shfmt" "${BIN_DIR}/shfmt" +} + +install_zizmor() { + python3 -m pip install --user --quiet --break-system-packages \ + "zizmor==1.32.0" +} + +main() { + TMP="$(mktemp -d)" + trap 'rm -rf "${TMP}"' EXIT + mkdir -p "${BIN_DIR}" + install_actionlint + install_shellcheck + install_shfmt + install_zizmor +} + +main "$@" diff --git a/scripts/lint.sh b/scripts/lint.sh new file mode 100755 index 0000000..2d7bf13 --- /dev/null +++ b/scripts/lint.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +# Run every repo lint check. CI, the stop hook and agents all run this. +# Install the tools first with scripts/install-lint-tools.sh; run npm ci for eslint. + +set -euo pipefail + +failed=() + +err() { + echo "$*" >&2 +} + +# Run a check and remember its name if it fails. +check() { + local name="$1" + shift + "$@" || failed+=("${name}") +} + +main() { + export PATH="${HOME}/.local/bin:${PATH}" + cd "$(git rev-parse --show-toplevel)" + local -a sh_files + mapfile -t sh_files < <(git ls-files -co --exclude-standard '*.sh') + + check actionlint actionlint + # Skip release/auto-merge workflows; zizmor only on workflows this branch changes. + local -a wf=() + local path base="origin/main" + for path in .github/workflows/*; do + if [[ "$path" == .github/workflows/publish.yml ]] || + [[ "$path" == .github/workflows/release-on-merge.yml ]] || + [[ "$path" == .github/workflows/dependabot-auto-merge.yml ]]; then + continue + fi + if git rev-parse --verify --quiet "${base}" >/dev/null && + git cat-file -e "${base}:${path}" 2>/dev/null && + git diff --quiet "${base}" -- "$path"; then + continue + fi + wf+=("$path") + done + if ((${#wf[@]} > 0)); then + check zizmor zizmor --quiet --offline "${wf[@]}" + fi + check shellcheck shellcheck "${sh_files[@]}" + check shfmt shfmt -d -i 2 -ci "${sh_files[@]}" + check eslint npm run lint --silent + + if ((${#failed[@]} > 0)); then + err "lint failed: ${failed[*]}" + exit 1 + fi +} + +main "$@" diff --git a/test/test_proxy_headers.js b/test/test_proxy_headers.js index b12d62e..b6e12ab 100644 --- a/test/test_proxy_headers.js +++ b/test/test_proxy_headers.js @@ -43,11 +43,6 @@ * 1 - One or more tests failed */ -import { fileURLToPath } from 'url'; -import { dirname } from 'path'; - -const __dirname = dirname(fileURLToPath(import.meta.url)); - // ============================================================================= // Configuration // ============================================================================= @@ -547,7 +542,7 @@ function listModules() { } } -async function runTests(testNames, config, verbose) { +async function runTests(testNames, config, _verbose) { console.log('='.repeat(60)); console.log('JavaScript Proxy Headers - Test Harness'); console.log('='.repeat(60));