Rename script/fetch-policy to script/commit-current-upstream-policy-docs
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
sneak, on the PR: the script does more than fetch, and short names are not wanted. The make target, the test names, the variables and the messages take the new name. Behaviour is unchanged. Model: opus-5-5
This commit is contained in:
1 parent
917fe4bc1d
commit
ed60414378
9 files changed
+145
-129
No files matched your search
+66
-59
@@ -1,13 +1,13 @@
|
||||
#!/bin/sh
|
||||
# test/update-policy.sh: test script/fetch-policy and
|
||||
# script/update-policy on throwaway repos. Each scenario gets one temp
|
||||
# directory holding a repo, its local bare origin, a local git
|
||||
# test/update-policy.sh: test script/commit-current-upstream-policy-docs
|
||||
# and script/update-policy on throwaway repos. Each scenario gets one
|
||||
# temp directory holding a repo, its local bare 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
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd -P)/script"
|
||||
FETCH_POLICY="$SCRIPT_DIR/fetch-policy"
|
||||
COMMIT_CURRENT_UPSTREAM_POLICY_DOCS="$SCRIPT_DIR/commit-current-upstream-policy-docs"
|
||||
UPDATE_POLICY="$SCRIPT_DIR/update-policy"
|
||||
|
||||
dir=""
|
||||
@@ -60,8 +60,8 @@ case "$url" in
|
||||
"$HASH" 0000000000000000000000000000000000000000 > "$output"
|
||||
fi
|
||||
;;
|
||||
"$site/raw/branch/main/script/fetch-policy")
|
||||
serve_file script/fetch-policy
|
||||
"$site/raw/branch/main/script/commit-current-upstream-policy-docs")
|
||||
serve_file script/commit-current-upstream-policy-docs
|
||||
;;
|
||||
"$site/compare/$first...$HASH.patch")
|
||||
git -C "$canonical" format-patch --stdout --root "$HASH" > "$output"
|
||||
@@ -79,7 +79,8 @@ EOF
|
||||
|
||||
write_canonical_files() {
|
||||
mkdir -p "$dir/canonical/prompts" "$dir/canonical/script"
|
||||
cp "$FETCH_POLICY" "$UPDATE_POLICY" "$dir/canonical/script/"
|
||||
cp "$COMMIT_CURRENT_UPSTREAM_POLICY_DOCS" "$UPDATE_POLICY" \
|
||||
"$dir/canonical/script/"
|
||||
cat > "$dir/canonical/.gitignore" << 'EOF'
|
||||
*.log
|
||||
*.tmp
|
||||
@@ -208,7 +209,8 @@ start_scenario() {
|
||||
git -C "$dir/repo" remote add origin "$dir/origin.git"
|
||||
|
||||
mkdir "$dir/repo/script"
|
||||
cp "$FETCH_POLICY" "$UPDATE_POLICY" "$dir/repo/script/"
|
||||
cp "$COMMIT_CURRENT_UPSTREAM_POLICY_DOCS" "$UPDATE_POLICY" \
|
||||
"$dir/repo/script/"
|
||||
printf '#!/bin/sh\necho example\n' > "$dir/repo/script/projectname"
|
||||
chmod +x "$dir/repo/script/projectname"
|
||||
mkdir -p "$dir/repo/cmd/app"
|
||||
@@ -261,12 +263,13 @@ run_update_policy() {
|
||||
script/update-policy "$@") > "$dir/output" 2>&1 || status=$?
|
||||
}
|
||||
|
||||
# run_fetch_policy <arguments>: run the script in this source tree,
|
||||
# from outside the repo it updates.
|
||||
run_fetch_policy() {
|
||||
# run_commit_current_upstream_policy_docs <arguments>: run the script in
|
||||
# this source tree, from outside the repo it updates.
|
||||
run_commit_current_upstream_policy_docs() {
|
||||
status=0
|
||||
(cd "$dir" && PATH="$dir/bin:$PATH" TMPDIR="$dir/tmp" \
|
||||
"$FETCH_POLICY" "$@") > "$dir/output" 2>&1 || status=$?
|
||||
"$COMMIT_CURRENT_UPSTREAM_POLICY_DOCS" "$@") > "$dir/output" 2>&1 ||
|
||||
status=$?
|
||||
}
|
||||
|
||||
head_of_repo() {
|
||||
@@ -478,27 +481,27 @@ test_nothing_changed() {
|
||||
expect_nothing_written
|
||||
}
|
||||
|
||||
test_target_lacking_fetch_policy_gets_both_scripts() {
|
||||
start_scenario "a repo lacking script/fetch-policy gets it, and the current script/update-policy, in the commit"
|
||||
rm "$dir/repo/script/fetch-policy"
|
||||
test_target_lacking_commit_current_upstream_policy_docs_gets_both_scripts() {
|
||||
start_scenario "a repo lacking script/commit-current-upstream-policy-docs gets it, and the current script/update-policy, in the commit"
|
||||
rm "$dir/repo/script/commit-current-upstream-policy-docs"
|
||||
echo "# An older version." >> "$dir/repo/script/update-policy"
|
||||
commit_and_push_fixture .prettierrc
|
||||
run_update_policy
|
||||
expect_success
|
||||
expect_same_as_canonical script/fetch-policy
|
||||
expect_same_as_canonical script/commit-current-upstream-policy-docs
|
||||
expect_same_as_canonical script/update-policy
|
||||
expect_committed_executable script/fetch-policy
|
||||
expect_committed_executable script/commit-current-upstream-policy-docs
|
||||
expect_committed_executable script/update-policy
|
||||
expect_new_commit_not_pushed
|
||||
[ "$(files_in_commit)" = ".prettierrc script/fetch-policy script/update-policy " ] ||
|
||||
[ "$(files_in_commit)" = ".prettierrc script/commit-current-upstream-policy-docs script/update-policy " ] ||
|
||||
fail "the commit holds other files: $(files_in_commit)"
|
||||
}
|
||||
|
||||
# The shell reads a script in blocks, so the padding makes it read the
|
||||
# last line only after main has returned. It finds that line only if
|
||||
# script/fetch-policy left the old file in place under a new name. The
|
||||
# old file is an earlier canonical version, so script/fetch-policy
|
||||
# replaces it.
|
||||
# script/commit-current-upstream-policy-docs left the old file in place
|
||||
# under a new name. The old file is an earlier canonical version, so
|
||||
# script/commit-current-upstream-policy-docs replaces it.
|
||||
test_update_policy_replaces_itself() {
|
||||
start_scenario "script/update-policy replaces its own file and still exits 0"
|
||||
{
|
||||
@@ -525,44 +528,46 @@ test_update_policy_replaces_itself() {
|
||||
expect_new_commit_not_pushed
|
||||
}
|
||||
|
||||
test_fetch_policy_with_path_commits_nothing() {
|
||||
start_scenario "script/fetch-policy with a path writes into that clone and commits nothing"
|
||||
rm "$dir/repo/script/fetch-policy" "$dir/repo/script/update-policy"
|
||||
test_commit_current_upstream_policy_docs_with_path_commits_nothing() {
|
||||
start_scenario "script/commit-current-upstream-policy-docs with a path writes into that clone and commits nothing"
|
||||
rm "$dir/repo/script/commit-current-upstream-policy-docs" \
|
||||
"$dir/repo/script/update-policy"
|
||||
commit_and_push_fixture .prettierrc
|
||||
run_fetch_policy "$dir/repo"
|
||||
run_commit_current_upstream_policy_docs "$dir/repo"
|
||||
expect_success
|
||||
expect_file .prettierrc << 'EOF'
|
||||
{ "tabWidth": 4 }
|
||||
EOF
|
||||
expect_same_as_canonical script/fetch-policy
|
||||
expect_same_as_canonical script/commit-current-upstream-policy-docs
|
||||
expect_same_as_canonical script/update-policy
|
||||
expect_executable script/fetch-policy
|
||||
expect_executable script/commit-current-upstream-policy-docs
|
||||
expect_executable script/update-policy
|
||||
expect_no_commit
|
||||
[ "$(head -n 1 "$dir/output")" = "$HASH" ] ||
|
||||
fail "the first line of output is not the hash"
|
||||
expect_output "script/fetch-policy"
|
||||
expect_output "script/commit-current-upstream-policy-docs"
|
||||
[ -z "$(ls -A "$dir/tmp")" ] || fail "a temporary directory is left"
|
||||
}
|
||||
|
||||
test_fetch_policy_without_script_directory() {
|
||||
start_scenario "script/fetch-policy with a path writes both scripts into a clone with no script directory"
|
||||
test_commit_current_upstream_policy_docs_without_script_directory() {
|
||||
start_scenario "script/commit-current-upstream-policy-docs with a path writes both scripts into a clone with no script directory"
|
||||
commit_and_push_fixture .prettierrc
|
||||
remove_from_fixture script
|
||||
run_fetch_policy "$dir/repo"
|
||||
run_commit_current_upstream_policy_docs "$dir/repo"
|
||||
expect_success
|
||||
expect_same_as_canonical script/fetch-policy
|
||||
expect_same_as_canonical script/commit-current-upstream-policy-docs
|
||||
expect_same_as_canonical script/update-policy
|
||||
expect_executable script/fetch-policy
|
||||
expect_executable script/commit-current-upstream-policy-docs
|
||||
expect_executable script/update-policy
|
||||
expect_no_commit
|
||||
}
|
||||
|
||||
test_fetch_policy_without_argument_updates_own_repo() {
|
||||
start_scenario "script/fetch-policy with no argument updates the repo it sits in"
|
||||
test_commit_current_upstream_policy_docs_without_argument_updates_own_repo() {
|
||||
start_scenario "script/commit-current-upstream-policy-docs with no argument updates the repo it sits in"
|
||||
commit_and_push_fixture .prettierrc
|
||||
status=0
|
||||
(cd "$dir" && PATH="$dir/bin:$PATH" repo/script/fetch-policy) \
|
||||
(cd "$dir" && PATH="$dir/bin:$PATH" \
|
||||
repo/script/commit-current-upstream-policy-docs) \
|
||||
> "$dir/output" 2>&1 || status=$?
|
||||
expect_success
|
||||
expect_file .prettierrc << 'EOF'
|
||||
@@ -571,19 +576,19 @@ EOF
|
||||
expect_no_commit
|
||||
}
|
||||
|
||||
test_fetch_policy_bad_target() {
|
||||
start_scenario "script/fetch-policy refuses a path that is not the top of a clone"
|
||||
test_commit_current_upstream_policy_docs_bad_target() {
|
||||
start_scenario "script/commit-current-upstream-policy-docs refuses a path that is not the top of a clone"
|
||||
commit_and_push_fixture .prettierrc
|
||||
run_fetch_policy "$dir/repo/script"
|
||||
run_commit_current_upstream_policy_docs "$dir/repo/script"
|
||||
expect_failure
|
||||
expect_output "not the top of a git clone"
|
||||
run_fetch_policy "$dir/bin"
|
||||
run_commit_current_upstream_policy_docs "$dir/bin"
|
||||
expect_failure
|
||||
expect_output "not the top of a git clone"
|
||||
run_fetch_policy "$dir/no-such-directory"
|
||||
run_commit_current_upstream_policy_docs "$dir/no-such-directory"
|
||||
expect_failure
|
||||
expect_output "no such directory"
|
||||
run_fetch_policy "$dir/repo" extra
|
||||
run_commit_current_upstream_policy_docs "$dir/repo" extra
|
||||
expect_failure
|
||||
expect_output "usage:"
|
||||
expect_nothing_written
|
||||
@@ -592,7 +597,7 @@ test_fetch_policy_bad_target() {
|
||||
test_failed_fetch_stops() {
|
||||
for url in \
|
||||
"/api/v1/repos/sneak/prompts/branches/main" \
|
||||
"/raw/branch/main/script/fetch-policy" \
|
||||
"/raw/branch/main/script/commit-current-upstream-policy-docs" \
|
||||
"/compare/" \
|
||||
"/raw/commit/"; do
|
||||
start_scenario "a failed fetch of $url stops with nothing written"
|
||||
@@ -662,14 +667,14 @@ EOF
|
||||
}
|
||||
|
||||
test_untracked_script_stops() {
|
||||
start_scenario "an untracked script/fetch-policy is not overwritten"
|
||||
rm "$dir/repo/script/fetch-policy"
|
||||
start_scenario "an untracked script/commit-current-upstream-policy-docs is not overwritten"
|
||||
rm "$dir/repo/script/commit-current-upstream-policy-docs"
|
||||
commit_and_push_fixture .prettierrc
|
||||
echo "our own script" > "$dir/repo/script/fetch-policy"
|
||||
run_fetch_policy "$dir/repo"
|
||||
echo "our own script" > "$dir/repo/script/commit-current-upstream-policy-docs"
|
||||
run_commit_current_upstream_policy_docs "$dir/repo"
|
||||
expect_failure
|
||||
expect_output "script/fetch-policy has uncommitted changes"
|
||||
expect_file script/fetch-policy << 'EOF'
|
||||
expect_output "script/commit-current-upstream-policy-docs has uncommitted changes"
|
||||
expect_file script/commit-current-upstream-policy-docs << 'EOF'
|
||||
our own script
|
||||
EOF
|
||||
expect_no_commit
|
||||
@@ -681,7 +686,7 @@ test_ignored_file_stops() {
|
||||
remove_from_fixture docs/API_POLICIES.md
|
||||
echo "docs/API_POLICIES.md" >> "$dir/repo/.git/info/exclude"
|
||||
echo "our own notes" > "$dir/repo/docs/API_POLICIES.md"
|
||||
run_fetch_policy "$dir/repo"
|
||||
run_commit_current_upstream_policy_docs "$dir/repo"
|
||||
expect_failure
|
||||
expect_output "docs/API_POLICIES.md is ignored by git"
|
||||
expect_file docs/API_POLICIES.md << 'EOF'
|
||||
@@ -691,7 +696,8 @@ EOF
|
||||
}
|
||||
|
||||
test_own_script_stops() {
|
||||
for script in script/fetch-policy script/update-policy; do
|
||||
for script in script/commit-current-upstream-policy-docs \
|
||||
script/update-policy; do
|
||||
start_scenario "a tracked $script with a line the canonical file has never held stops"
|
||||
echo "echo our own script" >> "$dir/repo/$script"
|
||||
commit_and_push_fixture .prettierrc
|
||||
@@ -849,9 +855,10 @@ test_former_canonical_gitignore_line_replaced() {
|
||||
}
|
||||
|
||||
test_former_canonical_script_line_replaced() {
|
||||
start_scenario "a script/fetch-policy line an earlier canonical commit held is replaced"
|
||||
expect_former_canonical_line_replaced script/fetch-policy "echo an older version"
|
||||
expect_same_as_canonical script/fetch-policy
|
||||
start_scenario "a script/commit-current-upstream-policy-docs line an earlier canonical commit held is replaced"
|
||||
expect_former_canonical_line_replaced \
|
||||
script/commit-current-upstream-policy-docs "echo an older version"
|
||||
expect_same_as_canonical script/commit-current-upstream-policy-docs
|
||||
}
|
||||
|
||||
# A line another file's history removed does not count as held by this
|
||||
@@ -879,12 +886,12 @@ main() {
|
||||
test_language_files_need_a_source_file
|
||||
test_javascript_source_brings_its_styleguide
|
||||
test_nothing_changed
|
||||
test_target_lacking_fetch_policy_gets_both_scripts
|
||||
test_target_lacking_commit_current_upstream_policy_docs_gets_both_scripts
|
||||
test_update_policy_replaces_itself
|
||||
test_fetch_policy_with_path_commits_nothing
|
||||
test_fetch_policy_without_script_directory
|
||||
test_fetch_policy_without_argument_updates_own_repo
|
||||
test_fetch_policy_bad_target
|
||||
test_commit_current_upstream_policy_docs_with_path_commits_nothing
|
||||
test_commit_current_upstream_policy_docs_without_script_directory
|
||||
test_commit_current_upstream_policy_docs_without_argument_updates_own_repo
|
||||
test_commit_current_upstream_policy_docs_bad_target
|
||||
test_failed_fetch_stops
|
||||
test_one_missing_file_stops_all
|
||||
test_branch_response_without_hash_stops
|
||||
|
||||
Reference in new issue
Block a user