From 6894442fdd9e5116dbda57d481913fff1070d1a7 Mon Sep 17 00:00:00 2001 From: heweidong-ecco <290444878+heweidong-ecco@users.noreply.github.com> Date: Mon, 21 Sep 2026 19:56:12 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E6=8C=82=20GitHub=20Actions=20=E2=80=94?= =?UTF-8?q?=E2=80=94=20=E9=A6=96=E4=BB=BD=20CI=EF=BC=88=E5=BF=85=E8=BF=87?= =?UTF-8?q?=20job=20+=20=E4=B8=8D=E9=98=BB=E6=96=AD=E7=9A=84=20embedding?= =?UTF-8?q?=20job=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 本仓此前没有任何 CI(gh pr checks → no checks reported)。 - job test(必过):PG(pgvector:pg16) + Redis 服务容器 → psql -f schema.sql 建表 → pytest -m "not requires_ollama"(39 用例) - job test-embedding(continue-on-error):装 Ollama + 拉 bge-m3 → pytest -m requires_ollama(13 用例) - pytest.ini 注册 requires_ollama 标记;test_day18 / test_day19 各加 pytestmark (day19 原本没有 import pytest,一并补上,否则 collection NameError) - 本地已验证两条选择:39 passed / 13 deselected,13 passed / 39 deselected 提交前两问 ① 本次有决策事项 ⇒ 已建 DEC:docs/decisions决策/DEC-002-CI的embedding边界-20260921.md (「CI 怎么覆盖 embedding 用例」三选一:单 job 全跑 / 只跑不依赖的 / 两个 job + 后者不阻断 → 选定第三种,理由与反悔成本见该文档) ② CHANGELOG 已写:CHANGELOG.md(第 2 轮) 注:CI 里的 PG 口令是刻意的公开值(一次性容器、runner 内网),真环境凭据一律走 .env。 --- .github/workflows/tests.yml | 148 ++++++++++++++++++ CHANGELOG.md | 14 ++ ...dding\350\276\271\347\225\214-20260921.md" | 52 ++++++ pytest.ini | 4 + test_day18_evolution_conditional.py | 3 + test_day19_performance_stability.py | 5 + 6 files changed, 226 insertions(+) create mode 100644 .github/workflows/tests.yml create mode 100644 "docs/decisions\345\206\263\347\255\226/DEC-002-CI\347\232\204embedding\350\276\271\347\225\214-20260921.md" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..eb80fea --- /dev/null +++ b/.github/workflows/tests.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index f6a2bce..4b93920 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 模型) diff --git "a/docs/decisions\345\206\263\347\255\226/DEC-002-CI\347\232\204embedding\350\276\271\347\225\214-20260921.md" "b/docs/decisions\345\206\263\347\255\226/DEC-002-CI\347\232\204embedding\350\276\271\347\225\214-20260921.md" new file mode 100644 index 0000000..08a81da --- /dev/null +++ "b/docs/decisions\345\206\263\347\255\226/DEC-002-CI\347\232\204embedding\350\276\271\347\225\214-20260921.md" @@ -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。 diff --git a/pytest.ini b/pytest.ini index db99261..b9b1a7e 100644 --- a/pytest.ini +++ b/pytest.ini @@ -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 推理且含性能断言) diff --git a/test_day18_evolution_conditional.py b/test_day18_evolution_conditional.py index c07e170..b8ab295 100644 --- a/test_day18_evolution_conditional.py +++ b/test_day18_evolution_conditional.py @@ -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:程序性记忆完整进化链路 ==================== diff --git a/test_day19_performance_stability.py b/test_day19_performance_stability.py index eee7d89..7c45802 100644 --- a/test_day19_performance_stability.py +++ b/test_day19_performance_stability.py @@ -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): """执行函数并返回耗时(秒)和结果"""