@sqaoss/flowy 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server/src/resolvers.test.ts +196 -0
- package/server/src/resolvers.ts +68 -0
- package/server/src/schema.ts +2 -0
- package/src/commands/task.test.ts +140 -2
- package/src/commands/task.ts +79 -5
package/package.json
CHANGED
|
@@ -1099,4 +1099,200 @@ describe('createResolvers', () => {
|
|
|
1099
1099
|
expect(results).toEqual([])
|
|
1100
1100
|
})
|
|
1101
1101
|
})
|
|
1102
|
+
|
|
1103
|
+
describe('Query.readyTasks', () => {
|
|
1104
|
+
function setStatus(id: string, status: string): void {
|
|
1105
|
+
resolvers.Mutation.updateNode(null, { id, status })
|
|
1106
|
+
}
|
|
1107
|
+
function block(blockerId: string, blockedId: string): void {
|
|
1108
|
+
resolvers.Mutation.createEdge(null, {
|
|
1109
|
+
sourceId: blockerId,
|
|
1110
|
+
targetId: blockedId,
|
|
1111
|
+
relation: 'blocks',
|
|
1112
|
+
})
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
it('returns an unblocked, not-done task', () => {
|
|
1116
|
+
const t = create(resolvers, { type: 'task', title: 'Free' })
|
|
1117
|
+
const ready = resolvers.Query.readyTasks(null, {})
|
|
1118
|
+
expect(ready.map((n) => n.id)).toEqual([t.id])
|
|
1119
|
+
})
|
|
1120
|
+
|
|
1121
|
+
it('excludes done and cancelled tasks', () => {
|
|
1122
|
+
const open = create(resolvers, { type: 'task', title: 'Open' })
|
|
1123
|
+
const done = create(resolvers, { type: 'task', title: 'Done' })
|
|
1124
|
+
const cancelled = create(resolvers, { type: 'task', title: 'Cancelled' })
|
|
1125
|
+
setStatus(done.id, 'done')
|
|
1126
|
+
setStatus(cancelled.id, 'cancelled')
|
|
1127
|
+
|
|
1128
|
+
const ready = resolvers.Query.readyTasks(null, {})
|
|
1129
|
+
const ids = ready.map((n) => n.id)
|
|
1130
|
+
expect(ids).toContain(open.id)
|
|
1131
|
+
expect(ids).not.toContain(done.id)
|
|
1132
|
+
expect(ids).not.toContain(cancelled.id)
|
|
1133
|
+
})
|
|
1134
|
+
|
|
1135
|
+
it('excludes a task blocked by an unfinished blocker', () => {
|
|
1136
|
+
const blocker = create(resolvers, { type: 'task', title: 'Blocker' })
|
|
1137
|
+
const blocked = create(resolvers, { type: 'task', title: 'Blocked' })
|
|
1138
|
+
block(blocker.id, blocked.id)
|
|
1139
|
+
|
|
1140
|
+
const ready = resolvers.Query.readyTasks(null, {})
|
|
1141
|
+
const ids = ready.map((n) => n.id)
|
|
1142
|
+
expect(ids).toContain(blocker.id)
|
|
1143
|
+
expect(ids).not.toContain(blocked.id)
|
|
1144
|
+
})
|
|
1145
|
+
|
|
1146
|
+
it('includes a task once all its blockers are done', () => {
|
|
1147
|
+
const blocker = create(resolvers, { type: 'task', title: 'Blocker' })
|
|
1148
|
+
const blocked = create(resolvers, { type: 'task', title: 'Blocked' })
|
|
1149
|
+
block(blocker.id, blocked.id)
|
|
1150
|
+
setStatus(blocker.id, 'done')
|
|
1151
|
+
|
|
1152
|
+
const ready = resolvers.Query.readyTasks(null, {})
|
|
1153
|
+
const ids = ready.map((n) => n.id)
|
|
1154
|
+
// The done blocker is itself excluded; the formerly-blocked task is ready.
|
|
1155
|
+
expect(ids).not.toContain(blocker.id)
|
|
1156
|
+
expect(ids).toContain(blocked.id)
|
|
1157
|
+
})
|
|
1158
|
+
|
|
1159
|
+
it('treats a cancelled blocker as no longer blocking', () => {
|
|
1160
|
+
const blocker = create(resolvers, { type: 'task', title: 'Blocker' })
|
|
1161
|
+
const blocked = create(resolvers, { type: 'task', title: 'Blocked' })
|
|
1162
|
+
block(blocker.id, blocked.id)
|
|
1163
|
+
setStatus(blocker.id, 'cancelled')
|
|
1164
|
+
|
|
1165
|
+
const ready = resolvers.Query.readyTasks(null, {})
|
|
1166
|
+
expect(ready.map((n) => n.id)).toContain(blocked.id)
|
|
1167
|
+
})
|
|
1168
|
+
|
|
1169
|
+
it('still blocks when any one of several blockers is unfinished', () => {
|
|
1170
|
+
const b1 = create(resolvers, { type: 'task', title: 'B1' })
|
|
1171
|
+
const b2 = create(resolvers, { type: 'task', title: 'B2' })
|
|
1172
|
+
const blocked = create(resolvers, { type: 'task', title: 'Blocked' })
|
|
1173
|
+
block(b1.id, blocked.id)
|
|
1174
|
+
block(b2.id, blocked.id)
|
|
1175
|
+
setStatus(b1.id, 'done')
|
|
1176
|
+
// b2 still open -> blocked stays not-ready
|
|
1177
|
+
|
|
1178
|
+
const ready = resolvers.Query.readyTasks(null, {})
|
|
1179
|
+
expect(ready.map((n) => n.id)).not.toContain(blocked.id)
|
|
1180
|
+
})
|
|
1181
|
+
|
|
1182
|
+
it('returns only tasks, never features or projects', () => {
|
|
1183
|
+
const project = create(resolvers, { type: 'project', title: 'P' })
|
|
1184
|
+
const feature = create(resolvers, { type: 'feature', title: 'F' })
|
|
1185
|
+
const task = create(resolvers, { type: 'task', title: 'T' })
|
|
1186
|
+
|
|
1187
|
+
const ready = resolvers.Query.readyTasks(null, {})
|
|
1188
|
+
const ids = ready.map((n) => n.id)
|
|
1189
|
+
expect(ids).toContain(task.id)
|
|
1190
|
+
expect(ids).not.toContain(project.id)
|
|
1191
|
+
expect(ids).not.toContain(feature.id)
|
|
1192
|
+
})
|
|
1193
|
+
|
|
1194
|
+
it('returns exactly the unblocked not-done tasks across a mixed fixture', () => {
|
|
1195
|
+
// free: ready. blocked-by-open: not ready. blocked-by-done: ready.
|
|
1196
|
+
// done: not ready. in_progress + unblocked: ready.
|
|
1197
|
+
const free = create(resolvers, { type: 'task', title: 'free' })
|
|
1198
|
+
const openBlocker = create(resolvers, { type: 'task', title: 'open-b' })
|
|
1199
|
+
const blockedByOpen = create(resolvers, { type: 'task', title: 'bbo' })
|
|
1200
|
+
const doneBlocker = create(resolvers, { type: 'task', title: 'done-b' })
|
|
1201
|
+
const blockedByDone = create(resolvers, { type: 'task', title: 'bbd' })
|
|
1202
|
+
const finished = create(resolvers, { type: 'task', title: 'finished' })
|
|
1203
|
+
const started = create(resolvers, { type: 'task', title: 'started' })
|
|
1204
|
+
|
|
1205
|
+
block(openBlocker.id, blockedByOpen.id)
|
|
1206
|
+
block(doneBlocker.id, blockedByDone.id)
|
|
1207
|
+
setStatus(doneBlocker.id, 'done')
|
|
1208
|
+
setStatus(finished.id, 'done')
|
|
1209
|
+
setStatus(started.id, 'in_progress')
|
|
1210
|
+
|
|
1211
|
+
const ready = resolvers.Query.readyTasks(null, {})
|
|
1212
|
+
const ids = new Set(ready.map((n) => n.id))
|
|
1213
|
+
expect(ids).toEqual(
|
|
1214
|
+
new Set([free.id, openBlocker.id, blockedByDone.id, started.id]),
|
|
1215
|
+
)
|
|
1216
|
+
})
|
|
1217
|
+
|
|
1218
|
+
it('scopes to a project via part_of when projectId is given', () => {
|
|
1219
|
+
const projA = create(resolvers, { type: 'project', title: 'A' })
|
|
1220
|
+
const featA = create(resolvers, { type: 'feature', title: 'FA' })
|
|
1221
|
+
const taskA = create(resolvers, { type: 'task', title: 'TA' })
|
|
1222
|
+
resolvers.Mutation.createEdge(null, {
|
|
1223
|
+
sourceId: featA.id,
|
|
1224
|
+
targetId: projA.id,
|
|
1225
|
+
relation: 'part_of',
|
|
1226
|
+
})
|
|
1227
|
+
resolvers.Mutation.createEdge(null, {
|
|
1228
|
+
sourceId: taskA.id,
|
|
1229
|
+
targetId: featA.id,
|
|
1230
|
+
relation: 'part_of',
|
|
1231
|
+
})
|
|
1232
|
+
|
|
1233
|
+
const projB = create(resolvers, { type: 'project', title: 'B' })
|
|
1234
|
+
const featB = create(resolvers, { type: 'feature', title: 'FB' })
|
|
1235
|
+
const taskB = create(resolvers, { type: 'task', title: 'TB' })
|
|
1236
|
+
resolvers.Mutation.createEdge(null, {
|
|
1237
|
+
sourceId: featB.id,
|
|
1238
|
+
targetId: projB.id,
|
|
1239
|
+
relation: 'part_of',
|
|
1240
|
+
})
|
|
1241
|
+
resolvers.Mutation.createEdge(null, {
|
|
1242
|
+
sourceId: taskB.id,
|
|
1243
|
+
targetId: featB.id,
|
|
1244
|
+
relation: 'part_of',
|
|
1245
|
+
})
|
|
1246
|
+
|
|
1247
|
+
const ready = resolvers.Query.readyTasks(null, { projectId: projA.id })
|
|
1248
|
+
expect(ready.map((n) => n.id)).toEqual([taskA.id])
|
|
1249
|
+
})
|
|
1250
|
+
})
|
|
1251
|
+
|
|
1252
|
+
describe('Query.edges', () => {
|
|
1253
|
+
function block(blockerId: string, blockedId: string): void {
|
|
1254
|
+
resolvers.Mutation.createEdge(null, {
|
|
1255
|
+
sourceId: blockerId,
|
|
1256
|
+
targetId: blockedId,
|
|
1257
|
+
relation: 'blocks',
|
|
1258
|
+
})
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
it('returns blockedBy: incoming blocks edges (sources that block the node)', () => {
|
|
1262
|
+
const blocker = create(resolvers, { type: 'task', title: 'Blocker' })
|
|
1263
|
+
const blocked = create(resolvers, { type: 'task', title: 'Blocked' })
|
|
1264
|
+
block(blocker.id, blocked.id)
|
|
1265
|
+
|
|
1266
|
+
const blockedBy = resolvers.Query.edges(null, {
|
|
1267
|
+
nodeId: blocked.id,
|
|
1268
|
+
relation: 'blocks',
|
|
1269
|
+
direction: 'incoming',
|
|
1270
|
+
})
|
|
1271
|
+
expect(blockedBy.map((n) => n.id)).toEqual([blocker.id])
|
|
1272
|
+
})
|
|
1273
|
+
|
|
1274
|
+
it('returns blocks: outgoing blocks edges (targets the node blocks)', () => {
|
|
1275
|
+
const blocker = create(resolvers, { type: 'task', title: 'Blocker' })
|
|
1276
|
+
const blocked = create(resolvers, { type: 'task', title: 'Blocked' })
|
|
1277
|
+
block(blocker.id, blocked.id)
|
|
1278
|
+
|
|
1279
|
+
const blocks = resolvers.Query.edges(null, {
|
|
1280
|
+
nodeId: blocker.id,
|
|
1281
|
+
relation: 'blocks',
|
|
1282
|
+
direction: 'outgoing',
|
|
1283
|
+
})
|
|
1284
|
+
expect(blocks.map((n) => n.id)).toEqual([blocked.id])
|
|
1285
|
+
})
|
|
1286
|
+
|
|
1287
|
+
it('returns an empty array for a node with no edges', () => {
|
|
1288
|
+
const lonely = create(resolvers, { type: 'task', title: 'Lonely' })
|
|
1289
|
+
expect(
|
|
1290
|
+
resolvers.Query.edges(null, {
|
|
1291
|
+
nodeId: lonely.id,
|
|
1292
|
+
relation: 'blocks',
|
|
1293
|
+
direction: 'incoming',
|
|
1294
|
+
}),
|
|
1295
|
+
).toEqual([])
|
|
1296
|
+
})
|
|
1297
|
+
})
|
|
1102
1298
|
})
|
package/server/src/resolvers.ts
CHANGED
|
@@ -194,6 +194,74 @@ export function createResolvers(db: Db) {
|
|
|
194
194
|
return selectNodes(rows)
|
|
195
195
|
},
|
|
196
196
|
|
|
197
|
+
// Nodes connected to `nodeId` by `relation`, following edges in the given
|
|
198
|
+
// direction. 'incoming' returns the *sources* of edges that point at the
|
|
199
|
+
// node (e.g. for relation 'blocks', the tasks that block it — blockedBy);
|
|
200
|
+
// 'outgoing' returns the *targets* of edges originating at the node (the
|
|
201
|
+
// tasks it blocks). Default direction is 'outgoing'.
|
|
202
|
+
edges: (
|
|
203
|
+
_: unknown,
|
|
204
|
+
args: {
|
|
205
|
+
nodeId: string
|
|
206
|
+
relation: string
|
|
207
|
+
direction?: string
|
|
208
|
+
},
|
|
209
|
+
) => {
|
|
210
|
+
const incoming = args.direction === 'incoming'
|
|
211
|
+
const sql = incoming
|
|
212
|
+
? `SELECT ${prefixedCols()} FROM nodes n
|
|
213
|
+
JOIN edges e ON n.id = e.source_id
|
|
214
|
+
WHERE e.target_id = ? AND e.relation = ?`
|
|
215
|
+
: `SELECT ${prefixedCols()} FROM nodes n
|
|
216
|
+
JOIN edges e ON n.id = e.target_id
|
|
217
|
+
WHERE e.source_id = ? AND e.relation = ?`
|
|
218
|
+
const rows = db.raw
|
|
219
|
+
.query(sql)
|
|
220
|
+
.all(args.nodeId, args.relation) as NodeRow[]
|
|
221
|
+
return selectNodes(rows)
|
|
222
|
+
},
|
|
223
|
+
|
|
224
|
+
// Tasks that are actionable now: type 'task', status not done/cancelled,
|
|
225
|
+
// and not blocked by any incomplete blocker. A blocker is an incoming
|
|
226
|
+
// `blocks` edge whose source task is itself not done/cancelled. Optionally
|
|
227
|
+
// scoped to a project via the `part_of` hierarchy (task -> feature ->
|
|
228
|
+
// project).
|
|
229
|
+
readyTasks: (_: unknown, args: { projectId?: string }) => {
|
|
230
|
+
const params: string[] = []
|
|
231
|
+
let scope = ''
|
|
232
|
+
if (args.projectId) {
|
|
233
|
+
// Restrict to tasks reachable from the project through part_of edges
|
|
234
|
+
// (any depth). Edges point child -> parent, so we walk upward from
|
|
235
|
+
// each candidate task to see if the project is an ancestor.
|
|
236
|
+
scope = `AND n.id IN (
|
|
237
|
+
WITH RECURSIVE up(id) AS (
|
|
238
|
+
SELECT source_id FROM edges
|
|
239
|
+
WHERE target_id = ?1 AND relation = 'part_of'
|
|
240
|
+
UNION
|
|
241
|
+
SELECT e.source_id FROM edges e
|
|
242
|
+
JOIN up ON e.target_id = up.id AND e.relation = 'part_of'
|
|
243
|
+
)
|
|
244
|
+
SELECT id FROM up
|
|
245
|
+
)`
|
|
246
|
+
params.push(args.projectId)
|
|
247
|
+
}
|
|
248
|
+
const rows = db.raw
|
|
249
|
+
.query(
|
|
250
|
+
`SELECT ${prefixedCols()} FROM nodes n
|
|
251
|
+
WHERE n.type = 'task'
|
|
252
|
+
AND n.status NOT IN ('done', 'cancelled')
|
|
253
|
+
${scope}
|
|
254
|
+
AND NOT EXISTS (
|
|
255
|
+
SELECT 1 FROM edges b
|
|
256
|
+
JOIN nodes src ON src.id = b.source_id
|
|
257
|
+
WHERE b.target_id = n.id AND b.relation = 'blocks'
|
|
258
|
+
AND src.status NOT IN ('done', 'cancelled')
|
|
259
|
+
)`,
|
|
260
|
+
)
|
|
261
|
+
.all(...params) as NodeRow[]
|
|
262
|
+
return selectNodes(rows)
|
|
263
|
+
},
|
|
264
|
+
|
|
197
265
|
search: (
|
|
198
266
|
_: unknown,
|
|
199
267
|
args: {
|
package/server/src/schema.ts
CHANGED
|
@@ -24,6 +24,8 @@ export const typeDefs = /* GraphQL */ `
|
|
|
24
24
|
nodes(type: String): [Node!]!
|
|
25
25
|
descendants(nodeId: String!, relation: String, maxDepth: Int): [Node!]!
|
|
26
26
|
subtree(nodeId: String!, maxDepth: Int): [Node!]!
|
|
27
|
+
edges(nodeId: String!, relation: String!, direction: String): [Node!]!
|
|
28
|
+
readyTasks(projectId: String): [Node!]!
|
|
27
29
|
search(query: String!, type: String, status: String, limit: Int): [Node!]!
|
|
28
30
|
}
|
|
29
31
|
|
|
@@ -6,6 +6,7 @@ vi.mock('../util/config.ts', () => ({
|
|
|
6
6
|
'No active feature. Run "flowy feature set <name-or-id>" or set FLOWY_FEATURE.',
|
|
7
7
|
)
|
|
8
8
|
}),
|
|
9
|
+
resolveProject: vi.fn(() => ({ id: 'proj_active', name: 'active' })),
|
|
9
10
|
}))
|
|
10
11
|
|
|
11
12
|
vi.mock('../util/client.ts', () => ({
|
|
@@ -22,10 +23,10 @@ describe('task command', () => {
|
|
|
22
23
|
vi.clearAllMocks()
|
|
23
24
|
})
|
|
24
25
|
|
|
25
|
-
test('exports a command group with
|
|
26
|
+
test('exports a command group with 8 subcommands', async () => {
|
|
26
27
|
const { taskCommand } = await import('./task.ts')
|
|
27
28
|
expect(taskCommand.name()).toBe('task')
|
|
28
|
-
expect(taskCommand.commands).toHaveLength(
|
|
29
|
+
expect(taskCommand.commands).toHaveLength(8)
|
|
29
30
|
|
|
30
31
|
const names = taskCommand.commands.map((c) => c.name())
|
|
31
32
|
expect(names).toContain('create')
|
|
@@ -35,6 +36,7 @@ describe('task command', () => {
|
|
|
35
36
|
expect(names).toContain('unblock')
|
|
36
37
|
expect(names).toContain('update')
|
|
37
38
|
expect(names).toContain('delete')
|
|
39
|
+
expect(names).toContain('deps')
|
|
38
40
|
})
|
|
39
41
|
|
|
40
42
|
test('create exposes both --description and --description-file options', async () => {
|
|
@@ -255,4 +257,140 @@ describe('task command', () => {
|
|
|
255
257
|
expect.objectContaining({ code: 'NOT_FOUND' }),
|
|
256
258
|
)
|
|
257
259
|
})
|
|
260
|
+
|
|
261
|
+
test('show includes blockedBy and blocks in its output', async () => {
|
|
262
|
+
const { graphql } = await import('../util/client.ts')
|
|
263
|
+
const { output } = await import('../util/format.ts')
|
|
264
|
+
const { taskCommand } = await import('./task.ts')
|
|
265
|
+
|
|
266
|
+
vi.mocked(graphql).mockResolvedValueOnce({
|
|
267
|
+
node: { id: 'task_a', title: 'A', status: 'draft' },
|
|
268
|
+
blockedBy: [{ id: 'task_b', title: 'B', status: 'in_progress' }],
|
|
269
|
+
blocks: [{ id: 'task_c', title: 'C', status: 'draft' }],
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
const showCmd = taskCommand.commands.find((c) => c.name() === 'show')!
|
|
273
|
+
await showCmd.parseAsync(['task_a'], { from: 'user' })
|
|
274
|
+
|
|
275
|
+
expect(output).toHaveBeenCalledWith(
|
|
276
|
+
expect.objectContaining({
|
|
277
|
+
id: 'task_a',
|
|
278
|
+
blockedBy: [{ id: 'task_b', title: 'B', status: 'in_progress' }],
|
|
279
|
+
blocks: [{ id: 'task_c', title: 'C', status: 'draft' }],
|
|
280
|
+
}),
|
|
281
|
+
)
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
test('show queries edges for both directions of blocks', async () => {
|
|
285
|
+
const { graphql } = await import('../util/client.ts')
|
|
286
|
+
const { taskCommand } = await import('./task.ts')
|
|
287
|
+
|
|
288
|
+
vi.mocked(graphql).mockResolvedValueOnce({
|
|
289
|
+
node: { id: 'task_a', title: 'A', status: 'draft' },
|
|
290
|
+
blockedBy: [],
|
|
291
|
+
blocks: [],
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
const showCmd = taskCommand.commands.find((c) => c.name() === 'show')!
|
|
295
|
+
await showCmd.parseAsync(['task_a'], { from: 'user' })
|
|
296
|
+
|
|
297
|
+
const [query, variables] = vi.mocked(graphql).mock.calls[0]!
|
|
298
|
+
expect(query).toContain('blockedBy')
|
|
299
|
+
expect(query).toContain('blocks')
|
|
300
|
+
expect(variables).toMatchObject({ id: 'task_a' })
|
|
301
|
+
})
|
|
302
|
+
|
|
303
|
+
test('deps lists blockedBy and blocks for a task', async () => {
|
|
304
|
+
const { graphql } = await import('../util/client.ts')
|
|
305
|
+
const { output } = await import('../util/format.ts')
|
|
306
|
+
const { taskCommand } = await import('./task.ts')
|
|
307
|
+
|
|
308
|
+
vi.mocked(graphql).mockResolvedValueOnce({
|
|
309
|
+
blockedBy: [{ id: 'task_b', title: 'B', status: 'draft' }],
|
|
310
|
+
blocks: [{ id: 'task_c', title: 'C', status: 'done' }],
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
const depsCmd = taskCommand.commands.find((c) => c.name() === 'deps')!
|
|
314
|
+
await depsCmd.parseAsync(['task_a'], { from: 'user' })
|
|
315
|
+
|
|
316
|
+
expect(output).toHaveBeenCalledWith({
|
|
317
|
+
id: 'task_a',
|
|
318
|
+
blockedBy: [{ id: 'task_b', title: 'B', status: 'draft' }],
|
|
319
|
+
blocks: [{ id: 'task_c', title: 'C', status: 'done' }],
|
|
320
|
+
})
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
test('deps surfaces errors via outputError', async () => {
|
|
324
|
+
const { graphql } = await import('../util/client.ts')
|
|
325
|
+
const { outputError } = await import('../util/format.ts')
|
|
326
|
+
const { taskCommand } = await import('./task.ts')
|
|
327
|
+
|
|
328
|
+
vi.mocked(graphql).mockRejectedValueOnce(new Error('Node task_a not found'))
|
|
329
|
+
|
|
330
|
+
const depsCmd = taskCommand.commands.find((c) => c.name() === 'deps')!
|
|
331
|
+
await depsCmd.parseAsync(['task_a'], { from: 'user' })
|
|
332
|
+
|
|
333
|
+
expect(outputError).toHaveBeenCalledWith(
|
|
334
|
+
expect.objectContaining({ message: 'Node task_a not found' }),
|
|
335
|
+
)
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
test('list --ready queries readyTasks and prints them', async () => {
|
|
339
|
+
const { graphql } = await import('../util/client.ts')
|
|
340
|
+
const { output } = await import('../util/format.ts')
|
|
341
|
+
const { taskCommand } = await import('./task.ts')
|
|
342
|
+
|
|
343
|
+
vi.mocked(graphql).mockResolvedValueOnce({
|
|
344
|
+
readyTasks: [{ id: 'task_x', title: 'X', status: 'draft' }],
|
|
345
|
+
})
|
|
346
|
+
|
|
347
|
+
const listCmd = taskCommand.commands.find((c) => c.name() === 'list')!
|
|
348
|
+
await listCmd.parseAsync(['--ready'], { from: 'user' })
|
|
349
|
+
|
|
350
|
+
const [query] = vi.mocked(graphql).mock.calls[0]!
|
|
351
|
+
expect(query).toContain('readyTasks')
|
|
352
|
+
expect(output).toHaveBeenCalledWith([
|
|
353
|
+
{ id: 'task_x', title: 'X', status: 'draft' },
|
|
354
|
+
])
|
|
355
|
+
})
|
|
356
|
+
|
|
357
|
+
test('list --ready --project scopes readyTasks to the given project', async () => {
|
|
358
|
+
const { graphql } = await import('../util/client.ts')
|
|
359
|
+
const { taskCommand } = await import('./task.ts')
|
|
360
|
+
|
|
361
|
+
vi.mocked(graphql).mockResolvedValueOnce({ readyTasks: [] })
|
|
362
|
+
|
|
363
|
+
const listCmd = taskCommand.commands.find((c) => c.name() === 'list')!
|
|
364
|
+
await listCmd.parseAsync(['--ready', '--project', 'proj_42'], {
|
|
365
|
+
from: 'user',
|
|
366
|
+
})
|
|
367
|
+
|
|
368
|
+
const [query, variables] = vi.mocked(graphql).mock.calls[0]!
|
|
369
|
+
expect(query).toContain('readyTasks')
|
|
370
|
+
expect(variables).toMatchObject({ projectId: 'proj_42' })
|
|
371
|
+
})
|
|
372
|
+
|
|
373
|
+
test('list --all lists every task node', async () => {
|
|
374
|
+
const { graphql } = await import('../util/client.ts')
|
|
375
|
+
const { output } = await import('../util/format.ts')
|
|
376
|
+
const { taskCommand } = await import('./task.ts')
|
|
377
|
+
|
|
378
|
+
vi.mocked(graphql).mockResolvedValueOnce({
|
|
379
|
+
nodes: [
|
|
380
|
+
{ id: 'task_1', type: 'task', title: 'One', status: 'draft' },
|
|
381
|
+
{ id: 'task_2', type: 'task', title: 'Two', status: 'done' },
|
|
382
|
+
],
|
|
383
|
+
})
|
|
384
|
+
|
|
385
|
+
const listCmd = taskCommand.commands.find((c) => c.name() === 'list')!
|
|
386
|
+
await listCmd.parseAsync(['--all'], { from: 'user' })
|
|
387
|
+
|
|
388
|
+
const [query, variables] = vi.mocked(graphql).mock.calls[0]!
|
|
389
|
+
expect(query).toContain('nodes')
|
|
390
|
+
expect(variables).toMatchObject({ type: 'task' })
|
|
391
|
+
expect(output).toHaveBeenCalledWith([
|
|
392
|
+
{ id: 'task_1', type: 'task', title: 'One', status: 'draft' },
|
|
393
|
+
{ id: 'task_2', type: 'task', title: 'Two', status: 'done' },
|
|
394
|
+
])
|
|
395
|
+
})
|
|
258
396
|
})
|
package/src/commands/task.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Command } from 'commander'
|
|
2
2
|
import { graphql } from '../util/client.ts'
|
|
3
|
-
import { requireFeature } from '../util/config.ts'
|
|
3
|
+
import { requireFeature, resolveProject } from '../util/config.ts'
|
|
4
4
|
import { resolveDescription } from '../util/description.ts'
|
|
5
5
|
import { output, outputError } from '../util/format.ts'
|
|
6
6
|
|
|
@@ -53,8 +53,45 @@ taskCommand
|
|
|
53
53
|
taskCommand
|
|
54
54
|
.command('list')
|
|
55
55
|
.description('List tasks in the active feature')
|
|
56
|
-
.
|
|
56
|
+
.option(
|
|
57
|
+
'--ready',
|
|
58
|
+
'Only actionable tasks: not done/cancelled and with zero unfinished blockers',
|
|
59
|
+
)
|
|
60
|
+
.option('--all', 'List every task across the whole backlog')
|
|
61
|
+
.option(
|
|
62
|
+
'--project <id>',
|
|
63
|
+
'Scope --ready/--all to a project (defaults to the active project)',
|
|
64
|
+
)
|
|
65
|
+
.action(async (opts) => {
|
|
57
66
|
try {
|
|
67
|
+
if (opts.ready) {
|
|
68
|
+
const projectId =
|
|
69
|
+
opts.project ?? (opts.all ? undefined : resolveProject()?.id)
|
|
70
|
+
const data = await graphql<{ readyTasks: unknown[] }>(
|
|
71
|
+
`query ReadyTasks($projectId: String) {
|
|
72
|
+
readyTasks(projectId: $projectId) {
|
|
73
|
+
id type title status createdAt
|
|
74
|
+
}
|
|
75
|
+
}`,
|
|
76
|
+
{ projectId: projectId ?? null },
|
|
77
|
+
)
|
|
78
|
+
output(data.readyTasks)
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (opts.all) {
|
|
83
|
+
const data = await graphql<{ nodes: unknown[] }>(
|
|
84
|
+
`query AllTasks($type: String!) {
|
|
85
|
+
nodes(type: $type) {
|
|
86
|
+
id type title status createdAt
|
|
87
|
+
}
|
|
88
|
+
}`,
|
|
89
|
+
{ type: 'task' },
|
|
90
|
+
)
|
|
91
|
+
output(data.nodes)
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
|
|
58
95
|
const featureId = requireFeature()
|
|
59
96
|
const data = await graphql<{ descendants: unknown[] }>(
|
|
60
97
|
`query ListTasks($nodeId: String!, $relation: String!, $maxDepth: Int) {
|
|
@@ -75,19 +112,33 @@ taskCommand
|
|
|
75
112
|
|
|
76
113
|
taskCommand
|
|
77
114
|
.command('show')
|
|
78
|
-
.description('Show task details')
|
|
115
|
+
.description('Show task details, including its blockedBy/blocks dependencies')
|
|
79
116
|
.argument('<id>', 'Task ID')
|
|
80
117
|
.action(async (id: string) => {
|
|
81
118
|
try {
|
|
82
|
-
const data = await graphql<{
|
|
119
|
+
const data = await graphql<{
|
|
120
|
+
node: Record<string, unknown>
|
|
121
|
+
blockedBy: unknown[]
|
|
122
|
+
blocks: unknown[]
|
|
123
|
+
}>(
|
|
83
124
|
`query ShowTask($id: String!) {
|
|
84
125
|
node(id: $id) {
|
|
85
126
|
id type title description status metadata createdAt updatedAt
|
|
86
127
|
}
|
|
128
|
+
blockedBy: edges(nodeId: $id, relation: "blocks", direction: "incoming") {
|
|
129
|
+
id type title status
|
|
130
|
+
}
|
|
131
|
+
blocks: edges(nodeId: $id, relation: "blocks", direction: "outgoing") {
|
|
132
|
+
id type title status
|
|
133
|
+
}
|
|
87
134
|
}`,
|
|
88
135
|
{ id },
|
|
89
136
|
)
|
|
90
|
-
output(
|
|
137
|
+
output({
|
|
138
|
+
...data.node,
|
|
139
|
+
blockedBy: data.blockedBy,
|
|
140
|
+
blocks: data.blocks,
|
|
141
|
+
})
|
|
91
142
|
} catch (error) {
|
|
92
143
|
outputError(error)
|
|
93
144
|
}
|
|
@@ -189,3 +240,26 @@ taskCommand
|
|
|
189
240
|
outputError(error)
|
|
190
241
|
}
|
|
191
242
|
})
|
|
243
|
+
|
|
244
|
+
taskCommand
|
|
245
|
+
.command('deps')
|
|
246
|
+
.description('List a task’s dependencies: what blocks it and what it blocks')
|
|
247
|
+
.argument('<id>', 'Task ID')
|
|
248
|
+
.action(async (id: string) => {
|
|
249
|
+
try {
|
|
250
|
+
const data = await graphql<{ blockedBy: unknown[]; blocks: unknown[] }>(
|
|
251
|
+
`query TaskDeps($id: String!) {
|
|
252
|
+
blockedBy: edges(nodeId: $id, relation: "blocks", direction: "incoming") {
|
|
253
|
+
id type title status
|
|
254
|
+
}
|
|
255
|
+
blocks: edges(nodeId: $id, relation: "blocks", direction: "outgoing") {
|
|
256
|
+
id type title status
|
|
257
|
+
}
|
|
258
|
+
}`,
|
|
259
|
+
{ id },
|
|
260
|
+
)
|
|
261
|
+
output({ id, blockedBy: data.blockedBy, blocks: data.blocks })
|
|
262
|
+
} catch (error) {
|
|
263
|
+
outputError(error)
|
|
264
|
+
}
|
|
265
|
+
})
|