Commit 84fc9d7
authored
test(agent-core-v2): dispose task fixtures before deleting their session dir (#216)
## Related Issue
No issue. Found when a CI shard failed on an unrelated PR with
`ENOTEMPTY: directory not empty, rmdir
'/tmp/pythinker-bg-limit-agent-*/sessions/test-workspace/test-session'`.
## Problem
Five `AgentTaskService` cases create a temporary session directory and
an agent context over it, then delete the directory in their `finally`
block. None of them disposed the context first, so the context was still
writing session state into that directory while the delete walked it. On
a loaded CI machine the two race and the run fails with `ENOTEMPTY`. The
tests also leaked six agent contexts per run.
One case already worked around a symptom of this by awaiting
`ISessionMetadata.ready`; the other four had nothing.
## What changed
- New `cleanupSessionDir(sessionDir, ...contexts)` test helper: disposes
every context, then removes the directory with `fs.rm`'s own
`maxRetries` / `retryDelay` — the documented remedy for `ENOTEMPTY` /
`EBUSY` / `EPERM` from a concurrent writer.
- All five cases now hoist their fixture above the `try` and clean up
through the helper. No production code changes; no changeset, since
nothing user-visible changes.
## Verification
- Instrumented the helper once locally: exactly 6 contexts are now
disposed per run of this file, none of which were disposed before.
- `test/agent/task/taskManager.test.ts` — 48 passed, 3 consecutive runs
- `pnpm --filter @pymodel/agent-core-v2 exec vitest run` — 347 files,
5,723 tests passed
- `typecheck`, `tsgo`, `check-no-comments`, oxlint — exit 0
## Checklist
- [x] I have read the
[CONTRIBUTING](https://github.com/PyModel/pythinker-code/blob/main/CONTRIBUTING.md)
document.
- [x] I have linked a related issue (external PRs: the issue must have a
maintainer's `/approve`).
- [x] I have added tests that prove my feature works.
- [x] Ran `gen-changesets` skill, or this PR needs no changeset.
- [x] Ran `gen-docs` skill, or this PR needs no doc update.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Tests**
* Improved cleanup of temporary session data after test runs.
* Ensured test-agent contexts are properly disposed of.
* Updated session-based tests to use separate reader and writer fixtures
where needed.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent afd313c commit 84fc9d7
1 file changed
Lines changed: 22 additions & 11 deletions
Lines changed: 22 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
69 | 77 | | |
70 | 78 | | |
71 | 79 | | |
| |||
681 | 689 | | |
682 | 690 | | |
683 | 691 | | |
| 692 | + | |
684 | 693 | | |
685 | | - | |
686 | 694 | | |
687 | 695 | | |
688 | 696 | | |
| |||
701 | 709 | | |
702 | 710 | | |
703 | 711 | | |
704 | | - | |
| 712 | + | |
705 | 713 | | |
706 | 714 | | |
707 | 715 | | |
708 | 716 | | |
709 | 717 | | |
| 718 | + | |
710 | 719 | | |
711 | | - | |
712 | 720 | | |
713 | 721 | | |
714 | 722 | | |
| |||
727 | 735 | | |
728 | 736 | | |
729 | 737 | | |
730 | | - | |
| 738 | + | |
731 | 739 | | |
732 | 740 | | |
733 | 741 | | |
734 | 742 | | |
735 | 743 | | |
| 744 | + | |
736 | 745 | | |
737 | | - | |
738 | 746 | | |
739 | 747 | | |
740 | 748 | | |
| |||
747 | 755 | | |
748 | 756 | | |
749 | 757 | | |
750 | | - | |
| 758 | + | |
751 | 759 | | |
752 | 760 | | |
753 | 761 | | |
| |||
1079 | 1087 | | |
1080 | 1088 | | |
1081 | 1089 | | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
1082 | 1093 | | |
1083 | | - | |
1084 | 1094 | | |
1085 | 1095 | | |
1086 | 1096 | | |
1087 | 1097 | | |
1088 | 1098 | | |
1089 | 1099 | | |
1090 | 1100 | | |
1091 | | - | |
| 1101 | + | |
| 1102 | + | |
1092 | 1103 | | |
1093 | 1104 | | |
1094 | 1105 | | |
| |||
1098 | 1109 | | |
1099 | 1110 | | |
1100 | 1111 | | |
1101 | | - | |
| 1112 | + | |
1102 | 1113 | | |
1103 | 1114 | | |
1104 | 1115 | | |
| |||
1285 | 1296 | | |
1286 | 1297 | | |
1287 | 1298 | | |
| 1299 | + | |
1288 | 1300 | | |
1289 | | - | |
1290 | 1301 | | |
1291 | 1302 | | |
1292 | 1303 | | |
1293 | 1304 | | |
1294 | 1305 | | |
1295 | 1306 | | |
1296 | | - | |
| 1307 | + | |
1297 | 1308 | | |
1298 | 1309 | | |
1299 | 1310 | | |
| |||
0 commit comments