@mettlecast/domain-cli 0.2.83 → 0.2.85

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mettlecast/domain-cli",
3
- "version": "0.2.83",
3
+ "version": "0.2.85",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org",
@@ -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
  });