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
148 changes: 148 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# 本仓的 CI:跑 pytest。
#
# ⚠️ 为什么分两个 job(不是一个):
# · job `test`(**必过**)—— 只跑不依赖 embedding 的用例(day17/20/21/22)。
# 起 PG(pgvector) + Redis 服务容器,用仓内的 schema.sql 建表。
# · job `test-embedding`(**不阻断**)—— 额外装 Ollama + 拉 bge-m3,跑 day18/day19。
# 它设 continue-on-error 的原因有二:
# ① GitHub runner 只有 CPU,1.2 GB 的 bge-m3 走 CPU 很慢;
# ② day19 是**性能断言**(KV≤Ledger、RAG>KV),在共享 runner 上噪声大。
# 红了先判断是不是环境抖动,别当逻辑错。
#
# ⚠️ CI 里的 PG 口令是**刻意的公开值**:容器是一次性的、只活在 runner 内网,不是机密。
# 真环境的凭据一律走 .env(不入库)—— 见 CLAUDE.md §8。

name: tests

on:
push:
branches: [main]
pull_request:
workflow_dispatch:

jobs:
test:
name: pytest(不依赖 embedding)
runs-on: ubuntu-latest

services:
postgres:
image: pgvector/pgvector:pg16
env:
POSTGRES_USER: memory_user
POSTGRES_PASSWORD: ci_only_ephemeral
POSTGRES_DB: memory_system
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U memory_user -d memory_system"
--health-interval 5s
--health-timeout 5s
--health-retries 10
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 5s
--health-timeout 5s
--health-retries 10

env:
PG_PASSWORD: ci_only_ephemeral
PG_HOST: localhost
PG_PORT: "5432"
PG_DB: memory_system
PG_USER: memory_user
REDIS_HOST: localhost
REDIS_PORT: "6379"
REDIS_DB: "0"

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: pip

- name: 装依赖
run: pip install -r requirements.txt

# ⚠️ 必须在跑测试前建表:CI 的库是空的,而表结构不在代码里,只在本文件里
- name: 用 schema.sql 建表
run: |
PGPASSWORD="$PG_PASSWORD" psql -h localhost -U memory_user -d memory_system \
-v ON_ERROR_STOP=1 -f schema.sql

- name: 跑测试(跳过需要 Ollama 的用例)
run: pytest -m "not requires_ollama" -q

test-embedding:
name: pytest(含 embedding · 不阻断)
runs-on: ubuntu-latest
continue-on-error: true

services:
postgres:
image: pgvector/pgvector:pg16
env:
POSTGRES_USER: memory_user
POSTGRES_PASSWORD: ci_only_ephemeral
POSTGRES_DB: memory_system
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U memory_user -d memory_system"
--health-interval 5s
--health-timeout 5s
--health-retries 10
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 5s
--health-timeout 5s
--health-retries 10

env:
PG_PASSWORD: ci_only_ephemeral
PG_HOST: localhost
PG_PORT: "5432"
PG_DB: memory_system
PG_USER: memory_user
REDIS_HOST: localhost
REDIS_PORT: "6379"
REDIS_DB: "0"

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: pip

- name: 装依赖
run: pip install -r requirements.txt

- name: 用 schema.sql 建表
run: |
PGPASSWORD="$PG_PASSWORD" psql -h localhost -U memory_user -d memory_system \
-v ON_ERROR_STOP=1 -f schema.sql

- name: 装并启动 Ollama,拉 bge-m3
run: |
curl -fsSL https://ollama.com/install.sh | sh
nohup ollama serve > /tmp/ollama.log 2>&1 &
for i in $(seq 1 30); do
curl -sf http://localhost:11434/api/tags >/dev/null && break
sleep 2
done
ollama pull bge-m3

- name: 跑需要 embedding 的用例
run: pytest -m requires_ollama -q
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@

---

## [第 2 轮] · 2026-09-21 · 挂 CI(GitHub Actions)· 🚧 进行中

### 新增(Added)

- **`.github/workflows/tests.yml`** —— 本仓**首份 CI**(此前 `gh pr checks` → `no checks reported`,即**没有任何 CI**)
- job `test`(**必过**):PG(pgvector pg16) + Redis 服务容器 → `psql -f schema.sql` 建表 → `pytest -m "not requires_ollama"`(39 用例)
- job `test-embedding`(**不阻断**,`continue-on-error: true`):装 Ollama + 拉 `bge-m3` → `pytest -m requires_ollama`(13 用例)
- 为什么分两个 job、为什么后者不阻断 → **`docs/decisions决策/DEC-002-CI的embedding边界-20260921.md`**
- **`requires_ollama` 标记** —— `pytest.ini` 注册;`test_day18` / `test_day19` 各加 `pytestmark`
- 本地同样可用:`pytest -m "not requires_ollama"`(39)/ `pytest -m requires_ollama`(13)
- ⚠️ `test_day19` 原本**没有 `import pytest`**,加标记时一并补上(否则 collection 直接 NameError)

---

## [第 1 轮] · 2026-09-21 · 环境重建 + KV 淘汰接线 · ✅ 已完成

