Marketing skills for Claude Code and AI agents. CRO, copywriting, SEO, analytics, and growth engineering.
JavaScript agent-skillsai-agentsai-seoclaudeclaude-codeclaude-code-pluginclaude-skillscodexcontent-marketingconversion-rate-optimizationcopywritingcursoremail-marketinggenerative-engine-optimizationgrowth-marketingmarketingmarketing-automationsaas-marketingseoskill-md
fix(buffer): preserve explicit false publication flags
Rudy Celekli40da26cea6aa
diff --git a/tests/clis/buffer-publish-flags.test.cjs b/tests/clis/buffer-publish-flags.test.cjsnew file mode 100644index 0000000..1f3d597--- /dev/null+++ b/tests/clis/buffer-publish-flags.test.cjs@@ -0,0 +1,35 @@+const { test } = require('node:test')+const assert = require('node:assert/strict')+const { spawnSync } = require('node:child_process')+const path = require('node:path')+const cli = path.resolve(__dirname, '../../tools/clis/buffer.js')+function run(flags, dry = false, forbidFetch = dry) {+ const argv = ['updates', 'create', '--profile-ids', 'one,two', '--text', 'Keep this queued', ...flags, ...(dry ? ['--dry-run'] : [])]+ const source = `global.fetch = async (url, options) => { ${forbidFetch ? "throw new Error('unexpected fetch')" : "return { status: 200, text: async () => JSON.stringify({ url, body: options.body }) }"} }; process.argv = ['node', ${JSON.stringify(cli)}, ...${JSON.stringify(argv)}]; require(${JSON.stringify(cli)});`+ return spawnSync(process.execPath, ['-e', source], { encoding: 'utf8', timeout: 5000, env: { ...process.env, BUFFER_API_KEY: 'fixture-token-never-sent' } })+}+function body(result) { assert.equal(result.status, 0, result.stderr); return new URLSearchParams(JSON.parse(result.stdout).body) }+for (const flag of ['now', 'top', 'shorten']) {+ test(`Buffer ${flag} preserves false and explicit true in the actual form request`, () => {+ assert.equal(body(run([`--${flag}`, 'false'])).get(flag), 'false')+ assert.equal(body(run([`--${flag}`, 'true'])).get(flag), 'true')+ assert.equal(body(run([`--${flag}`])).get(flag), 'true')+ assert.equal(body(run([])).has(flag), false)+ })+ test(`Buffer ${flag} rejects invalid state before fetch`, () => {+ for (const dry of [false, true]) {+ const result = run([`--${flag}`, 'maybe'], dry, true)+ assert.equal(result.status, 1)+ assert.match(result.stderr, /must be true or false/)+ assert.doesNotMatch(result.stderr, /unexpected fetch/)+ }+ })+}+test('false publishing state and repeated profiles survive a redacted offline preview', () => {+ const result = run(['--now', 'false', '--top', 'false', '--shorten', 'false'], true)+ const params = body(result)+ assert.deepEqual(params.getAll('profile_ids[]'), ['one', 'two'])+ assert.equal(params.get('text'), 'Keep this queued')+ for (const flag of ['now', 'top', 'shorten']) assert.equal(params.get(flag), 'false')+ assert.equal(result.stdout.includes('fixture-token-never-sent'), false)+})diff --git a/tools/clis/buffer.js b/tools/clis/buffer.jsindex 0ff2a14..3f1a000 100755--- a/tools/clis/buffer.js+++ b/tools/clis/buffer.js@@ -74,6 +74,12 @@ function parseArgs(args) {return result}+function booleanFlag(value, name) {+ if (value === true || value === 'true') return true+ if (value === 'false') return false+ throw new Error(`--${name} must be true or false`)+}+const args = parseArgs(rawArgs)const [cmd, sub, ...rest] = args._@@ -159,9 +165,9 @@ async function main() {formBody.append('text', text)profileIds.split(',').forEach(id => formBody.append('profile_ids[]', id.trim()))if (args['scheduled-at']) formBody.append('scheduled_at', args['scheduled-at'])- if (args.now) formBody.append('now', 'true')- if (args.top) formBody.append('top', 'true')- if (args.shorten) formBody.append('shorten', 'true')+ if (args.now !== undefined) formBody.append('now', String(booleanFlag(args.now, 'now')))+ if (args.top !== undefined) formBody.append('top', String(booleanFlag(args.top, 'top')))+ if (args.shorten !== undefined) formBody.append('shorten', String(booleanFlag(args.shorten, 'shorten')))if (args['dry-run']) {result = { _dry_run: true, method: 'POST', url: `${BASE_URL}/updates/create.json`, headers: { 'Authorization': '***', 'Content-Type': 'application/x-www-form-urlencoded', 'Accept': 'application/json' }, body: formBody.toString() }break