From b80180e77eebad8476aa66c8a5433764da672c62 Mon Sep 17 00:00:00 2001 From: Christian Cleberg Date: Wed, 15 Jul 2026 17:26:22 -0500 Subject: docs: document the exported API, and fix five bugs found writing it (#2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * docs: translate Russian comments and document exported API The package carried 35 Russian comments and no doc comments on its exported identifiers, so pkg.go.dev rendered a bare list of signatures. Translate the Russian to English and give every exported identifier a doc comment in godoc form. Add doc.go with a package overview covering the guest-session requirement, the Error-as-struct convention, and CloudFront blocking. The comments record what the signatures cannot: that UpdateCSRF must run first and that its token expires, that Error is a struct and so is never nil, that Thread is one comment rather than a thread, and that GetComments' page parameter costs one request per page. Comments only; the struct field realignment is gofmt's, from doc comments splitting alignment groups. Refs #1 * add CODEOWNERS * fix: stop the library killing its caller, and flatten text correctly Writing doc comments for the exported API surfaced behavior too alarming to document and leave alone. A library should never terminate the process that imports it. Crashes: - GetComments panicked on a comment with an empty body: the shape check read m[0] and m[len(m)-1] with no length check. - Group.Favourites and Group.Gallery indexed their variadic folderid without checking len, so omitting it — which the signature invites — panicked. Omitting it now means 0. - AEmedia and PerformSearch called log.Fatalln on a bad argument rune, terminating the caller. Both now return an error, which their signatures already allowed for. Draft.js flattening, in the same code both callers share: - The block loop assigned rather than accumulated, so every block but the last was dropped and a multi-paragraph body came back as its closing line alone. Blocks are block-level elements, so join them with newlines. - GetDeviation guarded on txt[1] == '{', the second character of a body that opens with {"blocks". It never fired, so descriptions were handed back as raw Draft.js JSON. It now shares flattenComment with GetComments rather than keeping its own copy. Both flattening fixes change output for existing callers. Refs #1 --- misc_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 misc_test.go (limited to 'misc_test.go') diff --git a/misc_test.go b/misc_test.go new file mode 100644 index 0000000..1141d4a --- /dev/null +++ b/misc_test.go @@ -0,0 +1,40 @@ +package devianter + +import "testing" + +// Regression: AEmedia used to call log.Fatalln on an unknown type, terminating +// the calling process. If this test ever regresses it will not fail — the test +// binary will exit(1) mid-run. +func TestAEmediaInvalidTypeReturnsError(t *testing.T) { + _, err := AEmedia("someuser", 'z') + if err == nil { + t.Fatal("want an error for an unknown type, got nil") + } +} + +// The argument checks must run in an order that never leaves a valid-looking +// call unreported: a short name is an error regardless of type. +func TestAEmediaShortNameReturnsError(t *testing.T) { + if _, err := AEmedia("", 'a'); err == nil { + t.Fatal("want an error for an empty name, got nil") + } +} + +// Regression: PerformSearch used to call log.Fatalln on an unknown scope. As +// above, a regression exits the test binary rather than failing this test. +func TestPerformSearchInvalidScopeReturnsError(t *testing.T) { + _, _, err := PerformSearch("cats", 0, 'z') + if err == nil { + t.Fatal("want an error for an unknown scope, got nil") + } +} + +// The account-scoped searches need a username, and must say so rather than +// requesting a URL with an empty one. +func TestPerformSearchAccountScopesRequireUser(t *testing.T) { + for _, scope := range []rune{'g', 'f'} { + if _, _, err := PerformSearch("cats", 0, scope); err == nil { + t.Errorf("want an error for scope %q with no username, got nil", scope) + } + } +} -- cgit v1.2.3