From 9f3b4782833fb6e7ce152dda1e178b21fa1494d4 Mon Sep 17 00:00:00 2001 From: irene Date: Sat, 19 Sep 2026 17:13:46 +0900 Subject: [PATCH] fix: correct stage3 branch, remove dead version-gate code for real Prior commits on this branch regressed past stage2, restoring the unconditional CLAUDE.md pointer-write logic stage2 removed. Reset to fork/main (stage2's merged head) and redo stage3 correctly: delete the now-dead fm_version_at_least/claude_supports_native_agents_md functions and their header-comment reference, and drop the now-vestigial with_mock_claude/with_no_claude test helpers (the script no longer reads claude --version at all). --- bin/fm-ensure-agents-md.sh | 39 ++++--------------------------- tests/fm-ensure-agents-md.test.sh | 39 ++++--------------------------- 2 files changed, 9 insertions(+), 69 deletions(-) diff --git a/bin/fm-ensure-agents-md.sh b/bin/fm-ensure-agents-md.sh index 5a1d6820737..968275c8723 100755 --- a/bin/fm-ensure-agents-md.sh +++ b/bin/fm-ensure-agents-md.sh @@ -6,11 +6,10 @@ # when neither file exists, promotes a real CLAUDE.md file when it is the only # file present (unless it is already the canonical pointer), converts a correct # CLAUDE.md -> AGENTS.md symlink into the pointer file, and refuses to clobber -# distinct real files or wrong symlinks. Skips writing a brand-new CLAUDE.md -# pointer (neither file existed, or AGENTS.md existed with no CLAUDE.md) when -# the invoking Claude Code is >= 2.1.277, which reads AGENTS.md natively; see -# claude_supports_native_agents_md. Existing pointers and symlink conversions -# are left alone by this gate for now. +# distinct real files or wrong symlinks. Never writes a brand-new CLAUDE.md +# pointer for a fresh project (neither file existed, or AGENTS.md existed with +# no CLAUDE.md); Claude Code reads AGENTS.md natively fleet-wide. Existing +# pointers and symlink conversions are left alone. # Owns the canonical "## Maintaining this file" self-governance wording for # project AGENTS.md files, injecting it idempotently into created skeletons, # promoted CLAUDE.md files, and existing AGENTS.md files lacking both the exact @@ -132,36 +131,6 @@ is_canonical_claude_pointer() { claude_pointer_content | cmp -s - "$CLAUDE" } -fm_version_at_least() { # - local candidate=${1:-} floor=${2:-} c f - candidate=${candidate%%[-+]*} - case "$candidate" in ''|*[!0-9.]*) return 1 ;; esac - while [ -n "$floor" ]; do - c=${candidate%%.*} - f=${floor%%.*} - [ -n "$c" ] || c=0 - [ "$c" -gt "$f" ] 2>/dev/null && return 0 - [ "$c" -lt "$f" ] 2>/dev/null && return 1 - case "$candidate" in *.*) candidate=${candidate#*.} ;; *) candidate= ;; esac - case "$floor" in *.*) floor=${floor#*.} ;; *) floor= ;; esac - done - return 0 -} - -# Returns 0 if local Claude Code is installed and version is >= 2.1.277. -# Returns 1 if missing, unparseable, command errors, or version < 2.1.277. -claude_supports_native_agents_md() { - command -v claude >/dev/null 2>&1 || return 1 - local ver_str ver - ver_str=$(claude --version 2>/dev/null) || return 1 - if [[ "$ver_str" =~ ([0-9]+\.[0-9]+\.[0-9]+) ]]; then - ver="${BASH_REMATCH[1]}" - else - return 1 - fi - fm_version_at_least "$ver" "2.1.277" -} - # Write the canonical pointer as a regular file. Unlink a symlink first so the # write cannot follow it and destroy AGENTS.md. Never overwrite a distinct real # file; callers classify that as a conflict before invoking this. diff --git a/tests/fm-ensure-agents-md.test.sh b/tests/fm-ensure-agents-md.test.sh index 2efc4da4ede..a80e03053da 100755 --- a/tests/fm-ensure-agents-md.test.sh +++ b/tests/fm-ensure-agents-md.test.sh @@ -26,40 +26,11 @@ write_fixture_claude_pointer() { EOF } -with_mock_claude() { - local output=$1 code=${2:-0} mock_dir - shift 2 - mock_dir=$(mktemp -d "$TMP_ROOT/mock-claude.XXXXXX") - cat > "$mock_dir/claude" </dev/null) - if [ -n "$claude_path" ]; then - claude_dir=$(dirname "$claude_path") - new_path=$(echo "$PATH" | tr ':' '\n' | grep -v -Fx "$claude_dir" | tr '\n' ':') - PATH="$new_path" "$@" - else - "$@" - fi -} - test_created_agents_md_includes_self_governance() { local repo agents repo="$TMP_ROOT/new-project" mkdir -p "$repo" - with_mock_claude "2.0.0" 0 "$ROOT/bin/fm-ensure-agents-md.sh" "$repo" >/dev/null 2>&1 || fail "fm-ensure-agents-md.sh failed for empty project" + "$ROOT/bin/fm-ensure-agents-md.sh" "$repo" >/dev/null 2>&1 || fail "fm-ensure-agents-md.sh failed for empty project" agents="$repo/AGENTS.md" assert_present "$agents" "AGENTS.md was not created" assert_absent "$repo/CLAUDE.md" "fresh setup created a CLAUDE.md file" @@ -188,7 +159,7 @@ test_existing_agents_md_without_claude_gains_section() { mkdir -p "$repo" printf '# Existing agent memory\n\nDeploy with kubectl.\n' > "$repo/AGENTS.md" agents="$repo/AGENTS.md" - out=$(with_mock_claude "2.0.0" 0 "$ROOT/bin/fm-ensure-agents-md.sh" "$repo" 2>&1) \ + out=$("$ROOT/bin/fm-ensure-agents-md.sh" "$repo" 2>&1) \ || fail "fm-ensure-agents-md.sh failed for existing AGENTS.md without CLAUDE.md" assert_contains "$out" "updated:" "injection without CLAUDE.md did not report an update" assert_absent "$repo/CLAUDE.md" "injection created a CLAUDE.md file" @@ -233,7 +204,7 @@ test_marked_project_guidance_stays_unchanged() { symlink) ln -s AGENTS.md "$repo/CLAUDE.md" ;; promotion) mv "$repo/AGENTS.md" "$repo/CLAUDE.md" ;; esac - with_mock_claude "2.0.0" 0 "$ROOT/bin/fm-ensure-agents-md.sh" "$repo" >/dev/null 2>&1 \ + "$ROOT/bin/fm-ensure-agents-md.sh" "$repo" >/dev/null 2>&1 \ || fail "ensure failed for marked project ($route)" cmp -s "$repo/.before" "$repo/AGENTS.md" \ || fail "marked project guidance was modified ($route)" @@ -268,7 +239,7 @@ test_reworded_guidance_requires_first_line_marker() { 'Keep broadly useful knowledge concise; link to sources and rewrite stale entries.' \ 'Preserve these rules for every agent.' | while IFS= read -r line; do printf '%s%s' "$line" "$eol"; done > "$repo/AGENTS.md" - with_mock_claude "2.0.0" 0 "$ROOT/bin/fm-ensure-agents-md.sh" "$repo" >/dev/null 2>&1 \ + "$ROOT/bin/fm-ensure-agents-md.sh" "$repo" >/dev/null 2>&1 \ || fail "ensure failed for unmarked reworded guidance" # AGENTS.md is the helper's generated output contract, not implementation source. assert_grep '## Editing these notes' "$repo/AGENTS.md" "ensure removed project guidance" @@ -276,7 +247,7 @@ test_reworded_guidance_requires_first_line_marker() { [ "$count" -eq 1 ] || fail "guidance without a first-line mark did not gain the canonical section" assert_absent "$repo/CLAUDE.md" "ensure created a CLAUDE.md file" cp "$repo/AGENTS.md" "$repo/.after-first" - with_mock_claude "2.0.0" 0 "$ROOT/bin/fm-ensure-agents-md.sh" "$repo" >/dev/null 2>&1 \ + "$ROOT/bin/fm-ensure-agents-md.sh" "$repo" >/dev/null 2>&1 \ || fail "ensure failed on unmarked project re-run" cmp -s "$repo/.after-first" "$repo/AGENTS.md" \ || fail "unmarked project re-run modified guidance"