(packet: FactPacket, rank: (kind: CardKind) => number)
| 250 | // ------------------------------------------------------------- the drafts --- |
| 251 | |
| 252 | function subjectDrafts(packet: FactPacket, rank: (kind: CardKind) => number): Draft[] { |
| 253 | const ir = packet.subjectIr; |
| 254 | if (ir === undefined) { |
| 255 | return []; |
| 256 | } |
| 257 | const source = sourceOfIr(ir); |
| 258 | const drafts: Draft[] = []; |
| 259 | |
| 260 | /* |
| 261 | * The counting sentence goes LAST, and that ordering was bought with an |
| 262 | * eval pass. With it on line two, two of the smaller candidates answered |
| 263 | * "what does listUsers do" with "it makes 1 call(s), reads 0 environment |
| 264 | * value(s)" and never reached the card that names the call. A count is a |
| 265 | * true fact and a useless answer, and a card's second line is the one a |
| 266 | * small model reaches for first. |
| 267 | */ |
| 268 | const identity: string[] = [ |
| 269 | `${whereOf(source)} is a ${ir.symbol.kind} in this project.`, |
| 270 | ir.tests.value.length === 0 |
| 271 | ? 'The index records no test that reaches it.' |
| 272 | : `The index records ${ir.tests.value.length} test(s) reaching it: ` |
| 273 | + `${listOf(ir.tests.value.map((test) => test.name), 3)}.`, |
| 274 | `It makes ${ir.calls.value.length} call(s), reads ${ir.reads.value.length} ` |
| 275 | + `environment value(s) and can raise ${ir.throws.value.length} error type(s).`, |
| 276 | ]; |
| 277 | drafts.push({ kind: 'subject', lines: identity, source, rank: rank('subject') }); |
| 278 | |
| 279 | if (ir.steps.value.length > 0) { |
| 280 | const calls = ir.steps.value.map((call) => { |
| 281 | const verb = call.strategy === 'construction' ? 'constructs' : 'calls'; |
| 282 | const line = call.line === undefined ? '' : ` [line ${call.line}]`; |
| 283 | return `${verb} ${call.targetName}${line}`; |
| 284 | }); |
| 285 | drafts.push({ |
| 286 | kind: 'calls', |
| 287 | lines: [`${ir.symbol.name}, in body order: ${listOf(calls)}.`], |
| 288 | source, |
| 289 | rank: rank('calls'), |
| 290 | }); |
| 291 | } |
| 292 | |
| 293 | const raiseLines: string[] = []; |
| 294 | if (ir.throws.value.length > 0) { |
| 295 | raiseLines.push( |
| 296 | `${ir.symbol.name} can raise ${listOf(ir.throws.value.map((raise) => { |
| 297 | const file = workspacePathOf(raise.file); |
| 298 | const at = raise.line === undefined |
| 299 | ? '' |
| 300 | : ` [${file.length > 0 ? `${file}:` : 'line '}${raise.line}]`; |
| 301 | return `${raise.type}${at}`; |
| 302 | }))}.`, |
| 303 | ); |
| 304 | } else if (ir.throws.state === 'known') { |
| 305 | raiseLines.push(`The index records no error type raised by ${ir.symbol.name}.`); |
| 306 | } |
| 307 | const envReads = ir.reads.value.filter((read) => read.kind === 'global'); |
| 308 | if (envReads.length > 0) { |
| 309 | raiseLines.push( |
no test coverage detected