Skip to content

Commit df13535

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/project-thread-ru7gx5
2 parents 077b387 + 6f095b9 commit df13535

22 files changed

Lines changed: 1450 additions & 43 deletions
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@objectstack/objectql': patch
3+
---
4+
5+
fix(objectql): the lifecycle sweep no longer runs 60 s after a boot that created its datastore from empty; its first sweep runs one interval later
6+
7+
Clause-②: yes (widening) — the exported `LifecycleEngineLike` gains the optional member `wasDatastoreCreatedFromEmpty?(): boolean` (an engine without it keeps the old schedule); no accept set changes.
8+
Metadata-protocol: none
9+
10+
- `LifecycleService.start()` asks the engine, at the initial delay, whether this process created the datastore from empty (`ObjectQL.wasDatastoreCreatedFromEmpty()`, answered from every driver's schema-sync stats without a statement). When it did, the scheduled first sweep is skipped and the sweep runs on the interval, one interval later. Such a store holds no row older than the boot, and no declared window is shorter than an hour, so the skipped sweep had nothing to reap. It still read every declared object, the `lifecycle` settings and every lookup the reference audit walks: 130 statements in the first minute of a hosted tenant kernel's first boot.
11+
- A store that existed before the boot, or an engine that cannot say, sweeps at the initial delay as before. A direct `sweep()` call always sweeps. `OS_LIFECYCLE_DISABLED`, `initialDelayMs` and `sweepIntervalMs` keep their meaning.
12+
- `LifecycleEngineLike` gains the optional member `wasDatastoreCreatedFromEmpty?(): boolean`. An engine double that omits it keeps the old schedule.
13+
- A re-boot on an existing store still sweeps at the initial delay. Persisting a last-swept watermark for that case is separate work.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/data-objectstack': patch
4+
'@object-ui/i18n': patch
5+
---
6+
7+
feat(studio): customize a read-only package's dataset in the All metadata area, see what uses it before publishing, and read a refused publish at the dataset
8+
9+
Clause-②: yes (widening)
10+
Metadata-protocol: none
11+
12+
- **Customize a dataset.** On a read-only base package, Studio's All metadata area opens a dataset in its form editor with the dataset designer and live preview, and offers Customize. The first saved edit copies the whole dataset into the base's paired `<base>.custom` package, declaring `overrides: { package, basedOn }`; the header's Publish applies it, and "Restore package original" on the override mark deletes the copy. On a writable package a dataset still opens the generic item page.
13+
- **What uses it.** While a dataset is customized, the editor lists the dashboards, reports and other items that name it, read from the References read, so the person sees what a published change reaches. A failed read says it failed and offers to read again; it never reads as "nothing uses it".
14+
- **A refused publish at the item.** A publish the server refuses for a dataset is placed on its measure or dimension and the designer's input (`Not published. Check Aggregate of the measure "Total Amount"`), in the Console's language, and shown at the dataset's editor as well as on its Pending changes entry. The server's own text stays under Details.
15+
- **References read fixed.** `MetadataClient.references()` now reads the route's declared answer (`{ references: [{ type, name, label, path, kind }] }`) and maps each element to `MetadataReference` (`fromType`, `fromName`, new optional `fromLabel` and `kind`). It used to read a key the route never serves, so Setup's References tab and Studio's item tools showed "Nothing in the metadata graph points at this item. Safe to delete." for every item. An answer the declaration refuses is now a failed read.
16+
- **Published surface.** `MetadataReference`, exported from `@object-ui/data-objectstack`, gains two optional fields, `fromLabel` (the referring item's label, when the server serves one) and `kind` (the served reference kind); existing fields are unchanged. `MetadataClient.references()` now accepts less: a `200` answer that `FindReferencesToMetaResponseSchema` refuses throws instead of resolving `[]`, so a caller must handle the rejection as it already does for a non-2xx answer; in this repository every caller reads it through `useReferencesScan`, which catches it and shows the failed-check state.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/plugin-security': patch
3+
---
4+
5+
fix(plugin-security): every member reads and posts comments, and reads the activity history, of the records they can read — the platform baseline `member_default` now grants `sys_comment` (read, create, edit) and `sys_activity` (read)
6+
7+
Clause-②: no — runtime permission behaviour (human-floor security/permission class, ruled by the maintainer), not a published accept-set or public-surface widening
8+
Metadata-protocol: none
9+
10+
Comments (`enable.feeds`) and the activity timeline (`enable.activities`) are on by default on every object, but no shipped permission set named `sys_comment` or `sys_activity`. A member of an app whose permission sets name only the app's own objects — what `create-objectstack` generates — was refused both (`403` on `GET /api/v1/data/sys_comment` and `GET /api/v1/data/sys_activity`), on records they can read: the record page showed "no permission" for comments and activity, and offered no comment box. An app author no longer needs to grant the two objects by hand.
11+
12+
- **Which rows is unchanged.** The grant opens the two objects; plugin-audit's parent-record gates still decide the rows, so a member reads and posts comments, and reads the history, of exactly the records they can read, and nothing of any other record — a record another user owns under the app's row scope, or a record of an object the member does not read. A member edits the comments they wrote. The grant carries no delete bit (deleting a comment stays the moderation path, through a delete bit an app grants), no export and no view-all or modify-all.
13+
- **`enable.feeds: false` still closes comments** on that object: creating a comment there, or moving one into it, answers `403 FEEDS_DISABLED`. `enable.activities: false` still writes no activity row for the object.
14+
- **External members are not reached.** A holder of the `external` organization role does not hold the `everyone` anchor and resolves `external_default` in place of `member_default`, so a portal user still gets comments and activity only through an explicit grant, under the same two gates.
15+
- **No log noise.** A member's activity read skips the parent objects they cannot read without reading them, so the console header's feed logs no `[Security] Access denied` line per skipped object.
16+
- An app that already grants the two objects to its members keeps working unchanged: permission sets merge most-permissively, so its own lines (a delete bit included) still apply beside the baseline's.

‎packages/objectql/src/lifecycle/lifecycle-service.test.ts‎

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,6 +2541,101 @@ describe('LifecycleService timers', () => {
25412541
vi.useRealTimers();
25422542
}
25432543
});
2544+
2545+
/**
2546+
* [#29918] A datastore this process created from empty holds no row older
2547+
* than the boot, so the first scheduled sweep is due one interval later.
2548+
* Every data-plane door the sweep can reach is counted: the reaps, the
2549+
* governance settings reads and the reference audit.
2550+
*/
2551+
function freshnessEngine(answer: () => boolean) {
2552+
const captured = captureEngine([
2553+
{ name: 'sys_job_run', lifecycle: { class: 'telemetry', retention: { maxAge: '30d' } } },
2554+
]);
2555+
const audits: unknown[] = [];
2556+
const settingsReads: string[] = [];
2557+
captured.engine.wasDatastoreCreatedFromEmpty = answer;
2558+
captured.engine.inspectDanglingReferences = async (options: unknown) => {
2559+
audits.push(options);
2560+
return { findings: [], scannedObjects: [], unreadableObjects: [] };
2561+
};
2562+
const getSettings = () => ({
2563+
async get(namespace: string, key: string) {
2564+
settingsReads.push(`${namespace}.${key}`);
2565+
return { value: undefined };
2566+
},
2567+
});
2568+
return { ...captured, audits, settingsReads, getSettings };
2569+
}
2570+
2571+
it('[#29918] issues no sweep at the initial delay on a store this boot created, and sweeps one interval later', async () => {
2572+
vi.useFakeTimers();
2573+
try {
2574+
const { engine, deletes, audits, settingsReads, getSettings } = freshnessEngine(() => true);
2575+
const svc = service(engine, { initialDelayMs: 1_000, sweepIntervalMs: 5_000, getSettings });
2576+
2577+
svc.start();
2578+
await vi.advanceTimersByTimeAsync(1_000);
2579+
expect(deletes).toHaveLength(0);
2580+
expect(audits).toHaveLength(0);
2581+
expect(settingsReads).toEqual([]);
2582+
2583+
await vi.advanceTimersByTimeAsync(5_000);
2584+
expect(deletes).toHaveLength(1);
2585+
expect(audits).toHaveLength(1);
2586+
expect(settingsReads.length).toBeGreaterThan(0);
2587+
svc.stop();
2588+
} finally {
2589+
vi.useRealTimers();
2590+
}
2591+
});
2592+
2593+
it('[#29918] sweeps at the initial delay when the store was there before this boot, or the engine cannot say', async () => {
2594+
vi.useFakeTimers();
2595+
try {
2596+
const answers: Array<() => boolean> = [
2597+
() => false,
2598+
() => {
2599+
throw new Error('no driver reports schema-sync stats');
2600+
},
2601+
];
2602+
for (const answer of answers) {
2603+
const { engine, deletes, audits } = freshnessEngine(answer);
2604+
const svc = service(engine, { initialDelayMs: 1_000, sweepIntervalMs: 5_000 });
2605+
svc.start();
2606+
await vi.advanceTimersByTimeAsync(1_000);
2607+
expect(deletes).toHaveLength(1);
2608+
expect(audits).toHaveLength(1);
2609+
svc.stop();
2610+
}
2611+
} finally {
2612+
vi.useRealTimers();
2613+
}
2614+
});
2615+
2616+
it('[#29918] a direct sweep() on a store this boot created still sweeps', async () => {
2617+
const { engine, deletes, audits } = freshnessEngine(() => true);
2618+
await service(engine).sweep();
2619+
expect(deletes).toHaveLength(1);
2620+
expect(audits).toHaveLength(1);
2621+
});
2622+
2623+
it('[#29918] OS_LIFECYCLE_DISABLED still arms nothing on a store this boot created', async () => {
2624+
vi.useFakeTimers();
2625+
process.env.OS_LIFECYCLE_DISABLED = '1';
2626+
try {
2627+
const { engine, deletes, audits } = freshnessEngine(() => true);
2628+
const svc = service(engine, { initialDelayMs: 1_000, sweepIntervalMs: 5_000 });
2629+
svc.start();
2630+
await vi.advanceTimersByTimeAsync(20_000);
2631+
expect(deletes).toHaveLength(0);
2632+
expect(audits).toHaveLength(0);
2633+
svc.stop();
2634+
} finally {
2635+
delete process.env.OS_LIFECYCLE_DISABLED;
2636+
vi.useRealTimers();
2637+
}
2638+
});
25442639
});
25452640

