diff --git a/docs/remove_session_contract.md b/docs/remove_session_contract.md new file mode 100644 index 0000000..43050ed --- /dev/null +++ b/docs/remove_session_contract.md @@ -0,0 +1,72 @@ +# remove_session Behavior Contract + +## Purpose +Safely and idempotently remove a session from the SQLite session store. + +Integration tests run repeatedly. This function must be reliable and safe to call multiple times. + +--- + +## Function Signature + +remove_session --db --session-id + +--- + +## Required Parameters + +--db (required): Path to SQLite database +--session-id (required): ID of session to remove + +--- + +## Success Definition + +Success means: + +If session exists: +- Session row is deleted +- Exit code 0 + +If session does NOT exist: +- No-op (safe) +- Exit code 0 + +Database remains valid and consistent. + +--- + +## Expected DB Changes + +DELETE FROM internet_sessions WHERE session_id = ? + +No other tables are modified. + +--- + +## Idempotency Guarantee + +Calling: + +remove_session X +remove_session X + +Produces the same final database state as calling it once. + +--- + +## Failure Modes + +Missing DB file -> Exit code 1 +Invalid arguments -> Exit code 2 +SQLite error -> Exit code 3 + +Errors must log a helpful message to stderr. + +--- + +## Logging Expectations + +On success: no output +On no-op: optional info log +On failure: descriptive error message diff --git a/test/helpers/sqlite_fixture.sh b/test/helpers/sqlite_fixture.sh new file mode 100755 index 0000000..c687f44 --- /dev/null +++ b/test/helpers/sqlite_fixture.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +create_test_db() { + DB_PATH="$1" + + sqlite3 "$DB_PATH" <