12 Commits

Author SHA1 Message Date
Leveling
c209fac226 test(parsing): use the platform default MinerU watchdog 2026-12-03 23:32:03 +08:00
Leveling
d5ce8dec12 test(parsing): bound MinerU lifecycle tests with an external timeout 2026-12-03 18:29:55 +08:00
AleFlyX
508a2bda35 test(parsing): 给清理用例补墙钟断言,并给夹具加真实耗时兜底
变更:
- 清理用例在夹具首次发布 `child.pid` 时记下墙钟时间,断言此后父进程在
  `POST_MARKER_BUDGET_SECONDS` 内返回,不再只靠整轮 20 秒的宽上限。
- 夹具的虚拟时间上限之外补一条真实墙钟兜底。虚拟时钟只在
  `local.time.sleep` 里推进,生产改成不调用它时虚拟时限永不触发,
  没有兜底就会无限空转。

验证(本机 Linux / CPython 3.13.5):
- 原 #3089 回归(时限 +8 秒):清理用例失败
- 时限判定处 8 秒真实停顿:清理用例失败
- 健康运行下 `after_marker` 约 1.2 秒,整轮约 3 秒
- 中途停顿 7.0 秒仍通过、7.8 秒失败;生产清理各环节各加 4 秒(均在
  其自身 5 秒预算内)时失败
- 轮询间隔 0.002 / 0.05 / 0.07 / 0.3:均 19 passed, 1 skipped
- pytest tests/services/parsing/:220 passed, 2 skipped
- pytest tests/runtime/test_launcher.py:67 passed, 1 skipped
- ruff check / ruff format --check tests/services/parsing/:PASS

已知局限:这条墙钟断言从「循环第一次调用 check()」起算,从进程启动到
首次 check 之间的耗时不在窗口内;兜底也只在 poll() 里检查,两次轮询
之间的阻塞观察不到。彻底解决需要外部超时机制,见 #3126 的讨论。
2026-12-01 16:57:07 +08:00
panghufattiger996-maker
65dcf1f0d0 test(parsing): restore MinerU deadline and process cleanup coverage
#3089 fixed the Windows CI race between fixture startup and the deadline
check, but it left two coverage gaps that let the tests pass without
verifying anything.

The explicit-timeout test allowed `elapsed < 20` for a 1.2s deadline.
Postponing the deadline comparison by eight seconds still passed it
(measured: 9.26s, green). The cleanup test allowed `elapsed < 15` while its
grandchild only slept 10s, so an implementation that waited for the
descendant to exit on its own would also finish in time.

Both were reproduced. Reverting only the skip recording, and delaying the
deadline, each kept the old assertions green.

What changed
------------

Timing is now driven by a fake clock over the real poll loop, so the test
asks "did the loop stop at the configured instant" without interpreter
startup, poll scheduling or tree teardown landing in the measurement. The
helper lives in `_mineru_deadline_probe.py`.

