Skip to content

Conversation

@tohlh
Copy link
Contributor

@tohlh tohlh commented Apr 5, 2025

This PR aims to add language options to Source Academy missions. The use case for now is allowing instructors to configure type strictness in Source Typed variants.

Library Schema

The Library Schema is used to describe the language configuration for an assessment question. An optional field languageOption is added into the Library schema to achieve our objective.

XML Parsing

This changes the XML parser. Specifically, the XML tags <DEPLOYMENT> and <GRADERDEPLOYMENT> are renamed to <PROGRAMMINGLANGUAGE>, <GRADERPROGRAMMINGLANGUAGE>, as per discussion. <LANGUAGEOPTIONS> tags are also added to configure programming language flags.

Example usage of <PROGRAMMINGLANGUAGE>, <GRADERPROGRAMMINGLANGUAGE> and <LANGUAGEOPTIONS> tag:

<PROGRAMMINGLANGUAGE chapter="2" variant="typed">
  <OPTION key="typedAllowAnyInVariables" value="false" />
  <OPTION key="typedAllowAnyInParameters" value="false" />
  <OPTION key="typedAllowAnyInReturnType" value="false" />
  <OPTION key="typedAllowAnyInTypeAnnotationParameters" value="false" />
  <OPTION key="typedAllowAnyInTypeAnnotationReturnType" value="false" />
</PROGRAMMINGLANGUAGE>

<GRADERPROGRAMMINGLANGUAGE chapter="2" variant="typed">
  <OPTION key="typedAllowAnyInVariables" value="false" />
  <OPTION key="typedAllowAnyInParameters" value="false" />
  <OPTION key="typedAllowAnyInReturnType" value="false" />
  <OPTION key="typedAllowAnyInTypeAnnotationParameters" value="false" />
  <OPTION key="typedAllowAnyInTypeAnnotationReturnType" value="false" />
</GRADERPROGRAMMINGLANGUAGE>

These changes are not breaking and should work with existing assessments. For future assessments, XMLs have to be changed.

Copy link
Contributor

@GabrielCWT GabrielCWT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me. Please format and fix any other failing CI

RichDom2185
RichDom2185 previously approved these changes Apr 6, 2025
Copy link
Member

@RichDom2185 RichDom2185 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@RichDom2185 RichDom2185 enabled auto-merge (squash) April 6, 2025 03:25
@RichDom2185 RichDom2185 dismissed their stale review April 6, 2025 03:34

CI fail

@coveralls
Copy link

coveralls commented Jun 13, 2025

Coverage Status

coverage: 89.621% (-0.02%) from 89.636%
when pulling ffbe470 on tohlh:language-options
into 40cd12a on source-academy:master.

@RichDom2185 RichDom2185 requested a review from Copilot November 4, 2025 15:28
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for language options in the programming language configuration by introducing a new language_options field to the Library schema. The changes enable parsing language-specific configuration options from XML and exposing them through the API.

  • Added language_options field to the Library embedded schema with a default value of an empty map
  • Updated XML parser to extract OPTION elements from PROGRAMMINGLANGUAGE tags and convert them to a key-value map
  • Refactored XML tag names from DEPLOYMENT/GRADERDEPLOYMENT to PROGRAMMINGLANGUAGE/GRADERPROGRAMMINGLANGUAGE and renamed the parsing function accordingly

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
lib/cadet/assessments/library.ex Added language_options field to Library schema and included it in optional fields for validation
lib/cadet/jobs/xml_parser.ex Updated XML parsing to use PROGRAMMINGLANGUAGE tags, renamed parsing function, and added logic to extract OPTION elements into language_options map
lib/cadet_web/helpers/assessments_helpers.ex Added languageOptions mapping to expose the new field in API responses
test/cadet_web/admin_controllers/admin_grading_controller_test.exs Updated test expectations to include the new languageOptions field in library objects
Comments suppressed due to low confidence (1)

lib/cadet/assessments/library.ex:32

  • The new language_options field lacks validation similar to the globals field. Since language_options is a map that will be parsed from XML attributes and exposed in the API, it should have validation to ensure the map contains only string keys and string values, similar to validate_globals/1. Consider adding a validate_language_options/1 function and calling it in the changeset pipeline.
  def changeset(library, params \\ %{}) do
    library
    |> cast(params, @required_fields ++ @optional_fields)
    |> cast_embed(:external)
    |> put_default_external()
    |> validate_required(@required_fields ++ @required_embeds)
    |> validate_globals()
    |> validate_chapter()
    |> validate_chapter_variant()
  end

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@RichDom2185 RichDom2185 disabled auto-merge November 4, 2025 15:47
@RichDom2185
Copy link
Member

@sentry generate-test

@seer-by-sentry
Copy link

seer-by-sentry bot commented Nov 4, 2025

Sentry has determined that unit tests are not necessary for this PR.

@RichDom2185
Copy link
Member

@sentry review

@RichDom2185 RichDom2185 merged commit 8736877 into source-academy:master Nov 4, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants