Skip to content

test: repair the pre-existing compat-offline-core failures - #450

Open
genedna wants to merge 2 commits into
ci-shard-command-testfrom
fix-main-test-suite
Open

test: repair the pre-existing compat-offline-core failures#450
genedna wants to merge 2 commits into
ci-shard-command-testfrom
fix-main-test-suite

Conversation

@genedna

@genedna genedna commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

堆叠在 #449 之上#449 合入后 GitHub 会自动把本 PR 的 base 改回 main
之所以堆叠:本 PR 修好 lib 失败后,cargo test --all 不再 fail-fast 中止,会继续跑完整个集成套件——如果基于裸 main(无分片),必然重演 360 分钟超时。堆在 #449 上它才跑得完。

这些失败都不是新的

它们是攒出来的cargo test --all 是 fail-fast:自 2026-07-28 lib 套件开始失败后,每一次运行都在那里中止,下游从来没有被报告过,于是每个新的破坏都无声地叠在上一个之上。

修复清单

1. 编译期断裂(阻塞所有 PR)

8f47a4c4 删掉了 tests/data/ai_semantic/rust/{sample,tools_sample}.rs,却留下 include_str! 它们的两个测试文件。main 当前在 --all-targets 下无法编译

error: couldn't read `tests/data/ai_semantic/rust/sample.rs`
error: could not compile `libra` (test "ai_semantic_rust_test")

这会让每一个开着的 PRcompat-clippy 失败,不只是本 PR。

选择从 8f47a4c4^ 原样恢复夹具,而非删掉这两个测试:夹具自己的头部写着 Line numbers are pinned by that test,测试里的断言仍在引用那些行号,删测试等于依据一个本该由删除者定夺的判断悄悄退掉活跃覆盖。恢复才是让两半保持自洽的读法。cargo fmt --all 不会碰它们(不在模块树里),钉死的行号安全。

