feat(tasks): surface ready/blockedBy on GET /tasks and a readable decompose preview
GET /tasks now reports dependency-graph status per task — ready (TODO with no unmet deps) and blockedBy (ids of unfinished blockers) — resolved via TaskGraph over each task's FULL project board, so a status filter can't hide a blocker. Default-valued fields are omitted (encodeDefaults=false); consumers read absent as zero. The task_decompose approval card now shows a readable graph (epic + numbered children with their "after" dependency labels) via renderDecomposePreview wired into computeToolPreview, instead of the truncated raw JSON the generic fallback gave. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,7 @@ import com.correx.core.events.types.TaskNoteAuthor
|
||||
import com.correx.core.events.types.TaskTargetKind
|
||||
import com.correx.core.tasks.Task
|
||||
import com.correx.core.tasks.TaskContextAssembler
|
||||
import com.correx.core.tasks.TaskGraph
|
||||
import com.correx.core.tasks.TaskHistory
|
||||
import com.correx.core.tasks.TaskMarkdown
|
||||
import com.correx.core.tasks.TaskSearch
|
||||
@@ -52,6 +53,11 @@ data class TaskResponse(
|
||||
val notes: List<TaskNoteDto>,
|
||||
val createdAt: String?,
|
||||
val updatedAt: String?,
|
||||
// Dependency-graph status for the board: ready = TODO with every dependency satisfied (workable
|
||||
// now); blockedBy = the ids of unfinished tasks this one waits on (its unmet DEPENDS_ON/BLOCKS).
|
||||
// Default to "not blocked / not ready" for the endpoints that don't resolve the graph.
|
||||
val ready: Boolean = false,
|
||||
val blockedBy: List<String> = emptyList(),
|
||||
)
|
||||
|
||||
@Serializable
|
||||
@@ -132,7 +138,7 @@ private fun Route.taskCollectionRoutes(service: TaskService) {
|
||||
if (call.request.queryParameters["ready"]?.toBoolean() == true) {
|
||||
val readyProject = call.request.queryParameters["project"]
|
||||
val workable = service.ready(readyProject?.let { ProjectId(it) })
|
||||
return@get call.respond(workable.map { it.toResponse() })
|
||||
return@get call.respond(workable.map { it.toResponse().copy(ready = true) })
|
||||
}
|
||||
val statusRaw = call.request.queryParameters["status"]
|
||||
val statusFilter = statusRaw?.let {
|
||||
@@ -149,7 +155,18 @@ private fun Route.taskCollectionRoutes(service: TaskService) {
|
||||
} else {
|
||||
TaskSearch.search(base, q)
|
||||
}
|
||||
call.respond(ordered.map { it.toResponse() })
|
||||
// Resolve ready/blockedBy against each task's FULL project board (not the filtered list — a
|
||||
// status filter must not hide a finished blocker). One list() per distinct project, cached.
|
||||
val boards = HashMap<ProjectId, List<Task>>()
|
||||
fun enrich(t: Task): TaskResponse {
|
||||
val pid = t.state.projectId ?: return t.toResponse()
|
||||
val board = boards.getOrPut(pid) { service.list(pid) }
|
||||
return t.toResponse().copy(
|
||||
ready = TaskGraph.isReady(t, board),
|
||||
blockedBy = TaskGraph.unmetBlockers(t, board).map { it.taskId.value },
|
||||
)
|
||||
}
|
||||
call.respond(ordered.map(::enrich))
|
||||
}
|
||||
post {
|
||||
val body = call.receive<CreateTaskRequest>()
|
||||
|
||||
@@ -116,6 +116,40 @@ class TaskRoutesTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GET tasks reports dependency-graph ready and blockedBy`(@TempDir tempDir: Path) {
|
||||
testApplication {
|
||||
application { configureServer(buildModule(tempDir)) }
|
||||
val client = createClient {}
|
||||
client.createTask() // demo-1 (TODO, no deps)
|
||||
client.post("/tasks") {
|
||||
contentType(ContentType.Application.Json)
|
||||
setBody("""{"project":"demo","title":"Rotate keys","goal":"rotate signing keys"}""")
|
||||
} // demo-2
|
||||
// demo-2 DEPENDS_ON demo-1 (TASK kind inferred from the id).
|
||||
client.post("/tasks/demo-2/links") {
|
||||
contentType(ContentType.Application.Json)
|
||||
setBody("""{"targetId":"demo-1","type":"DEPENDS_ON"}""")
|
||||
}
|
||||
|
||||
val rows = testJson.parseToJsonElement(client.get("/tasks?project=demo").bodyAsText()) as JsonArray
|
||||
val byId = rows.associate { (it as JsonObject)["id"]!!.jsonPrimitive.content to it }
|
||||
val one = byId.getValue("demo-1") as JsonObject
|
||||
val two = byId.getValue("demo-2") as JsonObject
|
||||
// default-valued fields are omitted from JSON (encodeDefaults=false), which the TUI reads
|
||||
// back as zero values — so tolerate absence here too.
|
||||
fun readyOf(o: JsonObject) = o["ready"]?.jsonPrimitive?.content == "true"
|
||||
fun blockedByOf(o: JsonObject): List<String> =
|
||||
(o["blockedBy"] as? JsonArray)?.map { it.jsonPrimitive.content } ?: emptyList()
|
||||
// demo-1: TODO with nothing in its way → ready, no blockers.
|
||||
assertTrue(readyOf(one))
|
||||
assertTrue(blockedByOf(one).isEmpty())
|
||||
// demo-2: waits on the unfinished demo-1 → not ready, blockedBy = [demo-1].
|
||||
assertTrue(!readyOf(two))
|
||||
assertEquals(listOf("demo-1"), blockedByOf(two))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `lifecycle transitions move a task to DONE`(@TempDir tempDir: Path) {
|
||||
testApplication {
|
||||
|
||||
Reference in New Issue
Block a user