Add chat-memory module: MessageWindowChatMemory, JDBC and Redis repositories, per-user conversation IDs

Real PostgreSQL 16 and Redis Stack 7.4; 24 tests write output/01-24. Covers the 20-message
default window with no property, the 36-character conversation_id, tool messages dropped by
JdbcChatMemoryRepository, concurrent add() on one conversation, a 1.x table under the 2.0
repository, the Redis repository silently backing off for a custom ChatMemory, and the
removal of PromptChatMemoryAdvisor.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ja4jkzrbQ4LQZBNrb5mkZE
This commit is contained in:
Claude
2026-09-24 15:56:47 +00:00
parent c1e36c6c09
commit 823f6fac5b
65 changed files with 2548 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# Compiles src/broken/PromptAdvisorFrom1x.java against the 2.0.1 classpath, then against the
# 1.1.8 spring-ai-client-chat + spring-ai-model jars, and writes both compiler results to
# output/23-prompt-advisor-removed.txt. Needs the module built once online (mvn -q test-compile).
set -euo pipefail
cd "$(dirname "$0")/.."
OUT=output/23-prompt-advisor-removed.txt
mvn -q -B dependency:build-classpath -Dmdep.outputFile=target/classpath.txt >/dev/null 2>&1
CP2="$(cat target/classpath.txt)"
WORK="$(mktemp -d)"
for a in spring-ai-client-chat spring-ai-model; do
# Maven Central occasionally answers 429/5xx to a burst of requests: retry with a pause.
for attempt in 1 2 3 4 5; do
curl -sfL -o "$WORK/$a-1.1.8.jar" "https://repo1.maven.org/maven2/org/springframework/ai/$a/1.1.8/$a-1.1.8.jar" && break
sleep $((attempt * 3))
done
done
CP1="$WORK/spring-ai-client-chat-1.1.8.jar:$WORK/spring-ai-model-1.1.8.jar:$CP2"
# put the 1.1.8 jars FIRST so their classes win over the 2.0.1 ones on the classpath
{
echo "# PromptChatMemoryAdvisor: Spring AI 1.1.8 vs 2.0.1"
echo
echo "\$ javac PromptAdvisorFrom1x.java # classpath: spring-ai-client-chat 2.0.1"
javac -proc:none -d "$WORK/out2" -cp "$CP2" src/broken/PromptAdvisorFrom1x.java 2>&1 | grep -v JAVA_TOOL | sed "s#src/broken/##" || true
echo
echo "\$ javac PromptAdvisorFrom1x.java # classpath: spring-ai-client-chat 1.1.8 first"
mkdir -p "$WORK/out1"
if javac -proc:none -d "$WORK/out1" -cp "$CP1" src/broken/PromptAdvisorFrom1x.java 2>&1 | grep -v JAVA_TOOL | sed "s#src/broken/##"; then :; fi
ls "$WORK/out1" | sed 's/^/compiled: /'
} > "$OUT"
cat "$OUT"
+13
View File
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
# Regenerates every file under output/. The test suite writes 01-22 and 24 itself through the
# Transcript helper; 23 comes from scripts/capture-1x-compile.sh.
#
# Backing services: scripts/services-up.sh starts PostgreSQL 16, Redis Stack (docker) and a plain
# Redis. Tests that need one that is not listening are SKIPPED with a message, not failed, so the
# in-memory tests (01-07, 20-22, 24) still run without any of them.
set -euo pipefail
cd "$(dirname "$0")/.."
rm -rf target
mvn -q -B test
scripts/capture-1x-compile.sh >/dev/null
ls output
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# Starts the three backing services the tests need, with no docker-compose:
# * PostgreSQL 16 on 127.0.0.1:5440 (apt: postgresql-16; runs as the postgres user)
# * Redis Stack on 127.0.0.1:6390 (docker: redis/redis-stack-server -- Redis + RediSearch + RedisJSON)
# * plain Redis on 127.0.0.1:6391 (apt: redis-server, NO modules; only used to capture a failure)
# If you already have these, skip this script and set CM_PG_URL / CM_REDIS_STACK_PORT / CM_REDIS_PLAIN_PORT.
set -euo pipefail
PGDATA="${PGDATA:-/tmp/pgchat/data}"; PGPORT="${PGPORT:-5440}"; SOCKDIR="$(dirname "$PGDATA")"
BIN="$(ls -d /usr/lib/postgresql/*/bin 2>/dev/null | sort -V | tail -1)"
as_pg() { if [ "$(id -u)" = 0 ]; then su postgres -c "$*"; else bash -c "$*"; fi; }
mkdir -p "$SOCKDIR"; [ "$(id -u)" = 0 ] && chown postgres "$SOCKDIR"
[ -d "$PGDATA/base" ] || as_pg "'$BIN/initdb' -D '$PGDATA' -A trust >'$SOCKDIR/initdb.log' 2>&1"
as_pg "'$BIN/pg_ctl' -D '$PGDATA' status" >/dev/null 2>&1 || \
as_pg "'$BIN/pg_ctl' -D '$PGDATA' -o \"-p $PGPORT -c listen_addresses=127.0.0.1 -c unix_socket_directories=$SOCKDIR\" -l '$SOCKDIR/pg.log' -w start"
PSQL="$BIN/psql -h $SOCKDIR -p $PGPORT -U postgres -v ON_ERROR_STOP=1 -q"
as_pg "$PSQL -d postgres -tc \"select 1 from pg_roles where rolname='chat'\"" | grep -q 1 || as_pg "$PSQL -d postgres -c \"create role chat login superuser password 'chat'\""
as_pg "$PSQL -d postgres -tc \"select 1 from pg_database where datname='chatdb'\"" | grep -q 1 || as_pg "$PSQL -d postgres -c 'create database chatdb owner chat'"
docker rm -f cm-redis-stack >/dev/null 2>&1 || true
docker run -d --name cm-redis-stack -p 6390:6379 redis/redis-stack-server:latest >/dev/null
redis-server --port 6391 --save "" --appendonly no --daemonize yes >/dev/null
echo "postgres 127.0.0.1:$PGPORT (chatdb / chat / chat), redis-stack :6390, plain redis :6391"