Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
feat(workspace): read Dapr pub/sub topics in .NET and Subscription manifests (#4729)
Thymeede2f9e60aacbe
diff --git a/docs/architecture/language-support.md b/docs/architecture/language-support.mdindex ef1c7627a..da8027d9a 100644--- a/docs/architecture/language-support.md+++ b/docs/architecture/language-support.md@@ -1312,7 +1312,7 @@ mislead the masker.|----------|-----------|-----------|| **HTTP** | Express, Hono, Fastify, Koa, Elysia, NestJS, Next.js, Remix, FastAPI, Flask, Django, Spring, JAX-RS, Micronaut, Laravel, Go, ASP.NET, Axum/Actix/Rocket, OpenAPI 3.x | Client calls in JS/TS, Python, PHP, Java, Kotlin, Go, C#, Ruby and Rust; JS/TS client instances carry their base URL across files || **gRPC** | `.proto` IDL, Go, Java (bare or package-qualified `ImplBase`), Python, NestJS (`@GrpcMethod`), Node grpc-js (`server.addService(X.service)`), C# (gRPC-dotnet, primary-constructor impls too) | Go, Java, Python, C# (`new X.XClient(...)`, `AddGrpcClient<X.XClient>`, and the class the client is injected into) |-| **Topic** | Kafka (Spring `KafkaTemplate` under any name, kafka-clients `ProducerRecord`, kafkajs, kafka-python, aiokafka, confluent-kafka for Python and .NET, Go sarama, segmentio/kafka-go and franz-go), RabbitMQ (Spring AMQP, amqplib, pika, php-amqplib), NATS (nats.go, jnats, nats.js, nats-py; read only in a file importing one), Redis pub/sub, BullMQ / Bull, SQS / SNS, NestJS `ClientProxy`, Laravel job dispatch | The same libraries' consumers (including pattern subscriptions and Laravel `ShouldQueue` classes), plus RabbitMQ queue bindings |+| **Topic** | Kafka (Spring `KafkaTemplate` under any name, kafka-clients `ProducerRecord`, kafkajs, kafka-python, aiokafka, confluent-kafka for Python and .NET, Go sarama, segmentio/kafka-go and franz-go), RabbitMQ (Spring AMQP, amqplib, pika, php-amqplib), NATS (nats.go, jnats, nats.js, nats-py; read only in a file importing one), Redis pub/sub, BullMQ / Bull, SQS / SNS, NestJS `ClientProxy`, Dapr `PublishEventAsync` (C#), Laravel job dispatch | The same libraries' consumers (including pattern subscriptions, Dapr `[Topic]` and `Subscription` manifests, and Laravel `ShouldQueue` classes), plus RabbitMQ queue bindings || **Socket** | SignalR `MapHub`, FastAPI `@app.websocket`, `ws`, NestJS gateways; socket.io `emit`, Laravel broadcast events, Pusher `trigger` | ClientWebSocket, SignalR client, NativeWebSocket, WebSocketSharp, `new WebSocket(url)`; socket.io `on`, Laravel Echo, pusher-js || **Data** | DDL `CREATE`/`ALTER`, Alembic `op.create_table`, Laravel `Schema::create`/`Schema::table`, Knex migrations, ORM models (SQLAlchemy, SQLModel, Django, JPA, EF Core, ActiveRecord, Eloquent, Prisma, TypeORM, Sequelize, Drizzle) | SQL string literals in app code (sqlglot-parsed, verb-anchored-regex fallback), Laravel `DB::table`, Knex queries || **Topic (C# integration events)** | `IntegrationEvent` subclasses constructed and passed to a publish call, keyed by short type name | `AddSubscription<T, TH>`, `Subscribe<T, TH>`, `IIntegrationEventHandler<T>` |diff --git a/docs/scale/WORKSPACES.md b/docs/scale/WORKSPACES.mdindex 0f2cc510b..82f8e9aad 100644--- a/docs/scale/WORKSPACES.md+++ b/docs/scale/WORKSPACES.md@@ -168,7 +168,7 @@ Scans source files for HTTP routes, gRPC services, database tables, message topi| Type | Providers | Consumers ||------|-----------|-----------|| gRPC | `.proto` service definitions, plus per-language dialects (Go, Java, Python, C#, TypeScript, NestJS `@GrpcMethod`) | gRPC client stubs |-| Topics | Kafka (Spring `KafkaTemplate` under any name, kafka-clients `ProducerRecord`, kafkajs, kafka-python, aiokafka, confluent-kafka for Python and .NET, Go sarama, segmentio/kafka-go and franz-go), RabbitMQ (Spring AMQP, amqplib, pika, php-amqplib), NATS (nats.go, jnats, nats.js, nats-py; read only in a file importing one), Redis pub/sub (ioredis/node-redis, redis-py, Laravel `Redis::publish`), BullMQ / Bull (`new Queue`, `@InjectQueue`, flows), SQS and SNS (AWS SDK v2/v3, boto3), NestJS `ClientProxy.emit`/`send`, MassTransit `Publish`/`Send`/`IRequestClient` (C#, VB.NET), Laravel job dispatch (`X::dispatch()->onQueue()`, `dispatch()`, `Queue::push*`, scheduled jobs) | The corresponding consumers (`new Worker`, `@Processor`, `ReceiveMessageCommand`, sqs-consumer, `subscribe`/`psubscribe`, `@EventPattern`/`@MessagePattern`, Laravel `ShouldQueue` classes on the queues they run on, MassTransit `IConsumer<T>`, open-generic consumers and saga events), plus RabbitMQ queue bindings (`bindQueue`, `queue_bind`) |+| Topics | Kafka (Spring `KafkaTemplate` under any name, kafka-clients `ProducerRecord`, kafkajs, kafka-python, aiokafka, confluent-kafka for Python and .NET, Go sarama, segmentio/kafka-go and franz-go), RabbitMQ (Spring AMQP, amqplib, pika, php-amqplib), NATS (nats.go, jnats, nats.js, nats-py; read only in a file importing one), Redis pub/sub (ioredis/node-redis, redis-py, Laravel `Redis::publish`), BullMQ / Bull (`new Queue`, `@InjectQueue`, flows), SQS and SNS (AWS SDK v2/v3, boto3), NestJS `ClientProxy.emit`/`send`, Dapr `DaprClient.PublishEventAsync` (C#), MassTransit `Publish`/`Send`/`IRequestClient` (C#, VB.NET), Laravel job dispatch (`X::dispatch()->onQueue()`, `dispatch()`, `Queue::push*`, scheduled jobs) | The corresponding consumers (`new Worker`, `@Processor`, `ReceiveMessageCommand`, sqs-consumer, `subscribe`/`psubscribe`, `@EventPattern`/`@MessagePattern`, Dapr `[Topic]` and `kind: Subscription` manifests, Laravel `ShouldQueue` classes on the queues they run on, MassTransit `IConsumer<T>`, open-generic consumers and saga events), plus RabbitMQ queue bindings (`bindQueue`, `queue_bind`) || Socket / WebSocket | SignalR `MapHub<T>("/path")`, FastAPI `@app.websocket("/path")`, `ws` `WebSocketServer({ path })`, NestJS `@WebSocketGateway`; events: socket.io `emit` (server and client), Laravel broadcast events (`broadcastOn` / `broadcastAs`), `Broadcast::on`, Pusher `trigger` | ClientWebSocket `ConnectAsync`, SignalR `HubConnectionBuilder.WithUrl`, NativeWebSocket and WebSocketSharp `new WebSocket(...)`, browser/Node `new WebSocket(url)`; events: socket.io `on` / `@SubscribeMessage`, Laravel Echo `listen` and `useEcho`, pusher-js `bind` || Topics: C# integration events | `new T(...)` of an `IntegrationEvent` subclass the repo declares, reaching `PublishAsync` / `Publish` or a repo method taking an `IntegrationEvent`; the id is the short type name, which the event bus routes by | `AddSubscription<T, TH>()`, `Subscribe<T, TH>()` on a declared event, and `IIntegrationEventHandler<T>` classes for events no registration subscribes || Topics: JMS | Spring `JmsTemplate` / `JmsMessagingTemplate` `convertAndSend` / `send` / `sendAndReceive` / `convertSendAndReceive` on a receiver named for JMS (`jmsTemplate`, `orderJmsTemplate`, `getJmsTemplate()`) with a destination argument; ActiveMQ and IBM MQ `queue://` names read as the bare queue | `@JmsListener(destination = ...)`, `receive` / `receiveAndConvert`, `DefaultMessageListenerContainer.setDestinationName` |diff --git a/packages/core/src/repowise/core/workspace/extractors/topic/__init__.py b/packages/core/src/repowise/core/workspace/extractors/topic/__init__.pyindex 68d356d97..c3ff3dd1a 100644--- a/packages/core/src/repowise/core/workspace/extractors/topic/__init__.py+++ b/packages/core/src/repowise/core/workspace/extractors/topic/__init__.py@@ -15,6 +15,7 @@ from .aws import SNS, SQSfrom .azure_servicebus import AZURE_SERVICE_BUSfrom .bullmq import BULLMQfrom .csharp_events import CSHARP_EVENTS+from .dapr import DAPR, DAPR_SUBSCRIPTIONSfrom .dialect import topic_identityfrom .jms import JMSfrom .kafka import KAFKA@@ -37,6 +38,8 @@ DIALECTS: tuple[ContractDialect, ...] = (SNS,AZURE_SERVICE_BUS,NESTJS,+ DAPR,+ DAPR_SUBSCRIPTIONS,LARAVEL_QUEUES,CSHARP_EVENTS,JMS,diff --git a/packages/core/src/repowise/core/workspace/extractors/topic/dapr.py b/packages/core/src/repowise/core/workspace/extractors/topic/dapr.pynew file mode 100644index 000000000..ccd592d3f--- /dev/null+++ b/packages/core/src/repowise/core/workspace/extractors/topic/dapr.py@@ -0,0 +1,115 @@+"""Dapr pub/sub: a topic named on a component, which runs over any broker.++``[Topic("pubsub", "orders")]`` subscribes a handler and+``daprClient.PublishEventAsync("pubsub", "orders", evt)`` publishes. The first+argument is the pub/sub component, the second the topic, so the topic is read+from position 1. ``PublishEventAsync`` is too common to read on any receiver,+so it is read only on the names the file declares as a ``DaprClient``.+"""++from __future__ import annotations++import re+from typing import TYPE_CHECKING++import yaml++from repowise.core.workspace.contracts import TOPIC_KIND_TOPIC+from repowise.core.workspace.origins import ContractOrigin++from ..langs import CSHARP+from ..strings import Arg+from .dialect import ReceiverCall, TopicCall, TopicDialect, topic_contract++if TYPE_CHECKING:+ from repowise.core.workspace.contracts import Contract++ from ..base import ScanContext+++_DAPR = ("Dapr",)+_TOPIC = Arg(keys=("name", "topicName"), pos=1)++DAPR = TopicDialect(+ name="dapr",+ receivers=(+ ReceiverCall(+ types=re.compile(r"\bDaprClient\b"),+ verbs=r"PublishEventAsync(?:\s*<[^>()]*>)?",+ role="provider",+ label="PublishEventAsync",+ extensions=CSHARP,+ name=_TOPIC,+ requires=_DAPR,+ ),+ ),+ calls=(+ TopicCall(+ head=re.compile(r"\[\s*Topic\s*\("),+ role="consumer",+ label="[Topic]",+ extensions=CSHARP,+ name=_TOPIC,+ requires=_DAPR,+ ),+ ),+)++_MANIFEST_EXTENSIONS = frozenset({".yaml", ".yml"})+++class DaprSubscriptionDialect:+ """A ``kind: Subscription`` manifest names the topic its handler route serves."""++ name = "dapr_subscriptions"+ extensions = _MANIFEST_EXTENSIONS+ requires = ("dapr.io",)++ def extract(self, ctx: ScanContext) -> list[Contract]:+ try:+ docs = list(yaml.safe_load_all(ctx.content))+ except (yaml.YAMLError, RecursionError):+ return []+ out: list[Contract] = []+ cursor = 0 # documents come in file order, so each topic is found after the last+ for doc in docs:+ topic = _subscription_topic(doc)+ if not topic:+ continue+ found = re.compile(rf"^\s*topic\s*:\s*['\"]?{re.escape(topic)}", re.M).search(+ ctx.content, cursor+ )+ offset = found.start() if found else cursor+ cursor = found.end() if found else cursor+ out.append(+ topic_contract(+ ctx,+ name=topic,+ broker="dapr",+ kind=TOPIC_KIND_TOPIC,+ role="consumer",+ label="Subscription",+ origin=ContractOrigin.IDL,+ offset=offset,+ )+ )+ return out+++def _subscription_topic(doc: object) -> str | None:+ """The ``spec.topic`` of a Dapr ``Subscription`` document, or None for any other."""+ if not isinstance(doc, dict):+ return None+ api_version = doc.get("apiVersion")+ if doc.get("kind") != "Subscription" or not (+ isinstance(api_version, str) and api_version.startswith("dapr.io/")+ ):+ return None+ spec = doc.get("spec")+ topic = spec.get("topic") if isinstance(spec, dict) else None+ return topic if isinstance(topic, str) else None+++DAPR_SUBSCRIPTIONS = DaprSubscriptionDialect()++__all__ = ["DAPR", "DAPR_SUBSCRIPTIONS"]diff --git a/packages/core/src/repowise/core/workspace/matching/topic.py b/packages/core/src/repowise/core/workspace/matching/topic.pyindex 517ab1d8d..f11da0258 100644--- a/packages/core/src/repowise/core/workspace/matching/topic.py+++ b/packages/core/src/repowise/core/workspace/matching/topic.py@@ -116,12 +116,12 @@ def matching_keys(consumer: Contract, provider_index: dict[str, list[Contract]])# Brokers that meet only their own kind: a BullMQ queue is a set of Redis keys-# only BullMQ reads. Laravel and NestJS name a queue or pattern whose transport-# is configured outside the code (RabbitMQ, SQS, Redis, Kafka, NATS), so either-# meets any broker but those. Every other pair must be the same broker: a Kafka-# topic and a RabbitMQ queue that share a name are two things.+# only BullMQ reads. Laravel, NestJS, and Dapr name a queue, pattern, or topic whose+# transport is configured outside the code (RabbitMQ, SQS, Redis, Kafka, NATS), so+# either meets any broker but those. Every other pair must be the same broker: a+# Kafka topic and a RabbitMQ queue that share a name are two things._OWN_KIND_ONLY = frozenset({"bullmq"})-_ANY_TRANSPORT = frozenset({"laravel", "nestjs"})+_ANY_TRANSPORT = frozenset({"laravel", "nestjs", "dapr"})def same_transport(provider: Contract, consumer: Contract) -> bool:diff --git a/tests/unit/workspace/test_async_links.py b/tests/unit/workspace/test_async_links.pyindex 313bbb8d8..a1d4d5c69 100644--- a/tests/unit/workspace/test_async_links.py+++ b/tests/unit/workspace/test_async_links.py@@ -114,6 +114,36 @@ def test_a_nestjs_object_pattern_across_repos(tmp_path: Path) -> None:assert _links(api, math) == {("api", "math", 'topic::{"cmd":"sum","role":"math"}')}+_DAPR_PUBLISH = (+ "using Dapr.Client;\n"+ "private readonly DaprClient dapr;\n"+ 'await dapr.PublishEventAsync("pubsub", "orders", evt);\n'+)+_DAPR_SUBSCRIPTION = (+ "apiVersion: dapr.io/v2alpha1\n"+ "kind: Subscription\n"+ "metadata: \n"+ " name: orders\n"+ "spec: \n"+ " pubsubname: pubsub\n"+ " topic: orders\n"+ " routes: \n"+ " default: /orders\n"+)+++def test_a_dapr_publisher_reaches_a_kafka_consumer(tmp_path: Path) -> None:+ api = _repo(tmp_path, "api", {"Pub.cs": _DAPR_PUBLISH})+ worker = _repo(tmp_path, "worker", {"c.ts": "await consumer.subscribe({ topic: 'orders' });\n"})+ assert _links(api, worker) == {("api", "worker", "topic::orders")}+++def test_a_dapr_subscription_manifest_reaches_a_dapr_publisher(tmp_path: Path) -> None:+ api = _repo(tmp_path, "api", {"Pub.cs": _DAPR_PUBLISH})+ billing = _repo(tmp_path, "billing", {"deploy/sub.yaml": _DAPR_SUBSCRIPTION})+ assert _links(api, billing) == {("api", "billing", "topic::orders")}++def test_fastapi_websocket_to_browser(tmp_path: Path) -> None:api = _repo(tmp_path, "api", {"ws.py": '@app.websocket("/ws/chat/{room_id}")\nasync def chat(): ...\n'})web = _repo(tmp_path, "web", {"c.ts": "new WebSocket(`wss://${host}/ws/chat/${room}`);\n"})diff --git a/tests/unit/workspace/test_topic_dialects.py b/tests/unit/workspace/test_topic_dialects.pyindex c8c3eddd2..243a9e3f9 100644--- a/tests/unit/workspace/test_topic_dialects.py+++ b/tests/unit/workspace/test_topic_dialects.py@@ -607,6 +607,71 @@ class TestNestMicroservices:assert _extract(tmp_path, "c.ts", "@EventPattern('x')\nf() {}\n") == []+class TestDapr:+ _USING = "using Dapr;\nusing Dapr.Client;\n"++ def test_topic_attribute_is_a_consumer(self, tmp_path: Path) -> None:+ src = self._USING + '[Topic("pubsub", "orders")]\npublic Task Handle(OrderPlaced e) { }\n'+ c = _one(_extract(tmp_path, "Orders.cs", src), "consumer")+ assert (c.contract_id, c.meta["broker"]) == ("topic::orders", "dapr")++ def test_publish_event_on_a_dapr_client_is_a_provider(self, tmp_path: Path) -> None:+ src = (+ self._USING+ + "private readonly DaprClient daprClient;\n"+ + 'await daprClient.PublishEventAsync("pubsub", "orders", evt);\n'+ )+ c = _one(_extract(tmp_path, "Pub.cs", src), "provider")+ assert (c.contract_id, c.meta["broker"]) == ("topic::orders", "dapr")++ def test_publish_event_on_another_receiver_is_not_read(self, tmp_path: Path) -> None:+ src = self._USING + 'await bus.PublishEventAsync("pubsub", "orders", evt);\n'+ assert _extract(tmp_path, "Other.cs", src) == []++ def test_topic_attribute_needs_the_dapr_import(self, tmp_path: Path) -> None:+ src = '[Topic("pubsub", "orders")]\npublic Task Handle(OrderPlaced e) { }\n'+ assert _extract(tmp_path, "NoDapr.cs", src) == []++ def test_a_named_topic_name_argument_is_read(self, tmp_path: Path) -> None:+ src = (+ self._USING+ + "private readonly DaprClient dapr;\n"+ + 'await dapr.PublishEventAsync("pubsub", topicName: "orders", evt);\n'+ )+ c = _one(_extract(tmp_path, "Named.cs", src), "provider")+ assert c.contract_id == "topic::orders"++ _SUBSCRIPTION = (+ "apiVersion: dapr.io/v2alpha1\n"+ "kind: Subscription\n"+ "metadata: \n"+ " name: order-sub\n"+ "spec:\n"+ " pubsubname: pubsub\n"+ " topic: orders\n"+ " routes: \n"+ " default: /orders\n"+ )++ def test_a_subscription_manifest_is_a_consumer(self, tmp_path: Path) -> None:+ c = _one(_extract(tmp_path, "deploy/sub.yaml", self._SUBSCRIPTION), "consumer")+ assert (c.contract_id, c.meta["broker"], c.line) == ("topic::orders", "dapr", 7)++ def test_every_subscription_in_a_multi_document_file_is_read(self, tmp_path: Path) -> None:+ other = self._SUBSCRIPTION.replace("orders", "refunds")+ rows = _extract(tmp_path, "sub.yml", self._SUBSCRIPTION + "---\n" + other)+ assert {c.contract_id for c in rows} == {"topic::orders", "topic::refunds"}++ def test_only_a_dapr_subscription_is_read(self, tmp_path: Path) -> None:+ component = self._SUBSCRIPTION.replace("Subscription", "Component")+ foreign = self._SUBSCRIPTION.replace("dapr.io/v2alpha1", "example.com/v1")+ assert _extract(tmp_path, "component.yaml", component) == []+ assert _extract(tmp_path, "foreign.yaml", foreign) == []++ def test_a_broken_manifest_is_skipped(self, tmp_path: Path) -> None:+ assert _extract(tmp_path, "bad.yaml", "dapr.io: [unclosed\n kind: Subscription") == []++class TestKafkaByReceiverType:"""A client read on whatever name the file declares it with."""diff --git a/tests/unit/workspace/test_topic_matching.py b/tests/unit/workspace/test_topic_matching.pyindex 3ebe8daec..8e5c4160a 100644--- a/tests/unit/workspace/test_topic_matching.py+++ b/tests/unit/workspace/test_topic_matching.py@@ -269,6 +269,10 @@ class TestTransports:("laravel", "rabbitmq", True),("rabbitmq", "laravel", True),("nestjs", "kafka", True),+ ("dapr", "kafka", True),+ ("rabbitmq", "dapr", True),+ ("dapr", "dapr", True),+ ("dapr", "bullmq", False),("laravel", "bullmq", False),("redis", "bullmq", False),("bullmq", "bullmq", True),