diff --git a/scripts/orchestrate-codex-worker.sh b/scripts/orchestrate-codex-worker.sh index a22703b9e..4e4cd8e35 100755 --- a/scripts/orchestrate-codex-worker.sh +++ b/scripts/orchestrate-codex-worker.sh @@ -32,8 +32,8 @@ EOF mkdir -p "$(dirname "$handoff_file")" "$(dirname "$status_file")" -if [[ ! -r "$task_file" ]]; then - write_status "failed" "- Error: task file is missing or unreadable (\`$task_file\`)" +if [[ ! -f "$task_file" || ! -r "$task_file" ]]; then + write_status "failed" "- Error: task file is missing, unreadable, or not a regular file (\`$task_file\`)" { echo "# Handoff" echo @@ -41,7 +41,7 @@ if [[ ! -r "$task_file" ]]; then echo "- Branch: \`$(git rev-parse --abbrev-ref HEAD)\`" echo "- Worktree: \`$(pwd)\`" echo - echo "Task file is missing or unreadable: \`$task_file\`" + echo "Task file is missing, unreadable, or not a regular file: \`$task_file\`" } > "$handoff_file" exit 1 fi diff --git a/tests/scripts/orchestrate-codex-worker.test.js b/tests/scripts/orchestrate-codex-worker.test.js index a02a9df6f..533374a66 100644 --- a/tests/scripts/orchestrate-codex-worker.test.js +++ b/tests/scripts/orchestrate-codex-worker.test.js @@ -24,7 +24,7 @@ function test(desc, fn) { } } -function runWorker({ policy, exitCode = 0, outsideTask = false, relativeTask = false } = {}) { +function runWorker({ policy, exitCode = 0, outsideTask = false, relativeTask = false, directoryTask = false } = {}) { const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-orch-worker-')); const binDir = path.join(tempRoot, 'bin'); const captureFile = path.join(tempRoot, 'args.json'); @@ -34,7 +34,8 @@ function runWorker({ policy, exitCode = 0, outsideTask = false, relativeTask = f try { fs.mkdirSync(binDir); - fs.writeFileSync(taskFile, 'Make a focused change.'); + if (directoryTask) fs.mkdirSync(taskFile); + else fs.writeFileSync(taskFile, 'Make a focused change.'); fs.writeFileSync(path.join(binDir, 'codex'), `#!/usr/bin/env node const fs = require('fs'); const args = process.argv.slice(2); @@ -96,6 +97,15 @@ test('rejects a readable sibling task before invoking Codex', () => { assert.ok(result.workerStatus.includes('task file outside worktree')); }); +test('rejects a directory task before invoking Codex', () => { + const result = runWorker({ directoryTask: true }); + assert.notStrictEqual(result.status, 0); + assert.strictEqual(result.args, null); + assert.ok(result.workerStatus.includes('- State: failed')); + assert.ok(result.handoff.includes('Task file is missing, unreadable, or not a regular file')); + assert.ok(result.workerStatus.includes('task file is missing, unreadable, or not a regular file')); +}); + test('forwards the explicit supported approval policy', () => { const result = runWorker({ policy: 'on-request' }); assert.strictEqual(result.status, 0, result.stderr); @@ -140,11 +150,11 @@ test('fails fast for an unreadable task file and records failure artifacts', () assert.ok(statusContent.includes('- State: failed'), 'Status file should record the failure state'); assert.ok( - statusContent.includes('task file is missing or unreadable'), + statusContent.includes('task file is missing, unreadable, or not a regular file'), 'Status file should explain the task-file failure' ); assert.ok( - handoffContent.includes('Task file is missing or unreadable'), + handoffContent.includes('Task file is missing, unreadable, or not a regular file'), 'Handoff file should explain the task-file failure' ); } finally {