From 0c4b8b27b7b0d12761338849ac345c377599bfd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?je=CC=81ro=CC=82me=20boileux?= Date: Thu, 22 Oct 2026 14:40:47 +0200 Subject: [PATCH 1/2] feat(challenge): add the optional partner block Adds partner (tool, sentence, two before/after metrics, required source) to the challenge schema with its caps, checks partner.tool against Tool slugs in validateRepository, and gives the Sales Compensation fixture the Qobra block from the mockup. Closes #97 --- scripts/__tests__/challenge.schema.test.js | 78 +++++++++++++++++-- .../fixtures/challenges/sales-compensation.md | 11 +++ scripts/__tests__/validate-repository.test.js | 49 ++++++++++++ scripts/schemas/challenge.schema.js | 18 +++++ scripts/validate-repository.js | 8 ++ 5 files changed, 158 insertions(+), 6 deletions(-) diff --git a/scripts/__tests__/challenge.schema.test.js b/scripts/__tests__/challenge.schema.test.js index e6df0e2..a432cbc 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,72 @@ 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', '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..d90901b 100644 --- a/scripts/__tests__/validate-repository.test.js +++ b/scripts/__tests__/validate-repository.test.js @@ -163,6 +163,55 @@ 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', + ); + + beforeEach(() => { + ['qobra', 'salesforce'].forEach((tool) => write(`tools/${tool}.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', SALES_COMPENSATION.replace(/^ {2}tool: qobra$/m, ' tool: 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('resolves a padded partner tool slug, as the schema trims it', () => { + write('challenges/fr/sales-compensation.md', SALES_COMPENSATION.replace(/^ {2}tool: qobra$/m, ' tool: " qobra "')); + + expect(validateRepository(repoRoot).failures).toEqual([]); + }); + + it('reports a blank partner tool once, as a schema error', () => { + write('challenges/fr/sales-compensation.md', SALES_COMPENSATION.replace(/^ {2}tool: qobra$/m, ' tool: " "')); + + expect(validateRepository(repoRoot).failures).toEqual([ + { + file: 'challenges/fr/sales-compensation.md', + schemaErrors: [{ path: ['partner', 'tool'], message: 'must not be empty' }], + crossRefErrors: [], + }, + ]); + }); + }); + 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..9b01ade 100644 --- a/scripts/validate-repository.js +++ b/scripts/validate-repository.js @@ -54,6 +54,14 @@ const validateCrossRefs = (type, data, resolver) => { } }); } + if (type === 'challenge') { + // A malformed partner block is already a schema error; skip the cross-reference. + // Trim as the schema does, so a padded slug resolves and a blank one is not reported twice. + const tool = typeof data.partner?.tool === 'string' ? data.partner.tool.trim() : ''; + if (tool !== '' && !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'], From dcf935f0296b1fe62899ce96e9a36998645fd0ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?je=CC=81ro=CC=82me=20boileux?= Date: Thu, 22 Oct 2026 15:18:21 +0200 Subject: [PATCH 2/2] fix(challenge): reject padded partner tool slugs Applies the PR #113 review: the partner.tool cross-reference no longer trims, like team tools and featuredTool. The fixture edit in the cross-reference tests now throws when it does not apply, the cap tests cover the second metric, and CLAUDE.md lists partner.tool among the strict cross-refs. --- CLAUDE.md | 2 +- scripts/__tests__/challenge.schema.test.js | 3 +++ scripts/__tests__/validate-repository.test.js | 27 ++++++++++--------- scripts/validate-repository.js | 5 ++-- 4 files changed, 21 insertions(+), 16 deletions(-) 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 a432cbc..b8c48b8 100644 --- a/scripts/__tests__/challenge.schema.test.js +++ b/scripts/__tests__/challenge.schema.test.js @@ -278,6 +278,9 @@ const PARTNER_CAPS = [ [['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], ]; diff --git a/scripts/__tests__/validate-repository.test.js b/scripts/__tests__/validate-repository.test.js index d90901b..760e17f 100644 --- a/scripts/__tests__/validate-repository.test.js +++ b/scripts/__tests__/validate-repository.test.js @@ -169,8 +169,15 @@ describe('validateRepository with challenge files', () => { '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(() => { - ['qobra', 'salesforce'].forEach((tool) => write(`tools/${tool}.md`, TOOL)); + write('tools/qobra.md', TOOL); }); it('accepts a partner citing an existing tool slug', () => { @@ -180,7 +187,7 @@ describe('validateRepository with challenge files', () => { }); it('reports a partner tool that is not a tool slug, naming the slug', () => { - write('challenges/fr/sales-compensation.md', SALES_COMPENSATION.replace(/^ {2}tool: qobra$/m, ' tool: ghost-tool')); + write('challenges/fr/sales-compensation.md', withPartnerTool('ghost-tool')); expect(validateRepository(repoRoot).failures).toEqual([ { @@ -193,20 +200,16 @@ describe('validateRepository with challenge files', () => { ]); }); - it('resolves a padded partner tool slug, as the schema trims it', () => { - write('challenges/fr/sales-compensation.md', SALES_COMPENSATION.replace(/^ {2}tool: qobra$/m, ' tool: " qobra "')); - - expect(validateRepository(repoRoot).failures).toEqual([]); - }); - - it('reports a blank partner tool once, as a schema error', () => { - write('challenges/fr/sales-compensation.md', SALES_COMPENSATION.replace(/^ {2}tool: qobra$/m, ' tool: " "')); + 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: [{ path: ['partner', 'tool'], message: 'must not be empty' }], - crossRefErrors: [], + schemaErrors: [], + crossRefErrors: [ + { path: ['partner', 'tool'], message: '" qobra " does not match any tool slug' }, + ], }, ]); }); diff --git a/scripts/validate-repository.js b/scripts/validate-repository.js index 9b01ade..b3d8f7a 100644 --- a/scripts/validate-repository.js +++ b/scripts/validate-repository.js @@ -56,9 +56,8 @@ const validateCrossRefs = (type, data, resolver) => { } if (type === 'challenge') { // A malformed partner block is already a schema error; skip the cross-reference. - // Trim as the schema does, so a padded slug resolves and a blank one is not reported twice. - const tool = typeof data.partner?.tool === 'string' ? data.partner.tool.trim() : ''; - if (tool !== '' && !resolver.isValidToolSlug(tool)) { + 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` }); } }