mirror of
https://github.com/jackwener/OpenCLI.git
synced 2026-09-14 18:25:42 +08:00
7e44e71150
* fix(lesswrong): drop "Unknown" silent sentinel in author column
Twelve lesswrong commands had `author: item.user?.displayName ?? 'Unknown'`
which masks the missing-author signal: an agent reading the result row
cannot distinguish "post has no associated user" from "author is literally
named Unknown". The repo's typed-error lint flags this pattern
(silent-sentinel rule, see scripts/check-typed-error-lint.mjs:323).
Replace `?? 'Unknown'` with `?? ''` so the missing-author case stays
visible as an empty string. Consistent with `clis/lesswrong/_helpers.js:68`
which was already using the empty-signal form.
Shrinks scripts/typed-error-lint-baseline.json from 173 to 161 entries.
Follows the same direction as #1603 (fix(adapters): surface silent empty
fallbacks).
Verified live: `opencli lesswrong frontpage --limit 2 -f json` returns
real posts with non-empty author values; empty-author rows would now
show `"author": ""` instead of fabricating `"Unknown"`.
* test(lesswrong): add empty-signal coverage for the author sentinel swap
Per owner's pattern in 71646158 (douyin/user-videos.test.js +
jike/read.test.js + weread/search-regression.test.js), pairs the
silent-sentinel value swap in this PR with a focused unit test that
mocks the upstream LessWrong GraphQL response to return posts where
`user` is null or `user.displayName` is missing, and asserts the row
surfaces `author: ''` instead of the old fabricated `'Unknown'`.
`clis/lesswrong/frontpage.test.js` is representative for the twelve
identical `author: item.user?.displayName ?? ''` swaps across
comments / curated / frontpage / new / read / sequences / shortform /
tag / top / top-month / top-week / top-year, all of which share the
exact same expression with no downstream sentinel consumer.
The empty-signal path is exercised live too: a deleted-account or
permission-restricted user shows up in the GraphQL response with
`user: null`, surfaces as `author: ''` post this PR (was 'Unknown'
before).
38 lines
1.6 KiB
JavaScript
38 lines
1.6 KiB
JavaScript
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { getRegistry } from '@jackwener/opencli/registry';
|
|
|
|
const { gqlRequestMock } = vi.hoisted(() => ({ gqlRequestMock: vi.fn() }));
|
|
vi.mock('./_helpers.js', async () => {
|
|
const actual = await vi.importActual('./_helpers.js');
|
|
return { ...actual, gqlRequest: gqlRequestMock };
|
|
});
|
|
|
|
import './frontpage.js';
|
|
|
|
describe('lesswrong frontpage', () => {
|
|
beforeEach(() => {
|
|
gqlRequestMock.mockReset();
|
|
});
|
|
|
|
it('emits empty-string for missing user.displayName instead of a sentinel', async () => {
|
|
const command = getRegistry().get('lesswrong/frontpage');
|
|
expect(command?.func).toBeDefined();
|
|
gqlRequestMock.mockResolvedValueOnce({
|
|
posts: {
|
|
results: [
|
|
{ _id: 'a1', slug: 'post-a', title: 'Has author', user: { displayName: 'Real Person' }, baseScore: 10, commentCount: 3 },
|
|
{ _id: 'b2', slug: 'post-b', title: 'Deleted user', user: null, baseScore: 5, commentCount: 0 },
|
|
{ _id: 'c3', slug: 'post-c', title: 'Missing name', user: {}, baseScore: 7, commentCount: 1 },
|
|
],
|
|
},
|
|
});
|
|
const rows = await command.func({ limit: 3 });
|
|
expect(rows).toHaveLength(3);
|
|
expect(rows[0]).toMatchObject({ rank: 1, title: 'Has author', author: 'Real Person', karma: 10, comments: 3 });
|
|
expect(rows[1].author).toBe('');
|
|
expect(rows[1].title).toBe('Deleted user');
|
|
expect(rows[2].author).toBe('');
|
|
expect(rows[2].title).toBe('Missing name');
|
|
});
|
|
});
|