Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

test: update all tests for no-tenant, versioned upserts, and new pipeline

riley0227268a7aabbfa1
diff --git a/build.sbt b/build.sbt
index f3d768a1..91ba6cf2 100644
--- a/build.sbt
+++ b/build.sbt
@@ -41,6 +41,9 @@ lazy val memoryLayer = (project in file("memory-layer"))
"org.typelevel" %% "cats-effect-testing-scalatest" % "1.5.0" % Test
),
+ // Run tests sequentially to avoid ArangoDB write-write conflicts on shared DB
+ Test / parallelExecution := false,
+
// Assembly settings
assembly / mainClass := Some("ix.memory.Main"),
assembly / assemblyJarName := "ix-memory-layer.jar",
diff --git a/memory-layer/src/test/scala/ix/memory/EndToEndSpec.scala b/memory-layer/src/test/scala/ix/memory/EndToEndSpec.scala
index c76a9966..25a1e539 100644
--- a/memory-layer/src/test/scala/ix/memory/EndToEndSpec.scala
+++ b/memory-layer/src/test/scala/ix/memory/EndToEndSpec.scala
@@ -15,7 +15,7 @@ import ix.memory.db._
import ix.memory.ingestion.{IngestionService, ParserRouter}
import ix.memory.model._
-class EndToEndSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
+class EndToEndSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers with TestDbHelper {
val clientResource = ArangoClient.resource(
host = "localhost", port = 8529,
@@ -65,6 +65,7 @@ class EndToEndSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
// Ingest the sample billing_service.py fixture
commit <- ingestion.ingestFile(fixtureFilePath)
// Query about billing retry
@@ -110,6 +111,7 @@ class EndToEndSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
// Step 1: Ingest billing_service.py (creates nodes for BillingService etc.)
commit1 <- ingestion.ingestFile(fixtureFilePath)
@@ -190,6 +192,7 @@ class EndToEndSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
// Step 1: Commit patch at rev N with billing_core node
patch1 = makePatch(
@@ -258,6 +261,7 @@ class EndToEndSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
// Step 1: First ingestion
commit1 <- ingestion.ingestFile(fixtureFilePath)
diff --git a/memory-layer/src/test/scala/ix/memory/TestDbHelper.scala b/memory-layer/src/test/scala/ix/memory/TestDbHelper.scala
new file mode 100644
index 00000000..9d618590
--- /dev/null
+++ b/memory-layer/src/test/scala/ix/memory/TestDbHelper.scala
@@ -0,0 +1,18 @@
+package ix.memory
+
+import cats.effect.IO
+import ix.memory.db.ArangoClient
+
+trait TestDbHelper {
+
+ /** Truncate all collections to ensure a clean state for each test. */
+ protected def cleanDatabase(client: ArangoClient): IO[Unit] = {
+ val collections = List(
+ "nodes", "edges", "claims", "patches",
+ "revisions", "idempotency_keys", "conflict_sets"
+ )
+ collections.foldLeft(IO.unit) { (acc, name) =>
+ acc >> client.execute(s"FOR doc IN $name REMOVE doc IN $name", Map.empty[String, AnyRef])
+ }
+ }
+}
diff --git a/memory-layer/src/test/scala/ix/memory/api/RoutesSpec.scala b/memory-layer/src/test/scala/ix/memory/api/RoutesSpec.scala
index 2c016a42..92589255 100644
--- a/memory-layer/src/test/scala/ix/memory/api/RoutesSpec.scala
+++ b/memory-layer/src/test/scala/ix/memory/api/RoutesSpec.scala
@@ -14,13 +14,14 @@ import org.http4s.implicits._
import org.scalatest.flatspec.AsyncFlatSpec
import org.scalatest.matchers.should.Matchers
+import ix.memory.TestDbHelper
import ix.memory.conflict.ConflictService
import ix.memory.context._
import ix.memory.db._
import ix.memory.ingestion.{IngestionService, ParserRouter}
import ix.memory.model._
-class RoutesSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
+class RoutesSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers with TestDbHelper {
val clientResource = ArangoClient.resource(
host = "localhost", port = 8529,
@@ -102,6 +103,7 @@ class RoutesSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
_ <- writeApi.commitPatch(patch)
req = Request[IO](Method.GET, Uri.unsafeFromString(s"/v1/entity/${nodeId.value}"))
resp <- app.run(req)
@@ -125,6 +127,7 @@ class RoutesSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
req = Request[IO](Method.GET, Uri.unsafeFromString(s"/v1/entity/$fakeId"))
resp <- app.run(req)
} yield {
@@ -143,6 +146,7 @@ class RoutesSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
req = Request[IO](Method.GET, Uri.unsafeFromString(s"/v1/conflicts"))
resp <- app.run(req)
body <- resp.as[Json]
@@ -169,6 +173,7 @@ class RoutesSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
result <- writeApi.commitPatch(patch)
diffReq = Json.obj(
"fromRev" -> 0L.asJson,
@@ -197,6 +202,7 @@ class RoutesSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
diffReq = Json.obj(
"fromRev" -> 5L.asJson,
"toRev" -> 2L.asJson
@@ -226,6 +232,7 @@ class RoutesSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
_ <- writeApi.commitPatch(patch)
ctxReq = Json.obj(
"query" -> "billing".asJson
@@ -250,6 +257,7 @@ class RoutesSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
tmpFile <- IO.blocking {
val f = java.nio.file.Files.createTempFile("ix-test-", ".py")
java.nio.file.Files.writeString(f,
@@ -285,6 +293,7 @@ class RoutesSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
ingestReq = Json.obj(
"path" -> "/tmp/../etc/passwd".asJson
)
@@ -306,6 +315,7 @@ class RoutesSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
diffReq = Json.obj(
"fromRev" -> 0L.asJson,
"toRev" -> 1L.asJson
@@ -334,6 +344,7 @@ class RoutesSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
_ <- writeApi.commitPatch(patch)
req = Request[IO](Method.POST, Uri.unsafeFromString(s"/v1/provenance/${nodeId.value}"))
resp <- app.run(req)
@@ -357,6 +368,7 @@ class RoutesSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
body = Json.obj(
"title" -> "Use exponential backoff".asJson,
"rationale" -> "Better for transient failures".asJson
@@ -388,6 +400,7 @@ class RoutesSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
_ <- writeApi.commitPatch(patch)
body = Json.obj("term" -> "billing_search_test".asJson)
req = Request[IO](Method.POST, uri"/v1/search").withEntity(body)
@@ -410,6 +423,7 @@ class RoutesSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
req = Request[IO](Method.GET, uri"/v1/truth")
resp <- app.run(req)
} yield {
@@ -428,6 +442,7 @@ class RoutesSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
body = Json.obj("statement" -> "Ship retry system by Friday".asJson)
req = Request[IO](Method.POST, uri"/v1/truth").withEntity(body)
resp <- app.run(req)
@@ -449,6 +464,7 @@ class RoutesSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
req = Request[IO](Method.GET, uri"/v1/patches")
resp <- app.run(req)
} yield {
@@ -475,6 +491,7 @@ class RoutesSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
_ <- writeApi.commitPatch(patch)
req = Request[IO](Method.GET, Uri.unsafeFromString(s"/v1/patches/${patchId.value}"))
resp <- app.run(req)
@@ -497,6 +514,7 @@ class RoutesSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
req = Request[IO](Method.GET, Uri.unsafeFromString(s"/v1/patches/$fakeId"))
resp <- app.run(req)
} yield {
diff --git a/memory-layer/src/test/scala/ix/memory/context/ConfidenceScorerSpec.scala b/memory-layer/src/test/scala/ix/memory/context/ConfidenceScorerSpec.scala
index 8adbf67e..0eb7dc2f 100644
--- a/memory-layer/src/test/scala/ix/memory/context/ConfidenceScorerSpec.scala
+++ b/memory-layer/src/test/scala/ix/memory/context/ConfidenceScorerSpec.scala
@@ -66,7 +66,9 @@ class ConfidenceScorerSpec extends AnyFlatSpec with Matchers {
it should "reduce score for stale sources" in {
val claim = makeClaim(SourceType.Code)
val fresh = scorer.score(claim, defaultCtx.copy(sourceChanged = false))
- val stale = scorer.score(claim, defaultCtx.copy(sourceChanged = true))
+ // Use an observedAt 60 days in the past so the recency penalty kicks in
+ val staleObservedAt = Instant.now().minus(java.time.Duration.ofDays(60))
+ val stale = scorer.score(claim, defaultCtx.copy(sourceChanged = true, observedAt = staleObservedAt))
fresh.confidence.score should be > stale.confidence.score
}
diff --git a/memory-layer/src/test/scala/ix/memory/context/ContextServiceSpec.scala b/memory-layer/src/test/scala/ix/memory/context/ContextServiceSpec.scala
index 2360da61..346f5549 100644
--- a/memory-layer/src/test/scala/ix/memory/context/ContextServiceSpec.scala
+++ b/memory-layer/src/test/scala/ix/memory/context/ContextServiceSpec.scala
@@ -9,10 +9,11 @@ import io.circe.Json
import org.scalatest.flatspec.AsyncFlatSpec
import org.scalatest.matchers.should.Matchers
+import ix.memory.TestDbHelper
import ix.memory.db._
import ix.memory.model._
-class ContextServiceSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
+class ContextServiceSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers with TestDbHelper {
val clientResource = ArangoClient.resource(
host = "localhost", port = 8529,
@@ -73,6 +74,7 @@ class ContextServiceSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
_ <- writeApi.commitPatch(patch)
result <- contextService.query("How does billing retry?")
} yield {
@@ -95,6 +97,7 @@ class ContextServiceSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
result <- contextService.query("something totally unknown xyz123")
} yield {
result.nodes shouldBe empty
@@ -134,6 +137,7 @@ class ContextServiceSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
_ <- writeApi.commitPatch(patch)
result <- contextService.query("What does billing do?")
} yield {
@@ -176,6 +180,7 @@ class ContextServiceSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
_ <- writeApi.commitPatch(patch)
result <- contextService.query("How does billing work?")
} yield {
@@ -205,6 +210,7 @@ class ContextServiceSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
_ <- writeApi.commitPatch(patch)
result <- contextService.query("billing info")
} yield {
diff --git a/memory-layer/src/test/scala/ix/memory/db/GraphQueryApiSpec.scala b/memory-layer/src/test/scala/ix/memory/db/GraphQueryApiSpec.scala
index f3dadba3..53f4c6c3 100644
--- a/memory-layer/src/test/scala/ix/memory/db/GraphQueryApiSpec.scala
+++ b/memory-layer/src/test/scala/ix/memory/db/GraphQueryApiSpec.scala
@@ -9,9 +9,10 @@ import io.circe.Json
import org.scalatest.flatspec.AsyncFlatSpec
import org.scalatest.matchers.should.Matchers
+import ix.memory.TestDbHelper
import ix.memory.model._
-class GraphQueryApiSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
+class GraphQueryApiSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers with TestDbHelper {
val clientResource = ArangoClient.resource(
host = "localhost", port = 8529,
@@ -45,6 +46,7 @@ class GraphQueryApiSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
clientResource.use { client =>
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
writeApi = new ArangoGraphWriteApi(client)
queryApi = new ArangoGraphQueryApi(client)
nodeId = NodeId(UUID.randomUUID())
@@ -79,6 +81,7 @@ class GraphQueryApiSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
clientResource.use { client =>
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
writeApi = new ArangoGraphWriteApi(client)
queryApi = new ArangoGraphQueryApi(client)
nodeId = NodeId(UUID.randomUUID())
@@ -120,6 +123,7 @@ class GraphQueryApiSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
clientResource.use { client =>
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
writeApi = new ArangoGraphWriteApi(client)
queryApi = new ArangoGraphQueryApi(client)
funcId1 = NodeId(UUID.randomUUID())
@@ -150,6 +154,7 @@ class GraphQueryApiSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
clientResource.use { client =>
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
writeApi = new ArangoGraphWriteApi(client)
queryApi = new ArangoGraphQueryApi(client)
nodeA = NodeId(UUID.randomUUID())
@@ -193,6 +198,7 @@ class GraphQueryApiSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
clientResource.use { client =>
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
writeApi = new ArangoGraphWriteApi(client)
queryApi = new ArangoGraphQueryApi(client)
node1 = NodeId(UUID.randomUUID())
@@ -218,6 +224,7 @@ class GraphQueryApiSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
clientResource.use { client =>
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
writeApi = new ArangoGraphWriteApi(client)
queryApi = new ArangoGraphQueryApi(client)
nodeId = NodeId(UUID.randomUUID())
@@ -246,6 +253,7 @@ class GraphQueryApiSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
clientResource.use { client =>
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
writeApi = new ArangoGraphWriteApi(client)
queryApi = new ArangoGraphQueryApi(client)
nodeId = NodeId(UUID.randomUUID())
diff --git a/memory-layer/src/test/scala/ix/memory/db/GraphWriteApiSpec.scala b/memory-layer/src/test/scala/ix/memory/db/GraphWriteApiSpec.scala
index 4923e9c4..5cf89ec1 100644
--- a/memory-layer/src/test/scala/ix/memory/db/GraphWriteApiSpec.scala
+++ b/memory-layer/src/test/scala/ix/memory/db/GraphWriteApiSpec.scala
@@ -9,9 +9,10 @@ import io.circe.Json
import org.scalatest.flatspec.AsyncFlatSpec
import org.scalatest.matchers.should.Matchers
+import ix.memory.TestDbHelper
import ix.memory.model._
-class GraphWriteApiSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
+class GraphWriteApiSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers with TestDbHelper {
val clientResource = ArangoClient.resource(
host = "localhost", port = 8529,
@@ -45,6 +46,7 @@ class GraphWriteApiSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
clientResource.use { client =>
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
api = new ArangoGraphWriteApi(client)
nodeId = NodeId(UUID.randomUUID())
patch = makePatch(
@@ -71,6 +73,7 @@ class GraphWriteApiSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
clientResource.use { client =>
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
api = new ArangoGraphWriteApi(client)
nodeId = NodeId(UUID.randomUUID())
patchId = PatchId(UUID.randomUUID())
@@ -101,6 +104,7 @@ class GraphWriteApiSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
clientResource.use { client =>
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
api = new ArangoGraphWriteApi(client)
nodeId1 = NodeId(UUID.randomUUID())
// First patch to establish rev 1
@@ -141,6 +145,7 @@ class GraphWriteApiSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
clientResource.use { client =>
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
api = new ArangoGraphWriteApi(client)
nodeId = NodeId(UUID.randomUUID())
patch = makePatch(
@@ -155,8 +160,8 @@ class GraphWriteApiSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
)
_ <- api.commitPatch(patch)
result <- client.queryOne(
- "FOR n IN nodes FILTER n._key == @key RETURN n",
- Map("key" -> nodeId.value.toString.asInstanceOf[AnyRef])
+ "FOR n IN nodes FILTER n.logical_id == @id AND n.deleted_rev == null RETURN n",
+ Map("id" -> nodeId.value.toString.asInstanceOf[AnyRef])
)
} yield {
result shouldBe defined
@@ -177,6 +182,7 @@ class GraphWriteApiSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
clientResource.use { client =>
for {
_ <- client.ensureSchema()
+ _ <- cleanDatabase(client)
api = new ArangoGraphWriteApi(client)
nodeId = NodeId(UUID.randomUUID())
// First patch: create the node
@@ -197,10 +203,10 @@ class GraphWriteApiSpec extends AsyncFlatSpec with AsyncIOSpec with Matchers {
ops = Vector(PatchOp.DeleteNode(nodeId))
)
res2 <- api.commitPatch(patch2)
- // Query the node to verify soft delete
+ // Query the node to verify soft delete (find by logical_id, expect deleted_rev set)
result <- client.queryOne(
- "FOR n IN nodes FILTER n._key == @key RETURN n",
- Map("key" -> nodeId.value.toString.asInstanceOf[AnyRef])
+ "FOR n IN nodes FILTER n.logical_id == @id AND n.deleted_rev != null RETURN n",
+ Map("id" -> nodeId.value.toString.asInstanceOf[AnyRef])
)
} yield {
res1.status shouldBe CommitStatus.Ok