Skip to content

Commit a0be05d

Browse files
committed
Increase impose limit of 1000 chars on expected notes in test cases. (DB update)
1 parent c7ee69c commit a0be05d

8 files changed

Lines changed: 31 additions & 5 deletions

File tree

db/install.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
<FIELD NAME="prtname" TYPE="char" LENGTH="32" NOTNULL="true" SEQUENCE="false" COMMENT="The name of the PRT for which these are the expected outcomes."/>
176176
<FIELD NAME="expectedscore" TYPE="number" LENGTH="12" NOTNULL="false" SEQUENCE="false" DECIMALS="7" COMMENT="The expected score."/>
177177
<FIELD NAME="expectedpenalty" TYPE="number" LENGTH="12" NOTNULL="false" SEQUENCE="false" DECIMALS="7" COMMENT="The expected penalty."/>
178-
<FIELD NAME="expectedanswernote" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The expected answer note."/>
178+
<FIELD NAME="expectedanswernote" TYPE="char" LENGTH="1023" NOTNULL="true" SEQUENCE="false" COMMENT="The expected answer note."/>
179179
</FIELDS>
180180
<KEYS>
181181
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>

db/upgrade.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,16 @@ function xmldb_qtype_stack_upgrade($oldversion) {
10351035
// STACK savepoint reached.
10361036
upgrade_plugin_savepoint(true, 2025042500, 'qtype', 'stack');
10371037
}
1038+
1039+
if ($oldversion < 2026042402) {
1040+
$table = new xmldb_table('qtype_stack_qtest_expected');
1041+
$field = new xmldb_field('expectedanswernote', XMLDB_TYPE_CHAR, '1023', null, XMLDB_NOTNULL, null, null, 'expectedpenalty');
1042+
1043+
$dbman->change_field_type($table, $field);
1044+
1045+
// STACK savepoint reached.
1046+
upgrade_plugin_savepoint(true, 2026042402, 'qtype', 'stack');
1047+
}
10381048
// Add new upgrade blocks just above here.
10391049

10401050
// Check the version of the Maxima library code that comes with this version

doc/en/STACK_question_admin/Testing.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Notes:
7777
* Some answer tests generate notes which depend on the specific input. For this reason, when automatically creating test case expectations from particular inputs the notes from the answer test are not included. You can choose to include these notes in the test case expectation manually.
7878
* We __anchor__ these notes to specify an expected start/end note. Use the range notations: `[...]` to expect both ends fixed; `(...]` specifies only the final note; `[...)` specifies the start note; `(...)` does not expect a particular start/end note.
7979
* `(...]`is the default if no anchor wrapping is defined (this retains back compatibility).
80+
* Expected test cases are limited to 1000 characters. (Since tags are typically each like `prt1-1-F |` (10 chars), that's a lot of checkable nodes.)
8081

8182
Hence, with the anchored expectation `[ prt1-1-F | prt1-3-F | prt1-4-F ]` the following will pass as tests.
8283

lang/en/qtype_stack.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@
603603
$string['questiontestsfirst'] = 'Expected first node of {$a->expected} but got {$a->actual}.';
604604
$string['questiontestslast'] = 'Expected last node of {$a->expected} but got {$a->actual}.';
605605
$string['questiontestsmissing'] = 'Expected node: {$a}.';
606+
$string['questiontestslong'] = 'Expected notes are truncated at 1000 characters in the database. PRT {$a->prt} was {$a->len} characters. Testcase not saved.';
606607
$string['runquestiontests'] = 'STACK question dashboard';
607608
$string['runquestiontests_help'] = 'The dashboard runs question tests which unit-test the questions to ensure the behaviour matches expectations expressed by the teacher, and deployed variants ensure random versions seen by a student are pre-tested against the question tests. These are tools to help you create and test reliable questions and should be used in all cases a question will be used by students. The dashboard also has numerous other STACK specific functions.';
608609
$string['runquestiontests_alert'] = 'Question is missing tests or variants.';

questiontestedit.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
if ($testcase || $confirmthistestcase) {
4646
$qtest = question_bank::get_qtype('stack')->load_question_test($questionid, $testcase);
4747
}
48+
$errors = [];
4849

4950
// Process any other URL parameters, and do require_login.
5051
[$context, $seed, $urlparams] = qtype_stack_setup_question_test_page($question);
@@ -164,8 +165,16 @@
164165
[$data->{$prtname . 'answernote'}]
165166
));
166167
}
168+
if (strlen($data->{$prtname . 'answernote'}) > 1000) {
169+
$errors[] = stack_string(
170+
'questiontestslong',
171+
['prt' => $prtname, 'len' => strlen($data->{$prtname . 'answernote'})]
172+
);
173+
}
167174
question_bank::get_qtype('stack')->save_question_test($questionid, $qtest, $testcase);
168-
redirect($backurl);
175+
if (empty($errors)) {
176+
redirect($backurl);
177+
}
169178
}
170179

171180
// Prepare the display options.
@@ -196,6 +205,10 @@
196205

197206
echo html_writer::tag('p', stack_string('testinputsimpwarning'));
198207

208+
if (!empty($errors)) {
209+
echo html_writer::tag('div', implode(' ', $errors), ['class' => 'alert alert-danger']);
210+
}
211+
199212
// Show the form.
200213
$mform->display();
201214
echo $OUTPUT->footer();

questiontype.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,8 @@ public function save_question_test($questionid, stack_question_test $qtest, $tes
10311031
(float) $expectedresults->penalty
10321032
);
10331033
}
1034-
$expected->expectedanswernote = $expectedresults->answernotes[0];
1034+
// We coerce the score and penalty to be numeric (correct DB type), so we should make sure the note isn't too long.
1035+
$expected->expectedanswernote = substr($expectedresults->answernotes[0], 0, 1000);
10351036
$DB->insert_record('qtype_stack_qtest_expected', $expected);
10361037
}
10371038

stack/maxima/stackmaxima.mac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3548,4 +3548,4 @@ is_lang(code):=ev(is(%_STACK_LANG=code),simp=true)$
35483548

35493549
/* Stack expects some output with the version number the output happens at */
35503550
/* maximalocal.mac after additional library loading */
3551-
stackmaximaversion:2026042300$
3551+
stackmaximaversion:2026042402$

version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
defined('MOODLE_INTERNAL') || die();
2626

27-
$plugin->version = 2026042300;
27+
$plugin->version = 2026042402;
2828
$plugin->requires = 2022041900;
2929
$plugin->cron = 0;
3030
$plugin->component = 'qtype_stack';

0 commit comments

Comments
 (0)