Failing test: appendText without authorId does not attribute to any author
File: src/tests/backend/specs/api/appendTextAuthor.ts:65-89
Status on develop HEAD (b96e262): failing — reproducible locally.
Surfaced by #7789 (which un-skips the tests/backend/specs/api/ subtree from CI). Same shape as #7785 — listAuthorsOfPad reports one author when the test expected zero.
What the test does
it('appendText without authorId does not attribute to any author', async function () {
const newPadId = `appendTextNoAuthor_${makeid()}`;
await agent.get(`${endPoint('createPad')}?padID=${newPadId}`)
.set('Authorization', await common.generateJWTToken()).expect(200);
await agent.post(endPoint('appendText'))
.set('Authorization', await common.generateJWTToken())
.send({padID: newPadId, text: 'anonymous text'}).expect(200);
const authorsRes = await agent.get(`${endPoint('listAuthorsOfPad')}?padID=${newPadId}`)
.set('Authorization', await common.generateJWTToken()).expect(200);
// No authors should be listed for anonymous text
assert.equal(authorsRes.body.data.authorIDs.length, 0);
});
appendText is called without an authorId in the body. The test expects listAuthorsOfPad to return zero authors afterwards.
What happens
AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
1 !== 0
authorIDs.length === 1. The appendText API path is attributing the inserted text to some author even though the caller didn't supply one — probably the JWT subject, the default system author, or whatever appendText's handler falls back to when authorId is missing.
Why this is likely a test bug, not a code bug
Cross-reference #7785. Same surface: an API path that mutates content is implicitly attributing the content to an author when none is provided. The test assertion of zero authors is the stale expectation; the code's behaviour (attributing under some author so revisions remain anchored) is consistent across the API surface.
Suggested fixes (choose one)
- Update the assertion to
assert.equal(authorsRes.body.data.authorIDs.length, 1) (and optionally assert which author — the JWT subject vs. the default).
- Or, if anonymous-author behaviour is desired, change
appendText to skip author attribution when no authorId is supplied. This is the larger change and probably wants its own discussion.
Reproduction
NODE_ENV=production npx mocha --import=tsx --require ./tests/backend/diagnostics.ts \
--timeout 60000 tests/backend/specs/api/appendTextAuthor.ts
(Note: invisible in CI on develop until #7789 lands. The current pnpm test glob skips the entire tests/backend/specs/api/ subtree.)
Failing test:
appendText without authorId does not attribute to any authorFile:
src/tests/backend/specs/api/appendTextAuthor.ts:65-89Status on develop HEAD (b96e262): failing — reproducible locally.
Surfaced by #7789 (which un-skips the
tests/backend/specs/api/subtree from CI). Same shape as #7785 —listAuthorsOfPadreports one author when the test expected zero.What the test does
appendTextis called without anauthorIdin the body. The test expectslistAuthorsOfPadto return zero authors afterwards.What happens
authorIDs.length === 1. TheappendTextAPI path is attributing the inserted text to some author even though the caller didn't supply one — probably the JWT subject, the default system author, or whateverappendText's handler falls back to whenauthorIdis missing.Why this is likely a test bug, not a code bug
Cross-reference #7785. Same surface: an API path that mutates content is implicitly attributing the content to an author when none is provided. The test assertion of zero authors is the stale expectation; the code's behaviour (attributing under some author so revisions remain anchored) is consistent across the API surface.
Suggested fixes (choose one)
assert.equal(authorsRes.body.data.authorIDs.length, 1)(and optionally assert which author — the JWT subject vs. the default).appendTextto skip author attribution when noauthorIdis supplied. This is the larger change and probably wants its own discussion.Reproduction
NODE_ENV=production npx mocha --import=tsx --require ./tests/backend/diagnostics.ts \ --timeout 60000 tests/backend/specs/api/appendTextAuthor.ts(Note: invisible in CI on develop until #7789 lands. The current
pnpm testglob skips the entiretests/backend/specs/api/subtree.)