Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 30, 2025

Tests currently accept negative or zero marks values, causing silent scoring failures. This adds build-time validation to reject invalid marks and notify instructors immediately.

Changes

Validation Logic (layouts/partials/test/single.html)

  • Added validation loop checking each question's marks field
  • Rejects values ≤ 0 using Hugo's errorf to halt build
  • Error includes question number, ID, invalid value, and file path

Template Documentation (archetypes/{test,final-test,optional-test}.md)

  • Added comment explaining marks must be positive to prevent instructor confusion

Build Configuration (.gitignore)

  • Excluded content/ directory

Example

Invalid test with negative/zero marks:

questions:
  - id: "q1"
    marks: -5  # Build fails
  - id: "q2"
    marks: 0   # Build fails

Build error output:

ERROR Question 1 (id: q1) has invalid marks value '-5'. 
Marks must be greater than 0. Please update the 'marks' field 
with a positive number. [ tests/example.md ]

Valid test:

questions:
  - id: "q1"
    marks: 2  # ✓ Passes validation
Original prompt

This section details on the original issue you should resolve

<issue_title>Prevent negative marks in quizzes, tests, exams and notify instructors of invalid input</issue_title>
<issue_description>### Current Behavior
Currently, if a quiz/test/exam question is assigned a negative value for the assigned weight (worth) of a question using the marks property (e.g., marks: -1), this value is accepted. This shouldn't be the case. The marks property needs validation.

There is no mechanism to notify instructors that negative marks are not supported or may be unintended.

Expected Behavior

  • Validation logic to ensure the scoring logic never processes negative marks silently, notifies of this error in value.
  • An error message (e.g., using errorf) in the template engine when .marks less than or equal to 0.
  • Display a validation phase in UI if negative marks are found in the YAML.

Implementation

Try suggestion 1. first, then move to 2. if that doesn't work.

  1. use Hugo's templating language to check for the presence of parameters and their basic types within your layouts and partials.

or

  1. Use Hugo's templating language to check for the presence of parameters and their basic types within your layouts and partials.Create a partial or a custom hook that runs during the Hugo build process to perform validation checks across all content files that use the test archetype. or

Contributor Guide and Resources

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Add validation for negative marks in quizzes and exams Add validation to prevent negative or zero marks in test questions Oct 30, 2025
Copilot AI requested a review from ritzorama October 30, 2025 20:56
Copilot finished work on behalf of ritzorama October 30, 2025 20:56
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.

Prevent negative marks in quizzes, tests, exams and notify instructors of invalid input

2 participants