Skip to content

Commit 7e44e71

Browse files
fix(lesswrong): drop "Unknown" silent sentinel in author column (#1611)
* 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 7164615 (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).
1 parent 76a9c78 commit 7e44e71

14 files changed

Lines changed: 49 additions & 108 deletions

clis/lesswrong/comments.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ cli({
5656
rows.push({
5757
rank: i + 1,
5858
score: item.baseScore ?? 0,
59-
author: user?.displayName ?? 'Unknown',
59+
author: user?.displayName ?? '',
6060
text: raw.length > 500 ? `${raw.slice(0, 500)}...` : raw,
6161
});
6262
}

clis/lesswrong/curated.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ cli({
2222
return posts.map((item, i) => ({
2323
rank: i + 1,
2424
title: item.title ?? '',
25-
author: item.user?.displayName ?? 'Unknown',
25+
author: item.user?.displayName ?? '',
2626
karma: item.baseScore ?? 0,
2727
comments: item.commentCount ?? 0,
2828
url: `https://${DOMAIN}/posts/${item._id}/${item.slug}`,

clis/lesswrong/frontpage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ cli({
2222
return posts.map((item, i) => ({
2323
rank: i + 1,
2424
title: item.title ?? '',
25-
author: item.user?.displayName ?? 'Unknown',
25+
author: item.user?.displayName ?? '',
2626
karma: item.baseScore ?? 0,
2727
comments: item.commentCount ?? 0,
2828
url: `https://${DOMAIN}/posts/${item._id}/${item.slug}`,

clis/lesswrong/frontpage.test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { beforeEach, describe, expect, it, vi } from 'vitest';
2+
import { getRegistry } from '@jackwener/opencli/registry';
3+
4+
const { gqlRequestMock } = vi.hoisted(() => ({ gqlRequestMock: vi.fn() }));
5+
vi.mock('./_helpers.js', async () => {
6+
const actual = await vi.importActual('./_helpers.js');
7+
return { ...actual, gqlRequest: gqlRequestMock };
8+
});
9+
10+
import './frontpage.js';
11+
12+
describe('lesswrong frontpage', () => {
13+
beforeEach(() => {
14+
gqlRequestMock.mockReset();
15+
});
16+
17+
it('emits empty-string for missing user.displayName instead of a sentinel', async () => {
18+
const command = getRegistry().get('lesswrong/frontpage');
19+
expect(command?.func).toBeDefined();
20+
gqlRequestMock.mockResolvedValueOnce({
21+
posts: {
22+
results: [
23+
{ _id: 'a1', slug: 'post-a', title: 'Has author', user: { displayName: 'Real Person' }, baseScore: 10, commentCount: 3 },
24+
{ _id: 'b2', slug: 'post-b', title: 'Deleted user', user: null, baseScore: 5, commentCount: 0 },
25+
{ _id: 'c3', slug: 'post-c', title: 'Missing name', user: {}, baseScore: 7, commentCount: 1 },
26+
],
27+
},
28+
});
29+
const rows = await command.func({ limit: 3 });
30+
expect(rows).toHaveLength(3);
31+
expect(rows[0]).toMatchObject({ rank: 1, title: 'Has author', author: 'Real Person', karma: 10, comments: 3 });
32+
expect(rows[1].author).toBe('');
33+
expect(rows[1].title).toBe('Deleted user');
34+
expect(rows[2].author).toBe('');
35+
expect(rows[2].title).toBe('Missing name');
36+
});
37+
});

clis/lesswrong/new.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ cli({
2222
return posts.map((item, i) => ({
2323
rank: i + 1,
2424
title: item.title ?? '',
25-
author: item.user?.displayName ?? 'Unknown',
25+
author: item.user?.displayName ?? '',
2626
karma: item.baseScore ?? 0,
2727
comments: item.commentCount ?? 0,
2828
url: `https://${DOMAIN}/posts/${item._id}/${item.slug}`,

clis/lesswrong/read.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ cli({
3434
return [
3535
{
3636
title: post.title ?? '',
37-
author: post.user?.displayName ?? 'Unknown',
37+
author: post.user?.displayName ?? '',
3838
karma: post.baseScore ?? 0,
3939
comments: post.commentCount ?? 0,
4040
tags: (post.tags ?? []).map((tag) => tag.name ?? '').filter(Boolean).join(', '),

clis/lesswrong/sequences.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ cli({
2222
return sequences.map((item, i) => ({
2323
rank: i + 1,
2424
title: item.title ?? '',
25-
author: item.user?.displayName ?? 'Unknown',
25+
author: item.user?.displayName ?? '',
2626
}));
2727
},
2828
});

clis/lesswrong/shortform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ cli({
2222
return posts.map((item, i) => ({
2323
rank: i + 1,
2424
title: item.title ?? '',
25-
author: item.user?.displayName ?? 'Unknown',
25+
author: item.user?.displayName ?? '',
2626
karma: item.baseScore ?? 0,
2727
comments: item.commentCount ?? 0,
2828
url: `https://${DOMAIN}/posts/${item._id}/${item.slug}`,

clis/lesswrong/tag.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ cli({
3737
return posts.map((item, i) => ({
3838
rank: i + 1,
3939
title: item.title ?? '',
40-
author: item.user?.displayName ?? 'Unknown',
40+
author: item.user?.displayName ?? '',
4141
karma: item.baseScore ?? 0,
4242
comments: item.commentCount ?? 0,
4343
url: `https://${DOMAIN}/posts/${item._id}/${item.slug}`,

clis/lesswrong/top-month.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ cli({
2222
return posts.map((item, i) => ({
2323
rank: i + 1,
2424
title: item.title ?? '',
25-
author: item.user?.displayName ?? 'Unknown',
25+
author: item.user?.displayName ?? '',
2626
karma: item.baseScore ?? 0,
2727
comments: item.commentCount ?? 0,
2828
url: `https://${DOMAIN}/posts/${item._id}/${item.slug}`,

0 commit comments

Comments
 (0)