|
1 | 1 | """Tests for KimiIntegration — skills integration with legacy migration.""" |
2 | 2 |
|
3 | 3 | from specify_cli.integrations import get_integration |
4 | | -from specify_cli.integrations.kimi import _migrate_legacy_kimi_dotted_skills |
| 4 | +from specify_cli.integrations.kimi import ( |
| 5 | + _migrate_legacy_kimi_context_file, |
| 6 | + _migrate_legacy_kimi_dotted_skills, |
| 7 | +) |
5 | 8 | from specify_cli.integrations.manifest import IntegrationManifest |
6 | 9 |
|
7 | 10 | from .test_integration_base_skills import SkillsIntegrationTests |
@@ -344,6 +347,88 @@ def test_teardown_skips_symlinked_legacy_skills_dir(self, tmp_path): |
344 | 347 | # The symlink target and its contents must survive teardown. |
345 | 348 | assert keep.exists() |
346 | 349 |
|
| 350 | + def test_migrate_skips_symlinked_legacy_parent_dir(self, tmp_path): |
| 351 | + # `.kimi` is itself a symlink to the project root, so `.kimi/skills` |
| 352 | + # resolves to `./skills` — an unrelated in-tree directory. Even though |
| 353 | + # the resolved path stays inside the project, migration must not |
| 354 | + # operate on it because a path component is a symlink. |
| 355 | + project = tmp_path / "project" |
| 356 | + unrelated = project / "skills" / "speckit-evillegacy" |
| 357 | + unrelated.mkdir(parents=True) |
| 358 | + (unrelated / "SKILL.md").write_text("# unrelated\n") |
| 359 | + # .kimi -> project root, so .kimi/skills == ./skills. |
| 360 | + (project / ".kimi").symlink_to(project, target_is_directory=True) |
| 361 | + |
| 362 | + i = get_integration("kimi") |
| 363 | + m = IntegrationManifest("kimi", project) |
| 364 | + i.setup(project, m, parsed_options={"migrate_legacy": True}) |
| 365 | + |
| 366 | + # The unrelated ./skills content must be untouched. |
| 367 | + assert (unrelated / "SKILL.md").exists() |
| 368 | + assert not ( |
| 369 | + project / ".kimi-code" / "skills" / "speckit-evillegacy" |
| 370 | + ).exists() |
| 371 | + |
| 372 | + def test_teardown_skips_symlinked_legacy_parent_dir(self, tmp_path): |
| 373 | + project = tmp_path / "project" |
| 374 | + project.mkdir() |
| 375 | + # Looks Speckit-generated, so only the symlink check protects it. |
| 376 | + unrelated = project / "skills" / "speckit-evillegacy" |
| 377 | + unrelated.mkdir(parents=True) |
| 378 | + (unrelated / "SKILL.md").write_text( |
| 379 | + "---\nmetadata:\n author: github-spec-kit\n---\n# x\n" |
| 380 | + ) |
| 381 | + (project / ".kimi").symlink_to(project, target_is_directory=True) |
| 382 | + |
| 383 | + i = get_integration("kimi") |
| 384 | + m = IntegrationManifest("kimi", project) |
| 385 | + i.teardown(project, m) |
| 386 | + |
| 387 | + # The unrelated ./skills content must survive teardown. |
| 388 | + assert (unrelated / "SKILL.md").exists() |
| 389 | + |
| 390 | + def test_context_migration_does_not_write_through_symlinked_agents_md( |
| 391 | + self, tmp_path |
| 392 | + ): |
| 393 | + # A sensitive file outside the project that a malicious AGENTS.md |
| 394 | + # symlink points at. Migration must never overwrite it. |
| 395 | + outside = tmp_path / "outside" |
| 396 | + outside.mkdir() |
| 397 | + secret = outside / "secret.txt" |
| 398 | + secret.write_text("original secret\n") |
| 399 | + |
| 400 | + project = tmp_path / "project" |
| 401 | + project.mkdir() |
| 402 | + (project / "AGENTS.md").symlink_to(secret) |
| 403 | + (project / "KIMI.md").write_text("# Notes\n\nKeep this.\n") |
| 404 | + |
| 405 | + result = _migrate_legacy_kimi_context_file(project) |
| 406 | + |
| 407 | + # The outside file must not be overwritten through the symlink. |
| 408 | + assert secret.read_text() == "original secret\n" |
| 409 | + # KIMI.md is preserved so the user can migrate manually. |
| 410 | + assert (project / "KIMI.md").is_file() |
| 411 | + assert result is False |
| 412 | + |
| 413 | + def test_context_migration_does_not_follow_symlinked_kimi_md(self, tmp_path): |
| 414 | + # A symlinked KIMI.md (source) must not be followed/consumed. |
| 415 | + outside = tmp_path / "outside" |
| 416 | + outside.mkdir() |
| 417 | + external = outside / "external.md" |
| 418 | + external.write_text("# external\n") |
| 419 | + |
| 420 | + project = tmp_path / "project" |
| 421 | + project.mkdir() |
| 422 | + (project / "KIMI.md").symlink_to(external) |
| 423 | + |
| 424 | + result = _migrate_legacy_kimi_context_file(project) |
| 425 | + |
| 426 | + assert result is False |
| 427 | + # The external file and the symlink are left intact. |
| 428 | + assert external.read_text() == "# external\n" |
| 429 | + assert (project / "KIMI.md").is_symlink() |
| 430 | + assert not (project / "AGENTS.md").exists() |
| 431 | + |
347 | 432 |
|
348 | 433 | class TestKimiNextSteps: |
349 | 434 | """CLI output tests for kimi next-steps display.""" |
|
0 commit comments