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
7 changes: 6 additions & 1 deletion scripts/lib/storage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,12 @@ agmsg_runtime_lock_acquire() {
resource="$1"; owner_pid="$2"; expected_owner="${3:-}"
case "$owner_pid:$expected_owner" in *[!0-9:]*) return 1 ;; esac
db="$(_agmsg_runtime_db_path)"
_agmsg_runtime_db_exists "$db" || return 1
if ! _agmsg_runtime_db_exists "$db"; then
# Leave a diagnostic (#424). The status stays 1. Keep the words busy and
# locked out of this line: actas-lock.sh retries stderr that matches them.
printf 'agmsg_runtime_lock_acquire: runtime db missing: %s\n' "$db" >&2
return 1
fi
resource_sql="$(_agmsg_runtime_lock_resource_sql "$resource")"
sql=".bail on
BEGIN IMMEDIATE;
Expand Down
30 changes: 30 additions & 0 deletions tests/test_storage.bats
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,36 @@ SH
[ ! -e "$AGMSG_STORAGE_PATH/messages.db" ]
}

@test "storage: runtime lock acquire on an absent store says why on stderr and keeps status 1" {
# #424: the refusal used to be silent.
export AGMSG_STORAGE_PATH="$BATS_TEST_TMPDIR/silent-lock-store"
source "$SCRIPTS/lib/storage.sh"
local err="$BATS_TEST_TMPDIR/lock-acquire.stderr" out rc=0 db
db="$(_agmsg_runtime_db_path)"

out="$(agmsg_runtime_lock_acquire codex-dispatcher:test 111 2>"$err")" || rc=$?

[ "$rc" -eq 1 ]
[ -z "$out" ]
[ "$(wc -l < "$err" | tr -d ' ')" -eq 1 ]
[ "$(cat "$err")" = "agmsg_runtime_lock_acquire: runtime db missing: $db" ]
[ ! -e "$db" ]
}

@test "storage: runtime lock acquire on a present store writes nothing to stderr" {
# Negative control for #424: the diagnostic belongs to the absent-store path only.
export AGMSG_STORAGE_PATH="$BATS_TEST_TMPDIR/present-lock-store"
source "$SCRIPTS/lib/storage.sh"
agmsg_storage_ensure_initialized
local err="$BATS_TEST_TMPDIR/lock-acquire-present.stderr" out rc=0

out="$(agmsg_runtime_lock_acquire codex-dispatcher:test 111 2>"$err")" || rc=$?

[ "$rc" -eq 0 ]
[ "$out" = 111 ]
[ ! -s "$err" ]
}

@test "storage: every runtime lock entrypoint refuses an absent store" {
export AGMSG_STORAGE_PATH="$BATS_TEST_TMPDIR/absent-lock-store"
source "$SCRIPTS/lib/storage.sh"
Expand Down
Loading