@mettlecast/domain-cli 0.2.84 → 0.2.86
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -120,9 +120,8 @@ export async function runBuildCatalog(registryDir) {
|
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
-
const
|
|
124
|
-
await mkdir(
|
|
125
|
-
const outPath = join(mcDir, 'domain-registry.json');
|
|
123
|
+
const outPath = join(dir, 'domain-registry.json');
|
|
124
|
+
await mkdir(dir, { recursive: true });
|
|
126
125
|
await writeFile(outPath, JSON.stringify(catalog), 'utf8');
|
|
127
126
|
cliLogger.info({ outPath, domains: catalog.domains.length, actions: catalog.actions.length, events: catalog.events.length, jobs: catalog.jobs.length, schedules: catalog.schedules.length, integrations: catalog.integrations.length }, 'Domain catalog written');
|
|
128
127
|
return catalog;
|
package/package.json
CHANGED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { writeFile, readFile, mkdir } from 'node:fs/promises';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
5
|
+
import { join, resolve } from 'node:path';
|
|
6
|
+
import { tmpdir } from 'node:os';
|
|
7
|
+
import { rmSync } from 'node:fs';
|
|
8
|
+
import { runBuildCatalog } from '../../commands/build-catalog.js';
|
|
9
|
+
|
|
10
|
+
describe('build-catalog', () => {
|
|
11
|
+
let tempDir: string;
|
|
12
|
+
|
|
13
|
+
beforeEach(async () => {
|
|
14
|
+
tempDir = join(tmpdir(), `tib-build-catalog-${Math.random().toString(36).slice(2)}`);
|
|
15
|
+
await mkdir(tempDir, { recursive: true });
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Regression test for #5087.
|
|
24
|
+
* When registryDir is explicitly given, the catalog output must be written
|
|
25
|
+
* to that directory (resolved) — NOT to process.cwd()/.mc.
|
|
26
|
+
* This ensures --mc-dir controls both read and write locations.
|
|
27
|
+
*/
|
|
28
|
+
it('writes catalog to the resolved registryDir, not to cwd/.mc (#5087)', async () => {
|
|
29
|
+
// Arrange: seed a temp .mc directory with one per-domain registry file.
|
|
30
|
+
const mcDir = join(tempDir, '.mc');
|
|
31
|
+
await mkdir(mcDir, { recursive: true });
|
|
32
|
+
|
|
33
|
+
await writeFile(
|
|
34
|
+
join(mcDir, 'test-domain-registry.json'),
|
|
35
|
+
JSON.stringify({
|
|
36
|
+
domain: { id: 'test-domain', name: 'Test Domain', tenancy: 'required' },
|
|
37
|
+
actions: [],
|
|
38
|
+
events: [],
|
|
39
|
+
subscribers: [],
|
|
40
|
+
jobs: [],
|
|
41
|
+
schedules: [],
|
|
42
|
+
integrations: [],
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
// Capture hash of the project's existing domain-registry.json (if any)
|
|
47
|
+
// so we can assert the test did NOT overwrite it.
|
|
48
|
+
const projectCatalogPath = join(process.cwd(), '.mc', 'domain-registry.json');
|
|
49
|
+
const beforeHash = existsSync(projectCatalogPath)
|
|
50
|
+
? createHash('sha256').update(readFileSync(projectCatalogPath)).digest('hex')
|
|
51
|
+
: null;
|
|
52
|
+
|
|
53
|
+
// Act: pass explicit registryDir (the temp .mc dir)
|
|
54
|
+
const catalog = await runBuildCatalog(mcDir);
|
|
55
|
+
|
|
56
|
+
// Assert — output landed inside the resolved registryDir
|
|
57
|
+
const outPath = join(mcDir, 'domain-registry.json');
|
|
58
|
+
expect(existsSync(outPath)).toBe(true);
|
|
59
|
+
|
|
60
|
+
const onDisk = JSON.parse(await readFile(outPath, 'utf8'));
|
|
61
|
+
expect(onDisk.version).toBe(2);
|
|
62
|
+
expect(onDisk.generatedAt).toBeDefined();
|
|
63
|
+
expect(onDisk.domains).toHaveLength(1);
|
|
64
|
+
expect(onDisk.domains[0]?.id).toBe('test-domain');
|
|
65
|
+
|
|
66
|
+
// Returned catalog matches what was written
|
|
67
|
+
expect(catalog.domains[0]?.id).toBe('test-domain');
|
|
68
|
+
|
|
69
|
+
// Assert — project .mc/domain-registry.json must NOT have been touched
|
|
70
|
+
const afterHash = existsSync(projectCatalogPath)
|
|
71
|
+
? createHash('sha256').update(readFileSync(projectCatalogPath)).digest('hex')
|
|
72
|
+
: null;
|
|
73
|
+
expect(afterHash).toBe(beforeHash);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('preserves default behavior when registryDir is omitted', async () => {
|
|
77
|
+
// Seed cwd/.mc with a temp registry file. We can't actually create
|
|
78
|
+
// files in cwd, but we CAN verify the default directory resolution
|
|
79
|
+
// produces the expected path relative to cwd.
|
|
80
|
+
// Instead, create a temp dir and pass no argument, then verify
|
|
81
|
+
// the function resolves dir to process.cwd() + '/.mc'.
|
|
82
|
+
// Since the project's .mc may have real registries, just verify
|
|
83
|
+
// no error is thrown and a valid catalog is returned.
|
|
84
|
+
const catalog = await runBuildCatalog();
|
|
85
|
+
expect(catalog.version).toBe(2);
|
|
86
|
+
expect(Array.isArray(catalog.domains)).toBe(true);
|
|
87
|
+
expect(Array.isArray(catalog.actions)).toBe(true);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -863,4 +863,117 @@ describe('runDoctor', () => {
|
|
|
863
863
|
expect(check?.message).toMatch(/some-command\.ts/);
|
|
864
864
|
});
|
|
865
865
|
});
|
|
866
|
+
|
|
867
|
+
describe('email doctor requirements', () => {
|
|
868
|
+
it('PASS for @no-consumers annotation when email events have the annotation', async () => {
|
|
869
|
+
await mkdir(join(tempDir, '.mc'), { recursive: true });
|
|
870
|
+
await mkdir(join(tempDir, 'domains', 'email', 'publishes'), { recursive: true });
|
|
871
|
+
await writeFile(
|
|
872
|
+
join(tempDir, '.mc', 'scaffold-config.json'),
|
|
873
|
+
JSON.stringify({ domainIds: ['email'] })
|
|
874
|
+
);
|
|
875
|
+
// Email publishes with @no-consumers annotation
|
|
876
|
+
await writeFile(
|
|
877
|
+
join(tempDir, 'domains', 'email', 'publishes', 'events.ts'),
|
|
878
|
+
[
|
|
879
|
+
'import { defineEvent } from \'@mettlecast/domain-runtime\';',
|
|
880
|
+
'import { z } from \'zod\';',
|
|
881
|
+
'',
|
|
882
|
+
'// @no-consumers: email events are public integration hooks for downstream projects.',
|
|
883
|
+
'',
|
|
884
|
+
'export const emailSent = defineEvent({',
|
|
885
|
+
' id: \'email.sent\',',
|
|
886
|
+
' versions: [{ version: 1,',
|
|
887
|
+
' schema: z.object({ templateKey: z.string() }),',
|
|
888
|
+
' }],',
|
|
889
|
+
'});',
|
|
890
|
+
].join('\n')
|
|
891
|
+
);
|
|
892
|
+
|
|
893
|
+
const report = await runDoctor({ projectRoot: tempDir });
|
|
894
|
+
const check = report.checks.find(c => c.name === 'Every event has consumer or annotation');
|
|
895
|
+
expect(check?.status).toBe('PASS');
|
|
896
|
+
});
|
|
897
|
+
|
|
898
|
+
it('FAIL for @no-consumers annotation when email events lack the annotation', async () => {
|
|
899
|
+
await mkdir(join(tempDir, '.mc'), { recursive: true });
|
|
900
|
+
await mkdir(join(tempDir, 'domains', 'email', 'publishes'), { recursive: true });
|
|
901
|
+
await writeFile(
|
|
902
|
+
join(tempDir, '.mc', 'scaffold-config.json'),
|
|
903
|
+
JSON.stringify({ domainIds: ['email'] })
|
|
904
|
+
);
|
|
905
|
+
// Email publishes WITHOUT @no-consumers annotation
|
|
906
|
+
await writeFile(
|
|
907
|
+
join(tempDir, 'domains', 'email', 'publishes', 'events.ts'),
|
|
908
|
+
[
|
|
909
|
+
'import { defineEvent } from \'@mettlecast/domain-runtime\';',
|
|
910
|
+
'import { z } from \'zod\';',
|
|
911
|
+
'',
|
|
912
|
+
'export const emailSent = defineEvent({',
|
|
913
|
+
' id: \'email.sent\',',
|
|
914
|
+
' versions: [{ version: 1,',
|
|
915
|
+
' schema: z.object({ templateKey: z.string() }),',
|
|
916
|
+
' }],',
|
|
917
|
+
'});',
|
|
918
|
+
].join('\n')
|
|
919
|
+
);
|
|
920
|
+
|
|
921
|
+
const report = await runDoctor({ projectRoot: tempDir });
|
|
922
|
+
const check = report.checks.find(c => c.name === 'Every event has consumer or annotation');
|
|
923
|
+
expect(check?.status).toBe('FAIL');
|
|
924
|
+
expect(check?.message).toContain('email');
|
|
925
|
+
});
|
|
926
|
+
|
|
927
|
+
it('PASS for tenancy trio when email migration includes workspace_id', async () => {
|
|
928
|
+
await mkdir(join(tempDir, '.mc'), { recursive: true });
|
|
929
|
+
await mkdir(join(tempDir, 'domains', 'email'), { recursive: true });
|
|
930
|
+
await mkdir(join(tempDir, 'db', 'migrations'), { recursive: true });
|
|
931
|
+
await writeFile(
|
|
932
|
+
join(tempDir, '.mc', 'scaffold-config.json'),
|
|
933
|
+
JSON.stringify({ domainIds: ['email'] })
|
|
934
|
+
);
|
|
935
|
+
// Migration with workspace_id (tenancy trio satisfied)
|
|
936
|
+
await writeFile(
|
|
937
|
+
join(tempDir, 'db', 'migrations', '008_email_templates.sql'),
|
|
938
|
+
[
|
|
939
|
+
'CREATE TABLE IF NOT EXISTS email_templates (',
|
|
940
|
+
' id UUID PRIMARY KEY,',
|
|
941
|
+
' tenant_id UUID,',
|
|
942
|
+
' workspace_id UUID,',
|
|
943
|
+
' org_id UUID',
|
|
944
|
+
');',
|
|
945
|
+
].join('\n')
|
|
946
|
+
);
|
|
947
|
+
|
|
948
|
+
const report = await runDoctor({ projectRoot: tempDir });
|
|
949
|
+
const check = report.checks.find(c => c.name === 'Migrations declare tenancy trio');
|
|
950
|
+
expect(check?.status).toBe('PASS');
|
|
951
|
+
});
|
|
952
|
+
|
|
953
|
+
it('FAIL for tenancy trio when email migration lacks workspace_id', async () => {
|
|
954
|
+
await mkdir(join(tempDir, '.mc'), { recursive: true });
|
|
955
|
+
await mkdir(join(tempDir, 'domains', 'email'), { recursive: true });
|
|
956
|
+
await mkdir(join(tempDir, 'db', 'migrations'), { recursive: true });
|
|
957
|
+
await writeFile(
|
|
958
|
+
join(tempDir, '.mc', 'scaffold-config.json'),
|
|
959
|
+
JSON.stringify({ domainIds: ['email'] })
|
|
960
|
+
);
|
|
961
|
+
// Migration WITHOUT workspace_id (tenancy trio not satisfied)
|
|
962
|
+
await writeFile(
|
|
963
|
+
join(tempDir, 'db', 'migrations', '008_email_templates.sql'),
|
|
964
|
+
[
|
|
965
|
+
'CREATE TABLE IF NOT EXISTS email_templates (',
|
|
966
|
+
' id UUID PRIMARY KEY,',
|
|
967
|
+
' tenant_id UUID,',
|
|
968
|
+
' org_id UUID',
|
|
969
|
+
');',
|
|
970
|
+
].join('\n')
|
|
971
|
+
);
|
|
972
|
+
|
|
973
|
+
const report = await runDoctor({ projectRoot: tempDir });
|
|
974
|
+
const check = report.checks.find(c => c.name === 'Migrations declare tenancy trio');
|
|
975
|
+
expect(check?.status).toBe('FAIL');
|
|
976
|
+
expect(check?.message).toContain('workspace_id');
|
|
977
|
+
});
|
|
978
|
+
});
|
|
866
979
|
});
|
|
@@ -213,9 +213,8 @@ export async function runBuildCatalog(registryDir?: string): Promise<DomainCatal
|
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
const
|
|
217
|
-
await mkdir(
|
|
218
|
-
const outPath = join(mcDir, 'domain-registry.json');
|
|
216
|
+
const outPath = join(dir, 'domain-registry.json');
|
|
217
|
+
await mkdir(dir, { recursive: true });
|
|
219
218
|
await writeFile(outPath, JSON.stringify(catalog), 'utf8');
|
|
220
219
|
|
|
221
220
|
cliLogger.info(
|