From 5ffc33e27b4ee954c746b25576bea706c9a41673 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 4 Dec 2026 05:41:54 +0000 Subject: [PATCH] brief --include coverage: return the framing as coverage, not stances (#27) The REST payload carries the per-outlet framing as stances ({outlet, stance, note}). --include coverage kept that array under its REST name, so a caller following the README found no coverage key. With --include, the CLI and io.sh now return it as coverage, [{outlet, framing, note}], the shape the MCP get_brief tool uses, and drop stances. Without --include the REST payload is unchanged. README says which name appears when. Test: test/brief-coverage.test.mjs; the #7 test now expects coverage. --- CHANGELOG.md | 6 +++ README.md | 4 ++ bin/indianopinion.mjs | 8 +++- io.sh | 2 +- test/brief-coverage.test.mjs | 75 ++++++++++++++++++++++++++++++++++++ test/fixes.test.mjs | 2 +- 6 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 test/brief-coverage.test.mjs diff --git a/CHANGELOG.md b/CHANGELOG.md index 63a97e8..05d486b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to the `indianopinion` npm package. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and versions follow [Semantic Versioning](https://semver.org/). +## [Unreleased] + +### Fixed + +- `brief --include coverage` returns the per-outlet framing as `coverage` (`[{outlet, framing, note}]`, the MCP `get_brief` shape) instead of under the REST name `stances`, in the CLI and in `io.sh`. With `--include`, `stances` is no longer in the output; without `--include` the REST payload is unchanged (#27). + ## [0.2.2] - 2026-10-22 ### Fixed diff --git a/README.md b/README.md index 8d01474..0656386 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,10 @@ Every command rejects a flag or extra word it does not take (exit 2), `--since` ISO 8601 (exit 6), and `brief --include` takes only `brief`, `analysis`, `coverage` and `sources` (exit 6). +`brief` without `--include` prints the REST payload as it is, where the per-outlet framing is the +`stances` array (`outlet`, `stance`, `note`). With `--include`, only the named parts are kept, and +`coverage` comes back as `coverage`: `[{outlet, framing, note}]`, the same as the MCP `get_brief` tool. + Output is JSON when stdout is not a terminal, or with `--json`; text on a terminal or with `--text`. Errors go to stderr (a JSON object in JSON mode). diff --git a/bin/indianopinion.mjs b/bin/indianopinion.mjs index 4b86fee..eb2dbbb 100755 --- a/bin/indianopinion.mjs +++ b/bin/indianopinion.mjs @@ -298,7 +298,7 @@ function printText(cmd, data) { w(`# ${data.title}`); w(`${data.section || ''} | ${data.published || ''} | ${data.corroboration} outlets`); w(data.url); w(''); if (data.brief) { w(data.brief); w(''); } if (data.analysis) { w('Analysis: ' + data.analysis); w(''); } - for (const s of data.stances || []) w(`- ${s.outlet}: ${s.stance}${s.note ? ` (${s.note})` : ''}`); + for (const s of data.coverage || coverageOf(data.stances)) w(`- ${s.outlet}: ${s.framing}${s.note ? ` (${s.note})` : ''}`); return; case 'digest': w(`Indian Opinion digest ${data.date}${data.lead ? `: ${data.lead}` : ''}`); w(data.web_url || ''); @@ -400,6 +400,7 @@ async function cmdBriefs(flags) { } const INCLUDE_FIELDS = ['brief', 'analysis', 'coverage', 'sources']; +const coverageOf = (stances) => (stances || []).map((s) => ({ outlet: s.outlet, framing: s.stance, note: s.note || null })); async function cmdBrief(pos, flags) { const v = pos[0]; @@ -433,7 +434,10 @@ async function cmdBrief(pos, flags) { if (!inc.includes('analysis')) delete b.analysis; if (!inc.includes('brief')) delete b.brief; if (!inc.includes('sources')) delete b.sources; - if (!inc.includes('coverage')) delete b.stances; + // The REST payload calls the per-outlet framing "stances" ({outlet, stance, note}); --include + // names it "coverage", so return it under that name and in the MCP get_brief shape (#27). + if (inc.includes('coverage')) b.coverage = coverageOf(b.stances); + delete b.stances; } return b; } diff --git a/io.sh b/io.sh index ca1dc80..fa5fb5f 100644 --- a/io.sh +++ b/io.sh @@ -264,7 +264,7 @@ case "$cmd" in if [ -n "$inc" ]; then OUT=$(printf '%s' "$OUT" | jq -c --arg inc "$inc" '($inc | split(",")) as $i | if ($i | index("analysis")) then . else del(.analysis) end | if ($i | index("brief")) then . else del(.brief) end | if ($i | index("sources")) then . else del(.sources) end - | if ($i | index("coverage")) then . else del(.stances) end') + | if ($i | index("coverage")) then .coverage = [(.stances // [])[] | {outlet, framing: .stance, note: (.note // null)}] else . end | del(.stances)') fi emit "$OUT" ;; topics) diff --git a/test/brief-coverage.test.mjs b/test/brief-coverage.test.mjs new file mode 100644 index 0000000..422c445 --- /dev/null +++ b/test/brief-coverage.test.mjs @@ -0,0 +1,75 @@ +// #27: brief --include coverage returns the per-outlet framing as "coverage", the name the +// README, the validation and the MCP get_brief tool use, instead of the REST name "stances". +// Node CLI and io.sh against the REST stub; no network. + +import { test, before, after } from 'node:test'; +import assert from 'node:assert/strict'; +import { spawn, spawnSync } from 'node:child_process'; +import fs from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { startStub, GOOD_TOKEN } from './stub-rest.mjs'; + +const HERE = path.dirname(fileURLToPath(import.meta.url)); +const ROOT = path.join(HERE, '..'); +const BIN = path.join(ROOT, 'bin', 'indianopinion.mjs'); +const IOSH = path.join(ROOT, 'io.sh'); +const HAVE_CURL = spawnSync('bash', ['-c', 'command -v curl']).status === 0; +const HAVE_JQ = spawnSync('bash', ['-c', 'command -v jq']).status === 0; +let stub; let home; + +function run(args, { env = {}, bin = 'node' } = {}) { + const [cmd, argv] = bin === 'node' ? [process.execPath, [BIN, ...args]] : ['bash', [IOSH, ...args]]; + return new Promise((resolve) => { + const child = spawn(cmd, argv, { env: { PATH: process.env.PATH, HOME: home, XDG_CONFIG_HOME: path.join(home, '.config'), IO_API: stub.api, IO_TOKEN: GOOD_TOKEN, ...env } }); + let out = ''; let errs = ''; + child.stdout.on('data', (d) => { out += d; }); + child.stderr.on('data', (d) => { errs += d; }); + child.stdin.end(); + child.on('close', (code) => resolve({ code, out, err: errs })); + }); +} + +before(async () => { stub = await startStub(); home = fs.mkdtempSync(path.join(os.tmpdir(), 'io-coverage-')); }); +after(async () => { await stub.close(); }); + +const bins = () => ['node', ...(HAVE_CURL && HAVE_JQ ? ['bash'] : [])]; + +const want = (b) => b.stances.map((s) => ({ outlet: s.outlet, framing: s.stance, note: s.note || null })); + +test('#27: --include coverage returns coverage (outlet, framing, note) and nothing under stances', async () => { + const full = JSON.parse((await run(['brief', '99812'])).out); + assert.ok(Array.isArray(full.stances) && full.stances.length === 3, 'the stub brief has three stances'); + for (const bin of bins()) { + let r = await run(['brief', '99812', '--include', 'coverage'], { bin }); + assert.equal(r.code, 0, `${bin}: ${r.err}`); + let b = JSON.parse(r.out); + assert.deepEqual(b.coverage, want(full), `${bin} coverage`); + for (const k of ['stances', 'brief', 'analysis', 'sources']) assert.equal(b[k], undefined, `${bin} --include coverage still has ${k}`); + assert.equal(b.id, 99812); + + r = await run(['brief', '99812', '--include', 'brief,coverage,sources'], { bin }); + b = JSON.parse(r.out); + assert.ok(b.brief && b.sources && b.coverage, `${bin} brief,coverage,sources`); + assert.equal(b.stances, undefined); + assert.equal(b.analysis, undefined); + + r = await run(['brief', '99812', '--include', 'brief'], { bin }); + b = JSON.parse(r.out); + assert.equal(b.coverage, undefined, `${bin} --include brief has no coverage`); + assert.equal(b.stances, undefined, `${bin} --include brief has no stances`); + + // Without --include, the REST payload is unchanged. + r = await run(['brief', '99812'], { bin }); + assert.deepEqual(JSON.parse(r.out), full, `${bin} without --include`); + } +}); + +test('#27: the text view lists the coverage with or without --include', async () => { + for (const args of [['brief', '99812', '--text'], ['brief', '99812', '--text', '--include', 'coverage']]) { + const r = await run(args); + assert.equal(r.code, 0, r.err); + assert.match(r.out, /- thehindu\.com: neutral-report \(Straight account\)/, args.join(' ')); + } +}); diff --git a/test/fixes.test.mjs b/test/fixes.test.mjs index 85016f1..4a086f5 100644 --- a/test/fixes.test.mjs +++ b/test/fixes.test.mjs @@ -133,7 +133,7 @@ test('#7: brief --include rejects unknown fields (exit 6)', async () => { assert.equal(r.code, 6); r = await run(['brief', '99812', '--include', 'brief,coverage']); assert.equal(r.code, 0, r.err); - assert.ok(r.json.brief && r.json.stances && !r.json.sources); + assert.ok(r.json.brief && r.json.coverage && !r.json.stances && !r.json.sources); // coverage by its name (#27) }); test('following --cursor never skips a brief, even when the API overfills a page', async () => {