Skip to content

Commit 38f170f

Browse files
committed
test(dogfood): pin config_change record_id end to end and move the run-level ledger row to an object-less action
A settings write's config_change row now names the settings row it changed, so the parent-read-gate fixture loses its only row about no record. It now gets one from the action door (an action invoked with no subject record), and pins that the config_change row follows the gate on the settings row it names while the admin is still served it. The settings audit fixture pins record_id against the stored sys_setting row and finds the mirror's row about the same write beside it. Adds the changeset for the three packages. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cyf254wVgypzQ5Uj1a
1 parent 96a1f7a commit 38f170f

3 files changed

Lines changed: 92 additions & 9 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@objectstack/service-settings': patch
3+
'@objectstack/plugin-audit': patch
4+
'@objectstack/plugin-sharing': patch
5+
---
6+
7+
feat(service-settings,plugin-audit,plugin-sharing): a config_change ledger row names the settings row it changed, an audit row's record page lists the other changes to the same record, and a queue's record page lists its members
8+
9+
Clause-②: no
10+
Metadata-protocol: none
11+
12+
- **`@objectstack/service-settings`: the `config_change` row's shape changes (not breaking).** A settings write's `config_change` row in `sys_audit_log` now sets `record_id` to the id of the stored settings row the write changed (`sys_setting`, or `sys_platform_setting` for a global value), beside the `object_name` it already named; before, `record_id` was always null. `metadata` and the digest in `new_value` are unchanged, and an in-memory settings store still writes null. Rows written before this release keep their null `record_id`.
13+
- **Who can read those rows narrows.** Because a `config_change` row now names a record, the ledger's parent-record read gate judges it by that settings row: a reader holding only the ledger's own read grant, who cannot read the settings store, no longer sees new `config_change` rows. Holders of the ledger's audit capability (`view_all_audit_log`, administrators by default) still see every row. Older rows with a null `record_id` are still served under the ledger grant. Nothing becomes visible to a reader who could not see it before.
14+
- **`@objectstack/plugin-audit`: `sys_audit_log` gets a default record page** (`sys_audit_log_detail`) that shows the row's fields and lists every other ledger row with the same `record_id`, newest first. Beside a `config_change` row that list holds the CRUD mirror's create and update rows for the same settings row, which carry a non-secret value in plain text; a secret's mirror row carries neither the value nor its handle. The list has no "New". The page label ships in all eleven locales.
15+
- **`@objectstack/plugin-sharing`: `sys_queue` gets a default record page** (`sys_queue_detail`) whose members list reads `sys_queue_member` where `queue` equals this queue's `name`, and whose "New" opens the member form with `queue` filled in with that name. `sys_queue_member.queue` is unchanged. Declared queues have no `sys_queue` row, so they have no page. The page label ships in the plugin's four locales.

‎packages/qa/dogfood/test/audit-log-parent-read-gate.dogfood.test.ts‎

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
// ledger rows about records it can read, plus the rows that are about no
88
// record. This file drives that on a real org-bound boot — better-auth
99
// sign-ups, the platform permission sets plus one explicit ledger read grant,
10-
// plugin-audit's real CRUD mirror and auth-event sink writing the rows, and
11-
// service-settings writing a run-level `config_change` row — through every
12-
// generic door that reads the object:
10+
// plugin-audit's real CRUD mirror and auth-event sink writing the rows,
11+
// an action invoked with no subject record writing a run-level
12+
// `action_invocation` row, and
13+
// service-settings writing a `config_change` row that names the settings row
14+
// it changed — through every generic door that reads the object:
1315
//
1416
// GET /data/sys_audit_log list (+ its `total`)
1517
// GET /data/sys_audit_log/:id by id
@@ -43,6 +45,27 @@ import { catalogPermissionSet } from './catalog-permission-set.js';
4345
const SYS = { isSystem: true } as const;
4446
const LEDGER = 'sys_audit_log';
4547
const READER_EMAIL = 'ledger-gate-reader@verify.test';
48+
/**
49+
* A run-level row: the action door's `action_invocation` row for an action
50+
* invoked with no subject record names no record (`action-invocation-audit.ts`).
51+
* The settings write that once supplied this file's run-level row now names
52+
* the settings row it changed (#30209), and this boot carries no other
53+
* run-level producer, so the fixture declares one object-scoped action.
54+
*/
55+
const RUN_LEVEL = 'action_invocation';
56+
const RUN_LEVEL_ACTION = 'cmt_ledger_ping';
57+
const gateStack = {
58+
...commentsFixtureStack,
59+
actions: [
60+
{
61+
name: RUN_LEVEL_ACTION,
62+
label: 'Ledger gate fixture: a run with no subject record',
63+
objectName: 'cmt_open',
64+
type: 'script',
65+
body: { language: 'js', source: 'return { ok: true };', capabilities: [] },
66+
},
67+
],
68+
};
4669

