Skip to content

Commit

Permalink
Don't replace identical test data
Browse files Browse the repository at this point in the history
  • Loading branch information
JHawk0224 committed Feb 11, 2024
1 parent ca6929a commit eed9490
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 14 deletions.
22 changes: 13 additions & 9 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ Here is an ordered list of todos and other things to work on for this framework:
2. Merge in few Frontend https://github.com/upenn-nets-2120/student-tests/pull/2
3. Fix security vulnerabilities (ask @JHawk0224 )
4. Make sure default tests are always run (from Gradescope files), e.g. even if student tests don’t pass (so default tests need to be uploaded to Gradescope every time the TA submits the autograder). Also make sure these default tests are run first to prevent server crashes affecting them.
5. Give useful feedback to students if tests.json is formatted incorrectly, e.g. if the test type field isn’t there, if it isn’t valid json, etc. Also ensure that the required fields are there like name, etc.
6. Set up/allow only https (port 443), also Elastic IP and A record for domain name
7. Make sure that when submitting identical tests the data isn’t actually overwritten on the backend, only if there is an update to some field.
8. Keep a log of the autograder’s backend’s print statement (at least most recent 1000 or so) to see why server goes down if so
9. Add backend support for unliking and undisliking and integrate with frontend
10. Add limit to number of autograder re-runs so not too frequent
11. Add support for running scripts as test cases
12. Tag tests with specific sections of an assignment, and display on website/filter by tag
13. Finish implementing visibility levels for tests (e.g. see actual content of tests depending on visibility flag, or just name and description, or what outputs to students when run in Gradescope). Also integrate with default tests so some can be completely hidden while others are displayed.
5. Finish implementing visibility levels for tests (e.g. see actual content of tests depending on visibility flag, or just name and description, or what outputs to students when run in Gradescope). Also integrate with default tests so some can be completely hidden while others are displayed.
- Have 3 options for each of 3 categories: visible for everyone, visible for admins only, visible to user only
- Categories: Determining who the test case code is visible for, determining who can see the details of the test case (the Gradescope output of it), and determining who can see the error logs for the test case
- Ensure owner of private tests can see error logs (not just Gradescope output) depending on visibility level
6. Give useful feedback to students if tests.json is formatted incorrectly, e.g. if the test type field isn’t there, if it isn’t valid json, etc. Also ensure that the required fields are there like name, etc.
7. Add support for running scripts as test cases
8. Set up/allow only https (port 443), also Elastic IP and A record for domain name
9. Keep a log of the autograder’s backend’s print statement (at least most recent 1000 or so) to see why server goes down if so
10. Add backend support for unliking and undisliking and integrate with frontend
11. Since run student code, they could add to/modify the gradescope output, or run things with environment variables (e.g. send requests to backend as Gradescope), need to increase security
12. Add limit to number of autograder re-runs so not too frequent
Make GitHub action that integrates STF so when new commits are made to a solution repo, the tests are automatically run (same workflow as Gradescope, but need to redo the details of the assignment metadata/tests output).
13. Tag tests with specific sections of an assignment, and display on website/filter by tag
14. Somehow allow students to rerun same suite of student tests twice in a row
15. Support for other types of tests like Jest and playwright
16. Finish TODOs written in codebase
Expand Down
30 changes: 25 additions & 5 deletions testit-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const express = require('express');
const bcrypt = require('bcrypt');
const jwt = require('jsonwebtoken');
const cors = require('cors');
const _ = require('lodash');
const mongodb = require('mongodb');
const MongoClient = mongodb.MongoClient;
const app = express();
Expand Down Expand Up @@ -311,8 +312,10 @@ app.post('/submit-tests/:assignmentName', authorize, express.json(), async (req,
const result = {failedToAdd: []};
const processedTestCases = [];
for (const testCase of testCases) {
testCase.author = author;
const existingTestCase = await collection.findOne({ name: testCase.name });
const isTestIdentical = existingTestCase && isTestSame(testCase, existingTestCase);

testCase.author = author;
testCase.timesRan = 0;
testCase.timesRanSuccessfully = 0;
testCase.numStudentsRan = 0;
Expand All @@ -325,17 +328,17 @@ app.post('/submit-tests/:assignmentName', authorize, express.json(), async (req,
testCase.public ??= true;
testCase.visibility = "limited"; // 3 options, full (actual content of test can be seen), limited (only name, description, and feedback), none (only author can see)
testCase.isDefault = false; // default would be true for instructor-created test cases that show up even if a student hasn't submitted any tests

if (testCase.author === "admin") {
testCase.isDefault = true;
}

const existingTestCase = await collection.findOne({ name: testCase.name });
if (existingTestCase) {
if (existingTestCase.author === author) {
// Author is the same, update the existing test case
await collection.updateOne({ name: testCase.name }, { $set: testCase });
console.log("Test " + testCase.name + " updated!");
if (!isTestIdentical) {
await collection.updateOne({ name: testCase.name }, { $set: testCase });
console.log("Test " + testCase.name + " updated!");
}
} else {
// Different author, cannot overwrite
console.log("Test " + testCase.name + " already exists by a different author!");
Expand Down Expand Up @@ -388,6 +391,23 @@ app.post('/submit-tests/:assignmentName', authorize, express.json(), async (req,
}
});

function isTestSame(newTest, oldTest) {
const newTestKeys = Object.keys(newTest);
const oldTestKeys = Object.keys(oldTest);

if (!newTestKeys.every(key => oldTestKeys.includes(key))) {
return false;
}

for (const key of newTestKeys) {
if (!_.isEqual(newTest[key], oldTest[key])) {
return false;
}
}

return true;
}

function weightedRandomSample(items, maxItems) {
let totalWeight = items.reduce((acc, item) => acc + item.weight, 0);
let weightedSamples = [];
Expand Down
6 changes: 6 additions & 0 deletions testit-server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions testit-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"cors": "^2.8.5",
"express": "^4.17.1",
"jsonwebtoken": "^9.0.2",
"lodash": "^4.17.21",
"mongodb": "^3.6.0"
},
"author": "JHawk0224",
Expand Down

0 comments on commit eed9490

Please sign in to comment.