test: stabilize async teardown and Feishu test isolation
Summary
Several CI failures observed while validating #1896 appear to come from pre-existing nondeterministic test behavior rather than the OpenCode changes in that PR.
A deeper comparison against pristine main identified multiple test-isolation and asynchronous teardown issues that can make the repository-wide unit-test gate fail intermittently.
Observed failures
Recent CI runs exposed:
core/TestCUJ_A5_FileReachesAgentt.TempDir()cleanup failed withdirectory not empty
tests/release_local/engine_matrix/TestUnknownSlashCommandNotifiesThenFallsThroughToAgent- the same
t.TempDir()cleanup failure
- the same
platform/feishu/TestAllowChat_FiltersGroupMessages/multiple_chat_ids,_match_second- asynchronous dispatch was not observed before the fixed 2-second timeout
These failures occur outside the OpenCode execution path.
Investigation
The same tests and relevant implementation were compared on both current main and the PR branch.
Repeated full-suite, race, shuffled-package, and isolated-test runs did not show a meaningful difference between the two revisions.
Engine teardown
The CUJ and engine-matrix tests can satisfy their assertions before asynchronous Engine processing and persistence have fully quiesced.
This leaves a window where session state can still be written while t.TempDir() cleanup is removing the persistence directory.
The tests currently observe an intermediate condition such as session creation or prompt forwarding rather than deterministic completion of the turn and persistence lifecycle.
Feishu allow-chat test
TestAllowChat_FiltersGroupMessages verifies the allow-list through the full asynchronous message dispatch path.
Before the test handler receives the accepted message, that path can resolve user/chat names through the real Lark SDK. With fake credentials, this can include tenant-token/network requests.
The test therefore uses a fixed 2-second timeout to measure both allow-list behavior and unrelated asynchronous/network work.
Artificially delaying the SDK HTTPS request on pristine main reproduces the same assertion failure.
Feishu token cache isolation
Shuffled/repeated Feishu package runs also expose an independent order-dependent failure: token-refresh tests reuse fixed app IDs while the Lark SDK maintains a process-global token cache keyed by app ID.
Later test iterations can therefore observe cached state from earlier runs.
Suggested direction
- Make Engine-based test harnesses wait for turn processing and persistence to fully stop before temporary-directory cleanup.
- Consider whether
Engine.Stop()should provide deterministic completion of processing goroutines. - Strengthen CUJ A5 so it verifies actual attachment delivery rather than only session creation.
- Test
allow_chatfiltering without requiring real SDK name/token lookups. - Isolate token-refresh tests from process-global SDK cache state, for example with unique app IDs or an isolated client/cache boundary.
- Avoid solving the Feishu timeout only by increasing the fixed wait.
This issue is intended to track test-harness reliability separately from #1896 so unrelated fixes do not expand that PR's scope.
Source: chenhg5/cc-connect