383 lines
13 KiB
JavaScript
383 lines
13 KiB
JavaScript
#!/usr/bin/env node
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
|
|
// Optionaler Root-Override (process.argv[2]) — erlaubt Tests, gegen eine isolierte Fixture-Kopie
|
|
// zu verifizieren, statt reale Repo-Dateien zu mutieren (verhindert Parallelitaets-Races).
|
|
const root = path.resolve(process.argv[2] ?? process.cwd());
|
|
const failures = [];
|
|
const passes = [];
|
|
|
|
function rel(...parts) {
|
|
return path.join(...parts);
|
|
}
|
|
|
|
function abs(relativePath) {
|
|
return path.join(root, relativePath);
|
|
}
|
|
|
|
function pass(message) {
|
|
passes.push(message);
|
|
}
|
|
|
|
function fail(message) {
|
|
failures.push(message);
|
|
}
|
|
|
|
function exists(relativePath) {
|
|
return fs.existsSync(abs(relativePath));
|
|
}
|
|
|
|
function isNonEmptyFile(relativePath) {
|
|
try {
|
|
return fs.statSync(abs(relativePath)).isFile() && fs.readFileSync(abs(relativePath), "utf8").trim().length > 0;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function hasDirectoryEntries(relativePath) {
|
|
try {
|
|
const stat = fs.statSync(abs(relativePath));
|
|
return stat.isDirectory() && fs.readdirSync(abs(relativePath)).length > 0;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function requireReportText(report, text) {
|
|
if (report.includes(text)) {
|
|
pass(`report references ${text}`);
|
|
} else {
|
|
fail(`report must reference ${text}`);
|
|
}
|
|
}
|
|
|
|
function requirePath(relativePath) {
|
|
if (exists(relativePath)) {
|
|
pass(`path exists: ${relativePath}`);
|
|
} else {
|
|
fail(`missing path: ${relativePath}`);
|
|
}
|
|
}
|
|
|
|
function requireRouteGlob(globText, directoryPath) {
|
|
if (hasDirectoryEntries(directoryPath)) {
|
|
pass(`glob resolves: ${globText} -> ${directoryPath}`);
|
|
} else {
|
|
fail(`glob does not resolve to a non-empty directory: ${globText} -> ${directoryPath}`);
|
|
}
|
|
}
|
|
|
|
function requireJsonArrayIncludes(fileLabel, array, expected, messagePrefix) {
|
|
if (Array.isArray(array) && array.includes(expected)) {
|
|
pass(`${messagePrefix}: ${expected}`);
|
|
} else {
|
|
fail(`${fileLabel} missing ${messagePrefix}: ${expected}`);
|
|
}
|
|
}
|
|
|
|
const reportPath = rel("docs", "feature-decisions", "email-marketing-decision-report.md");
|
|
const crmReportPath = rel("docs", "feature-decisions", "crm-decision-report.md");
|
|
const inventoryPath = rel("docs", "feature-inventory.md");
|
|
const pluginCandidatesPath = rel("docs", "feature-manifests", "plugin-candidates.json");
|
|
const transactionalMailPath = rel("docs", "feature-manifests", "transactional-mail.json");
|
|
const emailSequencesDocPath = rel("docs", "features", "email-sequences.md");
|
|
const marketingFunnelDocPath = rel("docs", "features", "marketing-funnel.md");
|
|
|
|
let report = "";
|
|
if (isNonEmptyFile(reportPath)) {
|
|
report = fs.readFileSync(abs(reportPath), "utf8");
|
|
pass(`report exists and is non-empty: ${reportPath}`);
|
|
} else {
|
|
fail(`report is missing or empty: ${reportPath}`);
|
|
}
|
|
|
|
if (report) {
|
|
const requiredHeadings = [
|
|
"## Decision",
|
|
"## Scope",
|
|
"## Current Code Surfaces",
|
|
"## Couplings",
|
|
"## Sender Secrets and Provider Boundary",
|
|
"## Schema and Data Impact",
|
|
"## CRM Audience Decision",
|
|
"## Execution Plan",
|
|
"## Verification Plan",
|
|
"## Risks",
|
|
];
|
|
|
|
for (const heading of requiredHeadings) {
|
|
if (report.includes(heading)) {
|
|
pass(`heading present: ${heading}`);
|
|
} else {
|
|
fail(`missing required heading: ${heading}`);
|
|
}
|
|
}
|
|
|
|
if (report.includes("Decision: `extract-plugin`")) {
|
|
pass("decision token present: Decision: `extract-plugin`");
|
|
} else {
|
|
fail("report must contain exact decision token: Decision: `extract-plugin`");
|
|
}
|
|
|
|
const placeholderPattern = /\b(?:TODO|TBD)\b/i;
|
|
const placeholderMatch = report
|
|
.split(/\r?\n/)
|
|
.filter((line) => !line.includes("TODO/TBD placeholders"))
|
|
.find((line) => placeholderPattern.test(line));
|
|
if (placeholderMatch) {
|
|
fail(`report contains unresolved placeholder line: ${placeholderMatch}`);
|
|
} else {
|
|
pass("report has no TODO/TBD placeholders outside the verifier requirement");
|
|
}
|
|
|
|
const requiredReportReferences = [
|
|
"apps/web/app/modules/emailMarketing",
|
|
"apps/web/app/routes/admin/email-marketing.tsx",
|
|
"apps/web/app/routes/admin/email-marketing/*",
|
|
"apps/web/app/routes/app.$tenant/email-marketing.tsx",
|
|
"apps/web/app/routes/app.$tenant/email-marketing/*",
|
|
"apps/web/app/modules/emailMarketing/services/EmailMarketingService.ts",
|
|
"apps/web/app/modules/emailMarketing/db/emailSender.ts",
|
|
"apps/web/app/modules/emailMarketing/db/campaigns.db.server.ts",
|
|
"apps/web/app/modules/emailMarketing/db/outboundEmails.db.server.ts",
|
|
"prisma/schema/email.prisma",
|
|
"apps/web/app/services/command-registry/commandRegistry.ts",
|
|
"apps/web/public/locales/en/translations.json",
|
|
"apps/web/public/locales/de/translations.json",
|
|
pluginCandidatesPath,
|
|
transactionalMailPath,
|
|
crmReportPath,
|
|
emailSequencesDocPath,
|
|
marketingFunnelDocPath,
|
|
];
|
|
|
|
for (const reference of requiredReportReferences) {
|
|
requireReportText(report, reference);
|
|
}
|
|
|
|
for (const coupling of ["CrmService", "ContactDto", "contact views", "marketingSubscriber", "OutboundEmail.contactRowId"]) {
|
|
requireReportText(report, coupling);
|
|
}
|
|
|
|
for (const boundary of ["EmailSender.apiKey", "platform/admin-owned", "transactional mail", "Marketing sender API keys"]) {
|
|
requireReportText(report, boundary);
|
|
}
|
|
|
|
for (const boundary of [
|
|
"CRM-contact campaign",
|
|
"foundation/admin-preview",
|
|
"production follow-ups",
|
|
"unbootstrapped general handler foundation",
|
|
]) {
|
|
requireReportText(report, boundary);
|
|
}
|
|
}
|
|
|
|
const requiredConcretePaths = [
|
|
"apps/web/app/modules/emailMarketing",
|
|
"apps/web/app/routes/admin/email-marketing.tsx",
|
|
"apps/web/app/routes/app.$tenant/email-marketing.tsx",
|
|
"apps/web/app/modules/emailMarketing/services/EmailMarketingService.ts",
|
|
"apps/web/app/modules/emailMarketing/db/emailSender.ts",
|
|
"apps/web/app/modules/emailMarketing/db/campaigns.db.server.ts",
|
|
"apps/web/app/modules/emailMarketing/db/outboundEmails.db.server.ts",
|
|
"prisma/schema/email.prisma",
|
|
"apps/web/app/services/command-registry/commandRegistry.ts",
|
|
"apps/web/public/locales/en/translations.json",
|
|
"apps/web/public/locales/de/translations.json",
|
|
inventoryPath,
|
|
pluginCandidatesPath,
|
|
transactionalMailPath,
|
|
crmReportPath,
|
|
emailSequencesDocPath,
|
|
marketingFunnelDocPath,
|
|
];
|
|
|
|
for (const requiredPath of requiredConcretePaths) {
|
|
requirePath(requiredPath);
|
|
}
|
|
|
|
requireRouteGlob("apps/web/app/routes/admin/email-marketing/*", "apps/web/app/routes/admin/email-marketing");
|
|
requireRouteGlob("apps/web/app/routes/app.$tenant/email-marketing/*", "apps/web/app/routes/app.$tenant/email-marketing");
|
|
|
|
if (isNonEmptyFile(inventoryPath)) {
|
|
const inventory = fs.readFileSync(abs(inventoryPath), "utf8");
|
|
for (const text of [reportPath, "Email Marketing/Newsletter", "extract-plugin", "transactional mail"]) {
|
|
if (inventory.includes(text)) {
|
|
pass(`inventory references ${text}`);
|
|
} else {
|
|
fail(`inventory must reference ${text}`);
|
|
}
|
|
}
|
|
} else {
|
|
fail(`inventory is missing or empty: ${inventoryPath}`);
|
|
}
|
|
|
|
if (isNonEmptyFile(pluginCandidatesPath)) {
|
|
try {
|
|
const manifest = JSON.parse(fs.readFileSync(abs(pluginCandidatesPath), "utf8"));
|
|
const emailMarketing = Array.isArray(manifest.components)
|
|
? manifest.components.find((component) => component && component.id === "email-marketing")
|
|
: undefined;
|
|
|
|
if (emailMarketing) {
|
|
pass('manifest contains component id "email-marketing"');
|
|
} else {
|
|
fail('manifest must contain component id "email-marketing"');
|
|
}
|
|
|
|
const codeAreas = Array.isArray(emailMarketing?.codeAreas) ? emailMarketing.codeAreas : [];
|
|
for (const codeArea of [
|
|
"apps/web/app/modules/emailMarketing",
|
|
"apps/web/app/modules/emailMarketing/services/EmailMarketingService.ts",
|
|
"apps/web/app/modules/emailMarketing/db/emailSender.ts",
|
|
"apps/web/app/modules/emailMarketing/db/campaigns.db.server.ts",
|
|
"apps/web/app/modules/emailMarketing/db/outboundEmails.db.server.ts",
|
|
"apps/web/app/routes/admin/email-marketing*",
|
|
"apps/web/app/routes/app.$tenant/email-marketing*",
|
|
"prisma/schema/email.prisma",
|
|
]) {
|
|
requireJsonArrayIncludes("plugin-candidates manifest", codeAreas, codeArea, "manifest Email Marketing code area present");
|
|
}
|
|
|
|
const validationSources = Array.isArray(manifest.validation?.source) ? manifest.validation.source : [];
|
|
requireJsonArrayIncludes("plugin-candidates manifest", validationSources, reportPath, "validation source present");
|
|
|
|
if (manifest.pruning?.action === "extract-plugin") {
|
|
pass("manifest pruning.action is extract-plugin");
|
|
} else {
|
|
fail(`manifest pruning.action must be extract-plugin, got ${JSON.stringify(manifest.pruning?.action)}`);
|
|
}
|
|
|
|
const emailSequences = Array.isArray(manifest.components)
|
|
? manifest.components.find((component) => component && component.id === "email-sequences")
|
|
: undefined;
|
|
if (emailSequences) {
|
|
fail('plugin-candidates manifest must not contain component id "email-sequences"; document it as foundation/admin-preview instead');
|
|
} else {
|
|
pass('plugin-candidates manifest excludes component id "email-sequences"');
|
|
}
|
|
|
|
const manifestText = JSON.stringify(manifest);
|
|
for (const forbidden of [
|
|
"apps/web/app/routes/admin/email-sequences*",
|
|
"packages/email-sequences",
|
|
"packages/email-templates",
|
|
"apps/worker/src/jobs/email-sequence-*",
|
|
"prisma/schema/emailSequences.prisma",
|
|
"email-sequence.step",
|
|
"email sequence trigger/scheduler/producers",
|
|
]) {
|
|
if (manifestText.includes(forbidden)) {
|
|
fail(`plugin-candidates manifest must not classify Email Sequences as plugin-candidate code/jobs: ${forbidden}`);
|
|
} else {
|
|
pass(`plugin-candidates manifest does not classify Email Sequences as plugin-candidate code/jobs: ${forbidden}`);
|
|
}
|
|
}
|
|
|
|
for (const requiredText of [
|
|
"Email Marketing remains a CRM-contact campaign plugin candidate",
|
|
"Email Sequences are documented separately as foundation/admin-preview work",
|
|
"marketing-outbound is only a general handler foundation until worker bootstrap is added",
|
|
]) {
|
|
if (manifestText.includes(requiredText)) {
|
|
pass(`plugin-candidates manifest documents boundary text: ${requiredText}`);
|
|
} else {
|
|
fail(`plugin-candidates manifest must document boundary text: ${requiredText}`);
|
|
}
|
|
}
|
|
} catch (error) {
|
|
fail(`manifest JSON parse failed: ${error.message}`);
|
|
}
|
|
} else {
|
|
fail(`manifest is missing or empty: ${pluginCandidatesPath}`);
|
|
}
|
|
|
|
if (isNonEmptyFile(transactionalMailPath)) {
|
|
try {
|
|
const transactionalMail = JSON.parse(fs.readFileSync(abs(transactionalMailPath), "utf8"));
|
|
requireJsonArrayIncludes(
|
|
"transactional-mail manifest",
|
|
transactionalMail.boundaries?.mayMoveToPlugin,
|
|
"Email marketing and newsletter abstractions",
|
|
"transactional boundary mayMoveToPlugin present",
|
|
);
|
|
if (transactionalMail.pruning?.action === "keep") {
|
|
pass("transactional-mail pruning.action remains keep");
|
|
} else {
|
|
fail(`transactional-mail pruning.action must remain keep, got ${JSON.stringify(transactionalMail.pruning?.action)}`);
|
|
}
|
|
} catch (error) {
|
|
fail(`transactional-mail JSON parse failed: ${error.message}`);
|
|
}
|
|
} else {
|
|
fail(`transactional-mail manifest is missing or empty: ${transactionalMailPath}`);
|
|
}
|
|
|
|
if (isNonEmptyFile(crmReportPath)) {
|
|
const crmReport = fs.readFileSync(abs(crmReportPath), "utf8");
|
|
for (const text of ["Email Marketing", "CrmService", "marketingSubscriber", "audience/contact-list abstraction"]) {
|
|
if (crmReport.includes(text)) {
|
|
pass(`CRM report references Email Marketing coupling text: ${text}`);
|
|
} else {
|
|
fail(`CRM report must warn about Email Marketing coupling with: ${text}`);
|
|
}
|
|
}
|
|
} else {
|
|
fail(`CRM report is missing or empty: ${crmReportPath}`);
|
|
}
|
|
|
|
if (isNonEmptyFile(emailSequencesDocPath)) {
|
|
const emailSequencesDoc = fs.readFileSync(abs(emailSequencesDocPath), "utf8");
|
|
for (const text of [
|
|
"foundation/admin-preview",
|
|
"MARKETING_SEQUENCES_ENABLED",
|
|
"production follow-ups",
|
|
"does not classify Email Sequences as the `email-marketing` CRM-contact",
|
|
"general subscriber is not bootstrapped from `apps/worker/src/index.ts`",
|
|
]) {
|
|
if (emailSequencesDoc.includes(text)) {
|
|
pass(`Email Sequences doc references boundary text: ${text}`);
|
|
} else {
|
|
fail(`Email Sequences doc must reference boundary text: ${text}`);
|
|
}
|
|
}
|
|
} else {
|
|
fail(`Email Sequences doc is missing or empty: ${emailSequencesDocPath}`);
|
|
}
|
|
|
|
if (isNonEmptyFile(marketingFunnelDocPath)) {
|
|
const marketingFunnelDoc = fs.readFileSync(abs(marketingFunnelDocPath), "utf8");
|
|
for (const text of [
|
|
"marketing-outbound boundary explicit",
|
|
"handler are a shipped general",
|
|
"general subscriber is not bootstrapped from",
|
|
"`email-marketing` CRM-contact campaign plugin candidate",
|
|
]) {
|
|
if (marketingFunnelDoc.includes(text)) {
|
|
pass(`Marketing Funnel doc references outbound boundary text: ${text}`);
|
|
} else {
|
|
fail(`Marketing Funnel doc must reference outbound boundary text: ${text}`);
|
|
}
|
|
}
|
|
} else {
|
|
fail(`Marketing Funnel doc is missing or empty: ${marketingFunnelDocPath}`);
|
|
}
|
|
|
|
if (failures.length > 0) {
|
|
process.stderr.write(
|
|
[
|
|
"FAIL email marketing decision report verification",
|
|
...failures.map((failure) => `- ${failure}`),
|
|
`Summary: ${passes.length} passed, ${failures.length} failed`,
|
|
].join("\n") + "\n",
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
process.stdout.write(
|
|
`PASS email marketing decision report verification\nSummary: ${passes.length} passed, 0 failed\n`,
|
|
);
|