fix: sua test target resolver khop voi hanh vi fallback that
CI / test (pull_request) Canceled after 0s

This commit is contained in:
2026-08-31 15:23:07 +09:00
parent e6847357aa
commit 218ee29893
+29 -4
View File
@@ -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(