- Covers several configured deadlines, continuous output (which refreshes
  the loop's `activity` value and must not extend the total deadline), and a
  CLI that exits normally before the deadline.
- The assertion is anchored on the first poll at or beyond the deadline
  rather than on a tolerance band, so the poll interval is not baked into
  the test. Verified still green with the production interval changed to
  50ms and 70ms.

Cleanup keeps real subprocesses, which is the only way to observe that the
tree is gone.

- The fixture publishes its PID through a temp file and rename, so the path
  never exists with partial contents.
- It also takes an independent exit signal, so a failure before the PID is
  published still lets the test tear its own process down.

Only test files change.

Verification
------------

- Windows / Python 3.13: `test_mineru_process_lifecycle.py` 10 passed,
  10 skipped (the skips are POSIX process-group cases), plus the launcher's
  detached-console test green.
- `ruff check` and `ruff format --check` clean on `tests/services/parsing/`.
- Injecting a deadline delay, hard-coding the deadline, comparing against
  `activity` instead of `started`, shortening the deadline, or replacing it
  with a constant all make the suite fail as intended.

Three pre-existing failures in `tests/runtime/test_launcher.py`
(`test_terminate_warns_*`, `test_kill_port_listeners_*`) reproduce on the
base commit `2d329c219` and are unrelated to this change.

Follow-up to #3089. Related to #3088.
2026-11-30 23:43:13 +08:00
Leveling
9bed004617 test(parsing): stop racing interpreter startup in the MinerU lifecycle checks (#3089)
* test(parsing): stop racing interpreter startup in the MinerU lifecycle checks

The Windows `import-check` job flakes on `dev`. It failed at 2026-11-30 03:12
and 03:32 on `79a66cb3` and `6b00f010`, passed on the same step 90 minutes
later in another run, and passed on `218dbe31` the evening before. Nothing
between those runs touched `.github/`, `tests/services/parsing/`,
`tests/runtime/` or the MinerU engine, so the workflow and the code under test
were identical in the green and red runs.

Reproduced, and the cause is a timing premise in the tests, not the runner.

The race
--------

`test_deadline_and_cancellation_settle_the_owned_tree[True]` sets
`timeout=0.8` and only cancels once the fixture child has spawned a grandchild
and written `child.pid`:

    def check():
        if cancelled and list(...glob(".../child.pid")):
            raise IndexingCancelled(...)

`local.py` starts its clock before `cli_process()`, which on Windows creates a
Job Object, spawns a suspended interpreter, resumes it and queries its threads.
That work plus two more interpreter startups has to fit inside the same 0.8s.
When it does not, the deadline wins before the marker exists and the assertion
reports `TIMEOUT is not CANCELLED`.

Measured on an idle machine the marker lands in 0.067-0.085s, so the margin
looked comfortable. Delaying only the child's first write, with no CPU
contention at all:

    startup delay | result    | expected  | verdict
         0.0s     | cancelled | cancelled | pass
         0.5s     | cancelled | cancelled | pass
         0.7s     | timeout   | cancelled | FAIL
         0.9s     | timeout   | cancelled | FAIL
         1.2s     | timeout   | cancelled | FAIL

CPU contention alone reproduced the same signature
`assert <LocalParseReason.TIMEOUT> is <LocalParseReason.CANCELLED>` at line 138,
plus `assert 2.087 < 2` and `assert 3.757 < 1.5` on neighbouring cases.

The production ordering is correct and is left alone: `run.check()` is
evaluated before the deadline comparison, so an available cancellation always
wins. What the tests must not do is depend on how fast the runner started a
Python interpreter.

What changed
------------

- `_await_marker()` waits for a fixture marker with a real timeout and a
  message that distinguishes "the CLI never started" from "the runner was
  slow". Bare `(path,) = glob(...)` unpacking turned both into
  `ValueError: not enough values to unpack (expected 1, got 0)`, which is what
  made these CI failures unreadable.
- The cancellation case waits for the recorded child before raising, so the
  interruption is decided by policy rather than by interpreter startup. A 3s
  startup delay now passes where 0.7s used to fail.
- Wall-clock bounds that were only guarding "did not wait for the descendant"
  were widened off the interpreter-startup budget (`elapsed < 2` -> `< 15`,
  `elapsed < 1.5` -> `< 10`, `elapsed < 2.5` -> `< 15`). The idle-threshold and
  deadline assertions that carry the actual meaning are unchanged.
- `_await_settled()` treats `psutil.AccessDenied` as "not settled yet" instead
  of raising mid-test.
- The decoy process in `test_parent_exit_does_not_wait_for_descendant_stdout`
  lives 120s instead of 10s, so a slow run cannot make it die of old age and be
  reported as "cleanup touched an unrelated process".
- `test_detached_venv_launcher_has_no_console` asserts the marker exists before
  reading it, instead of raising `FileNotFoundError` after its 15s wait.

Observability
-------------

The Windows step now runs with `-rA --durations=15`. Without them the job
reported only "Process completed with exit code 1" with no test name, which is
why these failures needed a local reproduction to attribute.

Verification
------------

- `pytest -q -rA --durations=15 tests/services/parsing/test_mineru_process_lifecycle.py tests/runtime/test_launcher.py::test_detached_venv_launcher_has_no_console`
  -> 7 passed, 10 skipped (the skips are POSIX/Darwin-only cases).
- Deliberate-startup-delay harness: 0.0/0.5/0.9/1.5/3.0s all report
  `cancelled` after the change; 0.7s+ reported `timeout` before it.
- `ruff check` and `ruff format --check` clean on both files; workflow YAML
  parses.

No production code is changed.

* test(parsing): synchronise the deadline fixtures with grandchild startup

Addresses review on #3089. Two real defects:

1. The deadline case of test_deadline_and_cancellation_settle_the_owned_tree
   still raced. Only the cancellation branch waited for `child.pid`; the
   deadline branch killed the fixture at 0.8s and then read a marker that was
   never written, so a 1.3s startup delay produced `TIMEOUT` and then a failed
   marker read. Both branches now synchronise through `check()`: it waits for
   the recorded grandchild and only then either raises (cancellation) or returns
   and lets the deadline comparison run. The timeout assertion is preserved.

   test_explicit_client_timeout_also_bounds_parent_runtime had the same shape —
   it read `deadline.txt` after a 1.2s kill. The record is written before the
   child parks, so it exists whenever the child started at all, and the read now
   reports "CLI did not start" instead of an unpacking error.

2. test_parent_exit_does_not_wait_for_descendant_stdout had lost its teeth: the
   new 10s bound exceeded the grandchild's 2s sleep, so an implementation that
   waited for inherited stdout could finish inside the bound and pass. The
   grandchild now lives 60s and the bound is 20s, derived from the fixture, so
   waiting for it fails the test again.

Verified with a 1.3s pre-startup delay (the reviewer's repro): both lifecycle
cases report the expected reason and the tree is settled. 0.0/1.3/2.0/3.0s all
pass. `7 passed, 10 skipped`; ruff clean.

* test: wait for the MinerU deadline record before enforcing the timeout

---------

Co-authored-by: Qiuner <wdst3635@163.com>
2026-11-30 05:55:09 -03:00
Bingxi Zhao (Frank)
92a26ae3cc fix(storage): isolate attachment writes and settle document parsing
Local dev repairs for #2244, #2245, #2255, #2426, #2453. Regression checks cover reported symptoms and compatibility boundaries.
2026-11-15 00:44:09 +08:00
Tazeem Mahashin
e372aacc90 fix(parsing): recheck groups that disappear during cleanup inspection 2026-11-06 12:37:11 -05:00
Bingxi Zhao (Frank)
39f744114f Confirm process group settlement and load the mastery transcript on demand 2026-11-06 02:16:17 +08:00
cgycorey
3845c9f231 test(parsing): stop racing init's reaping of a killed MinerU child
test_parent_exit_does_not_wait_for_descendant_stdout asserted
`not psutil.pid_exists(child)` immediately after the CLI exited, but
cli_process only SIGKILLs the group and waits for the direct child: an
orphaned grandchild is reaped by init, so there is a real window where the
pid still exists as a zombie.

Running the whole file in a loop fails 2 of 8 runs on 40c051b7 and 5 of 8 on
f7aed0744 (v1.7.1), and every failure is `status=zombie` -- the kill landed
and only the reaping was late. The test alone passes 12 of 12 in isolation,
which is why it reads as a CI-only flake.

Wait up to 0.25s for the pid to disappear, accepting a zombie or dead state
but still failing a running process. The window stays under the child's 2s
lifetime, so a kill that never landed still fails instead of dying of old
age. After the change the same loop passes 15 of 15, and with os.killpg
disabled the test still fails, so the relaxed check kept its teeth.

The deadline/cancel test carried the same immediate check against the same
reaping window, so it uses the helper too.

Those cleanup assertions only ever see the settled answer, so a separate test
pins both answers with real processes: a live pid is not settled, and an
unreaped kill is. Swapping the helper for the old `not pid_exists` check
makes that test fail.
2026-10-31 20:50:58 +00:00
Bingxi Zhao (Frank)
fbab59acbf feat: modularize installation and enforce feature dependency boundaries 2026-10-28 01:02:29 +08:00
Bingxi Zhao (Frank)
c3b98baf34 fix(parsing): align MinerU deadlines and retain terminal errors (#1982) 2026-10-19 01:52:28 +08:00
yepyhun
d48b6278d3 fix(mineru): own CLI workers and avoid log-silence termination 2026-10-12 13:12:57 +02:00