feat: allow solutions in any step (#67280)

This commit is contained in:
Oliver Eyton-Williams
2026-05-08 13:20:42 +02:00
committed by GitHub
parent 7671f673e4
commit 8aae60979e
2 changed files with 0 additions and 67 deletions

View File

@@ -1,8 +1,6 @@
const { isEmpty } = require('lodash');
const { root } = require('mdast-builder');
const visitChildren = require('unist-util-visit-children');
const fs = require('fs');
const path = require('path');
const { editableRegionMarker, isWorkshop } = require('./add-seed');
const { getSection } = require('./utils/get-section');
@@ -18,52 +16,6 @@ function validateMarkers({ value }) {
);
}
function isLastStep(file) {
const challengeDir = path.dirname(file.path);
const blockName = path.basename(challengeDir);
let current = challengeDir;
let blockJsonPath = null;
for (let i = 0; i < 10; i++) {
current = path.dirname(current);
const candidate = path.join(
current,
'structure',
'blocks',
`${blockName}.json`
);
if (fs.existsSync(candidate)) {
blockJsonPath = candidate;
break;
}
}
if (!blockJsonPath) return true;
try {
const blockData = JSON.parse(fs.readFileSync(blockJsonPath, 'utf8'));
// Upcoming blocks may still contain transitional content that does not yet
// follow this invariant.
if (blockData.isUpcomingChange) {
return true;
}
const challengeOrder = blockData.challengeOrder;
if (!Array.isArray(challengeOrder) || challengeOrder.length === 0) {
return true;
}
const currentId = path.basename(file.path, '.md');
const lastId = challengeOrder[challengeOrder.length - 1].id;
return currentId === lastId;
} catch {
return true;
}
}
function createPlugin() {
return function transformer(tree, file) {
const solutionArrays = splitOnThematicBreak(
@@ -100,11 +52,6 @@ function createPlugin() {
`Workshop challenge ${file.path} must have exactly 2 editable region markers`
);
}
if (solutions.length > 0 && !isLastStep(file)) {
throw Error(
`Workshop challenge ${file.path} has solutions but is not the last step.`
);
}
}
file.data = {
...file.data,

View File

@@ -95,20 +95,6 @@ describe('add solution plugin', () => {
plugin(mockAST, file);
expect(file.data).toMatchSnapshot();
});
it('should throw if a workshop non-last step has solutions', async () => {
expect.assertions(1);
const workshopNonLastAST = await parseFixture('with-multiple-solns.md');
const workshopFile = {
data: {},
path: path.join(
__dirname,
'../__fixtures__/workshop-test-steps/step-1.md'
)
};
expect(() => plugin(workshopNonLastAST, workshopFile)).toThrow(
'has solutions but is not the last step'
);
});
it('should allow solutions in non-last steps for upcoming workshop blocks', async () => {
expect.assertions(1);