Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pm-stack/ready-for-agent/apply-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#
# ./apply-config.sh apply config.json next to this script
# DRY_RUN=1 ./apply-config.sh print the mutations it would send
# DRY_RUN accepts only "1" or "true" (case-insensitive) as dry-run;
# "0", "false", "no", empty, and unset apply the config for real.
Comment on lines 16 to +19
#
# Overrides: RFA_CONFIG (config path), RFA_GRAPHQL_URL (endpoint),
# RFA_REPOS_DIR (clone root, default ./repos next to the config).
Expand All @@ -35,7 +37,7 @@ with open(config_path) as f:
config = json.load(f)
url = os.environ.get("GRAPHQL_URL") or config.get("graphqlUrl") or "http://127.0.0.1:6056/graphql"
repos_dir = os.environ["REPOS_DIR"]
dry_run = bool(os.environ.get("DRY_RUN"))
dry_run = os.environ.get("DRY_RUN", "").strip().lower() in {"1", "true"}

def gql(query, variables=None):
body = {"query": query}
Expand Down
32 changes: 32 additions & 0 deletions pm-stack/ready-for-agent/test-apply-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ grep -q "would register" "$WORK/dry-run.out"
}
echo "ok: dry run plans registration and mutates nothing"

DRY_RUN=TrUe ./apply-config.sh >"$WORK/true-dry-run.out"
grep -q "would register" "$WORK/true-dry-run.out"
[[ ! -s "$WORK/mutations.log" ]] || {
echo "FAIL: DRY_RUN=true mutated the harness"
exit 1
}
echo "ok: DRY_RUN=true is accepted case-insensitively"

./apply-config.sh >"$WORK/first.out"
grep -q "addLocalRepository" "$WORK/mutations.log"
grep -q "updateRepositorySettings" "$WORK/mutations.log"
Expand All @@ -126,4 +134,28 @@ grep -q "already match config" "$WORK/second.out"
}
echo "ok: second apply is a no-op (idempotent)"

# A conventional false-y string must not suppress a real config update.
python3 - "$WORK/config.json" <<'PYEOF'
import json, sys

with open(sys.argv[1]) as f:
config = json.load(f)
config["repositories"][0]["defaultModel"] = "opencode-go/dry-run-falsey-test"
with open(sys.argv[1], "w") as f:
json.dump(config, f)
PYEOF

: >"$WORK/mutations.log"
DRY_RUN=0 ./apply-config.sh >"$WORK/falsey.out"
grep -q "updated developing-today/code settings: defaultModel" "$WORK/falsey.out"
grep -Fxq "updateRepositorySettings" "$WORK/mutations.log" || {
echo "FAIL: DRY_RUN=0 did not send the config mutation to the harness"
exit 1
}
if grep -q "DRY-RUN" "$WORK/falsey.out"; then
echo "FAIL: DRY_RUN=0 was treated as dry-run"
exit 1
fi
echo "ok: DRY_RUN=0 applies config mutations"

echo "apply-config.test: PASS"
13 changes: 12 additions & 1 deletion pm-stack/ready-for-agent/test-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ run_case() {

mkdir -p "${home}/.local/bin" "${home}/.config/systemd/user" "${deploy}/systemd" "${stub_bin}" "${state}"
cp "${REPO_ROOT}/pm-stack/ready-for-agent/install.sh" "${deploy}/install.sh"
cat >"${deploy}/apply-config.sh" <<'APPLY_CONFIG'
#!/usr/bin/env bash
set -euo pipefail
printf 'apply-config\n' >>"${STUB_LOG}"
APPLY_CONFIG
cat >"${deploy}/config.json" <<'JSON'
{"repositories":[{"projectPath":"developing-today/code","localDir":"code","cloneUrl":"https://github.com/developing-today/code.git"}]}
JSON
cp "${REPO_ROOT}/pm-stack/ready-for-agent/systemd/ready-for-agent.service" \
"${deploy}/systemd/ready-for-agent.service"
if [[ ${unit_matches} == true ]]; then
Expand All @@ -34,7 +42,7 @@ run_case() {
printf '%s\n' "${initial_version}" >"${home}/.ready-agent-version"
cat >"${home}/.local/bin/ready-for-agent" <<'LAUNCHER'
#!/usr/bin/env bash
printf 'ready-for-agent %s\n' "$(cat "${HOME}/.ready-agent-version")"
printf 'ready-for-agent %s\n' "$(cat "${HOME}/.ready-agent-version")"
LAUNCHER
chmod +x "${home}/.local/bin/ready-for-agent"
fi
Expand Down Expand Up @@ -126,6 +134,7 @@ CURL
exit 0
SLEEP
chmod +x "${stub_bin}/systemctl" "${stub_bin}/npm" "${stub_bin}/git" "${stub_bin}/curl" "${stub_bin}/sleep"
chmod +x "${deploy}/apply-config.sh"

if [[ ${name} == clone-fail-retry ]]; then
# #4839: npm upgrades the package, then the clone step fails; the
Expand All @@ -146,6 +155,7 @@ SLEEP
fail "${name}: retry exited unsuccessfully"
fi
grep -Fxq restart "${log}" || fail "${name}: retry did not restart"
grep -Fxq apply-config "${log}" || fail "${name}: config helper was not invoked after retry"
printf '%s\n' "${retry_output}" | grep -Fq 'after restart' || fail "${name}: retry missing after-restart report"
printf '%s\n' "${retry_output}" | grep -Fq 'already running' && fail "${name}: retry falsely reported no-op"
[[ ! -f ${marker} ]] || fail "${name}: marker not cleared after verified restart"
Expand All @@ -160,6 +170,7 @@ SLEEP
fi

printf '%s\n' "${output}" | grep -Fq 'ready-for-agent@1.1.0'
grep -Fxq apply-config "${log}" || fail "${name}: config helper was not invoked"
case "${name}" in
package-change-active)
grep -Fxq restart "${log}" || fail "${name}: expected restart"
Expand Down
Loading