4770
/** The grant under test: object-level read on the ledger, nothing more. */
4871
const ledgerReaderSet: PermissionSet = PermissionSetSchema.parse({
@@ -62,12 +85,13 @@ describe('[#21175] sys_audit_log: a ledger reader reads the rows about records i
6285
let privateId: string; // cmt_private, owned by the admin — the reader cannot read it
6386
let openId: string; // cmt_open, created by the reader — the reader reads it
6487
let goneId: string; // cmt_open, created and deleted by the admin
88+
let settingRef: { object: string; id: string }; // the settings row the PUT below wrote
6589

6690
const ledgerAtRest = (where: Record<string, unknown>): Promise<Row[]> =>
6791
ql.find(LEDGER, { where, context: { ...SYS } });
6892

6993
beforeAll(async () => {
70-
stack = await bootStack(commentsFixtureStack as never, {
94+
stack = await bootStack(gateStack as never, {
7195
security: new SecurityPlugin({
7296
defaultPermissionSets: [...securityDefaultPermissionSets, cmtFixtureBaselineSet, ledgerReaderSet],
7397
fallbackPermissionSet: cmtFixtureBaselineSet.name,
@@ -96,14 +120,20 @@ describe('[#21175] sys_audit_log: a ledger reader reads the rows about records i
96120
openId = await idOf(await stack.apiAs(readerTok, 'POST', '/data/cmt_open', { name: 'shared board' }));
97121
goneId = await idOf(await stack.apiAs(adminTok, 'POST', '/data/cmt_open', { name: 'board, gone' }));
98122
expect((await stack.apiAs(adminTok, 'DELETE', `/data/cmt_open/${goneId}`)).status).toBeLessThan(300);
99-
// A run-level row, from its real producer: a settings write is a
100-
// `config_change` row that names no record.
123+
// A settings write, from its real producer: a `config_change` row that
124+
// names the settings row it changed (#30209), so it is a row ABOUT a record.
101125
const put = await stack.raw('/api/settings/branding', {
102126
method: 'PUT',
103127
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${adminTok}` },
104128
body: JSON.stringify({ workspace_name: 'Ledger gate fixture' }),
105129
});
106130
expect(put.status, await put.clone().text()).toBe(200);
131+
const [change] = await ledgerAtRest({ action: 'config_change' });
132+
settingRef = { object: String(change?.object_name), id: String(change?.record_id) };
133+
// A run-level row, from its real producer: the action door ledgers an
134+
// invocation with no subject record as a row naming no record.
135+
const ran = await stack.apiAs(adminTok, 'POST', `/actions/cmt_open/${RUN_LEVEL_ACTION}`, {});
136+
expect(ran.status, await ran.clone().text()).toBe(200);
107137

108138
await assertArmed([
109139
principalArmed({
@@ -131,9 +161,11 @@ describe('[#21175] sys_audit_log: a ledger reader reads the rows about records i
131161
private: (await ledgerAtRest({ object_name: 'cmt_private', record_id: privateId })).length,
132162
open: (await ledgerAtRest({ object_name: 'cmt_open', record_id: openId })).length,
133163
gone: (await ledgerAtRest({ object_name: 'cmt_open', record_id: goneId })).length,
134-
aboutNoRecord: (await ledgerAtRest({ action: 'config_change' })).filter((r) => r.record_id == null).length,
164+
aboutNoRecord: (await ledgerAtRest({ action: RUN_LEVEL })).filter((r) => r.record_id == null).length,
165+
configChange: (await ledgerAtRest({ action: 'config_change', object_name: settingRef.object, record_id: settingRef.id })).length,
166+
settingRow: (await ql.find(settingRef.object, { where: { id: settingRef.id }, context: { ...SYS } })).length,
135167
}),
136-
armed: (o) => o.private === 2 && o.open >= 1 && o.gone === 2 && o.aboutNoRecord >= 1,
168+
armed: (o) => o.private === 2 && o.open >= 1 && o.gone === 2 && o.aboutNoRecord >= 1 && o.configChange >= 1 && o.settingRow === 1,
137169
}),
138170
]);
139171
}, 180_000);
@@ -196,10 +228,21 @@ describe('[#21175] sys_audit_log: a ledger reader reads the rows about records i
196228
});
197229

198230
it('a row about no record is still served to the ledger reader', async () => {
199-
const [runLevel] = (await ledgerAtRest({ action: 'config_change' })).filter((r) => r.record_id == null);
231+
const [runLevel] = (await ledgerAtRest({ action: RUN_LEVEL })).filter((r) => r.record_id == null);
200232
expect((await stack.apiAs(readerTok, 'GET', `/data/${LEDGER}/${runLevel.id}`)).status).toBe(200);
201233
});
202234

235+
it('a config_change row follows the gate on the settings row it names; the admin is served it', async () => {
236+
const [change] = await ledgerAtRest({ action: 'config_change', object_name: settingRef.object, record_id: settingRef.id });
237+
const parent = (await stack.apiAs(readerTok, 'GET', `/data/${settingRef.object}/${settingRef.id}`)).status;
238+
const row = (await stack.apiAs(readerTok, 'GET', `/data/${LEDGER}/${change.id}`)).status;
239+
expect(row).toBe(parent === 200 ? 200 : 404);
240+
// The reader holds no read on the settings store, so the ledger-only read
241+
// no longer reaches the row; the admin's audit capability does.
242+
expect(parent).not.toBe(200);
243+
expect((await stack.apiAs(adminTok, 'GET', `/data/${LEDGER}/${change.id}`)).status).toBe(200);
244+
});
245+
203246
it('a row about a record that no longer exists is not served to the reader; the admin, a default holder of the ledger audit capability, is served it', async () => {
204247
const served = async (tok: string) =>
205248
(await rowsOf(await stack.apiAs(tok, 'GET', `/data/${LEDGER}?limit=1000`))).filter((r) => r.record_id === goneId);

‎packages/qa/dogfood/test/settings-config-change-audit.dogfood.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,31 @@ describe('#8145: a settings write reaches sys_audit_log as config_change', () =>
143143
// bare timeout, which names neither the object nor the filter.
144144
}, 30_000);
145145

146+
it('[#30209] the config_change row names the settings row it changed, and the mirror\'s row about that row carries the value', async () => {
147+
const [change] = await waitForRows(
148+
async () =>
149+
(await findRows(ql, 'sys_audit_log', { action: 'config_change' })).filter((r) =>
150+
String(r.metadata ?? '').includes('"key":"workspace_name"'),
151+
),
152+
(r) => r.length >= 1,
153+
'expected the config_change row for workspace_name',
154+
);
155+
const settingRows = await findRows(ql, String(change.object_name), { namespace: 'branding', key: 'workspace_name' });
156+
expect(settingRows).toHaveLength(1);
157+
// The pointer pair: object_name names the store, record_id the row in it.
158+
expect(change.record_id).toBe(String(settingRows[0].id));
159+
// The record page's same-record list keys on record_id: beside the
160+
// config_change row it finds the CRUD mirror's row about the same write,
161+
// which holds the non-secret value the digest row does not.
162+
const mirror = (await findRows(ql, 'sys_audit_log', { record_id: change.record_id })).filter((r) =>
163+
['create', 'update'].includes(String(r.action)),
164+
);
165+
expect(mirror.length).toBeGreaterThanOrEqual(1);
166+
expect(mirror.every((r) => r.object_name === change.object_name)).toBe(true);
167+
expect(mirror.some((r) => String(r.new_value ?? '').includes(WORKSPACE_NAME))).toBe(true);
168+
expect(String(change.new_value)).not.toContain(WORKSPACE_NAME);
169+
}, 30_000);
170+
146171
it('the shipped `config_changes` list view — its OWN declared filter — now matches', async () => {
147172
// The view's filter is read off the registered object rather than retyped,
148173
// so this cannot pass against a filter that agrees only with this test. It

0 commit comments

Comments
 (0)