diff --git a/prompts/REPO_POLICIES.md b/prompts/REPO_POLICIES.md index 1416ad6..9e2f2ab 100644 --- a/prompts/REPO_POLICIES.md +++ b/prompts/REPO_POLICIES.md @@ -1,6 +1,6 @@ --- title: Repository Policies -last_modified: 2026-11-18 +last_modified: 2026-11-19 --- This document covers repository structure, tooling, and workflow standards. Code @@ -163,6 +163,11 @@ style conventions are in separate documents: - `docs/REPO_POLICIES.md` - `docs/CODE_STYLEGUIDE.md` - `script/update-policy` itself, so the script stays current + - `docs/CODE_STYLEGUIDE_GO.md`, when the repo has a `go.mod` + - `docs/GO_HTTP_SERVER_CONVENTIONS.md`, when its Go code imports `net/http` + - `docs/CODE_STYLEGUIDE_JS.md`, when the repo has a `package.json` + - `docs/CODE_STYLEGUIDE_PYTHON.md`, when the repo has a `pyproject.toml` or + `setup.py` # Tests and checks diff --git a/script/update-policy b/script/update-policy index fc78ab2..f5efa23 100755 --- a/script/update-policy +++ b/script/update-policy @@ -1,7 +1,8 @@ #!/bin/sh -# script/update-policy: replace the files below with their current -# versions from the main branch of the prompts repo, and commit them. It -# does not push. Identical in all repos, and it updates itself. +# script/update-policy: replace the files below, and the style guides +# for the repo's languages, with their current versions from the main +# branch of the prompts repo, and commit them. It does not push. +# Identical in all repos, and it updates itself. set -eu ROOT="$(cd "$(dirname "$0")/.." && pwd -P)" @@ -14,6 +15,23 @@ prompts/CODE_STYLEGUIDE.md:docs/CODE_STYLEGUIDE.md script/update-policy:script/update-policy " +# The style guide for each language the repo uses, found by its file at +# the root, and the HTTP server conventions for Go code using net/http. +language_files() { + if [ -e go.mod ]; then + echo prompts/CODE_STYLEGUIDE_GO.md:docs/CODE_STYLEGUIDE_GO.md + if git grep -q '"net/http"' -- '*.go'; then + echo prompts/GO_HTTP_SERVER_CONVENTIONS.md:docs/GO_HTTP_SERVER_CONVENTIONS.md + fi + fi + if [ -e package.json ]; then + echo prompts/CODE_STYLEGUIDE_JS.md:docs/CODE_STYLEGUIDE_JS.md + fi + if [ -e pyproject.toml ] || [ -e setup.py ]; then + echo prompts/CODE_STYLEGUIDE_PYTHON.md:docs/CODE_STYLEGUIDE_PYTHON.md + fi +} + die() { echo "update-policy: $*" >&2 exit 1 @@ -27,6 +45,7 @@ main() { die "REPO_POLICIES.md is at the root;" \ "move it into docs/ with git mv and fix the links to it first" + FILES="$FILES $(language_files)" paths="" for entry in $FILES; do paths="$paths ${entry#*:}" diff --git a/test/update-policy.sh b/test/update-policy.sh index 2117218..d72079e 100755 --- a/test/update-policy.sh +++ b/test/update-policy.sh @@ -51,14 +51,21 @@ new_repo() { git commit -q -m initial } -new_repo "a first run writes and commits exactly the listed files" +# committed_files_are: check that the last commit holds the listed files +# and the ones given, and no others. +committed_files_are() { + [ "$(git show --name-only --format= HEAD | sort)" = \ + "$(echo "$LISTED $*" | tr ' ' '\n' | grep . | sort)" ] || + fail "commit holds the wrong files" +} + +new_repo "a first run, with no language files, commits exactly the listed files" echo stray > stray.txt echo staged >> README.md git add README.md script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero" [ "$(git rev-list --count HEAD)" = 2 ] || fail "made no single commit" -[ "$(git show --name-only --format= HEAD | sort)" = \ - "$(echo "$LISTED" | tr ' ' '\n' | sort)" ] || fail "commit holds other files" +committed_files_are cmp -s docs/REPO_POLICIES.md "$PROMPTS/prompts/REPO_POLICIES.md" || fail "REPO_POLICIES.md differs" [ -x script/update-policy ] || fail "script not executable" @@ -70,6 +77,32 @@ script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero" [ "$(git rev-list --count HEAD)" = 2 ] || fail "made a commit" grep -q "nothing to commit" "$dir/output" || fail "did not say so" +new_repo "a Go repo that uses net/http also gets the Go guide and HTTP conventions" +echo "module example.com/app" > go.mod +printf 'package main\n\nimport "net/http"\n' > main.go +git add go.mod main.go +git commit -q -m go +script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero" +committed_files_are docs/CODE_STYLEGUIDE_GO.md docs/GO_HTTP_SERVER_CONVENTIONS.md +cmp -s docs/CODE_STYLEGUIDE_GO.md "$PROMPTS/prompts/CODE_STYLEGUIDE_GO.md" || + fail "CODE_STYLEGUIDE_GO.md differs" + +new_repo "a Go repo without net/http gets only the Go guide" +echo "module example.com/app" > go.mod +printf 'package main\n\nimport "fmt"\n' > main.go +git add go.mod main.go +git commit -q -m go +script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero" +committed_files_are docs/CODE_STYLEGUIDE_GO.md + +new_repo "a repo with package.json and pyproject.toml gets the JS and Python guides" +echo "{}" > package.json +echo "[project]" > pyproject.toml +git add package.json pyproject.toml +git commit -q -m js-and-python +script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero" +committed_files_are docs/CODE_STYLEGUIDE_JS.md docs/CODE_STYLEGUIDE_PYTHON.md + new_repo "a failed fetch writes nothing" WGET_FAIL=prompts/CODE_STYLEGUIDE.md script/update-policy > "$dir/output" 2>&1 && fail "exited zero"