Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions clis/apple-podcasts/commands.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ describe('apple-podcasts search command', () => {
}),
]);
});
it('emits empty-string for missing trackCount and primaryGenreName instead of a sentinel', async () => {
const cmd = getRegistry().get('apple-podcasts/search');
const fetchMock = vi.fn().mockResolvedValue({
ok: true,
json: () => Promise.resolve({
results: [
{
collectionId: 99,
collectionName: 'No-Meta Show',
artistName: 'Anon Host',
collectionViewUrl: 'https://example.com/p/99',
},
],
}),
});
vi.stubGlobal('fetch', fetchMock);
const result = await cmd.func({ query: 'no-meta', limit: 1 });
expect(result[0].episodes).toBe('');
expect(result[0].genre).toBe('');
});
});
describe('apple-podcasts top command', () => {
beforeEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions clis/apple-podcasts/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ cli({
id: p.collectionId,
title: p.collectionName,
author: p.artistName,
episodes: p.trackCount ?? '-',
genre: p.primaryGenreName ?? '-',
episodes: p.trackCount ?? '',
genre: p.primaryGenreName ?? '',
url: p.collectionViewUrl || '',
}));
},
Expand Down
4 changes: 2 additions & 2 deletions clis/gitee/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ cli({
rows.push({
rank: rows.length + 1,
name,
language: normalizeText(getFirstText(fields.langs)) || '-',
description: normalizeText(getFirstText(fields.description)) || '-',
language: normalizeText(getFirstText(fields.langs)) || '',
description: normalizeText(getFirstText(fields.description)) || '',
stars: normalizeStars(fields['count.star']),
url: repoUrl,
});
Expand Down
65 changes: 65 additions & 0 deletions clis/gitee/search.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { getRegistry } from '@jackwener/opencli/registry';
import './search.js';

function mockGiteeResponse(hits) {
return {
ok: true,
json: () => Promise.resolve({ hits: { hits } }),
};
}

function makePage() {
return {
goto: vi.fn().mockResolvedValue(undefined),
wait: vi.fn().mockResolvedValue(undefined),
};
}

describe('gitee search', () => {
beforeEach(() => {
vi.restoreAllMocks();
});
afterEach(() => {
vi.unstubAllGlobals();
});

it('emits empty-string for missing language / description instead of a sentinel', async () => {
const cmd = getRegistry().get('gitee/search');
expect(cmd?.func).toBeTypeOf('function');
const fetchMock = vi.fn().mockResolvedValue(mockGiteeResponse([
{
fields: {
title: 'someuser/no-meta-repo',
url: 'https://gitee.com/someuser/no-meta-repo',
},
},
]));
vi.stubGlobal('fetch', fetchMock);
const rows = await cmd.func(makePage(), { keyword: 'test', limit: 10 });
expect(rows).toHaveLength(1);
expect(rows[0].name).toBe('someuser/no-meta-repo');
expect(rows[0].language).toBe('');
expect(rows[0].description).toBe('');
});

it('passes through populated language / description verbatim', async () => {
const cmd = getRegistry().get('gitee/search');
const fetchMock = vi.fn().mockResolvedValue(mockGiteeResponse([
{
fields: {
title: 'org/repo-a',
url: 'https://gitee.com/org/repo-a',
langs: 'TypeScript',
description: 'A test repo',
'count.star': '42',
},
},
]));
vi.stubGlobal('fetch', fetchMock);
const rows = await cmd.func(makePage(), { keyword: 'test', limit: 10 });
expect(rows[0].language).toBe('TypeScript');
expect(rows[0].description).toBe('A test repo');
expect(rows[0].stars).toBe('42');
});
});
2 changes: 1 addition & 1 deletion clis/reddit/saved.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ cli({
});
const d = await res.json();
return (d?.data?.children || []).map(c => ({
title: c.data.title || c.data.body?.slice(0, 100) || '-',
title: c.data.title || c.data.body?.slice(0, 100) || '',
subreddit: c.data.subreddit_name_prefixed || 'r/' + (c.data.subreddit || '?'),
score: c.data.score || 0,
comments: c.data.num_comments || 0,
Expand Down
2 changes: 1 addition & 1 deletion clis/reddit/upvoted.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ cli({
});
const d = await res.json();
return (d?.data?.children || []).map(c => ({
title: c.data.title || '-',
title: c.data.title || '',
subreddit: c.data.subreddit_name_prefixed || 'r/' + (c.data.subreddit || '?'),
score: c.data.score || 0,
comments: c.data.num_comments || 0,
Expand Down
52 changes: 2 additions & 50 deletions scripts/typed-error-lint-baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -819,15 +819,15 @@
"rule": "silent-clamp",
"command": "zhihu/collection",
"file": "clis/zhihu/collection.js",
"line": 141,
"line": 154,
"text": "const currentFetchLimit = Math.min(pageLimit, requestedLimit - collected.length);",
"occurrence": 0
},
{
"rule": "silent-clamp",
"command": "zhihu/collection",
"file": "clis/zhihu/collection.js",
"line": 130,
"line": 143,
"text": "const pageLimit = Math.min(requestedLimit, 20); // 知乎 API 限制每页最大 20",
"occurrence": 0
},
Expand Down Expand Up @@ -855,22 +855,6 @@
"text": "const limit = Math.max(1, Math.min(Number(args.limit) || 10, 25));",
"occurrence": 0
},
{
"rule": "silent-sentinel",
"command": "apple-podcasts/search",
"file": "clis/apple-podcasts/search.js",
"line": 26,
"text": "episodes: p.trackCount ?? '-',",
"occurrence": 0
},
{
"rule": "silent-sentinel",
"command": "apple-podcasts/search",
"file": "clis/apple-podcasts/search.js",
"line": 27,
"text": "genre: p.primaryGenreName ?? '-',",
"occurrence": 0
},
{
"rule": "silent-sentinel",
"command": "bilibili/download",
Expand All @@ -887,22 +871,6 @@
"text": "const jobName = f.jobName || 'unknown';",
"occurrence": 0
},
{
"rule": "silent-sentinel",
"command": "gitee/search",
"file": "clis/gitee/search.js",
"line": 127,
"text": "description: normalizeText(getFirstText(fields.description)) || '-',",
"occurrence": 0
},
{
"rule": "silent-sentinel",
"command": "gitee/search",
"file": "clis/gitee/search.js",
"line": 126,
"text": "language: normalizeText(getFirstText(fields.langs)) || '-',",
"occurrence": 0
},
{
"rule": "silent-sentinel",
"command": "gitee/trending",
Expand Down Expand Up @@ -935,22 +903,6 @@
"text": "prompt: params.prompt || item.common_attr?.title || 'N/A',",
"occurrence": 0
},
{
"rule": "silent-sentinel",
"command": "reddit/saved",
"file": "clis/reddit/saved.js",
"line": 33,
"text": "title: c.data.title || c.data.body?.slice(0, 100) || '-',",
"occurrence": 0
},
{
"rule": "silent-sentinel",
"command": "reddit/upvoted",
"file": "clis/reddit/upvoted.js",
"line": 33,
"text": "title: c.data.title || '-',",
"occurrence": 0
},
{
"rule": "silent-sentinel",
"command": "twitter/accept",
Expand Down
Loading