|
1 | 1 | 'use strict' |
2 | 2 | const { describe, it } = require('node:test') |
3 | 3 | const assert = require('node:assert/strict') |
| 4 | +const { mkdtempSync, writeFileSync, rmSync } = require('fs') |
| 5 | +const { tmpdir } = require('os') |
| 6 | +const { join } = require('path') |
4 | 7 |
|
5 | 8 | describe('TaskRepository', () => { |
6 | 9 | it('exports TaskRepository and taskRepo', () => { |
@@ -41,4 +44,79 @@ describe('TaskRepository', () => { |
41 | 44 | assert.deepEqual(task.assignees, ['writer-a']) |
42 | 45 | assert.equal(task.assignedAgent, 'writer-a') |
43 | 46 | }) |
| 47 | + |
| 48 | + describe('readTaskOutput', () => { |
| 49 | + const { taskRepo } = require('../../../core/repo/task.cjs') |
| 50 | + |
| 51 | + it('returns null for missing / empty output', () => { |
| 52 | + assert.equal(taskRepo.readTaskOutput(null), null) |
| 53 | + assert.equal(taskRepo.readTaskOutput({}), null) |
| 54 | + assert.equal(taskRepo.readTaskOutput({ output: '' }), null) |
| 55 | + }) |
| 56 | + |
| 57 | + it('reads a single existing file path (absolute)', () => { |
| 58 | + const dir = mkdtempSync(join(tmpdir(), 'af-readoutput-')) |
| 59 | + try { |
| 60 | + const f = join(dir, 'a.md') |
| 61 | + writeFileSync(f, '# Hello') |
| 62 | + const content = taskRepo.readTaskOutput({ output: f }) |
| 63 | + assert.equal(content, '# Hello') |
| 64 | + } finally { |
| 65 | + rmSync(dir, { recursive: true, force: true }) |
| 66 | + } |
| 67 | + }) |
| 68 | + |
| 69 | + it('reads comma-separated multi-path output (the bug that caused the rework death spiral)', () => { |
| 70 | + const dir = mkdtempSync(join(tmpdir(), 'af-readoutput-')) |
| 71 | + try { |
| 72 | + const a = join(dir, 'a.md') |
| 73 | + const b = join(dir, 'b.md') |
| 74 | + writeFileSync(a, 'Alpha content') |
| 75 | + writeFileSync(b, 'Beta content') |
| 76 | + const content = taskRepo.readTaskOutput({ output: `${a}, ${b}` }) |
| 77 | + assert.ok(content, 'should return non-null') |
| 78 | + assert.match(content, /Alpha content/) |
| 79 | + assert.match(content, /Beta content/) |
| 80 | + assert.match(content, /---/, 'should separate files with divider') |
| 81 | + } finally { |
| 82 | + rmSync(dir, { recursive: true, force: true }) |
| 83 | + } |
| 84 | + }) |
| 85 | + |
| 86 | + it('accepts array of paths', () => { |
| 87 | + const dir = mkdtempSync(join(tmpdir(), 'af-readoutput-')) |
| 88 | + try { |
| 89 | + const a = join(dir, 'a.md') |
| 90 | + writeFileSync(a, 'content A') |
| 91 | + const content = taskRepo.readTaskOutput({ output: [a] }) |
| 92 | + assert.match(content, /content A/) |
| 93 | + } finally { |
| 94 | + rmSync(dir, { recursive: true, force: true }) |
| 95 | + } |
| 96 | + }) |
| 97 | + |
| 98 | + it('skips non-existent paths but returns content from existing ones', () => { |
| 99 | + const dir = mkdtempSync(join(tmpdir(), 'af-readoutput-')) |
| 100 | + try { |
| 101 | + const a = join(dir, 'a.md') |
| 102 | + writeFileSync(a, 'real content') |
| 103 | + const content = taskRepo.readTaskOutput({ output: `${a}, ${dir}/missing.md` }) |
| 104 | + assert.match(content, /real content/) |
| 105 | + } finally { |
| 106 | + rmSync(dir, { recursive: true, force: true }) |
| 107 | + } |
| 108 | + }) |
| 109 | + |
| 110 | + it('returns null when all paths are missing', () => { |
| 111 | + assert.equal( |
| 112 | + taskRepo.readTaskOutput({ output: '/nope/a.md, /nope/b.md' }), |
| 113 | + null |
| 114 | + ) |
| 115 | + }) |
| 116 | + |
| 117 | + it('treats non-path strings as inline content (legacy)', () => { |
| 118 | + const content = taskRepo.readTaskOutput({ output: 'PM Review 通过: commit abc — tests OK' }) |
| 119 | + assert.equal(content, 'PM Review 通过: commit abc — tests OK') |
| 120 | + }) |
| 121 | + }) |
44 | 122 | }) |
0 commit comments