Skip to content

Commit e15a732

Browse files
fix(organizations): warn when a per-org seed replay refuses rows (#38629)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9St4eUWHFcCKuRUrCZPperJ)_ Fixes #35086 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户可见变化:新建组织时若种子数据被拒收,服务器日志会以警告(而非普通信息)提示,运维能看到组织为何是空的。 - 为什么做:修复"新组织缺少标准价目表却无任何告警"的静默不完整问题。 - 出错会怎样:只改日志级别,可直接撤回,不影响数据。 - 要你做什么:无。 ## What changes `replayOrganizationSeed` in the organizations plugin now logs a per-org seed replay with `N > 0` errors at **warn** instead of info. The warn line keeps the stable `[org-scoping] per-org seed replay for ORG_ID: ...` prefix and appends the first error's object and message; the context carries `organizationId` and the first five errors. A replay with zero errors still logs the unchanged info line. Decision: an error replay logs warn INSTEAD of info (one line per event, no duplicate); every existing pin asserts the info line only on error-free replays, so all stay true. ## Tests - New pin in `organizations-plugin.test.ts`: a replay returning one refused row raises exactly one warn naming the org, `1 error(s)`, the object and the message, and no info line. - `vitest run` on organizations-plugin.test.ts, first-organization-orphan-rows.pin.test.ts, org-creation-no-cross-org-copy.test.ts: 3 files / 34 tests passed; `@objectstack/organizations` typecheck green (lock VERDICT command-exit 0, after building the `^...` closure). ## Acceptance notes - Changeset: `.changeset/35086-seed-replay-warn.md` (patch). - Local gates: only the package tests and typecheck above; the farm of `check:*` gates is left to CI. ## Verification Run the new test: `pnpm --filter @objectstack/organizations exec vitest run src/organizations-plugin.test.ts` and expect it green. 🤖 Generated with [Claude Code](https://claude.ai/code) https://claude.ai/code/session_01ADHkmRar3Kkg6SpwVgaaVE <!-- signed: repo:objectstack#3 · os-steve · session_01ADHkmRar3Kkg6SpwVgaaVE --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 681fec2 commit e15a732

3 files changed

Lines changed: 49 additions & 7 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@objectstack/organizations": patch
3+
---
4+
5+
Clause-②: no
6+
Metadata-protocol: none
7+
8+
A per-organization seed replay that refuses rows now logs at warn, naming the object, the first error and the organization id, instead of an info line.

‎packages/plugins/organizations/src/organizations-plugin.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,33 @@ describe('OrganizationsPlugin', () => {
314314
).toBe(true);
315315
});
316316

317+
it('logs a replay with a refused row at warn, naming the object, the first error and the org', async () => {
318+
const plugin = new OrganizationsPlugin();
319+
const { ctx, middlewares } = makeCtx({ 'seed-datasets': [{ object: 'crm_price_book', records: [{ id: 'p1' }] }] });
320+
ctx.registerService('seed-replayer', vi.fn(async () => ({
321+
inserted: 0,
322+
updated: 0,
323+
skipped: 0,
324+
errors: [{ sourceObject: 'crm_price_book', message: 'refused: standard price book' }],
325+
})));
326+
await plugin.init(ctx);
327+
await plugin.start(ctx);
328+
329+
await middlewares[1](newOrgInsert('org_new'), async () => {});
330+
331+
const warns = (ctx.logger.warn as any).mock.calls.filter((c: any[]) =>
332+
String(c[0]).includes('per-org seed replay for org_new'),
333+
);
334+
expect(warns).toHaveLength(1);
335+
expect(String(warns[0][0])).toContain('1 error(s)');
336+
expect(String(warns[0][0])).toContain('crm_price_book');
337+
expect(String(warns[0][0])).toContain('refused: standard price book');
338+
expect(warns[0][1]).toMatchObject({ organizationId: 'org_new' });
339+
expect(
340+
(ctx.logger.info as any).mock.calls.some((c: any[]) => String(c[0]).includes('per-org seed replay for')),
341+
).toBe(false);
342+
});
343+
317344
it('surfaces a missing replayer — datasets present, no replayer registered — instead of silently skipping', async () => {
318345
const plugin = new OrganizationsPlugin();
319346
const datasets = [{ object: 'crm_account', records: [{ id: 'a1' }] }];

‎packages/plugins/organizations/src/organizations-plugin.ts‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -517,13 +517,20 @@ export class OrganizationsPlugin implements Plugin {
517517
? await replayer(newOrgId, { userId: founderId })
518518
: await replayer(newOrgId);
519519
const total = (summary?.inserted ?? 0) + (summary?.updated ?? 0);
520-
ctx.logger.info(
521-
`[org-scoping] per-org seed replay for ${newOrgId}: +${summary?.inserted ?? 0} inserted, ${summary?.updated ?? 0} updated, ${summary?.errors?.length ?? 0} error(s)`,
522-
{
523-
organizationId: newOrgId,
524-
errors: summary?.errors?.slice?.(0, 5),
525-
},
526-
);
520+
const replayErrors: any[] = Array.isArray(summary?.errors) ? summary.errors : [];
521+
const replaySummary = `[org-scoping] per-org seed replay for ${newOrgId}: +${summary?.inserted ?? 0} inserted, ${summary?.updated ?? 0} updated, ${replayErrors.length} error(s)`;
522+
if (replayErrors.length > 0) {
523+
// A refused seed row leaves the org partly (or wholly) unseeded, so an
524+
// operator must be able to see it: warn, naming the object and the
525+
// first error (the org id is in the prefix and the context).
526+
const first = replayErrors[0];
527+
ctx.logger.warn(
528+
`${replaySummary}; first error on ${first?.sourceObject ?? 'unknown object'}: ${first?.message ?? String(first)}`,
529+
{ organizationId: newOrgId, errors: replayErrors.slice(0, 5) },
530+
);
531+
} else {
532+
ctx.logger.info(replaySummary, { organizationId: newOrgId, errors: [] });
533+
}
527534
if (total > 0) replayed = true;
528535
} else if (datasets) {
529536
ctx.logger.warn(

0 commit comments

Comments
 (0)