**测试:45 passed / 0 failed**(改前基准:23 passed / 11 failed,11 个全因缺 embedding 模型)
Expand Down
52 changes: 52 additions & 0 deletions docs/decisions决策/DEC-002-CI的embedding边界-20260921.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# DEC-002 · CI 怎么覆盖「依赖 embedding」的 13 个用例

| 项 | 值 |
|---|---|
| **日期** | 2026-09-21 |
| **状态** | ✅ 已裁决(用户 2026-09-21 指示「把 pytest 挂成 GitHub Actions」) |
| **触发** | 本仓此前**没有任何 CI**(`gh pr checks` → `no checks reported`) |
| **相关** | `.github/workflows/tests.yml` · `pytest.ini` 的 `requires_ollama` 标记 · `DEC-001` |

---

## 一 · 问题

52 个用例里,**13 个依赖 Ollama + `bge-m3`**(`test_day18` 8 个 · `test_day19` 5 个):
它们要现加载 1.2 GB 模型做 embedding。CI 要怎么覆盖它们?

## 二 · 备选方案(三选一)

| 方案 | 做法 | 优 | 劣 |
|---|---|---|---|
| A. 单 job,全跑 | CI 里装 Ollama + 拉 bge-m3,52 个全跑 | 覆盖最全 | 每跑必下 1.2 GB;**runner 只有 CPU**,且 `test_day19` 是**性能断言**(KV≤Ledger、RAG>KV)—— 在共享 runner 上噪声大 ⇒ **天然 flaky,红了不知道该不该信** |
| B. 只跑不依赖 embedding 的 | CI 只跑 39 个,13 个永不在 CI 跑 | 快、稳、必绿 | 13 个用例**永远没有第二双眼睛**;本机内存紧张(8 GB)时它们本来就跑不动 ⇒ 等于没有回归保障 |
| **C. 两个 job —— 必过 + 不阻断** ✅**选定** | `test`(39 个,**必需**)· `test-embedding`(13 个,`continue-on-error: true`) | 该拦的照拦;该看的照看;embedding 那批**有结论但不阻断** | 会让人看到"有个 job 是黄的但 PR 仍可合"—— 需要这个 DEC 来解释 |

## 三 · 决定

**选 C**,并把「哪 13 个」用**标记**显式表达(不是靠路径或 `--ignore` 硬编码):

- `pytest.ini` 注册 `requires_ollama` 标记;`test_day18` / `test_day19` 各加一行 `pytestmark = pytest.mark.requires_ollama`
- CI:`pytest -m "not requires_ollama"`(必需)· `pytest -m requires_ollama`(不阻断)
- 本地:两条命令也直接可用(**已验证**:39 passed / 13 deselected;13 passed / 39 deselected)

**刻意不用** `continue-on-error` 去掩盖:job 名写明「含 embedding · 不阻断」,且文件头注释写清**为什么**。

## 四 · 两条配套约定

1. **CI 的 PG 口令是刻意的公开值**(`ci_only_ephemeral`)—— 容器一次性、只活在 runner 内网,不是机密。
⛔ **不得**把这个值当"默认口令"抄到任何真环境;真环境一律走 `.env`。
2. **CI 的库是空的** ⇒ 必须先 `psql -f schema.sql` 再跑测试。
这也让 `schema.sql` 从"导出的副产品"变成**CI 的硬依赖**(本仓此前无任何 DDL,见 `CHANGELOG` 第 1 轮)。

## 五 · 验收判据

- [x] 本地两条 `-m` 选择都能跑通(39 / 13,合计 52)
- [ ] PR 上能看到两个 job,且 `test` 为必需
- [ ] `test-embedding` 红了不阻断合并

## 六 · 反悔成本

低。要收紧成"embedding 也阻断",删掉 `continue-on-error: true` 即可;
要放宽成"只在手动触发时跑",给该 job 加 `if: github.event_name == 'workflow_dispatch'`。
**都不涉及代码改动**,只动本 workflow。
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ addopts = -ra
filterwarnings =
ignore:.*NotOpenSSLWarning.*
ignore:.*urllib3.*
markers =
requires_ollama: 需要本地 Ollama + bge-m3 才能跑(CI 默认跳过)
—— 用 `pytest -m "not requires_ollama"` 跳过,`pytest -m requires_ollama` 只跑这些。
见 .github/workflows/tests.yml(那个 job 设了 continue-on-error,因为它依赖 CPU 推理且含性能断言)
3 changes: 3 additions & 0 deletions test_day18_evolution_conditional.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
from db_pool import get_cursor
from cache_manager import redis_client, kv_key

# 本文件依赖 Ollama embedding(见 pytest.ini 的 markers 说明与 CI workflow)
pytestmark = pytest.mark.requires_ollama


# ==================== 场景 1:程序性记忆完整进化链路 ====================

Expand Down
5 changes: 5 additions & 0 deletions test_day19_performance_stability.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
from db_pool import get_cursor
from cache_manager import redis_client, tool_key, skill_key, cache_get

import pytest

# 本文件依赖 Ollama embedding(见 pytest.ini 的 markers 说明与 CI workflow)
pytestmark = pytest.mark.requires_ollama


def time_func(func, *args, **kwargs):
"""执行函数并返回耗时(秒)和结果"""
Expand Down
Loading