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(github): fail prospect exports when profile enrichment fails
Rudy Celekli7c9e986dc97c
diff --git a/tests/github-enrichment.test.cjs b/tests/github-enrichment.test.cjsnew file mode 100644index 0000000..706104c--- /dev/null+++ b/tests/github-enrichment.test.cjs@@ -0,0 +1,39 @@+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/github-prospects.js')+function run(command, status, args = []) {+ const source = `global.fetch = async url => {+ const profile = String(url).includes('/users/');+ const status = profile ? ${status} : 200;+ return {status, ok: status === 200, headers: {get: () => null},+ text: async () => JSON.stringify({message:'fixture failure'}),+ json: async () => profile ? {login:'alice',email:null,company:'Example',type:'User'} : ${JSON.stringify(command === 'forks' ? [{owner:{login:'alice'}}] : [{login:'alice'}])}};+ }; process.argv = ['node', ${JSON.stringify(cli)}, ${JSON.stringify(command)}, 'owner/repo', '--enrich', ...${JSON.stringify(args)}]; require(${JSON.stringify(cli)});`+ return spawnSync(process.execPath, ['-e', source], {encoding:'utf8', env:{...process.env,GITHUB_TOKEN:'fixture-key'}})+}+test('authentication or rate-limit failures cannot look like a successful empty prospect export', () => {+ for (const command of ['stargazers','forks','watchers']) {+ for (const status of [401,403,429,500]) {+ const result = run(command, status, ['--format','csv'])+ assert.equal(result.status, 1, `${command}/${status}: ${result.stdout}`)+ assert.equal(result.stdout, '')+ assert.match(JSON.parse(result.stderr).error, new RegExp(`Profile enrichment failed: HTTP ${status}`))+ }+ }+})+test('deleted profiles can still be skipped', () => {+ const result = run('stargazers',404)+ assert.equal(result.status,0,result.stderr)+ assert.equal(JSON.parse(result.stdout).count,0)+})+test('normal profiles and legitimate filter non-matches still return success', () => {+ const success = run('stargazers',200)+ assert.equal(success.status,0,success.stderr)+ assert.equal(JSON.parse(success.stdout).users[0].login,'alice')+ const filtered = run('watchers',200,['--with-email'])+ assert.equal(filtered.status,0,filtered.stderr)+ assert.equal(JSON.parse(filtered.stdout).count,0)+})diff --git a/tools/clis/github-prospects.js b/tools/clis/github-prospects.jsindex e416381..4e17091 100755--- a/tools/clis/github-prospects.js+++ b/tools/clis/github-prospects.js@@ -52,6 +52,7 @@ async function api(path, opts = {}) {const body = await res.text()return {error: `HTTP ${res.status}`,+ status: res.status,hint: TOKEN? 'Token rejected — check GITHUB_TOKEN scopes (public_repo is enough for public data).': 'Set GITHUB_TOKEN env var to raise rate limit from 60/hr to 5000/hr.',@@ -63,7 +64,7 @@ async function api(path, opts = {}) {if (!res.ok) {const body = await res.text()- return { error: `HTTP ${res.status}`, body }+ return { error: `HTTP ${res.status}`, status: res.status, body }}const data = await res.json()@@ -116,6 +117,9 @@ async function enrichUsers(users, opts = {}, { concurrency = 5, targetCount } =const batch = users.slice(i, i + concurrency)const profiles = await Promise.all(batch.map(u => getUser(u.login)))for (const profile of profiles) {+ if (profile?.error && profile.status !== 404) {+ throw new Error(`Profile enrichment failed: ${profile.error}`)+ }if (!profile || profile.error) continueif (matchesFilter(profile, opts)) matched.push(profile)}diff --git a/tools/integrations/github.md b/tools/integrations/github.mdindex fc04a1b..e7b2917 100644--- a/tools/integrations/github.md+++ b/tools/integrations/github.md@@ -180,3 +180,11 @@ See `skills/prospecting/references/saas-prospecting.md` and `data-sources.md` fo- prospecting (primary use case)- cold-email (downstream outreach)- competitor-profiling (deeper account-level research on individual stargazers worth pursuing)++### Enrichment failures++If profile enrichment fails because of authentication, rate limits, or another+HTTP error, `stargazers`, `forks`, and `watchers` exit with status 1 and a JSON+diagnostic on stderr. They do not print a partial CSV or a misleading successful+empty JSON export. A missing (404) user profile can still be skipped; a valid+profile that does not match the requested filters is also skipped.