diff --git a/CLAUDE.md b/CLAUDE.md index dc0984d..042a5fc 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -33,4 +33,4 @@ Traps to respect when editing content directly: - **Slugs are identity** - kebab-case, and the cross-reference key for authors, tools, hiringContacts. Renaming a slug breaks references. - **Blob URLs** - image fields (`avatar`, `image`, `iconUrl`) must resolve to Vercel Blob URLs; CI rewrites local paths on PR. `pnpm validate` fails on local paths until then - expected pre-sync. - **Multi-language paradigm** - blog/story/job/challenge live under `//.md` (`fr` default). Challenge files sit in `challenges//` with the same slug in both languages, and carry frontmatter only: a body fails validation. Team members carry both languages inline (`role.fr/en`, `bio.fr/en`); tools are language-agnostic (`name`, `category`, no translatable copy). Neither has a per-lang directory. -- **Cross-refs are strict** - `author`, `tools`, `featuredTool`, `hiringContact` must point to existing slugs; validation rejects dangling references. +- **Cross-refs are strict** - `author`, `tools`, `featuredTool`, `hiringContact`, `partner.tool` must point to existing slugs; validation rejects dangling references. diff --git a/scripts/__tests__/challenge.schema.test.js b/scripts/__tests__/challenge.schema.test.js index e6df0e2..b8c48b8 100644 --- a/scripts/__tests__/challenge.schema.test.js +++ b/scripts/__tests__/challenge.schema.test.js @@ -7,22 +7,22 @@ import { validateChallenge } from '../schemas/challenge.schema.js'; import { STAGE_IDS } from '../schemas/stage-ids.js'; // One golden fixture per challenge, built from the text of the six enjeux-*.html -// mockups in ocobo-revops/prototype, without the partner block and the agent -// window. +// mockups in ocobo-revops/prototype, without the agent window. Only the Sales +// Compensation mockup has a partner block. const FIXTURES_DIR = join(dirname(fileURLToPath(import.meta.url)), 'fixtures/challenges'); const loadFixture = (file) => matter(readFileSync(join(FIXTURES_DIR, file), 'utf8')).data; const base = loadFixture('revenue-performance.md'); -const withValue = (path, value) => { - const data = structuredClone(base); +const withValue = (path, value, from = base) => { + const data = structuredClone(from); const parent = path.slice(0, -1).reduce((node, key) => node[key], data); parent[path.at(-1)] = value; return data; }; -const without = (path) => { - const data = structuredClone(base); +const without = (path, from = base) => { + const data = structuredClone(from); const parent = path.slice(0, -1).reduce((node, key) => node[key], data); delete parent[path.at(-1)]; return data; @@ -269,6 +269,75 @@ describe('challenge optional fields', () => { }); }); +// ── partner block ───────────────────────────────────────────────────────────── + +const partnered = structuredClone({ ...base, partner: loadFixture('sales-compensation.md').partner }); + +const PARTNER_CAPS = [ + [['partner', 'sentence'], 140], + [['partner', 'metrics', 0, 'before'], 12], + [['partner', 'metrics', 0, 'after'], 12], + [['partner', 'metrics', 0, 'label'], 90], + [['partner', 'metrics', 1, 'before'], 12], + [['partner', 'metrics', 1, 'after'], 12], + [['partner', 'metrics', 1, 'label'], 90], + [['partner', 'source'], 90], +]; + +describe('challenge partner block', () => { + it('is optional', () => { + expect(base.partner).toBeUndefined(); + expect(issuesOf(base)).toEqual([]); + }); + + it('is open to any challenge', () => { + expect(base.key).not.toBe('sc'); + expect(issuesOf(partnered)).toEqual([]); + }); + + it.each(PARTNER_CAPS)('%j accepts %i characters', (path, cap) => { + expect(issuesOf(withValue(path, 'a'.repeat(cap), partnered))).toEqual([]); + }); + + it.each(PARTNER_CAPS)('%j rejects one character over cap %i, stating length, cap and overage', (path, cap) => { + expect(issuesOf(withValue(path, 'a'.repeat(cap + 1), partnered))).toEqual([ + { path, message: `${cap + 1} characters, cap ${cap} (1 over)` }, + ]); + }); + + it.each([1, 3])('rejects %i metrics', (count) => { + const metrics = Array.from({ length: count }, () => structuredClone(partnered.partner.metrics[0])); + expect(issuesOf(withValue(['partner', 'metrics'], metrics, partnered))).toEqual([ + { path: ['partner', 'metrics'], message: expect.any(String) }, + ]); + }); + + it.each([ + [['partner', 'tool']], + [['partner', 'sentence']], + [['partner', 'metrics']], + [['partner', 'source']], + [['partner', 'metrics', 1, 'after']], + ])('rejects a missing %j', (path) => { + expect(issuesOf(without(path, partnered))).toEqual([{ path, message: expect.any(String) }]); + }); + + it('rejects a blank Tool slug', () => { + expect(issuesOf(withValue(['partner', 'tool'], ' ', partnered))).toEqual([ + { path: ['partner', 'tool'], message: 'must not be empty' }, + ]); + }); + + it.each([ + [['partner', 'logo']], + [['partner', 'metrics', 0, 'trend']], + ])('rejects the unknown key %j', (path) => { + expect(issuesOf(withValue(path, 'x', partnered))).toEqual([ + { path: path.slice(0, -1), message: `Unrecognized key: "${path.at(-1)}"` }, + ]); + }); +}); + // ── unknown keys ────────────────────────────────────────────────────────────── describe('challenge unknown keys', () => { diff --git a/scripts/__tests__/fixtures/challenges/sales-compensation.md b/scripts/__tests__/fixtures/challenges/sales-compensation.md index f7b2f43..8ad56ad 100644 --- a/scripts/__tests__/fixtures/challenges/sales-compensation.md +++ b/scripts/__tests__/fixtures/challenges/sales-compensation.md @@ -68,6 +68,17 @@ workstreams: title: Un plan qui s'ajuste sur des faits description: Mesure de l'effet du plan sur les comportements, traitement des cas particuliers, revue annuelle avec vos RH. deliverable: Un rituel de revue et des règles de gestion des exceptions. +partner: + tool: qobra + sentence: "Qobra automatise le calcul. Ocobo conçoit le plan qu'il calcule, et s'assure qu'il produit les comportements attendus." + metrics: + - before: 7 jours + after: "1" + label: "Clôture mensuelle des commissions chez Doctolib (source : Qobra)" + - before: 3 jours + after: ½ + label: "Clôture mensuelle des commissions chez Pennylane (source : Qobra)" + source: Chiffres publiés par Qobra sur ses clients. aiBridge: title: Chaque commercial sait ce que lui rapporte le deal sur lequel il travaille. bullets: diff --git a/scripts/__tests__/validate-repository.test.js b/scripts/__tests__/validate-repository.test.js index a3b511f..760e17f 100644 --- a/scripts/__tests__/validate-repository.test.js +++ b/scripts/__tests__/validate-repository.test.js @@ -163,6 +163,58 @@ describe('validateRepository with challenge files', () => { expect(validateRepository(repoRoot).failures).toEqual([]); }); + describe('partner block', () => { + const SALES_COMPENSATION = readFileSync( + join(dirname(fileURLToPath(import.meta.url)), 'fixtures/challenges/sales-compensation.md'), + 'utf8', + ); + + // Throws when the fixture line is missing, so a test never runs on an unedited file. + const withPartnerTool = (line) => { + const pattern = /^ {2}tool: qobra$/m; + if (!pattern.test(SALES_COMPENSATION)) throw new Error('partner tool line not found in fixture'); + return SALES_COMPENSATION.replace(pattern, ` tool: ${line}`); + }; + + beforeEach(() => { + write('tools/qobra.md', TOOL); + }); + + it('accepts a partner citing an existing tool slug', () => { + write('challenges/fr/sales-compensation.md', SALES_COMPENSATION); + + expect(validateRepository(repoRoot).failures).toEqual([]); + }); + + it('reports a partner tool that is not a tool slug, naming the slug', () => { + write('challenges/fr/sales-compensation.md', withPartnerTool('ghost-tool')); + + expect(validateRepository(repoRoot).failures).toEqual([ + { + file: 'challenges/fr/sales-compensation.md', + schemaErrors: [], + crossRefErrors: [ + { path: ['partner', 'tool'], message: '"ghost-tool" does not match any tool slug' }, + ], + }, + ]); + }); + + it('reports a padded partner tool slug, like the other tool references', () => { + write('challenges/fr/sales-compensation.md', withPartnerTool('" qobra "')); + + expect(validateRepository(repoRoot).failures).toEqual([ + { + file: 'challenges/fr/sales-compensation.md', + schemaErrors: [], + crossRefErrors: [ + { path: ['partner', 'tool'], message: '" qobra " does not match any tool slug' }, + ], + }, + ]); + }); + }); + it('rejects a challenge file with a markdown body', () => { write('challenges/fr/revenue-performance.md', `${CHALLENGE}\nUn paragraphe.\n`); diff --git a/scripts/schemas/challenge.schema.js b/scripts/schemas/challenge.schema.js index e8340ba..626a0fb 100644 --- a/scripts/schemas/challenge.schema.js +++ b/scripts/schemas/challenge.schema.js @@ -73,6 +73,24 @@ export const challengeSchema = z.strictObject({ intro: cappedText(120), items: z.array(workstream).min(4).max(6), }), + // Open to every challenge (ADR 0002). The logo comes from the Tool file, and + // the figures belong to the partner, so their source is required. + partner: z + .strictObject({ + tool: slug, + sentence: cappedText(140), + metrics: z + .array( + z.strictObject({ + before: cappedText(12), + after: cappedText(12), + label: cappedText(90), + }), + ) + .length(2), + source: cappedText(90), + }) + .optional(), aiBridge: z.strictObject({ title: cappedText(92), bullets: z.array(cappedText(125)).length(3), diff --git a/scripts/validate-repository.js b/scripts/validate-repository.js index beed9e1..b3d8f7a 100644 --- a/scripts/validate-repository.js +++ b/scripts/validate-repository.js @@ -54,6 +54,13 @@ const validateCrossRefs = (type, data, resolver) => { } }); } + if (type === 'challenge') { + // A malformed partner block is already a schema error; skip the cross-reference. + const tool = data.partner?.tool; + if (typeof tool === 'string' && !resolver.isValidToolSlug(tool)) { + errors.push({ path: ['partner', 'tool'], message: `"${tool}" does not match any tool slug` }); + } + } if (type === 'job' && data.hiringContact && !resolver.isValidTeamSlug(data.hiringContact)) { errors.push({ path: ['hiringContact'],