Understand any codebase instantly. System intelligence for codebases, built for humans and AI.
TypeScript aiai-memoryclaude-codeclicode-analysiscode-mappingcode-memorycodebase-understandingcodexdeveloper-toolsllmopenclawpersistent-memoryprogram-analysissoftware-architecturesystem-intelligencesystem-mapping
fix: address review issues — provenance perf, path traversal, diff stub, ingest test
riley0227097b7f037abc
diff --git a/memory-layer/src/main/scala/ix/memory/api/DiffRoutes.scala b/memory-layer/src/main/scala/ix/memory/api/DiffRoutes.scalaindex bc920340..db6c1f32 100644--- a/memory-layer/src/main/scala/ix/memory/api/DiffRoutes.scala+++ b/memory-layer/src/main/scala/ix/memory/api/DiffRoutes.scala@@ -54,8 +54,9 @@ class DiffRoutes(queryApi: GraphQueryApi) {result <- diffEntity(tenantId, eid, Rev(body.fromRev), Rev(body.toRev))} yield result.toVectorcase None =>- // Diff all entities that changed between the two revisions- diffAllEntities(tenantId, Rev(body.fromRev), Rev(body.toRev))+ IO.raiseError(new UnsupportedOperationException(+ "Diff without entityId is not yet supported. Please provide an entityId."+ ))}resp <- Ok(DiffResponse(body.fromRev, body.toRev, changes))} yield resp).handleErrorWith(ErrorHandler.handle(_))@@ -80,17 +81,4 @@ class DiffRoutes(queryApi: GraphQueryApi) {}}- private def diffAllEntities(tenant: TenantId, fromRev: Rev, toRev: Rev): IO[Vector[DiffEntry]] = {- // Find all nodes that were created or modified between fromRev and toRev- // by looking at nodes with created_rev in (fromRev, toRev] or deleted_rev in (fromRev, toRev]- for {- // Get nodes visible at fromRev- fromNodes <- queryApi.findNodesByKind(tenant, NodeKind.Function, limit = 1000)- .flatMap(_ => queryApi.searchNodes(tenant, "", limit = 0))- .handleErrorWith(_ => IO.pure(Vector.empty[GraphNode]))-- // Instead of full scan, just return an empty diff for the "all entities" case- // This is a simplification — a full implementation would query patches between revisions- } yield Vector.empty[DiffEntry]- }}diff --git a/memory-layer/src/main/scala/ix/memory/api/EntityRoutes.scala b/memory-layer/src/main/scala/ix/memory/api/EntityRoutes.scalaindex 749c2847..51c20ead 100644--- a/memory-layer/src/main/scala/ix/memory/api/EntityRoutes.scala+++ b/memory-layer/src/main/scala/ix/memory/api/EntityRoutes.scala@@ -10,7 +10,7 @@ import org.http4s.HttpRoutesimport org.http4s.circe.CirceEntityCodec._import org.http4s.dsl.io._-import ix.memory.db.{ArangoClient, Direction, GraphQueryApi}+import ix.memory.db.{Direction, GraphQueryApi}import ix.memory.model._case class EntityResponse(node: GraphNode, claims: Vector[Claim], edges: Vector[GraphEdge])@@ -31,7 +31,7 @@ object ProvenanceResponse {implicit val encoder: Encoder[ProvenanceResponse] = deriveEncoder[ProvenanceResponse]}-class EntityRoutes(queryApi: GraphQueryApi, client: ArangoClient) {+class EntityRoutes(queryApi: GraphQueryApi) {val routes: HttpRoutes[IO] = HttpRoutes.of[IO] {@@ -72,44 +72,27 @@ class EntityRoutes(queryApi: GraphQueryApi, client: ArangoClient) {}private def queryProvenanceChain(tenant: TenantId, nodeId: NodeId): IO[Vector[ProvenanceEntry]] =- client.query(- """FOR p IN patches- | FILTER p.tenant == @tenant- | SORT p.rev ASC- | RETURN p""".stripMargin,- Map(- "tenant" -> tenant.value.toString.asInstanceOf[AnyRef]- )- ).map { jsons =>+ queryApi.getPatchesForEntity(tenant, nodeId).map { jsons =>jsons.flatMap { json =>val c = json.hcursorval dataC = c.downField("data")- // Check if this patch contains ops referencing our entity- val ops = dataC.downField("ops").focus.flatMap(_.asArray).getOrElse(Vector.empty)- val touchesEntity = ops.exists { op =>- val opC = op.hcursor- opC.get[String]("id").toOption.contains(nodeId.value.toString) ||- opC.get[String]("entityId").toOption.contains(nodeId.value.toString)- }- if (touchesEntity) {- for {- patchIdStr <- dataC.get[String]("patchId").toOption- .orElse(c.get[String]("patch_id").toOption)- patchId <- scala.util.Try(UUID.fromString(patchIdStr)).toOption.map(PatchId(_))- rev <- c.get[Long]("rev").toOption.map(Rev(_))- sourceUri <- dataC.downField("source").get[String]("uri").toOption- sourceHash = dataC.downField("source").get[String]("sourceHash").toOption- extractor <- dataC.downField("source").get[String]("extractor").toOption- stStr <- dataC.downField("source").get[String]("sourceType").toOption- sourceType <- SourceType.decoder.decodeJson(Json.fromString(stStr)).toOption- intent = dataC.get[String]("intent").toOption- } yield ProvenanceEntry(- patchId = patchId,- rev = rev,- source = PatchSource(sourceUri, sourceHash, extractor, sourceType),- intent = intent- )- } else None+ for {+ patchIdStr <- dataC.get[String]("patchId").toOption+ .orElse(c.get[String]("patch_id").toOption)+ patchId <- scala.util.Try(UUID.fromString(patchIdStr)).toOption.map(PatchId(_))+ rev <- c.get[Long]("rev").toOption.map(Rev(_))+ sourceUri <- dataC.downField("source").get[String]("uri").toOption+ sourceHash = dataC.downField("source").get[String]("sourceHash").toOption+ extractor <- dataC.downField("source").get[String]("extractor").toOption+ stStr <- dataC.downField("source").get[String]("sourceType").toOption+ sourceType <- SourceType.decoder.decodeJson(Json.fromString(stStr)).toOption+ intent = dataC.get[String]("intent").toOption+ } yield ProvenanceEntry(+ patchId = patchId,+ rev = rev,+ source = PatchSource(sourceUri, sourceHash, extractor, sourceType),+ intent = intent+ )}.toVector}}diff --git a/memory-layer/src/main/scala/ix/memory/api/IngestionRoutes.scala b/memory-layer/src/main/scala/ix/memory/api/IngestionRoutes.scalaindex 61967ce5..bbec9ee6 100644--- a/memory-layer/src/main/scala/ix/memory/api/IngestionRoutes.scala+++ b/memory-layer/src/main/scala/ix/memory/api/IngestionRoutes.scala@@ -34,6 +34,9 @@ class IngestionRoutes(ingestionService: IngestionService) {(for {body <- req.as[IngestRequest]tenantId <- IO.fromTry(scala.util.Try(UUID.fromString(body.tenant))).map(TenantId(_))+ _ <- IO.raiseWhen(body.path.contains(".."))(+ new IllegalArgumentException("Path traversal not allowed")+ )path = Paths.get(body.path)result <- ingestionService.ingestPath(tenantId, path, body.language, body.recursive.getOrElse(false))resp <- Ok(IngestResponse(diff --git a/memory-layer/src/main/scala/ix/memory/api/Routes.scala b/memory-layer/src/main/scala/ix/memory/api/Routes.scalaindex 101aa5e3..107ad341 100644--- a/memory-layer/src/main/scala/ix/memory/api/Routes.scala+++ b/memory-layer/src/main/scala/ix/memory/api/Routes.scala@@ -30,7 +30,7 @@ object Routes {val contextRoutes = new ContextRoutes(contextService).routesval ingestionRoutes = new IngestionRoutes(ingestionService).routes- val entityRoutes = new EntityRoutes(queryApi, client).routes+ val entityRoutes = new EntityRoutes(queryApi).routesval diffRoutes = new DiffRoutes(queryApi).routesval conflictRoutes = new ConflictRoutes(conflictService).routesdiff --git a/memory-layer/src/main/scala/ix/memory/db/ArangoGraphQueryApi.scala b/memory-layer/src/main/scala/ix/memory/db/ArangoGraphQueryApi.scalaindex 7ff8bf1b..212caeb3 100644--- a/memory-layer/src/main/scala/ix/memory/db/ArangoGraphQueryApi.scala+++ b/memory-layer/src/main/scala/ix/memory/db/ArangoGraphQueryApi.scala@@ -171,6 +171,25 @@ class ArangoGraphQueryApi(client: ArangoClient) extends GraphQueryApi {Map("key" -> tenant.value.toString.asInstanceOf[AnyRef])).map(_.flatMap(_.as[Long].toOption).map(Rev(_)).getOrElse(Rev(0L)))+ override def getPatchesForEntity(tenant: TenantId, entityId: NodeId): IO[List[Json]] = {+ val nodeIdStr = entityId.value.toString+ client.query(+ """FOR p IN patches+ | FILTER p.tenant == @tenant+ | FILTER LENGTH(+ | FOR op IN (IS_ARRAY(p.data.ops) ? p.data.ops : [])+ | FILTER op.id == @nodeId OR op.entityId == @nodeId+ | RETURN 1+ | ) > 0+ | SORT p.rev ASC+ | RETURN p""".stripMargin,+ Map(+ "tenant" -> tenant.value.toString.asInstanceOf[AnyRef],+ "nodeId" -> nodeIdStr.asInstanceOf[AnyRef]+ )+ )+ }+// ── JSON Parsers (snake_case → camelCase) ───────────────────────────private def parseNode(json: Json): Option[GraphNode] = {diff --git a/memory-layer/src/main/scala/ix/memory/db/GraphQueryApi.scala b/memory-layer/src/main/scala/ix/memory/db/GraphQueryApi.scalaindex 81979e89..ec1a1977 100644--- a/memory-layer/src/main/scala/ix/memory/db/GraphQueryApi.scala+++ b/memory-layer/src/main/scala/ix/memory/db/GraphQueryApi.scala@@ -1,6 +1,7 @@package ix.memory.dbimport cats.effect.IO+import io.circe.Jsonimport ix.memory.model._trait GraphQueryApi {@@ -12,6 +13,7 @@ trait GraphQueryApi {asOfRev: Option[Rev] = None): IO[ExpandResult]def getClaims(tenant: TenantId, entityId: NodeId): IO[Vector[Claim]]def getLatestRev(tenant: TenantId): IO[Rev]+ def getPatchesForEntity(tenant: TenantId, entityId: NodeId): IO[List[Json]]}sealed trait Directiondiff --git a/memory-layer/src/test/scala/ix/memory/api/RoutesSpec.scala b/memory-layer/src/test/scala/ix/memory/api/RoutesSpec.scalaindex b9666798..7cd28809 100644--- a/memory-layer/src/test/scala/ix/memory/api/RoutesSpec.scala+++ b/memory-layer/src/test/scala/ix/memory/api/RoutesSpec.scala@@ -273,7 +273,91 @@ class RoutesSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {}}- // ── Test 9: POST /v1/provenance/:id returns provenance chain ─────────+ // ── Test 9: POST /v1/ingest ingests a Python file ─────────────────────++ it should "ingest a Python file and return counts" in {+ clientResource.use { client =>+ val writeApi = new ArangoGraphWriteApi(client)+ val queryApi = new ArangoGraphQueryApi(client)+ val app = buildRoutes(client, writeApi, queryApi)+ val tenant = TenantId(UUID.randomUUID())++ for {+ _ <- client.ensureSchema()+ tmpFile <- IO.blocking {+ val f = java.nio.file.Files.createTempFile("ix-test-", ".py")+ java.nio.file.Files.writeString(f,+ """def hello():+ | return "world"+ |""".stripMargin+ )+ f+ }+ ingestReq = Json.obj(+ "path" -> tmpFile.toAbsolutePath.toString.asJson,+ "tenant" -> tenant.value.toString.asJson+ )+ req = Request[IO](Method.POST, uri"/v1/ingest").withEntity(ingestReq)+ resp <- app.run(req)+ body <- resp.as[Json]+ _ <- IO.blocking(java.nio.file.Files.deleteIfExists(tmpFile))+ } yield {+ resp.status shouldBe Status.Ok+ body.hcursor.get[Int]("filesProcessed").toOption should not be empty+ body.hcursor.get[Int]("patchesApplied").toOption should not be empty+ body.hcursor.get[Long]("latestRev").toOption should not be empty+ }+ }+ }++ // ── Test 10: POST /v1/ingest rejects path traversal ────────────────++ it should "return 400 for path traversal attempt" in {+ clientResource.use { client =>+ val writeApi = new ArangoGraphWriteApi(client)+ val queryApi = new ArangoGraphQueryApi(client)+ val app = buildRoutes(client, writeApi, queryApi)+ val tenant = TenantId(UUID.randomUUID())++ for {+ _ <- client.ensureSchema()+ ingestReq = Json.obj(+ "path" -> "/tmp/../etc/passwd".asJson,+ "tenant" -> tenant.value.toString.asJson+ )+ req = Request[IO](Method.POST, uri"/v1/ingest").withEntity(ingestReq)+ resp <- app.run(req)+ } yield {+ resp.status shouldBe Status.BadRequest+ }+ }+ }++ // ── Test 11: POST /v1/diff returns 422 without entityId ─────────────++ it should "return 422 for diff without entityId" in {+ clientResource.use { client =>+ val writeApi = new ArangoGraphWriteApi(client)+ val queryApi = new ArangoGraphQueryApi(client)+ val app = buildRoutes(client, writeApi, queryApi)+ val tenant = TenantId(UUID.randomUUID())++ for {+ _ <- client.ensureSchema()+ diffReq = Json.obj(+ "tenant" -> tenant.value.toString.asJson,+ "fromRev" -> 0L.asJson,+ "toRev" -> 1L.asJson+ )+ req = Request[IO](Method.POST, uri"/v1/diff").withEntity(diffReq)+ resp <- app.run(req)+ } yield {+ resp.status shouldBe Status.UnprocessableEntity+ }+ }+ }++ // ── Test 12: POST /v1/provenance/:id returns provenance chain ─────────it should "return provenance chain for entity" in {clientResource.use { client =>