Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions adapters/framework.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ function requirementCard(requirement, index, pageRoutes, base) {

function functionalityMarkup(frontmatter, pageRoutes, base) {
const requirements = frontmatter.requirements ?? [];
if (!requirements.length) return '';
if (!requirements.length) return undefined;
const facts = [];
if (frontmatter.realises?.length) facts.push(['Capabilities', frontmatter.realises.join(', ')]);
if (frontmatter.conformance) facts.push(['Conformance', frontmatter.conformance]);
Expand All @@ -552,19 +552,20 @@ function functionalityMarkup(frontmatter, pageRoutes, base) {
const cards = requirements
.map((requirement, index) => requirementCard(requirement, index + 1, pageRoutes, base))
.join('\n');
return `<div class="functionality-summary">
return {
summary: `<div class="functionality-summary">
<p>${inlineHtml(frontmatter.description)}</p>
${factMarkup ? `<dl>${factMarkup}</dl>` : ''}
</div>

## Requirements
</div>`,
requirements: `## Requirements

<p class="requirements-introduction">This functionality defines ${requirements.length} authoring-draft requirement${requirements.length === 1 ? '' : 's'}. “Unnumbered draft” reflects the source metadata and does not invent a permanent requirement identifier.</p>

<div class="requirements-list">
${cards}
</div>
`;
`,
};
}

function markdownTableCell(value) {
Expand Down Expand Up @@ -690,7 +691,9 @@ function transformBody({ page, pageRoutes, pageAnchors, base, metadata, authors,
body = `${[...page.compatibilityAnchors].map((id) => `<a id="${htmlEscape(id)}"></a>`).join('\n')}\n\n${body}`;
}
const functionality = functionalityMarkup(frontmatter, pageRoutes, base);
if (functionality) body = `${functionality}\n\n${body}`;
if (functionality) {
body = [functionality.summary, body, functionality.requirements].filter(Boolean).join('\n\n');
}
if (sourceName === 'README.md') body = `${homeMetadataMarkup(metadata, authors)}\n\n${body}`;
const isArchive = sourceName.startsWith('resources/history/') || sourceName.includes('/legacy/');
if (isArchive) {
Expand Down
123 changes: 112 additions & 11 deletions tests/framework.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ requirements:

# Consultation workflow

The source Registry remains authoritative.
The source Registry remains authoritative. Follow the [testing workflow](../resources/testing.md#consultation-1).

## Data structures

Registry Records carry the declared representation.
`);
await write(sourceRoot, 'resources/testing.md', `# Testing

Expand Down Expand Up @@ -156,6 +160,24 @@ Supporting text.
return { root, sourceRoot, siteRoot };
}

async function assertArchivePagesExcluded(siteRoot, pages) {
const archives = pages.filter(
({ source }) => source.startsWith('resources/history/') || source.includes('/legacy/'),
);
for (const archive of archives) {
const relative = archive.route ? `${archive.route}.md` : 'index.md';
const renderedArchive = await readFile(
path.join(siteRoot, 'src/content/docs', relative),
'utf8',
);
assert.match(
renderedArchive,
/^pagefind: false$/m,
`${archive.source} must stay out of default search`,
);
}
}

test('shared adapter module has no standalone CLI behavior', async () => {
const { stdout, stderr } = await execFileAsync(process.execPath, [adapterPath]);
assert.equal(stdout, '');
Expand Down Expand Up @@ -327,6 +349,7 @@ test('generator rewrites routes, renders requirement semantics, copies aliases,
assert.match(requirements, /^title: Provide Registry Services$/m);
assert.doesNotMatch(requirements, /^# Provide Registry Services$/m);
assert.match(requirements, /^## Consultation workflow$/m);
assert.match(requirements, /^## Data structures$/m);
assert.equal((requirements.match(/class="requirement-draft-id">Unnumbered draft/g) ?? []).length, 4);
assert.match(requirements, /class="requirement-card variation-point"/);
assert.match(requirements, /class="requirement-card-title requirement-statement"/);
Expand Down Expand Up @@ -362,6 +385,93 @@ test('generator rewrites routes, renders requirement semantics, copies aliases,
);
});

test('functionality reading order keeps source explanations before requirement cards', async () => {
const { sourceRoot, siteRoot } = await fixture();
const sourcePath = path.join(sourceRoot, 'requirements/service.md');
const sourceBefore = await readFile(sourcePath);

const manifest = await generateSite({ sourceRoot, siteRoot, base: '/' });
const output = await readFile(
path.join(siteRoot, 'src/content/docs/requirements/service.md'),
'utf8',
);

const summaryStart = output.indexOf('<div class="functionality-summary">');
const summaryEnd = output.indexOf('\n</div>', summaryStart);
assert.ok(summaryStart >= 0 && summaryEnd > summaryStart, 'functionality summary is missing');
assert.match(
output.slice(summaryStart, summaryEnd),
/Consumers use declared Registry services\.[\s\S]*Capabilities[\s\S]*Conformance/,
);
const markers = [
'<div class="functionality-summary">',
'## Consultation workflow',
'The source Registry remains authoritative.',
'## Data structures',
'Registry Records carry the declared representation.',
'## Requirements',
'<div class="requirements-list">',
'<article class="requirement-card variation-point"',
];
for (let index = 1; index < markers.length; index += 1) {
const before = markers[index - 1];
const after = markers[index];
assert.ok(
output.indexOf(before) < output.indexOf(after),
`${JSON.stringify(before)} must precede ${JSON.stringify(after)}`,
);
}
assert.equal((output.match(/<div class="functionality-summary">/g) ?? []).length, 1);
assert.equal((output.match(/^## Requirements$/gm) ?? []).length, 1);
assert.equal((output.match(/<article class="requirement-card /g) ?? []).length, 4);
assert.deepEqual(
[...output.matchAll(/<article class="requirement-card [^"]+" id="requirement-(\d+)"/g)].map(
(match) => match[1],
),
['1', '2', '3', '4'],
);
const statementOrder = [
'Provide at least one service.',
'Retrieve one Record.',
'Return the declared representation.',
'Apply the combined profile rules.',
];
for (let index = 1; index < statementOrder.length; index += 1) {
assert.ok(
output.indexOf(statementOrder[index - 1]) < output.indexOf(statementOrder[index]),
`${JSON.stringify(statementOrder[index - 1])} must precede ${JSON.stringify(statementOrder[index])}`,
);
}
assert.match(output, /\[testing workflow\]\(\/resources\/testing\/#consultation-1\)/);
assert.deepEqual(
manifest.pages.find(({ source }) => source === 'requirements/service.md')?.anchors,
[{ id: 'consultation-workflow' }, { id: 'data-structures' }],
);
assert.equal((await readFile(sourcePath)).compare(sourceBefore), 0, 'functionality source bytes changed');
});

test('archive search exclusion follows the generated route rather than the source filename', async () => {
const { sourceRoot, siteRoot } = await fixture();
const tocPath = path.join(sourceRoot, 'toc.yml');
await writeFile(
tocPath,
`${await readFile(tocPath, 'utf8')} resources/history:\n - Release Notes.md\n`,
);
await write(sourceRoot, 'resources/history/Release Notes.md', '# Release notes\n\nHistorical context.\n');

const manifest = await generateSite({ sourceRoot, siteRoot, base: '/' });
const archive = manifest.pages.find(
({ source }) => source === 'resources/history/Release Notes.md',
);
assert.equal(archive?.route, 'resources/history/release-notes');

await assertArchivePagesExcluded(siteRoot, manifest.pages);
assert.match(
await readFile(path.join(siteRoot, 'src/content/docs/resources/history/release-notes.md'), 'utf8'),
/:::caution\[Archived source\]/,
);
});

test('home metadata renders structured extensions and null author URNs faithfully', async () => {
const { sourceRoot, siteRoot } = await fixture();
const metadataPath = path.join(sourceRoot, 'metadata.yml');
Expand Down Expand Up @@ -608,16 +718,7 @@ test('canonical source integration renders its requirements without changing sou
assert.match(requirements, /Any of/);
assert.match(requirements, /Minimum selections/);

const releaseNotes = 'resources/history/release-notes.md';
const renderedReleaseNotes = await readFile(
path.join(siteRoot, 'src/content/docs', releaseNotes),
'utf8',
);
assert.match(
renderedReleaseNotes,
/^pagefind: false$/m,
`${releaseNotes} must stay out of default search`,
);
await assertArchivePagesExcluded(siteRoot, manifest.pages);

const [afterRevision, afterStatus] = await Promise.all([
execFileAsync('git', ['--no-optional-locks', '-C', canonicalSourceRoot, 'rev-parse', 'HEAD']),
Expand Down
Loading