Files
Benjamin Liu 7e44e71150 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 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).
2026-05-18 19:18:51 +08:00

47 lines
1.7 KiB
JavaScript

import { cli, Strategy } from '@jackwener/opencli/registry';
import { EmptyResultError } from '@jackwener/opencli/errors';
import { DOMAIN, SITE, gqlEscape, gqlRequest, parsePostId, stripHtml, } from './_helpers.js';
cli({
site: SITE,
name: 'read',
access: 'read',
description: 'Read full post by URL or ID',
domain: DOMAIN,
strategy: Strategy.PUBLIC,
browser: false,
args: [
{
name: 'url-or-id',
type: 'string',
required: true,
positional: true,
help: 'Post URL or LessWrong post ID',
},
],
columns: ['title', 'author', 'karma', 'comments', 'tags', 'content', 'url'],
func: async (kwargs) => {
const postId = parsePostId(String(kwargs['url-or-id']));
const query = `query PostsSingle {
post(input: {selector: {documentId: "${gqlEscape(postId)}"}}) {
result { _id title user { displayName } baseScore commentCount htmlBody slug postedAt tags { name } }
}
}`;
const data = await gqlRequest(query);
const post = data?.post?.result;
if (!post?._id) {
throw new EmptyResultError('lesswrong read', `Post "${postId}" not found`);
}
return [
{
title: post.title ?? '',
author: post.user?.displayName ?? '',
karma: post.baseScore ?? 0,
comments: post.commentCount ?? 0,
tags: (post.tags ?? []).map((tag) => tag.name ?? '').filter(Boolean).join(', '),
content: stripHtml(post.htmlBody ?? ''),
url: `https://${DOMAIN}/posts/${post._id}/${post.slug}`,
},
];
},
});