A line an earlier canonical commit held counted as the repo's own, so the script stopped on the outdated lines a re-vendor exists to replace. It now clones prompts and also treats every line removed from the file in its history as canonical. The .golangci.yml stop message no longer tells anyone to delete a line. The tests use a local git repository in place of prompts and gain one scenario each for .golangci.yml and .gitignore. Model: opus-5-5
This commit is contained in:
1 parent
97da381318
commit
44e8a601aa
3 files changed
+87
-31
No files matched your search
+61
-13
@@ -1,8 +1,9 @@
|
||||
#!/bin/sh
|
||||
# test/update-policy.sh: test script/update-policy on throwaway repos.
|
||||
# Each scenario gets one temp directory holding a repo, its local bare
|
||||
# origin, the canonical files and a stub curl that serves them, so
|
||||
# nothing touches the network.
|
||||
# origin, a local git repository of the canonical files in place of
|
||||
# prompts, and a stub curl that serves them, so nothing touches the
|
||||
# network.
|
||||
set -eu
|
||||
|
||||
UPDATE_POLICY="$(cd "$(dirname "$0")/.." && pwd -P)/script/update-policy"
|
||||
@@ -82,6 +83,15 @@ EOF
|
||||
echo "new api policy" > "$dir/canonical/prompts/API_POLICIES.md"
|
||||
}
|
||||
|
||||
# commit_canonical: commit the canonical files as they stand. The stub
|
||||
# curl serves only the newest commit; every other commit gets a 404.
|
||||
commit_canonical() {
|
||||
git -C "$dir/canonical" add .gitignore .dockerignore .editorconfig \
|
||||
.golangci.yml .prettierrc prompts
|
||||
git -C "$dir/canonical" commit -q -m "Canonical"
|
||||
HASH="$(git -C "$dir/canonical" rev-parse HEAD)"
|
||||
}
|
||||
|
||||
# write_outdated_files: this repo's files, one canonical version behind,
|
||||
# with the repo's own entries in the places the script keeps them. The
|
||||
# comment above the closing comment in .gitignore is replaced, not kept.
|
||||
@@ -131,18 +141,26 @@ EOF
|
||||
# the outdated files, not yet committed, and an empty origin.
|
||||
start_scenario() {
|
||||
scenario="$1"
|
||||
# The one commit the stub curl serves; every other commit gets a 404.
|
||||
export HASH=1111111111111111111111111111111111111111
|
||||
rm -rf "$dir"
|
||||
dir="$(mktemp -d)"
|
||||
: > "$dir/output"
|
||||
write_stub_curl
|
||||
write_canonical_files
|
||||
|
||||
# git clone reads no repo's own config, so the setting that points
|
||||
# git at the local canonical repository has to be in this file.
|
||||
export GIT_CONFIG_GLOBAL="$dir/gitconfig"
|
||||
git config --global user.name "Test"
|
||||
git config --global user.email "test@example.com"
|
||||
git config --global "url.$dir/canonical.insteadOf" \
|
||||
"https://git.eeqj.de/sneak/prompts.git"
|
||||
|
||||
git init -q -b main "$dir/canonical"
|
||||
export HASH
|
||||
commit_canonical
|
||||
|
||||
git init -q --bare -b main "$dir/origin.git"
|
||||
git init -q -b main "$dir/repo"
|
||||
git -C "$dir/repo" config user.name "Test"
|
||||
git -C "$dir/repo" config user.email "test@example.com"
|
||||
git -C "$dir/repo" remote add origin "$dir/origin.git"
|
||||
|
||||
mkdir "$dir/repo/script"
|
||||
@@ -476,16 +494,11 @@ test_short_commit_hash_refused() {
|
||||
expect_nothing_written
|
||||
}
|
||||
|
||||
# git is pointed at a local repository in place of the prompts remote,
|
||||
# and the stub curl serves the head of that repository's main.
|
||||
# git asks the local canonical repository for the head of main, and the
|
||||
# stub curl serves only that commit.
|
||||
test_no_hash_uses_head_of_main() {
|
||||
start_scenario "with no hash the script uses the head of main"
|
||||
commit_and_push_fixture .prettierrc
|
||||
git init -q --bare -b main "$dir/prompts.git"
|
||||
git -C "$dir/repo" push -q "$dir/prompts.git" HEAD:refs/heads/main
|
||||
git -C "$dir/repo" config "url.$dir/prompts.git.insteadOf" \
|
||||
"https://git.eeqj.de/sneak/prompts.git"
|
||||
HASH="$before"
|
||||
run_update_policy
|
||||
expect_success
|
||||
expect_file .prettierrc << 'EOF'
|
||||
@@ -497,6 +510,39 @@ EOF
|
||||
fail "the commit was not pushed"
|
||||
}
|
||||
|
||||
# expect_former_canonical_line_replaced <file> <line>: an earlier
|
||||
# canonical commit held the line and the newest does not. This repo's
|
||||
# file still has it, and the script replaces it and pushes.
|
||||
expect_former_canonical_line_replaced() {
|
||||
cp "$dir/canonical/$1" "$dir/newest"
|
||||
{ echo "$2"; cat "$dir/newest"; } > "$dir/canonical/$1"
|
||||
commit_canonical
|
||||
cp "$dir/newest" "$dir/canonical/$1"
|
||||
commit_canonical
|
||||
{ echo "$2"; cat "$dir/repo/$1"; } > "$dir/merged"
|
||||
mv "$dir/merged" "$dir/repo/$1"
|
||||
commit_and_push_fixture "$1" .prettierrc
|
||||
|
||||
run_update_policy "$HASH"
|
||||
expect_success
|
||||
if grep -q -F -x -e "$2" "$dir/repo/$1"; then
|
||||
fail "$1 still has: $2"
|
||||
fi
|
||||
[ "$(head_of_repo)" != "$before" ] || fail "no commit was made"
|
||||
[ "$(head_of_origin)" = "$(head_of_repo)" ] ||
|
||||
fail "the commit was not pushed"
|
||||
}
|
||||
|
||||
test_former_canonical_golangci_line_replaced() {
|
||||
start_scenario "a .golangci.yml line an earlier canonical commit held is replaced"
|
||||
expect_former_canonical_line_replaced .golangci.yml "version: 1"
|
||||
}
|
||||
|
||||
test_former_canonical_gitignore_line_replaced() {
|
||||
start_scenario "a .gitignore line above the closing comment that an earlier canonical commit held is replaced"
|
||||
expect_former_canonical_line_replaced .gitignore "*.old"
|
||||
}
|
||||
|
||||
main() {
|
||||
test_own_entries_kept
|
||||
test_files_not_carried_are_skipped
|
||||
@@ -513,6 +559,8 @@ main() {
|
||||
test_staged_file_stays_out_of_commit
|
||||
test_short_commit_hash_refused
|
||||
test_no_hash_uses_head_of_main
|
||||
test_former_canonical_golangci_line_replaced
|
||||
test_former_canonical_gitignore_line_replaced
|
||||
echo "update-policy tests passed"
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user