Skip to content
Open
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
1 change: 0 additions & 1 deletion buildSrc/src/main/kotlin/common-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ kotlin {
repositories {
mavenCentral()
maven("https://cache-redirector.jetbrains.com/intellij-dependencies")
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-js-wrappers")
maven("https://packages.jetbrains.team/maven/p/edu/maven")
maven("https://packages.jetbrains.team/maven/p/edu/educational-ml-library")
maven("https://packages.jetbrains.team/maven/p/grazi/grazie-platform-public")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ object EduFormatNames {
const val ROWS = "rows"
const val COLUMNS = "columns"
const val IS_CHECKBOX = "is_checkbox"
const val LINES = "lines"
const val COMPONENTS = "components"

const val DEFAULT_ENVIRONMENT = ""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package org.hyperskill.academy.learning.courseFormat.attempts

import com.fasterxml.jackson.annotation.JsonProperty
import org.hyperskill.academy.learning.courseFormat.EduFormatNames.COLUMNS
import org.hyperskill.academy.learning.courseFormat.EduFormatNames.COMPONENTS
import org.hyperskill.academy.learning.courseFormat.EduFormatNames.IS_CHECKBOX
import org.hyperskill.academy.learning.courseFormat.EduFormatNames.IS_MULTIPLE_CHOICE
import org.hyperskill.academy.learning.courseFormat.EduFormatNames.LINES
import org.hyperskill.academy.learning.courseFormat.EduFormatNames.OPTIONS
import org.hyperskill.academy.learning.courseFormat.EduFormatNames.PAIRS
import org.hyperskill.academy.learning.courseFormat.EduFormatNames.ROWS
Expand All @@ -28,6 +30,12 @@ class Dataset {
@JsonProperty(IS_CHECKBOX)
var isCheckbox: Boolean = false

@JsonProperty(LINES)
var lines: List<String>? = null

@JsonProperty(COMPONENTS)
var components: List<Component>? = null

constructor()
constructor(emptyDataset: String) // stepik returns empty string instead of null

Expand All @@ -38,4 +46,18 @@ class Dataset {
@JsonProperty("second")
val second: String = ""
}

/**
* A part of a `fill-blanks` step: the text with the blanks goes first, then an `input` or a `select` for every blank.
*/
class Component {
@JsonProperty("type")
val type: String = ""

@JsonProperty("text")
val text: String = ""

@JsonProperty(OPTIONS)
val options: List<String> = emptyList()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.hyperskill.academy.learning.courseFormat.EduFormatNames.HYPERSKILL
import org.hyperskill.academy.learning.courseFormat.EduFormatNames.HYPERSKILL_PROBLEMS
import org.hyperskill.academy.learning.courseFormat.EduFormatNames.HYPERSKILL_PROJECTS_URL
import org.hyperskill.academy.learning.courseFormat.EduFormatNames.HYPERSKILL_TOPICS
import org.hyperskill.academy.learning.courseFormat.tasks.QuizTask
import org.hyperskill.academy.learning.courseFormat.tasks.Task
import org.hyperskill.academy.learning.wrapWithUtm
import java.util.concurrent.ConcurrentHashMap
Expand Down Expand Up @@ -116,7 +117,7 @@ class HyperskillCourse : Course {
HyperskillTaskType.CODE.type,
HyperskillTaskType.PYCHARM.type,
HyperskillTaskType.TEXT.type,
)
) + QuizTask.BLOCK_NAMES

fun isStepSupported(type: String?): Boolean = type in SUPPORTED_STEP_TYPES
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ enum class HyperskillTaskType(val type: String, val value: String) {
DATASET("dataset", "Data"),
FILL_BLANKS("fill-blanks", "Fill Blanks"),
FREE_ANSWER("free-answer", "Free Response"),
HTML("html", "HTML"),
MANUAL_SCORE("manual-score", "Manual Score"),
MATCHING("matching", "Matching"),
MATH("math", "Math"),
NUMBER("number", "Number"),
PARSONS("parsons", "Parsons"),
PROMPT("prompt", "Prompt"),
PYCHARM(PYCHARM_TASK_TYPE, "Programming"),
REMOTE_EDU(REMOTE_EDU_TASK_TYPE, "Programming"),
SORTING("sorting", "Sorting"),
SQL("sql", "SQL"),
STRING("string", "Text"),
TABLE("table", "Table"),
TEXT("text", "Theory"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package org.hyperskill.academy.learning.courseFormat.tasks

import org.hyperskill.academy.learning.courseFormat.CheckStatus
import org.hyperskill.academy.learning.courseFormat.attempts.Attempt
import org.hyperskill.academy.learning.courseFormat.hyperskill.HyperskillTaskType
import java.util.*

/**
* A Hyperskill step that isn't a code step, answered with the form in the task description: choice, matching, sorting, etc.
*
* What the learner sees (options, pairs, rows) belongs to a server-side attempt and differs between attempts, so it is
* requested from the server every time the task is opened. The course files only store the block type, as the task `type`.
*
* Some blocks are answered with task files instead, see [ANSWER_FILES]: the form shows the rest of the step there.
*/
class QuizTask : Task {
var blockName: String = ""

/** The attempt the answer belongs to. It comes from the server and is not stored in the course files. */
var attempt: Attempt? = null

/** The answer in the format of a submission reply, `null` until the learner gives one. It is not stored in the course files. */
var reply: Map<String, Any?>? = null

//used for deserialization
constructor()

constructor(name: String, id: Int, position: Int, updateDate: Date, status: CheckStatus, blockName: String) :
super(name, id, position, updateDate, status) {
this.blockName = blockName
}

override val itemType: String
get() = blockName

override val isChangedOnFailed: Boolean
get() = true

companion object {
const val HTML_FILE_NAME: String = "index.html"
const val CSS_FILE_NAME: String = "style.css"
const val SQL_FILE_NAME: String = "query.sql"
const val DATASET_FILE_NAME: String = "dataset.txt"

/**
* Blocks that can be answered inside the IDE. `video` is the only block of the website that isn't there: it is a
* kind of theory, and no step uses it.
*/
val BLOCK_NAMES: Set<String> = setOf(
HyperskillTaskType.CHOICE.type,
HyperskillTaskType.DATASET.type,
HyperskillTaskType.FILL_BLANKS.type,
HyperskillTaskType.HTML.type,
HyperskillTaskType.MATCHING.type,
HyperskillTaskType.MATH.type,
HyperskillTaskType.NUMBER.type,
HyperskillTaskType.PARSONS.type,
HyperskillTaskType.PROMPT.type,
HyperskillTaskType.SORTING.type,
HyperskillTaskType.SQL.type,
HyperskillTaskType.STRING.type,
HyperskillTaskType.TABLE.type,
)

/**
* Blocks answered with task files: the learner writes the page or the query in the editor, not in the form.
*/
val ANSWER_FILES: Map<String, List<String>> = mapOf(
HyperskillTaskType.HTML.type to listOf(HTML_FILE_NAME, CSS_FILE_NAME),
HyperskillTaskType.SQL.type to listOf(SQL_FILE_NAME),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,14 @@ object YamlDeserializer {
// for student mode
CODE_TASK_TYPE -> CodeTask::class.java
UNSUPPORTED_TASK_TYPE -> UnsupportedTask::class.java
in QuizTask.BLOCK_NAMES -> QuizTask::class.java
else -> formatError(unsupportedItemTypeMessage(type, TASK))
}
return treeToValue(treeNode, clazz)
val task = treeToValue(treeNode, clazz)
if (task is QuizTask) {
task.blockName = type
}
return task
}

private fun <T : StudyItem> ObjectMapper.migrateStudyItemYamlTree(
Expand Down
7 changes: 7 additions & 0 deletions intellij-plugin/hs-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ dependencies {
"intellij.libraries.jcef",
"intellij.platform.sqlite",
)
// Not on the core classpath since 2026.3. They come transitively through `intellij.platform.vcs.impl`, but the Gradle plugin
// sometimes generates its descriptor without dependencies, and then `VcsBundle` and `RestService` are missing
bundledModulesSince(
baseVersion, 263,
"intellij.platform.vcs.core",
"intellij.platform.builtInServer.impl",
)
intellijPlugins(platformPluginsExtractedFromCore)
// `TestServiceMessageConsumer` uses the TeamCity service messages library, which is not part of the core classpath since 2026.3
testBundledModulesSince(baseVersion, 263, "intellij.libraries.teamcity.service.messages")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ action.open.on.text=Open on {0}
action.rename=Rename {0}

action.retry.already.running=Loading is already running
action.retry.shuffle.message=Answer choices will be shuffled next time.
action.retry.task.background=Loading task

action.select.course.location=Location
Expand Down Expand Up @@ -321,6 +320,11 @@ hyperskill.loading.project=Loading Hyperskill Project
hyperskill.loading.project.info=Fetching project information...
hyperskill.loading.step.info=Fetching step information...
hyperskill.creating.course=Creating course structure...
hyperskill.quiz.no.answer=Give an answer first
hyperskill.dataset.download.first=Download the dataset first
hyperskill.dataset.failed.to.download=Failed to download the dataset
hyperskill.dataset.failed.to.save=Failed to save the dataset
hyperskill.quiz.solve.on.website=Solve this problem on <a href="{0}">{1}</a>, then click "Sync with Hyperskill" to move on.
hyperskill.string.task.empty.text=Input text is empty
hyperskill.course.view.progress={0} of {1} stages completed
hyperskill.courses.explanation={0} is a project-based learning platform that hosts Hyperskill Academy educational content. Our \
Expand Down
151 changes: 151 additions & 0 deletions intellij-plugin/hs-core/resources/quiz/hyperskill_html_tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// The checklist of an `html` step: the same tests the website runs, see `apps/frontend/src/utils/html-tests.js` in `alt`.
//
// The server doesn't check an `html` step, it takes the score the client sends. So a check passes in the IDE exactly when
// it passes on the website. The libraries the tests need are in `lib/`, see `lib/README.md`.
window.hsHtmlTests = (() => {
function checkRegexp(regExp, content) {
const parsed = regExp.match(/^\/(.*)\/([a-z]{0,20})$/);
if (!parsed) return null;

const flags = `${parsed[2] || ''}g`
.split('')
.filter((flag) => 'gimsuy'.includes(flag))
.filter((flag, index, all) => all.indexOf(flag) === index)
.join('');
return new RegExp(parsed[1], flags).test(content);
}

function htmlHint() {
const module = window.HTMLHint;
return module && (module.HTMLHint || module);
}

function isValidHtml(html) {
const hint = htmlHint();
if (!hint || !hint.verify) return false;

const messages = hint.verify(html, {
'tagname-lowercase': true,
'attr-lowercase': true,
'attr-value-double-quotes': false,
'doctype-first': false,
'tag-pair': true,
'spec-char-escape': true,
'id-unique': true,
'src-not-empty': true,
'attr-no-duplication': true,
});
return !messages.some((message) => message.type === 'error');
}

function isValidCss(css) {
const validator = window.csstreeValidator;
if (!validator || !validator.validate) return false;
return validator.validate(css).length === 0;
}

const tests = {
hasElement(element, {childSel}) {
if (!element) return false;
return childSel ? !!element.querySelector(childSel) : true;
},

checkClass(element, {className}) {
if (element.classList) return element.classList.contains(className);
return new RegExp(`(^| )${className}( |$)`, 'gi').test(element.className);
},

checkAttribute(element, {attr, attrValue}) {
return element.getAttribute(attr) === attrValue;
},

// Comparing computed values makes aliases, shorthands and relative values work: `color: red`, `border: 1px solid`,
// `width: 50%`. The expected values are the ones the element gets with the expected rule applied.
checkCssStyle(element, {ruleName, value}) {
if (!(ruleName in element.style)) return false;

const shorthands = window.cssShorthandProps;
const longhands = shorthands ? [shorthands.expand(ruleName, true)].flat(Infinity) : [ruleName];
const computedStyle = element.ownerDocument.defaultView.getComputedStyle(element);
const actualValues = longhands.map((property) => computedStyle.getPropertyValue(property));

const originalStyle = element.style.cssText;
element.style.setProperty(ruleName, value, 'important');
const expectedValues = longhands.map((property) => computedStyle.getPropertyValue(property));
element.style.cssText = originalStyle;

return actualValues.every((actual, index) => actual === expectedValues[index]);
},

checkContent(element, {contentExpression}) {
const content = element.innerHTML;
const result = checkRegexp(contentExpression, content);
return result !== null ? result : content === contentExpression;
},

checkSource(element, {sourceType, sourceExpression}, sources) {
const source = sources[sourceType];
if (!source) return false;
return !!checkRegexp(sourceExpression, source);
},

checkValidityOfSources(element, {sourceType}, sources) {
if (!sourceType) return false;
const checksHtml = sourceType === 'html + css' || sourceType === 'html';
const checksCss = sourceType === 'html + css' || sourceType === 'css';
return (!checksHtml || isValidHtml(sources.html)) && (!checksCss || isValidCss(sources.css));
},
};

function runCheck(check, document, sources) {
const target = document.querySelector(check.selector || 'body');
if (!target) return false;

return (check.tests || []).every(({type, data}) => {
const test = tests[type];
if (!test) return false;
try {
return !!test(target, data || {}, sources);
}
catch (e) {
console.warn(`The ${type} test failed with an error`, e);
return false;
}
});
}

// Like on the website, the page is rendered from the HTML with the CSS put into its head, in place of a link to
// `style.css` if there is one, so that the tests see the styles applied.
function renderPage(frame, sources) {
const page = new DOMParser().parseFromString(sources.html.replace(/href="/g, 'target="_blank" href="'), 'text/html');
const head = page.head;
const firstHeadNode = head.firstChild;

const baseStyle = page.createElement('style');
baseStyle.textContent = 'body { font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica Neue, Arial, sans-serif; margin: 0; }';
head.insertBefore(baseStyle, firstHeadNode);

const userStyle = page.createElement('style');
userStyle.textContent = sources.css || '';
const styleLink = head.querySelector('link[href="style.css"]') || head.querySelector('link[href="./style.css"]');
head.insertBefore(userStyle, styleLink || firstHeadNode);
if (styleLink) head.removeChild(styleLink);

const document = frame.contentWindow.document;
document.replaceChild(document.importNode(page.documentElement, true), document.documentElement);
return document;
}

/**
* Renders the page in the [frame] and runs the [checklist] on it.
*
* @return the result of every check and the score the server expects: 1 if all of them pass, 0 otherwise
*/
function run(frame, checklist, sources) {
const document = renderPage(frame, sources);
const results = (checklist || []).map((check) => ({name: check.name, isSuccess: runCheck(check, document, sources)}));
return {results, score: results.every((result) => result.isSuccess) ? 1 : 0};
}

return {run};
})();
Loading
Loading