Skip to content

Commit 7363dfb

Browse files
committed
test(dogfood): the timeline count as the member's own reads answer it
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jSrQVdYaC3GSLbQCFd
1 parent bf102e3 commit 7363dfb

1 file changed

Lines changed: 22 additions & 28 deletions

File tree

‎packages/qa/dogfood/test/record-page-timeline.dogfood.test.ts‎

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
// org-bound boot with plugin-audit's real writers: the comments, the activity
66
// mirror and the ledger rows are the ones the member's own writes produce.
77
//
8-
// The count is of rows the caller could read, and of no other: for each
9-
// member it equals the sum of the separate list reads it stands for, asked as
10-
// that member (the spec's timeline table). A member who may read the ledger
11-
// counts its field changes, and the activity's `updated` rows step aside; a
12-
// member refused the ledger counts no field change, and the updates stay.
8+
// The count is of rows the caller could read, and of no other: it equals the
9+
// sum of the separate list reads it stands for, asked as the same member (the
10+
// spec's timeline table), and the activity's `updated` rows step aside once a
11+
// field change is counted. A refused ledger read counting no field change is
12+
// pinned at the route (`record-page-routes.test.ts`): on this boot the
13+
// platform's member floor reads the ledger rows of a record the member reads.
1314

1415
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
1516
import { bootStack, type VerifyStack } from '@objectstack/verify';
@@ -23,28 +24,20 @@ import { catalogPermissionSet } from './catalog-permission-set.js';
2324

2425
const SYS = { isSystem: true } as const;
2526
const AUTHOR_EMAIL = 'timeline-author@verify.test';
26-
const PEER_EMAIL = 'timeline-peer@verify.test';
2727

28-
/** Object-level reads of the activity stream and the ledger — the author holds both. */
28+
/** Object-level reads of the activity stream and the ledger. */
2929
const streamReaderSet: PermissionSet = PermissionSetSchema.parse({
3030
name: 'tl_stream_reader',
3131
label: 'Timeline fixture — object-level sys_activity and sys_audit_log read',
3232
objects: { sys_activity: { allowRead: true }, sys_audit_log: { allowRead: true } },
3333
});
34-
/** The activity stream alone — the peer holds this, and no ledger read. */
35-
const activityReaderSet: PermissionSet = PermissionSetSchema.parse({
36-
name: 'tl_activity_reader',
37-
label: 'Timeline fixture — object-level sys_activity read',
38-
objects: { sys_activity: { allowRead: true } },
39-
});
4034

4135
const ALL_SOURCES = { discussion: true, activity: true, fieldChanges: true } as const;
4236

4337
describe('[#28737] the timeline part counts the 动态 stream the caller could read', () => {
4438
let stack: VerifyStack;
4539
let ql: any;
4640
let authorTok: string;
47-
let peerTok: string;
4841
let recordId: string;
4942

5043
const grant = async (email: string, set: PermissionSet) => {
@@ -57,18 +50,16 @@ describe('[#28737] the timeline part counts the 动态 stream the caller could r
5750
beforeAll(async () => {
5851
stack = await bootStack(commentsFixtureStack as never, {
5952
security: new SecurityPlugin({
60-
defaultPermissionSets: [...securityDefaultPermissionSets, cmtFixtureBaselineSet, streamReaderSet, activityReaderSet],
53+
defaultPermissionSets: [...securityDefaultPermissionSets, cmtFixtureBaselineSet, streamReaderSet],
6154
fallbackPermissionSet: cmtFixtureBaselineSet.name,
6255
}),
6356
extraPlugins: [new AuditPlugin()],
6457
orgContext: true,
6558
});
6659
await stack.signIn();
6760
authorTok = await stack.signUp(AUTHOR_EMAIL);
68-
peerTok = await stack.signUp(PEER_EMAIL);
6961
ql = await stack.kernel.getServiceAsync('objectql');
7062
await grant(AUTHOR_EMAIL, streamReaderSet);
71-
await grant(PEER_EMAIL, activityReaderSet);
7263

7364
// The record's stream, from its real producers: a create and two renames
7465
// (ledger rows and their activity mirror), two comments and a reply.
@@ -98,13 +89,14 @@ describe('[#28737] the timeline part counts the 动态 stream the caller could r
9889
armed: (o) => o.comments === 3 && o.ledger >= 3 && o.updates === 2,
9990
}),
10091
armedWhen({
101-
control: 'the author reads the ledger and the peer is refused it',
102-
disarmedBy: 'a peer who could read the ledger would make the refused-ledger case a statement about nothing',
92+
control: 'the member reads each source the count stands for',
93+
disarmedBy: 'a refused source read would leave the sum below a statement about a stream nobody counted',
10394
observe: async () => ({
104-
author: (await stack.apiAs(authorTok, 'GET', `/data/sys_audit_log?$top=1`)).status,
105-
peer: (await stack.apiAs(peerTok, 'GET', `/data/sys_audit_log?$top=1`)).status,
95+
comments: (await stack.apiAs(authorTok, 'GET', '/data/sys_comment?$top=1')).status,
96+
activity: (await stack.apiAs(authorTok, 'GET', '/data/sys_activity?$top=1')).status,
97+
ledger: (await stack.apiAs(authorTok, 'GET', '/data/sys_audit_log?$top=1')).status,
10698
}),
107-
armed: (o) => o.author === 200 && o.peer >= 400,
99+
armed: (o) => o.comments === 200 && o.activity === 200 && o.ledger === 200,
108100
}),
109101
]);
110102
}, 180_000);
@@ -138,19 +130,21 @@ describe('[#28737] the timeline part counts the 动态 stream the caller could r
138130
return RecordPageResponseSchema.parse(json.data).timeline;
139131
};
140132

141-
it('a member who reads the ledger counts its field changes, and the updates step aside', async () => {
133+
it('counts the stream as the separate reads answer it, and the updates step aside for the field changes', async () => {
142134
const expected = await expectedAs(authorTok);
143135
expect(expected.comments).toBe(3);
144136
expect(expected.changes).toBeGreaterThanOrEqual(3);
145137
expect(expected.updates).toBe(2);
146138
expect(await timelineAs(authorTok)).toEqual({ total: expected.total });
147139
}, 60_000);
148140

149-
it('a member refused the ledger counts no field change, and the updates stay', async () => {
150-
const expected = await expectedAs(peerTok);
151-
expect(expected.changes).toBe(0);
152-
expect(await timelineAs(peerTok)).toEqual({ total: expected.total });
153-
expect(expected.total).toBe(expected.comments + expected.drawn);
141+
it('without the field changes, the updates stay in the count', async () => {
142+
const expected = await expectedAs(authorTok);
143+
const res = await stack.apiAs(authorTok, 'POST', `/data/cmt_open/${recordId}/page`, {
144+
timeline: { discussion: true, activity: true, fieldChanges: false },
145+
});
146+
expect(res.status).toBe(200);
147+
expect(RecordPageResponseSchema.parse(((await res.json()) as any).data).timeline).toEqual({ total: expected.comments + expected.drawn });
154148
}, 60_000);
155149

156150
it('counts only the sources named', async () => {

0 commit comments

Comments
 (0)