import test from 'node:test';
import assert from 'node:assert/strict';
import { summarizeFailureOutput } from './plan-worker.js';

test('summarizeFailureOutput ignores structured zero-failure diff lines', () => {
  const output = [
    '```diff',
    '+ failedCount: 0,',
    '+ webFailed=0',
    '+ iosFailed=0,',
    '```',
    'actual failure: service file missing',
  ].join('\n');

  assert.equal(summarizeFailureOutput(output, 'fallback'), 'actual failure: service file missing');
});

test('summarizeFailureOutput falls back when output only contains zero-failure noise', () => {
  const output = [
    '```diff',
    '+ failedCount: 0,',
    '+ webFailed=0',
    '+ failedCount: number;',
    '```',
  ].join('\n');

  assert.equal(summarizeFailureOutput(output, 'fallback failure'), 'fallback failure');
});

test('summarizeFailureOutput ignores managed service success stub lines', () => {
  const output = [
    "return Promise.resolve({ ok: true, skipped: false, title: definition.title, body: '', itemCount: 0, lines: [], ios: { ok: true, skipped: true, sentCount: 0, failedCount: 0 }, web: { ok: true, skipped: true, sentCount: 0, failedCount: 0 }, definition });",
  ].join('\n');

  assert.equal(summarizeFailureOutput(output, 'fallback success'), 'fallback success');
});
