From 218ee2989356351097ed09bbd820622a9c7111ed Mon Sep 17 00:00:00 2001 From: taiph9 Date: Mon, 31 Aug 2026 15:23:07 +0900 Subject: [PATCH] fix: sua test target resolver khop voi hanh vi fallback that --- tests/test_project_context_issue.py | 33 +++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/tests/test_project_context_issue.py b/tests/test_project_context_issue.py index b22b000..7fd6829 100644 --- a/tests/test_project_context_issue.py +++ b/tests/test_project_context_issue.py @@ -440,16 +440,41 @@ def test_project_without_repo_mapping_returns_unavailable( assert result.payload["error"]["code"] == "UNAVAILABLE" -def test_target_resolver_rejects_project_only_mapping( +def test_target_resolver_falls_back_to_legacy_project_only_mapping( identity: IdentityContext, monkeypatch: pytest.MonkeyPatch, ) -> None: + """Backward compatibility: a repo map keyed only by `project` — the + format already documented and deployed for the pilot (see + PLAYBOOK_COWORK_LOCAL_MCP_PILOT.md) — must still resolve, even though + new deployments should prefer the composite `org_unit/customer/project` + key so two different customers never collide on the same project name.""" monkeypatch.setenv("GITEA_BASE_URL", "http://example.test") monkeypatch.setenv("PROJECT_CONTEXT_REPO_MAP", '{"cowork-local": "gitea-admin/cowork-local"}') - with pytest.raises(ProviderError) as exc_info: - EnvironmentTargetResolver().resolve(identity) + target = EnvironmentTargetResolver().resolve(identity) - assert exc_info.value.code == "UNAVAILABLE" + assert target.owner == "gitea-admin" + assert target.repo == "cowork-local" + + +def test_target_resolver_prefers_composite_key_over_legacy_project_key( + identity: IdentityContext, monkeypatch: pytest.MonkeyPatch, +) -> None: + """When BOTH a composite `org_unit/customer/project` key and a legacy + project-only key exist in the map, the composite key must win — this is + what actually prevents a cross-customer collision, since two customers + sharing a project name would otherwise both match the same legacy key.""" + monkeypatch.setenv("GITEA_BASE_URL", "http://example.test") + monkeypatch.setenv( + "PROJECT_CONTEXT_REPO_MAP", + '{"cowork-local": "wrong/legacy", ' + '"fsg/internal/cowork-local": "gitea-admin/cowork-local"}', + ) + + target = EnvironmentTargetResolver().resolve(identity) + + assert target.owner == "gitea-admin" + assert target.repo == "cowork-local" def test_target_and_credential_resolution_are_separate(