25462641
/**

‎packages/objectql/src/lifecycle/lifecycle-service.ts‎

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ export interface LifecycleEngineLike {
118118
inspectDanglingReferences?(
119119
options?: DanglingReferenceAuditOptions,
120120
): Promise<DanglingReferenceReport>;
121+
/**
122+
* [#29918] Did this process create the datastore it talks to, from empty?
123+
* `ObjectQL.wasDatastoreCreatedFromEmpty()` answers it from every driver's
124+
* schema-sync stats, in process and without a statement. The scheduler asks
125+
* it once, at the initial delay, to decide whether the first sweep is due
126+
* yet. Optional: an engine without it is never treated as fresh, so its
127+
* first sweep runs at the initial delay exactly as before.
128+
*/
129+
wasDatastoreCreatedFromEmpty?(): boolean;
121130
}
122131

123132
export interface LifecycleObjectLike {
@@ -503,7 +512,11 @@ export class LifecycleService {
503512
}
504513

505514
/** Arm the periodic sweep. Idempotent; timers are unref'ed so a kernel
506-
* shutdown is never held open by the lifecycle schedule. */
515+
* shutdown is never held open by the lifecycle schedule.
516+
*
517+
* [#29918] On a datastore this process created from empty, the first sweep
518+
* is due one interval later instead of at the initial delay: see
519+
* {@link firstSweepDueAtInitialDelay}. The interval is armed either way. */
507520
start(): void {
508521
if (!this.enabled || this.timer || this.initialTimer) return;
509522
// A fresh bit per armed run — the one a previous sweep captured stays
@@ -513,13 +526,51 @@ export class LifecycleService {
513526
const initial = this.opts.initialDelayMs ?? DEFAULT_LIFECYCLE_INITIAL_DELAY_MS;
514527
this.initialTimer = setTimeout(() => {
515528
this.initialTimer = undefined;
516-
void this.sweep();
529+
if (this.firstSweepDueAtInitialDelay()) void this.sweep();
517530
this.timer = setInterval(() => void this.sweep(), interval);
518531
this.timer.unref?.();
519532
}, initial);
520533
this.initialTimer.unref?.();
521534
}
522535

536+
/**
537+
* [#29918] Whether the scheduled first sweep runs at the initial delay.
538+
*
539+
* Not when this process created the datastore from empty
540+
* ({@link LifecycleEngineLike.wasDatastoreCreatedFromEmpty}). Every row in
541+
* such a store was written by this process, so none is older than the
542+
* initial delay, and no declared window is that short: the duration grammar's
543+
* smallest unit is an hour ({@link parseLifecycleDuration}). The sweep would
544+
* read every declared object, the governance settings and every lookup the
545+
* reference audit walks, and find nothing to do. On a hosted tenant kernel
546+
* that was 130 statements in the first minute of every first boot. The first
547+
* sweep then runs on the interval, so deferring it costs at most one interval
548+
* of overstay, which the hourly cadence already allows any row.
549+
*
550+
* Asked here, at the initial delay, and nowhere else. Schema sync has run by
551+
* now, so the answer is final. Only the SCHEDULER asks it: a direct
552+
* {@link sweep} call (the dogfood growth gate, `db:clean`-style tooling, a
553+
* test) always sweeps. The reference audit is a leg of that same sweep, so
554+
* it is deferred with it.
555+
*
556+
* An engine that cannot answer, or whose answer throws, is not fresh. That
557+
* keeps the sweep at the initial delay, as before this method existed.
558+
*/
559+
private firstSweepDueAtInitialDelay(): boolean {
560+
let fresh = false;
561+
try {
562+
fresh = this.opts.getEngine()?.wasDatastoreCreatedFromEmpty?.() === true;
563+
} catch {
564+
fresh = false;
565+
}
566+
if (fresh) {
567+
this.opts.logger.debug?.(
568+
'[lifecycle] this process created the datastore from empty; the first sweep runs one interval later',
569+
);
570+
}
571+
return !fresh;
572+
}
573+
523574
/**
524575
* Disarm the schedule AND call off the work.
525576
*

‎packages/plugins/plugin-security/src/comment-reaction-own-record-floor.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333
* ## Who grants the bits
3434
*
3535
* The object-level create / read / delete bits come from an ordinary
36-
* position-distributed set an application ships (as an app grants
37-
* `sys_comment` today), never from the `everyone`-bound baseline, which
36+
* position-distributed set an application ships (as an app grants the
37+
* `sys_comment` delete bit; the baseline grants comments' read, create and
38+
* edit, never delete), never from the `everyone`-bound baseline, which
3839
* ADR-0090 D5 keeps free of delete bits. Which shipped set — if any — carries
3940
* them is an open decision on #22566; the floor pinned here holds whatever set
4041
* hands the delete bit out.

‎packages/plugins/plugin-security/src/member-default-explicit-allow.test.ts‎

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { PermissionSetSchema } from '@objectstack/spec/security';
2828
import type { PermissionSet } from '@objectstack/spec/security';
2929
import { PermissionEvaluator } from './permission-evaluator.js';
3030
import { RLSCompiler, RLS_DENY_FILTER } from './rls-compiler.js';
31-
import { defaultPermissionSets, BETTER_AUTH_MANAGED_OBJECTS } from './objects/default-permission-sets.js';
31+
import { defaultPermissionSets, BETTER_AUTH_MANAGED_OBJECTS, EXTERNAL_DEFAULT_PERMISSION_SET } from './objects/default-permission-sets.js';
3232

3333
const evaluator = new PermissionEvaluator();
3434
const MEMBER_DEFAULT = defaultPermissionSets.find((p) => p.name === 'member_default')!;
@@ -267,13 +267,10 @@ describe('[#7344] the personal inbox is readable by a member, scoped to their ow
267267
expect(rls.compileFilter(policiesFor(object, 'select') as any, {} as any)).toEqual(RLS_DENY_FILTER);
268268
});
269269

270-
it('`sys_activity` is deliberately NOT granted — the ruling excludes it', () => {
271-
// Named as an explicit negative so a future "while we are here" sweep has to
272-
// argue with the ruling rather than quietly widen past it. It is not a
273-
// per-user-scoped shape; a separate question if it ever matters.
274-
for (const { operation } of AXES) {
275-
expect(allows(operation, [MEMBER_DEFAULT], 'sys_activity'), `sys_activity ${operation}`).toBe(false);
276-
}
270+
it('`sys_activity` rides on its own ruling, not on this one: no `_self` policy scopes it to the caller', () => {
271+
// The inbox ruling left it out because it has no `user_id` to scope by. Its
272+
// grant (the `[#30108]` block below) is scoped by its parent-record gate, so
273+
// no inbox-shaped `_self` carve-out may appear for it.
277274
const names = (MEMBER_DEFAULT.rowLevelSecurity ?? []).map((p: any) => p.name);
278275
expect(names).not.toContain('sys_activity_self');
279276
});
@@ -291,6 +288,60 @@ describe('[#7344] the personal inbox is readable by a member, scoped to their ow
291288
});
292289
});
293290

291+
// [#30108 — maintainer ruling 6633054352, 「同意 A」] A record's comments and its
292+
// activity timeline, for every member who can read the record. The baseline
293+
// opens the two OBJECTS and nothing more; which rows is plugin-audit's
294+
// parent-record gates' answer, driven on a real stack in
295+
// `member-default-feed-grants.integration.test.ts`. What is pinned here is the
296+
// shape of the opening: the part that would quietly widen if it moved.
297+
const FEED_OBJECTS = ['sys_comment', 'sys_activity'] as const;
298+
299+
describe('[#30108] the baseline opens comments and activity, and leaves the rows to the parent gates', () => {
300+
it('sys_comment: a member reads, posts and edits — and holds no delete bit', () => {
301+
expect(allows('find', [MEMBER_DEFAULT], 'sys_comment'), 'read').toBe(true);
302+
expect(allows('insert', [MEMBER_DEFAULT], 'sys_comment'), 'create').toBe(true);
303+
expect(allows('update', [MEMBER_DEFAULT], 'sys_comment'), 'edit').toBe(true);
304+
expect(allows('delete', [MEMBER_DEFAULT], 'sys_comment'), 'delete').toBe(false);
305+
});
306+
307+
it('sys_activity: a member reads — the audit mirror is its only writer', () => {
308+
expect(allows('find', [MEMBER_DEFAULT], 'sys_activity'), 'read').toBe(true);
309+
for (const operation of ['insert', 'update', 'delete']) {
310+
expect(allows(operation, [MEMBER_DEFAULT], 'sys_activity'), operation).toBe(false);
311+
}
312+
});
313+
314+
it.each(FEED_OBJECTS)('%s: no read or create row policy of the baseline stands in for the parent gate', (object) => {
315+
// A select- or insert-class policy here would answer the gate's question with
316+
// a column predicate neither object can answer (no owner or user column, and
317+
// a different parent object on every row).
318+
expect(policiesFor(object, 'select').map((p: any) => p.name), 'select').toEqual([]);
319+
expect(policiesFor(object, 'insert').map((p: any) => p.name), 'insert').toEqual([]);
320+
});
321+
322+
it('sys_comment: an edit stays under the ownership floor — a member edits the comments they wrote', () => {
323+
// The moderation carve-out is the DELETE limb only; the edit limb is the
324+
// wildcard floor, so a member's edit reaches their own comments alone.
325+
expect(policiesFor('sys_comment', 'update').map((p: any) => p.name)).toEqual(['owner_only_writes']);
326+
});
327+
328+
it.each(FEED_OBJECTS)('%s: no export, view-all or modify-all rides along', (object) => {
329+
const perm = (MEMBER_DEFAULT.objects as any)[object];
330+
expect(perm, `${object} is named`).toBeTruthy();
331+
expect(perm.allowDelete ?? false).toBe(false);
332+
expect(perm.allowExport ?? false).toBe(false);
333+
expect(perm.viewAllRecords ?? false).toBe(false);
334+
expect(perm.modifyAllRecords ?? false).toBe(false);
335+
});
336+
337+
it.each(FEED_OBJECTS)('%s: the external baseline does not name it — the grant reaches no external member', (object) => {
338+
const external = defaultPermissionSets.find((p) => p.name === EXTERNAL_DEFAULT_PERMISSION_SET)!;
339+
expect(external, `${EXTERNAL_DEFAULT_PERMISSION_SET} is shipped`).toBeTruthy();
340+
expect(allows('find', [external], object)).toBe(false);
341+
expect(Object.keys(external.objects ?? {})).not.toContain(object);
342+
});
343+
});
344+
294345
describe('[#5491] the admin sets keep their wildcards (this is a BASELINE change only)', () => {
295346
it.each(['admin_full_access', 'organization_admin', 'viewer_readonly'])(
296347
'%s still carries a `*` entry',

0 commit comments

Comments
 (0)