2. worktree_scope 的 cwd 锁(0ce8f77c

五个测试直接调 std::env::set_current_dir#[serial] 只与其他 #[serial] 测试互斥,与每个 ChangeDirGuard 持有的 CWD_LOCK 是两套锁,于是它们把进程 cwd 从正在运行的夹具下面抽走——这正是连带打死 ai/hooks、rename_detect、utils::path 那批测试的原因

现在它们持有那把锁,并且在建完夹具之后才持有,避免整个 libra init 在一把全套件都在等的锁下运行。

a_pinned_scope_survives_a_cwd_change 另有一处:它 pin 的是环境 cwd,而 RequestScope::resolve 在非仓库目录下不装 pin——它此前只在「偶然抢到别的测试把 cwd 停在某个 libra 夹具里」的瞬间才通过,而那一刻恰恰就是它打死那个测试的一刻。现在给它一个真实仓库。

3. ai/hooks/runtimelibra.repoid6da73c67

CaptureScope 接入 ingest 路径后要解析 RepoIdentity,但夹具 ingest_fresh_conn 从未写入 libra.repoid,导致 14 条测试确定性失败——单条跑也挂。按 libra init 的做法补上种子。

ingest_fails_loud_when_table_missing 改为从完整 schema 里删掉一张表,而不是从无 schema 的空库开始:否则它会更早地栽在 config_kv 上,测不到它自己声称要测的东西。tombstone 测试则改为断言现在承载该拒绝的那条诊断信息。

4. utils/path 的 commondir 夹具

夹具的 commondir 目标缺少仓库数据库,已不再满足 is_terminal_common_storage

5. rename_detect5c1b7bb2a26cc9ac

LFS 分类在池化 io 线程上调用不可失败的 working_dir(),在非仓库目录下直接 panic 掉 worker,传到调用方只剩一个语焉不详的 IoTimeout。两个测试都给了真实仓库。

另外池被占满时同样报 IoTimeout——seam 测试会放弃那些仍在 worker 里睡觉的读,槽位活得比测试本身长,而池是进程级的。所以那个反向测试改为先排空池再重试。真正触发了 seam 的话每次重试都会挂,断言的判别力没有削弱。

6. ai/webtype_complexity

测试内部适配器字段的复杂类型,改为具名别名,顺带把元组两半的含义写下来。

验证

  • cargo test --lib4409 passed / 0 failed
  • ai_semantic_rust_test 4 passed、ai_semantic_tools_test 5 passed
  • cargo +nightly fmt --all --check 干净
  • cargo clippy --all-targets --all-features -- -D warnings 干净

不在本 PR 范围内

#447 的分片运行还暴露了若干产品与测试的契约不一致,例如只读 DB 导致的失败该报 LBR-IO-001(打开失败)还是 LBR-IO-002(写失败)、过期租约该返回 403 还是 409。改断言能让它们变绿,但那是在替维护者决定契约,不适合由本 PR 单方面做。

🤖 Generated with Claude Code


Note

Low Risk
Test-only and fixture changes with no production logic paths modified; risk is limited to CI signal quality if a fix masks a real bug.

Overview
Unblocks cargo test --all by fixing compile breaks, flaky cross-test cwd interference, and outdated test fixtures—not product behavior changes.

Restores deleted AI semantic fixtures (tests/data/ai_semantic/rust/sample.rs and tools_sample.rs) so integration tests that include_str! them and pin line numbers compile again.

Serializes worktree scope tests that call set_current_dir by taking ChangeDirGuard's cwd_lock_guard after fixtures are built (so libra init does not hold the suite-wide lock), and gives a_pinned_scope_survives_a_cwd_change a real repo so pinning is not a false pass on ambient cwd.

Hardens rename_detect / status I/O tests: lightweight repo_fixture for LFS/working_dir() discovery; wait_for_idle_io_pool plus retry in slow_op_seams_are_ignored_without_the_harness_gate so a full global I/O pool is not mistaken for fired delay seams.

Aligns AI hooks ingest tests with current contracts: seed libra.repoid in ingest_fresh_conn, drop a single table for the missing-table test, and assert tombstone errors via claim / erased diagnostics.

Fixes utils/path linked-worktree fixture by adding a stub repo DB so commondir targets satisfy terminal common storage. Minor ai/web test type alias for clippy.

Reviewed by Cursor Bugbot for commit 4c8fd5b. Bugbot is set up for automated code reviews on this repo. Configure here.

genedna and others added 2 commits August 10, 2026 11:27
None of these are new. They accumulated because `cargo test --all` is
fail-fast: once the lib suite started failing on 2026-07-28 every run
aborted there, so nothing downstream was ever reported and each new
breakage landed unseen on top of the last.

- worktree_scope (0ce8f77): five tests call `std::env::set_current_dir`
  directly. `#[serial]` only orders them against other `#[serial]`
  tests, not against the CWD_LOCK every `ChangeDirGuard` holds, so they
  yanked the process cwd out from under whatever fixture was in flight
  — which is what took down the ai/hooks, rename_detect and utils::path
  tests with them. They now take that lock, and take it AFTER building
  their fixtures so a whole `libra init` does not run under a lock the
  rest of the suite waits on. `a_pinned_scope_survives_a_cwd_change`
  additionally pinned the ambient cwd, which `RequestScope::resolve`
  refuses outside a repository: it only ever passed by stealing a
  moment when another test had parked the cwd in someone else's
  fixture, which is the same moment it broke that test. It gets a real
  repository now.

- ai/hooks/runtime (6da73c6): `CaptureScope` entered the ingest path
  and resolves `RepoIdentity`, but `ingest_fresh_conn` never wrote
  `libra.repoid`, so 14 tests failed deterministically — single-test
  runs included. Seed it, as `libra init` does.
  `ingest_fails_loud_when_table_missing` now drops one table from a
  complete schema instead of starting from a schema-less database, so
  it still tests the claim it makes rather than failing earlier on
  `config_kv`; the tombstone test asserts against the claim diagnostic
  that now carries the refusal.

- utils/path: the commondir fixture's target lacked the repository
  database, so it no longer satisfies `is_terminal_common_storage`.

- rename_detect (5c1b7bb, a26cc9a): the LFS classification resolves
  `working_dir()` infallibly on the pooled io thread, which panicked
  the worker outside a repository and reached the caller as an opaque
  `IoTimeout`. Both tests get a repository. A jammed pool reports
  `IoTimeout` too — the seam tests abandon reads that keep sleeping in
  a worker past their own end, and the pool is process-global — so the
  negative test drains the pool and retries. A seam that really fired
  would still blow every attempt, so the assertion keeps its teeth.

- ai/web: `type_complexity` on a test-local adapter field, now a named
  alias that also records what the tuple's two halves mean.

Verified with `cargo test --lib`: 4409 passed, 0 failed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`8f47a4c4` removed tests/data/ai_semantic/rust/{sample,tools_sample}.rs
but left tests/ai_semantic_{rust,tools}_test.rs, which `include_str!`
them. main therefore does not COMPILE under `--all-targets`:

    error: couldn't read `tests/data/ai_semantic/rust/sample.rs`
    error: could not compile `libra` (test "ai_semantic_rust_test")

This breaks `compat-clippy` for every open PR, not just this one.

Restored verbatim from 8f47a4c^ rather than deleting the orphaned
tests: the fixtures carry `Line numbers are pinned by that test` in
their own header, and the assertions still reference those lines, so
dropping the tests would silently retire live coverage on a judgement
that belongs to whoever made the deletion. Restoring is the reading
that keeps both halves consistent. `cargo fmt --all` leaves them
untouched — they are not in the module tree — so the pinned lines stay
put.

Verified: ai_semantic_rust_test 4 passed, ai_semantic_tools_test 5
passed, and `cargo clippy --all-targets --all-features -- -D warnings`
is clean again.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant